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

    "Create a network."
    net = Mininet_wifi(controller=Controller,
                       roads=10,
                       link=wmediumd,
                       wmediumd_mode=interference)

    info("*** Creating nodes\n")
    for id in range(0, 10):
        min_ = randint(1, 4)
        max_ = randint(11, 30)
        net.addCar('car%s' % (id + 1), wlans=2, 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')

    info("*** Configuring Propagation Model\n")
    net.setPropagationModel(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)
    for car in net.cars:
        net.addLink(car,
                    intf='%s-wlan1' % car,
                    cls=mesh,
                    ssid='mesh-ssid',
                    channel=5)

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

    net.startMobility(time=0)

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

    for car in net.cars:
        car.setIP('192.168.0.%s/24' % (int(net.cars.index(car)) + 1),
                  intf='%s-wlan0' % car)
        car.setIP('192.168.1.%s/24' % (int(net.cars.index(car)) + 1),
                  intf='%s-mp1' % car)

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

    info("*** Stopping network\n")
    net.stop()
コード例 #2
0
def topology():

    ncars = 15

    "Create a network."
    #net = Mininet_wifi(controller=None, autoStaticArp=True, switch=OVSKernelSwitch)
    net = Mininet_wifi(controller=None,
                       switch=OVSKernelSwitch,
                       link=wmediumd,
                       wmediumd_mode=interference)
    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='50',
                         ip='200.0.10.110/8',
                         mac='00:00:00:00:00:01',
                         position='2107,250,0')
    cars[1] = net.addCar('car1',
                         wlans=1,
                         range='50',
                         ip='200.0.10.111/8',
                         mac='00:00:00:00:00:02',
                         position='2107,247,0')
    cars[2] = net.addCar('car2',
                         wlans=1,
                         range='50',
                         ip='200.0.10.112/8',
                         mac='00:00:00:00:00:03',
                         position='2104,250,0')

    cars[3] = net.addCar('car3',
                         wlans=1,
                         range='50',
                         ip='200.0.10.113/8',
                         mac='00:00:00:00:00:04',
                         position='1607,247,0')
    cars[4] = net.addCar('car4',
                         wlans=1,
                         range='50',
                         ip='200.0.10.114/8',
                         mac='00:00:00:00:00:05',
                         position='1604,250,0')

    cars[5] = net.addCar('car5',
                         wlans=1,
                         range='50',
                         ip='200.0.10.115/8',
                         mac='00:00:00:00:00:06',
                         position='1107,250,0')
    cars[6] = net.addCar('car6',
                         wlans=1,
                         range='50',
                         ip='200.0.10.116/8',
                         mac='00:00:00:00:00:07',
                         position='1104,247,0')

    cars[7] = net.addCar('car7',
                         wlans=1,
                         range='50',
                         ip='200.0.10.117/8',
                         mac='00:00:00:00:00:08',
                         position='150,250,0')
    cars[8] = net.addCar('car8',
                         wlans=1,
                         range='50',
                         ip='200.0.10.118/8',
                         mac='00:00:00:00:00:09',
                         position='200,250,0')
    cars[9] = net.addCar('car9',
                         wlans=1,
                         range='50',
                         ip='200.0.10.119/8',
                         mac='00:00:00:00:00:10',
                         position='250,250,0')
    cars[10] = net.addCar('car10',
                          wlans=1,
                          range='50',
                          ip='200.0.10.120/8',
                          mac='00:00:00:00:00:11',
                          position='300,250,0')
    cars[11] = net.addCar('car11',
                          wlans=1,
                          range='50',
                          ip='200.0.10.121/8',
                          mac='00:00:00:00:00:12',
                          position='350,250,0')
    cars[12] = net.addCar('car12',
                          wlans=1,
                          range='50',
                          ip='200.0.10.122/8',
                          mac='00:00:00:00:00:13',
                          position='400,243,0')
    cars[13] = net.addCar('car13',
                          wlans=1,
                          range='50',
                          ip='200.0.10.123/8',
                          mac='00:00:00:00:00:14',
                          position='450,243,0')
    cars[14] = net.addCar('car14',
                          wlans=1,
                          range='50',
                          ip='200.0.10.124/8',
                          mac='00:00:00:00:00:15',
                          position='500,243,0')

    rsu1 = net.addAccessPoint('rsu1',
                              ssid='rsu1',
                              dpid='0000000000000005',
                              mode='g',
                              channel='11',
                              range=250,
                              position='1100,250,0',
                              protocols='OpenFlow13')
    rsu2 = net.addAccessPoint('rsu2',
                              ssid='rsu2',
                              dpid='0000000000000006',
                              mode='g',
                              channel='11',
                              range=250,
                              position='1600,250,0',
                              protocols='OpenFlow13')
    rsu3 = net.addAccessPoint('rsu3',
                              ssid='rsu3',
                              dpid='0000000000000007',
                              mode='g',
                              channel='11',
                              range=250,
                              position='2100,250,0',
                              protocols='OpenFlow13')

    sw1 = net.addSwitch('sw1',
                        dpid='0000000000000008',
                        protocols='OpenFlow13',
                        position='125,218,0')
    sw2 = net.addSwitch('sw2',
                        dpid='0000000000000009',
                        protocols='OpenFlow13',
                        position='170,218,0')

    server_s1 = net.addHost('server_s1', ip='200.0.10.2/8')
    server_s2 = net.addHost('server_s2', ip='200.0.10.2/8')
    server_s3 = net.addHost('server_s3', 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_g = net.addHost('server_g', ip='200.0.10.5/8')

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

    # net.useIFB()

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

    print("*** Creating links")
    net.addLink(server_s1, rsu1, 0, 5)
    net.addLink(server_s2, rsu2, 0, 5)
    net.addLink(server_s3, rsu3, 0, 5)
    # net.addLink(rsu1, sw1, 3, 4)
    # net.addLink(rsu2, sw1, 4, 3)
    # net.addLink(rsu3, sw1, 3, 2)
    net.addLink(server_g, sw2)
    net.addLink(server_e, sw2)
    net.addLink(server_e2, sw2)
    link1 = net.addLink(sw1, sw2, 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=17 )
    link2.intf1.config(bw=5.5)
    link3.intf1.config(bw=5.5)
    link4.intf1.config(bw=5.5)

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

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

    os.system(
        'ovs-vsctl set bridge rsu1 other-config:datapath-id=0000000000000005')
    os.system(
        'ovs-vsctl set bridge rsu2 other-config:datapath-id=0000000000000006')
    os.system(
        'ovs-vsctl set bridge rsu3 other-config:datapath-id=0000000000000007')
    os.system(
        'ovs-vsctl set bridge sw1 other-config:datapath-id=0000000000000008')
    os.system(
        'ovs-vsctl set bridge sw2 other-config:datapath-id=0000000000000009')

    time.sleep(2)

    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/0000000000000005/ovsdb_addr'
    )
    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'
    )

    # print("*** Starting servers")
    # server_s.cmdPrint("iperf -s -u -i 1 -p 5002 > /dev/null &")
    # server_e.cmdPrint("iperf -s -u -i 1 -p 5003 > /dev/null &")
    # server_e2.cmdPrint("iperf -s -u -i 1 -p 5004 > /dev/null &")
    time.sleep(2)

    # cars[0].cmd('ulimit -u 500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000')
    # cars[1].cmd('ulimit -u 500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000')
    # cars[2].cmd('ulimit -u 500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000')

    # time.sleep(1)

    # timeout = 120

    # server_s1.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'
    )

    # time.sleep(1)

    # print("*** Car[0] connection 7.5Mbps")
    # cars[0].cmdPrint("timeout 205 hping3 --udp -p 5002 -i u1400 -d 1470 200.0.10.2 -q &")
    # time.sleep(2)

    # cars[0].cmd('tcpdump udp port 5002 -i car0-wlan0 --direction=out -tttttnnvS > car.txt &')
    # server_s.cmd('tcpdump udp port 5002 -i server_s-eth0 --direction=in -tttttnnvS > server.txt &')
    # # cars[0].cmdPrint("ping 200.0.10.2 -i 1 -c %s  > ping.txt &", % timeout)
    # cars[0].cmdPrint("ping 200.0.10.2 -i 1 -c 205  > ping.txt &")
    # # makeTerm(cars[0], cmd="ping 200.0.10.2 -i 1")

    # print("*** Deu certo!")

    # time.sleep(105)

    # print("*** Car[1] e car[2] iniciam em paralelo - 7.5Mbps cada")
    # cars[1].cmdPrint("timeout 205 hping3 --udp -p 5003 -i u1400 -d 1470 200.0.10.3 -q &")
    # cars[2].cmdPrint("timeout 205 hping3 --udp -p 5004 -i u1400 -d 1470 200.0.10.4 -q &")

    # time.sleep(100)

    # print("*** Aplica QoS")
    # os.system('curl -X POST -d \'{"port_name": "rsu2-eth2", "type": "linux-htb", "max_rate": "9000000", "queues": [{"max_rate": "1000000"}, {"min_rate": "6000000"}]}\' http://localhost:8080/qos/queue/0000000000000007')
    # os.system('curl -X POST -d \'{"port_name": "rsu1-eth2", "type": "linux-htb", "max_rate": "9000000", "queues": [{"max_rate": "1000000"}, {"min_rate": "6000000"}]}\' 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')
    # os.system('curl -X POST -d \'{"match": {"nw_proto": "ICMP"}, "actions":{"queue": "1"}}\' http://localhost:8080/qos/rules/0000000000000006')
    # os.system('curl -X POST -d \'{"match": {"nw_proto": "ICMP"}, "actions":{"queue": "1"}}\' http://localhost:8080/qos/rules/0000000000000007')

    print("*** Aplica QoS")
    os.system(
        'curl -X POST -d \'{"port_name": "rsu1-eth3", "type": "linux-htb", "max_rate": "6000000", "queues": [{"max_rate": "500000"}, {"min_rate": "0"}, {"min_rate": "500000"}, {"min_rate": "1000000"}]}\' http://localhost:8080/qos/queue/0000000000000005'
    )
    os.system(
        'curl -X POST -d \'{"port_name": "rsu2-eth4", "type": "linux-htb", "max_rate": "6000000", "queues": [{"max_rate": "500000"}, {"min_rate": "0"}, {"min_rate": "500000"}, {"min_rate": "1000000"}]}\' http://localhost:8080/qos/queue/0000000000000006'
    )
    os.system(
        'curl -X POST -d \'{"port_name": "rsu3-eth3", "type": "linux-htb", "max_rate": "6000000", "queues": [{"max_rate": "500000"}, {"min_rate": "0"}, {"min_rate": "500000"}, {"min_rate": "1000000"}]}\' http://localhost:8080/qos/queue/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/0000000000000005'
    )
    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'
    )
    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_proto": "ICMP", "nw_dst": "200.0.10.2"}, "actions":{"queue": "1"}}\' http://localhost:8080/qos/rules/0000000000000005'
    )
    os.system(
        'curl -X POST -d \'{"match": {"nw_proto": "ICMP", "nw_dst": "200.0.10.2"}, "actions":{"queue": "1"}}\' http://localhost:8080/qos/rules/0000000000000006'
    )
    os.system(
        'curl -X POST -d \'{"match": {"nw_proto": "ICMP", "nw_dst": "200.0.10.2"}, "actions":{"queue": "1"}}\' http://localhost:8080/qos/rules/0000000000000007'
    )

    os.system(
        'curl -X POST -d \'{"match": {"nw_dst": "200.0.10.3", "nw_proto": "UDP", "tp_dst": "5003"}, "actions":{"queue": "2"}}\' http://localhost:8080/qos/rules/0000000000000005'
    )
    os.system(
        'curl -X POST -d \'{"match": {"nw_dst": "200.0.10.3", "nw_proto": "UDP", "tp_dst": "5003"}, "actions":{"queue": "2"}}\' http://localhost:8080/qos/rules/0000000000000006'
    )
    os.system(
        'curl -X POST -d \'{"match": {"nw_dst": "200.0.10.3", "nw_proto": "UDP", "tp_dst": "5003"}, "actions":{"queue": "2"}}\' http://localhost:8080/qos/rules/0000000000000007'
    )
    os.system(
        'curl -X POST -d \'{"match": {"nw_proto": "ICMP", "nw_dst": "200.0.10.3"}, "actions":{"queue": "2"}}\' http://localhost:8080/qos/rules/0000000000000005'
    )
    os.system(
        'curl -X POST -d \'{"match": {"nw_proto": "ICMP", "nw_dst": "200.0.10.3"}, "actions":{"queue": "2"}}\' http://localhost:8080/qos/rules/0000000000000006'
    )
    os.system(
        'curl -X POST -d \'{"match": {"nw_proto": "ICMP", "nw_dst": "200.0.10.3"}, "actions":{"queue": "2"}}\' http://localhost:8080/qos/rules/0000000000000007'
    )

    os.system(
        'curl -X POST -d \'{"match": {"nw_dst": "200.0.10.4", "nw_proto": "UDP", "tp_dst": "5004"}, "actions":{"queue": "3"}}\' http://localhost:8080/qos/rules/0000000000000005'
    )
    os.system(
        'curl -X POST -d \'{"match": {"nw_dst": "200.0.10.4", "nw_proto": "UDP", "tp_dst": "5004"}, "actions":{"queue": "3"}}\' http://localhost:8080/qos/rules/0000000000000006'
    )
    os.system(
        'curl -X POST -d \'{"match": {"nw_dst": "200.0.10.4", "nw_proto": "UDP", "tp_dst": "5004"}, "actions":{"queue": "3"}}\' http://localhost:8080/qos/rules/0000000000000007'
    )
    os.system(
        'curl -X POST -d \'{"match": {"nw_proto": "ICMP", "nw_dst": "200.0.10.4"}, "actions":{"queue": "3"}}\' http://localhost:8080/qos/rules/0000000000000005'
    )
    os.system(
        'curl -X POST -d \'{"match": {"nw_proto": "ICMP", "nw_dst": "200.0.10.4"}, "actions":{"queue": "3"}}\' http://localhost:8080/qos/rules/0000000000000006'
    )
    os.system(
        'curl -X POST -d \'{"match": {"nw_proto": "ICMP", "nw_dst": "200.0.10.4"}, "actions":{"queue": "3"}}\' http://localhost:8080/qos/rules/0000000000000007'
    )

    # os.system('curl -X POST -d \'{"type": "linux-htb", "max_rate": "9000000", "queues": [{"max_rate": "1000000"}, {"min_rate": "6000000"}]}\' http://localhost:8080/qos/queue/0000000000000008')
    # os.system('curl -X POST -d \'{"type": "linux-htb", "max_rate": "9000000", "queues": [{"max_rate": "1000000"}, {"min_rate": "6000000"}]}\' http://localhost:8080/qos/queue/0000000000000009')
    # 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/0000000000000008')
    # 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/0000000000000009')
    # os.system('curl -X POST -d \'{"match": {"nw_proto": "ICMP"}, "actions":{"queue": "1"}}\' http://localhost:8080/qos/rules/0000000000000008')
    # os.system('curl -X POST -d \'{"match": {"nw_proto": "ICMP"}, "actions":{"queue": "1"}}\' http://localhost:8080/qos/rules/0000000000000009')

    # cars[0].cmdPrint("timeout 101 hping3 --udp -p 5002 -i u1300 -d 1470 200.0.10.2 -q &")
    # cars[0].cmdPrint("ping 200.0.10.2 -i 1 -c 100  >> ping.txt &")

    # time.sleep(100)

    # server_s.cmd('pkill tcpdump')
    # cars[0].cmd('pkill tcpdump')

    # cars[0].cmd('pkill hping3')
    # # cars[0].cmd('pkill ping')
    # cars[1].cmd('pkill hping3')
    # cars[2].cmd('pkill hping3')
    # server_s.cmd('iptables -D OUTPUT 1')
    # server_e.cmd('iptables -D OUTPUT 1')
    # server_e2.cmd('iptables -D OUTPUT 1')

    # os.system('cat server.txt | grep IP | sed \'s/00:0/ 00:0/\' | tr -s \' \' | cut -d\' \' -f2,9,18 | cut -d\')\' -f1 | sed \'s/,//\'|cut -d\':\' -f2,3 | grep : > servert.txt; cat servert.txt | cut -d\'.\' -f2 > z.txt; cat servert.txt | cut -d\':\' -f1 | sed \'s/00/0*60/\' | sed \'s/01/1*60/\' | sed \'s/02/2*60/\' | sed \'s/03/3*60/\' | sed \'s/04/4*60/\'| sed \'s/05/5*60/\'| bc > x.txt; cat servert.txt | cut -d\':\' -f2 | cut -d\'.\' -f1 > y.txt; paste x.txt y.txt | expand | tr -s \' \' | tr \' \' \'+\' | bc > w.txt; cat z.txt | tr \' \' \'x\' >j.txt; paste w.txt j.txt | expand | tr -s \' \' | tr \' \' \'.\' | tr \'x\' \' \' > servertf.txt')
    # os.system('cat car.txt | grep IP | sed \'s/00:0/ 00:0/\' | tr -s \' \' | cut -d\' \' -f2,9,18 | cut -d\')\' -f1 | sed \'s/,//\'|cut -d\':\' -f2,3 | grep : > cart.txt; cat cart.txt | cut -d\'.\' -f2 > z.txt; cat cart.txt | cut -d\':\' -f1 | sed \'s/00/0*60/\' | sed \'s/01/1*60/\' | sed \'s/02/2*60/\' | sed \'s/03/3*60/\' | sed \'s/04/4*60/\'| sed \'s/05/5*60/\'| bc > x.txt; cat cart.txt | cut -d\':\' -f2 | cut -d\'.\' -f1 > y.txt; paste x.txt y.txt | expand | tr -s \' \' | tr \' \' \'+\' | bc > w.txt; cat z.txt | tr \' \' \'x\' >j.txt; paste w.txt j.txt | expand | tr -s \' \' | tr \' \' \'.\' | tr \'x\' \' \' > cartf.txt')
    # os.system('cat ping.txt |grep ms | cut -d\'=\' -f4 | grep -v % | cut -d\' \' -f1 > delay.txt')

    os.system('pkill xterm')

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

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

    "Create a network."
    net = Mininet_wifi(controller=None,
                       switch=OVSKernelSwitch,
                       link=wmediumd,
                       wmediumd_mode=interference)

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

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

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

    #c1 = net.addController('c1', controller=Controller)

    sw1 = net.addSwitch('sw1', dpid='9', protocols='OpenFlow13')
    sw2 = net.addSwitch('sw2', dpid='10', protocols='OpenFlow13')

    server_s1 = net.addHost('server_s1', ip='200.0.10.2/8')
    server_s2 = net.addHost('server_s2', ip='200.0.10.2/8')
    server_s3 = net.addHost('server_s3', 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_g = net.addHost('server_g', ip='200.0.10.5/8')

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

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

    print("*** Creating links")
    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)

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

    # net.roads(10)

    # net.startMobility( time=0 )
    # net.mobility( cars[0], 'start', time=1, position='120,1000,0' )
    # net.mobility( cars[0], 'stop', time=179, position='2101,1000,0' )
    # net.mobility( cars[1], 'start', time=1, position='130,999,0' )
    # net.mobility( cars[1], 'stop', time=179, position='2095,999,0' )
    # net.mobility( cars[2], 'start', time=1, position='135,997,0' )
    # net.mobility( cars[2], 'stop', time=59, position='2097,997,0' )
    # net.mobility( cars[3], 'start', time=1, position='140,1000,0' )
    # net.mobility( cars[3], 'stop', time=59, position='1601,1000,0' )
    # net.mobility( cars[4], 'start', time=1, position='145,999,0' )
    # net.mobility( cars[4], 'stop', time=59, position='1599,999,0' )
    # net.mobility( cars[5], 'start', time=1, position='150,997,0' )
    # net.mobility( cars[5], 'stop', time=179, position='1595,997,0' )
    # net.mobility( cars[6], 'start', time=1, position='155,1000,0' )
    # net.mobility( cars[6], 'stop', time=179, position='1101,1000,0' )
    # net.mobility( cars[7], 'start', time=1, position='160,1000,0' )
    # net.mobility( cars[7], 'stop', time=179, position='1098,1000,0' )
    # net.mobility( cars[8], 'start', time=1, position='165,999,0' )
    # net.mobility( cars[8], 'stop', time=179, position='1095,999,0' )
    # net.stopMobility( time=180 )

    cars[0].setPosition('1103,1000,0')
    cars[1].setPosition('1105,1000,0')
    cars[2].setPosition('1095,1000,0')
    cars[3].setPosition('1603,1000,0')
    cars[4].setPosition('1605,1000,0')
    cars[1].setPosition('1595,1000,0')
    cars[5].setPosition('2103,1000,0')
    cars[6].setPosition('2105,1000,0')
    cars[7].setPosition('2095,1000,0')
    cars[8].setPosition('2110,1000,0')
    cars[9].setPosition('2090,1000,0')

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

    time.sleep(1)

    os.system(
        'ovs-vsctl set bridge rsu1 other-config:datapath-id=0000000000000006')
    os.system(
        'ovs-vsctl set bridge rsu2 other-config:datapath-id=0000000000000007')
    os.system(
        'ovs-vsctl set bridge rsu3 other-config:datapath-id=0000000000000008')

    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)

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

    info("*** Stopping network\n")
    net.stop()

    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')
コード例 #4
0
def topology(flag):

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

    info("*** Creating nodes\n")
    cars = []
    for x in range(0, 15):
        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', position='2107,250,0')
    cars[1] = net.addCar('car1',  wlans=1, range='50', ip='200.0.10.111/8', mac='00:00:00:00:00:02', position='2107,247,0')
    cars[2] = net.addCar('car2',  wlans=1, range='50', ip='200.0.10.112/8', mac='00:00:00:00:00:03', position='2104,250,0')
    cars[3] = net.addCar('car3',  wlans=1, range='50', ip='200.0.10.113/8', mac='00:00:00:00:00:04', position='1607,247,0')
    cars[4] = net.addCar('car4',  wlans=1, range='50', ip='200.0.10.114/8', mac='00:00:00:00:00:05', position='1604,250,0')
    cars[5] = net.addCar('car5',  wlans=1, range='50', ip='200.0.10.115/8', mac='00:00:00:00:00:06', position='1107,250,0')
    cars[6] = net.addCar('car6',  wlans=1, range='50', ip='200.0.10.116/8', mac='00:00:00:00:00:07', position='1104,247,0')
    cars[7] = net.addCar('car7',  wlans=1, range='50', ip='200.0.10.117/8', mac='00:00:00:00:00:08', position='150,250,0')
    cars[8] = net.addCar('car8',  wlans=1, range='50', ip='200.0.10.118/8', mac='00:00:00:00:00:09', position='200,250,0')
    cars[9] = net.addCar('car9',  wlans=1, range='50', ip='200.0.10.119/8', mac='00:00:00:00:00:10', position='250,250,0')
    cars[10] = net.addCar('car10',  wlans=1, range='50', ip='200.0.10.120/8', mac='00:00:00:00:00:11', position='300,250,0')
    cars[11] = net.addCar('car11',  wlans=1, range='50', ip='200.0.10.121/8', mac='00:00:00:00:00:12', position='350,250,0')
    cars[12] = net.addCar('car12',  wlans=1, range='50', ip='200.0.10.122/8', mac='00:00:00:00:00:13', position='400,243,0')
    cars[13] = net.addCar('car13',  wlans=1, range='50', ip='200.0.10.123/8', mac='00:00:00:00:00:14', position='450,243,0')
    cars[14] = net.addCar('car14',  wlans=1, range='50', ip='200.0.10.124/8', mac='00:00:00:00:00:15', position='500,243,0')

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

    sw1 = net.addSwitch ('sw1', dpid='9', protocols='OpenFlow13')
    sw2 = net.addSwitch ('sw2', dpid='10', protocols='OpenFlow13')
    sw3 = net.addSwitch ('sw3', dpid='11', protocols='OpenFlow13')
    sw4 = net.addSwitch ('sw4', dpid='12', protocols='OpenFlow13')
    sw5 = net.addSwitch ('sw5', dpid='13', protocols='OpenFlow13')

    server_s1 = net.addHost ('server_s1', ip='200.0.10.2/8', mac='00:00:00:00:00:a2')
    server_s2 = net.addHost ('server_s2', ip='200.0.10.2/8', mac='00:00:00:00:00:a2')
    server_s3 = net.addHost ('server_s3', ip='200.0.10.2/8', mac='00:00:00:00:00:a2')
    server_e = net.addHost ('server_e', ip='200.0.10.3/8', mac='00:00:00:00:00:a3')
    server_e2 = net.addHost ('server_e2', ip='200.0.10.4/8', mac='00:00:00:00:00:a4')
    server_g = net.addHost ('server_g', ip='200.0.10.5/8', mac='00:00:00:00:00:a5')

    info("*** Configuring Propagation Model\n")
    net.propagationModel(model="logDistance", exp=4.5)
    
    info("*** Configuring wifi nodes\n")
    net.configureWifiNodes()
    
    print("*** Creating links")
    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)
    net.addLink(sw3, rsu1, 1, 3)
    net.addLink(sw4, rsu2, 2, 4)
    net.addLink(sw5, rsu3, 3, 3)
    link1 = net.addLink(sw1, sw2, 1, 4, cls=TCLink )
    link2 = net.addLink(sw3, sw1, 3, 2, cls=TCLink)
    link3 = net.addLink(sw4, sw1, 4, 3, cls=TCLink)
    link4 = net.addLink(sw5, sw1, 5, 4, cls=TCLink)

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

    net.plotGraph(max_x=2400, max_y=500)
    
    #starting scenarios
    print("*** Starting network")
    net.build()
    c1.start()
    rsu1.start([c1])
    rsu2.start([c1])
    rsu3.start([c1])
    sw1.start([c1])
    sw2.start([c1])
    sw3.start([c1])
    sw4.start([c1])
    sw5.start([c1])
    #Necessary to avoid icmp noise
    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')
    time.sleep(1)
    #Defining DPID of RSUs 
    os.system('ovs-vsctl set bridge rsu1 other-config:datapath-id=0000000000000006')
    os.system('ovs-vsctl set bridge rsu2 other-config:datapath-id=0000000000000007')
    os.system('ovs-vsctl set bridge rsu3 other-config:datapath-id=0000000000000008')
    #Cleaning old QoS rules and Queues
    os.system('ovs-vsctl --all destroy QoS; ovs-vsctl --all destroy Queue')
    #Setting manager in OVS to Ryu
    os.system('ovs-vsctl set-manager ptcp:6632')
    time.sleep(1)
    #configuring OVSDB in Ryu, using REST API
    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( "*** Creating initial basic flows in network" )
    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;')
    os.system('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;')
    os.system('ovs-ofctl del-flows sw3 -O Openflow13; ovs-ofctl add-flow sw3 "table=0, priority=0, actions=goto_table:1" -O Openflow13;\
        ovs-ofctl add-flow sw3 "table=1, priority=0, in_port=3 actions=1" -O Openflow13; ovs-ofctl add-flow sw3 "table=1, priority=0,\
        in_port=1 actions=3" -O Openflow13;')
    os.system('ovs-ofctl del-flows sw4 -O Openflow13; ovs-ofctl add-flow sw4 "table=0, priority=0, actions=goto_table:1" -O Openflow13;\
        ovs-ofctl add-flow sw4 "table=1, priority=0, in_port=2 actions=4" -O Openflow13; ovs-ofctl add-flow sw4 "table=1, priority=0,\
        in_port=4 actions=2" -O Openflow13;')
    os.system('ovs-ofctl del-flows sw5 -O Openflow13; ovs-ofctl add-flow sw5 "table=0, priority=0, actions=goto_table:1" -O Openflow13;\
        ovs-ofctl add-flow sw5 "table=1, priority=0, in_port=3 actions=5" -O Openflow13; ovs-ofctl add-flow sw5 "table=1, priority=0,\
        in_port=5 actions=3" -O Openflow13;')
    os.system('ovs-ofctl del-flows rsu1 -O Openflow13; ovs-ofctl add-flow rsu1 "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 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, nw_dst=200.0.10.2,udp,tp_dst=5002 actions=5" -O Openflow13;')
    os.system('ovs-ofctl del-flows rsu2 -O Openflow13; ovs-ofctl add-flow rsu2 "table=0, priority=0, actions=goto_table: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 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, nw_dst=200.0.10.2,udp,tp_dst=5002 actions=5" -O Openflow13;')
    os.system('ovs-ofctl del-flows rsu3 -O Openflow13; ovs-ofctl add-flow rsu3 "table=0, priority=0, actions=goto_table: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, nw_dst=200.0.10.2,udp,tp_dst=5002 actions=5" -O Openflow13;')
    
    #Removing trace files and stopping network manager
    os.system('rm -f car*; rm -f server*; rm -f ping*; rm -f delay*; rm log*; /etc/init.d/network-manager stop')
    time.sleep(2)

    #Automatic mobility (disabled to these experiments)
    #os.system('./framework_its_sdn/lc_mob.sh > j2.txt &')

    #Define which approach will be used (Framework, QoS only or best effort)
    if flag == '-f':
        print( "*** Using Framework with controllers database, central controller and local controllers scripts")
        os.system('mysql -u root -pwifi < ./framework_its_sdn/initialdb.sql -f &')
        time.sleep(4)
        os.system('./framework_its_sdn/central_controller2.sh > j1.txt &')
        time.sleep(4)
        os.system('./framework_its_sdn/local_controllers.sh > j3.txt &')
    elif flag == '-q':
        print( "*** Using Only QoQ approach")
        os.system('mysql -u root -pwifi < ./framework_its_sdn/initialdb.sql -f &')
        time.sleep(4)
        os.system('./framework_its_sdn/central_controller2.sh > j1.txt &')
    elif flag == '-b':
        print( "*** Using Best effort approach")
    else:
        print( "*** Using test version")

    #Configuring arp tables in servers (to avoid noise and inconsistent data)
    server_s1.cmd('arp -f ./mac2.txt &')
    server_s2.cmd('arp -f ./mac2.txt &')
    server_s3.cmd('arp -f ./mac2.txt &')
    server_e.cmd('arp -f ./mac2.txt &')
    server_e2.cmd('arp -f ./mac2.txt &')
    server_g.cmd('arp -f ./mac2.txt &')

    time.sleep(2)

    #Configuring arp tables in cars (to avoid noise and inconsistent data)
    for x in xrange(0,15):
        cars[x].cmd('arp -f ./mac.txt &')
        time.sleep(0.5)

    print( "*** Starting C1 - T1")
    # Car0, 1 and 2 in RSU3. Car3 and 4 in RSU2 and Car 5 and 6 in RSU1. Cars7-14 out of range
    #Configuring flows to vehicles in backbonne switches
    os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=4,dl_src=00:00:00:00:00:01 actions=1" -O Openflow13')
    os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:01 actions=4" -O Openflow13')
    os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=4,dl_src=00:00:00:00:00:02 actions=1" -O Openflow13')
    os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:02 actions=4" -O Openflow13')
    os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=4,dl_src=00:00:00:00:00:03 actions=1" -O Openflow13')
    os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:03 actions=4" -O Openflow13')
    os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=3,dl_src=00:00:00:00:00:04 actions=1" -O Openflow13')
    os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:04 actions=3" -O Openflow13')
    os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=3,dl_src=00:00:00:00:00:05 actions=1" -O Openflow13')
    os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:05 actions=3" -O Openflow13')
    os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=2,dl_src=00:00:00:00:00:06 actions=1" -O Openflow13')
    os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:06 actions=2" -O Openflow13')
    os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=2,dl_src=00:00:00:00:00:07 actions=1" -O Openflow13')
    os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:07 actions=2" -O Openflow13')
    os.system('ovs-ofctl add-flow sw2 "table=1, priority=1, cookie=0x0, in_port=1,dl_src=00:00:00:00:00:a3 actions=4" -O Openflow13')
    os.system('ovs-ofctl add-flow sw2 "table=1, priority=1, cookie=0x0, in_port=2,dl_src=00:00:00:00:00:a4 actions=4" -O Openflow13')
    os.system('ovs-ofctl add-flow sw2 "table=1, priority=1, cookie=0x0, in_port=3,dl_src=00:00:00:00:00:a5 actions=4" -O Openflow13')


    if flag == '-f' or flag == '-q' or flag == '-b':

        #starting tcpdump in servers to collect packets in order to generate the results
        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(5)

        #Starting applications in vehicles
        for x in xrange(0,15):
            cars[x].cmd('./framework_its_sdn/carcon.sh &')
            # time.sleep(1)

        #Waiting the Congestion Level 1 time
        time.sleep(75)

        #Starting the Congestion Level 2 - moving vehicles 3, 4 and 5
        # Car0, 1, 2 3 and 4 in RSU3. Car5 in RSU2 and Car6 in RSU1. Cars7-14 out of range
        print( "*** Starting C2 - T2")
        cars[3].setPosition('2104,247,0')
        cars[4].setPosition('2101,250,0')
        cars[5].setPosition('1607,247,0')
        #configuring flows of vehicles 3, 4 and 5 in backbone
        os.system('ovs-ofctl del-flows sw1 cookie=0x0/-1,dl_src=00:00:00:00:00:04 -O Openflow13')
        os.system('ovs-ofctl del-flows sw1 cookie=0x0/-1,dl_dst=00:00:00:00:00:04 -O Openflow13')
        os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=4,dl_src=00:00:00:00:00:04 actions=1" -O Openflow13')
        os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:04 actions=4" -O Openflow13')
        os.system('ovs-ofctl del-flows sw1 cookie=0x0/-1,dl_src=00:00:00:00:00:05 -O Openflow13')
        os.system('ovs-ofctl del-flows sw1 cookie=0x0/-1,dl_dst=00:00:00:00:00:05 -O Openflow13')
        os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=4,dl_src=00:00:00:00:00:05 actions=1" -O Openflow13')
        os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:05 actions=4" -O Openflow13')
        os.system('ovs-ofctl del-flows sw1 cookie=0x0/-1,dl_src=00:00:00:00:00:06 -O Openflow13')
        os.system('ovs-ofctl del-flows sw1 cookie=0x0/-1,dl_dst=00:00:00:00:00:06 -O Openflow13')
        os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=3,dl_src=00:00:00:00:00:06 actions=1" -O Openflow13')
        os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:06 actions=3" -O Openflow13')
        #Waiting the Congestion Level 2 time
        time.sleep(75)
        #Starting the Congestion Level 3 - moving vehicles 6, 7, 8, 9 and 10
        # Car0-4 in RSU3. Car5-8 in RSU2 and Car9-10 in RSU1. Cars11-14 out of range
        print( "*** Starting C3 - T3")
        cars[6].setPosition('1604,247,0')
        cars[7].setPosition('1607,250,0')
        cars[8].setPosition('1601,247,0')
        cars[9].setPosition('1107,250,0')
        cars[10].setPosition('1104,247,0')
        #Configuring flows to vehicles in backbone switch
        os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=3,dl_src=00:00:00:00:00:07 actions=1" -O Openflow13')
        os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:07 actions=3" -O Openflow13')
        os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=3,dl_src=00:00:00:00:00:08 actions=1" -O Openflow13')
        os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:08 actions=3" -O Openflow13')
        os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=3,dl_src=00:00:00:00:00:09 actions=1" -O Openflow13')
        os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:09 actions=3" -O Openflow13')
        os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=2,dl_src=00:00:00:00:00:10 actions=1" -O Openflow13')
        os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:10 actions=2" -O Openflow13')
        os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=2,dl_src=00:00:00:00:00:11 actions=1" -O Openflow13')
        os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:11 actions=2" -O Openflow13')
        #Waiting the Congestion Level 3 time
        time.sleep(75)
        #Starting the Congestion Level 4 - moving vehicles 9, 10, 11, 12, 13 and 14
        # Car0-4 in RSU3. Car5-10 in RSU2 and Car11-14 in RSU1.
        print( "*** Starting C4 - T4")

        time.sleep(0.5)
        cars[9].setPosition('1604,250,0')
        #time.sleep(0.5)
        cars[10].setPosition('1601,250,0')
        #time.sleep(0.5)
        cars[11].setPosition('1107,250,0')
        #time.sleep(0.5)
        cars[12].setPosition('1107,247,0')
        #time.sleep(0.5)
        cars[13].setPosition('1104,250,0')
        #time.sleep(0.5)
        cars[14].setPosition('1104,247,0')
        #Configuring flows to vehicles in backbone switch
        os.system('ovs-ofctl del-flows sw1 cookie=0x0/-1,dl_src=00:00:00:00:00:10 -O Openflow13')
        os.system('ovs-ofctl del-flows sw1 cookie=0x0/-1,dl_dst=00:00:00:00:00:10 -O Openflow13')
        os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=3,dl_src=00:00:00:00:00:10 actions=1" -O Openflow13')
        os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:10 actions=3" -O Openflow13')
        os.system('ovs-ofctl del-flows sw1 cookie=0x0/-1,dl_src=00:00:00:00:00:11 -O Openflow13')
        os.system('ovs-ofctl del-flows sw1 cookie=0x0/-1,dl_dst=00:00:00:00:00:11 -O Openflow13')
        os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=3,dl_src=00:00:00:00:00:11 actions=1" -O Openflow13')
        os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:11 actions=3" -O Openflow13')
        os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=2,dl_src=00:00:00:00:00:12 actions=1" -O Openflow13')
        os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:12 actions=2" -O Openflow13')
        os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=2,dl_src=00:00:00:00:00:13 actions=1" -O Openflow13')
        os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:13 actions=2" -O Openflow13')
        os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=2,dl_src=00:00:00:00:00:14 actions=1" -O Openflow13')
        os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:14 actions=2" -O Openflow13')
        os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=2,dl_src=00:00:00:00:00:15 actions=1" -O Openflow13')
        os.system('ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:15 actions=2" -O Openflow13')
        #Waiting the Congestion Level 4 time
        time.sleep(85)

        #Finishing process
        os.system('pkill tcpdump')
        os.system('pkill hping3')
        os.system('pkill ping')
        time.sleep(2)
    else:
         print( "*** Testing..")

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

    info("*** Stopping network\n")
    net.stop()

    #Kill processe using scripts pobile called
    os.system('fuser -k ./framework_its_sdn/lc_mob.sh') 
    os.system('fuser -k ./framework_its_sdn/central_controller2.sh')
    os.system('fuser -k ./framework_its_sdn/local_controllers.sh')
コード例 #5
0
def topology(flag):

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

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

    cars[0] = net.addCar('car0',
                         wlans=1,
                         ip='200.0.10.110/8',
                         range=50,
                         mac='00:00:00:00:00:01',
                         encrypt=['wpa2'],
                         bgscan_threshold=-60,
                         s_interval=5,
                         l_interval=10,
                         bgscan_module="simple")  #mudou
    cars[1] = net.addCar('car1',
                         wlans=1,
                         ip='200.0.10.111/8',
                         range=50,
                         mac='00:00:00:00:00:02',
                         encrypt=['wpa2'],
                         bgscan_threshold=-60,
                         s_interval=5,
                         l_interval=10,
                         bgscan_module="simple")  #mudou
    cars[2] = net.addCar('car2',
                         wlans=1,
                         ip='200.0.10.112/8',
                         range=50,
                         mac='00:00:00:00:00:03',
                         encrypt=['wpa2'],
                         bgscan_threshold=-60,
                         s_interval=5,
                         l_interval=10,
                         bgscan_module="simple")  #mudou
    cars[3] = net.addCar('car3',
                         wlans=1,
                         ip='200.0.10.113/8',
                         range=50,
                         mac='00:00:00:00:00:04',
                         encrypt=['wpa2'],
                         bgscan_threshold=-60,
                         s_interval=5,
                         l_interval=10,
                         bgscan_module="simple")  #mudou
    cars[4] = net.addCar('car4',
                         wlans=1,
                         ip='200.0.10.114/8',
                         range=50,
                         mac='00:00:00:00:00:05',
                         encrypt=['wpa2'],
                         bgscan_threshold=-60,
                         s_interval=5,
                         l_interval=10,
                         bgscan_module="simple")  #mudou
    cars[5] = net.addCar('car5',
                         wlans=1,
                         ip='200.0.10.115/8',
                         range=50,
                         mac='00:00:00:00:00:06',
                         encrypt=['wpa2'],
                         bgscan_threshold=-60,
                         s_interval=5,
                         l_interval=10,
                         bgscan_module="simple")  #mudou
    cars[6] = net.addCar('car6',
                         wlans=1,
                         ip='200.0.10.116/8',
                         range=50,
                         mac='00:00:00:00:00:07',
                         encrypt=['wpa2'],
                         bgscan_threshold=-60,
                         s_interval=5,
                         l_interval=10,
                         bgscan_module="simple")  #mudou
    cars[7] = net.addCar('car7',
                         wlans=1,
                         ip='200.0.10.117/8',
                         range=50,
                         mac='00:00:00:00:00:08',
                         encrypt=['wpa2'],
                         bgscan_threshold=-60,
                         s_interval=5,
                         l_interval=10,
                         bgscan_module="simple")  #mudou
    cars[8] = net.addCar('car8',
                         wlans=1,
                         ip='200.0.10.118/8',
                         range=50,
                         mac='00:00:00:00:00:09',
                         encrypt=['wpa2'],
                         bgscan_threshold=-60,
                         s_interval=5,
                         l_interval=10,
                         bgscan_module="simple")  #mudou
    cars[9] = net.addCar('car9',
                         wlans=1,
                         ip='200.0.10.119/8',
                         range=50,
                         mac='00:00:00:00:00:10',
                         encrypt=['wpa2'],
                         bgscan_threshold=-60,
                         s_interval=5,
                         l_interval=10,
                         bgscan_module="simple")  #mudou
    cars[10] = net.addCar('car10',
                          wlans=1,
                          ip='200.0.10.120/8',
                          range=50,
                          mac='00:00:00:00:00:11',
                          encrypt=['wpa2'],
                          bgscan_threshold=-60,
                          s_interval=5,
                          l_interval=10,
                          bgscan_module="simple")  #mudou
    cars[11] = net.addCar('car11',
                          wlans=1,
                          ip='200.0.10.121/8',
                          range=50,
                          mac='00:00:00:00:00:12',
                          encrypt=['wpa2'],
                          bgscan_threshold=-60,
                          s_interval=5,
                          l_interval=10,
                          bgscan_module="simple")  #mudou
    cars[12] = net.addCar('car12',
                          wlans=1,
                          ip='200.0.10.122/8',
                          range=50,
                          mac='00:00:00:00:00:13',
                          encrypt=['wpa2'],
                          bgscan_threshold=-60,
                          s_interval=5,
                          l_interval=10,
                          bgscan_module="simple")  #mudou
    cars[13] = net.addCar('car13',
                          wlans=1,
                          ip='200.0.10.123/8',
                          range=50,
                          mac='00:00:00:00:00:14',
                          encrypt=['wpa2'],
                          bgscan_threshold=-60,
                          s_interval=5,
                          l_interval=10,
                          bgscan_module="simple")  #mudou
    cars[14] = net.addCar('car14',
                          wlans=1,
                          ip='200.0.10.124/8',
                          range=50,
                          mac='00:00:00:00:00:15',
                          encrypt=['wpa2'],
                          bgscan_threshold=-60,
                          s_interval=5,
                          l_interval=10,
                          bgscan_module="simple")  #mudou

    for x in range(15, 50):  #15 vehicles
        cars.append(x)
    for i in range(15, 50):
        print("mac='00:01:00:00:00:%s'" % ((int(i) - 1) * 1))  #84 a 99
        cars[i] = net.addCar('car%s' % i,
                             wlans=1,
                             ip='200.0.9.%s/8' % (int(i) + 10),
                             range=50,
                             mac='00:01:00:00:00:%s' % ((int(i) - 1) * 1),
                             encrypt=['wpa2'],
                             bgscan_threshold=-60,
                             s_interval=5,
                             l_interval=10,
                             bgscan_module="simple")  #mudou

    # for x in range(81, 97): #16 vehicles
    #     cars.append(x)
    # for i in range(81, 97):
    #     print("mac='00:01:00:00:00:%s'" %((int(i)-114)*-1)) #  17 a 33
    #     cars[i] = net.addCar('car%s' %i,  wlans=1, ip='200.0.9.%s/8' %(int(i)+10), range = 50, mac='00:01:00:00:00:%s' %((int(i)-114)*-1), encrypt=['wpa2'], bgscan_threshold=-60, s_interval=5, l_interval=10, bgscan_module="simple") #mudou

    # for x in range(147, 151): #4 vehicles
    #     cars.append(x)
    # for i in range(147, 151):
    #     print("mac='00:01:00:00:00:%s'" %((int(i)-113)*1)) # 34 a 38
    #     cars[i] = net.addCar('car%s' %i,  wlans=1, ip='200.0.9.%s/8' %(int(i)+10), range = 50, mac='00:01:00:00:00:%s' %((int(i)-113)*1), encrypt=['wpa2'], bgscan_threshold=-60, s_interval=5, l_interval=10, bgscan_module="simple") #mudou

    #for i in range(105, 150):
    #   print("mac='00:02:00:00:00:%s'" %((int(i)-204)*-1))
    #  cars[i] = net.addCar('car%s' %i,  wlans=1, ip='200.0.9.%s/8' %(int(i)+10), range = 50, mac='00:02:00:00:00:%s' %((int(i)-204)*-1), encrypt=['wpa2'], bgscan_threshold=-60, s_interval=5, l_interval=10, bgscan_module="simple") #mudou

    rsu1 = net.addAccessPoint('rsu1',
                              ssid='rsu1',
                              mode='g',
                              channel='1',
                              range=100,
                              mac='00:00:00:11:00:01',
                              passwd='123456789a',
                              encrypt='wpa2',
                              protocols='OpenFlow13',
                              position='2380.96,3714.27,0',
                              config='ap_max_inactivity=6,'
                              'skip_inactivity_poll=1,'
                              'max_listen_interval=6')
    rsu2 = net.addAccessPoint('rsu2',
                              ssid='rsu2',
                              mode='g',
                              channel='6',
                              range=100,
                              mac='00:00:00:11:00:02',
                              passwd='123456789a',
                              encrypt='wpa2',
                              protocols='OpenFlow13',
                              position='2615.91,3587.85,0',
                              config='ap_max_inactivity=6,'
                              'skip_inactivity_poll=1,'
                              'max_listen_interval=6')
    rsu3 = net.addAccessPoint('rsu3',
                              ssid='rsu3',
                              mode='g',
                              channel='11',
                              range=100,
                              mac='00:00:00:11:00:03',
                              passwd='123456789a',
                              encrypt='wpa2',
                              protocols='OpenFlow13',
                              position='2860.93,3456.58,0',
                              config='ap_max_inactivity=6,'
                              'skip_inactivity_poll=1,'
                              'max_listen_interval=6')

    sw1 = net.addSwitch('sw1', dpid='9', protocols='OpenFlow13')
    sw2 = net.addSwitch('sw2', dpid='10', protocols='OpenFlow13')
    sw3 = net.addSwitch('sw3', dpid='11', protocols='OpenFlow13')
    sw4 = net.addSwitch('sw4', dpid='12', protocols='OpenFlow13')
    sw5 = net.addSwitch('sw5', dpid='13', protocols='OpenFlow13')

    server_s1 = net.addHost('server_s1',
                            ip='200.0.10.2/8',
                            mac='00:00:00:00:00:a2')
    server_s2 = net.addHost('server_s2',
                            ip='200.0.10.2/8',
                            mac='00:00:00:00:00:a2')
    server_s3 = net.addHost('server_s3',
                            ip='200.0.10.2/8',
                            mac='00:00:00:00:00:a2')
    server_e = net.addHost('server_e',
                           ip='200.0.10.3/8',
                           mac='00:00:00:00:00:a3')
    server_e2 = net.addHost('server_e2',
                            ip='200.0.10.4/8',
                            mac='00:00:00:00:00:a4')
    server_g = net.addHost('server_g',
                           ip='200.0.10.5/8',
                           mac='00:00:00:00:00:a5')

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

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

    print("*** Creating links")
    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)
    net.addLink(sw3, rsu1, 1, 3)
    net.addLink(sw4, rsu2, 2, 4)
    net.addLink(sw5, rsu3, 3, 3)

    link1 = net.addLink(sw1, sw2, 1, 4, cls=TCLink, bw=17)  #mudou
    link2 = net.addLink(sw3, sw1, 3, 2, cls=TCLink, bw=5.25)
    link3 = net.addLink(sw4, sw1, 4, 3, cls=TCLink, bw=5.25)
    link4 = net.addLink(sw5, sw1, 5, 4, cls=TCLink, bw=5.25)

    net.useExternalProgram(program=sumo, port=8813, config_file='map2.sumocfg')

    print("*** Starting network")
    net.build()
    c1.start()
    rsu1.start([c1])
    rsu2.start([c1])
    rsu3.start([c1])
    sw1.start([c1])
    sw2.start([c1])
    sw3.start([c1])
    sw4.start([c1])
    sw5.start([c1])
    #Necessary to avoid icmp noise
    time.sleep(2)

    nodes = net.cars + net.aps
    net.telemetry(nodes=nodes,
                  data_type='position',
                  min_x=2150,
                  min_y=3200,
                  max_x=3250,
                  max_y=3950)

    #Necessary to avoid icmp noise
    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'
    )
    time.sleep(1)
    #Defining DPID of RSUs
    os.system(
        'ovs-vsctl set bridge rsu1 other-config:datapath-id=0000000000000006')
    os.system(
        'ovs-vsctl set bridge rsu2 other-config:datapath-id=0000000000000007')
    os.system(
        'ovs-vsctl set bridge rsu3 other-config:datapath-id=0000000000000008')
    #Cleaning old QoS rules and Queues
    os.system('ovs-vsctl --all destroy QoS; ovs-vsctl --all destroy Queue')
    #Setting manager in OVS to Ryu
    os.system('ovs-vsctl set-manager ptcp:6632')
    time.sleep(1)
    #configuring OVSDB in Ryu, using REST API
    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( "*** Creating initial basic flows in network" )
    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;'
    )
    os.system(
        '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;'
    )
    os.system(
        'ovs-ofctl del-flows sw3 -O Openflow13; ovs-ofctl add-flow sw3 "table=0, priority=0, actions=goto_table:1" -O Openflow13;\
        ovs-ofctl add-flow sw3 "table=1, priority=0, in_port=3 actions=1" -O Openflow13; ovs-ofctl add-flow sw3 "table=1, priority=0,\
        in_port=1 actions=3" -O Openflow13;')
    os.system(
        'ovs-ofctl del-flows sw4 -O Openflow13; ovs-ofctl add-flow sw4 "table=0, priority=0, actions=goto_table:1" -O Openflow13;\
        ovs-ofctl add-flow sw4 "table=1, priority=0, in_port=2 actions=4" -O Openflow13; ovs-ofctl add-flow sw4 "table=1, priority=0,\
        in_port=4 actions=2" -O Openflow13;')
    os.system(
        'ovs-ofctl del-flows sw5 -O Openflow13; ovs-ofctl add-flow sw5 "table=0, priority=0, actions=goto_table:1" -O Openflow13;\
        ovs-ofctl add-flow sw5 "table=1, priority=0, in_port=3 actions=5" -O Openflow13; ovs-ofctl add-flow sw5 "table=1, priority=0,\
        in_port=5 actions=3" -O Openflow13;')
    os.system(
        'ovs-ofctl del-flows rsu1 -O Openflow13; ovs-ofctl add-flow rsu1 "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 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, nw_dst=200.0.10.2,udp,tp_dst=5002 actions=5" -O Openflow13;'
    )
    os.system(
        'ovs-ofctl del-flows rsu2 -O Openflow13; ovs-ofctl add-flow rsu2 "table=0, priority=0, actions=goto_table: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 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, nw_dst=200.0.10.2,udp,tp_dst=5002 actions=5" -O Openflow13;'
    )
    os.system(
        'ovs-ofctl del-flows rsu3 -O Openflow13; ovs-ofctl add-flow rsu3 "table=0, priority=0, actions=goto_table: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, nw_dst=200.0.10.2,udp,tp_dst=5002 actions=5" -O Openflow13;'
    )

    #Removing trace files and stopping network manager
    os.system(
        'rm -f car*; rm -f server*; rm -f ping*; rm -f delay*; rm -f okok*; rm log*; /etc/init.d/network-manager stop'
    )
    time.sleep(2)

    if flag == '-f':
        print(
            "*** Using Framework with controllers database, central controller and local controllers scripts"
        )
        os.system(
            'mysql -u root -pwifi < ./framework_its_sdn/initialdb.sql -f &')
        time.sleep(4)
        os.system('./framework_its_sdn/central_controller2.sh > j1.txt &')
        time.sleep(4)
        os.system('./framework_its_sdn/local_controllers.sh > j3.txt &')
    elif flag == '-q':
        print("*** Using Only QoQ approach")
        os.system(
            'mysql -u root -pwifi < ./framework_its_sdn/initialdb.sql -f &')
        time.sleep(4)
        os.system('./framework_its_sdn/central_controller2.sh > j1.txt &')
    elif flag == '-b':
        print("*** Using Best effort approach")
    else:
        print("*** Using test version")

    #Configuring arp tables in servers (to avoid noise and inconsistent data)
    server_s1.cmd('arp -f ./mac2.txt &')
    server_s2.cmd('arp -f ./mac2.txt &')
    server_s3.cmd('arp -f ./mac2.txt &')
    server_e.cmd('arp -f ./mac2.txt &')
    server_e2.cmd('arp -f ./mac2.txt &')
    server_g.cmd('arp -f ./mac2.txt &')

    time.sleep(2)

    #Configuring arp tables in cars (to avoid noise and inconsistent data)
    for x in range(0, 15):
        cars[x].cmd('arp -f ./mac.txt &')
        time.sleep(0.2)

    for x in range(15, 50):
        cars[x].cmd('arp -f ./mac.txt &')
        time.sleep(0.2)

    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=4,dl_src=00:00:00:00:00:01 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:01 actions=4" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=4,dl_src=00:00:00:00:00:02 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:02 actions=4" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=4,dl_src=00:00:00:00:00:03 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:03 actions=4" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=2,dl_src=00:00:00:00:00:07 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:07 actions=2" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw2 "table=1, priority=1, cookie=0x0, in_port=1,dl_src=00:00:00:00:00:a3 actions=4" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw2 "table=1, priority=1, cookie=0x0, in_port=2,dl_src=00:00:00:00:00:a4 actions=4" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw2 "table=1, priority=1, cookie=0x0, in_port=3,dl_src=00:00:00:00:00:a5 actions=4" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=4,dl_src=00:00:00:00:00:04 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:04 actions=4" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=4,dl_src=00:00:00:00:00:05 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:05 actions=4" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=3,dl_src=00:00:00:00:00:06 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:06 actions=3" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=3,dl_src=00:00:00:00:00:07 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:07 actions=3" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=3,dl_src=00:00:00:00:00:08 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:08 actions=3" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=3,dl_src=00:00:00:00:00:09 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:09 actions=3" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=3,dl_src=00:00:00:00:00:10 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:10 actions=3" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=3,dl_src=00:00:00:00:00:11 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:11 actions=3" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=2,dl_src=00:00:00:00:00:12 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:12 actions=2" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=2,dl_src=00:00:00:00:00:13 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:13 actions=2" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=2,dl_src=00:00:00:00:00:14 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:14 actions=2" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=2,dl_src=00:00:00:00:00:15 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:15 actions=2" -O Openflow13'
    )

    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(3)

    for x in range(0, 15):
        cars[x].cmd('./framework_its_sdn/carcont.sh &')
        time.sleep(1)

    for x in range(15, 50):
        cars[x].cmd('./framework_its_sdn/carcont2.sh &')
        time.sleep(1)

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

    info("*** Stopping network\n")
    net.stop()

    os.system('fuser -k ./framework_its_sdn/carcont.sh')
    os.system('fuser -k ./framework_its_sdn/carcont2.sh')

    #Kill processe using scripts pobile called
    #os.system('fuser -k ./framework_its_sdn/lc_mob.sh')
    os.system('fuser -k ./framework_its_sdn/central_controller2.sh')
    os.system('fuser -k ./framework_its_sdn/local_controllers.sh')
コード例 #6
0
ファイル: vanet-sumo.py プロジェクト: bhanu9b07/r
def topology():

    "Create a network."
    net = Mininet_wifi(controller=Controller,
                       accessPoint=UserAP,
                       link=wmediumd,
                       wmediumd_mode=interference)

    info("*** Creating nodes\n")
    cars = []
    for id in range(0, 10):
        cars.append(
            net.addCar('car%s' % (id + 1),
                       wlans=2,
                       bgscan_threshold=-60,
                       s_inverval=5,
                       l_interval=10))

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

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

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

    net.addLink(e1, e2)
    net.addLink(e2, e3)
    net.addLink(e3, e4)
    net.addLink(e4, e5)
    net.addLink(e5, e6)
    for car in cars:
        net.addLink(car,
                    intf=car.params['wlan'][1],
                    cls=mesh,
                    ssid='mesh-ssid',
                    channel=5)

    net.useExternalProgram(program=sumo, port=8813, config_file='map.sumocfg')

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

    for car in cars:
        car.setIP('192.168.0.%s/24' % (int(cars.index(car)) + 1),
                  intf='%s-wlan0' % car)
        car.setIP('192.168.1.%s/24' % (int(cars.index(car)) + 1),
                  intf='%s-mp1' % car)

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

    info("*** Stopping network\n")
    net.stop()
コード例 #7
0
def topology():

    "Create a network."
    net = Mininet_wifi(controller=Controller, accessPoint=UserAP,
                       link=wmediumd, wmediumd_mode=interference)

    info("*** Creating nodes\n")
    cars = []
    for id in range(0, 10):
        cars.append(net.addCar('car%s' % (id+1), wlans=2))

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

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

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

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

    net.addLink(e1, e2)
    net.addLink(e2, e3)
    net.addLink(e3, e4)
    net.addLink(e4, e5)
    net.addLink(e5, e6)
    for car in cars:
        net.addLink(car, intf=car.params['wlan'][1],
                    cls=mesh, ssid='mesh-ssid', channel=5)

    net.useExternalProgram(program=sumo, port=8813,
                           config_file='map.sumocfg')

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

    for car in cars:
        car.setIP('192.168.0.%s/24' % (int(cars.index(car))+1),
                  intf='%s-wlan0' % car)
        car.setIP('192.168.1.%s/24' % (int(cars.index(car))+1),
                  intf='%s-mp1' % car)

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

    info("*** Stopping network\n")
    net.stop()
コード例 #8
0
def topology():

    "Create a network."
    net = Mininet_wifi(controller=None,
                       switch=OVSKernelSwitch,
                       link=wmediumd,
                       wmediumd_mode=interference)

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

    info("*** Creating nodes\n")
    cars = []
    for x in range(0, 15):
        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',
                         position='2107,250,0')
    cars[1] = net.addCar('car1',
                         wlans=1,
                         range='50',
                         ip='200.0.10.111/8',
                         mac='00:00:00:00:00:02',
                         position='2107,247,0')
    cars[2] = net.addCar('car2',
                         wlans=1,
                         range='50',
                         ip='200.0.10.112/8',
                         mac='00:00:00:00:00:03',
                         position='2104,250,0')

    cars[3] = net.addCar('car3',
                         wlans=1,
                         range='50',
                         ip='200.0.10.113/8',
                         mac='00:00:00:00:00:04',
                         position='1607,247,0')
    cars[4] = net.addCar('car4',
                         wlans=1,
                         range='50',
                         ip='200.0.10.114/8',
                         mac='00:00:00:00:00:05',
                         position='1604,250,0')

    cars[5] = net.addCar('car5',
                         wlans=1,
                         range='50',
                         ip='200.0.10.115/8',
                         mac='00:00:00:00:00:06',
                         position='1107,250,0')
    cars[6] = net.addCar('car6',
                         wlans=1,
                         range='50',
                         ip='200.0.10.116/8',
                         mac='00:00:00:00:00:07',
                         position='1104,247,0')

    cars[7] = net.addCar('car7',
                         wlans=1,
                         range='50',
                         ip='200.0.10.117/8',
                         mac='00:00:00:00:00:08',
                         position='150,250,0')
    cars[8] = net.addCar('car8',
                         wlans=1,
                         range='50',
                         ip='200.0.10.118/8',
                         mac='00:00:00:00:00:09',
                         position='200,250,0')
    cars[9] = net.addCar('car9',
                         wlans=1,
                         range='50',
                         ip='200.0.10.119/8',
                         mac='00:00:00:00:00:10',
                         position='250,250,0')
    cars[10] = net.addCar('car10',
                          wlans=1,
                          range='50',
                          ip='200.0.10.120/8',
                          mac='00:00:00:00:00:11',
                          position='300,250,0')
    cars[11] = net.addCar('car11',
                          wlans=1,
                          range='50',
                          ip='200.0.10.121/8',
                          mac='00:00:00:00:00:12',
                          position='350,250,0')
    cars[12] = net.addCar('car12',
                          wlans=1,
                          range='50',
                          ip='200.0.10.122/8',
                          mac='00:00:00:00:00:13',
                          position='400,243,0')
    cars[13] = net.addCar('car13',
                          wlans=1,
                          range='50',
                          ip='200.0.10.123/8',
                          mac='00:00:00:00:00:14',
                          position='450,243,0')
    cars[14] = net.addCar('car14',
                          wlans=1,
                          range='50',
                          ip='200.0.10.124/8',
                          mac='00:00:00:00:00:15',
                          position='500,243,0')

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

    sw1 = net.addSwitch('sw1', dpid='9', protocols='OpenFlow13')
    sw2 = net.addSwitch('sw2', dpid='10', protocols='OpenFlow13')
    sw3 = net.addSwitch('sw3', dpid='11', protocols='OpenFlow13')
    sw4 = net.addSwitch('sw4', dpid='12', protocols='OpenFlow13')
    sw5 = net.addSwitch('sw5', dpid='13', protocols='OpenFlow13')

    server_s1 = net.addHost('server_s1',
                            ip='200.0.10.2/8',
                            mac='00:00:00:00:00:a2')
    server_s2 = net.addHost('server_s2',
                            ip='200.0.10.2/8',
                            mac='00:00:00:00:00:a2')
    server_s3 = net.addHost('server_s3',
                            ip='200.0.10.2/8',
                            mac='00:00:00:00:00:a2')
    server_e = net.addHost('server_e',
                           ip='200.0.10.3/8',
                           mac='00:00:00:00:00:a3')
    server_e2 = net.addHost('server_e2',
                            ip='200.0.10.4/8',
                            mac='00:00:00:00:00:a4')
    server_g = net.addHost('server_g',
                           ip='200.0.10.5/8',
                           mac='00:00:00:00:00:a5')

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

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

    print("*** Creating links")
    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)
    net.addLink(sw3, rsu1, 1, 3)
    net.addLink(sw4, rsu2, 2, 4)
    net.addLink(sw5, rsu3, 3, 3)
    link1 = net.addLink(sw1, sw2, 1, 4, cls=TCLink)
    link2 = net.addLink(sw3, sw1, 3, 2, cls=TCLink)
    link3 = net.addLink(sw4, sw1, 4, 3, cls=TCLink)
    link4 = net.addLink(sw5, sw1, 5, 4, cls=TCLink)

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

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

    print("*** Starting network")
    net.build()
    c1.start()
    rsu1.start([c1])
    rsu2.start([c1])
    rsu3.start([c1])
    sw1.start([c1])
    sw2.start([c1])
    sw3.start([c1])
    sw4.start([c1])
    sw5.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'
    )

    time.sleep(1)

    os.system(
        'ovs-vsctl set bridge rsu1 other-config:datapath-id=0000000000000006')
    os.system(
        'ovs-vsctl set bridge rsu2 other-config:datapath-id=0000000000000007')
    os.system(
        'ovs-vsctl set bridge rsu3 other-config:datapath-id=0000000000000008')

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

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

    time.sleep(1)

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

    os.system(
        'ovs-ofctl del-flows sw3 -O Openflow13; ovs-ofctl add-flow sw3 "table=0, priority=0, actions=goto_table:1" -O Openflow13; ovs-ofctl add-flow sw3 "table=1, priority=0, in_port=3 actions=1" -O Openflow13; ovs-ofctl add-flow sw3 "table=1, priority=0, in_port=1 actions=3" -O Openflow13; ovs-ofctl del-flows sw4 -O Openflow13; ovs-ofctl add-flow sw4 "table=0, priority=0, actions=goto_table:1" -O Openflow13; ovs-ofctl add-flow sw4 "table=1, priority=0, in_port=2 actions=4" -O Openflow13; ovs-ofctl add-flow sw4 "table=1, priority=0, in_port=4 actions=2" -O Openflow13; ovs-ofctl del-flows sw5 -O Openflow13; ovs-ofctl add-flow sw5 "table=0, priority=0, actions=goto_table:1" -O Openflow13; ovs-ofctl add-flow sw5 "table=1, priority=0, in_port=3 actions=5" -O Openflow13; ovs-ofctl add-flow sw5 "table=1, priority=0, in_port=5 actions=3" -O Openflow13;'
    )

    os.system(
        'rm -f car*; rm -f server*; rm -f ping*; rm -f delay*; /etc/init.d/network-manager stop'
    )

    time.sleep(2)

    os.system('mysql -u root -pwifi < ./framework_its_sdn/initialdb.sql -f &')
    #os.system('./framework_its_sdn/lc_mob.sh > j2.txt &')
    time.sleep(4)
    os.system('./framework_its_sdn/central_controller2.sh > j1.txt &')
    #os.system('./framework_its_sdn/local_controllers.sh > j3.txt &')

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

    server_s1.cmd('arp -f ./mac2.txt &')
    server_s2.cmd('arp -f ./mac2.txt &')
    server_s3.cmd('arp -f ./mac2.txt &')
    server_e.cmd('arp -f ./mac2.txt &')
    server_e2.cmd('arp -f ./mac2.txt &')
    server_g.cmd('arp -f ./mac2.txt &')

    time.sleep(2)

    for x in xrange(0, 15):
        cars[x].cmd('arp -f ./mac.txt &')
        time.sleep(1)

    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=4,dl_src=00:00:00:00:00:01 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:01 actions=4" -O Openflow13'
    )

    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=4,dl_src=00:00:00:00:00:02 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:02 actions=4" -O Openflow13'
    )

    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=4,dl_src=00:00:00:00:00:03 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:03 actions=4" -O Openflow13'
    )

    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=3,dl_src=00:00:00:00:00:04 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:04 actions=3" -O Openflow13'
    )

    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=3,dl_src=00:00:00:00:00:05 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:05 actions=3" -O Openflow13'
    )

    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=2,dl_src=00:00:00:00:00:06 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:06 actions=2" -O Openflow13'
    )

    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=2,dl_src=00:00:00:00:00:07 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:07 actions=2" -O Openflow13'
    )

    os.system(
        'ovs-ofctl add-flow sw2 "table=1, priority=1, cookie=0x0, in_port=1,dl_src=00:00:00:00:00:a3 actions=4" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw2 "table=1, priority=1, cookie=0x0, in_port=2,dl_src=00:00:00:00:00:a4 actions=4" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw2 "table=1, priority=1, cookie=0x0, in_port=3,dl_src=00:00:00:00:00:a5 actions=4" -O Openflow13'
    )

    ####################################################Scenario F
    print("*** Starting F - T1")

    # cars[0].setPosition('2107,250,0')
    # cars[1].setPosition('2107,247,0')
    # cars[2].setPosition('2104,250,0')

    # cars[3].setPosition('1607,247,0')
    # cars[4].setPosition('1604,250,0')

    # cars[5].setPosition('1107,250,0')
    # cars[6].setPosition('1104,247,0')

    # cars[7].setPosition('150,250,0')
    # cars[8].setPosition('200,250,0')
    # cars[9].setPosition('250,250,0')
    # cars[10].setPosition('300,250,0')
    # cars[11].setPosition('350,250,0')
    # cars[12].setPosition('400,243,0')
    # cars[13].setPosition('450,243,0')
    # cars[14].setPosition('500,243,0')

    time.sleep(5)

    # for x in xrange(0,7):
    # # for x in xrange(0,1,2):
    #     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 500kbps" %x)
    #     # cars[x].cmd('arp -s 200.0.10.2 00:00:00:00:00:a2 &')
    #     cars[x].cmdPrint("timeout 330 hping3 --udp -p 5002 -i u24000 -d 1470 200.0.10.2 -q &")
    #     # cars[x].cmdPrint("rm -f ping%d_s.txt" %x)
    #     cars[x].cmdPrint("ping 200.0.10.2 -i 1 -c 330 | while read line; do echo $(date +%%s) - $line >> ping%d_s.txt; done &" %x)

    #     print("*** Car[%d] connect to server_e at 500kbps" %x)
    #     # cars[x].cmd('arp -s 200.0.10.3 00:00:00:00:00:a3 &')
    #     cars[x].cmdPrint("timeout 330 hping3 --udp -p 5003 -i u24000 -d 1470 200.0.10.3 -q &")
    #     # cars[x].cmdPrint("rm -f ping%d_e.txt" %x)
    #     cars[x].cmdPrint("ping 200.0.10.3 -i 1 -c 330 | while read line; do echo $(date +%%s) - $line >> ping%d_e.txt; done &" %x)

    #     print("*** Car[%d] connect to server_e2 at 1Mbps" %x)
    #     # cars[x].cmd('arp -s 200.0.10.4 00:00:00:00:00:a4 &')
    #     cars[x].cmdPrint("timeout 330 hping3 --udp -p 5004 -i u12000 -d 1470 200.0.10.4 -q &")
    #     # cars[x].cmdPrint("rm -f ping%d_e2.txt" %x)
    #     cars[x].cmdPrint("ping 200.0.10.4 -i 1 -c 330 | while read line; do echo $(date +%%s) - $line >> ping%d_e2.txt; done &" %x)

    #     print("*** Car[%d] connect to server_g at 500kbps" %x)
    #     # cars[x].cmd('arp -s 200.0.10.5 00:00:00:00:00:a5 &')
    #     cars[x].cmdPrint("timeout 330 hping3 --udp -p 5005 -i u24000 -d 1470 200.0.10.5 -q &")
    #     # cars[x].cmdPrint("rm -f ping%d_g.txt" %x)
    #     cars[x].cmdPrint("ping 200.0.10.5 -i 1 -c 330 | while read line; do echo $(date +%%s) - $line >> ping%d_g.txt; done &" %x)

    for x in xrange(0, 15):
        cars[x].cmd('./framework_its_sdn/carcon.sh &')
        # time.sleep(1)

    time.sleep(65)

    #########################################################################Scenario C1 (t2)

    #os.system('fuser -k ./framework_its_sdn/local_controllers.sh')

    time.sleep(5)

    print("*** Starting C1 - T2")
    # cars[0].setPosition('2107,250,0')
    # cars[1].setPosition('2107,247,0')
    # cars[2].setPosition('2104,250,0')
    cars[3].setPosition('2104,247,0')
    cars[4].setPosition('2101,250,0')

    cars[5].setPosition('1607,247,0')

    # cars[6].setPosition('1104,247,0')

    # cars[7].setPosition('150,250,0')
    # cars[8].setPosition('200,250,0')
    # cars[9].setPosition('250,250,0')
    # cars[10].setPosition('300,250,0')
    # cars[11].setPosition('350,250,0')
    # cars[12].setPosition('400,243,0')
    # cars[13].setPosition('450,243,0')
    # cars[14].setPosition('500,243,0')

    os.system(
        'ovs-ofctl del-flows sw1 cookie=0x0/-1,dl_src=00:00:00:00:00:04 -O Openflow13'
    )
    os.system(
        'ovs-ofctl del-flows sw1 cookie=0x0/-1,dl_dst=00:00:00:00:00:04 -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=4,dl_src=00:00:00:00:00:04 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:04 actions=4" -O Openflow13'
    )

    os.system(
        'ovs-ofctl del-flows sw1 cookie=0x0/-1,dl_src=00:00:00:00:00:05 -O Openflow13'
    )
    os.system(
        'ovs-ofctl del-flows sw1 cookie=0x0/-1,dl_dst=00:00:00:00:00:05 -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=4,dl_src=00:00:00:00:00:05 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:05 actions=4" -O Openflow13'
    )

    os.system(
        'ovs-ofctl del-flows sw1 cookie=0x0/-1,dl_src=00:00:00:00:00:06 -O Openflow13'
    )
    os.system(
        'ovs-ofctl del-flows sw1 cookie=0x0/-1,dl_dst=00:00:00:00:00:06 -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=3,dl_src=00:00:00:00:00:06 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:06 actions=3" -O Openflow13'
    )

    # time.sleep(1)
    # os.system('./framework_its_sdn/lc_mob_2.sh > j7.txt &')

    time.sleep(5)

    #os.system('./framework_its_sdn/local_controllers.sh > j3.txt &')

    time.sleep(65)

    #########################################################################Scenario C2 (t3)
    print("*** Starting C2 - T3")

    #os.system('fuser -k ./framework_its_sdn/local_controllers.sh')

    time.sleep(5)

    # cars[0].setPosition('2107,250,0')
    # cars[1].setPosition('2107,247,0')
    # cars[2].setPosition('2104,250,0')
    # cars[3].setPosition('2104,247,0')
    # cars[4].setPosition('2101,250,0')

    # cars[5].setPosition('1607,247,0')
    cars[6].setPosition('1604,247,0')
    cars[7].setPosition('1607,250,0')
    cars[8].setPosition('1601,247,0')

    cars[9].setPosition('1107,250,0')
    cars[10].setPosition('1104,247,0')

    # cars[11].setPosition('350,250,0')
    # cars[12].setPosition('400,243,0')
    # cars[13].setPosition('450,243,0')
    # cars[14].setPosition('500,243,0')

    os.system(
        'ovs-ofctl del-flows sw1 cookie=0x0/-1,dl_src=00:00:00:00:00:07 -O Openflow13'
    )
    os.system(
        'ovs-ofctl del-flows sw1 cookie=0x0/-1,dl_dst=00:00:00:00:00:07 -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=3,dl_src=00:00:00:00:00:07 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:07 actions=3" -O Openflow13'
    )

    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=3,dl_src=00:00:00:00:00:08 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:08 actions=3" -O Openflow13'
    )

    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=3,dl_src=00:00:00:00:00:09 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:09 actions=3" -O Openflow13'
    )

    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=2,dl_src=00:00:00:00:00:10 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:10 actions=2" -O Openflow13'
    )

    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=2,dl_src=00:00:00:00:00:11 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:11 actions=2" -O Openflow13'
    )

    # time.sleep(1)
    # os.system('./framework_its_sdn/lc_mob_2.sh > j7.txt &')

    time.sleep(5)

    #os.system('./framework_its_sdn/local_controllers.sh > j3.txt &')

    # for x in xrange(7,11):

    #     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 500kbps" %x)
    #     cars[x].cmd('arp -s 200.0.10.2 00:00:00:00:00:a2 &')
    #     cars[x].cmdPrint("timeout 330 hping3 --udp -p 5002 -i u24000 -d 1470 200.0.10.2 -q &")
    #     cars[x].cmdPrint("rm -f ping%d_s.txt" %x)
    #     cars[x].cmdPrint("ping 200.0.10.2 -i 1 -c 330 | while read line; do echo $(date +%%s) - $line >> ping%d_s.txt; done &" %x)

    #     print("*** Car[%d] connect to server_e at 500kbps" %x)
    #     cars[x].cmd('arp -s 200.0.10.3 00:00:00:00:00:a3 &')
    #     cars[x].cmdPrint("timeout 330 hping3 --udp -p 5003 -i u24000 -d 1470 200.0.10.3 -q &")
    #     cars[x].cmdPrint("rm -f ping%d_e.txt" %x)
    #     cars[x].cmdPrint("ping 200.0.10.3 -i 1 -c 330 | while read line; do echo $(date +%%s) - $line >> ping%d_e.txt; done &" %x)

    #     print("*** Car[%d] connect to server_e2 at 1Mbps" %x)
    #     cars[x].cmd('arp -s 200.0.10.4 00:00:00:00:00:a4 &')
    #     cars[x].cmdPrint("timeout 330 hping3 --udp -p 5004 -i u12000 -d 1470 200.0.10.4 -q &")
    #     cars[x].cmdPrint("rm -f ping%d_e2.txt" %x)
    #     cars[x].cmdPrint("ping 200.0.10.4 -i 1 -c 330 | while read line; do echo $(date +%%s) - $line >> ping%d_e2.txt; done &" %x)

    #     print("*** Car[%d] connect to server_g at 500kbps" %x)
    #     cars[x].cmd('arp -s 200.0.10.5 00:00:00:00:00:a5 &')
    #     cars[x].cmdPrint("timeout 330 hping3 --udp -p 5005 -i u24000 -d 1470 200.0.10.5 -q &")
    #     cars[x].cmdPrint("rm -f ping%d_g.txt" %x)
    #     cars[x].cmdPrint("ping 200.0.10.5 -i 1 -c 330 | while read line; do echo $(date +%%s) - $line >> ping%d_g.txt; done &" %x)

    time.sleep(65)

    #########################################################################Scenario C3 (t4)
    print("*** Starting C3 - T4")

    #os.system('fuser -k ./framework_its_sdn/local_controllers.sh')

    time.sleep(5)

    # cars[0].setPosition('2107,250,0')
    # cars[1].setPosition('2107,247,0')
    # cars[2].setPosition('2104,250,0')
    # cars[3].setPosition('2104,247,0')
    # cars[4].setPosition('2101,250,0')

    # cars[5].setPosition('1607,247,0')
    # cars[6].setPosition('1604,247,0')
    # cars[7].setPosition('1607,250,0')
    # cars[8].setPosition('1601,247,0')
    cars[9].setPosition('1604,250,0')
    cars[10].setPosition('1601,250,0')

    cars[11].setPosition('1107,250,0')
    cars[12].setPosition('1107,247,0')
    cars[13].setPosition('1104,250,0')
    cars[14].setPosition('1104,247,0')

    os.system(
        'ovs-ofctl del-flows sw1 cookie=0x0/-1,dl_src=00:00:00:00:00:10 -O Openflow13'
    )
    os.system(
        'ovs-ofctl del-flows sw1 cookie=0x0/-1,dl_dst=00:00:00:00:00:10 -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=3,dl_src=00:00:00:00:00:10 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:10 actions=3" -O Openflow13'
    )

    os.system(
        'ovs-ofctl del-flows sw1 cookie=0x0/-1,dl_src=00:00:00:00:00:11 -O Openflow13'
    )
    os.system(
        'ovs-ofctl del-flows sw1 cookie=0x0/-1,dl_dst=00:00:00:00:00:11 -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=3,dl_src=00:00:00:00:00:11 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:11 actions=3" -O Openflow13'
    )

    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=2,dl_src=00:00:00:00:00:12 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:12 actions=2" -O Openflow13'
    )

    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=2,dl_src=00:00:00:00:00:13 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:13 actions=2" -O Openflow13'
    )

    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=2,dl_src=00:00:00:00:00:14 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:14 actions=2" -O Openflow13'
    )

    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=2,dl_src=00:00:00:00:00:15 actions=1" -O Openflow13'
    )
    os.system(
        'ovs-ofctl add-flow sw1 "table=1, priority=1, cookie=0x0, in_port=1,dl_dst=00:00:00:00:00:15 actions=2" -O Openflow13'
    )

    time.sleep(5)

    #os.system('./framework_its_sdn/local_controllers.sh > j3.txt &')

    # time.sleep(1)
    # os.system('./framework_its_sdn/lc_mob_2.sh > j7.txt &')

    # for x in xrange(11,15):

    #     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 500kbps" %x)
    #     cars[x].cmd('arp -s 200.0.10.2 00:00:00:00:00:a2 &')
    #     cars[x].cmdPrint("timeout 330 hping3 --udp -p 5002 -i u24000 -d 1470 200.0.10.2 -q &")
    #     cars[x].cmdPrint("rm -f ping%d_s.txt" %x)
    #     cars[x].cmdPrint("ping 200.0.10.2 -i 1 -c 330 | while read line; do echo $(date +%%s) - $line >> ping%d_s.txt; done &" %x)

    #     print("*** Car[%d] connect to server_e at 500kbps" %x)
    #     cars[x].cmd('arp -s 200.0.10.3 00:00:00:00:00:a3 &')
    #     cars[x].cmdPrint("timeout 330 hping3 --udp -p 5003 -i u24000 -d 1470 200.0.10.3 -q &")
    #     cars[x].cmdPrint("rm -f ping%d_e.txt" %x)
    #     cars[x].cmdPrint("ping 200.0.10.3 -i 1 -c 330 | while read line; do echo $(date +%%s) - $line >> ping%d_e.txt; done &" %x)

    #     print("*** Car[%d] connect to server_e2 at 1Mbps" %x)
    #     cars[x].cmd('arp -s 200.0.10.4 00:00:00:00:00:a4 &')
    #     cars[x].cmdPrint("timeout 330 hping3 --udp -p 5004 -i u12000 -d 1470 200.0.10.4 -q &")
    #     cars[x].cmdPrint("rm -f ping%d_e2.txt" %x)
    #     cars[x].cmdPrint("ping 200.0.10.4 -i 1 -c 330 | while read line; do echo $(date +%%s) - $line >> ping%d_e2.txt; done &" %x)

    #     print("*** Car[%d] connect to server_g at 500kbps" %x)
    #     cars[x].cmd('arp -s 200.0.10.5 00:00:00:00:00:a5 &')
    #     cars[x].cmdPrint("timeout 330 hping3 --udp -p 5005 -i u24000 -d 1470 200.0.10.5 -q &")
    #     cars[x].cmdPrint("rm -f ping%d_g.txt" %x)
    #     cars[x].cmdPrint("ping 200.0.10.5 -i 1 -c 330 | while read line; do echo $(date +%%s) - $line >> ping%d_g.txt; done &" %x)

    time.sleep(75)

    os.system('pkill tcpdump')
    os.system('pkill hping3')
    os.system('pkill ping')
    time.sleep(2)

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

    info("*** Stopping network\n")
    net.stop()

    os.system('fuser -k ./framework_its_sdn/lc_mob.sh')
    os.system('fuser -k ./framework_its_sdn/central_controller2.sh')
    os.system('fuser -k ./framework_its_sdn/local_controllers.sh')
コード例 #9
0
def topology():
    "Create a network."
    net = Mininet_wifi(controller=RemoteController,
                       accessPoint=UserAP,
                       link=wmediumd,
                       wmediumd_mode=interference)

    info("*** Creating nodes: car\n")
    cars = []
    for id in range(0, 8):
        cars.append(net.addCar('car%s' % (id + 1), wlans=2, encrypt='wpa2,'))

    info("*** Creating nodes: rsu\n")
    rsus = []
    for id in range(0, 3):
        rsus.append(net.addCar('rsu%s' % (id + 1), wlans=2, encrypt='wpa2,'))

    info("*** Creating nodes: controller\n")
    c1 = net.addController(name='c1',
                           ip='127.0.0.1',
                           port=6653,
                           protocol='tcp')

    poss = ['100.00,100.00,0.0', '250.00,100.00,0.0', '400.00,100.00,0.0']
    e1 = net.addAccessPoint('e1',
                            ssid='vanet-ssid',
                            mac='00:00:00:11:00:01',
                            mode='g',
                            channel='1',
                            passwd='123456789a',
                            encrypt='wpa2',
                            position=poss[0])
    e2 = net.addAccessPoint('e2',
                            ssid='vanet-ssid',
                            mac='00:00:00:11:00:02',
                            mode='g',
                            channel='6',
                            passwd='123456789a',
                            encrypt='wpa2',
                            position=poss[1])
    e3 = net.addAccessPoint('e3',
                            ssid='vanet-ssid',
                            mac='00:00:00:11:00:03',
                            mode='g',
                            channel='1',
                            passwd='123456789a',
                            encrypt='wpa2',
                            position=poss[2])

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

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

    info("*** Adding link\n")
    net.addLink(rsus[0], rsus[1])
    net.addLink(rsus[1], rsus[2])

    net.addLink(e1, e2)
    net.addLink(e2, e3)

    for rsu in rsus:
        net.addLink(rsu,
                    intf=rsu.wintfs[1].name,
                    cls=mesh,
                    ssid='mesh-ssid',
                    channel=5)

    for car in cars:
        net.addLink(car,
                    intf=car.wintfs[1].name,
                    cls=mesh,
                    ssid='mesh-ssid',
                    channel=5)

    info("*** Starting sumo\n")
    # change config_file name if you want
    # use --random for active the probability attribute of sumo
    net.useExternalProgram(program=sumo,
                           port=8813,
                           config_file='map.sumocfg --random')

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

    for rsu in rsus:
        rsu.setIP('192.168.0.%s/24' % (int(rsus.index(rsu)) + 101),
                  intf='%s-wlan0' % rsu)
        rsu.setIP('192.168.1.%s/24' % (int(rsus.index(rsu)) + 101),
                  intf='%s-mp1' % rsu)

    for rsu, pos in zip(rsus, poss):
        rsu.setPosition(pos=pos)

    for car in cars:
        car.setIP('192.168.0.%s/24' % (int(cars.index(car)) + 1),
                  intf='%s-wlan0' % car)
        car.setIP('192.168.1.%s/24' % (int(cars.index(car)) + 1),
                  intf='%s-mp1' % car)

    info("*** Starting telemetry\n")
    # Track the position of the nodes
    nodes = net.cars + net.aps
    net.telemetry(nodes=nodes,
                  data_type='position',
                  min_x=0,
                  min_y=0,
                  max_x=650,
                  max_y=650)

    info("*** Starting agents\n")
    for car in net.cars:
        if car.name in [rsu.name for rsu in rsus]:
            car.cmd(
                f'xterm -e python -m network_agent --log -srnm --filename {car} --name={car} --verbose --rsu &'
            )
        else:
            car.cmd(
                f'xterm -e python -m network_agent --name={car} -srmn --verbose &'
            )

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

    info("*** Stopping network\n")
    net.stop()
コード例 #10
0
def topology():

    "Create a network."
    # net = Mininet_wifi(controller=None, switch=OVSKernelSwitch, link=wmediumd, wmediumd_mode=interference)
    net = Mininet_wifi(controller=None,
                       autoStaticArp=True,
                       switch=OVSKernelSwitch,
                       accessPoint=OVSKernelAP)

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

    info("*** Creating nodes\n")
    cars = []
    for x in range(0, 30):
        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',
                         position='1105,975,0')
    cars[1] = net.addCar('car1',
                         wlans=1,
                         range='50',
                         ip='200.0.10.111/8',
                         mac='00:00:00:00:00:02',
                         position='1110,975,0')
    cars[2] = net.addCar('car2',
                         wlans=1,
                         range='50',
                         ip='200.0.10.112/8',
                         mac='00:00:00:00:00:03',
                         position='1605,975,0')
    cars[3] = net.addCar('car3',
                         wlans=1,
                         range='50',
                         ip='200.0.10.113/8',
                         mac='00:00:00:00:00:04',
                         position='2105,975,0')
    cars[4] = net.addCar('car4',
                         wlans=1,
                         range='50',
                         ip='200.0.10.114/8',
                         mac='00:00:00:00:00:05',
                         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',
                         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',
                         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',
                         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',
                         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',
                         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',
                          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',
                          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',
                          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',
                          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',
                          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',
                          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',
                          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',
                          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',
                          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',
                          position='1120,975,0')

    cars[20] = net.addCar('car20',
                          wlans=1,
                          range='50',
                          ip='200.0.10.130/8',
                          mac='00:00:00:00:00:21',
                          position='20,1025,0')
    cars[21] = net.addCar('car21',
                          wlans=1,
                          range='50',
                          ip='200.0.10.131/8',
                          mac='00:00:00:00:00:22',
                          position='40,1025,0')
    cars[22] = net.addCar('car22',
                          wlans=1,
                          range='50',
                          ip='200.0.10.132/8',
                          mac='00:00:00:00:00:23',
                          position='60,1025,0')
    cars[23] = net.addCar('car23',
                          wlans=1,
                          range='50',
                          ip='200.0.10.133/8',
                          mac='00:00:00:00:00:24',
                          position='80,1025,0')
    cars[24] = net.addCar('car24',
                          wlans=1,
                          range='50',
                          ip='200.0.10.134/8',
                          mac='00:00:00:00:00:25',
                          position='100,1025,0')
    cars[25] = net.addCar('car25',
                          wlans=1,
                          range='50',
                          ip='200.0.10.135/8',
                          mac='00:00:00:00:00:26',
                          position='120,1025,0')
    cars[26] = net.addCar('car26',
                          wlans=1,
                          range='50',
                          ip='200.0.10.136/8',
                          mac='00:00:00:00:00:27',
                          position='140,1025,0')
    cars[27] = net.addCar('car27',
                          wlans=1,
                          range='50',
                          ip='200.0.10.137/8',
                          mac='00:00:00:00:00:28',
                          position='160,1025,0')
    cars[28] = net.addCar('car28',
                          wlans=1,
                          range='50',
                          ip='200.0.10.138/8',
                          mac='00:00:00:00:00:29',
                          position='180,1025,0')
    cars[29] = net.addCar('car29',
                          wlans=1,
                          range='50',
                          ip='200.0.10.139/8',
                          mac='00:00:00:00:00:30',
                          position='200,1025,0')

    # cars[30] = net.addCar('car30',  wlans=1, range='50', ip='200.0.10.140/8', mac='00:00:00:00:00:31', position='210,1025,0')
    # cars[31] = net.addCar('car31',  wlans=1, range='50', ip='200.0.10.141/8', mac='00:00:00:00:00:32', position='220,1025,0')
    # cars[32] = net.addCar('car32',  wlans=1, range='50', ip='200.0.10.142/8', mac='00:00:00:00:00:33', position='240,1025,0')
    # cars[33] = net.addCar('car33',  wlans=1, range='50', ip='200.0.10.143/8', mac='00:00:00:00:00:34', position='260,1025,0')
    # cars[34] = net.addCar('car34',  wlans=1, range='50', ip='200.0.10.144/8', mac='00:00:00:00:00:35', position='280,1025,0')
    # cars[35] = net.addCar('car35',  wlans=1, range='50', ip='200.0.10.145/8', mac='00:00:00:00:00:36', position='300,1025,0')
    # cars[36] = net.addCar('car36',  wlans=1, range='50', ip='200.0.10.146/8', mac='00:00:00:00:00:37', position='320,1025,0')
    # cars[37] = net.addCar('car37',  wlans=1, range='50', ip='200.0.10.147/8', mac='00:00:00:00:00:38', position='340,1025,0')
    # cars[38] = net.addCar('car38',  wlans=1, range='50', ip='200.0.10.148/8', mac='00:00:00:00:00:39', position='360,1025,0')
    # cars[39] = net.addCar('car39',  wlans=1, range='50', ip='200.0.10.149/8', mac='00:00:00:00:00:40', position='380,1025,0')

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

    rsu1 = net.addAccessPoint('rsu1',
                              ssid='rsu1',
                              channel='11',
                              range=250,
                              position='1100,1000,0',
                              protocols='OpenFlow13')
    rsu2 = net.addAccessPoint('rsu2',
                              ssid='rsu2',
                              channel='11',
                              range=250,
                              position='1600,1000,0',
                              protocols='OpenFlow13')
    rsu3 = net.addAccessPoint('rsu3',
                              ssid='rsu3',
                              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')

    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=18)
    link2.intf1.config(bw=6)
    link3.intf1.config(bw=6)
    link4.intf1.config(bw=6)

    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 set bridge rsu1 other-config:datapath-id=0000000000000006')
    os.system(
        'ovs-vsctl set bridge rsu2 other-config:datapath-id=0000000000000007')
    os.system(
        'ovs-vsctl set bridge rsu3 other-config:datapath-id=0000000000000008')

    time.sleep(1)

    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(2)

    # os.system('mysql -u root -pwifi < ./framework_its_sdn/initialdb.sql -fv &')
    # os.system('./framework_its_sdn/lc_mob.sh > j2.txt &')
    # time.sleep(1)
    # os.system('./framework_its_sdn/central_controller2.sh > j1.txt &')
    # os.system('./framework_its_sdn/local_controllers.sh > j3.txt &')

    # # time.sleep(1)

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

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

    # time.sleep(2)

    # for x in xrange(0,40):

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

    # print("Moving Car0 to RSU2")
    # cars[0].setPosition('1605,975,0')

    # time.sleep(33)

    # print("Moving Car0 to RSU3")
    # cars[0].setPosition('2105,975,0')

    # time.sleep(33)

    # print("Moving Car1 to RSU2")
    # cars[1].setPosition('1605,975,0')

    # time.sleep(33)

    # print("Moving Car2 to RSU3")
    # cars[2].setPosition('2105,975,0')

    # time.sleep(33)

    # print("Moving Car1 to RSU3")
    # cars[1].setPosition('2105,975,0')

    # time.sleep(33)

    # os.system('fuser -k ./framework_its_sdn/central_controller2.sh')
    # os.system('fuser -k ./framework_its_sdn/lc_mob.sh')
    # os.system('fuser -k ./framework_its_sdn/local_controllers.sh')

    # 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()
コード例 #11
0
def topology():

    "Create a network."
    net = Mininet_wifi(controller=Controller, accessPoint=UserAP,
                       link=wmediumd, wmediumd_mode=interference)

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

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

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

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

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

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

    net.useExternalProgram(program=sumo, port=8813,
                           config_file='map.sumocfg')

    info("*** Starting network\n")
    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('ip addr add 10.0.0.%s dev %s' % (i, sw))
        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

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

    info("*** Stopping network\n")
    net.stop()
コード例 #12
0
def topology():

    "Create a network."
    net = Mininet_wifi(controller=Controller,
                       accessPoint=UserAP,
                       link=wmediumd,
                       wmediumd_mode=interference)

    info("*** Creating graph\n")
    G = nx.Graph()
    e = [('1', '2', 0.4), ('1', '3', 0.3), ('2', '4', 0.8), ('3', '4', 0.6),
         ('2', '3', 1.2)]
    G.add_weighted_edges_from(e)

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

    cars = []
    for id in range(0, 10):
        cars.append(
            net.addCar('car%s' % (id + 1), wlans=2,
                       ip='10.0.0.%s/8' % (x + 1)))

    rsus = {}

    for i in range(0, 4):
        for j in range(1, 4):
            magic = (i * 3 + j)
            channel = "%s" % (5 * j - 4)
            name = "e%s" % (magic)
            mac = "00:00:00:11:00:0%s" % (hex(magic)[2])

            if i % 2 == 0:
                pos = "%d,%d,0" % ((j - 1) * 2000 + 1000, (i + 1) * 1000)
            else:
                pos = "%d,%d,0" % ((3 - j) * 2000, (i + 1) * 1000)

            rsu = net.addAccessPoint(name,
                                     ssid='vanet-ssid%s' % (magic),
                                     mac=mac,
                                     mode='g',
                                     channel=channel,
                                     position=pos)
            rsus["e%d" % (magic)] = rsu
            # print ("RSU%d, pos %s, channel %s" % (magic , pos, channel))

    c1 = net.addController('c1')

    info("*** file placement\n")
    X = fp.FilePlacement(number_of_caches=len(rsus),
                         min_cache_size=10,
                         number_of_files=number_of_files,
                         max_cache_size=14)
    R = req.Requests(number_of_cars=10,
                     min_req_size=5,
                     max_req_size=10,
                     number_of_files=number_of_files)

    # info("*** Setting bgscan\n")
    # net.setBgscan(signal=0, s_inverval=1, l_interval=10)

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

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

    for i in range(1, 12):
        net.addLink("e%d" % (i), "e%d" % (i + 1))

    net.useExternalProgram(program=sumo,
                           port=8813,
                           config_file='bolognaringway.sumo.cfg')

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

    # net.startMobility(time=0)

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

    for i in rsus:
        rsus[i].start([c1])

    for car in cars:
        car.setIP('192.168.0.%s/24' % (int(cars.index(car)) + 1),
                  intf='%s-wlan0' % car)
        car.setIP('192.168.1.%s/24' % (int(cars.index(car)) + 1),
                  intf='%s-mp1' % car)

    t = timer.MyTimer(interval)
    t2 = timer.MyTimer(req_update_interval)
    t3 = timer.MyTimer(cache_update_interval)
    t.set_interval(show_cars_positions, {
        "cars": cars,
        "rsus": rsus,
        "X": X,
        "R": R,
        "G": G
    })
    t2.set_interval(R.update_req, {})
    t3.set_interval(X.mobile_RSU, {"G": G})

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

    info("*** Stopping network\n")
    t.stop_intervals()
    t2.stop_intervals()
    t3.stop_intervals()
    net.stop()
    os.system(
        "sudo ps -aux | sudo grep sumo-gui | sudo awk '{print $2}' | sudo head -n 1 | sudo xargs kill"
    )
    os.system("sudo mn -c")
コード例 #13
0
def topology():

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

    info("*** Creating nodes\n")
    cars = []
    for x in range(0, 2):
        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='2101,1000,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='2103,1000,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')

    # cars[20] = net.addCar('car20', wlans=1, range='50', ip='200.0.10.130/8', mac='00:00:00:00:00:21', mode='g', position='20,1025,0')
    # cars[21] = net.addCar('car21', wlans=1, range='50', ip='200.0.10.131/8', mac='00:00:00:00:00:22', mode='g', position='40,1025,0')
    # cars[22] = net.addCar('car22', wlans=1, range='50', ip='200.0.10.132/8', mac='00:00:00:00:00:23', mode='g', position='60,1025,0')
    # cars[23] = net.addCar('car23', wlans=1, range='50', ip='200.0.10.133/8', mac='00:00:00:00:00:24', mode='g', position='80,1025,0')
    # cars[24] = net.addCar('car24', wlans=1, range='50', ip='200.0.10.134/8', mac='00:00:00:00:00:25', mode='g', position='100,1025,0')
    # cars[25] = net.addCar('car25', wlans=1, range='50', ip='200.0.10.135/8', mac='00:00:00:00:00:26', mode='g', position='120,1025,0')
    # cars[26] = net.addCar('car26', wlans=1, range='50', ip='200.0.10.136/8', mac='00:00:00:00:00:27', mode='g', position='140,1025,0')
    # cars[27] = net.addCar('car27', wlans=1, range='50', ip='200.0.10.137/8', mac='00:00:00:00:00:28', mode='g', position='160,1025,0')
    # cars[28] = net.addCar('car28', wlans=1, range='50', ip='200.0.10.138/8', mac='00:00:00:00:00:29', mode='g', position='180,1025,0')
    # cars[29] = net.addCar('car29', wlans=1, range='50', ip='200.0.10.139/8', mac='00:00:00:00:00:30', mode='g', position='200,1025,0')
    # cars[30] = net.addCar('car30', wlans=1, range='50', ip='200.0.10.140/8', mac='00:00:00:00:00:31', mode='g', position='210,1025,0')
    # cars[31] = net.addCar('car31', wlans=1, range='50', ip='200.0.10.141/8', mac='00:00:00:00:00:32', mode='g', position='220,1025,0')
    # cars[32] = net.addCar('car32', wlans=1, range='50', ip='200.0.10.142/8', mac='00:00:00:00:00:33', mode='g', position='240,1025,0')
    # cars[33] = net.addCar('car33', wlans=1, range='50', ip='200.0.10.143/8', mac='00:00:00:00:00:34', mode='g', position='260,1025,0')
    # cars[34] = net.addCar('car34', wlans=1, range='50', ip='200.0.10.144/8', mac='00:00:00:00:00:35', mode='g', position='280,1025,0')
    # cars[35] = net.addCar('car35', wlans=1, range='50', ip='200.0.10.145/8', mac='00:00:00:00:00:36', mode='g', position='300,1025,0')
    # cars[36] = net.addCar('car36', wlans=1, range='50', ip='200.0.10.146/8', mac='00:00:00:00:00:37', mode='g', position='320,1025,0')
    # cars[37] = net.addCar('car37', wlans=1, range='50', ip='200.0.10.147/8', mac='00:00:00:00:00:38', mode='g', position='340,1025,0')
    # cars[38] = net.addCar('car38', wlans=1, range='50', ip='200.0.10.148/8', mac='00:00:00:00:00:39', mode='g', position='360,1025,0')
    # cars[39] = net.addCar('car39', wlans=1, range='50', ip='200.0.10.149/8', mac='00:00:00:00:00:40', mode='g', position='380,1025,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')
    sw2 = net.addSwitch('sw2', dpid='10', protocols='OpenFlow13')

    server_s1 = net.addHost('server_s1', ip='200.0.10.2/8')
    server_s2 = net.addHost('server_s2', ip='200.0.10.2/8')
    server_s3 = net.addHost('server_s3', 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_g = net.addHost('server_g', ip='200.0.10.5/8')

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

    # net.useIFB()

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

    print("*** Creating links")
    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)

    # net.associationControl('ssf')

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

    # for sw in net.carsSW:
    #     sw.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 &')

    # 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()
コード例 #14
0
def topology():

    taskTime = 20
    ncars = 4

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

    info("*** Creating nodes\n")
    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')

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

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

    info("*** Creating links\n")
    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)

    info("*** Starting network\n")
    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

    info("Moving nodes\n")
    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)

    info("applying second rule\n")
    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

    info("Moving nodes\n")
    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)

    info("applying third rule\n")
    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

    info("*** Generating graph\n")
    graphic()

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

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

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

    info("*** Stopping network\n")
    net.stop()
コード例 #15
0
ファイル: vanet.py プロジェクト: soreana/vanet-bandit
def topology():

    "Create a network."
    net = Mininet_wifi(controller=Controller,
                       link=wmediumd,
                       wmediumd_mode=interference)

    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.setPropagationModel(model="logDistance", exp=3.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))
        # sw.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward')
        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)
        # car.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward')
        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()
コード例 #16
0
def topology():

    "Create a network."
    net = Mininet_wifi(link=wmediumd, wmediumd_mode=interference)

    info("*** Creating nodes\n")
    for id in range(0, 10):
        net.addCar('car%s' % (id + 1), wlans=2, encrypt=['wpa2', ''])

    kwargs = {
        'ssid': 'vanet-ssid',
        'mode': 'g',
        'passwd': '123456789a',
        'encrypt': 'wpa2',
        'failMode': 'standalone',
        'datapath': 'user'
    }
    e1 = net.addAccessPoint('e1',
                            mac='00:00:00:11:00:01',
                            channel='1',
                            position='2600,3500,0',
                            **kwargs)
    e2 = net.addAccessPoint('e2',
                            mac='00:00:00:11:00:02',
                            channel='6',
                            position='2800,3500,0',
                            **kwargs)
    e3 = net.addAccessPoint('e3',
                            mac='00:00:00:11:00:03',
                            channel='11',
                            position='3000,3500,0',
                            **kwargs)
    e4 = net.addAccessPoint('e4',
                            mac='00:00:00:11:00:04',
                            channel='1',
                            position='2600,3300,0',
                            **kwargs)
    e5 = net.addAccessPoint('e5',
                            mac='00:00:00:11:00:05',
                            channel='6',
                            position='2800,3300,0',
                            **kwargs)
    e6 = net.addAccessPoint('e6',
                            mac='00:00:00:11:00:06',
                            channel='11',
                            position='3000,3300,0',
                            **kwargs)

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

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

    net.addLink(e1, e2)
    net.addLink(e2, e3)
    net.addLink(e3, e4)
    net.addLink(e4, e5)
    net.addLink(e5, e6)
    for car in net.cars:
        net.addLink(car,
                    intf=car.wintfs[1].name,
                    cls=ITSLink,
                    band=20,
                    channel=181)

    net.useExternalProgram(program=sumo, port=8813, config_file='map.sumocfg')

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

    for enb in net.aps:
        enb.start([])

    for id, car in enumerate(net.cars):
        car.setIP('192.168.0.%s/24' % (id + 1), intf='%s-wlan0' % car.name)
        car.setIP('192.168.1.%s/24' % (id + 1), intf='%s-wlan1' % car.name)

    # Track the position of the nodes
    """nodes = net.cars + net.aps
    net.telemetry(nodes=nodes, data_type='position',
                  min_x=2200, min_y=2800,
                  max_x=3200, max_y=3900)"""

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

    info("*** Stopping network\n")
    net.stop()
コード例 #17
0
ファイル: vanet-sumo.py プロジェクト: soeun727/mininet-wifi
def topology():

    "Create a network."
    net = Mininet_wifi(controller=Controller,
                       accessPoint=UserAP,
                       link=wmediumd,
                       wmediumd_mode=interference)

    info("*** Creating nodes\n")
    for id in range(0, 10):
        net.addCar('car%s' % (id + 1), wlans=2, encrypt=['wpa2', ''])

    e1 = net.addAccessPoint('e1',
                            ssid='vanet-ssid',
                            mac='00:00:00:11:00:01',
                            mode='g',
                            channel='1',
                            passwd='123456789a',
                            encrypt='wpa2',
                            position='2600,3500,0')
    e2 = net.addAccessPoint('e2',
                            ssid='vanet-ssid',
                            mac='00:00:00:11:00:02',
                            mode='g',
                            channel='6',
                            passwd='123456789a',
                            encrypt='wpa2',
                            position='2800,3500,0')
    e3 = net.addAccessPoint('e3',
                            ssid='vanet-ssid',
                            mac='00:00:00:11:00:03',
                            mode='g',
                            channel='11',
                            passwd='123456789a',
                            encrypt='wpa2',
                            position='3000,3500,0')
    e4 = net.addAccessPoint('e4',
                            ssid='vanet-ssid',
                            mac='00:00:00:11:00:04',
                            mode='g',
                            channel='1',
                            passwd='123456789a',
                            encrypt='wpa2',
                            position='2600,3300,0')
    e5 = net.addAccessPoint('e5',
                            ssid='vanet-ssid',
                            mac='00:00:00:11:00:05',
                            mode='g',
                            channel='6',
                            passwd='123456789a',
                            encrypt='wpa2',
                            position='2800,3300,0')
    e6 = net.addAccessPoint('e6',
                            ssid='vanet-ssid',
                            mac='00:00:00:11:00:06',
                            mode='g',
                            channel='11',
                            passwd='123456789a',
                            encrypt='wpa2',
                            position='3000,3300,0')
    c1 = net.addController('c1')

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

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

    net.addLink(e1, e2)
    net.addLink(e2, e3)
    net.addLink(e3, e4)
    net.addLink(e4, e5)
    net.addLink(e5, e6)
    for car in net.cars:
        net.addLink(car,
                    intf=car.wintfs[1].name,
                    cls=mesh,
                    ssid='mesh-ssid',
                    channel=5)

    net.useExternalProgram(program=sumo, port=8813, config_file='map.sumocfg')

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

    for car in net.cars:
        car.setIP('192.168.0.%s/24' % (int(net.cars.index(car)) + 1),
                  intf='%s-wlan0' % car.name)
        car.setIP('192.168.1.%s/24' % (int(net.cars.index(car)) + 1),
                  intf='%s-mp1' % car.name)

    # Track the position of the nodes
    #nodes = net.cars + net.aps
    #net.telemetry(nodes=nodes, data_type='position',
    #              min_x=2200, min_y=2800,
    #              max_x=3200, max_y=3900)

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

    info("*** Stopping network\n")
    net.stop()
コード例 #18
0
def topology():

    os.system('sudo fuser -k 6653/tcp')
    os.system('sudo fuser -k 6690/tcp')
    os.system('sudo fuser -k 6691/tcp')
    os.system('systemctl stop firewalld')
    os.system('service network-manager stop')

    "Create a network."
    net = Mininet_wifi(
        controller=InbandController,
        link=wmediumd,
        wmediumd_mode=interference,
        accessPoint=OVSAP,
    )

    ip_c0 = '10.0.0.101'
    ip_c1 = '10.0.0.102'
    ip_c2 = '10.0.0.103'

    info("*** Creating nodes\n")
    cars = []
    for id in range(0, 10):
        cars.append(net.addCar('car%s' % (id + 1), wlans=2, encrypt='wpa2,'))
        #cars.append(net.addCar('car%s' % (id+1), wlans=2, passwd='123456789a,123456789a', encrypt='wpa2,wpa2'))

    enb1 = net.addAccessPoint('enb1',
                              mac='00:00:00:00:00:01',
                              ssid="handover",
                              mode="g",
                              channel="1",
                              datapath='user',
                              passwd='123456789a',
                              encrypt='wpa2',
                              mobility_domain='a1b2',
                              dpid='1',
                              position='3279.02,3736.27,0',
                              inband=True)
    enb2 = net.addAccessPoint('enb2',
                              mac='00:00:00:00:00:02',
                              ssid="handover",
                              mode="g",
                              channel="6",
                              datapath='user',
                              passwd='123456789a',
                              encrypt='wpa2',
                              mobility_domain='a1b2',
                              dpid='2',
                              position='2320.82,3565.75,0',
                              color='r',
                              inband=True)
    enb3 = net.addAccessPoint('enb3',
                              mac='00:00:00:00:00:03',
                              ssid="handover",
                              mode="g",
                              channel="11",
                              datapath='user',
                              passwd='123456789a',
                              encrypt='wpa2',
                              mobility_domain='a1b2',
                              dpid='3',
                              position='2806.42,3395.22,0',
                              inband=True)
    # backbone1 = net.addSwitch('backbone1', mac='00:00:00:00:00:04', dpid='4',
    #                          failMode='standalone')
    h1 = net.addHost('h1', ip=ip_c0)
    h2 = net.addHost('h2', ip=ip_c1)
    h3 = net.addHost('h3', ip=ip_c2)
    server1 = net.addHost('server1', ip='10.0.0.100/8')
    c0 = net.addController('c0',
                           controller=InbandController,
                           port=6653,
                           ip=ip_c0)
    c1 = net.addController('c1',
                           controller=InbandController,
                           port=6690,
                           ip=ip_c1)
    c2 = net.addController('c2',
                           controller=InbandController,
                           port=6691,
                           ip=ip_c2)

    net.setPropagationModel(model="logDistance", exp=2)
    info("*** Configuring wifi nodes\n")
    net.configureWifiNodes()
    info("*** Associating Stations\n")
    # net.addLink(backbone1, enb1)
    # net.addLink(backbone1, enb2)
    # net.addLink(backbone1, enb3)
    # net.addLink(backbone1, server1)
    net.addLink(h1, enb1)
    net.addLink(h2, enb2)
    net.addLink(h3, enb3)

    #net.plotGraph(max_x=200, max_y=200)
    net.useExternalProgram(program=sumo, port=8813, config_file='map.sumocfg')

    net.setBgscan(signal=-60, s_inverval=5, l_interval=10)

    info("*** Starting network\n")
    net.build()
    #net.addNAT().configDefault()
    enb1.start([c0])
    enb2.start([c1])
    enb3.start([c2])
    # backbone1.start([])

    sleep(3)

    enb1.cmdPrint('sysctl net.ipv4.ip_forward=1')
    enb2.cmdPrint('sysctl net.ipv4.ip_forward=1')
    enb3.cmdPrint('sysctl net.ipv4.ip_forward=1')

    enb1.cmdPrint('ifconfig enb1-eth2 10.0.0.201')
    enb2.cmdPrint('ifconfig enb2-eth2 10.0.0.202')
    enb3.cmdPrint('ifconfig enb3-eth2 10.0.0.203')

    enb1.cmD('route add 10.0.0.101 dev enb1-eth2')
    enb2.cmd('route add 10.0.0.102 dev enb2-eth2')
    enb3.cmd('route add 10.0.0.103 dev enb3-eth2')

    cars[0].cmd('iw dev %s-wlan0 interface '
                'add %s-mon0 type monitor' % (cars[0].name, cars[0].name))
    cars[0].cmd('ifconfig %s-mon0 up' % cars[0].name)
    cars[0].cmd('ifconfig %s-wlan0 10.0.0.1' % cars[0].name)
    cars[0].cmd('route add default gw 10.0.0.12')
    cars[0].cmd('ifconfig lo up')

    #enb1.cmdPrint('dpctl unix:/tmp/enb1 flow-mod table=0,cmd=add in_port=1,eth_type=0x800,ip_proto=17,udp_src=8000 apply:output=ctrl')
    #enb2.cmdPrint('dpctl unix:/tmp/enb2 flow-mod table=0,cmd=add in_port=1,eth_type=0x800,ip_proto=17,udp_src=8000 apply:output=ctrl')
    #enb1.cmdPrint('dpctl unix:/tmp/enb1 flow-mod table=0,cmd=add in_port=1,ip_proto=17,udp_src=8000 apply:output=ctrl')
    #enb2.cmdPrint('dpctl unix:/tmp/enb2 flow-mod table=0,cmd=add in_port=1,ip_proto=17,udp_src=8000 apply:output=ctrl')
    #enb3.cmdPrint('dpctl unix:/tmp/enb3 flow-mod table=0,cmd=add in_port=1,ip_proto=17,udp_src=8000 apply:output=ctrl')
    #enb1.cmdPrint('dpctl unix:/tmp/enb1 flow-mod table=0,cmd=add in_port=2,ip_proto=17,udp_dst=8000 apply:output=1')
    #enb2.cmdPrint('dpctl unix:/tmp/enb2 flow-mod table=0,cmd=add in_port=2,ip_proto=17,udp_dst=8000 apply:output=1')
    #enb3.cmdPrint('dpctl unix:/tmp/enb3 flow-mod table=0,cmd=add in_port=2,ip_proto=17,udp_dst=8000 apply:output=1')
    #enb1.cmd('ovs-ofctl add-flow "enb1" in_port=1,udp,tp_src=8000,actions=controller')
    #enb2.cmd('ovs-ofctl add-flow "enb2" in_port=1,udp,tp_src=8000,actions=controller')
    #enb3.cmd('ovs-ofctl add-flow "enb3" in_port=1,udp,tp_src=8000,actions=controller')
    #makeTerm(cars[0], cmd="bash -c 'ping 10.0.0.100 -c200 > ping.txt;'")
    makeTerm(h1, cmd="bash -c 'cd ryu && ./test.sh h1;'")
    makeTerm(h2, cmd="bash -c 'cd ryu && ./test.sh h2;'")
    makeTerm(h3, cmd="bash -c 'cd ryu && ./test.sh h3;'")
    cars[0].cmd(' python %s.py &' % cars[0].name)

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

    os.system('pkill -f \"xterm -title\"')
    os.system('pkill sumo-gui')
    os.system('pkill ryu-manager')

    info("*** Stopping network\n")
    net.stop()
コード例 #19
0
ファイル: vanet.py プロジェクト: intrig-unicamp/mininet-wifi
def topology():

    "Create a network."
    net = Mininet_wifi(controller=Controller,
                       link=wmediumd,
                       wmediumd_mode=interference)

    info("*** Creating nodes\n")
    cars = []
    for id in range(0, 10):
        min_ = randint(1, 4)
        max_ = randint(11, 30)
        cars.append(net.addCar('car%s' % (id+1), wlans=2,
                               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')

    info("*** Configuring Propagation Model\n")
    net.setPropagationModel(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)
    for car in cars:
        net.addLink(car, intf=car.params['wlan'][1],
                    cls=mesh, ssid='mesh-ssid', channel=5)

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

    for car in cars:
        car.setIP('192.168.0.%s/24' % (int(cars.index(car))+1),
                  intf='%s-wlan0' % car)
        car.setIP('192.168.1.%s/24' % (int(cars.index(car))+1),
                  intf='%s-mp1' % car)

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

    info("*** Stopping network\n")
    net.stop()
コード例 #20
0
ファイル: sumo_vndn_new.py プロジェクト: awlane/mini-ndn
def build_sumo_vndn(vndnTopo, ssid, channel, mode, wmediumd, interference,
                    cluster, placement, servers, tunnelType, ctime, nPings,
                    pctTraffic, experimentName, nlsrSecurity):

    "Create a network."
    net = Mininet_wifi(host=NdnHost,
                       station=NdnStation,
                       car=NdnCar,
                       controller=Controller,
                       accessPoint=UserAP,
                       link=wmediumd,
                       wmediumd_mode=interference)

    info("*** Creating nodes\n")

    for carName in vndnTopo.hosts():
        if 'car' in str(carName):
            net.addCar(carName, wlans=1, **vndnTopo.nodeInfo(carName))
            #net.addCar(carName, **vndnTopo.nodeInfo(carName))

    e1 = net.addAccessPoint('e1',
                            ssid='vanet-ssid',
                            mac='00:00:00:11:00:01',
                            mode='g',
                            channel='1',
                            passwd='123456789a',
                            encrypt='wpa2',
                            position='3279.02,3736.27,0')
    e2 = net.addAccessPoint('e2',
                            ssid='vanet-ssid',
                            mac='00:00:00:11:00:02',
                            mode='g',
                            channel='6',
                            passwd='123456789a',
                            encrypt='wpa2',
                            position='2320.82,3565.75,0')

    c1 = net.addController('c1')

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

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

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

    net.addLink(e1, e2)

    for car in net.cars:
        #net.addLink(car, intf=car.params['wlan'][1],
        #            cls=mesh, ssid='mesh-ssid', channel=5)
        net.addLink(car, cls=adhoc, ssid='mesh-ssid', mode='g', channel=5)

    net.useExternalProgram(program=sumo, port=8813, config_file='map.sumocfg')

    info("*** Starting network\n")
    net.build()
    c1.start()
    e1.start([c1])
    e2.start([c1])
    '''i = 1
    for car in net.cars:
        car.setIP('192.168.0.%s/24' % str(i),
                  intf='%s-wlan0' % car)
        car.setIP('192.168.1.%s/24' % str(i),
                  intf='%s-mp1' % car)
	i+=1	
    '''
    for car in net.cars:
        car.nfd = Nfd(car, 65536)
        car.nfd.start()
        #Nfdc.setStrategy(car, "/vanet", "vanet")
        #cmd = "nfdc strategy set /vanet ndn:/localhost/nfd/strategy/vanet/"

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

    info("*** Stopping network\n")
    net.stop()

    info('Cleaning up...')
    call(["nfd-stop"])
    call(["sudo", "mn", "--clean"])
    call(["sudo", "pkill", "sumo"])
    sys.exit(1)