def pairNet( pairs=1, useSwitches=False, bw=None, cpu=-1, **kwargs ):
    "Convenience function for creating pair networks"
    clients, servers = [], []
    # This is a bit ugly - a lot of work to avoid flushing
    # routes; I think we should rethink how that works.
    class MyHost( CPULimitedHost ):
        "Put clients in root namespace and DON'T flush routes"
        def __init__( self, name, **kwargs ):
            # First N (=pairs) hosts are clients, in root NS
            kwargs.pop('inNamespace', True)
            isServer = int( name[ 1: ] ) > pairs
            CPULimitedHost.__init__( self, name, inNamespace=isServer, **kwargs )
        def setDefaultRoute( self, intf ):
            "Hack of sorts: don't set or flush route"
            pass

    cpu = custom( MyHost, cpu=cpu )
    link = custom( TCLink, bw=bw )
    topo = PairTopo( pairs, useSwitches )
    net = Mininet( topo, host=MyHost, **kwargs )
    net.hosts = sorted( net.hosts, key=lambda h: natural( h.name ) )
    clients, servers = net.hosts[ :pairs ], net.hosts[ pairs: ]
    info( "*** Configuring host routes\n" )
    for client, server in zip( clients, servers ):
        client.setHostRoute( server.IP(), client.defaultIntf() )
        server.setHostRoute( client.IP(), server.defaultIntf() )
    return net, clients, servers
Esempio n. 2
0
def cs461net():
    stophttp()
    "Create a simple network for cs461"
    r = get_ip_setting()
    if r == -1:
        exit("Couldn't load config file for ip addresses, check whether %s exists" % IPCONFIG_FILE)
    else:
        info( '*** Successfully loaded ip settings for hosts\n %s\n' % IP_SETTING)

    topo = CS461Topo()
    info( '*** Creating network\n' )
    net = Mininet( topo=topo, controller=RemoteController, ipBase=IPBASE )
    net.start()
    server1, server2, client, router = net.get( 'server1', 'server2', 'client', 'sw0')
    s1intf = server1.defaultIntf()
    s1intf.setIP('%s/8' % IP_SETTING['server1'])
    s2intf = server2.defaultIntf()
    s2intf.setIP('%s/8' % IP_SETTING['server2'])
    clintf = client.defaultIntf()
    clintf.setIP('%s/8' % IP_SETTING['client'])


    for host in server1, server2, client:
        set_default_route(host)
    starthttp( server1 )
    starthttp( server2 )
    CLI( net )
    stophttp()
    net.stop()
def addHosts():
    global h1, h2, h3, h4, h5


    "1. Add five hosts h1, h2, h3, h4, h5 to the network"
    "2. Provide DockerHost class as the base host for all these hosts (h1..h5)"
    "3. DockerHost class is defined above for you. Dockerhost class is derived from the default Host class of mininet. Dockerclass creates containers like this sudo docker run -i -t -d --name $host --hostname $host -v /vagrant:/home/ubuntu myace:v1 /bin/bash"
    "4. so basically container will have its /home/ubuntu folder shared with VM's /vagrant folder"
    "5. You just need to pass DockerHost class as a parameter to addHost command"
    "6. Provide ips like: 10.0.0.x where x is 1 for h1 and so on till 5 for h5"
    "7. You need to write something like this h1 = net.addHost(<parameters>)"
    "8. e.g h1 = net.addHost('h1', ip='x.x.x.x', cls=HostClass)"
    "9. When you add host using addHost command, DockerHost class will first try to remove it if exits. So first time you will see some warnings/errors in red saying that there is no such container named h1. Ignore them"

    info( '\nadding host h1\n' )
    h1 = net.addHost('h1', ip='10.0.0.1')

    info( '\nadding host h2\n' )
    h2 = net.addHost('h2', ip='10.0.0.2')

    info( '\nadding host h3\n' )
    h3 = net.addHost('h3', ip='10.0.0.3')

    info( '\nadding host h4\n' )
    h4 = net.addHost('h4', ip='10.0.0.4')

    info( '\nadding host h5\n' )
    h5 = net.addHost('h5', ip='10.0.0.5')
Esempio n. 4
0
def bwtest(cpuLimits, period_us=100000, seconds=5):
    """Example/test of link and CPU bandwidth limits
       cpu: cpu limit as fraction of overall CPU time"""

    topo = TreeTopo(depth=1, fanout=2)

    results = {}

    for sched in "rt", "cfs":
        print "*** Testing with", sched, "bandwidth limiting"
        for cpu in cpuLimits:
            host = custom(CPULimitedHost, sched=sched, period_us=period_us, cpu=cpu)
            try:
                net = Mininet(topo=topo, host=host)
            except:
                info("*** Skipping host %s\n" % sched)
                break
            net.start()
            net.pingAll()
            hosts = [net.getNodeByName(h) for h in topo.hosts()]
            client, server = hosts[0], hosts[-1]
            server.cmd("iperf -s -p 5001 &")
            waitListening(client, server, 5001)
            result = client.cmd("iperf -yc -t %s -c %s" % (seconds, server.IP())).split(",")
            bps = float(result[-1])
            server.cmdPrint("kill %iperf")
            net.stop()
            updated = results.get(sched, [])
            updated += [(cpu, bps)]
            results[sched] = updated

    return results
Esempio n. 5
0
def host3(net):
  info('Configuring host 3\n')
  host = net.getNodeByName('h3')
  host.setMAC('00:00:00:00:01:03')
  gw('LAN',host)
  #apagar = raw_input('Deseja zerar arquivos de log do IDS? sim|nao (um backup sera feito)\n')
  ids(host, 'sim')
Esempio n. 6
0
  def run(self):
    print self.receivelinkevent
    
    setLogLevel("info")
    OVSKernelSwitch.setup()#"Make sure Open vSwitch is installed and working"

    info("****creating network****\n")
    self.net = Mininet(listenPort = self.listenPort)

    controller = RemoteController("mirrorController",   ip = "127.0.0.1")
    self.net.addController(controller)
    #self.gettoptly()
    timesnum=0;
    while core.running:
      try:
        while True:
          rlist, wlist, elist = yield Select([self.receivelinkevent], [], [], 5)
          if len(rlist) == 0 and len(wlist) == 0 and len(elist) == 0:
            #self.gettoptly()
            if not core.running: break
          #if len(rlist)!=0:
            #print self.receivelinkevent
          if self.receivelinkevent==1:
            self.gettoptly()
            timesnum+=1
            if timesnum==5:
              self.net.pingAll()    
      except exceptions.KeyboardInterrupt:
        break
    self.net.stop()
Esempio n. 7
0
 def start_oe(self):
     '''
     start the existing LINC switch
     '''
     #starting Switch
     cmd = "linc:start_switch({}).\r\n".format(self.lincId)
     self.write_to_cli(cmd)
     #hanlding taps interfaces related to the switch
     crossConnectJSON = {}
     linkConfig = []
     for i in range(0,len(self.deletedCrossConnects)):
         crossConnect = self.deletedCrossConnects.pop()
         tap = None
         if isinstance(crossConnect.intf1.node, LINCSwitch):
             intf = crossConnect.intf2
             tapPort = crossConnect.intf1.port
         else:
             intf = crossConnect.intf1
             tapPort = crossConnect.intf2.port
         tap = LINCSwitch.findTap(self, tapPort)
         if tap:
             LINCSwitch.setupInts([tap])
             intf.node.attach(tap)
         self.crossConnects.append(crossConnect)
         linkConfig.append(crossConnect.json())
     #Sending crossConnect info to the ONOS.
     crossConnectJSON['links'] = linkConfig
     with open("crossConnect.json", 'w') as fd:
         json.dump(crossConnectJSON, fd, indent=4, separators=(',', ': '))
     info('*** Pushing crossConnect.json to ONOS\n')
     output = quietRun('%s/tools/test/bin/onos-topo-cfg %s\
      Topology.json' % (self.onosDir, self.controllers[ 0 ].ip), shell=True)
Esempio n. 8
0
 def setCPUFrac( self, f=-1, sched=None):
     """Set overall CPU fraction for this host
        f: CPU bandwidth limit (fraction)
        sched: 'rt' or 'cfs'
        Note 'cfs' requires CONFIG_CFS_BANDWIDTH"""
     if not f:
         return
     if not sched:
         sched = self.sched
     if sched == 'rt':
         pstr, qstr, period, quota = self.rtInfo( f )
     elif sched == 'cfs':
         pstr, qstr, period, quota = self.cfsInfo( f )
     else:
         return
     if quota < 0:
         # Reset to unlimited
         quota = -1
     # Set cgroup's period and quota
     self.cgroupSet( pstr, period )
     self.cgroupSet( qstr, quota )
     if sched == 'rt':
         # Set RT priority if necessary
         self.chrt()
     info( '(%s %d/%dus) ' % ( sched, quota, period ) )
Esempio n. 9
0
def sdnTopo(interface_name):

    CONTROLLER_IP='10.0.0.200'

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

    # Create nodes
    h1 = net.addHost( 'h1', ip='10.0.0.1/8' )
    h2 = net.addHost( 'h2', ip='10.0.0.2/8' )

    # Create switches
    s1 = net.addSwitch( 's1')

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

    # Add Controllers
    odl_ctrl = net.addController( 'c0', controller=RemoteController, ip=CONTROLLER_IP)


    info( "*** Creation de l'architecture réseau\n" )
    net.build()

    # Connect each switch to a different controller
    s1.start( [odl_ctrl] )


    info( "*** Ajout de l'interface",interface_name,"au switch" )
    _intf = Intf( interface_name, node=s1)
    net.start()
    CLI( net )
    net.stop()
Esempio n. 10
0
    def __init__(self, conf_arq, workDir, **opts):
        Topo.__init__(self, **opts)

        global hosts_conf
        global links_conf
        hosts_conf = parse_hosts(conf_arq)
        switches_conf = parse_switches(conf_arq)
        links_conf = parse_links(conf_arq)

        self.isTCLink = False
        self.isLimited = False

        for host in hosts_conf:
            if host.cpu != None and self.isLimited != True:
                self.isLimited = True
            self.addHost(host.name, app=host.app, params=host.uri_tuples, cpu=host.cpu,cores=host.cores,cache=host.cache, workdir=workDir)

        for switch in switches_conf:
            self.addSwitch(switch.name)

        for link in links_conf:
            if len(link.linkDict) == 0:
                self.addLink(link.h1, link.h2)
            else:
                self.addLink(link.h1, link.h2, **link.linkDict)
                self.isTCLink = True

        info('Parse of ' + conf_arq + ' done.\n')
Esempio n. 11
0
def sdnnet(opt):
    topo = SDNTopo()
    info( '*** Creating network\n' )
    net = Mininet( topo=topo, controller=MyController, link=TCLink)

    host = []
    for i in range (8):
      host.append(net.get( 'host%d' % i ))

    net.start()

    core_sw = []
    for i in range (2):
        name_suffix = '%s' % NWID + '0c' + '%02d' % i
        net.get('sw' + name_suffix).attach('tap%s0' % NWID)

    for i in range (8):
        host[i].defaultIntf().setIP('192.168.10.10%d/24' % i) 

    root = []
    for i in range (8):
        root.append(net.get( 'root%d' % i ))

    for i in range (8):
        host[i].intf('host%d-eth1' % i).setIP('1.1.%d.1/24' % i)
        root[i].intf('root%d-eth0' % i).setIP('1.1.%d.2/24' % i)

    stopsshd ()
    startsshds ( host )

    if opt=="cli":
        CLI(net)
        stopsshd()
        net.stop()
Esempio n. 12
0
 def runCpuLimitTest(self, cpu, duration=5):
     """run CPU limit test with 'while true' processes.
     cpu: desired CPU fraction of each host
     duration: test duration in seconds
     returns a single list of measured CPU fractions as floats.
     """
     pct = cpu * 100
     info("*** Testing CPU %.0f%% bandwidth limit\n" % pct)
     hosts = self.hosts
     for h in hosts:
         h.cmd("while true; do a=1; done &")
     pids = [h.cmd("echo $!").strip() for h in hosts]
     pids_str = ",".join(["%s" % pid for pid in pids])
     cmd = "ps -p %s -o pid,%%cpu,args" % pids_str
     # It's a shame that this is what pylint prefers
     outputs = []
     for _ in range(duration):
         sleep(1)
         outputs.append(quietRun(cmd).strip())
     for h in hosts:
         h.cmd("kill $!")
     cpu_fractions = []
     for test_output in outputs:
         # Split by line.  Ignore first line, which looks like this:
         # PID %CPU COMMAND\n
         for line in test_output.split("\n")[1:]:
             r = r"\d+\s*(\d+\.\d+)"
             m = re.search(r, line)
             if m is None:
                 error("*** Error: could not extract CPU fraction: %s\n" % line)
                 return None
             cpu_fractions.append(float(m.group(1)))
     output("*** Results: %s\n" % cpu_fractions)
     return cpu_fractions
Esempio n. 13
0
 def __init__( self, mininet, stdin=sys.stdin, script=None ):
     self.mn = mininet
     self.nodelist = self.mn.controllers + self.mn.switches + self.mn.hosts
     self.nodemap = {}  # map names to Node objects
     for node in self.nodelist:
         self.nodemap[ node.name ] = node
     # Attempt to handle input
     self.stdin = stdin
     self.inPoller = poll()
     self.inPoller.register( stdin )
     self.inputFile = script
     Cmd.__init__( self )
     info( '*** Starting CLI:\n' )
     if self.inputFile:
         self.do_source( self.inputFile )
         return
     while True:
         try:
             # Make sure no nodes are still waiting
             for node in self.nodelist:
                 while node.waiting:
                     node.sendInt()
                     node.monitor()
             if self.isatty():
                 quietRun( 'stty sane' )
             self.cmdloop()
             break
         except KeyboardInterrupt:
             output( '\nInterrupt\n' )
Esempio n. 14
0
 def __init__( self, mininet, stdin=sys.stdin, script=None ):
     self.mn = mininet
     # Local variable bindings for py command
     self.locals = { 'net': mininet }
     # Attempt to handle input
     self.stdin = stdin
     self.inPoller = poll()
     self.inPoller.register( stdin )
     self.inputFile = script
     Cmd.__init__( self )
     info( '*** Starting CLI:\n' )
     if self.inputFile:
         self.do_source( self.inputFile )
         return
     while True:
         try:
             # Make sure no nodes are still waiting
             for node in self.mn.values():
                 while node.waiting:
                     node.sendInt()
                     node.monitor()
             if self.isatty():
                 quietRun( 'stty sane' )
             self.cmdloop()
             break
         except KeyboardInterrupt:
             output( '\nInterrupt\n' )
Esempio n. 15
0
 def run(self, test, *args, **kwargs):
     "Perform a complete start/test/stop cycle."
     self.start()
     info("*** Running test\n")
     result = test(*args, **kwargs)
     self.stop()
     return result
Esempio n. 16
0
def probnet_building():   
    #read ./IP_CONFIG config file for host addressing
    r = get_ip_setting()
    if r == -1:
        exit("Couldn't load config file for ip addresses, check whether %s exists" % IPCONFIG_FILE)
    else:
        info( '*** Successfully loaded ip settings\n %s\n' % IP_SETTING)
    get_route_setting()
    topo = B6Probing()
    info( '*** Creating network\n' )
    net = Mininet( topo=topo, controller=RemoteController, link=TCLink)
    net.start()
    
    #get node objects
    probe, server, internet, transit_1, transit_2 = net.get( 'probe', 
                                                             'server',
                                                             'internet',
                                                             't1',
                                                             't2')

    #set IP address and default routes to prob and server nodes
    #it's quite ugly this part of code, try to rewrite
    host_node_ifconfig(probe)
    host_node_ifconfig(server)
    network_node_ifconfig(internet)
    network_node_ifconfig(transit_1)
    network_node_ifconfig(transit_2)
    set_probing_ip(probe)
    start_web_server( server )
    CLI( net )
    stop_web_server( server )
    net.stop()
Esempio n. 17
0
def moduleDeps( subtract=None, add=None ):
    """Handle module dependencies.
       subtract: string or list of module names to remove, if already loaded
       add: string or list of module names to add, if not already loaded"""
    subtract = subtract if subtract is not None else []
    add = add if add is not None else []
    if type( subtract ) is str:
        subtract = [ subtract ]
    if type( add ) is str:
        add = [ add ]
    for mod in subtract:
        if mod in lsmod():
            info( '*** Removing ' + mod + '\n' )
            rmmodOutput = rmmod( mod )
            if rmmodOutput:
                error( 'Error removing ' + mod + ': "%s">\n' % rmmodOutput )
                exit( 1 )
            if mod in lsmod():
                error( 'Failed to remove ' + mod + '; still there!\n' )
                exit( 1 )
    for mod in add:
        if mod not in lsmod():
            info( '*** Loading ' + mod + '\n' )
            modprobeOutput = modprobe( mod )
            if modprobeOutput:
                error( 'Error inserting ' + mod +
                       ' - is it installed and available via modprobe?\n' +
                       'Error was: "%s"\n' % modprobeOutput )
            if mod not in lsmod():
                error( 'Failed to insert ' + mod + ' - quitting.\n' )
                exit( 1 )
        else:
            debug( '*** ' + mod + ' already loaded\n' )
Esempio n. 18
0
def setup(num, hwintf, beg_ip):

    info( '*** Creating network\n' )
    #net = Mininet( topo=TestTopo( num ), switch=UserSwitch, controller=RemoteController)
    #net = Mininet( topo=TestTopo( num ), controller=RemoteController, listenPort=6634)
    net = Mininet( topo=TestTopo( num ), controller=RemoteController)
    #net = Mininet( topo=TestTopo( num ))

    os.environ['NOX_CORE_DIR'] = '/opt/nox/bin'
    #controller = net.addController(name='c0', controller=NOX, noxArgs='switchqos --threads=1')
    controller = net.addController(name='c0', controller=NOX, noxArgs='switchqos --threads=10')
    #controller = net.addController(name='c0', controller=NOX, noxArgs='switch --threads=10')

    #os.environ['NOX_CORE_DIR'] = '/usr/local/bin'
    #controller = net.addController(name='c0', controller=NOX, noxArgs='switchqos')

    # Add HW interface to root switch
    switch = net.switches[ 0 ]
    switch.addIntf(hwintf)

    ip = beg_ip.split('.')
    for n in range( N-1 ):
        h = net.hosts[n]
        i = h.intfs[0]
        h.setIP(i, '.'.join(ip), 24)
        #print "IP: " + `h.IP()`
        ip[3] = str(int(ip[3]) + 1)
        #print h.IP()

    #import networkx
    #networkx.draw(net.topo.g)
    #import pylab
    #pylab.show()

    return(net)
Esempio n. 19
0
    def loadResults(cls, jsonFile):
        """Load results from json file
        :param jsonFile : json format file to load from"""
        ms = json.load(open(jsonFile, "r"))
        methods = {}

        class Host(object):
            def __init__(self, name):
                self.name = name

        for name, method_data in ms.iteritems():
            methods[name] = {}
            methods[name]["pairs"] = []
            methods[name]["real_steps"] = method_data["real_steps"]
            for pairdata in method_data["pairs"]:
                s = cls.HostStats(
                    method=name,
                    host=Host(pairdata["host"]),
                    target=Host(pairdata["target"]),
                    baseline=DelayStats(**pairdata["baseline"]),
                    baselineMeasures=[DelayStats(**m) for m in pairdata["baselineMeasures"]],
                    measures=[DelayStats(**m) for m in pairdata["measures"]],
                )
                methods[name]["pairs"].append(s)
        info("Loading delay results done\n")
        return methods
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
Esempio n. 21
0
 def placeNodes( self ):
     """Place nodes on servers (if they don't have a server), and
        start shell processes"""
     if not self.servers or not self.topo:
         # No shirt, no shoes, no service
         return
     nodes = self.topo.nodes()
     placer = self.placement( servers=self.servers,
                              nodes=self.topo.nodes(),
                              hosts=self.topo.hosts(),
                              switches=self.topo.switches(),
                              links=self.topo.links() )
     for node in nodes:
         config = self.topo.nodeInfo( node )
         # keep local server name consistent accross nodes
         if 'server' in config.keys() and config[ 'server' ] is None:
             config[ 'server' ] = 'localhost'
         server = config.setdefault( 'server', placer.place( node ) )
         if server:
             config.setdefault( 'serverIP', self.serverIP[ server ] )
         info( '%s:%s ' % ( node, server ) )
         key = ( None, server )
         _dest, cfile, _conn = self.connections.get(
                     key, ( None, None, None ) )
         if cfile:
             config.setdefault( 'controlPath', cfile )
Esempio n. 22
0
def errRun( *cmd, **kwargs ):
    """Run a command and return stdout, stderr and return code
       cmd: string or list of command and args
       stderr: STDOUT to merge stderr with stdout
       shell: run command using shell
       echo: monitor output to console"""
    # By default we separate stderr, don't run in a shell, and don't echo
    stderr = kwargs.get( 'stderr', PIPE )
    shell = kwargs.get( 'shell', False )
    echo = kwargs.get( 'echo', False )
    if echo:
        # cmd goes to stderr, output goes to stdout
        info( cmd, '\n' )
    if len( cmd ) == 1:
        cmd = cmd[ 0 ]
    # Allow passing in a list or a string
    if isinstance( cmd, str ) and not shell:
        cmd = cmd.split( ' ' )
        cmd = [ str( arg ) for arg in cmd ]
    elif isinstance( cmd, list ) and shell:
        cmd = " ".join( arg for arg in cmd )
    debug( '*** errRun:', cmd, '\n' )
    popen = Popen( cmd, stdout=PIPE, stderr=stderr, shell=shell )
    # We use poll() because select() doesn't work with large fd numbers,
    # and thus communicate() doesn't work either
    out, err = '', ''
    poller = poll()
    poller.register( popen.stdout, POLLIN )
    fdtofile = { popen.stdout.fileno(): popen.stdout }
    outDone, errDone = False, True
    if popen.stderr:
        fdtofile[ popen.stderr.fileno() ] = popen.stderr
        poller.register( popen.stderr, POLLIN )
        errDone = False
    while not outDone or not errDone:
        readable = poller.poll()
        for fd, event in readable:
            f = fdtofile[ fd ]
            if event & POLLIN:
                data = f.read( 1024 )
                if echo:
                    output( data )
                if f == popen.stdout:
                    out += data
                    if data == '':
                        outDone = True
                elif f == popen.stderr:
                    err += data
                    if data == '':
                        errDone = True
            else:  # POLLHUP or something unexpected
                if f == popen.stdout:
                    outDone = True
                elif f == popen.stderr:
                    errDone = True
                poller.unregister( fd )

    returncode = popen.wait()
    debug( out, err, returncode )
    return out, err, returncode
Esempio n. 23
0
  def run (self):
    setLogLevel("info")
    OVSKernelSwitch.setup()#"Make sure Open vSwitch is installed and working"

    info("****creating network****\n")
    self.net = Mininet(listenPort = 6666)

    controller = RemoteController("mirrorController",   ip = "127.0.0.1")
    self.net.addController(controller)
    while core.running:
      try:
        time.sleep(3)
        if not core.running: break
        '''
        self.net.pingAll()
        if len(self.addswitches)!=0:
          for i in self.addswitches:
            print self.addswitches[i].dpctl('show')
        '''
        if self.rectopolyreply==1:
          mutex.acquire()
          self.createtoptly()
          self.rectopolyreply=0
          mutex.release()
      except exceptions.KeyboardInterrupt:
        break
      except:
        log.exception("Exception SendMes running ")
        break
    self.net.stop()
Esempio n. 24
0
def test_ping_with_background_traffice(network, round_count=1, round_duration=5, ping_interval=1.0, background=True):
    """
    h1 执行 ping 测试延时
    h2 执行 netperf 测试带宽利用率
    :param background:
    :param network: mininet class
    :param round_count:    循环次数
    :param round_duration: 循环时间每轮
    :param ping_interval:  ping包采样间隔
    :return:
    """
    result = ""
    h1 = network.get("h1")
    popens = {}
    if background:  # backgroud traffice, 每轮增加10秒时延
        h1.cmd("netperf -H h3 -l %s &" % (round_count * (round_duration + 5)))
    sleep(3)  # wait 2 second to reach tcp max output
    for r in range(round_count):
        print ("*** ROUND %s" % r)
        for h in [h1]:
            ping_cmd = "ping -c%s -i%s h3 " % (int(round_duration / ping_interval), ping_interval)
            info("<%s>: popen cmd: %s \n" % (h.name, ping_cmd))
            popens[h] = h.popen(ping_cmd)

        # Monitor them and print output
        for host, line in pmonitor(popens):
            if host:
                if line.find("icmp_seq") != -1:
                    debug("<%s>: %s\n" % (host.name, line.strip()))  # suppressed ping output to debug level
                else:
                    info("<%s>: %s\n" % (host.name, line.strip()))
                    result += "<%s>: %s\n" % (host.name, line.strip())

    debug("\n".join(os.popen('tc -s -d qdisc show dev s1-eth3').readlines()))
    return result
Esempio n. 25
0
def test01_04_ecn_red(network, bw=10, latency=50, qlen=200, duration=10):
    """

    测试结果记录在 ecn_result/2016-06-28_ecn_red.txt

    # 设置 使用 red ecn 以及不使用, 并使用 mesure_delay_and_output() 测试
    :param network:
    :param bw:          # 10Mbps 带宽
    :param latency:     # 50ms 延时
    :param qlen:        # 队列长度
    :param duration:    # 运行时间
    :return:
    """
    # print_mininet_objs(net)
    result_all = {}

    # result_all dict 追加入01 结果
    result_all.update(test01_base(network, "TEST01", bw=bw, latency=latency, qlen=qlen, duration=duration))

    # result_all dict 追加入03 04 05 结果
    for testname, redminmax in zip(["TEST02", "TEST03", "TEST04"],
                                   ["min 50000  max  150000 avpkt 1500",
                                    "min 65000  max  150000 avpkt 1500",
                                    "min 75000  max  150000 avpkt 1500"
                                    ]):
        # result_all = result1.copy()
        # if testname == "TEST02": continue
        result_all.update(
            test02_04_base_ecn_red(network, testname, redminmax, bw=bw, latency=latency, qlen=qlen, duration=duration))

    info("\n\n\n*** all result here ***\n\n\b")
    ecn_util.dump_result(result_all)
    return result_all
Esempio n. 26
0
def test01_base(network, testname, bw=10, latency=50, qlen=200, duration=10):
    """
    # 设置 使用 red ecn 以及不使用, 并使用 mesure_delay_and_output() 测试
    :param testname:    # 测试名称
    :param network:
    :param bw:          # 10Mbps 带宽
    :param latency:     # 50ms 延时
    :param qlen:        # 队列长度
    :param duration:    # 运行时间
    :return:
    """
    # print_mininet_objs(net)
    result = {}
    red_ecn = False

    def run_this_bench():
        return ecn_util.mesure_ping_and_netperf(network, round_count=1, round_duration=duration, ping_interval=0.1)

    # 无ecn测试 TEST01
    default_minmax = ""
    testfullname = "%s ECN:%s qlen:%s bw:%sMbps lat:%sms no red:%s" % (
        testname, red_ecn, qlen, bw, latency, "")
    info("*** setup %s\n" % testfullname)
    test01_06_setup_queue_and_latency(network, ecn=red_ecn, bw=bw, queue_len=qlen, latency=latency,
                                      redminmax=default_minmax)
    info("*** running %s ...\n" % testfullname)
    result[testfullname] = run_this_bench()

    ecn_util.dump_result(result)
    return result
Esempio n. 27
0
def test02_04_base_ecn_red(network, testname, redminmax, bw=10, latency=50, qlen=200, duration=10):
    """
    独立复制出的 03 04 实验, 用于enc抓包测试
    :param redminmax:      # red参数设置
    :param testname:       # 测试名称
    :param network:
    :param bw:
    :param latency:
    :param qlen:
    :param duration:
    :return:
    """

    result = {}

    def run_this_bench():
        return ecn_util.mesure_ping_and_netperf(network, round_count=1, round_duration=duration, ping_interval=0.1)

    # ecn 参数变化测试 02 03 04
    testfullname = "%s ECN:%s qlen:%s bw:%sMbps lat:%sms redminmax:%s" % (
        testname, True, qlen, bw, latency, redminmax)
    info("*** setup %s \n" % testfullname)
    test01_06_setup_queue_and_latency(network, ecn=True, bw=bw, queue_len=qlen, latency=latency,
                                      redminmax=redminmax)
    info("*** running %s ...\n" % testfullname)
    result[testfullname] = run_this_bench()

    ecn_util.dump_result(result)
    return result
Esempio n. 28
0
def waitListening( client=None, server='127.0.0.1', port=80, timeout=None ):
    """Wait until server is listening on port.
       returns True if server is listening"""
    runCmd = ( client.cmd if client else
               partial( quietRun, shell=True ) )
    if not runCmd( 'which telnet' ):
        raise Exception('Could not find telnet' )
    # pylint: disable=maybe-no-member
    serverIP = server if isinstance( server, basestring ) else server.IP()
    cmd = ( 'echo A | telnet -e A %s %s' % ( serverIP, port ) )
    time = 0
    result = runCmd( cmd )
    while 'Connected' not in result:
        if 'No route' in result:
            rtable = runCmd( 'route' )
            error( 'no route to %s:\n%s' % ( server, rtable ) )
            return False
        if timeout and time >= timeout:
            error( 'could not connect to %s on port %d\n' % ( server, port ) )
            return False
        debug( 'waiting for', server, 'to listen on port', port, '\n' )
        info( '.' )
        sleep( .5 )
        time += .5
        result = runCmd( cmd )
    return True
Esempio n. 29
0
 def assign_iface(cls, nodes, phys, **params):
     """Assign virtual interfaces for all nodes
     
     :param nodes: list of wireless nodes
     :param phys: list of phys
     :param **params: ifb -  Intermediate Functional Block device"""
     log_filename = '/tmp/mininetwifi-fakelb.log'
     cls.logging_to_file("%s" % log_filename)
     try:
         debug("\n*** Configuring interfaces with appropriated network"
               "-namespaces...\n")
         for node in nodes:
             for wlan in range(0, len(node.params['wpan'])):
                 node.wpanPhyID[wlan] = cls.wpanPhyID
                 cls.wpanPhyID += 1
                 phy = cls.getPhy(phys[0])
                 os.system('iwpan phy phy%s set netns %s' % (phy, node.pid))
                 node.cmd('ip link set %s down' % cls.wlan_list[0])
                 node.cmd('ip link set %s name %s'
                          % (cls.wlan_list[0], node.params['wpan'][wlan]))
                 cls.wlan_list.pop(0)
     except:
         logging.exception("Warning:")
         info("Warning! Error when loading fakelb. "
              "Please run sudo 'mn -c' before running your code.\n")
         info("Further information available at %s.\n" % log_filename)
         exit(1)
Esempio n. 30
0
 def startTerms( self ):
     "Start a terminal for each node."
     info( "*** Running terms on %s\n" % os.environ[ 'DISPLAY' ] )
     cleanUpScreens()
     self.terms += makeTerms( self.controllers, 'controller' )
     self.terms += makeTerms( self.switches, 'switch' )
     self.terms += makeTerms( self.hosts, 'host' )
Esempio n. 31
0
    parser.add_argument( '-n', '--nointernet', action='store_true', \
                         help="don't connect to the internet")
    args, unknown = parser.parse_known_args( argv )
    
    lg.setLogLevel( 'info' )
    
    # Create net
    if (not args.switch):
        humber = Humber()
    else:
        humber = Humber(Mode.SWITCH)
    net = Mininet(topo=humber)

    # Create itable.conf for student's router code, if requested
    if (args.itable is not None):
        info( '*** Creating itable for r0\n' )
        r0_itable = Itable()
        r0_itable.add('r0-eth0', '10.0.1.1', '00:00:00:00:00:01 ', '255.255.255.0')
        r0_itable.add('r0-eth1', '10.0.2.1', '00:00:00:00:00:02 ', '255.255.255.0')
        r0_itable.add('r0-eth2', '10.0.3.1', '00:00:00:00:00:03 ', '255.255.255.0')
        r0_itable.createFile('r0-'+args.itable) 
        info( '*** Creating itable for r1\n' )
        r1_itable = Itable()
        r1_itable.add('r1-eth0', '10.0.2.2', '00:00:00:00:01:01 ', '255.255.255.0')
        r1_itable.add('r1-eth1', '10.0.4.1', '00:00:00:00:01:02 ', '255.255.255.0')
        r1_itable.add('r1-eth2', '10.0.6.1', '00:00:00:00:01:03 ', '255.255.255.0')
        r1_itable.createFile('r1-'+args.itable) 
        info( '*** Creating itable for r2\n' )
        r2_itable = Itable()
        r2_itable.add('r2-eth0', '10.0.3.2', '00:00:00:00:02:01 ', '255.255.255.0')
        r2_itable.add('r2-eth1', '10.0.5.1', '00:00:00:00:02:02 ', '255.255.255.0')
Esempio n. 32
0
def Start(GI=False, MCS=2, Bandwidth=20, UDP=True, TP=20, PCAP=False):
    setLogLevel('info')
    #info( '*** ns-3 network demo\n' )
    net = Mininet()

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

    wifi = WIFISegment()

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

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

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

    # Enabling Shor guard intervals:
    wifi.phyhelper.Set("ShortGuardEnabled", ns.core.BooleanValue(gi))

    DataRate = ns.wifi.VhtWifiMacHelper.DataRateForMcs(mcs)
    #DataRate = ns.core.StringValue("VhtMcs3")

    # set datarate for node h0
    wifi.wifihelper.SetRemoteStationManager("ns3::ConstantRateWifiManager",
                                            "DataMode", DataRate,
                                            "ControlMode", DataRate)

    wifi.machelper = ns.wifi.VhtWifiMacHelper.Default()

    Sssid = "wifi-80211ac"

    wifi.addSta(h0, ssid=Sssid)

    wifi.addAp(h2, ssid=Sssid)

    # set channel bandwidth
    ns.core.Config.Set(
        "/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/ChannelWidth",
        ns.core.UintegerValue(bandwidth))

    if PCAP == True:
        wifi.phyhelper.EnablePcap("80211ac_Sta1.pcap", h0.nsNode.GetDevice(0),
                                  True, True)
        #wifi.phyhelper.EnablePcap( "Ap-h1.pcap", h1.nsNode.GetDevice( 1 ), True, True );
        wifi.phyhelper.EnablePcap("80211ac_Ap.pcap", h2.nsNode.GetDevice(0),
                                  True, True)

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

    mininet.ns3.start()

    #info( '\n *** Testing network connectivity\n' )
    net.pingFull([h0, h2])
    h0.cmdPrint("ping 192.168.123.3 -c 10")
    info(
        '*** Testing bandwidth between h0 and h2 while h1 is not transmitting\n'
    )
    h2.sendCmd("iperf -s -i 1 -u")
    val = "iperf -c 192.168.123.3 -u -b " + str(TP) + "M"
    h0.cmdPrint(val)
Esempio n. 33
0
    def run_FDM(self,
                changeList,
                backboneFT=False,
                quickStart=False,
                use_alpha=False):
        n_host = len(self.users) + 1
        n_net = len(self.nets)
        cnt = 0
        user_to_host = {}
        net_to_wireless = {}
        host_to_user = {}
        wireless_to_net = {}
        backbone_to_end = {}
        end_to_backbone = {}

        #Adding nodes
        for user in self.users:
            user_to_host[user] = cnt
            host_to_user[cnt] = user
            cnt += 1
        server = cnt
        cnt += 1
        for net in self.nets:
            net_to_wireless[net] = cnt
            wireless_to_net[cnt] = net
            backbone_to_end[self.backbones[net]] = cnt + n_net
            end_to_backbone[cnt + n_net] = self.backbones[net]
            cnt += 1
        cnt += n_net

        hub = cnt
        nn = hub + 1
        #Naming nodes
        names = range(nn)
        for i in range(nn):
            if (i in host_to_user):
                names[i] = host_to_user[i]
            if (i in wireless_to_net):
                names[i] = wireless_to_net[i]
            if (i in end_to_backbone):
                names[i] = end_to_backbone[i]
            if (i == hub):
                names[i] = self.hub
            if (i == server):
                names[i] = self.server

        info(names, '\n\n')
        #Addling links
        v_pairs = []
        for i in range(n_host - 1):
            for j in range(n_host, n_host + n_net):
                key = host_to_user[i] + '-' + wireless_to_net[j]
                v_pair = {}
                if (self.connectivity[key]):
                    v_pair['End1'] = i
                    v_pair['End2'] = j
                    #if there no key found, assume 0
                    if (key in self.delay):
                        v_pair['delay'] = self.delay[key]
                    # if there no key found, assume inf
                    if (key in self.capacity):
                        v_pair['cap'] = self.capacity[key]
                    v_pairs.append(v_pair)

        for i in range(n_host, n_host + n_net):
            key = wireless_to_net[i] + '-' + end_to_backbone[i + n_net]
            v_pair = {}
            if (key in self.connectivity):
                v_pair['End1'] = i
                v_pair['End2'] = i + n_net
                if (key in self.delay):
                    v_pair['delay'] = self.delay[key]
                if (key in self.capacity):
                    v_pair['cap'] = self.capacity[key]
                v_pairs.append(v_pair)
        for i in range(n_host, n_host + n_net):
            key = end_to_backbone[i + n_net] + '-' + names[hub]
            v_pair = {}
            if (key in self.connectivity):
                v_pair['End1'] = i + n_net
                v_pair['End2'] = hub
                if (key in self.delay):
                    v_pair['delay'] = self.delay[key]
                if (key in self.capacity):
                    v_pair['cap'] = self.capacity[key]
                v_pairs.append(v_pair)
        if True:
            key = names[hub] + '-' + names[server]
            #info('hub and server: ',key,'\n','\n\n')
            v_pair = {}
            if (key in self.connectivity):
                #info('add hub server key\n\n')
                v_pair['End1'] = hub
                v_pair['End2'] = server
                if (key in self.delay):
                    v_pair['delay'] = self.delay[key]
                if (key in self.capacity):
                    v_pair['cap'] = self.capacity[key]
                v_pairs.append(v_pair)

        nl = len(v_pairs)
        #info('got v_pairs\n')
        #info(v_pairs,'\n')
        #info(self.connectivity,'\n')
        Adj = [[] for i in range(nn)]
        End1, End2 = ([0 for j in range(nl)] for i in range(2))
        Cap, Cost, Offset, Gflow, Eflow, Pflow, FDlen, NewCap = ([
            float(0) for j in range(nl)
        ] for i in range(8))

        SPdist = [[float(0) for k in range(nn)] for i in range(nn)]
        SPpred = [[0 for k in range(nn)] for i in range(nn)]

        for idx, it in enumerate(v_pairs):
            End1[idx] = it['End1']
            End2[idx] = it['End2']
            Adj[it['End1']].append(idx)
            if ('delay' in it):
                Cost[idx] = float(it['delay'])
            else:
                Cost[idx] = float(0)
            if ('cap' in it):
                Cap[idx] = float(it['cap'])
            else:
                Cap[idx] = float("inf")
            Offset[idx] = -1
            if (it['End1'] in host_to_user):
                if (host_to_user[it['End1']] not in changeList):
                    key = host_to_user[it['End1']] + '-' + wireless_to_net[
                        it['End2']]
                    if (key in self.prev_flow):
                        Offset[idx] = float(self.prev_flow[key])
        #info("Adj is: \n\n")
        #info(Adj,'\n\n')
        Gtable, Etable = ([{} for i in range(nl)] for j in range(2))
        MsgLen = '1000B'
        PreviousDelay = float("inf")
        Req = [[float(0) for i in range(nn)] for j in range(nn)]
        MM_Req = [[float(0) for i in range(nn)] for j in range(nn)]
        TotReq = 0
        for i in range(n_host - 1):
            Req[i][server] = float(self.demand[host_to_user[i]])
            TotReq += Req[i][server]

        ###FDM algorithm

        #Initialize Gflow
        #Normal Start
        if (not quickStart):
            self.SetLinkLens(nl, Gflow, Cap, MsgLen, FDlen, Cost, Offset)
            self.SetSP(nn, End2, FDlen, Adj, SPdist, SPpred)
            #info("Predecessors:\n")
            #info(SPpred,'\n\n')
            self.LoadLinks(nn, nl, Req, SPpred, End1, Gflow, Gtable, names)
        else:
            #Quick start
            #load previous flows for users not in CL
            for user in self.users:
                if (user in changeList):
                    host = user_to_host[user]
                    for l in Adj[host]:
                        key = user + '-' + wireless_to_net[End2[l]]
                        ip = self.IPTable[self.linkToIntf[key]]
                        if self.prev_flow[key]:
                            f = self.prev_flow[key]
                            Gflow[l] += f
                            Gtable[l][ip] += f
                            s = End2[l]
                            while (s != server):
                                l = Adj[s][0]
                                Gflow[l] += f
                                Gtable[l][ip] += f
                                s = End2[l]
            self.SetLinkLens(nl, Gflow, Cap, MsgLen, FDlen, Cost, Offset)
            for user in self.users:
                if user in changeList:
                    host = user_to_host[user]
                    self.Bellman(nn, host, End2, FDlen, Adj, SPpred[host],
                                 SPdist[host])
                    self.LoadLInksInCL(host, server, Req[host][server], SPpred,
                                       End1, Gflow, Gtable, names)
        Aresult = self.AdjustCaps(nl, Gflow, Cap, NewCap)
        if Aresult == 1:
            Aflag = 0
        else:
            Aflag = 1
        CurrentDelay = self.CalcDelay(nl, Gflow, NewCap, MsgLen, TotReq, Cost,
                                      Offset)
        ori_delay = self.CalcDelay_ori(nl, Gflow, NewCap, MsgLen, TotReq, Cost)
        info(CurrentDelay, " ", ori_delay, '\n')

        delta, rho, step, gamma = [0.2, 0.2, 5, 2]
        req = TotReq / len(self.users)

        if (use_alpha and len(changeList) < len(self.users)):
            self.alpha=rho*max(CurrentDelay-self.global_opt,0.0)/step/(len(self.users)-len(changeList))\
                       /(delta*delta*req*req)
        count = 0
        feasible = 1
        while (Aflag or (CurrentDelay < PreviousDelay * (1 - self.EPSILON))):
            self.SetLinkLens(nl, Gflow, NewCap, MsgLen, FDlen, Cost, Offset)
            self.SetSP(nn, End2, FDlen, Adj, SPdist, SPpred)
            self.LoadLinks(nn, nl, Req, SPpred, End1, Eflow, Etable, names)
            PreviousDelay = self.CalcDelay(nl, Gflow, NewCap, MsgLen, TotReq,
                                           Cost, Offset)
            self.Superpose(nl, Eflow, Gflow, NewCap, TotReq, MsgLen, Cost,
                           Offset, Gtable, Etable)
            CurrentDelay = self.CalcDelay(nl, Gflow, NewCap, MsgLen, TotReq,
                                          Cost, Offset)
            tmp_delay = CurrentDelay
            if (Aflag):
                Aresult = self.AdjustCaps(nl, Gflow, Cap, NewCap)
                if Aresult == 1:
                    Aflag = 0
                else:
                    Aflag = 1

            CurrentDelay = self.CalcDelay(nl, Gflow, NewCap, MsgLen, TotReq,
                                          Cost, Offset)
            ori_delay = self.CalcDelay_ori(nl, Gflow, NewCap, MsgLen, TotReq,
                                           Cost)
            info(CurrentDelay, " ", ori_delay, '\n')
            CurrentDelay = tmp_delay
            if ((Aflag == 1 and (CurrentDelay >= PreviousDelay *
                                 (1 - self.EPSILON))) or count >= 100000):
                info('Problem is infeasible\n')
                feasible = 0
                break
            count += 1
            info(count, '\n')
        if (feasible):
            '''Printing flow tables and stuff'''

            print(Gtable)
            info('FDM success\n')
            '''Generate Flowtable and queues'''
            ft_book = [{} for i in range(nn)]
            for i in range(nl):
                end1 = End1[i]
                end2 = End2[i]
                key = names[end1] + '-' + names[end2]
                if end1 not in host_to_user:
                    if 'out' not in ft_book[end1]:
                        ft_book[end1]['out'] = []
                    if 'in' not in ft_book[end2]:
                        ft_book[end2]['in'] = []
                    ft_book[end1]['out'].append(self.linkToIntf[key][0])
                    ft_book[end2]['in'].append(self.linkToIntf[key][1])

            backFTConfig = []

            if backboneFT:
                backFTConfig = open("flowTable/backFTConfig.sh", "w")
                backFTConfig.write("#!/bin/bash\n\n")

            cnt = 1
            for n in range(nn):
                if n not in wireless_to_net and n not in host_to_user and n != server and backboneFT:
                    '''generate static backhaul flow table'''
                    if (len(ft_book[n]['out']) > 1):
                        info('backhaul node ', names[n],
                             ' output port number larger than 2\n')
                        print(ft_book[n]['out'])
                        exit(0)
                    outport = ft_book[n]['out'][0]
                    sw, intf1 = outport.split('-')
                    intf1_num = intf1[3:]
                    for port in ft_book[n]['in']:
                        sw, intf2 = port.split('-')
                        intf2_num = intf2[3:]
                        command="sudo ovs-ofctl add-flow "+names[n]+" in_port="+intf2_num+\
                            ",actions=output:"+intf1_num
                        backFTConfig.write(command + '\n')
                    command="sudo ovs-ofctl add-flow "+names[n]+" in_port="+intf1_num+\
                        ",actions=normal"
                    backFTConfig.write(command + '\n')
                    command = "sudo ovs-ofctl add-flow " + names[
                        n] + " priority=100,actions=normal\n"
                    backFTConfig.write(command)
                elif n in wireless_to_net:
                    '''generate dynamic net flow and queue tables'''
                    netFTConfig = open(
                        "flowTable/netFTConfig_" + names[n] + ".sh", "w")
                    netQConfig = open(
                        "flowTable/netQConfig_" + names[n] + ".sh", "w")
                    netFTConfig.write("#!/bin/bash\n\n")
                    netQConfig.write("#!/bin/bash\n\n")
                    outport = ft_book[n]['out'][0]
                    sw, intf = outport.split('-')
                    intf_num = intf[3:]
                    link = Adj[n][0]
                    Qcommand="sudo ovs-vsctl -- set Port "+outport+" qos=@newqos -- --id=@newqos"+\
                        " create QoS type=linux-htb other-config:max-rate=100000000 "

                    for idx in range(len(Gtable[link])):
                        Qcommand += " queues:" + str(idx + cnt) + "=@q" + str(
                            idx + cnt) + " "
                    Qcommand += '-- '
                    for idx, k in enumerate(Gtable[link]):
                        if (self.use_fdm):
                            Qcommand+="--id=@q"+str(idx+cnt)+" create Queue other-config:min-rate="+\
                                str(int(float(Gtable[link][k])*0.9*(10**6)))+" other-config:max-rate="+\
                                str(int(float(Gtable[link][k])*1.2*(10**6)))+" -- "
                            FTcommand = "sudo ovs-ofctl add-flow " + names[n] + " ip,nw_src=" + k + "/32,actions=set_queue:" + \
                                        str(idx + cnt) + ",output:" + intf_num
                        else:
                            userid = int(k.split('.')[2]) - 1
                            user = '******' + str(userid)
                            Qcommand += "--id=@q" + str(idx + cnt) + " create Queue other-config:min-rate=" + \
                                        str(int(float(self.demand[user]) * (10 ** 6))) + " other-config:max-rate=" + \
                                        str(int(float(self.demand[user]) * (10 ** 6))) + " -- "
                            FTcommand = "sudo ovs-ofctl add-flow " + names[
                                n] + " ip,nw_src=" + k + "/32,actions=output:" + intf_num
                        netFTConfig.write(FTcommand + '\n')
                    Qcommand = Qcommand.rstrip('-- ') + '\n'
                    netQConfig.write(Qcommand)
                    Qcommand = "sudo ovs-ofctl -O Openflow13 queue-stats " + names[
                        n] + '\n'
                    netQConfig.write(Qcommand)
                    FTcommand = "sudo ovs-ofctl add-flow " + names[
                        n] + " in_port=" + intf_num + ",actions=normal\n"
                    netFTConfig.write(FTcommand)
                    FTcommand = "sudo ovs-ofctl add-flow " + names[
                        n] + " priority=100,actions=normal\n"
                    netFTConfig.write(FTcommand)
                    cnt += len(Gtable[link])
                    netFTConfig.close()
                    call([
                        "sudo", "chmod", "777",
                        "flowTable/netFTConfig_" + names[n] + ".sh"
                    ])
                    netQConfig.close()
                    call([
                        "sudo", "chmod", "777",
                        "flowTable/netQConfig_" + names[n] + ".sh"
                    ])

            if backboneFT:
                backFTConfig.close()
                call(["sudo", "chmod", "777", "flowTable/backFTConfig.sh"])
                call(["sudo", "bash", "flowTable/backFTConfig.sh"])
            '''remove tables and queues and apply new ones'''
            info('*** remove net qos, queue, and flow tables ***\n')
            for net in self.nets:
                Net = self.mn.nameToNode[net]
                Net.cmdPrint('sudo ovs-vsctl clear port %s qos' %
                             ft_book[net_to_wireless[net]]['out'][0])
            Net.cmdPrint('sudo ovs-vsctl --all destroy qos')
            Net.cmdPrint('sudo ovs-vsctl --all destroy queue')
            for net in self.nets:
                Net.cmdPrint('sudo ovs-ofctl del-flows %s' % net)
                call(["sudo", "bash", "flowTable/netFTConfig_" + net + ".sh"])
                call(["sudo", "bash", "flowTable/netQConfig_" + net + ".sh"])

        else:
            '''Max-min reduce request'''
            info('FDM success infeasible\n')
Esempio n. 34
0
    def __init__(self,
                 mininet,
                 users,
                 nets,
                 demand={},
                 capacity={},
                 delay={},
                 start=0,
                 end=600,
                 interval=5,
                 use_fdm=True):
        self.mn = mininet
        #string list of sta names
        self.users = users
        #string list of lte/ap names
        self.nets = nets
        #dict {net name: backbone net name}
        self.backbones = {}
        #string of the single server
        self.server = ""
        if (len(mininet.hosts) == 1):
            self.server = mininet.hosts[0].name
        else:
            info('more than one hosts in Mininet\n')
            exit(0)
        #string of hub name
        self.hub = ""
        for intf in mininet.nameToNode[self.server].intfList():
            if intf.link:
                intfs = [intf.link.intf1, intf.link.intf2]
                intfs.remove(intf)
                if (intfs[0] != 'wireless'):
                    if (intfs[0].node not in mininet.switches
                            or self.hub != ""):
                        info('hub violation\n')
                        #print(intfs[0].node.name, mininet.switches, self.hub)
                        exit(0)
                    self.hub = intfs[0].node.name
        info('hub name is:')
        print(self.hub)
        #connectivity is a dict{string link pair: value 1/0}
        self.connectivity = {}

        self.IPTable = {}
        #dict{sta-net or net-backbone link: interface name}
        self.linkToIntf = {}
        self.prev_flow = {}
        #demand is a dictionary{sta name: double}
        self.demand = demand
        #capacity is a dict {string link pair: double}
        #assumption: capacity for sta-lte link and ltebackbone-hub link are set
        self.capacity = capacity
        #delay is a dict {string link pair: double}
        #assumption: delay for sta-lte and ltebackbone-hub links are set
        self.delay = delay
        self.alpha = 0
        self.global_opt = 0
        self.use_fdm = use_fdm
        #initialize AP related
        for user in users:
            for net in nets:
                key = user + '-' + net
                self.connectivity[key] = 0

        for user in users:
            sta = mininet.nameToNode[user]
            staid = user.lstrip('sta')
            ip = '10.0.' + str(int(staid) + 1) + '.0'
            #deal with AP
            for idx, wlan in enumerate(sta.params['wlan']):
                self.IPTable[wlan] = ip
                ip = getNextIP(ip)
                apNet = sta.params['associatedTo'][idx]
                if (apNet):
                    key = user + '-' + apNet.name
                    self.connectivity[key] = 1
                    self.linkToIntf[key] = wlan
                    #get dynamic link dist, cap, latency
                    dist = sta.get_distance_to(apNet)
                    cap = wirelessLink.setBW(sta=sta, ap=apNet, dist=dist)
                    #print(key+" capacity is: ",cap)
                    self.capacity[key] = cap
                    latency = wirelessLink.setLatency(dist)
                    #print(key+" latency is: ", latency)
                    self.delay[key] = latency
            #deal with Eth
            for idx, intf in enumerate(sta.intfList()):
                if (intf.name not in self.IPTable):
                    eth = intf.name
                    self.IPTable[eth] = ip
                    ip = getNextIP(ip)
                    intfs = [intf.link.intf1, intf.link.intf2]
                    intfs.remove(intf)
                    lteNet = intfs[0].node
                    key = user + '-' + lteNet.name
                    self.connectivity[key] = 1
                    self.linkToIntf[key] = eth

        # Find the backbone of Net
        for net in self.nets:
            Net = mininet.nameToNode[net]
            for intf in Net.intfList():
                if intf.link:
                    intfs = [intf.link.intf1, intf.link.intf2]
                    intfs.remove(intf)
                    if (intfs[0] != 'wireless'):
                        otherEnd = intfs[0].node
                        if (otherEnd in mininet.switches):
                            if (Net.name in self.backbones):
                                info("net ", Net.name,
                                     " connected to multiple backbones\n")
                                exit(0)
                            self.backbones[Net.name] = otherEnd.name
                            key = Net.name + '-' + otherEnd.name
                            self.connectivity[key] = 1
                            self.linkToIntf[key] = (intf.name, intfs[0].name)
                            #validate backbone node
                            for b_intf in otherEnd.intfList():
                                if (b_intf.name != 'lo'):
                                    b_intfs = [
                                        b_intf.link.intf1, b_intf.link.intf2
                                    ]
                                    b_intfs.remove(b_intf)
                                    tmpEnd = b_intfs[0].node
                                    if tmpEnd in mininet.switches or tmpEnd in mininet.aps:
                                        if (tmpEnd.name not in self.nets
                                                and tmpEnd.name != self.hub):
                                            info(
                                                'backbone node ',
                                                otherEnd.name,
                                                ' connected to unknown node\n')
                                            exit(0)
                                        if (tmpEnd.name not in self.nets):
                                            key2 = otherEnd.name + '-' + self.hub
                                            self.connectivity[key2] = 1
                                            self.linkToIntf[key2] = (
                                                b_intf.name, b_intfs[0].name)

        for intf in mininet.nameToNode[self.hub].intfList():
            if (intf.name != 'lo'):
                intfs = [intf.link.intf1, intf.link.intf2]
                intfs.remove(intf)
                if (intfs[0].node.name == self.server):
                    key = self.hub + '-' + self.server
                    self.connectivity[key] = 1
                    self.linkToIntf[key] = (intf.name, intfs[0].name)
        '''check keys of demand, capacity and delay'''
        for key in demand:
            if key not in self.users:
                info('demand does not match user\n')
                exit(0)
        for key in capacity:
            if key not in self.connectivity:
                info('capacity key does not match any link in connectivity\n')
                exit(0)
        for key in delay:
            if key not in self.connectivity:
                info('delay key does not match any link in connectivity\n')
                exit(0)

        info("connecitvities:\n")
        print(self.connectivity)
        info("IP tables:\n")
        print(self.IPTable)
        info("link and interfaces:\n")
        print(self.linkToIntf)
        info("backbones\n")
        print(self.backbones)

        thread = threading.Thread(target=self.checkChange,
                                  args=(start, end, interval))
        thread.daemon = True
        thread.start()
Esempio n. 35
0
def myNet(cname='controller', cargs='-v ptcp:'):
    "Create network from scratch using Open vSwitch."
    info( "*** Creating nodes\n" )
    controller = Node( 'c0', inNamespace=False )
    switch = Node( 's0', inNamespace=False )
    switch1 = Node( 's1', inNamespace=False )
    h0 = Node( 'h0' )
    h1 = Node( 'h1' )
   
    info( "*** Creating links\n" )
    linkopts0=dict(bw=100, delay='1ms', loss=0)
    linkopts1=dict(bw=100, delay='1ms', loss=10)
    link0=TCLink( h0, switch, **linkopts0)
    link1 = TCLink( switch, switch1, **linkopts1)    
    link2 = TCLink( h1, switch1, **linkopts0)
    #print link0.intf1, link0.intf2
    link0.intf2.setMAC("0:0:0:0:0:1")
    link1.intf1.setMAC("0:0:0:0:0:2")
    link1.intf2.setMAC("0:1:0:0:0:1")
    link2.intf2.setMAC("0:1:0:0:0:2")
 
    info( "*** Configuring hosts\n" )
    h0.setIP( '192.168.123.1/24' )
    h1.setIP( '192.168.123.2/24' )
      
    info( "*** Starting network using Open vSwitch\n" )
    switch.cmd( 'ovs-vsctl del-br dp0' )
    switch.cmd( 'ovs-vsctl add-br dp0' )
    switch1.cmd( 'ovs-vsctl del-br dp1' )
    switch1.cmd( 'ovs-vsctl add-br dp1' )
 
    controller.cmd( cname + ' ' + cargs + '&' )    
    for intf in switch.intfs.values():
        print intf
        print switch.cmd( 'ovs-vsctl add-port dp0 %s' % intf )
    for intf in switch1.intfs.values():
        print intf
        print switch1.cmd( 'ovs-vsctl add-port dp1 %s' % intf )
  
    # Note: controller and switch are in root namespace, and we
    # can connect via loopback interface
    switch.cmd( 'ovs-vsctl set-controller dp0 tcp:127.0.0.1:6633' )
    switch1.cmd( 'ovs-vsctl set-controller dp1 tcp:127.0.0.1:6633' )
 
    info( '*** Waiting for switch to connect to controller' )
    while 'is_connected' not in quietRun( 'ovs-vsctl show' ):
        sleep( 1 )
        info( '.' )
    info( '\n' )
 
    #info( "*** Running test\n" )
    h0.cmdPrint( 'ping -Q 0x64 -c 20 ' + h1.IP() )
   
    sleep( 1 )
    info( "*** Stopping network\n" )
    controller.cmd( 'kill %' + cname )
    switch.cmd( 'ovs-vsctl del-br dp0' )
    switch.deleteIntfs()
    switch1.cmd( 'ovs-vsctl del-br dp1' )
    switch1.deleteIntfs()
    info( '\n' )
Esempio n. 36
0
        print switch1.cmd( 'ovs-vsctl add-port dp1 %s' % intf )
  
    # Note: controller and switch are in root namespace, and we
    # can connect via loopback interface
    switch.cmd( 'ovs-vsctl set-controller dp0 tcp:127.0.0.1:6633' )
    switch1.cmd( 'ovs-vsctl set-controller dp1 tcp:127.0.0.1:6633' )
 
    info( '*** Waiting for switch to connect to controller' )
    while 'is_connected' not in quietRun( 'ovs-vsctl show' ):
        sleep( 1 )
        info( '.' )
    info( '\n' )
 
    #info( "*** Running test\n" )
    h0.cmdPrint( 'ping -Q 0x64 -c 20 ' + h1.IP() )
   
    sleep( 1 )
    info( "*** Stopping network\n" )
    controller.cmd( 'kill %' + cname )
    switch.cmd( 'ovs-vsctl del-br dp0' )
    switch.deleteIntfs()
    switch1.cmd( 'ovs-vsctl del-br dp1' )
    switch1.deleteIntfs()
    info( '\n' )
 
if __name__ == '__main__':
    setLogLevel( 'info' )
    info( '*** Scratch network demo (kernel datapath)\n' )
    Mininet.init()
    myNet()
Esempio n. 37
0
def vxlan():
    net = Mininet()

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

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

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

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

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

    info('*** Stopping network\n')
    net.stop()
Esempio n. 38
0
import time

from mininet.net import Mininet
from mininet.node import Node, Switch
from mininet.link import Link, Intf
from mininet.log import setLogLevel, info
from mininet.cli import CLI

import mininet.ns3
from mininet.ns3 import SimpleLink

readline.parse_and_bind("tab: complete")

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

    info('*** Creating Network\n')
    h0 = Node('h0')
    h1 = Node('h1')

    net.hosts.append(h0)
    net.hosts.append(h1)

    link = SimpleLink(h0, h1)

    mininet.ns3.start()

    info('*** Configuring hosts\n')
    h0.setIP('192.168.123.1/24')
Esempio n. 39
0
def myNetwork():

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

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

    info( '*** Add hosts\n')
    h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute=None)
    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)

    info( '*** Add links\n')
    net.addLink(h1, s1, cls= TCLink, bw=10, delay='5ms', loss=0, max_queue_size=1000)
    net.addLink(h2, s1, cls= TCLink, bw=10, delay='5ms', loss=0, max_queue_size=1000)
    net.addLink(h3, s1, cls= TCLink, bw=10, delay='5ms', loss=0, max_queue_size=1000)

    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([])

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

    CLI(net)
    net.stop()
Esempio n. 40
0
def topology():
    "Create a network."
    net = Mininet_wifi(controller=Controller,
                       accessPoint=OVSAP,
                       link=wmediumd,
                       wmediumd_mode=interference)

    info("*** Creating nodes\n")
    sta1 = net.addStation('sta1',
                          mac='00:00:00:00:00:02',
                          ip='10.0.0.1/8',
                          speed=4)
    sta2 = net.addStation('sta2',
                          mac='00:00:00:00:00:03',
                          ip='10.0.0.2/8',
                          speed=6)
    sta3 = net.addStation('sta3',
                          mac='00:00:00:00:00:04',
                          ip='10.0.0.3/8',
                          speed=3)
    sta4 = net.addStation('sta4',
                          mac='00:00:00:00:00:05',
                          ip='10.0.0.4/8',
                          speed=3)
    ap1 = net.addAccessPoint('ap1',
                             ssid='new-ssid',
                             mode='g',
                             channel='1',
                             position='45,45,0')
    c1 = net.addController('c1', controller=Controller)

    info("*** Configuring Propagation Model\n")
    net.setPropagationModel(model="logDistance", exp=4.5)

    info("*** Configuring wifi nodes\n")
    net.configureWifiNodes()

    info("*** Creating links\n")
    net.addLink(sta3, cls=adhoc, ssid='adhocNet')
    net.addLink(sta4, cls=adhoc, ssid='adhocNet')

    'ploting graph'
    #net.plotGraph(max_x=200, max_y=200)

    getTrace(sta1, 'examples/replaying/replayingMobility/node1.dat')
    getTrace(sta2, 'examples/replaying/replayingMobility/node2.dat')
    getTrace(sta3, 'examples/replaying/replayingMobility/node3.dat')
    getTrace(sta4, 'examples/replaying/replayingMobility/node4.dat')

    info("*** Starting network\n")
    net.build()
    c1.start()
    ap1.start([c1])

    replayingMobility(net)

    info("*** Running CLI\n")
    CLI_wifi(net)

    info("*** Stopping network\n")
    net.stop()
Esempio n. 41
0
def stopNetwork():
    "stops a network (only called on a forced cleanup)"

    if net is not None:
        info('** Tearing down Quagga network\n')
        net.stop()
Esempio n. 42
0
def emptyNet():

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

    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' )
    SimpleLink( h1, s3 )                    # line modified
    SimpleLink( h2, s3 )                    # line modified

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

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

    info( '*** Stopping network' )
    mininet.ns3.clear()                     # line added
    net.stop()
Esempio n. 43
0
 def _start_module(self, wirelessRadios):
     info( "*** Enabling Wireless Module\n" )
     os.system( 'modprobe mac80211_hwsim radios=%s' % wirelessRadios )
Esempio n. 44
0
def topology(mobility):
    'Create a network.'
    net = Mininet_wifi(link=wmediumd, wmediumd_mode=interference)

    info("*** Creating nodes\n")
    if mobility:
        sta1 = net.addStation('sta1',
                              mac='00:00:00:00:00:01',
                              ip='192.168.0.1/24')
    else:
        sta1 = net.addStation('sta1',
                              mac='00:00:00:00:00:01',
                              ip='192.168.0.1/24',
                              position='20,60,0')
    sta2 = net.addStation('sta2',
                          mac='00:00:00:00:00:02',
                          ip='192.168.1.1/24',
                          position='90,60,0')
    ap1 = net.addStation('ap1',
                         mac='02:00:00:00:01:00',
                         ip='192.168.0.10/24',
                         position='40,60,0')
    ap2 = net.addStation('ap2',
                         mac='02:00:00:00:02:00',
                         ip='192.168.1.10/24',
                         position='70,60,0')

    net.setPropagationModel(model="logDistance", exp=4.5)

    info("*** Configuring wifi nodes\n")
    net.configureWifiNodes()

    ap1.setMasterMode(intf='ap1-wlan0', ssid='ap1-ssid', channel='1', mode='n')
    ap2.setMasterMode(intf='ap2-wlan0', ssid='ap2-ssid', channel='6', mode='n')

    info("*** Adding Link\n")
    net.addLink(ap1, ap2)  # wired connection

    info("*** Plotting Graph\n")
    net.plotGraph(max_x=120, max_y=120)

    if mobility:
        net.startMobility(time=1)
        net.mobility(sta1, 'start', time=2, position='20.0,60.0,0.0')
        net.mobility(sta1, 'stop', time=6, position='100.0,60.0,0.0')
        net.stopMobility(time=7)

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

    ap1.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward')
    ap2.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward')

    ap1.setIP('192.168.0.10/24', intf='ap1-wlan0')
    ap1.setIP('192.168.2.1/24', intf='ap1-eth2')
    ap2.setIP('192.168.1.10/24', intf='ap2-wlan0')
    ap2.setIP('192.168.2.2/24', intf='ap2-eth2')
    ap1.cmd('route add -net 192.168.1.0/24 gw 192.168.2.2')
    ap2.cmd('route add -net 192.168.0.0/24 gw 192.168.2.1')
    sta1.cmd('route add -net 192.168.1.0/24 gw 192.168.0.10')
    sta1.cmd('route add -net 192.168.2.0/24 gw 192.168.0.10')
    sta2.cmd('route add -net 192.168.0.0/24 gw 192.168.1.10')
    sta2.cmd('route add -net 192.168.2.0/24 gw 192.168.1.10')

    info("*** Running CLI\n")
    CLI_wifi(net)

    info("*** Stopping network\n")
    net.stop()
def topology():
    "Create a network."
    net = Mininet_wifi(link=wmediumd, wmediumd_mode=interference)

    info("*** Creating nodes\n")
    net.addStation('sta1', position='10,20,0')
    net.addStation('sta2', position='40,30,0')
    net.addStation('sta3', position='60,20,0')
    net.addAccessPoint('ap1', ssid="my-ssid", mode="a", channel="36",
                       failMode='standalone', position='10,10,0')

    info("*** Configuring Propagation Model\n")
    net.setPropagationModel(model="logDistance", exp=4)

    net.plotGraph(max_x=100, max_y=100)

    info("*** Configuring wifi nodes\n")
    net.configureWifiNodes()

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

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

    info("*** Stopping network\n")
    net.stop()
Esempio n. 46
0
def startNetwork():
    "instantiates a topo, then starts the network and prints debug information"

    info('** Creating Quagga network topology\n')
    topo = QuaggaTopo()

    info('** Starting the network\n')
    global net
    net = MiniNExT(topo, controller=OVSController)
    net.start()

    info("** Running topology startup commands\n")
    topo.startup_commands(net.hosts)

    info('** Dumping host connections\n')
    dumpNodeConnections(net.hosts)

    info('** Testing network connectivity\n')
    net.ping(net.hosts)

    info('** Dumping host processes\n')
    for host in net.hosts:
        host.cmdPrint("ps aux")

    info('** Running CLI\n')
   # net.startTerms()
    CLI(net)
Esempio n. 47
0
def testRemoteNet(remote='ubuntu2'):
    "Test remote Node classes"
    info('*** Remote Node Test\n')
    net = Mininet(host=RemoteHost, switch=RemoteOVSSwitch, link=RemoteLink)
    c0 = net.addController('c0')
    # Make sure controller knows its non-loopback address
    Intf('eth0', node=c0).updateIP()
    info("*** Creating local h1\n")
    h1 = net.addHost('h1')
    info("*** Creating remote h2\n")
    h2 = net.addHost('h2', server=remote)
    info("*** Creating local s1\n")
    s1 = net.addSwitch('s1')
    info("*** Creating remote s2\n")
    s2 = net.addSwitch('s2', server=remote)
    info("*** Adding links\n")
    net.addLink(h1, s1)
    net.addLink(s1, s2)
    net.addLink(h2, s2)
    net.start()
    info('Mininet is running on', quietRun('hostname').strip())
    for node in c0, h1, h2, s1, s2:
        info('Node', node, 'is running on', node.cmd('hostname').strip())
    net.pingAll()
    CLI(net)
    net.stop()
Esempio n. 48
0
 def __init__(self, *args, **kwargs):
     info("** Using Mininet Extended (MiniNExT) Handler\n")
     Mininet.__init__(self, *args, **kwargs)
Esempio n. 49
0
def doopNetTest1():

    "Create a network with some docker containers acting as hosts."

    #net = Mininet( controller=Controller, etcHostsFile='/tmp/mnEtcHosts', doopnetFolder='/home/qys/SFI-SIRG-2015-01-VidSDN/hadoop-on-mininet-testbed/doopnet' )
    #net = Mininet( controller=Controller, doopnetFolder='/home/qys/SFI-SIRG-2015-01-VidSDN/hadoop-on-mininet-testbed/doopnet' )
    #net = Mininet( controller=Controller, etcHostsFile='/tmp/mnEtcHosts' )
    #net = Mininet( controller=Controller)
    net = Doopnet(
        controller=Controller,
        autoSetMacs=True,
        dimage="ubuntu:hadoop-cluster-test-1",
        hostExchangeFolder=
        '/home/qys/SFI-SIRG-2015-01-VidSDN/hadoop-on-mininet-testbed/doopnet/host-exchange'
    )

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

    # Normal hosts MUST be added before dockers,
    # otherwise docker cannot exit normally.
    #info( '*** Adding hosts\n' )
    #h1 = net.addHost( 'h1', ip='10.0.0.201' )
    #h2 = net.addHost( 'h2', ip='10.0.0.202' )
    #h1 = net.addHost( 'h1' )
    #h2 = net.addHost( 'h2' )

    info('*** Adding docker containers\n')
    #d1 = net.addDocker( 'd1', ip='10.0.0.1', dimage="ubuntu:hadoop-cluster-test-1" )
    #d2 = net.addDocker( 'd2', ip='10.0.0.2', dimage="ubuntu:hadoop-cluster-test-1" )
    #d3 = net.addDocker( 'd3', ip='10.0.0.3', dimage="ubuntu:hadoop-cluster-test-1" )
    #d1 = net.addDocker( 'd1', dimage="ubuntu:hadoop-cluster-test-1" )
    #d2 = net.addDocker( 'd2', dimage="ubuntu:hadoop-cluster-test-1" )
    #d3 = net.addDocker( 'd3', dimage="ubuntu:hadoop-cluster-test-1" )
    d1 = net.addDocker('d1')
    d2 = net.addDocker('d2')
    d3 = net.addDocker('d3')

    info('*** Adding switch\n')
    s1 = net.addSwitch('s1')
    # s2 = net.addSwitch( 's2', cls=OVSSwitch )
    # s3 = net.addSwitch( 's3' )

    info('*** Creating links\n')
    #net.addLink( h1, s1 )
    #net.addLink( h2, s1 )
    net.addLink(d1, s1)
    net.addLink(d2, s1)
    net.addLink(d3, s1)
    # try to add a second interface to a docker container
    # net.addLink( d2, s3, params1={"ip": "11.0.0.254/8"})
    # net.addLink( d3, s3 )

    info('*** Setting up Hadoop Cluster\n')
    hadoopClusterConfig = {
        'namenode': ['d1'],
        'secondarynamenode': ['d2'],
        'resourcemanager': ['d1'],
        'proxyserver': ['d1'],
        'historyserver': ['d1']
    }
    allSlaves = []
    for host in net.hosts:
        if host.__class__.__name__ == 'Docker':
            if host.hostname is not None:
                allSlaves += [host.hostname]
            else:
                allSlaves += [host.name]
    hadoopClusterConfig['datanode'] = allSlaves
    hadoopClusterConfig['nodemanager'] = allSlaves

    net.setupHadoopCluster(hadoopClusterConfig)

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

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

    info('*** Stopping network')
    net.stop()
Esempio n. 50
0
def topology():
    "Create a network."
    net = Mininet_wifi(controller=Controller, link=wmediumd,
                       wmediumd_mode=interference,
                       noise_th=-91, fading_cof=3)

    info("*** Creating nodes\n")
    ap1 = net.addAccessPoint('ap1', ssid='new-ssid', mode='a', channel='36',
                             position='15,30,0')
    net.addStation('sta1', mac='00:00:00:00:00:02', ip='10.0.0.1/8',
                   position='10,20,0')
    net.addStation('sta2', mac='00:00:00:00:00:03', ip='10.0.0.2/8',
                   position='20,50,0')
    net.addStation('sta3', mac='00:00:00:00:00:04', ip='10.0.0.3/8',
                   position='20,60,10')
    c1 = net.addController('c1')

    info("*** Configuring Propagation Model\n")
    net.setPropagationModel(model="logDistance", exp=4)

    info("*** Configuring wifi nodes\n")
    net.configureWifiNodes()

    nodes = net.stations + net.aps
    net.telemetry(nodes=nodes, single=True, data_type='rssi')

    info("*** Starting network\n")
    net.build()
    c1.start()
    ap1.start([c1])

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

    info("*** Stopping network\n")
    net.stop()
Esempio n. 51
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)
    s2 = net.addSwitch('s2', cls=OVSKernelSwitch)
    s3 = net.addSwitch('s3', cls=OVSKernelSwitch)

    info( '*** Add hosts\n')
    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)
    h5 = net.addHost('h5', cls=Host, ip='10.0.0.5', defaultRoute=None)
    h4 = net.addHost('h4', cls=Host, ip='10.0.0.4', defaultRoute=None)
    h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None)
    h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute=None)
    h8 = net.addHost('h8', cls=Host, ip='10.0.0.8', defaultRoute=None)
    h6 = net.addHost('h6', cls=Host, ip='10.0.0.6', defaultRoute=None)
    h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)
    h11 = net.addHost('h11', cls=Host, ip='10.0.0.11', defaultRoute=None)
    h9 = net.addHost('h9', cls=Host, ip='10.0.0.9', defaultRoute=None)

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

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

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

    CLI(net)
    net.stop()
Esempio n. 52
0
 def buildFromTopo(self, *args, **kwargs):
     "Start network"
     info('*** Placing nodes\n')
     self.placeNodes()
     info('\n')
     Mininet.buildFromTopo(self, *args, **kwargs)
Esempio n. 53
0
    def __init__(self):
        "Create custom topo."
        # Initialize topology
        Topo.__init__(self)
        # Add hosts and switches
        info('*** Add switches\n')
        s3 = self.addSwitch('s3')
        s8 = self.addSwitch('s8')
        s2 = self.addSwitch('s2')
        s11 = self.addSwitch('s11')
        s6 = self.addSwitch('s6')
        s5 = self.addSwitch('s5')
        s4 = self.addSwitch('s4')
        s10 = self.addSwitch('s10')
        s7 = self.addSwitch('s7')
        s12 = self.addSwitch('s12')
        s9 = self.addSwitch('s9')
        s1 = self.addSwitch('s1')
        s13 = self.addSwitch('s13')

        info('*** Add hosts\n')
        h15 = self.addHost('h15', cls=Host, ip='10.0.0.15', defaultRoute=None)
        h2 = self.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)
        h4 = self.addHost('h4', cls=Host, ip='10.0.0.4', defaultRoute=None)
        h5 = self.addHost('h5', cls=Host, ip='10.0.0.5', defaultRoute=None)
        h26 = self.addHost('h26', cls=Host, ip='10.0.0.26', defaultRoute=None)
        h17 = self.addHost('h17', cls=Host, ip='10.0.0.17', defaultRoute=None)
        h19 = self.addHost('h19', cls=Host, ip='10.0.0.19', defaultRoute=None)
        h6 = self.addHost('h6', cls=Host, ip='10.0.0.6', defaultRoute=None)
        h20 = self.addHost('h20', cls=Host, ip='10.0.0.20', defaultRoute=None)
        h27 = self.addHost('h27', cls=Host, ip='10.0.0.27', defaultRoute=None)
        h18 = self.addHost('h18', cls=Host, ip='10.0.0.18', defaultRoute=None)
        h9 = self.addHost('h9', cls=Host, ip='10.0.0.9', defaultRoute=None)
        h8 = self.addHost('h8', cls=Host, ip='10.0.0.8', defaultRoute=None)
        h13 = self.addHost('h13', cls=Host, ip='10.0.0.13', defaultRoute=None)
        h22 = self.addHost('h22', cls=Host, ip='10.0.0.22', defaultRoute=None)
        h16 = self.addHost('h16', cls=Host, ip='10.0.0.16', defaultRoute=None)
        h23 = self.addHost('h23', cls=Host, ip='10.0.0.23', defaultRoute=None)
        h10 = self.addHost('h10', cls=Host, ip='10.0.0.10', defaultRoute=None)
        h1 = self.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None)
        h11 = self.addHost('h11', cls=Host, ip='10.0.0.11', defaultRoute=None)
        h12 = self.addHost('h12', cls=Host, ip='10.0.0.12', defaultRoute=None)
        h25 = self.addHost('h25', cls=Host, ip='10.0.0.25', defaultRoute=None)
        h24 = self.addHost('h24', cls=Host, ip='10.0.0.24', defaultRoute=None)
        h3 = self.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute=None)
        h14 = self.addHost('h14', cls=Host, ip='10.0.0.14', defaultRoute=None)
        h21 = self.addHost('h21', cls=Host, ip='10.0.0.21', defaultRoute=None)
        h7 = self.addHost('h7', cls=Host, ip='10.0.0.7', defaultRoute=None)

        # Add links
        info('*** Add links\n')
        self.addLink(s5, s2)
        self.addLink(s2, s6)
        self.addLink(s2, s7)
        self.addLink(s5, h1)
        self.addLink(s5, h2)
        self.addLink(s5, h3)
        self.addLink(s6, h4)
        self.addLink(s6, h5)
        self.addLink(s6, h6)
        self.addLink(s7, h7)
        self.addLink(s7, h8)
        self.addLink(s7, h9)
        self.addLink(s3, s9)
        self.addLink(s8, s3)
        self.addLink(s8, h10)
        self.addLink(s8, h11)
        self.addLink(s8, h12)
        self.addLink(s9, h13)
        self.addLink(s9, h14)
        self.addLink(s9, h15)
        self.addLink(s3, s10)
        self.addLink(s10, h16)
        self.addLink(s10, h17)
        self.addLink(s10, h18)
        self.addLink(s4, s12)
        self.addLink(s4, s11)
        self.addLink(s11, h19)
        self.addLink(s11, h20)
        self.addLink(s11, h21)
        self.addLink(s12, h22)
        self.addLink(s12, h23)
        self.addLink(s12, h24)
        self.addLink(s13, h25)
        self.addLink(s13, h26)
        self.addLink(s13, h27)
        self.addLink(s4, s13)
        self.addLink(s1, s3)
        self.addLink(s1, s4)
        self.addLink(s2, s1)
Esempio n. 54
0
Enlaces:
https://blog.axosoft.com/gitkraken-tips-2/
'''

from mininet.node import OVSSwitch, Controller, RemoteController
from mininet.cli import CLI
from mininet.net import Containernet
from mininet.log import info, setLogLevel
import time

import os

setLogLevel('info')

info('*** Create the controller \n')

#info(c0)
"Create Simple topology example."
net = Containernet(switch=OVSSwitch, build=False)
net.addController('c0', controller=RemoteController, ip="127.0.0.1", port=6653)
net.addController('c1', controller=RemoteController, ip="127.0.0.1", port=6654)
# Initialize topology

# Add containers
h1 = net.addHost('h1', ip='10.0.0.251')  # Atacante
h2 = net.addHost('h2', ip='10.0.0.252')  # Cliente
h3 = net.addHost('h3', ip='10.0.0.253')  # Victima

# Add switches
info('*** Adding switches\n')
Esempio n. 55
0
def testLinkLimit(net, bw):
    "Run bandwidth limit test"
    info('*** Testing network %.2f Mbps bandwidth limit\n' % bw)
    net.iperf()
Esempio n. 56
0
#                'and is probably in use!\n' )
#         exit( 1 )

if __name__ == '__main__':
    simple_linear_2links = GeneratedTopo()

    setLogLevel('info')

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

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

    info('*** Creating network\n')
    controller = RemoteController('c0', ip='127.0.0.1', port=6633)
    net = Mininet(simple_linear_2links, controller=controller,
                  link=TCLink)  #topo=TreeTopo( depth=1, fanout=2 ) )

    # s1 = net.switches[0]
    # _intf_linkC = Intf('linkC', node=s1)
    # _intf_linkB = Intf('linkB', node=s1)
    # _intf_linkA = Intf('linkA', node=s1)
    #_intf_link8 = Intf('link8', node=s1)

    #net.addNAT().configDefault()
    #_intf_link8 = Intf('wlan0', node=s1)
    # switch = net.switches[ 0 ]
    # info( '*** Adding hardware interface', intfName, 'to switch',
    #       switch.name, '\n' )
Esempio n. 57
0
def myNetwork():

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

    info('*** Adding controller\n')
    # Change port and IP accordingly (c0 is Local controller, rest are Global controllers)
    c1 = net.addController(name='c1',
                           controller=InbandController,
                           ip='10.0.0.1',
                           protocol='tcp',
                           port=6653)

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

    c3 = net.addController(name='c3',
                           controller=InbandController,
                           ip='10.0.0.3',
                           protocol='tcp',
                           port=6653)

    c4 = net.addController(name='c4',
                           controller=InbandController,
                           ip='10.0.0.4',
                           protocol='tcp',
                           port=6653)

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

    c5 = net.addController(name='c5',
                           controller=InbandController,
                           ip='10.0.0.5',
                           protocol='tcp',
                           port=6653)

    c6 = net.addController(name='c6',
                           controller=InbandController,
                           ip='10.0.0.6',
                           protocol='tcp',
                           port=6653)

    c7 = net.addController(name='c7',
                           controller=InbandController,
                           ip='10.0.0.7',
                           protocol='tcp',
                           port=6653)

    info('*** Add switches\n')
    s1 = net.addSwitch('s1',
                       cls=OVSSwitch,
                       inband=True,
                       protocols='OpenFlow13')
    s2 = net.addSwitch('s2',
                       cls=OVSSwitch,
                       inband=True,
                       protocols='OpenFlow13')
    s3 = net.addSwitch('s3',
                       cls=OVSSwitch,
                       inband=True,
                       protocols='OpenFlow13')
    s4 = net.addSwitch('s4',
                       cls=OVSSwitch,
                       inband=True,
                       protocols='OpenFlow13')
    s5 = net.addSwitch('s5',
                       cls=OVSSwitch,
                       inband=True,
                       protocols='OpenFlow13')
    s6 = net.addSwitch('s6',
                       cls=OVSSwitch,
                       inband=True,
                       protocols='OpenFlow13')
    s7 = net.addSwitch('s7',
                       cls=OVSSwitch,
                       inband=True,
                       protocols='OpenFlow13')
    s8 = net.addSwitch('s8',
                       cls=OVSSwitch,
                       inband=True,
                       protocols='OpenFlow13')
    s9 = net.addSwitch('s9',
                       cls=OVSSwitch,
                       inband=True,
                       protocols='OpenFlow13')
    s10 = net.addSwitch('s10',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s11 = net.addSwitch('s11',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s12 = net.addSwitch('s12',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s13 = net.addSwitch('s13',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s14 = net.addSwitch('s14',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s15 = net.addSwitch('s15',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s16 = net.addSwitch('s16',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s17 = net.addSwitch('s17',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s18 = net.addSwitch('s18',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s19 = net.addSwitch('s19',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s20 = net.addSwitch('s20',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s21 = net.addSwitch('s21',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s22 = net.addSwitch('s22',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s23 = net.addSwitch('s23',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s24 = net.addSwitch('s24',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s25 = net.addSwitch('s25',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s26 = net.addSwitch('s26',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s27 = net.addSwitch('s27',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s28 = net.addSwitch('s28',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s29 = net.addSwitch('s29',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s30 = net.addSwitch('s30',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s31 = net.addSwitch('s31',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s32 = net.addSwitch('s32',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s33 = net.addSwitch('s33',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s34 = net.addSwitch('s34',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s35 = net.addSwitch('s35',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s36 = net.addSwitch('s36',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s37 = net.addSwitch('s37',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s38 = net.addSwitch('s38',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s39 = net.addSwitch('s39',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s40 = net.addSwitch('s40',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s41 = net.addSwitch('s41',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s42 = net.addSwitch('s42',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s43 = net.addSwitch('s43',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s44 = net.addSwitch('s44',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s45 = net.addSwitch('s45',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s46 = net.addSwitch('s46',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s47 = net.addSwitch('s47',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s48 = net.addSwitch('s48',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s49 = net.addSwitch('s49',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s50 = net.addSwitch('s50',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s51 = net.addSwitch('s51',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s52 = net.addSwitch('s52',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s53 = net.addSwitch('s53',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s54 = net.addSwitch('s54',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s55 = net.addSwitch('s55',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s56 = net.addSwitch('s56',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')
    s57 = net.addSwitch('s57',
                        cls=OVSSwitch,
                        inband=True,
                        protocols='OpenFlow13')

    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)

    # Add in link options for different experiments
    #linkopts = dict(delay='10ms', bw=1000)

    info('*** Add links\n')
    net.addLink(s1, h1)  #s1 Perth: 5 single switches attached
    net.addLink(s50, h2)
    net.addLink(s22, h3)
    net.addLink(s7, h4)
    net.addLink(s14, h5)
    net.addLink(s30, h6)
    net.addLink(s39, h7)
    net.addLink(s1, s2)
    net.addLink(s1, s3)
    net.addLink(s1, s4)
    net.addLink(s1, s5)
    net.addLink(s1, s6)
    net.addLink(s1, s7)  #s7 Darwin: 0
    net.addLink(s1, s8)  #s8 Adelaide: 11
    net.addLink(s8, s7)
    net.addLink(s8, s9)
    net.addLink(s8, s10)
    net.addLink(s8, s11)
    net.addLink(s8, s12)
    net.addLink(s8, s13)
    net.addLink(s8, s14)
    net.addLink(s8, s15)  #
    net.addLink(s8, s16)
    net.addLink(s8, s17)
    net.addLink(s8, s18)
    net.addLink(s8, s19)
    net.addLink(s8, s20)  #s20 Melbourne: 8
    net.addLink(s20, s21)
    net.addLink(s20, s22)
    net.addLink(s20, s23)
    net.addLink(s20, s24)
    net.addLink(s20, s25)
    net.addLink(s20, s26)
    net.addLink(s20, s27)
    net.addLink(s20, s28)
    net.addLink(s20, s29)  #s29 Hobart: 2
    net.addLink(s20, s30)  #s30 Canberra: 0
    net.addLink(s29, s31)
    net.addLink(s29, s32)
    net.addLink(s30, s33)  #s33 Sydney: 14
    net.addLink(s33, s34)
    net.addLink(s33, s35)
    net.addLink(s33, s36)
    net.addLink(s33, s37)
    net.addLink(s33, s38)
    net.addLink(s33, s39)
    net.addLink(s33, s40)
    net.addLink(s33, s41)
    net.addLink(s33, s42)
    net.addLink(s33, s43)
    net.addLink(s33, s44)
    net.addLink(s33, s45)
    net.addLink(s33, s46)
    net.addLink(s33, s47)
    net.addLink(s33, s48)  #s48 Brisbane: 9
    net.addLink(s48, s49)
    net.addLink(s48, s50)
    net.addLink(s48, s51)
    net.addLink(s48, s52)
    net.addLink(s48, s53)
    net.addLink(s48, s54)
    net.addLink(s48, s55)
    net.addLink(s48, s56)
    net.addLink(s48, s57)

    info('*** Starting network\n')
    net.build()
    info('*** Starting controllers\n')
    c0.start()
    c1.start()
    c2.start()
    c3.start()
    c4.start()
    c5.start()
    c6.start()
    c7.start()

    info('*** Starting switches\n')
    net.get('s1').start([c0, c1])
    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, c4])
    net.get('s8').start([c0])
    net.get('s9').start([c0])
    net.get('s10').start([c0])
    net.get('s11').start([c0])
    net.get('s12').start([c0])
    net.get('s13').start([c0])
    net.get('s14').start([c0, c5])
    net.get('s15').start([c0])
    net.get('s16').start([c0])
    net.get('s17').start([c0])
    net.get('s18').start([c0])
    net.get('s19').start([c0])
    net.get('s20').start([c0])
    net.get('s21').start([c0])
    net.get('s22').start([c0, c3])
    net.get('s23').start([c0])
    net.get('s24').start([c0])
    net.get('s25').start([c0])
    net.get('s26').start([c0])
    net.get('s27').start([c0])
    net.get('s28').start([c0])
    net.get('s29').start([c0])
    net.get('s30').start([c0, c6])
    net.get('s31').start([c0])
    net.get('s32').start([c0])
    net.get('s33').start([c0])
    net.get('s34').start([c0])
    net.get('s35').start([c0])
    net.get('s36').start([c0])
    net.get('s37').start([c0])
    net.get('s38').start([c0])
    net.get('s39').start([c0, c7])
    net.get('s40').start([c0])
    net.get('s41').start([c0])
    net.get('s42').start([c0])
    net.get('s43').start([c0])
    net.get('s44').start([c0])
    net.get('s45').start([c0])
    net.get('s46').start([c0])
    net.get('s47').start([c0])
    net.get('s48').start([c0])
    net.get('s49').start([c0])
    net.get('s50').start([c0, c2])
    net.get('s51').start([c0])
    net.get('s52').start([c0])
    net.get('s53').start([c0])
    net.get('s54').start([c0])
    net.get('s55').start([c0])
    net.get('s56').start([c0])
    net.get('s57').start([c0])

    info('*** Post configure switches and hosts\n')
    s1.cmd('ifconfig s1 10.0.0.21 up')
    s50.cmd('ifconfig s50 10.0.0.60 up')
    s22.cmd('ifconfig s22 10.0.0.42 up')
    s7.cmd('ifconfig s7 10.0.0.27 up')
    s14.cmd('ifconfig s14 10.0.0.34 up')
    s30.cmd('ifconfig s30 10.0.0.40 up')
    s39.cmd('ifconfig s39 10.0.0.49 up')

    s39.cmd('route add 10.0.0.7 dev s39')
    s30.cmd('route add 10.0.0.6 dev s30')
    s14.cmd('route add 10.0.0.5 dev s14')
    s7.cmd('route add 10.0.0.4 dev s7')
    s22.cmd('route add 10.0.0.3 dev s22')
    s50.cmd('route add 10.0.0.2 dev s50')
    s1.cmd('route add 10.0.0.1 dev s1')

    rootdir = '/sys/class/net'
    h1.cmd('ifconfig h1-eth0 mtu 10000')
    h2.cmd('ifconfig h2-eth0 mtu 10000')
    h3.cmd('ifconfig h3-eth0 mtu 10000')
    h4.cmd('ifconfig h4-eth0 mtu 10000')
    h5.cmd('ifconfig h5-eth0 mtu 10000')
    h6.cmd('ifconfig h6-eth0 mtu 10000')
    h7.cmd('ifconfig h7-eth0 mtu 10000')
    for switch in net.switches:
        for subdir, dirs, files in os.walk(rootdir):
            for dir in dirs:
                if (str(switch) == dir.split("-")[0]):
                    switch.cmd('ifconfig ' + dir + ' mtu 10000')

    #time.sleep(30)
    info("Starting Global Controller")

    #h1.cmd('cd ../controllers_used_in_labs/floodlight_global')
    #h1.cmd('java -jar target/floodlight.jar &')
    info("C1 started")
    #h2.cmd('cd ../controllers_used_in_labs/floodlight_global2')
    #h2.cmd('java -jar target/floodlight.jar &')
    info("C2 started")
    #h3.cmd('cd ../controllers_used_in_labs/floodlight_global3')
    #h3.cmd('java -jar target/floodlight.jar &')
    info("C3 started")
    #h4.cmd('cd ../controllers_used_in_labs/floodlight_global4')
    #h4.cmd('java -jar target/floodlight.jar &')
    info("C4 started")
    #h5.cmd('cd ../controllers_used_in_labs/floodlight_global5')
    #h5.cmd('java -jar target/floodlight.jar &')
    info("C5 started")
    #h6.cmd('cd ../controllers_used_in_labs/floodlight_global6')
    #h6.cmd('java -jar target/floodlight.jar &')
    info("C6 started")
    #h7.cmd('cd ../controllers_used_in_labs/floodlight_global7')
    #h7.cmd('java -jar target/floodlight.jar &')
    info("C7 started")

    net.staticArp()
    CLI(net)
    #s50.cmd('ifconfig s50 10.0.0.60 down')
    #s1.cmd('ifconfig s1 10.0.0.21 down')
    net.stop()
Esempio n. 58
0
 def waitStarted( self ):
     "Wait until we've really started"
     info( '(checking: karaf' )
     while True:
         status = self.ucmd( 'karaf status' ).lower()
         if 'running' in status and 'not running' not in status:
             break
         info( '.' )
         self.sanityCheck()
         time.sleep( 1 )
     info( ' ssh-port' )
     waitListening( server=self, port=KarafPort, callback=self.sanityCheck )
     info( ' openflow-port' )
     waitListening( server=self, port=OpenFlowPort,
                    callback=self.sanityCheck )
     info( ' client' )
     while True:
         result = quietRun( '%s -h %s "apps -a"' %
                            ( self.client, self.IP() ), shell=True )
         if 'openflow' in result:
             break
         info( '.' )
         self.sanityCheck()
         time.sleep( 1 )
     info( ' node-status' )
     while True:
         result = quietRun( '%s -h %s "nodes"' %
                            ( self.client, self.IP() ), shell=True )
         nodeStr = 'id=%s, address=%s:%s, state=READY, updated' %\
                   ( self.IP(), self.IP(), CopycatPort )
         if nodeStr in result:
             break
         info( '.' )
         self.sanityCheck()
         time.sleep( 1 )
     info( ')\n' )
Esempio n. 59
0
def topology():

    "Create a network."
    net = Mininet_wifi(controller=None,
                       switch=OVSKernelSwitch,
                       link=wmediumd,
                       wmediumd_mode=interference)
    # net = Mininet_wifi(controller=None, switch=OVSKernelAP)
    c1 = net.addController('c1',
                           controller=RemoteController,
                           ip='127.0.0.1',
                           port=6633)

    info("*** Creating nodes\n")
    cars = []
    for x in range(0, 20):
        cars.append(x)

    cars[0] = net.addCar('car0',
                         wlans=1,
                         range='50',
                         ip='200.0.10.110/8',
                         mac='00:00:00:00:00:01',
                         mode='g',
                         position='2060,975,0')
    cars[1] = net.addCar('car1',
                         wlans=1,
                         range='50',
                         ip='200.0.10.111/8',
                         mac='00:00:00:00:00:02',
                         mode='g',
                         position='2070,975,0')
    cars[2] = net.addCar('car2',
                         wlans=1,
                         range='50',
                         ip='200.0.10.112/8',
                         mac='00:00:00:00:00:03',
                         mode='g',
                         position='2080,975,0')
    cars[3] = net.addCar('car3',
                         wlans=1,
                         range='50',
                         ip='200.0.10.113/8',
                         mac='00:00:00:00:00:04',
                         mode='g',
                         position='2090,975,0')
    cars[4] = net.addCar('car4',
                         wlans=1,
                         range='50',
                         ip='200.0.10.114/8',
                         mac='00:00:00:00:00:05',
                         mode='g',
                         position='2100,975,0')
    cars[5] = net.addCar('car5',
                         wlans=1,
                         range='50',
                         ip='200.0.10.115/8',
                         mac='00:00:00:00:00:06',
                         mode='g',
                         position='2110,975,0')
    cars[6] = net.addCar('car6',
                         wlans=1,
                         range='50',
                         ip='200.0.10.116/8',
                         mac='00:00:00:00:00:07',
                         mode='g',
                         position='2095,975,0')

    cars[7] = net.addCar('car7',
                         wlans=1,
                         range='50',
                         ip='200.0.10.117/8',
                         mac='00:00:00:00:00:08',
                         mode='g',
                         position='1560,975,0')
    cars[8] = net.addCar('car8',
                         wlans=1,
                         range='50',
                         ip='200.0.10.118/8',
                         mac='00:00:00:00:00:09',
                         mode='g',
                         position='1570,975,0')
    cars[9] = net.addCar('car9',
                         wlans=1,
                         range='50',
                         ip='200.0.10.119/8',
                         mac='00:00:00:00:00:10',
                         mode='g',
                         position='1580,975,0')
    cars[10] = net.addCar('car10',
                          wlans=1,
                          range='50',
                          ip='200.0.10.120/8',
                          mac='00:00:00:00:00:11',
                          mode='g',
                          position='1590,975,0')
    cars[11] = net.addCar('car11',
                          wlans=1,
                          range='50',
                          ip='200.0.10.121/8',
                          mac='00:00:00:00:00:12',
                          mode='g',
                          position='1600,975,0')
    cars[12] = net.addCar('car12',
                          wlans=1,
                          range='50',
                          ip='200.0.10.122/8',
                          mac='00:00:00:00:00:13',
                          mode='g',
                          position='1585,975,0')

    cars[13] = net.addCar('car13',
                          wlans=1,
                          range='50',
                          ip='200.0.10.123/8',
                          mac='00:00:00:00:00:14',
                          mode='g',
                          position='1060,975,0')
    cars[14] = net.addCar('car14',
                          wlans=1,
                          range='50',
                          ip='200.0.10.124/8',
                          mac='00:00:00:00:00:15',
                          mode='g',
                          position='1070,975,0')
    cars[15] = net.addCar('car15',
                          wlans=1,
                          range='50',
                          ip='200.0.10.125/8',
                          mac='00:00:00:00:00:16',
                          mode='g',
                          position='1080,975,0')
    cars[16] = net.addCar('car16',
                          wlans=1,
                          range='50',
                          ip='200.0.10.126/8',
                          mac='00:00:00:00:00:17',
                          mode='g',
                          position='1090,975,0')
    cars[17] = net.addCar('car17',
                          wlans=1,
                          range='50',
                          ip='200.0.10.127/8',
                          mac='00:00:00:00:00:18',
                          mode='g',
                          position='1100,975,0')
    cars[18] = net.addCar('car18',
                          wlans=1,
                          range='50',
                          ip='200.0.10.128/8',
                          mac='00:00:00:00:00:19',
                          mode='g',
                          position='1110,975,0')
    cars[19] = net.addCar('car19',
                          wlans=1,
                          range='50',
                          ip='200.0.10.129/8',
                          mac='00:00:00:00:00:20',
                          mode='g',
                          position='1120,975,0')

    rsu1 = net.addAccessPoint('rsu1',
                              ssid='rsu1',
                              dpid='6',
                              mode='g',
                              channel='11',
                              range='250',
                              position='1100,1000,0',
                              protocols='OpenFlow13')
    rsu2 = net.addAccessPoint('rsu2',
                              ssid='rsu2',
                              dpid='7',
                              mode='g',
                              channel='11',
                              range='250',
                              position='1600,1000,0',
                              protocols='OpenFlow13')
    rsu3 = net.addAccessPoint('rsu3',
                              ssid='rsu3',
                              dpid='8',
                              mode='g',
                              channel='11',
                              range='250',
                              position='2100,1000,0',
                              protocols='OpenFlow13')

    sw1 = net.addSwitch('sw1',
                        dpid='9',
                        protocols='OpenFlow13',
                        position='1600,1750,0')
    sw2 = net.addSwitch('sw2',
                        dpid='10',
                        protocols='OpenFlow13',
                        position='1800,1750,0')

    server_s1 = net.addHost('server_s1',
                            ip='200.0.10.2/8',
                            position='1000,1150,0')
    server_s2 = net.addHost('server_s2',
                            ip='200.0.10.2/8',
                            position='1500,1150,0')
    server_s3 = net.addHost('server_s3',
                            ip='200.0.10.2/8',
                            position='2150,1150,0')
    server_e = net.addHost('server_e',
                           ip='200.0.10.3/8',
                           position='2000,1700,0')
    server_e2 = net.addHost('server_e2',
                            ip='200.0.10.4/8',
                            position='2000,1900,0')
    server_g = net.addHost('server_g',
                           ip='200.0.10.5/8',
                           position='2000,2100,0')

    # server_s1.plot(position='1000,1150,0')
    # server_s2.plot(position='1500,1150,0')
    # server_s3.plot(position='2150,1150,0')

    # server_e.plot(position='2000,1700,0')
    # server_e2.plot(position='2000,1900,0')
    # server_g.plot(position='2000,2100,0')

    # sw1.plot(position='1600,1750,0')
    # sw2.plot(position='1800,1750,0')

    info("*** Configuring Propagation Model\n")
    net.propagationModel(model="logDistance", exp=4.5)

    info("*** Configuring wifi nodes\n")
    net.configureWifiNodes()

    info("*** Associating and Creating links\n")
    net.addLink(rsu1, rsu2, 2, 2)
    net.addLink(rsu2, rsu3, 3, 2)
    net.addLink(server_s1, rsu1, 0, 5)
    net.addLink(server_s2, rsu2, 0, 5)
    net.addLink(server_s3, rsu3, 0, 5)
    net.addLink(server_e, sw2, 0, 1)
    net.addLink(server_e2, sw2, 0, 2)
    net.addLink(server_g, sw2, 0, 3)
    link1 = net.addLink(sw1, sw2, 1, 4, cls=TCLink)
    link2 = net.addLink(rsu1, sw1, 3, 2, cls=TCLink)
    link3 = net.addLink(rsu2, sw1, 4, 3, cls=TCLink)
    link4 = net.addLink(rsu3, sw1, 3, 4, cls=TCLink)

    print("*** Configuring links bandwidth")
    link1.intf1.config(bw=93)
    link2.intf1.config(bw=31)
    link3.intf1.config(bw=31)
    link4.intf1.config(bw=31)

    print("*** Ploting Graph")
    net.plotGraph(max_x=2500, max_y=2500)

    print("*** Starting network")
    net.build()
    c1.start()
    rsu1.start([c1])
    rsu2.start([c1])
    rsu3.start([c1])
    sw1.start([c1])
    sw2.start([c1])

    # server_s1.cmd('iptables -I OUTPUT -p icmp --icmp-type destination-unreachable -j DROP')
    # server_s2.cmd('iptables -I OUTPUT -p icmp --icmp-type destination-unreachable -j DROP')
    # server_s3.cmd('iptables -I OUTPUT -p icmp --icmp-type destination-unreachable -j DROP')
    # server_e.cmd('iptables -I OUTPUT -p icmp --icmp-type destination-unreachable -j DROP')
    # server_e2.cmd('iptables -I OUTPUT -p icmp --icmp-type destination-unreachable -j DROP')
    # server_g.cmd('iptables -I OUTPUT -p icmp --icmp-type destination-unreachable -j DROP')

    # os.system('ovs-vsctl --all destroy QoS; ovs-vsctl --all destroy Queue')

    # os.system('ovs-vsctl set-manager ptcp:6632')

    # os.system('curl -X PUT -d \'"tcp:127.0.0.1:6632"\' http://localhost:8080/v1.0/conf/switches/0000000000000006/ovsdb_addr')
    # os.system('curl -X PUT -d \'"tcp:127.0.0.1:6632"\' http://localhost:8080/v1.0/conf/switches/0000000000000007/ovsdb_addr')
    # os.system('curl -X PUT -d \'"tcp:127.0.0.1:6632"\' http://localhost:8080/v1.0/conf/switches/0000000000000008/ovsdb_addr')
    # os.system('curl -X PUT -d \'"tcp:127.0.0.1:6632"\' http://localhost:8080/v1.0/conf/switches/0000000000000009/ovsdb_addr')
    # os.system('curl -X PUT -d \'"tcp:127.0.0.1:6632"\' http://localhost:8080/v1.0/conf/switches/0000000000000010/ovsdb_addr')

    print("*** Shutting ports")
    #time.sleep(3)

    #Filtra trafego nas portas entre switches (evitar L2 loop)
    os.system(
        'curl -X POST -d \'{ "dpid": 6, "cookie": 0, "cookie_mask": 1, "table_id": 1, "priority": 1, "flags": 2, "match":{ "in_port":2}, "actions":[{ "type":"CLEAR_ACTIONS"}]}\' http://localhost:8080/stats/flowentry/add'
    )
    os.system(
        'curl -X POST -d \'{ "dpid": 7, "cookie": 0, "cookie_mask": 1, "table_id": 1, "priority": 1, "flags": 2, "match":{ "in_port":2}, "actions":[{ "type":"CLEAR_ACTIONS"}]}\' http://localhost:8080/stats/flowentry/add'
    )
    os.system(
        'curl -X POST -d \'{ "dpid": 7, "cookie": 0, "cookie_mask": 1, "table_id": 1, "priority": 1, "flags": 2, "match":{ "in_port":3}, "actions":[{ "type":"CLEAR_ACTIONS"}]}\' http://localhost:8080/stats/flowentry/add'
    )
    os.system(
        'curl -X POST -d \'{ "dpid": 8, "cookie": 0, "cookie_mask": 1, "table_id": 1, "priority": 1, "flags": 2, "match":{ "in_port":2}, "actions":[{ "type":"CLEAR_ACTIONS"}]}\' http://localhost:8080/stats/flowentry/add'
    )

    time.sleep(1)

    os.system(
        'ovs-ofctl del-flows sw1 -O Openflow13; ovs-ofctl add-flow sw1 "table=0, priority=0, actions=goto_table:1" -O Openflow13; ovs-ofctl del-flows sw2 -O Openflow13; ovs-ofctl add-flow sw2 "table=0, priority=0, actions=goto_table:1" -O Openflow13; ovs-ofctl add-flow sw2 "table=1, priority=0, actions=CONTROLLER:65535" -O Openflow13; ovs-ofctl add-flow sw2 "table=1, priority=0, in_port=1 actions=4" -O Openflow13; ovs-ofctl add-flow sw2 "table=1, priority=0, in_port=2 actions=4" -O Openflow13; ovs-ofctl add-flow sw2 "table=1, priority=0, in_port=3 actions=4" -O Openflow13; ovs-ofctl del-flows rsu1 -O Openflow13; ovs-ofctl del-flows rsu2 -O Openflow13; ovs-ofctl del-flows rsu3 -O Openflow13; ovs-ofctl add-flow rsu1 "table=0, priority=0, actions=goto_table:1" -O Openflow13; ovs-ofctl add-flow rsu2 "table=0, priority=0, actions=goto_table:1" -O Openflow13; ovs-ofctl add-flow rsu3 "table=0, priority=0, actions=goto_table:1" -O Openflow13; ovs-ofctl add-flow rsu1 "table=1, priority=0, in_port=1, actions=3" -O Openflow13; ovs-ofctl add-flow rsu1 "table=1, priority=0, in_port=3, actions=1" -O Openflow13; ovs-ofctl add-flow rsu2 "table=1, priority=0, in_port=1, actions=4" -O Openflow13; ovs-ofctl add-flow rsu2 "table=1, priority=0, in_port=4, actions=1" -O Openflow13; ovs-ofctl add-flow rsu3 "table=1, priority=0, in_port=1, actions=3" -O Openflow13; ovs-ofctl add-flow rsu3 "table=1, priority=0, in_port=3, actions=1" -O Openflow13; ovs-ofctl add-flow rsu3 "table=1, priority=1, cookie=0x28, in_port=1, nw_dst=200.0.10.2,icmp actions=5" -O Openflow13; ovs-ofctl add-flow rsu3 "table=1, priority=1, cookie=0x28,in_port=5, actions=1" -O Openflow13; ovs-ofctl add-flow rsu3 "table=1, priority=1, cookie=0x28, in_port=1, arp actions=3,5" -O Openflow13; ovs-ofctl add-flow rsu2 "table=1, priority=1, cookie=0x28, in_port=1, nw_dst=200.0.10.2,icmp actions=5" -O Openflow13; ovs-ofctl add-flow rsu2 "table=1, priority=1, cookie=0x28,in_port=5, actions=1" -O Openflow13; ovs-ofctl add-flow rsu2 "table=1, priority=1, cookie=0x28, in_port=1, arp actions=4,5" -O Openflow13; ovs-ofctl add-flow rsu1 "table=1, priority=1, cookie=0x28, in_port=1, nw_dst=200.0.10.2,icmp actions=5" -O Openflow13; ovs-ofctl add-flow rsu1 "table=1, priority=1, cookie=0x28,in_port=5, actions=1" -O Openflow13; ovs-ofctl add-flow rsu1 "table=1, priority=1, cookie=0x28, in_port=1, arp actions=3,5" -O Openflow13; ovs-ofctl add-flow rsu1 "table=1, priority=1, cookie=0x28, in_port=1, nw_dst=200.0.10.2,udp,tp_dst=5002 actions=5" -O Openflow13; ovs-ofctl add-flow rsu2 "table=1, priority=1, cookie=0x28, in_port=1, nw_dst=200.0.10.2,udp,tp_dst=5002 actions=5" -O Openflow13; ovs-ofctl add-flow rsu3 "table=1, priority=1, cookie=0x28, in_port=1, nw_dst=200.0.10.2,udp,tp_dst=5002 actions=5" -O Openflow13; mysql -u root -pwifi -e "delete from redirect;" framework 2> /dev/null'
    )

    time.sleep(1)

    # print( "*** Conectando nas RSUs" )

    # for i in xrange(0,7):
    #     cars[i].cmd('iw dev car%d-wlan0 connect rsu3' %i)

    # for i in xrange(7,13):
    #     cars[i].cmd('iw dev car%d-wlan0 connect rsu2' %i)

    # for i in xrange(13,20):
    #     cars[i].cmd('iw dev car%d-wlan0 connect rsu1' %i)

    # print( "*** Verificando Status das conexoes nas RSUs" )

    # time.sleep(10)

    # for i in xrange(0,20):
    #     cars[i].cmdPrint('iw dev car%d-wlan0 link' %i)

    # time.sleep(1)

    # os.system('./mininet-wifi/scripts/lc_mob.sh > j.txt &')
    # os.system('./mininet-wifi/scripts/local_controllers.sh > k.txt &')

    # os.system('./framework_its_sdn/lc_mob.sh > j.txt &')
    # os.system('./framework_its_sdn/local_controllers.sh > k.txt &')

    # time.sleep(10)

    # server_s1.cmd('tcpdump udp port 5002 -i server_s1-eth0 --direction=in -tttttnnvS --immediate-mode -l > server_s1.txt &')
    # server_s2.cmd('tcpdump udp port 5002 -i server_s2-eth0 --direction=in -tttttnnvS --immediate-mode -l > server_s2.txt &')
    # server_s3.cmd('tcpdump udp port 5002 -i server_s3-eth0 --direction=in -tttttnnvS --immediate-mode -l > server_s3.txt &')
    # server_e.cmd('tcpdump udp port 5003 -i server_e-eth0 --direction=in -tttttnnvS --immediate-mode -l > server_e.txt &')
    # server_e2.cmd('tcpdump udp port 5004 -i server_e2-eth0 --direction=in -tttttnnvS --immediate-mode -l > server_e2.txt &')
    # server_g.cmd('tcpdump udp port 5005 -i server_g-eth0 --direction=in -tttttnnvS --immediate-mode -l > server_g.txt &')

    # # time.sleep(10)

    # print( "*** Iniciando geracao de trafego" )

    # time.sleep(5)

    # for x in xrange(0,20):

    #     cars[x].cmd('tcpdump -i car%d-wlan0 --direction=out -tttttnnvS --immediate-mode -l > car%d.txt &' % (x, x))

    #     print("*** Car[%d] connect to server_s at 1Mbps" %x)
    #     cars[x].cmdPrint("timeout 205 hping3 --udp -p 5002 -i u10200 -d 1470 200.0.10.2 -q &")
    #     cars[x].cmdPrint("ping 200.0.10.2 -i 1 -c 205  > ping%d_ss.txt &" %x)

    #     print("*** Car[%d] connect to server_e at 1Mbps" %x)
    #     cars[x].cmdPrint("timeout 205 hping3 --udp -p 5003 -i u10200 -d 1470 200.0.10.3 -q &")
    #     cars[x].cmdPrint("ping 200.0.10.3 -i 1 -c 205  > ping%d_se.txt &" %x)

    #     print("*** Car[%d] connect to server_e2 at 2Mbps" %x)
    #     cars[x].cmdPrint("timeout 205 hping3 --udp -p 5004 -i u6800 -d 1470 200.0.10.4 -q &")
    #     cars[x].cmdPrint("ping 200.0.10.4 -i 1 -c 205  > ping%d_se2.txt &" %x)

    #     print("*** Car[%d] connect to server_g at 1Mbps" %x)
    #     cars[x].cmdPrint("timeout 205 hping3 --udp -p 5005 -i u10200 -d 1470 200.0.10.5 -q &")
    #     cars[x].cmdPrint("ping 200.0.10.4 -i 1 -c 205  > ping%d_sg.txt &" %x)

    # time.sleep(210)

    # # os.system('fuser -k ./mininet-wifi/scripts/lc_mob.sh')
    # # os.system('fuser -k ./mininet-wifi/scripts/local_controllers.sh')

    # os.system('fuser -k ./framework_its_sdn/lc_mob.sh > j.txt &')
    # os.system('fuser -k ./framework_its_sdn/local_controllers.sh > k.txt &')

    # print( "*** Verificando Status das conexoes nas RSUs" )

    # time.sleep(1)

    # for i in xrange(0,20):
    #     cars[i].cmdPrint('iw dev car%d-wlan0 link' %i)

    # time.sleep(1)

    # for i in xrange(0,20):
    #     cars[i].cmdPrint('iw dev car%d-wlan0 link' %i)

    # os.system('pkill tcpdump')
    # os.system('pkill hping3')
    # os.system('pkill ping')

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

    #os.system('rm *.vanetdata')

    # server_s1.cmd('iptables -D OUTPUT 1')
    # server_s2.cmd('iptables -D OUTPUT 1')
    # server_s3.cmd('iptables -D OUTPUT 1')
    # server_e.cmd('iptables -D OUTPUT 1')
    # server_e2.cmd('iptables -D OUTPUT 1')
    # server_g.cmd('iptables -D OUTPUT 1')

    print("*** Stopping network")
    net.stop()
Esempio n. 60
0
    gw='/'.join([gw,subnet])
    return gw

if __name__ == "__main__":
    setLogLevel('info')
        
    argc = len(sys.argv)
    if argc < 2 or argc > 4:
        raise Exception('usage: sdx_mininet config.json [ path_to_tnode.py [ [ semaphore_name ]')
    config_file = sys.argv[1]
    configfd = open(config_file)
    config = yaml.safe_load(configfd)
    configfd.close()
    
    if argc > 2:
        tnode_file = sys.argv[2]
    else:
        tnode_file = None
            
    topo = SDXTopo((config, ))

    net = Mininet(topo=topo, controller=RemoteController, switch=OVSSwitch)

    net.start()

    CLI(net)

    net.stop()

    info("done\n")