traceroute test for vnet
[tests.git] / node_tests / 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="$ttraceroute $guineapig";
49         my $out='';
50         open TT,"$cmdline|";
51
52         while (<TT>) {
53                 if (/\((\d+\.\d+\.\d+\.\d+)\)/) {
54                         $hash{$1}++;
55                 }
56         }
57 }
58
59 sub open_traceroute {
60         my $ref=shift;
61         my $cmdline="$traceroute $guineapig";
62         my $out='';
63         open TT,"$cmdline|";
64         glob %hash;
65
66         while (<TT>) {
67                 if (/\((\d+\.\d+\.\d+\.\d+)\)/) {
68                         if ($ref->{$1}) {print $ref->{$1};}
69                         $hash{$1}=$hash{$1}+1;
70                         if ($ref->{$1}) {print $ref->{$1};}
71                 }
72         }
73 }
74
75 sub compare {
76         my $ref=shift;
77         my $ret=1;
78         my $double=0;
79         my $single=0;
80         foreach (keys %hash) {
81                 print "$_->".$a1{$_}."\n";
82                 if ($hash{$_}==1) {
83                         $single++;
84                 } elsif ($hash{$_}==2) {
85                         print "Concorded on $_\n";
86                         $double++;
87                 }
88                 else { die ("[FAILED] bug in test script (sorry!).\n");}
89
90         }
91         return ($single,$double);
92 }
93
94 sub alhandler {
95         print "[FAILED] Timed out waiting.\n";
96         exit(-1);
97 }
98
99 print "Starting tcptraceroute...\n";
100 if (fork==0) {
101         my %r1;
102         my $s;
103         my $d;
104
105         open_tcptraceroute;
106         open_traceroute;
107         ($s,$d)=compare;
108         if ($s==0 && $d>2) {
109                 print "[SUCCESS] traceroute and tcptraceroute reported the same result. $d hops.\n";
110                 exit(0);
111         }
112         elsif ($s && $d>2) {
113                 print "[PARTIAL SUCCESS] traceroute and tcptraceroute reported $s different hops out of $d.\n";
114         }
115         else {
116                 print "[FAILED] traceroute and tcptraceroute reported different results\n";
117         }
118 }
119 else {
120         print "Generating connections...\n";
121         $SIG{ALRM}=\&alhandler;
122         alarm(60);
123         wait;
124 }