fdb0406459f91a2ce3d6615308e5fa91d3c3a6df
[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 use strict;
13
14 # ********************************************************************************
15 # CONFIGURATION
16
17
18 # The node that we're going to trace route. It's probably a good idea to change it
19 # periodically so that we don't harass the same host.
20 my $guineapig="vini-veritas.net";
21
22 # Location of traceroute, tcptraceroute
23 my $ttraceroute=`which tcptraceroute 2>/dev/null`;
24 my $traceroute=`which traceroute 2>/dev/null`;
25
26 my %tr;
27
28 chop($ttraceroute);
29 chop($traceroute);
30
31 if ($traceroute !~ /^\//) {
32         $traceroute=`which tracepath 2>/dev/null`;
33         chop($traceroute);
34 }
35
36 if (!-e "$ttraceroute") {
37         print $ttraceroute."\n";
38         print "[OOPS] TCPtraceroute not found. Installing... \n";
39     system("yum -y tcptraceroute");
40     if (!-e "$ttraceroute") {
41             print "[FAILED] TCPtraceroute could not be installed. Test failed.\n";
42     }
43 }       
44 else {
45         print "Found tcptraceroute. Good.\n";
46 }
47
48 if ($traceroute !~ /^\//) {
49         die("[FAILED] Please install traceroute in the slice before running this test\n");
50 }       
51
52 sub open_tcptraceroute {
53         my $cmdline="sudo $ttraceroute $guineapig 2>&1";
54         print $cmdline."\n";
55         my $out='';
56         open TT,"$cmdline|";
57
58         while (<TT>) {
59                 if (/\((\d+\.\d+\.\d+\.\d+)\)/) {
60             glob %tr;
61             $tr{"IP$1"}++;
62             print ">>>$1\n";
63                 }
64         }
65 }
66
67 sub open_traceroute {
68         my $ref=shift;
69         my $cmdline="$traceroute $guineapig 2>&1";
70         my $out='';
71         print $cmdline."\n";
72         open TT,"$cmdline|";
73
74         while (<TT>) {
75                 if (/\((\d+\.\d+\.\d+\.\d+)\)/) {
76             glob %tr;
77             $tr{"IP$1"}++;
78             print ">>>$1\n";
79                 }
80         }
81 }
82
83 sub compare {
84         my $ret=1;
85         my $double=0;
86         my $single=0;
87         glob %tr;
88         foreach (keys %tr) {
89                 if ($tr{$_}==1) {
90                         $single++;
91                 } elsif ($tr{$_}==2) {
92                         $double++;
93                 }
94         }
95         return ($single,$double);
96 }
97
98 sub alhandler {
99         print "[FAILED] Timed out waiting.\n";
100         exit(-1);
101 }
102
103 if (fork==0) {
104         my %r1;
105         my $s;
106         my $d;
107     glob %tr;
108
109         open_tcptraceroute;
110         open_traceroute;
111
112     ($s,$d)=compare;
113
114     if ($d>4) {
115         print "[SUCCESS] traceroutes succeeded, singles: $s, doubles: $d\n";
116     }
117     else {
118         print "[FAILED] traceroutes returned different results: $s, $d\n";
119     }
120 }
121 else {
122         print "Generating connections...\n";
123         $SIG{ALRM}=\&alhandler;
124         alarm(60);
125         wait;
126 }