def createTopo(): logging.debug("LV1 Create HugeTopo") topo = HugeTopo() topo.createTopo() topo.createLink() # TODO add multiple controller here logging.debug("LV1 Start Mininet") CONTROLLER_IP = "127.0.0.1" CONTROLLER_PORT = 6633 c0 = Controller('c0', port=6633) c1 = Controller('c1', port=6634) c2 = Controller('c2', port=6635) c3 = Controller('c3', port=6636) c5 = RemoteController('c2', ip='127.0.0.1') net = Mininet(topo=topo, link=TCLink, controller=POX) for c in [c0, c1, c2, c3 ]: net.addController(c) net.start() logger.debug("LV1 dumpNode") enableSTP() dumpNodeConnections(net.hosts) #pingTest(net) #iperfTest(net, topo) CLI(net) p = pexpect.spawn( 'controller test' ) # but first a simple ping test p.sendline( 'xterm c0' ) net.stop()
def run(self): '''Run the simulation environment''' # We create the topology # topology = DistributedTopology(self.nb_of_servers) topology = DistributedTopology_Segmented(self.nb_of_servers) c0 = Controller('c0', port=6633) # We create the simulation # Set the topology, the class for links and interfaces, the mininet environment must be cleaned up before launching, we should build now the topology simulation = Mininet(topo=topology, link=TCLink, intf=TCIntf, controller=c0, cleanup=True, build=True, ipBase='10.1.0.0/24') # We connect the network to Internet # simulation.addNAT().configDefault() terms = [] # We can start the simulation print "Starting the simulation..." simulation.start() for srv in simulation.hosts: if "server" in srv.name: # We open a xterm and start the server terms.append(self.startServer(srv)[0]) # We also start the Command Line Interface of Mininet CLI(simulation) # Once the CLI is closed (with exit), we can stop the simulation print "Stopping the simulation NOW!" # We close the xterms (mininet.term.cleanUpScreens) cleanUpScreens() for term in terms: os.kill(term.pid, signal.SIGKILL) simulation.stop()
def emptyNet(): net = Mininet(topo=None, build=False) c0 = Controller('c0', inNamespace=False) h1 = Host('h1') h2 = Host('h2') #intf1 = Intf("h1-eth1") #intf2 = Intf("h2-eth1") s1 = OVSSwitch('br0', inNamespace=False) Link(h1, s1) Link(h2, s1) c0.start() s1.start([c0]) net.start() #s1.cmd('ovs-vsctl set bridge br0 protocols=OpenFlow13') CLI(net) net.stop() h1.stop() h2.stop() s1.stop() c0.stop()
def main(logFile, depth, uMin, uMax, runtime, seeding, cli): # create residential WiFi topology mytopo = MnTopo(depth, uMin, uMax, seeding) # create & start Mininet net = Mininet(topo=mytopo, controller=None, link=TCLink, autoStaticArp=True) net.addController(Controller('c0')) net.start() # assign IP addresses to interfaces linklist = mytopo.links(sort=True) linklist.reverse() idx = 1 while linklist: item = linklist.pop() if re.match("gsw\d", item[1]): apid = re.findall(r'\d+', item[0])[0] swid = str(int(re.findall(r'\d+', item[1])[0])) net.getNodeByName(item[0]).setIP("192.168.%s.%s/24" % (swid, str(int(apid) + 1)), intf="ap%s-eth%s" % (apid, idx)) idx += 1 else: idx = 1 if cli == 1: CLI(net) time.sleep(10) nodelist = mytopo.nodes(sort=True) no_nodes = 0 while nodelist: item = nodelist.pop() if re.match("ap\d", item): with open("measurements/stdout" + item + ".txt", "wb") as out, open("measurements/stderr" + item + ".txt", "wb") as err: time.sleep(5) net.getNodeByName(item).popen( "python ../resfi_loader.py -r %s" % runtime, stdout=out, stderr=err) no_nodes = no_nodes + 1 print "script running. please wait." # wait until end time is reached start = datetime.datetime.now() while True: now = datetime.datetime.now() if (now - start).seconds < runtime: time.sleep(0.5) else: break net.stop()
def __init__(self): self.ap_dict = {} self.sw_dict = {} self.host_dict = {} self.sta_dict = {} self.net = Mininet_wifi(accessPoint=OVSKernelAP) self.net.propagationModel(model="logDistance", exp=3) self.c1 = Controller('c1') self.add_nodes()
def get_controller(remote_controller=""): if not remote_controller: return Controller(name='c0', port=6633) else: conn_params = remote_controller.split(':') if len(conn_params) == 1: ctrl_port = 6633 else: ctrl_port = int(conn_params[1]) return RemoteController(name='c0', ip=conn_params[0], port=ctrl_port)
def __init__( self ): "Creating OpenFlow Tutorial Topology." # Initialize topology Topo.__init__( self ) # Add controllers controller1 = Controller( 'c1' ) controller2 = Controller( 'c2' ) controller3 = Controller( 'c3' ) # Add hosts and switches switch1 = self.addSwitch( 's1' ) switch2 = self.addSwitch( 's2' ) switch3 = self.addSwitch( 's3' ) webServer = self.addHost( 'h1' ) # Add links self.addLink( switch1, switch2 ) self.addLink( switch2, switch3 )
def ClusterController(*args, **kwargs): "Custom Controller() constructor which updates its intf IP address" intf = kwargs.pop('intf', '') controller = Controller(*args, **kwargs) # Find out its IP address so that cluster switches can connect if not intf: output = controller.cmd(r"ip a | egrep -o '\w+:\s\w+'").split('\n') for line in output: intf = line.split()[-1] if intf != 'lo': break if intf == 'lo': raise Exception('Could not find non-loopback interface' 'for %s' % controller) Intf(intf, node=controller).updateIP() return controller
def topology(): "Create a network." net = Mininet(link=TCLink, switch=OVSSwitch) c0 = Controller('c0', port=6634) c1 = RemoteController('c1', ip='127.0.0.1', port=6633) net.addController(c0) net.addController(c1) print "*** Creating nodes" s0 = net.addSwitch('s0') ap1 = net.addBaseStation('ap1', ssid="ssid_ap1", mode="g", channel="5") ap2 = net.addBaseStation('ap2', ssid="ssid_ap2", mode="g", channel="1") sta1 = net.addStation('sta1', ip='192.168.0.1/24') sta2 = net.addStation('sta2', ip='192.168.0.2/24') sta3 = net.addStation('sta3', ip='192.168.0.3/24') sta4 = net.addStation('sta4', ip='192.168.0.4/24') h1 = net.addHost('h0', ip='192.168.0.5') h2 = net.addHost('h1', ip='192.168.0.6') print "*** Adding Link" net.addLink(sta1, ap1, bw=10, loss=0) net.addLink(sta2, ap1, bw=10, loss=0) net.addLink(sta3, ap2, bw=10, loss=0) net.addLink(sta4, ap2, bw=10, loss=0) net.addLink(ap1, s0) net.addLink(ap2, s0) net.addLink(h1, s0) net.addLink(h2, s0) net.build() c0.start() c1.start() ap1.start([c0]) ap2.start([c0]) #nat0.start( [c0] ) s0.start([c1]) print "*** Running CLI" CLI(net) print "*** Stopping network" net.stop()
def multiControllerNet(): "Create a network from semi-scratch with multiple controllers." net = Mininet(switch=OVSSwitch) c0 = Controller("c0") print("*** Creating switches") s1 = net.addSwitch('s1') print("*** Creating hosts") #hosts1 = [ net.addHost( 'h%d' % n ) for n in ( 1, 3 ) ] #h1 = net.addHost("h1", ip="192.168.3.1") h11 = net.addHost("h11", ip="192.168.101.1") h12 = net.addHost("h12", ip="192.168.102.1") print("*** Creating links") #for h in hosts1: # net.addLink( s1, h ) #net.addLink(s1, h1) net.addLink(s1, h11) net.addLink(s1, h12) print("*** Starting network") net.addController(c0) net.build() c0.start() s1.start([c0]) print("*** Testing network") #net.pingAll() #s1.cmd("ifconfig s1 192.168.5.10") print("*** Running CLI") CLI(net) print("*** Stopping network") net.stop()
""" Create a network where different switches are connected to different controllers, by creating a custom Switch() subclass. """ from mininet.net import Mininet from mininet.node import OVSSwitch, Controller, RemoteController from mininet.topolib import TreeTopo from mininet.log import setLogLevel from mininet.cli import CLI setLogLevel('info') # Two local and one "external" controller (which is actually c0) # Ignore the warning message that the remote isn't (yet) running c0 = Controller('c0', port=6633) c1 = Controller('c1', port=6634) c2 = RemoteController('c2', ip='127.0.0.1') cmap = {'s1': c0, 's2': c1, 's3': c2} class MultiSwitch(OVSSwitch): "Custom Switch() subclass that connects to different controllers" def start(self, controllers): return OVSSwitch.start(self, [cmap[self.name]]) topo = TreeTopo(depth=2, fanout=2) net = Mininet(topo=topo, switch=MultiSwitch, build=False)
different controllers, by creating a custom Switch() subclass. """ from mininet.topo import Topo from mininet.net import Mininet from mininet.node import OVSSwitch, Controller, RemoteController, OVSKernelSwitch from mininet.topolib import TreeTopo from mininet.log import setLogLevel from mininet.cli import CLI setLogLevel('info') # Two local and one "external" controller (which is actually c0) # Ignore the warning message that the remote isn't (yet) running c0 = RemoteController('c0', ip='127.0.0.1', port=6633) c1 = Controller('c1', port=6666) cmap = {'s1': c1, 'r1': c0, 'r2': c0, 's2': c1} class MultiSwitch(OVSSwitch): "Custom Switch() subclass that connects to different controllers" def start(self, controllers): return OVSSwitch.start(self, [cmap[self.name]]) class MyTopo(Topo): def __init__(self): # Initialize topology Topo.__init__(self)
def create_network(argv): "Run one stage of network" # if we have forgotten to raise them call('ifconfig eth0 up', shell=True) call('ifconfig eth1 up', shell=True) # about this network base_ip = argv[0][0:argv[0].rfind('.')] # the first three octets first_two_octets = base_ip[0:base_ip.rfind('.')] # first two octets this_subnet = int(base_ip[base_ip.rfind('.') + 1:]) # third octet as int # mininet topo = one_stage(ip=base_ip, low_bw=5, ext_delay=50000) net = Mininet(topo, link=TCLink, controller=Controller('c0', ip='127.0.0.2', port=6653)) # add eth0 to router 1 and set its ip # set the subnet of eth0 to 1 smaller than current subnet; for example: # set it to 192.168.10.254 when the network subnet is 192.168.11.0 r1 = net.getNodeByName('r1') Intf('eth0', r1) eth0_ip = first_two_octets + '.' + str(this_subnet - 1) + '.254' r1.cmd('ifconfig eth0 ' + eth0_ip + ' netmask 255.255.255.0') # add eth1 to switch s6 and set its ip s6 = net.getNodeByName('s6') Intf('eth1', s6) eth1_ip = first_two_octets + '.' + str(this_subnet) + '.253' s6.cmd('ifconfig eth1 ' + eth1_ip + ' netmask 255.255.255.0') # add eth2 to router 2 r2 = net.getNodeByName('r2') Intf('eth2', r2) eth2_ip = first_two_octets + '.' + str(this_subnet + 10 - 1) + '.254' r2.cmd('ifconfig eth2 ' + eth2_ip + ' netmask 255.255.255.0') # add eth1 to switch s9 and set its ip s9 = net.getNodeByName('s9') Intf('eth3', s9) eth3_ip = first_two_octets + '.' + str(this_subnet + 10) + '.253' s9.cmd('ifconfig eth3 ' + eth3_ip + ' netmask 255.255.255.0') # add routing tables r1.set_routing_table(first_two_octets, this_subnet, 'eth0') r2.set_routing_table(first_two_octets, this_subnet + 10, 'eth2') for h in net.hosts: if h.name[0] != 'r': # host other than a router config for x in range(this_subnet + 1, 15): #host config is only for non-default h.cmd('route add -net ' + first_two_octets + '.' + str(x) + '.0' + ' netmask 255.255.255.0 gw ' + first_two_octets + '.' + str(this_subnet) + '.254') h.cmd('route add -net ' + first_two_octets + '.' + str(this_subnet + 10) + '.0' + ' netmask 255.255.255.0 gw ' + first_two_octets + '.' + str(this_subnet) + '.250') # configuration for router 3 r3 = net.getNodeByName('r3') r3_eth0 = r3.intf('r3-eth0') r3_eth0.setIP(first_two_octets + '.' + str(this_subnet) + '.250', 24) r3_eth1 = r3.intf('r3-eth1') r3_eth1.setIP(first_two_octets + '.' + str(this_subnet + 10) + '.250', 24) r3.cmd('route add -net ' + first_two_octets + '.' + str(this_subnet) + '.0 netmask 255.255.255.0 dev r3-eth0') r3.cmd('route add -net ' + first_two_octets + '.' + str(this_subnet + 10) + '.0 netmask 255.255.255.0 dev r3-eth1') # run sshd on hosts for h in net.hosts: h.cmd('/usr/sbin/sshd -D -o UseDNS=no -u0 &') # root node root_node = add_root_node(net, first_two_octets, this_subnet + 10) #net operation net.start() CLI(net) for h in net.hosts: h.cmd('kill %/usr/sbin/sshd') h.cmd('wait %/usr/sbin/sshd') root_node.cmd('kill %/usr/sbin/sshd') root_node.cmd('wait %/usr/sbin/sshd') net.stop() # reconfigure the interface for use when we exit mininet sleep(0.5) call('ifconfig eth0 up', shell=True) call('ifconfig eth1 up', shell=True) sleep(0.5) call('ifconfig eth0 ' + eth0_ip + ' netmask 255.255.255.0', shell=True) call('ifconfig eth1 ' + eth1_ip + ' netmask 255.255.255.0', shell=True)
def qbb_qos_init(): """ :return: Create and test our QBB network standard" 初始化拓扑qos; 包括 四个存在带宽差异(big_link small_link)导致拥堵点的链路 qos 带宽 s1-eth3 s2-eth3 s3-eth3 s4-eth1 将 5002, h1, icmp 所有流量转移到队列2中, 便于测试 """ # LOG.setLogLevel("debug") #打开 debug 日志 qbb_topo = QbbTopo() # global net # MMininet 类 API 参考: http://mininet.org/api/classmininet_1_1net_1_1Mininet.html#a1ed0f0c8ba06a398e02f3952cc4c8393 # 命令行参数对应 --mac => autoSetMacs # 命令行参数对应 --arp => autoStaticArp # 命令行参数对应 -x => xterms net = Mininet(topo=qbb_topo, controller=None, link=TCLink, autoSetMacs=True, xterms=True, autoStaticArp=True) c0 = Controller('c0', port=6633) # net.addController('c0', controller=RemoteController, ip='192.168.57.2', port=6653) net.addController(c0) net.start() # 调整队列大小 print "调整下列端口的 txqueuelen 网络队列大小为 %s ..." % TX_QUEUE_LEN for port in ALL_PORTS.split(): print " %s" % port, LOG.debug( " 调整 %s 网络 队列长度 txqueuelen: sudo ip link set txqueuelen %s dev %s ..." % (port, TX_QUEUE_LEN, port)) os.popen("sudo ip link set txqueuelen %s dev %s" % (TX_QUEUE_LEN, port)) print " 检查设置: ifconfig | grep txqueuelen" print "使用 ovs-vsctl 创建各端口上的3个队列, 哑铃拓扑的流量策略, 主机接口带宽大 big_link, \n" \ " 交换机接口流量带宽小 small_lin. QoS 策略 ( tc htb qdisc ), " os.popen("""sudo ovs-vsctl \ -- set port s1-eth3 qos=@small_link \ -- set port s2-eth3 qos=@small_link \ -- set port s3-eth2 qos=@small_link \ -- set port s4-eth2 qos=@small_link \ -- --id=@small_link create qos type=linux-htb queues=0=@q0,1=@q1,2=@q2 \ -- --id=@q0 create queue other-config:min-rate=50000000 other-config:max-rate=1000000 \ -- --id=@q1 create queue other-config:min-rate=50000000 other-config:max-rate=1000000 \ -- --id=@q2 create queue other-config:min-rate=50000000 other-config:max-rate=1000000 \ -- set port s1-eth1 qos=@big_link \ -- set port s1-eth2 qos=@big_link \ -- set port s2-eth1 qos=@big_link \ -- set port s2-eth2 qos=@big_link \ -- --id=@big_link create qos type=linux-htb queues=0=@q3,1=@q4,2=@q5 \ -- --id=@q3 create queue other-config:min-rate=100000000 other-config:max-rate=20000000 \ -- --id=@q4 create queue other-config:min-rate=100000000 other-config:max-rate=20000000 \ -- --id=@q5 create queue other-config:min-rate=100000000 other-config:max-rate=20000000 """ ) # for port in SW_HOST_PORTS.split(): # 配置 HOST_PORT 和上面的 ovsctl 一样策略 (如果用 ALL_PORT 来执行可以不用上面 ovs-vsctl 了, # 之前用 ovs-vsctl 是为了保持和ovs的兼容性) # os.popen("tc qdisc add dev %s root handle 1: htb default 1" % port) # TODO 这里host的 burst 值还和 ovs 的不一样, 回头细调 # os.popen("tc class add dev %s parent 1: classid 1:fffe htb rate 10000mbit burst 1250b cburst 1250b" % port) # os.popen("tc class add dev %s parent 1:fffe classid 1:1 htb rate 5mbit burst 1563b cburst 1563b" % port) # os.popen("tc class add dev %s parent 1:fffe classid 1:2 htb rate 5mbit burst 1563b" % port) # os.popen("tc class add dev %s parent 1:fffe classid 1:3 htb rate 5mbit burst 1563b" % port) # pass # 通过 ovs-vsctl 已配置 # 设置 tc filter: 端口 5001 -> 队列 1:1, 5002 -> 1:2 , 5003 -> 1:3 LOG.info( "在各端口上设置 handle 和 filter 端口 5001 -> 队列 1:1, 5002 -> 1:2 , 5003 -> 1:3 \n" " h1 -> 队列2, icmp -> 队列2... \n") for port in SW_HOST_PORTS.split(): # 放置 class handle os.popen("tc qdisc add dev %s parent 1:1 handle 1: pfifo limit %s" % (port, TX_QUEUE_LEN)) os.popen("tc qdisc add dev %s parent 1:2 handle 2: pfifo limit %s" % (port, TX_QUEUE_LEN)) os.popen("tc qdisc add dev %s parent 1:3 handle 3: pfifo limit %s" % (port, TX_QUEUE_LEN)) # 放置 class filter u32_filter_prefix = "tc filter add dev %s protocol ip parent 1:0 prio 1 u32" % port os.popen('%s match ip dport 5001 0xffff flowid 1:1' % u32_filter_prefix) os.popen('%s match ip dport 5002 0xffff flowid 1:2' % u32_filter_prefix) os.popen('%s match ip dport 5003 0xffff flowid 1:3' % u32_filter_prefix) os.popen('%s match ip dport 5003 0xffff flowid 1:3' % u32_filter_prefix) os.popen('%s match match ip src 10.0.0.1/32 flowid 1:2' % u32_filter_prefix) # 把h1所有包 match 到队列2 os.popen('%s match ip protocol 1 0xff flowid 1:2' % u32_filter_prefix) # 把icmp所有包 match 到队列2 print " 设置端口 %s 完成 ..." % port print " 检查设置: tc filter show dev $NDEV parent 1:fffe" LOG.info("查看 tc qdisc") LOG.info(" 普通 pfifo_fast 接口 s3-eth1 状态为: tc qdisc show dev s3-eth1\n") LOG.debug("\n".join(os.popen('tc qdisc show dev s3-eth1').readlines())) print " 查看 netem 延时链路 s3-eth2 <->s4-eth1 接口状态为: tc qdisc show dev s3-eth2 / s4-eth1" LOG.debug("\n".join(os.popen('tc qdisc show dev s3-eth2').readlines())) LOG.debug("\n".join(os.popen('tc qdisc show dev s4-eth1').readlines())) print " 查看 htb qdisc 队列接口 s1-eth3, tc qdisc show dev $NDEV (采用的应是 htb, 而不是 pfifo_fast(普通) 或 netem(延时) )" LOG.debug("\n".join(os.popen('tc qdisc show dev s1-eth3').readlines())) print " 查看 htb class 队列接口 s1-eth3, tc class show dev $NDEV" LOG.debug("\n".join(os.popen('tc class show dev s1-eth3').readlines())) print " 查看 htb filter 队列接口 s1-eth3, tc filter show dev $NDEV parent 1:0" LOG.debug("\n".join( os.popen('tc filter show dev s1-eth3 parent 1:0').readlines())) print "拥塞测试方法:" print " 设置 iperf server 测速: h3(xterm)> iperf -s -p 5002 -m # 监听在5002端口, 会被 tc filter 匹配到队列2中 " print " 连接 iperf client 测速: h1(xterm)> iperf -c h3 -p 5002 -i 3 -t 60 -M 500 -m #以MSS500 发送数据流量" print " 应当流量都在队列2 class 1:2 中处理. 如修改端口号为 5003 则在 1:3 队列处理" print " 如 iperf -b 带宽超过QoS瓶颈之上, 应该能看到当前队列增加 ( backlog 100p ) 至TX_QUEUELEN后, 丢包(dropped)数开始增加" print " 当发送流量过高 时, s1-eth3 发生拥塞" print " 检查端口拥塞状态: s1(xterm)> watch -n 0.1 tc -s -d qdisc show dev s1-eth3 " print "队列2 qdisc 的修改方法 " print " - 先删除: tc qdisc delete dev $NDEV parent 1:2 handle 2: ; \ " print " - 再新增RED: " \ "tc qdisc add dev $NDEV parent 1:2 handle 2: red limit 200000 min 50000 max 150000 avpkt 1000 ecn" # check = threading.Timer(5, checkTimer) # check.start() # killPing = threadTwo(2,5) # killPing.start() # thread = threadOne(1,7) # thread.start() # s1 = net.get('s1') # s1.sendCmd('ls') # s1.sendCmd('watch -n 0.1 tc -s -d class show dev s1-eth3') # s1 = net.getNodeByName('s1') # s1.sendCmd('ls') CLI(net) # 激活命令行交互 # cli.do_sh("ls") net.stop()
def main(): topo = DemoTopo(args.behavioral_exe, args.json) net = Mininet(topo=topo, host=P4Host, switch=P4Switch, controller=None) # creating new controllers with specified ip addr [not sure if port is needed] c1 = Controller('c1', ip='192.168.101.1/24', mac='00:00:00:01:00:00', port=6631) c2 = Controller('c2', ip="192.168.102.1/24", mac='00:00:00:02:00:00', port=6632) c3 = Controller('c3', ip="192.168.103.1/24", mac='00:00:00:03:00:00', port=6633) c4 = Controller('c4', ip="192.168.104.1/24", mac='00:00:00:04:00:00', port=6634) c5 = Controller('c5', ip="192.168.105.1/24", mac='00:00:00:05:00:00', port=6635) #print("c1 ip = ", c1.ip()) #add newly created controlers to net (Mininet object, not Topo(!)) for c in [c1, c2, c3, c4, c5]: net.addController(c) c.start() #print("c1 ip = ", c1.ip()) #... s1 = net.get('s1') s2 = net.get('s2') s3 = net.get('s3') s4 = net.get('s4') s5 = net.get('s5') #Links between controlers and switches net.addLink(s1, c1, port1=4) net.addLink(s2, c2, port1=4) net.addLink(s3, c3, port1=4) net.addLink(s4, c4, port1=4) net.addLink(s5, c5, port1=4) #print("c1 ip = ", c1.ip()) #start switches with controllers s1.start([c1]) s2.start([c2]) s3.start([c3]) s4.start([c4]) s5.start([c5]) #net.start() #switch 1 configuration s1.setIP('192.168.1.1/24', intf='s1-eth0') s1.setMAC('00:00:00:00:01:00', intf='s1-eth0') s1.setIP('192.168.11.1/24', intf='s1-eth1') s1.setMAC('00:00:00:00:01:01', intf='s1-eth1') s1.setIP('192.168.12.1/24', intf='s1-eth2') s1.setMAC('00:00:00:00:01:02', intf='s1-eth2') #in/out ospf packets interface s1.setIP('192.168.101.2/24', intf='s1-eth4') s1.setMAC('00:00:00:00:01:04', intf='s1-eth4') #switch 2 configuration s2.setIP('192.168.2.1/24', intf='s2-eth0') s2.setMAC('00:00:00:00:02:00', intf='s2-eth0') s2.setIP('192.168.11.2/24', intf='s2-eth1') s2.setMAC('00:00:00:00:02:01', intf='s2-eth1') s2.setIP('192.168.13.2/24', intf='s2-eth2') s2.setMAC('00:00:00:00:02:02', intf='s2-eth2') s2.setIP('192.168.14.1/24', intf='s2-eth3') s2.setMAC('00:00:00:00:02:03', intf='s2-eth3') #in/out ospf packets interface s2.setIP('192.168.102.2/24', intf='s2-eth4') s2.setMAC('00:00:00:00:02:04', intf='s2-eth4') #switch 3 configuration s3.setIP('192.168.12.2/24', intf='s3-eth0') s3.setMAC('00:00:00:00:03:00', intf='s3-eth0') s3.setIP('192.168.15.1/24', intf='s3-eth1') s3.setMAC('00:00:00:00:03:01', intf='s3-eth1') s3.setIP('192.168.16.1/24', intf='s3-eth2') s3.setMAC('00:00:00:00:03:02', intf='s3-eth2') #in/out ospf packets interface s3.setIP('192.168.103.2/24', intf='s3-eth4') s3.setMAC('00:00:00:00:03:04', intf='s3-eth4') #switch 4 configuration s4.setIP('192.168.13.1/24', intf='s4-eth0') s4.setMAC('00:00:00:00:04:00', intf='s4-eth0') s4.setIP('192.168.15.2/24', intf='s4-eth1') s4.setMAC('00:00:00:00:04:01', intf='s4-eth1') s4.setIP('192.168.17.1/24', intf='s4-eth2') s4.setMAC('00:00:00:00:04:02', intf='s4-eth2') #in/out ospf packets interface s4.setIP('192.168.104.2/24', intf='s4-eth4') s4.setMAC('00:00:00:00:04:04', intf='s4-eth4') #switch 5 configuration s5.setIP('192.168.5.1/24', intf='s5-eth0') s5.setMAC('00:00:00:00:05:00', intf='s5-eth0') s5.setIP('192.168.14.2/24', intf='s5-eth1') s5.setMAC('00:00:00:00:05:01', intf='s5-eth1') s5.setIP('192.168.16.2/24', intf='s5-eth2') s5.setMAC('00:00:00:00:05:02', intf='s5-eth2') s5.setIP('192.168.17.2/24', intf='s5-eth3') s5.setMAC('00:00:00:00:05:03', intf='s5-eth3') #in/out ospf packets interface s5.setIP('192.168.105.2/24', intf='s5-eth4') s5.setMAC('00:00:00:00:05:04', intf='s5-eth4') #hosts default r h1 = net.get('h1') h1.setDefaultRoute("dev h1-eth0 via 192.168.1.1") h2 = net.get('h2') h2.setDefaultRoute("dev h2-eth0 via 192.168.2.1") h5 = net.get('h5') h5.setDefaultRoute("dev h5-eth0 via 192.168.5.1") print "Ready !" # print("c1 ip = ", c1.ip()) CLI(net) net.stop()
def emptyNet(): "Create an empty network and add nodes to it." net = Mininet( controller=Controller) info( '*** Adding controller\n' ) ctrlRemote = RemoteController( 'c0', ip=ipControladorOF ) net.addController(ctrlRemote) info('--> remote IP controller - c0:' + ctrlRemote.IP() +'\n') #ctrlLocal = RemoteController('c1', port=6633, ip="127.0.0.1") ctrlLocal = Controller('c1', port=6634) net.addController(ctrlLocal) info('--> local IP controller - c1:' + ctrlLocal.IP() +'\n') info( '*** Adding hosts\n' ) lanH1 = net.addHost('h1', ip='10.0.0.1') lanH2 = net.addHost('h2', ip='10.0.0.2') lanIDS = net.addHost('h3', ip='10.0.0.3') lanRouter = net.addHost('h4') wanH1 = net.addHost('h5', ip='192.168.0.5') wanH2 = net.addHost('h6', ip='192.168.0.6') info( '*** Adding switch\n' ) lanSw = net.addSwitch('s1') wanSw = net.addSwitch('s2') info( '*** Creating links\n' ) net.addLink(lanH1, lanSw) net.addLink(lanH2, lanSw) net.addLink(lanIDS, lanSw) net.addLink(lanRouter, lanSw) net.addLink(lanRouter, wanSw) net.addLink(wanH1, wanSw) net.addLink(wanH2, wanSw) info( '*** Starting network\n') net.start() info('*** Starting controllers and switches') #link remote controller to s0 internal network swith ctrlRemote.start() #use remote controller lanSw.start([ctrlRemote]) #use local controller #info('\n\n\n************ using local controller for swLAN') #lanSw.start([ctrlLocal]) #start local controller to switch from s1 external network ctrlLocal.start() wanSw.start([ctrlLocal]) info( '*** Executing hosts scripts\n') execCmds(net) sleep(5) # wai 5 seconds to start IDS! #log tests in files, the name of file and directory will be composed by date/time of start execution of test hst1 = net.getNodeByName('h1') hst1.cmdPrint('mkdir /var/log/tcpdump/'+date) arquivo = open('/var/log/tcpdump/'+date+'/teste.txt', 'w') textoTeste = """ Test - \n Begin at:\n """ data = datetime.datetime.now() textoTeste=textoTeste+"%s/%s/%s as %s:%s:%s:%s\n"%(data.year,data.month,data.day,data.hour,data.minute,data.second,data.microsecond) arquivo.write(textoTeste) ### Tests # # Start the testes here! # # Select the test to run. For that uncomment the line of the desired test. info( '*** Executing Tests\n') textoTeste = textoTeste =teste1(net) #textoTeste = testeIperf(net) #textoTeste = testeIDSWakeupExternoInterno(net) #textoTeste = testeDDoSExtInt(net) #textoTeste = testeDDoSIntExt(net) #textoTeste = testeDDoSIntInt(net) # record attack test! textoTeste = textoTeste+""" put comment of test here """ arquivo.write(textoTeste) ### end of test! # register the time that test was finished data = datetime.datetime.now() textoTeste=' \nFinished at:\n '+"%s/%s/%s as %s:%s:%s:%s\n"%(data.year,data.month,data.day,data.hour,data.minute,data.second,data.microsecond) arquivo.write(textoTeste) arquivo.close() info( '*** Running CLI\n' ) #Uncomment below line for execute the test with CLI console #CLI( net ) sleep(5) info('*** Stoping IDS process\n') desligarIDS(net,'h3') #thIds.join() info( '*** Stopping network\n' ) lanSw.stop() ctrlRemote.stop() net.stop() exit()
def add_controller(): num = len(controllers) string = 'c' + str(num) c = Controller(string, inNamespace=False) controllers.append(c) return redirect(url_for('create'))
def __init__(self): self.num_switches = topologies.num_switches = 5 self.controller = Controller('c0') self.topology = topologies.topos['bus'] self.switch = OVSSwitch self.tests = []
def set_controller(self, controller): switch = {'remote': RemoteController, 'default': Controller('c0')} self.controller = switch[controller] return self
def topology(): "Create a network." net = Mininet(link=TCLink, switch=OVSSwitch) #create local controller for APs c0 = Controller('c0', port=6634) #create controller for s0 (Ryuretic) c1 = RemoteController('c1', ip='127.0.0.1', port=6633) net.addController(c0) net.addController(c1) print "*** Creating nodes" s0 = net.addSwitch('s0') ################## Create Rogue APs ############################### ap1 = net.addBaseStation('ap1', ssid="ssid_ap1", channel="1", mode="g", range='20') ap3 = net.addBaseStation('ap3', ssid="ssid_ap3", mode="g", channel="6", range='20') ################ Create Rogue Stations ############################# sta1 = net.addStation('sta1', ip='192.168.0.11/24', mac='AA:BB:BB:BB:BB:01', defaultRoute='via 192.168.0.224') sta2 = net.addStation('sta2', ip='192.168.0.12/24', mac='AA:BB:BB:BB:BB:02', defaultRoute='via 192.168.0.224') sta3 = net.addStation('sta3', ip='192.168.0.13/24', mac='AA:BB:BB:BB:BB:03', defaultRoute='via 192.168.0.224') sta4 = net.addStation('sta4', ip='10.0.0.1/24', mac='AA:BB:BB:BB:BB:11', defaultRoute='via 10.0.0.22') sta5 = net.addStation('sta5', ip='10.0.0.2/24', mac='AA:BB:BB:BB:BB:12', defaultRoute='via 10.0.0.22') sta6 = net.addStation('sta6', ip='10.0.0.3/24', mac='AA:BB:BB:BB:BB:13', defaultRoute='via 10.0.0.22') ################## Create Hosts #################################### h1 = net.addHost('h1', ip='192.168.0.1', mac='AA:AA:AA:AA:AA:01', defaultRoute='via 192.168.0.224') h2 = net.addHost('h2', ip='192.168.0.2', mac='AA:AA:AA:AA:AA:02', defaultRoute='via 192.168.0.224') h3 = net.addHost('h3', ip='192.168.0.3', mac='AA:AA:AA:AA:AA:03', defaultRoute='via 192.168.0.224') h4 = net.addHost('h4', ip='192.168.0.4', mac='AA:AA:AA:AA:AA:04', defaultRoute='via 192.168.0.224') h5 = net.addHost('h5', ip='192.168.0.5', mac='AA:AA:AA:AA:AA:05', defaultRoute='via 192.168.0.224') h6 = net.addHost('h6', ip='192.168.0.6', mac='AA:AA:AA:AA:AA:06', defaultRoute='via 192.168.0.224') ################## Wireless AP Interface ############################# print "*** Adding Link" wl_bw = 15 wl_delay = '5ms' wl_loss = 10 net.addLink(ap1, sta1, bw=wl_bw, loss=wl_loss, delay=wl_delay) net.addLink(ap1, sta2, bw=wl_bw, loss=wl_loss, delay=wl_delay) net.addLink(ap1, sta3, bw=wl_bw, loss=wl_loss, delay=wl_delay) ##################### NAT1 Interface ############################### net.addLink(ap3, sta4, bw=wl_bw, loss=wl_loss, delay=wl_delay) net.addLink(ap3, sta5, bw=wl_bw, loss=wl_loss, delay=wl_delay) net.addLink(ap3, sta6, bw=wl_bw, loss=wl_loss, delay=wl_delay) ##################### Link devices to Switch ######################## w_delay = '3ms' net.addLink(ap1, s0, bw=15, delay=w_delay) net.addLink(h1, s0, bw=15, delay=w_delay) net.addLink(h2, s0, bw=15, delay=w_delay) net.addLink(h3, s0, bw=15, delay=w_delay) net.addLink(h4, s0, bw=15, delay=w_delay) net.addLink(h5, s0, bw=15, delay=w_delay) net.addLink(h6, s0, bw=15, delay=w_delay) ###################### Create NAT for Internet ####################### nat = net.addHost('nat', cls=NAT, ip='192.168.0.224', mac='AA:AA:AA:AA:02:24', subnet='192.168.0.0/24', inNamespace=False) net.addLink(nat, s0, bw=50) ########################### Create RAP ######################## nat1 = net.addHost('nat1', cls=NAT, ip='192.168.0.22', mac='AA:AA:AA:AA:00:22', subnet='10.0.0.0/24', inNameSpace=False, inetIntf='nat1-eth0', localIntf='nat1-eth1', defaultRoute='via 192.168.0.224') net.addLink(nat1, s0, bw=15, delay=w_delay) net.addLink(ap3, nat1, bw=15, delay='2ms') ######################### Build Topology ########################## net.build() ######################### Start Topology ########################## c0.start() c1.start() ap1.start([c0]) ap3.start([c0]) s0.start([c1]) ######################## Add RAP Interface ########################## nat1.setIP('10.0.0.22/8', intf='nat1-eth1') print "*** Running CLI" CLI(net) print "*** Stopping network" net.stop()
def topology(): "Create a network." net = Mininet(link=TCLink, switch=OVSSwitch) #create local controller for APs c0 = Controller('c0', port=6634) #create controller for s0 (Ryuretic) c1 = RemoteController('c1', ip='127.0.0.1', port=6633) net.addController(c0) net.addController(c1) print "*** Creating nodes" s0 = net.addSwitch('s0') ap1 = net.addBaseStation('ap1', ssid="ssid_ap1", mode="g", channel="5") ap2 = net.addBaseStation('ap2', ssid="ssid_ap2", mode="g", channel="1") ########### ap3 = net.addBaseStation('ap3', ssid="ssid_ap3", mode="g", channel="10") sta1 = net.addStation('sta1', ip='192.168.0.1/24', defaultRoute='via 192.168.0.224') sta2 = net.addStation('sta2', ip='192.168.0.2/24', defaultRoute='via 192.168.0.224') sta3 = net.addStation('sta3', ip='192.168.0.3/24', defaultRoute='via 192.168.0.224') sta4 = net.addStation('sta4', ip='192.168.0.4/24', defaultRoute='via 192.168.0.224') ############# sta5 = net.addStation('sta5', ip='10.0.0.2/24', defaultRoute='via 10.0.0.22') sta6 = net.addStation('sta6', ip='10.0.0.3/24', defaultRoute='via 10.0.0.22') ############# h1 = net.addHost('h1', ip='192.168.0.5', defaultRoute='via 192.168.0.224') h2 = net.addHost('h2', ip='192.168.0.6', defaultRoute='via 192.168.0.224') print "*** Adding Link" net.addLink(sta1, ap1, bw=10, loss=0) net.addLink(sta2, ap1, bw=10, loss=0) net.addLink(sta3, ap2, bw=10, loss=0) net.addLink(sta4, ap2, bw=10, loss=0) ############### net.addLink(sta5, ap3, bw=10, loss=0) net.addLink(sta6, ap3, bw=10, loss=0) net.addLink(ap1, s0) net.addLink(ap2, s0) net.addLink(h1, s0) net.addLink(h2, s0) ###### ############################################################## #Add NAT granting access to Internet nat = net.addHost('nat', cls=NAT, ip='192.168.0.224', subnet='192.168.0.0/24', inNamespace=False) net.addLink(nat, s0) ############################################################## #Create RAP nat1 = net.addHost('nat1', cls=NAT, ip='192.168.0.22', subnet='10.0.0.0/24', inNameSpace=False, inetIntf='nat1-eth0', localIntf='nat1-eth1', defaultRoute='via 192.168.0.224') net.addLink(nat1, s0) net.addLink(ap3, nat1) ############################################################### net.build() c0.start() c1.start() ap1.start([c0]) ap2.start([c0]) ap3.start([c0]) s0.start([c1]) nat1.setIP('10.0.0.22/8', intf='nat1-eth1') print "*** Running CLI" CLI(net) print "*** Stopping network" net.stop()
#!/usr/bin/python from mininet.topo import Topo from mininet.net import Mininet from mininet.node import OVSSwitch, Controller, RemoteController from mininet.util import dumpNodeConnections from mininet.log import setLogLevel setLogLevel( 'info' ) # Two local and one "external" controller (which is actually c0) # Ignore the warning message that the remote isn't (yet) running c0 = RemoteController( 'c0', ip='127.0.0.1', port=6633 ) c1 = Controller( 'c1', port=6634 ) c2 = Controller( 'c2', port=6633) cmap = { 'c0': c1&c2 ,'s1': c1, 's2': c2 } class MultiSwitch( OVSSwitch ): "Custom Switch() subclass that connects to different controllers" def start( self, controllers ): return OVSSwitch.start( self, [ cmap[ self.name ] ] ) topo = TreeTopo( depth=2, fanout=2 ) net = Mininet( topo=topo, switch=MultiSwitch, build=False ) for c in [ c0, c1 ]: net.addController(c) net.build() class MyFirstTopo( Topo ):
""" Create a network where different switches are connected to different controllers, by creating a custom Switch() subclass. """ from mininet.net import Mininet from mininet.node import OVSSwitch, Controller, RemoteController from mininet.topolib import TreeTopo from mininet.log import setLogLevel from mininet.cli import CLI setLogLevel('info') # Two local and one "external" controller (which is actually c0) # Ignore the warning message that the remote isn't (yet) running c0 = Controller('c0') c1 = Controller('c1') c2 = RemoteController('c2', ip='127.0.0.1') cmap = {'s1': c0, 's2': c1, 's3': c2} class MultiSwitch(OVSSwitch): "Custom Switch() subclass that connects to different controllers" def start(self, controllers): return OVSSwitch.start(self, [cmap[self.name]]) topo = TreeTopo(depth=2, fanout=2) net = Mininet(topo=topo, switch=MultiSwitch, build=False)
#!/usr/bin/python import sys from mininet.node import Host, OVSSwitch, Controller from mininet.link import Link n = sys.argv[1] c1 = Controller( 'c1', inNamespace=False ) i = 1 while( i <= n ): a1 = OVSSwitch( 'a%d', inNamespace=False) % (i) Link( c1, ai ) i = i + 1 i = 1 count = 1 while( i <= n ** 2): e1 = OVSSwitch( 'e%d', inNamespace=False ) % (i) Link( acount, ei ) if i == n: count = count + 1 i = i + 1 i = 1 count = 1 while( i <= n ** 3) : h1 = Host( 'h%d' ) % (i) Link( ecount, hi ) hi.setIP( '10.0.0.1/24' ) if i == n: count = count + 1
def ClusterController(*args, **kwargs): "Custom Controller() constructor which updates its eth0 IP address" controller = Controller(*args, **kwargs) # Find out its IP address so that cluster switches can connect Intf('eth0', node=controller).updateIP() return controller
#!/usr/bin/python """ Create a network where different switches are connected to different controllers, by creating a custom Switch() subclass. """ from mininet.net import Mininet from mininet.node import OVSSwitch, Controller, RemoteController from mininet.topolib import TreeTopo from mininet.cli import CLI # Set up two local controllers controller0 = Controller('controller0', port=6633) controller1 = Controller('controller1', port=6634) controllerMap = {'s1': controller0, 's2': controller1} class MultipleSwitch(OVSSwitch): def start(self, controllers): return OVSSwitch.start(self, [controllerMap[self.name]]) topo = TreeTopo(depth=2, fanout=2) net = Mininet(topo=topo, switch=MultiSwitch, build=False) for c in [controller0, controller1]: net.addController(c) net.build() net.start() CLI(net) net.stop()
#!/usr/bin/python from mininet.node import Host, OVSSwitch, Controller from mininet.link import Link h1 = Host('h1') h2 = Host('h2') h3 = Host('h3') h4 = Host('h4') s1 = OVSSwitch('s1', inNamespace=False) s2 = OVSSwitch('s2', inNamespace=False) c0 = Controller('c0', inNamespace=False) Link(h1, s1) Link(h2, s1) Link(h3, s2) Link(h4, s2) Link(s1, s2) h1.setIP('10.0.0.1/24') h2.setIP('10.0.0.2/24') h3.setIP('10.0.0.3/24') h4.setIP('10.0.0.4/24') c0.start() s1.start([c0]) s2.start([c0]) print h1.IP print h2.IP print h3.IP print h4.IP print 'Pinging ...' print h1.cmd('ping -c3 ', h2.IP()) print h1.cmd('ping -c3 ', h3.IP())
prefix = path.dirname( sys.argv[0]) if len(path.dirname(sys.argv[0])) != 0 else '.' setLogLevel('info') # #setLogLevel( 'debug' ) try: exec(open(sys.argv[1]).read()) conf = config['conf'] if config['conf'][0] == '/' else path.join( prefix, config['conf']) controllers = {} for c in config['controllers']: controller_ip, controller_port = config['controllers'][c] if controller_ip is None: c0 = Controller(c, port=controller_port) else: c0 = RemoteController(c, ip=controller_ip, port=controller_port) controllers[c] = c0 for intfName in config['phys']: checkIntf(intfName) cmap = {} for s in config['switches']: cmap[s] = controllers[config['switches'][s]] class MultiSwitch(OVSSwitch): "Custom Switch() subclass that connects to different controllers" def start(self, controllers): return OVSSwitch.start(self, [cmap[self.name]])
def ecn_qos_init(remote=False): """ :param remote 是否使用外部控制器 :return: Create and test our QBB network standard" 初始化拓扑qos; 包括 四个存在带宽差异(big_link small_link)导致拥堵点的链路 qos 带宽 s1-eth3 s2-eth3 s3-eth3 s4-eth1 将 5002, h1, icmp 所有流量转移到队列2中, 便于测试 """ topo = ECNTopo() # global net # MMininet 类 API 参考: http://mininet.org/api/classmininet_1_1net_1_1Mininet.html#a1ed0f0c8ba06a398e02f3952cc4c8393 # 命令行参数对应 --mac => autoSetMacs # 命令行参数对应 --arp => autoStaticArp # 命令行参数对应 -x => xterms net = Mininet(topo=topo, controller=None, link=ecn_util.ECNLink, autoSetMacs=True, xterms=False, autoStaticArp=True) if remote: # ecn_qdisc_helper.os_popen("PYTHONPATH=/opt/ryu/ /opt/ryu/bin/ryu-manager # ryu.app.rest_qos cuc.book.qos_simple_switch_13 ryu.app.rest_conf_switch & ") net.addController('c0', controller=RemoteController, ip='127.0.0.1', port=6653) else: c0 = Controller('c0', port=6633) # buildin-controller net.addController(c0) enable_ssh = False # 激活ssh如果系统 - 暂时不用 if enable_ssh: setup_ssh() else: net.start() # 手工添加给 dpctl 使用的 s1 交换机的 6634 监听端口 (Why? 为什么用命令行增加的交换机不用手工加这个参数? ) # 这样可以使用命令 dpctl dump-flows tcp:127.0.0.1:6634 查询内核流表 ecn_qdisc_helper.os_popen( 'ovs-vsctl --id=@s1c0 create Controller target="tcp\:127.0.0.1\:6633" max_backoff=1000 ' '-- --id=@s1-listen create Controller target="ptcp\:6634" max_backoff=1000 ' '-- set bridge s1 controller=[@s1c0,@s1-listen] ') if remote: print "*** run this command for remote ryu controller" print "cd /opt/ryu; PYTHONPATH=/opt/ryu/ /opt/ryu/bin/ryu-manager " \ "ryu.app.rest_qos cuc.book.qos_simple_switch_13 ryu.app.rest_conf_switch " setup_server(net) background = False # 激活后台流量 - 暂时不用 if background: # backgroud traffice, net.get("h1").cmd("netperf -H h3 -l %s &" % 3600) # ecn_util.print_mininet_objs(net) # 打印 mininet 拓扑对象 # ecn_test_case.test_diff_bw(net) # 设置不同带宽条件qos, 并使用 iperf测试 # ecn_test_case.test_diff_latency(net) # 设置不同延时条件qos, 并使用 ping 测试 # ecn_test_case.test01_06_setup_queue_and_latency(net) # 初始化 TEST01_06 拓扑 qos # no ecn 测试 # ecn_test_case.test01_base(net, "TEST01", duration=60) # 独立测试TEST 01 # ecn_red red ecn # ecn_test_case.test02_04_base_ecn_red(net, "red-ecn-200000", # redminmax="min 200000 max 300000 avpkt 1500", duration=60) # ecn_test_case.test01_04_ecn_red_duration(net, duration=(60, 180)) # 设置不同时长, 进行TEST01-04测试 # red ecn 进行TEST01-04测试 # ecn_test_case.test01_04_ecn_red(net, duration=10) # - openflow ecn # -- ecn_ip 多组测试 queue_mins = range(80000, 80001) # only 1 test # queue_mins = range(80000, 80002) # 2 test # queue_mins = range(80000, 80003) # 3 test ecn_test_case.ovs_openflow_ecn(net, "openflow-ecn_ip-", duration=60, qmins=queue_mins, wait_seconds=10, ecn_tcp_flag=False) # -- ecn_tcp 多组测试 # ecn_test_case.ovs_openflow_ecn(net, "openflow-ecn_tcp-", duration=120, # qmins=queue_mins, wait_seconds=1, ecn_tcp_flag=True) CLI(net) # 激活命令行交互 net.stop() clean_server(net) # 清楚所有残留服务
#!/usr/bin/python """ Create a network where different switches are connected to different controllers, by creating a custom Switch() subclass. """ from mininet.net import Mininet from mininet.node import OVSSwitch, Controller from mininet.topolib import TreeTopo from mininet.cli import CLI c0 = Controller('c0') c1 = Controller('c1', ip='127.0.0.2') cmap = {'s1': c0, 's2': c1, 's3': c1} class MultiSwitch(OVSSwitch): "Custom Switch() subclass that connects to different controllers" def start(self, controllers): return OVSSwitch.start(self, [cmap[self.name]]) topo = TreeTopo(depth=2, fanout=2) net = Mininet(topo=topo, switch=MultiSwitch, build=False) net.controllers = [c0, c1] net.build() net.start() CLI(net) net.stop()