Example #1
0
    def test_it_should_get_the_global_ip_of_tr3if1(self):
        options, args = sampleOptions("--configuration tests/mocks/veripy.cfg host")

        c = Configuration(args, options)

        self.assertEqual(2, len(c.test_network().tr1.if0_ips))
        self.assertTrue(IPAddress.identify("2012:6970:7636::fe:104") in c.test_network().tr3.if1_ips)
        self.assertTrue(IPAddress.identify("fe80::7a2b:cbff:fefe:104") in c.test_network().tr3.if1_ips)
Example #2
0
    def test_it_should_get_the_link_local_ip_of_tn1(self):
        options, args = sampleOptions("--configuration tests/mocks/veripy.cfg host")

        c = Configuration(args, options)

        self.assertEqual(3, len(c.test_network().tn1.if0_ips))
        self.assertTrue(IPAddress.identify("fe80::7a2b:cbff:feef:0102") in c.test_network().tn1.if0_ips)
        self.assertTrue(IPAddress.identify("fe80::7a2b:cbff:feca:ad05") in c.test_network().tn1.if0_ips)
Example #3
0
    def test_it_should_not_get_received_packets_for_another_ip(self):
        l = Link('A')
        n = TestNode('TNN',     link0=l, ips0=[IPAddress.identify("2001:db8::1"), IPAddress.identify("fe80::1")])

        l.accept(IPv6(src="2001:db8::2", dst="2001:db8::3")/ICMPv6EchoRequest())
        l.accept(IPv6(src="2001:db8::3", dst="2001:db8::2")/ICMPv6EchoReply())

        self.assertEqual(0, len(n.received()))
Example #4
0
    def test_it_should_get_received_packets_for_its_own_v4_address(self):
        l = Link('A')
        n = TestNode('TNN',     link0=l, ips0=[IPAddress.identify("2001:db8::1"), IPAddress.identify("fe80::1"), IPAddress.identify("10.0.0.1")])

        l.accept(IP(src="10.0.0.2", dst="10.0.0.1")/ICMP())
        l.accept(IP(src="10.0.0.1", dst="10.0.0.2")/ICMP())

        self.assertEqual(1, len(n.received()))
        self.assertTrue(n.received()[0].haslayer(ICMP))
Example #5
0
    def test_it_should_get_received_packets_for_its_own_link_local(self):
        l = Link('A')
        n = TestNode('TNN',     link0=l, ips0=[IPAddress.identify("2001:db8::1"), IPAddress.identify("fe80::1")])

        l.accept(IPv6(src="fe80::2", dst="fe80::1")/ICMPv6EchoRequest())
        l.accept(IPv6(src="fe80::1", dst="fe80::2")/ICMPv6EchoReply())

        self.assertEqual(1, len(n.received()))
        self.assertTrue(n.received()[0].haslayer(ICMPv6EchoRequest))
Example #6
0
    def test_it_should_not_forward_router_solicitations(self):
        l = Link('A')
        m = Link('B')
        r = TestRouter('TNN',   link0=l, ll_addr0="00:b0:d0:86:bb:f7", ips0=[IPAddress.identify("2001:500:88:200::10"), IPAddress.identify("2001:500:88:200::11"), IPAddress.identify("fe80:500:88:200::10"), IPAddress.identify("192.0.43.10")],
                                link1=m, ll_addr1="00:b0:d0:86:bb:f8", ips1=[IPAddress.identify("2001:600:88:200::10"), IPAddress.identify("2001:600:88:200::11"), IPAddress.identify("fe80:600:88:200::10"), IPAddress.identify("192.1.43.10")])

        l.accept(IPv6(src="fe80:500:88:200::20", dst="ff02::2")/ICMPv6ND_RS())
        
        self.assertFalse(any(map(lambda p: p.haslayer(ICMPv6ND_RS), m.forwarded())))
Example #7
0
    def test_it_should_not_forward_neighbour_advertisements(self):
        l = Link('A')
        m = Link('B')
        r = TestRouter('TNN',   link0=l, ll_addr0="00:b0:d0:86:bb:f7", ips0=[IPAddress.identify("2001:500:88:200::10"), IPAddress.identify("2001:500:88:200::11"), IPAddress.identify("fe80:500:88:200::10"), IPAddress.identify("192.0.43.10")],
                                link1=m, ll_addr1="00:b0:d0:86:bb:f8", ips1=[IPAddress.identify("2001:600:88:200::10"), IPAddress.identify("2001:600:88:200::11"), IPAddress.identify("fe80:600:88:200::10"), IPAddress.identify("192.1.43.10")])

        l.accept(IPv6(src="fe80:500:88:200::20", dst="ff02::2")/ICMPv6ND_NA())

        self.assertEqual(0, len(m.forwarded()))
Example #8
0
 def setUp(self):
     self.c = IPAddressCollection(
         [
             IPAddress.identify("2001:500:88:200::10"),
             IPAddress.identify("2001:500:88:200::11"),
             IPAddress.identify("fe80:500:88:200::10"),
             IPAddress.identify("192.0.43.10"),
         ]
     )
Example #9
0
    def test_it_should_not_forward_global_traffic_addressed_to_the_interface(self):
        l = Link('A')
        m = Link('B')
        r = TestRouter('TNN',   link0=l, ips0=[IPAddress.identify("2001:500:88:200::10"), IPAddress.identify("2001:500:88:200::11"), IPAddress.identify("fe80:500:88:200::10"), IPAddress.identify("192.0.43.10")],
                                link1=m, ips1=[IPAddress.identify("2001:600:88:200::10"), IPAddress.identify("2001:600:88:200::11"), IPAddress.identify("fe80:600:88:200::10"), IPAddress.identify("192.1.43.10")])

        l.accept(IPv6(dst="2001:500:88:200::10"))

        self.assertEqual(1, len(l.forwarded()))
        self.assertEqual(0, len(m.forwarded()))
Example #10
0
    def test_it_should_have_ip_addresses_on_if1(self):
        l = Link('A')
        m = Link('B')
        r = TestRouter('TNN',   link0=l, ips0=[IPAddress.identify("2001:500:88:200::10"), IPAddress.identify("2001:500:88:200::11"), IPAddress.identify("fe80:500:88:200::10"), IPAddress.identify("192.0.43.10")],
                                link1=m, ips1=[IPAddress.identify("2001:600:88:200::10"), IPAddress.identify("2001:600:88:200::11"), IPAddress.identify("fe80:600:88:200::10"), IPAddress.identify("192.1.43.10")])

        self.assertEqual("2001:600:88:200::10", r.ip(1).short_form())
        self.assertEqual("2001:600:88:200::10", r.global_ip(1).short_form())
        self.assertEqual("2001:600:88:200::11", r.global_ip(1, offset=1).short_form())
        self.assertEqual("192.1.43.10", r.ip(1, type='v4').short_form())
Example #11
0
    def test_it_should_send_traffic_on_if1(self):
        l = Link('A')
        m = Link('B')
        r = TestRouter('TNN',   link0=l, ips0=[IPAddress.identify("2001:500:88:200::10"), IPAddress.identify("2001:500:88:200::11"), IPAddress.identify("fe80:500:88:200::10"), IPAddress.identify("192.0.43.10")],
                                link1=m, ips1=[IPAddress.identify("2001:600:88:200::10"), IPAddress.identify("2001:600:88:200::11"), IPAddress.identify("fe80:600:88:200::10"), IPAddress.identify("192.1.43.10")])

        r.send("This is a packet.", iface=1)

        self.assertEqual(0, len(l.forwarded()))
        self.assertEqual(1, len(m.forwarded()))
        self.assertEqual("This is a packet.", m.forwarded()[0])
Example #12
0
    def test_it_should_receive_traffic_from_if1(self):
        l = Link('A')
        m = Link('B')
        r = TestRouter('TNN',   link0=l, ips0=[IPAddress.identify("2001:500:88:200::10"), IPAddress.identify("2001:500:88:200::11"), IPAddress.identify("fe80:500:88:200::10"), IPAddress.identify("192.0.43.10")],
                                link1=m, ips1=[IPAddress.identify("2001:600:88:200::10"), IPAddress.identify("2001:600:88:200::11"), IPAddress.identify("fe80:600:88:200::10"), IPAddress.identify("192.1.43.10")])

        m.accept(IPv6(src="2001:600:88:200::90", dst="2001:600:88:200::10"))

        self.assertEqual(0, len(r.received()))
        self.assertEqual(1, len(r.received(1)))
        self.assertTrue(r.received(1)[0].haslayer(IPv6))
Example #13
0
    def test_it_should_not_forward_link_local_traffic(self):
        l = Link('A')
        m = Link('B')
        r = TestRouter('TNN',   link0=l, ips0=[IPAddress.identify("2001:500:88:200::10"), IPAddress.identify("2001:500:88:200::11"), IPAddress.identify("fe80:500:88:200::10"), IPAddress.identify("192.0.43.10")],
                                link1=m, ips1=[IPAddress.identify("2001:600:88:200::10"), IPAddress.identify("2001:600:88:200::11"), IPAddress.identify("fe80:600:88:200::10"), IPAddress.identify("192.1.43.10")],
                                forwards_to_0=[Network("2001:0500:0088:0200:0000:0000:0000:0000/64")],
                                forwards_to_1=[Network("2001:0600:0088:0200:0000:0000:0000:0000/64")])

        l.accept(IPv6(dst="fe80:600:88:200::10"))

        self.assertEqual(1, len(l.forwarded()))
        self.assertEqual(0, len(m.forwarded()))
Example #14
0
    def test_it_should_not_respond_to_an_arp_reply_address(self):
        l = Link('A')
        n = TestNode('TNN',     link0=l, ll_addr0="00:b0:d0:86:bb:f7", ips0=[IPAddress.identify("2001:500:88:200::10"), IPAddress.identify("2001:500:88:200::11"), IPAddress.identify("fe80:500:88:200::10"), IPAddress.identify("192.0.43.10")])

        l.accept(ARP(hwsrc="00:01:02:03:04:05", psrc="192.0.43.100", pdst="192.0.43.200", op=0x002))

        self.assertEqual(1, len(l.forwarded()))
Example #15
0
    def test_it_should_get_the_global_ip_of_tn4(self):
        options, args = sampleOptions("--configuration tests/mocks/veripy.cfg host")

        c = Configuration(args, options)

        self.assertEqual(2, len(c.test_network().tn4.if0_ips))
        self.assertTrue(IPAddress.identify("2012:6d77:7269::ef:0105") in c.test_network().tn4.if0_ips)
Example #16
0
    def test_it_should_decrement_the_ttl_when_forwarding_ipv4_packets(self):
        l = Link('A')
        m = Link('B')
        r = TestRouter('TNN',   link0=l, ips0=[IPAddress.identify("2001:500:88:200::10"), IPAddress.identify("2001:500:88:200::11"), IPAddress.identify("fe80:500:88:200::10"), IPAddress.identify("192.0.43.10")],
                                link1=m, ips1=[IPAddress.identify("2001:600:88:200::10"), IPAddress.identify("2001:600:88:200::11"), IPAddress.identify("fe80:600:88:200::10"), IPAddress.identify("192.1.43.10")],
                                forwards_to_0=[Network("192.0.43.0/24")],
                                forwards_to_1=[Network("192.1.43.0/24")])
        p = IP(dst="192.1.43.10")

        self.assertEqual(64, p.ttl)

        l.accept(p)

        self.assertEqual(1, len(l.forwarded()))
        self.assertEqual(1, len(m.forwarded()))
        self.assertTrue(m.forwarded()[0].haslayer(IP))
        self.assertEqual(63, m.forwarded()[0].ttl)
Example #17
0
    def test_it_should_have_ip_addresses_on_if0(self):
        l = Link('A')
        n = TestNode('TNN',     link0=l, ips0=[IPAddress.identify("2001:500:88:200::10"), IPAddress.identify("2001:500:88:200::11"), IPAddress.identify("fe80:500:88:200::10"), IPAddress.identify("192.0.43.10")])

        self.assertEqual("2001:500:88:200::10", n.ip().short_form())
        self.assertEqual("2001:500:88:200::10", n.global_ip().short_form())
        self.assertEqual("2001:500:88:200::11", n.global_ip(offset=1).short_form())
        self.assertEqual("192.0.43.10", n.ip(type='v4').short_form())
Example #18
0
    def test_it_should_send_traffic_on_if0(self):
        l = Link('A')
        n = TestNode('TNN',     link0=l, ips0=[IPAddress.identify("2001:500:88:200::10"), IPAddress.identify("2001:500:88:200::11"), IPAddress.identify("fe80:500:88:200::10"), IPAddress.identify("192.0.43.10")])

        n.send("This is a packet.")

        self.assertEqual(1, len(l.forwarded()))
        self.assertEqual("This is a packet.", l.forwarded()[0])
Example #19
0
    def test_it_should_receive_traffic_from_if0(self):
        l = Link('A')
        n = TestNode('TNN',     link0=l, ips0=[IPAddress.identify("2001:500:88:200::10"), IPAddress.identify("2001:500:88:200::11"), IPAddress.identify("fe80:500:88:200::10"), IPAddress.identify("192.0.43.10")])

        l.accept(IPv6(src="2001:500:88:200::90", dst="2001:500:88:200::10"))

        self.assertEqual(1, len(n.received()))
        self.assertTrue(n.received()[0].haslayer(IPv6))
Example #20
0
    def test_it_should_not_respond_to_a_neighbourhood_solicitation_for_a_multicast_group_in_the_ips(self):
        l = Link('A')
        n = TestNode('TNN',     link0=l, ll_addr0="00:b0:d0:86:bb:f7", ips0=[IPAddress.identify("2001:500:88:200::10"), IPAddress.identify("2001:500:88:200::11"), IPAddress.identify("fe80:500:88:200::10"), IPAddress.identify("192.0.43.10")])

        l.accept(IPv6(src="fe80:500:88:200::20", dst="fe80:500:88:200::10")/ICMPv6ND_NS(tgt="ff02::1"))

        self.assertEqual(1, len(l.forwarded()))
        self.assertTrue(l.forwarded()[0].haslayer(ICMPv6ND_NS))
Example #21
0
    def run(self):
        self.logger.info("Sending ICMP Echo Request, to UUT's Link Local address...")
        self.node(1).send(
            IPv6(src=str(self.node(1).link_local_ip()), dst=str(self.target(1).link_local_ip()))/
                ICMPv6EchoRequest(seq=self.next_seq()))

        self.logger.info("Checking for a reply ...")
        r1 = self.node(1).received(src=self.target(1).link_local_ip(), dst=self.node(1).link_local_ip().solicited_node(), type=ICMPv6ND_NS)
        assertGreaterThanOrEqualTo(1, len(r1), "expected to receive a Neighbor Solicitation")
        
        assertEqual(self.node(1).link_local_ip(), IPAddress.identify(r1[0].getlayer(ICMPv6ND_NS).tgt))
Example #22
0
    def test_it_should_respond_to_arp_for_its_ipv4_address(self):
        l = Link('A')
        n = TestNode('TNN',     link0=l, ll_addr0="00:b0:d0:86:bb:f7", ips0=[IPAddress.identify("2001:500:88:200::10"), IPAddress.identify("2001:500:88:200::11"), IPAddress.identify("fe80:500:88:200::10"), IPAddress.identify("192.0.43.10")])

        l.accept(ARP(hwsrc="00:01:02:03:04:05", psrc="192.0.43.100", pdst="192.0.43.10"))

        self.assertEqual(2, len(l.forwarded()))
        self.assertTrue(l.forwarded()[1].haslayer(ARP))
        self.assertEqual(0x0002, l.forwarded()[1].getlayer(ARP).op)
        self.assertEqual("192.0.43.10", l.forwarded()[1].getlayer(ARP).psrc)
        self.assertEqual("00:b0:d0:86:bb:f7", l.forwarded()[1].getlayer(ARP).hwsrc)
        self.assertEqual("192.0.43.100", l.forwarded()[1].getlayer(ARP).pdst)
        self.assertEqual("00:01:02:03:04:05", l.forwarded()[1].getlayer(ARP).hwdst)
Example #23
0
    def test_it_should_respond_to_router_solicitations(self):
        l = Link('A')
        m = Link('B')
        r = TestRouter('TNN',   link0=l, ll_addr0="00:b0:d0:86:bb:f7", ips0=[IPAddress.identify("2001:500:88:200::10"), IPAddress.identify("2001:500:88:200::11"), IPAddress.identify("fe80:500:88:200::10"), IPAddress.identify("192.0.43.10")],
                                link1=m, ll_addr1="00:b0:d0:86:bb:f8", ips1=[IPAddress.identify("2001:600:88:200::10"), IPAddress.identify("2001:600:88:200::11"), IPAddress.identify("fe80:600:88:200::10"), IPAddress.identify("192.1.43.10")])

        l.accept(IPv6(src="fe80:500:88:200::20", dst="ff02::2")/ICMPv6ND_RS())

        self.assertEqual(2, len(l.forwarded()))
        self.assertTrue(l.forwarded()[0].haslayer(ICMPv6ND_RS))
        self.assertTrue(l.forwarded()[1].haslayer(ICMPv6ND_RA))
        self.assertEqual("fe80:500:88:200::10", l.forwarded()[1].getlayer(IPv6).src)
        self.assertEqual("ff02::1", l.forwarded()[1].getlayer(IPv6).dst)

        self.assertTrue(l.forwarded()[1].haslayer(ICMPv6NDOptSrcLLAddr))
        self.assertEqual("00:b0:d0:86:bb:f7", l.forwarded()[1].getlayer(ICMPv6NDOptSrcLLAddr).lladdr)

        self.assertTrue(l.forwarded()[1].haslayer(ICMPv6NDOptMTU))
        self.assertEqual(1500, l.forwarded()[1].getlayer(ICMPv6NDOptMTU).mtu)

        self.assertTrue(l.forwarded()[1].haslayer(ICMPv6NDOptPrefixInfo))
        self.assertEqual(64, l.forwarded()[1].getlayer(ICMPv6NDOptPrefixInfo).prefixlen)
        self.assertEqual("2001:500:88:200::", l.forwarded()[1].getlayer(ICMPv6NDOptPrefixInfo).prefix)
Example #24
0
    def test_it_should_respond_to_a_neighbourhood_solicitation_for_its_link_local_ip(self):
        l = Link('A')
        n = TestNode('TNN',     link0=l, ll_addr0="00:b0:d0:86:bb:f7", ips0=[IPAddress.identify("2001:500:88:200::10"), IPAddress.identify("2001:500:88:200::11"), IPAddress.identify("fe80:500:88:200::10"), IPAddress.identify("192.0.43.10")])

        l.accept(IPv6(src="fe80:500:88:200::20", dst="fe80:500:88:200::10")/ICMPv6ND_NS(tgt="fe80:500:88:200::10"))

        self.assertEqual(2, len(l.forwarded()))
        self.assertTrue(l.forwarded()[0].haslayer(ICMPv6ND_NS))
        self.assertTrue(l.forwarded()[1].haslayer(ICMPv6ND_NA))
        self.assertEqual("fe80:500:88:200::10", l.forwarded()[1].getlayer(IPv6).src)
        self.assertEqual("fe80:500:88:200::20", l.forwarded()[1].getlayer(IPv6).dst)
        self.assertEqual("fe80:500:88:200::10", l.forwarded()[1].getlayer(ICMPv6ND_NA).tgt)

        self.assertTrue(l.forwarded()[1].haslayer(ICMPv6NDOptDstLLAddr))
        self.assertEqual("00:b0:d0:86:bb:f7", l.forwarded()[1].getlayer(ICMPv6NDOptDstLLAddr).lladdr)
Example #25
0
    def run(self):
        self.logger.info("Sending Router Advertisement")
        self.router(1).send( 
            IPv6(src=str(self.router(1).link_local_ip(iface=1)), dst="ff02::1")/\
                ICMPv6ND_RA(code=0)/
                ICMPv6NDOptPrefixInfo(prefixlen=self.router(1).iface(1).global_ip().prefix_size, prefix=self.router(1).iface(1).global_ip().network()),
            iface=1)
        self.logger.info("Sending ICMP Echo Request, to UUT's global address...")
        self.node(1).send(
            IPv6(src=str(self.node(1).global_ip()), dst=str(self.target(1).global_ip()))/
                ICMPv6EchoRequest(seq=self.next_seq()))
        
        self.logger.info("Checking for a reply ...")
        r1 = self.node(1).received(src=self.target(1).global_ip(), dst=self.node(1).link_local_ip().solicited_node(), type=ICMPv6ND_NS)
        assertGreaterThanOrEqualTo(1, len(r1), "expected to receive a Neighbor Solicitation")

        assertEqual(self.node(1).global_ip(), IPAddress.identify(r1[0].getlayer(ICMPv6ND_NS).tgt))
Example #26
0
    def run(self):
        self.logger.info("Waiting for a DHCPv6 Solicit message, with a IA for Prefix Delegation...")
        r1 = self.node(1).received(src=self.target(1).link_local_ip(), dst=AllDHCPv6RelayAgentsAndServers, type=DHCP6_Solicit)

        assertGreaterThanOrEqualTo(1, len(r1), "expected to receive one-or-more DHCPv6 Solicit messages")
        assertHasLayer(DHCP6OptIA_PD, r1[0], "expected the DHCPv6 Solicit message to contain an IA for Prefix Delegation")

        self.logger.info("Sending a DHCPv6 Advertise message, offering a prefix...")
        self.node(1).send(
            IPv6(src=str(self.node(1).link_local_ip()), dst=str(self.target(1).link_local_ip()))/
                UDP(sport=DHCPv6DestPort, dport=DHCPv6SourcePort)/
                    self.build_dhcpv6_pd_advertise(r1[0], self.node(1), self.target(1), T1=50, T2=80))

        self.logger.info("Checking for a DHCPv6 Request message...")
        r2 = self.node(1).received(src=self.target(1).link_local_ip(), dst=AllDHCPv6RelayAgentsAndServers, type=DHCP6_Request)
        assertGreaterThanOrEqualTo(1, len(r2), "expected to receive a DHCPv6 Request message")
        assertHasLayer(DHCP6OptIA_PD, r2[0], "expected the DHCPv6 Request to contain an IA for Prefix Delegation")
        assertHasLayer(DHCP6OptIAPrefix, r2[0], "expected the DHCPv6 Request to contain an IA Prefix")
        assertEqual(IPAddress.identify(self.node(1).iface(0).link.v6_prefix), r2[0][DHCP6OptIAPrefix].prefix, "expected the requested Prefix to match the advertised one")
        assertEqual(self.node(1).iface(0).link.v6_prefix_size, r2[0][DHCP6OptIAPrefix].plen, "expected the requested Prefix Length to match the advertised one")

        self.logger.info("Sending a DHCPv6 Reply message, with the offered IA for Prefix Delegation...")
        self.node(1).send(
            IPv6(src=str(self.node(1).link_local_ip()), dst=str(self.target(1).link_local_ip()))/
                UDP(sport=DHCPv6DestPort, dport=DHCPv6SourcePort)/
                    self.build_dhcpv6_pd_reply(r2[0], self.node(1), self.target(1)))

        self.ui.wait(50)

        self.node(1).clear_received()
        self.logger.info("Waiting for a DHCPv6 Renew message, with a IA for Prefix Delegation...")
        r3 = self.node(1).received(src=self.target(1).link_local_ip(), dst=AllDHCPv6RelayAgentsAndServers, type=DHCP6_Renew)
        assertGreaterThanOrEqualTo(1, len(r3), "expected to receive one-or-more DHCPv6 Renew messages")
        assertHasLayer(DHCP6OptIA_PD, r3[0], "expected the DHCPv6 Renew to contain an IA for Prefix Delegation")
        assertHasLayer(DHCP6OptIAPrefix, r3[0], "expected the DHCPv6 Renew to contain an IA Prefix")
        assertEqual(r2[0][DHCP6OptIAPrefix].prefix, r3[0][DHCP6OptIAPrefix].prefix, "expected the original prefix to be renewed")

        self.ui.wait(50)

        self.node(1).clear_received()
        self.logger.info("Waiting for a DHCPv6 Renew message, with a IA for Prefix Delegation...")
        r3 = self.node(1).received(src=self.target(1).link_local_ip(), dst=AllDHCPv6RelayAgentsAndServers, type=DHCP6_Renew)
        assertGreaterThanOrEqualTo(1, len(r3), "expected to receive one-or-more DHCPv6 Renew messages")
        assertHasLayer(DHCP6OptIA_PD, r3[0], "expected the DHCPv6 Renew to contain an IA for Prefix Delegation")
        assertHasLayer(DHCP6OptIAPrefix, r3[0], "expected the DHCPv6 Renew to contain an IA Prefix")
        assertEqual(r2[0][DHCP6OptIAPrefix].prefix, r3[0][DHCP6OptIAPrefix].prefix, "expected the original prefix to be renewed")
Example #27
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)
Example #28
0
    def run(self):
        self.logger.info(
            "Waiting for a DHCPv6 Solicit message, with a IA for Prefix Delegation..."
        )
        r1 = self.node(1).received(src=self.target(1).link_local_ip(),
                                   dst=AllDHCPv6RelayAgentsAndServers,
                                   type=DHCP6_Solicit)

        assertGreaterThanOrEqualTo(
            1, len(r1),
            "expected to receive one-or-more DHCPv6 Solicit messages")
        assertHasLayer(
            DHCP6OptIA_PD, r1[0],
            "expected the DHCPv6 Solicit message to contain an IA for Prefix Delegation"
        )

        self.logger.info(
            "Sending a DHCPv6 Advertise message, offering a prefix...")
        self.node(1).send(
            IPv6(src=str(self.node(1).link_local_ip()),
                 dst=str(self.target(1).link_local_ip())) /
            UDP(sport=DHCPv6DestPort, dport=DHCPv6SourcePort) /
            self.build_dhcpv6_pd_advertise(
                r1[0], self.node(1), self.target(1), T1=50, T2=80))

        self.logger.info("Checking for a DHCPv6 Request message...")
        r2 = self.node(1).received(src=self.target(1).link_local_ip(),
                                   dst=AllDHCPv6RelayAgentsAndServers,
                                   type=DHCP6_Request)
        assertGreaterThanOrEqualTo(
            1, len(r2), "expected to receive a DHCPv6 Request message")
        assertHasLayer(
            DHCP6OptIA_PD, r2[0],
            "expected the DHCPv6 Request to contain an IA for Prefix Delegation"
        )
        assertHasLayer(DHCP6OptIAPrefix, r2[0],
                       "expected the DHCPv6 Request to contain an IA Prefix")
        assertEqual(
            IPAddress.identify(self.node(1).iface(0).link.v6_prefix),
            r2[0][DHCP6OptIAPrefix].prefix,
            "expected the requested Prefix to match the advertised one")
        assertEqual(
            self.node(1).iface(0).link.v6_prefix_size,
            r2[0][DHCP6OptIAPrefix].plen,
            "expected the requested Prefix Length to match the advertised one")

        self.logger.info(
            "Sending a DHCPv6 Reply message, with the offered IA for Prefix Delegation..."
        )
        self.node(1).send(
            IPv6(src=str(self.node(1).link_local_ip()),
                 dst=str(self.target(1).link_local_ip())) /
            UDP(sport=DHCPv6DestPort, dport=DHCPv6SourcePort) /
            self.build_dhcpv6_pd_reply(r2[0], self.node(1), self.target(1)))

        self.ui.tell("Configure the UUT to release the IPv6 prefix.")
        assertTrue(self.ui.ask("Press Y when it has released it."))

        self.logger.info(
            "Waiting for a DHCPv6 Release message, with a IA for Prefix Delegation..."
        )
        r3 = self.node(1).received(src=self.target(1).link_local_ip(),
                                   dst=AllDHCPv6RelayAgentsAndServers,
                                   type=DHCP6_Release)
        assertGreaterThanOrEqualTo(
            1, len(r3),
            "expected to receive one-or-more DHCPv6 Rebind messages")
        assertHasLayer(
            DHCP6OptIA_PD, r3[0],
            "expected the DHCPv6 Rebind to contain an IA for Prefix Delegation"
        )
        assertHasLayer(DHCP6OptIAPrefix, r3[0],
                       "expected the DHCPv6 Rebind to contain an IA Prefix")
        assertEqual(r2[0][DHCP6OptIAPrefix].prefix,
                    r3[0][DHCP6OptIAPrefix].prefix,
                    "expected the original prefix to be rebound")
Example #29
0
 def __extract_ips(self, ip_str):
     return map(lambda ip: IPAddress.identify(ip.strip()), ip_str.split(","))
Example #30
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)
Example #31
0
    def test_it_should_get_the_default_v6_link_local_ip(self):
        l = Link('A')
        i = Interface(link=l, ips=[IPAddress.identify("2001:500:88:200::10"), IPAddress.identify("2001:500:88:200::11"), IPAddress.identify("fe80:500:88:200::10"), IPAddress.identify("192.0.43.10")])

        self.assertEqual("fe80:500:88:200::10", i.link_local_ip().short_form())
Example #32
0
    def test_it_should_get_the_second_v6_global_ip(self):
        l = Link('A')
        i = Interface(link=l, ips=[IPAddress.identify("2001:500:88:200::10"), IPAddress.identify("2001:500:88:200::11"), IPAddress.identify("fe80:500:88:200::10"), IPAddress.identify("192.0.43.10")])

        self.assertEqual("2001:500:88:200::11", i.global_ip(offset=1).short_form())