28
|
1 #!/usr/bin/php |
|
2 <?php |
|
3 $nodes = array(); |
|
4 |
|
5 $file = STDIN; |
|
6 |
|
7 while (!feof($file)) { |
|
8 $line = stream_get_line($file, 1024, "\n"); |
|
9 if ($line === NULL) break; |
|
10 if (!strlen($line)) continue; |
|
11 $pathnodes = explode(' ', $line); |
|
12 $prevnode = NULL; |
|
13 foreach ($pathnodes as $node) { |
|
14 if ($prevnode && $node) $nodes[$prevnode][$node] = 1; |
|
15 $prevnode = $node; |
|
16 } |
|
17 } |
|
18 |
|
19 foreach ($nodes as $node => $links) { |
|
20 foreach ($links as $link => $dummy) { |
34
|
21 if ($node != $link && isset($nodes[$node][$link]) && isset($nodes[$link][$node])) unset($nodes[$link][$node]); |
28
|
22 } |
|
23 } |
|
24 |
35
|
25 function nodename ($node) { switch ($node) { |
|
26 case '64731': return 'SRN'; |
|
27 }; return $node; }; |
|
28 |
|
29 $nodelist=array(); |
|
30 foreach ($nodes as $node => $links) { |
|
31 if (!array_key_exists($node,$nodelist)) $nodelist[$node]=nodename($node); |
|
32 foreach ($links as $link => $dummy) |
|
33 if (!array_key_exists($link,$nodelist)) $nodelist[$node]=nodename($link); |
|
34 }; |
|
35 |
|
36 foreach ($nodelist as $node => $name) |
|
37 print "\t".$node.' [label="'.$name.'"]'."\n"; |
|
38 |
28
|
39 print("graph BGP_nodes {\n"); |
|
40 foreach ($nodes as $node => $links) { |
|
41 foreach ($links as $link => $dummy) { |
|
42 print("\t".$node.' -- '.$link.";\n"); |
|
43 } |
|
44 } |
|
45 print('}'); |