annotate doc/ucis.ano/bgp_graph/path_list_to_dot.php @ 187:bb91561cd116 draft

minor updates to a2.o
author Nick <nick@somerandomnick.ano>
date Fri, 15 Oct 2010 15:16:22 +0000
parents b1e1c567665b
children 3ef3b47c7437
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
50
0e7ba1239f5a now pulls AS info from dn42 registry
Nick <nick@somerandomnick.ano>
parents: 47
diff changeset
25 function static_nodename ($node) { switch ($node) {
51
198bd6e327eb added some more customization capability for ASN names
Nick <nick@somerandomnick.ano>
parents: 50
diff changeset
26 // case '64731': return 'SRN (AS64731)';
198bd6e327eb added some more customization capability for ASN names
Nick <nick@somerandomnick.ano>
parents: 50
diff changeset
27 // case '64766': return 'UFO (AS64766)';
198bd6e327eb added some more customization capability for ASN names
Nick <nick@somerandomnick.ano>
parents: 50
diff changeset
28 }; return NULL; };
198bd6e327eb added some more customization capability for ASN names
Nick <nick@somerandomnick.ano>
parents: 50
diff changeset
29
198bd6e327eb added some more customization capability for ASN names
Nick <nick@somerandomnick.ano>
parents: 50
diff changeset
30 function nodenickname ($node) { switch ($node) {
198bd6e327eb added some more customization capability for ASN names
Nick <nick@somerandomnick.ano>
parents: 50
diff changeset
31 case '64731': return 'SRN';
198bd6e327eb added some more customization capability for ASN names
Nick <nick@somerandomnick.ano>
parents: 50
diff changeset
32 case '64766': return 'UFO';
52
8643d1b779de added some ASN nicks
Nick <nick@somerandomnick.ano>
parents: 51
diff changeset
33 case '64768': return 'yang';
8643d1b779de added some ASN nicks
Nick <nick@somerandomnick.ano>
parents: 51
diff changeset
34 case '64738': return 'welterde';
8643d1b779de added some ASN nicks
Nick <nick@somerandomnick.ano>
parents: 51
diff changeset
35 case '64827': return 'deelkar';
64
b1e1c567665b stupid typo
Nick <nick@somerandomnick.ano>
parents: 63
diff changeset
36 case '64680': case '64692': return rtrim(`echo $node | ./asn2descr`);
50
0e7ba1239f5a now pulls AS info from dn42 registry
Nick <nick@somerandomnick.ano>
parents: 47
diff changeset
37 }; return NULL; };
0e7ba1239f5a now pulls AS info from dn42 registry
Nick <nick@somerandomnick.ano>
parents: 47
diff changeset
38
0e7ba1239f5a now pulls AS info from dn42 registry
Nick <nick@somerandomnick.ano>
parents: 47
diff changeset
39 function nodename ($node) {
0e7ba1239f5a now pulls AS info from dn42 registry
Nick <nick@somerandomnick.ano>
parents: 47
diff changeset
40 $node=preg_replace('/[^0-9]+/','',$node);
0e7ba1239f5a now pulls AS info from dn42 registry
Nick <nick@somerandomnick.ano>
parents: 47
diff changeset
41 if (($name=static_nodename($node))!==NULL) return $name;
51
198bd6e327eb added some more customization capability for ASN names
Nick <nick@somerandomnick.ano>
parents: 50
diff changeset
42 $nameparts=array();
198bd6e327eb added some more customization capability for ASN names
Nick <nick@somerandomnick.ano>
parents: 50
diff changeset
43 if (($nick=nodenickname($node))!==NULL) $nameparts[]=$nick;
50
0e7ba1239f5a now pulls AS info from dn42 registry
Nick <nick@somerandomnick.ano>
parents: 47
diff changeset
44 $name=rtrim(`echo $node | ./asn2adminc | ./hdl2person`);
51
198bd6e327eb added some more customization capability for ASN names
Nick <nick@somerandomnick.ano>
parents: 50
diff changeset
45 if (empty($name)) $name='AS'.$node; else $name="AS$node ($name)";
198bd6e327eb added some more customization capability for ASN names
Nick <nick@somerandomnick.ano>
parents: 50
diff changeset
46 $nameparts[]=$name;
198bd6e327eb added some more customization capability for ASN names
Nick <nick@somerandomnick.ano>
parents: 50
diff changeset
47 return join(' - ',$nameparts); };
35
bec289fc3b4a attempt at testing AS names
Nick <nick@somerandomnick.ano>
parents: 34
diff changeset
48
bec289fc3b4a attempt at testing AS names
Nick <nick@somerandomnick.ano>
parents: 34
diff changeset
49 $nodelist=array();
bec289fc3b4a attempt at testing AS names
Nick <nick@somerandomnick.ano>
parents: 34
diff changeset
50 foreach ($nodes as $node => $links) {
bec289fc3b4a attempt at testing AS names
Nick <nick@somerandomnick.ano>
parents: 34
diff changeset
51 if (!array_key_exists($node,$nodelist)) $nodelist[$node]=nodename($node);
bec289fc3b4a attempt at testing AS names
Nick <nick@somerandomnick.ano>
parents: 34
diff changeset
52 foreach ($links as $link => $dummy)
47
f2fb1d2dcf8c fixed another bug (misnamed ASes)
Nick <nick@somerandomnick.ano>
parents: 46
diff changeset
53 if (!array_key_exists($link,$nodelist)) $nodelist[$link]=nodename($link);
35
bec289fc3b4a attempt at testing AS names
Nick <nick@somerandomnick.ano>
parents: 34
diff changeset
54 };
bec289fc3b4a attempt at testing AS names
Nick <nick@somerandomnick.ano>
parents: 34
diff changeset
55
36
14e97bffdd55 was generating malformed dot
Nick <nick@somerandomnick.ano>
parents: 35
diff changeset
56 print("graph BGP_nodes {\n");
62
ec2590f00495 recovered some work lost accidentally outside git
Nick <nick@somerandomnick.ano>
parents: 61
diff changeset
57 print("\toverlap=\"prism\";\n");
35
bec289fc3b4a attempt at testing AS names
Nick <nick@somerandomnick.ano>
parents: 34
diff changeset
58 foreach ($nodelist as $node => $name)
61
d8b6fb8cd729 added hyperlinks to graph (to UFO's pages)
Nick <nick@somerandomnick.ano>
parents: 52
diff changeset
59 print "\t".$node.' [label="'.$name.'",URL="http://ix.ucis.dn42/dn42/db/asdetails.php?h='.$node.'"];'."\n";
35
bec289fc3b4a attempt at testing AS names
Nick <nick@somerandomnick.ano>
parents: 34
diff changeset
60
28
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
61 foreach ($nodes as $node => $links) {
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
62 foreach ($links as $link => $dummy) {
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
63 print("\t".$node.' -- '.$link.";\n");
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
64 }
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
65 }
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
66 print('}');