def topo():
    network = Containernet(controller=Controller, ipBase='1.0.0.1/24')

    s1 = network.addSwitch('s1')
    s2 = network.addSwitch('s2')
    s3 = network.addSwitch('s3')

    docker_image = "testbed:netdata"
    home_path = os.path.expanduser('~')

    h1 = network.addHost(
        'h1',
        cls=Docker,
        ip="1.0.0.101",
        dimage=docker_image,
        defaultRoute='via 1.0.0.1',
        ports=[19999],
        port_bindings={19999: 19001},
        publish_all_ports=True,
        volumes=[home_path + "/SDN-Testbed/traffic/:/root/traffic"])
    h2 = network.addHost(
        'h2',
        cls=Docker,
        ip="1.0.0.102",
        dimage=docker_image,
        defaultRoute='via 1.0.0.1',
        ports=[19999],
        port_bindings={19999: 19002},
        publish_all_ports=True,
        volumes=[home_path + "/SDN-Testbed/traffic/:/root/traffic"])
    h3 = network.addHost(
        'h3',
        cls=Docker,
        ip="1.0.0.103",
        dimage=docker_image,
        defaultRoute='via 1.0.0.1',
        ports=[19999],
        port_bindings={19999: 19003},
        publish_all_ports=True,
        volumes=[home_path + "/SDN-Testbed/traffic/:/root/traffic"])
    h4 = network.addHost(
        'h4',
        cls=Docker,
        ip="1.0.0.104",
        dimage=docker_image,
        defaultRoute='via 1.0.0.1',
        ports=[19999],
        port_bindings={19999: 19004},
        publish_all_ports=True,
        volumes=[home_path + "/SDN-Testbed/traffic/:/root/traffic"])

    network.addLink(s1, s2, cls=TCLink, delay='10ms', bw=10)
    network.addLink(s1, s3, cls=TCLink, delay='15ms', bw=10)

    network.addLink(s2, h1, cls=TCLink, delay='10ms', bw=10)
    network.addLink(s2, h2, cls=TCLink, delay='10ms', bw=10)
    network.addLink(s3, h3, cls=TCLink, delay='20ms', bw=10)
    network.addLink(s3, h4, cls=TCLink, delay='20ms', bw=10)

    return network
Exemple #2
0
def topology():

    "Create a network with some docker containers acting as hosts."

    net = Containernet(controller=Controller)

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

    info('*** Adding hosts\n')
    h1 = net.addHost('h1')
    h2 = net.addHost('h2')

    info('*** Adding docker containers\n')
    d1 = net.addDocker('d1', ip='10.0.0.251', dimage="ubuntu:trusty")
    d2 = net.addDocker('d2', ip='10.0.0.252', dimage="ubuntu:trusty", cpu_period=50000, cpu_quota=25000)
    d3 = net.addHost(
        'd3', ip='11.0.0.253', cls=Docker, dimage="ubuntu:trusty", cpu_shares=20)
    d5 = net.addDocker('d5', dimage="ubuntu:trusty", volumes=["/:/mnt/vol1:rw"])

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

    info('*** Creating links\n')
    net.addLink(h1, s1)
    net.addLink(s1, d1)
    net.addLink(h2, s2)
    net.addLink(d2, s2)
    net.addLink(s1, s2)
    #net.addLink(s1, s2, cls=TCLink, delay="100ms", bw=1, loss=10)
    # try to add a second interface to a docker container
    net.addLink(d2, s3, params1={"ip": "11.0.0.254/8"})
    net.addLink(d3, s3)

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

    net.ping([d1, d2])

    # our extended ping functionality
    net.ping([d1], manualdestip="10.0.0.252")
    net.ping([d2, d3], manualdestip="11.0.0.254")

    info('*** Dynamically add a container at runtime\n')
    d4 = net.addDocker('d4', dimage="ubuntu:trusty")
    # we have to specify a manual ip when we add a link at runtime
    net.addLink(d4, s1, params1={"ip": "10.0.0.254/8"})
    # other options to do this
    #d4.defaultIntf().ifconfig("10.0.0.254 up")
    #d4.setIP("10.0.0.254")

    net.ping([d1], manualdestip="10.0.0.254")

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

    info('*** Stopping network')
    net.stop()
Exemple #3
0
def topo():
    network = Containernet(controller=Controller, ipBase='44.44.44.1/24')

    s_adv1 = network.addSwitch('s_adv1')

    docker_image = "testbed:basic"
    home_path = os.path.expanduser('~')

    h_adv1 = network.addHost(
        'h_adv1',
        cls=Docker,
        ip="44.44.44.41",
        dimage=docker_image,
        defaultRoute='via 44.44.44.1',
        volumes=[home_path + "/SDN-Testbed/traffic/:/root/traffic"])
    h_adv2 = network.addHost(
        'h_adv2',
        cls=Docker,
        ip="44.44.44.42",
        dimage=docker_image,
        defaultRoute='via 44.44.44.1',
        volumes=[home_path + "/SDN-Testbed/traffic/:/root/traffic"])

    network.addLink(s_adv1, h_adv1, cls=TCLink, delay='10ms', bw=10)
    network.addLink(s_adv1, h_adv2, cls=TCLink, delay='10ms', bw=10)

    return network
def run():
    net = Containernet(controller=Controller)
    net.addController('c0', port=6654)

    info('*** Adding routers\n')
    r1 = net.addHost('r1', cls=LinuxRouter, ip='10.0.0.1/24')
    r2 = net.addHost('r2', cls=LinuxRouter, ip='10.1.0.1/24')

    info('*** Adding switches\n')
    s1, s2 = [net.addSwitch(s) for s in ('s1', 's2')]

    info('*** Adding host-switch links\n')
    net.addLink(s1, r1, intfName2='r1-eth1', params2={'ip': '10.0.0.1/24'})

    net.addLink(s2, r2, intfName2='r2-eth1', params2={'ip': '10.1.0.1/24'})

    info('*** Adding switch-switch link\n')
    net.addLink(r1,
                r2,
                intfName1='r1-eth2',
                intfName2='r2-eth2',
                params1={'ip': '10.100.0.1/24'},
                params2={'ip': '10.100.0.2/24'})

    info('*** Adding routing\n')
    # r1.cmd("ip route add 10.1.0.0/24 via 10.100.0.1")
    # r2.cmd("ip route add 10.0.0.0/24 via 10.100.0.2")
    r1.cmd("ip route add 10.1.0.0/24 via 10.100.0.2 dev r1-eth2")
    r2.cmd("ip route add 10.0.0.0/24 via 10.100.0.1 dev r2-eth2")

    info('*** Adding hosts\n')
    d1 = net.addHost(name='d1',
                     ip='10.0.0.251/24',
                     defaultRoute='via 10.0.0.1')
    d2 = net.addHost(name='d2',
                     ip='10.1.0.252/24',
                     defaultRoute='via 10.1.0.1')

    info('*** Adding host-switch link\n')
    for d, s in [(d1, s1), (d2, s2)]:
        info(net.addLink(d, s))

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

    info('*** Routing Table on Router:\n')
    print((net['r1'].cmd('route')))

    info('*** Routing Table on Router:\n')
    print((net['r2'].cmd('route')))

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

    CLI(net)
    net.stop()
Exemple #5
0
def tfTopo():
    net = Containernet(topo=None,
                       controller=RemoteController,
                       switch=OVSKernelSwitch)

    net.addController('c0', RemoteController, ip="127.0.0.1", port=6633)

    # Hosts
    h1 = net.addHost('h1', ip='10.0.0.1', mac='00:00:00:00:00:01')
    h2 = net.addHost('h2', ip='10.0.0.2', mac='00:00:00:00:00:02')
    h3 = net.addHost('h3',
                     ip='10.0.0.3',
                     mac='00:00:00:00:00:03',
                     cls=Docker,
                     dimage='gmiotto/click',
                     mem_limit=1024 * 1024 * 10)
    h4 = net.addHost('h4', ip='10.0.0.4', mac='00:00:00:00:00:04')
    h5 = net.addHost('h5', ip='10.0.0.5', mac='00:00:00:00:00:05')

    #Switches
    s1 = net.addSwitch('s1')
    s2 = net.addSwitch('s2')
    s3 = net.addSwitch('s3')
    s4 = net.addSwitch('s4')
    s5 = net.addSwitch('s5')

    net.addLink(h3, s3)
    net.addLink(h3, s3)

    net.addLink(s1, s2)
    net.addLink(s2, s3)
    net.addLink(s3, s4)
    net.addLink(s4, s5)

    net.addLink(h1, s1)
    net.addLink(h2, s2)
    net.addLink(h4, s4)
    net.addLink(h5, s5)

    net.start()

    for host in net.hosts:
        if "h" in host.name:
            host.cmd('ethtool -K %s-eth0 tso off' % host.name)
    #call("echo  %s "% 'ha',shell=True)

    CLI(net)
    net.stop()
Exemple #6
0
def example():
    from mininet.log import setLogLevel
    from mininet.clean import cleanup
    from mininet.net import Containernet
    from mininet.cli import CLI

    setLogLevel('debug')

    cleanup()

    net = Containernet(controller=None)

    kali = net.addDocker(
        'kali',
        cls=Kali,
        resolution="1920x1080x24",  # OPTIONAL
        port_vnc=5900,  # OPTIONAL
        port_web=6080,  # OPTIONAL
        ip='10.10.10.1/24')

    kali.install_package("iproute2", "dnmap")

    h1 = net.addHost('h1', ip='10.10.10.2/24')
    s1 = net.addSwitch('s1')

    net.addLink(h1, s1)
    net.addLink(kali, s1)

    net.start()

    kali.install_package(["nmap"])

    CLI(net)
    net.stop()
Exemple #7
0
def example():
    from mininet.clean import cleanup
    from mininet.cli import CLI
    from mininet.log import info, setLogLevel
    from mininet.net import Containernet

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

        info('*** Running Cleanup\n')
        cleanup()

        net = Containernet(controller=None)

        info('*** Adding host\n')
        h1 = net.addHost('h1', ip='10.10.10.2/24')
        info('*** Adding switch\n')
        s1 = net.addSwitch('s1')
        info('*** Adding dhcpd\n')
        dhcpd = net.addDocker('dhcpd',
                              cls=Dhcpd,
                              dhcp_switch=s1,
                              ip='10.10.10.1/24')  # type: Dhcpd
        dhcpd.add_subnet(IPv4Network(u'10.10.10.0/24'))
        info('*** Creating links\n')
        net.addLink(h1, s1)
        net.addLink(dhcpd, s1)
        info('*** Starting network\n')
        net.start()
        info('*** Running CLI\n')
        CLI(net)
        info('*** Stopping network')
        net.stop()
Exemple #8
0
def topology():
    "Create a network with different node types, also utilizing Libvirt"

    net = Containernet(controller=Controller)

    net.addController("c0")

    n1 = net.addHost("h1", ip='10.0.0.1')
    n2 = net.addLibvirthost("vm1", ip='10.0.0.2', domain_name="ubuntu16.04")
    n3 = net.addDocker('d1', ip='10.0.0.3', dimage="ubuntu:trusty")
    n4 = net.addLibvirthost("vm2",
                            ip='10.0.0.4',
                            disk_image="/var/libvirt/images/ubuntu16.04.qcow2")

    info('*** Starting Switches and Links\n')
    s1 = net.addSwitch("s1")
    net.addLink(n1, s1)
    net.addLink(n2, s1)
    net.addLink(n3, s1)
    net.addLink(n4, s1)

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

    CLI(net)

    info('*** Stopping network')
    net.stop()
Exemple #9
0
def tfTopo():
 net = Containernet( topo=None, controller=RemoteController, switch=OVSKernelSwitch )

 net.addController( 'c0', RemoteController, ip="127.0.0.1", port=6633 )

 # Hosts 
 h1 = net.addHost('h1', ip='10.0.0.1', mac='00:00:00:00:00:01')
 h2 = net.addHost('h2', ip='10.0.0.2', mac='00:00:00:00:00:02')
 h3 = net.addHost('h3', ip='10.0.0.3', mac='00:00:00:00:00:03', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10)
 h4 = net.addHost('h4', ip='10.0.0.4', mac='00:00:00:00:00:04')
 h5 = net.addHost('h5', ip='10.0.0.5', mac='00:00:00:00:00:05')

 #Switches
 s1 = net.addSwitch('s1')
 s2 = net.addSwitch('s2')
 s3 = net.addSwitch('s3')
 s4 = net.addSwitch('s4')
 s5 = net.addSwitch('s5')

 net.addLink(h3,s3)
 net.addLink(h3,s3)

 net.addLink(s1,s2)
 net.addLink(s2,s3)
 net.addLink(s3,s4)
 net.addLink(s4,s5)
 
 net.addLink(h1,s1)
 net.addLink(h2,s2)
 net.addLink(h4,s4)
 net.addLink(h5,s5)
 


 net.start()

 for host in net.hosts:
     if "h" in host.name:
         host.cmd('ethtool -K %s-eth0 tso off' % host.name)
 #call("echo  %s "% 'ha',shell=True)
 
 CLI(net)
 net.stop()
Exemple #10
0
def myNetwork():
    net = Containernet(controller=Controller)

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

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

    info('*** Add hosts\n')
    # attacker 2 docker containers
    mn_args = {
        "network_mode": "none",
        "dimage": "lab05/crypto",
        "dcmd": "./start_app.sh",
        "ip": "192.168.16.2/24",
    }
    H1 = net.addDocker('h1', **mn_args)
    mn_args = {
        "network_mode": "none",
        "dimage": "lab05/crypto",
        "dcmd": "./start_app.sh",
        "ip": "192.168.16.100/24",
    }
    H2 = net.addDocker('h2', **mn_args)

    info('*** Add links\n')
    net.addLink(H1, s1)
    net.addLink(H2, s1)

    info('*** Add Internet access\n')
    mn_args = {
        "ip": "192.168.16.1/24",
    }
    nat = net.addHost('nat0',
                      cls=NAT,
                      inNamespace=False,
                      subnet='192.168.16.0/24',
                      **mn_args)
    # Connect the nat to the switch
    net.addLink(nat, s1)

    info('*** Starting network\n')
    net.start()
    H1.cmd('ip r a default via 192.168.16.1')
    H2.cmd('ip r a default via 192.168.16.1')

    CLI(net)
    net.stop()
Exemple #11
0
def topology():

    "Create a network with some docker containers acting as hosts."

    net = Containernet(controller=Controller)

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

    info('*** Adding normal Mininet hosts\n')
    h1 = net.addHost('h1')
    h2 = net.addHost('h2')

    info('*** Adding docker containers\n')
    d1 = net.addDocker('d1', ip='10.0.0.251', dimage="ubuntu:trusty")
    d2 = net.addDocker('d2', ip='10.0.0.252', dimage="ubuntu:trusty")

    info('*** Adding switch\n')
    s1 = net.addSwitch('s1')
    s2 = net.addSwitch('s2')
    s3 = net.addSwitch('s3')

    info('*** Creating links\n')
    net.addLink(h1, s1)
    net.addLink(h2, s2)
    net.addLink(d1, s1)
    net.addLink(d2, s2)
    net.addLink(s1, s2, cls=TCLink, delay="100ms", bw=1)

    # we can even add multiple interfaces to a single docker container
    net.addLink(d2, s3, params1={"ip": "11.0.0.254/24"})

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

    # run a short test
    net.ping([d1, d2])

    info('*** Running CLI\n')
    CLI(net)  # wait for user input

    info('*** Stopping network')
    net.stop()
Exemple #12
0
def emptyNet():

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

    net = Containernet(controller=Controller, link=TCLink)

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

    info('*** Adding hosts\n')
    h1 = net.addHost('h1', ip='10.0.0.1')
    h2 = net.addHost('h2', ip='10.0.0.2')
    d5 = net.addDocker('d5', dimage='kumokay/ubuntu_wifi:v6')
    d6 = net.addDocker('d6', dimage='kumokay/ubuntu_wifi:v6')

    info('*** Adding switch\n')
    s3 = net.addSwitch('s3')
    s4 = net.addSwitch('s4')

    info('*** Creating links\n')
    net.addLink(h1, s3)
    link = net.addLink(s3, s4, delay='100ms')
    net.addLink(h2, s4)
    net.addLink(d5, s3)
    net.addLink(d6, s4)

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

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

    link.intf1.config(delay='500ms')
    CLI(net)

    link.intf2.config(delay='300ms')
    CLI(net)

    info('*** Stopping network')
    net.stop()
Exemple #13
0
def example():
    setLogLevel('debug')

    cleanup()

    net = Containernet(controller=Controller)
    net.addController('c0')

    ftp = net.addDocker('ftp',
                        cls=Vsftpd,
                        ip='10.10.10.1/24')
    h1 = net.addHost('h1', ip='10.10.10.2/24')
    s1 = net.addSwitch('s1')
    net.addLink(h1, s1)
    net.addLink(ftp, s1)

    net.start()
    # Add test:test to users
    add_user(ftp, "test", "test")

    CLI(net)
    net.stop()
Exemple #14
0
def example():
    from mininet.log import setLogLevel
    from mininet.clean import cleanup
    from mininet.net import Containernet
    from mininet.cli import CLI

    setLogLevel('debug')

    cleanup()

    net = Containernet(controller=None)

    base = net.addDocker('base', cls=Base)

    h1 = net.addHost('h1', ip='10.10.10.2/24')
    s1 = net.addSwitch('s1')

    net.addLink(h1, s1)
    net.addLink(base, s1)

    net.start()

    CLI(net)
    net.stop()
Exemple #15
0
from mininet.log import setLogLevel, info



setLogLevel( 'info' )

net = Containernet(controller=Controller)

net.addController('c0')

info( '*** Adding switches\n' )
s1 = net.addSwitch( 's1', cls=OVSSwitch )
Intf( 'eth0', node=s1 )

info( '*** Adding host\n' )
h1 = net.addHost( 'h1' , ip='192.168.43.110' )
h2 = net.addHost( 'h2' , ip='192.168.43.111' )

# see: https://docker-py.readthedocs.io/en/1.7.0/port-bindings/
# for infomation on port binfing with Docker-py (https://docker-py.readthedocs.io/en/stable/)

info( '*** Adding docker containers\n' )
d1 = net.addDocker('d1', ip='192.168.43.10', dimage="cn-signal:latest", dcmd="node ./main.node.js 0.0.0.0", network_mode="bridge", ports=[8333], port_bindings={8334:8333}, publish_all_ports=True )
d2 = net.addDocker('d2', ip='192.168.43.11', dimage="cn-server:latest", dcmd="node ./private/gameMiddlebox.node.js ws", network_mode="bridge", ports=[8333, 9333], port_bindings={8333:8333, 9333:9333}, publish_all_ports=True )

info( "***Linking\n" )
net.addLink( h1, s1, cls=TCLink, bw=1 ) # must have a TCLink to controle the link speed, jitter ect...
net.addLink( d1, s1, bw=1 )
net.addLink( h2, s1, bw=1 )
net.addLink( d2, s1, bw=1 )
Exemple #16
0
#!/usr/bin/python
from mininet.net import Containernet
from mininet.cli import CLI
from mininet.log import info, setLogLevel
from mininet.bmv2 import ONOSBmv2Switch, P4DockerHost, P4Host, Bmv2Switch
setLogLevel('info')

net = Containernet(switch=Bmv2Switch)

info('*** Adding docker containers\n')

# HOSTS
h1 = net.addHost('h1', cls=P4Host, ip='10.0.0.1', mac="00:00:00:00:00:01")
h2 = net.addHost('h2', cls=P4Host, ip='10.0.0.2', mac="00:00:00:00:00:02")

# INT COLLECTOR
h3 = net.addHost('h3', cls=P4Host, ip='10.0.0.254', mac="00:00:00:00:00:FF")

v1 = net.addDocker('v1',
                   cls=P4DockerHost,
                   ip='10.0.0.100',
                   mac="00:00:00:00:00:F1",
                   dimage='fop4_example:eINT')
v2 = net.addDocker('v2',
                   cls=P4DockerHost,
                   ip='10.0.0.101',
                   mac="00:00:00:00:00:F2",
                   dimage='fop4_example:eINT')

info('*** Adding switches\n')
# SWITCHES
def topology():

    "Create a network with some docker containers acting as hosts."
    net = Containernet(controller=RemoteController)

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

    info('*** Adding hosts\n')
    Victim = net.addHost('h1', mac='00:00:00:00:00:01')
    Host2 = net.addHost('h2', mac='00:00:00:00:00:02')
    Host3 = net.addHost('h3', mac='00:00:00:00:00:03')
    Host4 = net.addHost('h4', mac='00:00:00:00:00:04')
    Host5 = net.addHost('h5', mac='00:00:00:00:00:05')
    Host6 = net.addHost('h6', mac='00:00:00:00:00:06')

    info('*** Adding docker containers\n')
    d1 = net.addDocker('d1',
                       ip='10.0.0.251',
                       mac='00:00:00:00:00:11',
                       dimage="mit/filter:latest")
    d2 = net.addDocker('d2',
                       ip='10.0.0.252',
                       mac='00:00:00:00:00:12',
                       dimage="mit/filter:latest")

    info('*** Adding switch\n')
    Switch1 = net.addSwitch('s1')
    Switch2 = net.addSwitch('s2')
    Switch3 = net.addSwitch('s3')
    Switch4 = net.addSwitch('s4')
    Switch5 = net.addSwitch('s5')
    Switch6 = net.addSwitch('s6')

    info('*** Creating links\n')
    net.addLink(Switch1, Switch3)
    net.addLink(Switch3, Switch5)
    net.addLink(Switch3, Switch6)
    net.addLink(Switch5, Host2)
    net.addLink(Switch6, Victim)
    net.addLink(Switch6, Switch4)
    net.addLink(Switch4, Switch2)

    net.addLink(Host3, Switch1)
    net.addLink(Host4, Switch1)
    net.addLink(Host5, Switch2)
    net.addLink(Host6, Switch2)

    # Attackers
    net.addLink(Switch1, d1)
    net.addLink(Switch2, d2)

    #net.addLink(s1, s2, cls=TCLink, delay="100ms", bw=1, loss=10)
    # try to add a second interface to a docker container
    #net.addLink(d2, s3, params1={"ip": "11.0.0.254/8"})
    #net.addLink(d3, s3)

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

    #net.ping([d1, d2])

    # our extended ping functionality
    #net.ping([d1], manualdestip="10.0.0.252")
    #net.ping([d2, d3], manualdestip="11.0.0.254")

    #info('*** Dynamically add a container at runtime\n')
    #d4 = net.addDocker('d4', dimage="ubuntu:trusty")
    # we have to specify a manual ip when we add a link at runtime
    #net.addLink(d4, s1, params1={"ip": "10.0.0.254/8"})
    # other options to do this
    #d4.defaultIntf().ifconfig("10.0.0.254 up")
    #d4.setIP("10.0.0.254")

    #net.ping([d1], manualdestip="10.0.0.254")

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

    info('*** Stopping network')
    net.stop()
Exemple #18
0
#!/usr/bin/python
from mininet.net import Containernet
from mininet.cli import CLI
from mininet.log import info, setLogLevel
setLogLevel('info')

net = Containernet()

info('*** Adding Controller\n')
c = net.addController()

info('*** Adding Hosts\n')

# HOST
h1 = net.addHost('h1')
h2 = net.addEbpfHost('h2')

info('*** Adding switches\n')

s1 = net.addSwitch('s1')

info('*** Creating links\n')
net.addLink(h1, s1)
net.addLink(h2, s1, ebpfProgram1="./program.o")
info('*** Starting network\n')

net.start()
net.staticArp()

info('*** Running CLI\n')
CLI(net)
Exemple #19
0
import os

setLogLevel('info')

info('*** Create the controller \n')

#info(c0)
"Create Simple topology example."
net = Containernet(switch = OVSSwitch, build=False)
net.addController('c0', controller = RemoteController, ip = "127.0.0.1", port = 6653)
net.addController('c1', controller = RemoteController, ip = "127.0.0.1", port = 6654)
# Initialize topology

# Add containers
h1 = net.addHost('h1', ip='10.0.0.251')  # Cliente
h2 = net.addHost('h2', ip='10.0.0.252')  # Atacante
h3 = net.addHost('h3', ip='10.0.0.253')  # Victima

# Add switches    
info('*** Adding switches\n')
sw1 = net.addSwitch('sw1', protocols='OpenFlow13')

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

# Build the network
info('*** Build the network\n')
Exemple #20
0
from mininet.net import Mininet
from mininet.net import Containernet
from mininet.node import Controller, Docker, OVSSwitch
from mininet.cli import CLI

net = Containernet() # net is a Mininet() object
h1 = net.addHost( 'h1' ) # h1 is a Host() object
h2 = net.addHost( 'h2' ,cls=Docker,dimage="gmiotto/click") # h2 is a Host()
h3 = net.addHost( 'h3' ) # h1 is a Host() object
s1 = net.addSwitch( 's1' ) # s1 is a Switch() object
c0 = net.addController( 'c0' ) # c0 is a Controller()
net.addLink( h2, s1 )
net.addLink( h2, s1 )
net.addLink( h1, s1 ) # creates a Link() object
net.addLink( h3, s1 )

net.start()
#print h1.cmd( 'ping -c1', h2.IP() )
CLI( net )
net.stop() 
Exemple #21
0
class simpleTestTopology(unittest.TestCase):
    """
        Helper class to do basic test setups.
        s1 -- s2 -- s3 -- ... -- sN
    """
    def __init__(self, *args, **kwargs):
        self.net = None
        self.s = []  # list of switches
        self.h = []  # list of hosts
        self.d = []  # list of docker containers
        self.docker_cli = None
        super(simpleTestTopology, self).__init__(*args, **kwargs)

    def createNet(self,
                  nswitches=1,
                  nhosts=0,
                  ndockers=0,
                  autolinkswitches=False):
        """
        Creates a Mininet instance and automatically adds some
        nodes to it.
        """
        self.net = Containernet(controller=Controller)
        self.net.addController('c0')

        # add some switches
        for i in range(0, nswitches):
            self.s.append(self.net.addSwitch('s%d' % i))
        # if specified, chain all switches
        if autolinkswitches:
            for i in range(0, len(self.s) - 1):
                self.net.addLink(self.s[i], self.s[i + 1])
        # add some hosts
        for i in range(0, nhosts):
            self.h.append(self.net.addHost('h%d' % i))
        # add some dockers
        for i in range(0, ndockers):
            self.d.append(self.net.addDocker('d%d' % i,
                                             dimage="ubuntu:trusty"))

    def startNet(self):
        self.net.start()

    def stopNet(self):
        self.net.stop()
        self.s = []
        self.h = []
        self.d = []

    def getDockerCli(self):
        """
        Helper to interact with local docker instance.
        """
        if self.docker_cli is None:
            self.docker_cli = docker.APIClient(
                base_url='unix://var/run/docker.sock')
        return self.docker_cli

    @staticmethod
    def setUp():
        pass

    @staticmethod
    def tearDown():
        cleanup()
        # make sure that all pending docker containers are killed
        with open(os.devnull, 'w') as devnull:
            subprocess.call(
                "docker rm -f $(docker ps --filter 'label=com.containernet' -a -q)",
                stdout=devnull,
                stderr=devnull,
                shell=True)

    def getContainernetContainers(self):
        """
        List the containers managed by containernet
        """
        return self.getDockerCli().containers(
            filters={"label": "com.containernet"})
def run():
    "Test linux router"
    net = Containernet(controller=Controller)  # controller is used by s1-s3
    net.addController('c0', port=6654)

    defaultIP = '10.0.0.1/24'  # IP address for r0-eth1
    router = net.addHost('r0', cls=LinuxRouter, ip=defaultIP)

    s1, s2, s3 = [net.addSwitch(s) for s in ('s1', 's2', 's3')]

    net.addLink(s1, router, intfName2='r0-eth1', params2={'ip': defaultIP})
    net.addLink(s2, router, intfName2='r0-eth2', params2={'ip': '10.0.1.1/24'})
    net.addLink(s3,
                router,
                intfName2='r0-eth3',
                params2={'ip': '192.0.2.1/24'})

    d1 = net.addDocker(name='d1',
                       ip='10.0.0.251/24',
                       defaultRoute='via 10.0.0.1',
                       ports=[1883],
                       port_bindings={1883: 1883},
                       dimage=IMAGE_NAME,
                       environment={
                           "EMQX_NAME": "docker1",
                           "EMQX_HOST": "10.0.0.251",
                           "EMQX_NODE__DIST_LISTEN_MAX": 6379,
                           "EMQX_LISTENER__TCP__EXTERNAL": 1883,
                           "EMQX_CLUSTER__DISCOVERY": "static",
                           "EMQX_CLUSTER__STATIC__SEEDS": "[email protected]"
                       })

    d2 = net.addDocker(name='d2',
                       ip='10.0.1.252/24',
                       defaultRoute='via 10.0.1.1',
                       ports=[1883],
                       port_bindings={1883: 1884},
                       dimage=IMAGE_NAME,
                       environment={
                           "EMQX_NAME": "docker2",
                           "EMQX_HOST": "10.0.1.252",
                           "EMQX_NODE__DIST_LISTEN_MAX": 6379,
                           "EMQX_LISTENER__TCP__EXTERNAL": 1883,
                           "EMQX_CLUSTER__DISCOVERY": "static",
                           "EMQX_CLUSTER__STATIC__SEEDS": "[email protected]"
                       })

    d3 = net.addDocker(name='d3',
                       ip='192.0.2.253/24',
                       defaultRoute='via 192.0.2.1',
                       ports=[1883],
                       port_bindings={1883: 1885},
                       dimage=IMAGE_NAME,
                       environment={
                           "EMQX_NAME": "docker3",
                           "EMQX_HOST": "192.0.2.253",
                           "EMQX_NODE__DIST_LISTEN_MAX": 6379,
                           "EMQX_LISTENER__TCP__EXTERNAL": 1883,
                           "EMQX_CLUSTER__DISCOVERY": "static",
                           "EMQX_CLUSTER__STATIC__SEEDS": "[email protected]"
                       })

    for h, s in [(d1, s1), (d2, s2), (d3, s3)]:
        info(net.addLink(h, s, cls=TCLink, delay='10ms'))

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

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

    info('*** Routing Table on Router:\n')
    print((net['r0'].cmd('route')))

    info('*** Starting brokers\n')
    d1.start()
    d2.start()
    d3.start()

    CLI(net)
    net.stop()
def run():
    net = Containernet(controller=Controller)  # controller is used by s1-s3
    net.addController('c0', port=6654)

    # net = ipaddress.ip_network('192.0.2.0/24')
    # router_1 = ipaddress.ip_address('10.0.1.1')
    # router_2 = ipaddress.ip_address('10.0.2.1')
    # router_3 = ipaddress.ip_address('10.0.3.1')
    #

    networks = [
        ipaddress.ip_network('10.0.{}.0/24'.format(net))
        for net in range(0, 3)
    ]
    linking_networks = [
        ipaddress.ip_network('10.{}.0.0/24'.format(net))
        for net in range(10, 40, 10)
    ]
    print(networks)
    print(linking_networks)

    router_1 = '{}/24'.format(next(networks[0].hosts()))
    router_2 = '{}/24'.format(next(networks[1].hosts()))
    router_3 = '{}/24'.format(next(networks[2].hosts()))

    info('*** Adding routers\n')
    r1 = net.addHost('r1', cls=LinuxRouter, ip=router_1)
    r2 = net.addHost('r2', cls=LinuxRouter, ip=router_2)
    r3 = net.addHost('r3', cls=LinuxRouter, ip=router_3)

    info('*** Adding switches\n')
    s1, s2, s3 = [net.addSwitch(s) for s in ('s1', 's2', 's3')]

    info('*** Adding host-switch links\n')
    net.addLink(s1, r1, intfName2='r1-eth1', params2={'ip': router_1})

    net.addLink(s2, r2, intfName2='r2-eth1', params2={'ip': router_2})

    net.addLink(s3, r3, intfName2='r3-eth1', params2={'ip': router_3})

    info('*** Adding router-router links\n')
    net.addLink(
        r1,
        r2,
        intfName1='r1-eth2',
        intfName2='r2-eth2',
        params1={'ip': '{}/24'.format(linking_networks[0][1].compressed)},
        params2={'ip': '{}/24'.format(linking_networks[0][2].compressed)})
    net.addLink(
        r2,
        r3,
        intfName1='r2-eth3',
        intfName2='r3-eth2',
        params1={'ip': '{}/24'.format(linking_networks[1][1].compressed)},
        params2={'ip': '{}/24'.format(linking_networks[1][2].compressed)})
    net.addLink(
        r1,
        r3,
        intfName1='r1-eth3',
        intfName2='r3-eth3',
        params1={'ip': '{}/24'.format(linking_networks[2][1].compressed)},
        params2={'ip': '{}/24'.format(linking_networks[2][2].compressed)})

    info('*** Adding routing\n')
    r1.cmd("ip route add 10.0.1.0/24 via 10.10.0.2 dev r1-eth2")
    r2.cmd("ip route add 10.0.0.0/24 via 10.10.0.1 dev r2-eth2")

    r2.cmd("ip route add 10.0.2.0/24 via 10.20.0.2 dev r2-eth3")
    r3.cmd("ip route add 10.0.1.0/24 via 10.20.0.1 dev r3-eth2")

    r1.cmd("ip route add 10.0.2.0/24 via 10.30.0.2 dev r1-eth3")
    r3.cmd("ip route add 10.0.0.0/24 via 10.30.0.1 dev r3-eth3")

    info('*** Adding hosts\n')
    d1 = net.addDocker(name='d1',
                       ip='10.0.0.251/24',
                       defaultRoute='via 10.0.0.1',
                       ports=[1883],
                       port_bindings={1883: 1883},
                       dimage=IMAGE_NAME,
                       environment={
                           "EMQX_NAME": "docker1",
                           "EMQX_HOST": "10.0.0.251",
                           "EMQX_NODE__DIST_LISTEN_MAX": 6379,
                           "EMQX_LISTENER__TCP__EXTERNAL": 1883,
                           "EMQX_CLUSTER__DISCOVERY": "static",
                           "EMQX_CLUSTER__STATIC__SEEDS": "[email protected]"
                       })

    d2 = net.addDocker(name='d2',
                       ip='10.0.1.252/24',
                       defaultRoute='via 10.0.1.1',
                       ports=[1883],
                       port_bindings={1883: 1884},
                       dimage=IMAGE_NAME,
                       environment={
                           "EMQX_NAME": "docker2",
                           "EMQX_HOST": "10.0.1.252",
                           "EMQX_NODE__DIST_LISTEN_MAX": 6379,
                           "EMQX_LISTENER__TCP__EXTERNAL": 1883,
                           "EMQX_CLUSTER__DISCOVERY": "static",
                           "EMQX_CLUSTER__STATIC__SEEDS": "[email protected]"
                       })

    d3 = net.addDocker(name='d3',
                       ip='10.0.2.253/24',
                       defaultRoute='via 10.0.2.1',
                       ports=[1883],
                       port_bindings={1883: 1885},
                       dimage=IMAGE_NAME,
                       environment={
                           "EMQX_NAME": "docker3",
                           "EMQX_HOST": "10.0.2.253",
                           "EMQX_NODE__DIST_LISTEN_MAX": 6379,
                           "EMQX_LISTENER__TCP__EXTERNAL": 1883,
                           "EMQX_CLUSTER__DISCOVERY": "static",
                           "EMQX_CLUSTER__STATIC__SEEDS": "[email protected]"
                       })

    info('*** Adding host-switch link\n')
    for d, s in [(d1, s1), (d2, s2), (d3, s3)]:
        print(net.addLink(d, s))

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

    info('*** Routing Table on Router:\n')
    print((net['r1'].cmd('route')))

    info('*** Routing Table on Router:\n')
    print((net['r2'].cmd('route')))

    info('*** Routing Table on Router:\n')
    print((net['r3'].cmd('route')))

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

    info('*** Starting brokers\n')
    d1.start()
    d2.start()
    d3.start()

    CLI(net)
    net.stop()
Exemple #24
0
def topology():
    "Create a network with some docker containers acting as hosts."

    net = Containernet(controller=Controller)

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

    info('*** Adding hosts\n')
    h1 = net.addHost('h1')
    h2 = net.addHost('h2')

    info('*** Adding docker containers\n')
    d1 = net.addDocker('d1',
                       ip='10.0.0.251',
                       dimage="host-fluentd:latest",
                       log_driver='fluentd',
                       log_opts={
                           'fluentd-address': '{}:24224'.format(FLUENTD_IP),
                           'tag': 'docker-host-1'
                       },
                       environment={'FLUENTD_IP': FLUENTD_IP})
    d2 = net.addDocker('d2',
                       ip='10.0.0.252',
                       dimage="host-fluentd:latest",
                       cpu_period=50000,
                       cpu_quota=25000,
                       log_driver='fluentd',
                       log_opts={
                           'fluentd-address': '{}:24224'.format(FLUENTD_IP),
                           'tag': 'docker-host-2'
                       },
                       environment={'FLUENTD_IP': FLUENTD_IP})
    d3 = net.addHost('d3',
                     ip='11.0.0.253',
                     cls=Docker,
                     dimage="ubuntu:trusty",
                     cpu_shares=20)
    # using advanced features like volumes and exposed ports
    d5 = net.addDocker('d5',
                       dimage="ubuntu:trusty",
                       volumes=["/:/mnt/vol1:rw"],
                       ports=[9999],
                       port_bindings={9999: 9999},
                       publish_all_ports=True)

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

    info('*** Creating links\n')
    net.addLink(h1, s1)
    net.addLink(s1, d1)
    net.addLink(h2, s2)
    net.addLink(d2, s2)
    net.addLink(s1, s2)
    # net.addLink(s1, s2, cls=TCLink, delay="100ms", bw=1, loss=10)
    # try to add a second interface to a docker container
    net.addLink(d2, s3, params1={"ip": "11.0.0.254/8"})
    net.addLink(d3, s3)

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

    net.ping([d1, d2])

    # our extended ping functionality
    net.ping([d1], manualdestip="10.0.0.252")
    net.ping([d2, d3], manualdestip="11.0.0.254")

    info('*** Dynamically add a container at runtime\n')
    d4 = net.addDocker('d4', dimage="ubuntu:trusty")
    # we have to specify a manual ip when we add a link at runtime
    net.addLink(d4, s1, params1={"ip": "10.0.0.254/8"})
    # other options to do this
    # d4.defaultIntf().ifconfig("10.0.0.254 up")
    # d4.setIP("10.0.0.254")

    net.ping([d1], manualdestip="10.0.0.254")

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

    info('*** Stopping network')
    net.stop()
Exemple #25
0
class simpleTestTopology(unittest.TestCase):
    """
        Helper class to do basic test setups.
        s1 -- s2 -- s3 -- ... -- sN
    """
    def __init__(self, *args, **kwargs):
        self.net = None
        self.s = []  # list of switches
        self.h = []  # list of hosts
        self.d = []  # list of docker containers
        self.l = []
        self.docker_cli = None
        self.lv_conn_qemu = libvirt.open('qemu:///system')
        self.vm_names = ["vm1", "vm2", "vm3"]
        super(simpleTestTopology, self).__init__(*args, **kwargs)

    def createNet(self,
                  nswitches=1,
                  nhosts=0,
                  ndockers=0,
                  nlibvirt=0,
                  autolinkswitches=False,
                  use_running=False):
        """
        Creates a Mininet instance and automatically adds some
        nodes to it.
        """
        self.net = Containernet(controller=Controller,
                                mgmt_net={'mac': '00:AA:BB:CC:DD:EE'},
                                cmd_endpoint="qemu:///system")
        self.net.addController('c0')

        # add some switches
        for i in range(0, nswitches):
            self.s.append(self.net.addSwitch('s%d' % i))
        # if specified, chain all switches
        if autolinkswitches:
            for i in range(0, len(self.s) - 1):
                self.net.addLink(self.s[i], self.s[i + 1])
        # add some hosts
        for i in range(0, nhosts):
            self.h.append(self.net.addHost('h%d' % i))
        # add some dockers
        for i in range(0, ndockers):
            self.d.append(self.net.addDocker('d%d' % i,
                                             dimage="ubuntu:trusty"))

        for i in range(1, nlibvirt + 1):
            self.l.append(
                self.net.addLibvirthost('vm%d' % i,
                                        disk_image=DISK_IMAGE,
                                        use_existing_vm=use_running))

    def startNet(self):
        self.net.start()

    def stopNet(self):
        self.net.stop()

    def getDockerCli(self):
        """
        Helper to interact with local docker instance.
        """
        if self.docker_cli is None:
            self.docker_cli = docker.APIClient(
                base_url='unix://var/run/docker.sock')
        return self.docker_cli

    def setUp(self):
        print "\nTesting: ", self._testMethodName

    @staticmethod
    def tearDown():
        cleanup()
        # make sure that all pending docker containers are killed
        with open(os.devnull, 'w') as devnull:
            subprocess.call(
                "docker rm -f $(docker ps --filter 'label=com.containernet' -a -q)",
                stdout=devnull,
                stderr=devnull,
                shell=True)

    def getContainernetContainers(self):
        """
        List the containers managed by containernet
        """
        return self.getDockerCli().containers(
            filters={"label": "com.containernet"})

    def getContainernetLibvirtHosts(self):
        hosts = 0
        for domain in self.lv_conn_qemu.listAllDomains():
            xml = minidom.parseString(domain.XMLDesc())
            title = xml.getElementsByTagName("title")
            if title and "com.containernet" in title[0].toxml():
                hosts += 1

        return hosts
Exemple #26
0
def tfTopo():
    net = Containernet( topo=None, controller=RemoteController, switch=OVSKernelSwitch )

    net.addController( 'c0', RemoteController, ip="127.0.0.1", port=6633 )

    #Arguments
    opts, args = getopt.getopt(sys.argv[1:], "", ["flows=", "dos="])
    for o, a in opts:
        if o == "--flows":
            number_of_flows=int(a)
            print "Flows: ",a
        elif o in ("--dos"):
            number_of_dos=int(a)
            print "DoS: ",a

# Hosts 
    h1 = net.addHost('h1', ip='10.0.0.1', mac='00:00:00:00:00:01')
    h2 = net.addHost('h2', ip='10.0.0.2', mac='00:00:00:00:00:02')
    h3 = net.addHost('h3', ip='10.0.0.3', mac='00:00:00:00:00:03')
    h4 = net.addHost('h4', ip='10.0.0.4', mac='00:00:00:00:00:04')
    h5 = net.addHost('h5', ip='10.0.0.5', mac='00:00:00:00:00:05')
    h6 = net.addHost('h6', ip='10.0.0.6', mac='00:00:00:00:00:06')
    h7 = net.addHost('h7', ip='10.0.0.7', mac='00:00:00:00:00:07')
    h8 = net.addHost('h8', ip='10.0.0.8', mac='00:00:00:00:00:08')
    h9 = net.addHost('h9', ip='10.0.0.9', mac='00:00:00:00:00:09')
    h10 = net.addHost('h10', ip='10.0.0.10', mac='00:00:00:00:00:10')

    p1 = net.addHost('p1', ip='10.0.1.1', mac='00:00:00:00:01:01', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10, cpu_quota=pop_cpu_percentage*100,cpu_period=10000)
    p2 = net.addHost('p2', ip='10.0.1.2', mac='00:00:00:00:01:02', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10, cpu_quota=pop_cpu_percentage*100,cpu_period=10000)
    p3 = net.addHost('p3', ip='10.0.1.3', mac='00:00:00:00:01:03', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10, cpu_quota=pop_cpu_percentage*100,cpu_period=10000)
    p4 = net.addHost('p4', ip='10.0.1.4', mac='00:00:00:00:01:04', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10, cpu_quota=pop_cpu_percentage*100,cpu_period=10000)
    p5 = net.addHost('p5', ip='10.0.1.5', mac='00:00:00:00:01:05', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10, cpu_quota=pop_cpu_percentage*100,cpu_period=10000)
    p6 = net.addHost('p6', ip='10.0.1.6', mac='00:00:00:00:01:06', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10, cpu_quota=pop_cpu_percentage*100,cpu_period=10000)

    #Switches
    s1 = net.addSwitch('s1')
    s2 = net.addSwitch('s2')
    s3 = net.addSwitch('s3')
    s4 = net.addSwitch('s4')
    s5 = net.addSwitch('s5')
    s6 = net.addSwitch('s6')
    s7 = net.addSwitch('s7')
    s8 = net.addSwitch('s8')
    s9 = net.addSwitch('s9')
    s10 = net.addSwitch('s10')

    #PoP Hosts
    net.addLink(p1,s1, cls=TCLink, delay=pop_link_delay,bw=pop_link_bw,loss=pop_link_loss)
    net.addLink(p1,s1)

    net.addLink(p2,s2, cls=TCLink, delay=pop_link_delay,bw=pop_link_bw,loss=pop_link_loss)
    net.addLink(p2,s2)

    net.addLink(p3,s3, cls=TCLink, delay=pop_link_delay,bw=pop_link_bw,loss=pop_link_loss)
    net.addLink(p3,s3)

    net.addLink(p4,s4, cls=TCLink, delay=pop_link_delay,bw=pop_link_bw,loss=pop_link_loss)
    net.addLink(p4,s4)

    net.addLink(p5,s5, cls=TCLink, delay=pop_link_delay,bw=pop_link_bw,loss=pop_link_loss)
    net.addLink(p5,s5)

    net.addLink(p6,s6, cls=TCLink, delay=pop_link_delay,bw=pop_link_bw,loss=pop_link_loss)
    net.addLink(p6,s6)

    #Normal Hosts
    net.addLink(h1,s1, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
    net.addLink(h2,s2, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
    net.addLink(h3,s3, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
    net.addLink(h4,s4, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
    net.addLink(h5,s5, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
    net.addLink(h6,s6, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
    net.addLink(h7,s7, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
    net.addLink(h8,s8, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
    net.addLink(h9,s9, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
    net.addLink(h10,s10, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)

    net.addLink(s7, s1, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) #s7-s1
    net.addLink(s7, s2, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s1, s2, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s1, s8, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s1, s3, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s1, s6, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s8, s3, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s2, s5, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s2, s4, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s3, s5, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s3, s4, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s4, s9, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s4, s6, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s5, s6, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s5, s10, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s9, s6, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s10, s6, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 

    net.start()

    for host in net.hosts:
        if "h" in host.name:
            host.cmd('ethtool -K %s-eth0 tso off' % host.name)
            host.cmd('python httpserver.py  80 &')

    for host in net.hosts:
        if "p" in host.name:
            call("sudo bash Click/runFirewall.sh %s Click/firewall3.click " % host.name,shell=True)


    CLI(net)
    net.stop()
class simpleTestTopology( unittest.TestCase ):
    """
        Helper class to do basic test setups.
        s1 -- s2 -- s3 -- ... -- sN
    """

    def __init__(self, *args, **kwargs):
        self.net = None
        self.s = []  # list of switches
        self.h = []  # list of hosts
        self.d = []  # list of docker containers
        self.docker_cli = None
        super(simpleTestTopology, self).__init__(*args, **kwargs)

    def createNet(
            self,
            nswitches=1, nhosts=0, ndockers=0,
            autolinkswitches=False):
        """
        Creates a Mininet instance and automatically adds some
        nodes to it.
        """
        self.net = Containernet( controller=Controller )
        self.net.addController( 'c0' )

        # add some switches
        for i in range(0, nswitches):
            self.s.append(self.net.addSwitch('s%d' % i))
        # if specified, chain all switches
        if autolinkswitches:
            for i in range(0, len(self.s) - 1):
                self.net.addLink(self.s[i], self.s[i + 1])
        # add some hosts
        for i in range(0, nhosts):
            self.h.append(self.net.addHost('h%d' % i))
        # add some dockers
        for i in range(0, ndockers):
            self.d.append(self.net.addDocker('d%d' % i, dimage="ubuntu:trusty"))

    def startNet(self):
        self.net.start()

    def stopNet(self):
        self.net.stop()

    def getDockerCli(self):
        """
        Helper to interact with local docker instance.
        """
        if self.docker_cli is None:
            self.docker_cli = docker.APIClient(
                base_url='unix://var/run/docker.sock')
        return self.docker_cli

    @staticmethod
    def setUp():
        pass

    @staticmethod
    def tearDown():
        cleanup()
        # make sure that all pending docker containers are killed
        with open(os.devnull, 'w') as devnull:
            subprocess.call(
                "docker rm -f $(docker ps --filter 'label=com.containernet' -a -q)",
                stdout=devnull,
                stderr=devnull,
                shell=True)

    def getContainernetContainers(self):
        """
        List the containers managed by containernet
        """
        return self.getDockerCli().containers(filters={"label": "com.containernet"})
net = Containernet(controller=Controller, switch=NormalP4Switch)

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

info('*** Adding docker containers\n')

# Fake HOST
d1 = net.addDocker('d1',
                   cls=P4DockerHost,
                   ip='192.168.1.100',
                   dimage="containernet_example:ubuntup4",
                   mac="00:00:00:00:00:01")
d1.start()
# HOST
h1 = net.addHost('h1', ip='192.168.1.104', mac="00:00:00:00:00:04")
h2 = net.addHost('h2', ip='192.168.1.105', mac="00:00:00:00:00:05")

# h4 = net.addDocker('h4', cls=P4DockerHost, ip='192.168.1.104',
#                   dimage="containernet_ubuntup4:latest", mac="00:00:00:00:00:04")
# h5 = net.addDocker('h5', cls=P4DockerHost, ip='192.168.1.105',
#                   dimage="containernet_ubuntup4:latest", mac="00:00:00:00:00:05")

# LAMP servers
d2 = net.addDocker('d2',
                   cls=P4DockerHost,
                   ip='192.168.1.200',
                   dimage="containernet_example:lamp",
                   mac="00:00:00:00:00:A0")
d2.start()
d3 = net.addDocker('d3',
Exemple #29
0
def tfTopo():
    net = Containernet( topo=None, controller=RemoteController, switch=OVSKernelSwitch )

    net.addController( 'c0', RemoteController, ip="127.0.0.1", port=6633 )

    #Arguments
    opts, args = getopt.getopt(sys.argv[1:], "", ["flows=", "dos="])
    for o, a in opts:
        if o == "--flows":
            number_of_flows=int(a)
            print "Flows: ",a
        elif o in ("--dos"):
            number_of_dos=int(a)
            print "DoS: ",a

# Hosts 
    h1 = net.addHost('h1', ip='10.0.0.1', mac='00:00:00:00:00:01')
    h2 = net.addHost('h2', ip='10.0.0.2', mac='00:00:00:00:00:02')
    h3 = net.addHost('h3', ip='10.0.0.3', mac='00:00:00:00:00:03')
    h4 = net.addHost('h4', ip='10.0.0.4', mac='00:00:00:00:00:04')
    h5 = net.addHost('h5', ip='10.0.0.5', mac='00:00:00:00:00:05')
    h6 = net.addHost('h6', ip='10.0.0.6', mac='00:00:00:00:00:06')
    h7 = net.addHost('h7', ip='10.0.0.7', mac='00:00:00:00:00:07')
    h8 = net.addHost('h8', ip='10.0.0.8', mac='00:00:00:00:00:08')
    h9 = net.addHost('h9', ip='10.0.0.9', mac='00:00:00:00:00:09')
    h10 = net.addHost('h10', ip='10.0.0.10', mac='00:00:00:00:00:10')

    p1 = net.addHost('p1', ip='10.0.1.1', mac='00:00:00:00:01:01', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10, cpu_quota=pop_cpu_percentage*100,cpu_period=10000)
    p2 = net.addHost('p2', ip='10.0.1.2', mac='00:00:00:00:01:02', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10, cpu_quota=pop_cpu_percentage*100,cpu_period=10000)
    p3 = net.addHost('p3', ip='10.0.1.3', mac='00:00:00:00:01:03', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10, cpu_quota=pop_cpu_percentage*100,cpu_period=10000)
    p4 = net.addHost('p4', ip='10.0.1.4', mac='00:00:00:00:01:04', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10, cpu_quota=pop_cpu_percentage*100,cpu_period=10000)
    p5 = net.addHost('p5', ip='10.0.1.5', mac='00:00:00:00:01:05', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10, cpu_quota=pop_cpu_percentage*100,cpu_period=10000)

    #Switches
    s1 = net.addSwitch('s1')
    s2 = net.addSwitch('s2')
    s3 = net.addSwitch('s3')
    s4 = net.addSwitch('s4')
    s5 = net.addSwitch('s5')
    s6 = net.addSwitch('s6')
    s7 = net.addSwitch('s7')
    s8 = net.addSwitch('s8')
    s9 = net.addSwitch('s9')
    s10 = net.addSwitch('s10')

    #PoP Hosts
    net.addLink(p1,s1, cls=TCLink, delay=pop_link_delay,bw=pop_link_bw,loss=pop_link_loss)
    net.addLink(p1,s1)

    net.addLink(p2,s2, cls=TCLink, delay=pop_link_delay,bw=pop_link_bw,loss=pop_link_loss)
    net.addLink(p2,s2)

    net.addLink(p3,s3, cls=TCLink, delay=pop_link_delay,bw=pop_link_bw,loss=pop_link_loss)
    net.addLink(p3,s3)

    net.addLink(p4,s4, cls=TCLink, delay=pop_link_delay,bw=pop_link_bw,loss=pop_link_loss)
    net.addLink(p4,s4)

    net.addLink(p5,s5, cls=TCLink, delay=pop_link_delay,bw=pop_link_bw,loss=pop_link_loss)
    net.addLink(p5,s5)

    #Normal Hosts
    net.addLink(h1,s1, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
    net.addLink(h2,s2, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
    net.addLink(h3,s3, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
    net.addLink(h4,s4, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
    net.addLink(h5,s5, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
    net.addLink(h6,s6, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
    net.addLink(h7,s7, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
    net.addLink(h8,s8, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
    net.addLink(h9,s9, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
    net.addLink(h10,s10, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)

    net.addLink(s7, s1, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) #s7-s1
    net.addLink(s7, s2, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s1, s2, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s1, s8, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s1, s3, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s1, s6, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s8, s3, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s2, s5, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s2, s4, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s3, s5, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s3, s4, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s4, s9, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s4, s6, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s5, s6, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s5, s10, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s9, s6, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 
    net.addLink(s10, s6, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) 

    net.start()

    for host in net.hosts:
        if "h" in host.name:
            host.cmd('ethtool -K %s-eth0 tso off' % host.name)
            host.cmd('python httpserver.py  80 &')

    for host in net.hosts:
        if "p" in host.name:
            call("sudo bash Click/runFirewall.sh %s Click/firewall3.click " % host.name,shell=True)

    time.sleep(5)

    #Flows 
    random.seed()
    hs = [0,1,2,3,4,5,6,7,8,9]
    random.shuffle(hs)
    if number_of_flows > 5:
        number_of_flows = 5
    for i in range(0,number_of_flows):
        h_src = hs[2*i]
        h_tgt = hs[2*i+1]
        #pair = random.sample([0,1,2,3,4,5,6,7,8,9],2)
    #    print net.hosts[pair[0]].name, "->", net.hosts[pair[1]].name
        net.hosts[h_src].cmd('bash client.sh "%s" 10.0.0.%s &' % (net.hosts[h_src].name, h_tgt+1))
        net.hosts[h_src].cmd('echo ha')
        print 'bash client.sh "%s" %s &' % (net.hosts[h_src].name, net.hosts[h_tgt].name)
        
    time.sleep(2)

    targets = [1,2,3,4,5]
    random.shuffle(targets)
    for i in range(0,number_of_dos):
        h1.cmd('ping -c1 10.0.1.%s &' % targets[i])
        print "Attacking p%s" % targets[i]

    #h1.cmd('ping -c10 p5 &')
    time.sleep(60)
    #time.sleep(150)
    for host in net.hosts:
        if "h" in host.name:
            host.cmd('echo ha')

    #CLI(net)
    net.stop()
                    dimage="phfaustini/firewall:latest")

net.addLink(s1, h51, **linkopts_switches)
net.addLink(s1, h52, **linkopts_switches)
net.addLink(h52, s3, **linkopts_switches)
net.addLink(h51, s2, **linkopts_switches)
net.addLink(s2, s3, **linkopts_switches)

info('*** Adding hosts...\n')
#hosts.append(net.addHost('h1', ip="10.0.1.1", mac="00:00:00:00:00:01" )) # Server1
hosts.append(
    net.addDocker('h1',
                  ip="10.0.1.1",
                  mac="00:00:00:00:00:01",
                  dimage="phfaustini/server:latest"))
hosts.append(net.addHost('h2', ip="10.0.2.2",
                         mac="00:00:00:00:00:02"))  # Client Legit
hosts.append(net.addHost('h3', ip="10.0.2.3",
                         mac="00:00:00:00:00:03"))  # Client Legit
hosts.append(net.addHost('h4', ip="10.0.2.4",
                         mac="00:00:00:00:00:04"))  # Client Malicious
#hosts.append(net.addHost('h5', ip="10.0.1.5", mac="00:00:00:00:00:05" )) # Server2
hosts.append(
    net.addDocker('h5',
                  ip="10.0.1.5",
                  mac="00:00:00:00:00:05",
                  dimage="phfaustini/server:latest"))
net.addLink(hosts[0], s1, **linkopts_hosts)
net.addLink(hosts[1], s2, **linkopts_hosts)
net.addLink(hosts[2], s2, **linkopts_hosts)
net.addLink(hosts[3], s2, **linkopts_hosts)
net.addLink(hosts[4], s1, **linkopts_hosts)
Exemple #31
0
def myNetwork():
    net = Containernet(controller=Controller)

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

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

    info('*** Add hosts\n')
    # attacker 2 docker containers
    mn_args = {
        "network_mode": "none",
        "dimage": "exam_docker",
        "dcmd": "./start_app.sh",
        "ip": "192.168.16.2/24",
    }
    H1 = net.addDocker('h1', **mn_args)
    mn_args = {
        "network_mode": "none",
        "dimage": "exam_docker",
        "dcmd": "./start_app.sh",
        "ip": "192.168.16.3/24",
    }
    H2 = net.addDocker('h2', **mn_args)
    mn_args = {
        "network_mode": "none",
        "dimage": "lab07/snort",
        "dcmd": None,
        "ip": "192.168.16.100/24",
    }
    H3 = net.addDocker('IDS', **mn_args)

    info('*** Add links\n')
    net.addLink(H1, s1)
    net.addLink(H2, s1)
    net.addLink(H3, s1)

    info('*** Add Internet access\n')
    mn_args = {
        "ip": "192.168.16.1/24",
    }
    nat = net.addHost('nat0',
                      cls=NAT,
                      inNamespace=False,
                      subnet='192.168.16.0/24',
                      **mn_args)
    # Connect the nat to the switch
    net.addLink(nat, s1)

    info('*** Starting network\n')
    net.start()
    H1.cmd('ip r a default via 192.168.16.1')
    H2.cmd('ip r a default via 192.168.16.1')

    # port mirroring all from s1 to IDS
    cmd = '''ovs-vsctl del-port s1-eth3'''
    results = subprocess.run(cmd,
                             shell=True,
                             universal_newlines=True,
                             check=True).stdout
    print(results)

    cmd = '''ovs-vsctl add-port s1 s1-eth3 -- --id=@p get port s1-eth3 -- --id=@m create mirror name=m0 select-all=true output-port=@p -- set bridge s1 mirrors=@m'''
    results = subprocess.run(cmd,
                             shell=True,
                             universal_newlines=True,
                             check=True).stdout

    CLI(net)
    net.stop()
def emulate():

    "Create a network with some docker containers acting as hosts."

    net = Containernet(controller=Controller)

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

    info('*** Adding hosts\n')
    h1 = net.addHost('h1')
    h2 = net.addHost('h2')

    info('*** Adding docker containers\n')
    d1 = net.addDocker('d1', ip='10.0.0.251', dimage="ubuntu:trusty")
    
    # A container with more specific params: cpu period and cpu quota
    d2 = net.addDocker('d2', ip='10.0.0.252', dimage="ubuntu:trusty", cpu_period=50000, cpu_quota=25000)

    # Add a container as a host, using Docker class option.
    d3 = net.addHost('d3', ip='11.0.0.253', cls=Docker, dimage="ubuntu:trusty", cpu_shares=20)

    # Add a container with a specific volume.
    d5 = net.addDocker('d5', dimage="ubuntu:trusty", volumes=["/:/mnt/vol1:rw"])

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

    info('*** Creating links\n')
    net.addLink(h1, s1)
    net.addLink(s1, d1)
    net.addLink(h2, s2)
    net.addLink(d2, s2)
    net.addLink(s1, s2)

    # try to add a second interface to a docker container
    net.addLink(d2, s3, params1={"ip": "11.0.0.254/8"})
    net.addLink(d3, s3)

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

    # The typical ping example, with two docker instances in place of hosts.
    net.ping([d1, d2])

    # our extended ping functionality
    net.ping([d1], manualdestip="10.0.0.252")
    net.ping([d2, d3], manualdestip="11.0.0.254")

    info('*** Dynamically add a container at runtime\n')
    d4 = net.addDocker('d4', dimage="ubuntu:trusty")

    # we have to specify a manual ip when we add a link at runtime
    net.addLink(d4, s1, params1={"ip": "10.0.0.254/8"})

    # Ping docker instance d1.
    net.ping([d1], manualdestip="10.0.0.254")

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

    info('*** Stopping network')
    net.stop()
Exemple #33
0
                      ip=CONTROLLER_IP,
                      port=CONTROLLER_PORT)

    try:
        # ----------switches and hosts -----------------------------
        switches = {}
        links = {}
        for sw_ind in switch_names:
            name = switch_names[sw_ind]
            dpid = DPID_BASE + sw_ind

            params = {'other_config': {'stp-priority': sw_ind}}
            sw = net.addSwitch(name, dpid="%x" % dpid, cls=OpenFlow14Switch)
            switches[sw_ind] = sw
            for host_index in range(1, host_count_per_switch + 1):
                host = net.addHost(name + '%02d' % host_index)
                net.addLink(sw, host)

        # ---------- create links -----------------------------
        for item in switch_link_matrix:
            sw1 = switches[item[0]]
            sw2 = switches[item[1]]
            link = net.addLink(sw1, sw2)
            links[item] = link
            if item in no_flood_links:
                sw1_port = sw1.ports[link.intf1]
                sw1.dpctl("mod-port", sw1_port, "no-flood")
                sw2_port = sw2.ports[link.intf2]
                sw2.dpctl("mod-port", sw2_port, "no-flood")

        # ----------switches-----------------------------
from mininet.net import Containernet
from mininet.node import Controller
from mininet.cli import CLI
from mininet.link import TCLink
from mininet.log import info, setLogLevel
setLogLevel('info')

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

info('*** Adding Docker containers - Routers\n')
r1 = net.addDocker('r1', ip='20.0.0.1', dimage="ubuntu:trusty")

info('*** Adding Mininet containers - Hosts\n')
h1 = net.addHost('h1', ip='20.0.0.2/30')
h2 = net.addHost('h2', ip='50.0.0.2/30')

#info('*** Adding Mininet containers - Router\n')
#r1 = net.addHost('r1', ip='20.0.0.1/30')

info('*** Creating links\n')
#net.addLink(g1, h1, cls=TCLink, delay='100ms', bw=1)
net.addLink(h1, r1, cls=TCLink, bw=10)
net.addLink(h2, r1, cls=TCLink, bw=10)

info('*** Setting IP addresses\n')
r1.setIP('50.0.0.1/30', intf="r1-eth1")

info('*** Starting network\n')
net.start()
Exemple #35
0
def tfTopo():
 net = Containernet( topo=None, controller=RemoteController, switch=OVSKernelSwitch )

 net.addController( 'c0', RemoteController, ip="127.0.0.1", port=6633 )

 # Hosts 
 h1 = net.addHost('h1', ip='10.0.0.1', mac='00:00:00:00:00:01')
 h2 = net.addHost('h2', ip='10.0.0.2', mac='00:00:00:00:00:02')
 h3 = net.addHost('h3', ip='10.0.0.3', mac='00:00:00:00:00:03', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10, cpu_shares=2)
 h4 = net.addHost('h4', ip='10.0.0.4', mac='00:00:00:00:00:04', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10, cpu_shares=10)
 h5 = net.addHost('h5', ip='10.0.0.5', mac='00:00:00:00:00:05', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10, cpu_shares=10)
 h6 = net.addHost('h6', ip='10.0.0.6', mac='00:00:00:00:00:06')
 h7 = net.addHost('h7', ip='10.0.0.7', mac='00:00:00:00:00:07')
 h8 = net.addHost('h8', ip='10.0.0.8', mac='00:00:00:00:00:08')
 h9 = net.addHost('h9', ip='10.0.0.9', mac='00:00:00:00:00:09')

 #Switches
 s1 = net.addSwitch('s1')
 s2 = net.addSwitch('s2')
 s3 = net.addSwitch('s3')
 s4 = net.addSwitch('s4')
 s5 = net.addSwitch('s5')
 s6 = net.addSwitch('s6')
 s7 = net.addSwitch('s7')
 s8 = net.addSwitch('s8')
 s9 = net.addSwitch('s9')

 net.addLink(h3,s3)
 net.addLink(h3,s3)

 net.addLink(h4,s4)
 net.addLink(h4,s4)

 net.addLink(h5,s5)
 net.addLink(h5,s5)

 net.addLink(s1,s6)
 net.addLink(s1,s7)

 #net.addLink(s6, s3, cls=TCLink, delay="100ms", bw=0.5, loss=0)
 net.addLink(s6,s3)
 net.addLink(s6, s4, cls=TCLink, delay="1ms", bw=2, loss=0)
 #net.addLink(s6,s4)
 net.addLink(s6,s5)
 net.addLink(s7,s3)
 net.addLink(s7,s5)
 
 net.addLink(s3,s8)
 net.addLink(s3,s9)
 net.addLink(s4,s8, cls=TCLink, delay="1ms", bw=2, loss=0)
 net.addLink(s4,s9)
 net.addLink(s5,s9)
 
 net.addLink(s8,s2)
 net.addLink(s9,s2)
 
 net.addLink(h1,s1)
 net.addLink(h2,s2)
 net.addLink(h6,s6)
 net.addLink(h7,s7)
 net.addLink(h8,s8)
 net.addLink(h9,s9)
 


 net.start()

 for host in net.hosts:
     if "h" in host.name:
         host.cmd('ethtool -K %s-eth0 tso off' % host.name)
 call("sudo bash Click/runFirewall.sh h3 Click/firewall3.click ",shell=True)
 call("sudo bash Click/runFirewall.sh h4 Click/firewall3.click ",shell=True)
 call("sudo bash Click/runFirewall.sh h5 Click/firewall3.click ",shell=True)
 
 h2.cmd('python -m SimpleHTTPServer 80 &')

 CLI(net)
 net.stop()