source: genesis/nodes/make-network-graph.py@ 8261

Last change on this file since 8261 was 8240, checked in by rick, 14 years ago

Hacky, hacky to get some network topology pictures going again

  • Property svn:executable set to *
File size: 2.0 KB
Line 
1#!/usr/bin/env python
2# zoek de eerste vrije (== niet in een wleiden.conf gedefinieerde) interlink
3# range
4# lodewijk@wirelessleiden.nl
5import re
6import sys
7import glob
8import getrange
9import tempfile
10import subprocess
11
12OUTFILE = 'network.png'
13
14def make_graph():
15 substre = re.compile("^(\$[a-zA-Z][^ =]*) ?= ?'([^']*)';")
16
17
18 poel = {}
19
20 #XXX: Make parsing global, merge with getrange.get_ranges if possible
21 for fname in glob.glob("*/wleiden.conf"):
22 substs = {}
23 lineNr = 0
24 for l in open(fname):
25 lineNr += 1
26 l = l[:-1]
27 match = substre.match(l)
28 if match != None:
29 substs[match.group(1)] = match.group(2)
30 if l.startswith("IP="):
31 right = l[3:]
32 if '/' not in right:
33 addr = right
34 mask = 32
35 else:
36 addr, mask = right.split('/')
37 if addr in substs:
38 addr = substs[addr]
39 try:
40 addr = getrange.parseaddr(addr)
41 mask = int(mask)
42 addr = addr & ~((1 << (32 - mask)) - 1)
43 cname = fname.split('/')[0]
44 if poel.has_key(addr):
45 poel[addr] += [cname]
46 else:
47 poel[addr] = [cname]
48 except ValueError, e:
49 print "[FOUT] in bestand '%s' regel '%i': %s" % (fname, lineNr, l)
50
51 f = tempfile.NamedTemporaryFile(bufsize=0)
52 sys.stderr.write("# Building temponary graph file\n")
53 print >> f, "Graph WirelessLeidenNetwork {"
54 print >> f ,"""
55graph [ fontsize = 36,
56 overlap = scalexy,
57 splines = true,
58 ]
59"""
60 for addr,leden in poel.iteritems():
61 leden = sorted(set(leden))
62 for index,lid in enumerate(leden[:-1]):
63 for buur in leden[index + 1:]:
64 print >> f,' %s -- %s [label="%s"]' % (lid, buur, getrange.showaddr(addr))
65 print >> f, "}"
66 sys.stderr.write("# Plotting temponary graph file using graphviz\n")
67 retval = subprocess.call(["neato","-Tpng",f.name, "-o", OUTFILE])
68 if retval != 0:
69 sys.stderr.write("# FAILED [%i]\n" % retval)
70 subprocess.call(["cat",f.name])
71 exit(1)
72 sys.stderr.write("# COMPLETED find your output in %s\n" % OUTFILE)
73
74
75if __name__ == "__main__":
76 make_graph()
77
Note: See TracBrowser for help on using the repository browser.