dlspinhir has asked for the wisdom of the Perl Monks concerning the following question:

We will be testing out some new cisco loadbalancers and firewalls next week, and I thought it would be interesting to write a simple traffic generator to hammer away at them. I wanted something that could spawn off a bunch of child processes that would transmit customized packets to these devices. I came up with the following script using the Parallel::ForkManager and Net::RawIP packages. The script runs, but my test server doesnt seem to be generating as much traffic as I expected. In fact it hardly sends anything at all. I know it is sending some requests because I can see them via tcpdump on my victim server.

Has anyone had any experience writing anything similar to this? Is there anything obvious that sticks out in here?

#==================================================================== # USER DEFINES # global defaults my $def_proto = "icmp"; # default protocol to use my $pattern = 153; # default data pattern to send. + my $num_bytes = 40; # default number number of bytes to send in data +section. my $children = 20; # default number of child processes to spawn my $requests = 50; # default number of requests that each child sends # protocol specific defaults my $prot_ip = { tos => '0', ttl => '30', saddr => '172.16.0.1', }; my $prot_tcp = {source => "33333", dest => "80", urg => "0", ack => "0", psh => "0", rst => "0", syn => "1", fin => "0", }; my $prot_udp = {source => "53", dest => "33333", }; my $prot_icmp = {type => "8", code => "0", }; #======================================= #===================================================================== += # MAIN #------------------- # get data info from user print "number of bytes in data field? [$num_bytes] : "; $input = <STDIN>; chomp ($input); if (($input) && ($input<1501) && ($input>0)) {$num_bytes = $input;} #--------- #------------------- # make data portion of packet my $data = $pattern x $num_bytes; $data = pack("C", $data); #--------- #------------------- # get protocol info from user # get ip info set_ip(); # get upper layer protocol type and info print "tcp, udp, or icmp? [$def_proto] : "; $input = <STDIN>; chomp ($input); if ($input ne "") { if ($input eq "tcp") { $def_proto = "tcp"; set_tcp(); # set prefs for tcp datagram $prot_tcp->{data} = $data; $packet{tcp} = $prot_tcp; } elsif ($input eq "udp") { $def_proto = "udp"; set_udp(); # set prefs for udp datagram $prot_udp->{data} = $data; $packet{udp} = $prot_udp; } else { $def_proto = "icmp"; set_icmp(); # set prefs for icmp datagram $prot_icmp->{data} = $data; $packet{icmp} = $prot_icmp; } } $packet{ip} = $prot_ip; #--------- #------------------- # fork off children and x-mit data my $pm = new Parallel::ForkManager($children); ReadMode 4; # Turn off controls keys print "press any key to quit...\n"; while (not defined (my $key = ReadKey(-1))) { # Forks and returns the pid for the child: my $pid = $pm->start and next; my $pkt_h = new Net::RawIP; $pkt_h->set(\%packet); $pkt_h->send(.25,$requests); $pm->finish; # Terminates the child process } ReadMode 0; # Reset tty mode before exiting print "\n\nwaiting on child processes to stop..."; $pm->wait_all_children; print "...all done...quitting.\n"; #--------- #=======================================

Replies are listed 'Best First'.
Re: rawIP traffic generator
by tachyon (Chancellor) on Dec 17, 2002 at 22:33 UTC

    Your ip prototype does not have a destination address. I suspect that will help.....

    use Net::RawIP; $a = new Net::RawIP; $a->set({ip => {saddr => 'my.target.lan',daddr => 'my.target.lan'}, tcp => {source => 139,dest => 139,psh => 1, syn => 1}});
    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      the subroutine set_ip() is used to set the destination address (along with a few other options). i guess i should have put a comment next to it that expained its purpose a little better.
Re: rawIP traffic generator
by Ryszard (Priest) on Dec 18, 2002 at 09:12 UTC
    I can see them via tcpdump on my victim server.

    Are you checking the outbound interface on the traffic server? netstat -I hme0 -i 0 works on my solaris box.

    I did something like this to load up a DHCP server and found there was an optimum number of child processes to produces the maximum amount of traffic, after which the machine became overloaded processing the childred the traffic dropped.