Commit a10f9e1d authored by Tom Niget's avatar Tom Niget

demo: fix graph generation for empty prefixes

parent 3a2f806a
......@@ -94,6 +94,7 @@ class Re6stNode(nemu.Node):
def __init__(self, name, short):
super().__init__()
print("Re6stNode ctor %r %r" % (name, short))
self.name = name
self.short = short
self.Popen(('sysctl', '-q',
......@@ -428,13 +429,12 @@ def route_svg(ipv4, z=4, default=type('', (), {'short': None})):
graph: dict[Re6stNode, dict[tuple[Re6stNode, bool], list[Re6stNode]]] = {}
for n in nodes:
g = graph[n] = defaultdict(list)
g: dict[tuple[Re6stNode, bool], list[Re6stNode]]
for r in n.get_routes():
if (r.prefix and r.prefix.startswith('10.42.') if ipv4 else
r.prefix is None or r.prefix.startswith('2001:db8:')):
for route in n.get_routes():
if (route.prefix and route.prefix.startswith('10.42.') if ipv4 else
route.prefix is None or route.prefix.startswith('2001:db8:')):
try:
g[node_by_ll(r.nexthop)].append(
node_by_ll(r.prefix)[0] if r.prefix else default)
if route.prefix:
g[node_by_ll(route.nexthop)].append(node_by_ll(route.prefix)[0])
except KeyError:
pass
gv = ["digraph { splines = true; edge[color=grey, labelangle=0];"]
......@@ -442,20 +442,16 @@ def route_svg(ipv4, z=4, default=type('', (), {'short': None})):
a = 2 * math.pi / N
edges = set()
for i, n in enumerate(nodes):
i: int
gv.append('%s[pos="%s,%s!"];'
% (n.name, z * math.cos(a * i), z * math.sin(a * i)))
l = []
for p, r in graph[n].items():
p: tuple[Re6stNode, bool]
r: list[Re6stNode]
j: int = abs(nodes.index(p[0]) - i)
j = abs(nodes.index(p[0]) - i)
l.append((min(j, N - j), p, r))
for j, (_, (p2, t), r) in enumerate(sorted(l, key=lambda x: x[0])):
p2: Re6stNode
l2: list[str] = []
l2 = []
arrowhead = 'none'
for r2 in sorted(r2.short for r2 in r):
for r2 in sorted(r2.short or '' for r2 in r):
if r2:
if r2 == p2.short:
r2 = '<font color="grey">%s</font>' % r2
......
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