Exemplo n.º 1
0
        docker_args={
            "hostname": "h3",
            "pid_mode": "host"
        },
    )

    info("*** Adding switch and links\n")
    s1 = net.addSwitch("s1")
    net.addLinkNamedIfce(s1, h1, bw=1000, delay="5ms")
    # Add the interfaces for service traffic.
    net.addLinkNamedIfce(s1, h2, bw=1000, delay="5ms")
    net.addLinkNamedIfce(s1, h3, bw=1000, delay="5ms")
    # Add the interface for host internal traffic.
    net.addLink(s1,
                h2,
                bw=1000,
                delay="1ms",
                intfName1="s1-h2-int",
                intfName2="h2-s1-int")
    net.addLink(s1,
                h3,
                bw=1000,
                delay="1ms",
                intfName1="s1-h3-int",
                intfName2="h3-s1-int")

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

    s1_h1_port_num = get_ofport("s1-h1")
    s1_h2_port_num = get_ofport("s1-h2")
    s1_h3_port_num = get_ofport("s1-h3")
Exemplo n.º 2
0
        docker_args={"hostname": "h1"},
    )
    h2 = net.addDockerHost(
        "h2",
        dimage="network_measurement",
        ip="10.0.0.2",
        docker_args={
            "hostname": "h2",
            "volumes": {f"{cwd}": {"bind": "/flent_data", "mode": "rw"}},
        },
    )

    info("*** Adding switch and links\n")
    switch1 = net.addSwitch("s1")
    switch2 = net.addSwitch("s2")
    net.addLink(switch1, h1, bw=10, delay="10ms")
    net.addLink(switch1, switch2, bw=10, delay="10ms")
    net.addLink(switch2, h2, bw=10, delay="10ms")

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

    info("*** Run ping and UDP latency measurement with single flow.\n")
    srv1_1 = mgr.addContainer(
        "srv1_1", "h1", "network_measurement", "sockperf server", docker_args={}
    )
    ret = h2.cmd("ping -c 10 -i 0.01 10.0.0.1")
    print(f"- Result of ping: \n{ret}")

    ret = h2.cmd("sockperf under-load -i 10.0.0.1 -t 3 --reply-every 1")
    print(f"- Result of Sockperf: \n{ret}")
Exemplo n.º 3
0
                           docker_args={"hostname": "server"})
    h9 = net.addDockerHost("WC",
                           dimage="dev_test",
                           ip="10.0.0.9",
                           mac="00:00:00:00:00:09",
                           docker_args={"hostname": "client"})

    print("*** Creating switches")
    switch1 = net.addSwitch("s1")
    switch2 = net.addSwitch("s2")
    switch3 = net.addSwitch("s3")
    switch4 = net.addSwitch("s4")

    print("*** Creating links")
    # From broker to central switch
    net.addLink(switch4, h7, bw=10, delay="10ms")

    # From the central switch to the switches
    net.addLink(switch1, switch4, bw=10, delay="10ms")
    net.addLink(switch2, switch4, bw=10, delay="10ms")
    net.addLink(switch3, switch4, bw=10, delay="10ms")

    # From switch 1 to hosts
    net.addLink(switch1, h8, bw=10, delay="10ms")
    net.addLink(switch1, h9, bw=10, delay="10ms")

    # From switch 2 to drones 1,2,3
    net.addLink(switch2, h1, bw=10, delay="10ms")
    net.addLink(switch2, h2, bw=10, delay="10ms")
    net.addLink(switch2, h3, bw=10, delay="10ms")
Exemplo n.º 4
0
def run_net():

    # To be tested parameters at runtime
    loss_rates = [30]

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

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

    info("*** Adding hosts\n")
    h1 = net.addHost(
        "h1",
        cls=DockerHost,
        dimage="dev_test",
        ip="10.0.0.1/24",
        docker_args={"cpuset_cpus": "0", "nano_cpus": int(1e8)},
    )
    h2 = net.addHost(
        "h2",
        cls=DockerHost,
        dimage="dev_test",
        ip="10.0.0.2/24",
        docker_args={"cpuset_cpus": "0", "nano_cpus": int(1e8)},
    )

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

    info("*** Creating links\n")
    net.addLink(h1, s1, bw=10, delay="100ms", intfName1="h1-s1", intfName2="s1-h1")
    net.addLink(h2, s1, bw=10, delay="100ms", intfName1="h2-s1", intfName2="s1-h2")

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

    info("**** Testing bandwidth between h1 and h2\n")
    net.iperf((h1, h2), l4Type="UDP", udpBw="10M")

    info("*** Configure the link loss rate of h1 at runtime\n")
    for loss in loss_rates:
        print("* The loss rate of h1 is {:.2f}%, unidirectional".format(loss))
        print("* Ping test count: %d" % PING_COUNT)

        host = net.get("h1")
        # INFO: The parent number is defined in mininet/link.py
        ret = host.cmd(
            "tc qdisc change dev {} {} handle 10: netem loss {}%".format(
                "h1-s1", " parent 5:1", loss
            )
        )
        if ret != "":
            print("Failed to change loss. Error:%s\n", ret)

        ret = h1.cmd("ping -c %d 10.0.0.2" % PING_COUNT)
        sent, received = tool.parsePing(ret)
        measured = ((sent - received) / float(sent)) * 100.0
        print(
            "Expected loss rate: {:.2f}%, measured loss rate: {:.2f}%".format(
                loss, measured
            )
        )

    info("*** Stopping network")
    net.stop()
Exemplo n.º 5
0
def testDockerInDocker(n):

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

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

    info("*** Adding Docker hosts and switches in a chain topology\n")
    last_sw = None
    hosts = list()
    # Connect hosts
    for i in range(n):
        # Unlimited access to CPU(s) cycles in CPU_SETS
        host = net.addDockerHost(
            "h%s" % (i + 1),
            dimage="dev_test",
            ip="10.0.0.%s" % (i + 1),
            docker_args={"cpuset_cpus": "0"},
        )
        hosts.append(host)
        switch = net.addSwitch("s%s" % (i + 1))
        net.addLink(switch, host, bw=10, delay="10ms")
        if last_sw:
            # Connect switches
            net.addLink(switch, last_sw, bw=10, delay="10ms")
        last_sw = switch

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

    info(
        "*** Run a simple ping test between two internal containers deployed on h1 and h%s\n"
        % n)
    head = mgr.addContainer("head",
                            "h1",
                            "dev_test",
                            "/bin/bash",
                            docker_args={})
    tail = mgr.addContainer("tail",
                            "h%s" % n,
                            "dev_test",
                            "ping -c 3 10.0.0.1",
                            docker_args={})

    info("*** Tail start ping head, wait for 5s...")
    time.sleep(5)
    info("\nThe ping result of tail to head: \n")
    print(tail.dins.logs().decode("utf-8"))
    mgr.removeContainer(head.name)
    mgr.removeContainer(tail.name)

    time.sleep(3)

    info("*** Run CPU resource limitation test.")
    info("Update CPU limitation of all Docker hosts (h1-h%s) to %.2f %% \n" %
         (n, 50.0 / n))
    info("Update Memory limitation of all Docker hosts (h1-h%s) to 10MB\n" % n)
    info(
        "Deploy the stress app (100 % CPU and 300M memory) inside all Docker hosts to test the CPU/Memory limitation\n"
    )
    containers = list()
    # Mark: CPU percent = cpu_quota / cpu_period. The default CPU period is
    # 100ms = 100000 us
    for i, h in enumerate(hosts):
        h.dins.update(cpu_quota=int(50000 / n))
        h.dins.update(mem_limit=10 * (1024**2))  # in bytes
        c = mgr.addContainer(
            "stress_app_%s" % (i + 1),
            h.name,
            "dev_test",
            "stress-ng -c 1 -m 1 --vm-bytes 300M",
            docker_args={},
        )
        containers.append(c)

    info("Start monitoring resource usage of internal containers"
         "with default sample count: 3 and sample period: 1 sec\n")
    for c in containers:
        usages = mgr.monResourceStats(c.name)
        if usages:
            print(
                " The average CPU and Memory usage of container:{} is {:.2f}%, {:.2f}MB"
                .format(
                    c.name,
                    (sum(u[0] for u in usages) / len(usages)),
                    (sum(u[1] for u in usages) / len(usages)),
                ))
        else:
            print("[ERROR] Failed to get resource usages from manager")

    for c in containers:
        mgr.removeContainer(c.name)

    info("*** Stopping network\n")
    net.stop()
    mgr.stop()
Exemplo n.º 6
0
def start() -> None:
    net = Containernet(build=False, link=TCLink, xterms=False)
    mgr = VNFManager(net)

    rx_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    rx_socket.bind(("127.0.0.1", 8016))
    cnt: int = 0
    active_container: bool = False
    full_tree: bool = False

    info("\n*** Adding Controller\n")
    controller1: RemoteController = net.addController(
        "controller1", controller=RemoteController, ip="127.0.0.1", port=6633)
    controller1.start()

    info("\n*** Adding Hosts\n")
    client1: DockerHost = net.addDockerHost(
        "client1",
        dimage="mec_test",
        ip="10.0.0.10",
        mac="00:00:00:00:00:01",
        docker_args={"volumes": {
            "/tmp": {
                "bind": "/tmp",
                "mode": "rw"
            }
        }},
    )
    probe1: DockerHost = net.addDockerHost(
        "probe1",
        dimage="mec_test",
        docker_args={},
        ip="10.0.0.40",
        mac="00:00:00:00:01:ff",
    )
    server1: DockerHost = net.addDockerHost(
        "server1",
        dimage="mec_test",
        ip="10.0.0.21",
        mac="00:00:00:00:01:01",
        docker_args={
            "cpuset_cpus": "0",
            "cpu_quota": 25000
        },
    )
    server2: DockerHost = net.addDockerHost(
        "server2",
        dimage="mec_test",
        ip="10.0.0.22",
        mac="00:00:00:00:01:02",
        docker_args={
            "cpuset_cpus": "0",
            "cpu_quota": 25000
        },
    )
    server3: DockerHost = net.addDockerHost(
        "server3",
        dimage="mec_test",
        ip="10.0.0.23",
        mac="00:00:00:00:01:03",
        docker_args={
            "cpuset_cpus": "0",
            "cpu_quota": 25000
        },
    )
    server4: DockerHost = net.addDockerHost(
        "server4",
        dimage="mec_test",
        ip="10.0.0.24",
        mac="00:00:00:00:01:04",
        docker_args={
            "cpuset_cpus": "0",
            "cpu_quota": 25000
        },
    )
    if full_tree:
        server5: DockerHost = net.addDockerHost(
            "server5",
            dimage="mec_test",
            ip="10.0.0.25",
            mac="00:00:00:00:01:05",
            docker_args={
                "cpuset_cpus": "0",
                "cpu_quota": 25000
            },
        )
        server6: DockerHost = net.addDockerHost(
            "server6",
            dimage="mec_test",
            ip="10.0.0.26",
            mac="00:00:00:00:01:06",
            docker_args={
                "cpuset_cpus": "0",
                "cpu_quota": 25000
            },
        )
        server7: DockerHost = net.addDockerHost(
            "server7",
            dimage="mec_test",
            ip="10.0.0.27",
            mac="00:00:00:00:01:07",
            docker_args={
                "cpuset_cpus": "0",
                "cpu_quota": 25000
            },
        )
        server8: DockerHost = net.addDockerHost(
            "server8",
            dimage="mec_test",
            ip="10.0.0.28",
            mac="00:00:00:00:01:08",
            docker_args={
                "cpuset_cpus": "0",
                "cpu_quota": 25000
            },
        )

    info("\n*** Adding Switches\n")
    switch1: OVSSwitch = net.addSwitch("switch1")

    switch11: OVSSwitch = net.addSwitch("switch11")
    switch12: OVSSwitch = net.addSwitch("switch12")

    switch111: OVSSwitch = net.addSwitch("switch111")
    switch112: OVSSwitch = net.addSwitch("switch112")
    switch121: OVSSwitch = net.addSwitch("switch121")
    switch122: OVSSwitch = net.addSwitch("switch122")

    switch1.start([controller1])
    switch1.cmdPrint("ovs-vsctl show")

    switch11.start([controller1])
    switch11.cmdPrint("ovs-vsctl show")
    switch12.start([controller1])
    switch12.cmdPrint("ovs-vsctl show")

    switch111.start([controller1])
    switch111.cmdPrint("ovs-vsctl show")
    switch112.start([controller1])
    switch112.cmdPrint("ovs-vsctl show")
    switch121.start([controller1])
    switch121.cmdPrint("ovs-vsctl show")
    switch122.start([controller1])
    switch122.cmdPrint("ovs-vsctl show")

    info("\n*** Adding Links\n")
    net.addLink(node1=switch1, node2=client1, delay="200ms", use_htb=True)
    net.addLink(node1=switch1, node2=probe1, delay="50ms", use_htb=True)

    net.addLink(node1=switch1, node2=switch11, delay="10ms", use_htb=True)
    if full_tree:
        net.addLink(node1=switch1, node2=switch12, delay="10ms", use_htb=True)

    net.addLink(node1=switch11, node2=switch111, delay="10ms", use_htb=True)
    net.addLink(node1=switch11, node2=switch112, delay="10ms", use_htb=True)
    if full_tree:
        net.addLink(node1=switch12,
                    node2=switch121,
                    delay="10ms",
                    use_htb=True)
        net.addLink(node1=switch12,
                    node2=switch122,
                    delay="10ms",
                    use_htb=True)

    net.addLink(node1=switch111, node2=server1, delay="100ms", use_htb=True)
    net.addLink(node1=switch111, node2=server2, delay="150ms", use_htb=True)
    net.addLink(node1=switch112, node2=server3, delay="200ms", use_htb=True)
    net.addLink(node1=switch112, node2=server4, delay="250ms", use_htb=True)
    if full_tree:
        net.addLink(node1=switch121,
                    node2=server5,
                    delay="300ms",
                    use_htb=True)
        net.addLink(node1=switch121,
                    node2=server6,
                    delay="350ms",
                    use_htb=True)
        net.addLink(node1=switch122,
                    node2=server7,
                    delay="400ms",
                    use_htb=True)
        net.addLink(node1=switch122,
                    node2=server8,
                    delay="450ms",
                    use_htb=True)

    info("\n*** Starting Network\n")
    net.build()
    net.start()
    net.pingAll()  # optional

    info("\n*** Adding Docker Containers\n")
    client1_container: APPContainer = mgr.addContainer(
        name="client1_container",
        dhost="client1",
        dimage="mec_test",
        docker_args={},
        dcmd="python3.6 /tmp/client.py",
    )
    probe1_container: APPContainer = mgr.addContainer(
        name="probe1_container",
        dhost="probe1",
        dimage="mec_test",
        docker_args={},
        dcmd="python3.6 /tmp/probe_agent.py",
    )

    probing_server1_container: APPContainer = mgr.addContainer(
        name="probing_server1_container",
        dhost="server1",
        dimage="mec_test",
        docker_args={},
        dcmd="python3.6 /tmp/probe_server.py",
    )
    probing_server2_container: APPContainer = mgr.addContainer(
        name="probing_server2_container",
        dhost="server2",
        dimage="mec_test",
        docker_args={},
        dcmd="python3.6 /tmp/probe_server.py",
    )
    probing_server3_container: APPContainer = mgr.addContainer(
        name="probing_server3_container",
        dhost="server3",
        dimage="mec_test",
        docker_args={},
        dcmd="python3.6 /tmp/probe_server.py",
    )
    probing_server4_container: APPContainer = mgr.addContainer(
        name="probing_server4_container",
        dhost="server4",
        dimage="mec_test",
        docker_args={},
        dcmd="python3.6 /tmp/probe_server.py",
    )
    if full_tree:
        probing_server5_container: APPContainer = mgr.addContainer(
            name="probing_server5_container",
            dhost="server5",
            dimage="mec_test",
            docker_args={},
            dcmd="python3.6 /tmp/probe_server.py",
        )
        probing_server6_container: APPContainer = mgr.addContainer(
            name="probing_server6_container",
            dhost="server6",
            dimage="mec_test",
            docker_args={},
            dcmd="python3.6 /tmp/probe_server.py",
        )
        probing_server7_container: APPContainer = mgr.addContainer(
            name="probing_server7_container",
            dhost="server7",
            dimage="mec_test",
            docker_args={},
            dcmd="python3.6 /tmp/probe_server.py",
        )
        probing_server8_container: APPContainer = mgr.addContainer(
            name="probing_server8_container",
            dhost="server8",
            dimage="mec_test",
            docker_args={},
            dcmd="python3.6 /tmp/probe_server.py",
        )

    time.sleep(5)

    print(
        f"client 1 : \n{client1_container.dins.logs().decode('utf-8')}\n"
        f"probe 1 : \n{probe1_container.dins.logs().decode('utf-8')}\n"
        f"probing server 1 : \n{probing_server1_container.dins.logs().decode('utf-8')}\n"
        f"probing server 2 : \n{probing_server2_container.dins.logs().decode('utf-8')}\n"
        f"probing server 3 : \n{probing_server3_container.dins.logs().decode('utf-8')}\n"
        f"probing server 4 : \n{probing_server4_container.dins.logs().decode('utf-8')}\n"
    )
    if full_tree:
        print(
            f"probing server 5 : \n{probing_server5_container.dins.logs().decode('utf-8')}\n"
            f"probing server 6 : \n{probing_server6_container.dins.logs().decode('utf-8')}\n"
            f"probing server 7 : \n{probing_server7_container.dins.logs().decode('utf-8')}\n"
            f"probing server 8 : \n{probing_server8_container.dins.logs().decode('utf-8')}\n"
        )

    # time.sleep(2)
    # CLI(net)
    time.sleep(30)

    server_container: APPContainer = None

    info("\n*** Await REST instruction from Controller\n"
         )  # REST -> REpresentational State Transfer
    while True:
        data, addr = rx_socket.recvfrom(1024)
        _: str = data.decode()
        print(f"{_} {_[_.__len__()-1]}")
        if active_container:  # if container set, remove it
            mgr.removeContainer(server_container.name)
            time.sleep(2)  # prevent hang on waitContainerStart()
            print("removing container")
        server_container: APPContainer = mgr.addContainer(
            name="server_container",
            # update dhost appropriate to target host
            dhost=f"server{_[_.__len__()-1]}",
            dimage="mec_test",
            docker_args={},
            dcmd="python3.6 /tmp/server.py",
        )
        print(
            f"New container : \n{server_container.dins.logs().decode('utf-8')} on server{_[_.__len__()-1]}"
        )
        cnt += 1
        active_container = True
        time.sleep(10)  # dont allow container change too frequent
        if cnt > 10:
            break

    info("\n*** Removing Docker Containers\n")
    mgr.removeContainer(client1_container.name)
    mgr.removeContainer(probe1_container.name)

    mgr.removeContainer(probing_server1_container.name)
    mgr.removeContainer(probing_server2_container.name)
    mgr.removeContainer(probing_server3_container.name)
    mgr.removeContainer(probing_server4_container.name)
    if full_tree:
        mgr.removeContainer(probing_server5_container.name)
        mgr.removeContainer(probing_server6_container.name)
        mgr.removeContainer(probing_server7_container.name)
        mgr.removeContainer(probing_server8_container.name)

    info("\n*** Stopping Network\n")
    net.stop()
    mgr.stop()
Exemplo n.º 7
0
    info("*** Adding switch and links\n")

    for i in range(7):
        sconfig = {"dpid": "%016x" % (i + 1)}
        net.addSwitch("s%d" % (i + 1), protocols="OpenFlow10", **sconfig)

    # 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")

    # Add switch links
    net.addLink("s1", "s3", **http_link_config)
    net.addLink("s1", "s4", **http_link_config)
    net.addLink("s2", "s4", **http_link_config)
    net.addLink("s2", "s5", **http_link_config)
    net.addLink("s3", "s6", **http_link_config)
    net.addLink("s4", "s6", **http_link_config)
    net.addLink("s4", "s7", **http_link_config)
    net.addLink("s5", "s7", **http_link_config)

    # Add host links
    net.addLink("h1", "s1", **host_link_config)
    net.addLink("h2", "s1", **host_link_config)
    net.addLink("h3", "s2", **host_link_config)
    net.addLink("h4", "s2", **host_link_config)
    net.addLink("h5", "s6", **host_link_config)
    net.addLink("h6", "s6", **host_link_config)
def myTopology():
    net = Containernet(
        switch=OVSKernelSwitch,
        build=False,
        autoSetMacs=True,
        autoStaticArp=True,
        link=TCLink,
    )

    mgr = VNFManager(net)
    setLogLevel("info")

    info("*** Add Switches\n")
    sconfig1 = {"dpid": "%016x" % 1}
    sconfig2 = {"dpid": "%016x" % 2}
    sconfig3 = {"dpid": "%016x" % 3}
    sconfig4 = {"dpid": "%016x" % 4}
    sconfig5 = {"dpid": "%016x" % 5}
    net.addSwitch("s1", **sconfig1)
    net.addSwitch("s2", **sconfig2)
    net.addSwitch("s3", **sconfig3)
    net.addSwitch("s4", **sconfig4)
    net.addSwitch("s5", **sconfig5)

    info("*** Add Hosts\n")
    host_config = dict(inNamespace=True)
    #net.addHost("h1", **host_config, ip="192.0.0.1")
    h1 = net.addDockerHost(
        "h1",
        dimage="dev_test",
        ip="192.0.0.1",
        docker_args={"hostname": "h1"},
    )
    h2 = net.addDockerHost(
        "h2",
        dimage="dev_test",
        ip="192.0.0.2",
        docker_args={"hostname": "h2"},
    )
    h3 = net.addDockerHost(
        "h3",
        dimage="dev_test",
        ip="192.0.0.3",
        docker_args={"hostname": "h3"},
    )
    h4 = net.addDockerHost(
        "h4",
        dimage="dev_test",
        ip="192.0.0.4",
        docker_args={"hostname": "h4"},
    )
    h5 = net.addDockerHost(
        "h5",
        dimage="dev_test",
        ip="192.0.0.5",
        docker_args={"hostname": "h5"},
    )
    h6 = net.addDockerHost(
        "h6",
        dimage="dev_test",
        ip="192.0.0.6",
        docker_args={"hostname": "h6"},
    )
    h7 = net.addDockerHost(
        "h7",
        dimage="dev_test",
        ip="192.0.0.7",
        docker_args={"hostname": "h7"},
    )
    h8 = net.addDockerHost(
        "h8",
        dimage="dev_test",
        ip="192.0.0.8",
        docker_args={"hostname": "h8"},
    )

    info("*** Add Links\n")
    net.addLink("h1", "s1", bw=B1)
    net.addLink("h2", "s1", bw=B1)
    net.addLink("h3", "s1", bw=B1)
    net.addLink("h4", "s5", bw=B2)
    net.addLink("h5", "s5", bw=B2)
    net.addLink("s1", "s2", bw=B1)
    net.addLink("s2", "s3", bw=B1, delay=DELAY)
    net.addLink("s3", "s4", bw=B1, delay=DELAY)
    net.addLink("s2", "s4", bw=B2)
    net.addLink("s1", "s4", bw=B1)
    net.addLink("s1", "s5", bw=B1)
    net.addLink("s4", "h6", bw=B1)
    net.addLink("s4", "h7", bw=B1)
    net.addLink("s4", "h8", bw=B1)

    info("*** Add controller\n")
    controller = RemoteController("c0", ip="127.0.0.1", port=6633)
    net.addController(controller)
    net.build()
    #controller.start()
    #s1.start( [controller] )
    #s2.start( [controller] )
    #s1.cmd("ovs-vsctl set port s1-eth4 qos=@newqos -- --id=@newqos create QoS type=linux-htb other-config:max-rate=1000000 queues:123=@1q queues:234=@2q -- --id=@1q create queue other-config:min-rate=100000 other-config:max-rate=700000 -- --id=@2q create queue other-config:min-rate=100000 other-config:max-rate=700000")
    #s1.cmd("ovs-ofctl add-flow s1 nw_src=192.0.0.2,nw_dst=192.0.0.7,actions=enqueue:4:123")
    net.start()
    srv1 = mgr.addContainer(
        "srv1",
        "h1",
        "servernew",
        "python /home/servernew.py",
        docker_args={},
    )  #autonomus
    srv2 = mgr.addContainer(
        "srv2",
        "h2",
        "dev_test",
        "bash",
        docker_args={},
    )  #udp
    srv3 = mgr.addContainer(
        "srv3",
        "h3",
        "eclipse-mosquitto",
        "bash",
        docker_args={},
    )  #brocker
    srv4 = mgr.addContainer(
        "srv4",
        "h4",
        "aksakalli/mqtt-client",
        "bash /home/clientnew.sh",
        docker_args={},
    )
    srv5 = mgr.addContainer(
        "srv5",
        "h5",
        "aksakalli/mqtt-client",
        "bash",
        docker_args={},
    )
    srv6 = mgr.addContainer(
        "srv6",
        "h6",
        "dev_test",
        "bash",
        docker_args={},
    )
    srv7 = mgr.addContainer(
        "srv7",
        "h7",
        "dev_test",
        "bash",
        docker_args={},
    )
    srv8 = mgr.addContainer(
        "srv8",
        "h8",
        "dev_test",
        "bash",
        docker_args={},
    )
    spawnXtermDocker("srv2")
    spawnXtermDocker("srv7")
    CLI(net)
    mgr.removeContainer("srv1")
    mgr.removeContainer("srv2")
    mgr.removeContainer("srv3")
    mgr.removeContainer("srv4")
    mgr.removeContainer("srv5")
    mgr.removeContainer("srv6")
    mgr.removeContainer("srv7")
    mgr.removeContainer("srv8")
    net.stop()
    mgr.stop()
def test_ovx():
    try:
        ip = "127.0.0.1"
        port = 6633

        info("*** Add remote controller\n")
        c = RemoteController("c", ip=ip, port=port)
        net = Containernet(
            autoStaticArp=True, autoSetMacs=True, controller=None, link=TCLink
        )
        net.addController(c)
        info("*** Add switches, hosts and links \n")
        # Add core switches
        cores = {}
        for switch in CORES:
            cores[switch] = net.addSwitch(switch, dpid=(CORES[switch]["dpid"] % "0"))

        # Add hosts and connect them to their core switch
        for switch in CORES:
            for count in range(1, FANOUT + 1):
                # Add hosts
                host = "h_%s_%s" % (switch, count)
                ip = "10.0.0.%s" % count
                mac = CORES[switch]["dpid"][4:] % count
                h = net.addDockerHost(host, dimage="dev_test", ip=ip, mac=mac)
                # Connect hosts to core switches
                net.addLink(cores[switch], h)

        # Connect core switches
        net.addLink(cores["SFO"], cores["SEA"])
        net.addLink(cores["SEA"], cores["SLC"])
        net.addLink(cores["SFO"], cores["LAX"])
        net.addLink(cores["LAX"], cores["SLC"])
        net.addLink(cores["LAX"], cores["IAH"])
        net.addLink(cores["SLC"], cores["MCI"])
        net.addLink(cores["MCI"], cores["IAH"])
        net.addLink(cores["MCI"], cores["ORD"])
        net.addLink(cores["IAH"], cores["ATL"])
        net.addLink(cores["ORD"], cores["ATL"])
        net.addLink(cores["ORD"], cores["CLE"])
        net.addLink(cores["ATL"], cores["IAD"])
        net.addLink(cores["CLE"], cores["IAD"])
        net.addLink(cores["CLE"], cores["EWR"])
        net.addLink(cores["EWR"], cores["IAD"])

        info("*** Start network... \n")
        net.start()
        print(
            "Hosts configured with IPs, switches pointing to OpenVirteX at %s:%s"
            % (ip, port)
        )

        info("[OVX] Create a virtual network between SEA and LAX\n")
        wd = os.getcwd()
        os.chdir(OVXCTL_DIR)
        commands = [
            # Create virtual networks
            "python2 ovxctl.py createNetwork tcp:{}:{} 10.0.0.0 16".format(
                SDN_CONTROLLER_IP, SDN_CONTROLLER_PORT
            ),
            # Create virtual switches
            "python2 ovxctl.py -n createSwitch 1 00:00:00:00:00:00:01:00",
            "python2 ovxctl.py -n createSwitch 1 00:00:00:00:00:00:02:00",
            "python2 ovxctl.py -n createSwitch 1 00:00:00:00:00:00:03:00",
            # Create virtual ports
            "python2 ovxctl.py -n createPort 1 00:00:00:00:00:00:01:00 1",
            "python2 ovxctl.py -n createPort 1 00:00:00:00:00:00:01:00 5",
            "python2 ovxctl.py -n createPort 1 00:00:00:00:00:00:02:00 5",
            "python2 ovxctl.py -n createPort 1 00:00:00:00:00:00:02:00 6",
            "python2 ovxctl.py -n createPort 1 00:00:00:00:00:00:03:00 5",
            "python2 ovxctl.py -n createPort 1 00:00:00:00:00:00:03:00 2",
            # Create virtual links
            "python2 ovxctl.py -n connectLink 1 00:a4:23:05:00:00:00:01 2 00:a4:23:05:00:00:00:02 1 spf 1",
            "python2 ovxctl.py -n connectLink 1 00:a4:23:05:00:00:00:02 2 00:a4:23:05:00:00:00:03 1 spf 1",
            # Connect hosts
            "python2 ovxctl.py -n connectHost 1 00:a4:23:05:00:00:00:01 1 00:00:00:00:01:01",
            "python2 ovxctl.py -n connectHost 1 00:a4:23:05:00:00:00:03 2 00:00:00:00:03:02",
            # Start virtual network
            "python2 ovxctl.py -n startNetwork 1",
        ]
        for cmd in commands:
            ret = check_output(sh_split(cmd), encoding="utf-8")
            print(ret)

        os.chdir(wd)
        CLI(net)

    except Exception as e:
        error(e)
    finally:
        net.stop()
Exemplo n.º 10
0
def myTopology():
    net = Containernet(
        switch=OVSKernelSwitch,
        build=False,
        autoSetMacs=True,
        autoStaticArp=True,
        link=TCLink,
    )

    mgr = VNFManager(net)
    setLogLevel("info")

    info("*** Add Switches\n")
    sconfig1 = {"dpid": "%016x" % 1}
    sconfig2 = {"dpid": "%016x" % 2}
    sconfig3 = {"dpid": "%016x" % 3}
    sconfig4 = {"dpid": "%016x" % 4}
    net.addSwitch("s1", **sconfig1)
    net.addSwitch("s2", **sconfig2)
    net.addSwitch("s3", **sconfig3)
    net.addSwitch("s4", **sconfig4)
    info("*** Add Hosts\n")
    host_config = dict(inNamespace=True)
    #net.addHost("h1", **host_config, ip="192.0.0.1")
    h1 = net.addDockerHost(
        "h1",
        dimage="dev_test",
        ip="192.0.0.1",
        docker_args={"hostname": "h1"},
    )
    h2 = net.addDockerHost(
        "h2",
        dimage="dev_test",
        ip="192.0.0.2",
        docker_args={"hostname": "h2"},
    )
    h3 = net.addDockerHost(
        "h3",
        dimage="dev_test",
        ip="192.0.0.3",
        docker_args={"hostname": "h3"},
    )
    h4 = net.addDockerHost(
        "h4",
        dimage="dev_test",
        ip="192.0.0.4",
        docker_args={"hostname": "h4"},
    )
    h5 = net.addDockerHost(
        "h5",
        dimage="dev_test",
        ip="192.0.0.5",
        docker_args={"hostname": "h5"},
    )
    h6 = net.addDockerHost(
        "h6",
        dimage="dev_test",
        ip="192.0.0.6",
        docker_args={"hostname": "h6"},
    )
    h7 = net.addDockerHost(
        "h7",
        dimage="dev_test",
        ip="192.0.0.7",
        docker_args={"hostname": "h7"},
    )

    info("*** Add Links\n")
    net.addLink("h1", "s1", bw=B1)
    net.addLink("h2", "s1", bw=B1)
    net.addLink("h3", "s1", bw=B1)
    net.addLink("h4", "s1", bw=B1)
    net.addLink("s1", "s2", bw=B1)
    net.addLink("s2", "s3", bw=B1, delay=DELAY)
    net.addLink("s3", "s4", bw=B1, delay=DELAY)
    net.addLink("s2", "s4", bw=B2)
    net.addLink("s1", "s4", bw=B1)
    net.addLink("s4", "h5", bw=B1)
    net.addLink("s4", "h6", bw=B1)
    net.addLink("s4", "h7", bw=B1)

    info("*** Add controller\n")
    controller = RemoteController("c1", ip="127.0.0.1", port=6633)
    net.addController(controller)
    net.build()
    net.start()
    srv1 = mgr.addContainer(
        "srv1",
        "h1",
        "echo_server",
        "python /home/server_ad.py",
        docker_args={},
    )
    srv2 = mgr.addContainer(
        "srv2",
        "h2",
        "echo_server",
        "python /home/server.py",
        docker_args={},
    )
    srv3 = mgr.addContainer(
        "srv3",
        "h3",
        "echo_server",
        "python /home/server.py",
        docker_args={},
    )
    srv4 = mgr.addContainer(
        "srv4",
        "h4",
        "dev_test",
        "bash",
        docker_args={},
    )
    srv5 = mgr.addContainer(
        "srv5",
        "h5",
        "dev_test",
        "bash",
        docker_args={},
    )
    srv6 = mgr.addContainer(
        "srv6",
        "h6",
        "dev_test",
        "bash",
        docker_args={},
    )
    srv7 = mgr.addContainer(
        "srv7",
        "h7",
        "dev_test",
        "bash",
        docker_args={},
    )
    spawnXtermDocker("srv5")
    spawnXtermDocker("srv1")
    CLI(net)
    mgr.removeContainer("srv1")
    mgr.removeContainer("srv2")
    mgr.removeContainer("srv3")
    mgr.removeContainer("srv4")
    mgr.removeContainer("srv5")
    mgr.removeContainer("srv6")
    mgr.removeContainer("srv7")
    net.stop()
    mgr.stop()
Exemplo n.º 11
0
def testMuNF(nano_cpus):
    net = Containernet(controller=Controller, link=TCLink)
    mgr = VNFManager(net)

    start_ts = time.time()
    info("*** Adding controller\n")
    net.addController("c0")

    info("*** Adding Docker hosts\n")
    pktgen = net.addDockerHost(
        "pktgen",
        dimage=f"trex:{TREX_VER}",
        ip="10.0.0.1/24",
        docker_args={
            "cpuset_cpus": "0",
            "hostname": "pktgen",
            "volumes": {
                os.path.join(TREX_CONF_DIR, "trex_cfg.yaml"): {
                    "bind": "/etc/trex_cfg.yaml",
                    "mode": "rw",
                },
                TREX_CONF_DIR: {"bind": f"/trex/{TREX_VER}/local", "mode": "rw"},
            },
        },
    )

    dut = net.addDockerHost(
        "dut",
        dimage=f"ffpp:{FFPP_VER}",
        ip="10.0.0.2/24",
        docker_args={
            "cpuset_cpus": "1,2",
            "nano_cpus": int(nano_cpus),
            "hostname": "dut",
            "volumes": {
                "/sys/bus/pci/drivers": {"bind": "/sys/bus/pci/drivers", "mode": "rw"},
                "/sys/kernel/mm/hugepages": {
                    "bind": "/sys/kernel/mm/hugepages",
                    "mode": "rw",
                },
                "/sys/devices/system/node": {
                    "bind": "/sys/devices/system/node",
                    "mode": "rw",
                },
                "/dev": {"bind": "/dev", "mode": "rw"},
                FFPP_DIR: {"bind": "/ffpp", "mode": "rw"},
            },
        },
    )
    s1 = net.addSwitch("s1")

    # Control plane links.
    net.addLinkNamedIfce(s1, pktgen)
    net.addLinkNamedIfce(s1, dut)

    # Data plane links.
    net.addLink(
        dut, pktgen, bw=1000, delay="1ms", intfName1="vnf-in", intfName2="pktgen-out"
    )
    net.addLink(
        dut, pktgen, bw=1000, delay="1ms", intfName1="vnf-out", intfName2="pktgen-in"
    )
    pktgen.cmd("ip addr add 192.168.17.1/24 dev pktgen-out")
    pktgen.cmd("ip addr add 192.168.18.1/24 dev pktgen-in")
    dut.cmd("ip addr add 192.168.17.2/24 dev vnf-in")
    dut.cmd("ip addr add 192.168.18.2/24 dev vnf-out")

    # TODO: Deploy a chain of CNFs.
    cnfs = list()
    for n in range(1):
        cnf = mgr.addContainer(
            f"cnf{n}",
            "dut",
            f"ffpp:{FFPP_VER}",
            "/bin/bash",
            docker_args={
                "volumes": {
                    "/sys/bus/pci/drivers": {
                        "bind": "/sys/bus/pci/drivers",
                        "mode": "rw",
                    },
                    "/sys/kernel/mm/hugepages": {
                        "bind": "/sys/kernel/mm/hugepages",
                        "mode": "rw",
                    },
                    "/sys/devices/system/node": {
                        "bind": "/sys/devices/system/node",
                        "mode": "rw",
                    },
                    "/dev": {"bind": "/dev", "mode": "rw"},
                    FFPP_DIR: {"bind": "/ffpp", "mode": "rw"},
                }
            },
        )
        cnfs.append(cnf)

    net.start()

    # Avoid looping
    pktgen.cmd("ip addr flush dev pktgen-s1")
    pktgen.cmd("ip link set pktgen-s1 down")
    dut.cmd("ip addr flush dev dut-s1")
    dut.cmd("ip link set dut-s1 down")

    pktgen.cmd("ping -c 5 192.168.17.2")
    pktgen.cmd("ping -c 5 192.168.18.2")

    duration = time.time() - start_ts
    print(f"Setup duration: {duration:.2f} seconds.")

    CLI(net)

    info("*** Stopping network\n")
    net.stop()
    mgr.stop()
Exemplo n.º 12
0
    h4 = net.addDockerHost(
        "h4",
        dimage="dev_test",
        ip="10.0.0.4",
        docker_args={"hostname": "h4"},
    )

    h5 = net.addDockerHost(
        "h5",
        dimage="dev_test",
        ip="10.0.0.5",
        docker_args={"hostname": "h5"},
    )
    info("*** Adding switch and links\n")
    switch1 = net.addSwitch("s1")
    net.addLink(switch1, h1, bw=10, delay="10ms")
    net.addLink(switch1, h2, bw=10, delay="10ms")
    net.addLink(switch1, h3, bw=10, delay="10ms")
    net.addLink(switch1, h4, bw=10, delay="10ms")
    net.addLink(switch1, h5, bw=10, delay="10ms")

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

    #Broker
    ad = mgr.addContainer("MQTT",
                          "h1",
                          "mqttbroker",
                          "sh broker.sh",
                          docker_args={})
    time.sleep(5)
    info("*** Adding switch and links\n")

    for i in range(7):
        sconfig = {'dpid': "%016x" % (i + 1)}
        net.addSwitch('s%d' % (i + 1), protocols='OpenFlow10', **sconfig)

    #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")

    # Add switch links
    net.addLink('s1', 's3', **http_link_config)
    net.addLink('s1', 's4', **http_link_config)
    net.addLink('s2', 's4', **http_link_config)
    net.addLink('s2', 's5', **http_link_config)
    net.addLink('s3', 's6', **http_link_config)
    net.addLink('s4', 's6', **http_link_config)
    net.addLink('s4', 's7', **http_link_config)
    net.addLink('s5', 's7', **http_link_config)

    # Add host links
    net.addLink('h1', 's1', **host_link_config)
    net.addLink('h2', 's1', **host_link_config)
    net.addLink('h3', 's2', **host_link_config)
    net.addLink('h4', 's2', **host_link_config)
    net.addLink('h5', 's6', **host_link_config)
    net.addLink('h6', 's6', **host_link_config)