Ejemplo n.º 1
0
 def test_update_v6_message_adds_route(self):
     path_attributes = {
         "as_path" : "65032 65011 65002",
         "origin" : "EGP",
         "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"),
             ]
         }
     }
     route_attributes = {
         "prefix" : IP6Prefix.from_string("2001:db4::/127"),
         "next_hop" : IP6Address.from_string("2001:db8:1::242:ac11:2"),
         "as_path" : "65032 65011 65002",
         "origin" : "EGP"
     }
     message = BgpUpdateMessage([], path_attributes, [])
     self.state_machine.event(EventMessageReceived(message), self.tick)
     self.assertEqual(self.state_machine.state, "established")
     self.assertEqual(self.state_machine.route_updates.qsize(), 1)
     self.assertEqual(self.state_machine.route_updates.get(), RouteAddition(**route_attributes))
Ejemplo n.º 2
0
 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"))
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
 def test_keepalive_message_sends_all_routes_v6(self):
     self.tick += 3600
     self.state_machine.routes_to_advertise = [
         RouteAddition(
             IP6Prefix.from_string("2001:db4::/127"),
             IP6Address.from_string("2001:db1::1"),
             "",
             "IGP"
         ),
         RouteAddition(
             IP6Prefix.from_string("2001:db5::/127"),
             IP6Address.from_string("2001:db1::1"),
             "",
             "IGP"
         ),
         RouteAddition(
             IP6Prefix.from_string("2001:db6::/127"),
             IP6Address.from_string("2001:db1::2"),
             "",
             "IGP"
         )
     ]
     message = BgpKeepaliveMessage()
     self.state_machine.event(EventMessageReceived(message), self.tick)
     self.assertEqual(self.state_machine.state, "established")
     self.assertTrue(self.state_machine.timers["hold"].running())
     self.assertFalse(self.state_machine.timers["hold"].expired(self.tick))
     self.assertEqual(self.state_machine.output_messages.qsize(), 2)
     first_update = self.state_machine.output_messages.get()
     second_update = self.state_machine.output_messages.get()
     self.assertTrue(isinstance(first_update, BgpUpdateMessage))
     self.assertTrue(isinstance(second_update, BgpUpdateMessage))
     self.assertEqual(first_update.path_attributes["mp_reach_nlri"]["next_hop"], [IP6Address.from_string("2001:db1::1")])
     self.assertEqual(first_update.path_attributes["mp_reach_nlri"]["nlri"], [
         IP6Prefix.from_string("2001:db4::/127"),
         IP6Prefix.from_string("2001:db5::/127")
     ])
     self.assertEqual(second_update.path_attributes["mp_reach_nlri"]["next_hop"], [IP6Address.from_string("2001:db1::2")])
     self.assertEqual(second_update.path_attributes["mp_reach_nlri"]["nlri"], [
         IP6Prefix.from_string("2001:db6::/127")
     ])