def repp(graph): """ repp() method takes networkx object as input and enables and configures rep on all ports for all nodes in networkx object. """ Userlogger.info("enabling rep in network") Userlogger.info("\nEnabling rep on Selected logical topology") graph_nodes_list=graph.nodes() node_num=1 i=0 while i< len(graph_nodes_list): try: node_data=graph_nodes_list[i].split('\n') if node_num==1: Userlogger.info('Enabling rep on '+str(node_data[0])+ ' edge') run.Switch_commands.commandExecute(node_data[1],node_data[2],'config','rep segment 1','enable',graph.node[graph_nodes_list[i]]['node_port'],'edge') else: Userlogger.info('Enabling rep on '+str(node_data[0])) run.Switch_commands.commandExecute(node_data[1],node_data[2],'config','rep segment 1','enable',graph.node[graph_nodes_list[i]]['node_port'],' ') node_num+=1 i = i+1 #bar update bar.update(.4*barlen+( (.6*barlen*i)/len(graph_nodes_list) )) except: pass #end the bar bar.finish()
def rror(topology, opt_rings): rep.Rep_configuration.disable_switch(topology) #for ring in opt_rings: rep.Rep_configuration.repp(opt_rings[0]) print "wait for 10 seconds for rep to configure" bar.start() for i in range(0,10): bar.update((i+1)*10) time.sleep(1) bar.finish()
def restore(graph): """ restore() method takes networkx object as input and enables all ports and disables rep on all ports for all nodes in networkx object. """ bar.start() Userlogger.info("restoring the previous network topology") Userlogger.info('\nRestoring prevoius Physical topology and diabling rep') graph_nodes_list=graph.nodes() i=0 while i< len(graph_nodes_list): try: node_data=graph_nodes_list[i].split('\n') run.Switch_commands.commandExecute(node_data[1],node_data[2],'config','no rep segment 1','restore',graph.node[graph_nodes_list[i]]['node_port']) i+=1 #bar update bar.update( (barlen*i)/len(graph_nodes_list) ) except: pass #end the bar bar.finish()
def disable_switch(graph): """ disable_switch() method takes networkx object as input and disables all ports for all nodes in networkx object. """ #start the progressbar bar.start() Userlogger.info("disable all the ports in network") Userlogger.info('\nDisabling all ports of Physical topology') graph_nodes_list=graph.nodes() i=0 while i< len(graph_nodes_list): try: node_data=graph_nodes_list[i].split('\n') Userlogger.info('\nDisabling all ports of '+str(node_data[0])) run.Switch_commands.commandExecute(node_data[1],node_data[2],'config','shutdown','disable',graph.node[graph_nodes_list[i]]['node_port']) i=i+1 #bar update bar.update((.4*barlen*i)/len(graph_nodes_list)) except: pass
#start the progressbar bar.start() Userlogger.info('\n\n\t'+' ' + str(datetime.datetime.now()) ) # get topology fout=open('4.txt','r') lines=fout.readlines() i=0 while i<len(lines): try: line=lines[i] Switch = mt.Network_topology(line.split()[0],line.split()[1]) Switch.cdpread() i+=1 #bar update bar.update((.4*barlen)*(i)/len(lines)) except: pass mt.Network_topology.eList_Modify() #draw Physical Topology Userlogger.info('\nCreating networkx object of the physical topology') topology,isMultigraph=gui.Network_graph.makeGraph(mt.Network_topology.EdgeList) Userlogger.info('Drawing the physical topology through networkx object') gui.Network_graph.drawTopology(topology,isMultigraph,'graph.png') #bar update bar.update((.2*barlen)) #saving object of Physicaltopology