def test_update_message_new_routes_parses_as4_new(self): serialised_message = build_byte_string("0000001c4001010040020e020300bc614e0000fe080001b2e5400304ac1900042009090909") parser = BgpMessageParser() parser.capabilities = { "fourbyteas": 12345 } message = parser.parse(BgpMessage.UPDATE_MESSAGE, serialised_message) self.assertEqual(message.nlri, [IP4Prefix.from_string("9.9.9.9/32")]) self.assertEqual(message.path_attributes["next_hop"], IP4Address.from_string("172.25.0.4")) self.assertEqual(message.path_attributes["origin"], "IGP") self.assertEqual(message.path_attributes["as_path"], "12345678 65032 111333")
def test_notification_message_parses(self): serialised_message = build_byte_string("0202feb0") message = BgpMessageParser().parse(BgpMessage.NOTIFICATION_MESSAGE, serialised_message) self.assertEqual(message.error_code, 2) self.assertEqual(message.error_subcode, 2) self.assertEqual(message.data, b"\xfe\xb0")
def test_update_message_new_routes_parses(self): serialised_message = build_byte_string("0000000e40010101400200400304c0a80021080a") message = BgpMessageParser().parse(BgpMessage.UPDATE_MESSAGE, serialised_message) self.assertEqual(message.nlri[0], IP4Prefix.from_string("10.0.0.0/8")) self.assertEqual(message.path_attributes["next_hop"], IP4Address.from_string("192.168.0.33")) self.assertEqual(message.path_attributes["origin"], "EGP") self.assertEqual(message.path_attributes["as_path"], "")
def test_open_message_parses_ipv6_multiprotocol(self): serialised_message = build_byte_string("04fe0900b4c0a8000f080206010400020001") message = BgpMessageParser().parse(BgpMessage.OPEN_MESSAGE, serialised_message) self.assertEqual(message.version, 4) self.assertEqual(message.peer_as, 65033) self.assertEqual(message.hold_time, 180) self.assertEqual(message.identifier, IP4Address.from_string("192.168.0.15")) self.assertEqual(message.capabilities["multiprotocol"], ["ipv6-unicast"])
def test_update_v6_message_new_routes_parses(self): serialised_message = build_byte_string("0000004b400101004002040201fdeb800e3d0002012020010db80001000000000242ac110002fe800000000000000042acfffe110002007f20010db40000000000000000000000002f20010db30000") message = BgpMessageParser().parse(BgpMessage.UPDATE_MESSAGE, serialised_message) self.assertEqual(message.path_attributes["origin"], "IGP") self.assertEqual(message.path_attributes["mp_reach_nlri"]["next_hop"][0], IP6Address.from_string("2001:db8:1::242:ac11:2")) self.assertEqual(message.path_attributes["mp_reach_nlri"]["next_hop"][1], IP6Address.from_string("fe80::42:acff:fe11:2")) self.assertEqual(message.path_attributes["mp_reach_nlri"]["nlri"][0], IP6Prefix.from_string("2001:db4::/127")) self.assertEqual(message.path_attributes["mp_reach_nlri"]["nlri"][1], IP6Prefix.from_string("2001:db3::/47"))
def test_update_message_new_routes_parses_as4(self): serialised_message = build_byte_string("000000274001010040020802035ba0fe08fdebc0110e020300bc614e0000fe080000fdeb400304ac1900042009090909") message = BgpMessageParser().parse(BgpMessage.UPDATE_MESSAGE, serialised_message) self.assertEqual(message.nlri, [IP4Prefix.from_string("9.9.9.9/32")]) self.assertEqual(message.path_attributes["next_hop"], IP4Address.from_string("172.25.0.4")) self.assertEqual(message.path_attributes["origin"], "IGP") self.assertEqual(message.path_attributes["as_path"], "23456 65032 65003") self.assertEqual(message.path_attributes["as4_path"], "12345678 65032 65003")
def test_open_message_parses_exabgp_optional_params(self): serialised_message = build_byte_string("04fe0900b4c0a8000f9402060104000100010206010400010002020601040001000402060104000100800206010400010084020601040001008502060104000100860206010400020001020601040002000202060104000200040206010400020080020601040002008502060104000200860206010400190041020601040019004602060104400400470206010440040048020206000206410400010001") message = BgpMessageParser().parse(BgpMessage.OPEN_MESSAGE, serialised_message) self.assertEqual(message.version, 4) self.assertEqual(message.peer_as, 65033) self.assertEqual(message.hold_time, 180) self.assertEqual(message.identifier, IP4Address.from_string("192.168.0.15")) self.assertTrue("ipv4-unicast" in message.capabilities["multiprotocol"]) self.assertTrue("ipv6-unicast" in message.capabilities["multiprotocol"])
def test_update_v6_message_withdrawn_routes_parses(self): serialised_message = build_byte_string("0000002d800f2a0002017f20010db40000000000000000000000003020010db100003320010db20000002f20010db30000") message = BgpMessageParser().parse(BgpMessage.UPDATE_MESSAGE, serialised_message) expected_withdrawn_routes = [ IP6Prefix.from_string("2001:db4::/127"), IP6Prefix.from_string("2001:db1::/48"), IP6Prefix.from_string("2001:db2::/51"), IP6Prefix.from_string("2001:db3::/47") ] self.assertEqual(message.path_attributes["mp_unreach_nlri"]["withdrawn_routes"], expected_withdrawn_routes)
def test_update_message_withdrawn_routes_parses(self): serialised_message = build_byte_string("0004180a01010000") message = BgpMessageParser().parse(BgpMessage.UPDATE_MESSAGE, serialised_message) self.assertEqual(message.withdrawn_routes[0], IP4Prefix.from_string("10.1.1.0/24"))
def test_keepalive_message_parses(self): serialised_message = b"" message = BgpMessageParser().parse(BgpMessage.KEEPALIVE_MESSAGE, serialised_message)