def test_it_should_forward_packets_from_phy_to_the_link(self): l = Link('A') i = MockInterface('if0', '00:b0:d0:86:bb:f7') k = TargetInterface(link_addr="00:b0:d0:bb:cc:ff") t = Tap(l, i, k) i.accept(["This is a packet."]) self.assertEqual(1, len(l.forwarded())) self.assertEqual("This is a packet.", l.forwarded()[0])
def test_it_should_forward_traffic_to_a_real_interface_through_a_tap(self): l = Link('A') i = Interface(link=l) j = MockInterface('if0', '00:b0:d0:86:bb:f7') k = TargetInterface(link_addr="00:b0:d0:bb:cc:ff") t = Tap(l, j, k) j.accept(["This is a packet."]) self.assertEqual(1, len(l.forwarded())) self.assertEqual("This is a packet.", l.forwarded()[0])
def setUp(self): self.n = TestNetwork(TestNetworkConfiguration()) self.n._TestNetwork__taps[0].unbind() self.n._TestNetwork__taps[1].unbind() self.n.node(1).if0.ips.append(IPAddress.identify("2001:500:88:200::10")) self.n.node(1).if0.ips.append(IPAddress.identify("fe80:500:88:200::10")) self.n.node(2).if0.ips.append(IPAddress.identify("2001:600:88:200::10")) self.n.node(2).if0.ips.append(IPAddress.identify("fe80:600:88:200::10")) self.n.node(3).if0.ips.append(IPAddress.identify("2001:600:88:200::11")) self.n.node(3).if0.ips.append(IPAddress.identify("fe80:600:88:200::11")) self.n.node(4).if0.ips.append(IPAddress.identify("2001:700:88:200::10")) self.n.node(4).if0.ips.append(IPAddress.identify("fe80:700:88:200::10")) self.n.router(1).if0.ips.append(IPAddress.identify("2001:600:88:200::1")) self.n.router(1).if0.ips.append(IPAddress.identify("fe80:600:88:200::1")) self.n.router(1).if1.ips.append(IPAddress.identify("2001:500:88:200::1")) self.n.router(1).if1.ips.append(IPAddress.identify("fe80:500:88:200::1")) self.n.router(1)._TestRouter__forwards_to_0.append(Network("2001:0600:0088:0200::/64")) self.n.router(1)._TestRouter__forwards_to_1.append(Network("2001:0500:0088:0200::/64")) self.n.router(2).if0.ips.append(IPAddress.identify("2001:600:88:200::2")) self.n.router(2).if0.ips.append(IPAddress.identify("fe80:600:88:200::2")) self.n.router(2).if1.ips.append(IPAddress.identify("2001:500:88:200::2")) self.n.router(2).if1.ips.append(IPAddress.identify("fe80:500:88:200::2")) self.n.router(3).if0.ips.append(IPAddress.identify("2001:600:88:200::3")) self.n.router(3).if0.ips.append(IPAddress.identify("fe80:600:88:200::3")) self.n.router(3).if1.ips.append(IPAddress.identify("2001:500:88:200::3")) self.n.router(3).if1.ips.append(IPAddress.identify("fe80:500:88:200::3")) self.ethx_s = MockInterface("if0", "00:b0:d0:86:bb:f7") self.ethx_t = TargetInterface( ips=[IPAddress.identify("2001:500:88:200::20"), IPAddress.identify("fe80:500:88:200::20")], link_addr="00:b0:d0:bb:cc:ff", ) self.ethx = Tap(self.n.link(2), self.ethx_s, self.ethx_t) self.ethy_s = MockInterface("if1", "00:b0:e0:86:bb:f7") self.ethy_t = TargetInterface( ips=[IPAddress.identify("2001:600:88:200::20"), IPAddress.identify("fe80:600:88:200::20")], link_addr="00:b0:e0:bb:cc:ff", ) self.ethy = Tap(self.n.link(3), self.ethy_s, self.ethy_t)
def __init__(self): self.link_layer = "Ethernet" self.ifaces = [ MockInterface('if0', "be:ef:ca:fe:09:00"), MockInterface('if1', "be:ef:ca:fe:09:01") ] self.link1 = LinkConfiguration( v6_prefix = "2012:7665:7269:7079::", v6_prefix_size = 64, v4_prefix = "10.0.0.0", v4_prefix_size = 24) self.link2 = LinkConfiguration( v6_prefix = "2012:6970:7636::", v6_prefix_size = 64, v4_prefix = "10.1.0.0", v4_prefix_size = 24) self.link3 = LinkConfiguration( v6_prefix = "2012:6d77:7269::", v6_prefix_size = 64, v4_prefix = "10.2.0.0", v4_prefix_size = 24) self.tn1 = NodeConfiguration( ips0 = ["2001:500:88:200::11", "fe80::11"], ll_addr0 = "de:ad:be:ef:01:01") self.tn2 = NodeConfiguration( ips0 = ["2001:600:88:200::12", "fe80::12"], ll_addr0 = "de:ad:be:ef:01:02") self.tn3 = NodeConfiguration( ips0 = ["2001:600:88:200::13", "fe80::13"], ll_addr0 = "de:ad:be:ef:01:03") self.tn4 = NodeConfiguration( ips0 = ["2001:700:88:200::14", "fe80::14"], ll_addr0 = "de:ad:be:ef:01:04") self.tp1 = TapConfiguration('if0', 'de:ad:be:ef:01:02') self.tp2 = TapConfiguration('if0', 'de:ad:be:ef:01:02') self.tr1 = RouterConfiguration( ips0 = ["2001:600:88:200::1", "fe80::1"], ll_addr0 = "de:ad:be:ef:02:01", ips1 = ["2001:500:88:200::1", "fe80::5"], ll_addr1 = "de:ad:be:ef:02:02") self.tr2 = RouterConfiguration( ips0 = ["2001:600:88:200::2", "fe80::2"], ll_addr0 = "de:ad:be:ef:02:03", ips1 = ["2001:500:88:200::2", "fe80::6"], ll_addr1 = "de:ad:be:ef:02:04") self.tr3 = RouterConfiguration( ips0 = ["2001:600:88:200::3", "fe80::3"], ll_addr0 = "de:ad:be:ef:02:04", ips1 = ["2001:500:88:200::3", "fe80::7"], ll_addr1 = "de:ad:be:ef:02:05") self.uut1 = TargetConfiguration(ips = ["2012:6970:7636:0:20c:29ff:fef4:b890", "fe80::20c:29ff:fef4:b890"], ll_addr = "be:ef:ca:fe:01:02") self.uut2 = TargetConfiguration(ips = ["2012:6970:7636:0:20c:29ff:fef4:b890", "fe80::20c:29ff:fef4:b890"], ll_addr = "be:ef:ca:fe:01:02")
def setUp(self): self.n = TestNetwork(TestNetworkConfiguration()) self.n._TestNetwork__taps[0].unbind() self.n._TestNetwork__taps[1].unbind() self.n.node(1).if0.ips.append(IPAddress.identify("2001:500:88:200::10")) self.n.node(1).if0.ips.append(IPAddress.identify("fe80:500:88:200::10")) self.n.node(2).if0.ips.append(IPAddress.identify("2001:600:88:200::10")) self.n.node(2).if0.ips.append(IPAddress.identify("fe80:600:88:200::10")) self.n.node(3).if0.ips.append(IPAddress.identify("2001:600:88:200::11")) self.n.node(3).if0.ips.append(IPAddress.identify("fe80:600:88:200::11")) self.n.node(4).if0.ips.append(IPAddress.identify("2001:700:88:200::10")) self.n.node(4).if0.ips.append(IPAddress.identify("fe80:700:88:200::10")) self.n.router(1).if0.ips.append(IPAddress.identify("2001:600:88:200::1")) self.n.router(1).if0.ips.append(IPAddress.identify("fe80:600:88:200::1")) self.n.router(1).if1.ips.append(IPAddress.identify("2001:500:88:200::1")) self.n.router(1).if1.ips.append(IPAddress.identify("fe80:500:88:200::1")) self.n.router(1)._TestRouter__forwards_to_0.append(Network("2001:0600:0088:0200::/64")) self.n.router(1)._TestRouter__forwards_to_1.append(Network("2001:0500:0088:0200::/64")) self.n.router(2).if0.ips.append(IPAddress.identify("2001:600:88:200::2")) self.n.router(2).if0.ips.append(IPAddress.identify("fe80:600:88:200::2")) self.n.router(2).if1.ips.append(IPAddress.identify("2001:500:88:200::2")) self.n.router(2).if1.ips.append(IPAddress.identify("fe80:500:88:200::2")) self.n.router(3).if0.ips.append(IPAddress.identify("2001:600:88:200::3")) self.n.router(3).if0.ips.append(IPAddress.identify("fe80:600:88:200::3")) self.n.router(3).if1.ips.append(IPAddress.identify("2001:500:88:200::3")) self.n.router(3).if1.ips.append(IPAddress.identify("fe80:500:88:200::3")) self.ethx_s = MockInterface('if0', '00:b0:d0:86:bb:f7') self.ethx_t = TargetInterface(ips=[IPAddress.identify("2001:500:88:200::20"), IPAddress.identify("fe80:500:88:200::20")], link_addr="00:b0:d0:bb:cc:ff") self.ethx = Tap(self.n.link(2), self.ethx_s, self.ethx_t) self.ethy_s = MockInterface('if1', '00:b0:e0:86:bb:f7') self.ethy_t = TargetInterface(ips=[IPAddress.identify("2001:600:88:200::20"), IPAddress.identify("fe80:600:88:200::20")], link_addr="00:b0:e0:bb:cc:ff") self.ethy = Tap(self.n.link(3), self.ethy_s, self.ethy_t)
class TestNetworkTestCase(unittest.TestCase): def setUp(self): self.n = TestNetwork(TestNetworkConfiguration()) self.n._TestNetwork__taps[0].unbind() self.n._TestNetwork__taps[1].unbind() self.n.node(1).if0.ips.append(IPAddress.identify("2001:500:88:200::10")) self.n.node(1).if0.ips.append(IPAddress.identify("fe80:500:88:200::10")) self.n.node(2).if0.ips.append(IPAddress.identify("2001:600:88:200::10")) self.n.node(2).if0.ips.append(IPAddress.identify("fe80:600:88:200::10")) self.n.node(3).if0.ips.append(IPAddress.identify("2001:600:88:200::11")) self.n.node(3).if0.ips.append(IPAddress.identify("fe80:600:88:200::11")) self.n.node(4).if0.ips.append(IPAddress.identify("2001:700:88:200::10")) self.n.node(4).if0.ips.append(IPAddress.identify("fe80:700:88:200::10")) self.n.router(1).if0.ips.append(IPAddress.identify("2001:600:88:200::1")) self.n.router(1).if0.ips.append(IPAddress.identify("fe80:600:88:200::1")) self.n.router(1).if1.ips.append(IPAddress.identify("2001:500:88:200::1")) self.n.router(1).if1.ips.append(IPAddress.identify("fe80:500:88:200::1")) self.n.router(1)._TestRouter__forwards_to_0.append(Network("2001:0600:0088:0200::/64")) self.n.router(1)._TestRouter__forwards_to_1.append(Network("2001:0500:0088:0200::/64")) self.n.router(2).if0.ips.append(IPAddress.identify("2001:600:88:200::2")) self.n.router(2).if0.ips.append(IPAddress.identify("fe80:600:88:200::2")) self.n.router(2).if1.ips.append(IPAddress.identify("2001:500:88:200::2")) self.n.router(2).if1.ips.append(IPAddress.identify("fe80:500:88:200::2")) self.n.router(3).if0.ips.append(IPAddress.identify("2001:600:88:200::3")) self.n.router(3).if0.ips.append(IPAddress.identify("fe80:600:88:200::3")) self.n.router(3).if1.ips.append(IPAddress.identify("2001:500:88:200::3")) self.n.router(3).if1.ips.append(IPAddress.identify("fe80:500:88:200::3")) self.ethx_s = MockInterface("if0", "00:b0:d0:86:bb:f7") self.ethx_t = TargetInterface( ips=[IPAddress.identify("2001:500:88:200::20"), IPAddress.identify("fe80:500:88:200::20")], link_addr="00:b0:d0:bb:cc:ff", ) self.ethx = Tap(self.n.link(2), self.ethx_s, self.ethx_t) self.ethy_s = MockInterface("if1", "00:b0:e0:86:bb:f7") self.ethy_t = TargetInterface( ips=[IPAddress.identify("2001:600:88:200::20"), IPAddress.identify("fe80:600:88:200::20")], link_addr="00:b0:e0:bb:cc:ff", ) self.ethy = Tap(self.n.link(3), self.ethy_s, self.ethy_t) def test_it_should_deliver_a_packet_from_tn1_on_ethx(self): self.n.node(1).send( IPv6(src=str(self.n.node(1).global_ip()), dst=str(self.ethx_t.global_ip())) / ICMPv6EchoRequest() ) self.assertEqual(1, len(self.ethx_s.sent)) p = self.ethx_s.sent[0] self.assertTrue(p.haslayer(Ether)) self.assertEqual("00:b0:d0:86:bb:f7", p.getlayer(Ether).src) self.assertEqual("00:b0:d0:bb:cc:ff", p.getlayer(Ether).dst) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.n.node(1).global_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.ethx_t.global_ip().short_form(), p.getlayer(IPv6).dst) self.assertTrue(self.ethx_s.sent[0].haslayer(ICMPv6EchoRequest)) def test_it_should_deliver_a_link_local_packet_from_tn1_to_ethx(self): self.n.node(1).send( IPv6(src=str(self.n.node(1).link_local_ip()), dst=str(self.ethx_t.link_local_ip())) / ICMPv6EchoRequest() ) self.assertEqual(1, len(self.ethx_s.sent)) p = self.ethx_s.sent[0] self.assertTrue(p.haslayer(Ether)) self.assertEqual("00:b0:d0:86:bb:f7", p.getlayer(Ether).src) self.assertEqual("00:b0:d0:bb:cc:ff", p.getlayer(Ether).dst) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.n.node(1).link_local_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.ethx_t.link_local_ip().short_form(), p.getlayer(IPv6).dst) self.assertTrue(self.ethx_s.sent[0].haslayer(ICMPv6EchoRequest)) def test_it_should_not_deliver_a_packet_from_tn1_on_ethy(self): self.n.node(1).send( IPv6(src=str(self.n.node(1).link_local_ip()), dst=str(self.ethx_t.link_local_ip())) / ICMPv6EchoRequest() ) self.assertEqual(0, len(self.ethy_s.sent)) def test_it_should_deliver_a_packet_from_tn2_on_ethx(self): self.n.node(2).send( IPv6(src=str(self.n.node(2).global_ip()), dst=str(self.ethx_t.global_ip())) / ICMPv6EchoRequest() ) self.assertEqual(1, len(self.ethx_s.sent)) p = self.ethx_s.sent[0] self.assertTrue(p.haslayer(Ether)) self.assertEqual("00:b0:d0:86:bb:f7", p.getlayer(Ether).src) self.assertEqual("00:b0:d0:bb:cc:ff", p.getlayer(Ether).dst) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.n.node(2).global_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.ethx_t.global_ip().short_form(), p.getlayer(IPv6).dst) def test_it_should_not_deliver_a_link_local_packet_from_tn2_on_ethx(self): self.n.node(2).send( IPv6(src=str(self.n.node(2).link_local_ip()), dst=str(self.ethx_t.link_local_ip())) / ICMPv6EchoRequest() ) self.assertEqual(0, len(self.ethx_s.sent)) def test_it_should_not_deliver_a_packet_from_tn2_on_ethy(self): self.n.node(2).send( IPv6(src=str(self.n.node(2).link_local_ip()), dst=str(self.ethx_t.link_local_ip())) / ICMPv6EchoRequest() ) self.assertEqual(0, len(self.ethy_s.sent)) def test_it_should_deliver_a_packet_from_tn3_on_ethx(self): self.n.node(3).send( IPv6(src=str(self.n.node(3).global_ip()), dst=str(self.ethx_t.global_ip())) / ICMPv6EchoRequest() ) self.assertEqual(1, len(self.ethx_s.sent)) p = self.ethx_s.sent[0] self.assertTrue(p.haslayer(Ether)) self.assertEqual("00:b0:d0:86:bb:f7", p.getlayer(Ether).src) self.assertEqual("00:b0:d0:bb:cc:ff", p.getlayer(Ether).dst) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.n.node(3).global_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.ethx_t.global_ip().short_form(), p.getlayer(IPv6).dst) def test_it_should_not_deliver_a_link_local_packet_from_tn3_on_ethx(self): self.n.node(3).send( IPv6(src=str(self.n.node(3).link_local_ip()), dst=str(self.ethx_t.link_local_ip())) / ICMPv6EchoRequest() ) self.assertEqual(0, len(self.ethx_s.sent)) def test_it_should_not_deliver_a_packet_from_tn3_on_ethy(self): self.n.node(3).send( IPv6(src=str(self.n.node(3).link_local_ip()), dst=str(self.ethx_t.link_local_ip())) / ICMPv6EchoRequest() ) self.assertEqual(0, len(self.ethy_s.sent)) def test_it_should_deliver_a_packet_from_tn4_on_ethy(self): self.n.node(4).send( IPv6(src=str(self.n.node(4).global_ip()), dst=str(self.ethy_t.global_ip())) / ICMPv6EchoRequest() ) self.assertEqual(1, len(self.ethy_s.sent)) p = self.ethy_s.sent[0] self.assertTrue(p.haslayer(Ether)) self.assertEqual("00:b0:e0:86:bb:f7", p.getlayer(Ether).src) self.assertEqual("00:b0:e0:bb:cc:ff", p.getlayer(Ether).dst) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.n.node(4).global_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.ethy_t.global_ip().short_form(), p.getlayer(IPv6).dst) def test_it_should_deliver_a_link_local_packet_from_tn4_on_ethy(self): self.n.node(4).send( IPv6(src=str(self.n.node(4).link_local_ip()), dst=str(self.ethy_t.link_local_ip())) / ICMPv6EchoRequest() ) self.assertEqual(1, len(self.ethy_s.sent)) p = self.ethy_s.sent[0] self.assertTrue(p.haslayer(Ether)) self.assertEqual("00:b0:e0:86:bb:f7", p.getlayer(Ether).src) self.assertEqual("00:b0:e0:bb:cc:ff", p.getlayer(Ether).dst) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.n.node(4).link_local_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.ethy_t.link_local_ip().short_form(), p.getlayer(IPv6).dst) def test_it_should_not_deliver_a_packet_from_tn4_on_ethx(self): self.n.node(4).send( IPv6(src=str(self.n.node(4).global_ip()), dst=str(self.ethy_t.global_ip())) / ICMPv6EchoRequest() ) self.assertEqual(0, len(self.ethx_s.sent)) def test_it_should_deliver_a_packet_from_tr1_on_ethx(self): self.n.router(1).send( IPv6(src=str(self.n.router(1).global_ip()), dst=str(self.ethx_t.global_ip())) / ICMPv6EchoRequest(), iface=1 ) self.assertEqual(1, len(self.ethx_s.sent)) p = self.ethx_s.sent[0] self.assertTrue(p.haslayer(Ether)) self.assertEqual("00:b0:d0:86:bb:f7", p.getlayer(Ether).src) self.assertEqual("00:b0:d0:bb:cc:ff", p.getlayer(Ether).dst) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.n.router(1).global_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.ethx_t.global_ip().short_form(), p.getlayer(IPv6).dst) def test_it_should_deliver_a_link_local_packet_from_tr1_on_ethx(self): self.n.router(1).send( IPv6(src=str(self.n.router(1).link_local_ip()), dst=str(self.ethx_t.link_local_ip())) / ICMPv6EchoRequest(), iface=1, ) self.assertEqual(1, len(self.ethx_s.sent)) p = self.ethx_s.sent[0] self.assertTrue(p.haslayer(Ether)) self.assertEqual("00:b0:d0:86:bb:f7", p.getlayer(Ether).src) self.assertEqual("00:b0:d0:bb:cc:ff", p.getlayer(Ether).dst) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.n.router(1).link_local_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.ethx_t.link_local_ip().short_form(), p.getlayer(IPv6).dst) def test_it_should_not_deliver_a_packet_from_tr1_if0_to_ethx(self): self.n.router(1).send( IPv6(src=str(self.n.router(1).global_ip()), dst=str(self.ethx_t.global_ip())) / ICMPv6EchoRequest(), iface=0 ) self.assertEqual(0, len(self.ethx_s.sent)) def test_it_should_not_deliver_a_packet_from_tr1_on_ethy(self): self.n.router(1).send( IPv6(src=str(self.n.router(1).link_local_ip(iface=1)), dst=str(self.ethx_t.link_local_ip())) / ICMPv6EchoRequest(), iface=1, ) self.assertEqual(0, len(self.ethy_s.sent)) def test_it_should_deliver_a_packet_from_tr2_on_ethx(self): self.n.router(2).send( IPv6(src=str(self.n.router(2).link_local_ip(iface=1)), dst=str(self.ethx_t.link_local_ip())) / ICMPv6EchoRequest(), iface=1, ) self.assertEqual(0, len(self.ethy_s.sent)) def test_it_should_deliver_a_packet_from_tr3_on_ethx(self): self.n.router(3).send( IPv6(src=str(self.n.router(3).link_local_ip(iface=1)), dst=str(self.ethx_t.link_local_ip())) / ICMPv6EchoRequest(), iface=1, ) self.assertEqual(1, len(self.ethx_s.sent)) def test_it_should_deliver_a_packet_from_ethx_to_tn1(self): self.ethx_s.accept( IPv6(src=str(self.ethx_t.global_ip()), dst=str(self.n.node(1).global_ip())) / ICMPv6EchoReply() ) self.assertEqual(1, len(self.n.node(1).received())) p = self.n.node(1).received()[0] self.assertFalse(p.haslayer(Ether)) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.ethx_t.global_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.n.node(1).global_ip().short_form(), p.getlayer(IPv6).dst) def test_it_should_deliver_a_link_local_packet_from_ethx_to_tn1(self): self.ethx_s.accept( IPv6(src=str(self.ethx_t.link_local_ip()), dst=str(self.n.node(1).link_local_ip())) / ICMPv6EchoReply() ) self.assertEqual(1, len(self.n.node(1).received())) p = self.n.node(1).received()[0] self.assertFalse(p.haslayer(Ether)) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.ethx_t.link_local_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.n.node(1).link_local_ip().short_form(), p.getlayer(IPv6).dst) def test_it_should_not_deliver_a_packet_from_ethy_to_tn1(self): self.ethy_s.accept( IPv6(src=str(self.ethx_t.global_ip()), dst=str(self.n.node(1).global_ip())) / ICMPv6EchoReply() ) self.assertEqual(0, len(self.n.node(1).received())) def test_it_should_deliver_a_packet_from_ethx_to_tn2(self): self.ethx_s.accept( IPv6(src=str(self.ethx_t.global_ip()), dst=str(self.n.node(2).global_ip())) / ICMPv6EchoReply() ) self.assertEqual(1, len(self.n.node(2).received())) p = self.n.node(2).received()[0] self.assertFalse(p.haslayer(Ether)) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.ethx_t.global_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.n.node(2).global_ip().short_form(), p.getlayer(IPv6).dst) def test_it_should_not_deliver_a_link_local_packet_from_ethx_to_tn2(self): self.ethx_s.accept( IPv6(src=str(self.ethx_t.link_local_ip()), dst=str(self.n.node(2).link_local_ip())) / ICMPv6EchoReply() ) self.assertEqual(0, len(self.n.node(2).received())) def test_it_should_not_deliver_a_packet_from_ethy_to_tn2(self): self.ethy_s.accept( IPv6(src=str(self.ethx_t.global_ip()), dst=str(self.n.node(2).global_ip())) / ICMPv6EchoReply() ) self.assertEqual(0, len(self.n.node(2).received())) def test_it_should_deliver_a_packet_from_ethx_to_tn3(self): self.ethx_s.accept( IPv6(src=str(self.ethx_t.global_ip()), dst=str(self.n.node(3).global_ip())) / ICMPv6EchoReply() ) self.assertEqual(1, len(self.n.node(3).received())) p = self.n.node(3).received()[0] self.assertFalse(p.haslayer(Ether)) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.ethx_t.global_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.n.node(3).global_ip().short_form(), p.getlayer(IPv6).dst) def test_it_should_not_deliver_a_link_local_packet_from_ethx_to_tn3(self): self.ethx_s.accept( IPv6(src=str(self.ethx_t.link_local_ip()), dst=str(self.n.node(3).link_local_ip())) / ICMPv6EchoReply() ) self.assertEqual(0, len(self.n.node(3).received())) def test_it_should_not_deliver_a_packet_from_ethy_to_tn3(self): self.ethy_s.accept( IPv6(src=str(self.ethx_t.global_ip()), dst=str(self.n.node(3).global_ip())) / ICMPv6EchoReply() ) self.assertEqual(0, len(self.n.node(3).received())) def test_it_should_deliver_a_packet_from_ethy_to_tn4(self): self.ethy_s.accept( IPv6(src=str(self.ethy_t.global_ip()), dst=str(self.n.node(4).global_ip())) / ICMPv6EchoReply() ) self.assertEqual(1, len(self.n.node(4).received())) p = self.n.node(4).received()[0] self.assertFalse(p.haslayer(Ether)) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.ethy_t.global_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.n.node(4).global_ip().short_form(), p.getlayer(IPv6).dst) def test_it_should_deliver_a_link_local_packet_from_ethy_to_tn4(self): self.ethy_s.accept( IPv6(src=str(self.ethy_t.link_local_ip()), dst=str(self.n.node(4).link_local_ip())) / ICMPv6EchoReply() ) self.assertEqual(1, len(self.n.node(4).received())) p = self.n.node(4).received()[0] self.assertFalse(p.haslayer(Ether)) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.ethy_t.link_local_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.n.node(4).link_local_ip().short_form(), p.getlayer(IPv6).dst) def test_it_should_not_deliver_a_packet_from_ethx_to_tn4(self): self.ethx_s.accept( IPv6(src=str(self.ethy_t.global_ip()), dst=str(self.n.node(4).global_ip())) / ICMPv6EchoReply() ) self.assertEqual(0, len(self.n.node(4).received())) def test_it_should_deliver_a_packet_from_ethx_to_tr1(self): self.ethx_s.accept( IPv6(src=str(self.ethx_t.global_ip()), dst=str(self.n.router(1).global_ip(iface=1))) / ICMPv6EchoReply() ) self.assertEqual(1, len(self.n.router(1).received(iface=1))) p = self.n.router(1).received(iface=1)[0] self.assertFalse(p.haslayer(Ether)) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.ethx_t.global_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.n.router(1).global_ip(iface=1).short_form(), p.getlayer(IPv6).dst) def test_it_should_deliver_a_link_local_packet_from_ethx_to_tr1(self): self.ethx_s.accept( IPv6(src=str(self.ethx_t.link_local_ip()), dst=str(self.n.router(1).link_local_ip(iface=1))) / ICMPv6EchoReply() ) self.assertEqual(1, len(self.n.router(1).received(iface=1))) p = self.n.router(1).received(iface=1)[0] self.assertFalse(p.haslayer(Ether)) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.ethx_t.link_local_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.n.router(1).link_local_ip(iface=1).short_form(), p.getlayer(IPv6).dst) def test_it_should_not_deliver_a_packet_from_ethy_to_tr1(self): self.ethy_s.accept( IPv6(src=str(self.ethx_t.global_ip()), dst=str(self.n.router(1).global_ip(iface=1))) / ICMPv6EchoReply() ) self.assertEqual(0, len(self.n.router(1).received())) def test_it_should_deliver_a_packet_from_ethx_to_tr2(self): self.ethx_s.accept( IPv6(src=str(self.ethx_t.global_ip()), dst=str(self.n.router(2).global_ip(iface=1))) / ICMPv6EchoReply() ) self.assertEqual(1, len(self.n.router(2).received(iface=1))) def test_it_should_deliver_a_packet_from_ethx_to_tr3(self): self.ethx_s.accept( IPv6(src=str(self.ethx_t.global_ip()), dst=str(self.n.router(3).global_ip(iface=1))) / ICMPv6EchoReply() ) self.assertEqual(1, len(self.n.router(3).received(iface=1)))
def setUp(self): self.test_network = TestNetwork(TestNetworkConfiguration()) # replace the network taps with mocked taps, referencing mocked network # and target interfaces self.test_network._TestNetwork__taps[0].unbind() self.test_network._TestNetwork__taps[1].unbind() self.t1 = self.test_network._TestNetwork__taps[0] = MockTap( self.test_network.link(2), MockInterface('if0', 'be:ef:ca:fe:09:01'), MockTargetInterface(ips=["2001:800:88:200::50", "fe80::50"], ll_protocol='Ethernet', link_addr='be:ef:ba:be:09:01')) self.t2 = self.test_network._TestNetwork__taps[1] = MockTap( self.test_network.link(3), MockInterface('if1', 'be:ef:ca:fe:09:02'), MockTargetInterface(ips=["2001:900:88:200::50", "fe80::51"], ll_protocol='Ethernet', link_addr='be:ef:ba:be:09:02')) # grab references to the target interfaces and internal nodes for easy # reference throughout a test case self.ifx = self.test_network.tap(1).target_iface self.ify = self.test_network.tap(2).target_iface self.tn1 = self.test_network.node(1) self.tn2 = self.test_network.node(2) self.tn3 = self.test_network.node(3) self.tn4 = self.test_network.node(4) self.tr1 = self.test_network.router(1) # TODO: tr2 and tr3 def _received_on_tn1(iface=0, src=None, dst=None, lbda=None, seq=None, type=None, timeout=5): return self.tn1.iface(iface).received( src=src, dst=dst == None and self.tn1.ip(iface=iface, offset='*', scope='*', type='*') or dst, lbda=lbda, seq=None, type=type) def _received_on_tn2(iface=0, src=None, dst=None, lbda=None, seq=None, type=None, timeout=5): return self.tn2.iface(iface).received( src=src, dst=dst == None and self.tn2.ip(iface=iface, offset='*', scope='*', type='*') or dst, lbda=lbda, seq=None, type=type) def _received_on_tn3(iface=0, src=None, dst=None, lbda=None, seq=None, type=None, timeout=5): return self.tn3.iface(iface).received( src=src, dst=dst == None and self.tn3.ip(iface=iface, offset='*', scope='*', type='*') or dst, lbda=lbda, seq=None, type=type) def _received_on_tn4(iface=0, src=None, dst=None, lbda=None, seq=None, type=None, timeout=5): return self.tn4.iface(iface).received( src=src, dst=dst == None and self.tn4.ip(iface=iface, offset='*', scope='*', type='*') or dst, lbda=lbda, seq=None, type=type) # override the #received() method on each of the TRs and TNs, to remove # the delay introduced self.tn1.received = _received_on_tn1 self.tn2.received = _received_on_tn2 self.tn3.received = _received_on_tn3 self.tn4.received = _received_on_tn4 self.ui = MockCallbacks(None) self.ui.test_network = self.test_network
class TestNetworkTestCase(unittest.TestCase): def setUp(self): self.n = TestNetwork(TestNetworkConfiguration()) self.n._TestNetwork__taps[0].unbind() self.n._TestNetwork__taps[1].unbind() self.n.node(1).if0.ips.append(IPAddress.identify("2001:500:88:200::10")) self.n.node(1).if0.ips.append(IPAddress.identify("fe80:500:88:200::10")) self.n.node(2).if0.ips.append(IPAddress.identify("2001:600:88:200::10")) self.n.node(2).if0.ips.append(IPAddress.identify("fe80:600:88:200::10")) self.n.node(3).if0.ips.append(IPAddress.identify("2001:600:88:200::11")) self.n.node(3).if0.ips.append(IPAddress.identify("fe80:600:88:200::11")) self.n.node(4).if0.ips.append(IPAddress.identify("2001:700:88:200::10")) self.n.node(4).if0.ips.append(IPAddress.identify("fe80:700:88:200::10")) self.n.router(1).if0.ips.append(IPAddress.identify("2001:600:88:200::1")) self.n.router(1).if0.ips.append(IPAddress.identify("fe80:600:88:200::1")) self.n.router(1).if1.ips.append(IPAddress.identify("2001:500:88:200::1")) self.n.router(1).if1.ips.append(IPAddress.identify("fe80:500:88:200::1")) self.n.router(1)._TestRouter__forwards_to_0.append(Network("2001:0600:0088:0200::/64")) self.n.router(1)._TestRouter__forwards_to_1.append(Network("2001:0500:0088:0200::/64")) self.n.router(2).if0.ips.append(IPAddress.identify("2001:600:88:200::2")) self.n.router(2).if0.ips.append(IPAddress.identify("fe80:600:88:200::2")) self.n.router(2).if1.ips.append(IPAddress.identify("2001:500:88:200::2")) self.n.router(2).if1.ips.append(IPAddress.identify("fe80:500:88:200::2")) self.n.router(3).if0.ips.append(IPAddress.identify("2001:600:88:200::3")) self.n.router(3).if0.ips.append(IPAddress.identify("fe80:600:88:200::3")) self.n.router(3).if1.ips.append(IPAddress.identify("2001:500:88:200::3")) self.n.router(3).if1.ips.append(IPAddress.identify("fe80:500:88:200::3")) self.ethx_s = MockInterface('if0', '00:b0:d0:86:bb:f7') self.ethx_t = TargetInterface(ips=[IPAddress.identify("2001:500:88:200::20"), IPAddress.identify("fe80:500:88:200::20")], link_addr="00:b0:d0:bb:cc:ff") self.ethx = Tap(self.n.link(2), self.ethx_s, self.ethx_t) self.ethy_s = MockInterface('if1', '00:b0:e0:86:bb:f7') self.ethy_t = TargetInterface(ips=[IPAddress.identify("2001:600:88:200::20"), IPAddress.identify("fe80:600:88:200::20")], link_addr="00:b0:e0:bb:cc:ff") self.ethy = Tap(self.n.link(3), self.ethy_s, self.ethy_t) def test_it_should_deliver_a_packet_from_tn1_on_ethx(self): self.n.node(1).send(IPv6(src=str(self.n.node(1).global_ip()), dst=str(self.ethx_t.global_ip()))/ICMPv6EchoRequest()) self.assertEqual(1, len(self.ethx_s.sent)) p = self.ethx_s.sent[0] self.assertTrue(p.haslayer(Ether)) self.assertEqual('00:b0:d0:86:bb:f7', p.getlayer(Ether).src) self.assertEqual('00:b0:d0:bb:cc:ff', p.getlayer(Ether).dst) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.n.node(1).global_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.ethx_t.global_ip().short_form(), p.getlayer(IPv6).dst) self.assertTrue(self.ethx_s.sent[0].haslayer(ICMPv6EchoRequest)) def test_it_should_deliver_a_link_local_packet_from_tn1_to_ethx(self): self.n.node(1).send(IPv6(src=str(self.n.node(1).link_local_ip()), dst=str(self.ethx_t.link_local_ip()))/ICMPv6EchoRequest()) self.assertEqual(1, len(self.ethx_s.sent)) p = self.ethx_s.sent[0] self.assertTrue(p.haslayer(Ether)) self.assertEqual('00:b0:d0:86:bb:f7', p.getlayer(Ether).src) self.assertEqual('00:b0:d0:bb:cc:ff', p.getlayer(Ether).dst) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.n.node(1).link_local_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.ethx_t.link_local_ip().short_form(), p.getlayer(IPv6).dst) self.assertTrue(self.ethx_s.sent[0].haslayer(ICMPv6EchoRequest)) def test_it_should_not_deliver_a_packet_from_tn1_on_ethy(self): self.n.node(1).send(IPv6(src=str(self.n.node(1).link_local_ip()), dst=str(self.ethx_t.link_local_ip()))/ICMPv6EchoRequest()) self.assertEqual(0, len(self.ethy_s.sent)) def test_it_should_deliver_a_packet_from_tn2_on_ethx(self): self.n.node(2).send(IPv6(src=str(self.n.node(2).global_ip()), dst=str(self.ethx_t.global_ip()))/ICMPv6EchoRequest()) self.assertEqual(1, len(self.ethx_s.sent)) p = self.ethx_s.sent[0] self.assertTrue(p.haslayer(Ether)) self.assertEqual('00:b0:d0:86:bb:f7', p.getlayer(Ether).src) self.assertEqual('00:b0:d0:bb:cc:ff', p.getlayer(Ether).dst) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.n.node(2).global_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.ethx_t.global_ip().short_form(), p.getlayer(IPv6).dst) def test_it_should_not_deliver_a_link_local_packet_from_tn2_on_ethx(self): self.n.node(2).send(IPv6(src=str(self.n.node(2).link_local_ip()), dst=str(self.ethx_t.link_local_ip()))/ICMPv6EchoRequest()) self.assertEqual(0, len(self.ethx_s.sent)) def test_it_should_not_deliver_a_packet_from_tn2_on_ethy(self): self.n.node(2).send(IPv6(src=str(self.n.node(2).link_local_ip()), dst=str(self.ethx_t.link_local_ip()))/ICMPv6EchoRequest()) self.assertEqual(0, len(self.ethy_s.sent)) def test_it_should_deliver_a_packet_from_tn3_on_ethx(self): self.n.node(3).send(IPv6(src=str(self.n.node(3).global_ip()), dst=str(self.ethx_t.global_ip()))/ICMPv6EchoRequest()) self.assertEqual(1, len(self.ethx_s.sent)) p = self.ethx_s.sent[0] self.assertTrue(p.haslayer(Ether)) self.assertEqual('00:b0:d0:86:bb:f7', p.getlayer(Ether).src) self.assertEqual('00:b0:d0:bb:cc:ff', p.getlayer(Ether).dst) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.n.node(3).global_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.ethx_t.global_ip().short_form(), p.getlayer(IPv6).dst) def test_it_should_not_deliver_a_link_local_packet_from_tn3_on_ethx(self): self.n.node(3).send(IPv6(src=str(self.n.node(3).link_local_ip()), dst=str(self.ethx_t.link_local_ip()))/ICMPv6EchoRequest()) self.assertEqual(0, len(self.ethx_s.sent)) def test_it_should_not_deliver_a_packet_from_tn3_on_ethy(self): self.n.node(3).send(IPv6(src=str(self.n.node(3).link_local_ip()), dst=str(self.ethx_t.link_local_ip()))/ICMPv6EchoRequest()) self.assertEqual(0, len(self.ethy_s.sent)) def test_it_should_deliver_a_packet_from_tn4_on_ethy(self): self.n.node(4).send(IPv6(src=str(self.n.node(4).global_ip()), dst=str(self.ethy_t.global_ip()))/ICMPv6EchoRequest()) self.assertEqual(1, len(self.ethy_s.sent)) p = self.ethy_s.sent[0] self.assertTrue(p.haslayer(Ether)) self.assertEqual('00:b0:e0:86:bb:f7', p.getlayer(Ether).src) self.assertEqual('00:b0:e0:bb:cc:ff', p.getlayer(Ether).dst) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.n.node(4).global_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.ethy_t.global_ip().short_form(), p.getlayer(IPv6).dst) def test_it_should_deliver_a_link_local_packet_from_tn4_on_ethy(self): self.n.node(4).send(IPv6(src=str(self.n.node(4).link_local_ip()), dst=str(self.ethy_t.link_local_ip()))/ICMPv6EchoRequest()) self.assertEqual(1, len(self.ethy_s.sent)) p = self.ethy_s.sent[0] self.assertTrue(p.haslayer(Ether)) self.assertEqual('00:b0:e0:86:bb:f7', p.getlayer(Ether).src) self.assertEqual('00:b0:e0:bb:cc:ff', p.getlayer(Ether).dst) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.n.node(4).link_local_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.ethy_t.link_local_ip().short_form(), p.getlayer(IPv6).dst) def test_it_should_not_deliver_a_packet_from_tn4_on_ethx(self): self.n.node(4).send(IPv6(src=str(self.n.node(4).global_ip()), dst=str(self.ethy_t.global_ip()))/ICMPv6EchoRequest()) self.assertEqual(0, len(self.ethx_s.sent)) def test_it_should_deliver_a_packet_from_tr1_on_ethx(self): self.n.router(1).send(IPv6(src=str(self.n.router(1).global_ip()), dst=str(self.ethx_t.global_ip()))/ICMPv6EchoRequest(), iface=1) self.assertEqual(1, len(self.ethx_s.sent)) p = self.ethx_s.sent[0] self.assertTrue(p.haslayer(Ether)) self.assertEqual('00:b0:d0:86:bb:f7', p.getlayer(Ether).src) self.assertEqual('00:b0:d0:bb:cc:ff', p.getlayer(Ether).dst) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.n.router(1).global_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.ethx_t.global_ip().short_form(), p.getlayer(IPv6).dst) def test_it_should_deliver_a_link_local_packet_from_tr1_on_ethx(self): self.n.router(1).send(IPv6(src=str(self.n.router(1).link_local_ip()), dst=str(self.ethx_t.link_local_ip()))/ICMPv6EchoRequest(), iface=1) self.assertEqual(1, len(self.ethx_s.sent)) p = self.ethx_s.sent[0] self.assertTrue(p.haslayer(Ether)) self.assertEqual('00:b0:d0:86:bb:f7', p.getlayer(Ether).src) self.assertEqual('00:b0:d0:bb:cc:ff', p.getlayer(Ether).dst) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.n.router(1).link_local_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.ethx_t.link_local_ip().short_form(), p.getlayer(IPv6).dst) def test_it_should_not_deliver_a_packet_from_tr1_if0_to_ethx(self): self.n.router(1).send(IPv6(src=str(self.n.router(1).global_ip()), dst=str(self.ethx_t.global_ip()))/ICMPv6EchoRequest(), iface=0) self.assertEqual(0, len(self.ethx_s.sent)) def test_it_should_not_deliver_a_packet_from_tr1_on_ethy(self): self.n.router(1).send(IPv6(src=str(self.n.router(1).link_local_ip(iface=1)), dst=str(self.ethx_t.link_local_ip()))/ICMPv6EchoRequest(), iface=1) self.assertEqual(0, len(self.ethy_s.sent)) def test_it_should_deliver_a_packet_from_tr2_on_ethx(self): self.n.router(2).send(IPv6(src=str(self.n.router(2).link_local_ip(iface=1)), dst=str(self.ethx_t.link_local_ip()))/ICMPv6EchoRequest(), iface=1) self.assertEqual(0, len(self.ethy_s.sent)) def test_it_should_deliver_a_packet_from_tr3_on_ethx(self): self.n.router(3).send(IPv6(src=str(self.n.router(3).link_local_ip(iface=1)), dst=str(self.ethx_t.link_local_ip()))/ICMPv6EchoRequest(), iface=1) self.assertEqual(1, len(self.ethx_s.sent)) def test_it_should_deliver_a_packet_from_ethx_to_tn1(self): self.ethx_s.accept(IPv6(src=str(self.ethx_t.global_ip()), dst=str(self.n.node(1).global_ip()))/ICMPv6EchoReply()) self.assertEqual(1, len(self.n.node(1).received())) p = self.n.node(1).received()[0] self.assertFalse(p.haslayer(Ether)) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.ethx_t.global_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.n.node(1).global_ip().short_form(), p.getlayer(IPv6).dst) def test_it_should_deliver_a_link_local_packet_from_ethx_to_tn1(self): self.ethx_s.accept(IPv6(src=str(self.ethx_t.link_local_ip()), dst=str(self.n.node(1).link_local_ip()))/ICMPv6EchoReply()) self.assertEqual(1, len(self.n.node(1).received())) p = self.n.node(1).received()[0] self.assertFalse(p.haslayer(Ether)) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.ethx_t.link_local_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.n.node(1).link_local_ip().short_form(), p.getlayer(IPv6).dst) def test_it_should_not_deliver_a_packet_from_ethy_to_tn1(self): self.ethy_s.accept(IPv6(src=str(self.ethx_t.global_ip()), dst=str(self.n.node(1).global_ip()))/ICMPv6EchoReply()) self.assertEqual(0, len(self.n.node(1).received())) def test_it_should_deliver_a_packet_from_ethx_to_tn2(self): self.ethx_s.accept(IPv6(src=str(self.ethx_t.global_ip()), dst=str(self.n.node(2).global_ip()))/ICMPv6EchoReply()) self.assertEqual(1, len(self.n.node(2).received())) p = self.n.node(2).received()[0] self.assertFalse(p.haslayer(Ether)) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.ethx_t.global_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.n.node(2).global_ip().short_form(), p.getlayer(IPv6).dst) def test_it_should_not_deliver_a_link_local_packet_from_ethx_to_tn2(self): self.ethx_s.accept(IPv6(src=str(self.ethx_t.link_local_ip()), dst=str(self.n.node(2).link_local_ip()))/ICMPv6EchoReply()) self.assertEqual(0, len(self.n.node(2).received())) def test_it_should_not_deliver_a_packet_from_ethy_to_tn2(self): self.ethy_s.accept(IPv6(src=str(self.ethx_t.global_ip()), dst=str(self.n.node(2).global_ip()))/ICMPv6EchoReply()) self.assertEqual(0, len(self.n.node(2).received())) def test_it_should_deliver_a_packet_from_ethx_to_tn3(self): self.ethx_s.accept(IPv6(src=str(self.ethx_t.global_ip()), dst=str(self.n.node(3).global_ip()))/ICMPv6EchoReply()) self.assertEqual(1, len(self.n.node(3).received())) p = self.n.node(3).received()[0] self.assertFalse(p.haslayer(Ether)) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.ethx_t.global_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.n.node(3).global_ip().short_form(), p.getlayer(IPv6).dst) def test_it_should_not_deliver_a_link_local_packet_from_ethx_to_tn3(self): self.ethx_s.accept(IPv6(src=str(self.ethx_t.link_local_ip()), dst=str(self.n.node(3).link_local_ip()))/ICMPv6EchoReply()) self.assertEqual(0, len(self.n.node(3).received())) def test_it_should_not_deliver_a_packet_from_ethy_to_tn3(self): self.ethy_s.accept(IPv6(src=str(self.ethx_t.global_ip()), dst=str(self.n.node(3).global_ip()))/ICMPv6EchoReply()) self.assertEqual(0, len(self.n.node(3).received())) def test_it_should_deliver_a_packet_from_ethy_to_tn4(self): self.ethy_s.accept(IPv6(src=str(self.ethy_t.global_ip()), dst=str(self.n.node(4).global_ip()))/ICMPv6EchoReply()) self.assertEqual(1, len(self.n.node(4).received())) p = self.n.node(4).received()[0] self.assertFalse(p.haslayer(Ether)) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.ethy_t.global_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.n.node(4).global_ip().short_form(), p.getlayer(IPv6).dst) def test_it_should_deliver_a_link_local_packet_from_ethy_to_tn4(self): self.ethy_s.accept(IPv6(src=str(self.ethy_t.link_local_ip()), dst=str(self.n.node(4).link_local_ip()))/ICMPv6EchoReply()) self.assertEqual(1, len(self.n.node(4).received())) p = self.n.node(4).received()[0] self.assertFalse(p.haslayer(Ether)) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.ethy_t.link_local_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.n.node(4).link_local_ip().short_form(), p.getlayer(IPv6).dst) def test_it_should_not_deliver_a_packet_from_ethx_to_tn4(self): self.ethx_s.accept(IPv6(src=str(self.ethy_t.global_ip()), dst=str(self.n.node(4).global_ip()))/ICMPv6EchoReply()) self.assertEqual(0, len(self.n.node(4).received())) def test_it_should_deliver_a_packet_from_ethx_to_tr1(self): self.ethx_s.accept(IPv6(src=str(self.ethx_t.global_ip()), dst=str(self.n.router(1).global_ip(iface=1)))/ICMPv6EchoReply()) self.assertEqual(1, len(self.n.router(1).received(iface=1))) p = self.n.router(1).received(iface=1)[0] self.assertFalse(p.haslayer(Ether)) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.ethx_t.global_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.n.router(1).global_ip(iface=1).short_form(), p.getlayer(IPv6).dst) def test_it_should_deliver_a_link_local_packet_from_ethx_to_tr1(self): self.ethx_s.accept(IPv6(src=str(self.ethx_t.link_local_ip()), dst=str(self.n.router(1).link_local_ip(iface=1)))/ICMPv6EchoReply()) self.assertEqual(1, len(self.n.router(1).received(iface=1))) p = self.n.router(1).received(iface=1)[0] self.assertFalse(p.haslayer(Ether)) self.assertTrue(p.haslayer(IPv6)) self.assertEqual(self.ethx_t.link_local_ip().short_form(), p.getlayer(IPv6).src) self.assertEqual(self.n.router(1).link_local_ip(iface=1).short_form(), p.getlayer(IPv6).dst) def test_it_should_not_deliver_a_packet_from_ethy_to_tr1(self): self.ethy_s.accept(IPv6(src=str(self.ethx_t.global_ip()), dst=str(self.n.router(1).global_ip(iface=1)))/ICMPv6EchoReply()) self.assertEqual(0, len(self.n.router(1).received())) def test_it_should_deliver_a_packet_from_ethx_to_tr2(self): self.ethx_s.accept(IPv6(src=str(self.ethx_t.global_ip()), dst=str(self.n.router(2).global_ip(iface=1)))/ICMPv6EchoReply()) self.assertEqual(1, len(self.n.router(2).received(iface=1))) def test_it_should_deliver_a_packet_from_ethx_to_tr3(self): self.ethx_s.accept(IPv6(src=str(self.ethx_t.global_ip()), dst=str(self.n.router(3).global_ip(iface=1)))/ICMPv6EchoReply()) self.assertEqual(1, len(self.n.router(3).received(iface=1)))
def setUp(self): self.phy = MockInterface( OSInterfaceAdapter.get_physical_interfaces()[0], None)