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): ...@@ -247,17 +247,18 @@ def node_by_ll(addr):
_ll[a] = n, t _ll[a] = n, t
return _ll[addr] return _ll[addr]
def route_svg(z=4): def route_svg(z = 4, default = type('', (), {'short': None})):
graph = {} graph = {}
for n in nodes: for n in nodes:
g = graph[n] = defaultdict(list) g = graph[n] = defaultdict(list)
for r in n.get_routes(): 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: 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: except KeyError:
pass pass
gv = ["digraph { splines = true; edge[color=grey, labelangle=0, arrowhead=dot];"] gv = ["digraph { splines = true; edge[color=grey, labelangle=0];"]
N = len(nodes) N = len(nodes)
a = 2 * math.pi / N a = 2 * math.pi / N
edges = set() edges = set()
...@@ -270,17 +271,23 @@ def route_svg(z=4): ...@@ -270,17 +271,23 @@ def route_svg(z=4):
l.append((min(j, N - j), p, r)) l.append((min(j, N - j), p, r))
for j, (l, (p, t), r) in enumerate(sorted(l)): for j, (l, (p, t), r) in enumerate(sorted(l)):
l = [] l = []
arrowhead = 'odot'
for r in sorted(r.short for r in r): for r in sorted(r.short for r in r):
if r == p.short: if r:
r = '<font color="grey">%s</font>' % r if r == p.short:
l.append(r) r = '<font color="grey">%s</font>' % r
l.append(r)
else:
arrowhead = 'dot'
if (n.name, p.name) in edges: if (n.name, p.name) in edges:
r = 'penwidth=0' r = 'penwidth=0'
else: else:
edges.add((p.name, n.name)) edges.add((p.name, n.name))
r = 'style=solid' if t else 'style=dashed' r = 'style=solid' if t else 'style=dashed'
gv.append('%s -> %s [labeldistance=%u, headlabel=<%s>, %s];' gv.append(
% (p.name, n.name, 1.5 * math.sqrt(j) + 2, ','.join(l), r)) '%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') gv.append('}\n')
return subprocess.Popen(('neato', '-Tsvg'), return subprocess.Popen(('neato', '-Tsvg'),
stdin=subprocess.PIPE, stdout=subprocess.PIPE, 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