Mercurial > hg > anonet-resdb
view doc/ucis.ano/bgp_graph/path_list_to_dot.php @ 37:fd9b90f6fbc1 draft
trying a different format
author | Nick <nick@somerandomnick.ano> |
---|---|
date | Fri, 11 Jun 2010 20:21:42 +0000 |
parents | 14e97bffdd55 |
children | c79c2e94307c |
line wrap: on
line source
#!/usr/bin/php <?php $nodes = array(); $file = STDIN; while (!feof($file)) { $line = stream_get_line($file, 1024, "\n"); if ($line === NULL) break; if (!strlen($line)) continue; $pathnodes = explode(' ', $line); $prevnode = NULL; foreach ($pathnodes as $node) { if ($prevnode && $node) $nodes[$prevnode][$node] = 1; $prevnode = $node; } } foreach ($nodes as $node => $links) { foreach ($links as $link => $dummy) { if ($node != $link && isset($nodes[$node][$link]) && isset($nodes[$link][$node])) unset($nodes[$link][$node]); } } function nodename ($node) { switch ($node) { case '64731': return 'SRN (AS64731)'; }; return 'AS'.$node; }; $nodelist=array(); foreach ($nodes as $node => $links) { if (!array_key_exists($node,$nodelist)) $nodelist[$node]=nodename($node); foreach ($links as $link => $dummy) if (!array_key_exists($link,$nodelist)) $nodelist[$node]=nodename($link); }; print("graph BGP_nodes {\n"); foreach ($nodelist as $node => $name) print "\t".$node.' [label="'.$name.'"]'."\n"; foreach ($nodes as $node => $links) { foreach ($links as $link => $dummy) { print("\t".$node.' -- '.$link.";\n"); } } print('}');