* VNET test that runs traceroute, tcptraceroute, checks if they run to completion...
[tests.git] / qaapi / qa / tests / node / traceroutes.pl
1 #!/usr/bin/perl
2 # Generate a ton of connections and check if we can see syn/ack packets via tcpdump
3
4 my $guineapig="vini-veritas.net";
5 my $ttraceroute="/usr/sbin/tcptraceroute";
6 my $traceroute="/usr/sbin/tracepath";
7
8 sub open_tcptraceroute {
9         if (!-e "$ttraceroute") {
10                 die("[FAILED] Please install tcptraceroute in the slice before running this test\n");
11         }       
12         my $cmdline="$ttraceroute $guineapig";
13         my $out='';
14         my %result;
15         open TT,"$cmdline|";
16
17         while (<TT>) {
18                 if (/\((\d+\.\d+\.\d+\.\d+)\)/) {
19                         $result{$1}=$result{$1}+1;
20                 }
21         }
22         return %result;
23
24 }
25
26 sub open_traceroute {
27         if (!-e "$traceroute") {
28                 die("[FAILED] Please install tcptraceroute in the slice before running this test\n");
29         }       
30         my $ref=shift;
31         my $cmdline="$traceroute $guineapig";
32         my $out='';
33         my %result=%$ref;;
34         open TT,"$cmdline|";
35
36         while (<TT>) {
37                 if (/\((\d+\.\d+\.\d+\.\d+)\)/) {
38                         $result{$1}=$results{$1}+1;
39                 }
40         }
41         return %result;
42
43 }
44
45 sub compare {
46         my $ref=shift;
47         my %a1=%$ref;
48         my $ret=1;
49         my $double=0;
50         my $single=0;
51         foreach (keys %a1) {
52                 print "$_->".$a1{$_}."\n";
53                 if ($a1{$_}==1) {
54                         print "Single: $_\n";
55                         $single++;
56                 } elsif ($a1{$_}==2) {
57                         print "Double: $_\n";
58                         $double++;
59                 }
60                 else { die ("bug in test script");}
61
62         }
63         return ($single,$double);
64 }
65
66 sub alhandler {
67         print "[FAILED] Timed out waiting\n";
68         exit(-1);
69 }
70
71 print "Starting tcptraceroute...\n";
72 if (fork==0) {
73         my %r1;
74         my $s;
75         my $d;
76
77         %r1=open_tcptraceroute;
78         %r1=open_traceroute %r1;
79         ($s,$d)=compare(\%r1);
80         if ($s==0 && $d>2) {
81                 print "[SUCCESS] traceroute and tcptraceroute reported the same result. $d hops.\n";
82                 exit(0);
83         }
84         elsif ($s && $d>2) {
85                 print "[PARTIAL SUCCESS] traceroute and tcptraceroute reported $s different hops out of $d.\n";
86         }
87         else {
88                 print "[FAILED] traceroute and tcptraceroute reported different results\n";
89         }
90 }
91 else {
92         print "Generating connections...\n";
93         $SIG{ALRM}=\&alhandler;
94         alarm(60);
95         wait;
96 }