elif options.topology == 'ufrgs': topo = UFRGSTopo() elif options.topology == 'fattree': topo = FatTree(num_pods=options.pods) # Setting mininet configuration setLogLevel('info') # Adding root host root = Host('root', inNamespace=False) # Adding the remote controller net = Mininet(topo=topo, link=TCLink, autoSetMacs=True, controller=lambda name: RemoteController(name, ip=options.ip)) for host in net.hosts: host.linkTo(root) # Start the network net.start() # Waiting for apache starts file_server = 0 video_server = 1 net.hosts[file_server].cmd('service apache2 restart') net.hosts[video_server].cmd( 'su - efcastillo -c \'vlc -vvv /var/www/videoplayback.mp4 --sout "#standard{access=http,mux=asf,dst=:8080}"\' &' )
if ips: error('Error:', intf, 'has an IP address,' 'and is probably in use!\n') exit(1) if __name__ == '__main__': setLogLevel('info') # try to get hw intf from the command line; by default, use eth1 intfName = sys.argv[1] if len(sys.argv) > 1 else 'eth1' info('*** Connecting to hw intf: %s' % intfName) info('*** Checking', intfName, '\n') checkIntf(intfName) info('*** Creating network\n') net = Mininet(topo=MyTopo(), controller=None) #关键函数,创建mininet网络,指定拓扑和控制器。这里的控制器在后面添加进去 switch = net.switches[0] #取第一个交换机与eth1桥接 info('*** Adding hardware interface', intfName, 'to switch', switch.name, '\n') _intf = Intf(intfName, node=switch) #最关键的函数,用作把一个网卡与一个交换机桥接 info( '*** Note: you may need to reconfigure the interfaces for ' 'the Mininet hosts:\n', net.hosts, '\n') c0 = RemoteController('c0', ip='127.0.0.1', port=6633) net.addController(c0) net.start() CLI(net) net.stop()
#host2 = self.addHost('host2', cls=SdnipHost, ips=ips2, gateway='2.0.0.254') # Set up data plane connectivity #self.addLink( router, peer1 ) #self.addLink( router, peer2 ) #self.addLink( peer1, host1 ) #self.addLink( peer2, host2 ) # Set up management plane and connectivity if __name__ == "__main__": setLogLevel('debug') topo = SDNTopo() remoteController = RemoteController('onos', ip='192.168.2.103', port=6633) net = Mininet(topo=topo, controller=remoteController, switch=OVSSwitch) # addting the eth1 and eth2 to the router router = net.switches[0] Intf("eth1", router) Intf("eth2", router) Intf("eth3", router) net.start() CLI(net) net.stop() info("done\n")
def myTopo ( key ): net=Mininet(listenPort=6634,autoSetMacs=True,ipBase='10.0.0.0/8',autoStaticArp=False) info( "****creating network****\n" ) info('****add controller****\n') mycontroller=RemoteController("floodlight",ip="192.168.0.18",port=6633) net.addController(mycontroller) info('****add core switches****\n') for i in range( 1, key*key/4+1 ): switch_c = net.addSwitch( 's%d%d' %(key+1,i) ) info('****add aggregation switches****\n') for i in range( 1, key+1 ): for j in range( 1, key/2+1 ): switch_au = net.addSwitch( 's%d%d' %(i,j) ) for j in range( key/2+1, key+1 ): switch_ad = net.addSwitch( 's%d%d' %(i,j) ) info('****add hosts****\n') for i in range( 1, key*key*key/4+1 ): host = net.addHost( 'h%d' %i ) info('****add links between core switches and aggregation switches****\n') for i in range( 1, key*key/4+1 ): switch_c = net.get( 's%d%d' %(key+1,i) ) for j in range( 1, key+1 ): swtich_au = net.get( 's%d%d' %(j,(i-1)/(key/2)+1) ) net.addLink( switch_c, swtich_au ) info('****Add links between two layer aggregation switches****\n') for i in range( 1, key+1 ): for j in range( 1, key/2+1 ): switch_au = net.get( 's%d%d' %(i,j) ) for k in range( key/2+1, key+1 ): switch_ad = net.get( 's%d%d' %(i,k) ) net.addLink( switch_au, switch_ad ) info('****Add links between aggregation switches and hosts****\n') for i in range( 1, key+1 ): for j in range( 1, key/2+1 ): switch_ad = net.get( 's%d%d' %(i,j+key/2) ) for k in range( 1, key/2+1 ): host = net.get( 'h%d' %((i-1)*key*key/4+(j-1)*(key/2)+k ) ) net.addLink( switch_ad, host ) info('****starting network****\n') net.start() CLI(net) net.stop()
def simpleTest(): print("infection hosts rate:") inf_rate = eval(input()) print("amplituda (packets per second):") max = eval(input()) print("period T:") grow_time = eval(input()) / 2 atck_time = 40 test_time = 50 controller = RemoteController('Runos', ip='127.0.0.1', port=6653) switch = partial(OVSKernelSwitch, protocols='OpenFlow13') net = TreeNet(depth=2, fanout=3, controller=controller, switch=switch, cleanup=True) net.start() sleep(3) hosts = net.topo.hosts() inf_amount = round(inf_rate * len(hosts)) inf_hosts = [] while inf_amount: num = randint(0, 8) if inf_amount and not (hosts[num] in inf_hosts): inf_hosts.append(hosts[num]) inf_amount -= 1 print(inf_hosts) general_capacity_per_sec = max / len(inf_hosts) connection_interval = grow_time / len(inf_hosts) send_delay_for_host = round(1000 / general_capacity_per_sec) print(send_delay_for_host) infection_sequence = numpy.arange(len(inf_hosts)) numpy.random.shuffle(infection_sequence) start = monotonic() childs = [] for i in range(len(hosts)): try: pid = os.fork() except: print('error: create child process') sys.exit(33) if pid == 0: host = net.get(hosts[i]) if hosts[i] in inf_hosts: index = inf_hosts.index(hosts[i]) host_turn = connection_interval * infection_sequence[index] ping_pair = net.get(hosts[i - 1]) curr_time = monotonic() - start interval = ( 2.5 + host_turn - curr_time) if (2.5 + host_turn - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), ping_pair.IP(), interval)) host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (ping_pair.IP(), interval)) ping_pair = net.get(hosts[i - 2]) curr_time = monotonic() - start interval = ( 5 + host_turn - curr_time) if (5 + host_turn - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), ping_pair.IP(), interval)) host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (ping_pair.IP(), interval)) j = 0 while curr_time < atck_time + 5: curr_time = monotonic() - start sleep_time = 5 + (grow_time * 2) * j + host_turn - curr_time if sleep_time > 0: sleep(sleep_time) curr_time = monotonic() - start interval = 5 + grow_time if (5 + grow_time) >= 1 else 1 if (curr_time + interval) > atck_time + 5: interval = atck_time + 5 - curr_time print("curr_time=%s :: %s start attack" % (curr_time, host.IP())) host.cmd( "./runos/src/apps/ddos-defender/scripts/atckWithOpts.sh %s %s %s %s" % (host.MAC(), host.IP(), interval, send_delay_for_host)) curr_time = monotonic() - start while curr_time < test_time + 5: curr_time = monotonic() - start interval = ( 5 + test_time - curr_time) if (5 + test_time - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), ping_pair.IP(), interval)) host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (ping_pair.IP(), interval)) sleep(0.5) file_name = "atck_duration_" + str(i) + ".txt" handle = open(file_name, "w") handle.write( "'%s' : [%s, %s]" % (net.get(hosts[i]).IP(), 5 + host_turn, 5 + atck_time)) handle.close() else: ping_pair = net.get(hosts[i - 1]) curr_time = monotonic() - start interval = (5 - curr_time) if (5 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), ping_pair.IP(), interval)) host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (ping_pair.IP(), interval)) ping_pair = net.get(hosts[i - 2]) curr_time = monotonic() - start interval = (25 - curr_time) if (25 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), ping_pair.IP(), interval)) host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (ping_pair.IP(), interval)) ping_pair = net.get(hosts[i - 3]) curr_time = monotonic() - start interval = (50 - curr_time) if (50 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), ping_pair.IP(), interval)) host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (ping_pair.IP(), interval)) sys.exit(3) if pid > 0: childs.append(pid) for p in childs: pid, status = os.wait() print('childs end') host = net.get(hosts[0]) handleResult = open("runos/src/apps/ddos-defender/tests/infectedMACs.txt", "w") handleResult.write("{") for i in range(len(hosts)): if hosts[i] in inf_hosts: file_name = "atck_duration_" + str(i) + ".txt" handle = open(file_name, "r") result = handle.read() handleResult.write(result) if i < (len(hosts) - 1): handleResult.write(", ") handle.close() cmnd = "sudo rm " + file_name host.cmd(cmnd) handleResult.write("}") handleResult.close() CLI(net) net.stop()
def multiControllerNet(): net = Mininet(controller=Controller, switch=OVSSwitch, link=TCLink) info("*** Creating switches\n") s1 = net.addSwitch('s1') #switches for the data network s2 = net.addSwitch('s2') s5 = net.addSwitch('s5') s4 = net.addSwitch('s4') s3 = net.addSwitch('s3') #switch for the control network info("*** Creating hosts\n") agent1 = net.addHost('agent1', ip='10.0.0.11') agent2 = net.addHost('agent2', ip='10.0.0.21') client1 = net.addHost('client1', ip='10.0.0.111') server1 = net.addHost('server1', ip='10.0.0.211') #controller = net.addHost('controller', ip='10.0.2.150') #controller.cmd("cd /home/vagrant/sos-for-floodlight && java -jar target/floodlight.jar") info("*** Creating data links\n") net.addLink(s1, client1) net.addLink(s1, s4) net.addLink(s4, agent1) net.addLink(s1, s2, delay='100ms') net.addLink(s2, server1) net.addLink(s2, s5) net.addLink(s5, agent2) info("*** Creating control links\n") Link(agent1, s3, intfName1='agent1-eth1') agent1.cmd('ifconfig agent1-eth1 192.168.100.1 netmask 255.255.255.0') Link(agent2, s3, intfName1='agent2-eth1') agent2.cmd('ifconfig agent2-eth1 192.168.100.2 netmask 255.255.255.0') info("*** Starting network\n") net.build() makeTerms([agent1, agent2, server1, client1]) info("*** Creating controllers\n") local = net.addController('localctl', port=6633) #controller for control network local.start() s3.start([local]) info("*** Assigning IP to host interface\n") #call ('sudo', '/sbin/ifconfig', 's3', '192.168.100.10/24', 'up', shell=True) subprocess.Popen('sudo ifconfig s3 192.168.100.10/24 up', shell=True) remote = RemoteController( 'remotectl', ip='192.168.100.10', port=6653) #controller for data network (floodlight IP) remote.start() s1.start([remote]) s2.start([remote]) s4.start([remote]) s5.start([remote]) #info( "*** Testing network\n" ) #net.pingAll() #info( "*** Running CLI\n" ) CLI(net) #info( "*** Stopping network\n" ) cleanUpScreens() net.stop() local.stop()
def simpleTest(): topo = MultiSwitchTopo() net = Mininet(topo = topo, switch = OVSSwitch, controller= lambda name: RemoteController(name, ip= '127.0.0.1')) net.start() print("Dumping host connection") popens = {} for h in net.switches: if h.name=='s1': for n in range(10): randDelay = random.randint(1,3) h.cmdPrint("tc qdisc add dev s1-eth%d root netem delay %dms"%(n+1, randDelay)) elif h.name == 's2': for n in range(10): randDelay = random.randint(1,3) h.cmdPrint("tc qdisc add dev s2-eth%d root netem delay %dms"%(n+1, randDelay)) elif h.name == 's3': for n in range(10): randDelay = random.randint(1,5) h.cmdPrint("tc qdisc add dev s3-eth%d root netem delay %dms"%(n+1, randDelay)) elif h.name == 's4': for n in range(10): randDelay = random.randint(1,3) h.cmdPrint("tc qdisc add dev s4-eth%d root netem delay %dms"%(n+1, randDelay)) elif h.name == 's5': for n in range(10): randDelay = random.randint(1,4) h.cmdPrint("tc qdisc add dev s5-eth%d root netem delay %dms"%(n+1, randDelay)) elif h.name == 's6': for n in range(10): randDelay = random.randint(1,5) h.cmdPrint("tc qdisc add dev s6-eth%d root netem delay %dms"%(n+1, randDelay)) elif h.name == 's7': for n in range(10): randDelay = random.randint(1,5) h.cmdPrint("tc qdisc add dev s7-eth%d root netem delay %dms"%(n+1, randDelay)) #elif h.name == 's8': # for n in range(10): # randDelay = random.randint(1,4) # h.cmdPrint("tc qdisc add dev s8-eth%d root netem delay %dms"%(n+1, randDelay)) #elif h.name == 's9': # for n in range(10): # randDelay = random.randint(1,3) # h.cmdPrint("tc qdisc add dev s9-eth%d root netem delay %dms"%(n+1, randDelay)) #elif h.name == 's10': # for n in range(10): # randDelay = random.randint(1,5) # h.cmdPrint("tc qdisc add dev s10-eth%d root netem delay %dms"%(n+1, randDelay)) elif h.name == 's11': h.cmdPrint("tc qdisc add dev s1-eth11 root netem delay 5ms") elif h.name == 's12': h.cmdPrint("tc qdisc add dev s2-eth11 root netem delay 5ms") elif h.name == 's13': h.cmdPrint("tc qdisc add dev s3-eth11 root netem delay 5ms") elif h.name == 's14': h.cmdPrint("tc qdisc add dev s4-eth11 root netem delay 5ms") elif h.name == 's15': h.cmdPrint("tc qdisc add dev s5-eth11 root netem delay 5ms") elif h.name == 's16': h.cmdPrint("tc qdisc add dev s6-eth11 root netem delay 5ms") elif h.name == 's17': h.cmdPrint("tc qdisc add dev s7-eth11 root netem delay 5ms") #elif h.name == 's18': # h.cmdPrint("tc qdisc add dev s8-eth11 root netem delay 5ms") #elif h.name == 's19': # h.cmdPrint("tc qdisc add dev s9-eth11 root netem delay 5ms") #elif h.name == 's20': # h.cmdPrint("tc qdisc add dev s10-eth11 root netem delay 5ms") CLI(net)
def test_ovx(): try: ip = "127.0.0.1" port = 6633 info("*** Add remote controller\n") c = RemoteController("c", ip=ip, port=port) net = Containernet( autoStaticArp=True, autoSetMacs=True, controller=None, link=TCLink ) net.addController(c) info("*** Add switches, hosts and links \n") # Add core switches cores = {} for switch in CORES: cores[switch] = net.addSwitch(switch, dpid=(CORES[switch]["dpid"] % "0")) # Add hosts and connect them to their core switch for switch in CORES: for count in range(1, FANOUT + 1): # Add hosts host = "h_%s_%s" % (switch, count) ip = "10.0.0.%s" % count mac = CORES[switch]["dpid"][4:] % count h = net.addDockerHost(host, dimage="dev_test", ip=ip, mac=mac) # Connect hosts to core switches net.addLink(cores[switch], h) # Connect core switches net.addLink(cores["SFO"], cores["SEA"]) net.addLink(cores["SEA"], cores["SLC"]) net.addLink(cores["SFO"], cores["LAX"]) net.addLink(cores["LAX"], cores["SLC"]) net.addLink(cores["LAX"], cores["IAH"]) net.addLink(cores["SLC"], cores["MCI"]) net.addLink(cores["MCI"], cores["IAH"]) net.addLink(cores["MCI"], cores["ORD"]) net.addLink(cores["IAH"], cores["ATL"]) net.addLink(cores["ORD"], cores["ATL"]) net.addLink(cores["ORD"], cores["CLE"]) net.addLink(cores["ATL"], cores["IAD"]) net.addLink(cores["CLE"], cores["IAD"]) net.addLink(cores["CLE"], cores["EWR"]) net.addLink(cores["EWR"], cores["IAD"]) info("*** Start network... \n") net.start() print( "Hosts configured with IPs, switches pointing to OpenVirteX at %s:%s" % (ip, port) ) info("[OVX] Create a virtual network between SEA and LAX\n") wd = os.getcwd() os.chdir(OVXCTL_DIR) commands = [ # Create virtual networks "python2 ovxctl.py createNetwork tcp:{}:{} 10.0.0.0 16".format( SDN_CONTROLLER_IP, SDN_CONTROLLER_PORT ), # Create virtual switches "python2 ovxctl.py -n createSwitch 1 00:00:00:00:00:00:01:00", "python2 ovxctl.py -n createSwitch 1 00:00:00:00:00:00:02:00", "python2 ovxctl.py -n createSwitch 1 00:00:00:00:00:00:03:00", # Create virtual ports "python2 ovxctl.py -n createPort 1 00:00:00:00:00:00:01:00 1", "python2 ovxctl.py -n createPort 1 00:00:00:00:00:00:01:00 5", "python2 ovxctl.py -n createPort 1 00:00:00:00:00:00:02:00 5", "python2 ovxctl.py -n createPort 1 00:00:00:00:00:00:02:00 6", "python2 ovxctl.py -n createPort 1 00:00:00:00:00:00:03:00 5", "python2 ovxctl.py -n createPort 1 00:00:00:00:00:00:03:00 2", # Create virtual links "python2 ovxctl.py -n connectLink 1 00:a4:23:05:00:00:00:01 2 00:a4:23:05:00:00:00:02 1 spf 1", "python2 ovxctl.py -n connectLink 1 00:a4:23:05:00:00:00:02 2 00:a4:23:05:00:00:00:03 1 spf 1", # Connect hosts "python2 ovxctl.py -n connectHost 1 00:a4:23:05:00:00:00:01 1 00:00:00:00:01:01", "python2 ovxctl.py -n connectHost 1 00:a4:23:05:00:00:00:03 2 00:00:00:00:03:02", # Start virtual network "python2 ovxctl.py -n startNetwork 1", ] for cmd in commands: ret = check_output(sh_split(cmd), encoding="utf-8") print(ret) os.chdir(wd) CLI(net) except Exception as e: error(e) finally: net.stop()
class FourSwMeshTopo(Topo): "Four switch mesh topology with n hosts connected to each switch" def build(self, n=1): # create the switches fourMeshSw = {} for i in range(1, 5): j = i - 1 fourMeshSw[j] = self.addSwitch('of%d' % i, cls=OVSSwitch) while (j > 0): self.addLink('of%d' % i, 'of%d' % j) j = j - 1 # create n hosts for each switch and link them with switches for k in range(1, n + 1): self.addHost('h%d%d' % (i, k)) self.addLink('h%d%d' % (i, k), 'of%d' % i) if __name__ == '__main__': "Create network and test multicast packet delivery" net = Mininet( topo=FourSwMeshTopo(1), switch=OVSSwitch, controller=lambda a: RemoteController(a, ip='192.168.56.100')) net.start() CLI(net) net.stop()
## s3 = self.addSwitch( 's3', dpid=int2dpid(3) ) ## s4 = self.addSwitch( 's4', dpid=int2dpid(4) ) s1 = self.addSwitch( 's1', dpid='1' ) s2 = self.addSwitch( 's2', dpid='2' ) s3 = self.addSwitch( 's3', dpid='3' ) s4 = self.addSwitch( 's4', dpid='4' ) #info( '*** Creating links\n' ) self.addLink(h1, s1, port2=3 ) self.addLink(h2, s1, port2=4 ) self.addLink(h3, s4, port2=3 ) self.addLink(h4, s4, port2=4 ) self.addLink(s1, s2, port1=1, port2=1, bw=1 ) self.addLink(s2, s4, port1=2, port2=1, bw=1 ) self.addLink(s1, s3, port1=2, port2=1, bw=10) self.addLink(s3, s4, port1=2, port2=2, bw=10) topo = AssingmentTopology() net = Mininet(topo=topo, controller=lambda name: RemoteController(name, ip='127.0.0.1', protocol='tcp', port = 6633), link=TCLink) info( '*** Starting network\n') net.start() info( '*** Running CLI\n' ) CLI( net ) info( '*** Stopping network' ) net.stop()
def main(): ''' 1. Radomly selcect hosts and servers. 2. Repeat throughput test use fixed hosts. :return: ''' # 1. declare and parse arguments top_dir = os.path.join("result") if not os.path.exists(top_dir): os.makedirs(top_dir) subflow_num_start = 1 subflow_num_end = 9 test_name = 'test1' test_type = 'mptcp' # 0: random-based ecmp; 1:mptcp-awared load-balance #datacollection_step_time = 1 connection_interval_time = 5 connection_during_time = 30 # 2. createTopo topo = FatTreeTopo(k=4) link = custom(TCLink, bw=10) # , delay=args.delay) c0 = RemoteController(name='c0', ip='10.103.89.185', port=6633) #c0 = RemoteController(name='c0', ip='10.103.90.184', port=6633) net = Mininet(controller=c0, topo=topo, link=link, switch=OVSKernelSwitch) # c0 = net.addController('c0', ip='10.103.89.185', port=6633) net.start() countDown('Pepareing for test, remain time:%d....', 10) net.pingAll() hosts = list(net.hosts) host_count = len(hosts) client_hosts, server_hosts = selectHostsPairs(hosts) random.shuffle(client_hosts) c_hosts = client_hosts[0:host_count / 2] s_hosts = client_hosts[host_count / 2:host_count] # 3. start evaluation while True: test_flag = readTestFlag() if test_flag == False: break test_name = readTestName() test_dir = os.path.join(top_dir, test_name) test_type = readTestType() subflow_num_start = readStartSubflowNum() subflow_num_end = readEndSubflowNum() connection_interval_time = readConnectionInterval() connection_during_time = readConnectionDuringTime() test_info = "Test info,Test type:%s, Subflow num:%d--%d, Connection interval: %d, Connection during: %d" % ( test_type, subflow_num_start, subflow_num_end, connection_interval_time, connection_during_time) print test_info test_time = (len(net.hosts) - 1) * connection_interval_time + connection_during_time print('Test time: %d' % test_time) os.popen("sudo touch README.md") os.popen("sudo echo %s >> README.md" % test_info) print 'Start test ...' for subflow_num in range(subflow_num_start, subflow_num_end + 1): print 'Sub-test start,subflow num: %d.....' % subflow_num cmd_set_subflw = "echo '" + str( subflow_num ) + "' > /sys/module/mptcp_fullmesh/parameters/num_subflows" os.popen(cmd_set_subflw) throughput_test(net, test_dir, subflow_num, test_type, 1, connection_interval_time, connection_during_time, c_hosts, s_hosts) CLI(net) net.stop()
from time import sleep if __name__ == "__main__": config = ConfigParser.ConfigParser() config.read('./config') link_type = config.get('main', 'Distribution') number_switches = int(config.get('main', 'MainSwitches')) number_hosts = 0 number_servers = int(config.get('main', 'Datacenters')) ip = config.get('main', 'Ip') topology = RandomScaleFree(None, link_type, number_servers, number_switches, number_hosts) controller = RemoteController('c1', ip=ip, port=6633) print("Creating network") setLogLevel("info") network = Mininet(topo=topology, link=TCLink, controller=controller) print("Starting network") network.start() sleep(5) print("Running network") network.pingAll()
def start(ip="192.168.137.150", port=6633): classifier1_intfName = 'eth1' classifier2_intfName = 'eth2' sff1_intfName = 'eth3' sff2_intfName = 'eth4' # Set up logging etc. lg.setLogLevel('info') lg.setLogLevel('output') ctrlr = lambda n: RemoteController(n, ip=ip, port=port, inNamespace=False) ctrlr2 = RemoteController('2', ip='192.168.137.160', port=port, inNamespace=False) net = LINCNet(switch=OVSSwitch, controller=ctrlr, autoStaticArp=True, listenPort=6634) c1 = net.addController('c1') #c2 = net.addController('c2',controller=RemoteController, ip='192.168.137.62',port=6633) c2 = net.addController(ctrlr2) # Add hosts #h1 = net.addHost('h1') #h2 = net.addHost('h2') #h101 = net.addHost('h101') #h102 = net.addHost('h102') # Add packet switches to connect hosts to the optical network s1 = net.addSwitch('s1', dpid='00:00:00:00:00:00:00:01', protocols='OpenFlow10') s2 = net.addSwitch('s2', dpid='00:00:00:00:00:00:00:02', protocols='OpenFlow10') # Add optical switches r1 = net.addSwitch('r1', dpid='00:00:00:00:00:00:00:11', cls=LINCSwitch) r2 = net.addSwitch('r2', dpid='00:00:00:00:00:00:00:12', cls=LINCSwitch) r3 = net.addSwitch('r3', dpid='00:00:00:00:00:00:00:13', cls=LINCSwitch) r4 = net.addSwitch('r4', dpid='00:00:00:00:00:00:00:14', cls=LINCSwitch) r5 = net.addSwitch('r5', dpid='00:00:00:00:00:00:00:15', cls=LINCSwitch) r6 = net.addSwitch('r6', dpid='00:00:00:00:00:00:00:16', cls=LINCSwitch) r7 = net.addSwitch('r7', dpid='00:00:00:00:00:00:00:17', cls=LINCSwitch) r8 = net.addSwitch('r8', dpid='00:00:00:00:00:00:00:18', cls=LINCSwitch) # Connect hosts to packet switches #print "Adding physical hosts to mininet network..." _intf1 = Intf(classifier1_intfName, node=s1, port=1) _intf2 = Intf(sff1_intfName, node=s1, port=2) _intf3 = Intf(classifier2_intfName, node=s2, port=1) _intf4 = Intf(sff2_intfName, node=s2, port=2) #net.addLink(h1, s1) #net.addLink(h2, s2) #net.addLink(h101, s1) #net.addLink(h102, s2) linkopts = dict(bw=100, delay='1ms', max_queue_size=500, loss=0, use_htb=True) print "Adding Links..." # Connect packet switches to optical switches net.addLink(s1, r1, port1=3, port2=1, speed1=100, annotations={ "bandwidth": 100, "durable": "true" }, cls=LINCLink) net.addLink(s1, r1, port1=4, port2=2, speed1=100, annotations={ "bandwidth": 100, "durable": "true" }, cls=LINCLink) net.addLink(s2, r2, port1=3, port2=1, speed1=100, annotations={ "bandwidth": 100, "durable": "true" }, cls=LINCLink) net.addLink(s2, r2, port1=4, port2=2, speed1=100, annotations={ "bandwidth": 100, "durable": "true" }, cls=LINCLink) # Connect optical switches to each other net.addLink(r1, r3, port1=3, port2=1, speed1=100, annotations={ "bandwidth": 100, "durable": "true" }, cls=LINCLink) net.addLink(r1, r5, port1=4, port2=1, speed1=100, annotations={ "bandwidth": 100, "durable": "true" }, cls=LINCLink) net.addLink(r1, r6, 5, 1, cls=LINCLink) net.addLink(r1, r7, 6, 1, cls=LINCLink) net.addLink(r2, r4, 3, 2, cls=LINCLink) net.addLink(r2, r5, 4, 2, cls=LINCLink) net.addLink(r2, r6, 5, 2, cls=LINCLink) net.addLink(r2, r8, 6, 2, cls=LINCLink) net.addLink(r3, r4, 2, 1, cls=LINCLink) net.addLink(r7, r8, 2, 1, cls=LINCLink) # Start the network and prime other ARP caches net.start() # Uncomment below if using virtal hosts #net.staticArp() #Uncomment below if using physical hosts #print "Configuring ARP entries..." #utils.setStaticArp() # Enter CLI mode output("Network ready\n") output("Press Ctrl-d or type exit to quit\n") CLI(net) net.stop()
def runNetworkTopo(team_size, port, target_mode, extra_peers): "Bootstrap a Mininet network using the Minimal Topology" # Create an instance of our topology hosts = team_size + 1 topo = NetworkTopo(hosts, extra_peers) # Create a network based on the topology using OVS and controlled by # a remote controller. net = Mininet( topo=topo, controller=lambda name: RemoteController(name, ip='127.0.0.1'), switch=OVSSwitch, autoSetMacs=True) # Actually start the network net.start() print("IP splitter", net.hosts[hosts - 1].IP()) print(net.hosts[hosts - 1].cmd("echo -n a | nc -u -w 1 10.0.0.1 12345")) print(net.hosts[hosts - 1].cmd( "echo -n a | nc -u -w 1 11.0.0.{} 12345".format(hosts - 1))) id_host = 0 for host in net.hosts[0:-(4 + extra_peers)]: id_host += 1 do_log = " &" if __debug__: do_log = " > " + str(id_host) + ".log &" run_hp = "python3 -u dummy_hp.py -p " + str(port) + \ " -s 172.31.31." + str(hosts) + " -z " \ + str(team_size) + " -e " + str(extra_peers) \ + " --split" + str(do_log) host.cmd(run_hp) print(host, ":", run_hp) print("HPs running") if __debug__: id_host += 1 do_log = " > " + str(id_host) + ".log &" run_tp = "python3 -u dummy_tp.py -p " + str(port) + " -s 172.31.31." \ + str(hosts) + " -z " + str(team_size) + " -e " \ + str(extra_peers) + " --split" + str(do_log) net.hosts[-(4 + extra_peers)].cmd(run_tp) print(net.hosts[-(4 + extra_peers)], ":", run_tp) print("TP running") if __debug__: id_host += 1 do_log = " > " + str(id_host) + ".log &" if target_mode == 0: target = randint(1, team_size - 1) else: target = 0 run_mp = "python3 -u dummy_mp.py -p " + str(port) + " -s 172.31.31." \ + str(hosts) + " -z " + str(team_size) + " -t " + str(target) \ + " -e " + str(extra_peers) + " -e " + str(extra_peers) \ + " --split" + str(do_log) net.hosts[-(3 + extra_peers)].cmd(run_mp) print(net.hosts[-(3 + extra_peers)], ":", run_mp) print("MP running with traget = {}".format(target)) # Extra peers (peers out of the SDN) id_host += 1 # splitter id for host in net.hosts[-(1 + extra_peers):(hosts + extra_peers)]: id_host += 1 do_log = " &" if __debug__: do_log = " > " + str(id_host) + ".log &" run_hp = "python3 -u dummy_hp.py -p " + str(port) + \ " -s 172.31.31." + str(hosts) + " -z " \ + str(team_size) + " -e " + str(extra_peers) \ + " --split" + str(do_log) host.cmd(run_hp) print(host, ":", run_hp) print("HPs running in extra peers") print("Running splitter...") run_s = "python3 -u dummy_s.py -p " + str(port) + " -z " + str(team_size) \ + " -e " + str(extra_peers) + " --split" print(net.hosts[-(2 + extra_peers)], ":", run_s) results = net.hosts[-(2 + extra_peers)].cmd(run_s) print(results) # Drop the user in to a CLI so user can run commands. # CLI(net) # After the user exits the CLI, shutdown the network. net.stop()
#!/usr/bin/python from mininet.net import Mininet from mininet.node import RemoteController, OVSSwitch import netconstants as netconst from mininet.cli import CLI def ofp_version(switch, protocols): protocols_str = ','.join(protocols) command = 'ovs-vsctl set Bridge %s protocols=%s' % (switch, protocols_str) switch.cmd(command.split(' ')) if '__main__' == __name__: net = Mininet(switch=OVSSwitch) c_any = RemoteController('c_any', netconst.CTLR_AC_IP, netconst.PORT_CTLR) #c_any = RemoteController('c_any', netconst.CTLR_AC_IP, netconst.PORT_CTLR) net.addController(c_any) # add switches s1 = net.addSwitch('s1') # add host h1 = net.addHost('h1') net.addLink(s1, h1) # build net net.build() net.start() # start: Overridden to do nothing. c_any.start() ofp_version(s1, ['OpenFlow13']) # add command line interface CLI(net)
def multiControllerNet(): net = Mininet(controller=Controller, switch=OVSSwitch, link=TCLink) info("*** Creating switches\n") s1 = net.addSwitch('s1') #switches for the data network s2 = net.addSwitch('s2') s5 = net.addSwitch('s5') s4 = net.addSwitch('s4') s3 = net.addSwitch('s3') #switch for the control network info("*** Creating hosts\n") agent1 = net.addHost('agent1', ip='10.0.0.11') agent2 = net.addHost('agent2', ip='10.0.0.21') agent3 = net.addHost('agent3', ip='10.0.0.31') agent4 = net.addHost('agent4', ip='10.0.0.41') agent5 = net.addHost('agent5', ip='10.0.0.51') agent6 = net.addHost('agent6', ip='10.0.0.61') client1 = net.addHost('client1', ip='10.0.0.111') client2 = net.addHost('client2', ip='10.0.0.112') client3 = net.addHost('client3', ip='10.0.0.113') server1 = net.addHost('server1', ip='10.0.0.211') server2 = net.addHost('server2', ip='10.0.0.212') server3 = net.addHost('server3', ip='10.0.0.213') info("*** Creating data links\n") net.addLink( s1, client1, ) net.addLink(s1, client2) net.addLink(s1, client3) net.addLink(s1, s4) net.addLink(s4, agent1) net.addLink(s4, agent3) net.addLink(s4, agent5) net.addLink(s1, s2, delay='50ms') net.addLink(s2, server1) net.addLink(s2, server2) net.addLink(s2, server3) net.addLink(s2, s5) net.addLink(s5, agent2) net.addLink(s5, agent4) net.addLink(s5, agent6) info("*** Creating control links\n") Link(agent1, s3, intfName1='eth1') Link(agent2, s3, intfName1='eth1') Link(agent3, s3, intfName1='eth1') Link(agent4, s3, intfName1='eth1') Link(agent5, s3, intfName1='eth1') Link(agent6, s3, intfName1='eth1') agent1.cmd('ifconfig eth1 192.168.100.1 netmask 255.255.255.0') agent2.cmd('ifconfig eth1 192.168.100.2 netmask 255.255.255.0') agent3.cmd('ifconfig eth1 192.168.100.3 netmask 255.255.255.0') agent4.cmd('ifconfig eth1 192.168.100.4 netmask 255.255.255.0') agent5.cmd('ifconfig eth1 192.168.100.5 netmask 255.255.255.0') agent6.cmd('ifconfig eth1 192.168.100.6 netmask 255.255.255.0') info("*** Starting network\n") net.build() makeTerms([ agent1, agent2, agent3, agent4, agent5, agent6, server1, server2, server3, client1, client2, client3 ]) info("*** Creating controllers\n") local = net.addController('localctl', port=6633) #controller for control network local.start() s3.start([local]) info("*** Assigning IP to host interface\n") subprocess.Popen('sudo ifconfig s3 192.168.100.10/24 up', shell=True) remote = RemoteController( 'remotectl', ip='192.168.100.10', port=6663) #controller for data network (floodlight IP) remote.start() s1.start([remote]) s2.start([remote]) s4.start([remote]) s5.start([remote]) CLI(net) #info( "*** Stopping network\n" ) cleanUpScreens() local.stop() net.stop()
intfs = {'r1-eth0': {'ipAddrs': ['10.0.1.1/24', '2000::101/120'], 'mac': '00:88:00:00:00:01'}, 'r1-eth1': {'ipAddrs': ['10.0.99.1/16']}, 'r1-eth2': {'ipAddrs': ['2000::9901/120']}} r1 = self.addHost('r1', cls=BgpRouter, interfaces=intfs, quaggaConfFile='./bgpdr1.conf') self.addLink(r1, s205) # External IPv4 Host behind r1 rh1 = self.addHost('rh1', cls=RoutedHost, ips=['10.0.99.2/24'], gateway='10.0.99.1') self.addLink(r1, rh1) # External IPv6 Host behind r1 rh1v6 = self.addHost('rh1v6', cls=RoutedHost, ips=['2000::9902/120'], gateway='2000::9901') self.addLink(r1, rh1v6) topos = { 'trellis' : Trellis } if __name__ == "__main__": setLogLevel('debug') topo = Trellis() net = Mininet(topo=topo, controller=None) net.addController(RemoteController('c0', ip='192.168.56.11')) net.addController(RemoteController('c1', ip='192.168.56.12')) net.addController(RemoteController('c2', ip='192.168.56.13')) net.start() CLI(net) net.stop()
def RemoteControllerNet(): "Cria uma rede configurada manualmente com controlador remoto." net = Mininet( controller=RemoteController, switch=OVSSwitch, build=False ) print "*** Criando switches" SW1 = net.addSwitch( 'SW1' ) SW2 = net.addSwitch( 'SW2' ) SW3 = net.addSwitch( 'SW3' ) SW4 = net.addSwitch( 'SW4' ) print "*** Criando hosts e enlaces para os switches" hosts = {} for oct3 in range(10,31,10): for host in range(1,2+1): name = "h%d_%d" % (oct3,host) hosts[name] = net.addHost( name, ip='192.168.%d.%d/24' % (oct3, host), mac='02:00:00:00:%d:%d' % (oct3, host)) if oct3 == 10: net.addLink(hosts[name], SW1) elif oct3 == 20: net.addLink(hosts[name], SW2) elif oct3 == 30: net.addLink(hosts[name], SW3) print "*** Criando enlace entre os switches" net.addLink( SW4, SW1 ) net.addLink( SW4, SW2 ) net.addLink( SW4, SW3 ) print "*** Adicionando controlador remoto POX" c0 = RemoteController('POX_L2', ip='127.0.0.1', port=6633) c1 = RemoteController('POX_SR', ip='127.0.0.1', port=9000) print "*** Construindo e iniciando os elementos da rede" net.build() SW1.start([c1]) SW2.start([c1]) SW3.start([c1]) SW4.start([c0]) print "*** Configurando default GWs em cada host" for oct3 in range(10,31,10): for host in range(1,2+1): name = "h%d_%d" % (oct3,host) hosts[name].cmd('route add default gw 192.168.%d.254' % oct3) print "*** Imprimindo tabela de conexoes:" dumpNodeConnections(net.switches) print "*** Imprimindo DPIDs dos switches:" print "SW1:",SW1.dpid print "SW2:",SW2.dpid print "SW3:",SW3.dpid print "SW4:",SW4.dpid print "*** Iniciando CLI" CLI( net ) print "*** Parando a rede..." net.stop()
def topology(): # "Create a network." net = Mininet(controller=RemoteController, link=TCLink, switch=OVSKernelSwitch) _bw = 10 _latency = '5ms' _max_queue_size = 100 _use_htb = True _ip_remote_control = '127.0.0.1' _port_remote_control = 6653 adp_USB100MB_MAC = "00:13:3B:85:05:05" print "*** Creating Hosts" h1 = net.addHost('h1', mac="00:00:00:00:00:01", ip='192.168.2.1') h2 = net.addHost('h2', mac="00:00:00:00:00:02", ip='192.168.2.2') h3 = net.addHost('h3', mac="00:00:00:00:00:03", ip='192.168.2.3') h4 = net.addHost('h4', mac="00:00:00:00:00:04", ip='192.168.2.4') h5 = net.addHost('h5', mac="00:00:00:00:00:05", ip='192.168.2.5') h6 = net.addHost('h6', mac="00:00:00:00:00:06", ip='192.168.2.6') h7 = net.addHost('h7', mac="00:00:00:00:00:07", ip='192.168.2.7') h8 = net.addHost('h8', mac="00:00:00:00:00:08", ip='192.168.2.8') h9 = net.addHost('h9', mac="00:00:00:00:00:09", ip='192.168.2.9') h10 = net.addHost('h10', mac="00:00:00:00:00:10", ip='192.168.2.10') h11 = net.addHost('h11', mac="00:00:00:00:00:11", ip='192.168.2.11') # h12 = net.addHost( 'h12', mac="00:00:00:00:00:12", ip='192.168.2.12' ) # h13 = net.addHost( 'h13', mac="00:00:00:00:00:13", ip='192.168.2.13' ) hc = net.addHost('hc', mac="00:00:00:00:00:50", ip='192.168.2.50') hs1 = net.addHost('hs1', mac="00:00:00:00:00:51", ip='192.168.2.51') hs2 = net.addHost('hs2', mac="00:00:00:00:00:52", ip='192.168.2.52') print "*** Creating Switchs" s35 = net.addSwitch('s35', dpid='00:00:00:00:aa:bb:cc:35') s32 = net.addSwitch('s32', dpid='00:00:00:00:aa:bb:cc:32') s15 = net.addSwitch('s15', dpid='00:00:00:00:aa:bb:cc:15') s14 = net.addSwitch('s14', dpid='00:00:00:00:aa:bb:cc:14') s02 = net.addSwitch('s02', dpid='00:00:00:00:aa:bb:cc:02') s17 = net.addSwitch('s17', dpid='00:00:00:00:aa:bb:cc:17') s38 = net.addSwitch('s38', dpid='00:00:00:00:aa:bb:cc:38') print "*** Creating Controller Openflow" c0 = RemoteController('c0', ip=_ip_remote_control, port=_port_remote_control) print "*** Connecting hosts" net.addLink(h1, s32, bw=_bw, use_htb=_use_htb) net.addLink(h2, s38, bw=_bw, use_htb=_use_htb) net.addLink(h3, s38, bw=_bw, use_htb=_use_htb) net.addLink(h4, s38, bw=_bw, use_htb=_use_htb) net.addLink(h5, s02, bw=_bw, use_htb=_use_htb) net.addLink(h6, s02, bw=_bw, use_htb=_use_htb) net.addLink(h7, s02, bw=_bw, use_htb=_use_htb) net.addLink(h8, s17, bw=_bw, use_htb=_use_htb) net.addLink(h9, s17, bw=_bw, use_htb=_use_htb) net.addLink(h10, s17, bw=_bw, use_htb=_use_htb) net.addLink(h11, s35, bw=_bw, use_htb=_use_htb) # net.addLink(h12, s35, bw=_bw, use_htb=_use_htb) # net.addLink(h13, s35, bw=_bw, use_htb=_use_htb) net.addLink(hc, s32, bw=_bw, use_htb=_use_htb) net.addLink(hs1, s14, bw=_bw, use_htb=_use_htb) net.addLink(hs2, s15, bw=_bw, use_htb=_use_htb) print "*** Creating connection between switches" net.addLink(s35, s15, bw=_bw, latency=_latency, max_queue_size=_max_queue_size, use_htb=_use_htb) net.addLink(s35, s14, bw=_bw, latency=_latency, max_queue_size=_max_queue_size, use_htb=_use_htb) net.addLink(s32, s15, bw=_bw, latency=_latency, max_queue_size=_max_queue_size, use_htb=_use_htb) net.addLink(s32, s14, bw=_bw, latency=_latency, max_queue_size=_max_queue_size, use_htb=_use_htb) net.addLink(s15, s17, bw=_bw, latency=_latency, max_queue_size=_max_queue_size, use_htb=_use_htb) net.addLink(s15, s02, bw=_bw, latency=_latency, max_queue_size=_max_queue_size, use_htb=_use_htb) net.addLink(s14, s17, bw=_bw, latency=_latency, max_queue_size=_max_queue_size, use_htb=_use_htb) net.addLink(s14, s02, bw=_bw, latency=_latency, max_queue_size=_max_queue_size, use_htb=_use_htb) net.addLink(s02, s38, bw=_bw, latency=_latency, max_queue_size=_max_queue_size, use_htb=_use_htb) net.addLink(s17, s38, bw=_bw, latency=_latency, max_queue_size=_max_queue_size, use_htb=_use_htb) print "*** Starting network" net.build() c0.start() s35.start([c0]) s15.start([c0]) s17.start([c0]) s14.start([c0]) s32.start([c0]) s02.start([c0]) s38.start([c0]) try: #Run Floodlight in another terminal exec_floodlight = "cd ../floodlight && java -jar target/floodlight.jar > mcast_log.txt && exit" # exec_floodlight="cd ../floodlight && ant && java -jar target/floodlight.jar > mcast_log.txt && exit" os.system("gnome-terminal -x sh -c '" + exec_floodlight + " ; bash'") #wait time for compile and run Floodlight time.sleep(15) # net.pingAll() #Arquivo de log dos hosts os.system("rm -f scripts/mcast_v1/log.txt") # os.system("cd scripts/mcast_v1 && echo '' > log.txt") print "\n" #List of hots hosts = [h2, h3, h4, h5, h6, h7, h8, h9, h10, h11] #, h12, h13] #Start Server h1.cmd('cd scripts/mcast_v1 && python mc_server.py h1 >> log.txt &') print "H1 START " time.sleep(2) thread.start_new_thread(link_down, (net, )) thread.start_new_thread(link_iperf, (net, hc, hs1, hs2)) #Starts a host every 5 seconds for i in range(2, (len(hosts) + 2)): hosts[i - 2].cmd('cd scripts/mcast_v1 && python mc_client.py h' + str(i) + ' >> log.txt &') if (i == 2): os.system( "sudo tcpdump -i any -n -tt -v tcp port 6653 > evalvid/files/open_flow_mcast.txt &" ) # os.system("sudo tcpdump -i any -n -tt -v igmp > evalvid/files/igmp_mcast.txt &") print("H" + str(i) + " START") time.sleep(5) except Exception as e: print("Failed " + str(e)) try: time.sleep(15) os.system( "sudo kill -1 $(ps -C 'java -jar target/floodlight.jar' -o pid=)") time.sleep(1) os.system( "mv scripts/mcast_v1/log.txt evalvid/files && mv ../floodlight/mcast_log.txt evalvid/files" ) time.sleep(1) os.system("cd evalvid/files && sort -n -k1 log.txt -o log.txt") time.sleep(1) os.system( "sudo kill -1 $(ps -C 'sh -c cd ../floodlight && ant && java -jar target/floodlight.jar > mcast_log.txt' -o pid=)" ) # raw_input("\nPress Enter to continue...\n") # os.system("cd evalvid && ./evaluation_complete.sh h2 mcast_10h_5s_linkdown") finally: print "*** Stopping network" net.stop()
def myNet(): global brokennode brokennode = sys.argv[1] print(brokennode) net = Mininet( topo=GeneratedTopo(), controller=lambda a: RemoteController(a, ip='127.0.0.1', port=6633), host=CPULimitedHost, link=TCLink) #net=Mininet(topo=GeneratedTopo(),host=CPULimitedHost,link=TCLink) #net.addController('c0', RemoteController, ip="127.0.0.1",port=6633) print("Hello") #net.start() print("DUmping host coonnections") #dumpNodeConnections(net.hosts) net.start() print("host is OKJ") #sleep(10) while 'is_connected' not in quietRun('ovs-vsctl show'): sleep(1) print('.') print("Test pingall") print(type(net.hosts)) print(type(net.links)) global neighbors neighbors = {} global mac mac = {} f_neighbors = open('neighbors.txt', 'w') f_mac = open('mac.txt', 'w') for item in net.hosts: list_host = [] host_mac = {} print(type(item.name)) print(item.name) neighbors[item.name] = list_host mac[item.name] = host_mac for item in net.switches: list_switch = [] switch_mac = {} print(type(type(item.name))) print(item.name) neighbors[item.name] = list_switch mac[item.name] = switch_mac dic_temp = {} mac_all = {} for item in net.links: count1 = item.intf1.name.find('-') count2 = item.intf2.name.find('-') print(item.intf1.name[:count1]) print(item.intf2.name[:count2]) if item.intf1.name not in dic_temp: dic_temp[item.intf1.name] = 1 if item.intf2.name not in dic_temp: dic_temp[item.intf2.name] = 1 node1 = item.intf1.name[:count1] node2 = item.intf2.name[:count2] neighbors[node1].append(node2) neighbors[node2].append(node1) mac[node1][node2] = item.intf1.mac mac[node2][node1] = item.intf2.mac mac_all[item.intf1.name] = item.intf1.mac mac_all[item.intf2.name] = item.intf2.mac print(item.intf1.mac) print(item.intf2.mac) print(type(item.intf1.mac)) print(type(item.intf2.mac)) f_mac_all = open("mac_all.txt", 'w') for item in mac_all: f_mac_all.write(item + '\t' + mac_all[item] + '\t' + '\n') for item in neighbors: print(item + '\t') for temp in neighbors[item]: print(temp + '\t') f_neighbors.write(item + '\t' + temp + '\n') print('\n') for item in mac: print(item + '\t') for temp in mac[item]: print(temp + '\t') print(mac[item][temp] + '\n') f_mac.write(item + '\t' + temp + '\t' + mac[item][temp] + '\n') print('\n') f_neighbors.close() f_mac.close() """ h0=net.hosts[0] for item in net.hosts[1:]: h0.cmdPrint('ping -Q 0x64 -c 1 '+item.IP()) """ net.pingAll() f_temp = open('tcplook.sh', 'w') for item in dic_temp: f_temp.write('sudo tcpdump -i ' + item + ' -w ' + item + '.pcap' + ' &' + '\n') f_temp.close() global tcp_start tcp_start = time.time() os.system('sh -x tcplook.sh') #sleep(2) samples = 1 for i in range(samples): print(i) #event=random.randint(0,2) event = 0 h0 = net.hosts[0] h1 = net.hosts[1] h2 = net.hosts[2] #h0.cmdPrint('ping -Q 0x64 -c 1 '+h1.IP()) #sleep(3) if (event == 0): #normal(net,i) traffic(net, i) if (event == 1): brokenlink(net, i) if (event == 2): brokenswitch(net, i, brokennode) sleep(1) net.stop()
self.addLink(s[2], s[4]) #s3---s5 self.addLink(s[2], s[5], **linkopt1) #s3---s6 self.addLink(s[2], s[3]) #s3---s4 self.addLink(s[4], s[5]) #s5---s6 self.addLink(s[3], s[5], **linkopt2) #s4---s6 self.addLink(h[2], s[5]) #s6---h3 self.addLink(h[3], s[5]) #s6---h4 #topos = {'mytopo':(lambda:QosTopo())} if __name__ == '__main__': setLogLevel('info') net = Mininet(topo=QosTopo(), host=CPULimitedHost, link=TCLink, controller=RemoteController('paulController')) net.start() #net.iperf() "output host-port" # dumpNodeConnections(net.h) "output results of bradwidth between nodes" # h1,h2 = net.get('h1','h2') # print "testing bandwidth between h1 and h2" # net.iperf((h1,h2)) "run GUI to show xterm" # app = ConsoleApp( net, width=10 ) # app.mainloop() "show CLI recommand" CLI(net) net.stop()
def myNetwork(): net = Mininet(topo=None, build=False, ipBase='10.0.0.0/24') info(""" Creating the folow topology: +------------+ +----+ | controller | +----+ | h1 | +-----:------+ /---| h3 | +----+ +---:---+ +----+ +----+ +----+ \----------| swof1 |-----| r2 |----| s1 | +-------+ +----+ +----+ +----+ +----+ | |------| h4 | | h2 |--------------| +----+ +----+ ------------------------------------------------------------------------ DEVICE NAME IP:PORT DESCRIPTION ------------------------------------------------------------------------ switch_OpenFlow swof1 10.0.0.250/24 controller controller 127.0.0.1:6633 r2 r2 10.0.0.254/24 192.168.111.254/24 h1 h1 10.0.0.1/24 h2 h2 10.0.0.2/24 h3 h3 192.168.111.1/24 h4 h4 192.168.111.2/24 ------------------------------------------------------------------------ """) info('*** Adding controller\n') controller = RemoteController('controller', ip='127.0.0.1', protocol='tcp', port=6633) net.addController(controller) info('*** Add switches\n') swof1 = net.addSwitch('swof1', cls=OVSKernelSwitch) s1 = net.addSwitch('s1', cls=OVSKernelSwitch, failMode='standalone') info('*** Add router\n') r2 = net.addHost('r2', cls=Node, ip='10.0.0.254/24') info('*** Add hosts\n') h1 = net.addHost('h1', cls=Host, ip='10.0.0.1/24', defaultRoute='via 10.0.0.254') h2 = net.addHost('h2', cls=Host, ip='10.0.0.2/24', defaultRoute='via 10.0.0.254') h3 = net.addHost('h3', cls=Host, ip='192.168.111.1/24', defaultRoute='via 192.168.111.254') h4 = net.addHost('h4', cls=Host, ip='192.168.111.2/24', defaultRoute='via 192.168.111.254') info('*** Add links\n') net.addLink(swof1, r2) net.addLink(s1, r2) net.addLink(swof1, h1) net.addLink(swof1, h2) net.addLink(s1, h3) net.addLink(s1, h4) info('*** Starting network\n') net.build() info('*** Starting controllers\n') info('*** Starting controllers\n') for controller in net.controllers: controller.start() info('*** Starting switches\n') net.get('swof1').start([controller]) net.get('s1').start([]) info('*** Post configure switches and hosts\n') swof1.cmd('ifconfig swof1 10.0.0.250/24 up') info('*** Config router\n') r2.cmd('sysctl -w net.ipv4.ip_forward=1') r2.cmd('ifconfig r2-eth0 down && ifconfig r2-eth0 10.0.0.254/24 up') r2.cmd('ifconfig r2-eth1 down && ifconfig r2-eth1 192.168.111.254/24 up') CLI(net) info('########## Stopping CLI ##########\n') net.stop()
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]]) net = Mininet(switch=MultiSwitch, build=False)
from mininet.cli import CLI from mininet.log import setLogLevel, info, error from mininet.net import Mininet from mininet.node import RemoteController, OVSSwitch from mininet.link import TCLink if __name__ == "__main__": default_hs_bw = 10 default_ss_bw = 10 default_gs_bw = 10 default_ng_bw = 10 setLogLevel("info") net = Mininet(switch=OVSSwitch, listenPort=6633, ipBase='191.0.0.1/4') mycontroller = RemoteController("RemoteController") net.controllers = [mycontroller] net.nameToNode["RemoteController"] = mycontroller # host # tenant 1 host1 = net.addHost('h1', ip="191.168.1.1", mac='00:00:00:00:00:01') host2 = net.addHost('h2', ip="191.168.1.4", mac='00:00:00:00:00:04') # switch switch1 = net.addSwitch('s1', ip="191.168.2.1", datapath='user') # host - switch net.addLink(host1, switch1, 1, 1, cls=TCLink, bw=default_hs_bw) net.addLink(host2, switch1, 1, 2, cls=TCLink, bw=default_hs_bw)
def run(): # Construct the network with cpu limited hosts and shaped links net = Mininet(link=TCLink, autoStaticArp=True, autoSetMacs=True, cleanup=True) swlinks, hostlinks, swes, hnums = process_graph_file("g.graph") # Create the network switches sw = list() # sw[i] is 'si', e.g. sw[1] is 's1', sw[0] is not used sw.append(None) # let sw[0] = None for i in range(1, sorted(swes)[-1] + 1): if i in swes: s = net.addSwitch('s%s' % i) # dpid='000000000000ff0%s' % i sw.append(s) else: sw.append(None) # Create network hosts # h1, h2 = [net.addHost(h) for h in ['h1', 'h2']] hosts = list() hosts.append(None) # let hosts[0] = None for i in range(1, sorted(hnums)[-1] + 1): if i in hnums: h = net.addHost('h%s' % i) hosts.append(h) else: hosts.append(None) # Tell mininet to use a remote controller located at 127.0.0.1:6653 c1 = RemoteController('c1', ip='127.0.0.1', port=6653) # c1 = OVSController('c1') net.addController(c1) # Simple topology for testing # net.addLink(h1, sw[1], bw=10) # net.addLink(h2, sw[2], bw=10) # net.addLink(sw[1], sw[2], bw=10) # Add link between switches # for (s1, s2) in [(sw[1], sw[2]), (sw[1], sw[5]), (sw[1], sw[6]), (sw[2], sw[3]), (sw[3], sw[4]), (sw[4], sw[8]), (sw[5], sw[7]), (sw[6], sw[7]), (sw[7], sw[8])]: # s1_num = int(s1.name[1]) # s2_num = int(s2.name[1]) # print("s%d, s%d" % (s1_num, s2_num)) # # link with a delay of 5ms and 15Mbps bandwidth; s1-eth3 connects to s3, s3-eth1 connects to s1, etc. # net.addLink(s1, s2, port1=s2_num, port2=s1_num, bw=15) # delay='5ms' for (s1_num, s2_num, bandwidth) in swlinks: print("s%d, s%d" % (s1_num, s2_num)) # link with a delay of 5ms and 15Mbps bandwidth; s1-eth3 connects to s3, s3-eth1 connects to s1, etc. net.addLink(sw[s1_num], sw[s2_num], port1=s2_num, port2=s1_num, bw=bandwidth) # delay='5ms' for (h_num, s_num, bandwidth) in hostlinks: print("h%d, s%d" % (h_num, s_num)) net.addLink(hosts[h_num], sw[s_num], bw=bandwidth) # Add link between a host and a switch # for (h, s) in [(h1, sw[0]), (h2, sw[7])]: # h_num = int(h.name[1]) # s_num = int(s.name[1]) # print("h%d, s%d" % (h_num, s_num)) # net.addLink(h, s, bw=10) # Start each switch and assign it to the controller for i in range(1, len(sw)): # omit sw[0] if sw[i] is not None: sw[i].start([c1]) net.staticArp( ) # add all-pairs ARP entries to eliminate the need to handle broadcast net.start() # print "Network connectivity" # dumpNetConnections(net) # net.pingAll() # print(sw[5].intfs) # print node dict {port# : intf object} # print(h1.IP(h1.intfs[3])) # print IP associated with a specific interface of h1 # print(sw[5].ports) # print node dict {intf object : port#} CLI(net) # open command-line interface # Start iperf server (-s) in h1 # h1.cmd('iperf -s &') # Run a iperf client on h2 and print the throughput # result = h2.cmd('iperf -yc -c ' + h1.IP() + ' -t 2').split(",")[-1] # test for 2 sec, parse the csv row to get the last item (bandwidth in bps) # print "Throughput between h1<-->h2: " + str(float(result)/1000000.0) + "Mbps" net.stop()
def addControllers(self, controllers): i = 0 for ctrl in controllers: self.addController(RemoteController('c%d' % i, ip=ctrl)) i += 1
protocols='OpenFlow13') s4 = self.addSwitch('s4', mac="11:00:00:00:00:14", protocols='OpenFlow13') s5 = self.addSwitch('s5', mac="11:00:00:00:00:15", protocols='OpenFlow13') h1 = self.addHost('h1', mac="00:00:00:00:00:01", ip="10.0.0.1/12") h2 = self.addHost('h2', mac="00:00:00:00:00:02", ip="10.0.0.2/12") self.addLink(h1, s1) self.addLink(h2, s4) self.addLink(s1, s2) self.addLink(s1, s3) self.addLink(s2, s4) self.addLink(s3, s5) self.addLink(s4, s5) if __name__ == '__main__': setLogLevel('info') topo = MastersSwitchTopo() c1 = RemoteController('c1', ip='127.0.0.1') net = Mininet(topo=topo, controller=c1) net.start() #net.pingAll() CLI(net) net.stop()
def start_network(**kwargs): if kwargs['-t'] == 'dag': topo = DAGTopo(**kwargs) else: error('ERROR: unkown topology, default to DAG\n') topo = DAGTopo(**kwargs) """add controller""" controller_ip = kwargs['-c'] if controller_ip != '127.0.0.1': debug('DEBUG: add remote controller on tcp:%s:6633' % controller_ip) ctl = RemoteController(name='c1', ip=controller_ip, protocol='tcp', port=6633) else: ctl = Controller(name='c1') net = Mininet(topo=topo, controller=ctl) "bridge the management interface to the management switch" management_sw = net.switches[0] management_if = kwargs['--mi'] management_if_ip = checkIntf(management_if) try: management_if_ip is not None or raise_ValueError() info('INFO: remove the IP address from %s \n' % management_if) subprocess.check_output(['ifconfig', management_if, '0.0.0.0']) except ValueError: error( 'ERROR: no valid IP address for remote access, mininet wont be accissable externally\n' ) info('INFO: add: %s to switch %s \n' % (management_if, management_sw.name)) Intf(management_if, node=management_sw) """bridge the ICN data interface to data switch, if different from management switch""" try: data_sw = net.switches[1] data_if = kwargs['--di'] data_if_ip = checkIntf(data_if) try: data_if_ip is not None or raise_ValueError() info('INFO: remove the IP address from %s \n' % data_if) subprocess.check_output(['ifconfig', data_if, '0.0.0.0']) except ValueError: info('INFO: no IP address for ICN data interface') info('add: %s to switch %s \n' % (data_if, data_sw.name)) Intf(data_if, node=data_sw) except: info( 'INFO: no separate data switch, management switch is used for both purposes\n' ) """configure ovs switch ports""" if kwargs['-s'] == 'ovs': of_protocol = kwargs['--of'] management_ports = management_sw.intfs for port in management_ports: management_sw.cmd('ovs-ofctl -O %s mod-port %s %s up' % (of_protocol, management_sw.name, port)) management_sw.cmd('ovs-ofctl -O %s mod-port %s %s no-flood' % (of_protocol, management_sw.name, port)) management_sw.cmd( 'ovs-vsctl -- set interface %s options:key=flow' % port) try: data_ports = data_sw.intfs for port in data_ports: data_sw.cmd('ovs-ofctl -O %s mod-port %s %s up' % (of_protocol, data_sw.name, port)) data_sw.cmd('ovs-ofctl -O %s mod-port %s %s no-flood' % (of_protocol, data_sw.name, port)) data_sw.cmd('ovs-vsctl -- set interface %s options:key=flow' % port) except: debug('DEBUG: no separate data switch') """add data network and configure remote accessability""" number_pairs = int(kwargs['-n']) data_net = IPNetwork(kwargs['--dn']) prefixlen = '/%s' % str(data_net.prefixlen) data_ip = data_net.ip ssh_cmd = '/usr/sbin/sshd &' forward_cmd = 'echo 1 > /proc/sys/net/ipv4/ip_forward' icmp_cmd = 'sudo iptables -I OUTPUT -p icmp --icmp-type destination-unreachable -j DROP' for i in range(0, number_pairs): ip = str(data_ip) + prefixlen """configure the client""" net.hosts[i].setIP(ip, intf=net.hosts[i].intfs[1]) debug('DEBUG: client configure ssh') net.hosts[i].cmd(ssh_cmd) data_ip = IPAddress(int(data_ip) + 1) ip = str(data_ip) + prefixlen """configure default gw of client to be the NAP""" debug('DEBUG: client configure default route') net.hosts[i].cmd('route add default gw %s %s' % (str(data_ip), net.hosts[i].intfs[1])) """configure the NAP""" net.hosts[i + number_pairs].setIP( ip, intf=net.hosts[i + number_pairs].intfs[1]) debug('DEBUG: NAP configure ssh\n') net.hosts[i + number_pairs].cmd(ssh_cmd) debug('DEBUG: NAP configure forward\n') net.hosts[i + number_pairs].cmd(forward_cmd) debug('DEBUG: NAP configure ICMP\n') net.hosts[i + number_pairs].cmd(icmp_cmd) """configure default route to the NAP, to push all default traffic to the cluster host""" try: management_if_ip is not None or raise_ValueError() debug('DEBUG: NAP configure default route\n') net.hosts[i + number_pairs].cmd( 'route add default gw %s %s' % (management_if_ip, net.hosts[i + number_pairs].intfs[0])) except ValueError: debug('DEBUG: NAP no valid management IP\n') data_ip = IPAddress(int(data_ip) + 1) """ add route to external network""" try: kwargs['--en'] is not None or raise_KeyError() external_net = kwargs['--en'] route_cmd = 'route add -net %s gw %s' % (external_net, management_if_ip) for i in range(0, number_pairs): debug('DEBUG: NAP configure route to the external network\n') net.hosts[i].cmd(route_cmd, net.hosts[i].intfs[0]) debug('DEBUG: NAP configure route to the external network\n') net.hosts[i + number_pairs].cmd( route_cmd, net.hosts[i + number_pairs].intfs[0]) except KeyError: debug( 'DEBUG: no valid external network, mininet will not be accessable from external networks\n' ) info('INFO: starting\n') net.start() debug( 'DEBUG: assign the management IP to the management switch. Careful the controller may not like it\n' ) if management_if_ip is not None: subprocess.check_output( ['ifconfig', management_sw.name, management_if_ip]) """ add management_if and data_if to switches after net.start so the host system recongize mn bridging""" if kwargs['-s'] == 'ovs': management_sw.cmd( 'ovs-vsctl add port %s %s -- set interface %s options:key=flow' % (management_sw.name, management_if, management_if)) management_sw.cmd( 'ovs-ofctl -O %s add-flow %s "priority=0, action=NORMAL" ' % (of_protocol, management_sw.name)) try: data_sw.cmd( 'ovs-vsct add port %s %s -- set interface %s options:key=flow' % (data_sw.name, data_if, data_if)) except: debug('DEBUG: no separate data switch\n') else: management_sw.cmd('brctl addif %s %s' % (management_sw.name, management_if)) try: data_sw.cmd('brctl addif %s %s' % (data_sw, data_if)) except: debug('DEBUG: no separate data switch\n') """ start minient cli""" debug('DEBUG: start mininet cli\n') CLI(net) debug('DEBUG: stop mininet\n') net.stop() debug( 'DEBUG: re-assign management and data IPs to respective host interfaces\n' ) if management_if_ip is not None: subprocess.check_output(['ifconfig', management_if, management_if_ip]) try: subprocess.check_output(['ifconfig', data_if, data_if_ip]) except: debug('DEBUG: no separate data switch\n')
from mininet.cli import CLI from mininet.node import RemoteController, OVSSwitch from mininet.net import Mininet from mininet.log import setLogLevel, info import requests as r from time import sleep from functools import partial #CONTROLLER_IP = 'floodlight' CONTROLLER_IP = '172.18.0.3' BASE = 'http://' + CONTROLLER_IP + ':8080' switch = partial(OVSSwitch) net = Mininet(controller=RemoteController, switch=switch) net.addController(RemoteController('c0', ip=CONTROLLER_IP, port=6653)) # setup topology # ============================================================================== # h1 -- s1 -- s2 -- h2 hosts = [] hosts.append(False) # h1 -- s1 s1 = net.addSwitch('s1') hosts.append(net.addHost('h1', mac='00:00:00:00:01:01', ip='10.0.0.101')) net.addLink(hosts[1], s1) # s2 -- h2 s2 = net.addSwitch('s2') hosts.append(net.addHost('h2', mac='00:00:00:00:01:02', ip='10.0.0.102')) net.addLink(hosts[2], s2)
def __init__(self, *args, **kwargs): Topo.__init__(self, *args, **kwargs) self.routers = {} k1 = RemoteController('k1', ip='127.0.0.1', port=2001) # Add sdx1 fabric sdx1_fabric = { 'name': 'SDX 1', 'switch': self.addSwitch('s1', controller=k1, cls=SDXSwitch), 'route_server': '172.1.255.254', 'as': 65000 } k2 = RemoteController('k2', ip='127.0.0.1', port=2002) # Add sdx1 fabric sdx2_fabric = { 'name': 'SDX 2', 'switch': self.addSwitch('s2', controller=k2, cls=SDXSwitch), 'route_server': '172.2.255.254', 'as': 65500 } # Adds Participants to the IXP # Each participant consists of 1 quagga router PLUS # 1 host per network advertised behind quagga self.routers['a1'] = self.addAutonomousSystem(sdx_fabric=sdx1_fabric, name='a1', sdx_interface={ 'ip': '172.1.0.1/16', 'mac': '08:00:27:89:3b:9f' }, other_interfaces=[ { 'ip': '172.3.0.1/16' }, ], networks=['20.0.0.0/24'], AS=100, neighbors=[{ 'name': 'z1', 'address': '172.3.0.2', 'as': 800 }]) self.routers['b1'] = self.addAutonomousSystem(sdx_fabric=sdx1_fabric, name='b1', sdx_interface={ 'ip': '172.1.0.2/16', 'mac': '08:00:27:92:18:1f' }, other_interfaces=[ { 'ip': '172.4.0.1/16' }, ], networks=None, AS=200, neighbors=[{ 'name': 'x1', 'address': '172.4.0.2', 'as': 700 }]) self.routers['c1'] = self.addAutonomousSystem(sdx_fabric=sdx1_fabric, name='c1', sdx_interface={ 'ip': '172.1.0.3/16', 'mac': '08:00:27:54:56:ea' }, other_interfaces=[ { 'ip': '172.5.0.1/16' }, ], networks=None, AS=300, neighbors=[{ 'name': 'f1', 'address': '172.5.0.2', 'as': 600, 'local_pref': 500 }]) self.routers['d1'] = self.addAutonomousSystem(sdx_fabric=sdx2_fabric, name='d1', sdx_interface={ 'ip': '172.2.0.1/16', 'mac': '08:00:27:bd:f8:b2' }, other_interfaces=[ { 'ip': '172.6.0.1/16' }, ], networks=['30.0.0.0/24'], AS=400, neighbors=[{ 'name': 'z1', 'address': '172.6.0.2', 'as': 800, 'local_pref': 500 }]) self.routers['e1'] = self.addAutonomousSystem(sdx_fabric=sdx2_fabric, name='e1', sdx_interface={ 'ip': '172.2.0.2/16', 'mac': '08:00:27:11:ff:aa' }, other_interfaces=[ { 'ip': '172.7.0.1/16' }, ], networks=None, AS=500, neighbors=[{ 'name': 'x1', 'address': '172.7.0.2', 'as': 700 }]) self.routers['f1'] = self.addAutonomousSystem(sdx_fabric=sdx2_fabric, name='f1', sdx_interface={ 'ip': '172.2.0.3/16', 'mac': '08:00:27:22:3b:34' }, other_interfaces=[ { 'ip': '172.5.0.2/16' }, ], networks=None, AS=600, neighbors=[{ 'name': 'c1', 'address': '172.5.0.1', 'as': 300 }]) self.routers['x1'] = self.addAutonomousSystem(sdx_fabric=None, name='x1', sdx_interface=None, other_interfaces=[ { 'ip': '172.4.0.2/16' }, { 'ip': '172.7.0.2/16' }, ], networks=['10.0.0.0/8'], AS=700, neighbors=[ { 'name': 'b1', 'address': '172.4.0.1', 'as': 200 }, { 'name': 'e1', 'address': '172.7.0.1', 'as': 500 }, ]) self.routers['z1'] = self.addAutonomousSystem(sdx_fabric=None, name='z1', sdx_interface=None, other_interfaces=[{ 'ip': '172.3.0.2/16' }, { 'ip': '172.6.0.2/16' }], networks=None, AS=800, neighbors=[ { 'name': 'a1', 'address': '172.3.0.1', 'as': 100, 'local_pref': 500 }, { 'name': 'd1', 'address': '172.6.0.1', 'as': 400 }, ]) # Add root node for route server of SDX 1 - exaBGP - and connect it to the fabric sdx1_rs = self.addHost('rs1', ip='172.1.255.254/16', mac='08:00:27:89:33:dd', inNamespace=False) self.addLink(sdx1_rs, sdx1_fabric['switch']) # Add root node for route server of SDX 2 - exaBGP - and connect it to the fabric sdx2_rs = self.addHost('rs2', ip='172.2.255.254/16', mac='08:00:27:89:33:ff', inNamespace=False) self.addLink(sdx2_rs, sdx2_fabric['switch'])