Beispiel #1
0
def topology():
    "Adding network details for a containerized topology"

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

    info('***** Adding BIRD Routers *****\n')
    r1 = net.addDocker('r1', ip='10.10.1.1/24', dimage='bird:tanmay')
    r2 = net.addDocker('r2', ip='10.11.1.1/24', dimage='bird:tanmay')
    r3 = net.addDocker('r3', ip='10.20.1.1/24', dimage='bird:tanmay')
    r4 = net.addDocker('r4', ip='10.21.1.1/24', dimage='bird:tanmay')
    r5 = net.addDocker('r5', ip='192.168.99.2/24', dimage='bird:tanmay')

    info('***** Adding Hosts *****\n')
    h1 = net.addDocker('h1',
                       ip='10.10.1.2/24',
                       defaultRoute='via 10.10.1.1',
                       dimage='ubuntu:focal')
    h2 = net.addDocker('h2',
                       ip='10.11.1.2/24',
                       defaultRoute='via 10.11.1.1',
                       dimage='ubuntu:focal')
    h3 = net.addDocker('h3',
                       ip='10.20.1.2/24',
                       defaultRoute='via 10.20.1.1',
                       dimage='ubuntu:focal')
    h4 = net.addDocker('h4',
                       ip='10.21.1.2/24',
                       defaultRoute='via 10.21.1.1',
                       dimage='ubuntu:focal')

    info('***** Adding Switches *****\n')
    sdn_r1 = net.addSwitch('sdn_r1')
    sdn_r2 = net.addSwitch('sdn_r2')

    info('***** Creating Links *****\n')
    net.addLink(h1, r1)
    net.addLink(h2, r2)
    net.addLink(h3, r3)
    net.addLink(h4, r4)

    net.addLink(r1, sdn_r1, params1={'ip': '192.168.101.2/24'})
    net.addLink(r2, sdn_r1, params1={'ip': '192.168.102.2/24'})

    net.addLink(r3, sdn_r2, params1={'ip': '192.168.201.2/24'})
    net.addLink(r4, sdn_r2, params1={'ip': '192.168.202.2/24'})
    net.addLink(sdn_r1, r5)
    net.addLink(r5, sdn_r2, params1={'ip': '192.168.98.2/24'})
    net.addLink(sdn_r1, sdn_r2)

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

    #Adding management interface on router sdn 1
    cmd1 = 'sudo ip addr add 192.168.101.1/24 dev sdn_r1'
    cmd2 = 'sudo ip addr add 192.168.102.1/24 dev sdn_r1'
    cmd3 = 'sudo ip addr add 192.168.99.1/24 dev sdn_r1'
    cmd4 = 'sudo ip link set sdn_r1 up'
    os.system(cmd1)
    os.system(cmd2)
    os.system(cmd3)
    os.system(cmd4)
    cmd5 = 'sudo ovs-vsctl set bridge sdn_r1 other-config:disable-in-band=true'
    os.system(cmd5)

    #Adding management interface on router sdn 2
    cmd1 = 'sudo ip addr add 192.168.201.1/24 dev sdn_r2'
    cmd2 = 'sudo ip addr add 192.168.202.1/24 dev sdn_r2'
    cmd3 = 'sudo ip addr add 192.168.98.1/24 dev sdn_r2'
    cmd4 = 'sudo ip link set sdn_r2 up'
    os.system(cmd1)
    os.system(cmd2)
    os.system(cmd3)
    os.system(cmd4)
    cmd5 = 'sudo ovs-vsctl set bridge sdn_r2 other-config:disable-in-band=true'
    os.system(cmd5)

    #copying BIRD configs in respective dockers
    os.system('sudo docker cp r1.conf mn.r1:/etc/bird.conf')
    os.system('sudo docker cp r2.conf mn.r2:/etc/bird.conf')
    os.system('sudo docker cp r3.conf mn.r3:/etc/bird.conf')
    os.system('sudo docker cp r4.conf mn.r4:/etc/bird.conf')
    os.system('sudo docker cp r5.conf mn.r5:/etc/bird.conf')
    r1.cmd('bird -c /etc/bird.conf')
    r2.cmd('bird -c /etc/bird.conf')
    r3.cmd('bird -c /etc/bird.conf')
    r4.cmd('bird -c /etc/bird.conf')
    r5.cmd('bird -c /etc/bird.conf')

    info('***** Running CLI *****\n')
    CLI(net)
    info('***** Stopping network *****\n')
    net.stop()
Beispiel #2
0
def topology():
    "Create a network."
    net = Mininet(controller=Controller, link=TCLink, accessPoint=OVSKernelAP)

    print "*** Creating nodes"
    sta1 = net.addStation('sta1')
    sta2 = net.addStation('sta2')
    sta3 = net.addStation('sta3')
    ap1 = net.addAccessPoint('ap1', ssid='ssid-ap1', mode='g', channel='11', position='100,100,0', range=100)
    c1 = net.addController('c1', controller=Controller)

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

    sta1.setIP('10.0.0.1/8', intf="sta1-wlan0")
    sta2.setIP('10.0.0.2/8', intf="sta2-wlan0")
    sta3.setIP('10.0.0.3/8', intf="sta3-wlan0")

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

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

    net.associationControl('ssf')

    net.startMobility(time=0)
    net.mobility(sta1, 'start', time=1, position='8,100,0')
    net.mobility(sta2, 'start', time=1, position='1,107,0')
    net.mobility(sta3, 'start', time=1, position='1,93,0')
    net.mobility(sta1, 'stop', time=250, position='199,100,0')
    net.mobility(sta2, 'stop', time=250, position='192,107,0')
    net.mobility(sta3, 'stop', time=250, position='192,93,0')
    net.stopMobility(time=250)

    sleep(2)

    s1 = net.get('sta1')
    s2 = net.get('sta2')
    s3 = net.get('sta3')
    popens = {} # Python subprocess.Popen objects keyed by Mininet hosts
    startTime = int(time()) + SYNC_START
    endTime = startTime + EXPERIMENT_DURATION 

    print "*** Starting %d second experiment in %d second(s) - at Unix epoch: %d..." % (
      EXPERIMENT_DURATION, (startTime - int(time())), startTime)

    popens[s1] = s1.popen(EXECUTABLE_PATH, '-role=l', '-addr=%s' % s1.IP(), 
      '-dsts=%s,%s' % (s2.IP(), s3.IP()), '-start=%d' % startTime)
    popens[s2] = s2.popen(EXECUTABLE_PATH, '-role=f', 
      '-addr=%s' % s2.IP(), '-start=%d' % startTime)
    popens[s3] = s3.popen(EXECUTABLE_PATH, '-role=f', 
      '-addr=%s' % s3.IP(), '-start=%d' % startTime)

    with open(OUTPUT_FILE, 'w') as f:
      for h, line in pmonitor(popens, timeoutms=500):
        if h:
          f.write('<%s>: %s' % (h.name, line))
        if time() >= endTime:
          break

    popens[s1].send_signal(SIGINT)
    popens[s2].send_signal(SIGINT)
    popens[s3].send_signal(SIGINT)

    f.close()

    print "*** Ending experiment..."

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

    print "*** Stopping network"
    net.stop()
def mcastTest(topo, cnet_topo, interactive = False, hosts = [], log_file_name = 'test_log.log', util_link_weight = 10, link_weight_type = 'linear'):
    membership_mean = 0.1
    membership_std_dev = 0.25
    membership_avg_bound = float(len(hosts)) / 8.0
    test_groups = []
    test_group_launch_times = []
    
    # Launch the control plane network
    print 'Building control network...'
    controller_switch, metric_val, con_path_map = cnet_topo.get_controller_placement(LATENCY_METRIC_MIN_AVERAGE_DELAY)
    cnet_topo.addHost('pox', cls=DataController, ip='192.168.123.254', port=6634, inNamespace=True)
    cnet_topo.addLink(controller_switch, 'pox', bw=1000, use_htb=True)
    root = cnet_topo.addHost('root', inNamespace=False)
    cnet_topo.addLink(root, controller_switch)
    cnet = Mininet( topo=cnet_topo, ipBase='192.168.123.0/24', controller=None, switch=UserSwitch, link=TCLink, build=False, autoSetMacs=False)
    cnet.addController( 'cc0', controller=Controller )
    cnet.start()
    print 'Control network launched.'
    
    # Launch the external controller
    pox_arguments = ['pox.py', 'log', '--file=pox.log,w', 'openflow.of_01', '--address=192.168.123.254', '--port=6634', 'openflow.discovery',
            'openflow.flow_tracker', '--query_interval=1', '--link_max_bw=30', '--link_cong_threshold=30', '--avg_smooth_factor=0.65', '--log_peak_usage=True',
            'misc.benchmark_terminator', 'openflow.igmp_manager', 
            'openflow.groupflow', '--util_link_weight=' + str(util_link_weight), '--link_weight_type=' + link_weight_type,
            'log.level', '--WARNING', '--openflow.discovery=DEBUG', '--openflow.igmp_manager=DEBUG', '--openflow.flow_tracker=INFO']
    print 'Launching external controller: ' + str(pox_arguments[0])
    print 'Launch arguments:'
    print ' '.join(pox_arguments)
    
    with open(os.devnull, "w") as fnull:
        pox_process = cnet.get(controller_switch).popen(pox_arguments, stdout=fnull, stderr=fnull, shell=False, close_fds=True)
        # Allow time for the log file to be generated
        sleep(1)
    
    # Determine the flow tracker log file
    pox_log_file = open('./pox.log', 'r')
    flow_log_path = None
    event_log_path = ''
    got_flow_log_path = False
    got_event_log_path = True
    while (not got_flow_log_path) or (not got_event_log_path):
        pox_log = pox_log_file.readline()

        if 'Writing flow tracker info to file:' in pox_log:
            pox_log_split = pox_log.split()
            flow_log_path = pox_log_split[-1]
            got_flow_log_path = True
        
        if 'Writing event trace info to file:' in pox_log:
            pox_log_split = pox_log.split()
            event_log_path = pox_log_split[-1]
            got_event_log_path = True
            
            
    print 'Got flow tracker log file: ' + str(flow_log_path)
    print 'Got event trace log file: ' + str(event_log_path)
    print 'Controller initialized'
    pox_log_offset = pox_log_file.tell()
    pox_log_file.close()
    
    # Launch the data plane network
    print 'Building data plane network...'
    net = Mininet(topo, controller=None, switch=OVSSwitch, link=TCLink, build=False, autoSetMacs=False)
    for host in cnet.hosts:
        if isinstance(host, Controller):
            net.addController(host)
            print 'Added controller at host ' + str(host) + ' with IP ' + host.IP() + ' to data plane network.' 
    net.start()
    print 'Data network launched.'
    
    #for switch_name in topo.get_switch_list():
    #    net.get(switch_name).cmd('route 127.0.0.1 dev lo')
    
    topo.mcastConfig(net)
    sleep_time = 8 + (float(len(hosts))/8)
    print 'Waiting ' + str(sleep_time) + ' seconds to allow for controller topology discovery'
    sleep(sleep_time)   # Allow time for the controller to detect the topology
    
    if interactive:
        CLI(net)
    else:
        mcast_group_last_octet = 1
        mcast_port = 5010
        rand_seed = int(time())
        print 'Using random seed: ' + str(rand_seed)
        np.random.seed(rand_seed)
        host_join_probabilities = generate_group_membership_probabilities(hosts, membership_mean, membership_std_dev, membership_avg_bound)
        print 'Host join probabilities: ' + ', '.join(str(p) for p in host_join_probabilities)
        host_join_sum = sum(p[1] for p in host_join_probabilities)
        print 'Measured mean join probability: ' + str(host_join_sum / len(host_join_probabilities))
        print 'Predicted average group size: ' + str(host_join_sum)
        i = 1
        while True:
            print 'Generating multicast group #' + str(i)
            # Choose a sending host using a uniform random distribution
            sender_index = randint(0,len(hosts))
            sender_host = hosts[sender_index]
            
            # Choose a random number of receivers by comparing a uniform random variable
            # against the previously generated group membership probabilities
            receivers = []
            for host_prob in host_join_probabilities:
                p = uniform(0, 1)
                if p <= host_prob[1]:
                    receivers.append(host_prob[0])
            
            # Initialize the group
            # Note - This method of group IP generation will need to be modified slightly to support more than
            # 255 groups
            mcast_ip = '224.1.1.{last_octet}'.format(last_octet = str(mcast_group_last_octet))
            test_groups.append(MulticastGroupDefinition(sender_host, receivers, mcast_ip, mcast_port, mcast_port + 1))
            launch_time = time()
            test_group_launch_times.append(launch_time)
            print 'Launching multicast group #' + str(i) + ' at time: ' + str(launch_time)
            test_groups[-1].launch_mcast_applications(net)
            mcast_group_last_octet = mcast_group_last_octet + 1
            mcast_port = mcast_port + 2
            i += 1
            sleep(5 + uniform(0, 5))
            
            # Read from the log file to determine if a link has become overloaded, and cease generating new groups if so
            print 'Check for congested link...'
            congested_link = False
            pox_log_file = open('./pox.log', 'r')
            pox_log_file.seek(pox_log_offset)
            for line in pox_log_file:
                if 'Network peak link throughout (MBps):' in line:
                    line_split = line.split(' ')
                    print 'Peak Usage (Mbps): ' + line_split[-1],
                if 'Network avg link throughout (MBps):' in line:
                    line_split = line.split(' ')
                    print 'Mean Usage (Mbps): ' + line_split[-1],
                if 'Congested link detected!' in line:
                    congested_link = True
                    break
            pox_log_offset = pox_log_file.tell()
            pox_log_file.close()
            if congested_link:
                print 'Detected congested link, terminating simulation.'
                break
            else:
                print 'No congestion detected.'

    
    print 'Terminating network applications'
    for group in test_groups:
        group.terminate_mcast_applications()
    print 'Terminating controller'
    pox_process.send_signal(signal.SIGINT)
    sleep(1)
    print 'Waiting for network application termination...'
    for group in test_groups:
        group.wait_for_application_termination()
    print 'Network applications terminated'
    print 'Waiting for controller termination...'
    pox_process.send_signal(signal.SIGKILL)
    pox_process.wait()
    print 'Controller terminated'
    pox_process = None
    
    print 'Stopping data network...'
    net.stop()
    print 'Data network stopped.'
    
    print 'Stopping control network...'
    cnet.stop()
    print 'Control network stopped.'

    if not interactive:
        write_final_stats_log(log_file_name, flow_log_path, event_log_path, membership_mean, membership_std_dev, membership_avg_bound, test_groups, test_group_launch_times, topo)
def MyNet():

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

    info('***Add switches\n')
    s1 = net.addSwitch('s1', cls=OVSKernelSwitch)
    s2 = net.addSwitch('s2', cls=OVSKernelSwitch)
    s3 = net.addSwitch('s3', cls=OVSKernelSwitch)
    s4 = net.addSwitch('s4', cls=OVSKernelSwitch)
    s5 = net.addSwitch('s5', cls=OVSKernelSwitch)
    s6 = net.addSwitch('s6', cls=OVSKernelSwitch)
    s7 = net.addSwitch('s7', cls=OVSKernelSwitch)
    s8 = net.addSwitch('s8', cls=OVSKernelSwitch)
    s9 = net.addSwitch('s9', cls=OVSKernelSwitch)
    s10 = net.addSwitch('s10', cls=OVSKernelSwitch)
    s11 = net.addSwitch('s11', cls=OVSKernelSwitch)
    s12 = net.addSwitch('s12', cls=OVSKernelSwitch)
    s13 = net.addSwitch('s13', cls=OVSKernelSwitch)
    s14 = net.addSwitch('s14', cls=OVSKernelSwitch)
    s15 = net.addSwitch('s15', cls=OVSKernelSwitch)
    s16 = net.addSwitch('s16', cls=OVSKernelSwitch)
    s17 = net.addSwitch('s17', cls=OVSKernelSwitch)
    s18 = net.addSwitch('s18', cls=OVSKernelSwitch)
    s19 = net.addSwitch('s19', cls=OVSKernelSwitch)
    s20 = net.addSwitch('s20', cls=OVSKernelSwitch)

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

    info('***Add links\n')
    net.addLink(h1, s1, 1, 1)
    net.addLink(h2, s1, 1, 2)
    net.addLink(h3, s2, 1, 1)
    net.addLink(h4, s2, 1, 2)
    net.addLink(h5, s3, 1, 1)
    net.addLink(h6, s3, 1, 2)
    net.addLink(h7, s4, 1, 1)
    net.addLink(h8, s4, 1, 2)
    net.addLink(h9, s5, 1, 1)
    net.addLink(h10, s5, 1, 2)
    net.addLink(h11, s6, 1, 1)
    net.addLink(h12, s6, 1, 2)
    net.addLink(h13, s7, 1, 1)
    net.addLink(h14, s7, 1, 2)
    net.addLink(h15, s8, 1, 1)
    net.addLink(h16, s8, 1, 2)

    net.addLink(s1, s9, 3, 1)
    net.addLink(s1, s10, 4, 1)
    net.addLink(s2, s9, 3, 2)
    net.addLink(s2, s10, 4, 2)

    net.addLink(s3, s11, 3, 1)
    net.addLink(s3, s12, 4, 1)
    net.addLink(s4, s11, 3, 2)
    net.addLink(s4, s12, 4, 2)

    net.addLink(s5, s13, 3, 1)
    net.addLink(s5, s14, 4, 1)
    net.addLink(s6, s13, 3, 2)
    net.addLink(s6, s14, 4, 2)

    net.addLink(s7, s15, 3, 1)
    net.addLink(s7, s16, 4, 1)
    net.addLink(s8, s15, 3, 2)
    net.addLink(s8, s16, 4, 2)

    net.addLink(s17, s9, 1, 3)
    net.addLink(s17, s11, 2, 3)
    net.addLink(s17, s13, 3, 3)
    net.addLink(s17, s15, 4, 3)

    net.addLink(s18, s9, 1, 4)
    net.addLink(s18, s11, 2, 4)
    net.addLink(s18, s13, 3, 4)
    net.addLink(s18, s15, 4, 4)

    net.addLink(s19, s10, 1, 3)
    net.addLink(s19, s12, 2, 3)
    net.addLink(s19, s14, 3, 3)
    net.addLink(s19, s16, 4, 3)

    net.addLink(s20, s10, 1, 4)
    net.addLink(s20, s12, 2, 4)
    net.addLink(s20, s14, 3, 4)
    net.addLink(s20, s16, 4, 4)

    info('*** Starting network\n')
    net.start()
    #s1
    s1.cmd(r'ovs-ofctl add-flow s1 "arp,nw_dst=10.0.0.2,actions=output:1"')
    s1.cmd(r'ovs-ofctl add-flow s1 "arp,nw_dst=10.0.0.3,actions=output:2"')
    s1.cmd(r'ovs-ofctl add-flow s1 "icmp,nw_dst=10.0.0.2,actions=output:1"')
    s1.cmd(r'ovs-ofctl add-flow s1 "icmp,nw_dst=10.0.0.3,actions=output:2"')
    s1.cmd(r'ovs-ofctl add-flow s1 "arp,nw_dst=10.0.1.2,actions=output:3"')
    s1.cmd(r'ovs-ofctl add-flow s1 "arp,nw_dst=10.0.1.3,actions=output:3"')
    s1.cmd(r'ovs-ofctl add-flow s1 "icmp,nw_dst=10.0.1.2,actions=output:3"')
    s1.cmd(r'ovs-ofctl add-flow s1 "icmp,nw_dst=10.0.1.3,actions=output:3"')

    s1.cmd(r'ovs-ofctl add-flow s1 "arp,nw_dst=10.1.0.2,actions=output:3"')
    s1.cmd(r'ovs-ofctl add-flow s1 "arp,nw_dst=10.1.1.2,actions=output:3"')
    s1.cmd(r'ovs-ofctl add-flow s1 "arp,nw_dst=10.2.0.2,actions=output:3"')
    s1.cmd(r'ovs-ofctl add-flow s1 "arp,nw_dst=10.2.1.2,actions=output:3"')
    s1.cmd(r'ovs-ofctl add-flow s1 "arp,nw_dst=10.3.0.2,actions=output:3"')
    s1.cmd(r'ovs-ofctl add-flow s1 "arp,nw_dst=10.3.1.2,actions=output:3"')
    s1.cmd(r'ovs-ofctl add-flow s1 "icmp,nw_dst=10.1.0.2,actions=output:3"')
    s1.cmd(r'ovs-ofctl add-flow s1 "icmp,nw_dst=10.1.1.2,actions=output:3"')
    s1.cmd(r'ovs-ofctl add-flow s1 "icmp,nw_dst=10.2.0.2,actions=output:3"')
    s1.cmd(r'ovs-ofctl add-flow s1 "icmp,nw_dst=10.2.1.2,actions=output:3"')
    s1.cmd(r'ovs-ofctl add-flow s1 "icmp,nw_dst=10.3.0.2,actions=output:3"')
    s1.cmd(r'ovs-ofctl add-flow s1 "icmp,nw_dst=10.3.1.2,actions=output:3"')

    s1.cmd(r'ovs-ofctl add-flow s1 "arp,nw_dst=10.1.0.3,actions=output:4"')
    s1.cmd(r'ovs-ofctl add-flow s1 "arp,nw_dst=10.1.1.3,actions=output:4"')
    s1.cmd(r'ovs-ofctl add-flow s1 "arp,nw_dst=10.2.0.3,actions=output:4"')
    s1.cmd(r'ovs-ofctl add-flow s1 "arp,nw_dst=10.2.1.3,actions=output:4"')
    s1.cmd(r'ovs-ofctl add-flow s1 "arp,nw_dst=10.3.0.3,actions=output:4"')
    s1.cmd(r'ovs-ofctl add-flow s1 "arp,nw_dst=10.3.1.3,actions=output:4"')
    s1.cmd(r'ovs-ofctl add-flow s1 "icmp,nw_dst=10.1.0.3,actions=output:4"')
    s1.cmd(r'ovs-ofctl add-flow s1 "icmp,nw_dst=10.1.1.3,actions=output:4"')
    s1.cmd(r'ovs-ofctl add-flow s1 "icmp,nw_dst=10.2.0.3,actions=output:4"')
    s1.cmd(r'ovs-ofctl add-flow s1 "icmp,nw_dst=10.2.1.3,actions=output:4"')
    s1.cmd(r'ovs-ofctl add-flow s1 "icmp,nw_dst=10.3.0.3,actions=output:4"')
    s1.cmd(r'ovs-ofctl add-flow s1 "icmp,nw_dst=10.3.1.3,actions=output:4"')

    #s2
    s2.cmd(r'ovs-ofctl add-flow s2 "arp,nw_dst=10.0.1.2,actions=output:1"')
    s2.cmd(r'ovs-ofctl add-flow s2 "arp,nw_dst=10.0.1.3,actions=output:2"')
    s2.cmd(r'ovs-ofctl add-flow s2 "icmp,nw_dst=10.0.1.2,actions=output:1"')
    s2.cmd(r'ovs-ofctl add-flow s2 "icmp,nw_dst=10.0.1.3,actions=output:2"')
    s2.cmd(r'ovs-ofctl add-flow s2 "arp,nw_dst=10.0.0.2,actions=output:4"')
    s2.cmd(r'ovs-ofctl add-flow s2 "arp,nw_dst=10.0.0.3,actions=output:4"')
    s2.cmd(r'ovs-ofctl add-flow s2 "icmp,nw_dst=10.0.0.2,actions=output:4"')
    s2.cmd(r'ovs-ofctl add-flow s2 "icmp,nw_dst=10.0.0.3,actions=output:4"')

    s2.cmd(r'ovs-ofctl add-flow s2 "arp,nw_dst=10.1.0.2,actions=output:4"')
    s2.cmd(r'ovs-ofctl add-flow s2 "arp,nw_dst=10.1.1.2,actions=output:4"')
    s2.cmd(r'ovs-ofctl add-flow s2 "arp,nw_dst=10.2.0.2,actions=output:4"')
    s2.cmd(r'ovs-ofctl add-flow s2 "arp,nw_dst=10.2.1.2,actions=output:4"')
    s2.cmd(r'ovs-ofctl add-flow s2 "arp,nw_dst=10.3.0.2,actions=output:4"')
    s2.cmd(r'ovs-ofctl add-flow s2 "arp,nw_dst=10.3.1.2,actions=output:4"')
    s2.cmd(r'ovs-ofctl add-flow s2 "icmp,nw_dst=10.1.0.2,actions=output:4"')
    s2.cmd(r'ovs-ofctl add-flow s2 "icmp,nw_dst=10.1.1.2,actions=output:4"')
    s2.cmd(r'ovs-ofctl add-flow s2 "icmp,nw_dst=10.2.0.2,actions=output:4"')
    s2.cmd(r'ovs-ofctl add-flow s2 "icmp,nw_dst=10.2.1.2,actions=output:4"')
    s2.cmd(r'ovs-ofctl add-flow s2 "icmp,nw_dst=10.3.0.2,actions=output:4"')
    s2.cmd(r'ovs-ofctl add-flow s2 "icmp,nw_dst=10.3.1.2,actions=output:4"')

    s2.cmd(r'ovs-ofctl add-flow s2 "arp,nw_dst=10.1.0.3,actions=output:3"')
    s2.cmd(r'ovs-ofctl add-flow s2 "arp,nw_dst=10.1.1.3,actions=output:3"')
    s2.cmd(r'ovs-ofctl add-flow s2 "arp,nw_dst=10.2.0.3,actions=output:3"')
    s2.cmd(r'ovs-ofctl add-flow s2 "arp,nw_dst=10.2.1.3,actions=output:3"')
    s2.cmd(r'ovs-ofctl add-flow s2 "arp,nw_dst=10.3.0.3,actions=output:3"')
    s2.cmd(r'ovs-ofctl add-flow s2 "arp,nw_dst=10.3.1.3,actions=output:3"')
    s2.cmd(r'ovs-ofctl add-flow s2 "icmp,nw_dst=10.1.0.3,actions=output:3"')
    s2.cmd(r'ovs-ofctl add-flow s2 "icmp,nw_dst=10.1.1.3,actions=output:3"')
    s2.cmd(r'ovs-ofctl add-flow s2 "icmp,nw_dst=10.2.0.3,actions=output:3"')
    s2.cmd(r'ovs-ofctl add-flow s2 "icmp,nw_dst=10.2.1.3,actions=output:3"')
    s2.cmd(r'ovs-ofctl add-flow s2 "icmp,nw_dst=10.3.0.3,actions=output:3"')
    s2.cmd(r'ovs-ofctl add-flow s2 "icmp,nw_dst=10.3.1.3,actions=output:3"')
    #s9
    s9.cmd(r'ovs-ofctl add-flow s9 "arp,nw_dst=10.0.0.0/24,actions=output:1"')
    s9.cmd(r'ovs-ofctl add-flow s9 "arp,nw_dst=10.0.1.0/24,actions=output:2"')
    s9.cmd(r'ovs-ofctl add-flow s9 "icmp,nw_dst=10.0.0.0/24,actions=output:1"')
    s9.cmd(r'ovs-ofctl add-flow s9 "icmp,nw_dst=10.0.1.0/24,actions=output:2"')

    s9.cmd(r'ovs-ofctl add-flow s9 "arp,nw_dst=10.1.0.2,actions=output:3"')
    s9.cmd(r'ovs-ofctl add-flow s9 "arp,nw_dst=10.1.1.2,actions=output:3"')
    s9.cmd(r'ovs-ofctl add-flow s9 "arp,nw_dst=10.2.0.2,actions=output:3"')
    s9.cmd(r'ovs-ofctl add-flow s9 "arp,nw_dst=10.2.1.2,actions=output:3"')
    s9.cmd(r'ovs-ofctl add-flow s9 "arp,nw_dst=10.3.0.2,actions=output:3"')
    s9.cmd(r'ovs-ofctl add-flow s9 "arp,nw_dst=10.3.1.2,actions=output:3"')
    s9.cmd(r'ovs-ofctl add-flow s9 "icmp,nw_dst=10.1.0.2,actions=output:3"')
    s9.cmd(r'ovs-ofctl add-flow s9 "icmp,nw_dst=10.1.1.2,actions=output:3"')
    s9.cmd(r'ovs-ofctl add-flow s9 "icmp,nw_dst=10.2.0.2,actions=output:3"')
    s9.cmd(r'ovs-ofctl add-flow s9 "icmp,nw_dst=10.2.1.2,actions=output:3"')
    s9.cmd(r'ovs-ofctl add-flow s9 "icmp,nw_dst=10.3.0.2,actions=output:3"')
    s9.cmd(r'ovs-ofctl add-flow s9 "icmp,nw_dst=10.3.1.2,actions=output:3"')

    s9.cmd(r'ovs-ofctl add-flow s9 "arp,nw_dst=10.1.0.3,actions=output:4"')
    s9.cmd(r'ovs-ofctl add-flow s9 "arp,nw_dst=10.1.1.3,actions=output:4"')
    s9.cmd(r'ovs-ofctl add-flow s9 "arp,nw_dst=10.2.0.3,actions=output:4"')
    s9.cmd(r'ovs-ofctl add-flow s9 "arp,nw_dst=10.2.1.3,actions=output:4"')
    s9.cmd(r'ovs-ofctl add-flow s9 "arp,nw_dst=10.3.0.3,actions=output:4"')
    s9.cmd(r'ovs-ofctl add-flow s9 "arp,nw_dst=10.3.1.3,actions=output:4"')
    s9.cmd(r'ovs-ofctl add-flow s9 "icmp,nw_dst=10.1.0.3,actions=output:4"')
    s9.cmd(r'ovs-ofctl add-flow s9 "icmp,nw_dst=10.1.1.3,actions=output:4"')
    s9.cmd(r'ovs-ofctl add-flow s9 "icmp,nw_dst=10.2.0.3,actions=output:4"')
    s9.cmd(r'ovs-ofctl add-flow s9 "icmp,nw_dst=10.2.1.3,actions=output:4"')
    s9.cmd(r'ovs-ofctl add-flow s9 "icmp,nw_dst=10.3.0.3,actions=output:4"')
    s9.cmd(r'ovs-ofctl add-flow s9 "icmp,nw_dst=10.3.1.3,actions=output:4"')

    #s10
    s10.cmd(
        r'ovs-ofctl add-flow s10 "arp,nw_dst=10.0.0.0/24,actions=output:1"')
    s10.cmd(
        r'ovs-ofctl add-flow s10 "arp,nw_dst=10.0.1.0/24,actions=output:2"')
    s10.cmd(
        r'ovs-ofctl add-flow s10 "icmp,nw_dst=10.0.0.0/24,actions=output:1"')
    s10.cmd(
        r'ovs-ofctl add-flow s10 "icmp,nw_dst=10.0.1.0/24,actions=output:2"')

    s10.cmd(r'ovs-ofctl add-flow s10 "arp,nw_dst=10.1.0.2,actions=output:4"')
    s10.cmd(r'ovs-ofctl add-flow s10 "arp,nw_dst=10.1.1.2,actions=output:4"')
    s10.cmd(r'ovs-ofctl add-flow s10 "arp,nw_dst=10.2.0.2,actions=output:4"')
    s10.cmd(r'ovs-ofctl add-flow s10 "arp,nw_dst=10.2.1.2,actions=output:4"')
    s10.cmd(r'ovs-ofctl add-flow s10 "arp,nw_dst=10.3.0.2,actions=output:4"')
    s10.cmd(r'ovs-ofctl add-flow s10 "arp,nw_dst=10.3.1.2,actions=output:4"')
    s10.cmd(r'ovs-ofctl add-flow s10 "icmp,nw_dst=10.1.0.2,actions=output:4"')
    s10.cmd(r'ovs-ofctl add-flow s10 "icmp,nw_dst=10.1.1.2,actions=output:4"')
    s10.cmd(r'ovs-ofctl add-flow s10 "icmp,nw_dst=10.2.0.2,actions=output:4"')
    s10.cmd(r'ovs-ofctl add-flow s10 "icmp,nw_dst=10.2.1.2,actions=output:4"')
    s10.cmd(r'ovs-ofctl add-flow s10 "icmp,nw_dst=10.3.0.2,actions=output:4"')
    s10.cmd(r'ovs-ofctl add-flow s10 "icmp,nw_dst=10.3.1.2,actions=output:4"')

    s10.cmd(r'ovs-ofctl add-flow s10 "arp,nw_dst=10.1.0.3,actions=output:3"')
    s10.cmd(r'ovs-ofctl add-flow s10 "arp,nw_dst=10.1.1.3,actions=output:3"')
    s10.cmd(r'ovs-ofctl add-flow s10 "arp,nw_dst=10.2.0.3,actions=output:3"')
    s10.cmd(r'ovs-ofctl add-flow s10 "arp,nw_dst=10.2.1.3,actions=output:3"')
    s10.cmd(r'ovs-ofctl add-flow s10 "arp,nw_dst=10.3.0.3,actions=output:3"')
    s10.cmd(r'ovs-ofctl add-flow s10 "arp,nw_dst=10.3.1.3,actions=output:3"')
    s10.cmd(r'ovs-ofctl add-flow s10 "icmp,nw_dst=10.1.0.3,actions=output:3"')
    s10.cmd(r'ovs-ofctl add-flow s10 "icmp,nw_dst=10.1.1.3,actions=output:3"')
    s10.cmd(r'ovs-ofctl add-flow s10 "icmp,nw_dst=10.2.0.3,actions=output:3"')
    s10.cmd(r'ovs-ofctl add-flow s10 "icmp,nw_dst=10.2.1.3,actions=output:3"')
    s10.cmd(r'ovs-ofctl add-flow s10 "icmp,nw_dst=10.3.0.3,actions=output:3"')
    s10.cmd(r'ovs-ofctl add-flow s10 "icmp,nw_dst=10.3.1.3,actions=output:3"')
    #s3
    s3.cmd(r'ovs-ofctl add-flow s3 "arp,nw_dst=10.1.0.2,actions=output:1"')
    s3.cmd(r'ovs-ofctl add-flow s3 "arp,nw_dst=10.1.0.3,actions=output:2"')
    s3.cmd(r'ovs-ofctl add-flow s3 "icmp,nw_dst=10.1.0.2,actions=output:1"')
    s3.cmd(r'ovs-ofctl add-flow s3 "icmp,nw_dst=10.1.0.3,actions=output:2"')
    s3.cmd(r'ovs-ofctl add-flow s3 "arp,nw_dst=10.1.1.2,actions=output:3"')
    s3.cmd(r'ovs-ofctl add-flow s3 "arp,nw_dst=10.1.1.3,actions=output:3"')
    s3.cmd(r'ovs-ofctl add-flow s3 "icmp,nw_dst=10.1.1.2,actions=output:3"')
    s3.cmd(r'ovs-ofctl add-flow s3 "icmp,nw_dst=10.1.1.3,actions=output:3"')

    s3.cmd(r'ovs-ofctl add-flow s3 "arp,nw_dst=10.0.0.2,actions=output:3"')
    s3.cmd(r'ovs-ofctl add-flow s3 "arp,nw_dst=10.0.1.2,actions=output:3"')
    s3.cmd(r'ovs-ofctl add-flow s3 "arp,nw_dst=10.2.0.2,actions=output:3"')
    s3.cmd(r'ovs-ofctl add-flow s3 "arp,nw_dst=10.2.1.2,actions=output:3"')
    s3.cmd(r'ovs-ofctl add-flow s3 "arp,nw_dst=10.3.0.2,actions=output:3"')
    s3.cmd(r'ovs-ofctl add-flow s3 "arp,nw_dst=10.3.1.2,actions=output:3"')
    s3.cmd(r'ovs-ofctl add-flow s3 "icmp,nw_dst=10.0.0.2,actions=output:3"')
    s3.cmd(r'ovs-ofctl add-flow s3 "icmp,nw_dst=10.0.1.2,actions=output:3"')
    s3.cmd(r'ovs-ofctl add-flow s3 "icmp,nw_dst=10.2.0.2,actions=output:3"')
    s3.cmd(r'ovs-ofctl add-flow s3 "icmp,nw_dst=10.2.1.2,actions=output:3"')
    s3.cmd(r'ovs-ofctl add-flow s3 "icmp,nw_dst=10.3.0.2,actions=output:3"')
    s3.cmd(r'ovs-ofctl add-flow s3 "icmp,nw_dst=10.3.1.2,actions=output:3"')

    s3.cmd(r'ovs-ofctl add-flow s3 "arp,nw_dst=10.0.0.3,actions=output:4"')
    s3.cmd(r'ovs-ofctl add-flow s3 "arp,nw_dst=10.0.1.3,actions=output:4"')
    s3.cmd(r'ovs-ofctl add-flow s3 "arp,nw_dst=10.2.0.3,actions=output:4"')
    s3.cmd(r'ovs-ofctl add-flow s3 "arp,nw_dst=10.2.1.3,actions=output:4"')
    s3.cmd(r'ovs-ofctl add-flow s3 "arp,nw_dst=10.3.0.3,actions=output:4"')
    s3.cmd(r'ovs-ofctl add-flow s3 "arp,nw_dst=10.3.1.3,actions=output:4"')
    s3.cmd(r'ovs-ofctl add-flow s3 "icmp,nw_dst=10.0.0.3,actions=output:4"')
    s3.cmd(r'ovs-ofctl add-flow s3 "icmp,nw_dst=10.0.1.3,actions=output:4"')
    s3.cmd(r'ovs-ofctl add-flow s3 "icmp,nw_dst=10.2.0.3,actions=output:4"')
    s3.cmd(r'ovs-ofctl add-flow s3 "icmp,nw_dst=10.2.1.3,actions=output:4"')
    s3.cmd(r'ovs-ofctl add-flow s3 "icmp,nw_dst=10.3.0.3,actions=output:4"')
    s3.cmd(r'ovs-ofctl add-flow s3 "icmp,nw_dst=10.3.1.3,actions=output:4"')
    #s4
    s4.cmd(r'ovs-ofctl add-flow s4 "arp,nw_dst=10.1.1.2,actions=output:1"')
    s4.cmd(r'ovs-ofctl add-flow s4 "arp,nw_dst=10.1.1.3,actions=output:2"')
    s4.cmd(r'ovs-ofctl add-flow s4 "icmp,nw_dst=10.1.1.2,actions=output:1"')
    s4.cmd(r'ovs-ofctl add-flow s4 "icmp,nw_dst=10.1.1.3,actions=output:2"')
    s4.cmd(r'ovs-ofctl add-flow s4 "arp,nw_dst=10.1.0.2,actions=output:4"')
    s4.cmd(r'ovs-ofctl add-flow s4 "arp,nw_dst=10.1.0.3,actions=output:4"')
    s4.cmd(r'ovs-ofctl add-flow s4 "icmp,nw_dst=10.1.0.2,actions=output:4"')
    s4.cmd(r'ovs-ofctl add-flow s4 "icmp,nw_dst=10.1.0.3,actions=output:4"')

    s4.cmd(r'ovs-ofctl add-flow s4 "arp,nw_dst=10.0.0.2,actions=output:4"')
    s4.cmd(r'ovs-ofctl add-flow s4 "arp,nw_dst=10.0.1.2,actions=output:4"')
    s4.cmd(r'ovs-ofctl add-flow s4 "arp,nw_dst=10.2.0.2,actions=output:4"')
    s4.cmd(r'ovs-ofctl add-flow s4 "arp,nw_dst=10.2.1.2,actions=output:4"')
    s4.cmd(r'ovs-ofctl add-flow s4 "arp,nw_dst=10.3.0.2,actions=output:4"')
    s4.cmd(r'ovs-ofctl add-flow s4 "arp,nw_dst=10.3.1.2,actions=output:4"')
    s4.cmd(r'ovs-ofctl add-flow s4 "icmp,nw_dst=10.0.0.2,actions=output:4"')
    s4.cmd(r'ovs-ofctl add-flow s4 "icmp,nw_dst=10.0.1.2,actions=output:4"')
    s4.cmd(r'ovs-ofctl add-flow s4 "icmp,nw_dst=10.2.0.2,actions=output:4"')
    s4.cmd(r'ovs-ofctl add-flow s4 "icmp,nw_dst=10.2.1.2,actions=output:4"')
    s4.cmd(r'ovs-ofctl add-flow s4 "icmp,nw_dst=10.3.0.2,actions=output:4"')
    s4.cmd(r'ovs-ofctl add-flow s4 "icmp,nw_dst=10.3.1.2,actions=output:4"')

    s4.cmd(r'ovs-ofctl add-flow s4 "arp,nw_dst=10.0.0.3,actions=output:3"')
    s4.cmd(r'ovs-ofctl add-flow s4 "arp,nw_dst=10.0.1.3,actions=output:3"')
    s4.cmd(r'ovs-ofctl add-flow s4 "arp,nw_dst=10.2.0.3,actions=output:3"')
    s4.cmd(r'ovs-ofctl add-flow s4 "arp,nw_dst=10.2.1.3,actions=output:3"')
    s4.cmd(r'ovs-ofctl add-flow s4 "arp,nw_dst=10.3.0.3,actions=output:3"')
    s4.cmd(r'ovs-ofctl add-flow s4 "arp,nw_dst=10.3.1.3,actions=output:3"')
    s4.cmd(r'ovs-ofctl add-flow s4 "icmp,nw_dst=10.0.0.3,actions=output:3"')
    s4.cmd(r'ovs-ofctl add-flow s4 "icmp,nw_dst=10.0.1.3,actions=output:3"')
    s4.cmd(r'ovs-ofctl add-flow s4 "icmp,nw_dst=10.2.0.3,actions=output:3"')
    s4.cmd(r'ovs-ofctl add-flow s4 "icmp,nw_dst=10.2.1.3,actions=output:3"')
    s4.cmd(r'ovs-ofctl add-flow s4 "icmp,nw_dst=10.3.0.3,actions=output:3"')
    s4.cmd(r'ovs-ofctl add-flow s4 "icmp,nw_dst=10.3.1.3,actions=output:3"')
    #s11
    s11.cmd(
        r'ovs-ofctl add-flow s11 "arp,nw_dst=10.1.0.0/24,actions=output:1"')
    s11.cmd(
        r'ovs-ofctl add-flow s11 "arp,nw_dst=10.1.1.0/24,actions=output:2"')
    s11.cmd(
        r'ovs-ofctl add-flow s11 "icmp,nw_dst=10.1.0.0/24,actions=output:1"')
    s11.cmd(
        r'ovs-ofctl add-flow s11 "icmp,nw_dst=10.1.1.0/24,actions=output:2"')

    s11.cmd(r'ovs-ofctl add-flow s11 "arp,nw_dst=10.0.0.2,actions=output:3"')
    s11.cmd(r'ovs-ofctl add-flow s11 "arp,nw_dst=10.0.1.2,actions=output:3"')
    s11.cmd(r'ovs-ofctl add-flow s11 "arp,nw_dst=10.2.0.2,actions=output:3"')
    s11.cmd(r'ovs-ofctl add-flow s11 "arp,nw_dst=10.2.1.2,actions=output:3"')
    s11.cmd(r'ovs-ofctl add-flow s11 "arp,nw_dst=10.3.0.2,actions=output:3"')
    s11.cmd(r'ovs-ofctl add-flow s11 "arp,nw_dst=10.3.1.2,actions=output:3"')
    s11.cmd(r'ovs-ofctl add-flow s11 "icmp,nw_dst=10.0.0.2,actions=output:3"')
    s11.cmd(r'ovs-ofctl add-flow s11 "icmp,nw_dst=10.0.1.2,actions=output:3"')
    s11.cmd(r'ovs-ofctl add-flow s11 "icmp,nw_dst=10.2.0.2,actions=output:3"')
    s11.cmd(r'ovs-ofctl add-flow s11 "icmp,nw_dst=10.2.1.2,actions=output:3"')
    s11.cmd(r'ovs-ofctl add-flow s11 "icmp,nw_dst=10.3.0.2,actions=output:3"')
    s11.cmd(r'ovs-ofctl add-flow s11 "icmp,nw_dst=10.3.1.2,actions=output:3"')

    s11.cmd(r'ovs-ofctl add-flow s11 "arp,nw_dst=10.0.0.3,actions=output:4"')
    s11.cmd(r'ovs-ofctl add-flow s11 "arp,nw_dst=10.0.1.3,actions=output:4"')
    s11.cmd(r'ovs-ofctl add-flow s11 "arp,nw_dst=10.2.0.3,actions=output:4"')
    s11.cmd(r'ovs-ofctl add-flow s11 "arp,nw_dst=10.2.1.3,actions=output:4"')
    s11.cmd(r'ovs-ofctl add-flow s11 "arp,nw_dst=10.3.0.3,actions=output:4"')
    s11.cmd(r'ovs-ofctl add-flow s11 "arp,nw_dst=10.3.1.3,actions=output:4"')
    s11.cmd(r'ovs-ofctl add-flow s11 "icmp,nw_dst=10.0.0.3,actions=output:4"')
    s11.cmd(r'ovs-ofctl add-flow s11 "icmp,nw_dst=10.0.1.3,actions=output:4"')
    s11.cmd(r'ovs-ofctl add-flow s11 "icmp,nw_dst=10.2.0.3,actions=output:4"')
    s11.cmd(r'ovs-ofctl add-flow s11 "icmp,nw_dst=10.2.1.3,actions=output:4"')
    s11.cmd(r'ovs-ofctl add-flow s11 "icmp,nw_dst=10.3.0.3,actions=output:4"')
    s11.cmd(r'ovs-ofctl add-flow s11 "icmp,nw_dst=10.3.1.3,actions=output:4"')
    #s12
    s12.cmd(
        r'ovs-ofctl add-flow s12 "arp,nw_dst=10.1.0.0/24,actions=output:1"')
    s12.cmd(
        r'ovs-ofctl add-flow s12 "arp,nw_dst=10.1.1.0/24,actions=output:2"')
    s12.cmd(
        r'ovs-ofctl add-flow s12 "icmp,nw_dst=10.1.0.0/24,actions=output:1"')
    s12.cmd(
        r'ovs-ofctl add-flow s12 "icmp,nw_dst=10.1.1.0/24,actions=output:2"')

    s12.cmd(r'ovs-ofctl add-flow s12 "arp,nw_dst=10.0.0.2,actions=output:4"')
    s12.cmd(r'ovs-ofctl add-flow s12 "arp,nw_dst=10.0.1.2,actions=output:4"')
    s12.cmd(r'ovs-ofctl add-flow s12 "arp,nw_dst=10.2.0.2,actions=output:4"')
    s12.cmd(r'ovs-ofctl add-flow s12 "arp,nw_dst=10.2.1.2,actions=output:4"')
    s12.cmd(r'ovs-ofctl add-flow s12 "arp,nw_dst=10.3.0.2,actions=output:4"')
    s12.cmd(r'ovs-ofctl add-flow s12 "arp,nw_dst=10.3.1.2,actions=output:4"')
    s12.cmd(r'ovs-ofctl add-flow s12 "icmp,nw_dst=10.0.0.2,actions=output:4"')
    s12.cmd(r'ovs-ofctl add-flow s12 "icmp,nw_dst=10.0.1.2,actions=output:4"')
    s12.cmd(r'ovs-ofctl add-flow s12 "icmp,nw_dst=10.2.0.2,actions=output:4"')
    s12.cmd(r'ovs-ofctl add-flow s12 "icmp,nw_dst=10.2.1.2,actions=output:4"')
    s12.cmd(r'ovs-ofctl add-flow s12 "icmp,nw_dst=10.3.0.2,actions=output:4"')
    s12.cmd(r'ovs-ofctl add-flow s12 "icmp,nw_dst=10.3.1.2,actions=output:4"')

    s12.cmd(r'ovs-ofctl add-flow s12 "arp,nw_dst=10.0.0.3,actions=output:3"')
    s12.cmd(r'ovs-ofctl add-flow s12 "arp,nw_dst=10.0.1.3,actions=output:3"')
    s12.cmd(r'ovs-ofctl add-flow s12 "arp,nw_dst=10.2.0.3,actions=output:3"')
    s12.cmd(r'ovs-ofctl add-flow s12 "arp,nw_dst=10.2.1.3,actions=output:3"')
    s12.cmd(r'ovs-ofctl add-flow s12 "arp,nw_dst=10.3.0.3,actions=output:3"')
    s12.cmd(r'ovs-ofctl add-flow s12 "arp,nw_dst=10.3.1.3,actions=output:3"')
    s12.cmd(r'ovs-ofctl add-flow s12 "icmp,nw_dst=10.0.0.3,actions=output:3"')
    s12.cmd(r'ovs-ofctl add-flow s12 "icmp,nw_dst=10.0.1.3,actions=output:3"')
    s12.cmd(r'ovs-ofctl add-flow s12 "icmp,nw_dst=10.2.0.3,actions=output:3"')
    s12.cmd(r'ovs-ofctl add-flow s12 "icmp,nw_dst=10.2.1.3,actions=output:3"')
    s12.cmd(r'ovs-ofctl add-flow s12 "icmp,nw_dst=10.3.0.3,actions=output:3"')
    s12.cmd(r'ovs-ofctl add-flow s12 "icmp,nw_dst=10.3.1.3,actions=output:3"')
    #s5
    s5.cmd(r'ovs-ofctl add-flow s5 "arp,nw_dst=10.2.0.2,actions=output:1"')
    s5.cmd(r'ovs-ofctl add-flow s5 "arp,nw_dst=10.2.0.3,actions=output:2"')
    s5.cmd(r'ovs-ofctl add-flow s5 "icmp,nw_dst=10.2.0.2,actions=output:1"')
    s5.cmd(r'ovs-ofctl add-flow s5 "icmp,nw_dst=10.2.0.3,actions=output:2"')
    s5.cmd(r'ovs-ofctl add-flow s5 "arp,nw_dst=10.2.1.2,actions=output:3"')
    s5.cmd(r'ovs-ofctl add-flow s5 "arp,nw_dst=10.2.1.3,actions=output:3"')
    s5.cmd(r'ovs-ofctl add-flow s5 "icmp,nw_dst=10.2.1.2,actions=output:3"')
    s5.cmd(r'ovs-ofctl add-flow s5 "icmp,nw_dst=10.2.1.3,actions=output:3"')

    s5.cmd(r'ovs-ofctl add-flow s5 "arp,nw_dst=10.0.0.2,actions=output:3"')
    s5.cmd(r'ovs-ofctl add-flow s5 "arp,nw_dst=10.0.1.2,actions=output:3"')
    s5.cmd(r'ovs-ofctl add-flow s5 "arp,nw_dst=10.1.0.2,actions=output:3"')
    s5.cmd(r'ovs-ofctl add-flow s5 "arp,nw_dst=10.1.1.2,actions=output:3"')
    s5.cmd(r'ovs-ofctl add-flow s5 "arp,nw_dst=10.3.0.2,actions=output:3"')
    s5.cmd(r'ovs-ofctl add-flow s5 "arp,nw_dst=10.3.1.2,actions=output:3"')
    s5.cmd(r'ovs-ofctl add-flow s5 "icmp,nw_dst=10.0.0.2,actions=output:3"')
    s5.cmd(r'ovs-ofctl add-flow s5 "icmp,nw_dst=10.0.1.2,actions=output:3"')
    s5.cmd(r'ovs-ofctl add-flow s5 "icmp,nw_dst=10.1.0.2,actions=output:3"')
    s5.cmd(r'ovs-ofctl add-flow s5 "icmp,nw_dst=10.1.1.2,actions=output:3"')
    s5.cmd(r'ovs-ofctl add-flow s5 "icmp,nw_dst=10.3.0.2,actions=output:3"')
    s5.cmd(r'ovs-ofctl add-flow s5 "icmp,nw_dst=10.3.1.2,actions=output:3"')

    s5.cmd(r'ovs-ofctl add-flow s5 "arp,nw_dst=10.0.0.3,actions=output:4"')
    s5.cmd(r'ovs-ofctl add-flow s5 "arp,nw_dst=10.0.1.3,actions=output:4"')
    s5.cmd(r'ovs-ofctl add-flow s5 "arp,nw_dst=10.1.0.3,actions=output:4"')
    s5.cmd(r'ovs-ofctl add-flow s5 "arp,nw_dst=10.1.1.3,actions=output:4"')
    s5.cmd(r'ovs-ofctl add-flow s5 "arp,nw_dst=10.3.0.3,actions=output:4"')
    s5.cmd(r'ovs-ofctl add-flow s5 "arp,nw_dst=10.3.1.3,actions=output:4"')
    s5.cmd(r'ovs-ofctl add-flow s5 "icmp,nw_dst=10.0.0.3,actions=output:4"')
    s5.cmd(r'ovs-ofctl add-flow s5 "icmp,nw_dst=10.0.1.3,actions=output:4"')
    s5.cmd(r'ovs-ofctl add-flow s5 "icmp,nw_dst=10.1.0.3,actions=output:4"')
    s5.cmd(r'ovs-ofctl add-flow s5 "icmp,nw_dst=10.1.1.3,actions=output:4"')
    s5.cmd(r'ovs-ofctl add-flow s5 "icmp,nw_dst=10.3.0.3,actions=output:4"')
    s5.cmd(r'ovs-ofctl add-flow s5 "icmp,nw_dst=10.3.1.3,actions=output:4"')
    #s6
    s6.cmd(r'ovs-ofctl add-flow s6 "arp,nw_dst=10.2.1.2,actions=output:1"')
    s6.cmd(r'ovs-ofctl add-flow s6 "arp,nw_dst=10.2.1.3,actions=output:2"')
    s6.cmd(r'ovs-ofctl add-flow s6 "icmp,nw_dst=10.2.1.2,actions=output:1"')
    s6.cmd(r'ovs-ofctl add-flow s6 "icmp,nw_dst=10.2.1.3,actions=output:2"')
    s6.cmd(r'ovs-ofctl add-flow s6 "arp,nw_dst=10.2.0.2,actions=output:4"')
    s6.cmd(r'ovs-ofctl add-flow s6 "arp,nw_dst=10.2.0.3,actions=output:4"')
    s6.cmd(r'ovs-ofctl add-flow s6 "icmp,nw_dst=10.2.0.2,actions=output:4"')
    s6.cmd(r'ovs-ofctl add-flow s6 "icmp,nw_dst=10.2.0.3,actions=output:4"')

    s6.cmd(r'ovs-ofctl add-flow s6 "arp,nw_dst=10.0.0.2,actions=output:4"')
    s6.cmd(r'ovs-ofctl add-flow s6 "arp,nw_dst=10.0.1.2,actions=output:4"')
    s6.cmd(r'ovs-ofctl add-flow s6 "arp,nw_dst=10.1.0.2,actions=output:4"')
    s6.cmd(r'ovs-ofctl add-flow s6 "arp,nw_dst=10.1.1.2,actions=output:4"')
    s6.cmd(r'ovs-ofctl add-flow s6 "arp,nw_dst=10.3.0.2,actions=output:4"')
    s6.cmd(r'ovs-ofctl add-flow s6 "arp,nw_dst=10.3.1.2,actions=output:4"')
    s6.cmd(r'ovs-ofctl add-flow s6 "icmp,nw_dst=10.0.0.2,actions=output:4"')
    s6.cmd(r'ovs-ofctl add-flow s6 "icmp,nw_dst=10.0.1.2,actions=output:4"')
    s6.cmd(r'ovs-ofctl add-flow s6 "icmp,nw_dst=10.1.0.2,actions=output:4"')
    s6.cmd(r'ovs-ofctl add-flow s6 "icmp,nw_dst=10.1.1.2,actions=output:4"')
    s6.cmd(r'ovs-ofctl add-flow s6 "icmp,nw_dst=10.3.0.2,actions=output:4"')
    s6.cmd(r'ovs-ofctl add-flow s6 "icmp,nw_dst=10.3.1.2,actions=output:4"')

    s6.cmd(r'ovs-ofctl add-flow s6 "arp,nw_dst=10.0.0.3,actions=output:3"')
    s6.cmd(r'ovs-ofctl add-flow s6 "arp,nw_dst=10.0.1.3,actions=output:3"')
    s6.cmd(r'ovs-ofctl add-flow s6 "arp,nw_dst=10.1.0.3,actions=output:3"')
    s6.cmd(r'ovs-ofctl add-flow s6 "arp,nw_dst=10.1.1.3,actions=output:3"')
    s6.cmd(r'ovs-ofctl add-flow s6 "arp,nw_dst=10.3.0.3,actions=output:3"')
    s6.cmd(r'ovs-ofctl add-flow s6 "arp,nw_dst=10.3.1.3,actions=output:3"')
    s6.cmd(r'ovs-ofctl add-flow s6 "icmp,nw_dst=10.0.0.3,actions=output:3"')
    s6.cmd(r'ovs-ofctl add-flow s6 "icmp,nw_dst=10.0.1.3,actions=output:3"')
    s6.cmd(r'ovs-ofctl add-flow s6 "icmp,nw_dst=10.1.0.3,actions=output:3"')
    s6.cmd(r'ovs-ofctl add-flow s6 "icmp,nw_dst=10.1.1.3,actions=output:3"')
    s6.cmd(r'ovs-ofctl add-flow s6 "icmp,nw_dst=10.3.0.3,actions=output:3"')
    s6.cmd(r'ovs-ofctl add-flow s6 "icmp,nw_dst=10.3.1.3,actions=output:3"')
    #s13
    s13.cmd(
        r'ovs-ofctl add-flow s13 "arp,nw_dst=10.2.0.0/24,actions=output:1"')
    s13.cmd(
        r'ovs-ofctl add-flow s13 "arp,nw_dst=10.2.1.0/24,actions=output:2"')
    s13.cmd(
        r'ovs-ofctl add-flow s13 "icmp,nw_dst=10.2.0.0/24,actions=output:1"')
    s13.cmd(
        r'ovs-ofctl add-flow s13 "icmp,nw_dst=10.2.1.0/24,actions=output:2"')

    s13.cmd(r'ovs-ofctl add-flow s13 "arp,nw_dst=10.0.0.2,actions=output:3"')
    s13.cmd(r'ovs-ofctl add-flow s13 "arp,nw_dst=10.0.1.2,actions=output:3"')
    s13.cmd(r'ovs-ofctl add-flow s13 "arp,nw_dst=10.1.0.2,actions=output:3"')
    s13.cmd(r'ovs-ofctl add-flow s13 "arp,nw_dst=10.1.1.2,actions=output:3"')
    s13.cmd(r'ovs-ofctl add-flow s13 "arp,nw_dst=10.3.0.2,actions=output:3"')
    s13.cmd(r'ovs-ofctl add-flow s13 "arp,nw_dst=10.3.1.2,actions=output:3"')
    s13.cmd(r'ovs-ofctl add-flow s13 "icmp,nw_dst=10.0.0.2,actions=output:3"')
    s13.cmd(r'ovs-ofctl add-flow s13 "icmp,nw_dst=10.0.1.2,actions=output:3"')
    s13.cmd(r'ovs-ofctl add-flow s13 "icmp,nw_dst=10.1.0.2,actions=output:3"')
    s13.cmd(r'ovs-ofctl add-flow s13 "icmp,nw_dst=10.1.1.2,actions=output:3"')
    s13.cmd(r'ovs-ofctl add-flow s13 "icmp,nw_dst=10.3.0.2,actions=output:3"')
    s13.cmd(r'ovs-ofctl add-flow s13 "icmp,nw_dst=10.3.1.2,actions=output:3"')

    s13.cmd(r'ovs-ofctl add-flow s13 "arp,nw_dst=10.0.0.3,actions=output:4"')
    s13.cmd(r'ovs-ofctl add-flow s13 "arp,nw_dst=10.0.1.3,actions=output:4"')
    s13.cmd(r'ovs-ofctl add-flow s13 "arp,nw_dst=10.1.0.3,actions=output:4"')
    s13.cmd(r'ovs-ofctl add-flow s13 "arp,nw_dst=10.1.1.3,actions=output:4"')
    s13.cmd(r'ovs-ofctl add-flow s13 "arp,nw_dst=10.3.0.3,actions=output:4"')
    s13.cmd(r'ovs-ofctl add-flow s13 "arp,nw_dst=10.3.1.3,actions=output:4"')
    s13.cmd(r'ovs-ofctl add-flow s13 "icmp,nw_dst=10.0.0.3,actions=output:4"')
    s13.cmd(r'ovs-ofctl add-flow s13 "icmp,nw_dst=10.0.1.3,actions=output:4"')
    s13.cmd(r'ovs-ofctl add-flow s13 "icmp,nw_dst=10.1.0.3,actions=output:4"')
    s13.cmd(r'ovs-ofctl add-flow s13 "icmp,nw_dst=10.1.1.3,actions=output:4"')
    s13.cmd(r'ovs-ofctl add-flow s13 "icmp,nw_dst=10.3.0.3,actions=output:4"')
    s13.cmd(r'ovs-ofctl add-flow s13 "icmp,nw_dst=10.3.1.3,actions=output:4"')
    #s14
    s14.cmd(
        r'ovs-ofctl add-flow s14 "arp,nw_dst=10.2.0.0/24,actions=output:1"')
    s14.cmd(
        r'ovs-ofctl add-flow s14 "arp,nw_dst=10.2.1.0/24,actions=output:2"')
    s14.cmd(
        r'ovs-ofctl add-flow s14 "icmp,nw_dst=10.2.0.0/24,actions=output:1"')
    s14.cmd(
        r'ovs-ofctl add-flow s14 "icmp,nw_dst=10.2.1.0/24,actions=output:2"')

    s14.cmd(r'ovs-ofctl add-flow s14 "arp,nw_dst=10.0.0.2,actions=output:4"')
    s14.cmd(r'ovs-ofctl add-flow s14 "arp,nw_dst=10.0.1.2,actions=output:4"')
    s14.cmd(r'ovs-ofctl add-flow s14 "arp,nw_dst=10.1.0.2,actions=output:4"')
    s14.cmd(r'ovs-ofctl add-flow s14 "arp,nw_dst=10.1.1.2,actions=output:4"')
    s14.cmd(r'ovs-ofctl add-flow s14 "arp,nw_dst=10.3.0.2,actions=output:4"')
    s14.cmd(r'ovs-ofctl add-flow s14 "arp,nw_dst=10.3.1.2,actions=output:4"')
    s14.cmd(r'ovs-ofctl add-flow s14 "icmp,nw_dst=10.0.0.2,actions=output:4"')
    s14.cmd(r'ovs-ofctl add-flow s14 "icmp,nw_dst=10.0.1.2,actions=output:4"')
    s14.cmd(r'ovs-ofctl add-flow s14 "icmp,nw_dst=10.1.0.2,actions=output:4"')
    s14.cmd(r'ovs-ofctl add-flow s14 "icmp,nw_dst=10.1.1.2,actions=output:4"')
    s14.cmd(r'ovs-ofctl add-flow s14 "icmp,nw_dst=10.3.0.2,actions=output:4"')
    s14.cmd(r'ovs-ofctl add-flow s14 "icmp,nw_dst=10.3.1.2,actions=output:4"')

    s14.cmd(r'ovs-ofctl add-flow s14 "arp,nw_dst=10.0.0.3,actions=output:3"')
    s14.cmd(r'ovs-ofctl add-flow s14 "arp,nw_dst=10.0.1.3,actions=output:3"')
    s14.cmd(r'ovs-ofctl add-flow s14 "arp,nw_dst=10.1.0.3,actions=output:3"')
    s14.cmd(r'ovs-ofctl add-flow s14 "arp,nw_dst=10.1.1.3,actions=output:3"')
    s14.cmd(r'ovs-ofctl add-flow s14 "arp,nw_dst=10.3.0.3,actions=output:3"')
    s14.cmd(r'ovs-ofctl add-flow s14 "arp,nw_dst=10.3.1.3,actions=output:3"')
    s14.cmd(r'ovs-ofctl add-flow s14 "icmp,nw_dst=10.0.0.3,actions=output:3"')
    s14.cmd(r'ovs-ofctl add-flow s14 "icmp,nw_dst=10.0.1.3,actions=output:3"')
    s14.cmd(r'ovs-ofctl add-flow s14 "icmp,nw_dst=10.1.0.3,actions=output:3"')
    s14.cmd(r'ovs-ofctl add-flow s14 "icmp,nw_dst=10.1.1.3,actions=output:3"')
    s14.cmd(r'ovs-ofctl add-flow s14 "icmp,nw_dst=10.3.0.3,actions=output:3"')
    s14.cmd(r'ovs-ofctl add-flow s14 "icmp,nw_dst=10.3.1.3,actions=output:3"')
    #s7
    s7.cmd(r'ovs-ofctl add-flow s7 "arp,nw_dst=10.3.0.2,actions=output:1"')
    s7.cmd(r'ovs-ofctl add-flow s7 "arp,nw_dst=10.3.0.3,actions=output:2"')
    s7.cmd(r'ovs-ofctl add-flow s7 "icmp,nw_dst=10.3.0.2,actions=output:1"')
    s7.cmd(r'ovs-ofctl add-flow s7 "icmp,nw_dst=10.3.0.3,actions=output:2"')
    s7.cmd(r'ovs-ofctl add-flow s7 "arp,nw_dst=10.3.1.2,actions=output:3"')
    s7.cmd(r'ovs-ofctl add-flow s7 "arp,nw_dst=10.3.1.3,actions=output:3"')
    s7.cmd(r'ovs-ofctl add-flow s7 "icmp,nw_dst=10.3.1.2,actions=output:3"')
    s7.cmd(r'ovs-ofctl add-flow s7 "icmp,nw_dst=10.3.1.3,actions=output:3"')

    s7.cmd(r'ovs-ofctl add-flow s7 "arp,nw_dst=10.0.0.2,actions=output:3"')
    s7.cmd(r'ovs-ofctl add-flow s7 "arp,nw_dst=10.0.1.2,actions=output:3"')
    s7.cmd(r'ovs-ofctl add-flow s7 "arp,nw_dst=10.1.0.2,actions=output:3"')
    s7.cmd(r'ovs-ofctl add-flow s7 "arp,nw_dst=10.1.1.2,actions=output:3"')
    s7.cmd(r'ovs-ofctl add-flow s7 "arp,nw_dst=10.2.0.2,actions=output:3"')
    s7.cmd(r'ovs-ofctl add-flow s7 "arp,nw_dst=10.2.1.2,actions=output:3"')
    s7.cmd(r'ovs-ofctl add-flow s7 "icmp,nw_dst=10.0.0.2,actions=output:3"')
    s7.cmd(r'ovs-ofctl add-flow s7 "icmp,nw_dst=10.0.1.2,actions=output:3"')
    s7.cmd(r'ovs-ofctl add-flow s7 "icmp,nw_dst=10.1.0.2,actions=output:3"')
    s7.cmd(r'ovs-ofctl add-flow s7 "icmp,nw_dst=10.1.1.2,actions=output:3"')
    s7.cmd(r'ovs-ofctl add-flow s7 "icmp,nw_dst=10.2.0.2,actions=output:3"')
    s7.cmd(r'ovs-ofctl add-flow s7 "icmp,nw_dst=10.2.1.2,actions=output:3"')

    s7.cmd(r'ovs-ofctl add-flow s7 "arp,nw_dst=10.0.0.3,actions=output:4"')
    s7.cmd(r'ovs-ofctl add-flow s7 "arp,nw_dst=10.0.1.3,actions=output:4"')
    s7.cmd(r'ovs-ofctl add-flow s7 "arp,nw_dst=10.1.0.3,actions=output:4"')
    s7.cmd(r'ovs-ofctl add-flow s7 "arp,nw_dst=10.1.1.3,actions=output:4"')
    s7.cmd(r'ovs-ofctl add-flow s7 "arp,nw_dst=10.2.0.3,actions=output:4"')
    s7.cmd(r'ovs-ofctl add-flow s7 "arp,nw_dst=10.2.1.3,actions=output:4"')
    s7.cmd(r'ovs-ofctl add-flow s7 "icmp,nw_dst=10.0.0.3,actions=output:4"')
    s7.cmd(r'ovs-ofctl add-flow s7 "icmp,nw_dst=10.0.1.3,actions=output:4"')
    s7.cmd(r'ovs-ofctl add-flow s7 "icmp,nw_dst=10.1.0.3,actions=output:4"')
    s7.cmd(r'ovs-ofctl add-flow s7 "icmp,nw_dst=10.1.1.3,actions=output:4"')
    s7.cmd(r'ovs-ofctl add-flow s7 "icmp,nw_dst=10.2.0.3,actions=output:4"')
    s7.cmd(r'ovs-ofctl add-flow s7 "icmp,nw_dst=10.2.1.3,actions=output:4"')
    #s8
    s8.cmd(r'ovs-ofctl add-flow s8 "arp,nw_dst=10.3.1.2,actions=output:1"')
    s8.cmd(r'ovs-ofctl add-flow s8 "arp,nw_dst=10.3.1.3,actions=output:2"')
    s8.cmd(r'ovs-ofctl add-flow s8 "icmp,nw_dst=10.3.1.2,actions=output:1"')
    s8.cmd(r'ovs-ofctl add-flow s8 "icmp,nw_dst=10.3.1.3,actions=output:2"')
    s8.cmd(r'ovs-ofctl add-flow s8 "arp,nw_dst=10.3.0.2,actions=output:4"')
    s8.cmd(r'ovs-ofctl add-flow s8 "arp,nw_dst=10.3.0.3,actions=output:4"')
    s8.cmd(r'ovs-ofctl add-flow s8 "icmp,nw_dst=10.3.0.2,actions=output:4"')
    s8.cmd(r'ovs-ofctl add-flow s8 "icmp,nw_dst=10.3.0.3,actions=output:4"')

    s8.cmd(r'ovs-ofctl add-flow s8 "arp,nw_dst=10.0.0.2,actions=output:4"')
    s8.cmd(r'ovs-ofctl add-flow s8 "arp,nw_dst=10.0.1.2,actions=output:4"')
    s8.cmd(r'ovs-ofctl add-flow s8 "arp,nw_dst=10.1.0.2,actions=output:4"')
    s8.cmd(r'ovs-ofctl add-flow s8 "arp,nw_dst=10.1.1.2,actions=output:4"')
    s8.cmd(r'ovs-ofctl add-flow s8 "arp,nw_dst=10.2.0.2,actions=output:4"')
    s8.cmd(r'ovs-ofctl add-flow s8 "arp,nw_dst=10.2.1.2,actions=output:4"')
    s8.cmd(r'ovs-ofctl add-flow s8 "icmp,nw_dst=10.0.0.2,actions=output:4"')
    s8.cmd(r'ovs-ofctl add-flow s8 "icmp,nw_dst=10.0.1.2,actions=output:4"')
    s8.cmd(r'ovs-ofctl add-flow s8 "icmp,nw_dst=10.1.0.2,actions=output:4"')
    s8.cmd(r'ovs-ofctl add-flow s8 "icmp,nw_dst=10.1.1.2,actions=output:4"')
    s8.cmd(r'ovs-ofctl add-flow s8 "icmp,nw_dst=10.2.0.2,actions=output:4"')
    s8.cmd(r'ovs-ofctl add-flow s8 "icmp,nw_dst=10.2.1.2,actions=output:4"')

    s8.cmd(r'ovs-ofctl add-flow s8 "arp,nw_dst=10.0.0.3,actions=output:3"')
    s8.cmd(r'ovs-ofctl add-flow s8 "arp,nw_dst=10.0.1.3,actions=output:3"')
    s8.cmd(r'ovs-ofctl add-flow s8 "arp,nw_dst=10.1.0.3,actions=output:3"')
    s8.cmd(r'ovs-ofctl add-flow s8 "arp,nw_dst=10.1.1.3,actions=output:3"')
    s8.cmd(r'ovs-ofctl add-flow s8 "arp,nw_dst=10.2.0.3,actions=output:3"')
    s8.cmd(r'ovs-ofctl add-flow s8 "arp,nw_dst=10.2.1.3,actions=output:3"')
    s8.cmd(r'ovs-ofctl add-flow s8 "icmp,nw_dst=10.0.0.3,actions=output:3"')
    s8.cmd(r'ovs-ofctl add-flow s8 "icmp,nw_dst=10.0.1.3,actions=output:3"')
    s8.cmd(r'ovs-ofctl add-flow s8 "icmp,nw_dst=10.1.0.3,actions=output:3"')
    s8.cmd(r'ovs-ofctl add-flow s8 "icmp,nw_dst=10.1.1.3,actions=output:3"')
    s8.cmd(r'ovs-ofctl add-flow s8 "icmp,nw_dst=10.2.0.3,actions=output:3"')
    s8.cmd(r'ovs-ofctl add-flow s8 "icmp,nw_dst=10.2.1.3,actions=output:3"')
    #s15
    s15.cmd(
        r'ovs-ofctl add-flow s15 "arp,nw_dst=10.3.0.0/24,actions=output:1"')
    s15.cmd(
        r'ovs-ofctl add-flow s15 "arp,nw_dst=10.3.1.0/24,actions=output:2"')
    s15.cmd(
        r'ovs-ofctl add-flow s15 "icmp,nw_dst=10.3.0.0/24,actions=output:1"')
    s15.cmd(
        r'ovs-ofctl add-flow s15 "icmp,nw_dst=10.3.1.0/24,actions=output:2"')

    s15.cmd(r'ovs-ofctl add-flow s15 "arp,nw_dst=10.0.0.2,actions=output:3"')
    s15.cmd(r'ovs-ofctl add-flow s15 "arp,nw_dst=10.0.1.2,actions=output:3"')
    s15.cmd(r'ovs-ofctl add-flow s15 "arp,nw_dst=10.1.0.2,actions=output:3"')
    s15.cmd(r'ovs-ofctl add-flow s15 "arp,nw_dst=10.1.1.2,actions=output:3"')
    s15.cmd(r'ovs-ofctl add-flow s15 "arp,nw_dst=10.2.0.2,actions=output:3"')
    s15.cmd(r'ovs-ofctl add-flow s15 "arp,nw_dst=10.2.1.2,actions=output:3"')
    s15.cmd(r'ovs-ofctl add-flow s15 "icmp,nw_dst=10.0.0.2,actions=output:3"')
    s15.cmd(r'ovs-ofctl add-flow s15 "icmp,nw_dst=10.0.1.2,actions=output:3"')
    s15.cmd(r'ovs-ofctl add-flow s15 "icmp,nw_dst=10.1.0.2,actions=output:3"')
    s15.cmd(r'ovs-ofctl add-flow s15 "icmp,nw_dst=10.1.1.2,actions=output:3"')
    s15.cmd(r'ovs-ofctl add-flow s15 "icmp,nw_dst=10.2.0.2,actions=output:3"')
    s15.cmd(r'ovs-ofctl add-flow s15 "icmp,nw_dst=10.2.1.2,actions=output:3"')

    s15.cmd(r'ovs-ofctl add-flow s15 "arp,nw_dst=10.0.0.3,actions=output:4"')
    s15.cmd(r'ovs-ofctl add-flow s15 "arp,nw_dst=10.0.1.3,actions=output:4"')
    s15.cmd(r'ovs-ofctl add-flow s15 "arp,nw_dst=10.1.0.3,actions=output:4"')
    s15.cmd(r'ovs-ofctl add-flow s15 "arp,nw_dst=10.1.1.3,actions=output:4"')
    s15.cmd(r'ovs-ofctl add-flow s15 "arp,nw_dst=10.2.0.3,actions=output:4"')
    s15.cmd(r'ovs-ofctl add-flow s15 "arp,nw_dst=10.2.1.3,actions=output:4"')
    s15.cmd(r'ovs-ofctl add-flow s15 "icmp,nw_dst=10.0.0.3,actions=output:4"')
    s15.cmd(r'ovs-ofctl add-flow s15 "icmp,nw_dst=10.0.1.3,actions=output:4"')
    s15.cmd(r'ovs-ofctl add-flow s15 "icmp,nw_dst=10.1.0.3,actions=output:4"')
    s15.cmd(r'ovs-ofctl add-flow s15 "icmp,nw_dst=10.1.1.3,actions=output:4"')
    s15.cmd(r'ovs-ofctl add-flow s15 "icmp,nw_dst=10.2.0.3,actions=output:4"')
    s15.cmd(r'ovs-ofctl add-flow s15 "icmp,nw_dst=10.2.1.3,actions=output:4"')
    #s16
    s16.cmd(
        r'ovs-ofctl add-flow s16 "arp,nw_dst=10.3.0.0/24,actions=output:1"')
    s16.cmd(
        r'ovs-ofctl add-flow s16 "arp,nw_dst=10.3.1.0/24,actions=output:2"')
    s16.cmd(
        r'ovs-ofctl add-flow s16 "icmp,nw_dst=10.3.0.0/24,actions=output:1"')
    s16.cmd(
        r'ovs-ofctl add-flow s16 "icmp,nw_dst=10.3.1.0/24,actions=output:2"')

    s16.cmd(r'ovs-ofctl add-flow s16 "arp,nw_dst=10.0.0.2,actions=output:4"')
    s16.cmd(r'ovs-ofctl add-flow s16 "arp,nw_dst=10.0.1.2,actions=output:4"')
    s16.cmd(r'ovs-ofctl add-flow s16 "arp,nw_dst=10.1.0.2,actions=output:4"')
    s16.cmd(r'ovs-ofctl add-flow s16 "arp,nw_dst=10.1.1.2,actions=output:4"')
    s16.cmd(r'ovs-ofctl add-flow s16 "arp,nw_dst=10.2.0.2,actions=output:4"')
    s16.cmd(r'ovs-ofctl add-flow s16 "arp,nw_dst=10.2.1.2,actions=output:4"')
    s16.cmd(r'ovs-ofctl add-flow s16 "icmp,nw_dst=10.0.0.2,actions=output:4"')
    s16.cmd(r'ovs-ofctl add-flow s16 "icmp,nw_dst=10.0.1.2,actions=output:4"')
    s16.cmd(r'ovs-ofctl add-flow s16 "icmp,nw_dst=10.1.0.2,actions=output:4"')
    s16.cmd(r'ovs-ofctl add-flow s16 "icmp,nw_dst=10.1.1.2,actions=output:4"')
    s16.cmd(r'ovs-ofctl add-flow s16 "icmp,nw_dst=10.2.0.2,actions=output:4"')
    s16.cmd(r'ovs-ofctl add-flow s16 "icmp,nw_dst=10.2.1.2,actions=output:4"')

    s16.cmd(r'ovs-ofctl add-flow s16 "arp,nw_dst=10.0.0.3,actions=output:3"')
    s16.cmd(r'ovs-ofctl add-flow s16 "arp,nw_dst=10.0.1.3,actions=output:3"')
    s16.cmd(r'ovs-ofctl add-flow s16 "arp,nw_dst=10.1.0.3,actions=output:3"')
    s16.cmd(r'ovs-ofctl add-flow s16 "arp,nw_dst=10.1.1.3,actions=output:3"')
    s16.cmd(r'ovs-ofctl add-flow s16 "arp,nw_dst=10.2.0.3,actions=output:3"')
    s16.cmd(r'ovs-ofctl add-flow s16 "arp,nw_dst=10.2.1.3,actions=output:3"')
    s16.cmd(r'ovs-ofctl add-flow s16 "icmp,nw_dst=10.0.0.3,actions=output:3"')
    s16.cmd(r'ovs-ofctl add-flow s16 "icmp,nw_dst=10.0.1.3,actions=output:3"')
    s16.cmd(r'ovs-ofctl add-flow s16 "icmp,nw_dst=10.1.0.3,actions=output:3"')
    s16.cmd(r'ovs-ofctl add-flow s16 "icmp,nw_dst=10.1.1.3,actions=output:3"')
    s16.cmd(r'ovs-ofctl add-flow s16 "icmp,nw_dst=10.2.0.3,actions=output:3"')
    s16.cmd(r'ovs-ofctl add-flow s16 "icmp,nw_dst=10.2.1.3,actions=output:3"')
    #s17
    s17.cmd(
        r'ovs-ofctl add-flow s17 "arp,nw_dst=10.0.0.0/16,actions=output:1"')
    s17.cmd(
        r'ovs-ofctl add-flow s17 "arp,nw_dst=10.1.0.0/16,actions=output:2"')
    s17.cmd(
        r'ovs-ofctl add-flow s17 "arp,nw_dst=10.2.0.0/16,actions=output:3"')
    s17.cmd(
        r'ovs-ofctl add-flow s17 "arp,nw_dst=10.3.0.0/16,actions=output:4"')
    s17.cmd(
        r'ovs-ofctl add-flow s17 "icmp,nw_dst=10.0.0.0/16,actions=output:1"')
    s17.cmd(
        r'ovs-ofctl add-flow s17 "icmp,nw_dst=10.1.0.0/16,actions=output:2"')
    s17.cmd(
        r'ovs-ofctl add-flow s17 "icmp,nw_dst=10.2.0.0/16,actions=output:3"')
    s17.cmd(
        r'ovs-ofctl add-flow s17 "icmp,nw_dst=10.3.0.0/16,actions=output:4"')
    #s18
    s18.cmd(
        r'ovs-ofctl add-flow s18 "arp,nw_dst=10.0.0.0/16,actions=output:1"')
    s18.cmd(
        r'ovs-ofctl add-flow s18 "arp,nw_dst=10.1.0.0/16,actions=output:2"')
    s18.cmd(
        r'ovs-ofctl add-flow s18 "arp,nw_dst=10.2.0.0/16,actions=output:3"')
    s18.cmd(
        r'ovs-ofctl add-flow s18 "arp,nw_dst=10.3.0.0/16,actions=output:4"')
    s18.cmd(
        r'ovs-ofctl add-flow s18 "icmp,nw_dst=10.0.0.0/16,actions=output:1"')
    s18.cmd(
        r'ovs-ofctl add-flow s18 "icmp,nw_dst=10.1.0.0/16,actions=output:2"')
    s18.cmd(
        r'ovs-ofctl add-flow s18 "icmp,nw_dst=10.2.0.0/16,actions=output:3"')
    s18.cmd(
        r'ovs-ofctl add-flow s18 "icmp,nw_dst=10.3.0.0/16,actions=output:4"')
    #s19
    s19.cmd(
        r'ovs-ofctl add-flow s19 "arp,nw_dst=10.0.0.0/16,actions=output:1"')
    s19.cmd(
        r'ovs-ofctl add-flow s19 "arp,nw_dst=10.1.0.0/16,actions=output:2"')
    s19.cmd(
        r'ovs-ofctl add-flow s19 "arp,nw_dst=10.2.0.0/16,actions=output:3"')
    s19.cmd(
        r'ovs-ofctl add-flow s19 "arp,nw_dst=10.3.0.0/16,actions=output:4"')
    s19.cmd(
        r'ovs-ofctl add-flow s19 "icmp,nw_dst=10.0.0.0/16,actions=output:1"')
    s19.cmd(
        r'ovs-ofctl add-flow s19 "icmp,nw_dst=10.1.0.0/16,actions=output:2"')
    s19.cmd(
        r'ovs-ofctl add-flow s19 "icmp,nw_dst=10.2.0.0/16,actions=output:3"')
    s19.cmd(
        r'ovs-ofctl add-flow s19 "icmp,nw_dst=10.3.0.0/16,actions=output:4"')
    #s20
    s20.cmd(
        r'ovs-ofctl add-flow s20 "arp,nw_dst=10.0.0.0/16,actions=output:1"')
    s20.cmd(
        r'ovs-ofctl add-flow s20 "arp,nw_dst=10.1.0.0/16,actions=output:2"')
    s20.cmd(
        r'ovs-ofctl add-flow s20 "arp,nw_dst=10.2.0.0/16,actions=output:3"')
    s20.cmd(
        r'ovs-ofctl add-flow s20 "arp,nw_dst=10.3.0.0/16,actions=output:4"')
    s20.cmd(
        r'ovs-ofctl add-flow s20 "icmp,nw_dst=10.0.0.0/16,actions=output:1"')
    s20.cmd(
        r'ovs-ofctl add-flow s20 "icmp,nw_dst=10.1.0.0/16,actions=output:2"')
    s20.cmd(
        r'ovs-ofctl add-flow s20 "icmp,nw_dst=10.2.0.0/16,actions=output:3"')
    s20.cmd(
        r'ovs-ofctl add-flow s20 "icmp,nw_dst=10.3.0.0/16,actions=output:4"')

    CLI(net)
    net.stop()
def treeTopo():
    net = Mininet(controller=Controller)

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

    info('*** Adding hosts\n')
    h1 = net.addHost('h1',
                     cls=Host,
                     ip='10.0.0.1',
                     mac='00:00:00:00:00:01',
                     defaultRoute=None)
    h2 = net.addHost('h2',
                     cls=Host,
                     ip='10.0.0.2',
                     mac='00:00:00:00:00:02',
                     defaultRoute=None)
    h3 = net.addHost('h3',
                     cls=Host,
                     ip='10.0.0.3',
                     mac='00:00:00:00:00:03',
                     defaultRoute=None)
    h4 = net.addHost('h4',
                     cls=Host,
                     ip='10.0.0.4',
                     mac='00:00:00:00:00:04',
                     defaultRoute=None)
    h5 = net.addHost('h5',
                     cls=Host,
                     ip='10.0.0.5',
                     mac='00:00:00:00:00:05',
                     defaultRoute=None)
    h6 = net.addHost('h6',
                     cls=Host,
                     ip='10.0.0.6',
                     mac='00:00:00:00:00:06',
                     defaultRoute=None)
    h7 = net.addHost('h7',
                     cls=Host,
                     ip='10.0.0.7',
                     mac='00:00:00:00:00:07',
                     defaultRoute=None)

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

    info('*** Creating links\n')
    s2h1 = {'bw': 1000}
    net.addLink(h1, s2, cls=TCLink, **s2h1)
    s2h2 = {'bw': 1000}
    net.addLink(h2, s2, cls=TCLink, **s2h2)
    s2h3 = {'bw': 1000}
    net.addLink(h3, s2, cls=TCLink, **s2h3)
    s2h4 = {'bw': 1000}
    net.addLink(h4, s2, cls=TCLink, **s2h4)
    s3h5 = {'bw': 1000}
    net.addLink(h5, s3, cls=TCLink, **s3h5)
    s3h6 = {'bw': 1000}
    net.addLink(h6, s3, cls=TCLink, **s3h6)
    s3h7 = {'bw': 1000}
    net.addLink(h7, s3, cls=TCLink, **s3h7)

    root = s1
    layer1 = [s2, s3]

    for idx, l1 in enumerate(layer1):
        rootl1 = {'bw': 10000}
        net.addLink(root, l1)

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

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

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

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

    info('*** Stopping network')
    net.stop()
Beispiel #6
0
def mobileNet(loc, loss, conges, delay):

    print("*** System configuration ***\n")
    # Configuring the congestion control
    if conges == 'bbr':
        os.system('sudo sysctl -w net.core.default_qdisc=fq')
    else:
        os.system('sudo sysctl -w net.core.default_qdisc=pfifo_fast')
    os.system('sudo sysctl -w net.ipv4.tcp_congestion_control=' + conges)

    net = Mininet(controller=Controller, link=TCLink, autoSetMacs=True)

    print("*** Creating nodes ***")
    nodes = {}

    node = net.addHost('r1', cls=LinuxRouter, ip='10.0.0.1/24')
    nodes['r1'] = node
    node = net.addHost('r2', cls=LinuxRouter, ip='10.0.0.2/24')
    nodes['r2'] = node
    node = net.addHost('h1', ip='10.0.1.2/24', defaultRoute='via 10.0.1.1')
    nodes['h1'] = node
    node = net.addHost('h2', ip='10.0.2.2/24', defaultRoute='via 10.0.2.1')
    nodes['h2'] = node
    node = net.addSwitch('s1')
    nodes['s1'] = node
    node = net.addSwitch('s2')
    nodes['s2'] = node

    net.addLink(nodes['r1'],
                nodes['r2'],
                intfName1='r1-eth0',
                intfName2='r2-eth0',
                bw=10,
                delay=str(delay) + 'ms',
                loss=float(loss) * 100)
    net.addLink(nodes['s1'], nodes['r1'], intfName2='r1-eth1', bw=10)
    net.addLink(nodes['s2'], nodes['r2'], intfName2='r2-eth1', bw=10)
    net.addLink(nodes['h1'], nodes['s1'], bw=10)
    net.addLink(nodes['h2'], nodes['s2'], bw=10)

    node = net.addController('c0')
    nodes['c0'] = node

    print("*** Starting network simulation ***")
    net.start()

    # Addressing and routing
    r1, r2 = [nodes['r1'], nodes['r2']]
    r1.cmd('ip addr add 10.0.1.1/24 dev r1-eth1')
    r1.cmd('../tunnel-forwarder/netconfig.sh set tunt1 192.168.0.1/24')
    r1.cmd('ip route add 10.0.2.0/24 via 192.168.0.1')
    r2.cmd('ip addr add 10.0.2.1/24 dev r2-eth1')
    r2.cmd('../tunnel-forwarder/netconfig.sh set tunt2 192.168.0.2/24')
    r2.cmd('ip route add 10.0.1.0/24 via 192.168.0.2')

    # Launching the forwarder to initiate the tunnel
    r2.cmd('../tunnel-forwarder/tunnel -i tunt2 -s &')
    r1.cmd('../tunnel-forwarder/tunnel -i tunt1 -c 10.0.0.2 &')

    # Adding tap interfaces for connecting VMs
    print("*** Configuring virtual ports for VMs ***")
    os.system('sudo ip tuntap add mode tap vport1')
    os.system('sudo ip tuntap add mode tap vport2')
    os.system('sudo ifconfig vport1 up')
    os.system('sudo ifconfig vport2 up')
    os.system('sudo ovs-vsctl add-port s1 vport1')
    os.system('sudo ovs-vsctl add-port s2 vport2')

    CLI(net)

    print "*** Starting to generate the traffic ***"
    # traffic_thread = threading.Thread(target=sendingIperfTraffic, args=(nodes, loc))
    # traffic_thread.start()
    # traffic_thread.join()

    print("*** Stopping network ***")
    os.system('sudo ovs-vsctl del-port s1 vport1')
    os.system('sudo ovs-vsctl del-port s2 vport2')
    os.system('sudo ifconfig vport1 down')
    os.system('sudo ifconfig vport2 down')
    os.system('sudo ip link delete vport1')
    os.system('sudo ip link delete vport2')
    net.stop()
Beispiel #7
0
def CreateTopology():
    net = Mininet(controller=RemoteController,
                  link=TCLink,
                  switch=OVSKernelSwitch)

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

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

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

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

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

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

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

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

    host = {}

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

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

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

        if x >= 54:
            x = 1
        WaitTillEndOfSec(2)
    # ------

    # --------
    print '#Pulse pattern...'
    thread.start_new_thread(PulseTrafficThread, (host, ))

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

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

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

    print 'Stopping network...'
    net.stop()
def topology():
    "Create a network."
    net = Mininet(controller=Controller, link=TCLink, switch=OVSKernelSwitch, accessPoint=OVSKernelAP)
    global gnet
    gnet = net

    print "*** Creating nodes"
    car = []
    stas = []
    for x in range(0, 4):
        car.append(x)
        stas.append(x)
    for x in range(0, 4):
        car[x] = net.addCar('car%s' % (x), wlans=2, ip='10.0.0.%s/8' % (x + 1), \
        mac='00:00:00:00:00:0%s' % x, mode='b')

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

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

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

    print "*** Creating links"
    net.addLink(eNodeB1, switch)
    net.addLink(eNodeB2, switch)
    net.addLink(rsu1, switch)
    net.addLink(switch, client)

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

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

    i = 1
    j = 2
    for c in car:
        c.cmd('ifconfig %s-wlan0 192.168.0.%s/24 up' % (c, i))
        c.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (c, i))
        c.cmd('ip route add 10.0.0.0/8 via 192.168.1.%s' % j)
        i += 2
        j += 2

    i = 1
    j = 2
    for v in net.vehiclesSTA:
        v.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (v, j))
        v.cmd('ifconfig %s-mp0 10.0.0.%s/24 up' % (v, i))
        v.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward')
        i += 1
        j += 2

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

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

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

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

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

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

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

    """plot graph"""
    net.plotGraph(max_x=250, max_y=250)

    net.startGraph()

    # Uncomment and modify the two commands below to stream video using VLC 
    car[0].cmdPrint("vlc -vvv bunnyMob.mp4 --sout '#duplicate{dst=rtp{dst=200.0.10.2,port=5004,mux=ts},dst=display}' :sout-keep &")
    client.cmdPrint("vlc rtp://@200.0.10.2:5004 &")

    car[0].moveNodeTo('95,100,0')
    car[1].moveNodeTo('80,100,0')
    car[2].moveNodeTo('65,100,0')
    car[3].moveNodeTo('50,100,0')

    os.system('ovs-ofctl del-flows switch')

    time.sleep(3)

    apply_experiment(car,client,switch,net)

    # Uncomment the line below to generate the graph that you implemented
    graphic()

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

   

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

    print "*** Stopping network"
    net.stop()
Beispiel #9
0
def main(cli=0):
    net = Mininet(controller=None)

    # add hosts
    h1 = net.addHost('h1', ip='172.16.101.5/24', mac='00:04:00:00:00:02')
    h2 = net.addHost('h2', ip='172.16.102.5/24', mac='00:05:00:00:00:02')
    h3 = net.addHost('h3', ip='172.16.102.6/24', mac='00:06:00:00:00:02')
    h4 = net.addHost('h4', ip='172.16.102.7/24', mac='00:07:00:00:00:02')

    # add switch
    sw_model_dir = '/p4factory/targets/switch/'
    sw1_fs_map = []
    sw1_fs_map.append([os.getcwd() + '/' + 'configs/sw1/l3vi', '/configs'])
    sw1 = net.addSwitch('sw1',
                        cls=BmDockerSwitch,
                        image='p4dockerswitch',
                        fs_map=sw1_fs_map,
                        model_dir=sw_model_dir)

    # add links
    if StrictVersion(VERSION) <= StrictVersion('2.2.0'):
        net.addLink(sw1, h1, port1=1)
        net.addLink(sw1, h2, port1=2)
        net.addLink(sw1, h3, port1=3)
        net.addLink(sw1, h4, port1=4)
    else:
        net.addLink(sw1, h1, port1=1, fast=False)
        net.addLink(sw1, h2, port1=2, fast=False)
        net.addLink(sw1, h3, port1=3, fast=False)
        net.addLink(sw1, h4, port1=4, fast=False)

    net.start()

    # configure hosts
    h1.setDefaultRoute('via 172.16.101.1')
    h2.setDefaultRoute('via 172.16.102.1')
    h3.setDefaultRoute('via 172.16.102.1')
    h4.setDefaultRoute('via 172.16.102.1')

    result = 0

    if cli:
        CLI(net)
    else:
        hosts = net.hosts

        # ping hosts
        print "PING BETWEEN THE HOSTS"
        result = net.ping(hosts, 30)

        # print host arp table & routes
        for host in hosts:
            print "ARP ENTRIES ON HOST"
            print host.cmd('arp -n')
            print "HOST ROUTES"
            print host.cmd('route')
            print "HOST INTERFACE LIST"
            intfList = host.intfNames()
            print intfList

        if result != 0:
            print "PING FAILED BETWEEN HOSTS %s" % (hosts)
        else:
            print "PING SUCCESSFUL!!!"

    net.stop()
    return result
Beispiel #10
0
def myNetwork():

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

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

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

    info('*** Add hosts\n')
    h1 = net.addHost('h1',
                     cls=Host,
                     ip='10.0.0.1',
                     defaultRoute=None,
                     mac='00:00:00:00:00:01')
    h2 = net.addHost('h2',
                     cls=Host,
                     ip='10.0.0.2',
                     defaultRoute=None,
                     mac='00:00:00:00:00:02')
    h3 = net.addHost('h3',
                     cls=Host,
                     ip='10.0.0.3',
                     defaultRoute=None,
                     mac='00:00:00:00:00:03')
    h4 = net.addHost('h4',
                     cls=Host,
                     ip='10.0.0.4',
                     defaultRoute=None,
                     mac='00:00:00:00:00:04')
    h5 = net.addHost('h5',
                     cls=Host,
                     ip='10.0.0.5',
                     defaultRoute=None,
                     mac='00:00:00:00:00:05')
    h6 = net.addHost('h6',
                     cls=Host,
                     ip='10.0.0.6',
                     defaultRoute=None,
                     mac='00:00:00:00:00:06')

    info('*** Add links\n')
    # balanceado
    # net.addLink(h1, s1, bw=10)
    # net.addLink(h2, s1, bw=10)
    # net.addLink(h3, s1, bw=10)
    # net.addLink(h4, s1, bw=10)
    # net.addLink(h5, s1, bw=10)
    # net.addLink(h6, s1, bw=100)

    net.addLink(h1, s1, bw=5)
    net.addLink(h2, s1, bw=5)
    net.addLink(h3, s1, bw=7.5)
    net.addLink(h4, s1, bw=10)
    net.addLink(h5, s1, bw=10)
    net.addLink(h6, s1, bw=100)

    # net.addLink(s1, s2, bw=0.1) #port 1
    # net.addLink(s1, s2, bw=10) #port 2

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

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

    net.get('h1').popen('python -m SimpleHTTPServer 80')
    net.get('h2').popen('python -m SimpleHTTPServer 80')
    net.get('h3').popen('python -m SimpleHTTPServer 80')
    net.get('h4').popen('python -m SimpleHTTPServer 80')
    net.get('h5').popen('python -m SimpleHTTPServer 80')

    CLI(net)
    net.stop()
def createNetwork():
    #send rate at each link in Mbps
    bwg = 1  #in Mbps
    bwbn = 1  #in Mbps
    loss = 8  #in %
    mqs = 100  #max queue size of interfaces
    dly = '2.5ms'

    #create empty network
    net = Mininet(intf=TCIntf)

    info('\n*** Adding controller\n')
    net.addController('c0')  #is it ok ?

    #add host to topology
    ht = net.addHost('ht', ip='10.10.0.1/24')
    hu = net.addHost('hu', ip='10.10.0.2/24')
    it = net.addHost('it', ip='10.20.0.1/24')
    iu = net.addHost('iu', ip='10.20.0.2/24')

    rh = net.addHost('rh', ip='10.10.0.10/24')
    ri = net.addHost('ri', ip='10.20.0.20/24')

    info('\n** Adding Switches\n')
    # Adding 2 switches to the network
    sw1 = net.addSwitch('sw1')
    sw2 = net.addSwitch('sw2')

    info('\n** Creating Links \n')
    #create link beetween the network
    link_ht_sw1 = net.addLink(ht, sw1)
    link_hu_sw1 = net.addLink(hu, sw1)
    link_rh_sw1 = net.addLink(rh, sw1, intfName1='rh-eth0')

    link_it_sw2 = net.addLink(it, sw2)
    link_iu_sw2 = net.addLink(iu, sw2)
    link_ri_sw2 = net.addLink(ri, sw2, intfName1='ri-eth0')

    link_rh_ri = net.addLink(rh, ri, intfName1='rh-eth1', intfName2='ri-eth1')

    #set bandwith
    link_ht_sw1.intf1.config(bw=bwbn, max_queue_size=mqs)
    link_hu_sw1.intf1.config(bw=bwbn, max_queue_size=mqs)
    link_rh_sw1.intf1.config(
        bw=bwbn, max_queue_size=mqs
    )  #max_queue_size is hardcoded low to prevent bufferbloat, too high queuing delays

    link_it_sw2.intf1.config(bw=bwg, max_queue_size=mqs)
    link_iu_sw2.intf1.config(bw=bwg, max_queue_size=mqs)
    link_ri_sw2.intf1.config(bw=bwg, max_queue_size=mqs,
                             delay=dly)  #delay is set at ri on both interfaces

    link_rh_ri.intf1.config(
        bw=bwg, max_queue_size=mqs,
        loss=loss)  #loss is set at rh on its interface to ri only

    link_ht_sw1.intf2.config(bw=bwbn, max_queue_size=mqs)
    link_hu_sw1.intf2.config(bw=bwbn, max_queue_size=mqs)
    link_rh_sw1.intf2.config(bw=bwbn, max_queue_size=mqs)

    link_it_sw2.intf2.config(bw=bwg, max_queue_size=mqs)
    link_iu_sw2.intf2.config(bw=bwg, max_queue_size=mqs)
    link_ri_sw2.intf2.config(bw=bwg, max_queue_size=mqs)

    link_rh_ri.intf2.config(bw=bwg, max_queue_size=mqs,
                            delay=dly)  #delay is set at ri on both interfaces

    net.start()

    info('\n*** Configuring hosts\n')

    rh.cmd(
        'ifconfig rh-eth1 10.12.0.10 netmask 255.255.255.0'
    )  #reconfiguring mutiples intefaces host to prevent mininet strange initialisation behaviors
    rh.cmd('ifconfig rh-eth0 10.10.0.10 netmask 255.255.255.0')
    rh.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward'
           )  #enable forwarding at routers

    ri.cmd(
        'ifconfig ri-eth1 10.12.0.20 netmask 255.255.255.0'
    )  #reconfiguring mutiples intefaces host to prvent mininet strange initialisation behaviors
    ri.cmd('ifconfig ri-eth0 10.20.0.20 netmask 255.255.255.0')
    ri.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward'
           )  #enable forwarding at routers

    #configure host default gateways
    ht.cmd('ip route add default via 10.10.0.10')
    hu.cmd('ip route add default via 10.10.0.10')
    it.cmd('ip route add default via 10.20.0.20')
    iu.cmd('ip route add default via 10.20.0.20')

    #configure router routing tables
    rh.cmd('ip route add default via 10.12.0.20')
    ri.cmd('ip route add default via 10.12.0.10')

    # weiyu:
    iu.cmd('touch server.pcap')
    hu.cmd('touch client.pcap')

    rh.cmd('tc qdisc del dev rh-eth1 root')

    start_nodes(rh, ri, iu, hu, mqs)  #experiment actions

    it.cmd(
        'ethtool -K it-eth0 tx off sg off tso off'
    )  #disable TSO on TCP on defaul TCP sender need to be done on other host if sending large TCP file from other nodes

    time.sleep(1)

    # Enable the mininet> prompt if uncommented
    info('\n*** Running CLI\n')
    CLI(net)

    # stops the simulation
    net.stop()
Beispiel #12
0
def myNetwork():

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

    info('*** Adding routers\n')
    fbn_r = net.addHost('FlyByNight', cls=Node, ip='0.0.0.0')
    ru_r = net.addHost('RsUs', cls=Node, ip='0.0.0.0')
    internet_r = net.addHost('Internet', cls=Node, ip='0.0.0.0')
    fbn_r.cmd('sysctl -w net.ipv4.ip_forward=1')
    ru_r.cmd('sysctl -w net.ipv4.ip_forward=1')
    internet_r.cmd('sysctl -w net.ipv4.ip_forward=1')

    info('*** Adding hosts\n')
    h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None)
    h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)
    h3 = net.addHost('h3', cls=Host, ip='10.0.0.2', defaultRoute=None)

    info('*** Adding links\n')
    TCLink(fbn_r,
           h1,
           bw=10,
           delay="15ms",
           jitter="1ms",
           loss=0,
           max_queue_size=100)
    TCLink(fbn_r,
           h2,
           bw=10,
           delay="15ms",
           jitter="1ms",
           loss=0,
           max_queue_size=100)
    TCLink(ru_r,
           h3,
           bw=10,
           delay="15ms",
           jitter="1ms",
           loss=0,
           max_queue_size=100)
    TCLink(fbn_r,
           internet_r,
           bw=10,
           delay="15ms",
           jitter="1ms",
           loss=0,
           max_queue_size=100)
    TCLink(ru_r,
           internet_r,
           bw=10,
           delay="15ms",
           jitter="1ms",
           loss=0,
           max_queue_size=100)

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

    info('*** Configuring addresses\n')
    h1.cmd('ifconfig h1-eth0 200.20.16.1 netmask 255.255.254.0 txqueuelen 1')
    h2.cmd('ifconfig h2-eth0 200.20.18.1 netmask 255.255.254.0 txqueuelen 1')
    h3.cmd('ifconfig h3-eth0 200.20.20.1 netmask 255.255.254.0 txqueuelen 1')
    fbn_r.cmd(
        'ifconfig FlyByNight-eth0 200.20.16.2 netmask 255.255.254.0 txqueuelen 1'
    )
    fbn_r.cmd(
        'ifconfig FlyByNight-eth1 200.20.18.2 netmask 255.255.254.0 txqueuelen 1'
    )
    fbn_r.cmd(
        'ifconfig FlyByNight-eth3 10.0.0.2 netmask 255.255.255.0 txqueuelen 1')
    ru_r.cmd(
        'ifconfig RsUs-eth0 200.20.20.2 netmask 255.255.254.0 txqueuelen 1')
    ru_r.cmd('ifconfig RsUs-eth1 10.0.1.2 netmask 255.255.255.0 txqueuelen 1')
    internet_r.cmd('ifconfig Internet-eth0 10.0.0.1 netmask 255.255.255.0')
    internet_r.cmd('ifconfig Internet-eth1 10.0.1.1 netmask 255.255.255.0')

    info('*** Adding routes\n')
    h1.cmd('route add default gw 200.20.16.2')
    h2.cmd('route add default gw 200.20.18.2')
    h3.cmd('route add default gw 200.20.20.2')
    internet_r.cmd(
        'route add -net 200.20.16.0 netmask 255.255.240.0 gw 10.0.0.2')
    internet_r.cmd(
        'route add -net 200.20.20.0 netmask 255.255.254.0 gw 10.0.1.2')
    internet_r.cmd('route add -net 199.31.0.0 netmask 255.255.0.0 gw 10.0.1.2')

    CLI(net)
    net.stop()
Beispiel #13
0
def dosSim():
    net = Mininet(controller=RemoteController)

    net.addController('c0', controller=RemoteController)

    ##build network
    # Add hosts and switches
    leftoneHost = net.addHost('h1')
    lefttwoHost = net.addHost('h2')
    leftthreeHost = net.addHost('h3')
    leftfourHost = net.addHost('h4')
    leftfiveHost = net.addHost('h5')
    leftsixHost = net.addHost('h6')
    leftsevenHost = net.addHost('h7')
    lefteightHost = net.addHost('h8')
    leftnineHost = net.addHost('h9')
    lefttenHost = net.addHost('h10')
    rightoneHost = net.addHost('h11')
    righttwoHost = net.addHost('h12')
    rightthreeHost = net.addHost('h13')
    rightfourHost = net.addHost('h14')
    rightfiveHost = net.addHost('h15')
    rightsixHost = net.addHost('h16')
    rightsevenHost = net.addHost('h17')
    righteightHost = net.addHost('h18')
    rightnineHost = net.addHost('h19')
    righttenHost = net.addHost('h20')
    leftSwitch = net.addSwitch('s1')
    rightSwitch = net.addSwitch('s2')
    centerSwitch = net.addSwitch('s3')

    # Add links
    net.addLink(leftoneHost, leftSwitch)
    net.addLink(lefttwoHost, leftSwitch)
    net.addLink(leftthreeHost, leftSwitch)
    net.addLink(leftfourHost, leftSwitch)
    net.addLink(leftfiveHost, leftSwitch)
    net.addLink(leftsixHost, leftSwitch)
    net.addLink(leftsevenHost, leftSwitch)
    net.addLink(lefteightHost, leftSwitch)
    net.addLink(leftnineHost, leftSwitch)
    net.addLink(lefttenHost, leftSwitch)
    net.addLink(rightoneHost, rightSwitch)
    net.addLink(righttwoHost, rightSwitch)
    net.addLink(rightthreeHost, rightSwitch)
    net.addLink(rightfourHost, rightSwitch)
    net.addLink(rightfiveHost, rightSwitch)
    net.addLink(rightsixHost, rightSwitch)
    net.addLink(rightsevenHost, rightSwitch)
    net.addLink(righteightHost, rightSwitch)
    net.addLink(rightnineHost, rightSwitch)
    net.addLink(righttenHost, rightSwitch)
    net.addLink(leftSwitch, centerSwitch)
    net.addLink(rightSwitch, centerSwitch)

    ##start network
    net.start()
    CLI(net)

    ##en network
    net.stop()
Beispiel #14
0
def multiControllerNet(con_num=2, sw_num=7, host_num=3):
    "Create a network from semi-scratch with multiple controllers."

    controller_list = []

    net = Mininet(controller=None, switch=OVSSwitch, link=TCLink)

    # for i in xrange(con_num):
    #     name = 'controller%s' % str(i)
    #     c = net.addController(name, controller=RemoteController,
    #                               port=6661 + i)
    #     controller_list.append(c)
    #     print "*** Creating %s" % name

    print "*** Creating c0"
    c0 = net.addController('c0', controller=RemoteController, port=6661)
    controller_list.append(c0)

    # Contact to a remote controller running at 192.168.75.147
    # which is the ip address of the virtual machine
    print "*** Creating c1"
    c1 = net.addController('c1',
                           controller=RemoteController,
                           ip='192.168.75.147',
                           port=6662)
    controller_list.append(c1)

    print "*** Creating switches"
    switch_list = [
        net.addSwitch('s%d' % (n + 1), protocols='OpenFlow13')
        for n in xrange(sw_num)
    ]

    print "*** Creating hosts"
    host_list = [net.addHost('h%d' % n) for n in xrange(host_num)]

    print "*** Creating links of host2switch."

    net.addLink(switch_list[0], host_list[0])
    net.addLink(switch_list[5], host_list[2])
    net.addLink(switch_list[6], host_list[1])

    print "*** Creating intra links of switch2switch."
    for i in xrange(0, sw_num - 2):
        net.addLink(switch_list[i], switch_list[i + 1])
    net.addLink(switch_list[4], switch_list[6])

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

    _No = 0
    for i in xrange(0, 3):
        switch_list[i].start([controller_list[_No]])

    _No = 1
    for j in xrange(3, 7):
        switch_list[j].start([controller_list[_No]])

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

    print "*** Stopping network"
    net.stop()
def defineNetwork():
    if len(sys.argv) < 2:
        print "Missing paramenter: python hotmboxes16-topo-2016-02-05.py <debug=1|0>"
        sys.exit()
        #commento
    debug = sys.argv[1]  #print some usefull information

    net = Mininet(topo=None, build=False, link=TCLink)
    net.addController(
        name='c0',
        controller=RemoteController,
        # ip='192.168.224.133',
        port=6633)
    #net = Mininet(controller=RemoteController, link=TCLink, build=False, xterms=False)

    info("*** Create an empty network and add nodes and swith to it *** \n")
    #net = Mininet(controller=RemoteController, link=TCLink, build=False) #MyPOXController
    info("\n*** Adding Controller: Controller will be external *** \n")

    #BUILDING CLUSTER 1: s1, s2, s3, s4 and vmu1, vmu2, dpi, wana, tc
    info("\n*** Creating Switch *** \n")
    s1 = net.addSwitch(
        's1'
    )  # this should be equivalent to s1 = net.addSwitch('s1', OVSSwitch)
    s1.cmd('ovs-vsctl del-br ' + s1.name)
    s1.cmd('ovs-vsctl add-br ' + s1.name)
    s1.cmd('ovs-vsctl set Bridge ' + s1.name +
           ' stp_enable=false')  # Disabling STP

    s2 = net.addSwitch('s2')
    s2.cmd('ovs-vsctl del-br ' + s2.name)
    s2.cmd('ovs-vsctl add-br ' + s2.name)
    s2.cmd('ovs-vsctl set Bridge ' + s2.name +
           ' stp_enable=false')  # Disabling STP

    s3 = net.addSwitch('s3')
    s3.cmd('ovs-vsctl del-br ' + s3.name)
    s3.cmd('ovs-vsctl add-br ' + s3.name)
    s3.cmd('ovs-vsctl set Bridge ' + s3.name +
           ' stp_enable=false')  # Disabling STP

    s4 = net.addSwitch('s4')
    s4.cmd('ovs-vsctl del-br ' + s4.name)
    s4.cmd('ovs-vsctl add-br ' + s4.name)
    s4.cmd('ovs-vsctl set Bridge ' + s4.name +
           ' stp_enable=false')  # Disabling STP

    info("\n*** Creating VM-User 1 *** \n")
    vmu1 = net.addHost('VMU1')
    info("\n*** Creating VM-User 2 *** \n")
    vmu2 = net.addHost('VMU2')
    info("\n*** Creating DPI *** \n")
    dpi = net.addHost('DPI')
    info("\n*** Creating WAN A. *** \n")
    wana = net.addHost('WANA')
    info("\n*** Creating TC *** \n")
    tc = net.addHost('TC')
    info("\n*** Creating Virtual Router 1 *** \n")
    vr1 = net.addHost('VR1')
    info("\n*** Creating Links on Cluster 1 *** \n")
    net.addLink(vmu1, s1, bw=100)
    net.addLink(vmu2, s1, bw=100)
    net.addLink(dpi, s1, bw=100)
    net.addLink(wana, s1, bw=100)
    net.addLink(wana, s1, bw=100)
    net.addLink(tc, s1, bw=100)
    net.addLink(tc, s1, bw=100)
    net.addLink(s1, s2, bw=100)
    net.addLink(s1, s3, bw=100)
    net.addLink(s2, s4, bw=100)
    net.addLink(s3, s4, bw=100)
    net.addLink(vr1, s4, bw=100)

    #BUILDING CLUSTER 2: s5, s6, s7, s8 and h2, wana2, vr2, vr3
    s5 = net.addSwitch('s5')
    s5.cmd('ovs-vsctl del-br ' + s5.name)
    s5.cmd('ovs-vsctl add-br ' + s5.name)
    s5.cmd('ovs-vsctl set Bridge ' + s5.name +
           ' stp_enable=false')  # Disabling STP

    s6 = net.addSwitch('s6')
    s6.cmd('ovs-vsctl del-br ' + s6.name)
    s6.cmd('ovs-vsctl add-br ' + s6.name)
    s6.cmd('ovs-vsctl set Bridge ' + s6.name +
           ' stp_enable=false')  # Disabling STP

    s7 = net.addSwitch('s7')
    s7.cmd('ovs-vsctl del-br ' + s7.name)
    s7.cmd('ovs-vsctl add-br ' + s7.name)
    s7.cmd('ovs-vsctl set Bridge ' + s7.name +
           ' stp_enable=false')  # Disabling STP

    s8 = net.addSwitch('s8')
    s8.cmd('ovs-vsctl del-br ' + s8.name)
    s8.cmd('ovs-vsctl add-br ' + s8.name)
    s8.cmd('ovs-vsctl set Bridge ' + s8.name +
           ' stp_enable=false')  # Disabling STP

    info("\n*** Creating Host 2 *** \n")
    h2 = net.addHost('H2')
    info("\n*** Creating WAN A. 2 *** \n")
    wana2 = net.addHost('WANA2')
    info("\n*** Creating VR2 *** \n")
    vr2 = net.addHost('VR2')
    info("\n*** Creating VR3 *** \n")
    vr3 = net.addHost('VR3')
    info("\n*** Creating Links on Cluster 2 *** \n")
    net.addLink(vr1, vr2, bw=100)
    net.addLink(vr2, s5, bw=100)
    net.addLink(s5, s6, bw=100)
    net.addLink(s5, s8, bw=100)
    net.addLink(h2, s8, bw=100)
    net.addLink(wana2, s6, bw=100)
    net.addLink(wana2, s6, bw=100)
    net.addLink(s6, s7, bw=100)
    net.addLink(s8, s7, bw=100)
    net.addLink(s7, vr3, bw=100)

    #BUILDING CLUSTER 3: s9, s10, s11, s12 and h3, wana3, vr4
    s9 = net.addSwitch('s9')
    s9.cmd('ovs-vsctl del-br ' + s9.name)
    s9.cmd('ovs-vsctl add-br ' + s9.name)
    s9.cmd('ovs-vsctl set Bridge ' + s9.name +
           ' stp_enable=false')  # Disabling STP

    s10 = net.addSwitch('s10')
    s10.cmd('ovs-vsctl del-br ' + s10.name)
    s10.cmd('ovs-vsctl add-br ' + s10.name)
    s10.cmd('ovs-vsctl set Bridge ' + s10.name +
            ' stp_enable=false')  # Disabling STP

    s11 = net.addSwitch('s11')
    s11.cmd('ovs-vsctl del-br ' + s11.name)
    s11.cmd('ovs-vsctl add-br ' + s11.name)
    s11.cmd('ovs-vsctl set Bridge ' + s11.name +
            ' stp_enable=false')  # Disabling STP

    s12 = net.addSwitch('s12')
    s12.cmd('ovs-vsctl del-br ' + s12.name)
    s12.cmd('ovs-vsctl add-br ' + s12.name)
    s12.cmd('ovs-vsctl set Bridge ' + s12.name +
            ' stp_enable=false')  # Disabling STP

    info("\n*** Creating Host 3 *** \n")
    h3 = net.addHost('H3')
    info("\n*** Creating WAN A. 3 *** \n")
    wana3 = net.addHost('WANA3')
    info("\n*** Creating VR4 *** \n")
    vr4 = net.addHost('VR4')
    info("\n*** Creating Links on Cluster 3 *** \n")
    net.addLink(vr4, vr3, bw=100)
    net.addLink(vr4, s9, bw=100)
    net.addLink(s9, s10, bw=100)
    net.addLink(s9, s12, bw=100)
    net.addLink(wana3, s10, bw=100)
    net.addLink(wana3, s10, bw=100)
    net.addLink(s10, s11, bw=100)
    net.addLink(s11, s12, bw=100)
    net.addLink(s11, h3, bw=100)

    #Trying to assign MAC address to each node of the cluster 1
    vmu1.setMAC("00:00:00:00:00:01", vmu1.name + "-eth0")
    vmu2.setMAC("00:00:00:00:00:02", vmu2.name + "-eth0")
    dpi.setMAC("00:00:00:00:00:03", dpi.name + "-eth0")
    wana.setMAC("00:00:00:00:00:04", wana.name + "-eth0")
    wana.setMAC("00:00:00:00:00:05", wana.name + "-eth1")
    tc.setMAC("00:00:00:00:00:06", tc.name + "-eth0")
    tc.setMAC("00:00:00:00:00:07", tc.name + "-eth1")
    vr1.setMAC("00:00:00:00:00:08", vr1.name + "-eth0")
    vr1.setMAC("00:00:00:00:00:09", vr1.name + "-eth1")

    #Trying to assign MAC address to each node of the cluster 2
    vr2.setMAC("00:00:00:00:00:0A", vr2.name + "-eth0")
    vr2.setMAC("00:00:00:00:00:0B", vr2.name + "-eth1")
    h2.setMAC("00:00:00:00:00:0C", h2.name + "-eth0")
    wana2.setMAC("00:00:00:00:00:0D", wana2.name + "-eth0")
    wana2.setMAC("00:00:00:00:00:0E", wana2.name + "-eth1")
    vr3.setMAC("00:00:00:00:00:0F", vr3.name + "-eth0")
    vr3.setMAC("00:00:00:00:00:10", vr3.name + "-eth1")

    #Trying to assign MAC address to each node of the cluster 3
    vr4.setMAC("00:00:00:00:00:11", vr4.name + "-eth0")
    vr4.setMAC("00:00:00:00:00:12", vr4.name + "-eth1")
    wana3.setMAC("00:00:00:00:00:13", wana3.name + "-eth0")
    wana3.setMAC("00:00:00:00:00:14", wana3.name + "-eth1")
    h3.setMAC("00:00:00:00:00:15", h3.name + "-eth0")

    #Disabling IPv6
    for host in net.hosts:
        print 'Going to disable IPv6 on ' + host.name
        host.cmd('sysctl -w net.ipv6.conf.all.disable_ipv6=1')
        host.cmd('sysctl -w net.ipv6.conf.default.disable_ipv6=1')
        host.cmd('sysctl -w net.ipv6.conf.lo.disable_ipv6=1')

    for switch in net.switches:
        for intf in switch.intfs.values():
            switch.cmd('ovs-vsctl add-port ' + switch.name + ' %s' % intf)
            print "Eseguito comando: ovs-vsctl add-port ", switch.name, " ", intf

    #info("\n*** Starting Network using Open vSwitch and remote controller*** \n")

    # Set the controller for the switch
    for switch in net.switches:
        switch.cmd('ovs-vsctl set-controller ' + switch.name +
                   ' tcp:127.0.0.1:6633')
        info('\n*** Waiting for switch to connect to controller')
        while 'is_connected' not in quietRun('ovs-vsctl show'):
            sleep(1)
            info('.')
        info('\n')

    # Creating a Linux Bridge on each host
    nhosts = len(net.hosts)
    print 'Total number of hosts: ' + str(nhosts)
    count = 1

    net.start()
    info('\n*** Going to take down default configuration ...\n')
    info(
        '\n*** ... and creating Linux bridge on WANA and TC, as well as configuring interfaces \n'
    )
    for host in net.hosts:
        print 'Deleting ip address on ' + host.name + '-eth0 interface ...'
        host.cmd('ip addr del ' + host.IP(host.name + '-eth0') + '/8 dev ' +
                 host.name + '-eth0')
        print 'Deleting entry in IP routing table on ' + host.name
        host.cmd('ip route del 10.0.0.0/8')
        print "Going to configure new IP"
        if host.name == 'WANA' or host.name == 'WANA2' or host.name == 'WANA3' or host.name == 'TC':  # VNFs case
            print "Host with 2 interfaces: " + host.name
            host.cmd('brctl addbr br-' + host.name)
            host.cmd('brctl addif br-' + host.name + ' ' + host.name + '-eth0')
            host.cmd('brctl addif br-' + host.name + ' ' + host.name + '-eth1')
            if host.name == 'WANA' or host.name == 'TC':
                host.cmd('ip addr add 192.168.1.' + str(count) +
                         '/24 dev br-' + host.name)
            elif host.name == 'WANA2':
                host.cmd('ip addr add 192.168.2.' + str(count) +
                         '/24 dev br-' + host.name)
            else:
                host.cmd('ip addr add 192.168.3.' + str(count) +
                         '/24 dev br-' + host.name)
            host.cmd('ip link set br-' + host.name + ' up')
            print "LB configured!"
            host.cmd('sysctl -w net.ipv4.ip_forward=1')
            print "IP Forwarding enabled!"
        elif host.name == 'VMU1' or host.name == 'VMU2' or host.name == 'DPI' or host.name == 'H2' or host.name == 'H3':
            if host.name == 'VMU1' or host.name == 'VMU2' or host.name == 'DPI':  # Machine on cluster 1
                host.setIP("192.168.1." + str(count), 24, host.name + "-eth0")
            elif host.name == 'H2':  # Machine on cluster 2
                host.setIP("192.168.2." + str(count), 24, host.name + "-eth0")
            else:  # Machine on cluster 3
                host.setIP("192.168.3." + str(count), 24, host.name + "-eth0")
            print "[CURRENT-CHECK] IP: " + net.hosts[count - 1].IP(
                net.hosts[count - 1].name + '-eth0')
        elif host.name == 'VR1' or host.name == 'VR3':
            if host.name == 'VR1':
                host.setIP("192.168.1." + str(count), 24, host.name + "-eth0")
            elif host.name == 'VR3':
                host.setIP("192.168.2." + str(count), 24, host.name + "-eth0")
            net.hosts[count - 1].setIP("10.0.0." + str(count - 5), 30,
                                       net.hosts[count - 1].name + "-eth1")
            net.hosts[count + 2].setIP(
                "10.0.0." + str(count - 4), 30, net.hosts[count + 2].name +
                "-eth0")  # also configuring VR2-eth0 and VR4-eth0
            print net.hosts[count -
                            1].name + "-eth1 interface has been configured!"
            print "[Checking VR IP] " + net.hosts[count - 1].IP(host.name +
                                                                '-eth1')
            net.hosts[count - 1].cmd(
                'sysctl -w net.ipv4.ip_forward=1')  # enabled on VR1
            print "On VR node: IP Forwarding enabled!"
        else:  # VR2 or VR4 case
            if host.name == 'VR2':
                host.setIP("192.168.2." + str(count), 24, host.name + "-eth1")
            else:  # VR4
                host.setIP("192.168.3." + str(count), 24, host.name + "-eth1")
            net.hosts[count - 1].cmd('sysctl -w net.ipv4.ip_forward=1')
            print "On VR node: IP Forwarding enabled!"
        count = count + 1
        print "\n"

    # ARP storm avoidance rules
#  for switch in net.switches:
#    if switch.name == 's1':
#      switch.cmd('ovs-ofctl add-flow ' + switch.name + ' in_port=4,arp,dl_dst=FF:FF:FF:FF:FF:FF,actions=drop')
#      switch.cmd('ovs-ofctl add-flow ' + switch.name + ' in_port=5,arp,dl_dst=FF:FF:FF:FF:FF:FF,actions=drop')
#      switch.cmd('ovs-ofctl add-flow ' + switch.name + ' in_port=6,arp,dl_dst=FF:FF:FF:FF:FF:FF,actions=drop')
#      switch.cmd('ovs-ofctl add-flow ' + switch.name + ' in_port=7,arp,dl_dst=FF:FF:FF:FF:FF:FF,actions=drop')
#    elif switch.name == 's6' or switch.name == 's10':
#      switch.cmd('ovs-ofctl add-flow ' + switch.name + ' in_port=2,arp,dl_dst=FF:FF:FF:FF:FF:FF,actions=drop')
#      switch.cmd('ovs-ofctl add-flow ' + switch.name + ' in_port=3,arp,dl_dst=FF:FF:FF:FF:FF:FF,actions=drop')

#  for switch in net.switches:
#    print "Rules installed on switch " + switch.name + ": " + switch.cmdPrint('ovs-ofctl dump-flows ' + switch.name)

    print "Configuring default gw on each host.. TODO"
    count = 1
    for host in net.hosts:
        print "Adding default gw ..."
        '''if host.name != 'VR' and host.name != 'H1' and host.name != 'WANA' and host.name != 'TC': 
      host.setDefaultRoute('dev ' + host.name + '-eth0 via ' + net.hosts[nhosts - 2].IP(net.hosts[nhosts - 2].name + '-eth0'))
    elif host.name == 'TC' or host.name == 'WANA':
      print "Default GW manually configured"
      host.cmd('route add default gw ' + net.hosts[nhosts - 2].IP(net.hosts[nhosts - 2].name + '-eth0'))  
    else:
      #H1 case  
      host.setDefaultRoute('dev ' + host.name + '-eth0 via ' + net.hosts[nhosts - 2].IP(net.hosts[nhosts - 2].name + '-eth1'))'''
        if host.name == 'VMU1' or host.name == 'VMU2':
            host.setDefaultRoute(
                'dev ' + host.name + '-eth0 via ' +
                net.hosts[nhosts - 8].IP(net.hosts[nhosts - 8].name + '-eth0'))
        elif host.name == 'H2':
            host.cmd('route add -net 192.168.1.0 netmask 255.255.255.0 gw ' +
                     net.hosts[nhosts - 5].IP(net.hosts[nhosts - 5].name +
                                              '-eth1'))
            host.cmd('route add -net 192.168.3.0 netmask 255.255.255.0 gw ' +
                     net.hosts[nhosts - 4].IP(net.hosts[nhosts - 4].name +
                                              '-eth0'))
        elif host.name == 'H3':
            host.setDefaultRoute(
                'dev ' + host.name + '-eth0 via ' +
                net.hosts[nhosts - 1].IP(net.hosts[nhosts - 1].name + '-eth1'))
        elif host.name == 'VR1':
            host.cmd('route add -net 192.168.2.0 netmask 255.255.255.0 gw ' +
                     net.hosts[nhosts - 5].IP(net.hosts[nhosts - 5].name +
                                              '-eth0'))
            host.cmd('route add -net 192.168.3.0 netmask 255.255.255.0 gw ' +
                     net.hosts[nhosts - 5].IP(net.hosts[nhosts - 5].name +
                                              '-eth0'))
        elif host.name == 'VR2':
            host.cmd('route add -net 192.168.1.0 netmask 255.255.255.0 gw ' +
                     net.hosts[nhosts - 8].IP(net.hosts[nhosts - 8].name +
                                              '-eth1'))
            host.cmd('route add -net 192.168.3.0 netmask 255.255.255.0 gw ' +
                     net.hosts[nhosts - 4].IP(net.hosts[nhosts - 4].name +
                                              '-eth0'))
        elif host.name == 'VR3':
            host.cmd('route add -net 192.168.1.0 netmask 255.255.255.0 gw ' +
                     net.hosts[nhosts - 5].IP(net.hosts[nhosts - 5].name +
                                              '-eth1'))
            host.cmd('route add -net 192.168.3.0 netmask 255.255.255.0 gw ' +
                     net.hosts[nhosts - 1].IP(net.hosts[nhosts - 1].name +
                                              '-eth0'))
        elif host.name == 'VR4':
            host.cmd('route add -net 192.168.1.0 netmask 255.255.255.0 gw ' +
                     net.hosts[nhosts - 4].IP(net.hosts[nhosts - 4].name +
                                              '-eth1'))
            host.cmd('route add -net 192.168.2.0 netmask 255.255.255.0 gw ' +
                     net.hosts[nhosts - 4].IP(net.hosts[nhosts - 4].name +
                                              '-eth1'))
        else:
            print "Host " + host.name + ": routing table currently not configured"

    #Building GRE tunnels
    for switch in net.switches:
        if switch.name == 's4':
            switch.cmd('sudo ifconfig ' + switch.name + ' 192.168.1.45/24')
            switch.cmd(
                'ovs-vsctl add-port ' + switch.name +
                ' grec1c2k1 -- set Interface grec1c2k1 type=gre options:key=1 options:remote_ip=192.168.2.54 options:local_ip=192.168.1.45'
            )
            switch.cmd(
                'ovs-vsctl add-port ' + switch.name +
                ' grec1c3k2 -- set Interface grec1c3k2 type=gre options:key=2 options:remote_ip=192.168.3.74 options:local_ip=192.168.1.45'
            )
        elif switch.name == 's5':
            switch.cmd('sudo ifconfig ' + switch.name + ' 192.168.2.54/24')
            switch.cmd(
                'ovs-vsctl add-port ' + switch.name +
                ' grec2c1k1 -- set Interface grec2c1k1 type=gre options:key=1 options:remote_ip=192.168.1.45 options:local_ip=192.168.2.54'
            )
        elif switch.name == 's7':
            switch.cmd('sudo ifconfig ' + switch.name + ' 192.168.2.79/24')
            switch.cmd(
                'ovs-vsctl add-port ' + switch.name +
                ' grec2c3k3 -- set Interface grec2c3k3 type=gre options:key=3 options:remote_ip=192.168.3.74 options:local_ip=192.168.2.79'
            )
        elif switch.name == 's9':
            switch.cmd('sudo ifconfig ' + switch.name + ' 192.168.3.74/24')
            switch.cmd(
                'ovs-vsctl add-port ' + switch.name +
                ' grec3c1k2 -- set Interface grec3c1k2 type=gre options:key=2 options:remote_ip=192.168.1.45 options:local_ip=192.168.3.74'
            )
            switch.cmd(
                'ovs-vsctl add-port ' + switch.name +
                ' grec3c2k3 -- set Interface grec3c2k3 type=gre options:key=3 options:remote_ip=192.168.2.79 options:local_ip=192.168.3.74'
            )
        else:
            print 'Switch ' + switch.name + ' does not need GRE tunnels'

    info('... running CLI \n***')
    CLI(net)
    info('\n')
    info('... stopping Network ***\n')
    net.stop()
Beispiel #16
0
def main():
    net = Mininet(topo=TutorialTopo(), controller=None)
    net.start()
    CLI(net)
    net.stop()
Beispiel #17
0
def stopfw(h1):
    h1.cmd('iptables -F')
    h1.cmd('iptables -t nat -F')
    h1.cmd('sysctl net.ipv4.ip_forward=0')


if __name__ == "__main__":
    while apptype > 0:
        print '*** Starting network\n'
        net = Mininet()
        net.addController('c0')
        # Create internal LAN switch
        s1 = net.addSwitch('s1')
        # Create internal DMZ switch
        s2 = net.addSwitch('s2')
        CLI(net)
        net.start()
        while apptype > 0:
            getapptype(apptype)
            if apptype == 1:
                print '*** Adding Host\n'
                h1 = net.addHost('h1')
                print '*** Linking to Switch\n'
                net.addLink(h1, s1)
                CLI(net)
                startfw(h1)
            elif apptype == 2:
                print '*** Adding Host\n'
                h5 = net.addHost('h5')
                h6 = net.addHost('h6')
                h7 = net.addHost('h7')
Beispiel #18
0
def emptyNet():

    "Create an empty network and add nodes to it."
    "[h1]<---wifi-network---> [h0:AP] <---wired-link ---> [s0] <---wired-link--->[h5]"
    "[h2]<---wifi-network--->                        ---> [s0] <---wired-link--->[h6]"
    "[h3]<---wifi-network--->"
    "[h4]<---wifi-network--->"

    net = Mininet(controller=OVSController)

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

    info('*** Adding switch\n')
    s0 = net.addSwitch('s0')
    s0.listenPort = 6634

    h0 = net.addHost('h0')
    h1 = net.addHost('h1', ip='192.168.0.2')
    h2 = net.addHost('h2', ip='192.168.0.3')
    h3 = net.addHost('h3', ip='192.168.0.4')
    h4 = net.addHost('h4', ip='192.168.0.5')
    h5 = net.addHost('h5', ip='10.0.0.2')
    h6 = net.addHost('h6', ip='10.0.0.3')
    linkopts = dict(bw=100, delay='1ms', loss=0)
    TCLink(s0, h5, **linkopts)
    TCLink(s0, h6, **linkopts)
    TCLink(h0, s0, **linkopts)

    wifi = WIFISegment()

    wifi.addAp(h0)
    wifi.addSta(h1)
    wifi.addSta(h2)
    wifi.addSta(h3)
    wifi.addSta(h4)

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

    h0.cmdPrint("ifconfig h0-eth0 10.0.0.1 netmask 255.255.255.0")
    h0.cmdPrint("ifconfig h0-eth1 192.168.0.1 netmask 255.255.255.0")
    h0.cmdPrint("sudo echo 1 > /proc/sys/net/ipv4/ip_forward")
    h1.cmdPrint("route add default gw 192.168.0.1")
    h2.cmdPrint("route add default gw 192.168.0.1")
    h3.cmdPrint("route add default gw 192.168.0.1")
    h4.cmdPrint("route add default gw 192.168.0.1")
    h5.cmdPrint("route add default gw 10.0.0.1")
    h6.cmdPrint("route add default gw 10.0.0.1")

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

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

    info('*** Stopping network')
    mininet.ns3.stop()
    mininet.ns3.clear()  # line added
    net.stop()
def emptyNet():

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

    net = Mininet( controller=Controller )

    info( '*** Adding controller\n' )
    net.addController( 'c0' )
    
    num_switch = int(sys.argv[1])
    num_host = int(sys.argv[2])
    total_host = num_switch*num_host

    odd_ip = '10.0.0.'
    even_ip = '11.0.0.'

    list_oddhosts = []
    list_evenhosts = []

    for i in range(total_host):
	    host_name = 'h'+str(i)
    	if i % 2 == 0:
		    add = net.addHost(host_name, ip=even_ip+str(i+1))
		    list_evenhosts.append(add)
	  else:
		  add = net.addHost(host_name, ip=odd_ip+str(i+1))
		  list_oddhosts.append(add)

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

    info( '*** Adding switch\n' )
    #s1 = net.addSwitch( 's1' )
    #s2 = net.addSwitch( 's2' )
    list_switch = []
    for i in range(num_switch):
	    s = 's'+str(i)
	    switch = net.addSwitch(s)
	    list_switch.append(switch)

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

    k = 0
    for i in list_switch:
	    net.addLink(list_oddhosts[k], i)
	    net.addLink(list_evenhosts[k], i)
	    k = k + 1

    for i in range(len(list_switch)-1):
	    net.addLink(list_switch[i], list_switch[i+1])
    

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

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

    info( '*** Stopping network' )
    net.stop()
Beispiel #20
0
def myNetwork(number_of_hosts=2):

    # Create an instance of Mininet class i.e. the network with default values
    net = Mininet(controller=RemoteController,switch=OVSSwitch,link=TCULink,autoSetMacs=True)

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

    info( '*** Adding switches\n')
    s1 = net.addSwitch('s1')
    s2 = net.addSwitch('s2')
    # Intf('enp0s8', node=s1)
    # sleep(5)
    net.addLink(s1,s2,bw=40000,delay=0.16)
    hr = net.addHost('hr')
    net.addLink(s2,hr)
    net.addLink(s2,c0)
    hosts = list()
    info( '*** Adding hosts and Links\n')
    time = datetime.now()
    info("** time  :")
    info(str(time.minute) + ':' + str(time.second))
    for i in range (1,number_of_hosts+1):
        name = 'h'+str(i)
        # ip = '1.0.0.'+ str(i)
        # ip = '0.0.0.0'
        # Add the hosts with IP address
        host = net.addHost(name)
        # Add the link between s1 and  the host
        bandWidth = random.randint(200, 400)
        net.addLink(s1,host,bw=bandWidth,delay=10)
        # host.cmdPrint('dhclient' + host.defaultIntf().name)
        hosts.append(host)
    info( '*** Starting network\n')
    net.start()
    # Run a pingall test
    # for host in hosts:
    #     host.cmdPrint('dhclient '+host.defaultIntf().name)
    #     host.cmdPrint(' ifconfig| grep -i broadcast ')
    # time = datetime.now()
    # net.pingAll()
    # # time = datetime.now()
    # info("** time   :")
    # info(str(time.minute) + ':' + str(time.second) + "\n")

    iperfDuration = 20  #To speed-up testing, reduce the iperf duration (while developing your Ryu solution)
    # info ('*** Running Iperf Tests\n')
    # time = datetime.now()
    # info("** time   :")
    # info(str(time.minute) + ':' + str(time.second) + "\n")
    # # Get the instance of h1
    # h1 = net.get('h1')
    # for src in net.hosts:
    #     for dst in net.hosts:  # For each host in the network
    #         if src != dst:      # Except h1
    #             # Start an Iperf server (data sink) on host that reports every second.
    #             # Use & to run in background and avoid blocking cmd. Also save the reports to a log file.
    #             cmd = 'iperf -s ' + '-t' + str(iperfDuration) + '  >> /tmp/iperf_server.log &'
    #             dst.cmd(cmd)   # Send the command to the host
    #             info(src.name, ' <==>', dst)
    #             # sleep(1)    # Wait for a second to ensure that the iperf server is running
    #             cmd = 'iperf -c ' + dst.IP() + ' -t '+ str(iperfDuration) +' >> /tmp/iperf_client &'
    #             time = datetime.now()
    #             info(cmd + '\n')
    #             src.cmd(cmd)   # Run the client (data source) on h1 to send data to host.IP
    #             cmd = ' ping -c 5000 -f ' + dst.IP() + ' >> /tmp/pinging &'
    #             info(cmd + '\n')
    #             src.cmd(cmd)
    #             # sleep(1)    # Wait for a second before starting the next host
    #             # time = datetime.now()
    #             info("** time   :")
    #             info(str(time.minute) + ':' + str(time.second) + "\n")
    #             # sleep(3)
    #     time = datetime.now()
    #     net.pingAll()

    #     info("** time    :")
    #     info(str(time.minute) + ':' + str(time.second) + "\n")

    # info('\n*** Wait ',str(iperfDuration), ' seconds for Iperf to Finish\n')
    # sleep(iperfDuration)

    CLI(net)
    # Stop the network
    net.stop()
def topology():

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

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

    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)

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

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

    print "*** Associating and Creating links"
    net.addLink(rsu11, rsu12)
    net.addLink(rsu11, rsu13)
    net.addLink(rsu11, rsu14)

    print "*** Starting network"
    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('ifconfig %s 10.0.0.%s' % (sw, i))
        i += 1
    """uncomment to plot graph"""
    net.plotGraph(max_x=500, max_y=500)
    """Number of Roads"""
    net.roads(20)
    """Start Mobility"""
    net.startMobility(time=0)

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

    i = 1
    j = 2
    for v in net.carsSTA:
        v.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (v, j))
        v.cmd('ifconfig %s-mp0 10.0.0.%s/24 up' % (v, i))
        v.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward')
        i += 1
        j += 2

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

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

    print "*** Stopping network"
    net.stop()
Beispiel #22
0
def myNetwork():
    net = Mininet(topo=None, build=False, link=TCLink)

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

    info('*** Add switches\n')
    s1 = net.addSwitch('s1', cls=OVSKernelSwitch, protocols='OpenFlow13')
    s2 = net.addSwitch('s2', cls=OVSKernelSwitch, protocols='OpenFlow13')
    s3 = net.addSwitch('s3', cls=OVSKernelSwitch, protocols='OpenFlow13')
    s4 = net.addSwitch('s4', cls=OVSKernelSwitch, protocols='OpenFlow13')
    s5 = net.addSwitch('s5', cls=OVSKernelSwitch, protocols='OpenFlow13')
    s6 = net.addSwitch('s6', cls=OVSKernelSwitch, protocols='OpenFlow13')
    s7 = net.addSwitch('s7', cls=OVSKernelSwitch, protocols='OpenFlow13')
    s8 = net.addSwitch('s8', cls=OVSKernelSwitch, protocols='OpenFlow13')
    s9 = net.addSwitch('s9', cls=OVSKernelSwitch, protocols='OpenFlow13')
    s10 = net.addSwitch('s10', cls=OVSKernelSwitch, protocols='OpenFlow13')
    s11 = net.addSwitch('s11', cls=OVSKernelSwitch, protocols='OpenFlow13')
    net.addLink('s1', 's2', bw=10)
    net.addLink('s1', 's3', bw=10)
    net.addLink('s3', 's4', bw=10)
    net.addLink('s2', 's5', bw=10)
    net.addLink('s4', 's5', bw=10)
    net.addLink('s3', 's7', bw=10)
    net.addLink('s4', 's8', bw=10)
    net.addLink('s7', 's8', bw=10)
    net.addLink('s6', 's7', bw=10)
    net.addLink('s8', 's9', bw=10)
    net.addLink('s9', 's11', bw=10)
    net.addLink('s6', 's9', bw=10)
    net.addLink('s6', 's10', bw=10)
    net.addLink('s10', 's9', bw=10)

    info('*** Adding end devices.\n')
    h1 = net.addHost('h1', ip='10.0.0.1')
    TCLink(h1, s1, intfName='h1-eth0')
    TCLink(h1, s6, intfName='h1-eth1')
    h1.setIP('10.0.0.1', intf='h1-eth0')
    h1.setIP('10.0.0.2', intf='h1-eth1')
    h1.setMAC('00:00:00:00:00:01', intf='h1-eth0')
    h1.setMAC('00:00:00:00:00:02', intf='h1-eth1')
    h1.cmd('ip rule add from 10.0.0.1 table 1')
    h1.cmd('ip rule add from 10.0.0.2 table 2')
    h1.cmd('ip route add 10.0.0.0/24 dev h1-eth0 scope link table 1')
    h1.cmd('ip route add 10.0.0.0/24 dev h1-eth1 scope link table 2')
    h1.cmd('sysctl -w net.ipv4.conf.all.arp_filter=1')
    h1.cmd('/home/mato/ryu/scripts/h1_arp.sh')

    h2 = net.addHost('h2', ip='10.0.0.3')
    TCLink(h2, s5, intfName='h2-eth0')
    TCLink(h2, s11, intfName='h2-eth1')
    h2.setIP('10.0.0.3', intf='h2-eth0')
    h2.setIP('10.0.0.4', intf='h2-eth1')
    h2.setMAC('00:00:00:00:00:03', intf='h2-eth0')
    h2.setMAC('00:00:00:00:00:04', intf='h2-eth1')
    h2.cmd('ip rule add from 10.0.0.3 table 1')
    h2.cmd('ip rule add from 10.0.0.4 table 2')
    h2.cmd('ip route add 10.0.0.0/24 dev h2-eth0 scope link table 1')
    h2.cmd('ip route add 10.0.0.0/24 dev h2-eth1 scope link table 2')
    h2.cmd('sysctl -w net.ipv4.conf.all.arp_filter=1')
    h2.cmd('/home/mato/ryu/scripts/h2_arp.sh')

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

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

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

    info('*** Add interfaces to switch ***')

    #_intf = Intf('eth0', node=s1)
    #_intf = Intf('eth1', node=s6)
    #_intf = Intf('eth2', node=s5)
    #_intf = Intf('eth3', node=s11)

    #call(['ovs-vsctl', 'add-port', 's1', 'eth0'])
    #call(['ovs-vsctl', 'add-port', 's6', 'eth1'])
    #call(['ovs-vsctl', 'add-port', 's5', 'eth2'])
    #call(['ovs-vsctl', 'add-port', 's11', 'eth3'])
    info('*** Starting iperf server on host #2')
    h2.cmd('iperf -s &')
    info('*** Done.\n')

    CLI(net)
    net.stop()
def createNetwork():
	#send rate at each link in Mbps
	bwg = 1#000 #1000 #in Mbps
	bwbn = 1#000 #1000 #25 #in Mbps
	loss = 80 #1 #2.5 #10 #1 #in %
	mqs = 100 #0 #1000 #max queue size of interfaces
	dly = '2.5ms'#'2.5ms 0.5ms'#'1ms 0.5ms' #can take all tc qdisc delay distribution formulations

	#create empty network
	net = Mininet(intf=TCIntf)

	info( '\n*** Adding controller\n' )
	net.addController( 'c0' ) #is it ok ?

	#add host to topology
	ht = net.addHost( 'ht', ip='10.10.0.1/24' )
	hu = net.addHost( 'hu', ip='10.10.0.2/24' )
	it = net.addHost( 'it', ip='10.20.0.1/24' )
	iu = net.addHost( 'iu', ip='10.20.0.2/24' )

	rh = net.addHost('rh', ip='10.10.0.10/24')
	ri = net.addHost('ri', ip='10.20.0.20/24')

	info('\n** Adding Switches\n')
	# Adding 2 switches to the network
	sw1 = net.addSwitch('sw1')
	sw2 = net.addSwitch('sw2')

	info('\n** Creating Links \n')
	#create link beetween the network
	link_ht_sw1 = net.addLink( ht, sw1)
	link_hu_sw1 = net.addLink( hu, sw1)
	link_rh_sw1 = net.addLink( rh, sw1, intfName1='rh-eth0')

	link_it_sw2 = net.addLink( it, sw2)
	link_iu_sw2 = net.addLink( iu, sw2)
	link_ri_sw2 = net.addLink( ri, sw2, intfName1='ri-eth0')

	link_rh_ri  = net.addLink( rh, ri, intfName1='rh-eth1', intfName2='ri-eth1')


	#set bandwith
	link_ht_sw1.intf1.config( bw = bwbn, max_queue_size = mqs)
	link_hu_sw1.intf1.config( bw = bwbn, max_queue_size = mqs)
	link_rh_sw1.intf1.config( bw = bwbn, max_queue_size = mqs) #max_queue_size is hardcoded low to prevent bufferbloat, too high queuing delays

	link_it_sw2.intf1.config( bw = bwg, max_queue_size = mqs)
	link_iu_sw2.intf1.config( bw = bwg, max_queue_size = mqs)
	link_ri_sw2.intf1.config( bw = bwg, max_queue_size = mqs, delay=dly) #delay is set at ri on both interfaces

	# link_rh_ri.intf1.config(  bw = bwg, max_queue_size = 10, loss=loss) #loss is set at rh on its interface to ri only
	link_rh_ri.intf1.config(  bw = bwg, max_queue_size = mqs, loss=loss) #loss is set at rh on its interface to ri only

	link_ht_sw1.intf2.config( bw = bwbn, max_queue_size = mqs)
	link_hu_sw1.intf2.config( bw = bwbn, max_queue_size = mqs)
	link_rh_sw1.intf2.config( bw = bwbn, max_queue_size = mqs)

	link_it_sw2.intf2.config( bw = bwg, max_queue_size = mqs)
	link_iu_sw2.intf2.config( bw = bwg, max_queue_size = mqs)
	link_ri_sw2.intf2.config( bw = bwg, max_queue_size = mqs)

	link_rh_ri.intf2.config(  bw = bwg, max_queue_size = mqs,  delay=dly) #delay is set at ri on both interfaces

	net.start()

	info( '\n*** Configuring hosts\n' )

	rh.cmd('ifconfig rh-eth1 10.12.0.10 netmask 255.255.255.0') #reconfiguring mutiples intefaces host to prevent mininet strange initialisation behaviors
	rh.cmd('ifconfig rh-eth0 10.10.0.10 netmask 255.255.255.0')
	rh.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward') #enable forwarding at routers

	ri.cmd('ifconfig ri-eth1 10.12.0.20 netmask 255.255.255.0') #reconfiguring mutiples intefaces host to prvent mininet strange initialisation behaviors
	ri.cmd('ifconfig ri-eth0 10.20.0.20 netmask 255.255.255.0')
	ri.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward') #enable forwarding at routers

	#configure host default gateways
	ht.cmd('ip route add default via 10.10.0.10')
	hu.cmd('ip route add default via 10.10.0.10')
	it.cmd('ip route add default via 10.20.0.20')
	iu.cmd('ip route add default via 10.20.0.20')

	#configure router routing tables
	rh.cmd('ip route add default via 10.12.0.20')
	ri.cmd('ip route add default via 10.12.0.10')

        # weiyu:
        iu.cmd('touch server.pcap')
        hu.cmd('touch client.pcap')


        rh.cmd('tc qdisc del dev rh-eth1 root')
        rh.cmd('tc qdisc add dev rh-eth1 root netem loss gemodel 0.2% 20% 90% 0.1% limit ' + str(mqs))
        #rh.cmd('tc qdisc add dev rh-eth1 root netem loss gemodel 0.2% 2% 90% 2% limit 10')
        #rh.cmd('tc qdisc add dev rh-eth1 root netem loss gemodel 0.1% 1% 90% 2% limit 1000')
        #rh.cmd('tc qdisc add dev rh-eth1 root netem loss gemodel 0.5% 2% 90% 2% limit 1000')

       # rh.cmd('python ./monitor_qlen_rh.py &')
        rh.cmd('xterm -xrm \'XTerm.vt100.allowTitleOps: false\' -T rh -e \'sudo python ./monitor_queue.py\' &')
       # ri.cmd('python ./monitor_qlen_ri.py &')
        ri.cmd('xterm -xrm \'XTerm.vt100.allowTitleOps: false\' -T ri -e \'sudo python ./monitor_qlen_ri.py\' &')
        #it.cmd('xterm -xrm \'XTerm.vt100.allowTitleOps: false\' -T it -e \'sudo ./tcpserver 6666 > tcp-output-server.txt\' &')

        #ht.cmd('xterm -xrm \'XTerm.vt100.allowTitleOps: false\' -T ht -e \'sleep 10; sudo ./tcpclient 10.20.0.1 6666 > tcp-output-client.txt\' &')

       # iu.cmd('tshark -i iu-eth0 -w server.pcap &')
        iu.cmd('xterm -xrm \'XTerm.vt100.allowTitleOps: false\' -T iu -e \'sudo tshark -i iu-eth0 -w server.pcap\' &')
       # iu.cmd('./server.sh &')
        # iu.cmd('xterm -xrm \'XTerm.vt100.allowTitleOps: false\' -T iu -e \'sudo ./baseline_server.sh > output-server.txt\' &')
        iu.cmd('xterm -xrm \'XTerm.vt100.allowTitleOps: false\' -T iu -e \'python3 tcp_server.py > tcp-output-server.txt\' &')
       # hu.cmd('tshark -i hu-eth0 -w client.pcap &')
        hu.cmd('xterm -xrm \'XTerm.vt100.allowTitleOps: false\' -T hu -e \'sudo tshark -i hu-eth0 -w client.pcap\' &')
       # hu.cmd('./client.sh &')
        # hu.cmd('xterm -xrm \'XTerm.vt100.allowTitleOps: false\' -T hu -e \'sleep 5; sudo ./baseline_client.sh > output-client.txt\' &')
        hu.cmd('xterm -xrm \'XTerm.vt100.allowTitleOps: false\' -T hu -e \'python3 tcp_client.py > tcp-output-client.txt \' &')


	it.cmd('ethtool -K it-eth0 tx off sg off tso off') #disable TSO on TCP on defaul TCP sender need to be done on other host if sending large TCP file from other nodes

	method = 'tcp' #case selector varible for the flow used by smart-grid 'udp' = FRED

	logFolder = "../Estimations/wifiTer/"+ method + "/" #folder where log files and metrics will be saved
	# timeout = 10 #durantion of test

	#if not os.path.exists(logFolder):
	try:
		os.makedirs(logFolder) #error if folder already exist in order to prevent exidental overwirie
	except:
		print("File already exists.")

        # makeTerms([iu, hu, rh, ri], "host")

	#hu.cmd("bash /home/lca2/Desktop/server.sh")
	time.sleep(1)

	#iu.cmd("bash /home/lca2/Desktop/client-network.sh")
	time.sleep(1)

	"""it.cmd("python3 tcpserver.py &> "+logFolder+"it.txt &")
	time.sleep(1)
	ht.cmd("python3 tcpclient.py --ip 10.20.0.1 --port 4242 -s "+logFolder+"ht- -t "+str(timeout)+" &> "+logFolder+"ht.txt &")

	#potential second flow in the reverse direction of the first

	#ht.cmd("python3 tcpserver.py --ip 10.10.0.1 --port 4243 &> "+logFolder+"ht2.txt &")
	#time.sleep(1)
	#it.cmd("python3 tcpclient.py --ip 10.10.0.1 --port 4243 -s "+logFolder+"it2- -t "+str(timeout)+" &> "+logFolder+"it2.txt &")

	#smart grid data will be transported by TCP, delay will be recorded
	if method == 'tcp':
		info(method)
		iu.cmd("python3 delayReceiver.py --tcp --ip 10.20.0.2 -p 4242 -s "+logFolder+"iu- -t "+str(timeout)+" &> "+logFolder+"iu.txt &")
		time.sleep(1)
		hu.cmd("python3 tcpsender.py -t "+str(timeout)+" &> "+logFolder+"hu.txt &")

	#smart grid data will be transported by FRED, delay will be recorded
	elif method == 'udp':
		info(method)
		iu.cmd("python3 delayReceiver.py --ip 10.20.0.2 -p 4242 -s "+logFolder+"iu- -t "+str(timeout)+" &> "+logFolder+"iu.txt &")
		time.sleep(1)
		hu.cmd("python3 udpsender.py -s "+logFolder+"hu- -t "+str(timeout)+" &> "+logFolder+"hu.txt &")

	else:
		info("method unknown")
		net.stop()
		return

	#wainting until test end
	info('\n*** Sleeping\n')
	for i in range(int(timeout)):
		time.sleep(60)
		info("**slept "+str(i+1))"""

	# Enable the mininet> prompt if uncommented
	info('\n*** Running CLI\n')
	CLI(net)

	#kill xterms in case some where opened
	#ht.cmd("killall xterm")
	#it.cmd("killall xterm")
	# hu.cmd("killall xterm")
	iu.cmd("killall xterm")
Beispiel #24
0
 def interact( self ):
     "Start network and run our simple CLI."
     self.start()
     result = CLI( self )
     self.stop()
     return result
def run():
    
    #Setup topo and list information
    topo = topoFinal()
    net = Mininet( topo=topo, controller=None, link=TCLink )
    net.start()

    info( "*** Setup routes on all devices" )
    #Host routes
    net['h101'].cmd( 'route add -net 192.168.1.0/24 gw {}'.format(net['r201'].IP()) ) 
    net['h102'].cmd( 'route add -net 192.168.1.0/24 gw {}'.format(net['r205'].IP()) ) 
    net['h103'].cmd( 'route add -net 192.168.1.0/24 gw {}'.format(net['r206'].IP()) ) 
    net['h104'].cmd( 'route add -net 192.168.1.0/24 gw {}'.format(net['r207'].IP()) ) 
   
    #Router r201 routes
    net['r201'].cmd( 'ip route add {}/32 dev r201-eth0'.format(net['r202'].IP()) )
    net['r201'].cmd( 'ip route add {}/32 dev r201-eth1'.format(net['r203'].IP()) )
    net['r201'].cmd( 'ip route add {}/32 dev r201-eth2'.format(net['r204'].IP()) )
    net['r201'].cmd( 'ip route add {}/32 dev r201-eth3'.format(net['h101'].IP()) )

    #Router r202 routes
    net['r202'].cmd( 'ip route add {}/32 dev r202-eth0'.format(net['r201'].IP()) )
    net['r202'].cmd( 'ip route add {}/32 dev r202-eth1'.format(net['r205'].IP()) )

    #Router r203 routes
    net['r203'].cmd( 'ip route add {}/32 dev r203-eth0'.format(net['r201'].IP()) )
    net['r203'].cmd( 'ip route add {}/32 dev r203-eth1'.format(net['r206'].IP()) )

    #Router r204 routes
    net['r204'].cmd( 'ip route add {}/32 dev r204-eth0'.format(net['r201'].IP()) )
    net['r204'].cmd( 'ip route add {}/32 dev r204-eth1'.format(net['r207'].IP()) )
    
    #Router r205 routes
    net['r205'].cmd( 'ip route add {}/32 dev r205-eth0'.format(net['r202'].IP()) )
    net['r205'].cmd( 'ip route add {}/32 dev r205-eth1'.format(net['r206'].IP()) )
    net['r205'].cmd( 'ip route add {}/32 dev r205-eth2'.format(net['h102'].IP()) ) 
    
    #Router r206 routes
    net['r206'].cmd( 'ip route add {}/32 dev r206-eth0'.format(net['r203'].IP()) )
    net['r206'].cmd( 'ip route add {}/32 dev r206-eth1'.format(net['r205'].IP()) )
    net['r206'].cmd( 'ip route add {}/32 dev r206-eth2'.format(net['r207'].IP()) )
    net['r206'].cmd( 'ip route add {}/32 dev r206-eth3'.format(net['h103'].IP()) )
    
    #Router r206 routes
    net['r207'].cmd( 'ip route add {}/32 dev r207-eth0'.format(net['r204'].IP()) )
    net['r207'].cmd( 'ip route add {}/32 dev r207-eth1'.format(net['r206'].IP()) )
    net['r207'].cmd( 'ip route add {}/32 dev r207-eth2'.format(net['h104'].IP()) )
    
    #DEBUGGING INFO    
    info( "\n\n" )
    info( "*** List host IPs\n" )
    get_host_ips(net)
    info( "*** List all routes\n" )
    for node in net.hosts:
	print(node.cmd('route -n'))
    info( "*** Dumping host connections\n" )
    dumpNodeConnections(net.hosts)
    info( "*** Pinging all devices\n" )
    #net.pingAll()
    
    CLI( net )
    net.stop()
def projectNet():

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

    net = Mininet(controller=RemoteController,
                  link=TCLink,
                  switch=OVSKernelSwitch)

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

    #number of components in the network
    number_components = 3

    info('*** Adding hosts\n')
    Clients = []
    Servers = []
    Ips = [
        '10.0.0.1/24', '10.0.0.2/24', '10.0.0.3/24', '10.0.0.4/24',
        '10.0.0.5/24', '10.0.0.6/24'
    ]
    Macs = [
        '00:00:00:00:00:01', '00:00:00:00:00:02', '00:00:00:00:00:03',
        '00:00:00:00:00:04', '00:00:00:00:00:05', '00:00:00:00:00:06',
        '00:00:00:00:00:07', '00:00:00:00:00:08', '00:00:00:00:00:09'
    ]
    for i in range(1, number_components + 1):
        client = net.addHost('client%d' % i, mac=Macs[i - 1], ip=Ips[i - 1])
        server = net.addHost('server%d' % i, mac=Macs[i + 2], ip=Ips[i + 2])
        Clients.append(client)
        Servers.append(server)

    info('*** Adding switch\n')
    Switches = []
    Listen_Ports = [6673, 6674, 6675]
    for i in range(1, number_components + 1):
        switch = net.addSwitch('switch%d' % i,
                               mac=Macs[i + 5],
                               listenPort=Listen_Ports[i - 1])
        Switches.append(switch)

    info('*** Creating links\n')
    for i in range(number_components):
        net.addLink(Clients[i], Switches[i])
        net.addLink(Servers[i], Switches[i])
    for i in range(number_components):
        net.addLink(Switches[i % 3], Switches[(i + 1) % 3])

    info('***Setting switches to openflow 1.3\n')
    for i in range(number_components):
        Switches[i].cmd('ovs-vsctl set Bridge switch%d protocols=OpenFlow13' %
                        (i + 1))

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

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

    info('*** Stopping network')
    net.stop()
Beispiel #27
0
def topology():

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

    print "*** Creating nodes"
    car1 = net.addVehicle('car1',
                          wlans=2,
                          mac='00:00:00:00:00:01',
                          ip='10.0.0.1/8',
                          min_speed=1,
                          max_speed=5)
    car2 = net.addVehicle('car2',
                          wlans=2,
                          mac='00:00:00:00:00:02',
                          ip='10.0.0.2/8',
                          min_speed=5,
                          max_speed=10)
    car3 = net.addVehicle('car3',
                          mac='00:00:00:00:00:03',
                          ip='10.0.0.3/8',
                          min_speed=10,
                          max_speed=15)
    car4 = net.addVehicle('car4',
                          mac='00:00:00:00:00:04',
                          ip='10.0.0.4/8',
                          min_speed=15,
                          max_speed=20)
    car5 = net.addVehicle('car5',
                          mac='00:00:00:00:00:05',
                          ip='10.0.0.5/8',
                          min_speed=15,
                          max_speed=20)
    bs1 = net.addBaseStation('BS1', ssid='new-ssid1', mode='g', channel='1')
    bs2 = net.addBaseStation('BS2', ssid='new-ssid2', mode='g', channel='6')
    bs3 = net.addBaseStation('BS3', ssid='new-ssid3', mode='g', channel='11')
    c1 = net.addController('c1', controller=Controller)

    print "*** Associating and Creating links"
    net.addMesh(car1, ssid='mesh')
    net.addMesh(car2, ssid='mesh')
    net.addMesh(car3, ssid='mesh')
    net.addMesh(car4, ssid='mesh')
    net.addMesh(car5, ssid='mesh')
    net.addLink(bs1, bs2)
    net.addLink(bs1, bs3)

    print "*** Starting network"
    net.build()
    c1.start()
    bs1.start([c1])
    bs2.start([c1])
    bs3.start([c1])
    """uncomment to plot graph"""
    net.plotGraph(max_x=500, max_y=500)
    """Number of Roads"""
    net.roads(4)
    """Seed"""
    net.seed(20)
    """Start Mobility"""
    net.startMobility(startTime=0)

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

    print "*** Stopping network"
    net.stop()
Beispiel #28
0
def main():  # pylint: disable=R0914,R0915
    '''main'''

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

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

    info('*** Add switches\n')
    sw_1 = net.addSwitch('s1', dpid='0000000000000001', cls=OVSKernelSwitch)
    sw_2 = net.addSwitch('s2', dpid='0000000000000002', cls=OVSKernelSwitch)
    sw_3 = net.addSwitch('s3', dpid='0000000000000003', cls=OVSKernelSwitch)
    sw_4 = net.addSwitch('s4', dpid='0000000000000004', cls=OVSKernelSwitch)
    sw_5 = net.addSwitch('s5', dpid='0000000000000101', cls=OVSKernelSwitch)
    sw_b = net.addSwitch('sbr', dpid='00000000000000ff', cls=OVSKernelSwitch)
    sw_sp = net.addSwitch('span', dpid='00000800272d1636', cls=OVSKernelSwitch)
    Intf('eth2', node=sw_sp)  # Physical SPAN iface

    info('*** Add hosts\n')
    #cisco              00:01:42:
    #foxconn		    00:01:6c:
    #msi		        00:16:17:
    #siemens		    00:1f:f8:
    #moxa		        00:90:e8:
    #broadcom	        d4:01:29:
    #rockwell	        e4:90:69:
    hst_1 = net.addHost('h1',
                        cls=Host,
                        ip='192.168.1.10',
                        mac='00:16:17:fe:ba:22',
                        defaultRoute='via 192.168.1.1')  # LIT101
    hst_2 = net.addHost('h2',
                        cls=Host,
                        ip='192.168.1.11',
                        mac='e4:90:69:22:ce:d7',
                        defaultRoute='via 192.168.1.1')  # MV101
    hst_3 = net.addHost('h3',
                        cls=Host,
                        ip='192.168.1.12',
                        mac='00:90:e8:88:1e:53',
                        defaultRoute='via 192.168.1.1')  # P101
    hst_4 = net.addHost('h4',
                        cls=Host,
                        ip='192.168.1.14',
                        mac='08:00:06:67:ae:c4',
                        defaultRoute='via 192.168.1.1')  # PLC101
    atk_1 = net.addHost('a1',
                        cls=Host,
                        ip='192.168.1.100',
                        mac='00:01:6c:22:4c:a5',
                        defaultRoute='via 192.168.1.1')
    hst_5 = net.addHost('h5',
                        cls=Host,
                        ip='192.168.1.10',
                        mac='00:16:17:fe:bb:21',
                        defaultRoute='via 192.168.1.1')  # LIT101    honeypot
    hst_6 = net.addHost('h6',
                        cls=Host,
                        ip='192.168.1.11',
                        mac='e4:90:69:43:cd:a2',
                        defaultRoute='via 192.168.1.1')  # MV101     honeypot
    hst_7 = net.addHost('h7',
                        cls=Host,
                        ip='192.168.1.12',
                        mac='00:90:e8:6f:de:b9',
                        defaultRoute='via 192.168.1.1')  # P101      honeypot
    hst_8 = net.addHost('h8',
                        cls=Host,
                        ip='192.168.1.14',
                        mac='08:00:06:db:c0:1f',
                        defaultRoute='via 192.168.1.1')  # PLC101    honeypot
    hst_9 = net.addHost('h9',
                        cls=Host,
                        ip='10.0.0.10/24',
                        mac='00:01:6c:55:a7:cb',
                        defaultRoute='via 10.0.0.1')
    hst_10 = net.addHost('h10',
                         cls=Host,
                         ip='10.0.0.11/24',
                         mac='00:01:6c:3a:da:f2',
                         defaultRoute='via 10.0.0.1')
    # Router to corporate
    rt_0 = net.addHost('r0', cls=Host, ip='192.168.1.1/24', defaultRoute=None)
    rt_0.cmd('sysctl net.ipv4.ip_forward=1')

    info('*** Add links\n')
    # Field
    net.addLink(sw_1, sw_2)
    # Honey
    net.addLink(sw_4, sw_3)
    # Bridge
    net.addLink(sw_1, sw_b)
    net.addLink(sw_2, sw_b)
    net.addLink(sw_3, sw_b)
    net.addLink(sw_4, sw_b)
    # SPAN
    net.addLink(sw_1, sw_sp)
    net.addLink(sw_2, sw_sp)
    net.addLink(sw_3, sw_sp)
    net.addLink(sw_4, sw_sp)
    # Router
    net.addLink(sw_1, rt_0, intfName2='r0-eth1', addr2='00:01:42:a5:34:c0')
    net.addLink(sw_5, rt_0, intfName2='r0-eth2', addr2='00:01:42:a5:34:c1')
    rt_0.cmd('ifconfig r0-eth1 192.168.1.1/24 up')
    rt_0.cmd('ifconfig r0-eth2 10.0.0.1/24 up')
    # Hosts
    net.addLink(hst_1, sw_1)
    net.addLink(hst_2, sw_1)
    net.addLink(hst_3, sw_2)
    net.addLink(hst_4, sw_2)
    net.addLink(atk_1, sw_2)
    net.addLink(hst_5, sw_3)
    net.addLink(hst_6, sw_3)
    net.addLink(hst_7, sw_4)
    net.addLink(hst_8, sw_4)
    net.addLink(hst_9, sw_5)
    net.addLink(hst_10, sw_5)

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

    info('*** Starting switches\n')
    net.get('span').start([cont0])
    net.get('sbr').start([cont0])
    net.get('s1').start([cont0])
    net.get('s2').start([cont0])
    net.get('s3').start([cont0])
    net.get('s4').start([cont0])
    net.get('s5').start([cont0])

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

    # Gateway static ARP for the honeypot
    hst_5.cmd('arp -s 192.168.1.1 00:01:42:a5:34:c0')
    hst_6.cmd('arp -s 192.168.1.1 00:01:42:a5:34:c0')
    hst_7.cmd('arp -s 192.168.1.1 00:01:42:a5:34:c0')
    hst_8.cmd('arp -s 192.168.1.1 00:01:42:a5:34:c0')

    info('*** Add required SDN configurations\n')
    rauth = requests.auth.HTTPBasicAuth(REST_USER,
                                        REST_PASS)  # REST API authentication
    # SDN switch groups
    create_switch_groups(rauth)

    # Flows
    uri = 'http://{0:s}:{1:d}/onos/v1/flows?appId=org.onosproject.fwd'.format(
        CONT_IP, REST_PORT)

    # Basic bridge flows
    add_bridge_flows(
        uri, rauth
    )  # Upon startup, the bridge sould ignore all the traffic and establish some basic flows towards the gateway and honeypot.

    # Mirror flows
    add_mirror_flows(
        uri, rauth
    )  # Basic flows in the mirror switch: Ignore incoming flows and redirect all traffic to mirror port (NIC in IDS)

    # Field network mirroring
    mirror_field_switches(
        uri, rauth
    )  # Mirror all traffic in the field switches toward the mirror switch via the SDN groups.

    # Honeypot mirroring
    mirror_honeypot_switches(
        uri, rauth
    )  # Mirror all traffic in the honeypot switches toward the mirror switch via the SDN groups.

    net.pingAll()

    info('*** Start ICS processes\n')
    icscwd = '/home/mininet/topoics/'
    hnycwd = '/home/mininet/topohny/'
    hst_1_proc = hst_1.popen('python2 lit101.py &', cwd=icscwd)
    hst_5_proc = hst_5.popen('python2 lit101.py &', cwd=hnycwd)
    sleep(0.333)
    hst_4_proc = hst_4.popen('python2 plc101.py &', cwd=icscwd)
    hst_8_proc = hst_8.popen('python2 plc101.py &', cwd=hnycwd)
    sleep(0.333)
    hst_3_proc = hst_3.popen('python2 p101.py &', cwd=icscwd)
    hst_7_proc = hst_7.popen('python2 p101.py &', cwd=hnycwd)
    sleep(0.333)
    hst_2_proc = hst_2.popen('python2 mv101.py &', cwd=icscwd)
    hst_6_proc = hst_6.popen('python2 mv101.py &', cwd=hnycwd)

    CLI(net)

    # Cleanup flows
    i = 3
    while i > 0:
        uri = 'http://{0:s}:{1:d}/onos/v1/flows/application/org.onosproject.fwd'.format(
            CONT_IP, REST_PORT)
        requests.request('DELETE', uri, auth=rauth)
        uri = 'http://{0:s}:{1:d}/onos/v1/flows/application/org.onosproject.rest'.format(
            CONT_IP, REST_PORT)
        requests.request('DELETE', uri, auth=rauth)
        sleep(0.3333)
        i -= 1

    hst_1_proc.terminate()
    hst_2_proc.terminate()
    hst_3_proc.terminate()
    hst_4_proc.terminate()
    hst_5_proc.terminate()
    hst_6_proc.terminate()
    hst_7_proc.terminate()
    hst_8_proc.terminate()

    net.stop()

    rt_0.cmd('sysctl net.ipv4.ip_forward=0')

    system('mn -c')
Beispiel #29
0
	net = Mininet(topo=SOCKSTopo(), link=TCLink, controller=OVSController)
	net.start()
	
	client = net.get('h1')
	proxy  = net.get('h2')
	server = net.get('h3')
	
	proxy.cmdPrint('ifconfig h2-eth1 10.0.23.2/24')
	
	client.cmdPrint('ip r a default via 10.0.12.2')
	server.cmdPrint('ip r a default via 10.0.23.2')
	proxy.cmdPrint('sysctl net.ipv4.ip_forward net.ipv4.ip_forward=1')
	
	client.cmdPrint('/home/vlad/sigcomm18demo/proxyme.sh')
	client.cmdPrint('/home/vlad/sixtysocks/sixtysocks -m proxify -l 12345 -U user -P passwd -s 10.0.12.2 -p 1080 -D &> /dev/null &')
	
	proxy.cmdPrint('/home/vlad/sixtysocks/sixtysocks -m proxy -l 1080 -U user -P passwd &> /dev/null &')
	
	server.cmdPrint('/usr/sbin/start_apache2')
	
	#client.cmdPrint('ovs-ofctl add-flow s1 actions=flood')
	#client.cmdPrint('ovs-ofctl add-flow s2 actions=flood')
	
	
	CLI(net)
	
	server.cmdPrint('killall httpd-prefork')
	server.cmdPrint('killall sixtysocks')
	
	net.stop()
Beispiel #30
0
def simpleTest():

	#os.system("sudo mysql -u root -p mysql < ./schema.sql")
	#"Create and test a simple network"
	topo = SingleSwitchTopo(n=4)
	net = Mininet(topo, controller=partial(RemoteController, ip='127.0.0.1', port=6633))
	net.start();
	os.system("sudo ./deleteFlowForSwitchs.sh")
	net.pingAll();
	os.system("sudo ./sendFlowRuleForBasicPacket.sh PUT 127.0.0.1:8181")
        os.system("sudo ./deleteFlowForSwitchs.sh")
        os.system("sudo rm /etc/suricata/rules/i2nsf-firewall.rules")
        os.system("sudo rm /etc/suricata/rules/i2nsf-web-filter.rules")

##


	# Inintalize components
	nat = net.get('nat');
	sff = net.get('sff1');
	firewall = net.get('firewall');
	web_filter = net.get('web_filter');
	admin = net.get('admin');
	staff_1 = net.get('staff_1');
	staff_2 = net.get('staff_2');
	manager = net.get('manager');
	president = net.get('president');


	firewall.cmd('cd ../NSF/Firewall; sudo make clean');
	firewall.cmd('secu');
	firewall.cmd('sudo make all start >> /tmp/firewall.out &');

	web_filter.cmd('cd ../NSF/Web_Filter; sudo make clean');
	web_filter.cmd('secu');
	web_filter.cmd('sudo make all start >> /tmp/web_filter.out &');


	#admin.cmd('cd ../RESTCONF');
	#admin.cmd('sudo npm start >> /tmp/webserver1.out &');
	admin.cmd('cd /works/jetconf');
	admin.cmd('sudo python3.6 run.py -c example-config.yaml >> /tmp/webserver.out &');
	admin.cmd('cd ~/Hackathon/Hackathon-Registration/FullVersion/SecurityController');
	admin.cmd('sudo service apache2 stop >> /tmp/webserver.out');
	admin.cmd('sudo service apache2 start >> /tmp/webserver.out');
	admin.cmd('sudo python server.py >> /tmp/webserver.out &');
	admin.cmd('sudo make clean')
	admin.cmd('sudo make all start >> /tmp/securitycontroller.out &')
	
	str_exe_enterprise = "truncate table Policy_enterprise;"
	db = MySQLdb.connect(host="localhost", user="******", passwd="secu", db="I2NSF")
	cur = db.cursor()
	cur.execute(str_exe_enterprise)

	str_exe_web = "truncate table Policy_web;"
	db = MySQLdb.connect(host="localhost", user="******", passwd="secu", db="I2NSF")
	cur = db.cursor()
	cur.execute(str_exe_web)
	db.close()


	staff_1.cmd( 'sudo route add default gw', '10.0.0.100')
	staff_2.cmd( 'sudo route add default gw', '10.0.0.100')
	manager.cmd( 'sudo route add default gw', '10.0.0.100')
	president.cmd( 'sudo route add default gw', '10.0.0.100')

	sff.cmd( 'sudo route add default gw', '10.0.0.200')
	sff.cmd( 'sudo sysctl net.ipv4.ip_forward=1')

	firewall.cmd( 'sudo route add default gw', '10.0.0.201')
	firewall.cmd( 'sudo sysctl net.ipv4.ip_forward=1')
	firewall.cmd( 'sudo iptables -I FORWARD -j NFQUEUE')

	firewall.cmd('sudo rm /var/run/suricata-firewall.pid >> /tmp/firewall.out');
	firewall.cmd('sudo rm /var/run/suricata/firewall.socket');
	firewall.cmd('sudo /usr/bin/suricata -D --pidfile /var/run/suricata-firewall.pid -c /etc/suricata/suricata_firewall.yaml -q 0 >> /tmp/firewall.out');
	firewall.cmd('sudo /usr/bin/suricatasc -c reload-rules & >> /tmp/firewall.out');

	web_filter.cmd( 'sudo route add default gw', '10.0.0.150')
	web_filter.cmd( 'sudo sysctl net.ipv4.ip_forward=1')
	web_filter.cmd( 'sudo iptables -I FORWARD -j NFQUEUE')

	web_filter.cmd('sudo rm /var/run/suricata-web.pid >> /tmp/web_filter.out');
	web_filter.cmd('sudo rm /var/run/suricata/web.socket');
	web_filter.cmd('sudo /usr/bin/suricata -D --pidfile /var/run/suricata-web.pid -c /etc/suricata/suricata_web.yaml -q 0 >> /tmp/web_filter.out');
	web_filter.cmd('sudo /usr/bin/suricatasc -c reload-rules & >> /tmp/web_filter.out');



	# Identify the interface connecting to the mininet network
	localIntf = nat.defaultIntf()
	fixNetworkManager(nat, 'nat-eth0')

	# Flush any currently active rules
	nat.cmd( 'sudo iptables -F' )
	nat.cmd( 'sudo iptables -t nat -F' )

	# Create default entries for unmatched traffic
	nat.cmd( 'sudo iptables -P INPUT ACCEPT' )
	nat.cmd( 'sudo iptables -P OUTPUT ACCEPT' )
	nat.cmd( 'sudo iptables -P FORWARD DROP' )

	# Configure NAT
	nat.cmd( 'sudo iptables -I FORWARD -i', localIntf, '-d', '10.0/8', '-j DROP' )
	nat.cmd( 'sudo iptables -A FORWARD -i', localIntf, '-s', '10.0/8', '-j ACCEPT' )
	nat.cmd( 'sudo iptables -A FORWARD -i', 'eth0', '-d', '10.0/8', '-j ACCEPT' )
	nat.cmd( 'sudo iptables -t nat -A POSTROUTING -o ', 'eth0', '-j MASQUERADE' )

	# Instruct the kernel to perform forwarding
	nat.cmd( 'sudo sysctl net.ipv4.ip_forward=1' )
			
	CLI(net)


	os.system("sudo killall -9 /usr/bin/suricata")

	"""Stop NAT/forwarding between Mininet and external network"""
	# Flush any currently active rules
	nat.cmd( 'sudo iptables -F' )
	nat.cmd( 'sudo iptables -t nat -F' )

	# Instruct the kernel to stop forwarding
	nat.cmd( 'sudo sysctl net.ipv4.ip_forward=0' )

	os.system("sudo ./deleteFlowForSwitchs.sh")


	net.stop()