def generate_OTN_circuits(plan, otn_links): i = 1 for otn_link in otn_links: name = otn_link['name'] if len(otn_link['endpoints']) == 2: nodeAKey = NodeKey(otn_link['endpoints'][0]['node']) nodeAintfname = otn_link['endpoints'][0]['channel'] + name nodeBKey = NodeKey(otn_link['endpoints'][1]['node']) nodeBintfname = otn_link['endpoints'][1]['channel'] + name te_metric = 10 igp_metric = 10 affinity = "0x80" intfbw = otn_link['intfbw'] # intfbw = 100000 scale = 16 ## equals to hexadecimal num_of_bits = 32 affinitylist = list(bin(int(affinity, scale))[2:].zfill(num_of_bits)) affinities = [] c = 0 for afbit in reversed(affinitylist): if afbit == '1': affinities.append(c) c += 1 intfArec = InterfaceRecord(sourceKey=nodeAKey, name=nodeAintfname, isisLevel=2, affinityGroup=affinities, igpMetric=igp_metric, teMetric=te_metric) intfBrec = InterfaceRecord(sourceKey=nodeBKey, name=nodeBintfname, isisLevel=2, affinityGroup=affinities, igpMetric=igp_metric, teMetric=te_metric) circRec = CircuitRecord(name=name) network = plan.getNetwork() circuit = network.newConnection(ifaceARec=intfArec, ifaceBRec=intfBrec, circuitRec=circRec) if 'och-trail-fdn' in otn_link: l1CircuitManager = plan.getNetwork().getL1Network( ).getL1CircuitManager() l1circuits = l1CircuitManager.getAllL1Circuits() for attr, val in l1circuits.items(): if otn_link['och-trail-fdn'] == val.getName(): l1circuit_name = val.getName() # logging.info("L1 circuit name is " + l1circuit_name) # logging.info("Name matched!") l1circuit = l1CircuitManager.getL1Circuit(val.getKey()) circuit.setL1Circuit(l1circuit) # TODO recode setting the L3 node site based on connected L1 node site circuit.setCapacity(intfbw) i += 1
def new_private_lsp(id, src, dest, name, lspBW, frr, lspSetupPriority, lspHoldPriority): lspRec = LSPRecord(sourceKey=NodeKey(name=src), name=name, destinationKey=NodeKey(name=dest), setupPriority=int(lspSetupPriority), holdPriority=int(lspHoldPriority), isActive=True, isPrivate=True, setupBW=lspBW, FRREnabled=True, type=LSPType.RSVP) lspMgr = id.getNetwork().getLSPManager() lspMgr.newLSP(lspRec)
def new_demand_for_LSP(id, src, dest, lspName, demandName, val): serviceClass = 'Default' serviceClassMgr = id.getNetwork().getServiceClassManager() serviceClassExists = serviceClassMgr.hasServiceClass( ServiceClassKey(name=serviceClass)) if not serviceClassExists: serviceClassRecord = ServiceClassRecord(name=serviceClass) serviceClassMgr.newServiceClass(serviceClassRecord) keylist = serviceClassMgr.getAllServiceClassKeys() dmdRec = DemandRecord(name=demandName, source=DemandEndpointKey(key=src), destination=DemandEndpointKey(key=dest), serviceClass=ServiceClassKey(name='Default'), privateLSP=LSPKey(name=lspName, sourceKey=NodeKey(name=src))) dmdMgr = id.getNetwork().getDemandManager() dmdMgr.newDemand(dmdRec) dmdTraffKey = DemandTrafficKey( traffLvlKey=TrafficLevelKey(name='Default'), dmdKey=DemandKey( name=demandName, source=DemandEndpointKey(key=src), destination=DemandEndpointKey(key=dest), serviceClass=ServiceClassKey(name='Default'), )) dmdTrafficMgr = id.getTrafficManager().getDemandTrafficManager() dmdTrafficMgr.setTraffic(dmdTraffKey, val)
def generateL3circuit(plan, name, l3nodeA, l3nodeB, affinity, l3nodeA_ip, l3nodeB_ip, nodeAintfname, nodeBintfname, igp_metric, te_metric): nodeAKey = NodeKey(l3nodeA) nodeBKey = NodeKey(l3nodeB) # nodeAintfname = "L3_intf_" + name + "_to_" + l3nodeB # nodeBintfname = "L3_intf_" + name + "_to_" + l3nodeA scale = 16 ## equals to hexadecimal num_of_bits = 32 # logging.warn bin(int(affinity, scale))[2:].zfill(num_of_bits) affinitylist = list(bin(int(affinity, scale))[2:].zfill(num_of_bits)) affinities = [] c = 0 for afbit in reversed(affinitylist): if afbit == '1': affinities.append(c) c += 1 intfArec = InterfaceRecord(sourceKey=nodeAKey, name=nodeAintfname, isisLevel=2, affinityGroup=affinities, ipAddresses=l3nodeA_ip, igpMetric=igp_metric, teMetric=te_metric) intfBrec = InterfaceRecord(sourceKey=nodeBKey, name=nodeBintfname, isisLevel=2, affinityGroup=affinities, ipAddresses=l3nodeB_ip, igpMetric=igp_metric, teMetric=te_metric) circRec = CircuitRecord(name=name) network = plan.getNetwork() circuit = network.newConnection(ifaceARec=intfArec, ifaceBRec=intfBrec, circuitRec=circRec) return circuit
def generateL1circuits(plan, och_trails): l1NodeManager = plan.getNetwork().getL1Network().getL1NodeManager() nodemanager = plan.getNetwork().getNodeManager() for och_trail in och_trails: fdn = och_trail['fdn'] logging.info("Generating L1 circuit for OCH Trail " + fdn) # TODO add actual capacity of wavelength to plan (hard coded to 200G now) # wavelength = och_trail['wavelength'] * 100 if 'Ordered L1 Hops' in och_trail: if len(och_trail['Ordered L1 Hops']) > 0: term_points = och_trail['termination-points'] firstnode = term_points[0]['node'] lastnode = term_points[1]['node'] l1hops, firstl1node, lastl1node = getfirstlastl1node( och_trail['Ordered L1 Hops'], firstnode, lastnode) firstsite = l1NodeManager.getL1Node( L1NodeKey(firstl1node)).getSite() try: nodemanager.getNode(NodeKey(firstnode)).setSite(firstsite) except Exception as err: pass try: lastsite = l1NodeManager.getL1Node( L1NodeKey(lastl1node)).getSite() nodemanager.getNode(NodeKey(lastnode)).setSite(lastsite) except Exception as err: logging.warn("Could not get site for " + lastl1node) try: l1circuit = generateL1circuit(plan, fdn, firstl1node, lastl1node, l1hops, 200000) except Exception as err: logging.critical( "Could not generate L1 circuit for OCH Trail " + fdn) break else: logging.warn("OCH Trail " + fdn + " has no L1 hops!")
def main(): # Get path for collection files from command line arguments parser = argparse.ArgumentParser(description='A WAE collection tool for EPNM') parser.add_argument('archive_root', metavar='N', type=str, help='Please provide the local path to your archive directory') parser.add_argument('state_or_states', metavar='N', type=str, help="Please provide a list of states for mplstopo discovery. 'New York, Florida'") parser.add_argument('epnm_ipaddr', metavar='N', type=str, help="Please provide the EPNM Server address for API calls") parser.add_argument('epnm_user', metavar='N', type=str, help="Please provide the EPNM User name for the EPNM Server") parser.add_argument('epnm_pass', metavar='N', type=str, help="Please provide the EPNM password for the EPNM Server") parser.add_argument('phases', metavar='N', type=str, help="List of the collection phases to run(1-6), example '1356'") parser.add_argument('--build_plan', action='store_true', help="Add this flag to build the plan file.") parser.add_argument('--delete_previous', action='store_true', help="Add this flag to delete previous collection files.") args = parser.parse_args() epnmipaddr = args.epnm_ipaddr baseURL = "https://" + epnmipaddr + "/restconf" epnmuser = args.epnm_user epnmpassword = args.epnm_pass current_time = str(datetime.now().strftime('%Y-%m-%d-%H%M-%S')) archive_root = args.archive_root + "/captures/" + current_time planfiles_root = args.archive_root + "/planfiles/" phases = args.phases build_plan = args.build_plan delete_previous = args.delete_previous state_or_states_list = args.state_or_states.split(',') state_or_states_list = [state.strip(' ') for state in state_or_states_list] # # Set up logging # try: # os.remove('collection.log') # except Exception as err: # print("No log file to delete...") logFormatter = logging.Formatter('%(levelname)s: %(message)s') rootLogger = logging.getLogger() rootLogger.level = logging.INFO log_file_name = 'collection-' + current_time + '.log' fileHandler = logging.FileHandler(filename=log_file_name) fileHandler.setFormatter(logFormatter) rootLogger.addHandler(fileHandler) consoleHandler = logging.StreamHandler() consoleHandler.setFormatter(logFormatter) rootLogger.addHandler(consoleHandler) logging.info("Collection start time is " + current_time) # Delete all output files if delete_previous: logging.info("Cleaning files from last collection...") try: remove_tree('jsonfiles') remove_tree('jsongets') except Exception as err: logging.info("No files to cleanup...") # Recreate output directories mkpath('jsonfiles') mkpath('jsongets') mkpath(planfiles_root) else: logging.info("Keeping collection files from previous collection, building plan file only...") # phase_list = [] # for phase in phases: # phase_list.append(int(phase)) # # # Run the collector... # collection_calls = [{'type': 'l1nodes', 'baseURL': baseURL, 'epnmuser': epnmuser, 'epnmpassword': epnmpassword}, # {'type': 'l1links', 'baseURL': baseURL, 'epnmuser': epnmuser, 'epnmpassword': epnmpassword}, # {'type': 'allnodes', 'baseURL': baseURL, 'epnmuser': epnmuser, 'epnmpassword': epnmpassword}, # {'type': '4knodes', 'baseURL': baseURL, 'epnmuser': epnmuser, 'epnmpassword': epnmpassword}, # {'type': 'lsps', 'baseURL': baseURL, 'epnmuser': epnmuser, 'epnmpassword': epnmpassword}, # {'type': 'mpls', 'baseURL': baseURL, 'epnmuser': epnmuser, 'epnmpassword': epnmpassword, 'state_or_states': state_or_states_list}, # {'type': 'optical', 'baseURL': baseURL, 'epnmuser': epnmuser, 'epnmpassword': epnmpassword}, # ] # phases_to_run = [] # c = 1 # for call in collection_calls: # for phase_num in phase_list: # if phase_num == c: # phases_to_run.append(call) # break # c +=1 # # pool = ThreadPool(7) # pool.map(collectioncode.collect.collection_router, phases_to_run) # pool.close() # pool.join() collectioncode.collect.runcollector(baseURL, epnmuser, epnmpassword, state_or_states_list) # print "PYTHONPATH=" + os.getenv('PYTHONPATH') # print "PATH=" + os.getenv('PATH') # print "CARIDEN_HOME=" + os.getenv('CARIDEN_HOME') if build_plan: logging.info("Building plan file...") # Create a service to be used by this script conn = com.cisco.wae.design.ServiceConnectionManager.newService() cwd = os.getcwd() fileName = os.path.join(cwd, 'planfiles/blank.pln') plan = conn.getPlanManager().newPlanFromFileSystem(fileName) ####################################### # # Experimental # ####################################### # Read node coordinates file into a dict # nodecoordinates = [] # with open('waecode/node_coordinates.csv', 'rb') as f: # reader = csv.DictReader(f) # for row in reader: # nodecoordinates.append(row) # f.close() ####################################### # # Experimental # ####################################### # # Add MPLS nodes to plan # logging.info("Adding nodes to plan...") # with open("jsonfiles/mpls_nodes.json", 'rb') as f: # mpls_nodes = json.load(f) # f.close() # l3nodes = [] # for mpls_node in mpls_nodes: # tmpnode = {'Name': mpls_node} # l3nodes.append(tmpnode) # waecode.planbuild.generateL3nodes(plan, l3nodelist=l3nodes) # Check 4k_nodes_db.json for duplicate entries logging.info("Checking 4k-nodes_db.json for duplicate entries...") with open("jsonfiles/4k-nodes_db.json", 'rb') as f: four_k_nodes = json.load(f) f.close() for k, v in four_k_nodes.items(): count = 0 for k1, v1 in four_k_nodes.items(): if v['Name'] == v1['Name']: count += 1 if count > 1: logging.info("Found a dup, removing this node: " + v['Name']) four_k_nodes.pop(k) ####################################### # # Build MPLS Plan Components # ####################################### l3nodeloopbacks = [] # Add L3 nodes to plan for state in state_or_states_list: logging.info("Adding L3 nodes...") l3nodes, l3linksdict = get_l3_nodes(state) waecode.planbuild.generateL3nodes(plan, l3nodelist=l3nodes) # Add L3 links to plan and stitch to L1 links where applicable logging.info("Adding L3 links...") waecode.planbuild.generateL3circuits(plan, l3linksdict) # <--- Moved above OCH Trails # read FlexLSP add-on options with open("waecode/options.json", 'rb') as f: options = json.load(f) f.close() # Make/update list of nodenames and loopbacks for k1, v1 in l3linksdict.items(): tmpnode = {k1: v1['Loopback Address']} l3nodeloopbacks.append(tmpnode) # Set node coordinates logging.info("Setting node coordinates...") node_manager = plan.getNetwork().getNodeManager() with open("jsonfiles/all-nodes.json", 'rb') as f: nodesdict = json.load(f) f.close() for l3_node in l3nodes: tmp_name = l3_node['Name'] try: tmp_node = next( (item for item in nodesdict if item["name"] == tmp_name or item['name'].split('.')[0] == tmp_name), None) node = node_manager.getNode(NodeKey(l3_node['Name'])) node.setLatitude(tmp_node['Latitude']['fdtn.double-amount']) node.setLongitude(tmp_node['Longitude']['fdtn.double-amount']) except Exception as err: logging.warn("Unable to set node coordinates, node not in EPNM inventory: " + tmp_name) # Add LSPs to plan logging.info("Adding LSP's...") with open("jsonfiles/lsps.json", 'rb') as f: lsps = json.load(f) f.close() waecode.planbuild.generate_lsps(plan, lsps, l3nodeloopbacks, options, conn) # Create and assign nodes to Sites logging.info("Assigning nodes to sites...") waecode.planbuild.assignSites_l3nodes(plan) ####################################### # # Build Optical Plan Components # ####################################### # # Add L1 nodes to plan # logging.info("Adding L1 nodes...") # with open("jsonfiles/l1Nodes.json", 'rb') as f: # l1nodesdict = json.load(f) # f.close() # l1nodes = [] # sites = [] # site_manager = plan.getNetwork().getSiteManager() # # found = False # for k1, v1 in l1nodesdict.items(): # tmpnode = {'Name': v1['Name'], 'X': v1['Longitude']['fdtn.double-amount'], 'Y': v1['Latitude']['fdtn.double-amount']} # site_rec = SiteRecord(name=tmpnode['Name'], latitude=float(tmpnode['Y']), longitude=float(tmpnode['X'])) # try: # tmpsite = site_manager.newSite(siteRec=site_rec) # tmpnode['sitekey'] = tmpsite.getKey() # sites.append(tmpsite) # l1nodes.append(tmpnode) # logging.info("successfully added node " + tmpnode['Name']) # except Exception as err: # logging.warn('Could not process node ' + tmpnode['Name']) # logging.warn(err) # waecode.planbuild.generateL1nodes(plan, l1nodelist=l1nodes) # # # Add L1 links to plan # logging.info("Adding L1 links...") # with open("jsonfiles/l1Links.json", 'rb') as f: # l1linksdict = json.load(f) # f.close() # waecode.planbuild.generateL1links(plan, l1linksdict) # # # Add 4K nodes (pure OTN) to plan (if any are duplicated from MPLS nodes skip it) # logging.info("Adding 4k nodes to plan...") # with open("jsonfiles/4k-nodes_db.json", 'rb') as f: # four_k_nodes = json.load(f) # f.close() # added_nodes = [] # l3nodes = [] # for k, v in four_k_nodes.items(): # exists = waecode.planbuild.check_node_exists(plan,v['Name']) # if not exists: # tmpnode = {'Name': v['Name']} # added_nodes.append(tmpnode) # l3nodes.append({'Name': v['Name']}) # # waecode.planbuild.generateL3nodes(plan, l3nodelist=added_nodes) # # # Set node coordinates # logging.info("Setting node coordinates...") # node_manager = plan.getNetwork().getNodeManager() # with open("jsonfiles/all-nodes.json", 'rb') as f: # nodesdict = json.load(f) # f.close() # for l3_node in l3nodes: # tmp_name = l3_node['Name'] # tmp_node = next( # (item for item in nodesdict if item["name"] == tmp_name or item['name'].split('.')[0] == tmp_name), # None) # node = node_manager.getNode(NodeKey(l3_node['Name'])) # node.setLatitude(tmp_node['Latitude']['fdtn.double-amount']) # node.setLongitude(tmp_node['Longitude']['fdtn.double-amount']) # # # Add OCH-Trails (wavelengths) to plan # logging.info("Adding OCH Trails as L1 circuits to the plan...") # with open("jsonfiles/och_trails.json", 'rb') as f: # och_trails = json.load(f) # f.close() # waecode.planbuild.generateL1circuits(plan, och_trails=och_trails) # # Add OTN links to plan # logging.info("Adding OTN links...") # with open("jsonfiles/otn_links.json", 'rb') as f: # otn_links = json.load(f) # f.close() # waecode.planbuild.generate_OTN_circuits(plan, otn_links) # # # TODO see if assignSites is breaking something (seems to be) # waecode.planbuild.assignSites(plan) # # # # Add OTN services to the plan # logging.info("Adding ODU services to the plan...") # with open("jsonfiles/odu_services.json", 'rb') as f: # odu_services = json.load(f) # f.close() # waecode.planbuild.generate_otn_lsps(plan, odu_services, conn) # Save the plan file plan.serializeToFileSystem('planfiles/latest.pln') plan.serializeToFileSystem(planfiles_root + current_time + '.pln') logging.info("Plan file created.") # Backup current output files logging.info("Backing up files from collection...") try: copy_tree('jsonfiles', archive_root + '/jsonfiles') copy_tree('planfiles', archive_root + '/planfiles') copy_tree('jsongets', archive_root + '/jsongets') except Exception as err: logging.info("No output files to backup...") logging.info("Copying log file...") try: mkpath(archive_root) shutil.copy(log_file_name, archive_root + '/collection.log') except Exception as err: logging.info("No log file to copy...") # Script completed finish_time = str(datetime.now().strftime('%Y-%m-%d-%H%M-%S')) logging.info("Collection finish time is " + finish_time) time.sleep(2)
def createflexlsp(options, conn, plan, nodes, name, lspBW): # get all necessary Managers network = plan.getNetwork() nodeManager = network.getNodeManager() circuitManager = network.getCircuitManager() lspManager = network.getLSPManager() lspPathManager = network.getLSPPathManager() namedPathManager = network.getNamedPathManager() simulationManager = conn.getSimulationManager() toolManager = conn.getToolManager() interfaceManager = network.getInterfaceManager() nodeKeyList = [] for node in nodes: nodeKeyList.append(NodeKey(node)) rprint("Retrieved and parsed Options:") rprint("-----") rprint("") text = "LSP Endpoint A = " + nodeKeyList[0].name rprint(text) text = "LSP Endpoint B = " + nodeKeyList[1].name rprint(text) text = "LSP Name = " + name rprint(text) sticky = options['sticky'] if sticky: rprint("sticky enabled") coRouted = options['coRouted'] if sticky: rprint("co-routing enabled") nonRevertive = options['nonRevertive'] if sticky: rprint("non-revertive enabled") protection = options['protection'] text = "Protection Mode = " + protection rprint(text) rprint("") lspBandwidth = lspBW # add the LSPs rprint("1. Creating forward LSP") lsp = cs_common.createLsp(lspManager, name + "_forward", nodeKeyList[0], nodeKeyList[1], lspBandwidth, "Forward") text = "LSP called " + lsp.getName() + " with Bandwidth of " + str( lsp.getSetupBW()) + "Mbps created from Node " + lsp.getSource( ).getName() + " to Node " + lsp.getDestination().getName() rprint(text) # debug lsp2 begin # lsp2 = cs_common.createLsp(lspManager, str(99), nodeKeyList[0], nodeKeyList[1], 10, "Forward") # lsp2Path = cs_common.addPathToLsp(lsp2, lspPathManager, namedPathManager, nodeKeyList[0], 1, False, True) circuitRecords = circuitManager.getAllCircuitRecords() reverseInterfaceHopList = [] for circuitRecord in circuitRecords: if circuitRecord.interfaceAKey.sourceKey.name == "4" and circuitRecord.interfaceBKey.sourceKey.name == "1": reverseInterfaceHopList.append(circuitRecord.interfaceAKey) if circuitRecord.interfaceBKey.sourceKey.name == "4" and circuitRecord.interfaceAKey.sourceKey.name == "1": reverseInterfaceHopList.append(circuitRecord.interfaceBKey) for circuitRecord in circuitRecords: if circuitRecord.interfaceAKey.sourceKey.name == "5" and circuitRecord.interfaceBKey.sourceKey.name == "4": reverseInterfaceHopList.append(circuitRecord.interfaceAKey) if circuitRecord.interfaceBKey.sourceKey.name == "5" and circuitRecord.interfaceAKey.sourceKey.name == "4": reverseInterfaceHopList.append(circuitRecord.interfaceBKey) for circuitRecord in circuitRecords: if circuitRecord.interfaceAKey.sourceKey.name == "3" and circuitRecord.interfaceBKey.sourceKey.name == "5": reverseInterfaceHopList.append(circuitRecord.interfaceAKey) if circuitRecord.interfaceBKey.sourceKey.name == "3" and circuitRecord.interfaceAKey.sourceKey.name == "5": reverseInterfaceHopList.append(circuitRecord.interfaceBKey) reverseNamedPathHopRecordList = [] for interfaceHop in reverseInterfaceHopList: hopRecord = com.cisco.wae.design.model.net.NamedPathHopRecord() hopRecord.ifaceHop = interfaceHop hopRecord.type = com.cisco.wae.design.model.net.HopType.PathStrict reverseNamedPathHopRecordList.append(hopRecord) # cs_common.setStrictNamedPath(lsp2Path, reverseNamedPathHopRecordList) # rprint("lsp2") # rprint(reverseNamedPathHopRecordList) # debug lsp2 end rprint("") rprint("---") rprint("") rprint("2. Creating Reverse LSP") rlsp = cs_common.createLsp(lspManager, name + "_reverse", nodeKeyList[1], nodeKeyList[0], lspBandwidth, "Reverse") text = "LSP called " + rlsp.getName() + " with Bandwidth of " + str( rlsp.getSetupBW()) + "Mbps created from Node " + rlsp.getSource( ).getName() + " to Node " + rlsp.getDestination().getName() rprint(text) rprint("") rprint("---") rprint("") # add dynamic forward LSP Paths rprint("3. Adding dynamic Forward Paths") workingLspPath = cs_common.addPathToLsp(lsp, lspPathManager, namedPathManager, nodeKeyList[0], 1, False, True) protectLspPath = cs_common.addPathToLsp(lsp, lspPathManager, namedPathManager, nodeKeyList[0], 2, True, True) standbyString = cs_common.lspStandbyToString(workingLspPath.getStandby()) text = "working LSP using path-option " + str(workingLspPath.getPathOption( )) + " with named Path " + workingLspPath.getNamedPath().getName( ) + " created (" + standbyString + ")" rprint(text) standbyString = cs_common.lspStandbyToString(protectLspPath.getStandby()) text = "protect LSP using path-option " + str(protectLspPath.getPathOption( )) + " with named Path " + protectLspPath.getNamedPath().getName( ) + " created (" + standbyString + ")" rprint(text) rprint("") rprint("---") rprint("") # run simulation rprint("4. Running Simulation") failureScenarioRecord = com.cisco.wae.design.sim.FailureScenarioRecord() routeSimulation = simulationManager.newRouteSimulation( plan, failureScenarioRecord) routeOptions = com.cisco.wae.design.sim.RouteOptions() lspRouteRecords = routeSimulation.getAllLSPRouteRecords(routeOptions) lspPathRouteRecords = routeSimulation.getAllLSPPathRouteRecords( routeOptions) # retrieve and print dynamic forward Paths rprint("working forward LSP Path:") indent = " " workingRouteInterfaceList = cs_common.getRouteInterfaceList( workingLspPath, routeSimulation, routeOptions) text = cs_common.printInterfaceList(workingRouteInterfaceList, True) text = indent + text rprint(text) rprint("protect forward LSP Path:") indent = " " protectRouteInterfaceList = cs_common.getRouteInterfaceList( protectLspPath, routeSimulation, routeOptions) text = cs_common.printInterfaceList(protectRouteInterfaceList, True) text = indent + text rprint(text) # debug lsp2 # rprint("lsp2") # lsp2InterfaceList = cs_common.getRouteInterfaceList(lsp2Path, routeSimulation, routeOptions) # text = cs_common.printInterfaceList(lsp2InterfaceList, True) # text = indent + text # rprint(text) rprint("") rprint("---") rprint("") rprint("5. Disjoint Optimizer") disjointOptimizer = toolManager.newLSPDisjointPathOptimizer() disjointOptimizerOptions = com.cisco.wae.design.tools.LSPDisjointPathOptimizerOptions( ) lspList = [lsp.getKey()] disjointOptimizerOptions.lsps = lspList disjointOptimizerOptions.srlgPriority = 'ignore' # disjointOptimizerOptions.srlgPriority = '1' try: disjointOptimizerResults = disjointOptimizer.run( network, disjointOptimizerOptions) except Exception as err: logging.warn( "!!!!!!!!!Could not run disjoint optimizer for LSP!!!!!!!!!") print err rprint("") rprint("---") rprint("") rprint("6. Simulate again after adding explicit Paths to Forward LSPs") failureScenarioRecord = com.cisco.wae.design.sim.FailureScenarioRecord() routeSimulation = simulationManager.newRouteSimulation( plan, failureScenarioRecord) routeOptions = com.cisco.wae.design.sim.RouteOptions() lspRouteRecords = routeSimulation.getAllLSPRouteRecords(routeOptions) lspPathRouteRecords = routeSimulation.getAllLSPPathRouteRecords( routeOptions) # retrieve and print optimized forward Paths rprint("disjoint optimized and sticky working forward LSP Path:") indent = " " workingRouteInterfaceList = cs_common.getRouteInterfaceList( workingLspPath, routeSimulation, routeOptions) text = cs_common.printInterfaceList(workingRouteInterfaceList, True) text = indent + text rprint(text) rprint("disjoint optimized and sticky protect forward LSP Path:") indent = " " protectRouteInterfaceList = cs_common.getRouteInterfaceList( protectLspPath, routeSimulation, routeOptions) text = cs_common.printInterfaceList(protectRouteInterfaceList, True) text = indent + text rprint(text) rprint("") rprint("---") rprint("") # adding sticky, co-routed reverse paths rprint("7. Calculating and adding co-routed & sticky reverse Paths") # add paths to reverse LSP rWorkingLspPath = cs_common.addPathToLsp(rlsp, lspPathManager, namedPathManager, nodeKeyList[1], 1, False, True) rProtectLspPath = cs_common.addPathToLsp(rlsp, lspPathManager, namedPathManager, nodeKeyList[1], 2, True, True) # calculate reverse paths to be used workingReverseNamedPathHopRecordList = cs_common.calculateReverseNamedPathHopRecordList( workingLspPath, circuitManager) protectReverseNamedPathHopRecordList = cs_common.calculateReverseNamedPathHopRecordList( protectLspPath, circuitManager) # set explicit hops cs_common.setStrictNamedPath(rWorkingLspPath, workingReverseNamedPathHopRecordList) cs_common.setStrictNamedPath(rProtectLspPath, protectReverseNamedPathHopRecordList) # recompute simulation # routeSimulation.recompute() failureScenarioRecord = com.cisco.wae.design.sim.FailureScenarioRecord() routeSimulation = simulationManager.newRouteSimulation( plan, failureScenarioRecord) routeOptions = com.cisco.wae.design.sim.RouteOptions() lspRouteRecords = routeSimulation.getAllLSPRouteRecords(routeOptions) lspPathRouteRecords = routeSimulation.getAllLSPPathRouteRecords( routeOptions) # rertrieve and print paths rprint("co-routing and sticky working reverse LSP Path:") indent = " " rWorkingRouteInterfaceList = cs_common.getRouteInterfaceList( rWorkingLspPath, routeSimulation, routeOptions) text = cs_common.printInterfaceList(rWorkingRouteInterfaceList, True) text = indent + text rprint(text) rprint("co-routing and sticky protect reverse LSP Path:") indent = " " rProtectRouteInterfaceList = cs_common.getRouteInterfaceList( rProtectLspPath, routeSimulation, routeOptions) # rprint("route interface list") # rprint(rProtectRouteInterfaceList) text = cs_common.printInterfaceList(rProtectRouteInterfaceList, True) text = indent + text rprint(text) rprint("") rprint("hops") rprint(rProtectLspPath.getNamedPath().getHops()) rprint("") # rprint("ifusage") # rprint(routeSimulation.getLSPPathRouteRecord(rProtectLspPath, routeOptions).interfaceUsage) rprint("") rprint("---") rprint("") return
def create_otn_lsp(conn, plan, nodeA, nodeB, name, lspBW, otn_link_hops): # get all necessary Managers network = plan.getNetwork() circuitManager = network.getCircuitManager() lspManager = network.getLSPManager() lspPathManager = network.getLSPPathManager() namedPathManager = network.getNamedPathManager() simulationManager = conn.getSimulationManager() lspBandwidth = lspBW nodeAkey = NodeKey(nodeA) nodeBkey = NodeKey(nodeB) # add the LSPs rprint("Creating forward LSP") lsp = cs_common.createLsp(lspManager, name + "_forward", nodeAkey, nodeBkey, lspBandwidth, "Forward") text = "LSP called " + lsp.getName() + " with Bandwidth of " + str( lsp.getSetupBW()) + "Mbps created from Node " + lsp.getSource( ).getName() + " to Node " + lsp.getDestination().getName() rprint(text) rprint("Creating Reverse LSP") rlsp = cs_common.createLsp(lspManager, name + "_reverse", nodeBkey, nodeAkey, lspBandwidth, "Reverse") text = "LSP called " + rlsp.getName() + " with Bandwidth of " + str( rlsp.getSetupBW()) + "Mbps created from Node " + rlsp.getSource( ).getName() + " to Node " + rlsp.getDestination().getName() rprint(text) workingLspPath = cs_common.addPathToLsp(lsp, lspPathManager, namedPathManager, nodeAkey, 1, False, True, "0x80", "0x80") rWorkingLspPath = cs_common.addPathToLsp(rlsp, lspPathManager, namedPathManager, nodeBkey, 1, False, True, "0x80", "0x80") forward_lsp_path = lsp.getOrderedLSPPaths()[0] namedPathHopRecordList = cs_common.buildNamedPathHopRecordList( forward_lsp_path, circuitManager, otn_link_hops) if namedPathHopRecordList != None: forward_lsp_path.getNamedPath().addHops(namedPathHopRecordList) else: logging.warn("Failed to route forward OTN LSP " + name + " according to circuit list! Will route dynamically.") reverse_lsp_path = rlsp.getOrderedLSPPaths()[0] namedPathHopRecordList = cs_common.buildNamedPathHopRecordList( reverse_lsp_path, circuitManager, otn_link_hops) if namedPathHopRecordList != None: reverse_lsp_path.getNamedPath().addHops(namedPathHopRecordList) else: logging.warn("Failed to route reverse OTN LSP " + name + " according to circuit list! Will route dynamically.") # run simulation rprint("4. Running Simulation") failureScenarioRecord = com.cisco.wae.design.sim.FailureScenarioRecord() routeSimulation = simulationManager.newRouteSimulation( plan, failureScenarioRecord) routeOptions = com.cisco.wae.design.sim.RouteOptions() lspRouteRecords = routeSimulation.getAllLSPRouteRecords(routeOptions) lspPathRouteRecords = routeSimulation.getAllLSPPathRouteRecords( routeOptions) # retrieve and print dynamic forward Paths rprint("working forward LSP Path:") indent = " " workingRouteInterfaceList = cs_common.getRouteInterfaceList( workingLspPath, routeSimulation, routeOptions) text = cs_common.printInterfaceList(workingRouteInterfaceList, True) text = indent + text rprint(text) rprint("protect forward LSP Path:") indent = " " protectRouteInterfaceList = cs_common.getRouteInterfaceList( rWorkingLspPath, routeSimulation, routeOptions) text = cs_common.printInterfaceList(protectRouteInterfaceList, True) text = indent + text rprint(text) return