def finalize(self): # make mininet topo topo = Topo() # add nodes for x, d in self.nodes(data=True): if d['isSwitch']: topo.addSwitch(str(x)) else: topo.addHost(str(x)) # add links for src, dst in self.edges(): topo.addLink(str(src), str(dst)) # backpatch ports into original graph for x in self.nodes(): self.node[x]['ports'] = {} self.node[x]['port'] = {} for y in self.neighbors(x): x_port, y_port = topo.port(str(x), str(y)) self.node[x]['ports'][y] = x_port # Support indexing in by port to get neighbor switch/port self.node[x]['port'][x_port] = (y, y_port) self.topo = topo self.finalized = True
def main(): logger = MininetLogger() logger.setLogLevel(levelname='info') controller_ip = sys.argv[2] topo = Topo() n = int(sys.argv[1]) switches = [topo.addSwitch('s%d' % (i+1), protocols='OpenFlow13') for i in range(n)] host1 = topo.addHost('h%d' % 1, mac="12:34:56:78:00:01") host2 = topo.addHost('h%d' % 2, mac="12:34:56:78:00:02") hosts = [host1, host2] for i in [0, 1]: topo.addLink(hosts[i], switches[i]) for i in range(n): topo.addLink(switches[i], switches[(i+1) % n]) net = Mininet(topo=topo, controller=RemoteController, link=TCLink, build=False) net.addController(ip=controller_ip) net.start() CLI(net) net.stop()
def get_topo(): topo = Topo() # 构造具体的拓扑 # 192.168.1.x x∈[101-105] # 192.168.2.x x∈[106-113] # 192.168.3.x x∈[114-117] # 192.168.4.x x∈[118-121] add_sw(topo, 8) add_host(topo, 1, 101, 105) add_host(topo, 2, 106, 113) add_host(topo, 3, 114, 117) add_host(topo, 4, 118, 121) add_host(topo, 5, 122, 124) add_link_sw_host(topo, 1, 101, 105) add_link_sw_host(topo, 2, 106, 113) add_link_sw_host(topo, 3, 114, 117) add_link_sw_host(topo, 4, 118, 121) add_link_sw_host(topo, 5, 122, 122) add_link_sw_host(topo, 6, 123, 123) add_link_sw_host(topo, 7, 124, 124) add_link_sw_sw(topo, 8, 1) add_link_sw_sw(topo, 8, 2) add_link_sw_sw(topo, 8, 3) add_link_sw_sw(topo, 8, 4) add_link_sw_sw(topo, 8, 5) add_link_sw_sw(topo, 8, 6) add_link_sw_sw(topo, 8, 7) return topo
def simpleTest(num_hosts, tcp=0): topo = Topo(n=num_hosts) #Create topology net = Mininet(topo, host=CPULimitedHost, link=TCLink) net.start() #start network h = net.hosts IPstr = str(h[0].IP()) #get IP of first host (Server) for i in range(len(h)): if i == 0: #if Server h[i].cmd("python Server.py &") #Start Server program elif i > 1: #if DOS client h[i].cmd("python Client.py " + IPstr + " &") #Start DOS client program time.sleep(5) #wait 5 seconds if tcp == 0: #if UDP analysis h[0].cmd( "iperf -s -u -i 1 -p 5566 > results_" + str(num_hosts) + ".txt &") #start iperf UDP server on h1. Print output to file. time.sleep(5) # wait 5 seconds h[1].cmd("iperf -c " + IPstr + " -u -t 15 -p 5566 -b 1M &") #start iperf UDP client on h2. time.sleep(60) #allow enough time for analysis to complete else: #if TCP analysis h[0].cmd( "iperf -s -i 15 -p 5566 > resultsTCP_" + str(num_hosts) + ".txt &") #start iperf TCP server on h1. Print output to file. time.sleep(5) # wait 5 seconds h[1].cmd("iperf -c " + IPstr + " -t 15 -p 5566 &") #start iperf TCP client on h2. time.sleep(60) #allow enough time for analysis to complete net.stop() #shutdown network
def _parse_metis_result(self,filepath,n): for i in range(0,n): self.partitions.append(Topo()) f = open(filepath,"r") i = 1 switch_to_part={} for line in f: part = int(line) switch_to_part[self.pos[i]]=part self.partitions[part].addNode(self.pos[i],**self.topo.nodeInfo(self.pos[i])) i=i+1 f.close() for node in self.topo.nodes(): if not self.topo.isSwitch(node): for edge in self.topo.links(): if(edge[0]==node): self.partitions[switch_to_part[edge[1]]].addNode(node,**self.topo.nodeInfo(node)) # print node, edge[0], edge[1], self.topo.linkInfo(node,edge[1]) self.partitions[switch_to_part[edge[1]]].addLink(node,edge[1],**self.topo.linkInfo(node,edge[1])) if(edge[1]==node): self.partitions[switch_to_part[edge[0]]].addNode(node,**self.topo.nodeInfo(node)) self.partitions[switch_to_part[edge[0]]].addLink(edge[0],node,**self.topo.linkInfo(edge[0],node)) for edge in self.topo.links(): if (self.topo.isSwitch(edge[0]) and self.topo.isSwitch(edge[1])): if(switch_to_part[edge[0]] == switch_to_part[edge[1]]): self.partitions[switch_to_part[edge[0]]].addLink(edge[0],edge[1],**self.topo.linkInfo(edge[0],edge[1])) else: self.tunnels.append([edge[0],edge[1],self.topo.linkInfo(edge[0],edge[1])]) self.logger.debug("Topologies:") for t in self.partitions: self.logger.debug("Partition "+str(self.partitions.index(t))) self.logger.debug("Nodes: "+str(t.nodes())) self.logger.debug("Links: "+str(t.links())) self.logger.debug("Tunnels: "+str(self.tunnels))
def partition(self, n, alg="chaco", shares=None): self.tunnels = [] self.partitions = [] # Write Chaco input parameters inputPara = self.toolCMD + '.in' subprocess.call('echo "' + self.graph + '\n' + self.graph + '.out\n1\n50\n2\n2\nn\n" > ' + inputPara, shell=True) subprocess.call('echo "' + self.chacoCtlPara + '" > User_Params', shell=True) if (n > 1 and len(self.switches) > 1): startT = time.time() outp = subprocess.check_output( ["cat " + inputPara + " | " + self.toolCMD], shell=True) #print "Chaco-partition:", time.time()-startT self.logger.debug(outp) startT = time.time() self._parse_chaco_result(self.graph + ".out", n) #print "Chaco-reconstruct:", time.time()-startT os.remove(self.graph + ".out") os.remove(self.graph) else: tpart = [self._convert_to_plain_topo(self.topo)] while (len(tpart) < n): tpart.append(Topo()) self.partitions = tpart return Clustering(self.partitions, self.tunnels)
def _convert_to_plain_topo(self, topo): r = Topo() for node in topo.nodes(): r.addNode(node, **topo.nodeInfo(node)) for edge in topo.links(): r.addLink(edge[0], edge[1], **topo.linkInfo(edge[0], edge[1])) return r
def partition(self, n, alg='random', shares=None): self.alg = alg self.placer = self.placers[self.alg](servers=[x for x in range(4)], nodes=self.topo.nodes(), hosts=self.topo.hosts(), switches=self.topo.switches(), links=self.topo.links()) # Create subtopologies for i in range(0, n): self.partitions.append(Topo()) # Assign switches and hosts to partitions for node in self.topo.nodes(): part = self.placer.place(node) self.nodeToPart[node] = part # Assign nodes to sub-topologies self.partitions[part].addNode(node, **self.topo.nodeInfo(node)) # Add links for link in self.topo.links(): if self.nodeToPart[link[0]] == self.nodeToPart[link[1]]: self.partitions[self.nodeToPart[link[0]]].addLink( link[0], link[1], **self.topo.linkInfo(link[0], link[1])) else: self.tunnels.append( [link[0], link[1], self.topo.linkInfo(link[0], link[1])]) return Clustering(self.partitions, self.tunnels)
def create_new_topology(topology_vector): # vector is constructed as: # there are n switches (s[0], ..., s[n-1]), where n is the length of topology_vector. # the ith switch s[i-1] is connected to topology_vector[i-1] end-hosts (h[i-1][0], ..., h[i-1][topology[i-1]-1]). newTopo = Topo() if topology_vector: # Verifies there are values in topology_vector before doing any work. for ind, switch in enumerate(topology_vector): if ind == 0: # Creates 1st switch of the network. newSwitch = 's' + str(ind) newTopo.addSwitch(newSwitch) i = 0 while i < int( switch ): # Creates hosts & links to switch per topology_vector value. newHost = 'h' + str(ind) + str(i) newTopo.addHost(newHost) newTopo.addLink(newSwitch, newHost) i += 1 else: newSwitch = 's' + str(ind) prevSwitch = 's' + str(ind - 1) newTopo.addSwitch(newSwitch) newTopo.addLink(newSwitch, prevSwitch) i = 0 while i < int(switch): newHost = 'h' + str(ind) + str(i) newTopo.addHost(newHost) newTopo.addLink(newSwitch, newHost) i += 1 return newTopo
def main(): cocoon(":connect") subprocess.call(["rmmod", "dummy"]) subprocess.check_call(["sudo", "modprobe", "dummy", "numdummies=10"]) topo = Topo() net = VNet(topo=topo, controller=None) net.start() cocoon("LogicalSwitch.put(LogicalSwitch{123})") subprocess.check_call(["ifconfig", "dummy0", "10.10.10.101"]) dp_id1 = net.addHV(1, "10.10.10.101") subprocess.check_call(["ifconfig", "dummy1", "10.10.10.102"]) dp_id2 = net.addHV(2, "10.10.10.102") net.addVM(1, dp_id1, '11:22:33:44:55:66', "192.168.0.1") cocoon("LogicalPort.put(LogicalPort{0,123,1,48'h112233445566})") net.addVM(2, dp_id2, '11:22:33:44:55:77', "192.168.0.2") cocoon("LogicalPort.put(LogicalPort{1,123,2,48'h112233445577})") CLI(net) subprocess.call(["rmmod", "dummy"]) net.stop()
def createTopo(): topo = Topo() swCore1 = topo.addSwitch('s1') ## Ajuste do parametro de fanout da rede fanout = 2 # Switches counter lastSW = 2 lastHost = 1 # Aggregation switches loop for i in irange(1, fanout): swAggregL = topo.addSwitch('s%s' % lastSW) topo.addLink(swCore1, swAggregL) lastSW += 1 # Edge switches loop for j in irange(1, fanout): swEdge = topo.addSwitch('s%s' % lastSW) topo.addLink(swAggregL, swEdge) lastSW += 1 # Hosts loop for k in irange(1, fanout): host = topo.addHost('h%s' % lastHost) topo.addLink(swEdge, host) lastHost += 1 return topo
def test_mininet_conversion_to_logical(): """Test the conversion from a mininet logical network to a logical one.""" import networkx as nx from distriopt import VirtualNetwork from mininet.topo import Topo virt_topo_mn = Topo() # Add nodes u = virt_topo_mn.addHost("u", cores=2, memory=1000) v = virt_topo_mn.addHost("v", cores=2, memory=1000) z = virt_topo_mn.addSwitch("z", cores=2, memory=1000) # Add links virt_topo_mn.addLink(u, v, rate=1000) virt_topo_mn.addLink(v, z, rate=1000) virt_topo_mn.addLink(u, z, rate=1000) virtual_topo = VirtualNetwork.from_mininet(virt_topo_mn) assert virtual_topo.number_of_nodes() == 3 assert len(virtual_topo.edges()) == 3 assert nx.is_connected(virtual_topo.g) for node in virtual_topo.nodes(): assert virtual_topo.req_cores(node) == 2 assert virtual_topo.req_memory(node) == 1000 for i, j in virtual_topo.edges(): assert virtual_topo.req_rate(i, j) == 1000
def process_custom_topology(topology_file): topo = Topo() with open(topology_file) as f: topo_data = yaml.full_load(f) name_mapping = {} environments = {} groups = {} for group in topo_data.keys(): if group == "connections": continue groups[group] = [] if topo_data[group] is not None: for node, env in topo_data[group].items(): node_name = "%s_%s" % (group[:2].upper(), node) name_mapping[node] = node_name environments[node_name] = env groups[group].append(node_name) topo.addHost(node_name) for node_name in name_mapping.values(): environments[node_name]["NODE_PREFIX"] = "/ndn/%s-site/%s" % ( node_name, node_name) for couple in topo_data["connections"]: for node_A, node_B in couple.items(): if not isinstance(node_B, List) and node_A != node_B: topo.addLink(name_mapping[node_A], name_mapping[node_B], delay='10ms') return topo, name_mapping, environments, groups
def finalize(self): # make mininet topo topo = Topo() # add nodes for x,d in self.nodes(data=True): topo.add_node(x,Node(is_switch=d['isSwitch'])) # add links for src,dst in self.edges(): topo.add_edge(src,dst) # backpatch ports into original graph for x in self.nodes(): self.node[x]['ports'] = {} self.node[x]['port'] = {} for y in self.neighbors(x): x_port, y_port = topo.port(x,y) self.node[x]['ports'][y] = x_port # Support indexing in by port to get neighbor switch/port self.node[x]['port'][x_port] = (y, y_port) topo.enable_all() self.topo = topo self.finalized = True
def test_mininet_conversion_to_physical(): """Test the conversion from a mininet physical network to a PhysicalNetwork one.""" import networkx as nx from distriopt.embedding import PhysicalNetwork from mininet.topo import Topo phy_topo_mn = Topo() # Add nodes master1 = phy_topo_mn.addHost("Master1", cores=2, memory=1000) node1 = phy_topo_mn.addHost("Node1", cores=2, memory=1000) sw = phy_topo_mn.addSwitch("SW") # Add links phy_topo_mn.addLink(master1, sw, port1="eth0", port2="eth0", rate=1000) phy_topo_mn.addLink(master1, sw, port1="eth1", port2="eth2", rate=1000) phy_topo_mn.addLink(node1, sw, port1="eth0", port2="eth1", rate=1000) phy_topo = PhysicalNetwork.from_mininet(phy_topo_mn) assert len(phy_topo.compute_nodes) == 2 assert phy_topo.number_of_nodes() == 3 assert len(phy_topo.edges()) == 3 assert nx.is_connected(phy_topo.g) for node in phy_topo.compute_nodes: assert phy_topo.cores(node) == 2 assert phy_topo.memory(node) == 1000 for i, j, device in phy_topo.edges(keys=True): assert phy_topo.rate(i, j, device) == 1000
def createTopo(): topo = Topo() #Create Host Nodes for x in range(1, 9): print "h" + str(x) topo.addHost("h" + str(x)) #Create Switch Nodes topo.addSwitch("c1") topo.addSwitch("d1") topo.addSwitch("d2") for x in range(1, 5): print "a" + str(x) topo.addSwitch("a" + str(x)) #Create links topo.addLink("c1", "d1", bw=1000, delay='2ms') topo.addLink("c1", "d2", bw=1000, delay='2ms') for x in range(1, 3): topo.addLink("d" + str(x), "a" + str(2 * x - 1), bw=100, delay='2ms') topo.addLink("d" + str(x), "a" + str(2 * x), bw=100, delay='2ms') for x in range(1, 5): topo.addLink("a" + str(x), "h" + str(2 * x - 1), bw=10, delay='2ms') topo.addLink("a" + str(x), "h" + str(2 * x), bw=10, delay='2ms') return topo
def partition(self, n, shares=None): self.tunnels = [] self.partitions = [] if (n > 1 and len(self.switches) > 1): if (shares): tpw = "" for i in range(0, n): tpw += str(i) + " = " + str(shares[i]) + "\n" tpwf = self._write_to_file(tpw) outp = subprocess.check_output([ self.metisCMD + " -tpwgts=" + tpwf + " " + self.graph + " " + str(n) ], shell=True) os.remove(tpwf) else: outp = subprocess.check_output( [self.metisCMD + " " + self.graph + " " + str(n)], shell=True) self.logger.debug(outp) self._parse_metis_result(self.graph + ".part." + str(n), n) os.remove(self.graph + ".part." + str(n)) os.remove(self.graph) else: tpart = [self._convert_to_plain_topo(self.topo)] while (len(tpart) < n): tpart.append(Topo()) self.partitions = tpart return Clustering(self.partitions, self.tunnels)
def partition(self,n,shares=None): self.tunnels=[] self.partitions=[] if(n>1 and len(self.switches)>1): if(shares): tpw="" for i in range(0,n): tpw+=str(i)+ " = " +str(shares[i])+"\n" tpwf=self._write_to_file(tpw) outp=subprocess.check_output([self.toolCMD+" -tpwgts="+tpwf+" "+self.graph+" "+str(n)],shell=True) os.remove(tpwf) else: startT = time.time() outp=subprocess.check_output([self.toolCMD+" "+self.graph+" --output_filename "+self.graph+".out --k "+str(n)],shell=True) print "KaHIP-partition:", time.time()-startT self.logger.debug(outp) startT = time.time() self._parse_metis_result(self.graph+".out",n) print "KaHIP-reconstruct:", time.time()-startT os.remove(self.graph+".out") os.remove(self.graph) else: tpart = [self._convert_to_plain_topo(self.topo)] while(len(tpart) < n): tpart.append(Topo()) self.partitions = tpart return Clustering(self.partitions,self.tunnels)
def testActualDpidAssignment(self): """Verify that Switch dpid is the actual dpid assigned if dpid is passed in switch creation.""" dpid = self.dpidFrom(0xABCD) switch = Mininet(Topo(), self.switchClass, Host, Controller).addSwitch('s1', dpid=dpid) self.assertEqual(switch.dpid, dpid)
def createTopo(): topo=Topo() #Create Nodes topo.addHost("h1") topo.addHost("h2") topo.addHost("h3") topo.addHost("h4") topo.addHost("h5") topo.addHost("h6") topo.addSwitch('s1') topo.addSwitch('s2') topo.addSwitch('s3') topo.addHost("r1") #router topo.addHost("r2") #router topo.addHost("r3") #router #Create links topo.addLink('h1','s1') topo.addLink('h2','s1') topo.addLink('s1','r1') topo.addLink('h3','s2') topo.addLink('h4','s2') topo.addLink('s2','r2') topo.addLink('h5','s3') topo.addLink('h6','s3') topo.addLink('s3','r3') topo.addLink('r1','r2') topo.addLink('r1','r3') topo.addLink('r2','r3') return topo
def testDefaultDpid( self ): """Verify that the default dpid is assigned using a valid provided canonical switchname if no dpid is passed in switch creation.""" net = Mininet( Topo(), self.switchClass, Host, Controller ) switch = net.addSwitch( 's1' ) self.assertEqual( switch.defaultDpid(), switch.dpid ) net.stop()
def createTopo(): topo = Topo() #Create Nodes topo.addHost("h1") topo.addHost("h2") topo.addHost("h3") topo.addHost("h4") topo.addHost("h5") topo.addHost("h6") topo.addHost("h7") topo.addHost("h8") topo.addSwitch('d1') topo.addSwitch('d2') topo.addSwitch('a1') topo.addSwitch('a2') topo.addSwitch('a3') topo.addSwitch('a4') #Create links topo.addLink('d1', 'd2', bw=10000, delay='1ms') topo.addLink('d1', 'a1', bw=1000, delay='3ms') topo.addLink('d1', 'a2', bw=1000, delay='3ms') topo.addLink('d2', 'a3', bw=1000, delay='3ms') topo.addLink('d2', 'a4', bw=1000, delay='3ms') topo.addLink('a1', 'h1', bw=100, delay='5ms') topo.addLink('a1', 'h2', bw=100, delay='5ms') topo.addLink('a2', 'h3', bw=100, delay='5ms') topo.addLink('a2', 'h4', bw=100, delay='5ms') topo.addLink('a3', 'h5', bw=100, delay='5ms') topo.addLink('a3', 'h6', bw=100, delay='5ms') topo.addLink('a4', 'h7', bw=100, delay='5ms') topo.addLink('a4', 'h8', bw=100, delay='5ms', loss=15) return topo
def test_path_rules(self): topo = Topo() topo.addHost("h1", mac="00:00:00:00:00:01", ip="10.0.0.1/24") topo.addHost("h2", mac="00:00:00:00:00:02", ip="10.0.0.2/24") topo.addSwitch("s1") topo.addSwitch("s2") topo.addLink("h1", "s1", bw=10, port1=1, port2=3) topo.addLink("s1", "s2", bw=10, port1=2, port2=5) topo.addLink("s2", "h2", bw=20, port1=8, port2=10) expected_s1_paths = [{ 'src_ip': '10.0.0.1', 'src_mac': '00:00:00:00:00:01', 'dst_ip': '10.0.0.2', 'dst_mac': '00:00:00:00:00:02', 'out_port': '2' }, { 'src_ip': '10.0.0.2', 'src_mac': '00:00:00:00:00:02', 'dst_ip': '10.0.0.1', 'dst_mac': '00:00:00:00:00:01', 'out_port': '3' }] expected_s2_paths = [{ 'src_ip': '10.0.0.1', 'src_mac': '00:00:00:00:00:01', 'dst_ip': '10.0.0.2', 'dst_mac': '00:00:00:00:00:02', 'out_port': '8' }, { 'src_ip': '10.0.0.2', 'src_mac': '00:00:00:00:00:02', 'dst_ip': '10.0.0.1', 'dst_mac': '00:00:00:00:00:01', 'out_port': '5' }] net = Mininet(topo=topo, controller=None, build=True) result = GraphConverted.from_mininet(net=net) paths = result.path_rules(["h1", "s1", "s2", "h2"]) s1, s2 = paths["s1"], paths["s2"] net.stop() for i in s1: if i["src_ip"] == '10.0.0.1': if i['out_port'] != "2": self.assertTrue(False) if i["src_ip"] == '10.0.0.2': if i['out_port'] != "3": self.assertTrue(False) for i in s2: if i["src_ip"] == '10.0.0.1': if i['out_port'] != "8": self.assertTrue(False) if i["src_ip"] == '10.0.0.2': if i['out_port'] != "5": self.assertTrue(False) self.assertTrue(True)
def run_mininet(self, topology_string): """ Create and run multiple link network """ self.topo_client = Topo() hosts = set() switches = set() relations = re.sub(r's', '', topology_string) relations = [ i.split(':') for i in relations.split(',') if 'h' not in i ] relations = [[int(y) - 1 for y in x] for x in relations] builtin.log(relations, 'DEBUG') verticles_count = len(set(list(itertools.chain(*relations)))) builtin.log(self.topology, 'DEBUG') for i in xrange(verticles_count): temp = [] for j in xrange(verticles_count): temp.append(-1) self.topology.append(temp[:]) builtin.log(self.topology, 'DEBUG') for i in relations: self.topology[i[0]][i[1]] = 1 self.topology[i[1]][i[0]] = 1 builtin.log(self.topology, 'DEBUG') for v1, v2 in [x.split(':') for x in str(topology_string).split(',')]: if 'h' in v1 and v1 not in hosts: self.topo_client.addHost(v1) hosts.add(v1) if 'h' in v2 and v2 not in hosts: self.topo_client.addHost(v2) hosts.add(v2) if 's' in v1 and v1 not in switches: self.topo_client.addSwitch(v1) switches.add(v1) if 's' in v2 and v2 not in switches: self.topo_client.addSwitch(v2) switches.add(v2) if self.delay: self.topo_client.addLink(v1, v2, delay=self.delay) else: self.topo_client.addLink(v1, v2) self.mininet_client = Mininet(switch=user_switch, controller=remote_controller, topo=self.topo_client, link=TCLink) self.mininet_client.start() builtin.log('Links info:') for link in self.topo_client.links(withKeys=True, withInfo=True): builtin.log(link) # self.mininet_client.waitConnected(timeout=20) sleep(20)
def testActualDpidAssignment(self): """Verify that AP dpid is the actual dpid assigned if dpid is passed in ap creation.""" dpid = self.dpidFrom(0xABCD) ap = Mininet(topo=Topo(), accessPoint=self.accessPointClass, station=Station, controller=Controller, isWiFi=True).addAccessPoint('ap1', dpid=dpid) self.assertEqual(ap.dpid, dpid)
def testDefaultDpid(self): """Verify that the default dpid is assigned using a valid provided canonical apname if no dpid is passed in ap creation.""" ap = Mininet(topo=Topo(), accessPoint=self.accessPointClass, station=Station, controller=Controller, isWiFi=True).addAccessPoint('ap1') self.assertEqual(ap.defaultDpid(), ap.dpid)
def testDefaultDpidLen(self): """Verify that Default dpid length is 16 characters consisting of 16 - len(hex of first string of contiguous digits passed in switch name) 0's followed by hex of first string of contiguous digits passed in switch name.""" switch = Mininet(Topo(), self.switchClass, Host, Controller).addSwitch('s123') self.assertEqual(switch.dpid, self.dpidFrom(123))
def createNet(args): topo = Topo() h1 = topo.addHost("h1", ip='10.0.1.1/24') s1 = topo.addSwitch("s1") h2 = topo.addHost("h2", ip='10.0.1.2/24') topo.addLink(h1, s1, cls=TCLink, bw=10, delay="10ms", loss=1) topo.addLink(s1, h2, cls=TCLink, bw=10, delay="10ms", loss=1) return Mininet(topo)
def testDefaultDpidAssignmentFailure(self): """Verify that Default dpid assignment raises an Exception if the name of the switch does not contin a digit. Also verify the exception message.""" with self.assertRaises(Exception) as raises_cm: Mininet(Topo(), self.switchClass, Host, Controller).addSwitch('A') self.assertEqual( raises_cm.exception.message, 'Unable to derive ' 'default datapath ID - please either specify a dpid ' 'or use a canonical switch name such as s23.')
def testDefaultDpidLen(self): """Verify that Default dpid length is 16 characters consisting of 16 - len(hex of first string of contiguous digits passed in ap name) 0's followed by hex of first string of contiguous digits passed in ap name.""" ap = Mininet(topo=Topo(), accessPoint=self.accessPointClass, station=Station, controller=Controller, isWiFi=True).addAccessPoint('ap123') self.assertEqual(ap.dpid, self.dpidFrom(123))