コード例 #1
0
def topology():

    "Create a network."
    net = Mininet_wifi(controller=Controller,
                       switch=OVSKernelSwitch,
                       accessPoint=OVSKernelAP)

    print("*** Creating nodes")
    sta1 = net.addStation('sta1', mac='00:00:00:00:00:01', ip='10.0.0.1/8')
    ap1 = net.addAccessPoint('ap1',
                             ssid='new-ssid1',
                             mode='g',
                             channel='1',
                             position='15,30,0')
    ap2 = net.addAccessPoint('ap2',
                             ssid='new-ssid1',
                             mode='g',
                             channel='6',
                             position='55,30,0')
    s3 = net.addSwitch('s3')
    h1 = net.addHost('h1', mac='00:00:00:00:00:02', ip='10.0.0.2/8')
    c1 = net.addController('c1', controller=Controller, port=6653)

    net.propagationModel(model="logDistance", exp=4.3)

    print("*** Configuring WiFi Nodes")
    net.configureWifiNodes()

    h1.plot(position='35,90,0')
    s3.plot(position='35,80,0')

    print("*** Creating links")
    net.addLink(ap1, s3)
    net.addLink(ap2, s3)
    net.addLink(h1, s3)

    'plotting graph'
    net.plotGraph(max_x=100, max_y=100)

    net.startMobility(time=0)
    net.mobility(sta1, 'start', time=1, position='10,30,0')
    net.mobility(sta1, 'stop', time=80, position='60,30,0')
    net.stopMobility(time=80)

    print("*** Starting network")
    net.build()
    c1.start()
    ap1.start([c1])
    ap2.start([c1])
    s3.start([c1])

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

    print("*** Stopping network")
    net.stop()
コード例 #2
0
def topology():
    "Create a network."
    net = Mininet_wifi(controller=RemoteController,
                       link=TCLink,
                       switch=OVSKernelSwitch,
                       accessPoint=OVSKernelAP)

    print("*** Creating nodes")
    ap1 = net.addAccessPoint('ap1', ssid="ssid_1", mode="g", channel="5")
    ap2 = net.addAccessPoint('ap2', ssid="ssid_2", mode="g", channel="11")
    sta3 = net.addStation('sta3', ip="192.168.0.100/24", wlans=2)
    h4 = net.addHost('h4', ip="192.168.0.1/24", mac="00:00:00:00:00:04")
    s5 = net.addSwitch('s5')
    c0 = net.addController('c0',
                           controller=RemoteController,
                           ip='127.0.0.1',
                           port=6653)

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

    print("*** Adding Link")
    net.addLink(h4, s5, bw=1000)
    net.addLink(ap1, s5, bw=1000)
    net.addLink(ap2, s5, bw=1000)
    net.addLink(ap1, sta3)
    net.addLink(sta3, ap2)

    print("*** Starting network")
    net.build()
    c0.start()
    s5.start([c0])
    ap1.start([c0])
    ap2.start([c0])

    sta3.cmd("ifconfig sta3-wlan1 192.168.1.100/24 up")
    h4.cmd("ifconfig h4-eth0:0 192.168.1.1/24")

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

    print("*** Stopping network")
    net.stop()
コード例 #3
0
def topology():
    car_type = SD_Car
    op = raw_input("Choose Type of Experiment: (1)v2i \t (2)v2v \nChoice:")
    if(op == "1"):
        v2v = False
        pass
    else:
        v2v = True
        caching = input(
            "What do you prefere to run:\n (1)car-level caching enabled (2)car-level caching disbled \nChoice: ")
        if(caching == "1"):
            car_type = SD_C_Car
        else:
            car_type = SD_Car

    "Create a network."
    net = Mininet_wifi(controller=Vanet_controller, accessPoint=UserAP,
                       switch=SD_Car_Switch, station=SD_station,link=wmediumd,
                       wmediumd_mode=interference)

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

    e1 = net.addAccessPoint('e1', wlans=2, ssid='vanet-ssid,', mac='00:00:00:11:00:01', mode='g', channel='1',
                            passwd='123456789a', encrypt='wpa2', position='3332.62,3253.92,0', cls=eNodeB, inNamespace=True)
    e2 = net.addAccessPoint('e2', wlans=2, ssid='vanet-ssid,', mac='00:00:00:11:00:02', mode='g', channel='1',
                            passwd='123456789a', encrypt='wpa2', position='3279.02,3736.27,0', cls=eNodeB, inNamespace=True)
    e3 = net.addAccessPoint('e3', wlans=2, ssid='vanet-ssid,', mac='00:00:00:11:00:03', mode='g', channel='11',
                            passwd='123456789a', encrypt='wpa2', position='2806.42,3395.22,0', cls=eNodeB, inNamespace=True)
    e4 = net.addAccessPoint('e4', wlans=2, ssid='vanet-ssid,', mac='00:00:00:11:00:04', mode='g', channel='6',
                            passwd='123456789a', encrypt='wpa2', position='2320.82,3565.75,0', cls=eNodeB, inNamespace=True)
    e5 = net.addAccessPoint('e5', wlans=2, ssid='vanet-ssid,', mac='00:00:00:11:00:05', mode='g', channel='6',
                            passwd='123456789a', encrypt='wpa2', position='2887.62,2935.61,0', cls=eNodeB, inNamespace=True)
    e6 = net.addAccessPoint('e6', wlans=2, ssid='vanet-ssid,', mac='00:00:00:11:00:06', mode='g', channel='11',
                            passwd='123456789a', encrypt='wpa2', position='2351.68,3083.40,0', cls=eNodeB, inNamespace=True)

    client = net.addHost('cloud', cls=Cloud_host)
    switch = net.addSwitch('switch', dpid='4000000000000000', cls=SD_Switch)
    c1 = net.addController(
        'c1', controller=Vanet_controller, ip='127.0.0.1', port=6653)
    # "logDistancePropagationLossModel"
    net.propagationModel(exp=2.8)

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

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

    net.addLink(switch, e1)
    net.addLink(client, switch)
    """net.addLink(e1, e2)
    net.addLink(e2, e3)
    net.addLink(e3, e4)
    net.addLink(e4, e5)
    net.addLink(e5, e6)"""
    
    net.addLink(e1, intf = 'e1-wlan2', cls=mesh, ssid='mesh-ssid')
    net.addLink(e2, intf = 'e2-wlan2', cls=mesh, ssid='mesh-ssid')
    net.addLink(e3, intf = 'e3-wlan2', cls=mesh, ssid='mesh-ssid')
    net.addLink(e4, intf = 'e4-wlan2', cls=mesh, ssid='mesh-ssid')
    net.addLink(e5, intf = 'e5-wlan2', cls=mesh, ssid='mesh-ssid')
    net.addLink(e6, intf = 'e6-wlan2', cls=mesh, ssid='mesh-ssid')

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

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

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

    i = 1
    j = 2
    for car in cars:
        car.setIP('192.168.0.%s/24' % i, 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

    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

    # Assigning IPs for Access points wlan interfaces
    IPs = ['90','91','92','93','94','95','96']
    for i in range(0,6):
        net.aps[i].cmd('ifconfig e%s-wlan1 192.168.0.%s'%(i+1,IPs[i]))
        net.aps[i].cmd('ifconfig e%s-mp2 192.168.2.%s'%(i+1,i+1))
        net.aps[i].extIP = '192.168.0.%s'%(IPs[i])

    c1.initializeNetworkResources(net)

    if(v2v):
        raw_input("Press Enter to continue (wait 30sec after t=28)...")
        os.system('clear')
        os.system('ovs-ofctl mod-flows car2SW in_port=2,actions=drop')
        cars[2].cmdPrint('iwconfig car2-wlan0')
        sleep(3)
        cars[6].cmdPrint('iwconfig car6-wlan0')
        print ("****************************************************")
        print ("*** Both car2 and car6 are associated to enodeB5 ***")
        print ("****************************************************")
        sleep(6)
        os.system('clear')
        print ("****************************************************************")
        print ("*** Car6 is so far from enodeB5. Trying to send data by car2 ***")
        print ("****************************************************************")
        sleep(6)
        os.system('clear')
        print ("**************************************")
        print ("*** Trying to send data to car6... ***")
        print ("**************************************")
        cars[2].cmdPrint('ping -c5 10.0.0.7')
        print ("****************************************************************************************************")
        print ("*** Car2: V2V is blocked! Car6 is unreachable! Controller, please let me talk directly with car6 ***")
        print ("****************************************************************************************************")
        sleep(6)
        os.system('clear')
        print ("***********************************************")
        print ("*** controller says: Car6 is now reachable! ***")
        print ("***********************************************")
        os.system('ovs-ofctl mod-flows car2SW in_port=2,actions=1')
        sleep(6)
        os.system('clear')
        cars[2].cmdPrint('ping -c5 10.0.0.7')
        os.system('clear')
        print ("***********************************")
        print ("*** Car2: Requesting Content for car6! ***")
        print ("***********************************")
        sleep(1)
        cars[2].RequestContent(net, 2)
        print ("***********************************")
        print ("*** Car2: Thank you Controller! ***")
        print ("***********************************")
    else:
        print ("***********************************")
        print ("********  V2I experiment **********")
        print ("***********************************")
        raw_input("PressEnter after T=28 ...")

        print ("type>> py car4.RequestContent(net)")

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

    print ("*** Stopping network")
    net.stop()
コード例 #4
0
def topology():
    """
          *ap2--h4.      .s7.
         *         .    .    .
    sta1*           s6--     s9--h10
        *          .    .    .
         *        .      .  .
          *ap3--h5        s8
    """

    "Create a network."
    net = Mininet_wifi(controller=RemoteController, switch=OVSKernelSwitch)

    print("*** Creating nodes")
    sta1 = net.addStation('sta1',
                          wlans=2,
                          ip='10.0.0.10/8',
                          position='51,10,0')
    ap2 = net.addAccessPoint('ap2',
                             mac='00:00:00:00:00:02',
                             equipmentModel='TLWR740N',
                             protocols='OpenFlow10',
                             ssid='ssid_ap2',
                             mode='g',
                             channel='6',
                             position='55,17,0')
    ap3 = net.addAccessPoint('ap3',
                             mac='00:00:00:00:00:03',
                             equipmentModel='TLWR740N',
                             protocols='OpenFlow10',
                             ssid='ssid_ap3',
                             mode='n',
                             channel='1',
                             position='50,11,0')
    h4 = net.addHost('h4', mac='00:00:00:00:00:04', ip='10.0.0.254/8')
    h5 = net.addHost('h5', mac='00:00:00:00:00:05', ip='192.168.0.254/24')
    s6 = net.addSwitch('s6', mac='00:00:00:00:00:06', protocols='OpenFlow10')
    s7 = net.addSwitch('s7', mac='00:00:00:00:00:07', protocols='OpenFlow10')
    s8 = net.addSwitch('s8', mac='00:00:00:00:00:08', protocols='OpenFlow10')
    s9 = net.addSwitch('s9', mac='00:00:00:00:00:09', protocols='OpenFlow10')
    h10 = net.addHost('h10', mac='00:00:00:00:00:10', ip='192.168.1.254/24')
    c11 = net.addController('c11', controller=RemoteController, ip='127.0.0.1')

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

    print("*** Associating and Creating links")
    net.addLink(ap2, sta1)
    net.addLink(ap3, sta1)
    net.addLink(ap2, h4, bw=1000)
    net.addLink(ap3, h5, bw=1000)
    net.addLink(s6, h4, bw=1000)
    net.addLink(s6, h5, bw=1000)
    net.addLink(s6, s7, bw=1000)
    net.addLink(s6, s8, bw=1000)
    net.addLink(s7, s9, bw=1000)
    net.addLink(s8, s9, bw=1000)
    net.addLink(s9, h10, bw=1000)

    h4.cmd('ifconfig h4-eth1 192.168.1.1/24')
    h5.cmd('ifconfig h5-eth1 192.168.1.2/24')

    sta1.cmd('ifconfig sta1-wlan0 10.0.0.10/8')
    sta1.cmd('ifconfig sta1-wlan1 192.168.0.10/24')

    sta1.cmd('ip route add default 10.0.0.254/8 via sta1-wlan0')
    sta1.cmd('ip route add default 192.168.0.254/24 via sta1-wlan1')

    sta1.cmd('ip rule add from 10.0.0.10 table 1')
    sta1.cmd('ip rule add from 192.168.0.10 table 2')

    sta1.cmd('ip route add 10.0.0.0 dev sta1-wlan0 scope link table 1')
    sta1.cmd('ip route add default via 10.0.0.254 dev sta1-wlan0 table 1')

    sta1.cmd('ip route add 192.168.0.0 dev sta1-wlan1 scope link table 2')
    sta1.cmd('ip route add default via 192.168.0.254 dev sta1-wlan1 table 2')

    sta1.cmd(
        'ip route add default scope global nexthop via 10.0.0.254 dev sta1-wlan0'
    )

    print("*** Starting network")
    net.build()
    c11.start()
    s6.start([c11])
    s7.start([c11])
    s8.start([c11])
    s9.start([c11])
    ap2.start([c11])
    ap3.start([c11])

    h10.cmd('ip route add 10.0.0.0/8 via 192.168.1.1')
    h10.cmd('ip route add 192.168.0.0/24 via 192.168.1.2')

    h4.cmd('sysctl -w net.ipv4.ip_forward=1')
    h5.cmd('sysctl -w net.ipv4.ip_forward=1')

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

    print("*** Stopping network")
    net.stop()
コード例 #5
0
def topology():

    taskTime = 20
    ncars = 4

    "Create a network."
    net = Mininet_wifi(controller=Controller, switch=OVSKernelSwitch,
                       accessPoint=OVSKernelAP)

    print("*** Creating nodes")
    cars = []
    stas = []
    for idx in range(0, ncars):
        cars.append(idx)
        stas.append(idx)
    for idx in range(0, ncars):
        cars[idx] = net.addCar('car%s' % idx, wlans=2, ip='10.0.0.%s/8'
                                                          % (idx + 1), range="50,50",
        mac='00:00:00:00:00:0%s' % idx, mode='b', position='%d,%d,0'
                                                           % ((120 - (idx * 20)),
                                                              (100 - (idx * 0))))

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

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

    print("*** Configuring Propagation Model")
    net.propagationModel(model="logDistance", exp=4.1)

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

    print("*** Creating links")
    net.addLink(eNodeB1, switch)
    net.addLink(eNodeB2, switch)
    net.addLink(rsu1, switch)
    net.addLink(switch, client)
    net.addLink(rsu1, cars[0])
    net.addLink(eNodeB2, cars[0])
    net.addLink(eNodeB1, cars[3])

    'Plotting Graph'
    net.plotGraph(max_x=250, max_y=250)

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

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

    i = 1
    j = 2
    for car in cars:
        car.setIP('192.168.0.%s/24' % i, intf='%s-wlan0' % car)
        car.setIP('192.168.1.%s/24' % i, intf='%s-eth2' % car)
        car.cmd('ip route add 10.0.0.0/8 via 192.168.1.%s' % j)
        car.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward')
        i += 2
        j += 2

    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-eth3' % 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

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

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

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

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

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

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

    os.system('rm *.vanetdata')

    #os.system('xterm -hold -title "car0" -e "util/m car0 ping 200.0.10.2" &')
    cars[0].cmdPrint("cvlc -vvv v4l2:///dev/video0 --mtu 1000 --sout \'#transcode{vcodec=mp4v,vb=800,scale=1,\
                acodec=mpga,ab=128,channels=1}: duplicate{dst=display,dst=rtp{sdp=rtsp://200.0.10.100:8080/helmet.sdp}}\' &")
    client.cmdPrint("cvlc rtsp://200.0.10.100:8080/helmet.sdp &")

    os.system('ovs-ofctl mod-flows switch in_port=1,actions=drop')
    os.system('ovs-ofctl mod-flows switch in_port=2,actions=drop')
    os.system('ovs-ofctl mod-flows switch in_port=3,actions=drop')

    time.sleep(2)

    print("applying first rule")
    os.system('ovs-ofctl mod-flows switch in_port=1,actions=output:4')
    os.system('ovs-ofctl mod-flows switch in_port=4,actions=output:1')
    os.system('ovs-ofctl mod-flows switch in_port=2,actions=drop')
    os.system('ovs-ofctl mod-flows switch in_port=3,actions=drop')
    os.system('ovs-ofctl del-flows eNodeB1')
    os.system('ovs-ofctl del-flows eNodeB2')
    os.system('ovs-ofctl del-flows rsu1')

    cars[0].cmd('ip route add 200.0.10.2 via 200.0.10.50')
    client.cmd('ip route add 200.0.10.100 via 200.0.10.150')

    kernel = 0
    var = client.cmd('ifconfig client-eth0 | grep \"bytes\" | awk -F\' \' \'NR==1{print $5}\'')
    if var:
        kernel = 1

    timeout = time.time() + taskTime
    currentTime = time.time()
    i = 0
    while True:
        if time.time() > timeout:
            break
        if time.time() - currentTime >= i:
            recordValues(cars[0], client, kernel)
            i += 0.5

    print("Moving nodes")
    cars[0].setPosition('150,100,0')
    cars[1].setPosition('120,100,0')
    cars[2].setPosition('90,100,0')
    cars[3].setPosition('70,100,0')

    # time.sleep(3)

    print("applying second rule")
    os.system('ovs-ofctl mod-flows switch in_port=1,actions=drop')
    os.system('ovs-ofctl mod-flows switch in_port=2,actions=output:4')
    os.system('ovs-ofctl mod-flows switch in_port=4,actions=output:2,3')
    os.system('ovs-ofctl mod-flows switch in_port=3,actions=output:4')
    os.system('ovs-ofctl del-flows eNodeB1')
    os.system('ovs-ofctl del-flows eNodeB2')
    os.system('ovs-ofctl del-flows rsu1')

    cars[0].cmd('ip route del 200.0.10.2 via 200.0.10.50')
    client.cmd('ip route del 200.0.10.100 via 200.0.10.150')

    timeout = time.time() + taskTime
    currentTime = time.time()
    i = 0
    while True:
        if time.time() > timeout:
            break
        if time.time() - currentTime >= i:
            recordValues(cars[0], client, kernel)
            i += 0.5

    print("Moving nodes")
    cars[0].setPosition('190,100,0')
    cars[1].setPosition('150,100,0')
    cars[2].setPosition('120,100,0')
    cars[3].setPosition('90,100,0')

    # time.sleep(2)

    print("applying third rule")
    os.system('ovs-ofctl mod-flows switch in_port=1,actions=drop')
    os.system('ovs-ofctl mod-flows switch in_port=3,actions=drop')
    os.system('ovs-ofctl mod-flows switch in_port=2,actions=output:4')
    os.system('ovs-ofctl mod-flows switch in_port=4,actions=output:2')
    os.system('ovs-ofctl del-flows eNodeB1')
    os.system('ovs-ofctl del-flows eNodeB2')
    os.system('ovs-ofctl del-flows rsu1')

    timeout = time.time() + taskTime
    currentTime = time.time()
    i = 0
    while True:
        if time.time() > timeout:
            break
        if time.time() - currentTime >= i:
            recordValues(cars[0], client, kernel)
            i += 0.5

    print("*** Generating graph")
    graphic()

    os.system('pkill -f vlc')
    os.system('pkill xterm')

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

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

    print("*** Stopping network")
    net.stop()
コード例 #6
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)
コード例 #7
0
def topology():
    "Create a network."
    net = Mininet_wifi(controller=Controller,
                       switch=OVSKernelSwitch,
                       accessPoint=OVSKernelAP)

    print "*** Creating nodes"
    sta1 = net.addStation('sta1',
                          wlans=2,
                          ip='10.0.0.2/8',
                          max_x=120,
                          max_y=50,
                          min_v=1.4,
                          max_v=1.6)
    h1 = net.addHost('h1', mac='00:00:00:00:00:01', ip='10.0.0.1/8')
    ap1 = net.addAccessPoint('ap1',
                             ssid='ssid_ap1',
                             mode='g',
                             channel=6,
                             position='70,25,0')
    ap2 = net.addAccessPoint('ap2',
                             ssid='ssid_ap2',
                             mode='g',
                             channel=1,
                             position='30,25,0')
    ap3 = net.addAccessPoint('ap3',
                             ssid='ssid_ap3',
                             mode='g',
                             channel=11,
                             position='110,25,0')
    s4 = net.addSwitch('s4', mac='00:00:00:00:00:10')
    c1 = net.addController('c1', controller=Controller)

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

    print "*** Associating and Creating links"
    net.addLink(ap1, s4)
    net.addLink(ap2, s4)
    net.addLink(ap3, s4)
    net.addLink(s4, h1)

    sta1.cmd('modprobe bonding mode=3')
    sta1.cmd('ip link add bond0 type bond')
    sta1.cmd('ip link set bond0 address 02:01:02:03:04:08')
    sta1.cmd('ip link set sta1-wlan0 down')
    sta1.cmd('ip link set sta1-wlan0 address 00:00:00:00:00:11')
    sta1.cmd('ip link set sta1-wlan0 master bond0')
    sta1.cmd('ip link set sta1-wlan1 down')
    sta1.cmd('ip link set sta1-wlan1 address 00:00:00:00:00:12')
    sta1.cmd('ip link set sta1-wlan1 master bond0')
    sta1.cmd('ip addr add 10.0.0.10/8 dev bond0')
    sta1.cmd('ip link set bond0 up')

    'seed'
    net.seed(12)

    'plotting graph'
    net.plotGraph(max_x=140, max_y=140)

    net.startMobility(startTime=0, model='RandomDirection')

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

    sta1.cmd('ip addr del 10.0.0.2/8 dev sta1-wlan0')
    os.system('ovs-ofctl add-flow s4 actions=normal')

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

    print "*** Stopping network"
    net.stop()
コード例 #8
0
def myNetwork():

    net = Mininet_wifi(controller=Controller,
                       accessPoint=OVSKernelAP,
                       link=wmediumd,
                       enable_interference=False,
                       configure4addr=True,
                       disableAutoAssociation=True)

    info('+Add controller+\n')
    c0 = net.addController('c0',
                           controller=Controller,
                           ip='127.0.0.1',
                           port=6633)

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

    info('+Add AP+\n')
    ap1 = net.addAccessPoint('ap1',
                             _4addr="ap",
                             ssid="AP1-ssid1",
                             mode="g",
                             channel="1",
                             position='20,20,0')
    ap2 = net.addAccessPoint('ap2',
                             _4addr="client",
                             ssid="AP2-ssid2",
                             mode="g",
                             channel="1",
                             position='50,70,0')

    info('+Add station+\n')
    sta1 = net.addStation('sta1', ip="192.168.0.1/24", position='21,22,0')
    sta2 = net.addStation('sta2', ip="192.168.0.2/24", position='24,28,0')
    sta3 = net.addStation('sta3', ip="192.168.0.3/24", position='51,72,0')
    sta4 = net.addStation('sta4', ip="192.168.0.4/24", position='52,74,0')

    info('+Config propagation model & wifi nodes+\n')
    net.propagationModel(model="logDistance", exp=3.5)
    net.configureWifiNodes()

    info('+Add hosts+\n')
    h7 = net.addHost('h7', cls=Host, ip='10.0.0.7', defaultRoute=None)
    h15 = net.addHost('h15', cls=Host, ip='10.0.0.15', defaultRoute=None)
    h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', 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)
    h16 = net.addHost('h16', cls=Host, ip='10.0.0.16', defaultRoute=None)
    h13 = net.addHost('h13', cls=Host, ip='10.0.0.13', defaultRoute=None)
    h10 = net.addHost('h10', cls=Host, ip='10.0.0.10', defaultRoute=None)
    h14 = net.addHost('h14', cls=Host, ip='10.0.0.14', defaultRoute=None)
    h8 = net.addHost('h8', cls=Host, ip='10.0.0.8', defaultRoute=None)
    h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)
    h6 = net.addHost('h6', cls=Host, ip='10.0.0.6', 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)
    h5 = net.addHost('h5', cls=Host, ip='10.0.0.5', defaultRoute=None)
    h12 = net.addHost('h12', cls=Host, ip='10.0.0.12', defaultRoute=None)

    info('+Add links\n')
    net.addLink(ap1, ap2, link='4addr')
    net.addLink(sta1, ap1)
    net.addLink(sta2, ap1)
    net.addLink(sta3, ap2)
    net.addLink(sta4, ap2)
    net.addLink(s1, h3)
    net.addLink(h1, s1)
    net.addLink(h2, s1)
    net.addLink(s1, s2)
    net.addLink(s2, h4)
    net.addLink(s2, s3)
    net.addLink(s3, s4)
    net.addLink(s3, s5)
    net.addLink(s3, s6)
    net.addLink(s5, h5)
    net.addLink(s4, h7)
    net.addLink(s4, h6)
    net.addLink(s3, s7)
    net.addLink(s7, h8)
    net.addLink(s6, h10)
    net.addLink(s6, h9)
    net.addLink(s5, s8)
    net.addLink(s8, h11)
    net.addLink(s8, h12)
    net.addLink(s6, s9)
    net.addLink(s9, h13)
    net.addLink(s9, h14)
    net.addLink(s4, s10)
    net.addLink(s10, h15)
    net.addLink(s10, h16)

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

    info('+Starting network+\n')
    net.addNAT().configDefault()
    net.build()

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

    info('+Starting switches+\n')
    net.get('s9').start([c0])
    net.get('s3').start([c0])
    net.get('s4').start([c0])
    net.get('s10').start([c0])
    net.get('s1').start([c0])
    net.get('s7').start([c0])
    net.get('s5').start([c0])
    net.get('s6').start([c0])
    net.get('s8').start([c0])
    net.get('s2').start([c0])

    ap1.start([c0])
    ap2.start([c0])
    ap3.start([c0])

    info('+Post configure switches and hosts+\n')
    CLI_wifi(net)
    net.stop()
コード例 #9
0
def topology():

    ncars = 3

    "Create a network."
    net = Mininet_wifi(controller=None,
                       autoStaticArp=True,
                       switch=OVSKernelSwitch,
                       accessPoint=OVSKernelAP)
    c1 = net.addController('c1',
                           controller=RemoteController,
                           ip='127.0.0.1',
                           port=6633)

    print("*** Creating nodes")
    cars = []
    stas = []
    for idx in range(0, ncars):
        cars.append(idx)
        stas.append(idx)

    #for idx in range(0, ncars):
    cars[0] = net.addCar('car0',
                         wlans=1,
                         range='30',
                         ip='200.0.10.100/8',
                         mac='00:00:00:00:00:01',
                         mode='b',
                         position='40,125,0')
    cars[1] = net.addCar('car1',
                         wlans=1,
                         range='30',
                         ip='200.0.10.150/8',
                         mac='00:00:00:00:00:02',
                         mode='b',
                         position='50,125,0')
    cars[2] = net.addCar('car2',
                         wlans=1,
                         range='30',
                         ip='200.0.10.200/8',
                         mac='00:00:00:00:00:03',
                         mode='b',
                         position='60,125,0')

    rsu1 = net.addAccessPoint('rsu1',
                              ssid='rsu1',
                              dpid='0000000000000006',
                              mode='g',
                              channel='11',
                              range='40',
                              position='50,140,0',
                              protocols='OpenFlow13')
    rsu2 = net.addAccessPoint('rsu2',
                              ssid='rsu2',
                              dpid='0000000000000007',
                              mode='g',
                              channel='11',
                              range='40',
                              position='130,140,0',
                              protocols='OpenFlow13')
    rsu3 = net.addAccessPoint('rsu3',
                              ssid='rsu3',
                              dpid='0000000000000008',
                              mode='g',
                              channel='11',
                              range='40',
                              position='210,140,0',
                              protocols='OpenFlow13')

    sw1 = net.addSwitch('sw1', dpid='0000000000000009', protocols='OpenFlow13')
    sw2 = net.addSwitch('sw2', dpid='0000000000000010', protocols='OpenFlow13')

    server_s = net.addHost('server_s', ip='200.0.10.2/8')
    server_e = net.addHost('server_e', ip='200.0.10.3/8')
    server_e2 = net.addHost('server_e2', ip='200.0.10.4/8')

    server_s.plot(position='210,190,0')
    server_e.plot(position='210,220,0')
    server_e2.plot(position='210,240,0')

    sw1.plot(position='125,218,0')
    sw2.plot(position='170,218,0')

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

    net.useIFB()

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

    print("*** Creating links")
    net.addLink(rsu1, rsu2)
    net.addLink(rsu2, rsu3)
    net.addLink(server_s, sw2)
    net.addLink(server_e, sw2)
    net.addLink(server_e2, sw2)
    link1 = net.addLink(sw1, sw2, cls=TCLink)
    link2 = net.addLink(rsu1, sw1, cls=TCLink)
    link3 = net.addLink(rsu2, sw1, cls=TCLink)
    link4 = net.addLink(rsu3, sw1, cls=TCLink)

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

    'Plotting Graph'
    net.plotGraph(max_x=250, max_y=250)

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

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

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

    os.system('ovs-ofctl mod-port rsu1 rsu1-eth3 down -O Openflow13')
    os.system('ovs-ofctl mod-port rsu2 rsu2-eth3 down -O Openflow13')
    os.system('ovs-ofctl mod-port rsu2 rsu2-eth4 down -O Openflow13')
    os.system('ovs-ofctl mod-port rsu3 rsu3-eth3 down -O Openflow13')

    # time.sleep(1)
    # makeTerm(cars[0], cmd="bash -c 'ping 200.0.10.2;'")

    print("*** Moving nodes")

    taskTime = 40

    os.system('rm *.vanetdata')

    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("*** Starting servers")
    server_s.cmdPrint("iperf -s -u -i 1 -p 5002 > result_safety.datares &")
    server_e.cmdPrint("iperf -s -u -i 1 -p 5003 > result_enter.datares &")
    server_e2.cmdPrint("iperf -s -u -i 1 -p 5003 > result_enter2.datares &")
    time.sleep(2)

    print("*** Car[0] connection 7.5Mbps")
    cars[0].cmdPrint("iperf -c 200.0.10.2 -p 5002 -u -b 1.5M -t130 &")
    cars[1].cmdPrint("iperf -c 200.0.10.3 -p 5003 -u -b 1.5M -t100 &")
    cars[2].cmdPrint("iperf -c 200.0.10.4 -p 5003 -u -b 1.5M -t100 &")

    timeout = time.time() + taskTime
    currentTime = time.time()
    i = 0
    while True:
        if time.time() > timeout:
            break
        if time.time() - currentTime >= i:
            recordValues(cars[0], server_s)
            i += 0.5

    cars[0].setPosition('115,125,0')
    cars[1].setPosition('125,125,0')
    cars[2].setPosition('135,125,0')

    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 add-flow sw1 "table=1, priority=0, actions=CONTROLLER:65535" -O Openflow13'
    )

    timeout = time.time() + taskTime
    currentTime = time.time()
    i = 0
    while True:
        if time.time() > timeout:
            break
        if time.time() - currentTime >= i:
            recordValues(cars[0], server_s)
            i += 0.5

    cars[0].setPosition('200,125,0')
    cars[1].setPosition('210,125,0')
    cars[2].setPosition('220,125,0')

    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 add-flow sw1 "table=1, priority=0, actions=CONTROLLER:65535" -O Openflow13'
    )

    timeout = time.time() + taskTime
    currentTime = time.time()
    i = 0
    while True:
        if time.time() > timeout:
            break
        if time.time() - currentTime >= i:
            recordValues(cars[0], server_s)
            i += 0.5

    # print("*** Aplica QoS")
    # os.system('curl -X POST -d \'{"port_name": "rsu2-eth2", "type": "linux-htb", "max_rate": "8300000", "queues": [{"max_rate": "1000000"}, {"min_rate": "7500000"}]}\' http://localhost:8080/qos/queue/0000000000000007')
    # os.system('curl -X POST -d \'{"port_name": "rsu1-eth2", "type": "linux-htb", "max_rate": "8300000", "queues": [{"max_rate": "1000000"}, {"min_rate": "7500000"}]}\' http://localhost:8080/qos/queue/0000000000000006')
    # os.system('curl -X POST -d \'{"match": {"nw_dst": "200.0.10.2", "nw_proto": "UDP", "tp_dst": "5002"}, "actions":{"queue": "1"}}\' http://localhost:8080/qos/rules/0000000000000007')
    # os.system('curl -X POST -d \'{"match": {"nw_dst": "200.0.10.2", "nw_proto": "UDP", "tp_dst": "5002"}, "actions":{"queue": "1"}}\' http://localhost:8080/qos/rules/0000000000000006')

    # timeout = time.time() + taskTime
    # currentTime = time.time()
    # i = 0
    # while True:
    #     if time.time() > timeout:
    #         break
    #     if time.time() - currentTime >= i:
    #         recordValues(cars[0], server_s)
    #         i += 0.5

    print("*** Generating graph")
    graphic()

    # os.system('pkill -f vlc')
    os.system('pkill xterm')

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

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

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