From 2a9c494477ed1d88f97b8b8db98a841c74159b1f Mon Sep 17 00:00:00 2001 From: ivo Date: Thu, 10 Jun 2010 00:15:51 +0200 Subject: Added bgp graph scripts --- doc/ucis.ano/bgp_graph/bgp_path_list_bird.php | 20 +++++++++++ doc/ucis.ano/bgp_graph/bgp_path_list_bird.sh | 3 ++ doc/ucis.ano/bgp_graph/bgp_path_list_quagga.php | 16 +++++++++ doc/ucis.ano/bgp_graph/bgp_path_list_quagga.sh | 21 +++++++++++ doc/ucis.ano/bgp_graph/bgp_path_list_xml.php | 48 +++++++++++++++++++++++++ doc/ucis.ano/bgp_graph/path_list_to_dot.php | 31 ++++++++++++++++ doc/ucis.ano/bgp_graph/path_list_to_xml.php | 17 +++++++++ doc/ucis.ano/bgp_graph/process_xml.sh | 6 ++++ 8 files changed, 162 insertions(+) create mode 100755 doc/ucis.ano/bgp_graph/bgp_path_list_bird.php create mode 100755 doc/ucis.ano/bgp_graph/bgp_path_list_bird.sh create mode 100755 doc/ucis.ano/bgp_graph/bgp_path_list_quagga.php create mode 100755 doc/ucis.ano/bgp_graph/bgp_path_list_quagga.sh create mode 100755 doc/ucis.ano/bgp_graph/bgp_path_list_xml.php create mode 100755 doc/ucis.ano/bgp_graph/path_list_to_dot.php create mode 100755 doc/ucis.ano/bgp_graph/path_list_to_xml.php create mode 100755 doc/ucis.ano/bgp_graph/process_xml.sh (limited to 'doc/ucis.ano/bgp_graph') diff --git a/doc/ucis.ano/bgp_graph/bgp_path_list_bird.php b/doc/ucis.ano/bgp_graph/bgp_path_list_bird.php new file mode 100755 index 0000000..6ef71c7 --- /dev/null +++ b/doc/ucis.ano/bgp_graph/bgp_path_list_bird.php @@ -0,0 +1,20 @@ +#!/usr/bin/php + array('pipe','r'), 1 => array('pipe','w'), 2 => STDERR), $fds); +fwrite($fds[0], "show route all\n"); +fclose($fds[0]); +$paths = array(); + +while (!feof($fds[1])) { + $line = stream_get_line($fds[1], 1024, "\n"); + if ($line === NULL || $line === FALSE) break; + if (!strlen($line) || $line[0] != "\t") continue; + if (substr($line, 0, 14) != "\tBGP.as_path: ") continue; + $path = substr($line, 14); + if (in_array($path, $paths)) continue; + $paths[] = $path; + print($mynode.' '.$path."\n"); +} diff --git a/doc/ucis.ano/bgp_graph/bgp_path_list_bird.sh b/doc/ucis.ano/bgp_graph/bgp_path_list_bird.sh new file mode 100755 index 0000000..747f017 --- /dev/null +++ b/doc/ucis.ano/bgp_graph/bgp_path_list_bird.sh @@ -0,0 +1,3 @@ +#!/bin/sh +LOCALNODE=0 +echo "show route all" | birdc | grep -F "BGP.as_path:" | sed "s/^\tBGP.as_path: \([0-9 ]*\)$/$LOCALNODE \1/" | sort -u diff --git a/doc/ucis.ano/bgp_graph/bgp_path_list_quagga.php b/doc/ucis.ano/bgp_graph/bgp_path_list_quagga.php new file mode 100755 index 0000000..240dcf3 --- /dev/null +++ b/doc/ucis.ano/bgp_graph/bgp_path_list_quagga.php @@ -0,0 +1,16 @@ +#!/usr/bin/php +') === FALSE) break; + seekto($file, ''); + $endofsection = FALSE; + $path = $mynode; + while (!feof($file)) { + if (seekto($file, '<') === FALSE) break; + switch (fread($file, 4)) { + case 'asn>': break; + case '/seg': $endofsection = TRUE; break; + default: die('unknown tag at '.(ftell($file)-4)); + } + if ($endofsection) break; + $asn = seekto($file, ''); + $path .= ' '.$asn; + } + if (in_array($path, $paths)) continue; + $paths[] = $path; + print($path."\n"); +} + +function seekto($f, $str) { + $part = ''; + $i = 0; + $len = strlen($str); + while ($i < $len && !feof($f)) { + $c = fgetc($f); + if ($c === FALSE) return FALSE; + if ($c == $str[$i]) { + $i++; + } else { + if ($i) { + $i = 0; + $part = ''; + } + $part .= $c; + } + } + return $part; +} diff --git a/doc/ucis.ano/bgp_graph/path_list_to_dot.php b/doc/ucis.ano/bgp_graph/path_list_to_dot.php new file mode 100755 index 0000000..d198331 --- /dev/null +++ b/doc/ucis.ano/bgp_graph/path_list_to_dot.php @@ -0,0 +1,31 @@ +#!/usr/bin/php + $links) { + foreach ($links as $link => $dummy) { + if (isset($nodes[$node][$link]) && isset($nodes[$link][$node])) unset($nodes[$link][$node]); + } +} + +print("graph BGP_nodes {\n"); +foreach ($nodes as $node => $links) { + foreach ($links as $link => $dummy) { + print("\t".$node.' -- '.$link.";\n"); + } +} +print('}'); diff --git a/doc/ucis.ano/bgp_graph/path_list_to_xml.php b/doc/ucis.ano/bgp_graph/path_list_to_xml.php new file mode 100755 index 0000000..d9df7f6 --- /dev/null +++ b/doc/ucis.ano/bgp_graph/path_list_to_xml.php @@ -0,0 +1,17 @@ +#!/usr/bin/php +'."\n"); + $prevnode = $node; + } +} diff --git a/doc/ucis.ano/bgp_graph/process_xml.sh b/doc/ucis.ano/bgp_graph/process_xml.sh new file mode 100755 index 0000000..dec83dd --- /dev/null +++ b/doc/ucis.ano/bgp_graph/process_xml.sh @@ -0,0 +1,6 @@ +#!/bin/sh +for file in ./xml/* +do + echo "Processing $file" + ./bgp_path_list_xml.php < "$file" > data/`basename "$file"` +done -- cgit v1.2.3