def test_has_prefix_info(self): lsa_body = link.Link(1, 51, 'fe80::c004:18ff:fe30:0') lsa_body.add_prefix_info(1, 0, '::') self.assertTrue(lsa_body.has_prefix_info(1, 0, '::')) self.assertFalse(lsa_body.has_prefix_info(0, 0, '::')) self.assertFalse(lsa_body.has_prefix_info(1, 1, '::')) self.assertFalse(lsa_body.has_prefix_info(1, 0, '1::'))
def test_pack_body(self): body_bytes = b'\x01\x00\x003\xfe\x80\x00\x00\x00\x00\x00\x00\xc0\x04\x18\xff\xfe0\x00\x00\x00\x00\x00\x00' lsa_body = link.Link(1, 51, 'fe80::c004:18ff:fe30:0') self.assertEqual(body_bytes, lsa_body.pack_lsa_body()) body_bytes = b'\x01\x00\x003\xfe\x80\x00\x00\x00\x00\x00\x00\xc0\x04\x18\xff\xfe0\x00\x00\x00\x00\x00\t\x00' \ b'\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00 \x01\r\xb8!\x00\x00\x00 \x01\r\xb8' \ b'\x80\x00\x00\x00@\x00\x00\x00 \x01\r\xb8\xca\xfe\x00\x11A\x00\x00\x00 \x01\r\xb8\xca\xfe\x00' \ b'\x12\x00\x00\x00\x00`\x00\x00\x00 \x01\r\xb8\xca\xfe\x00\x13\x00\x00\x00\x00a\x00\x00\x00 \x01' \ b'\r\xb8\xca\xfe\x00\x14\x00\x00\x00\x00\x00\x00\x00\x00\x80\x02\x00\x00 \x01\r\xb8\xca\xfe\x00' \ b'\x15\x00\x00\x00\x00\x00\x00\x00\x01' lsa_body = link.Link(1, 51, 'fe80::c004:18ff:fe30:0') lsa_body.add_prefix_info(0, 0, '::') lsa_body.add_prefix_info(1, 0, '::') lsa_body.add_prefix_info(32, 0, '2001:db8::') lsa_body.add_prefix_info(33, 0, '2001:db8:8000::') lsa_body.add_prefix_info(64, 0, '2001:db8:cafe:11::') lsa_body.add_prefix_info(65, 0, '2001:db8:cafe:12::') lsa_body.add_prefix_info(96, 0, '2001:db8:cafe:13::') lsa_body.add_prefix_info(97, 0, '2001:db8:cafe:14::') lsa_body.add_prefix_info(128, 2, '2001:db8:cafe:15::1') self.assertEqual(body_bytes, lsa_body.pack_lsa_body())
def test_add_prefix_info(self): lsa_body = link.Link(1, 51, 'fe80::c004:18ff:fe30:0') self.assertEqual(0, len(lsa_body.prefixes)) self.assertEqual(0, lsa_body.prefix_number) lsa_body.add_prefix_info(1, 0, '::') self.assertEqual(1, len(lsa_body.prefixes)) self.assertEqual(1, lsa_body.prefix_number) self.assertEqual(1, lsa_body.prefixes[0][0]) lsa_body.add_prefix_info(1, 0, '::') self.assertEqual(1, len(lsa_body.prefixes)) self.assertEqual(1, lsa_body.prefix_number) self.assertEqual(1, lsa_body.prefixes[0][0]) lsa_body.add_prefix_info(3, 0, '::') self.assertEqual(2, len(lsa_body.prefixes)) self.assertEqual(2, lsa_body.prefix_number) self.assertEqual(3, lsa_body.prefixes[1][0])
def create_link_lsa_body(self, router_priority, options, link_local_address): self.body = link.Link(router_priority, options, link_local_address) # Link-LSAs have link local scope - LS Type field remains unchanged self.set_lsa_length() self.set_lsa_checksum()