Fixed for Thierry's test environment.
[tests.git] / qaapi / qa / tests / slice / traceroutes.pl
1 #!/usr/bin/perl
2
3 # Module: VNET+
4 # Description:  Trace the route path to a node using two methods: TCP-related ICMP errors, and TTL expiry. 
5 # Then match the two paths to see that they concord. If there's a slight difference, it's probably OK given that
6 # some routers might support one type of error but not the other, and that the routes are not guaranteed to be the
7 # same.
8 # Dependencies: tcptraceroute, traceroute, which
9 # Author: sapanb@cs.princeton.edu
10
11 $|=1;
12
13 # ********************************************************************************
14 # CONFIGURATION
15
16
17 # The node that we're going to trace route. It's probably a good idea to change it
18 # periodically so that we don't harass the same host.
19 my $guineapig="vini-veritas.net";
20
21 # Location of traceroute, tcptraceroute
22 my $ttraceroute=`which tcptraceroute 2>/dev/null`;
23 my $traceroute=`which traceroute 2>/dev/null`;
24
25 chop($ttraceroute);
26 chop($traceroute);
27
28 if ($traceroute !~ /^\//) {
29         $traceroute=`which tracepath 2>/dev/null`;
30         chop($traceroute);
31 }
32
33 if (!-e "$ttraceroute") {
34         print $ttraceroute."\n";
35         die("[FAILED] Please install tcptraceroute in the slice before running this test\n");
36 }       
37 else {
38         print "Found rcptraceroute. Good.\n";
39 }
40
41 if ($traceroute !~ /^\//) {
42         die("[FAILED] Please install traceroute in the slice before running this test\n");
43 }       
44
45 my %hash;
46
47 sub open_tcptraceroute {
48         my $cmdline="sudo $ttraceroute $guineapig";
49         my $out='';
50         open TT,"$cmdline|";
51
52         while (<TT>) {
53                 if (/\((\d+\.\d+\.\d+\.\d+)\)/) {
54                         glob %hash;
55                         print ">>> $_";
56                         $hash{$1}++;
57                 }
58         }
59 }
60
61 sub open_traceroute {
62         my $ref=shift;
63         my $cmdline="$traceroute $guineapig";
64         my $out='';
65         print $cmdline."\n";
66         open TT,"$cmdline|";
67
68         while (<TT>) {
69                 if (/\((\d+\.\d+\.\d+\.\d+)\)/) {
70                         glob %hash;
71                         print ">>> $_";
72                         $hash{$1}=$hash{$1}+1;
73                 }
74         }
75 }
76
77 sub compare {
78         my $ref=shift;
79         my $ret=1;
80         my $double=0;
81         my $single=0;
82         glob %hash;
83         foreach (keys %hash) {
84                 if ($hash{$_}==1) {
85                         $single++;
86                 } elsif ($hash{$_}==2) {
87                         print "Concorded on $_\n";
88                         $double++;
89                 }
90                 else { die ("[FAILED] Could not complete test.\n");}
91
92         }
93         return ($single,$double);
94 }
95
96 sub alhandler {
97         print "[FAILED] Timed out waiting.\n";
98         exit(-1);
99 }
100
101 print "Starting tcptraceroute...\n";
102 if (fork==0) {
103         my %r1;
104         my $s;
105         my $d;
106
107         open_tcptraceroute;
108         open_traceroute;
109         ($s,$d)=compare;
110         if ($s==0 && $d>2) {
111                 print "[SUCCESS] traceroute and tcptraceroute reported the same result. $d hops.\n";
112                 exit(0);
113         }
114         elsif ($s && $d>2) {
115                 print "[PARTIAL SUCCESS] traceroute and tcptraceroute reported $s different hops out of $d.\n";
116         }
117         else {
118                 print "[FAILED] traceroute and tcptraceroute reported different results\n";
119         }
120 }
121 else {
122         print "Generating connections...\n";
123         $SIG{ALRM}=\&alhandler;
124         alarm(60);
125         wait;
126 }