Esempio n. 1
0
    def build_test_network(self):
        tn = TestNetwork(self.test_network())

        tn._TestNetwork__taps[0].unbind()
        tn._TestNetwork__taps[0] = MockTap(tn.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'))
        tn._TestNetwork__taps[1].unbind()
        tn._TestNetwork__taps[1] = MockTap(tn.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'))

        return tn
Esempio n. 2
0
    def setUp(self):
        self.test_network = TestNetwork(TestNetworkConfiguration())

        self.test_network._TestNetwork__taps[0].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'))
Esempio n. 3
0
    def setUp(self):
        self.test_network = TestNetwork(TestNetworkConfiguration())

        self.test_network._TestNetwork__taps[0].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'))
    def test_it_should_expose_routers_or_the_test_network(self):
        n = TestNetwork(TestNetworkConfiguration())

        n._TestNetwork__taps[0].unbind()
        n._TestNetwork__taps[1].unbind()

        c = ComplianceTestCase(n, None)

        self.assertEqual(3, len(c.routers()))
        self.assertEqual('TR1', c.router(1).name)
        self.assertEqual('TR2', c.router(2).name)
        self.assertEqual('TR3', c.router(3).name)
    def test_it_should_expose_links_of_the_test_network(self):
        n = TestNetwork(TestNetworkConfiguration())

        n._TestNetwork__taps[0].unbind()
        n._TestNetwork__taps[1].unbind()

        c = ComplianceTestCase(n, None)

        self.assertEqual(3, len(c.links()))
        self.assertEqual('A', c.link(1).name)
        self.assertEqual('B', c.link(2).name)
        self.assertEqual('C', c.link(3).name)
Esempio n. 6
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 test_it_should_expose_nodes_of_the_test_network(self):
        n = TestNetwork(TestNetworkConfiguration())

        n._TestNetwork__taps[0].unbind()
        n._TestNetwork__taps[1].unbind()

        c = ComplianceTestCase(n, None)

        self.assertEqual(4, len(c.nodes()))
        self.assertEqual('TN1', c.node(1).name)
        self.assertEqual('TN2', c.node(2).name)
        self.assertEqual('TN3', c.node(3).name)
        self.assertEqual('TN4', c.node(4).name)
Esempio n. 8
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)
Esempio n. 9
0
    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
Esempio n. 10
0
    def build_test_network(self):
        tn = TestNetwork(self.test_network())

        tn._TestNetwork__taps[0].unbind()
        tn._TestNetwork__taps[0] = MockTap(tn.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'))
        tn._TestNetwork__taps[1].unbind()
        tn._TestNetwork__taps[1] = MockTap(tn.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'))

        return tn
Esempio n. 11
0
class ComplianceTestTestCase(unittest.TestCase):
    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

    def assertCheckFails(self, outcome):
        messages = (not outcome.message == None
                    and " Said: " + str(outcome.message) or "")
        if outcome.result_string() == "Error":
            messages += "\n" + outcome.backtrace

        self.assertEqual(
            False, outcome.result, "Expected compliance test to FAIL. Got: " +
            outcome.result_string() + "." + messages)

    def assertCheckPasses(self, outcome):
        messages = (not outcome.message == None
                    and " Said: " + str(outcome.message) or "")
        if outcome.result_string() == "Error":
            messages += "\n" + outcome.backtrace

        self.assertEqual(
            True, outcome.result, "Expected compliance test to PASS. Got: " +
            outcome.result_string() + "." + messages)

    def break_checksum(self, packet):
        b = IPv6(packet.build())

        if b.haslayer(ICMPv6EchoReply):
            b.getlayer(ICMPv6EchoReply).cksum = None
        elif b.haslayer(ICMPv6EchoRequest):
            b.getlayer(ICMPv6EchoRequest).cksum = None

        return b

    def get_outcome(self, test_case):
        return self.prepare(test_case).run_case()

    def prepare(self, test_case):
        c = test_case(self.test_network, self.ui)

        c.send_on_set_up = self.send_on_set_up

        return c

    def send_on_set_up(self):
        self.ui.wait(0)
Esempio n. 12
0
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)))
Esempio n. 13
0
class ComplianceTestTestCase(unittest.TestCase):

    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

    def assertCheckFails(self, outcome):
        messages = (not outcome.message == None and " Said: " + str(outcome.message) or "")
        if outcome.result_string() == "Error":
            messages += "\n" + outcome.backtrace

        self.assertEqual(False, outcome.result, "Expected compliance test to FAIL. Got: " + outcome.result_string() + "." + messages)
        
    def assertCheckPasses(self, outcome):
        messages = (not outcome.message == None and " Said: " + str(outcome.message) or "")
        if outcome.result_string() == "Error":
            messages += "\n" + outcome.backtrace

        self.assertEqual(True, outcome.result, "Expected compliance test to PASS. Got: " + outcome.result_string() + "." + messages)

    def break_checksum(self, packet):
        b = IPv6(packet.build())

        if b.haslayer(ICMPv6EchoReply):
            b.getlayer(ICMPv6EchoReply).cksum = None
        elif b.haslayer(ICMPv6EchoRequest):
            b.getlayer(ICMPv6EchoRequest).cksum = None

        return b
    
    def get_outcome(self, test_case):
        return self.prepare(test_case).run_case()
    
    def prepare(self, test_case):
        c = test_case(self.test_network, self.ui)

        c.send_on_set_up = self.send_on_set_up

        return c

    def send_on_set_up(self):
        self.ui.wait(0)
Esempio n. 14
0
class ComplianceTestCaseTestCase(unittest.TestCase):

    def setUp(self):
        self.test_network = TestNetwork(TestNetworkConfiguration())

        self.test_network._TestNetwork__taps[0].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'))

    class MyTestCase(ComplianceTestCase):
        """
        Example Test Case

        This test case has a title, a description and some private
        comments.

        @private
        This is implemented badly!
        """
        pass

    class AnotherTestCase(ComplianceTestCase):
        """
        Test Case - With no Description
        """
        pass

    class BlankTestCase1(ComplianceTestCase):
        """
        """
        pass

    class BlankTestCase2(ComplianceTestCase):
        pass

    @should
    class OptionalTestCase(ComplianceTestCase):
        pass

    @must
    class MandatoryTestCase(ComplianceTestCase):
        pass

    class InstrumentedTestCase(ComplianceTestCase):

        def __init__(self, test_network, ui):
            super(ComplianceTestCaseTestCase.InstrumentedTestCase, self).__init__(test_network, ui)
            
            self.sequence = []

        def run(self):
            self.sequence.append("run")

        def set_up(self):
            self.sequence.append("set_up")

        def tear_down(self):
            self.sequence.append("tear_down")
    

    def test_it_should_extract_the_title_from_the_pydoc_comment(self):
        self.assertEqual("Example Test Case", ComplianceTestCaseTestCase.MyTestCase.title())

    def test_it_should_extract_the_description_from_the_pydoc_comment(self):
        self.assertEqual("This test case has a title, a description and some private comments.", ComplianceTestCaseTestCase.MyTestCase.description())

    def test_it_should_extract_the_title_if_a_description_is_missing(self):
        self.assertEqual("Test Case - With no Description", ComplianceTestCaseTestCase.AnotherTestCase.title())

    def test_it_should_extract_a_blank_description_if_it_is_missing(self):
        self.assertEqual("", ComplianceTestCaseTestCase.AnotherTestCase.description())

    def test_it_should_default_the_title_if_the_pydoc_is_blank(self):
        self.assertEqual("BlankTestCase1", ComplianceTestCaseTestCase.BlankTestCase1.title())

    def test_it_should_return_a_blank_description_if_the_pydoc_is_blank(self):
        self.assertEqual("", ComplianceTestCaseTestCase.BlankTestCase1.description())

    def test_it_should_default_the_title_if_the_pydoc_is_missing(self):
        self.assertEqual("BlankTestCase2", ComplianceTestCaseTestCase.BlankTestCase2.title())

    def test_it_should_return_a_blank_description_if_the_pydoc_is_missing(self):
        self.assertEqual("", ComplianceTestCaseTestCase.BlankTestCase2.description())

    def test_it_should_not_be_optional_by_default(self):
        self.assertFalse(ComplianceTestCaseTestCase.MyTestCase.is_optional())

    def test_it_should_use_a_decorator_to_indicate_an_optional_case(self):
        self.assertTrue(ComplianceTestCaseTestCase.OptionalTestCase.is_optional())

    def test_it_should_use_a_decoration_to_reinforce_a_mandatory_case(self):
        self.assertFalse(ComplianceTestCaseTestCase.MandatoryTestCase.is_optional())

    def test_it_should_make_a_logger_available(self):
        c = ComplianceTestCaseTestCase.MyTestCase(self.test_network, None)

        self.assertTrue(hasattr(c, 'logger'))
        self.assertTrue(isinstance(c.logger, logging.Logger))

    def test_it_should_use_a_per_case_logger(self):
        c = ComplianceTestCaseTestCase.MyTestCase(self.test_network, None)

        self.assertTrue(hasattr(c, 'logger'))
        self.assertEqual(".veripy.compliance_tests.MyTestCaseLogger", c.logger.name)

    def test_it_should_make_the_logger_output_available(self):
        c = ComplianceTestCaseTestCase.MyTestCase(self.test_network, None)

        self.assertEqual("", c.log_file())

        c.logger.info("This is a log message.")

        self.assertTrue(c.log_file() != "")

    def test_it_should_return_a_result_from_run_case(self):
        t = ComplianceTestCaseTestCase.MyTestCase(self.test_network, None)

        o = t.run_case()

        self.assertTrue(isinstance(o, Outcome))

    def test_it_should_return_a_pass_result_if_the_test_case_passed(self):
        class PassingTestCase(ComplianceTestCase):
            def run(self):
                assertTrue(True)

        self.assertEqual(Outcome.Results.PASS, PassingTestCase(self.test_network, None).run_case().result)

    def test_it_should_return_a_fail_result_if_the_test_case_did_not_pass(self):
        class FailingTestCase(ComplianceTestCase):
            def run(self):
                fail("failure message")

        o = FailingTestCase(self.test_network, None).run_case()

        self.assertEqual(Outcome.Results.FAIL, o.result)
        self.assertEqual("failure message", o.message)

    def test_it_should_return_a_error_result_if_the_test_case_caused_an_exception(self):
        class PassingTestCase(ComplianceTestCase):
            def run(self):
                raise Exception("unexpected error")

        o = PassingTestCase(self.test_network, None).run_case()

        self.assertEqual(Outcome.Results.ERROR, o.result)
        self.assertEqual("unexpected error", o.message)

    def test_it_should_return_an_unimplemented_result_if_the_test_case_had_no_body(self):
        class UnimplementedTestCase(ComplianceTestCase):
            pass

        self.assertEqual(Outcome.Results.UNIMPLEMENTED, UnimplementedTestCase(self.test_network, None).run_case().result)

    def test_it_should_return_an_unimplemented_result_if_the_test_case_had_no_assertions(self):
        class UnimplementedTestCase(ComplianceTestCase):
            def run(self):
                pass

        self.assertEqual(Outcome.Results.UNIMPLEMENTED, UnimplementedTestCase(self.test_network, None).run_case().result)

    def test_it_should_execute_the_setup_procedure_before_running_a_test_case(self):
        t = ComplianceTestCaseTestCase.InstrumentedTestCase(self.test_network, None)

        t.run_case()

        self.assertEqual("set_up", t.sequence[0])
        self.assertEqual("run", t.sequence[1])

    def test_it_should_execute_the_teardown_procedure_after_running_a_test_case(self):
        t = ComplianceTestCaseTestCase.InstrumentedTestCase(self.test_network, None)

        t.run_case()

        self.assertEqual("run", t.sequence[1])
        self.assertEqual("tear_down", t.sequence[2])
        
Esempio n. 15
0
class ComplianceTestCaseTestCase(unittest.TestCase):
    def setUp(self):
        self.test_network = TestNetwork(TestNetworkConfiguration())

        self.test_network._TestNetwork__taps[0].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'))

    class MyTestCase(ComplianceTestCase):
        """
        Example Test Case

        This test case has a title, a description and some private
        comments.

        @private
        This is implemented badly!
        """
        pass

    class AnotherTestCase(ComplianceTestCase):
        """
        Test Case - With no Description
        """
        pass

    class BlankTestCase1(ComplianceTestCase):
        """
        """
        pass

    class BlankTestCase2(ComplianceTestCase):
        pass

    @should
    class OptionalTestCase(ComplianceTestCase):
        pass

    @must
    class MandatoryTestCase(ComplianceTestCase):
        pass

    class InstrumentedTestCase(ComplianceTestCase):
        def __init__(self, test_network, ui):
            super(ComplianceTestCaseTestCase.InstrumentedTestCase,
                  self).__init__(test_network, ui)

            self.sequence = []

        def run(self):
            self.sequence.append("run")

        def set_up(self):
            self.sequence.append("set_up")

        def tear_down(self):
            self.sequence.append("tear_down")

    def test_it_should_extract_the_title_from_the_pydoc_comment(self):
        self.assertEqual("Example Test Case",
                         ComplianceTestCaseTestCase.MyTestCase.title())

    def test_it_should_extract_the_description_from_the_pydoc_comment(self):
        self.assertEqual(
            "This test case has a title, a description and some private comments.",
            ComplianceTestCaseTestCase.MyTestCase.description())

    def test_it_should_extract_the_title_if_a_description_is_missing(self):
        self.assertEqual("Test Case - With no Description",
                         ComplianceTestCaseTestCase.AnotherTestCase.title())

    def test_it_should_extract_a_blank_description_if_it_is_missing(self):
        self.assertEqual(
            "", ComplianceTestCaseTestCase.AnotherTestCase.description())

    def test_it_should_default_the_title_if_the_pydoc_is_blank(self):
        self.assertEqual("BlankTestCase1",
                         ComplianceTestCaseTestCase.BlankTestCase1.title())

    def test_it_should_return_a_blank_description_if_the_pydoc_is_blank(self):
        self.assertEqual(
            "", ComplianceTestCaseTestCase.BlankTestCase1.description())

    def test_it_should_default_the_title_if_the_pydoc_is_missing(self):
        self.assertEqual("BlankTestCase2",
                         ComplianceTestCaseTestCase.BlankTestCase2.title())

    def test_it_should_return_a_blank_description_if_the_pydoc_is_missing(
            self):
        self.assertEqual(
            "", ComplianceTestCaseTestCase.BlankTestCase2.description())

    def test_it_should_not_be_optional_by_default(self):
        self.assertFalse(ComplianceTestCaseTestCase.MyTestCase.is_optional())

    def test_it_should_use_a_decorator_to_indicate_an_optional_case(self):
        self.assertTrue(
            ComplianceTestCaseTestCase.OptionalTestCase.is_optional())

    def test_it_should_use_a_decoration_to_reinforce_a_mandatory_case(self):
        self.assertFalse(
            ComplianceTestCaseTestCase.MandatoryTestCase.is_optional())

    def test_it_should_make_a_logger_available(self):
        c = ComplianceTestCaseTestCase.MyTestCase(self.test_network, None)

        self.assertTrue(hasattr(c, 'logger'))
        self.assertTrue(isinstance(c.logger, logging.Logger))

    def test_it_should_use_a_per_case_logger(self):
        c = ComplianceTestCaseTestCase.MyTestCase(self.test_network, None)

        self.assertTrue(hasattr(c, 'logger'))
        self.assertEqual(".veripy.compliance_tests.MyTestCaseLogger",
                         c.logger.name)

    def test_it_should_make_the_logger_output_available(self):
        c = ComplianceTestCaseTestCase.MyTestCase(self.test_network, None)

        self.assertEqual("", c.log_file())

        c.logger.info("This is a log message.")

        self.assertTrue(c.log_file() != "")

    def test_it_should_return_a_result_from_run_case(self):
        t = ComplianceTestCaseTestCase.MyTestCase(self.test_network, None)

        o = t.run_case()

        self.assertTrue(isinstance(o, Outcome))

    def test_it_should_return_a_pass_result_if_the_test_case_passed(self):
        class PassingTestCase(ComplianceTestCase):
            def run(self):
                assertTrue(True)

        self.assertEqual(
            Outcome.Results.PASS,
            PassingTestCase(self.test_network, None).run_case().result)

    def test_it_should_return_a_fail_result_if_the_test_case_did_not_pass(
            self):
        class FailingTestCase(ComplianceTestCase):
            def run(self):
                fail("failure message")

        o = FailingTestCase(self.test_network, None).run_case()

        self.assertEqual(Outcome.Results.FAIL, o.result)
        self.assertEqual("failure message", o.message)

    def test_it_should_return_a_error_result_if_the_test_case_caused_an_exception(
            self):
        class PassingTestCase(ComplianceTestCase):
            def run(self):
                raise Exception("unexpected error")

        o = PassingTestCase(self.test_network, None).run_case()

        self.assertEqual(Outcome.Results.ERROR, o.result)
        self.assertEqual("unexpected error", o.message)

    def test_it_should_return_an_unimplemented_result_if_the_test_case_had_no_body(
            self):
        class UnimplementedTestCase(ComplianceTestCase):
            pass

        self.assertEqual(
            Outcome.Results.UNIMPLEMENTED,
            UnimplementedTestCase(self.test_network, None).run_case().result)

    def test_it_should_return_an_unimplemented_result_if_the_test_case_had_no_assertions(
            self):
        class UnimplementedTestCase(ComplianceTestCase):
            def run(self):
                pass

        self.assertEqual(
            Outcome.Results.UNIMPLEMENTED,
            UnimplementedTestCase(self.test_network, None).run_case().result)

    def test_it_should_execute_the_setup_procedure_before_running_a_test_case(
            self):
        t = ComplianceTestCaseTestCase.InstrumentedTestCase(
            self.test_network, None)

        t.run_case()

        self.assertEqual("set_up", t.sequence[0])
        self.assertEqual("run", t.sequence[1])

    def test_it_should_execute_the_teardown_procedure_after_running_a_test_case(
            self):
        t = ComplianceTestCaseTestCase.InstrumentedTestCase(
            self.test_network, None)

        t.run_case()

        self.assertEqual("run", t.sequence[1])
        self.assertEqual("tear_down", t.sequence[2])
Esempio n. 16
0
    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
Esempio n. 17
0
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)))