示例#1
0
def build_vndn(vndnTopo, ssid, channel, mode, wmediumd, interference, cluster,
               placement, servers, tunnelType, ctime, nPings, pctTraffic,
               experimentName, nlsrSecurity):
    """Create an ad hoc network from a topology object
       At the end of this function, everything should be connected
       and up..
       adhocTopo:topology object that be builded according to a file of network topology configure;
       isManet: mobile ad hoc network;
       isAdhoc: stationary ad hoc network;
       channel: channel parames;
       ssid: service set identifier;
       wmedimd:param for 802.11 simulation tool;
       interferce:param for 802.11 simulation tool;
       placement:
       servers:
       tunnelType:
       the following paramters are for experiments.
       ctime: specific time that the nentwork covergence;
       nPings: number that perform
    """
    t = datetime.datetime.now()
    cls = Association
    cls.printCon = False

    #<<<<<<< HEAD
    #    vndn = Mininet(host=NdnHost, station=NdnStation, car=NdnCar, controller=Controller, switch=OVSKernelSwitch, ssid=ssid, channel=channel,
    #=======
    vndn = Mininet_wifi(
        host=NdnHost,
        station=NdnStation,
        car=NdnCar,
        controller=Controller,
        switch=OVSKernelSwitch,
        ssid=ssid,
        channel=channel,
        #>>>>>>> 43eaca4746df52b3eec2b5d2a3bd70a1afb8ae2b
        mode=mode,
        enable_wmediumd=wmediumd,
        enable_interference=interference)

    # Possibly we should clean up here and/or validate
    # the topo
    #if vndn.cleanup:
    #     pass

    info('*** Creating ndn based vehicle network\n')
    if not vndn.controllers and vndn.controller:
        # Add a default controller
        info('*** Adding controller\n')
        classes = vndn.controller
        if not isinstance(classes, list):
            classes = [classes]
        for i, cls in enumerate(classes):
            # Allow Controller objects because nobody understands partial()
            if isinstance(cls, Controller):
                vndn.addController(cls)
            else:
                vndn.addController('c%d' % i, cls)
            info('c%d' % i)

    info('\n*** Adding cars and car stations:\n')
    x = 0
    for carName in vndnTopo.hosts():
        min = random.randint(1, 5)
        max = random.randint(5, 15)
        if 'car' in str(carName):
            vndn.addCar(carName,
                        ip='10.0.0.%s/8' % (x + 1),
                        wlans=1,
                        range='100',
                        min_speed=min,
                        max_speed=max,
                        **vndnTopo.nodeInfo(carName))
        else:
            vndn.addHost(carName, **vndnTopo.nodeInfo(carName))
        x = x + 1
        info(carName + ' ')

    info('\n*** Adding Road Sides Units:\n')
    channelValueList = [1, 6, 11]
    i = 0
    for accessPointName in vndnTopo.switches():
        # A bit ugly: add batch parameter if appropriate
        i = i + 1
        #randomly select a channel value
        channelValue = channelValueList[random.randint(
            0,
            len(channelValueList) - 1)]
        params = vndnTopo.nodeInfo(accessPointName)
        cls = params.get('cls', vndn.accessPoint)
        if hasattr(cls, 'batchStartup'):
            params.setdefault('batch', True)
        if 'rsu' in str(accessPointName):
            vndn.addAccessPoint(accessPointName,
                                ssid="RSU1%s" % i,
                                range='50',
                                mode='g',
                                channel='%s' % channelValue,
                                **params)
        else:
            vndn.addSwitch(accessPointName, **params)
            info(accessPointName + ' ')
        info(accessPointName + ' ')

    info('\n*** Configuring propagation model...\n')
    # this code line must be put here
    vndn.propagationModel(model="logDistance", exp=4.5)
    #Only can use this propagation model

    info('\n*** Configuring wifi nodes...\n')
    vndn.configureWifiNodes()

    info('\n*** Adding links......\n')
    for srcName, dstName, params in vndnTopo.links(sort=True, withInfo=True):
        vndn.addLink(**params)
        info('(%s, %s) ' % (srcName, dstName))
    info('\n')

    print "*** Starting network"
    vndn.plotGraph(max_x=500, max_y=500)
    """Number of Roads"""
    vndn.roads(10)
    """Start Mobility"""
    # this code line must be put here
    vndn.startMobility(startTime=0)

    print "start network......"
    vndn.build()
    vndn.controllers[0].start()
    for rsu in vndn.accessPoints:
        rsu.start(vndn.controllers)

    i = 201
    for sw in vndn.carsSW:
        sw.start(vndn.controllers)
        os.system('ip addr add 10.0.0.%s dev %s' % (i, sw))
        i += 1

    i = 1
    j = 2
    k = 1
    for car in vndn.cars:
        car.setIP('192.168.0.%s/24' % k, intf='%s-wlan0' % car)
        car.setIP('192.168.1.%s/24' % i, intf='%s-eth0' % car)
        car.cmd('ip route add 10.0.0.0/8 via 192.168.1.%s' % j)
        i += 2
        j += 2
        k += 1

    i = 1
    j = 2
    for v in vndn.carsSTA:
        v.setIP('192.168.1.%s/24' % j, intf='%s-eth0' % v)
        v.setIP('10.0.0.%s/24' % i, intf='%s-wlan0' %
                v)  #This is for v2v communication in ad hoc mode
        v.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward')
        i += 1
        j += 2

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

    # Load experiment

    if experimentName is not None:
        print("Loading experiment: %s" % experimentName)

        experimentArgs = {
            "isWiFi": True,
            "isVndn": True,
            "isSumoVndn": False,
            "net": vndn,
            "ctime": ctime,
            "nPings": nPings,
            "strategy": Nfd.STRATEGY_BEST_ROUTE,
            "pctTraffic": pctTraffic,
            "nlsrSecurity": nlsrSecurity
        }

        experiment = WifiExperimentManager.create(experimentName,
                                                  experimentArgs)

        if experiment is not None:
            experiment.start()
        else:
            print("ERROR: Experiment '%s' does not exist" % experimentName)
            return
    """Running CLI....."""
    MiniNdnWifiCLI(vndn)

    print "*** Stopping network"
    vndn.stop()

    print('Cleaning up...')
    call(["nfd-stop"])
    call(["sudo", "mn", "--clean"])
    sys.exit(1)
示例#2
0
def topology():

    "Create a network."
    net = Mininet_wifi(controller=Controller, switch=OVSKernelSwitch,
                  enable_wmediumd=True, enable_interference=True)

    info("*** Creating nodes\n")
    cars = []
    for x in range(0, 10):
        cars.append(x)
    for x in range(0, 10):
        min_ = random.randint(1, 4)
        max_ = random.randint(11, 30)
        cars[x] = net.addCar('car%s' % (x + 1), wlans=1,
                             ip='10.0.0.%s/8'% (x + 1), min_speed=min_,
                             max_speed=max_)

    rsu11 = net.addAccessPoint('RSU11', ssid='RSU11', mode='g',
                               channel='1')
    rsu12 = net.addAccessPoint('RSU12', ssid='RSU12', mode='g',
                               channel='6')
    rsu13 = net.addAccessPoint('RSU13', ssid='RSU13', mode='g',
                               channel='11')
    rsu14 = net.addAccessPoint('RSU14', ssid='RSU14', mode='g',
                               channel='11')
    c1 = net.addController('c1', controller=Controller)

    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(rsu11, rsu12)
    net.addLink(rsu11, rsu13)
    net.addLink(rsu11, rsu14)

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

    net.roads(10)

    net.startMobility(time=0)

    info("*** Starting network\n")
    net.build()
    c1.start()
    rsu11.start([c1])
    rsu12.start([c1])
    rsu13.start([c1])
    rsu14.start([c1])

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

    i = 1
    j = 2
    k = 1
    for car in cars:
        car.setIP('192.168.0.%s/24' % k, intf='%s-wlan0' % car)
        car.setIP('192.168.1.%s/24' % i, intf='%s-eth1' % car)
        car.cmd('ip route add 10.0.0.0/8 via 192.168.1.%s' % j)
        i += 2
        j += 2
        k += 1

    i = 1
    j = 2
    for carsta in net.carsSTA:
        carsta.setIP('10.0.0.%s/24' % i, intf='%s-mp0' % carsta)
        carsta.setIP('192.168.1.%s/24' % j, intf='%s-eth2' % carsta)
        # May be confuse, but it allows ping to the name instead of ip addr
        carsta.setIP('10.0.0.%s/24' % i, intf='%s-wlan0' % carsta)
        carsta.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward')
        i += 1
        j += 2

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

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

    info("*** Stopping network\n")
    net.stop()
示例#3
0
def topology():

    "Create a network."
    net = Mininet_wifi(controller=VANET_Controller, link=wmediumd,
                  switch=SD_Switch, station=SD_station, enable_interference=True)

    print ("*** Creating nodes")
    car = []
    stas = []
    mec = []
    channel = ['1','6','11']
    NUM_OF_MECS = 4
    for x in range(0, 5):
        car.append(x)
        stas.append(x)
    for x in range(0, 5):
        min = random.randint(1,10)
        max= random.randint(11,30)
        car[x] = net.addCar('car%s' % (x+1), wlans=1, ip='10.0.0.%s/8' % (x + 1), min_speed=min, max_speed=max,cls=SD_Car)

    c = 0
    for m in range(0, NUM_OF_MECS):
        mec.append(m)
    for m in range(0,NUM_OF_MECS):
        #print "Counter of mecs is %s "%m
        if((m+1) % 3 == 0):
            c=0
        mec[m] = net.addAccessPoint('MEC%s' % (m+1), ssid= 'RSU%s' % (m+1), mode= 'g', channel= channel[c], range=100 ,cls=RSU)
        c += 1

    c1 = net.addController( 'c1', controller=VANET_Controller )


    def SDStorage(datasize):
        start2 = time.time()
        datasize = int(datasize)
        print ("car %s want to store %s bytes" % (0, datasize))
        car[0].store(datasize,Modes.MEC, net)
        end2 = time.time()
        with open('Storage.txt', 'a') as f:
            f.write('%.12f \n' % (end2-start2))
        print ("took : ", end2 - start2)

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

    #net.meshRouting('custom')

    print ("*** Associating and Creating links")
    for m in range(0, NUM_OF_MECS):
        if(m < (NUM_OF_MECS-1)):
            net.addLink(mec[m],mec[m+1])
        else:
            net.addLink(mec[0],mec[m])


    """uncomment to plot graph"""
    net.plotGraph(max_x=700, max_y=700)

    """Number of Roads"""
    net.roads(10)

    """Start Mobility"""
    net.startMobility(time=0)

    print ("*** Starting network")
    net.build()
    c1.start()

    c1.initializeNetworkResources(net)
    print ("Draw 10 roads and place the 4 MEC nodes along them?")
    print ("\n\n\n***************************START*******************************")
    datasize = raw_input("What is the amount of storage you want (in bytes)")
    SDStorage(datasize)
    print ("\n\n\n***************************END*******************************")
    print ("(MEC) info Table after the test")
    net.aps[0].listMecContents(Modes.MEC, net)
    print ("*** Running CLI")
    CLI( net )

    print ("*** Stopping network")
    net.stop()