Ejemplo n.º 1
0
def stop(mn):
    global log
    if log: sys.stderr.write('Stopping the network...\n')
    for s in mn.servers:
        if log: sys.stderr.write('Killing web-server in server %s\n' % s.name)
        s.cmd('kill %python')
    if log: sys.stderr.write('Killing NOX, if any running\n')
    run('killall nox_core lt-nox_core')
    mn.net.stop()
Ejemplo n.º 2
0
def stop(mn):
    global log
    if log: sys.stderr.write('Stopping the network...\n')
    for s in mn.servers:
	if log: sys.stderr.write('Killing web-server in server %s\n' %
		s.name)
        s.cmd('kill %python')
    if log: sys.stderr.write('Killing NOX, if any running\n')
    run('killall nox_core lt-nox_core')
    mn.net.stop()
Ejemplo n.º 3
0
def stop(mn):
    global log
    if log:
        sys.stderr.write("Stopping the network...\n")
    for c in mn.clients:
        if log:
            sys.stderr.write("Killing web-server in server %s\n" % c.name)
        c.cmd("kill %python")
    if log:
        sys.stderr.write("Killing NOX, if any running\n")
    run("killall nox_core lt-nox_core")
    mn.net.stop()
Ejemplo n.º 4
0
                          ip='192.168.1.101/24',
                          defaultRoute='via 192.168.1.1')
        self.addLink(h4, s2)
        self.addLink(h5, s2)


if __name__ == '__main__':
    info('*** Starting Mininet *** \n')
    print '*** Starting Mininet *** \n'
    topo = RevocationTopo()
    net = Mininet(topo=topo, link=TCLink, controller=RemoteController)
    info('*** Topology Created *** \n')
    print "***Toplology Created***"

    net.start()
    run("ovs-vsctl set bridge s1 protocols=OpenFlow13")

    info('***attempting to start dhcp server***')
    #net.get('dhcp1').cmd('sudo /etc/init.d/isc-dhcp-server start')
    #net.get('dhcp1').cmd('sudo wireshark &')
    #info('***Starting Wireshark...*** \n')
    #raw_input("\nPress Enter once Wireshark is capturing trafic \n")
    #info('*** Assigning IP to h1 and h2 (See Wireshark) *** \n')
    #net.get('h1').cmd('dhclient')
    #net.get('h2').cmd('dhclient')
    info('*** Running CLI *** \n')
    net.get('nat1').cmd('ifconfig nat1-eth1 192.168.1.1')
    print '***Starting CLI *** \n'
    CLI(net)

    info('*** Stopping Network ***')
Ejemplo n.º 5
0
Archivo: QTopo.py Proyecto: kkc90/bal
def makeIntfPair(intf1,
                 intf2,
                 addr1=None,
                 addr2=None,
                 node1=None,
                 node2=None,
                 deleteIntfs=True,
                 runCmd=None):
    """Make a veth pair connnecting new interfaces intf1 and intf2
       intf1: name for interface 1
       intf2: name for interface 2
       addr1: MAC address for interface 1 (optional)
       addr2: MAC address for interface 2 (optional)
       node1: home node for interface 1 (optional)
       node2: home node for interface 2 (optional)
       deleteIntfs: delete intfs before creating them
       runCmd: function to run shell commands (quietRun)
       raises Exception on failure"""
    if not runCmd:
        runCmd = util.quietRun if not node1 else node1.cmd
        runCmd2 = util.quietRun if not node2 else node2.cmd
    if deleteIntfs:
        # Delete any old interfaces with the same names
        runCmd('ip link del ' + intf1)
        runCmd2('ip link del ' + intf2)
    """cmdOutput = util.run('ip tuntap add %s mode tap' %
                         (intf1))
    if cmdOutput:
        raise Exception("Error creating interface pair (%s,%s): %s " %
                        (intf1, intf2, cmdOutput))
    cmdOutput = util.run('ip tuntap add %s mode tap' %
                         (intf2))
    if cmdOutput:
        raise Exception("Error creating interface pair (%s,%s): %s " %
                        (intf1, intf2, cmdOutput))"""
    # Create new pair
    netns = 1 if not node2 else node2.pid
    print(
        '\nctapudp -s 0.0.0.0 -p %i -t 127.0.0.1 -k %i -i %s -a 1 -q 127.0.0.1 -r 55554 -e 100\n'
        % (makeIntfPair.portscount, makeIntfPair.portscount + 1, intf1))
    print(
        '\nctapudp -s 0.0.0.0 -p %i -t 127.0.0.1 -k %i -i %s -a 1 -q 127.0.0.1 -r 55554 -e 100\n'
        % (makeIntfPair.portscount + 1, makeIntfPair.portscount, intf2))
    process = subprocess.Popen([
        'ctapudp', '-s', '127.0.0.1', '-p',
        str(makeIntfPair.portscount), '-t', '127.0.0.1', '-k',
        str(makeIntfPair.portscount + 1), '-i', intf1, '-a', '1', '-q',
        '127.0.0.1', '-r', '55554', '-e', '100'
        """, '-d', '1'"""
    ],
                               preexec_fn=os.setpgrp)
    QKLink.processes.append(process)
    process = subprocess.Popen([
        'ctapudp', '-s', '127.0.0.1', '-p',
        str(makeIntfPair.portscount + 1), '-t', '127.0.0.1', '-k',
        str(makeIntfPair.portscount), '-i', intf2, '-a', '1', '-q',
        '127.0.0.1', '-r', '55554', '-e', '100'
        """, '-d', '1'"""
    ],
                               preexec_fn=os.setpgrp)
    QKLink.processes.append(process)
    time.sleep(0.5)
    makeIntfPair.portscount = makeIntfPair.portscount + 2
    if addr1 is None:
        cmdOutput = util.run('ip link set %s ' 'netns %s' % (intf1, node1.pid))
    else:
        cmdOutput = util.run('ip link set %s address %s '
                             'netns %s' % (intf1, addr1, node1.pid))

    if cmdOutput:
        for p in QKLink.processes:
            p.kill()
        raise Exception("Error creating interface pair (%s,%s): %s " %
                        (intf1, intf2, cmdOutput))
    if addr2 is None:
        cmdOutput = util.run('ip link set %s ' 'netns %s' % (intf2, netns))
    else:
        cmdOutput = util.run('ip link set %s address %s '
                             'netns %s' % (intf2, addr2, netns))

    if cmdOutput:
        for p in QKLink.processes:
            p.kill()
        raise Exception("Error creating interface pair (%s,%s): %s " %
                        (intf1, intf2, cmdOutput))
Ejemplo n.º 6
0
  ipc = '127.0.0.1'
  port = 6633 
  c = RemoteController('c', ip=ipc, port=port)
  net = Mininet(topo=topo, autoSetMacs=True, xterms=False, controller=None ,
                host=CPULimitedHost,
                link=TCLink)
  net.addController(c)
  net.start()
 
  # configure switches IP addresses
  for switch in net.switches:
      n = switchno[switch.name]
      s = G.node[n]['name']
      ip =  G.node[n]['ip'] + '/64'
      # switches shall be OpenFlow1.3 to support IPv6
      run('ovs-vsctl set bridge ' + s + ' protocols=OpenFlow13')
      for intf in switch.intfs.values():
          if intf.name != 'lo':
              switch.cmd('ip', '-f inet6 addr add', ip, 'dev', intf.name)
  
  for host in net.hosts:
      n = hostswitchno[host.name]
      ip = G.node[n]['hosts'][host.name]['ip'] + '/64'
      for intf in host.intfs.values():
          if intf.name != 'lo':
              host.cmd('ip', '-f inet6 addr add', ip, 'dev', intf.name)
      
  print "Hosts configured with IPs, switches pointing to simple_rpl_router at %s:%s" % (ipc, port)
  CLI(net)
  net.stop()
  
def BwidthTest( lossy=True ):
    "Create network and run simple performance test"
    topo = TwoSwitchTopo( n=4, lossy=lossy )
    net = Mininet( topo=topo,
                   host=CPULimitedHost, link=TCLink,
                   autoStaticArp=True )
    net.start()
    run("ovs-ofctl add-flow s1 in_port=3,actions=output:1 ")
    run( "ovs-ofctl add-flow s2 in_port=1,actions=output:4" )
    run("ovs-ofctl add-flow s2 in_port=4,actions=output:1")
    run("ovs-ofctl add-flow s1 in_port=1,actions=output:3")
    run("ovs-ofctl add-flow s1 in_port=3,udp,priority=40000,actions=output:2")
    f = open('output.txt','w')
    print( "Testing throughput between h1 and h4" )
    #Return node(s) with given name(s) 
    h1, h2, h3, h4 = net.getNodeByName('h1', 'h2','h3','h4')
    #Creating a UDP Server on H4
    h4.popen("iperf -s -u", shell = True)
    #Creating a TCP Server for the long running TCP Process
    processC=h4.popen("iperf -s -p 5201 -i 1 -1", shell = True)
    processD=h4.popen("iperf -s -p 5202 -i 1", shell = True)
    processA  = h1.popen("iperf -c 10.0.0.4 -p 5201 -t 120 -i 1 -b 5M", shell=True)
    sleep(5)
    CLI(net)
    print( "Throughput between h1 and h4, bwidth of 2" )
    process  = h1.popen("iperf -u -c 10.0.0.4 -p 5202 -t 10 -b 2M", shell=True)
    stdout, stderr = process.communicate()
    #f.write(stdout)
    print( stdout)
    sleep(10)
    print( "Throughput between h1 and h4, bwidth of 4" )
    process  = h1.popen("iperf -u -c 10.0.0.4 -p 5202 -t 10 -b 4M", shell=True)
    stdout, stderr = process.communicate()
    print( stdout )
    #f.write(stdout)
    sleep(5)
    print( "Throughput between h1 and h4, bwidth of 6" )
    process  = h1.popen("iperf -u -c 10.0.0.4 -p 5202 -t 10 -b 6M", shell=True)
    stdout, stderr = process.communicate()
    print( stdout )
    sleep(5)
    print( "Throughput between h1 and h4, bwidth of 8" )
    process = h1.popen("iperf -u -c 10.0.0.4 -p 5202 -t 10 -b 8M", shell=True)
    stdout, stderr = process.communicate()
    print( stdout )
    sleep(5)
    print( "Throughput between h1 and h4, bwidth of 10" )
    process = h1.popen("iperf -u -c 10.0.0.4 -p 5202 -t 10 -b 10M", shell=True)
    stdout, stderr = process.communicate()
    print( stdout )
    sleep(5)
    print( "Throughput between h1 and h4, bwidth of 12" )
    process = h1.popen("iperf -u -c 10.0.0.4 -p 5202 -t 10 -b 12M", shell=True)
    stdout, stderr = process.communicate()
    print( stdout )
    sleep(5)
    stdout1, stderr1 = processC.communicate()
    print( stdout1 )
    f.write(stdout1)
    stdout2, stderr2 = processA.communicate()
    print( stdout2 )
    print ("hello")
    net.stop()
def BwidthTest(lossy=True):
    "Create network and run simple performance test"
    topo = TwoSwitchTopo(n=4, lossy=lossy)
    net = Mininet(topo=topo,
                  host=CPULimitedHost,
                  link=TCLink,
                  autoStaticArp=True)
    net.start()
    run("ovs-ofctl add-flow s1 in_port=3,actions=output:1 ")
    run("ovs-ofctl add-flow s2 in_port=1,actions=output:4")
    run("ovs-ofctl add-flow s2 in_port=4,actions=output:1")
    run("ovs-ofctl add-flow s1 in_port=1,actions=output:3")
    run("ovs-ofctl add-flow s1 in_port=3,udp,priority=40000,actions=output:2")
    f = open('output.txt', 'w')
    print("Testing throughput between h1 and h4")
    #Return node(s) with given name(s)
    h1, h2, h3, h4 = net.getNodeByName('h1', 'h2', 'h3', 'h4')
    #Creating a UDP Server on H4
    h4.popen("iperf -s -u", shell=True)
    #Creating a TCP Server for the long running TCP Process
    processC = h4.popen("iperf -s -p 5201 -i 1 -1", shell=True)
    processD = h4.popen("iperf -s -p 5202 -i 1", shell=True)
    processA = h1.popen("iperf -c 10.0.0.4 -p 5201 -t 120 -i 1 -b 5M",
                        shell=True)
    sleep(5)
    CLI(net)
    print("Throughput between h1 and h4, bwidth of 2")
    process = h1.popen("iperf -u -c 10.0.0.4 -p 5202 -t 10 -b 2M", shell=True)
    stdout, stderr = process.communicate()
    #f.write(stdout)
    print(stdout)
    sleep(10)
    print("Throughput between h1 and h4, bwidth of 4")
    process = h1.popen("iperf -u -c 10.0.0.4 -p 5202 -t 10 -b 4M", shell=True)
    stdout, stderr = process.communicate()
    print(stdout)
    #f.write(stdout)
    sleep(5)
    print("Throughput between h1 and h4, bwidth of 6")
    process = h1.popen("iperf -u -c 10.0.0.4 -p 5202 -t 10 -b 6M", shell=True)
    stdout, stderr = process.communicate()
    print(stdout)
    sleep(5)
    print("Throughput between h1 and h4, bwidth of 8")
    process = h1.popen("iperf -u -c 10.0.0.4 -p 5202 -t 10 -b 8M", shell=True)
    stdout, stderr = process.communicate()
    print(stdout)
    sleep(5)
    print("Throughput between h1 and h4, bwidth of 10")
    process = h1.popen("iperf -u -c 10.0.0.4 -p 5202 -t 10 -b 10M", shell=True)
    stdout, stderr = process.communicate()
    print(stdout)
    sleep(5)
    print("Throughput between h1 and h4, bwidth of 12")
    process = h1.popen("iperf -u -c 10.0.0.4 -p 5202 -t 10 -b 12M", shell=True)
    stdout, stderr = process.communicate()
    print(stdout)
    sleep(5)
    stdout1, stderr1 = processC.communicate()
    print(stdout1)
    f.write(stdout1)
    stdout2, stderr2 = processA.communicate()
    print(stdout2)
    print("hello")
    net.stop()
Ejemplo n.º 9
0
        print "*** Linking h4 and h5 to Rogue NAT ***"
        self.addLink(h4, self.nat1, intfName1="nat1-eth1", params1=natParams)
        self.addLink(h5, self.nat1, intfName2="nat1-eth2", params2=natParams2)


if __name__ == "__main__":
    # info('*** Starting Mininet *** \n')
    print "*** Starting Mininet *** \n"
    topo = RevocationTopo()
    net = Mininet(topo=topo, link=TCLink, controller=RemoteController)
    # info('*** Topology Created *** \n')
    print "*** Toplology Created*** \n"

    net.start()
    run("ovs-vsctl set bridge s1 protocols=OpenFlow13")

    # info('*** Running CLI *** \n')
    print "*** Running CLI *** \n"
    # if the nat1-eth2 interface needs to be created, uncomment below line.
    # net.get('nat1').cmd('echo "iface nat1-eth2 inet manual" >> /etc/network/interfaces ')
    print "*** Assigning IPs to nat1-eth1 and nat1-eth2 ***"
    net.get("nat1").cmd("ifconfig nat1-eth1 192.168.1.1")
    net.get("nat1").cmd("ifconfig nat1-eth2 192.168.2.1")
    ##IPTABLE Config
    print "*** Configuring IP Tables for nat1 (allowing second interface)."
    net.get("nat1").cmd("iptables -P INPUT ACCEPT")
    net.get("nat1").cmd("iptables -P OUTPUT ACCEPT")
    net.get("nat1").cmd("iptables -P FORWARD DROP")
    net.get("nat1").cmd("sysctl net.ipv4.ip_forward=0")
    net.get("nat1").cmd(
Ejemplo n.º 10
0
def makeIntfPair(intf1,
                 intf2,
                 addr1=None,
                 addr2=None,
                 node1=None,
                 node2=None,
                 deleteIntfs=True,
                 runCmd=None,
                 isEncrypted=True):
    if not runCmd:
        runCmd = util.quietRun if not node1 else node1.cmd
        runCmd2 = util.quietRun if not node2 else node2.cmd
    if deleteIntfs:
        # Delete any old interfaces with the same names
        runCmd('ip link del ' + intf1)
        runCmd2('ip link del ' + intf2)

    # Create new pair
    netns = 1 if not node2 else node2.pid
    addEnc = '-e 100'
    if isEncrypted == False:
        addEnc = ''
    print(
        '\nctapudp -s 0.0.0.0 -p %i -t 127.0.0.1 -k %i -i %s -a 1 -q 127.0.0.1 -r 55554 %s\n'
        %
        (makeIntfPair.portscount, makeIntfPair.portscount + 1, intf1, addEnc))
    print(
        '\nctapudp -s 0.0.0.0 -p %i -t 127.0.0.1 -k %i -i %s -a 1 -q 127.0.0.1 -r 55554 %s\n'
        %
        (makeIntfPair.portscount + 1, makeIntfPair.portscount, intf2, addEnc))
    if isEncrypted == True:
        process = subprocess.Popen([
            'ctapudp', '-s', '127.0.0.1', '-p',
            str(makeIntfPair.portscount), '-t', '127.0.0.1', '-k',
            str(makeIntfPair.portscount + 1), '-i', intf1, '-a', '1', '-q',
            '127.0.0.1', '-r', '55554', '-e', '100'
            """, '-d', '1'"""
        ],
                                   preexec_fn=os.setpgrp)
    else:
        process = subprocess.Popen([
            'ctapudp', '-s', '127.0.0.1', '-p',
            str(makeIntfPair.portscount), '-t', '127.0.0.1', '-k',
            str(makeIntfPair.portscount + 1), '-i', intf1, '-a', '1', '-q',
            '127.0.0.1', '-r', '55554'
            """, '-d', '1'"""
        ],
                                   preexec_fn=os.setpgrp)
    QKLink.processes.append(process)
    if isEncrypted == True:
        process = subprocess.Popen([
            'ctapudp', '-s', '127.0.0.1', '-p',
            str(makeIntfPair.portscount + 1), '-t', '127.0.0.1', '-k',
            str(makeIntfPair.portscount), '-i', intf2, '-a', '1', '-q',
            '127.0.0.1', '-r', '55554', '-e', '100'
            """, '-d', '1'"""
        ],
                                   preexec_fn=os.setpgrp)
    else:
        process = subprocess.Popen([
            'ctapudp', '-s', '127.0.0.1', '-p',
            str(makeIntfPair.portscount + 1), '-t', '127.0.0.1', '-k',
            str(makeIntfPair.portscount), '-i', intf2, '-a', '1', '-q',
            '127.0.0.1', '-r', '55554'
            """, '-d', '1'"""
        ],
                                   preexec_fn=os.setpgrp)
    QKLink.processes.append(process)
    time.sleep(0.5)
    makeIntfPair.portscount = makeIntfPair.portscount + 2
    if addr1 is None:
        cmdOutput = util.run('ip link set %s ' 'netns %s' % (intf1, node1.pid))
    else:
        cmdOutput = util.run('ip link set %s address %s '
                             'netns %s' % (intf1, addr1, node1.pid))

    if cmdOutput:
        for p in QKLink.processes:
            p.kill()
        raise Exception("Error creating interface pair (%s,%s): %s " %
                        (intf1, intf2, cmdOutput))
    if addr2 is None:
        cmdOutput = util.run('ip link set %s ' 'netns %s' % (intf2, netns))
    else:
        cmdOutput = util.run('ip link set %s address %s '
                             'netns %s' % (intf2, addr2, netns))

    if cmdOutput:
        for p in QKLink.processes:
            p.kill()
        raise Exception("Error creating interface pair (%s,%s): %s " %
                        (intf1, intf2, cmdOutput))
Ejemplo n.º 11
0
def WifiNet():

    "Creation d'un reseau sans fil"

    net = Mininet(switch=OVSSwitch)

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

    wifi = WifiSegment(standard=ns.wifi.WIFI_PHY_STANDARD_80211g)
    wifinodes = []

    for n in nodes:
        nodename = n.get('name', None)
        nodetype = n.get('type', None)
        nodemob = n.get('mobility', None)
        nodepos = n.get('position', None)
        nodevel = n.get('velocity', None)
        nodeip = n.get('ip', None)
        if nodetype is 'host':
            addfunc = net.addHost
            color = (255, 0, 0)
        elif nodetype is 'switch':
            addfunc = net.addSwitch
            color = (0, 0, 255)
        else:
            addfunc = None
        if nodename is None or addfunc is None:
            continue
        if nodetype is 'host':
            node = addfunc(nodename, ip=nodeip)
        else:
            listenPort = n.get('ListenPort', None)
            node = addfunc(nodename, ip=nodeip, listenPort=listenPort)
        mininet.ns3.setMobilityModel(node, nodemob)
        if nodepos is not None:
            mininet.ns3.setPosition(node, nodepos[0], nodepos[1], nodepos[2])
        if nodevel is not None:
            mininet.ns3.setVelocity(node, nodevel[0], nodevel[1], nodevel[2])
        wifinodes.append(node)

    for wi in wifiintfs:
        winodename = wi.get('nodename', None)
        witype = wi.get('type', None)
        wichannel = wi.get('channel', None)
        wissid = wi.get('ssid', None)
        wiip = wi.get('ip', None)
        if witype is 'sta':
            addfunc = wifi.addSta
        elif witype is 'ap':
            addfunc = wifi.addAp
        else:
            addfunc = None
        if winodename is None or addfunc is None or wichannel is None:
            continue
        node = getWifiNode(wifinodes, winodename)
        tb = addfunc(node, wichannel, wissid)

    for cl in csmalinks:
        clnodename1 = cl.get('nodename1', None)
        clnodename2 = cl.get('nodename2', None)
        if clnodename1 is None or clnodename2 is None:
            continue
        clnode1 = getWifiNode(wifinodes, clnodename1)
        clnode2 = getWifiNode(wifinodes, clnodename2)
        if clnode1 is None or clnode2 is None:
            continue
        CSMALink(clnode1, clnode2, DataRate="100Mbps")

    #Generation d'un fichier xml pour faire l'animation avec NetAnim
    rv = os.path.isdir("/tmp/pcap")
    if rv is False:
        os.mkdir("/tmp/pcap")
    ns.wifi.YansWifiPhyHelper().Default().EnablePcapAll("/tmp/pcap/wifi")
    ns.csma.CsmaHelper().EnablePcapAll("/tmp/pcap/csma")

    rv = os.path.isdir("/tmp/xml")
    if rv is False:
        os.mkdir("/tmp/xml")
    anim = ns.netanim.AnimationInterface("/tmp/xml/wifi-wired-bridged4.xml")
    anim.EnablePacketMetadata(True)

    for n in nodes:
        anim.UpdateNodeDescription(node.nsNode,
                                   nodename + '-' + str(node.nsNode.GetId()))
        anim.UpdateNodeColor(node.nsNode, color[0], color[1], color[2])

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

    info('*** Liste des STA \n')
    for wi in wifiintfs:
        winodename = wi.get('nodename', None)
        witype = wi.get('type', None)
        wichannel = wi.get('channel', None)
        if witype is 'sta':
            info(winodename, " Channel: ", wichannel, "\n")
    info('*** Liste des AP \n')
    for wi in wifiintfs:
        winodename = wi.get('nodename', None)
        witype = wi.get('type', None)
        wichannel = wi.get('channel', None)
        if witype is 'ap':
            info(winodename, " Channel: ", wichannel, "\n")

    #info( '*** Testing Network connectivity\n' )
    #wifinodes[0].cmdPrint( 'ping 172.31.1.2 -c 3 ' )

    # Explicitly enable OpenFlow 1.3, then run the network
    run("ovs-vsctl set bridge s1 protocols=OpenFlow13")

    CLI(net)

    info('*** Stopping network\n')
    mininet.ns3.stop()
    info('*** mininet.ns3.stop()\n')
    mininet.ns3.clear()
    info('*** mininet.ns3.clear()\n')