|
|
@ -1,9 +1,10 @@
|
|
|
|
from . import Annotator, Annotation
|
|
|
|
from . import Annotator, Annotation, AnnotatorID
|
|
|
|
import .analysis as analysis
|
|
|
|
import birdvisu.annotations.analysis as analysis
|
|
|
|
from ..topo_v3 import VertexID, VertexType
|
|
|
|
from ..topo_v3 import VertexID, VertexType
|
|
|
|
from ..ospffile import load
|
|
|
|
from ..ospffile import load
|
|
|
|
|
|
|
|
|
|
|
|
from collections.abc import Sequence
|
|
|
|
from collections.abc import Sequence
|
|
|
|
|
|
|
|
from collections import defaultdict
|
|
|
|
from ipaddress import ip_network, IPv4Network
|
|
|
|
from ipaddress import ip_network, IPv4Network
|
|
|
|
from socket import AF_INET, AF_INET6
|
|
|
|
from socket import AF_INET, AF_INET6
|
|
|
|
|
|
|
|
|
|
|
@ -233,15 +234,15 @@ class EdgeWidthByCost(StyleAnnotator):
|
|
|
|
# The param is a function mapping the costs to widths.
|
|
|
|
# The param is a function mapping the costs to widths.
|
|
|
|
# This _is_ hashable, but also it _is_ ugly. But convenient :-)
|
|
|
|
# This _is_ hashable, but also it _is_ ugly. But convenient :-)
|
|
|
|
self.width_for_cost = param if param is not None else _default_width_for_cost
|
|
|
|
self.width_for_cost = param if param is not None else _default_width_for_cost
|
|
|
|
def annotate(topo):
|
|
|
|
def annotate(self, topo):
|
|
|
|
result = Annotation()
|
|
|
|
result = Annotation()
|
|
|
|
result.for_edge = {e: self.width_for_cost(e.cost) for e in topo.topology.edges}
|
|
|
|
result.for_edge = {e: {'width': self.width_for_cost(e.cost)} for e in topo.topology.edges}
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
class HighlightTopoDiff(StyleAnnotator):
|
|
|
|
class HighlightTopoDiff(StyleAnnotator):
|
|
|
|
idempotent = True
|
|
|
|
idempotent = True
|
|
|
|
def __init__(self, _param): pass
|
|
|
|
def __init__(self, _param): pass
|
|
|
|
def annotate(topo):
|
|
|
|
def annotate(self, topo):
|
|
|
|
topodiff = AnnotatorID(annotator=analysis.TopologyDifference)
|
|
|
|
topodiff = AnnotatorID(annotator=analysis.TopologyDifference)
|
|
|
|
topo.run_annotator(topodiff) # make sure
|
|
|
|
topo.run_annotator(topodiff) # make sure
|
|
|
|
td_result = topo.annotations[topodiff]
|
|
|
|
td_result = topo.annotations[topodiff]
|
|
|
@ -265,7 +266,7 @@ class HighlightCurrent(StyleAnnotator):
|
|
|
|
idempotent = False
|
|
|
|
idempotent = False
|
|
|
|
def __init__(self, what):
|
|
|
|
def __init__(self, what):
|
|
|
|
self.what = what
|
|
|
|
self.what = what
|
|
|
|
def annotate(topo):
|
|
|
|
def annotate(self, topo):
|
|
|
|
result = Annotation()
|
|
|
|
result = Annotation()
|
|
|
|
if self.what is None:
|
|
|
|
if self.what is None:
|
|
|
|
# Not going to guess.
|
|
|
|
# Not going to guess.
|
|
|
@ -275,7 +276,7 @@ class HighlightCurrent(StyleAnnotator):
|
|
|
|
topo.run_annotator(self.what)
|
|
|
|
topo.run_annotator(self.what)
|
|
|
|
current = topo.annotations[self.what]
|
|
|
|
current = topo.annotations[self.what]
|
|
|
|
if False: 'alignment'
|
|
|
|
if False: 'alignment'
|
|
|
|
elif self.what.annotator = analysis.ShortestPathTree:
|
|
|
|
elif self.what.annotator == analysis.ShortestPathTree:
|
|
|
|
# Highlight edges
|
|
|
|
# Highlight edges
|
|
|
|
result.for_edge = {e: {'highlight_colour': (200, 200, 0, 128)} for e in current.for_edge.keys()}
|
|
|
|
result.for_edge = {e: {'highlight_colour': (200, 200, 0, 128)} for e in current.for_edge.keys()}
|
|
|
|
return result
|
|
|
|
return result
|
|
|
@ -313,7 +314,7 @@ class MegaStyler(StyleAnnotator):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
self.detect = True
|
|
|
|
self.detect = True
|
|
|
|
|
|
|
|
|
|
|
|
def annotate(topo):
|
|
|
|
def annotate(self, topo):
|
|
|
|
# First, set some base styles
|
|
|
|
# First, set some base styles
|
|
|
|
edge_style = defaultdict(lambda: {
|
|
|
|
edge_style = defaultdict(lambda: {
|
|
|
|
'width': 1,
|
|
|
|
'width': 1,
|
|
|
@ -326,7 +327,7 @@ class MegaStyler(StyleAnnotator):
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
# Walk the annotators and collect the annotations
|
|
|
|
# Walk the annotators and collect the annotations
|
|
|
|
if not detect:
|
|
|
|
if not self.detect:
|
|
|
|
relevant_annotators = self.relevant_annotators
|
|
|
|
relevant_annotators = self.relevant_annotators
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
# We will be iterating over this often, so this time it is not a set.
|
|
|
|
# We will be iterating over this often, so this time it is not a set.
|
|
|
|