コード例 #1
0
 def test_update_message_new_routes_packs_as4_new(self):
     expected_serialised_message = build_byte_string("0000001c4001010040020e020300bc614e0000fe080001b2e5400304ac1900042009090909")
     nlri = [
         IP4Prefix.from_string("9.9.9.9/32"),
     ]
     path_attributes = {
         "next_hop": IP4Address.from_string("172.25.0.4"),
         "origin": "IGP",
         "as_path": "12345678 65032 111333"
     }
     message = BgpUpdateMessage([], path_attributes, nlri)
     packer = BgpMessagePacker()
     packer.capabilities = {"fourbyteas": 12345}
     serialised_message = packer.pack(message)
     self.assertEqual(serialised_message[19:], expected_serialised_message)
コード例 #2
0
 def test_open_message_packs(self):
     expected_serialised_message = build_byte_string(
         "04fe0900b4c0a8000f080206010400010001")
     message = BgpOpenMessage(4, 65033, 180,
                              IP4Address.from_string("192.168.0.15"),
                              {"multiprotocol": ["ipv4-unicast"]})
     serialised_message = BgpMessagePacker().pack(message)
     self.assertEqual(serialised_message[19:], expected_serialised_message)
コード例 #3
0
 def test_open_message_packs_capabilities(self):
     expected_serialised_message = build_byte_string("04fe0900b4c0a8000f160214010400010001010400020001020041040000fdeb")
     capabilities = {
         "multiprotocol": ["ipv4-unicast", "ipv6-unicast"],
         "routerefresh": [True],
         "fourbyteas": [65003]
     }
     message = BgpOpenMessage(4, 65033, 180, IP4Address.from_string("192.168.0.15"), capabilities)
     serialised_message = BgpMessagePacker().pack(message)
     self.assertEqual(serialised_message[19:], expected_serialised_message)
コード例 #4
0
 def test_update_message_new_routes_packs_as4(self):
     expected_serialised_message = build_byte_string("000000274001010040020802035ba0fe08fdebc0110e020300bc614e0000fe080000fdeb400304ac1900042009090909")
     nlri = [
         IP4Prefix.from_string("9.9.9.9/32"),
     ]
     path_attributes = {
         "next_hop": IP4Address.from_string("172.25.0.4"),
         "origin": "IGP",
         "as_path": "23456 65032 65003",
         "as4_path": "12345678 65032 65003"
     }
     message = BgpUpdateMessage([], path_attributes, nlri)
     serialised_message = BgpMessagePacker().pack(message)
     self.assertEqual(serialised_message[19:], expected_serialised_message)
コード例 #5
0
 def test_update_message_new_routes_packs(self):
     expected_serialised_message = build_byte_string("0000000e40010101400200400304c0a80021080a17c0a840")
     nlri = [
         IP4Prefix.from_string("10.0.0.0/8"),
         IP4Prefix.from_string("192.168.64.0/23")
     ]
     path_attributes = {
         "next_hop": IP4Address.from_string("192.168.0.33"),
         "origin": "EGP",
         "as_path": ""
     }
     message = BgpUpdateMessage([], path_attributes, nlri)
     serialised_message = BgpMessagePacker().pack(message)
     self.assertEqual(serialised_message[19:], expected_serialised_message)
コード例 #6
0
    def test_update_v6_message_withdrawn_routes_packs(self):
        expected_serialised_message = build_byte_string("0000002d800f2a0002017f20010db40000000000000000000000003020010db100003320010db20000002f20010db30000")

        path_attributes = {
            "mp_unreach_nlri": {
                "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")
                ]
            }
        }

        message = BgpUpdateMessage([], path_attributes, [])
        serialised_message = BgpMessagePacker().pack(message)
        self.assertEqual(serialised_message[19:], expected_serialised_message)
コード例 #7
0
 def test_update_v6_message_new_routes_packs(self):
     expected_serialised_message = build_byte_string("0000004740010100400200800e3d0002012020010db80001000000000242ac110002fe800000000000000042acfffe110002007f20010db40000000000000000000000002f20010db30000")
     path_attributes = {
         "origin": "IGP",
         "as_path": "",
         "mp_reach_nlri": {
             "next_hop": [
                 IP6Address.from_string("2001:db8:1::242:ac11:2"),
                 IP6Address.from_string("fe80::42:acff:fe11:2")
             ],
             "nlri": [
                 IP6Prefix.from_string("2001:db4::/127"),
                 IP6Prefix.from_string("2001:db3::/47")
             ]
         }
     }
     message = BgpUpdateMessage([], path_attributes, [])
     serialised_message = BgpMessagePacker().pack(message)
     self.assertEqual(serialised_message[19:], expected_serialised_message)
コード例 #8
0
 def test_update_message_withdrawn_routes_packs(self):
     expected_serialised_message = build_byte_string("0004180a01010000")
     message = BgpUpdateMessage([IP4Prefix.from_string("10.1.1.0/24")], {},
                                [])
     serialised_message = BgpMessagePacker().pack(message)
     self.assertEqual(serialised_message[19:], expected_serialised_message)
コード例 #9
0
 def test_notification_message_packs(self):
     expected_serialised_message = build_byte_string("0202feb0")
     message = BgpNotificationMessage(2, 2, b"\xfe\xb0")
     serialised_message = BgpMessagePacker().pack(message)
     self.assertEqual(serialised_message[19:], expected_serialised_message)
コード例 #10
0
 def test_keepalive_message_packs(self):
     expected_serialised_message = b""
     message = BgpKeepaliveMessage()
     serialised_message = BgpMessagePacker().pack(message)
     self.assertEqual(serialised_message[19:], expected_serialised_message)