Commit f128ba9d authored by Julien Muchembled's avatar Julien Muchembled

demo: show default route on the route graph

This is useful because the default one is not always the same as the route
to the registry.

Before, arrows were filled dot. Now only the default one is filled.
parent 9dc1707e
......@@ -247,17 +247,18 @@ def node_by_ll(addr):
_ll[a] = n, t
return _ll[addr]
def route_svg(z=4):
def route_svg(z = 4, default = type('', (), {'short': None})):
graph = {}
for n in nodes:
g = graph[n] = defaultdict(list)
for r in n.get_routes():
if r.prefix and r.prefix.startswith('2001:db8:'):
if r.prefix is None or r.prefix.startswith('2001:db8:'):
try:
g[node_by_ll(r.nexthop)].append(node_by_ll(r.prefix)[0])
g[node_by_ll(r.nexthop)].append(
node_by_ll(r.prefix)[0] if r.prefix else default)
except KeyError:
pass
gv = ["digraph { splines = true; edge[color=grey, labelangle=0, arrowhead=dot];"]
gv = ["digraph { splines = true; edge[color=grey, labelangle=0];"]
N = len(nodes)
a = 2 * math.pi / N
edges = set()
......@@ -270,17 +271,23 @@ def route_svg(z=4):
l.append((min(j, N - j), p, r))
for j, (l, (p, t), r) in enumerate(sorted(l)):
l = []
arrowhead = 'odot'
for r in sorted(r.short for r in r):
if r == p.short:
r = '<font color="grey">%s</font>' % r
l.append(r)
if r:
if r == p.short:
r = '<font color="grey">%s</font>' % r
l.append(r)
else:
arrowhead = 'dot'
if (n.name, p.name) in edges:
r = 'penwidth=0'
else:
edges.add((p.name, n.name))
r = 'style=solid' if t else 'style=dashed'
gv.append('%s -> %s [labeldistance=%u, headlabel=<%s>, %s];'
% (p.name, n.name, 1.5 * math.sqrt(j) + 2, ','.join(l), r))
gv.append(
'%s -> %s [labeldistance=%u, headlabel=<%s>, arrowhead=%s, %s];'
% (p.name, n.name, 1.5 * math.sqrt(j) + 2, ','.join(l),
arrowhead, r))
gv.append('}\n')
return subprocess.Popen(('neato', '-Tsvg'),
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment