Beispiel #1
0
 def test_has_prefix_info(self):
     lsa_body = intra_area_prefix.IntraAreaPrefix(0x2001, '0.0.0.0',
                                                  '8.8.8.8')
     lsa_body.add_prefix_info(0, 0, 10, '::')
     self.assertTrue(lsa_body.has_prefix_info(0, 0, 10, '::'))
     self.assertFalse(lsa_body.has_prefix_info(1, 0, 10, '::'))
     self.assertFalse(lsa_body.has_prefix_info(0, 1, 10, '::'))
     self.assertFalse(lsa_body.has_prefix_info(0, 0, 11, '::'))
     self.assertFalse(lsa_body.has_prefix_info(0, 0, 10, '1::'))
 def create_intra_area_prefix_lsa_body(self, referenced_ls_type,
                                       referenced_link_state_id,
                                       referenced_advertising_router):
     if (self.get_ospf_version() == conf.VERSION_IPV6) & (
             referenced_ls_type != conf.LSA_TYPE_LINK) & (referenced_ls_type
                                                          < 0x2000):
         referenced_ls_type += 0x2000
     self.body = intra_area_prefix.IntraAreaPrefix(
         referenced_ls_type, referenced_link_state_id,
         referenced_advertising_router)
     self.set_lsa_length()
     self.set_lsa_checksum()
Beispiel #3
0
    def test_pack_body(self):
        body_bytes = b'\x00\x00 \x01\x00\x00\x00\x00\x08\x08\x08\x08'
        self.assertEqual(
            body_bytes,
            intra_area_prefix.IntraAreaPrefix(0x2001, '0.0.0.0',
                                              '8.8.8.8').pack_lsa_body())

        body_bytes = b'\x00\t \x01\x00\x00\x00\x00\x07\x07\x07\x07\x00\x00\x00\n\x01\x00\x00\n\x00\x00\x00\x00 \x00' \
                     b'\x00\n \x01\r\xb8!\x00\x00\n \x01\r\xb8\x80\x00\x00\x00@\x00\x00\n \x01\r\xb8\xca\xfe\x00\x11A' \
                     b'\x00\x00\n \x01\r\xb8\xca\xfe\x00\x12\x00\x00\x00\x00`\x00\x00\n \x01\r\xb8\xca\xfe\x00\x13' \
                     b'\x00\x00\x00\x00a\x00\x00\n \x01\r\xb8\xca\xfe\x00\x14\x00\x00\x00\x00\x00\x00\x00\x00\x80\x02' \
                     b'\x00\x00 \x01\r\xb8\xca\xfe\x00\x15\x00\x00\x00\x00\x00\x00\x00\x01'
        lsa_body = intra_area_prefix.IntraAreaPrefix(0x2001, '0.0.0.0',
                                                     '7.7.7.7')
        lsa_body.add_prefix_info(0, 0, 10, '::')
        lsa_body.add_prefix_info(1, 0, 10, '::')
        lsa_body.add_prefix_info(32, 0, 10, '2001:db8::')
        lsa_body.add_prefix_info(33, 0, 10, '2001:db8:8000::')
        lsa_body.add_prefix_info(64, 0, 10, '2001:db8:cafe:11::')
        lsa_body.add_prefix_info(65, 0, 10, '2001:db8:cafe:12::')
        lsa_body.add_prefix_info(96, 0, 10, '2001:db8:cafe:13::')
        lsa_body.add_prefix_info(97, 0, 10, '2001:db8:cafe:14::')
        lsa_body.add_prefix_info(128, 2, 0, '2001:db8:cafe:15::1')
        self.assertEqual(body_bytes, lsa_body.pack_lsa_body())
Beispiel #4
0
 def test_add_prefix_info(self):
     lsa_body = intra_area_prefix.IntraAreaPrefix(0x2001, '0.0.0.0',
                                                  '8.8.8.8')
     self.assertEqual(0, len(lsa_body.prefixes))
     self.assertEqual(0, lsa_body.prefix_number)
     lsa_body.add_prefix_info(0, 0, 10, '::')
     self.assertEqual(1, len(lsa_body.prefixes))
     self.assertEqual(1, lsa_body.prefix_number)
     self.assertTrue('::', lsa_body.prefixes[0][3])
     lsa_body.add_prefix_info(0, 0, 10, '::')
     self.assertEqual(1, len(lsa_body.prefixes))
     self.assertEqual(1, lsa_body.prefix_number)
     lsa_body.add_prefix_info(1, 0, 10, '::')
     self.assertEqual(2, len(lsa_body.prefixes))
     self.assertEqual(2, lsa_body.prefix_number)
     self.assertEqual(1, lsa_body.prefixes[1][0])