def setUp(self): self.n0 = Node("n0") self.n1 = Node("n1") self.r0 = Node("r0") self.r1 = Node("r1") self.r0.enable_ip_forwarding() self.r1.enable_ip_forwarding()
def setUp(self): self.n0 = Node("n0") self.n1 = Node("n1") self.r0 = Node("r0") self.r1 = Node("r1") self.r0.enable_ip_forwarding() self.r1.enable_ip_forwarding() ### Create interfaces and connect nodes and routers ### (eth_p1r1, eth_r1p1) = connect(self.n0, self.r0, "eth-n1r1-0", "eth-r1n1-0") (eth_r1r2, eth_r2r1) = connect(self.r0, self.r1, "eth-r1r2-0", "eth-r2r1-0") (eth_r2p2, eth_p2r2) = connect(self.r1, self.n1, "eth-r2n2-0", "eth-n2r2-0") ### Assign addresses to interfaces ### eth_p1r1.set_address("10.0.1.1/24") eth_r1p1.set_address("10.0.1.2/24") eth_r1r2.set_address("10.0.2.2/24") eth_r2r1.set_address("10.0.2.3/24") eth_r2p2.set_address("10.0.3.3/24") eth_p2r2.set_address("10.0.3.4/24") config.set_value("routing_suite", "quagga") # Use quagga
def test_experiment_ipv6(self): # Test IPv6 with Duplicate Address Detection (DAD) disabled n0 = Node("n0") n1 = Node("n1") r = Node("r") r.enable_ip_forwarding() (n0_r, r_n0) = connect(n0, r) (r_n1, n1_r) = connect(r, n1) n0_r.set_address("10::1:1/122") r_n0.set_address("10::1:2/122") r_n1.set_address("10::2:2/122") n1_r.set_address("10::2:1/122") n0.add_route("DEFAULT", n0_r) n1.add_route("DEFAULT", n1_r) n0_r.set_attributes("100mbit", "5ms") r_n0.set_attributes("100mbit", "5ms") r_n1.set_attributes("10mbit", "40ms", "pie") n1_r.set_attributes("10mbit", "40ms") exp = Experiment("test-experiment-ipv6") flow = Flow(n0, n1, n1_r.address, 0, 5, 2) exp.add_tcp_flow(flow) exp.run()
def setUp(self): self.n0 = Node("n0") self.n1 = Node("n1") self.net1 = Network("10.0.1.0/24") self.net2 = Network("10.0.2.0/24") self.net3 = Network("2001:101::/122") self.net4 = Network("2002:101::/122")
def test_dumbbell_lan(self): # pylint: disable=too-many-locals n0 = Node("n0") n1 = Node("n1") n2 = Node("n2") n3 = Node("n3") s0 = Switch("s0") s1 = Switch("s1") (n0_s0, _) = connect(n0, s0) (n1_s0, _) = connect(n1, s0) (n2_s1, _) = connect(n2, s1) (n3_s1, _) = connect(n3, s1) connect(s0, s1) nodes = [n0, n1, n2, n3] interface = [n0_s0, n1_s0, n2_s1, n3_s1] n0_s0.set_address("10.0.0.1/24") n1_s0.set_address("10.0.0.2/24") n2_s1.set_address("10.0.0.3/24") n3_s1.set_address("10.0.0.4/24") for x in nodes: for y in interface: status = x.ping(y.address, verbose=False) if not status: break self.assertTrue(status)
def setUp(self): self.assertTrue(isfile("/usr/lib/frr/zebra"), "Frrouting is not installed") self.n0 = Node("n0") self.n1 = Node("n1") self.r0 = Node("r0") self.r1 = Node("r1") self.r0.enable_ip_forwarding() self.r1.enable_ip_forwarding() ### Create interfaces and connect nodes and routers ### (eth_p1r1, eth_r1p1) = connect(self.n0, self.r0, "eth-n1r1-0", "eth-r1n1-0") (eth_r1r2, eth_r2r1) = connect(self.r0, self.r1, "eth-r1r2-0", "eth-r2r1-0") (eth_r2p2, eth_p2r2) = connect(self.r1, self.n1, "eth-r2n2-0", "eth-n2r2-0") ### Assign addresses to interfaces ### eth_p1r1.set_address("10.0.1.1/24") eth_r1p1.set_address("10.0.1.2/24") eth_r1r2.set_address("10.0.2.2/24") eth_r2r1.set_address("10.0.2.3/24") eth_r2p2.set_address("10.0.3.3/24") eth_p2r2.set_address("10.0.3.4/24") config.set_value("routing_suite", "frr") # Use frr
def setUp(self): self.n0 = Node("n0") self.n1 = Node("n1") self.r0 = Node("r0") self.r1 = Node("r1") self.r0.enable_ip_forwarding() self.r1.enable_ip_forwarding() ### Create interfaces and connect nodes and routers ### (eth_p1r1, eth_r1p1) = connect(self.n0, self.r0, "eth-n1r1-0", "eth-r1n1-0") (eth_r1r2, eth_r2r1) = connect(self.r0, self.r1, "eth-r1r2-0", "eth-r2r1-0") (eth_r2p2, eth_p2r2) = connect(self.r1, self.n1, "eth-r2n2-0", "eth-n2r2-0") ### Assign addresses to interfaces ### eth_p1r1.set_address("10::1:1/122") eth_r1p1.set_address("10::1:2/122") eth_r1r2.set_address("10::2:2/122") eth_r2r1.set_address("10::2:3/122") eth_r2p2.set_address("10::3:3/122") eth_p2r2.set_address("10::3:4/122") config.set_value("routing_suite", "frr") # Use frr
def test_disable_offload(self): n2 = Node("n2") n1 = Node("n1") (n1_n2, n2_n1) = connect(n1, n2) # Disable TSO offload on n1_n2 interface n1_n2.disable_offload("tso") with n1: proc = subprocess.Popen( f"ip netns exec {n1.id} ethtool -k {n1_n2.id}", shell=True, stdout=subprocess.PIPE, ) (output, _) = proc.communicate() self.assertTrue("tcp-segmentation-offload: off" in output.decode()) # Disable offloads GSO, GRO on n2_n1 interface n2_n1.disable_offload(["gso", "gro"]) with n2: proc = subprocess.Popen( f"ip netns exec {n2.id} ethtool -k {n2_n1.id}", shell=True, stdout=subprocess.PIPE, ) (output, _) = proc.communicate() self.assertTrue("generic-segmentation-offload: off" in output.decode()) self.assertTrue("generic-receive-offload: off" in output.decode())
def test_simple_lan(self): # pylint: disable=too-many-locals n0 = Node("n0") n1 = Node("n1") n2 = Node("n2") n3 = Node("n3") s0 = Switch("s0") (n0_s0, _) = connect(n0, s0) (n1_s0, _) = connect(n1, s0) (n2_s0, _) = connect(n2, s0) (n3_s0, _) = connect(n3, s0) nodes = [n0, n1, n2, n3] interface = [n0_s0, n1_s0, n2_s0, n3_s0] n0_s0.set_address("10.0.0.1/24") n1_s0.set_address("10.0.0.2/24") n2_s0.set_address("10.0.0.3/24") n3_s0.set_address("10.0.0.4/24") for x in nodes: for y in interface: status = x.ping(y.address, packets=1) if not status: break self.assertTrue(status)
def test_experiment_udp(self): n0 = Node("n0") n1 = Node("n1") r = Node("r") r.enable_ip_forwarding() (n0_r, r_n0) = connect(n0, r) (r_n1, n1_r) = connect(r, n1) n0_r.set_address("10.1.1.1/24") r_n0.set_address("10.1.1.2/24") r_n1.set_address("10.1.2.2/24") n1_r.set_address("10.1.2.1/24") n0.add_route("DEFAULT", n0_r) n1.add_route("DEFAULT", n1_r) n0_r.set_attributes("100mbit", "5ms") r_n0.set_attributes("100mbit", "5ms") r_n1.set_attributes("10mbit", "40ms", "pie") n1_r.set_attributes("10mbit", "40ms") exp = Experiment("test-experiment-udp") flow = Flow(n0, n1, n1_r.address, 0, 5, 2) exp.add_udp_flow(flow) exp.run()
def test_optional_and_list_field(self): samplemethod3([Node("h1"), Node("h2")]) with self.assertRaises(TypeError) as ex: samplemethod3(Node("h3")) self.assertEqual( str(ex.exception), "Expected type of argument 'interfaces' in method 'samplemethod3' " "is List. But got input 'Node('h3')' of type <class 'nest.topology.node.Node'>", )
def setUp(self): self.assertTrue( "mpls_iptunnel" in subprocess.check_output("lsmod").decode(), "Couldn't load mpls", ) self.n0 = Node("n0") self.n1 = Node("n1") self.r0 = Node("r0") self.r1 = Node("r1") self.r0.enable_ip_forwarding() self.r1.enable_ip_forwarding()
def test_invalid_veth_name(self): # Disable topology map config.set_value("assign_random_names", False) node0 = Node("longname0") node1 = Node("longname1") with self.assertRaises(ValueError) as cm: connect(node0, node1) err = cm.exception self.assertEqual( str(err), "Auto-generated device name longname0-longname1-0 is " "too long. The length of name should not exceed 15 characters.", ) # Enable topology map config.set_value("assign_random_names", True)
def test_invalid_ifb_interface_name(self): # Disable topology map config.set_value("assign_random_names", False) node0 = Node("node0") node1 = Node("node1") eth0, _ = connect(node0, node1) with self.assertRaises(ValueError) as cm: eth0.set_attributes("10mbit", "10ms", "codel") err = cm.exception self.assertEqual( str(err), "Device name ifb-node0-node1-0 is too " "long. Device names should not exceed 15 characters", ) # Enable topology map config.set_value("assign_random_names", True)
def test_prrp(self): # pylint: disable=invalid-name r1 = Node("r") r2 = Node("r") r1.enable_ip_forwarding() r2.enable_ip_forwarding() with self.net1: (n0_r1, r1_n0) = connect(self.n0, r1) (r1_r2, r2_r1) = connect(r1, r2, network=self.net2) (r2_n1, n1_r2) = connect(r2, self.n1) AddressHelper.assign_addresses() r2_n1.set_address("10.1.3.2/24") n1_r2.set_address("10.1.3.1/24") RoutingHelper(protocol="rip").populate_routing_tables() status = self.n0.ping(n1_r2.get_address(), verbose=False) self.assertTrue(status)
def test_type_casting(self): samplemethod2(Node("n1"), Address("10.0.0.1/24")) samplemethod2(Node("n2"), "10.0.0.1/24") with self.assertRaises(TypeError) as ex: samplemethod2("n3", "10.0.0.1/24") self.assertEqual( str(ex.exception), "Expected type of argument 'node' in method 'samplemethod2' " "is <class 'nest.topology.node.Node'>. But got input 'n3' of type <class 'str'>", ) with self.assertRaises(TypeError) as ex: samplemethod2(Node("n4"), "10.0.0.1/244") self.assertEqual( str(ex.exception), "For argument 'address' in method 'samplemethod2', " "converting '10.0.0.1/244' to type Address failed.\n" "Please see the previous exception to know why the conversion failed.", )
def test_valid_veth_name(self): node0 = Node("node0") node1 = Node("node1") eth0, eth1 = connect(node0, node1) self.assertEqual(eth0.name, "node0-node1-0", "eth0 has unexpected autogenerated name") self.assertEqual(eth1.name, "node1-node0-0", "eth1 has unexpected autogenerated name") eth2, eth3 = connect(node0, node1) self.assertEqual(eth2.name, "node0-node1-1", "eth2 has unexpected autogenerated name") self.assertEqual(eth3.name, "node1-node0-1", "eth3 has unexpected autogenerated name") eth4, eth5 = connect(node0, node1, "eth4", "eth5") self.assertEqual(eth4.name, "eth4", "eth4 has unexpected user-given name") self.assertEqual(eth5.name, "eth5", "eth5 has unexpected user-given name")
def test_prp_ipv6(self): # pylint: disable=invalid-name r = Node("r") r.enable_ip_forwarding() with self.net3: (n0_r, r_n0) = connect(self.n0, r) with self.net4: (r_n1, n1_r) = connect(r, self.n1, network=self.net4) AddressHelper.assign_addresses() self.n0.add_route("DEFAULT", n0_r) self.n1.add_route("DEFAULT", n1_r) status = self.n0.ping(n1_r.get_address(), verbose=False) self.assertTrue(status)
def test_prp(self): # pylint: disable=invalid-name r = Node("r") r.enable_ip_forwarding() (n0_r, r_n0) = connect(self.n0, r) (r_n1, n1_r) = connect(r, self.n1) n0_r.set_address("10.1.1.1/24") r_n0.set_address("10.1.1.2/24") r_n1.set_address("10.1.2.2/24") n1_r.set_address("10.1.2.1/24") self.n0.add_route("DEFAULT", n0_r) self.n1.add_route("DEFAULT", n1_r) status = self.n0.ping("10.1.2.1") self.assertTrue(status)
def test_prp_ipv6(self): # pylint: disable=invalid-name r = Node("r") r.enable_ip_forwarding(ipv6=True) (n0_r, r_n0) = connect(self.n0, r) (r_n1, n1_r) = connect(r, self.n1) self.n0.disable_ip_dad() self.n1.disable_ip_dad() n0_r.set_address("2001:0001:0001:1443::0411/122") r_n0.set_address("2001:0001:0001:1443::0412/122") r_n1.set_address("2001:0001:0001:1444::0412/122") n1_r.set_address("2001:0001:0001:1444::0411/122") self.n0.add_route("DEFAULT", n0_r) self.n1.add_route("DEFAULT", n1_r) status = self.n0.ping(n1_r.address) self.assertTrue(status)
def setUp(self): self.n0 = Node("n0") self.n1 = Node("n1")