source: genesis/nodes/channelplot.py@ 2052

Last change on this file since 2052 was 1938, checked in by jasper, 21 years ago

Lebkov: interface rabo,omni omgewisseld

File size: 2.4 KB
RevLine 
[1206]1# Usage:
2#
3# $ find . -name wleiden.conf > l
4#
5# prune demo, test and uninteresting stuff from l
6#
7# $ python channelplot.py
8# $ gv channelplot.ps
9#
10# needs graphviz (http://www.graphviz.org/) to run
11import os
12import re
13import string
14
15ipdict = {}
16ipnr_node = {}
17node_ipnr = {}
18node_wi_channel = {}
19node_links = {}
20node_links_channel = {}
21nodelabel = {}
22
23def parse_wleiden_conf(lines):
24 ipnr = None
25 wi = None
26 peer = None
27 omni = 0
28 for l in lines:
29 if wi != None:
30 match = re.match("^\EW.*", l)
31 if match != None:
32 wi = None
33 ipnr = None
34 peer = None
35 continue
36 match = re.match("^SDESC=omni.*", l)
37 if match != None:
38 omni = 1
39 match = re.match("^IP=([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*).*", l)
40 if match != None:
41 ipnr = match.group(1)
42 if not node_ipnr.has_key(nodename):
43 node_ipnr[nodename] = []
44 node_ipnr[nodename].append(ipnr)
45 ipnr_node[ipnr] = nodename
46 match = re.match("^POINT_TO_POINT=([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*).*", l)
47 if match != None:
48 peer = match.group(1)
49 if not node_links.has_key(nodename):
50 node_links[nodename] = []
51 node_links[nodename].append( (peer, wi) )
52 match = re.match("^CHANNEL=([0-9]*).*", l)
53 if match != None:
54 if omni == 1:
55 nodelabel[nodename] = "%s\\n(%s)" % (nodename, match.group(1) )
56 else:
57 node_wi_channel[(nodename, wi)] = match.group(1)
58 else:
59 match = re.match("^\$nodename='([^']*)';.*", l)
60 if match != None:
61 nodename = match.group(1).lower()
62 match = re.match("^\$config{'(wi[0-9]*).*", l)
63 if match != None:
64 wi = match.group(1)
65 omni = 0
66
67for fname in open("l").readlines():
68 parse_wleiden_conf(open(fname[:-1]).readlines())
69
70out = open("foo.dot", "w")
71out.write("digraph channelplot {\n")
72for node in node_ipnr.keys():
73 if nodelabel.has_key(node):
74 label = "[label=\"%s\"]" % nodelabel[node]
75 else:
76 label = ''
77 out.write("\t%s %s\n" % (node, label))
78for node in node_ipnr.keys():
79 if node_links.has_key(node):
80 for peer, wi in node_links[node]:
81 if ipnr_node.has_key(peer):
82 if node_wi_channel.has_key( (node,wi) ):
83 label = "[label=\"%s\"]" % node_wi_channel[ (node, wi) ]
84 else:
85 label = ''
86 out.write("%s -> %s%s\n" % (node, ipnr_node[peer], label))
87 else:
88 # link naar onbekend iemand, zal wel niet
89 # belangrijk zijn.
90 pass
91out.write("}\n")
92out.close()
[1938]93os.system('neato -Tjpg -Gstart=foo -Goverlap=false/scale -Gsplines=true -Gsep=2 -Gratio=fill -Gnslimit=50.0 -Grotate=90 -o channelplot.jpg foo.dot')
[1206]94
Note: See TracBrowser for help on using the repository browser.