def setUp(self): """ Initialize Top data store """ self._nwtopdata_store = NwtopDataStore(logger) self.test_nwtop = RwTl.YangData_IetfNetwork() self.l2top = MyL2Topology(self.test_nwtop, logger) self.l2top.setup_all() # Get initial test data self.l2net1 = self.l2top.find_nw("L2HostNetwork-1") # Create initial nw self._nwtopdata_store.create_network("L2HostNetwork-1", self.l2net1) # Get test data self.l2net1 = self.l2top.find_nw("L2HostNetwork-1") assert self.l2net1 is not None self.new_l2net = RwTl.YangData_IetfNetwork_Network() self.new_l2net.network_id = "L2HostNetwork-1" self.src_node = self.new_l2net.node.add() self.src_node.node_id = "TempNode1" self.tp1 = self.src_node.termination_point.add() self.tp1.tp_id = "TempTp1" self.dest_node = self.new_l2net.node.add() self.dest_node.node_id = "TempNode2" self.tp2 = self.dest_node.termination_point.add() self.tp2.tp_id = "TempTp2" logger.info("SdnTopStoreTest: setUp NetworkLinkTest")
def configure_l2_network(self, dts): nwtop = RwTl.YangData_IetfNetwork() l2top = MyL2Topology(nwtop, self.log) l2top.setup_all() nw_xpath = "C,/nd:network" self.log.info("Configuring l2 network: %s", nwtop) yield from dts.query_create(nw_xpath, rwdts.XactFlag.ADVISE, nwtop)
def setUp(self): """ Initialize Top data store """ self._nwtopdata_store = NwtopDataStore(logger) self.test_nwtop = RwTl.YangData_IetfNetwork() self.l2top = MyL2Topology(self.test_nwtop, logger) self.l2top.setup_all() # Get initial test data self.l2net1 = self.l2top.find_nw("L2HostNetwork-1") # Create initial nw self._nwtopdata_store.create_network("L2HostNetwork-1", self.l2net1) # Add test data self.l2net1 = self.l2top.find_nw("L2HostNetwork-1") assert self.l2net1 is not None self.new_l2net = RwTl.YangData_IetfNetwork_Network() self.new_l2net.network_id = "L2HostNetwork-2" logger.info("SdnTopStoreNetworkTest: setUp")
def test_change_network_link_dest_tp(self): """ Test: Change L2 link attributes """ logger.info("SdnTopStoreTest: Change network link dest-tp") # Create initial state self.link1 = self.new_l2net.link.add() self.link1.link_id = "Link1" self.link1.source.source_node = self.src_node.node_id self.link1.source.source_tp = self.tp1.tp_id self.link1.destination.dest_node = self.dest_node.node_id self.link1.destination.dest_tp = self.tp2.tp_id self.link1.l2_link_attributes.name = "Link L2 name" self.link1.l2_link_attributes.rate = 10000 self._nwtopdata_store.update_network("L2HostNetwork-1", self.new_l2net) # Verify initial state nw = self._nwtopdata_store.get_network("L2HostNetwork-1") self.assertIsNotNone(nw) self.assertEqual(nw.network_id, "L2HostNetwork-1") self.assertEqual(len(self._nwtopdata_store._networks), 1) self.assertEqual(len(nw.node), NUM_NODES_L2_NW + 2) self.assertEqual(nw.node[NUM_NODES_L2_NW].node_id, "TempNode1") self.assertEqual(len(nw.node[NUM_NODES_L2_NW].termination_point), 1) self.assertEqual(nw.node[NUM_NODES_L2_NW].termination_point[0].tp_id, "TempTp1") self.assertEqual(nw.node[NUM_NODES_L2_NW + 1].node_id, "TempNode2") self.assertEqual( nw.node[NUM_NODES_L2_NW + 1].termination_point[0].tp_id, "TempTp2") self.assertEqual(nw.link[NUM_LINKS].link_id, "Link1") self.assertEqual(len(nw.link), NUM_LINKS + 1) self.assertEqual(nw.link[NUM_LINKS].l2_link_attributes.name, "Link L2 name") self.assertEqual(nw.link[NUM_LINKS].l2_link_attributes.rate, 10000) # Create test state self.test_l2net = RwTl.YangData_IetfNetwork_Network() self.test_l2net.network_id = "L2HostNetwork-1" self.link1 = self.test_l2net.link.add() self.link1.link_id = "Link1" # Changing dest node params self.link1.destination.dest_node = self.src_node.node_id self.link1.destination.dest_tp = self.tp1.tp_id self._nwtopdata_store.update_network("L2HostNetwork-1", self.test_l2net) # Verify test state nw = self._nwtopdata_store.get_network("L2HostNetwork-1") self.assertEqual(nw.network_id, "L2HostNetwork-1") self.assertEqual(nw.link[NUM_LINKS].destination.dest_node, self.src_node.node_id)
def configure_sfc_network(self, dts): nwtop = RwTl.YangData_IetfNetwork() l2top = MyL2Topology(nwtop, self.log) l2top.setup_all() provtop = MyProvTopology(nwtop, l2top, self.log) provtop.setup_all() vmtop = MyVMTopology(nwtop, l2top, provtop, self.log) vmtop.setup_all() sfctop = MySfcTopology(nwtop, l2top, provtop, vmtop, self.log) sfctop.setup_all() nw_xpath = "C,/nd:network" self.log.info("Configuring SFC network: %s", nwtop) yield from dts.query_create(nw_xpath, rwdts.XactFlag.ADVISE, nwtop)
def get_network_list(self, account): """ Returns the discovered network @param account - a SDN account """ nwtop = RwTl.YangData_IetfNetwork() #topology_source = "/net/boson/home1/rchamart/work/topology/l2_top.xml" if not account.sdnsim.has_field( 'topology_source') or account.sdnsim.topology_source is None: return nwtop topology_source = account.sdnsim.topology_source logger.info("Reading topology file: %s", topology_source) if 'json' in topology_source: with open(topology_source, 'r') as f: print("Reading static topology file") op_json = f.read() nwtop.from_json(self._model, op_json) for nw in nwtop.network: nw.server_provided = False logger.debug("...Network id %s", nw.network_id) #nw_xpath = ("D,/nd:network[network-id={}]").format(quoted_key(nw.network_id)) #xact_info.respond_xpath(rwdts.XactRspCode.MORE, # nw_xpath, nw) elif 'xml' in topology_source: tree = etree.parse(topology_source) root = tree.getroot() xmlstr = etree.tostring(root, encoding="unicode") # The top level topology object does not have XML conversion # Hence going one level down #l2nw1 = nwtop.network.add() #l2nw1.from_xml_v2(self._model, xmlstr) nwtop.from_xml_v2(self._model, xmlstr) logger.debug("Returning topology data imported from XML file") return nwtop
def create_default_topology(self): logger.debug('Creating default topology: ') self.topology = RwTl.YangData_IetfNetwork() self.nw = self.topology.network.add() self.nw.network_id = "L2HostTopology-Def1" self.nw.server_provided = 'true' # L2 Network type augmentation self.nw.network_types.l2_network = self.nw.network_types.l2_network.new( ) # L2 Network augmentation self.nw.l2_network_attributes.name = "Rift LAB SFC-Demo Host Network" for cfg_node in NW_NODES: self.create_node(cfg_node) for cfg_link in NW_BIDIR_LINKS: self.create_link(cfg_link['src'][0], cfg_link['src'][1], cfg_link['dest'][0], cfg_link['dest'][1]) self.create_link(cfg_link['src'][1], cfg_link['src'][0], cfg_link['dest'][1], cfg_link['dest'][0]) return self.topology
def get_network_list(self, account): """ Returns the discovered network @param account - a SDN account """ topology_source = "/net/boson/home1/rchamart/work/topology/l2_top.xml" logger.info("Reading topology file: %s", topology_source) tree = etree.parse(topology_source) root = tree.getroot() xmlstr = etree.tostring(root, encoding="unicode") model = RwYang.Model.create_libncx() model.load_schema_ypbc(RwTl.get_schema()) nwtop = RwTl.YangData_IetfNetwork() # The top level topology object does not have XML conversion # Hence going one level down l2nw1 = nwtop.network.add() l2nw1.from_xml_v2(model, xmlstr) logger.debug("Returning topology data imported from XML file") return nwtop
for lbuf in buffer: outf.write(lbuf) buffer = [] # empty buffer print("\n\n") continue if in_block: print("Gathering line...", line) buffer.append(line) # gather lines else: outf.write(line) if __name__ == "__main__": model = RwYang.Model.create_libyang() model.load_schema_ypbc(RwTl.get_schema()) # create logger logger = logging.getLogger('Provider Network Topology') logger.setLevel(logging.DEBUG) logging.basicConfig(level=logging.DEBUG) logger.info('Creating an instance of Provider Network Topology') nwtop = RwTl.YangData_IetfNetwork() # Setup L2 topology l2top = MyL2Topology(nwtop, logger) l2top.setup_all() # Setup Provider network topology provtop = MyProvTopology(nwtop, l2top, logger)
def __init__(self): super(SdnSim, self).__init__() self._model = RwYang.Model.create_libncx() self._model.load_schema_ypbc(RwTl.get_schema())
def configure_schema(cls): return RwTl.get_schema()
# Add links to sfcnet1 network # These links are unidirectional and point-to-point logging.debug("Setting up links") # Bidir Links for OVS bridges self.create_link(self.sfc1, self.sfc1_vxlannsh1, self.sff1, self.sff1_vxlannsh1, "Link_sfc1_sff1") self.create_link(self.sfc1, self.sfc1_vxlannsh1, self.sf1, self.sf1_vxlannsh1, "Link_sff1_sf1", "Link_sf1_sff1") def setup_all(self): self.setup_nodes() self.setup_tps() #self.setup_links() if __name__ == "__main__": model = RwYang.Model.create_libncx() model.load_schema_ypbc(RwTl.get_schema()) # create logger logger = logging.getLogger('SFC Network Topology') logger.setLevel(logging.DEBUG) logging.basicConfig(level=logging.DEBUG) logger.info('Creating an instance of SFC Network Topology') nwtop = RwTl.YangData_IetfNetwork() # Setup L2 topology l2top = MyL2Topology(nwtop, logger) l2top.setup_all() # Setup Provider network topology provtop = MyProvTopology(nwtop, l2top, logger)