annotate doc/ucis.ano/bgp_graph/path_list_to_dot.php @ 46:c79c2e94307c draft

forgot semicolons in dot code (bug reported and tracked down by UFO)
author Nick <nick@somerandomnick.ano>
date Sat, 12 Jun 2010 00:05:16 +0000
parents fd9b90f6fbc1
children f2fb1d2dcf8c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
1 #!/usr/bin/php
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
2 <?php
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
3 $nodes = array();
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
4
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
5 $file = STDIN;
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
6
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
7 while (!feof($file)) {
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
8 $line = stream_get_line($file, 1024, "\n");
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
9 if ($line === NULL) break;
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
10 if (!strlen($line)) continue;
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
11 $pathnodes = explode(' ', $line);
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
12 $prevnode = NULL;
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
13 foreach ($pathnodes as $node) {
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
14 if ($prevnode && $node) $nodes[$prevnode][$node] = 1;
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
15 $prevnode = $node;
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
16 }
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
17 }
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
18
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
19 foreach ($nodes as $node => $links) {
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
20 foreach ($links as $link => $dummy) {
34
e429d8af6e44 fixed a typo
Nick <nick@somerandomnick.ano>
parents: 33
diff changeset
21 if ($node != $link && isset($nodes[$node][$link]) && isset($nodes[$link][$node])) unset($nodes[$link][$node]);
28
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
22 }
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
23 }
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
24
35
bec289fc3b4a attempt at testing AS names
Nick <nick@somerandomnick.ano>
parents: 34
diff changeset
25 function nodename ($node) { switch ($node) {
37
fd9b90f6fbc1 trying a different format
Nick <nick@somerandomnick.ano>
parents: 36
diff changeset
26 case '64731': return 'SRN (AS64731)';
fd9b90f6fbc1 trying a different format
Nick <nick@somerandomnick.ano>
parents: 36
diff changeset
27 }; return 'AS'.$node; };
35
bec289fc3b4a attempt at testing AS names
Nick <nick@somerandomnick.ano>
parents: 34
diff changeset
28
bec289fc3b4a attempt at testing AS names
Nick <nick@somerandomnick.ano>
parents: 34
diff changeset
29 $nodelist=array();
bec289fc3b4a attempt at testing AS names
Nick <nick@somerandomnick.ano>
parents: 34
diff changeset
30 foreach ($nodes as $node => $links) {
bec289fc3b4a attempt at testing AS names
Nick <nick@somerandomnick.ano>
parents: 34
diff changeset
31 if (!array_key_exists($node,$nodelist)) $nodelist[$node]=nodename($node);
bec289fc3b4a attempt at testing AS names
Nick <nick@somerandomnick.ano>
parents: 34
diff changeset
32 foreach ($links as $link => $dummy)
bec289fc3b4a attempt at testing AS names
Nick <nick@somerandomnick.ano>
parents: 34
diff changeset
33 if (!array_key_exists($link,$nodelist)) $nodelist[$node]=nodename($link);
bec289fc3b4a attempt at testing AS names
Nick <nick@somerandomnick.ano>
parents: 34
diff changeset
34 };
bec289fc3b4a attempt at testing AS names
Nick <nick@somerandomnick.ano>
parents: 34
diff changeset
35
36
14e97bffdd55 was generating malformed dot
Nick <nick@somerandomnick.ano>
parents: 35
diff changeset
36 print("graph BGP_nodes {\n");
35
bec289fc3b4a attempt at testing AS names
Nick <nick@somerandomnick.ano>
parents: 34
diff changeset
37 foreach ($nodelist as $node => $name)
46
c79c2e94307c forgot semicolons in dot code (bug reported and tracked down by UFO)
Nick <nick@somerandomnick.ano>
parents: 37
diff changeset
38 print "\t".$node.' [label="'.$name.'"];'."\n";
35
bec289fc3b4a attempt at testing AS names
Nick <nick@somerandomnick.ano>
parents: 34
diff changeset
39
28
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
40 foreach ($nodes as $node => $links) {
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
41 foreach ($links as $link => $dummy) {
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
42 print("\t".$node.' -- '.$link.";\n");
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
43 }
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
44 }
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
45 print('}');