Beispiel #1
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)
Beispiel #2
0
 def test_open_message_advances_to_idle_and_sends_notification(self):
     message = BgpOpenMessage(4, 65002, 240, IP4Address.from_string("2.2.2.2"), {"multiprotocol": "ipv4-unicast"})
     with self.assertRaises(IdleError) as context:
         self.state_machine.event(EventMessageReceived(message), self.tick)
     self.assertEqual(self.state_machine.state, "idle")
     self.assertEqual(self.state_machine.output_messages.qsize(), 1)
     message = self.state_machine.output_messages.get()
     self.assertEqual(message.error_code, 6) # Cease
Beispiel #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)
Beispiel #4
0
 def setUp(self):
     self.tick = 10000
     self.state_machine = StateMachine(local_as=65001, peer_as=65002, local_address="1.1.1.1", router_id="1.1.1.1", neighbor="2.2.2.2", hold_time=240)
     message = BgpOpenMessage(4, 65002, 240, IP4Address.from_string("2.2.2.2"), {"multiprotocol": "ipv4-unicast"})
     self.state_machine.event(EventMessageReceived(message), self.tick)
     self.assertEqual(self.state_machine.state, "open_confirm")
     for _ in range(self.state_machine.output_messages.qsize()):
         self.state_machine.output_messages.get()
     self.assertTrue(self.state_machine.timers["keepalive"].running())
     self.assertTrue(self.state_machine.timers["hold"].running())
Beispiel #5
0
 def test_open_message_advances_to_open_confirm_and_sets_timers(self):
     capabilities = {"multiprotocol": "ipv4-unicast"}
     message = BgpOpenMessage(4, 65002, 240, IP4Address.from_string("2.2.2.2"), capabilities)
     self.state_machine.event(EventMessageReceived(message), self.tick)
     self.assertEqual(self.state_machine.state, "open_confirm")
     self.assertEqual(self.state_machine.output_messages.qsize(), 1)
     self.open_handler.assert_called_with(capabilities)
     self.assertTrue(isinstance(self.state_machine.output_messages.get(), BgpKeepaliveMessage))
     self.assertTrue(self.state_machine.timers["hold"].running())
     self.assertTrue(self.state_machine.timers["keepalive"].running())