Correct AS path prepend count in bgpmap.

Without this patch, show_bgpmap() method does duplicate counts of aspath prepends, and returns a larger prepend count than it actually is.
This commit is contained in:
tamihiro 2019-06-09 21:41:35 +09:00
parent 85963901f8
commit 648197da24
1 changed files with 9 additions and 2 deletions

11
lg.py
View File

@ -477,7 +477,13 @@ def show_bgpmap():
hop_label = ""
for _as in asmap:
if _as == previous_as:
prepend_as[_as] = prepend_as.get(_as, 1) + 1
if not prepend_as.get(_as, None):
prepend_as[_as] = {}
if not prepend_as[_as].get(host, None):
prepend_as[_as][host] = {}
if not prepend_as[_as][host].get(asmap[0], None):
prepend_as[_as][host][asmap[0]] = 1
prepend_as[_as][host][asmap[0]] += 1
continue
if not hop:
@ -514,7 +520,8 @@ def show_bgpmap():
node.set_shape("box")
for _as in prepend_as:
graph.add_edge(pydot.Edge(*(_as, _as), label=" %dx" % prepend_as[_as], color="grey", fontcolor="grey"))
for n in set([ n for h, d in prepend_as[_as].iteritems() for p, n in d.iteritems() ]):
graph.add_edge(pydot.Edge(*(_as, _as), label=" %dx" % n, color="grey", fontcolor="grey"))
fmt = request.args.get('fmt', 'png')
#response = Response("<pre>" + graph.create_dot() + "</pre>")