Example #1
0
def config( opts ):

    dhcp = bool(opts.dhcp)
    routers = bool(opts.routers)
    ipv6 = bool(opts.ipv6)
    ipv4 = bool(opts.ipv4)

    if opts.onosIp != '':
        controllers = opts.onosIp.split( ',' )
    else:
        controllers = ['127.0.0.1']
    topo = ComcastLeafSpineFabric(dhcp=dhcp, routers=routers, ipv6=ipv6,
                                  ipv4=ipv4)

    net = Mininet( topo=topo, link=TCLink, build=False,
                   controller=None, autoSetMacs=True )
    i = 0
    for ip in controllers:
        net.addController( "c%s" % ( i ), controller=RemoteController, ip=ip )
        i += 1

    net.build()
    net.start()
    CLI( net )
    net.stop()
Example #2
0
def intfOptions():
    "run various traffic control commands on a single interface"
    net = Mininet( autoStaticArp=True )
    net.addController( 'c0' )
    h1 = net.addHost( 'h1' )
    h2 = net.addHost( 'h2' )
    s1 = net.addSwitch( 's1' )
    link1 = net.addLink( h1, s1, cls=TCLink )
    net.addLink( h2, s1 )
    net.start()
    
    # flush out latency from reactive forwarding delay
    net.pingAll()

    info( '\n*** Configuring one intf with bandwidth of 5 Mb\n' )
    link1.intf1.config( bw=5 )
    info( '\n*** Running iperf to test\n' )
    net.iperf()

    info( '\n*** Configuring one intf with loss of 50%\n' )
    link1.intf1.config( loss=50 )
    info( '\n' )
    net.iperf( ( h1, h2 ), l4Type='UDP' )
    
    info( '\n*** Configuring one intf with delay of 15ms\n' )
    link1.intf1.config( delay='15ms' )
    info( '\n*** Run a ping to confirm delay\n' )
    net.pingPairFull()
    
    info( '\n*** Done testing\n' )
    net.stop()
Example #3
0
def emptyNet():

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

    net = Mininet( controller=lambda a: RemoteController(a, ip='128.208.125.60' ))

    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' )

    info( '*** Adding switch\n' )
    s3 = net.addSwitch( 's3' )
    s4 = net.addSwitch( 's4' )
    s5 = net.addSwitch( 's5' )

    info( '*** Creating links\n' )
    net.addLink( h1, s3 )
    net.addLink( h2, s5 )
    net.addLink( s3 , s4 )
    net.addLink( s4 , s5 )

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

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

    info( '*** Stopping network' )
    net.stop()
Example #4
0
def RunTest():
    """TOPO"""
    topo = FatTreeTopo()
    topo.topoCreate(4,4,2,2,2)

    CONTROLLER_NAME = topo.crtlname
    CONTROLLER_IP = topo.crtlip
    CONTROLLER_PORT = topo.crtlport
    net = Mininet(topo=topo,build= False,link=TCLink, controller=None)
    time.sleep(1)
    net.addController( CONTROLLER_NAME,controller=RemoteController,
                      ip=CONTROLLER_IP,
                      port=CONTROLLER_PORT)

    net.start()
    dumpNodeConnections(net.hosts)
    net.pingAll()
    h1 = net.get('h000')
    h16 = net.get('h311')
    h2 = net.get('h001')
    h1.popen('iperf -s -u -i 1')
    h16.popen('iperf -s -u -i 1')
    h2.cmdPrint('iperf -c '+ h1.IP() + ' -u -t 10 -i 1 -b 100m')
    h2.cmdPrint('iperf -c '+ h16.IP() + ' -u -t 10 -i 1 -b 100m')
    CLI(net)
    net.stop()
Example #5
0
def run():
    "Create control and data networks, and invoke the CLI"

    info( '* Creating Control Network\n' )
    ctopo = ControlNetwork( n=4, dataController=DataController )
    cnet = Mininet( topo=ctopo, ipBase='192.168.123.0/24', controller=None )
    info( '* Adding Control Network Controller\n')
    cnet.addController( 'cc0', controller=Controller )
    info( '* Starting Control Network\n')
    cnet.start()

    info( '* Creating Data Network\n' )
    topo = TreeTopo( depth=2, fanout=2 )
    # UserSwitch so we can easily test failover
    sw = partial( UserSwitch, opts='--inactivity-probe=1 --max-backoff=1' )
    net = Mininet( topo=topo, switch=sw, controller=None )
    info( '* Adding Controllers to Data Network\n' )
    for host in cnet.hosts:
        if isinstance(host, Controller):
            net.addController( host )
    info( '* Starting Data Network\n')
    net.start()

    mn = MininetFacade( net, cnet=cnet )

    CLI( mn )

    info( '* Stopping Data Network\n' )
    net.stop()

    info( '* Stopping Control Network\n' )
    cnet.stop()
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 myNet():
   MultiSwitch13 = partial( MultiSwitch, protocols='OpenFlow13' )
   #tree_topo = TreeTopo(depth=3,fanout=2)
   tree_topo = SingleSwitchTopo(n=14)

   net = Mininet(controller=RemoteController, topo=tree_topo, switch=MultiSwitch13, build=False, autoSetMacs=True)

   info( '*** Adding controllers\n')
   #c1 = net.addController('c1', controller=RemoteController, ip="127.0.0.1", port=6633)
   c1 = net.addController('c1', controller=RemoteController, ip="192.168.1.1", port=6633)
   c2 = net.addController('c2', controller=RemoteController, ip="192.168.1.2", port=6633)
   c3 = net.addController('c3', controller=RemoteController, ip="192.168.1.3", port=6633)

#   info( '*** Add 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( '*** Add switches\n')
#   s1 = net.addSwitch( 's1', cls=OVSKernelSwitch, protocols='OpenFlow13' )
#   s2 = net.addSwitch( 's2', cls=OVSKernelSwitch, protocols='OpenFlow13' )
#   s3 = net.addSwitch( 's3', cls=OVSKernelSwitch, protocols='OpenFlow13' )
#   s4 = net.addSwitch( 's4', cls=OVSKernelSwitch, protocols='OpenFlow13' )

#   info( '*** Add links\n')
#   s1.linkTo( h1 )
#   s1.linkTo( s2 )
#   s2.linkTo( h2 )
#   s2.linkTo( s3 )
#   s3.linkTo( h3 )
#   s3.linkTo( s4 )
#   s4.linkTo( h4 )

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

   info( '*** Starting controllers\n')
   c1.start()
   c2.start()
   c3.start()

#   info( '*** Starting switches\n')
#   s1.start([c1,c2,c3])
#   s2.start([c1,c2,c3])
#   s3.start([c1,c2,c3])
#   s4.start([c1,c2,c3])

   net.start()
   net.staticArp()
#   i = 0;
#   while i < 10:
#     h1, h2  = random.choice(net.hosts), random.choice(net.hosts)
#     print h1.IP(), "-->", h2.IP()
#     sent, received, rttmin, rttavg, rttmax, rttdev = ping(h1, h2)
#     print received,"/",sent
#     i = i + 1
#     sleep(1)
   CLI( net )
   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()
    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() :
        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
Example #11
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 #12
0
def createTopo(pod, density, ip="192.168.56.101", port=6633, bw_c2a=1000, bw_a2e=1000, bw_h2a=1000):
    logging.debug("LV1 Create Fattree")
    topo = Fattree(pod, density)
    topo.createTopo()
    topo.createLink(bw_c2a=bw_c2a, bw_a2e=bw_a2e, bw_h2a=bw_h2a)

    logging.debug("LV1 Start Mininet")
    CONTROLLER_IP = ip
    CONTROLLER_PORT = port
    switch = partial( OVSSwitch, protocols='OpenFlow13' )
    net = Mininet(topo=topo, switch=switch, link=TCLink, controller=None, autoSetMacs=True,
                  autoStaticArp=True)
    net.addController(
        'controller', controller=RemoteController,
        ip=CONTROLLER_IP, port=CONTROLLER_PORT)
    net.start()

    '''
        Set OVS's protocol as OF13
    '''
    topo.set_ovs_protocol_13()

    logger.debug("LV1 dumpNode")

    #dumpNodeConnections(net.hosts)
    #pingTest(net)
    #iperfTest(net, topo)

    CLI(net)
    net.stop()
Example #13
0
class ONOSCluster( Controller ):
    # TODO
    n = 3
   
    def start( self ):
        ctopo = ControlNetwork( n=self.n, dataController=ONOS )
        self.cnet = Mininet( topo=ctopo, ipBase='192.168.123.0/24', controller=None )
        self.cnet.addController( 'cc0', controller=Controller )
        self.cnet.start()

        self.ctrls = []
        for host in self.cnet.hosts:
            if isinstance( host, Controller ):
                self.ctrls.append( host )
                host.start()

    def stop( self ):
        for host in self.cnet.hosts:
            if isinstance( host, Controller ):
                host.stop()
        self.cnet.stop()
        
    def clist( self ):
        "Return list of Controller proxies for this ONOS cluster"
        print 'controllers:', self.ctrls
        return self.ctrls
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()
Example #15
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()
Example #16
0
 def _initMininet(self, ctrl=Floodlight.Controller):
     """Initialise a default configuration of Mininet"""
     mininet = Mininet(controller=ctrl)
     mininet.addController("controller1")
     overlord = Overlord()
     switch = mininet.addSwitch("switch1")
     return mininet, overlord, switch
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', dpid='00000000000000a1')
        h1 = self.net.addHost('h1', ip='10.0.0.11/24', mac='00:00:00:00:00:01')

        # Add links
        self.net.addLink(h1, 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=45.55.19.146 option:key=flow')
        CLI(self.net)
        self.net.stop()
Example #18
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 QoSFlowNet():
    "Create network by using QoSFlow user switch."
    
    net = Mininet(controller=RemoteController, switch=QoSFlowUserSwitch, link=TCLink) 
    
    info('*** Adding controller\n')
    net.addController('c0')
    
    info('*** Adding hosts\n')
    h1 = net.addHost('h1')
    h2 = net.addHost('h2')

    info('*** Adding switch\n')
    I1 = net.addSwitch('I1')
    s2 = net.addSwitch('s2')
    s3 = net.addSwitch('s3')
    s4 = net.addSwitch('s4')
    s5 = net.addSwitch('s5')
    s6 = net.addSwitch('s6')
    s7 = net.addSwitch('s7')
    s8 = net.addSwitch('s8')
    s9 = net.addSwitch('s9')
    E2 = net.addSwitch('E2')

    info('*** Creating host links\n')
    #h2.linkTo(s2)
    net.addLink(I1, h1)#, 2, 1, intfName1 = 'eth0-h1')
    net.addLink(E2, h2)#, 2, 1, intfName1 = 'eth0-h2')

    info('*** Creating swicth links\n')
    #s1.linkTo(s2)
    net.addLink(I1, s2)
    net.addLink(s2, s3)
    net.addLink(s3, s4)
    net.addLink(s4, s5)
    net.addLink(s5, s6)
    net.addLink(s6, s7)
    net.addLink(s7, s8)
    net.addLink(s8, s9)
    net.addLink(s9, E2)
    
    print I1.intfNames()
    print s2.intfNames()
    print s3.intfNames()
    print s4.intfNames()
    print s5.intfNames()
    print s6.intfNames()
    print s7.intfNames()
    print s8.intfNames()
    print s9.intfNames()
    print E2.intfNames()

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

    info('*** Stopping network')
    net.stop()
Example #20
0
def createTreeTopo():


    net = Mininet( controller=RemoteController)

    info( '*** Adding controller\n' )
    net.addController( 'c0', controller=RemoteController,ip="127.0.0.1",port=6633 )
    # Add hosts and switches
    host1 = net.addHost( 'h1' )
    host2 = net.addHost( 'h2' )

    edgeSwitch1 = net.addSwitch( 's3' )
    edgeSwitch2 = net.addSwitch( 's4' )
    aggrSwitch1 = net.addSwitch( 's5' )
    aggrSwitch2 = net.addSwitch( 's6' )
    coreSwitch = net.addSwitch( 's7' )

    # Add links
    net.addLink( host1, edgeSwitch1 )
    net.addLink( edgeSwitch1, aggrSwitch1 )
    net.addLink( aggrSwitch1, coreSwitch )
    net.addLink( coreSwitch, aggrSwitch2 )
    net.addLink( aggrSwitch2, edgeSwitch2 )
    net.addLink( edgeSwitch2, host2 )


    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
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 #23
0
def createTopo():
    logging.debug("LV1 Create HugeTopo")
    topo = HugeTopo()
    topo.createTopo()
    topo.createLink()
    # TODO  add multiple controller here
    logging.debug("LV1 Start Mininet")
    CONTROLLER_IP = "127.0.0.1"
    CONTROLLER_PORT = 6633
    c0 = Controller('c0', port=6633)
    c1 = Controller('c1', port=6634)
    c2 = Controller('c2', port=6635)
    c3 = Controller('c3', port=6636)
    c5 = RemoteController('c2', ip='127.0.0.1')
    net = Mininet(topo=topo, link=TCLink, controller=POX)
    for c in [c0, c1, c2, c3 ]:
        net.addController(c)
    net.start()
    logger.debug("LV1 dumpNode")
    enableSTP()
    dumpNodeConnections(net.hosts)

    #pingTest(net)
    #iperfTest(net, topo)


    CLI(net)
    p = pexpect.spawn( 'controller test' )
    # but first a simple ping test
    p.sendline( 'xterm c0' )
    net.stop()
Example #24
0
def main(argv):
    global _remControl
    global _controllers
    remote_ip = '127.0.0.1'
    lan = 2
    
    try:
        opts, args = getopt(argv[1:], 'r:l:', ['remote-ip=','lan='])
    except GetoptError as err:
        print err.msg, err.opt
        exit(1);
    print opts
    print args

    for opt, arg in opts:
        if opt in ('-r', '--remote-ip'):
            remote_ip = arg
        if opt in ('-l', '--lan'):
            lan = int(arg)

    _remControl = RemoteController('Remote Controller', ip=remote_ip)
    _controllers['remote'] = _remControl
    topo = HomeTopo(ethHosts=lan)
    net = Mininet(topo=topo, switch=MultiController, host=CPULimitedHost, 
                  link=TCLink, autoPinCpus=True, build=False)
    net.addController(_controller)
    net.build()
    topo.routerSetup(net)
    net.start()
    dumpNodeConnections(net.hosts)
    CLI( net )
    net.stop()
Example #25
0
def emptyNet():

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

    net = Mininet( controller=RemoteController )

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

    info( '*** Adding hosts\n' )
    h3 = net.addHost( 'h3', ip = "10.0.0.3" )
    h4 = net.addHost( 'h4', ip = "10.0.0.4" )
    info( '*** Adding switch\n' )
    s2 = net.addSwitch( 's2' ,mac="00:00:00:00:00:02" )

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

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

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

    info( '*** Stopping network' )
    net.stop()
Example #26
0
def net():
    '''Create a simulated network'''

    net = Mininet(controller=lambda a: RemoteController(a,ip='127.0.0.1'))

    info('*** Adding controller\n')
    # currently, we do not add a controller to this network.
    net.addController('c0')

    info('*** Adding hosts\n')
    # this is a host that is in the external network
    h1 = net.addHost('h1', ip='10.0.0.1')
    h2 = net.addHost('h2', ip='10.0.0.1')

    info('*** Adding switches\n')
    inst1 = net.addSwitch('inst1', dpid=int2dpid(11))
    inst2 = net.addSwitch('inst2', dpid=int2dpid(12))
    lb = net.addSwitch('lb', dpid=int2dpid(1))

    info('*** Creating links\n')
    net.addLink(h1, inst1)
    net.addLink(h2, inst2)
    net.addLink(inst1, lb)
    net.addLink(inst2, lb)

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

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

    info('*** Stopping network\n')
    net.stop()
Example #27
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 #28
0
def emptyNet():

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

    net = Mininet( controller=Controller )

    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' )

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

    info( '*** Creating links\n' )
    h1.linkTo( s3 )
    h2.linkTo( s3 )

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

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

    info( '*** Stopping network' )
    net.stop()
Example #29
0
def emptyNet():

    "Create an empty network and add nodes to it."
    "[h1]<---wifi-network-a--->[s3]<---wifi-network-b--->[h2]"
    "   ^                      ^  ^                      ^   "
    "  Sta                    Ap  Ap                    Sta  "

    net = Mininet()

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

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

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

    info( '*** Creating links\n' )
    WIFIApStaLink( s3, h1, ssid="wifi-network-a"  )   # line modified
    WIFIApStaLink( s3, h2, ssid="wifi-network-b" )    # line modified

    info( '*** Starting network\n')
    net.start()
    mininet.ns3.start()                     # line added

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

    info( '*** Stopping network' )
    mininet.ns3.stop()
    mininet.ns3.clear()                     # line added
    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()
Example #31
0
def createNetwork():
    #send rate at each link in Mbps
    bwg = 1  #in Mbps
    bwbn = 1  #in Mbps
    loss = 18  #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 #32
0
from mininet.net import Mininet
from mininet.cli import CLI

net = Mininet()  # net is a Mininet() object
h1 = net.addHost('h1')  # h1 is a Host() object
h2 = net.addHost('h2')  # h2 is a Host()
s1 = net.addSwitch('s1')  # s1 is a Switch() object
c0 = net.addController('c0')  # c0 is a Controller()
net.addLink(h1, s1)  # creates a Link() object
net.addLink(h2, s1)
net.start()
print h1.cmd('ping -c1', h2.IP())
CLI(net)
net.stop()
def myFattree():
    net = Mininet( topo=None,
                   build=False,
                   ipBase='10.0.0.0/8')
    
    info( '*** Adding controller\n')

    c0=net.addController(name='c0',
                         controller=RemoteController,
                         protocol='tcp',
                         port=6633)

    info(' *** Add switches\n')
    ''''
    一共有四组交换机,一共20个,每组的排序按照从下到上从左到右
    ''''
    s1 = net.addSwitch('s1', 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)
    s2 = net.addSwitch('s2', cls=OVSKernelSwitch)
    s21 = net.addSwitch('s21', cls=OVSKernelSwitch)
    s22 = net.addSwitch('s22', cls=OVSKernelSwitch)
    s23 = net.addSwitch('s23', cls=OVSKernelSwitch)
    s24 = net.addSwitch('s24', cls=OVSKernelSwitch)
    s3 = net.addSwitch('s3', cls=OVSKernelSwitch)
    s31 = net.addSwitch('s31', cls=OVSKernelSwitch)
    s32 = net.addSwitch('s32', cls=OVSKernelSwitch)
    s33 = net.addSwitch('s33', cls=OVSKernelSwitch)
    s34 = net.addSwitch('s34', cls=OVSKernelSwitch)
    s4 = net.addSwitch('s4', cls=OVSKernelSwitch)
    s41 = net.addSwitch('s41', cls=OVSKernelSwitch)
    s42 = net.addSwitch('s42', cls=OVSKernelSwitch)
    s43 = net.addSwitch('s43', cls=OVSKernelSwitch)
    s44 = net.addSwitch('s44', cls=OVSKernelSwitch)

    info(' *** Add hosts\n')
    ''''
    一共16个主机
    ''''
    h1 = net.addHost('h1', cls=Host, ip='10.0.0.2',defaultRoute=None)
    h2 = net.addHost('h2', cls=Host, ip='10.0.0.3',defaultRoute=None)
    h3 = net.addHost('h3', cls=Host, ip='10.0.1.2',defaultRoute=None)
    h4 = net.addHost('h4', cls=Host, ip='10.0.1.3',defaultRoute=None)
    h5 = net.addHost('h5', cls=Host, ip='10.1.0.2',defaultRoute=None)
    h6 = net.addHost('h6', cls=Host, ip='10.1.0.3',defaultRoute=None)
    h7 = net.addHost('h7', cls=Host, ip='10.1.1.2',defaultRoute=None)
    h8 = net.addHost('h8', cls=Host, ip='10.1.1.3',defaultRoute=None)
    h9 = net.addHost('h9', cls=Host, ip='10.2.0.2',defaultRoute=None)
    h10 = net.addHost('h10', cls=Host, ip='10.2.0.3',defaultRoute=None)
    h11 = net.addHost('h11', cls=Host, ip='10.2.1.2',defaultRoute=None)
    h12 = net.addHost('h12', cls=Host, ip='10.2.1.3',defaultRoute=None)
    h13 = net.addHost('h13', cls=Host, ip='10.3.0.2',defaultRoute=None)
    h14 = net.addHost('h14', cls=Host, ip='10.3.0.3',defaultRoute=None)
    h15 = net.addHost('h15', cls=Host, ip='10.3.1.2',defaultRoute=None)
    h16 = net.addHost('h16', cls=Host, ip='10.3.1.3',defaultRoute=None)

    info(' *** Add links\n')
    ''''
    第一层交换机与第二层的连接
    ''''
    net.addLink(s1,s13)
    net.addLink(s1,s23)
    net.addLink(s1,s33)
    net.addLink(s1,s43)
    net.addLink(s2,s13)
    net.addLink(s2,s23)
    net.addLink(s2,s33)
    net.addLink(s2,s43)
    net.addLink(s3,s14)
    net.addLink(s3,s24)
    net.addLink(s3,s34)
    net.addLink(s3,s44)
    net.addLink(s4,s14)
    net.addLink(s4,s24)
    net.addLink(s4,s34)
    net.addLink(s4,s44)
    ''''
    第二层之间的连接
    ''''
    net.addLink(s11,s13)
    net.addLink(s11,s14)
    net.addLink(s12,s13)
    net.addLink(s12,s14)
    net.addLink(s21,s23)
    net.addLink(s21,s24)
    net.addLink(s22,s23)
    net.addLink(s22,s24)
    net.addLink(s31,s33)
    net.addLink(s31,s34)
    net.addLink(s32,s33)
    net.addLink(s32,s34)
    net.addLink(s41,s43)
    net.addLink(s41,s44)
    net.addLink(s42,s43)
    net.addLink(s42,s44)
    ''''
    第二层和第三层之间的连接
    ''''
    net.addLink(s11,h1)
    net.addLink(s11,h2)
    net.addLink(s12,h3)
    net.addLink(s12,h4)
    net.addLink(s21,h5)
    net.addLink(s21,h6)
    net.addLink(s22,h7)
    net.addLink(s22,h8)
    net.addLink(s31,h9)
    net.addLink(s31,h10)
    net.addLink(s32,h11)
    net.addLink(s32,h12)
    net.addLink(s41,h13)
    net.addLink(s41,h14)
    net.addLink(s42,h15)
    net.addLink(s42,h16)

    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('s11').start([c0])
    net.get('s12').start([c0])
    net.get('s13').start([c0])
    net.get('s14').start([c0])
    net.get('s2').start([c0])
    net.get('s21').start([c0])
    net.get('s22').start([c0])
    net.get('s23').start([c0])
    net.get('s24').start([c0])
    net.get('s3').start([c0])
    net.get('s31').start([c0])
    net.get('s32').start([c0])
    net.get('s33').start([c0])
    net.get('s34').start([c0])
    net.get('s4').start([c0])
    net.get('s41').start([c0])
    net.get('s42').start([c0])
    net.get('s43').start([c0])
    net.get('s44').start([c0])
    

    info(' *** Post configure switches and hosts\n')
#    net.configLinkStatus('s3', 's14', 'down')
#    net.configLinkStatus('s24', 's21', 'down')
#    net.configLinkStatus('s11', 's13', 'down')    

    CIL(net)
    net.stop()
Example #34
0
def setupTopology(controller_addr,interface):
    "Create and run multiple link network"

    global hosts
    global net
    hosts = []
    switches = []

    net = Mininet(controller=RemoteController)

    print "mininet created"

    c1 = net.addController('c1', ip=controller_addr,port=6653)
    print "addController ", controller_addr
    #net1 = Mininet(controller=RemoteController)
    #c2 = net1.addController('c2', ip="127.0.0.1",port=6673)


    # h1: IOT Device.
    # h2 : StatciDHCPD
    # h3# : router / NAT
    # h4 : Non IOT device.

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

    s1 = net.addSwitch('s1',dpid="1")
    # The host for dhclient
    s1.linkTo(h1)
    # The IOT device
    s1.linkTo(h2)
    # The MUD controller
    s1.linkTo(h3)
    # The MUD server runs here.
    s1.linkTo(h4)
    # The non-iot client runs here
    s1.linkTo(h5)

    h6 = net.addHost('h6')

    # Switch s2 is the "multiplexer".
    s2 = net.addSwitch('s2',dpid="2")

    s3 = net.addSwitch('s3',dpid="3")


    # h7 and h9 are on a VLAN
    # Make sure we can reach the VLAN'ed hosts from h1.

    host = partial(VLANHost,vlan=772)
    h7 = net.addHost('h7', cls=host)

    h8 = net.addHost('h8')
   
    net.addLink(s3,h7)
    
    host = partial(VLANHost,vlan=772)
    h9 = net.addHost('h9', cls=host)

    net.addLink(s3,h9)
    s2.linkTo(h6)

    s2.linkTo(s3)
    # h8 is the ids.
    s2.linkTo(h8)
    # h9 is our fake server.
    # s2 linked to s3 via our router.
    h7.cmd( 'ip link set h7-eth0 down')
    h9.cmd( 'ip link set h9-eth0 down')
    s3.linkTo(h9)
    s3.linkTo(h7)

    # S2 is the NPE switch.
    # Direct link between S1 and S2
    s1.linkTo(s2)


    net.build()
    c1.start()
    s1.start([c1])
    s2.start([c1])
    s3.start([c1])

    net.start()
     

    # Clean up any traces of the previous invocation (for safety)


    h1.setMAC("00:00:00:00:00:01","h1-eth0")
    h2.setMAC("00:00:00:00:00:02","h2-eth0")
    h3.setMAC("00:00:00:00:00:03","h3-eth0")
    h4.setMAC("00:00:00:00:00:04","h4-eth0")
    h5.setMAC("00:00:00:00:00:05","h5-eth0")
    h6.setMAC("00:00:00:00:00:06","h6-eth0")
    h8.setMAC("00:00:00:00:00:08","h8-eth0")
    #h9.setMAC("00:00:00:00:00:09","h9-eth0.772")
    #h7.setMAC("00:00:00:00:00:07","h7-eth0.772")

    
    # Set up a routing rule on h2 to route packets via h3
    h1.cmdPrint('ip route del default')
    h1.cmdPrint('ip route add default via 10.0.0.7 dev h1-eth0')

    # Set up a routing rule on h2 to route packets via h3
    h2.cmdPrint('ip route del default')
    h2.cmdPrint('ip route add default via 10.0.0.7 dev h2-eth0')

    # Set up a routing rule on h2 to route packets via h7
    h3.cmdPrint('ip route del default')
    h3.cmdPrint('ip route add default via 10.0.0.7 dev h3-eth0')

    # Set up a routing rule on h2 to route packets via h3
    h4.cmdPrint('ip route del default')
    h4.cmdPrint('ip route add default via 10.0.0.7 dev h4-eth0')

    # Set up a routing rule on h5 to route packets via h3
    h5.cmdPrint('ip route del default')
    h5.cmdPrint('ip route add default via 10.0.0.7 dev h5-eth0')

    # h6 is a localhost.
    h6.cmdPrint('ip route del default')
    h6.cmdPrint('ip route add default via 10.0.0.7 dev h6-eth0')

    # The IDS runs on h8
    h8.cmdPrint('ip route del default')
    h8.cmdPrint('ip route add default via 10.0.0.7 dev h8-eth0')

    # Start dnsmasq (our dns server).
    h5.cmdPrint('/usr/sbin/dnsmasq --server  10.0.4.3 --pid-file=/tmp/dnsmasq.pid'  )


    time.sleep(5)

    hosts.append(h1)
    hosts.append(h2)
    hosts.append(h3)
    hosts.append(h4)
    hosts.append(h5)
    hosts.append(h6)
    hosts.append(h7)
    hosts.append(h8)
    hosts.append(h9)

    switches.append(s1)
    switches.append(s2)
    switches.append(s3)
    
    print "Should see at least 10 successful pings"
    #h1.cmdPrint("ping 10.0.0.9 -c 10")

    print "Should see at least 10 successful pings"
    #h1.cmdPrint("ping 10.0.0.2 -c 10")
  
    print "Should see at most 1 successful ping"
    #h1.cmdPrint("ping 10.0.0.8 -c 10")


    print "*********** System ready *********"
def topology():

    "Create a network."
    net = Mininet(controller=Controller,
                  link=TCLink,
                  accessPoint=UserAP,
                  enable_wmediumd=True,
                  enable_interference=True)

    print "*** Creating nodes"
    cars = []
    stas = []
    for x in range(0, 10):
        cars.append(x)
        stas.append(x)
    for x in range(0, 10):
        cars[x] = net.addCar('car%s' % (x),
                             wlans=1,
                             ip='10.0.0.%s/8' % (x + 1))

    e1 = net.addAccessPoint('e1',
                            ssid='vanet-ssid',
                            mac='00:00:00:11:00:01',
                            mode='g',
                            channel='1',
                            passwd='123456789a',
                            encrypt='wpa2',
                            position='3279.02,3736.27,0')
    e2 = net.addAccessPoint('e2',
                            ssid='vanet-ssid',
                            mac='00:00:00:11:00:02',
                            mode='g',
                            channel='6',
                            passwd='123456789a',
                            encrypt='wpa2',
                            position='2320.82,3565.75,0')
    e3 = net.addAccessPoint('e3',
                            ssid='vanet-ssid',
                            mac='00:00:00:11:00:03',
                            mode='g',
                            channel='11',
                            passwd='123456789a',
                            encrypt='wpa2',
                            position='2806.42,3395.22,0')
    e4 = net.addAccessPoint('e4',
                            ssid='vanet-ssid',
                            mac='00:00:00:11:00:04',
                            mode='g',
                            channel='1',
                            passwd='123456789a',
                            encrypt='wpa2',
                            position='3332.62,3253.92,0')
    e5 = net.addAccessPoint('e5',
                            ssid='vanet-ssid',
                            mac='00:00:00:11:00:05',
                            mode='g',
                            channel='6',
                            passwd='123456789a',
                            encrypt='wpa2',
                            position='2887.62,2935.61,0')
    e6 = net.addAccessPoint('e6',
                            ssid='vanet-ssid',
                            mac='00:00:00:11:00:06',
                            mode='g',
                            channel='11',
                            passwd='123456789a',
                            encrypt='wpa2',
                            position='2351.68,3083.40,0')
    c1 = net.addController('c1',
                           controller=Controller,
                           ip='127.0.0.1',
                           port=6633)

    net.propagationModel("logDistancePropagationLossModel", exp=2.5)

    print "*** Setting bgscan"
    net.setBgscan(signal=-45, s_inverval=5, l_interval=10)

    print "*** Configuring Propagation Model"
    net.propagationModel("logDistancePropagationLossModel", exp=2)

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

    net.addLink(e1, e2)
    net.addLink(e2, e3)
    net.addLink(e3, e4)
    net.addLink(e4, e5)
    net.addLink(e5, e6)

    "Available Options: sumo, sumo-gui"
    net.useExternalProgram('sumo-gui', config_file='map.sumocfg')

    print "*** Starting network"
    net.build()
    c1.start()
    e1.start([c1])
    e2.start([c1])
    e3.start([c1])
    e4.start([c1])
    e5.start([c1])
    e6.start([c1])

    i = 201
    for sw in net.carsSW:
        sw.start([c1])
        os.system('ifconfig %s 10.0.0.%s' % (sw, i))
        i += 1

    i = 1
    j = 2
    for car in cars:
        car.cmd('ifconfig %s-wlan0 192.168.0.%s/24 up' % (car, i))
        car.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (car, i))
        car.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.carsSTA:
        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.carsSTA:
        i = 1
        j = 1
        for v2 in net.carsSTA:
            if v1 != v2:
                v1.cmd('route add -host 192.168.1.%s gw 10.0.0.%s' % (j, i))
            i += 1
            j += 2

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

    print "*** Stopping network"
    net.stop()
Example #36
0
def myNetwork():

    info( '********* Project 1Task 1  **********************\n' )
    net = Mininet( topo=None, build=False, ipBase='10.0.0.0/8')

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

    info( '*** Add switches\n')
    s0 = net.addSwitch('s0', cls=OVSKernelSwitch, failMode='standalone', stp=1)
    s1 = net.addSwitch('s1', cls=OVSKernelSwitch, failMode='standalone', stp=1)
    s5 = net.addSwitch('s5', cls=OVSKernelSwitch, failMode='standalone', stp=1)
    s2 = net.addSwitch('s2', cls=OVSKernelSwitch, failMode='standalone', stp=1)
    s6 = net.addSwitch('s6', cls=OVSKernelSwitch, failMode='standalone', stp=1)
    s8 = net.addSwitch('s8', cls=OVSKernelSwitch, failMode='standalone', stp=1)

    info( '*** Add hosts\n')
    hTEM = net.addHost('hTEM', ip='10.0.0.1/8')
    hTES = net.addHost('hTES', ip='10.0.0.3/8')
    hServer = net.addHost('hServer', ip='10.0.0.2/8')	
    h0 = net.addHost('h0')
    h1 = net.addHost('h1')
    h5 = net.addHost('h5')
    h2 = net.addHost('h2')
    h6 = net.addHost('h6')
    h8 = net.addHost('h8')

    info( '*** Add links between hosts and switches\n')
    linkConfig_HToS = {'delay':'0', 'bw' : 100}

    L0 = net.addLink(h0, s0,cls=TCLink , **linkConfig_HToS)
    L1 = net.addLink(h1, s1,cls=TCLink , **linkConfig_HToS)
    L2 = net.addLink(h2, s2,cls=TCLink , **linkConfig_HToS)
    L6 = net.addLink(h6, s6,cls=TCLink , **linkConfig_HToS)
    L5 = net.addLink(h5, s5,cls=TCLink , **linkConfig_HToS)
    L8 = net.addLink(h8, s8,cls=TCLink , **linkConfig_HToS)

    L9 = net.addLink(hTEM, s1,cls=TCLink , **linkConfig_HToS)
    L10 = net.addLink(hTES, s6,cls=TCLink , **linkConfig_HToS)
    L11 = net.addLink(hServer, s5,cls=TCLink , **linkConfig_HToS)

    info( '*** Add links between switches\n')
    Ls3 = net.addLink(s0, s5, cls=TCLink , **linkConfig_s0s5)
    Ls2 = net.addLink(s0, s1, cls=TCLink , **linkConfig_s0s1)
    Ls1 = net.addLink(s1, s5, cls=TCLink , **linkConfig_s1s5)
    Ls4 = net.addLink(s1, s2, cls=TCLink , **linkConfig_s1s2)
    Ls5 = net.addLink(s2, s6, cls=TCLink , **linkConfig_s2s6)
    Ls6 = net.addLink(s5, s6, cls=TCLink , **linkConfig_s5s6)
    Ls8 = net.addLink(s5, s8, cls=TCLink , **linkConfig_s5s8)
    Ls7 = net.addLink(s6, s8, cls=TCLink , **linkConfig_s6s8)

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

    info( '*** Starting controllers\n')
    c0.start()

    info( '*** Starting switches\n')
    net.get('s0').start([c0])
    net.get('s2').start([c0])
    net.get('s1').start([c0])
    net.get('s5').start([c0])
    net.get('s6').start([c0])
    net.get('s8').start([c0])

    net.start()
    net.staticArp()


    info( '*** Waiting for STP to converge \n')
    time.sleep(35)

    net.pingAll()

    return(net)
        self.addLink("s1", "s2", **video_link_config)
        self.addLink("s2", "s4", **video_link_config)
        self.addLink("s1", "s3", **http_link_config)
        self.addLink("s3", "s4", **http_link_config)

        # Add host links
        self.addLink("h1", "s1", **host_link_config)
        self.addLink("h2", "s1", **host_link_config)
        self.addLink("h3", "s4", **host_link_config)
        self.addLink("h4", "s4", **host_link_config)


topos = {"networkslicingtopo": (lambda: NetworkSlicingTopo())}

if __name__ == "__main__":
    topo = NetworkSlicingTopo()
    net = Mininet(
        topo=topo,
        switch=OVSKernelSwitch,
        build=False,
        autoSetMacs=True,
        autoStaticArp=True,
        link=TCLink,
    )
    controller = RemoteController("c1", ip="127.0.0.1", port=6633)
    net.addController(controller)
    net.build()
    net.start()
    CLI(net)
    net.stop()
Example #38
0
def topology():

    "Create a network."
    net = Mininet(controller=RemoteController,
                  link=TCLink,
                  accessPoint=OVSKernelAP)
    staList = []

    print "*** Creating nodes"
    for n in range(10):
        staList.append(n)
        staList[n] = net.addStation('sta%s' % (n + 1),
                                    wlans=2,
                                    mac='00:00:00:00:00:%s' % (n + 1),
                                    ip='192.168.0.%s/24' % (n + 1))
    phyap1 = net.addPhysicalBaseStation('phyap1',
                                        ssid='SBRC16-MininetWiFi',
                                        mode='g',
                                        channel='1',
                                        position='50,115,0',
                                        phywlan='wlan1')
    sta11 = net.addStation('sta11', ip='10.0.0.111/8', position='120,200,0')
    ap2 = net.addAccessPoint('ap2',
                             ssid='ap2',
                             mode='g',
                             channel='11',
                             position='100,175,0')
    ap3 = net.addAccessPoint('ap3',
                             ssid='ap3',
                             mode='g',
                             channel='6',
                             position='150,50,0')
    ap4 = net.addAccessPoint('ap4',
                             ssid='ap4',
                             mode='g',
                             channel='1',
                             position='175,150,0')
    c1 = net.addController('c1', controller=Controller, port=6653)
    root = Node('root', inNamespace=False)

    print "*** Configuring wifi nodes"
    net.configureWifiNodes()
    """uncomment to plot graph"""
    net.plotGraph(max_x=220, max_y=220)
    """Routing"""
    net.meshRouting('custom')
    """Seed"""
    net.seed(20)

    print "*** Associating and Creating links"
    for sta in staList:
        net.addMesh(sta, ssid='meshNet')
    net.addLink(phyap1, ap2)
    net.addLink(ap2, ap3)
    net.addLink(ap3, ap4)

    print "*** Starting network"
    net.build()
    c1.start()
    phyap1.start([c1])
    ap2.start([c1])
    ap3.start([c1])
    ap4.start([c1])

    ip = 201
    for sta in staList:
        sta.setIP('10.0.0.%s/8' % ip, intf="%s-wlan1" % sta)
        ip += 1

    "*** Available models: RandomWalk, TruncatedLevyWalk, RandomDirection, RandomWayPoint, GaussMarkov, ReferencePoint, TimeVariantCommunity ***"
    net.startMobility(time=0,
                      model='RandomWalk',
                      max_x=220,
                      max_y=220,
                      min_v=0.1,
                      max_v=0.2)

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

    print "*** Stopping network"
    net.stop()
    # parser.add_argument('--face-type', dest='faceType', default='udp', choices=['udp', 'tcp'])
    # 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.''')

    # cleanning minnet, for the sake of safety
    cmd = ["sudo", "mn", "--clean"]
    subprocess.call(cmd)

    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)

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

    switch = net.addSwitch('s1')

    # Add links
    #bw in Mbit/s
    host_link = partial(TCLink, bw=1)
    net.addLink(h1, switch, cls=host_link)
    net.addLink(h2, switch, cls=host_link)
Example #40
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',
        #                     ip='192.168.56.1',
        protocol='tcp',
        port=6633)

    info('*** Add switches\n')
    s2 = net.addSwitch('s2', cls=OVSKernelSwitch, protocols='OpenFlow13')
    s1 = net.addSwitch('s1', cls=OVSKernelSwitch, protocols='OpenFlow13')
    #s2 = net.addSwitch('s2', cls=OVSKernelSwitch, protocols='OpenFlow10, OpenFlow13')
    #s1 = net.addSwitch('s1', cls=OVSKernelSwitch, protocols='OpenFlow10, OpenFlow13')

    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')

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

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

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

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

    CLI(net)
    net.stop()
Example #41
0
            self.addHost("301", mac="00:00:00:00:00:01", ip="10.0.0.1/24"))
        self.host.append(
            self.addHost("302", mac="00:00:00:00:00:02", ip="10.0.0.2/24"))
        self.host.append(
            self.addHost("303", mac="00:00:00:00:00:03", ip="10.0.0.3/24"))
        self.host.append(
            self.addHost("304", mac="00:00:00:00:00:04", ip="10.0.0.4/24"))

        # add links
        for i in range(2):
            self.addLink(self.spineswitch[i], self.leafswitch[0], 1, i + 1)
            self.addLink(self.spineswitch[i], self.leafswitch[1], 2, i + 1)

        for i in range(2):
            self.addLink(self.leafswitch[i], self.host[i * 2], 3)
            self.addLink(self.leafswitch[i], self.host[i * 2 + 1], 4)


topos = {'mytopo': (lambda: MyTopo())}

if __name__ == "__main__":
    setLogLevel('info')

    topo = MyTopo()
    net = Mininet(topo=topo, link=TCLink, controller=None)
    net.addController('c0', controller=RemoteController, ip='127.0.0.1')

    net.start()
    CLI(net)
    net.stop()
Example #42
0
File: sdn.py Project: as74150/sdn
def myNetwork():
    info('*** Create network\n')
    net = Mininet(topo=None, link=TCLink, build=False, ipBase='10.0.0.0/8')

    #cita = 90
    #print math.sin(math.radians(cita))
    info('*** Adding controller\n')
    c0 = net.addController(name='c0',
                           controller=RemoteController,
                           ip='172.23.22.246',
                           protocol='tcp',
                           port=6633)
    '''
    c1=net.addController(name='c1',
                      controller=RemoteController,
                      ip='192.168.1.2',
                      protocol='tcp',
                      port=6633)
    c2=net.addController(name='c2',
                      controller=RemoteController,
                      ip='192.168.1.3',
                      protocol='tcp',
                      port=6633)s
    '''

    info('*** Add switches\n')
    s1 = net.addSwitch('s1',
                       cls=OVSKernelSwitch,
                       position='102,76.3',
                       min_x=100,
                       max_x=150,
                       min_y=76,
                       max_y=150,
                       dpid='1')
    s2 = net.addSwitch('s2',
                       cls=OVSKernelSwitch,
                       position='144,416.5',
                       min_x=100,
                       max_x=150,
                       min_y=350,
                       max_y=423,
                       dpid='2')
    s3 = net.addSwitch('s3',
                       cls=OVSKernelSwitch,
                       position='228,256',
                       min_x=200,
                       max_x=250,
                       min_y=225,
                       max_y=275,
                       dpid='3')
    s4 = net.addSwitch('s4',
                       cls=OVSKernelSwitch,
                       position='348,147.5',
                       min_x=300,
                       max_x=350,
                       min_y=100,
                       max_y=150,
                       dpid='4')
    s5 = net.addSwitch('s5',
                       cls=OVSKernelSwitch,
                       position='389.5,405',
                       min_x=300,
                       max_x=400,
                       min_y=375,
                       max_y=425,
                       dpid='5')
    s6 = net.addSwitch('s6',
                       cls=OVSKernelSwitch,
                       position='468,76',
                       min_x=453,
                       max_x=500,
                       min_y=52,
                       max_y=100,
                       dpid='6')
    s7 = net.addSwitch('s7',
                       cls=OVSKernelSwitch,
                       position='606,323.6',
                       min_x=600,
                       max_x=700,
                       min_y=300,
                       max_y=350,
                       dpid='7')
    s8 = net.addSwitch('s8',
                       cls=OVSKernelSwitch,
                       position='623.3,184.5',
                       min_x=600,
                       max_x=646,
                       min_y=150,
                       max_y=198,
                       dpid='8')
    s9 = net.addSwitch('s9',
                       cls=OVSKernelSwitch,
                       position='772,82.6',
                       min_x=750,
                       max_x=798,
                       min_y=50,
                       max_y=100,
                       dpid='9')

    info('*** Add hosts\n')
    h1 = net.addHost('h1',
                     cls=Host,
                     ip='10.0.0.1',
                     position='86,123.5',
                     defaultRoute=None)
    h2 = net.addHost('h2',
                     cls=Host,
                     ip='10.0.0.2',
                     position='128.5,346.4',
                     defaultRoute=None)
    h3 = net.addHost('h3',
                     cls=Host,
                     ip='10.0.0.3',
                     position='746,63.5,0',
                     defaultRoute=None)

    info('*** Add links\n')
    #net.addLink(s1, s2)
    net.addLink(s2, h2)
    net.addLink(h1, s1)
    net.addLink(h3, s9)

    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])
    net.get('s5').start([c0])
    net.get('s6').start([c0])
    net.get('s7').start([c0])
    net.get('s8').start([c0])
    net.get('s9').start([c0])

    startMoniter = 4

    th_check = threading.Thread(target=topoCheck, args=(net, ))
    th_check.start()
    info('*** Post configure switches and hosts\n')

    CLI(net)
    try:
        net.stop()
        plt.close()
        os.system("sudo mn -c")
    except Exception, e:
        print str(e)
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 = 10  #0 #1000 #max queue size of interfaces
    dly = '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 tcp_server.py > tcp-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 tcp_client.py > tcp-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
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', ip='192.168.99.101', port=6633)

    s1 = net.addSwitch('s1')

    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')

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

    net.build()

    c0.start()
    s1.start([c0])

    net.terms.append(makeTerm(s1))

    CLI(net)
    net.stop()
Example #45
0
def setupTopology(controller_addr):
    global net, c1, s1, s2, s3
    global h1, h2, h3, h4, h5, h6, h7, h8, h9, h10
    "Create and run multiple link network"

    net = Mininet(controller=RemoteController)

    print "mininet created"

    c1 = net.addController('c1', ip=controller_addr, port=6653)

    # h1: IOT Device.
    # h2 : StatciDHCPD
    # h3 : router / NAT
    # h4 : Non IOT device.

    h1 = net.addHost('h1')
    h2 = net.addHost('h2')
    h3 = net.addHost('h3')
    h4 = net.addHost('h4')
    h5 = net.addHost('h5')
    h6 = net.addHost('h6')
    h7 = net.addHost('h7')
    h8 = net.addHost('h8')
    h9 = net.addHost('h9')
    h10 = net.addHost('h10')

    hosts.append(h1)
    hosts.append(h2)
    hosts.append(h3)
    hosts.append(h4)
    hosts.append(h5)
    hosts.append(h6)
    hosts.append(h7)
    hosts.append(h8)
    hosts.append(h9)
    hosts.append(h10)

    s2 = net.addSwitch('s2', dpid="2")
    s3 = net.addSwitch('s3', dpid="3")
    s1 = net.addSwitch('s1', dpid="1")

    s1.linkTo(h1)
    s1.linkTo(h2)
    s1.linkTo(h3)
    s1.linkTo(h4)
    s1.linkTo(h5)
    s1.linkTo(h6)
    s1.linkTo(h7)

    s2.linkTo(h8)
    s3.linkTo(h8)

    s3.linkTo(h9)
    s3.linkTo(h10)

    # S2 is the NPE switch.
    # Direct link between S1 and S2
    s1.linkTo(s2)

    h8.cmdPrint('echo 0 > /proc/sys/net/ipv4/ip_forward')
    # Flush old rules.
    h8.cmdPrint('iptables -F')
    h8.cmdPrint('iptables -t nat -F')
    h8.cmdPrint('iptables -t mangle -F')
    h8.cmdPrint('iptables -X')
    h8.cmdPrint('echo 1 > /proc/sys/net/ipv4/ip_forward')

    # Set up h3 to be our router (it has two interfaces).
    # Set up iptables to forward as NAT
    h8.cmdPrint(
        'iptables -t nat -A POSTROUTING -o h8-eth1 -s 10.0.0.0/24 -j MASQUERADE'
    )

    net.build()
    net.build()
    c1.start()
    s1.start([c1])
    s2.start([c1])
    s3.start([c1])

    net.start()

    # Clean up any traces of the previous invocation (for safety)

    h1.setMAC("00:00:00:00:00:01", "h1-eth0")
    h2.setMAC("00:00:00:00:00:02", "h2-eth0")
    h3.setMAC("00:00:00:00:00:03", "h3-eth0")
    h4.setMAC("00:00:00:00:00:04", "h4-eth0")
    h5.setMAC("00:00:00:00:00:05", "h5-eth0")
    h6.setMAC("00:00:00:00:00:06", "h6-eth0")
    h7.setMAC("00:00:00:00:00:07", "h7-eth0")
    h8.setMAC("00:00:00:00:00:08", "h8-eth0")
    h9.setMAC("00:00:00:00:00:09", "h9-eth0")
    h10.setMAC("00:00:00:00:00:10", "h10-eth0")

    # Set up a routing rule on h2 to route packets via h3
    h1.cmdPrint('ip route del default')
    h1.cmdPrint('ip route add default via 10.0.0.8 dev h1-eth0')

    # Set up a routing rule on h2 to route packets via h3
    h2.cmdPrint('ip route del default')
    h2.cmdPrint('ip route add default via 10.0.0.8 dev h2-eth0')

    # Set up a routing rule on h2 to route packets via h7
    h3.cmdPrint('ip route del default')
    h3.cmdPrint('ip route add default via 10.0.0.8 dev h3-eth0')

    # Set up a routing rule on h2 to route packets via h3
    h4.cmdPrint('ip route del default')
    h4.cmdPrint('ip route add default via 10.0.0.8 dev h4-eth0')

    # Set up a routing rule on h5 to route packets via h3
    h5.cmdPrint('ip route del default')
    h5.cmdPrint('ip route add default via 10.0.0.8 dev h5-eth0')

    # h6 is a localhost.
    h6.cmdPrint('ip route del default')
    h6.cmdPrint('ip route add default via 10.0.0.8 dev h6-eth0')

    # The IDS runs on h8
    h7.cmdPrint('ip route del default')
    h7.cmdPrint('ip route add default via 10.0.0.8 dev h7-eth0')

    # h9 is our fake host. It runs our "internet" web server.
    h9.cmdPrint('ifconfig h9-eth0 203.0.113.13 netmask 255.255.255.0')
    # Start a web server there.

    # h10 is our second fake host. It runs another internet web server that we cannot reach
    h10.cmdPrint('ifconfig h10-eth0 203.0.113.14 netmask 255.255.255.0')

    # Start dnsmasq (our dns server).
    h5.cmdPrint(
        '/usr/sbin/dnsmasq --server  10.0.4.3 --pid-file=/tmp/dnsmasq.pid')

    # Set up our router routes.
    h8.cmdPrint('ip route add 203.0.113.13/32 dev h8-eth1')
    h8.cmdPrint('ip route add 203.0.113.14/32 dev h8-eth1')
    h8.cmdPrint('ifconfig h8-eth1 203.0.113.1 netmask 255.255.255.0')

    #subprocess.Popen(cmd,shell=True,  stdin= subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=False)
    if os.environ.get("UNITTEST") is None or os.environ.get("UNITTEST") == '0':
        #h3.cmdPrint("python ../util/udpping.py --port 8008 --server &")
        #h2.cmdPrint("python ../util/udpping.py --port 8008 --server &")
        h1.cmdPrint("python ../util/udpping.py --port 8008 --server &")
        #h1.cmdPrint("python ../util/tcp-server.py -P 8010 -H 10.0.0.1 -T 10000 -C &")
        #h3.cmdPrint("python ../util/tcp-server.py -P 8010 -H 10.0.0.3 -T 10000 -C &")

    # Start the IDS on node 8

    print "*********** System ready *********"
Example #46
0
def verySimpleNet():

    if len(sys.argv) < 3:
        info(
            '*** Specify time [s] of simulation and lambda for poisson generators (requests/60s)! --> python very-simple-net-script.py <time> <lambda>...\n'
        )
        return

    simulationTime = int(sys.argv[1])
    lam = float(sys.argv[2])

    info('*** Starting controller...\n')
    cmd = "java -jar target/floodlight.jar -cf /home/sszwaczyk/WAT/PhD/impl/floodlight/scenarios/simple-net/mininet/floodlightdefault.properties"
    proc = subprocess.Popen(cmd.split(),
                            cwd='/home/sszwaczyk/WAT/PhD/impl/floodlight')

    info('*** Sleep 5 seconds to let controller start...\n')
    sleep(5)

    net = Mininet(topo=None,
                  build=False,
                  ipBase='10.0.0.0/24',
                  autoSetMacs=True,
                  autoStaticArp=True,
                  host=CPULimitedHost)

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

    info('*** Add switches\n')
    s1 = net.addSwitch('s1',
                       cls=OVSKernelSwitch,
                       dpid='00:00:00:00:00:00:00:01')
    s2 = net.addSwitch('s2',
                       cls=OVSKernelSwitch,
                       dpid='00:00:00:00:00:00:00:02')
    s3 = net.addSwitch('s3',
                       cls=OVSKernelSwitch,
                       dpid='00:00:00:00:00:00:00:03')
    s4 = net.addSwitch('s4',
                       cls=OVSKernelSwitch,
                       dpid='00:00:00:00:00:00:00:04')

    info('*** Add hosts\n')
    hostsNumber = 2
    userOneHost = net.addHost('User1',
                              cls=Host,
                              ip='10.0.0.101/24',
                              cpu=.1 / hostsNumber)

    httpLsHost = net.addHost('HTTP_LS',
                             cls=Host,
                             ip='10.0.0.1/24',
                             cpu=.1 / hostsNumber)
    httpSsHost = net.addHost('HTTP_SS',
                             cls=Host,
                             ip='10.0.0.2/24',
                             cpu=.1 / hostsNumber)

    info('*** Add links\n')
    # Add links between switches
    net.addLink(s1, s2, cls=TCLink, bw=10)
    net.addLink(s1, s3, cls=TCLink, bw=10)

    net.addLink(s2, s4, cls=TCLink, bw=10)

    net.addLink(s3, s4, cls=TCLink, bw=10)

    # Add links to services
    net.addLink(s4, httpLsHost, cls=TCLink, bw=10)
    net.addLink(s4, httpSsHost, cls=TCLink, bw=10)

    #Add links to users
    net.addLink(s1, userOneHost, cls=TCLink, bw=10)

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

    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('*** Sleep 30 seconds to let controller get topology...\n')
    sleep(30)

    popens = {}

    info('*** Starting services\n')

    httpLsCommand = 'java -jar /home/sszwaczyk/WAT/PhD/impl/http-server/target/http-server-0.0.1-SNAPSHOT.jar --usersFile=/home/sszwaczyk/WAT/PhD/impl/floodlight/scenarios/simple-net/users.json --servicesFile=/home/sszwaczyk/WAT/PhD/impl/floodlight/scenarios/simple-net/mininet/services.json --logging.file=./http-ls.log --exitStatsFile=./http-ls-exit.xlsx'
    popens[httpLsHost] = httpLsHost.popen(httpLsCommand.split())

    httpSsCommand = 'java -jar /home/sszwaczyk/WAT/PhD/impl/http-server/target/http-server-0.0.1-SNAPSHOT.jar --usersFile=/home/sszwaczyk/WAT/PhD/impl/floodlight/scenarios/simple-net/users.json --servicesFile=/home/sszwaczyk/WAT/PhD/impl/floodlight/scenarios/simple-net/mininet/services.json --logging.file=./http-ss.log --exitStatsFile=./http-ss-exit.xlsx'
    popens[httpSsHost] = httpSsHost.popen(httpSsCommand.split())

    info('*** Sleep 30 seconds to let services start...\n')
    sleep(30)

    info('*** Starting requests generators...\n')

    userOneCommand = 'java -jar /home/sszwaczyk/WAT/PhD/impl/requests-generator/target/requests-generator-1.0-SNAPSHOT.jar -sf /home/sszwaczyk/WAT/PhD/impl/floodlight/scenarios/simple-net/mininet/services.json -lf user-one -st ./user-one-exit.xlsx -er ./user-one-every-request.xlsx -s 1 -g poisson -l ' + str(
        lam)
    popens[userOneHost] = userOneHost.popen(userOneCommand.split())

    info("Simulating for", simulationTime, "seconds\n")
    endTime = time() + simulationTime

    for h, line in pmonitor(popens, timeoutms=500):
        if h:
            info('<%s>: %s' % (h.name, line))
        if time() >= endTime:
            for p in popens.values():
                info('*** Stopping requests generators and services...\n')
                p.send_signal(SIGTERM)

    info('*** Stopping net...\n')
    net.stop()

    info('*** Stopping controller...\n')
    os.kill(proc.pid, signal.SIGTERM)
def topology():

    "Create a network."
    net = Mininet(controller=RemoteController,
                  link=TCLink,
                  switch=OVSKernelSwitch)

    print "*** Creating nodes"
    ap1 = net.addAccessPoint('ap1', ssid='new-ssid', mode='g', channel='1')
    sta2 = net.addStation('sta2',
                          wlans=1,
                          mac='00:02:00:00:00:02',
                          ip='10.0.0.2/8')
    sta3 = net.addStation('sta3',
                          wlans=1,
                          mac='00:02:00:00:00:03',
                          ip='10.0.0.3/8')
    sta4 = net.addStation('sta4',
                          wlans=1,
                          mac='00:02:00:00:00:04',
                          ip='10.0.0.4/8')
    c5 = net.addController('c5', ip='127.0.0.1', port=6633)
    h7 = net.addHost('h7', mac='00:00:00:00:00:07', ip='10.0.0.7/8')

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

    print "*** Creating links"
    net.addLink(sta4, ap1)
    net.addLink(sta3, ap1)
    net.addLink(sta2, ap1)
    net.addLink(ap1, h7)

    print "*** Starting network"
    net.build()
    c5.start()
    ap1.start([c5])

    ap1.cmd("iw dev ap1-wlan0 interface add vwlan1 type managed")
    ap1.cmd("iw dev ap1-wlan0 interface add vwlan2 type managed")
    ap1.cmd("ifconfig vwlan1 hw ether 00:00:00:aa:bb:11")
    ap1.cmd("ifconfig vwlan2 hw ether 00:00:00:aa:bb:22")
    ap1.cmd("ifconfig vwlan1 up")
    ap1.cmd("ifconfig vwlan2 up")
    ap1.cmd("ovs-vsctl add-port ap1 vwlan1")
    ap1.cmd("ovs-vsctl add-port ap1 vwlan2")
    ap1.cmd(
        "echo -e 'interface=vwlan1\ndriver=nl80211\nssid=vwlan1\nhw_mode=g\nchannel=1\nwme_enabled=1\nwmm_enabled=1' > vwlan1.conf"
    )
    ap1.cmd("hostapd -B vwlan1.conf &")
    ap1.cmd(
        "echo -e 'interface=vwlan2\ndriver=nl80211\nssid=vwlan2\nhw_mode=g\nchannel=1\nwme_enabled=1\nwmm_enabled=1' > vwlan2.conf"
    )
    ap1.cmd("hostapd -B vwlan2.conf &")

    sta2.cmd("ifconfig sta2-wlan0 down")
    sta2.cmd("iwconfig sta2-wlan0 essid 'vwlan1'")
    sta2.cmd("ifconfig sta2-wlan0 up")

    sta3.cmd("ifconfig sta3-wlan0 down")
    sta3.cmd("iwconfig sta3-wlan0 essid 'vwlan2'")
    sta3.cmd("ifconfig sta3-wlan0 up")

    ### after the above setting, sta2( sta3, or sta4) can ping h7. sta2 can also ping sta3/sta4.

    #the following rule can block sta2 from communicating with other host or station
    ap1.cmd(
        "ovs-ofctl add-flow ap1 priority=65535,ip,nw_dst=10.0.0.2,actions=drop"
    )

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

    print "*** Stopping network"
    net.stop()
Example #48
0
if __name__ == '__main__':
    setLogLevel('info')

    # try to get hw intf from the command line; by default, use eth1
    intfName = sys.argv[1] if len(sys.argv) > 1 else 'ens33'
    info('*** Connecting to hw intf: %s' % intfName)

    info('*** Checking', intfName, '\n')
    checkIntf(intfName)

    info('*** Creating network\n')
    net = Mininet(topo=MyTopo(),
                  controller=None)  #关键函数,创建mininet网络,指定拓扑和控制器。这里的控制器在后面添加进去
    switch = net.switches[2]  #取第一个交换机与eth1桥接
    switch.cmd('ovs-vsctl set Bridge s1 protocols=OpenFlow13')
    switch.cmd('ovs-vsctl set Bridge s2 protocols=OpenFlow13')
    switch.cmd('ovs-vsctl set Bridge s3 protocols=OpenFlow13')
    info('*** Adding hardware interface', intfName, 'to switch', switch.name,
         '\n')
    _intf = Intf(intfName, node=switch)  #最关键的函数,用作把一个网卡与一个交换机桥接

    info(
        '*** Note: you may need to reconfigure the interfaces for '
        'the Mininet hosts:\n', net.hosts, '\n')
    c0 = RemoteController('c0', ip='127.0.0.1', port=6653)
    net.addController(c0)
    net.start()
    CLI(net)
    net.stop()
Example #49
0
class MininetManager(object):
    def __init__(self):
        self.logger = logging.getLogger(__name__)
        self.net = None

    @Pyro4.expose
    def create_mininet(self,
                       topo,
                       tunnels=[],
                       switch=UserSwitch,
                       controller=None,
                       STT=False):
        if (not self.net is None):
            self.logger.warn("running mininet instance detected!\
                              Shutting it down...")
            self.destroy_mininet()

        self.logger.info("Creating mininet instance")
        if controller:
            self.net = Mininet(topo=topo,
                               intf=TCIntf,
                               link=TCLink,
                               switch=switch,
                               controller=controller)
        else:
            self.net = Mininet(topo=topo,
                               intf=TCIntf,
                               link=TCLink,
                               switch=switch)
        if STT:
            self.logger.info("Starting Mininet...")
            self.net.start()
        self.logger.info("Adding tunnels to mininet instance")
        for tunnel in tunnels:
            port = None
            cls = None
            if "node1" not in tunnel[2].keys():
                self.logger.info("Error! node1 is missing in tunnel metadata")
            if tunnel[2]["node1"] in topo.nodes():
                port = tunnel[2]["port1"]
            else:
                port = tunnel[2]["port2"]

            if "cls" in tunnel[2].keys():
                cls = tunnel[2]["cls"]
                del tunnel[2]["cls"]
            self.addTunnel(tunnel[0],
                           tunnel[1],
                           port,
                           cls,
                           STT=STT,
                           **tunnel[2])
        if not STT:
            self.logger.info("Starting Mininet...")
            self.net.start()
        self.logger.info("Startup complete.")
        self.x11popens = []
        return True

    @Pyro4.expose
    def destroy_mininet(self):
        """shut down mininet instance"""
        if self.net:
            for popen in self.x11popens:
                popen.terminate()
                popen.communicate()
                popen.wait()
            self.net.stop()
            self.logger.info("mininet instance terminated")
            self.net = None

    @Pyro4.expose
    def configLinkStatus(self, src, dst, status):
        self.net.configLinkStatus(src, dst, status)

    @Pyro4.expose
    def rpc(self, hostname, cmd, *params1, **params2):
        h = self.net.get(hostname)
        return getattr(h, cmd)(*params1, **params2)

    @Pyro4.expose
    def attr(self, hostname, name):
        h = self.net.get(hostname)
        return getattr(h, name)

    @Pyro4.expose
    def addHost(self, name, cls=None, **params):
        self.net.addHost(name, cls, **params)
        return name

    @Pyro4.expose
    def addSwitch(self, name, cls=None, **params):
        self.net.addSwitch(name, cls, **params)
        #TODO: This should not be done here
        self.net.get(name).start(self.net.controllers)
        return name

    @Pyro4.expose
    def addController(self, name="c0", controller=None, **params):
        self.net.addController(name, controller, **params)
        return name

    @Pyro4.expose
    def addTunnel(self, name, switch, port, intf, STT=False, **params):
        switch_i = self.net.get(switch)
        if not intf:
            intf = TCIntf
        if STT:
            subprocess.check_output(["ovs-vsctl", "add-port", switch, name])
        else:
            intf(name, node=switch_i, port=port, link=None, **params)

    @Pyro4.expose
    def tunnelX11(self, node, display):
        node = self.net.get(node)
        (tunnel, popen) = mininet.term.tunnelX11(node, display)
        self.x11popens.append(popen)

    @Pyro4.expose
    def addLink(self,
                node1,
                node2,
                port1=None,
                port2=None,
                cls=None,
                **params):
        node1 = self.net.get(node1)
        node2 = self.net.get(node2)
        l = self.net.addLink(node1, node2, port1, port2, cls, **params)
        return ((node1.name, l.intf1.name), (node2.name, l.intf2.name))

    @Pyro4.expose
    def runCmdOnHost(self, hostname, command, noWait=False):
        '''
            e.g. runCmdOnHost('h1', 'ifconfig')
        '''
        h1 = self.net.get(hostname)
        if noWait:
            return h1.sendCmd(command)
        else:
            return h1.cmd(command)
Example #50
0
                        default='10',
                        type=str,
                        help='Test bandwidth')
    parser.add_argument('ips',
                        metavar='ip',
                        help='ONOS Network Controllers IP Addresses',
                        default=['127.0.0.1'],
                        type=str,
                        nargs='*')
    cli_args = parser.parse_args()

    setLogLevel('info')

    switch = partial(OVSSwitch, protocols='OpenFlow13')

    rcs = []
    for ip in cli_args.ips:
        rcs.append(RemoteController('ONOS-%s' % ip, ip=ip, port=6633))
    net = Mininet(topo=TreeTopo(cli_args.depth, 2), switch=switch, build=False)
    for rc in rcs:
        net.addController(rc)
    net.build()
    net.start()
    b = int(cli_args.bandwidth)
    for i in range(b):
        net.hosts[i].sendCmd('ping -c100 -i 0.01 %s' % net.hosts[i + 1].IP())
    for i in range(b):
        print(net.hosts[i].waitOutput())
    CLI(net)
    net.stop()
Example #51
0
def topology():
    """Create a network"""
    net = Mininet(controller=RemoteController,
                  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.0.3/24')
    h4 = net.addHost('h4', mac='00:00:00:00:00:04', ip='10.0.0.4/24')
    h5 = net.addHost('h5', mac='00:00:00:00:00:05', ip='10.0.0.5/24')
    s1 = net.addSwitch('s1', listenPort=6671)
    s2 = net.addSwitch('s2', listenPort=6672)
    s3 = net.addSwitch('s3', listenPort=6673)
    s4 = net.addSwitch('s4', listenPort=6674)
    s5 = net.addSwitch('s5', listenPort=6675)
    c7 = net.addController('c7',
                           controller=RemoteController,
                           ip='127.0.0.1',
                           port=6633)

    print("*** Creating links")

    net.addLink(s1, h1)
    net.addLink(s2, h2)
    net.addLink(s3, h3)
    net.addLink(s4, h4)
    net.addLink(s5, h5)
    net.addLink(s1, s2)
    net.addLink(s2, s3)
    net.addLink(s3, s4)
    net.addLink(s4, s5)
    net.addLink(s3, h2)
    net.addLink(s4, h3)
    h2.cmd('ifconfig h2-eth1 10.0.0.12 netmask 255.255.255.0')
    h3.cmd('ifconfig h3-eth1 10.0.0.13 netmask 255.255.255.0')

    print("*** Starting network")

    net.build()
    h2.cmd(
        'ip route add 10.0.0.1/32 dev h2-eth0; ip route add 10.0.0.5/32 dev h2-eth1'
    )
    h2.cmd(
        'ip route add 10.0.0.253/32 dev h2-eth0; ip route add 10.0.0.254/32 dev h2-eth1'
    )
    h2.cmd('sudo arp -i h2-eth0 -s 10.0.0.253 01:02:03:04:05:06')
    h2.cmd('sudo arp -i h2-eth1 -s 10.0.0.254 11:12:13:14:15:16')

    h3.cmd(
        'ip route add 10.0.0.1/32 dev h3-eth0; ip route add 10.0.0.5/32 dev h3-eth1'
    )
    h3.cmd(
        'ip route add 10.0.0.253/32 dev h3-eth0; ip route add 10.0.0.254/32 dev h3-eth1'
    )
    h3.cmd('sudo arp -i h3-eth0 -s 10.0.0.253 01:02:03:04:05:06')
    h3.cmd('sudo arp -i h3-eth1 -s 10.0.0.254 11:12:13:14:15:16')

    h5.cmd('sudo arp -i h5-eth0 -s 10.0.0.253 01:02:03:04:05:06')

    c7.start()
    s1.start([c7])
    s2.start([c7])
    s3.start([c7])
    s4.start([c7])
    s5.start([c7])

    h2.cmd(
        './json_register.py --file=forwarder1.txt -a 10.0.0.253 -p 30012 -n registration'
    )
    h2.cmd(
        './json_register.py --file=forwarder1-2.txt -a 10.0.0.254 -p 30012 -n registration'
    )
    h3.cmd(
        './json_register.py --file=forwarder2-1.txt -a 10.0.0.253 -p 30012 -n registration'
    )
    h3.cmd(
        './json_register.py --file=forwarder2-2.txt -a 10.0.0.254 -p 30012 -n registration'
    )
    h5.cmd(
        './json_register.py --file=forwarder3.txt -a 10.0.0.253 -p 30012 -n registration'
    )
    print("*** Running CLI")
    CLI(net)

    print("*** Stopping network")
    net.stop()
Example #52
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=Controller,
                           protocol='tcp',
                           port=6633)

    c1 = net.addController(name='c1',
                           controller=Controller,
                           protocol='tcp',
                           port=6634)

    c2 = net.addController(name='c2',
                           controller=Controller,
                           protocol='tcp',
                           port=6635)

    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)

    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)
    h6 = net.addHost('h6', cls=Host, ip='10.0.0.6', 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)
    h9 = net.addHost('h9', cls=Host, ip='10.0.0.9', defaultRoute=None)
    h10 = net.addHost('h10', cls=Host, ip='10.0.0.10', defaultRoute=None)

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

    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('s6').start([c1])
    net.get('s7').start([c1])
    net.get('s8').start([c1])

    net.get('s3').start([c2])
    net.get('s4').start([c2])
    net.get('s5').start([c2])

    return net
Example #53
0
from mininet.cli import CLI
from mininet.log import setLogLevel
from mininet.net import Mininet
from mininet.topo import Topo
from mininet.node import RemoteController

net = Mininet()

h1 = net.addHost('h1',ip='192.168.10.1/24',defaultRoute='via 192.168.10.254')
h2 = net.addHost('h2',ip='192.168.20.1/24',defaultRoute='via 192.168.20.254')
h3 = net.addHost('h3',ip='192.168.30.1/24',defaultRoute='via 192.168.30.254')
h4 = net.addHost('h4',ip='8.8.8.8/8',defaultRoute='via 8.255.255.254')

s1 = net.addSwitch('s1')
s2 = net.addSwitch('s2')
s3 = net.addSwitch('s3')
c0 = net.addController(controller = RemoteController)

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

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

net.start()
CLI(net)
net.stop()
Example #54
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=Controller,
                      protocol='tcp',
                      port=6633)

    info( '*** Add switches\n')
    s1 = net.addSwitch('s1', cls=OVSKernelSwitch)
    s5 = net.addSwitch('s5', cls=OVSKernelSwitch)
    s7 = net.addSwitch('s7', cls=OVSKernelSwitch)
    s4 = net.addSwitch('s4', cls=OVSKernelSwitch)
    s10 = net.addSwitch('s10', cls=OVSKernelSwitch, failMode='standalone')
    s6 = net.addSwitch('s6', cls=OVSKernelSwitch)
    s3 = net.addSwitch('s3', cls=OVSKernelSwitch)
    s8 = net.addSwitch('s8', cls=OVSKernelSwitch)
    s9 = net.addSwitch('s9', cls=OVSKernelSwitch, failMode='standalone')
    s2 = net.addSwitch('s2', cls=OVSKernelSwitch)

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

    info( '*** Add links\n')
    s2s1 = {'bw':1000,'delay':'10','loss':1}
    net.addLink(s2, s1, cls=TCLink , **s2s1)
    s1s3 = {'bw':200,'delay':'20','loss':2}
    net.addLink(s1, s3, cls=TCLink , **s1s3)
    s1s4 = {'bw':50,'delay':'100','loss':5}
    net.addLink(s1, s4, cls=TCLink , **s1s4)
    h1s5 = {'bw':500,'delay':'10','loss':1}
    net.addLink(h1, s5, cls=TCLink , **h1s5)
    s5s2 = {'bw':700,'delay':'5','loss':1}
    net.addLink(s5, s2, cls=TCLink , **s5s2)
    s6s2 = {'bw':300,'delay':'5','loss':1}
    net.addLink(s6, s2, cls=TCLink , **s6s2)
    s7s3 = {'bw':100,'delay':'20','loss':1}
    net.addLink(s7, s3, cls=TCLink , **s7s3)
    s3s8 = {'bw':100,'delay':'20','loss':1}
    net.addLink(s3, s8, cls=TCLink , **s3s8)
    s9s4 = {'bw':20,'delay':'50','loss':5}
    net.addLink(s9, s4, cls=TCLink , **s9s4)
    s4s10 = {'bw':30,'delay':'50','loss':1}
    net.addLink(s4, s10, cls=TCLink , **s4s10)
    s5h2 = {'bw':200,'delay':'5','loss':1}
    net.addLink(s5, h2, cls=TCLink , **s5h2)
    h3s6 = {'bw':200,'delay':'10','loss':1}
    net.addLink(h3, s6, cls=TCLink , **h3s6)
    s6h4 = {'bw':100,'delay':'5','loss':1}
    net.addLink(s6, h4, cls=TCLink , **s6h4)
    h5s7 = {'bw':30,'delay':'30','loss':2}
    net.addLink(h5, s7, cls=TCLink , **h5s7)
    s7h6 = {'bw':70,'delay':'30','loss':2}
    net.addLink(s7, h6, cls=TCLink , **s7h6)
    s8h7 = {'bw':50,'delay':'30','loss':2}
    net.addLink(s8, h7, cls=TCLink , **s8h7)
    s8h8 = {'bw':50,'delay':'30','loss':2}
    net.addLink(s8, h8, cls=TCLink , **s8h8)
    h9s9 = {'bw':10,'delay':'50','loss':1}
    net.addLink(h9, s9, cls=TCLink , **h9s9)
    s9h10 = {'bw':10,'delay':'50','loss':1}
    net.addLink(s9, h10, cls=TCLink , **s9h10)
    s10h11 = {'bw':15,'delay':'50','loss':1}
    net.addLink(s10, h11, cls=TCLink , **s10h11)
    s10h12 = {'bw':15,'delay':'50','loss':1}
    net.addLink(s10, h12, cls=TCLink , **s10h12)

    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('s5').start([c0])
    net.get('s7').start([c0])
    net.get('s4').start([c0])
    net.get('s10').start([])
    net.get('s6').start([c0])
    net.get('s3').start([c0])
    net.get('s8').start([c0])
    net.get('s9').start([])
    net.get('s2').start([c0])

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

    CLI(net)
    net.stop()
Example #55
0
def multiControllerNet(con_num=3, sw_num=15, host_num=30):
    "Create a network from semi-scratch with multiple controllers."
    controller_list = []
    switch_list = []
    host_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
    '''
    # 改为自定义ip的
    c1 = RemoteController('c1', ip='120.79.164.198', port=6653)
    c2 = RemoteController('c2', ip='127.0.0.1', port=6653)
    c3 = RemoteController('c3', ip='172.20.80.175', port=6653)

    # 加入网络
    net.addController(c1)
    net.addController(c2)
    net.addController(c3)
    controller_list.append(c1)
    controller_list.append(c2)
    controller_list.append(c3)
    print "*** Creating switches"
    switch_list = [net.addSwitch('s%d' % n) 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."
    for i in xrange(0, sw_num):
        net.addLink(switch_list[i], host_list[i * 2])
        net.addLink(switch_list[i], host_list[i * 2 + 1])

    print "*** Creating interior links of switch2switch."
    for i in xrange(0, sw_num, sw_num / con_num):
        for j in xrange(sw_num / con_num):
            for k in xrange(sw_num / con_num):
                if j != k and j > k:
                    net.addLink(switch_list[i + j], switch_list[i + k])

    print "*** Creating intra links of switch2switch."

    # 改
    # 用首末两个交换机和外部网络链接,一个网络链接一条
    # c1:0,4  c2:5,9  c3:10,14
    # c1 -> others
    net.addLink(switch_list[0], switch_list[5])
    net.addLink(switch_list[4], switch_list[10])

    # c2 -> others

    # c3 has not need to add links.

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

    _No = 0
    for i in xrange(0, sw_num, sw_num / con_num):
        for j in xrange(sw_num / con_num):
            switch_list[i + j].start([controller_list[_No]])
        _No += 1

    #print "*** Testing network"
    #net.pingAll()

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

    print "*** Stopping network"
    net.stop()
Example #56
0
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()

    # 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)

    graphic()

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

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

    print "*** Stopping network"
    net.stop()
Example #57
0
                    index, 'x')
            self.graph.node[switch][
                'vdpid'] = "00a42305" + self.graph.node[switch]['dpid'][-10:-2]
            self.addSwitch(switch, dpid=self.graph.node[switch]['dpid'])

        # Add hosts and connect them to their core switch
        for switch in self.graph.nodes():
            for i in range(host_per_sw):
                # Add host
                host = 'h_%s_%d' % (switch, i + 1)
                ip = '10.0.0.%d' % (i + 1)
                mac = self.graph.node[switch]['dpid'][4:-1] + '%d' % (i + 1)
                h = self.addHost(host, ip=ip, mac=mac)
                # Connect hosts to core switches
                self.addLink(h, switch)


if __name__ == '__main__':
    topo = MNTopo()
    net = Mininet(topo,
                  autoSetMacs=True,
                  xterms=False,
                  controller=RemoteController)
    net.addController(
        'c', ip='127.0.0.1'
    )  # localhost:127.0.0.1 vm-to-mac:10.0.2.2 server-to-mac:128.112.93.28
    print "\nHosts configured with IPs, switches pointing to OpenVirteX at 127.0.0.1 port 6633\n"
    net.start()
    CLI(net)
    net.stop()
def CreateTopology():
    net = Mininet(controller=RemoteController,
                  link=TCLink,
                  switch=OVSKernelSwitch)

    print 'Creating nodes...'
    h = {}
    for i in range(1, 101):
        h[i] = net.addHost('h' + str(i),
                           mac='00:00:00:00:00:' + str(i),
                           ip='10.0.0.' + str(i) + '/24')

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

    c0 = net.addController('c0',
                           controller=RemoteController,
                           ip='127.0.0.1',
                           port=6653)

    print 'Creating links...'
    for i in range(1, 51):
        net.addLink(h[i], s1, bw=100)

    for i in range(51, 101):
        net.addLink(h[i], s2, bw=100)

    net.addLink(s1, s2, bw=100)

    print 'Starting network...'
    net.build()
    c0.start()
    s1.start([c0])
    s2.start([c0])

    print 'Verifying connectivity...'
    #loss = net.pingAll()

    host = {}

    print '*** Mausezahn flood...'
    for i in range(1, 101):
        host[i] = net.getNodeByName('h' + str(i))

    # Wait until end of second
    t = datetime.datetime.utcnow()
    sleeptime = 1 - (t.microsecond / 1000000.0)
    time.sleep(sleeptime)
    #

    # NoNAttack traffic for 25 users for each 2 seconds
    x = 1
    for count in range(0, 25):
        BaseTraffic(host, x, x + 25, 2, 2)
        x += 25

        if x >= 54:
            x = 1
        WaitTillEndOfSec(2)
    # ------
    #
    # # RANDOM
    # for p in range(0, 50):
    #     for j in range(0, 50):
    #         x = random.randint(1, 79)
    #         BaseTraffic(host, x, x + 1, 1, 1)
    #     WaitTillEndOfSec(1)

    #  NoNAttack traffic 10 and 5 users for each 5 seconds
    # x = 1
    # for count in range(0, 10):
    #
    #     BaseTraffic(host, x, x + 10, 3, 5)
    #     BaseTraffic(host, x + 10, x + 15, 4, 5)
    #     x += 15
    #
    #     if x >= 64:
    #         x = 1
    #
    #     WaitTillEndOfSec(5)

    # x = 1
    # for count in range(0, 16):
    #
    #     BaseTraffic(host, x, x + 10, 3, 3)
    #     BaseTraffic(host, x + 10, x + 15, 4, 3)
    #     x += 15
    #
    #     if x >= 64:
    #         x = 1
    #
    #     WaitTillEndOfSec(3)
    #
    # BaseTraffic(host, 65, 75, 3, 2)
    # BaseTraffic(host, 75, 80, 4, 2)

    # x = 1
    # for count in range(0, 16):
    #     BaseTraffic(host, x, x + 16, 2, 3)
    #     BaseTraffic(host, x + 16, x + 22, 3, 3)
    #     x += 22
    #
    #     if x >= 58:
    #         x = 1
    #
    #     WaitTillEndOfSec(3)
    #
    # BaseTraffic(host, 55, 80, 2, 2)

    print 'Running CLI...'
    CLI(net)

    print 'Stopping network...'
    net.stop()
Example #59
0
            self.addLink(c, cs0)
        # Connect switch to root namespace so that data network
        # switches will be able to talk to us
        root = self.addHost('root', inNamespace=False)
        self.addLink(root, cs0)


# Make it Happen!!

setLogLevel('info')

info('* Creating Control Network\n')
ctopo = ControlNetwork(n=4, dataController=DataController)
cnet = Mininet(topo=ctopo, ipBase='192.168.123.0/24', build=False)
info('* Adding Control Network Controller\n')
cnet.addController('cc0')
info('* Starting Control Network\n')
cnet.build()
cnet.start()
dataControllers = cnet.hosts[:-1]  # ignore 'root' node

info('* Creating Data Network\n')
topo = TreeTopo(depth=2, fanout=2)
# UserSwitch so we can easily test failover
net = Mininet(topo=topo, switch=UserSwitch, build=False)
info('* Adding Controllers to Data Network\n')
net.controllers = dataControllers
net.build()
info('* Starting Data Network\n')
net.start()
Example #60
0
def keyboardInterruptHandler(signal, frame):
    print("KeyboardInterrupt (ID: {1}) has been caught. Cleaning up...".format(
        signal))
    net.stop()
    exit(0)


signal.signal(signal.SIGINT, keyboardInterruptHandler)

print('Configure your controller correctly before starting the simulation...')
print('type <ENTER>')

input()

net.addController('rmController',
                  controller=RemoteController,
                  ip='127.0.0.1',
                  port=6653)

net.start()

# Before starting the simulation, run a ping all.
while net.pingAll() > 0:
    continue

# Start the monitoring thread
# output = open("./logs/utilization.log", "w+")

# # Creating the threads
# monitoring_thread = MonitoringThread(monitor, output)

# # Before starting the ti pythonhreads, execute the testing.