def testTopo(): # xterms=True, spawn xterms for all nodes after net.start() net = Containernet(controller=Controller, link=TCLink, xterms=True) info("*** Adding controller\n") net.addController("c0") info("*** Adding hosts\n") h1 = net.addDockerHost( "h1", dimage="dev_test", ip="10.0.0.1/24", docker_args={ "cpuset_cpus": "0", "nano_cpus": int(1e8), "hostname": "h1" }, ) h2 = net.addDockerHost( "h2", dimage="dev_test", ip="10.0.0.2/24", docker_args={ "cpuset_cpus": "0", "nano_cpus": int(1e8), "hostname": "h2" }, ) h3 = net.addHost("h3", ip="10.0.0.3/24") h4 = net.addHost("h4", ip="10.0.0.4/24") info("*** Adding switch\n") s1 = net.addSwitch("s1") info("*** Creating links\n") net.addLinkNamedIfce(s1, h1, bw=10, delay="100ms") net.addLinkNamedIfce(s1, h2, bw=10, delay="100ms") net.addLinkNamedIfce(s1, h3, bw=10, delay="100ms") net.addLinkNamedIfce(s1, h4, bw=10, delay="100ms") info("*** Starting network\n") net.start() info("*** Enter CLI\n") info("Use help command to get CLI usages\n") CLI(net) info("*** Stopping network") net.stop()
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()