def run_topo(): net = Containernet( controller=Controller, link=TCLink, switch=OVSBridge, topo=TestTopo(2) ) info("*** Adding controller\n") net.addController("c0") info("*** Starting network\n") net.start() net.pingAll() h1 = net.get("h1") h2 = net.get("h2") net.iperf((h1, h2), l4Type="UDP", udpBw="10M") info("*** Stopping network") net.stop()
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()
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") compressor = net.addDockerHost( "compressor", dimage="o2sc", ip="10.0.0.1/24", docker_args={ "cpuset_cpus": "1", "cpu_quota": 25000, "hostname": "compressor" }, ) decompressor = net.addDockerHost( "decompressor", dimage="o2sc", ip="10.0.0.2/24", docker_args={ "cpuset_cpus": "1", "cpu_quota": 25000, "hostname": "decompressor", }, ) source_1 = net.addDockerHost( "source_1", dimage="o2sc", ip="10.0.0.11/24", docker_args={ "cpuset_cpus": "1", "cpu_quota": 25000, "hostname": "source_1" }, ) source_2 = net.addDockerHost( "source_2", dimage="o2sc", ip="10.0.0.12/24", docker_args={ "cpuset_cpus": "1", "cpu_quota": 25000, "hostname": "source_2" }, ) source_3 = net.addDockerHost( "source_3", dimage="o2sc", ip="10.0.0.13/24", docker_args={ "cpuset_cpus": "1", "cpu_quota": 25000, "hostname": "source_3" }, ) info("*** Adding switch\n") s1 = net.addSwitch("s1") info("*** Creating links\n") net.addLinkNamedIfce(s1, compressor, bw=10, delay="100ms") net.addLinkNamedIfce(s1, decompressor, bw=10, delay="100ms") net.addLinkNamedIfce(s1, source_1, bw=10, delay="100ms") net.addLinkNamedIfce(s1, source_2, bw=10, delay="100ms") net.addLinkNamedIfce(s1, source_3, bw=10, delay="100ms") info("*** Starting network\n") net.start() net.pingAll() info("*** Enter CLI\n") info("Use help command to get CLI usages\n") CLI(net) info("*** Stopping network") net.stop()
def testTopo(): """testTopo""" net = Containernet( controller=Controller, link=TCLink, autoSetMacs=True, autoStaticArp=True, xterms=True, ) info("*** Adding controller\n") net.addController("c0") info("*** Adding hosts\n") client = net.addDockerHost( "client", dimage="yolov2", ip="10.0.0.11/24", docker_args={ "cpuset_cpus": "0", "hostname": "client" }, ) vnf = net.addDockerHost( "vnf", dimage="yolov2", ip="10.0.0.12/24", docker_args={ "cpuset_cpus": "0", "hostname": "vnf" }, ) # Run server on another vCPU since it is more compute-intensive than client # and vnf. server = net.addDockerHost( "server", dimage="yolov2", ip="10.0.0.21/24", docker_args={ "cpuset_cpus": "1", "hostname": "server" }, ) info("*** Adding switch\n") s1 = net.addSwitch("s1") info("*** Creating links\n") net.addLinkNamedIfce(s1, client, bw=10, delay="150ms", use_htb=True) net.addLinkNamedIfce(s1, vnf, bw=10, delay="150ms", use_htb=True) net.addLinkNamedIfce(s1, server, bw=10, delay="150ms", use_htb=True) info("*** Starting network\n") net.start() net.pingAll() add_ovs_flows() ifces = ["s1-vnf"] disable_cksum_offload(ifces) info("*** Enter CLI\n") CLI(net) info("*** Stopping network") net.stop()
def run_benchmark(proto): net = Containernet(controller=Controller, link=TCLink, switch=OVSSwitch, autoStaticArp=False) info("*** Adding controller\n") net.addController("c0") info("*** Adding switch\n") s1 = net.addSwitch("s1") # MARK: The relay should run on a different CPU core as the client and # server. To avoid cache misses of the VNF running on the relay. info("*** Adding client and server.\n") client = net.addDockerHost( "client", dimage="lat_bm:latest", ip="10.0.0.100/24", docker_args={ "cpuset_cpus": "0", "volumes": { "%s" % FFPP_DIR: { "bind": "/ffpp", "mode": "ro" } }, }, ) net.addLinkNamedIfce(s1, client, delay="100ms") server = net.addDockerHost( "server", dimage="lat_bm:latest", ip="10.0.0.200/24", docker_args={"cpuset_cpus": "0"}, ) net.addLinkNamedIfce(s1, server, delay="100ms") if ADD_RELAY: cpus_relay = "1" if TEST_NF == "l2fwd-power": print( "*** [INFO] l2fwd-power application require at least one master and one slave core.\n" "The master handles timers and slave core handles forwarding task." ) cpus_relay = "0,1" info("*** Adding relay.\n") # Need additional mounts to run DPDK application # MARK: Just used for development, never use this in production container # setup. relay = net.addDockerHost( "relay", dimage="ffpp:latest", ip="10.0.0.101/24", docker_args={ "cpuset_cpus": cpus_relay, "nano_cpus": int(1.0 * 1e9), "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" }, "%s" % FFPP_DIR: { "bind": "/ffpp", "mode": "rw" }, }, }, ) net.addLinkNamedIfce(s1, relay, delay="100ms") info("*** Starting network\n") net.start() net.pingAll() nodes = [n.name for n in net.hosts] sw_ifaces = [f"s1-{n}" for n in nodes] info("*** Disable kernel IP checksum offloading.\n") for iface in sw_ifaces: check_output(split(f"ethtool --offload {iface} rx off tx off")) node_portnum_map = {n: getOFPort(s1, f"s1-{n}") for n in nodes} if ADD_RELAY: info("*** Add OpenFlow rules for traffic redirection.\n") peer_map = {"client": "relay", "relay": "server", "server": "client"} for p in ["udp", "tcp"]: for peer in peer_map.keys(): check_output( split( 'ovs-ofctl add-flow s1 "{},in_port={},actions=output={}"' .format(p, node_portnum_map[peer], node_portnum_map[peer_map[peer]]))) if DEBUG: flow_table = s1.dpctl("dump-flows") print(f"*** Current flow table of s1: \n {flow_table}") info("*** Run DPDK helloworld\n") relay.cmd("cd $RTE_SDK/examples/helloworld && make") ret = relay.cmd( "cd $RTE_SDK/examples/helloworld/build && ./helloworld") print(f"Output of helloworld app:\n{ret}") DISPATCHER[TEST_NF](relay) server.cmd("pkill sockperf") setup_server(server, proto) for mps in LAT_TEST_PARAS["client_mps_list"]: run_latency_test(server, client, proto, mps) time.sleep(3) if ENTER_CLI: info("*** Enter CLI\n") info("Use help command to get CLI usages\n") CLI(net) info("*** Stopping network") net.stop()