]>
git.ipfire.org Git - thirdparty/squid.git/blob - scripts/udp-banger.pl
3 ## Copyright (C) 1996-2018 The Squid Software Foundation and contributors
5 ## Squid software is distributed under GPLv2+ license and includes
6 ## contributions from numerous individuals and organizations.
7 ## Please see the COPYING and CONTRIBUTORS files for details.
12 # Duane Wessels, Dec 1995
14 # Usage: udp-banger.pl [host [port]] < url-list
16 # Sends a continuous stream of ICP queries to a cache. Stdin is a list of
17 # URLs to request. Run N of these at the same time to simulate a heavy
18 # neighbor cache load.
28 $host=(shift || 'localhost') ;
29 $port=(shift || '3130') ;
31 # just copy this from src/proto.c
60 $sock = IO
::Socket
::INET
->new(PeerAddr
=> "$host:$port", Proto
=> 'udp');
61 die "socket: $!\n" unless defined($sock);
63 chop($me=`uname -a|cut -f2 -d' '`);
64 $myip=(gethostbyname($me))[4];
66 $flags = fcntl ($sock, &F_GETFL
, 0);
67 $flags |= &O_NONBLOCK
;
68 die "fcntl O_NONBLOCK: $!\n" unless
69 fcntl ($sock, &F_SETFL
, $flags);
73 $flags |= 0x40000000 if ($opt_n);
81 if ($opt_l) { # it's a Squid log file
82 @stuff = split(/\s+/, $_);
86 $len = length($_) + 1;
87 $request_template = sprintf 'CCnNNa4a4x4a%d', $len;
88 $request = pack($request_template,
97 die "send: $!\n" unless
98 send($sock, $request, 0);
101 vec($rin,fileno($sock),1) = 1;
102 ($nfound,$timeleft) = select($rout=$rin, undef, undef, 2.0);
103 next if ($nfound == 0);
105 last unless ($theiraddr = recv($sock, $reply, 1024, 0));
106 next if $opt_q; # quietly carry on
109 # only print send/receive rates
110 if (($nsent & 0xFF) == 0) {
112 printf "SENT %d %f/sec; RECV %d %f/sec\n",
119 # print the whole reply
120 ($junk, $junk, $sourceaddr, $junk) = unpack($sockaddr, $theiraddr);
121 @theirip = unpack('C4', $sourceaddr);
122 ($type,$ver,$len,$flag,$p1,$p2,$payload) = unpack('CCnx4Nnnx4A', $reply);
123 print join('.', @theirip) . ' ' . $CODES[$type] . " $_";
124 print " hop=$p1" if ($opt_n);
125 print " rtt=$p2" if ($opt_n);