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 |
|
25 print("graph BGP_nodes {\n"); |
|
26 foreach ($nodes as $node => $links) { |
|
27 foreach ($links as $link => $dummy) { |
|
28 print("\t".$node.' -- '.$link.";\n"); |
|
29 } |
|
30 } |
|
31 print('}'); |