Changeset 8268 in genesis for nodes/make-network-graph.py
- Timestamp:
- Aug 8, 2010, 3:24:13 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
nodes/make-network-graph.py
-
Property svn:keywords
set to
Id
r8240 r8268 1 1 #!/usr/bin/env python 2 # zoek de eerste vrije (== niet in een wleiden.conf gedefinieerde) interlink 3 # range 4 # lodewijk@wirelessleiden.nl 2 # vim:ts=2:et:sw=2:ai 3 # 4 # Build topological network graph 5 # Rick van der Zwet <info@rickvanderzwet.nl> 5 6 import re 6 7 import sys 7 8 import glob 8 import getrange9 9 import tempfile 10 10 import subprocess 11 import gformat 11 12 12 13 OUTFILE = 'network.png' 13 14 14 15 def 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) 16 poel = {} 17 link_type = {} 18 try: 19 for host in gformat.get_proxylist() + gformat.get_nodelist(): 20 print "## Processing host", host 21 datadump = gformat.get_yaml(host) 22 iface_keys = [elem for elem in datadump.keys() if (elem.startswith('iface_') and not "lo0" in elem)] 23 for iface_key in iface_keys: 24 l = datadump[iface_key]['ip'] 25 addr, mask = l.split('/') 50 26 51 f = tempfile.NamedTemporaryFile(bufsize=0) 52 sys.stderr.write("# Building temponary graph file\n") 53 print >> f, "Graph WirelessLeidenNetwork {" 54 print >> f ,""" 27 addr = gformat.parseaddr(addr) 28 mask = int(mask) 29 addr = addr & ~((1 << (32 - mask)) - 1) 30 if poel.has_key(addr): 31 poel[addr] += [host] 32 else: 33 poel[addr] = [host] 34 # Assume all eth2wifibridge to be 11a for a moment 35 if datadump[iface_key].has_key('eth2wifibridge'): 36 link_type[addr] = '11a' 37 else: 38 link_type[addr] = datadump[iface_key]['type'] 39 print "### %s [%s] is of type %s" % (gformat.showaddr(addr), iface_key, link_type[addr]) 40 except (KeyError, ValueError), e: 41 print "[FOUT] in '%s' interface '%s'" % (host,iface_key) 42 print e 43 sys.exit(1) 44 45 f = tempfile.NamedTemporaryFile(bufsize=0) 46 sys.stderr.write("# Building temponary graph file\n") 47 print >> f, "Graph WirelessLeidenNetwork {" 48 print >> f ,""" 55 49 graph [ fontsize = 36, 56 50 overlap = scalexy, … … 58 52 ] 59 53 """ 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) 54 for addr,leden in poel.iteritems(): 55 if link_type[addr] == '11a': 56 color = 'red' 57 weight = 4 58 elif link_type[addr] == 'eth': 59 color = 'blue' 60 weight = 8 61 else: 62 color = 'black' 63 weight = 1 64 leden = sorted(set(leden)) 65 for index,lid in enumerate(leden[:-1]): 66 for buur in leden[index + 1:]: 67 print >> f,' %s -- %s [label="%s", color="%s", weight="%s"]' % (lid, buur, gformat.showaddr(addr), color, weight) 68 print >> f, "}" 69 sys.stderr.write("# Plotting temponary graph file using graphviz\n") 70 retval = subprocess.call(["neato","-Tpng",f.name, "-o", OUTFILE]) 71 if retval != 0: 72 sys.stderr.write("# FAILED [%i]\n" % retval) 73 subprocess.call(["cat",f.name]) 74 exit(1) 75 sys.stderr.write("# COMPLETED find your output in %s\n" % OUTFILE) 73 76 74 77 75 78 if __name__ == "__main__": 76 79 make_graph() 77 80 -
Property svn:keywords
set to
Note:
See TracChangeset
for help on using the changeset viewer.