def bwtest( cpuLimits, period_us=100000, seconds=5 ):
    """Example/test of link and CPU bandwidth limits
       cpu: cpu limit as fraction of overall CPU time"""

    topo = TreeTopo( depth=1, fanout=2 )

    results = {}

    for sched in 'rt', 'cfs':
        print '*** Testing with', sched, 'bandwidth limiting'
        for cpu in cpuLimits:
            host = custom( CPULimitedHost, sched=sched,
                           period_us=period_us,
                           cpu=cpu )
            net = Mininet( topo=topo, host=host )
            net.start()
            net.pingAll()
            hosts = [ net.getNodeByName( h ) for h in topo.hosts() ]
            client, server = hosts[ 0 ], hosts[ -1 ]
            server.cmd( 'iperf -s -p 5001 &' )
            waitListening( client, server, 5001 )
            result = client.cmd( 'iperf -yc -t %s -c %s' % (
                seconds, server.IP() ) ).split( ',' )
            bps = float( result[ -1 ] )
            server.cmdPrint( 'kill %iperf' )
            net.stop()
            updated = results.get( sched, [] )
            updated += [ ( cpu, bps ) ]
            results[ sched ] = updated

    return results
Beispiel #2
0
def bwtest(cpuLimits, period_us=100000, seconds=5):
    """Example/test of link and CPU bandwidth limits
       cpu: cpu limit as fraction of overall CPU time"""

    topo = TreeTopo(depth=1, fanout=2)

    results = {}

    for sched in "rt", "cfs":
        print "*** Testing with", sched, "bandwidth limiting"
        for cpu in cpuLimits:
            host = custom(CPULimitedHost, sched=sched, period_us=period_us, cpu=cpu)
            try:
                net = Mininet(topo=topo, host=host)
            except:
                info("*** Skipping host %s\n" % sched)
                break
            net.start()
            net.pingAll()
            hosts = [net.getNodeByName(h) for h in topo.hosts()]
            client, server = hosts[0], hosts[-1]
            server.cmd("iperf -s -p 5001 &")
            waitListening(client, server, 5001)
            result = client.cmd("iperf -yc -t %s -c %s" % (seconds, server.IP())).split(",")
            bps = float(result[-1])
            server.cmdPrint("kill %iperf")
            net.stop()
            updated = results.get(sched, [])
            updated += [(cpu, bps)]
            results[sched] = updated

    return results
Beispiel #3
0
def bwtest( cpuLimits, period_us=100000, seconds=10 ):
    """Example/test of link and CPU bandwidth limits
       cpu: cpu limit as fraction of overall CPU time"""

    topo = TreeTopo( depth=1, fanout=2 )

    results = {}

    for sched in 'rt', 'cfs':
        info( '*** Testing with', sched, 'bandwidth limiting\n' )
        for cpu in cpuLimits:
            # cpu is the cpu fraction for all hosts, so we divide
            # it across two hosts
            host = custom( CPULimitedHost, sched=sched,
                           period_us=period_us,
                           cpu=.5*cpu )
            try:
                net = Mininet( topo=topo, host=host )
            # pylint: disable=bare-except
            except:
                info( '*** Skipping scheduler %s and cleaning up\n' % sched )
                cleanup()
                break
            net.start()
            net.pingAll()
            hosts = [ net.getNodeByName( h ) for h in topo.hosts() ]
            client, server = hosts[ 0 ], hosts[ -1 ]
            info( '*** Starting iperf with %d%% of CPU allocated to hosts\n' %
                  ( 100.0 * cpu ) )
            # We measure at the server because it doesn't include
            # the client's buffer fill rate
            popen = server.popen( 'iperf -yc -s -p 5001' )
            waitListening( client, server, 5001 )
            # ignore empty result from waitListening/telnet
            popen.stdout.readline()
            client.cmd( 'iperf -yc -t %s -c %s' % ( seconds, server.IP() ) )
            result = decode( popen.stdout.readline() ).split( ',' )
            bps = float( result[ -1 ] )
            popen.terminate()
            net.stop()
            updated = results.get( sched, [] )
            updated += [ ( cpu, bps ) ]
            results[ sched ] = updated

    return results
Beispiel #4
0
#
#    def terminate( self ):
#        self.cmd('sysctl net.ipv4.ip_forward=0')
#        super(LinuxRouter, self).terminate()

if __name__ == '__main__':

    class SingleSwitch(OVSSwitch):
        def start(self, controllers):
            return OVSSwitch.start(self, [cmap[self.name]])

    lg.setLogLevel('info')
    c0 = RemoteController('c0', ip='127.0.0.1', port=6633)
    cmap = {'s1': c0, 's2': c0, 's3': c0, 's4': c0}

    topo = TreeTopo(depth=2, fanout=2)
    net = Mininet(topo=topo, switch=SingleSwitch, build=False)
    net.addController(c0)
    net.build()
    #h3 = net.hosts[3]
    #h3.setDefaultRoute('via %s' % '10.0.0.1')

    # Add NAT connectivity
    #net.addNAT().config(mac=None, ip=h3.IP(), defaultRoute=None, lo='up')
    #net.addNAT().config(mac=None, defaultRoute=None, lo='up')
    net.addNAT().configDefault()
    net.start()
    print("*** Hosts are running and should have internet connectivity")
    print("*** Type 'exit' or control-D to shut down network")
    CLI(net)
    # Shut down NAT
Beispiel #5
0
# Test Suite
pingall_test("quick_start", "repeater.py", topo=SingleSwitchTopo(2))
pingall_test("netkat_principles", "repeater2.py", topo=SingleSwitchTopo(2))
pingall_test("netkat_principles", "repeater3.py", expect_pct=100)
pingall_test("netkat_principles", "repeater4.py")
pingall_test("netkat_principles", "repeater5.py")
pingall_test("l2_learning_switch", "learning1.py")
pingall_test("l2_learning_switch", "learning2.py", expect_pct=100)
pingall_test("l2_learning_switch", "learning3.py")
pingall_test("l2_learning_switch", "learning4.py")
pingall_test("handling_vlans", "vlan1.py", expect_pct=66)
sys.path.append("../handling_vlans")
from mn_custom_topo import VlanMininetBuilder
ct = VlanMininetBuilder()
pingall_test("handling_vlans", "vlan2.py", custom_topo=ct, expect_pct=83)
pingall_test("multiswitch_topologies", "multiswitch1.py", topo=TreeTopo(2, 4))
pingall_test("multiswitch_topologies", "multiswitch2.py", topo=TreeTopo(2, 4))
pingall_test("multiswitch_topologies", "multiswitch3.py", topo=TreeTopo(3, 3))
sys.path.append("../routing")
from mn_dot_topology import RouterMininetBuilder
ct = RouterMininetBuilder(CODE_ROOT + "/routing/topology.dot")
pingall_test("routing", "routing1.py", custom_topo=ct)
pingall_test("routing_variants",
             "load_balancer1.py",
             custom_topo=ct,
             custom_test=load_balancer_test)
pingall_test("routing_variants",
             "load_balancer2.py",
             custom_topo=ct,
             custom_test=load_balancer_test)
Beispiel #6
0
    if ips:
        error('Error:', intf, 'has an IP address,' 'and is probably in use!\n')
        exit(1)


if __name__ == '__main__':
    setLogLevel('info')

    # try to get hw intf from the command line; by default, use eth1
    intfName = sys.argv[1] if len(sys.argv) > 1 else 'eth1'
    info('*** Connecting to hw intf: %s' % intfName)

    info('*** Checking', intfName, '\n')
    checkIntf(intfName)

    info('*** Creating network\n')
    net = Mininet(topo=TreeTopo(depth=1, fanout=2), waitConnected=True)

    switch = net.switches[0]
    info('*** Adding hardware interface', intfName, 'to switch', switch.name,
         '\n')
    _intf = Intf(intfName, node=switch)

    info(
        '*** Note: you may need to reconfigure the interfaces for '
        'the Mininet hosts:\n', net.hosts, '\n')

    net.start()
    CLI(net)
    net.stop()
from mininet.net import Mininet
from mininet.topolib import TreeTopo
from mininet.node import Controller, RemoteController,OVSSwitch

import random
import threading

# Create and start mininet topology
tree_topo = TreeTopo(depth=3, fanout=2)
net = Mininet(topo=tree_topo, controller=RemoteController,switch=OVSSwitch)
net.start()

episode_count = 100
episode_length = 10
no_of_hosts = 8
victim_host_ip = '10.0.0.' + str(no_of_hosts)
spoofed_ip = '10.1.1.1'

# Command line tool hping3 is used to simulate DDoS
def ddos_flood(host):
    # Attack the last host with IP 10.0.0.4
    # timout command is used to abort the hping3 command after the attack was performed for the specifed time
    host.cmd('timeout ' + str(episode_length) + 's hping3 --flood ' + ' -a '+ spoofed_ip +' '+ victim_host_ip)
    host.cmd('killall hping3')


def ddos_benign(host):
    # Send benign packets to victim
    host.cmd('timeout ' + str(episode_length) + 's hping3 ' + victim_host_ip)
    host.cmd('killall hping3')
Beispiel #8
0
    if ips:
        error('Error:', intf, 'has an IP address,' 'and is probably in use!\n')
        exit(1)


if __name__ == '__main__':
    setLogLevel('info')

    # try to get hw intf from the command line; by default, use eth1
    intfName = sys.argv[1] if len(sys.argv) > 1 else 'wlan1'
    info('*** Connecting to hw intf: %s' % intfName)

    info('*** Checking', intfName, '\n')
    checkIntf(intfName)

    info('*** Creating network\n')
    net = Mininet(topo=TreeTopo(depth=1, fanout=2))

    switch = net.switches[0]
    info('*** Adding hardware interface', intfName, 'to switch', switch.name,
         '\n')
    _intf = Intf(intfName, node=switch)

    info(
        '*** Note: you may need to reconfigure the interfaces for '
        'the Mininet hosts:\n', net.hosts, '\n')

    net.start()
    CLI(net)
    net.stop()
Beispiel #9
0
#!/usr/bin/python

from mininet.log import setLogLevel
from mininet.net import Mininet
from mininet.topolib import TreeTopo
from mininet.cli import CLI

# We assume you are in the same directory as pox.py
# or that it is loadable via PYTHONPATH
from controllers import RYU, POX

setLogLevel('info')
'''
# ENSAYO CON RYU --> ok

net = Mininet( topo=TreeTopo( depth=2, fanout=2 ),
               controller=RYU )
'''

# ENSAYO CON POX --> ok
net = Mininet(topo=TreeTopo(depth=2, fanout=2), controller=POX)

net.start()
CLI(net)
net.stop()
Beispiel #10
0
                        default='10',
                        type=str,
                        help='Test bandwidth')
    parser.add_argument('ips',
                        metavar='ip',
                        help='ONOS Network Controllers IP Addresses',
                        default=['127.0.0.1'],
                        type=str,
                        nargs='*')
    cli_args = parser.parse_args()

    setLogLevel('info')

    switch = partial(OVSSwitch, protocols='OpenFlow13')

    rcs = []
    for ip in cli_args.ips:
        rcs.append(RemoteController('ONOS-%s' % ip, ip=ip, port=6633))
    net = Mininet(topo=TreeTopo(cli_args.depth, 2), switch=switch, build=False)
    for rc in rcs:
        net.addController(rc)
    net.build()
    net.start()
    b = int(cli_args.bandwidth)
    for i in range(b):
        net.hosts[i].sendCmd('ping -c100 -i 0.01 %s' % net.hosts[i + 1].IP())
    for i in range(b):
        print(net.hosts[i].waitOutput())
    CLI(net)
    net.stop()
Beispiel #11
0
def TreeNet( depth=1, fanout=2, **kwargs ):
    "Convenience function for creating tree networks."
    topo = TreeTopo( depth, fanout )
    return Mininet( topo, **kwargs )
Beispiel #12
0
from mininet.cli import CLI
from mininet.log import lg, info
from mininet.net import Mininet
from mininet.node import OVSKernelSwitch
from mininet.topolib import TreeTopo


def ifconfigTest(net):
    "Run ifconfig on all hosts in net."
    hosts = net.hosts
    for host in hosts:
        info(host.cmd('ifconfig'))


if __name__ == '__main__':
    lg.setLogLevel('info')
    info("*** Initializing Mininet and kernel modules\n")
    OVSKernelSwitch.setup()
    info("*** Creating network\n")
    network = Mininet(TreeTopo(depth=2, fanout=2), switch=OVSKernelSwitch)
    info("*** Starting network\n")
    network.start()
    info("*** Running ping test\n")
    network.pingAll()
    info("*** Running ifconfig test\n")
    ifconfigTest(network)
    info("*** Starting CLI (type 'exit' to exit)\n")
    CLI(network)
    info("*** Stopping network\n")
    network.stop()
    setLogLevel('info')

    # Create network
    if (len(sys.argv) != 2):
        print 'Specify topology single, tree, linear, assign1, triangle, mesh, or someloops'
        sys.exit(1)
    topoName = sys.argv[1]
    topoParts = topoName.split(',')
    if (topoParts[0] == "single"):
        if (len(topoParts) != 2 or not topoParts[1].isdigit()):
            sys.exit(1)
        topo = SingleSwitchTopo(k=int(topoParts[1]))
    elif (topoParts[0] == "tree"):
        if (len(topoParts) != 2 or not topoParts[1].isdigit()):
            sys.exit(1)
        topo = TreeTopo(depth=int(topoParts[1]))
    elif (topoParts[0] == "linear"):
        if (len(topoParts) != 2 or not topoParts[1].isdigit()):
            sys.exit(1)
        topo = LinearTopo(k=int(topoParts[1]))
    elif (topoParts[0] == "assign1"):
        topo = AssignOneTopo()
    elif (topoParts[0] == "triangle"):
        topo = TriangleTopo()
    elif (topoParts[0] == "mesh"):
        if (len(topoParts) != 2 or not topoParts[1].isdigit()):
            sys.exit(1)
        topo = MeshTopo(n=int(topoParts[1]))
    elif (topoParts[0] == "someloops"):
        topo = SomeLoopsTopo()
    else: