Example #1
0
def emptyNet():

    net = Mininet(controller=RemoteController, switch=OVSKernelSwitch)

    c1 = net.addController('c1', controller=RemoteController, ip="127.0.0.1", port=6633)

    h1 = net.addHost( 'h1', ip='10.0.0.1' )
    h2 = net.addHost( 'h2', ip='10.0.0.2' )
    h3 = net.addHost( 'h3', ip='10.0.0.3' )
    h4 = net.addHost( 'h4', ip='10.0.0.4' )

    s1 = net.addSwitch( 's1' )
    s2 = net.addSwitch( 's2' )

    s1.linkTo( h1 )
    s1.linkTo( h2 )
    s2.linkTo( h3 )
    s2.linkTo( h4 )
    s1.linkTo( s2 )

    net.build()
    c1.start()
    s1.start([c1])
    s2.start([c1])
   
    CLI( net )
    net.stop()
Example #2
0
    def build( self ):
        print "Build network based on our topology."

        net = Mininet( topo=None, build=False, link=TCLink, ipBase=self.minieditIpBase )
 
        net.controllers = self.addControllers()
        
        # Make nodes
        print "Getting Hosts and Switches."
        for widget in self.widgetToItem:
            name = widget[ 'text' ]
            tags = self.canvas.gettags( self.widgetToItem[ widget ] )
            nodeNum = int( name[ 1: ] )
            if 'Switch' in tags:
                net.addSwitch( name )
            elif 'Host' in tags:
                ipBaseNum, prefixLen = netParse( self.minieditIpBase )
                ip = ipAdd(i=nodeNum, prefixLen=prefixLen, ipBaseNum=ipBaseNum)
                net.addHost( name, ip=ip )
            else:
                raise Exception( "Cannot create mystery node: " + name )

        # Make links
        print "Getting Links."
        for link in self.links.values():
            ( src, dst, linkopts ) = link
            srcName, dstName = src[ 'text' ], dst[ 'text' ]
            src, dst = net.nameToNode[ srcName ], net.nameToNode[ dstName ]
            net.addLink(src, dst, **linkopts)

        self.printInfo()
        # Build network (we have to do this separately at the moment )
        net.build()

        return net
Example #3
0
def emptyNet(N):
	
	"Create an empty network and add nodes to it."
	
	net = Mininet( controller=Controller )
	
	#info( '*** Adding controller\n' )
	#net.addController( 'c0' )
	N = int(N)

	host_array = [None] * N
	switch_array = [None] * N

	info( '*** Creating Network\n' )
	for i in range(N):
		host_array[i] = net.addHost('h'+ str(i+1))		
		switch_array[i] = net.addSwitch( 's' + str(i+1))
		net.addLink (host_array[i], switch_array[i])
		if (i>0):
			net.addLink (switch_array[i - 1], switch_array[i])
	

	receiver = net.addHost ('h0')
	net.addLink (receiver, switch_array[0])
	
	info( '*** Starting network\n')
	net.start()
	
	info( '*** Running CLI\n' )
	CLI( net )
	
	info( '*** Stopping network' )
	net.stop()
def topology():
    net = Mininet(controller=Controller, link=TCLink, switch=OVSKernelSwitch)

    print "*** Creating nodes"
    h1 = net.addHost('red1', mac='00:00:00:00:10:01', ip='10.0.10.1/24')
    h2 = net.addHost('blue1', mac='00:00:00:00:20:01', ip='10.0.20.1/24')

    s1 = net.addSwitch('s1', protocols='OpenFlow13')
    ctrl = RemoteController('ryu', ip='192.168.10.1')

    print "*** Creating links"
    net.addLink(s1, h1, bw=10)
    net.addLink(s1, h2, bw=10)

    print "*** Starting network"
    net.build()
    ctrl.start()
    s1.start([ctrl])
    s1.cmd(
        'ovs-vsctl add-port s1 vtep2 -- set interface vtep2 type=vxlan option:remote_ip=192.168.20.2 option:key=flow ofport_request=12 &')
    s1.cmd(
        'ovs-vsctl add-port s1 vtep3 -- set interface vtep3 type=vxlan option:remote_ip=192.168.30.2 option:key=flow ofport_request=13 &')
    print "*** Running Ping"
    time.sleep(5)
    h1.cmd('ping -c 1 10.0.10.10 &')
    h1.cmd('ifconfig red1-eth0 mtu 1450')
    # h1.cmd('python -m SimpleHTTPServer 80 &')
    h2.cmd('ping -c 1 10.0.20.10 &')
    h2.cmd('ifconfig blue1-eth0 mtu 1450')

    print "*** Running CLI"
    CLI(net)
    print "*** Stopping network"
    net.stop()
    def build( self ):
        "Build network based on our topology."

        net = Mininet(controller=RemoteController, topo=None )

        # Make controller
        net.addController( 'c0' )
        # Make nodes
        for widget in self.widgetToItem:
            name = widget[ 'text' ]
            tags = self.canvas.gettags( self.widgetToItem[ widget ] )
            nodeNum = int( name[ 1: ] )
            if 'Switch' in tags:
                net.addSwitch( name )
            elif 'Host' in tags:
                net.addHost( name, ip=ipStr( nodeNum ) )
            else:
                raise Exception( "Cannot create mystery node: " + name )
        # Make links
        for link in self.links.values():
            ( src, dst ) = link
            srcName, dstName = src[ 'text' ], dst[ 'text' ]
            src, dst = net.nameToNode[ srcName ], net.nameToNode[ dstName ]
            src.linkTo( dst )

        # Build network (we have to do this separately at the moment )
        net.build()

        return net
def emptyNet():

    "Create an empty network and add nodes to it."

    net = Mininet( topo=None,
                   build=False)

    net.addController( 'c0',
                       controller=RemoteController,
                       ip='0.0.0.0'  )

    h1 = net.addHost( 'h1', ip='10.0.0.1' )
    h2 = net.addHost( 'h2', ip='10.0.0.2' )
    h3 = net.addHost( 'h3', ip='10.0.0.3' )

    s1 = net.addSwitch( 's1', cls=OVSSwitch )

    net.addLink( h1, s1 )
    net.addLink( h2, s1 )
    net.addLink( h3, s1 )

    net.start()
    s1.cmd('ifconfig s1 inet 10.0.0.10')

    CLI( net )
    net.stop()
def topology():
    "Create a network."
    net = Mininet( controller=Controller, link=TCLink, switch=OVSKernelSwitch )

    print "*** Creating nodes"
    h1 = net.addHost( 'h1', mac='00:00:00:00:00:01', ip='10.0.0.1/8' )
    h2 = net.addHost( 'h2', mac='00:00:00:00:00:02', ip='10.0.0.2/8' )
    h3 = net.addHost( 'h3', mac='00:00:00:00:00:03', ip='10.0.0.3/8' )
    s4 = net.addSwitch( 's4', mac='00:00:00:00:00:10')
    s5 = net.addSwitch( 's5', mac='00:00:00:00:00:11')
    c6 = net.addController( 'c6', controller=RemoteController, defaultIP="127.0.0.1", port=6633)

    print "*** Creating links"
    net.addLink(s4, s5, 3, 5, bw=100)
    net.addLink(s5, h3, 2, 0, bw=100)
    net.addLink(s5, h2, 1, 0, bw=100)
    net.addLink(s4, h2, 2, 0, bw=100)
    net.addLink(s4, h1, 1, 0, bw=100)

    print "*** Starting network"
    net.build()
    s5.start( [c6] )
    s4.start( [c6] )
    c6.start()

    print "*** Running CLI"
    CLI( net )

    print "*** Stopping network"
    net.stop()
def createEmptyNet():
    final_hosts=[]
    final_switches=[]
    net = Mininet(controller=OVSController,link=TCLink)
    net.addController('c0')
    evenflag=1
    oddflag=1
    evenflagip='11.0.0.'
    oddflagip='11.0.1.'
    for x in range(0,B*A):
        if x%2==0:
            final_hosts.append(net.addHost('h'+str(x+1), ip=evenflagip+str(evenflag)+'/24'))
            evenflag+=1
        else:
            final_hosts.append(net.addHost('h'+str(x+1), ip=oddflagip+str(oddflag)+'/24'))
            oddflag+=1
    for x in range(0,A):
        final_switches.append(net.addSwitch('s'+str(x+1)))
    
    bwidth=0
    for x in range(0,A):
        for y in range(0,B):
            net.addLink( final_hosts[B*x+y], final_switches[x] , bw=bwidth+1)
            bwidth=(bwidth+1)%2
    for x in range(0,A-1):
        net.addLink(final_switches[x],final_switches[x+1],bw=2)

    net.start()
    CLI( net )
    net.stop()
Example #9
0
def testRemoteNet( remote='ubuntu2', link=RemoteGRELink ):
    "Test remote Node classes"
    print( '*** Remote Node Test' )
    net = Mininet( host=RemoteHost, switch=RemoteOVSSwitch, link=link )
    c0 = net.addController( 'c0' )
    # Make sure controller knows its non-loopback address
    Intf( 'eth0', node=c0 ).updateIP()
    print( "*** Creating local h1" )
    h1 = net.addHost( 'h1' )
    print( "*** Creating remote h2" )
    h2 = net.addHost( 'h2', server=remote )
    print( "*** Creating local s1" )
    s1 = net.addSwitch( 's1' )
    print( "*** Creating remote s2" )
    s2 = net.addSwitch( 's2', server=remote )
    print( "*** Adding links" )
    net.addLink( h1, s1 )
    net.addLink( s1, s2 )
    net.addLink( h2, s2 )
    net.start()
    print( 'Mininet is running on', quietRun( 'hostname' ).strip() )
    for node in c0, h1, h2, s1, s2:
        print( 'Node', node, 'is running on', node.cmd( 'hostname' ).strip() )
    net.pingAll()
    CLI( net )
    net.stop()
Example #10
0
def createTopo(  ):
    "Simple topology example."


    net = Mininet( controller=RemoteController)

    info( '*** Adding controller\n' )
    net.addController( 'c0', controller=RemoteController,ip="127.0.0.1",port=6633 )

    # Add hosts and switches
    leftHost = net.addHost( 'h1' )
    rightHost = net.addHost( 'h2' )
    leftSwitch = net.addSwitch( 's3' )
    rightSwitch = net.addSwitch( 's4' )
    centerSwitchl = net.addSwitch( 's5' )
    centerSwitchr = net.addSwitch( 's6' )

    # Add links
    net.addLink( leftHost, leftSwitch )
    net.addLink( leftSwitch, centerSwitchl )
    net.addLink( centerSwitchl, centerSwitchr )
    net.addLink( centerSwitchr, rightSwitch)

    linkOpts = {'bw':10};
    net.addLink( rightSwitch, rightHost, cls=TCLink, **linkOpts)


    info( '*** Starting network\n')
    net.start()

    info( '*** Running CLI\n' )
    CLI( net )

    info( '*** Stopping network' )
    net.stop()
Example #11
0
def emptyNet():
    "Create an empty network and add nodes to it."
    net = Mininet( controller=RemoteController )
    info( '*** Adding controller\n' )
    net.addController( 'c0',ip='127.0.0.1',port=6633 )
    info( '*** Adding hosts\n' )
    Host_1 = net.addHost('Host_1', ip='10.0.1.10/24',defaultRoute='via 10.0.1.1',mac='00:00:00:00:00:01')
    Host_2 = net.addHost('Host_2', ip='10.0.2.10/24',defaultRoute='via 10.0.2.1',mac='00:00:00:00:00:02')
    Host_3 = net.addHost('Host_3', ip='10.0.3.10/24',defaultRoute='via 10.0.3.1',mac='00:00:00:00:00:03')
    Host_4 = net.addHost('Host_4', ip='192.168.0.22/24',defaultRoute='via 192.168.0.1',mac='00:00:00:00:00:04')
    info( '*** Adding switch\n' )
    Device_1 = net.addSwitch( 's1' )
    Device_2 = net.addSwitch( 's2' )
    info( '*** Creating links\n' )
    net.addLink( Host_1, Device_1 )
    net.addLink( Host_2, Device_1 )
    net.addLink( Host_3, Device_1 )
    net.addLink( Host_4, Device_2 )
    net.addLink( Device_1, Device_2  )
    info( '*** Starting network\n')
    net.start()
    info( '*** Running CLI\n' )
    CLI( net )
    info( '*** Stopping network' )
    net.stop()
def emptyNet() :
        l=[int(i) for i in raw_input().split()]
        X=l[0]
        Y=l[1]
        net=Mininet(controller=Controller,link=TCLink)
        net.addController('c0')
        info('Adding Switches\n')
        S=[]
        for i in range(Y) :
                switchname='S'+str(i)
                S.append(net.addSwitch(switchname))
        k=0
        H=[]
        info('Adding Hosts\n')
	 for i in range(Y) :
                for j in range(X) :
                        if k%2 == 0 :
                                hostname='H'+str(k)
                                ipaddr='10.0.0.'+str(k+1)+'/24'
                                H.append(net.addHost(hostname,ip=ipaddr))        
                        else :
                                hostname='H'+str(k)
                                ipaddr='10.0.1.'+str(k+1)+'/24'
                                H.append(net.addHost(hostname,ip=ipaddr))
                        k=k+1
def topology():
    "Create a network."
    net = Mininet( controller=None, link=TCLink, switch=OVSKernelSwitch )
    print "*** Creating nodes"
    h1 = net.addHost( 'h1', mac='00:00:00:00:00:01', ip='10.0.0.1/24' )
    h2 = net.addHost( 'h2', mac='00:00:00:00:00:02', ip='10.0.0.2/24' )
    h3 = net.addHost( 'h3', mac='00:00:00:00:00:03', ip='10.0.10.33/24' )
    s1 = net.addSwitch ( 's1')

    print "*** Creating links"
    
    #direct connection between h1 and h2
    net.addLink(h1, h2, intfName1='h1-eth0', intfName2='h2-eth0',bw=100)
    # connection via switch s1
    net.addLink(h1, s1, intfName1='h1-eth1', intfName2='s1-eth1', bw=100)
    net.addLink(h2, s1, intfName1='h2-eth1', intfName2='s1-eth2', bw=100)
    net.addLink(h3, s1, intfName1='h3-eth0', intfName2='s1-eth0', bw=100)
    h1.cmd('ifconfig h1-eth1 10.0.10.11 netmask 255.255.255.0')
    h2.cmd('ifconfig h2-eth1 10.0.10.22 netmask 255.255.255.0')

    print "*** Starting network"
    net.build()
   # start s1 switch
    s1.start('')
    s1.cmd('switch s1 start')
   # add flows in switch
    s1.cmd('ovs-ofctl add-flow s1 in_port=1,actions:output=2')
    s1.cmd('ovs-ofctl add-flow s1 in_port=3,actions:output=2')
    s1.cmd('ovs-ofctl add-flow s1 in_port=2,actions:output=1,3')

    print "*** Running CLI"
    CLI( net )
    print "*** Stopping network"
    net.stop()
def myTopo():
    net = Mininet(switch=OVSKernelSwitch)
    net.addController('controller01',controller=RemoteController,ip=ofc_ip, port=ofc_port)

    spine1 = net.addSwitch(spine1_name, dpid=spine1_dpid)
    leaf1  = net.addSwitch(leaf1_name,  dpid=leaf1_dpid)
    leaf2  = net.addSwitch(leaf2_name,  dpid=leaf2_dpid)

    host1 = net.addHost(host1_name, ip=host1_ip)
    host2 = net.addHost(host2_name, ip=host2_ip)
    host3 = net.addHost(host3_name, ip=host3_ip)
    host4 = net.addHost(host4_name, ip=host4_ip)

    net.addLink(spine1, leaf1)
    net.addLink(spine1, leaf2)

    net.addLink(leaf1, host1)
    net.addLink(leaf1, host2)

    net.addLink(leaf2, host3)
    net.addLink(leaf2, host4)

    net.start()
    print "Dumping node connections"
    dumpNodeConnections(net.switches)
    dumpNodeConnections(net.hosts)

    ofp_version(spine1, ['OpenFlow13'])
    ofp_version(leaf1,  ['OpenFlow13'])
    ofp_version(leaf2,  ['OpenFlow13'])

    CLI(net)
    net.stop()
def main():
    net = Mininet(controller = None, autoSetMacs=True, autoStaticArp=True)

    h1 = net.addHost('h1', cls=P4Host)
    h2 = net.addHost('h2', cls=P4Host)
    h3 = net.addHost('h3', cls=P4Host)
    h4 = net.addHost('h4', cls=P4Host)

    s1 = net.addSwitch('s1', cls = P4Switch, sw_path=SW_PATH, json_path=JSON_PATH, thrift_port=9091)
    s2 = net.addSwitch('s2', cls = P4Switch, sw_path=SW_PATH, json_path=JSON_PATH, thrift_port=9092)
    s3 = net.addSwitch('s3', cls = P4Switch, sw_path=SW_PATH, json_path=JSON_PATH, thrift_port=9093)
    s4 = net.addSwitch('s4', cls = P4Switch, sw_path=SW_PATH, json_path=JSON_PATH, thrift_port=9094)

    net.addLink(s1, h1, port1=0, port2=0)
    net.addLink(s1, s3, port1=1, port2=1)
    net.addLink(s1, s2, port1=2, port2=0)

    net.addLink(s2, s4, port1=1, port2=1)
    net.addLink(s2, h2, port1=2, port2=0)

    net.addLink(s3, h3, port1=0, port2=0)
    net.addLink(s3, s4, port1=2, port2=0)

    net.addLink(s4, h4, port1=2, port2=0)


    net.start()
    CLI(net)
    net.stop()
Example #16
0
def dummyNet():
  net = Mininet( controller=RemoteController )
  net.addController( 'r0' , controller=RemoteController,
                   ip='10.39.1.18',
                   port=6633)

  p = net.addHost( 'p', ip='10.0.0.2' )
  c = net.addHost( 'c', ip='10.0.0.1' )
  t11 = net.addHost( 't11', ip='10.0.0.11' )
  #
  s1 = net.addSwitch( 's1' )
  #
  net.addLink( p, s1 )
  net.addLink( s1, t11 )
  net.addLink( s1, c )
  #
  p.setMAC(mac='00:00:00:01:00:02')
  c.setMAC(mac='00:00:00:01:00:01')
  t11.setMAC(mac='00:00:00:00:01:01')
  #To fix "network is unreachable"
  p.setDefaultRoute(intf='p-eth0')
  c.setDefaultRoute(intf='c-eth0')
  t11.setDefaultRoute(intf='t11-eth0')
  #
  net.start()
  #
  run_tnodes([t11])
  #
  CLI( net )
  net.stop()
def emptyNet():

    "Create an empty network and add nodes to it."

    net = Mininet( controller=RemoteController )

    info( '*** Adding controller\n' )
    net.addController( 'c0', controller=RemoteController,ip="192.168.56.101",port=6653)

    info( '*** Adding hosts\n' )
    h3 = net.addHost( 'host3', cls=Host, ip='10.0.0.1', mac="00:00:00:00:00:00:00:01" )
    h4 = net.addHost( 'host4', cls=Host, ip='10.0.0.2', mac="00:00:00:00:00:00:00:02" )
    h1 = net.addHost( 'host1', cls=Host, ip='10.0.0.3', mac="00:00:00:00:00:00:00:03" )
    h2 = net.addHost( 'host2', cls=Host, ip='10.0.0.4', mac="00:00:00:00:00:00:00:04" )

    info( '*** Adding switch\n' )
    s1 = net.addSwitch( 's1' )
    s2 = net.addSwitch( 's2' )


    info( '*** Creating links\n' )
    net.addLink( h1, s1 )
    net.addLink( h3, s1 )
    net.addLink( h2, s2 )
    net.addLink( h4, s2 )


    info( '*** Starting network\n')
    net.start()

    info( '*** Running CLI\n' )
    CLI( net )

    info( '*** Stopping network' )
    net.stop()
    def config_net(self):
        net = Mininet(switch=OVSKernelSwitch,controller=RemoteController)

        print '*** Adding controller'
        net.addController('c0',ip=self.controller_ip)

        print '*** Adding hosts'
        h1 = net.addHost( 'h1', mac='00:00:00:00:00:01')
        h2 = net.addHost( 'h2', mac='00:00:00:00:00:02')
        h3 = net.addHost( 'h3', mac='00:00:00:00:00:03')
        h4 = net.addHost( 'h4', mac='00:00:00:00:00:04')

        print '*** Adding switch'
        s1 = net.addSwitch( 's1' )
        s2 = net.addSwitch( 's2' )
        s3 = net.addSwitch( 's3' )

        print '*** Creating links'
        net.addLink(h1,s2)
        net.addLink(h2,s2)
        net.addLink(h3,s3)
        net.addLink(h4,s3)
        net.addLink(s1,s2)
        net.addLink(s1,s3)

        self.net = net
Example #19
0
def myNetwork():
    net = Mininet()
    
    host_1 = net.addHost('host_1', ip='192.168.0.10/24')
    router_1 = net.addHost('router_1')
    
    net.addLink(host_1, router_1)

    # Interface binding with the SDN_hub's eth1 
    Intf( 'eth0', node=router_1)

    # Print information
    info( '*** Starting network\n')

    net.start()

    router_1.cmd('ifconfig router-eth0 0')
    router_1.cmd('ifconfig router-eth1 0')
    
    # Get ip from NAT's DHCP
    router_1.cmd("dhclient eth0")
    
    router_1.cmd("ip addr add 192.168.0.1/24 brd + dev router_1-eth0")
    router_1.cmd("echo 1 > /proc/sys/net/ipv4/ip_forward")
    
    # Change the Intranet IP to NAT IP
    router_1.cmd("iptables -t nat -A POSTROUTING -o eth0 -s 192.168.0.0/24 -j MASQUERADE")

    host_1.cmd("ip route add default via 192.168.0.1")

    CLI(net)
    net.stop()
def allfour():

    "Create an empty network and add nodes to it."

    net = Mininet(controller = OVSController, 
                    switch=OVSSwitch, autoSetMacs=True)

    info( '*** Adding controller\n')
    net.addController( 'c0' )

    info( '*** Adding hosts\n' )
    h1 = net.addHost( 'h1', ip='10.0.0.1' )
    h2 = net.addHost( 'h2', ip='10.0.0.2' )
    h3 = net.addHost( 'h3', ip='10.0.0.3' )
    h4 = net.addHost( 'h4', ip='10.0.0.4' )

    info( '*** Adding switch\n' )
    s1 = net.addSwitch( 's1' )

    info( '*** Creating links\n' )
    net.addLink( h1, s1)
    net.addLink( h2, s1)
    net.addLink( h3, s1)
    net.addLink( h4, s1)

    info( '*** Starting network\n')
    net.start()

    info( '*** Running CLI\n' )
    CLI( net )

    info( '*** Stopping network' )
    net.stop()
Example #21
0
def customNet():
        net = Mininet()        
        #Adding hosts
        pc0 = net.addHost( 'h1' )
        pc1 = net.addHost( 'h2' )
        pc2 = net.addHost( 'h3' )
        pc3 = net.addHost( 'h4' )
        #Adding switches
        switch0 = net.addSwitch( 's1' )
        switch1 = net.addSwitch( 's2' )
        router2 = net.addSwitch( 'r2' )
        router3 = net.addSwitch( 'r3' )
        # Add links
        net.addLink( pc0, switch0 )
        net.addLink( pc1, switch0 )
        net.addLink( pc2, switch1 )
        net.addLink( pc3, switch1 )
        net.addLink( switch0, router3 )
        net.addLink( switch1, router2 )
        net.addLink( router2, router3 )

        net.build()
        net.start()

        CLI( net )
        net.stop()
Example #22
0
def createStaticRouterNetwork():
    info( '*** Creating network for Static Router Example\n' )

    # Create an empty network.
    net = Mininet(controller=RemoteController, switch=OVSKernelSwitch)
    net.addController('c0')

    # Creating nodes in the network.
    h0 = net.addHost('h0')
    s0 = net.addSwitch('s0')
    h1 = net.addHost('h1')
    s1 = net.addSwitch('s1')

    # Creating links between nodes in network.
    h0int, s0int = createLink(h0, s0)
    h1int, s1int = createLink(h1, s1)
    s0pint, s1pint = createLink(s0, s1)

    # Configuration of IP addresses in interfaces
    s0.setIP(s0int, '192.168.1.1', 26)
    h0.setIP(h0int, '192.168.1.2', 26)
    s1.setIP(s1int, '192.168.1.65', 26)
    h1.setIP(h1int, '192.168.1.66', 26)
    s0.setIP(s0pint, '192.168.1.129', 26)
    s1.setIP(s1pint, '192.168.1.130', 26)

    info( '*** Network state:\n' )
    for node in s0, s1, h0, h1:
        info( str( node ) + '\n' )

    # Start command line 
    net.start()
    CLI(net)
    net.stop()
Example #23
0
def MininetTopo(switchnum):
    # 存放 switch 參照
    switchlist = []

    # 產生一個 Mininet Object
    net = Mininet()

    # 在 Mininet 中加入兩個 hosts
    info("Create host nodes.\n")
    lefthost = net.addHost("h1")
    righthost = net.addHost("h2")
    
    info("Create switch node.\n")
    
    # 連接至 remote controller, 6633 為 Ryu controller 預設 port
    info("Connect to controller node.\n")
    c1 = net.addController(name='c1',controller=RemoteController,ip='192.168.89.129',port=6633)
    c2 = net.addController(name='c2',controller=RemoteController,ip='192.168.89.130',port=6634)

    count = 1
    while count <= int(switchnum):
        # switch name 設為 s1, s2, s3...
        switchname = "s" + str(count)
        # 加入新的 switch, switch 種類使用 OVSSwitch (即 OpenvSwitch) 取代預設的 Linux OVSKernelSwitch, OpenFlow protocol 使用 1.3 版, 最後將參照存放進 list
        switchlist.append(net.addSwitch(switchname, switch=OVSSwitch, protocols='OpenFlow13', failMode='secure'))
        count+=1
    

    # 加入 link, 串起 h1 和 s1
    info("Create Links.\n")
    net.addLink(lefthost, switchlist[0])
    
    # s2 之後每台 switch 和前一台連接
    count=1
    while count <= int(switchnum)-1:
        net.addLink(switchlist[count-1],switchlist[count])
        count+=1

    # 加入 link, 串起 sn 和 h2
    net.addLink(righthost, switchlist[len(switchlist)-1])

    info("build and start.\n")
    # 建立 topo
    net.build()
    c1.start()
    c2.start()
    
    switchlist[0].start([c1])
    switchlist[1].start([c1])
    switchlist[2].start([c1])
    switchlist[3].start([c2])
    switchlist[4].start([c2])
    switchlist[5].start([c2])
    


    # 啟動 switches 和 controller
    #net.start()
    # 進入 Command Line Interface
    CLI(net)
Example #24
0
def myNetwork():
    net = Mininet()
    
    host_1 = net.addHost('host_1', ip='192.168.0.10/24')
    router_1 = net.addHost('router_1')

    net.addLink(host_1, router_1)

    # Interface binding with the SDN_hub's eth1 
    Intf( 'eth1', node=router_1)

    # Print information
    info( '*** Starting network\n')

    net.start()

    router_1.cmd('ifconfig router-eth0 0')
    router_1.cmd('ifconfig router-eth1 0')
    router_1.cmd("ip addr add 192.168.0.1/24 brd + dev router_1-eth0")
    router_1.cmd("ip addr add 10.0.0.1 brd + dev router_1-eth1")
    router_1.cmd("echo 1 > /proc/sys/net/ipv4/ip_forward")

    host_1.cmd("ip route add default via 192.168.0.1")

    CLI(net)
    net.stop()
def Mesh(switches=4):
	"Create A Mesh Topo"
	clients = servers = cservers = switches
	print "*** Mesh With", switches, "Switches,", clients, "Client,", servers, "Servers,", cservers, "CacheServers"
	"Create Switches And Hosts"
        cli = []
        ser = []
        cse = []
        swi = []
	links = [] # Links to be monitored
	net = Mininet( controller=RemoteController, switch=OVSKernelSwitch, build=False )
	i = 0
	h = 0
	print "*** Creating Clients"
	for h in range(0, clients):
		 cli.append(net.addHost('cli%s' % (h+1)))
	print "*** Creating Servers"
	for h in range(0, servers):
		 ser.append(net.addHost('ser%s' % (h+1)))
	print "*** Creating CacheServers"
	for h in range(0, cservers):
		 cse.append(net.addHost('cse%s' % (h+1)))
        print "*** Creating Switches"
	root = connectToRootNS(net)
	# When you create a new topology you have to save in some way the link and sw that you want to be monitored
	for i in range(switches):
		sw = (net.addSwitch('s%s_c' % (i+1)))
		print "Connect", cli[i], "To", sw
		print "Connect", ser[i], "To", sw
		print "Connect", cse[i], "To", sw
		net.addLink(cli[i], sw)
	    	net.addLink(ser[i], sw)
	    	net.addLink(cse[i], sw)
		for rhs in swi:
			if i == (switches-1):
				links.append(net.addLink(sw,rhs))
			else:
                		net.addLink(sw, rhs)
			print "Connect", sw, "To", rhs   
		swi.append(sw)	
	print "*** Configure Clients"
	for h in range(0,clients):
		node_config(cli[h],(h+1))

	print "*** Configure Servers"	 
	for h in range(0,servers):
		node_config(ser[h],(h+1))

	print "*** Configure CacheServers"	 
	for h in range(0,cservers):
		node_config(cse[h],(h+1))
	print "*** Prepare Link To Be Monitored"
	
	for link in links:	
		portsToBeMonitored.append(portToBeMonitored( 	swi[len(swi)-1].dpid, # Switch To Be Monitored
								str(link.intf1), # Intf To Be Monitored
								str(link.intf2))) # Connected To
	swi.append(root)
	fixSwitchIntf(swi)
	return net
def topology():
    "Create a network."
    net = Mininet( controller=RemoteController, link=TCLink, switch=OVSKernelSwitch )
 
    print "*** Creating nodes"
    s1 = net.addSwitch( 's1', listenPort=6634, mac='00:00:00:00:00:01' )
    s4 = net.addSwitch( 's4', listenPort=6635, mac='00:00:00:00:00:04' )
    s6 = net.addSwitch( 's6', listenPort=6636, mac='00:00:00:00:00:06' )
    h2 = net.addHost( 'h2', mac='00:00:00:00:00:02', ip='10.0.0.2/8' )
    h3 = net.addHost( 'h3', mac='00:00:00:00:00:03', ip='10.0.0.3/8' )
    h4 = net.addHost( 'h4', mac='00:00:00:00:00:04', ip='10.0.0.4/8' )
    #c7 = net.addController( 'c5', controller=RemoteController, ip='127.0.0.1', port=6633 )
    c7 = net.addController( 'c5', controller=RemoteController, ip='192.168.59.105', port=6633 )
         
 
    print "*** Creating links"
    net.addLink(s1, h2, 1, 0)
    net.addLink(s1, s4, 2, 1)
    net.addLink(s4, h4, 3, 0)
    net.addLink(s4, s6, 2, 1)
    net.addLink(s6, h3, 2, 0)    
 
    print "*** Starting network"
    net.build()
    s1.start( [c7] )
    s4.start( [c7] )
    s6.start( [c7] )
    c7.start()
 
    print "*** Running CLI"
    CLI( net )
 
    print "*** Stopping network"
    net.stop()
Example #27
0
def emptyNet(nHost,nSwitch):

    "Create an empty network and add nodes to it."

    net = Mininet( controller=Controller )

    info( '*** Adding controller ***\n' )
    net.addController( 'c0' )

    info( '*** Adding hosts\n' )
    odd = []
    even = []
    arr = [] 
    for i in range(nHost):
        if i%2 == 0:
            randomN = random.randint(1,50000)
            h1 = net.addHost('h' +str(i), ip = subnet1 + str(i+1) )
            s = 'h' + str(i)
            arr.append({s:randomN} )
            odd.append(h1)
        else:
            h2 = net.addHost('h' + str(i),ip = subnet2 + str(i+1) )
            randomN = random.randint(1,50000)
            s = 'h' + str(i)
            arr.append({s:randomN})
            even.append(h2)
    print 'Host name and their id are as follows : '
    print arr
    # h1 = net.addHost( 'h1', ip= ip1  )
    # h2 = net.addHost( 'h2', ip= ip2 )

    info( '*** Adding switch\n' )
    switch = []
    for i in range(nSwitch):
        s3 = net.addSwitch('s'+str(i+1))
        switch.append(s3)

#    s3 = net.addSwitch( 's3' )

    info( '*** Creating links\n' )
    for i in range(nSwitch):
        a = net.addLink( odd[i], switch[i]) 
        a.intf1.config(bw=2)
        b = net.addLink(even[i], switch[i])
        b.intf1.config(bw=1)

    for i in range(nSwitch-1):
        net.addLink(switch[i], switch[i+1])
 
    # net.addLink( h1, s3 )
    # net.addLink( h2, s3 )
    
    info( '*** Starting network\n')
    net.start()

    info( '*** Running CLI\n' )
    CLI( net )

    info( '*** Stopping network' )
    net.stop()
Example #28
0
def server2():

    "Create an empty network and add nodes to it."

    net = Mininet( controller=None )

    info( '*** Adding hosts\n' )
    red2 = net.addHost( 'red2', ip='10.0.0.2', mac='00:00:00:00:00:02')
    blue2 = net.addHost( 'blue2', ip='10.0.0.2', mac='00:00:00:00:00:02')

    info( '*** Adding switch\n' )
    s2 = net.addSwitch( 's2' )

    info( '*** Creating links\n' )
    net.addLink( red2, s2 )
    net.addLink( blue2, s2 )

    info( '*** Starting network\n')
    net.start()

    info( '*** Running CLI\n' )
    CLI( net )

    info( '*** Stopping network' )
    net.stop()
Example #29
0
def myNet():
	
	net = Mininet(controller=RemoteController)
	net.addController( 'c0',ip='127.0.0.1')
 
        #NAT
        s1 = net.addSwitch( 's1', dpid = '000000000000000A', protocols = 'OpenFlow13')

        #Internal hosts
        alice = net.addHost( 'alice', ip='192.168.0.2/24', defaultRoute='via 192.168.0.1', mac='0000000000E1')
        bob = net.addHost( 'bob', ip='192.168.0.3/24', defaultRoute='via 192.168.0.1', mac='0000000000E2')

        #External host        
        charlie = net.addHost( 'charlie', ip='10.0.0.100', mac='0000000000E3')

        net.addLink(s1, alice)
        net.addLink(s1, bob)
        net.addLink(s1, charlie)
	net.start()

	alice.cmd('arp -s 192.168.0.1  00:00:00:00:00:e3 -i alice-eth0')
	alice.cmd('arp -s 192.168.0.3  00:00:00:00:00:e2 -i alice-eth0')
	bob.cmd('arp -s 192.168.0.1  00:00:00:00:00:e3 -i bob-eth0')
	bob.cmd('arp -s 192.168.0.2  00:00:00:00:00:e1 -i bob-eth0')
	charlie.cmd('arp -s 10.0.0.2  00:00:00:00:00:e1 -i charlie-eth0')
	charlie.cmd('arp -s 10.0.0.3  00:00:00:00:00:e2 -i charlie-eth0')
	
	c = net.get('c0')
    	CLI(net)

    	net.stop()
Example #30
0
class MyTopo(object):
    def __init__(self, cname='onos', cips=['10.0.3.1']):
        # Create network with multiple controllers
        self.net = Mininet(controller=RemoteController, switch=OVSKernelSwitch,
                           build=False, autoSetMacs=True)
 
        # Add controllers with input IPs to the network
        ctrls = [RemoteController(cname, cip, 6633) for cip in cips]
        for ctrl in ctrls:
            print ctrl.ip
            self.net.addController(ctrl)
 
        # Add components
        self.s1 = self.net.addSwitch('s1', protocols='OpenFlow13')
        h1 = self.net.addHost('h1', ip='192.168.0.9', mac='00:00:00:00:00:01')
        h2 = self.net.addHost('h2', ip='192.168.0.10', mac='00:00:00:00:00:02')

        # Add links
        self.net.addLink(h1, self.s1)
        self.net.addLink(h2, self.s1)
 
    def run(self):
        self.net.build()
        self.net.start()
	self.s1.cmd('ovs-vsctl set bridge s1 protocols=OpenFlow13')
        self.s1.cmd('ovs-vsctl add-port s1 vxlan1')
        self.s1.cmd('ovs-vsctl set interface vxlan1 type=vxlan option:remote_ip=flow option:local_ip=flow option:key=flow')
        CLI(self.net)
        self.net.stop()
def topology():
    "Create a network."
    net = Mininet(controller=Controller, link=TCLink, switch=OVSKernelSwitch, accessPoint=OVSKernelAP)
    global gnet
    gnet = net

    print "*** Creating nodes"
    car = []
    stas = []
    for x in range(0, 4):
        car.append(x)
        stas.append(x)
    for x in range(0, 4):
        car[x] = net.addCar('car%s' % (x), wlans=2, ip='10.0.0.%s/8' % (x + 1), \
        mac='00:00:00:00:00:0%s' % x, mode='b')

    
    eNodeB1 = net.addAccessPoint('eNodeB1', ssid='eNodeB1', dpid='1000000000000000', mode='ac', channel='1', position='80,75,0', range=60)
    eNodeB2 = net.addAccessPoint('eNodeB2', ssid='eNodeB2', dpid='2000000000000000', mode='ac', channel='6', position='180,75,0', range=70)
    rsu1 = net.addAccessPoint('rsu1', ssid='rsu1', dpid='3000000000000000', mode='g', channel='11', position='140,120,0', range=40)
    c1 = net.addController('c1', controller=Controller)
    client = net.addHost ('client')
    switch = net.addSwitch ('switch', dpid='4000000000000000')

    net.plotNode(client, position='125,230,0')
    net.plotNode(switch, position='125,200,0')

    print "*** Configuring wifi nodes"
    net.configureWifiNodes()

    print "*** Creating links"
    net.addLink(eNodeB1, switch)
    net.addLink(eNodeB2, switch)
    net.addLink(rsu1, switch)
    net.addLink(switch, client)

    print "*** Starting network"
    net.build()
    c1.start()
    eNodeB1.start([c1])
    eNodeB2.start([c1])
    rsu1.start([c1])
    switch.start([c1])

    for sw in net.vehicles:
        sw.start([c1])

    i = 1
    j = 2
    for c in car:
        c.cmd('ifconfig %s-wlan0 192.168.0.%s/24 up' % (c, i))
        c.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (c, i))
        c.cmd('ip route add 10.0.0.0/8 via 192.168.1.%s' % j)
        i += 2
        j += 2

    i = 1
    j = 2
    for v in net.vehiclesSTA:
        v.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (v, j))
        v.cmd('ifconfig %s-mp0 10.0.0.%s/24 up' % (v, i))
        v.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward')
        i += 1
        j += 2

    for v1 in net.vehiclesSTA:
        i = 1
        j = 1
        for v2 in net.vehiclesSTA:
            if v1 != v2:
                v1.cmd('route add -host 192.168.1.%s gw 10.0.0.%s' % (j, i))
            i += 1
            j += 2

    client.cmd('ifconfig client-eth0 200.0.10.2')
    net.vehiclesSTA[0].cmd('ifconfig car0STA-eth0 200.0.10.50')

    car[0].cmd('modprobe bonding mode=3')
    car[0].cmd('ip link add bond0 type bond')
    car[0].cmd('ip link set bond0 address 02:01:02:03:04:08')
    car[0].cmd('ip link set car0-eth0 down')
    car[0].cmd('ip link set car0-eth0 address 00:00:00:00:00:11')
    car[0].cmd('ip link set car0-eth0 master bond0')
    car[0].cmd('ip link set car0-wlan0 down')
    car[0].cmd('ip link set car0-wlan0 address 00:00:00:00:00:15')
    car[0].cmd('ip link set car0-wlan0 master bond0')
    car[0].cmd('ip link set car0-wlan1 down')
    car[0].cmd('ip link set car0-wlan1 address 00:00:00:00:00:13')
    car[0].cmd('ip link set car0-wlan1 master bond0')
    car[0].cmd('ip addr add 200.0.10.100/24 dev bond0')
    car[0].cmd('ip link set bond0 up')

    car[3].cmd('ifconfig car3-wlan0 200.0.10.150')

    client.cmd('ip route add 192.168.1.8 via 200.0.10.150')
    client.cmd('ip route add 10.0.0.1 via 200.0.10.150')

    net.vehiclesSTA[3].cmd('ip route add 200.0.10.2 via 192.168.1.7')
    net.vehiclesSTA[3].cmd('ip route add 200.0.10.100 via 10.0.0.1')
    net.vehiclesSTA[0].cmd('ip route add 200.0.10.2 via 10.0.0.4')

    car[0].cmd('ip route add 10.0.0.4 via 200.0.10.50')
    car[0].cmd('ip route add 192.168.1.7 via 200.0.10.50')
    car[0].cmd('ip route add 200.0.10.2 via 200.0.10.50')
    car[3].cmd('ip route add 200.0.10.100 via 192.168.1.8')

    """plot graph"""
    net.plotGraph(max_x=250, max_y=250)

    net.startGraph()

    # Uncomment and modify the two commands below to stream video using VLC 
    car[0].cmdPrint("vlc -vvv bunnyMob.mp4 --sout '#duplicate{dst=rtp{dst=200.0.10.2,port=5004,mux=ts},dst=display}' :sout-keep &")
    client.cmdPrint("vlc rtp://@200.0.10.2:5004 &")

    car[0].moveNodeTo('95,100,0')
    car[1].moveNodeTo('80,100,0')
    car[2].moveNodeTo('65,100,0')
    car[3].moveNodeTo('50,100,0')

    os.system('ovs-ofctl del-flows switch')

    time.sleep(3)

    apply_experiment(car,client,switch,net)

    # Uncomment the line below to generate the graph that you implemented
    graphic()

    # kills all the xterms that have been opened
    #os.system('pkill xterm')

   

    print "*** Running CLI"
    CLI(net)

    print "*** Stopping network"
    net.stop()
Example #32
0
    parser.add_argument('--routing',
                        dest='routingType',
                        default='link-state',
                        choices=['link-state', 'hr', 'dry'],
                        help='''Choose routing type, dry = link-state is used
                                 but hr is calculated for comparision.''')

    net = Mininet(switch=OVSKernelSwitch,
                  controller=OVSController,
                  waitConnected=True)

    info('*** Adding controller\n')
    net.addController('c0')

    info('*** Adding NAT\n')
    nat = net.addHost('nat', cls=NAT, ip='10.0.0.99', inNamespace=False)

    #net = Mininet()
    h1 = net.addHost('h1', ip='10.0.0.1', inNamespace=True)
    h2 = net.addHost('h2', ip='10.0.0.2', inNamespace=True)
    #c = net.addHost('c',ip='10.0.0.3', inNamespace=True)

    switch = net.addSwitch('s1')

    # Add links
    host_link = partial(TCLink, bw=1)
    net.addLink(h1, switch, cls=host_link)
    net.addLink(h2, switch, cls=host_link)
    #net.addLink(c, switch)
    net.addLink(nat, switch)
Example #33
0
def myNetwork():

    net = Mininet(topo=None, build=False, ipBase='10.0.0.0/8')

    info('*** Adding routers\n')
    fbn_r = net.addHost('FlyByNight', cls=Node, ip='0.0.0.0')
    ru_r = net.addHost('RsUs', cls=Node, ip='0.0.0.0')
    internet_r = net.addHost('Internet', cls=Node, ip='0.0.0.0')
    fbn_r.cmd('sysctl -w net.ipv4.ip_forward=1')
    ru_r.cmd('sysctl -w net.ipv4.ip_forward=1')
    internet_r.cmd('sysctl -w net.ipv4.ip_forward=1')

    info('*** Adding hosts\n')
    h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None)
    h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)
    h3 = net.addHost('h3', cls=Host, ip='10.0.0.2', defaultRoute=None)

    info('*** Adding links\n')
    TCLink(fbn_r,
           h1,
           bw=10,
           delay="15ms",
           jitter="1ms",
           loss=0,
           max_queue_size=100)
    TCLink(fbn_r,
           h2,
           bw=10,
           delay="15ms",
           jitter="1ms",
           loss=0,
           max_queue_size=100)
    TCLink(ru_r,
           h3,
           bw=10,
           delay="15ms",
           jitter="1ms",
           loss=0,
           max_queue_size=100)
    TCLink(fbn_r,
           internet_r,
           bw=10,
           delay="15ms",
           jitter="1ms",
           loss=0,
           max_queue_size=100)
    TCLink(ru_r,
           internet_r,
           bw=10,
           delay="15ms",
           jitter="1ms",
           loss=0,
           max_queue_size=100)

    info('*** Starting network\n')
    net.build()

    info('*** Configuring addresses\n')
    h1.cmd('ifconfig h1-eth0 200.20.16.1 netmask 255.255.254.0 txqueuelen 1')
    h2.cmd('ifconfig h2-eth0 200.20.18.1 netmask 255.255.254.0 txqueuelen 1')
    h3.cmd('ifconfig h3-eth0 200.20.20.1 netmask 255.255.254.0 txqueuelen 1')
    fbn_r.cmd(
        'ifconfig FlyByNight-eth0 200.20.16.2 netmask 255.255.254.0 txqueuelen 1'
    )
    fbn_r.cmd(
        'ifconfig FlyByNight-eth1 200.20.18.2 netmask 255.255.254.0 txqueuelen 1'
    )
    fbn_r.cmd(
        'ifconfig FlyByNight-eth3 10.0.0.2 netmask 255.255.255.0 txqueuelen 1')
    ru_r.cmd(
        'ifconfig RsUs-eth0 200.20.20.2 netmask 255.255.254.0 txqueuelen 1')
    ru_r.cmd('ifconfig RsUs-eth1 10.0.1.2 netmask 255.255.255.0 txqueuelen 1')
    internet_r.cmd('ifconfig Internet-eth0 10.0.0.1 netmask 255.255.255.0')
    internet_r.cmd('ifconfig Internet-eth1 10.0.1.1 netmask 255.255.255.0')

    info('*** Adding routes\n')
    h1.cmd('route add default gw 200.20.16.2')
    h2.cmd('route add default gw 200.20.18.2')
    h3.cmd('route add default gw 200.20.20.2')
    internet_r.cmd(
        'route add -net 200.20.16.0 netmask 255.255.240.0 gw 10.0.0.2')
    internet_r.cmd(
        'route add -net 200.20.20.0 netmask 255.255.254.0 gw 10.0.1.2')
    internet_r.cmd('route add -net 199.31.0.0 netmask 255.255.0.0 gw 10.0.1.2')

    CLI(net)
    net.stop()
Example #34
0
def dosSim():
    net = Mininet(controller=RemoteController)

    net.addController('c0', controller=RemoteController)

    ##build network
    # Add hosts and switches
    leftoneHost = net.addHost('h1')
    lefttwoHost = net.addHost('h2')
    leftthreeHost = net.addHost('h3')
    leftfourHost = net.addHost('h4')
    leftfiveHost = net.addHost('h5')
    leftsixHost = net.addHost('h6')
    leftsevenHost = net.addHost('h7')
    lefteightHost = net.addHost('h8')
    leftnineHost = net.addHost('h9')
    lefttenHost = net.addHost('h10')
    rightoneHost = net.addHost('h11')
    righttwoHost = net.addHost('h12')
    rightthreeHost = net.addHost('h13')
    rightfourHost = net.addHost('h14')
    rightfiveHost = net.addHost('h15')
    rightsixHost = net.addHost('h16')
    rightsevenHost = net.addHost('h17')
    righteightHost = net.addHost('h18')
    rightnineHost = net.addHost('h19')
    righttenHost = net.addHost('h20')
    leftSwitch = net.addSwitch('s1')
    rightSwitch = net.addSwitch('s2')
    centerSwitch = net.addSwitch('s3')

    # Add links
    net.addLink(leftoneHost, leftSwitch)
    net.addLink(lefttwoHost, leftSwitch)
    net.addLink(leftthreeHost, leftSwitch)
    net.addLink(leftfourHost, leftSwitch)
    net.addLink(leftfiveHost, leftSwitch)
    net.addLink(leftsixHost, leftSwitch)
    net.addLink(leftsevenHost, leftSwitch)
    net.addLink(lefteightHost, leftSwitch)
    net.addLink(leftnineHost, leftSwitch)
    net.addLink(lefttenHost, leftSwitch)
    net.addLink(rightoneHost, rightSwitch)
    net.addLink(righttwoHost, rightSwitch)
    net.addLink(rightthreeHost, rightSwitch)
    net.addLink(rightfourHost, rightSwitch)
    net.addLink(rightfiveHost, rightSwitch)
    net.addLink(rightsixHost, rightSwitch)
    net.addLink(rightsevenHost, rightSwitch)
    net.addLink(righteightHost, rightSwitch)
    net.addLink(rightnineHost, rightSwitch)
    net.addLink(righttenHost, rightSwitch)
    net.addLink(leftSwitch, centerSwitch)
    net.addLink(rightSwitch, centerSwitch)

    ##start network
    net.start()
    CLI(net)

    ##en network
    net.stop()
Example #35
0
class Testbed(object):
    def __init__(self,
                 is_reliability_simulation=True,
                 simulation_interval=5,
                 topology=None,
                 rng=None,
                 host_count=10):
        self.ctrl = RemoteController("c1", port=6653)
        self.net = Mininet()
        self.hosts = []
        self.switches = []
        self.links = []
        self.is_reliability_simulation = is_reliability_simulation
        self.simulation_interval = simulation_interval

        if rng is None:
            self.rnd = Random()
            self.rnd.seed(0)
        else:
            self.rnd = rng

        topology = SimpleTopology(self.rnd,
                                  10) if topology is None else topology
        self.host_count = host_count
        self.switch_count = topology.switches
        self.topology = topology.generate()

        self._host_no = 0
        self._switch_no = 0

        self.schedules = [
            lambda now: now.minute % 2 == 0,
            lambda now: now.minute % 2 == 1,
            lambda now: now.minute % 5 != 0,
        ]

        # Link
        self.link_profile_wireless = LinkProfile(bw=10, delay="200ms", loss=15)
        self.link_profile_wired_1 = LinkProfile(bw=1000, delay="1ms", loss=1)
        self.link_profile_wired_2 = LinkProfile(bw=400, delay="20ms", loss=5)
        self.link_profile_wired_3 = LinkProfile(bw=100, delay="80ms", loss=10)
        self.link_host_profiles = [
            self.link_profile_wired_1, self.link_profile_wireless
        ]
        self.link_node_profiles = [
            self.link_profile_wired_1, self.link_profile_wired_2,
            self.link_profile_wired_3
        ]

        # Services
        self.service_profile_ping = ServiceProfile("Ping", self.rnd, [],
                                                   ["ping -c 1 {ip}"])
        self.service_profiles = [
            ServiceProfile("SSH", self.rnd, ["sshd -D"], [
                "ssh testbed@{ip} -oStrictHostKeyChecking=no command -v ls /"
            ]),
            ServiceProfile("FileTransfer", self.rnd, ["pure-ftpd -I 1"], [
                "python ./services/repeater.py wget ftp://testbed:testbed@{ip}/ftp/small.txt -O /dev/null",
                "python ./services/repeater.py wget ftp://testbed:testbed@{ip}/ftp/Tomorrowland2011Aftermovie.ts -O /dev/null"
            ]),
            ServiceProfile("Web", self.rnd, ["nodejs ./services/webServer.js"],
                           ["python ./services/repeater.py curl {ip}"]),
            ServiceProfile(
                "Secure Web", self.rnd,
                ["nodejs ./services/secureWebServer.js"],
                ["python ./services/repeater.py curl https://{ip}"]),
            ServiceProfile(
                "Video",
                self.rnd, [
                    "tsplay ./services/Tomorrowland2011Aftermovie.ts -loop -udp {ip}:554"
                ], [
                    r'su - vagrant -c "cvlc --no-embedded-video --video-title=UDP-TSPLAY '
                    r'--udp-caching 1000 --deinterlace 0 --deinterlace-mode yadif '
                    r'--sout-deinterlace-mode x udp://@:554"'
                ],
                is_provide_first=False)
        ]
        """
        TODO:
            DNS:  !! consume part not working
                provide:    "dnsmasq -k -h -z --addn-hosts=/vagrant/testbed/services/hosts"
                consume:    "dig sdnalyzer @{ip}"

            RTPS:
                provide: ["nodejs ./services/rtsp/rtsp-server/server.js", "ffmpeg -re -i ./services/rtsp/big_buck_bunny_480p_h264.mov -c:v copy -c:a copy -f flv rtmp://localhost/live/stream"]
                consume: "su - vagrant -c 'cvlc --no-embedded-video --video-title=Video --deinterlace 0 --deinterlace-mode yadif  --sout-deinterlace-mode x rtsp://{ip}/live/stream'"
        """

    def _add_switch(self, reliability=1.0):
        self._switch_no += 1
        ip, mac = self.get_next_ip_and_mac()
        datapath_id = "0001{}".format(mac.replace(":", ""))
        sw = self.net.addSwitch("s{}".format(self._switch_no),
                                cls=SdnNode,
                                reliability=reliability,
                                ip=ip,
                                dpid=datapath_id)
        self.switches.append(sw)
        return sw

    def _start_switches(self):
        for sw in self.switches:
            sw.start([self.ctrl])

    def _add_link(self, left, right, profile=None):
        if profile is None:
            profile = LinkProfile()

        link = self.net.addLink(left, right, cls=SdnLink)
        link.intf1.config(bw=profile.bw,
                          delay=profile.delay,
                          loss=profile.loss)
        link.intf2.config(bw=profile.bw,
                          delay=profile.delay,
                          loss=profile.loss)
        self.links.append(link)
        return link

    def get_next_ip_and_mac(self):
        cnt = self._host_no + self._switch_no + 1
        ip = "10.0.{}.{}/8".format(cnt // 255, cnt % 255)
        mac = "c0:de:00:00:{:02x}:{:02x}".format(cnt // 256, cnt % 256)
        return ip, mac

    def _add_host(self, reliability=1.0, schedule=None):
        self._host_no += 1
        ip, mac = self.get_next_ip_and_mac()
        host = self.net.addHost(
            "h{}".format(self._host_no),
            ip=ip,
            mac=mac,
            cls=SdnHost,
            reliability=reliability if self.is_reliability_simulation else 1,
            schedule=schedule if self.is_reliability_simulation else None)

        self.hosts.append(host)
        return host

    def _start_simulation(self):
        for host in self.hosts:
            host.start_services()

        try:
            while True:
                for host in self.hosts:
                    host.simulate_online()

                time.sleep(self.simulation_interval)
        except KeyboardInterrupt:
            print "End simulation."

    def _stop_simulation(self):
        for host in self.hosts:
            host.shut_down()

        self.net.stop()

    def _apply_profiles(self):
        self.service_profiles.append(self.service_profile_ping)

        for profile in self.service_profiles:
            profile.apply()

    def _generate_host(self, link_profiles):
        reliability = 0.85 + self.rnd.random() * 0.1
        schedule = self.rnd.choice(
            self.schedules) if self.rnd.random() > 0.8 else None
        hst = self._add_host(reliability=reliability, schedule=schedule)
        if self.service_profile_ping.provider_count() == 0:
            self.service_profile_ping.register_provider(hst)
        elif self.rnd.random() > 0.4:
            profile = self.rnd.choice(self.service_profiles)
            if self.rnd.random() > 0.5:
                profile.register_provider(hst)
            else:
                profile.register_consumer(hst)
        else:
            self.service_profile_ping.register_consumer(hst)
        self._add_link(hst, self.rnd.choice(self.switches),
                       self.rnd.choice(link_profiles))

    def _generate_network(self):
        for _ in range(self.switch_count):
            self._add_switch()

        for _ in range(self.host_count):
            self._generate_host(self.link_host_profiles)

        for left_id in self.topology:
            for right_id in self.topology[left_id]:
                if left_id < right_id:
                    profile = self.rnd.choice(self.link_node_profiles)
                    self._add_link(self.switches[left_id],
                                   self.switches[right_id], profile)

    def run(self):
        self._generate_network()
        self._start_switches()
        self.net.build()
        self._apply_profiles()
        self._start_simulation()
        self._stop_simulation()
Example #36
0
    server_ip = sys.argv[1]
    server_port = int(sys.argv[2])

# Init Mininet / Controller
net = Mininet(topo=None,controller=None,switch=OVSKernelSwitch)
controller = net.addController(name='c0', controller=RemoteController, ip=server_ip, port=server_port);


# Create switches
s1 = net.addSwitch('s1', protocols='OpenFlow13')
s2 = net.addSwitch('s2', protocols='OpenFlow13')
s3 = net.addSwitch('s3', protocols='OpenFlow13')
s4 = net.addSwitch('s4', protocols='OpenFlow13')

# Create hosts
h1 = net.addHost('h1', ip='10.0.0.1')
h2 = net.addHost('h2', ip='10.0.0.2')
h3 = net.addHost('h3', ip='10.0.0.3')
h4 = net.addHost('h4', ip='10.0.0.4')

# Create links
net.addLink(h1, s1)
net.addLink(h2, s2)
net.addLink(h3, s3)
net.addLink(h4, s4)

net.addLink(s1, s2)
net.addLink(s2, s4)
net.addLink(s1, s3)
net.addLink(s3, s4)
Example #37
0
def multiControllerNet(con_num=2, sw_num=7, host_num=3):
    "Create a network from semi-scratch with multiple controllers."

    controller_list = []

    net = Mininet(controller=None, switch=OVSSwitch, link=TCLink)

    # for i in xrange(con_num):
    #     name = 'controller%s' % str(i)
    #     c = net.addController(name, controller=RemoteController,
    #                               port=6661 + i)
    #     controller_list.append(c)
    #     print "*** Creating %s" % name

    print "*** Creating c0"
    c0 = net.addController('c0', controller=RemoteController, port=6661)
    controller_list.append(c0)

    # Contact to a remote controller running at 192.168.75.147
    # which is the ip address of the virtual machine
    print "*** Creating c1"
    c1 = net.addController('c1',
                           controller=RemoteController,
                           ip='192.168.75.147',
                           port=6662)
    controller_list.append(c1)

    print "*** Creating switches"
    switch_list = [
        net.addSwitch('s%d' % (n + 1), protocols='OpenFlow13')
        for n in xrange(sw_num)
    ]

    print "*** Creating hosts"
    host_list = [net.addHost('h%d' % n) for n in xrange(host_num)]

    print "*** Creating links of host2switch."

    net.addLink(switch_list[0], host_list[0])
    net.addLink(switch_list[5], host_list[2])
    net.addLink(switch_list[6], host_list[1])

    print "*** Creating intra links of switch2switch."
    for i in xrange(0, sw_num - 2):
        net.addLink(switch_list[i], switch_list[i + 1])
    net.addLink(switch_list[4], switch_list[6])

    print "*** Starting network"
    net.build()
    for c in controller_list:
        c.start()

    _No = 0
    for i in xrange(0, 3):
        switch_list[i].start([controller_list[_No]])

    _No = 1
    for j in xrange(3, 7):
        switch_list[j].start([controller_list[_No]])

    print "*** Running CLI"
    CLI(net)

    print "*** Stopping network"
    net.stop()
Example #38
0
from mininet.net import Mininet
from mininet.node import Node, Switch
from mininet.link import Link, Intf
from mininet.log import setLogLevel, info
from mininet.cli import CLI

import mininet.ns3
from mininet.ns3 import WIFISegment

if __name__ == '__main__':
    setLogLevel('info')
    info('*** ns-3 network demo\n')
    net = Mininet()

    info('*** Creating Network\n')
    h0 = net.addHost('h0')
    h1 = net.addHost('h1')
    h2 = net.addHost('h2')

    wifi = WIFISegment()

    wifi.add(h0)
    wifi.add(h1)
    wifi.add(h2)

    info('*** Configuring hosts\n')
    h0.setIP('192.168.123.1/24')
    h1.setIP('192.168.123.2/24')
    h2.setIP('192.168.123.3/24')

    mininet.ns3.start()
def myNetwork():

    net = Mininet(topo=None, build=False, ipBase='10.0.0.0/8')

    info('*** Adding controller\n')
    info('*** Add switches\n')
    s1 = net.addSwitch('s1', cls=OVSKernelSwitch, failMode='standalone')
    s2 = net.addSwitch('s2', cls=OVSKernelSwitch, failMode='standalone')
    s3 = net.addSwitch('s3', cls=OVSKernelSwitch, failMode='standalone')
    s4 = net.addSwitch('s4', cls=OVSKernelSwitch, failMode='standalone')

    info('*** Add hosts\n')
    h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None)
    h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)
    h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute=None)
    h4 = net.addHost('h4', cls=Host, ip='10.0.0.4', defaultRoute=None)
    h5 = net.addHost('h5', cls=Host, ip='10.0.0.5', defaultRoute=None)

    info('*** Add links\n')
    # example QoS
    satellite_qos = {
        'bw': 1000,
        'delay': '400ms',
        'loss': None,
        'max_queue_size': 10,
        'jitter': '50ms'
    }
    home_wifi_qos = {
        'bw': 100,
        'delay': '2ms',
        'loss': None,
        'max_queue_size': 10,
        'jitter': '1ms'
    }
    trailer_wifi_qos = {
        'bw': 100,
        'delay': '2ms',
        'loss': None,
        'max_queue_size': 10,
        'jitter': '1ms'
    }
    drone_wifi_qos = {
        'bw': 100,
        'delay': '3ms',
        'loss': None,
        'max_queue_size': 10,
        'jitter': '1ms'
    }

    net.addLink(h1, s1, cls=TCLink, **home_wifi_qos)
    net.addLink(s1, s2, cls=TCLink, **satellite_qos)
    net.addLink(s2, h2, cls=TCLink, **satellite_qos)
    net.addLink(s2, s3, cls=TCLink, **satellite_qos)
    net.addLink(s3, s4, cls=TCLink, **trailer_wifi_qos)
    net.addLink(s4, h3, cls=TCLink, **drone_wifi_qos)
    net.addLink(s4, h4, cls=TCLink, **drone_wifi_qos)
    net.addLink(s4, h5, cls=TCLink)  # direct link

    info('*** Starting network\n')
    net.build()
    info('*** Starting controllers\n')
    for controller in net.controllers:
        controller.start()

    info('*** Starting switches\n')
    net.get('s1').start([])
    net.get('s2').start([])
    net.get('s3').start([])
    net.get('s4').start([])

    info('*** Post configure switches and hosts\n')

    #    CLI(net)
    #    net.stop()
    return net
def Start(GI=False, MCS=2, Bandwidth=20, UDP=True, TP=20, PCAP=False):
    setLogLevel( 'info' )
    #info( '*** ns-3 network demo\n' )
    net = Mininet()

    #info( '*** Creating Network\n' )
    h0 = net.addHost( 'h0' )
    h1 = net.addHost( 'h1' )
    h2 = net.addHost( 'h2' )

    wifi = WIFISegment()

    #CONFIGURATION
    udp = UDP
    gi = GI #0,1
    bandwidth = Bandwidth #20,40,80
    mcs = MCS #2,4,7

    if udp == False:
        #TCP
        payloadSize = 1448  #bytes
        ns.core.Config.SetDefault ("ns3::TcpSocket::SegmentSize", ns.core.UintegerValue (payloadSize))
    else:
        payloadSize = 1472

    wifi.wifihelper.SetStandard(ns.wifi.WIFI_PHY_STANDARD_80211ac)

    # Enabling Shor guard intervals:
    wifi.phyhelper.Set("ShortGuardEnabled", ns.core.BooleanValue(gi))
    
    DataRate = ns.wifi.VhtWifiMacHelper.DataRateForMcs(mcs)
    #DataRate = ns.core.StringValue("VhtMcs3")

    # set datarate for node h0
    wifi.wifihelper.SetRemoteStationManager( "ns3::ConstantRateWifiManager",
                                             "DataMode", DataRate, "ControlMode", ns.wifi.VhtWifiMacHelper.DataRateForMcs(0) )
    
    wifi.machelper = ns.wifi.VhtWifiMacHelper.Default()
    
    #wifi.wifihelper.SetRemoteStationManager( "ns3::ConstantRateWifiManager",
    #                                         "DataMode", ns.core.StringValue ("VhtMcs8"), "ControlMode", ns.core.StringValue ("VhtMcs8") )
    
    Sssid = "wifi-80211acCA"
    
    wifi.addSta( h0,ext="ac",ca=True, ssid=Sssid )
    wifi.addSta( h1,ext="ac",ca=True, ssid=Sssid )
    wifi.addAp( h2,ext="ac",ca=True, ssid=Sssid  )
    
    # set channel bandwidth
    ns.core.Config.Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/ChannelWidth", ns.core.UintegerValue (bandwidth))
    
    if PCAP == True:
        wifi.phyhelper.EnablePcap( "80211acCA_Sta1.pcap", h0.nsNode.GetDevice( 0 ), True, True );
        wifi.phyhelper.EnablePcap( "80211acCA_Sta2.pcap", h1.nsNode.GetDevice( 0 ), True, True );
        wifi.phyhelper.EnablePcap( "80211acCA_Ap.pcap", h2.nsNode.GetDevice( 0 ), True, True );
   
    #info( '*** Configuring hosts\n' )
    h0.setIP('192.168.123.1/24')
    h1.setIP('192.168.123.2/24')
    h2.setIP('192.168.123.3/24')

    mininet.ns3.start()

    
    #info( '\n *** Testing network connectivity\n' )
    net.pingFull([h0,h2])
    #net.pingFull([h1,h2])
    #net.pingFull([h0,h1])
    info('*** Starting UDP iperf server on AP(h2)\n')
    h2.sendCmd( "iperf -s -i 1 -u" )
    info( '*** Testing bandwidth between h0 and h2 while h1 is not transmitting\n' )
    val = "iperf -c 192.168.123.3 -u -b "+str(TP)+"M"
    h0.cmdPrint(val)
    info( '*** Testing bandwidth between h0 and h2 while h1 is also transmitting\n' )
    val = "iperf -c 192.168.123.3 -u -b "+str(TP)+"M"
    h1.sendCmd(val)
    h0.cmdPrint(val)
Example #41
0
def myNetwork():

    net = Mininet(topo=None, build=False, ipBase='10.0.0.0/8')

    info('*** Adding controller\n')
    c0 = net.addController(name='c0',
                           controller=RemoteController,
                           ip='127.0.0.1',
                           protocol='tcp',
                           port=6633)

    info('*** Add switches\n')
    info('*** switches protocols')
    openFlowVersions = []
    openFlowVersions.append('OpenFlow13')
    protoList = ",".join(openFlowVersions)
    switchParms = {}
    switchParms['protocols'] = protoList

    s1 = net.addSwitch('s1', cls=OVSKernelSwitch, **switchParms)
    s2 = net.addSwitch('s2', cls=OVSKernelSwitch, **switchParms)
    s3 = net.addSwitch('s3', cls=OVSKernelSwitch, **switchParms)
    s4 = net.addSwitch('s4', cls=OVSKernelSwitch, **switchParms)

    info('*** Add hosts\n')
    h1 = net.addHost('h1',
                     cls=Host,
                     ip='10.0.0.1',
                     mac='B6:29:CE:E1:DB:51',
                     defaultRoute=None)
    h2 = net.addHost('h2',
                     cls=Host,
                     ip='10.0.0.2',
                     mac='92:88:E9:9C:0D:81',
                     defaultRoute=None)

    info('*** Add links\n')
    net.addLink(s1, s2)
    net.addLink(s2, s3)
    net.addLink(s1, s4)
    net.addLink(s4, s3)

    net.addLink(h1, s1)
    net.addLink(h2, s3)

    info('*** Starting network\n')
    net.build()
    info('*** Starting controllers\n')
    for controller in net.controllers:
        controller.start()

    info('*** Starting switches\n')
    net.get('s1').start([c0])
    net.get('s2').start([c0])
    net.get('s3').start([c0])
    net.get('s4').start([c0])

    info('*** Post configure switches and hosts\n')

    CLI(net)
    net.stop()
#!/usr/bin/python

from mininet.net import Mininet
from mininet.node import Controller, OVSKernelSwitch, RemoteController
from mininet.log import setLogLevel
from mininet.cli import CLI

setLogLevel('info')

net = Mininet(controller=RemoteController, switch=OVSKernelSwitch)
c1 = net.addController('c2',
                       controller=RemoteController,
                       ip='127.0.0.1',
                       port=5555)

h1 = net.addHost('h1', ip='10.20.1.10/24')
h2 = net.addHost('h2', ip='10.20.1.11/24')
s1 = net.addSwitch('s1')

s1.linkTo(h1)
s1.linkTo(h2)

net.build()

c1.start()
s1.start([c1])

net.start()
net.staticArp()
CLI(net)
net.stop()
def createNetwork():
	#send rate at each link in Mbps
	bwg = 1#000 #1000 #in Mbps
	bwbn = 1#000 #1000 #25 #in Mbps
	loss = 80 #1 #2.5 #10 #1 #in %
	mqs = 100 #0 #1000 #max queue size of interfaces
	dly = '2.5ms' #'2.5ms 0.5ms'#'1ms 0.5ms' #can take all tc qdisc delay distribution formulations

	#create empty network
	net = Mininet(intf=TCIntf)

	info( '\n*** Adding controller\n' )
	net.addController( 'c0' ) #is it ok ?

	#add host to topology
	ht = net.addHost( 'ht', ip='10.10.0.1/24' )
	hu = net.addHost( 'hu', ip='10.10.0.2/24' )
	it = net.addHost( 'it', ip='10.20.0.1/24' )
	iu = net.addHost( 'iu', ip='10.20.0.2/24' )

	rh = net.addHost('rh', ip='10.10.0.10/24')
	ri = net.addHost('ri', ip='10.20.0.20/24')

	info('\n** Adding Switches\n')
	# Adding 2 switches to the network
	sw1 = net.addSwitch('sw1')
	sw2 = net.addSwitch('sw2')

	info('\n** Creating Links \n')
	#create link beetween the network
	link_ht_sw1 = net.addLink( ht, sw1)
	link_hu_sw1 = net.addLink( hu, sw1)
	link_rh_sw1 = net.addLink( rh, sw1, intfName1='rh-eth0')

	link_it_sw2 = net.addLink( it, sw2)
	link_iu_sw2 = net.addLink( iu, sw2)
	link_ri_sw2 = net.addLink( ri, sw2, intfName1='ri-eth0')

	link_rh_ri  = net.addLink( rh, ri, intfName1='rh-eth1', intfName2='ri-eth1')


	#set bandwith
	link_ht_sw1.intf1.config( bw = bwbn, max_queue_size = mqs)
	link_hu_sw1.intf1.config( bw = bwbn, max_queue_size = mqs)
	link_rh_sw1.intf1.config( bw = bwbn, max_queue_size = mqs) #max_queue_size is hardcoded low to prevent bufferbloat, too high queuing delays

	link_it_sw2.intf1.config( bw = bwg, max_queue_size = mqs)
	link_iu_sw2.intf1.config( bw = bwg, max_queue_size = mqs)
	link_ri_sw2.intf1.config( bw = bwg, max_queue_size = mqs, delay=dly) #delay is set at ri on both interfaces

	# link_rh_ri.intf1.config(  bw = bwg, max_queue_size = 10, loss=loss) #loss is set at rh on its interface to ri only
	link_rh_ri.intf1.config(  bw = bwg, max_queue_size = mqs, loss=loss) #loss is set at rh on its interface to ri only

	link_ht_sw1.intf2.config( bw = bwbn, max_queue_size = mqs)
	link_hu_sw1.intf2.config( bw = bwbn, max_queue_size = mqs)
	link_rh_sw1.intf2.config( bw = bwbn, max_queue_size = mqs)

	link_it_sw2.intf2.config( bw = bwg, max_queue_size = mqs)
	link_iu_sw2.intf2.config( bw = bwg, max_queue_size = mqs)
	link_ri_sw2.intf2.config( bw = bwg, max_queue_size = mqs)

	link_rh_ri.intf2.config(  bw = bwg, max_queue_size = mqs,  delay=dly) #delay is set at ri on both interfaces

	net.start()

	info( '\n*** Configuring hosts\n' )

	rh.cmd('ifconfig rh-eth1 10.12.0.10 netmask 255.255.255.0') #reconfiguring mutiples intefaces host to prevent mininet strange initialisation behaviors
	rh.cmd('ifconfig rh-eth0 10.10.0.10 netmask 255.255.255.0')
	rh.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward') #enable forwarding at routers

	ri.cmd('ifconfig ri-eth1 10.12.0.20 netmask 255.255.255.0') #reconfiguring mutiples intefaces host to prvent mininet strange initialisation behaviors
	ri.cmd('ifconfig ri-eth0 10.20.0.20 netmask 255.255.255.0')
	ri.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward') #enable forwarding at routers

	#configure host default gateways
	ht.cmd('ip route add default via 10.10.0.10')
	hu.cmd('ip route add default via 10.10.0.10')
	it.cmd('ip route add default via 10.20.0.20')
	iu.cmd('ip route add default via 10.20.0.20')

	#configure router routing tables
	rh.cmd('ip route add default via 10.12.0.20')
	ri.cmd('ip route add default via 10.12.0.10')

        # weiyu:
        iu.cmd('touch server.pcap')
        hu.cmd('touch client.pcap')


        rh.cmd('tc qdisc del dev rh-eth1 root')
        rh.cmd('tc qdisc add dev rh-eth1 root netem loss gemodel 0.2% 2% 90% 2% limit ' + str(mqs))
        #rh.cmd('tc qdisc add dev rh-eth1 root netem loss gemodel 0.2% 2% 90% 2% limit 10')
        #rh.cmd('tc qdisc add dev rh-eth1 root netem loss gemodel 0.1% 1% 90% 2% limit 1000')
        #rh.cmd('tc qdisc add dev rh-eth1 root netem loss gemodel 0.5% 2% 90% 2% limit 1000')

       # rh.cmd('python ./monitor_qlen_rh.py &')
        rh.cmd('xterm -xrm \'XTerm.vt100.allowTitleOps: false\' -T rh -e \'sudo python ./monitor_queue.py\' &')
       # ri.cmd('python ./monitor_qlen_ri.py &')
        ri.cmd('xterm -xrm \'XTerm.vt100.allowTitleOps: false\' -T ri -e \'sudo python ./monitor_qlen_ri.py\' &')
        #it.cmd('xterm -xrm \'XTerm.vt100.allowTitleOps: false\' -T it -e \'sudo ./tcpserver 6666 > tcp-output-server.txt\' &')

        #ht.cmd('xterm -xrm \'XTerm.vt100.allowTitleOps: false\' -T ht -e \'sleep 10; sudo ./tcpclient 10.20.0.1 6666 > tcp-output-client.txt\' &')

       # iu.cmd('tshark -i iu-eth0 -w server.pcap &')
        iu.cmd('xterm -xrm \'XTerm.vt100.allowTitleOps: false\' -T iu -e \'sudo tshark -i iu-eth0 -w server.pcap\' &')
       # iu.cmd('./server.sh &')
        #iu.cmd('xterm -xrm \'XTerm.vt100.allowTitleOps: false\' -T iu -e \'sudo ./baseline_server.sh > output-server.txt\' &')
        iu.cmd('xterm -xrm \'XTerm.vt100.allowTitleOps: false\' -T iu -e \'python3 udp_server.py > udp-output-server.txt\' &')
       # hu.cmd('tshark -i hu-eth0 -w client.pcap &')
        hu.cmd('xterm -xrm \'XTerm.vt100.allowTitleOps: false\' -T hu -e \'sudo tshark -i hu-eth0 -w client.pcap\' &')
       # hu.cmd('./client.sh &')
        #hu.cmd('xterm -xrm \'XTerm.vt100.allowTitleOps: false\' -T hu -e \'sleep 5; sudo ./baseline_client.sh > output-client.txt\' &')
        hu.cmd('xterm -xrm \'XTerm.vt100.allowTitleOps: false\' -T hu -e \'python3 udp_client.py > udp-output-client.txt \' &')


	it.cmd('ethtool -K it-eth0 tx off sg off tso off') #disable TSO on TCP on defaul TCP sender need to be done on other host if sending large TCP file from other nodes

	method = 'tcp' #case selector varible for the flow used by smart-grid 'udp' = FRED

	logFolder = "../Estimations/wifiTer/"+ method + "/" #folder where log files and metrics will be saved
	# timeout = 10 #durantion of test

	#if not os.path.exists(logFolder):
	try:
		os.makedirs(logFolder) #error if folder already exist in order to prevent exidental overwirie
	except:
		print("File already exists.")

        # makeTerms([iu, hu, rh, ri], "host")

	#hu.cmd("bash /home/lca2/Desktop/server.sh")
	time.sleep(1)

	#iu.cmd("bash /home/lca2/Desktop/client-network.sh")
	time.sleep(1)

	"""it.cmd("python3 tcpserver.py &> "+logFolder+"it.txt &")
	time.sleep(1)
	ht.cmd("python3 tcpclient.py --ip 10.20.0.1 --port 4242 -s "+logFolder+"ht- -t "+str(timeout)+" &> "+logFolder+"ht.txt &")

	#potential second flow in the reverse direction of the first

	#ht.cmd("python3 tcpserver.py --ip 10.10.0.1 --port 4243 &> "+logFolder+"ht2.txt &")
	#time.sleep(1)
	#it.cmd("python3 tcpclient.py --ip 10.10.0.1 --port 4243 -s "+logFolder+"it2- -t "+str(timeout)+" &> "+logFolder+"it2.txt &")

	#smart grid data will be transported by TCP, delay will be recorded
	if method == 'tcp':
		info(method)
		iu.cmd("python3 delayReceiver.py --tcp --ip 10.20.0.2 -p 4242 -s "+logFolder+"iu- -t "+str(timeout)+" &> "+logFolder+"iu.txt &")
		time.sleep(1)
		hu.cmd("python3 tcpsender.py -t "+str(timeout)+" &> "+logFolder+"hu.txt &")

	#smart grid data will be transported by FRED, delay will be recorded
	elif method == 'udp':
		info(method)
		iu.cmd("python3 delayReceiver.py --ip 10.20.0.2 -p 4242 -s "+logFolder+"iu- -t "+str(timeout)+" &> "+logFolder+"iu.txt &")
		time.sleep(1)
		hu.cmd("python3 udpsender.py -s "+logFolder+"hu- -t "+str(timeout)+" &> "+logFolder+"hu.txt &")

	else:
		info("method unknown")
		net.stop()
		return

	#wainting until test end
	info('\n*** Sleeping\n')
	for i in range(int(timeout)):
		time.sleep(60)
		info("**slept "+str(i+1))"""

	# Enable the mininet> prompt if uncommented
	info('\n*** Running CLI\n')
	CLI(net)

	#kill xterms in case some where opened
	#ht.cmd("killall xterm")
	#it.cmd("killall xterm")
	# hu.cmd("killall xterm")
	iu.cmd("killall xterm")
Example #44
0
def define_network():
    """
    Create Mininet network
    """
    info('+++ Defining Mininet Network\n')
    net = Mininet(topo=None,
                  build=False,
                  autoSetMacs=True,
                  ipBase='10.10.0.0/16')

    info('+++ Adding controller\n')
    c0 = net.addController(
        name='c0',
        controller=SDSecController,
        # ip='10.10.0.1',
        protocol='tcp',
        port=6633)

    info('+++ Add switches\n')
    m = 2
    switches = []
    for i in xrange(0, m):
        switches.append(
            net.addSwitch('s%d' % (i + 1),
                          cls=OVSSwitch,
                          protocols='OpenFlow13',
                          ip='10.10.%d.1' % (i + 1)))

    info('+++ Add hosts\n')
    n = 8
    hosts = []
    for i in xrange(0, n / 2):
        hosts.append(
            net.addHost('h%d' % (i + 1),
                        cls=Host,
                        ip='10.10.1.%d' % (i + 2),
                        defaultRoute=None))
    for i in xrange(n / 2, n):
        hosts.append(
            net.addHost('h%d' % (i + 1),
                        cls=Host,
                        ip='10.10.2.%d' % (i + 2),
                        defaultRoute=None))

    info('+++ Add links\n')
    # net.addLink(c0, switches[0])
    # net.addLink(c0, switches[1])
    for i in xrange(0, n / 2):
        net.addLink(switches[0], hosts[i])
    for i in xrange(n / 2, n):
        net.addLink(switches[1], hosts[i])
    net.addLink(switches[0], switches[1])

    info('+++ Starting network\n')
    net.build()
    info('+++ Starting controllers\n')
    for controller in net.controllers:
        controller.start(controller, net)

    info('+++ Starting switches\n')

    # info('+++ Post configure switches and hosts\n')
    switches[0].cmd('ifconfig s1 10.10.1.1')
    switches[1].cmd('ifconfig s2 10.10.2.1')

    CLI(net)
    net.stop()
Example #45
0
def topology():
    "Create a network."
    net = Mininet(controller=RemoteController,
                  link=TCLink,
                  switch=OVSKernelSwitch)
    print "*** Creating Hosts"
    h1 = net.addHost('h1', mac='00:00:00:00:00:01')  # h1--10.0.0.1
    h2 = net.addHost('h2', mac='00:00:00:00:00:02')  # h2--10.0.0.2
    h3 = net.addHost('h3', mac='00:00:00:00:00:03')  # h3--10.0.0.3
    h4 = net.addHost('h4', mac='00:00:00:00:00:04')  # h4--10.0.0.4

    #h5 = net.addHost( 'h5', mac = '00:00:00:00:00:05')	# h5--10.0.0.5
    #h6 = net.addHost( 'h6', mac = '00:00:00:00:00:06')	# h6--10.0.0.6

    print "*** Creating Switches & Controller"
    s1 = net.addSwitch('s1')
    s2 = net.addSwitch('s2')
    s3 = net.addSwitch('s3')
    s4 = net.addSwitch('s4')

    c0 = net.addController('c0',
                           controller=RemoteController,
                           defaultIP='127.0.0.1',
                           port=6633)

    # between hosts & switches
    print "*** Creating and configuring link between Hosts & Switches"
    net.addLink(h1, s1, intfName1='h1-eth0', intfName2='s1-eth1')  # h1--s1
    net.addLink(h2, s2, intfName1='h2-eth0', intfName2='s2-eth1')  # h2--s2
    net.addLink(h3, s3, intfName1='h3-eth0', intfName2='s3-eth1')  # h3--s3
    net.addLink(h4, s4, intfName1='h4-eth0', intfName2='s4-eth1')  # h4--s4

    #net.addLink(h5, s2, intfName1='h5-eth0', intfName2='s2-eth4')	# h5--s2
    #net.addLink(h6, s3, intfName1='h6-eth0', intfName2='s3-eth4')	# h6--s3

    net.addLink(s1, s2, intfName1='s1-eth2', intfName2='s2-eth2')  # s1--s2
    net.addLink(s2,
                s3,
                intfName1='s2-eth3',
                intfName2='s3-eth2',
                bw=20,
                delay='30ms',
                max_queue_size=100)  # s2--s3
    net.addLink(s3, s4, intfName1='s3-eth3', intfName2='s4-eth2')  # s3--s4

    print "\n*** Starting controller"
    net.build()
    c0.start

    print "*** Starting 4 switches"
    s1.start([c0])
    s1.cmd('switch s1 start')
    s2.start([c0])
    s2.cmd('switch s2 start')
    s3.start([c0])
    s3.cmd('switch s3 start')
    s4.start([c0])
    s4.cmd('switch s4 start')

    s1.cmd('bash forwarding_table_normal.sh'
           )  # setting up switches forwarding table

    time.sleep(5)

    # to set tcp segmentation tso, gro, gso offloading disabled
    print "\n*** Configuring tso, gro, gso & Flowtable"
    h1.cmd('bash eth.sh')  # host1 -- gro, gso, tso off
    h4.cmd('bash eth.sh')  # host4 -- gro, gso, tso off
    h2.cmd('bash eth.sh')  # host4 -- gro, gso, tso off
    h3.cmd('bash eth.sh')  # host4 -- gro, gso, tso off
    time.sleep(2)
    s1.cmd('bash eth.sh')  # switch1 -- gro, gso, tso off
    s2.cmd('bash eth.sh')  # switch2 -- gro, gso, tso off
    s3.cmd('bash eth.sh')  # switch3 -- gro, gso, tso off
    s4.cmd('bash eth.sh')  # switch4 -- gro, gso, tso off
    time.sleep(2)
    s2.cmd('bash reno.sh'
           )  # setting tcp RENO, window_scalling on, maximum receiver buffer
    time.sleep(2)
    # StopWatch website to open
    # webbrowser.open('http://timer-tab.com/', new = 0)

    print "*** Dumping Host Connections"
    dumpNodeConnections(net.hosts)

    print "*** Ping : Checking connectivity"
    net.pingAll()

    time.sleep(2)

    print "*** Start transfering data"
    h4.cmd('./h4.sh &')
    h3.cmd('./host.sh &')
    h1.cmd('./h1.sh &')
    h2.cmd('./h2.sh &')
    '''
	# h1.cmd('h1 ping h2 -c 2')

	# h2.cmd('tcpdump -i h2-eth2 -w server-tcpdump')
	# h1.cmd('tcpdump -i h1-eth2 -w client-tcpdump')
	# h2.cmd('iperf -s > server_output.txt &')
	# h1.cmd('iperf -c ', h1.IP() + ' -i 1 -t 50   >  client_output.txt &')
	'''
    print "*** Running CLI"
    CLI(net)
    print "*** Stopping network"
    net.stop()
Example #46
0
from mininet.cli import CLI
from mininet.net import Mininet
from mininet.node import RemoteController
from mininet.term import makeTerm

if '__main__' == __name__:
    net = Mininet(controller=RemoteController)

    c0 = net.addController('c0', port=6633)

    s1 = net.addSwitch('s1')
    s2 = net.addSwitch('s2')
    s3 = net.addSwitch('s3')

    h1 = net.addHost('h1')
    h2 = net.addHost('h2')
    h3 = net.addHost('h3')

    net.addLink(s1, h1)
    net.addLink(s2, h2)
    net.addLink(s3, h3)

    net.addLink(s1, s2)
    net.addLink(s2, s3)
    net.addLink(s3, s1)

    net.build()
    c0.start()
    s1.start([c0])
    s2.start([c0])
def myNetwork():

    net = Mininet(topo=None, build=False, ipBase='10.0.0.0/8')

    info('*** Adding controller\n')
    c1 = net.addController(name='c1',
                           controller=RemoteController,
                           ip='172.17.0.3',
                           protocol='tcp',
                           port=6653)

    c0 = net.addController(name='c0',
                           controller=RemoteController,
                           ip='172.17.0.2',
                           protocol='tcp',
                           port=6653)

    c2 = net.addController(name='c2',
                           controller=RemoteController,
                           ip='172.17.0.4',
                           protocol='tcp',
                           port=6653)

    info('*** Add switches\n')
    s1 = net.addSwitch('s1', cls=OVSKernelSwitch)
    s2 = net.addSwitch('s2', cls=OVSKernelSwitch)
    s4 = net.addSwitch('s4', cls=OVSKernelSwitch)
    s5 = net.addSwitch('s5', cls=OVSKernelSwitch)
    s6 = net.addSwitch('s6', cls=OVSKernelSwitch)
    s3 = net.addSwitch('s3', cls=OVSKernelSwitch)

    info('*** Add hosts\n')
    h6 = net.addHost('h6', cls=Host, ip='10.0.0.6', defaultRoute=None)
    h9 = net.addHost('h9', cls=Host, ip='10.0.0.9', defaultRoute=None)
    h11 = net.addHost('h11', cls=Host, ip='10.0.0.11', defaultRoute=None)
    h5 = net.addHost('h5', cls=Host, ip='10.0.0.5', defaultRoute=None)
    h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None)
    h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute=None)
    h7 = net.addHost('h7', cls=Host, ip='10.0.0.7', defaultRoute=None)
    h8 = net.addHost('h8', cls=Host, ip='10.0.0.8', defaultRoute=None)
    h10 = net.addHost('h10', cls=Host, ip='10.0.0.10', defaultRoute=None)
    h12 = net.addHost('h12', cls=Host, ip='10.0.0.12', defaultRoute=None)
    h4 = net.addHost('h4', cls=Host, ip='10.0.0.4', defaultRoute=None)
    h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)

    info('*** Add links\n')
    net.addLink(h1, s1)
    net.addLink(h2, s1)
    net.addLink(h3, s2)
    net.addLink(h4, s2)
    net.addLink(h5, s3)
    net.addLink(h6, s3)
    net.addLink(h7, s4)
    net.addLink(h8, s4)
    net.addLink(h9, s5)
    net.addLink(h10, s5)
    net.addLink(h11, s6)
    net.addLink(h12, s6)
    net.addLink(s1, s2)
    net.addLink(s2, s3)
    net.addLink(s3, s4)
    net.addLink(s4, s5)
    net.addLink(s6, s5)

    info('*** Starting network\n')
    net.build()
    info('*** Starting controllers\n')
    for controller in net.controllers:
        controller.start()

    info('*** Starting switches\n')
    net.get('s1').start([c0])
    net.get('s2').start([c0])
    net.get('s4').start([c1])
    net.get('s5').start([c2])
    net.get('s6').start([c2])
    net.get('s3').start([c1])

    info('*** Post configure switches and hosts\n')

    CLI(net)
    net.stop()
def mobileNet(name, configFile):

    resp = requests.get('http://192.168.1.3:8080/api/settings/init')
    if resp.status_code != 200:
        # This means something went wrong.
        raise ApiError('GET /tasks/ {}'.format(resp.status_code))
    sats = resp.json()['satellites']

    # print("*** Loading the parameters for simulation ***\n")
    # # Parsing the JSON file
    # with open(configFile, 'r') as read_file:
    #     paras = json.load(read_file)
    # sats = paras['SatcomScnDef']['sateDef']
    # usrs = paras['SatcomScnDef']['userDef']
    # lnks = paras['SatcomScnDef']['scnLinkDef']

    # Initializing the Mininet network
    net = Mininet(controller=Controller, link=TCLink, autoSetMacs=True)

    print("*** Creating nodes ***")
    # Storing all nodes objects
    nodes = {}
    # Storing all links information
    tcInfo = {}

    # Creating satellite nodes: each satellite is constructed with one host and one switch
    for sat, i in zip(sats, range(1, len(sats) + 1)):
        sat_name = 'h' + str(i)
        sat_id = str(sat['satID']) + '-sat'
        print(sat_name, sat_id)
        swi_name = 's' + str(i)
        # Type id for satellite is 1
        swi_id = '1' + str(sat['satID'])
        node = net.addHost(sat_name, position=str(50 + (5 * i)) + ',50,0')
        nodes[sat_id] = node
        node = net.addSwitch(swi_name)
        nodes[swi_id] = node
        net.addLink(nodes[sat_id], nodes[swi_id])

    # # Creating user nodes: each user is constructed with one host and one switch
    # for usr,i in zip(usrs,range(len(sats)+1,len(sats)+len(usrs)+1)):
    #     usr_name = 'h'+str(i)
    #     usr_id = str(usr['ID'])+'-usr'
    #     print(usr_name, usr_id)
    #     swi_name = 's' + str(i)
    #     # Type id for user is 0
    #     swi_id = '0'+str(usr['ID'])
    #     node = net.addHost(usr_name, position=str(50+(30*i))+',150,0')
    #     nodes[usr_id] = node
    #     node = net.addSwitch(swi_name)
    #     nodes[swi_id] = node
    #     net.addLink(nodes[usr_id], nodes[swi_id])

    # # Creating links
    # for lnk in lnks:
    #     src_id = str(lnk['Config'][0]['srcType'])+str(lnk['Config'][0]['srcID'])
    #     des_id = str(lnk['Config'][1]['destType'])+str(lnk['Config'][1]['destID'])
    #     print(src_id, des_id)
    #     node_s = nodes[src_id]
    #     node_d = nodes[des_id]
    #     net.addLink(node_s, node_d)
    #     tcInfo.setdefault(src_id+'->'+des_id, {})
    #     break

    # Creating default controller to the network
    node = net.addController('c0')
    nodes['c0'] = node

    # print("*** Loading event into Controller ***")
    # # Parsing the JSON file
    # with open('configs/gpsSCNSimulationscripv2t.json', 'r') as read_file:
    #     events = json.load(read_file)
    # linkEvents = events['SimScript']['scnLinkEvnt']
    # appEvents = events['SimScript']['scnappEvnt']
    # # Storing all the events info
    # actList = {}
    # # Link event: format [time, [source, destination, event type, parameter]]
    # for evt in linkEvents:
    #     for act in evt['actionlist']:
    #         actList.setdefault(str(act['Time']), []).append([str(evt['srcType'])+str(evt['srcID']), str(evt['destType'])+str(evt['destID']), str(act['Type']), str(act['para1'])])
    # # Application event: format [time, [application name, event type, parameter]]
    # for evt in appEvents:
    #     for act in evt['actionlist']:
    #         actList.setdefault(str(act['Time']), []).append([str(evt['AppName']), str(act['Type']), str(act['para1'])])
    # # Sorting the event list based on the timestamp
    # actList = sorted(actList.items(), key=lambda x:float(x[0]))
    # print actList

    print("*** Starting network simulation ***")
    # Starting the Mininet simulation network
    net.start()

    # Creating and starting the controller logic thread
    # control_thread = threading.Thread(target=controllerLogic,args=(net, nodes, tcInfo, actList))
    # control_thread.start()
    # control_thread.join()

    # CLI(net)
    # time.sleep(5)
    # nodes['38833-sat'].cmdPrint('iperf -s &')
    # nodes['39533-sat'].cmdPrint('iperf -c 10.0.0.22 -t 10')
    # time.sleep(15)

    # print "*** Addressing for station ***"
    # for i in range(1, numOfSPSta+numOfMPSta+1):
    #     sta_name = 'sta'+str(i)
    #     station = nodes[sta_name]
    #     for j in range(0, wlanPerSta):
    #         station.cmdPrint('ifconfig '+sta_name+'-wlan'+str(j)+' 10.0.'+str(i+1)+'.'+str(j)+'/32')
    #         station.cmdPrint('ip rule add from 10.0.'+str(i+1)+'.'+str(j)+' table '+str(j+1))
    #         station.cmdPrint('ip route add 10.0.'+str(i+1)+'.'+str(j)+'/32 dev '+sta_name+'-wlan'+str(j)+' scope link table '+str(j+1))
    #         station.cmdPrint('ip route add default via 10.0.'+str(i+1)+'.'+str(j)+' dev '+sta_name+'-wlan'+str(j)+' table '+str(j+1))
    #         if j==0:
    #             station.cmdPrint('ip route add default scope global nexthop via 10.0.'+str(i+1)+'.'+str(j)+' dev '+sta_name+'-wlan'+str(j))
    #     for j in range(wlanPerSta, ethPerSta+wlanPerSta):
    #         station.cmdPrint('ifconfig '+sta_name+'-eth'+str(j)+' 10.0.'+str(i+1)+'.'+str(j)+'/32')
    #         station.cmdPrint('ip rule add from 10.0.'+str(i+1)+'.'+str(j)+' table '+str(j+1))
    #         station.cmdPrint('ip route add 10.0.'+str(i+1)+'.'+str(j)+'/32 dev '+sta_name+'-eth'+str(j)+' scope link table '+str(j+1))
    #         station.cmdPrint('ip route add default via 10.0.'+str(i+1)+'.'+str(j)+' dev '+sta_name+'-eth'+str(j)+' table '+str(j+1))
    #         # if j==1 and i==1:
    #         #     station.cmdPrint('ip route add default scope global nexthop via 10.0.'+str(i+1)+'.'+str(j)+' dev '+sta_name+'-eth'+str(j))

    # print "*** Data processing ***"
    # for i in range(1, numOfSPSta+numOfMPSta+numOfFixApSta+numOfFixLteSta+1):
    #     for j in range(0, wlanPerSta):
    #         ip = '10.0.'+str(i+1)+'.'+str(j)
    #         if mptcpEnabled:
    #             out_f = folderName+'/sta'+str(i)+'-wlan'+str(j)+'_mptcp.stat'
    #         else:
    #             out_f = folderName+'/sta'+str(i)+'-wlan'+str(j)+'_sptcp.stat'
    #         nodes['sta'+str(i)].cmdPrint('sudo tshark -r '+folderName+'/sta'+str(i)+'-wlan'+str(j)+'.pcap -qz \"io,stat,0,BYTES()ip.src=='+ip+',AVG(tcp.analysis.ack_rtt)tcp.analysis.ack_rtt&&ip.addr=='+ip+'\" >'+out_f)
    #     for j in range(wlanPerSta, ethPerSta+wlanPerSta):
    #         ip = '10.0.'+str(i+1)+'.'+str(j)
    #         if mptcpEnabled:
    #             out_f = folderName + '/sta' + str(i) + '-eth' + str(j) + '_mptcp.stat'
    #         else:
    #             out_f = folderName + '/sta' + str(i) + '-eth' + str(j) + '_sptcp.stat'
    #         nodes['sta'+str(i)].cmdPrint('sudo tshark -r '+folderName+'/sta'+str(i)+'-eth'+str(j)+'.pcap -qz \"io,stat,0,BYTES()ip.src=='+ip+',AVG(tcp.analysis.ack_rtt)tcp.analysis.ack_rtt&&ip.addr=='+ip+'\" >'+out_f)

    # if trafficGen == 'd':
    #     os.system('sudo python analysis.py '+(str(range(1, numOfSPSta+numOfMPSta+numOfFixApSta+numOfFixLteSta+1))).replace(' ', '')+' '+folderName)

    # throughput_l = []
    # delay_l = []
    # for i in range(1, numOfSPSta+numOfMPSta+numOfFixApSta+numOfFixLteSta+1):
    #     throughput, delay, byte = (0.0, 0.0, 0.0)
    #     if i<=numOfSPSta+numOfMPSta:
    #         for j in range(0, wlanPerSta):
    #             if mptcpEnabled:
    #                 out_f = folderName + '/sta' + str(i) + '-wlan' + str(j) + '_mptcp.stat'
    #             else:
    #                 out_f = folderName + '/sta' + str(i) + '-wlan' + str(j) + '_sptcp.stat'
    #             f = open(out_f, 'r')
    #             for line in f:
    #                 if line.startswith('|'):
    #                     l = line.strip().strip('|').split()
    #                     if '<>' in l:
    #                         duration = float(l[2])
    #                         byte += float(l[8])
    #                         throughput += float(l[8]) * 8 / duration
    #                         delay += float(l[8]) * float(l[10])
    #             f.close()
    #         for j in range(wlanPerSta, ethPerSta + wlanPerSta):
    #             if mptcpEnabled:
    #                 out_f = folderName + '/sta' + str(i) + '-eth' + str(j) + '_mptcp.stat'
    #             else:
    #                 out_f = folderName + '/sta' + str(i) + '-eth' + str(j) + '_sptcp.stat'
    #             f = open(out_f, 'r')
    #             for line in f:
    #                 if line.startswith('|'):
    #                     l = line.strip().strip('|').split()
    #                     if '<>' in l:
    #                         duration = float(l[2])
    #                         byte += float(l[8])
    #                         throughput = throughput + float(l[8]) * 8 / duration if duration else 0
    #                         delay += float(l[8]) * float(l[10])
    #             f.close()
    #         delay = delay / byte if byte else 0
    #         throughput_l.append(str(throughput))
    #         delay_l.append(str(delay))
    #         out_f = folderName + "/sta" + str(i) + '-wireshark.stat'
    #         o = open(out_f, 'w')
    #         o.write("Throughput: " + str(throughput) + "\nDelay: " + str(delay))
    #         o.close()

    # statFile = folderName + '/' + protocol + ".stat"
    # o = open(statFile, 'w')
    # host_l = []
    # for i in range(1, numOfSPSta+numOfMPSta+numOfFixApSta+numOfFixLteSta+1):
    #     host_l.append('sta' + str(i))
    # o.write(','.join(str(i) for i in host_l))
    # o.write('\n')
    # o.write(','.join(str(i) for i in throughput_l))
    # o.write('\n')
    # o.write(','.join(str(i) for i in delay_l))
    # o.close()

    print("*** Stopping network ***")
    net.stop()
Example #49
0
def FTopo():

    net = Mininet(topo=None, link=link, build=False, ipBase='1.0.0.0/24')

    info('*** Adding controller\n')
    c0 = net.addController(name='c0', controller=RemoteController)

    info('*** Add switches\n')
    s1 = net.addSwitch('s1', cls=OVSKernelSwitch)
    s2 = net.addSwitch('s2', cls=OVSKernelSwitch)
    s3 = net.addSwitch('s3', cls=OVSKernelSwitch)
    s4 = net.addSwitch('s4', cls=OVSKernelSwitch)
    s5 = net.addSwitch('s5', cls=OVSKernelSwitch)
    s6 = net.addSwitch('s6', cls=OVSKernelSwitch)
    s7 = net.addSwitch('s7', cls=OVSKernelSwitch)
    s8 = net.addSwitch('s8', cls=OVSKernelSwitch)
    s9 = net.addSwitch('s9', cls=OVSKernelSwitch)
    s10 = net.addSwitch('s10', cls=OVSKernelSwitch)
    s11 = net.addSwitch('s11', cls=OVSKernelSwitch)
    s12 = net.addSwitch('s12', cls=OVSKernelSwitch)
    s13 = net.addSwitch('s13', cls=OVSKernelSwitch)
    s14 = net.addSwitch('s14', cls=OVSKernelSwitch)
    s15 = net.addSwitch('s15', cls=OVSKernelSwitch)

    info('*** Add hosts\n')
    h1 = net.addHost('h1', cls=Host, ip='1.0.2.1', mac='00:01:00:00:00:37')
    h2 = net.addHost('h2', cls=Host, ip='1.0.2.2', mac='00:01:00:00:00:38')
    h3 = net.addHost('h3', cls=Host, ip='1.0.2.3', mac='00:01:00:00:00:39')
    h4 = net.addHost('h4', cls=Host, ip='1.0.2.4', mac='00:01:00:00:00:3a')
    h5 = net.addHost('h5', cls=Host, ip='1.0.2.5', mac='00:01:00:00:00:3b')
    h6 = net.addHost('h6', cls=Host, ip='1.0.2.6', mac='00:01:00:00:00:3c')
    h7 = net.addHost('h7', cls=Host, ip='1.0.2.7', mac='00:01:00:00:00:3d')
    h8 = net.addHost('h8', cls=Host, ip='1.0.2.8', mac='00:01:00:00:00:3e')
    h9 = net.addHost('h9', cls=Host, ip='1.0.2.9', mac='00:01:00:00:00:3f')
    h10 = net.addHost('h10', cls=Host, ip='1.0.2.10', mac='00:01:00:00:00:40')
    h11 = net.addHost('h11', cls=Host, ip='1.0.2.11', mac='00:01:00:00:00:41')
    h12 = net.addHost('h12', cls=Host, ip='1.0.2.12', mac='00:01:00:00:00:42')
    h13 = net.addHost('h13', cls=Host, ip='1.0.2.13', mac='00:01:00:00:00:43')
    h14 = net.addHost('h14', cls=Host, ip='1.0.2.14', mac='00:01:00:00:00:44')
    h15 = net.addHost('h15', cls=Host, ip='1.0.2.15', mac='00:01:00:00:00:45')
    h16 = net.addHost('h16', cls=Host, ip='1.0.2.16', mac='00:01:00:00:00:46')

    info('*** Add links\n')

    # s1 switch
    net.addLink(s1, s2)
    net.addLink(s1, s3)
    # s2 switch
    net.addLink(s2, s4)
    net.addLink(s2, s5)
    # s3 switch
    net.addLink(s3, s6)
    net.addLink(s3, s7)
    # s4 switch
    net.addLink(s4, s8)
    net.addLink(s4, s9)
    net.addLink(s4, s5)
    # s5 switch
    net.addLink(s5, s10)
    net.addLink(s5, s11)
    net.addLink(s5, s6)
    # s6 switch
    net.addLink(s6, s12)
    net.addLink(s6, s13)
    net.addLink(s6, s7)
    # s7 switch
    net.addLink(s7, s14)
    net.addLink(s7, s15)
    # s8 switch
    net.addLink(s8, h2)
    net.addLink(s8, h1)
    # s9 switch
    net.addLink(s9, h3)
    net.addLink(s9, h4)
    # s10 switch
    net.addLink(s10, h5)
    net.addLink(s10, h6)
    # s11 switch
    net.addLink(s11, h7)
    net.addLink(s11, h8)
    # s12 switch
    net.addLink(s12, h9)
    net.addLink(s12, h10)
    # s13 switch
    net.addLink(s13, h11)
    net.addLink(s13, h12)
    # s14 switch
    net.addLink(s14, h13)
    net.addLink(s14, h14)
    # s15 switch
    net.addLink(s15, h15)
    net.addLink(s15, h16)

    info('*** Starting network\n')
    net.start()
    dumpNodeConnections(net.hosts)

    # info( '*** Starting controllers\n')
    # for controller in net.controllers:
    #     controller.start()

    info('*** Post configure switches and hosts\n')

    CLI(net)
    net.stop()
Example #50
0
print "#                             #"
print "###############################"
#
servicelevel = input("Number selection: ")
print 'Selection: %s ' % servicelevel
print " "
a = raw_input ("Hit Enter to confirm!")
os.system('clear')
#
#
#net = Mininet( controller=RemoteController )
net = Mininet( topo=None, build=False )
c0 = net.addController( 'c0' )
c1 = net.addController('c1' , controller=RemoteController, ip='10.192.34.22')
#c1 = RemoteController( 'c1', ip='10.192.34.22' )
h1 = net.addHost( 'h1' )
h2 = net.addHost( 'h2' )
s1 = net.addSwitch( 's1' )
net.addLink( h1, s1 )
net.addLink( h2, s1 )
os.system('clear')

print "###############################"
print "# Creating Virtual Machines.. #"
print "# Creating Virtual Switch.... #"
print "# Assign IP addressing....... #"
print "# Testing IP connectivity.... #"
print "###############################"
net.start()
#CLI( net )
print h1.cmd( 'ping -c2', h2.IP() )
def MyNetwork():
    net = Mininet(topo=None, build=False, ipBase='192.168.1.0/24', link=TCLink)

    info("*** Creating Network")
    print("")
    print("")

    info("*** Adding Controller 1 and Controller 2")
    print("")
    print("")
    # add Controller 1
    c1 = net.addController(name='Controller1',
                           controller=RemoteController,
                           ip='192.168.56.101',
                           port=6633)

    # add Controller 2
    c2 = net.addController(name='Controller2',
                           controller=RemoteController,
                           ip='192.168.56.102',
                           port=6634)

    info("*** Adding four switch")
    print("")
    # add switch
    switch1 = net.addSwitch('switch1')
    switch2 = net.addSwitch('switch2')
    switch3 = net.addSwitch('switch3')
    switch4 = net.addSwitch('switch4')
    print("(switch1,switch2,switch3,switch4)")
    print("")

    # add host
    host1 = net.addHost('h1', ip='192.168.1.1')
    host2 = net.addHost('h2', ip='192.168.1.2')
    host3 = net.addHost('h3', ip='192.168.1.3')
    host4 = net.addHost('h4', ip='192.168.1.4')
    host5 = net.addHost('h5', ip='192.168.1.5')
    host6 = net.addHost('h6', ip='192.168.1.6')
    host7 = net.addHost('h7', ip='192.168.1.7')
    host8 = net.addHost('h8', ip='192.168.1.8')

    # add link
    net.addLink(host1, switch1)
    net.addLink(host2, switch1)
    net.addLink(host3, switch2)
    net.addLink(host4, switch2)
    net.addLink(host5, switch3)
    net.addLink(host6, switch3)
    net.addLink(host7, switch4)
    net.addLink(host8, switch4)

    net.addLink(switch1, switch2)
    net.addLink(switch2, switch3)
    net.addLink(switch3, switch4)

    net.build()

    for controller in net.controllers:
        controller.start()

    net.get('switch1').start([c1])
    net.get('switch2').start([c1])
    net.get('switch3').start([c1])
    net.get('switch4').start([c1])

    print("")

    CLI(net)
    net.stop()
Example #52
0
from mininet.cli import CLI
from mininet.log import setLogLevel, info, error
from mininet.link import Intf
from mininet.util import quietRun

info("*** Creating controllers\n")
net = Mininet( controller=RemoteController )
c1 = net.addController('c1', ip='192.168.56.101', port=6633)
c2 = net.addController('c2', ip='192.168.56.102', port=6633)

info("*** Creating switches\n")
s1 = net.addSwitch('s1',dpid='0000000000000005')

info("*** Creating hosts\n")
h1 = net.addHost('h1',ip='10.0.1.1')
h2 = net.addHost('h2',ip='10.0.1.2')

info("*** Creating links\n")
net.addLink(s1,h1)
net.addLink(s1,h2)

intfName = sys.argv[ 1 ] if len( sys.argv ) > 1 else 'eth1' # 'eth1' can be instead by physical ethernet you want to assign to mininet switch
_intf = Intf( intfName, node=s1) # assign physical port to switch in mininet

info("*** Starting network\n")
net.build()
net.start()
CLI(net)
net.stop()
from mininet.cli import CLI
from mininet.link import TCLink
import os
import time

if __name__ == '__main__':

    delays = [30]
    loss_list = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90]
    max_pkts = [1000, 10000]
    max_rts = [1, 2, 3, 4, 5]
    timeout = 120000

    net = Mininet(link=TCLink)

    net.addHost('h1', ip="10.0.0.1", mac="00:00:00:00:00:01")
    net.addHost('h2', ip="10.0.0.2", mac="00:00:00:00:00:02")
    # net.addSwitch('s1')

    h1 = net['h1']
    h2 = net['h2']
    # s1 = net.switches[0]

    params = dict(intfName1='eth0', intfName2='eth0', delay='0ms', loss=0)

    net.addLink(h1, h2, **params)
    # net.addLink(h1, s1, loss=5)
    # net.addLink(h2, s1, loss=5)

    setLogLevel( 'info' )
    net.start()
def MyNetwork():
    net = Mininet(topo=None,
                  build=False,
                  ipBase='10.0.0.0/8',
                  link=TCLink,
                  host=CPULimitedHost)

    info("****Adding Controller1")
    print ""

    c1 = net.addController(name='poxController',
                           controller=RemoteController,
                           ip='0.0.0.0',
                           port=6633)
    info("****Adding Second Controller")
    print ""
    c2 = net.addController(name='poxController2',
                           controller=RemoteController,
                           ip='0.0.0.0',
                           port=6634)

    info('****Now Adding Two Switches')
    print ""

    switch1 = net.addSwitch('switch1')
    switch2 = net.addSwitch('switch2')
    switch3 = net.addSwitch('switch3')
    switch4 = net.addSwitch('switch4')
    switch5 = net.addSwitch('switch5')
    switch6 = net.addSwitch('switch6')
    switch7 = net.addSwitch('switch7')
    switch8 = net.addSwitch('switch8')

    host1 = net.addHost('h1', ip='10.0.0.1/8', cpu=0.1)
    host2 = net.addHost('h2', ip='10.0.0.2/8', cpu=0.1)
    host3 = net.addHost('h3', ip='10.0.0.3/8', cpu=0.1)
    host4 = net.addHost('h4', ip='10.0.0.4/8', cpu=0.1)
    host5 = net.addHost('h5', ip='10.0.0.5/8', cpu=0.1)
    host6 = net.addHost('h6', ip='10.0.0.6/8', cpu=0.1)
    host7 = net.addHost('h7', ip='10.0.0.7/8', cpu=0.1)
    host8 = net.addHost('h8', ip='10.0.0.8/8', cpu=0.1)

    net.addLink(host1, switch1, bw=100, max_queue_size=5000, use_htb=True)
    net.addLink(host2, switch2, bw=100, max_queue_size=5000, use_htb=True)
    net.addLink(host3, switch3, bw=100, max_queue_size=5000, use_htb=True)
    net.addLink(host4, switch4, bw=100, max_queue_size=5000, use_htb=True)
    net.addLink(host5, switch5, bw=100, max_queue_size=5000, use_htb=True)
    net.addLink(host6, switch6, bw=100, max_queue_size=5000, use_htb=True)
    net.addLink(host7, switch7, bw=100, max_queue_size=5000, use_htb=True)
    net.addLink(host8, switch8, bw=100, max_queue_size=5000, use_htb=True)

    net.addLink(switch1, switch2)
    net.addLink(switch2, switch3)
    net.addLink(switch3, switch4)
    net.addLink(switch4, switch5)
    # net.addLink(switch5, switch1)

    # net.addLink(switch4, switch1)

    net.addLink(switch5, switch6)
    net.addLink(switch6, switch7)
    net.addLink(switch7, switch8)
    # net.addLink(switch8, switch1)

    net.build()

    for controller in net.controllers:
        controller.start()

    net.get('switch1').start([c1, c2])
    net.get('switch2').start([c1, c2])
    net.get('switch3').start([c1, c2])
    net.get('switch4').start([c1, c2])
    net.get('switch5').start([c1, c2])
    net.get('switch6').start([c1, c2])
    net.get('switch7').start([c1, c2])
    net.get('switch8').start([c1, c2])

    # net.get('switch1').stop()
    # net.get('switch2').stop()
    # net.get('switch3').stop()
    # net.get('switch4').stop()
    # net.get('switch5').stop()
    # net.get('switch6').stop()
    # net.get('switch7').stop()
    # net.get('switch8').stop()

    # net.get('switch1').start([c1])
    # net.get('switch2').start([c1])
    # net.get('switch3').start([c1])
    # net.get('switch4').start([c1])
    # net.get('switch5').start([c2])
    # net.get('switch6').start([c2])
    # net.get('switch7').start([c2])
    # net.get('switch8').start([c2])

    CLI(net)
    net.stop()
Example #55
0
#!/usr/bin/env python

from mininet.cli import CLI
from mininet.net import Mininet
from mininet.link import Link, TCLink, Intf

if '__main__' == __name__:

    net = Mininet(link=TCLink)

    h1 = net.addHost('h1')  # Sender
    h2 = net.addHost('h2')  # Router
    h3 = net.addHost('h3')  # Receiver

    net.addLink(h1, h2)  # Sender - Router
    net.addLink(h2, h3)  # Receiver - Router

    net.build()

    # Seperate the network

    h1.cmd('ifconfig h1-eth0 172.16.0.1 netmask 255.255.0.0')
    h2.cmd('ifconfig h2-eth0 172.16.0.2 netmask 255.255.0.0')

    h3.cmd('ifconfig h3-eth0 172.17.0.1 netmask 255.255.0.0')
    h2.cmd('ifconfig h2-eth1 172.17.0.2 netmask 255.255.0.0')

    h2.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward')  # Routing => enable

    h1.cmd('route add default gw 172.16.0.2')  # h2-eth0
    h3.cmd('route add default gw 172.17.0.2')  # h2-eth1
Example #56
0
def topology():
    "Create a network."
    net = Mininet(controller=RemoteController,
                  link=TCLink,
                  switch=OVSKernelSwitch)

    #begin controller
    c1 = net.addController('c1',
                           controller=RemoteController,
                           ip='127.0.0.1',
                           port=6633,
                           mac='00:00:00:00:00:0d')

    #add switches
    print "*** Creating Switches"
    s1 = net.addSwitch('s1', listenPort=6634, mac='00:00:00:00:00:02')
    s2 = net.addSwitch('s2', listenPort=6634, mac='00:00:00:00:00:03')
    s3 = net.addSwitch('s3', listenPort=6634, mac='00:00:00:00:00:04')
    s4 = net.addSwitch('s4', listenPort=6634, mac='00:00:00:00:00:05')
    s5 = net.addSwitch('s5', listenPort=6634, mac='00:00:00:00:00:06')
    lb6 = net.addSwitch('lb6', listenPort=6634, mac='00:00:00:00:00:07')
    lb7 = net.addSwitch('lb7', listenPort=6634, mac='00:00:00:00:00:08')
    id8 = net.addSwitch('id8', listenPort=6634, mac='00:00:00:00:00:09')
    n9 = net.addSwitch('n9', listenPort=6634, mac='00:00:00:00:00:0a')
    fw10 = net.addSwitch('fw10', listenPort=6634, mac='00:00:00:00:00:0b')
    fw11 = net.addSwitch('fw11', listenPort=6634, mac='00:00:00:00:00:0c')

    #add hosts
    print "*** Creating Hosts "
    h1 = net.addHost('h1', ip='100.0.0.11/24')
    h2 = net.addHost('h2', ip='100.0.0.12/24')
    h3 = net.addHost('h3', ip='100.0.0.51/24')
    h4 = net.addHost('h4', ip='100.0.0.52/24')
    ws5 = net.addHost('ws5', ip='100.0.0.40/24')
    ws6 = net.addHost('ws6', ip='100.0.0.41/24')
    ws7 = net.addHost('ws7', ip='100.0.0.42/24')
    ds8 = net.addHost('ds8', ip='100.0.0.20/24')
    ds9 = net.addHost('ds9', ip='100.0.0.21/24')
    ds10 = net.addHost('ds10', ip='100.0.0.22/24')
    insp11 = net.addHost('insp11', ip='100.0.0.30/24')

    print "*** Creating links"
    net.addLink(s1, h1)
    net.addLink(s1, h2)
    net.addLink(s1, fw10)
    net.addLink(s2, fw10)

    net.addLink(s2, fw11)
    net.addLink(s2, id8)
    net.addLink(s2, lb6)
    net.addLink(s3, ds8)
    net.addLink(s3, ds9)
    net.addLink(s3, ds10)
    net.addLink(s3, lb6)
    net.addLink(s4, ws5)
    net.addLink(s4, ws6)
    net.addLink(s4, ws7)
    net.addLink(s4, lb7)
    net.addLink(lb7, id8)
    net.addLink(n9, fw11)
    net.addLink(s5, h3)
    net.addLink(s5, h4)
    net.addLink(s5, n9)
    net.addLink(id8, insp11)

    print "*** Starting network"
    net.build()
    s1.start([c1])
    s2.start([c1])
    s3.start([c1])
    s4.start([c1])
    s5.start([c1])
    lb6.start([c1])
    lb7.start([c1])
    id8.start([c1])
    n9.start([c1])
    fw10.start([c1])
    fw11.start([c1])
    print("Done")
    test_start(net)
def createNetwork():
    #send rate at each link in Mbps
    bwg = 1  #in Mbps
    bwbn = 1  #in Mbps
    loss = 8  #in %
    mqs = 100  #max queue size of interfaces
    dly = '2.5ms'

    #create empty network
    net = Mininet(intf=TCIntf)

    info('\n*** Adding controller\n')
    net.addController('c0')  #is it ok ?

    #add host to topology
    ht = net.addHost('ht', ip='10.10.0.1/24')
    hu = net.addHost('hu', ip='10.10.0.2/24')
    it = net.addHost('it', ip='10.20.0.1/24')
    iu = net.addHost('iu', ip='10.20.0.2/24')

    rh = net.addHost('rh', ip='10.10.0.10/24')
    ri = net.addHost('ri', ip='10.20.0.20/24')

    info('\n** Adding Switches\n')
    # Adding 2 switches to the network
    sw1 = net.addSwitch('sw1')
    sw2 = net.addSwitch('sw2')

    info('\n** Creating Links \n')
    #create link beetween the network
    link_ht_sw1 = net.addLink(ht, sw1)
    link_hu_sw1 = net.addLink(hu, sw1)
    link_rh_sw1 = net.addLink(rh, sw1, intfName1='rh-eth0')

    link_it_sw2 = net.addLink(it, sw2)
    link_iu_sw2 = net.addLink(iu, sw2)
    link_ri_sw2 = net.addLink(ri, sw2, intfName1='ri-eth0')

    link_rh_ri = net.addLink(rh, ri, intfName1='rh-eth1', intfName2='ri-eth1')

    #set bandwith
    link_ht_sw1.intf1.config(bw=bwbn, max_queue_size=mqs)
    link_hu_sw1.intf1.config(bw=bwbn, max_queue_size=mqs)
    link_rh_sw1.intf1.config(
        bw=bwbn, max_queue_size=mqs
    )  #max_queue_size is hardcoded low to prevent bufferbloat, too high queuing delays

    link_it_sw2.intf1.config(bw=bwg, max_queue_size=mqs)
    link_iu_sw2.intf1.config(bw=bwg, max_queue_size=mqs)
    link_ri_sw2.intf1.config(bw=bwg, max_queue_size=mqs,
                             delay=dly)  #delay is set at ri on both interfaces

    link_rh_ri.intf1.config(
        bw=bwg, max_queue_size=mqs,
        loss=loss)  #loss is set at rh on its interface to ri only

    link_ht_sw1.intf2.config(bw=bwbn, max_queue_size=mqs)
    link_hu_sw1.intf2.config(bw=bwbn, max_queue_size=mqs)
    link_rh_sw1.intf2.config(bw=bwbn, max_queue_size=mqs)

    link_it_sw2.intf2.config(bw=bwg, max_queue_size=mqs)
    link_iu_sw2.intf2.config(bw=bwg, max_queue_size=mqs)
    link_ri_sw2.intf2.config(bw=bwg, max_queue_size=mqs)

    link_rh_ri.intf2.config(bw=bwg, max_queue_size=mqs,
                            delay=dly)  #delay is set at ri on both interfaces

    net.start()

    info('\n*** Configuring hosts\n')

    rh.cmd(
        'ifconfig rh-eth1 10.12.0.10 netmask 255.255.255.0'
    )  #reconfiguring mutiples intefaces host to prevent mininet strange initialisation behaviors
    rh.cmd('ifconfig rh-eth0 10.10.0.10 netmask 255.255.255.0')
    rh.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward'
           )  #enable forwarding at routers

    ri.cmd(
        'ifconfig ri-eth1 10.12.0.20 netmask 255.255.255.0'
    )  #reconfiguring mutiples intefaces host to prvent mininet strange initialisation behaviors
    ri.cmd('ifconfig ri-eth0 10.20.0.20 netmask 255.255.255.0')
    ri.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward'
           )  #enable forwarding at routers

    #configure host default gateways
    ht.cmd('ip route add default via 10.10.0.10')
    hu.cmd('ip route add default via 10.10.0.10')
    it.cmd('ip route add default via 10.20.0.20')
    iu.cmd('ip route add default via 10.20.0.20')

    #configure router routing tables
    rh.cmd('ip route add default via 10.12.0.20')
    ri.cmd('ip route add default via 10.12.0.10')

    # weiyu:
    iu.cmd('touch server.pcap')
    hu.cmd('touch client.pcap')

    rh.cmd('tc qdisc del dev rh-eth1 root')

    start_nodes(rh, ri, iu, hu, mqs)  #experiment actions

    it.cmd(
        'ethtool -K it-eth0 tx off sg off tso off'
    )  #disable TSO on TCP on defaul TCP sender need to be done on other host if sending large TCP file from other nodes

    time.sleep(1)

    # Enable the mininet> prompt if uncommented
    info('\n*** Running CLI\n')
    CLI(net)

    # stops the simulation
    net.stop()
Example #58
0
  net = Mininet(link=TCLink)

  key = "net.mptcp.mptcp_enabled"

  value = 1

  p = Popen("sysctl -w %s=%s" % (key, value), shell=True, stdout=PIPE, stderr=PIPE)

  stdout, stderr = p.communicate()

  print "stdout=",stdout,"stderr=", stderr

 

  h1 = net.addHost('h1')

  h2 = net.addHost('h2')

  r1 = net.addHost('r1')

  linkopt={'bw':10}

  net.addLink(r1,h1,cls=TCLink, **linkopt)

  net.addLink(r1,h1,cls=TCLink, **linkopt)

  net.addLink(r1,h2,cls=TCLink, **linkopt)

  net.addLink(r1,h2,cls=TCLink, **linkopt)
Example #59
0
def myNetwork():

    net = Mininet(topo=None, build=False, link=TCLink, ipBase='10.0.0.0/8')

    info('*** Adding controller\n')
    c0 = net.addController(name='c0',
                           controller=RemoteController,
                           ip='127.0.0.1',
                           protocol='tcp',
                           port=6633)

    info('*** Add switches\n')
    s1 = net.addSwitch('s1', cls=OVSKernelSwitch)

    info('*** Add hosts\n')
    h1 = net.addHost('h1',
                     cls=Host,
                     ip='10.0.0.1',
                     defaultRoute=None,
                     mac='00:00:00:00:00:01')
    h2 = net.addHost('h2',
                     cls=Host,
                     ip='10.0.0.2',
                     defaultRoute=None,
                     mac='00:00:00:00:00:02')
    h3 = net.addHost('h3',
                     cls=Host,
                     ip='10.0.0.3',
                     defaultRoute=None,
                     mac='00:00:00:00:00:03')
    h4 = net.addHost('h4',
                     cls=Host,
                     ip='10.0.0.4',
                     defaultRoute=None,
                     mac='00:00:00:00:00:04')
    h5 = net.addHost('h5',
                     cls=Host,
                     ip='10.0.0.5',
                     defaultRoute=None,
                     mac='00:00:00:00:00:05')
    h6 = net.addHost('h6',
                     cls=Host,
                     ip='10.0.0.6',
                     defaultRoute=None,
                     mac='00:00:00:00:00:06')

    info('*** Add links\n')
    # balanceado
    # net.addLink(h1, s1, bw=10)
    # net.addLink(h2, s1, bw=10)
    # net.addLink(h3, s1, bw=10)
    # net.addLink(h4, s1, bw=10)
    # net.addLink(h5, s1, bw=10)
    # net.addLink(h6, s1, bw=100)

    net.addLink(h1, s1, bw=5)
    net.addLink(h2, s1, bw=5)
    net.addLink(h3, s1, bw=7.5)
    net.addLink(h4, s1, bw=10)
    net.addLink(h5, s1, bw=10)
    net.addLink(h6, s1, bw=100)

    # net.addLink(s1, s2, bw=0.1) #port 1
    # net.addLink(s1, s2, bw=10) #port 2

    info('*** Starting network\n')
    net.build()
    info('*** Starting controllers\n')
    for controller in net.controllers:
        controller.start()

    info('*** Starting switches\n')
    net.get('s1').start([c0])

    net.get('h1').popen('python -m SimpleHTTPServer 80')
    net.get('h2').popen('python -m SimpleHTTPServer 80')
    net.get('h3').popen('python -m SimpleHTTPServer 80')
    net.get('h4').popen('python -m SimpleHTTPServer 80')
    net.get('h5').popen('python -m SimpleHTTPServer 80')

    CLI(net)
    net.stop()
Example #60
0
net = Mininet(host=CPULimitedHost, link=TCLink)
#creating nodes in the network
c0 = net.addController(name='c0',
                       controller=RemoteController,
                       ip='127.0.0.1',
                       port=6633)
s1 = net.addSwitch('s1', dpid='0000000000000001', protocols=["OpenFlow13"])
s2 = net.addSwitch('s2', dpid='0000000000000002', protocols=["OpenFlow13"])
s3 = net.addSwitch('s3', dpid='0000000000000003', protocols=["OpenFlow13"])
s4 = net.addSwitch('s4', dpid='0000000000000004', protocols=["OpenFlow13"])
s5 = net.addSwitch('s5', dpid='0000000000000005', protocols=["OpenFlow13"])
s6 = net.addSwitch('s6', dpid='0000000000000006', protocols=["OpenFlow13"])
s7 = net.addSwitch('s7', dpid='0000000000000007', protocols=["OpenFlow13"])
s8 = net.addSwitch('s8', dpid='0000000000000008', protocols=["OpenFlow13"])
#add hosts
h1 = net.addHost('h1', cpu=0.5 / 5, mac='00:00:00:00:00:01')
h2 = net.addHost('h2', cpu=0.5 / 5, mac='00:00:00:00:00:02')
h3 = net.addHost('h3', cpu=0.5 / 5, mac='00:00:00:00:00:03')
h4 = net.addHost('h4', cpu=0.5 / 5, mac='00:00:00:00:00:04')
h5 = net.addHost('h5', cpu=0.5 / 5, mac='00:00:00:00:00:05')
h6 = net.addHost('h6', cpu=0.5 / 5, mac='00:00:00:00:00:06')
h7 = net.addHost('h7', cpu=0.5 / 5, mac='00:00:00:00:00:07')
h8 = net.addHost('h8', cpu=0.5 / 5, mac='00:00:00:00:00:08')
#Creating links between nodes in network
#bw=1  1Mbps=1000kbps
#net.addLink(s0,h0,port1=None,port2=None,bw=10,delay='5ms',max_queue_size=100,loss=10,use_htb=True)
net.addLink(s1, h1, 1)
net.addLink(s1, h2, 2)
net.addLink(s1, h3, 3)
net.addLink(s1, h4, 4)
net.addLink(s8, h5, 1)