Files
infix/test/infamy/env.py
T
Tobias WaldekranzandJoachim Wiberg 753f3806a1 test: Improve efficiency of logical to physical topology matching
- Present the topologies to networkx as multigraphs, rather than
  expaning each port of the record shape as a separate node.

- Create a topology mapping by locating a subgraph monomorphism of the
  logical topology in the physical ditto.

This cuts down the time of finding a mapping by several orders of
magnitude. Example:

Before:

time python3 test/infamy/topology.py \
     	     test/virt/quad/topology.dot.in \
	     test/infamy/topologies/ring-4-duts.dot >/dev/null

real    13m1,213s
user    13m0,112s
sys     0m0,732s

After:

time python3 test/infamy/topology.py \
     	     test/virt/quad/topology.dot.in \
	     test/infamy/topologies/ring-4-duts.dot >/dev/null

real    0m0,153s
user    0m0,128s
sys     0m0,024s
2024-05-03 14:44:54 +02:00

63 lines
2.0 KiB
Python

import argparse
import networkx
import os
import pydot
import shlex
import sys
from . import neigh, netconf, tap, topology
class ArgumentParser(argparse.ArgumentParser):
def __init__(self, ltop):
super().__init__()
self.add_argument("-d", "--debug", default=False, action="store_true")
self.add_argument("-l", "--logical-topology", dest="ltop", default=ltop)
self.add_argument("-p", "--package", default=None)
self.add_argument("-y", "--yangdir", default=None)
self.add_argument("ptop", nargs=1, metavar="topology")
class Env(object):
def __init__(self, ltop=None, argv=sys.argv[1::], environ=os.environ):
if "INFAMY_ARGS" in environ:
argv = shlex.split(environ["INFAMY_ARGS"]) + argv
self.args = ArgumentParser(ltop).parse_args(argv)
pdot = pydot.graph_from_dot_file(self.args.ptop[0])[0]
self.ptop = topology.Topology(pdot)
self.ltop = None
if self.args.ltop:
ldot = pydot.graph_from_dot_file(self.args.ltop)[0]
self.ltop = topology.Topology(ldot)
if not self.ltop.map_to(self.ptop):
raise tap.TestSkip()
def attach(self, node, port, factory_default=True):
if self.ltop:
mapping = self.ltop.mapping[node]
node, port = self.ltop.xlate(node, port)
else:
mapping = None
password=self.ptop.get_password(node)
if not password:
password = "admin"
ctrl = self.ptop.get_ctrl()
cport, _ = self.ptop.get_mgmt_link(ctrl, node)
print(f"Probing {node} on port {cport} for IPv6LL mgmt address ...")
mgmtip = neigh.ll6ping(cport)
if not mgmtip:
raise Exception(f"Failed, cannot find mgmt IP for {node}")
return netconf.Device(
location=netconf.Location(cport, mgmtip, password),
mapping=mapping,
yangdir=self.args.yangdir,
factory_default=factory_default
)