def __init__(self, fileName = None, controller = None): docontroller = False self.controller = None if docontroller: if not controller: self.controller = ODLClient(topology=self) else: self.controller = controller # Build topology self.builder = TopoBuilder(fileName = fileName, controller = self.controller) self.buildNodes() if docontroller and not controller: # now that self.builder is ready self.controller.init()
class TestbedTopology (GenericTopologyProvider): def displayDot(self): sys.stdout.write('.') sys.stdout.flush() def buildSwitch(self, switch): enosSwitch = TestbedNode(switch.name, props=dict(switch.props, controller=self.controller)) self.addNode(enosSwitch) switch.props['enosNode'] = enosSwitch def buildHost(self,host): enosHost = TestbedHost(host.name,props=host.props) self.addNode(enosHost) host.props['enosNode'] = enosHost def buildLink(self,link): p1 = link.props['endpoints'][0] p2 = link.props['endpoints'][1] n1 = p1.props['node'] n2 = p2.props['node'] node1 = n1.props['enosNode'] node2 = n2.props['enosNode'] port1 = TestbedPort(port=p1) port1.props['enosNode'] = node1 port1.setNode(node1) p1.props['enosPort'] = port1 port2 = TestbedPort(port=p2) port2.props['enosNode'] = node2 port2.setNode(node2) p2.props['enosPort'] = port2 self.addPort (node1,port1) self.addPort (node2,port2) p1.props['switch'] = node1 p2.props['switch'] = node2 l = TestbedLink(node1,port1,node2,port2,props=link.props) link.props['enosLink'] = l self.addLink(l) # Links are assumed to be uni-directional. Create reverse link r = TestbedLink(node1=node2,port1=port2,node2=node1,port2=port1) self.addLink(r) def buildNodes(self): for switch in self.builder.switchIndex.values(): self.buildSwitch(switch) for host in self.builder.hostIndex.values(): self.buildHost(host) for link in self.builder.linkIndex.values(): self.buildLink(link) def toGraph(self): graph = self.getGraph(TopologyProvider.WeightType.TrafficEngineering) # Add a non null arbitrary weight for e in graph.edgeSet(): graph.setEdgeWeight(e, 1) def __init__(self, fileName = None, controller = None): docontroller = False self.controller = None if docontroller: if not controller: self.controller = ODLClient(topology=self) else: self.controller = controller # Build topology self.builder = TopoBuilder(fileName = fileName, controller = self.controller) self.buildNodes() if docontroller and not controller: # now that self.builder is ready self.controller.init()