diff doc/ucis.ano/bgp_graph/bgp_path_list_xml.php @ 28:4dbe5bf653bb draft

Added bgp graph scripts
author ivo <ivo@UFO-Net.nl>
date Thu, 10 Jun 2010 00:15:51 +0200
parents
children 77b07c336f91
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/doc/ucis.ano/bgp_graph/bgp_path_list_xml.php	Thu Jun 10 00:15:51 2010 +0200
@@ -0,0 +1,48 @@
+#!/usr/bin/php
+<?php
+$mynode = 0;
+
+$file = STDIN;
+$paths = array();
+
+while (!feof($file)) {
+	if (seekto($file, '<as-path>') === FALSE) break;
+	seekto($file, '<segment');
+	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, '</asn>');
+		$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;
+}