Exemple #1
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 #2
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 #3
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 docker containers\n')
    
    # Containers de imagenes con herramientas de red 
    A = net.addDocker('A', ip='10.0.0.100', dimage="openswitch/ubuntuscapy", volumes=["/home/tigarto/Documents/test_diarios_tesis/abril17/test1/trazas:/mnt/trazas:rw"])
    V = net.addDocker('V', ip='10.0.0.101', dimage="openswitch/ubuntuscapy") 


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

    info('*** Creating links\n')
    net.addLink(A, s1)
    net.addLink(s1, V)
    

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

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

    info('*** Stopping network')
    net.stop()
Exemple #4
0
def topology():
    "Create a network with some docker containers acting as hosts."
    edgefile = os.path.join(RESULTS_FOLDER, "./substrate.edges.empty.data")
    nodesfile = os.path.join(RESULTS_FOLDER, "./substrate.nodes.data")
    CDNfile = os.path.join(RESULTS_FOLDER, "CDN.nodes.data")
    startersFile = os.path.join(RESULTS_FOLDER, "starters.nodes.data")
    solutionsFile = os.path.join(RESULTS_FOLDER, "solutions.data")
    service_edges = os.path.join(RESULTS_FOLDER, "./service.edges.data")
    switch = partial(OVSSwitch, protocols='OpenFlow13')

    topo = loadTopo(edgefile, nodesfile, CDNfile, startersFile, solutionsFile,
                    service_edges)

    c = RemoteController('c', '0.0.0.0', 6633)
    # topodock=  loaddocker(os.path.join(RESULTS_FOLDER, "./substrate.edges.data"), os.path.join(RESULTS_FOLDER, "./substrate.nodes.data"))
    info('*** Start Containernet\n')
    net = Containernet(topo=topo, controller=c, link=TCLink, switch=switch)
    for host in net.hosts:
        if host.name in topo._cmd:
            for cmd in topo._cmd[host.name]:
                print("send cmd")
                print((host.sendCmd(cmd)))

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

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

    info('*** Stopping network')
    net.stop()
Exemple #5
0
def networkTest():
    "Create a network with some docker containers acting as hosts."
    info('*** Create the controller \n')
    c0 = POXBridge()
    net = Containernet(build=False)
    info('*** Creating the network\n')
    # Containers de imagenes con herramientas de red
    h1 = net.addDocker('h1', ip='10.0.0.100', dimage="ubuntu_net_tools")
    h2 = net.addDocker('h2', ip='10.0.0.101', dimage="ubuntu_net_tools")
    h3 = net.addDocker('h3', ip='10.0.0.102', dimage="ubuntu_net_tools")

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

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

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

    info('*** Build the network\n')
    net.build()

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

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

    info('*** Stopping network')
    net.stop()
Exemple #6
0
    def start(self):
        # deal with kind
        # Now by default it's kind node, can integrate other kind of node.
        if len(self.kubeCluster) > 0:
            self.boostKubeCluster()

        for k in self.kubeCluster:
            self.kubeCluster[k].init()
            # TODO:allowing to add sth other than kind?
            # TODO: make sure the container ID and process ID is get

        for l in self.linksNotProcessed:
            Containernet.addLink(self,
                                 l[0],
                                 l[1],
                                 port1=l[2],
                                 port2=l[3],
                                 cls=l[4],
                                 **l[5])

        Containernet.start(self)

        for k in self.kubeCluster:
            self.kubeCluster[k].bringIntfUp()
            self.kubeCluster[k].setupKube()
Exemple #7
0
def createTopo(g=4,
               a=None,
               p=1,
               h=1,
               bw_sw_h=10,
               bw_inn_sw=30,
               bw_int_sw=10,
               ip="127.0.0.1",
               port=6633):
    if a is None: a = g - 1  # Canonical Topo
    logging.debug("LV1 Create DragonFly")
    topo = DragonFly(g, a, p, h)
    topo.createTopo(bw_sw_h=bw_sw_h, bw_inn_sw=bw_inn_sw, bw_int_sw=bw_int_sw)

    logging.debug("LV1 Start Mininet")
    CONTROLLER_IP = ip
    CONTROLLER_PORT = port
    net = Containernet(topo=topo,
                       link=TCLink,
                       controller=None,
                       autoSetMacs=True,
                       autoStaticArp=True)
    net.addController('controller',
                      controller=RemoteController,
                      ip=CONTROLLER_IP,
                      port=CONTROLLER_PORT)
    net.start()

    dump_etc_hosts(net)
    dump_mpi_hosts_file(net)
    run_set_ssh(net)

    CLI(net)
    net.stop()
Exemple #8
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 #9
0
def topology():
    "Create a network with some docker containers acting as hosts."
    edgefile = os.path.join(RESULTS_FOLDER, "./substrate.edges.empty.data")
    nodesfile = os.path.join(RESULTS_FOLDER, "./substrate.nodes.data")
    CDNfile = os.path.join(RESULTS_FOLDER, "CDN.nodes.data")
    startersFile = os.path.join(RESULTS_FOLDER, "starters.nodes.data")
    solutionsFile = os.path.join(RESULTS_FOLDER, "solutions.data")
    service_edges = os.path.join(RESULTS_FOLDER, "./service.edges.data")
    switch = partial( OVSSwitch, protocols='OpenFlow13')

    topo = loadTopo(edgefile, nodesfile, CDNfile, startersFile, solutionsFile,service_edges)

    c = RemoteController('c', '0.0.0.0', 6633)
    # topodock=  loaddocker(os.path.join(RESULTS_FOLDER, "./substrate.edges.data"), os.path.join(RESULTS_FOLDER, "./substrate.nodes.data"))
    info('*** Start Containernet\n')
    net = Containernet(topo=topo, controller=c, link=TCLink,switch=switch)
    for host in net.hosts:
        if host.name in topo._cmd:
            for cmd in topo._cmd[host.name]:
                print("send cmd")
                print((host.sendCmd(cmd)))



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

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

    info('*** Stopping network')
    net.stop()
Exemple #10
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 #11
0
    def run(self, sim_args, curtime, entrypoint):
        if any(v not in environ for v in ['CLIENT', 'CLIENT_PARAMS', 'SERVER', 'SERVER', 'CLIENT_LOGS', 'SERVER_LOGS', 'CL_COMMIT', 'SV_COMMIT']):
            # TODO show help
            exit(1)
        client_image = environ['CLIENT']
        client_params = environ['CLIENT_PARAMS']
        server_image = environ['SERVER']
        server_params = environ['SERVER_PARAMS']
        cl_logdir = environ['CLIENT_LOGS']
        sv_logdir = environ['SERVER_LOGS']
        clcommit = environ['CL_COMMIT']
        svcommit = environ['SV_COMMIT']

        setLogLevel('info')

        net = Containernet(controller=Controller)
        info('*** Adding controller\n')
        net.addController('c0')
        info('*** Adding docker containers\n')
        server_vs = [sv_logdir + ':/logs']
        # add kernel debug volume to allow eBPF code to run
        if sim_args.k:
            server_vs.append( '/sys/kernel/debug:/sys/kernel/debug:ro')
        server = net.addDocker('server', ip='10.0.0.251',
                               environment={"ROLE": "server", "SERVER_PARAMS": server_params, "COMMIT": svcommit},
                               dimage=server_image + ":latest",
                               volumes=server_vs)
        client = net.addDocker('client', ip='10.0.0.252', 
                               environment={"ROLE": "client", "CLIENT_PARAMS": client_params, "COMMIT": clcommit},
                               dimage=client_image + ":latest", 
                               volumes=[cl_logdir + ':/logs'])

        info('*** Adding switches\n')
        s1 = net.addSwitch('s1')
        s2 = net.addSwitch('s2')
        info('*** Creating links\n')
        net.addLink(s1, s2, cls=TCLink, delay=sim_args.delay, bw=sim_args.bandwidth, max_queue_size=sim_args.queue)
        net.addLink(s1, client)
        net.addLink(s2, server)
        info('\n*** Updating and building client/server\n')
        server.cmd('./updateAndBuild.sh')
        client.cmd('./updateAndBuild.sh')
        info('*** Starting network\n')
        net.start()
        capture = PacketCapture()
        if sim_args.k:
            client.cmd(entrypoint + " &")
        else:
            server.cmd(entrypoint + " &" )
        capture.startCapture()
        info('\n' + entrypoint + '\n')
        if sim_args.k:
            info(server.cmd(entrypoint) + "\n")
        else:
            info(client.cmd(entrypoint) + "\n")
        # Wait some time to allow server finish writing to log file
        sleep(3)
        capture.stopCapture()
        info('*** Stopping network')
        net.stop()
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 #13
0
def main():
    setLogLevel('info')

    topo = EvalTetraTopo()

    net = Containernet(controller=RemoteController,
                       topo=topo,
                       build=False,
                       autoSetMacs=True,
                       link=TCLink)
    net.start()

    print()

    print("**Wiping log dir.")
    for root, dirs, files in os.walk(LoggingReceiveAction.LOG_DIR):
        for file in files:
            os.remove(os.path.join(root, file))

    print("**Starting containernet REST Server.")
    thr = threading.Thread(target=start_rest,
                           args=(net, ))  # comma behind net is on purpose
    thr.daemon = True
    thr.start()

    # wait for connection with controller
    time.sleep(3)

    hosts = net.hosts

    # send arp from reqHost to every other host -> required by ONOS HostService to resolve hosts (i.e. map MAC<->IP)
    reqHost = hosts[0]
    for host in hosts:
        if (host is not reqHost):
            startARP(reqHost, reqHost.IP(), reqHost.MAC(), host.IP(),
                     reqHost.intf())

    CLI(net)

    ## set up UDP servers to join group
    for host in hosts:
        if host.name in ['tbs10host', 'tbs11host', 'tbs4host', 'tbs21host']:
            startUDPServer(host, GROUP_IP, host.IP())

    CLI(net)

    ## send data
    startUDPClient(net.getNodeByName('tbs17host'),
                   GROUP_IP,
                   UDP_MESSAGE_SIZE_BYTES,
                   count=PACKET_COUNT,
                   rate=PACKETS_PER_SECOND)

    CLI(net)

    net.stop()
Exemple #14
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 #15
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()
def simpleTest():
    info('*** Starting network\n')
    topo = TestingTopo()
    c1 = RemoteController('c1', ip='127.0.0.1')
    net = Containernet(topo=topo, link=link, controller=c1)  #
    d1 = net.addDocker('d1',
                       dimage="tests",
                       volumes=["/home/osboxes/Documents/tests/:/mnt/vol1:rw"])
    net.addLink(d1, net.get('s1'))
    s1 = net.get('s1')
    net.start()

    # Connect switch to Internet NAT
    s1.cmdPrint('ovs-vsctl add-port s1 enp0s3')

    # Setup mirrored port interface
    s1.cmdPrint('ovs-vsctl add-port s1 snort0')
    s1.cmdPrint('ovs-vsctl set interface snort0 type=internal')
    s1.cmdPrint('sudo ip link set snort0 up')
    s1.cmdPrint('ovs-vsctl show')

    # Disable docker NAT connection
    d1.cmdPrint('ifconfig eth0 down')

    # Reset and connect d1 to internet through s1
    d1.cmdPrint('ifconfig d1-eth0 0')
    d1.cmdPrint('dhclient d1-eth0')
    # Confirm d1 is connected to internet
    d1.cmdPrint('ping -c 2 google.com')
    info('*** Running CLI\n')
    CLI(net)
    # Quit CLI to start packet capture
    tcpdump = 'sudo timeout 930 tcpdump -i snort0 -w /home/osboxes/Documents/tests/pcaps/vulahometrain1.pcap'
    process = subprocess.Popen(tcpdump.split())
    # Start selenium powered application test (simulate website interaction)
    d1.cmdPrint('python /mnt/vol1/WebTrafficSDN/vulatest.py')
    #CLI(net)
    tcpdump = 'sudo timeout 930 tcpdump -i snort0 -w /home/osboxes/Documents/tests/pcaps/youtubehometrain1.pcap'
    process = subprocess.Popen(tcpdump.split())
    d1.cmdPrint('python /mnt/vol1/WebTrafficSDN/youtubetest.py')
    #CLI(net)
    tcpdump = 'sudo timeout 930 tcpdump -i snort0 -w /home/osboxes/Documents/tests/pcaps/outlookhometrain1.pcap'
    process = subprocess.Popen(tcpdump.split())
    d1.cmdPrint('python /mnt/vol1/WebTrafficSDN/outlooktest.py')

    info('*** Stopping network')
    net.stop()
Exemple #17
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 #18
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()
def setup(service, n=3):
    n = int(n)
    # - Core setup -------

    net = Containernet(controller=Controller, switch=OVSSwitch)
    info("*** Adding controller\n")
    net.addController("c0")

    info("*** Adding switches\n")
    s1 = net.addSwitch("s1")

    info("*** Adding docker containers and adding links\n")
    cluster_ips = [ip_from_int(i + 2) for i in range(n)]
    dimage = "cjj39_dks28/" + service
    print("*** Using image: " + dimage)
    dockers = [
        net.addDocker("d" + str(i + 1), ip=cluster_ips[i], dimage=dimage)
        for i in range(n)
    ]

    for d in dockers:
        net.addLink(d, s1, cls=TCLink, delay="50ms", bw=1, max_queue_size=200)

    microclient = addClient(net, service, "mc", ip="10.0.0.1")

    net.addLink(microclient, s1)

    net.start()

    system_setup_func = (
        importlib.import_module("systems.{0}.scripts.setup".format(service))
    ).setup

    restarters = system_setup_func(dockers, cluster_ips)
    # TODO add mininet restart stuff here
    restarters = [
        lambda: [restart_host(docker), restart][-1]
        for restert, docker in zip(restarters, dockers)
    ]

    return (net, cluster_ips, [microclient], restarters)
Exemple #20
0
def main():
    info('Starting network...\n')
    net = Containernet(controller=Controller)
    controller = net.addController('c0')
    middlebox = net.addDocker('d1', ip='10.0.0.251', dimage="middlebox:latest")
    tester = net.addDocker('d2', ip='10.0.0.252', dimage="tester:latest")

    def cmd(c):
        info('Running command %s on all hosts...\n' % c)
        middlebox.cmd(c)
        tester.cmd(c)

    info('Adding links...\n')
    switch = net.addSwitch('s1')
    net.addLink(middlebox, switch, cls=TCLink, delay='0ms', bw=1000)
    net.addLink(tester, switch, cls=TCLink, delay='0ms', bw=1000)
    net.addLink(middlebox, tester, cls=TCLink, delay='1ms', bw=1000)
    middlebox.setMAC('00:00:00:00:00:fb', 'd1-eth1')
    tester.setMAC('00:00:00:00:00:fc', 'd2-eth1')
    net.start()
    info('Network started.\n')

    # info('Pinging all hosts...\n')
    # net.ping([middlebox, tester])

    info('Running the experiment...\n')
    nf = 'dpdk-nat-basichash'
    scenario = 'latency'    # either 'thru-1p' or 'latency'
    pcap_file = '1packet.pcap'
    result_file = 'bench-%s-%s-%s.results' % (nf, scenario, pcap_file)

    middlebox.cmd('mkdir /mnt/huge')
    middlebox.cmd('mount -t hugetlbfs nodev /mnt/huge')
    # middlebox.cmd('/bin/bash ~/castan/scripts/perf/start-middlebox.sh %s' % nf)
    # middlebox.cmd('/bin/bash ~/castan/scripts/perf/run.sh %s %s %s %s' % (nf, scenario, result_file, pcap_file))

    info('Starting CLI...\n')
    CLI(net)

    info('Stopping network...\n')
    net.stop()
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 docker containers\n')
    d1 = net.addDocker('d1', ip='10.0.0.251', dimage="mpeuster/stress", cpuset_cpus="0,1")
    d1.sendCmd("./start.sh")

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

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

    info('*** Stopping network')
    net.stop()
Exemple #22
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 docker containers\n')
    d1 = net.addDocker('d1', ip='10.0.0.251', dimage="mpeuster/stress", cpuset="0,1")
    d1.sendCmd("./start.sh")

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

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

    info('*** Stopping network')
    net.stop()
Exemple #23
0
def topology():
    "Create a network with some docker containers acting as hosts."
    global net
    net = Containernet()

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

    info('*** Starting network\n')
    net.start()
    # server ip
    run(host='localhost', port=8090)
    # info('*** Running CLI\n')
    # CLI(net)

    info('*** Stopping network')
    net.stop()
Exemple #24
0
def main():
    os.system("rm -f /tmp/R*.log /tmp/R*.pid logs/*")
    os.system("mn -c >/dev/null 2>&1")
    os.system("killall -9 zebra bgpd > /dev/null 2>&1")

    net = Containernet(topo=SimpleTopo(), switch=Router)
    net.start()
    for router in net.switches:
        router.cmd("sysctl -w net.ipv4.ip_forward=1")
        router.waitOutput()

    log("Waiting %d seconds for sysctl changes to take effect..." % args.sleep)
    sleep(args.sleep)

    for router in net.switches:
        router.cmd(
            "/usr/sbin/zebra -f conf/zebra-%s.conf -d -i /tmp/zebra-%s.pid > logs/%s-zebra-stdout 2>&1"
            % (router.name, router.name, router.name))
        router.waitOutput()
        router.cmd(
            "/usr/sbin/bgpd -f conf/bgpd-%s.conf -d -i /tmp/bgp-%s.pid > logs/%s-bgpd-stdout 2>&1"
            % (router.name, router.name, router.name),
            shell=True)
        router.waitOutput()
        log("Starting zebra and bgpd on %s" % router.name)
        if router.name == "R1":
            r1 = router
        if router.name == "R2":
            r2 = router

    info('*** Adding docker containers\n')
    d1 = net.addDocker('d1', path="./Dockerfile.webserver", rm=True)
    d2 = net.addDocker('d2', path="./Dockerfile.webserver", rm=True)

    net.addLink(d1, r1)
    net.addLink(d2, r2)

    CLI(net)
    net.stop()
    os.system("killall -9 zebra bgpd")
Exemple #25
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 #26
0
def createTopo(pod, density, ip="127.0.0.1", port=6633, bw_c2a=0.8, bw_a2e=0.4, bw_h2a=0.2):
    logging.debug("LV1 Create Fattree")
    topo = Fattree(pod, density)
    topo.createTopo()
    topo.createLink(bw_c2a=bw_c2a, bw_a2e=bw_a2e, bw_h2a=bw_h2a)

    logging.debug("LV1 Start Mininet")
    CONTROLLER_IP = ip
    CONTROLLER_PORT = port
    net = Containernet(topo=topo, link=TCLink, controller=None, autoSetMacs=True,
                  autoStaticArp=True)
    net.addController(
        'controller', controller=RemoteController,
        ip=CONTROLLER_IP, port=CONTROLLER_PORT)
    net.start()

    dump_etc_hosts(net)
    dump_mpi_hosts_file(net)
    run_set_ssh(net)

    CLI(net)
    net.stop()
Exemple #27
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 docker containers\n')
    '''
    Containers de imagenes sin herramientas de red
    h1 = net.addDocker('h1', ip='10.0.0.100', dimage="ubuntu:latest")
    h2 = net.addDocker('h2', ip='10.0.0.101', dimage="ubuntu:latest") 
    h3 = net.addDocker('h3', ip='10.0.0.102', dimage="ubuntu:latest")  
    '''
    # Containers de imagenes con herramientas de red
    h1 = net.addDocker('h1', ip='10.0.0.100', dimage="ubuntu_net_tools")
    h2 = net.addDocker('h2', ip='10.0.0.101', dimage="ubuntu_net_tools")
    h3 = net.addDocker('h3', ip='10.0.0.102', dimage="ubuntu_net_tools")

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

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

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

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

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

    info('*** Stopping network')
    net.stop()
Exemple #28
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 #29
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()
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 #31
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"})
Exemple #33
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()
Exemple #34
0
 def start(self):
     # start
     for dc in self.dcs.itervalues():
         dc.start()
     Containernet.start(self)
"""
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\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 switches\n')
s1 = net.addSwitch('s1')
s2 = net.addSwitch('s2')
info('*** Creating links\n')
net.addLink(d1, s1)
net.addLink(s1, s2, cls=TCLink, delay='100ms', bw=1)
net.addLink(s2, d2)
info('*** Starting network\n')
net.start()
info('*** Testing connectivity\n')
net.ping([d1, d2])
info('*** Running CLI\n')
CLI(net)
info('*** Stopping network')
net.stop()

Exemple #36
0
 def start(self):
     # start
     for dc in self.dcs.itervalues():
         dc.start()
     Containernet.start(self)
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 #38
0
                if options.get("multi", False):
                    for i in range(multi_count):
                        host_name_i = host_name + "-" + str(i + 1)
                        host = net[host_name_i]
                        host.cmd("/usr/sbin/sshd -D -o UseDNS=no -u0 &")
                        debug("Starting SSHD on host")
                        waitListening(client=host,
                                      server=host,
                                      port=22,
                                      timeout=5)
                else:
                    host = net[host_name]
                    host.cmd("/usr/sbin/sshd -D -o UseDNS=no -u0 &")
                    debug("Starting SSHD on host")
                    waitListening(client=host, server=host, port=22, timeout=5)


if __name__ == '__main__':
    # Tell mininet to print useful information
    setLogLevel('info')
    topo = CDCITopology()
    net = Containernet(controller=Controller)
    topo.configure_network(net, "lab03", 1)
    net.start()
    topo.start_sshd(net, "lab03", 1)
    topo.configure_routes(net)
    print("Host connections:")
    #dumpNodeConnections(net.hosts)
    CLI(net)
    net.stop()
Exemple #39
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()