offline pcap reading working
[netsniff-ng.git] / src / trafgen_imix.pl
blob70bbb17b34097c85ff8a57976782cf71634f69f2
1 #!/usr/bin/perl
3 # netsniff-ng - the packet sniffing beast
4 # Copyright 2011 Daniel Borkmann <daniel@netsniff-ng.org>
5 # Subject to the GPL.
6 # Configuration file generator for trafgen.
7 # Generates IMIX packet distribution (64:7, 570:4, 1518:1)
8 # In lengths the Frame Check Sequence of 4 Byte is not counted
10 use warnings;
11 use strict;
13 my %conf = (
14 60 => 7, # 64 - 4
15 566 => 4, # 570 - 4
16 1514 => 1 # 1518 - 4
19 print "# Run in round-robin mode with trafgen!\n";
20 print "# E.g. trafgen --dev eth0 --conf <this-as-file> --bind 0\n\n";
22 my $sum = 0;
23 foreach (values(%conf)) {
24 $sum = $sum + $_;
27 for (my $pkt = 0; $pkt < $sum; ++$pkt) {
28 my ($len, $done) = (0, 0);
30 do {
31 my @list = keys(%conf);
32 my $index = int(rand(scalar(@list)));
33 my $key = $list[$index];
34 if ($conf{$key} > 0) {
35 $conf{$key}--;
36 $len = $key;
37 $done = 1;
39 } while ($done == 0);
41 print "\$P$pkt {\n";
42 for (my $byte = 0; $byte < $len;) {
43 for (my $off = 0; $off < 13 && $byte < $len; ++$off, ++$byte) {
44 my $cur = sprintf("0x%02x", int(rand(256)));
45 print "$cur, ";
47 print "\n";
49 print "}\n\n";