def test_connection(source_container, target_ip):
    info("*** Test the connection\n")
    info("* Ping test count: %d" % PING_COUNT)
    ret = source_container.cmd("ping -c " + str(PING_COUNT) + " " + target_ip)
    sent, received = tool.parsePing(ret)
    measured = ((sent - received) / float(sent)) * 100.0
    info("* Measured loss rate: {:.2f}%\n".format(measured))
コード例 #2
0
def test_connection(client):
    info("*** Test the connection\n")
    print("* Ping test count: %d" % PING_COUNT)
    ret = client.cmd("ping -c %d 10.0.0.1" % PING_COUNT)
    sent, received = tool.parsePing(ret)
    measured = ((sent - received) / float(sent)) * 100.0
    print("* Measured loss rate: {:.2f}%".format(measured))
def test_connection(source_container, target_ip):
    ret = source_container.cmd("ping -c " + str(PING_COUNT) + " " + target_ip)
    sent, received = tool.parsePing(ret)
    measured = ((sent - received) / float(sent)) * 100.0
    if measured == 0.0:
        return True
    else:
        return False
def test_connection(source_container, target_ip):
    ret = source_container.cmd("ping -c " + str(PING_COUNT) + " " + target_ip)
    sent, received = tool.parsePing(ret)
    measured = ((sent - received) / float(sent)) * 100.0
    if measured == 0.0:
        return info("* Connection established\n")
    else:
        return info("* Connection denied\n")
コード例 #5
0
def testTopo():
    "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.addDockerHost(
        "h1",
        dimage="sec_test",
        ip="10.0.0.1",
        docker_args={
            "cpuset_cpus": "0",
            "nano_cpus": int(1e8)
        },
    )
    h2 = net.addDockerHost(
        "h2",
        dimage="sec_test",
        ip="10.0.0.2",
        docker_args={
            "cpuset_cpus": "0",
            "nano_cpus": int(1e8)
        },
    )

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

    info("*** Creating links\n")
    net.addLinkNamedIfce(s1, h1, bw=10, delay="1ms", use_htb=True)
    net.addLinkNamedIfce(s1, h2, bw=10, delay="1ms", use_htb=True)

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

    info("*** Create wg key pairs\n")
    h1.cmd("umask 077; wg genkey > privatekey")
    h1.cmd("wg pubkey < privatekey > publickey")
    h1_pubkey = h1.cmd("cat ./publickey").replace("\n", " ").replace("\r", "")

    h2.cmd("umask 077; wg genkey > privatekey")
    h2.cmd("wg pubkey < privatekey > publickey")
    h2_pubkey = h2.cmd("cat ./publickey").replace("\n", " ").replace("\r", "")

    info("*** Create wg interfaces\n")
    h1.cmd("ip link add dev wg0 type wireguard")
    h1.cmd("ip address add dev wg0 192.168.0.1/24")

    h2.cmd("ip link add dev wg0 type wireguard")
    h2.cmd("ip address add dev wg0 192.168.0.2/24")

    info("*** Setup peer configuration\n")
    h1.cmd(
        "wg set wg0 listen-port 1337 private-key ./privatekey peer {} allowed-ips 192.168.0.0/24 endpoint 10.0.0.2:1337"
        .format(h2_pubkey))
    h1.cmd("ip link set up dev wg0")

    h2.cmd(
        "wg set wg0 listen-port 1337 private-key ./privatekey peer {} allowed-ips 192.168.0.0/24 endpoint 10.0.0.1:1337"
        .format(h1_pubkey))
    h2.cmd("ip link set up dev wg0")

    info("*** Test the connection\n")
    print("* Ping test count: %d" % PING_COUNT)
    ret = h1.cmd("ping -c %d 192.168.0.2" % PING_COUNT)
    sent, received = tool.parsePing(ret)
    measured = ((sent - received) / float(sent)) * 100.0
    print("* Measured loss rate: {:.2f}%".format(measured))

    info("*** Stopping network")
    net.stop()
コード例 #6
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()