예제 #1
0
    def __init__(self,
                 name,
                 link0,
                 link1,
                 ll_addr0=None,
                 ll_addr1=None,
                 ips0=None,
                 ips1=None,
                 forwards_to_0=None,
                 forwards_to_1=None):
        super(TestRouter, self).__init__(name,
                                         link0,
                                         ll_addr0=ll_addr0,
                                         ips0=ips0)

        self.add_iface(Interface(link=link1, link_addr=ll_addr1, ips=ips1))
        self.if1 = self.iface(1)

        if not (self.if0 == None or self.if1 == None):
            self.if0.on_receive(self.__forward_to_if1)
        if not (self.if0 == None or self.if1 == None):
            self.if1.on_receive(self.__forward_to_if0)

        self.__forwards_to_0 = []
        self.__forwards_to_1 = []

        self.__perform_ra = True

        if forwards_to_0 != None:
            for n in forwards_to_0:
                self.__forwards_to_0.append(Network(n))
        if forwards_to_1 != None:
            for n in forwards_to_1:
                self.__forwards_to_1.append(Network(n))
예제 #2
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)
예제 #3
0
    def run(self):
        # This relies on SEND - Ping it so it sends an NS
        self.logger.info(
            "Sending an ICMPv6 Echo Request to the UUT, to trigger a Secure Neighbor Solicitation..."
        )
        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 signed CGA packet...")
        cga_packets = self.node(1).received(src=self.target(1).link_local_ip(),
                                            dst=self.node(1).link_local_ip(),
                                            type=ICMPv6NDOptCGA,
                                            timeout=120)
        assertGreaterThanOrEqualTo(
            1, len(cga_packets), "expect to receive one-or-more CGA packets")

        self.logger.info("Receive a CGA packet. Verifying it:")
        cga_layer = cga_packets[0][ICMPv6NDOptCGA]

        self.logger.info("Checking Collision count is in range...")
        assertTrue(cga_layer.collision in [0, 1, 2],
                   "expected Collision Count to be 0, 1 or 2")

        iface_identifier = inet_pton(socket.AF_INET6,
                                     IPAddress.identify(
                                         cga_packets[0].src).ip)[8:]
        prefix = IPAddress.identify(cga_packets[0].src).network()
        # check the CGA subnet prefix(mask) is equal to the subnet prefix
        self.logger.info("Checking the Subnet Prefix Mask...")
        assertEqual(str(Network(cga_layer.mask)), prefix,
                    "expected the CGA Prefix to match the Address Prefix")

        self.logger.info("Checking Hash One...")
        hash1 = self.hash_one(cga_layer)
        mask1 = '\x1c\xff\xff\xff\xff\xff\xff\xff'  # RFC3972, Section 2
        # Hash1 & Mask1 == Interface Identifier & Mask1, last 7 octets should match exactly
        assertEqual(self.and_byte_strings(hash1, mask1),
                    self.and_byte_strings(iface_identifier, mask1),
                    "expected hash1 to match the interface identifier")
        assertEqual(hash1[7:], iface_identifier[7:],
                    "expected hash1 to match the interface identifier")

        self.logger.info("Checking Hash Two...")
        hash2 = self.hash_two(cga_layer)
        sec = (ord(iface_identifier[0]) >> 5) & 0x07
        mask2 = '\xff\xff' * sec + '\x00\x00' * (
            7 - sec)  # 112bit mask as in RFC 3972, Section 2
        # Hash2 & Mask2  ==  0x0000000000000000000000000000
        assertEqual(self.and_byte_strings(hash2, mask2), '\x00\x00' * 7,
                    "expected hash2 & mask2 to be zero")
예제 #4
0
        def __init__(self, config, link):
            self.__config = config

            n4 = Network(self.__config.get('test-network', 'link-' + link + '-v4'))
            n6 = Network(self.__config.get('test-network', 'link-' + link + '-v6'))

            self.v4_prefix = str(n4.network())
            self.v4_prefix_size = n4.subnet()
            
            self.prefix = self.v6_prefix = str(n6.network())
            self.prefix_size = self.v6_prefix_size = n6.subnet()
예제 #5
0
    def __lt__(self, other):
        n1 = Network(self)
        n2 = Network(other)

        return int(n1) < int(n2)
예제 #6
0
    def __ge__(self, other):
        n1 = Network(self)
        n2 = Network(other)

        return int(n1) >= int(n2)
예제 #7
0
 def network(self):
     return str(Network("%s/%s" % (self.ip, self.prefix_size)).network())