annotate doc/ucis.ano/bgp_graph/path_list_to_dot.php @ 61:d8b6fb8cd729 draft

added hyperlinks to graph (to UFO's pages)
author Nick <nick@somerandomnick.ano>
date Thu, 17 Jun 2010 16:04:03 +0000
parents 8643d1b779de
children ec2590f00495
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';
50
0e7ba1239f5a now pulls AS info from dn42 registry
Nick <nick@somerandomnick.ano>
parents: 47
diff changeset
36 }; return NULL; };
0e7ba1239f5a now pulls AS info from dn42 registry
Nick <nick@somerandomnick.ano>
parents: 47
diff changeset
37
0e7ba1239f5a now pulls AS info from dn42 registry
Nick <nick@somerandomnick.ano>
parents: 47
diff changeset
38 function nodename ($node) {
0e7ba1239f5a now pulls AS info from dn42 registry
Nick <nick@somerandomnick.ano>
parents: 47
diff changeset
39 $node=preg_replace('/[^0-9]+/','',$node);
0e7ba1239f5a now pulls AS info from dn42 registry
Nick <nick@somerandomnick.ano>
parents: 47
diff changeset
40 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
41 $nameparts=array();
198bd6e327eb added some more customization capability for ASN names
Nick <nick@somerandomnick.ano>
parents: 50
diff changeset
42 if (($nick=nodenickname($node))!==NULL) $nameparts[]=$nick;
50
0e7ba1239f5a now pulls AS info from dn42 registry
Nick <nick@somerandomnick.ano>
parents: 47
diff changeset
43 $name=rtrim(`echo $node | ./asn2adminc | ./hdl2person`);
51
198bd6e327eb added some more customization capability for ASN names
Nick <nick@somerandomnick.ano>
parents: 50
diff changeset
44 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
45 $nameparts[]=$name;
198bd6e327eb added some more customization capability for ASN names
Nick <nick@somerandomnick.ano>
parents: 50
diff changeset
46 return join(' - ',$nameparts); };
35
bec289fc3b4a attempt at testing AS names
Nick <nick@somerandomnick.ano>
parents: 34
diff changeset
47
bec289fc3b4a attempt at testing AS names
Nick <nick@somerandomnick.ano>
parents: 34
diff changeset
48 $nodelist=array();
bec289fc3b4a attempt at testing AS names
Nick <nick@somerandomnick.ano>
parents: 34
diff changeset
49 foreach ($nodes as $node => $links) {
bec289fc3b4a attempt at testing AS names
Nick <nick@somerandomnick.ano>
parents: 34
diff changeset
50 if (!array_key_exists($node,$nodelist)) $nodelist[$node]=nodename($node);
bec289fc3b4a attempt at testing AS names
Nick <nick@somerandomnick.ano>
parents: 34
diff changeset
51 foreach ($links as $link => $dummy)
47
f2fb1d2dcf8c fixed another bug (misnamed ASes)
Nick <nick@somerandomnick.ano>
parents: 46
diff changeset
52 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
53 };
bec289fc3b4a attempt at testing AS names
Nick <nick@somerandomnick.ano>
parents: 34
diff changeset
54
36
14e97bffdd55 was generating malformed dot
Nick <nick@somerandomnick.ano>
parents: 35
diff changeset
55 print("graph BGP_nodes {\n");
35
bec289fc3b4a attempt at testing AS names
Nick <nick@somerandomnick.ano>
parents: 34
diff changeset
56 foreach ($nodelist as $node => $name)
61
d8b6fb8cd729 added hyperlinks to graph (to UFO's pages)
Nick <nick@somerandomnick.ano>
parents: 52
diff changeset
57 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
58
28
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
59 foreach ($nodes as $node => $links) {
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
60 foreach ($links as $link => $dummy) {
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
61 print("\t".$node.' -- '.$link.";\n");
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
62 }
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
63 }
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
64 print('}');