def test_update4_process(self, update=update4_1, test_prefix="1.2.3.0/24"): """Check if IPv4 UPDATES are correcty processed.""" rib = EmulatedRIB() rib.set_access_time(2807) # Process route = Route(rib) message = route.process(update) # Compare the message that was returned if update == update4_1: assert message == [expected_message4] elif update == update6: assert message == [expected_message6] else: assert None == "Unknown abstracted BGP UPDATE !" # Retrieve the node from the radix tee node = rib.search_exact(test_prefix) # The node is in the tree assert node != None # Verify the internal structure integrity route_key = dict() route_key[RouteInformation(64497, 64496, "127.0.0.1")] = 2807 assert node.data.get("routes_information", None) == route_key
def test_update4_process(self, update=update4_1, test_prefix="1.2.3.0/24"): """Check if IPv4 UPDATES are correcty processed.""" rib = EmulatedRIB() rib.set_access_time(2807) # Process route = Route(rib) message = route.process(update) # Compare the message that was returned if update == update4_1: assert message == [ expected_message4 ] elif update == update6: assert message == [ expected_message6 ] else: assert None == "Unknown abstracted BGP UPDATE !" # Retrieve the node from the radix tee node = rib.search_exact(test_prefix) # The node is in the tree assert node != None # Verify the internal structure integrity route_key = dict() route_key[RouteInformation(64497, 64496, "127.0.0.1")] = 2807 assert node.data.get("routes_information", None) == route_key
def test_update(self): """Check update() behavior.""" rib = EmulatedRIB() rib.set_access_time(2807) rib.update("192.168.0.0/24", "value", "key") assert [x.prefix for x in rib.nodes()] == ["192.168.0.0/24"] assert [x.data for x in rib.nodes()] == [{"key": {"value": 2807}}]
def test_update(self): """Check update() behavior.""" rib = EmulatedRIB() rib.set_access_time(2807) rib.update("192.168.0.0/24", "value", "key") assert [ x.prefix for x in rib.nodes() ] == ["192.168.0.0/24"] assert [ x.data for x in rib.nodes() ] == [ {"key": { "value": 2807 } } ]
def test_bview_fake_withdraw_nothing(self): """Check the bview_fake_withdraw() behavior when there is nothing to do.""" rib = EmulatedRIB() rib.set_access_time(0) # Process an UPDATE route = Route(rib) route.process(update4) # Pretend to do a withdraw route_messages, hijack_messages = bview_fake_withdraw(rib, "collector", 0, 42) assert len(route_messages) == 0 assert len(hijack_messages) == 0 assert len(rib.nodes()) == 1
def test_bview_fake_withdraw_route(self): """Check the bview_fake_withdraw() behavior with regular routes.""" rib = EmulatedRIB() rib.set_access_time(0) # Process an UPDATE route = Route(rib) route.process(update4) # Pretend to do a withdraw route_messages, hijack_messages = bview_fake_withdraw(rib, "collector", 1, 42) assert len(route_messages) == 1 assert route_messages[0] == expected_fake_withdraw_route assert len(hijack_messages) == 0 assert len(rib.nodes()) == 0
def test_update4_origins_process(self): """Check if IPv4 UPDATES from several origins are correcty processed.""" rib = EmulatedRIB() rib.set_access_time(2807) # Process then retrieve the node from the radix tee route = Route(rib) route.process(update4_1) # Process the same UPDATE and pretend that it was inserted later route = Route(rib) route.process(update4_2) node = rib.search_exact("1.2.3.0/24") # Verify the internal structure integrity route_keys = dict() route_keys[RouteInformation(64497, 64496, "127.0.0.1")] = 2807 route_keys[RouteInformation(64500, 64496, "127.0.0.1")] = 2807 assert node.data.get("routes_information", None) == route_keys
def test_update4_origins_process(self): """Check if IPv4 UPDATES from several origins are correcty processed.""" rib = EmulatedRIB() rib.set_access_time(2807) # Process then retrieve the node from the radix tee route = Route(rib) route.process(update4_1) # Process the same UPDATE and pretend that it was inserted later route = Route(rib) route.process(update4_2) node = rib.search_exact("1.2.3.0/24") # Verify the internal structure integrity route_keys = dict() route_keys[RouteInformation(64497, 64496, "127.0.0.1")] = 2807 route_keys[RouteInformation(64500, 64496, "127.0.0.1")] = 2807 assert node.data.get("routes_information", None) == route_keys
def test_hijack_withdraw(self): """Check that a WITHDRAW concerning a hijack is correctly processed.""" rib = EmulatedRIB() rib.set_access_time(0) # Process an UPDATE route = Route(rib) route.process(update4) # Process the hijack hijack = Hijack(rib, "F") hijack.process(hijack4_specific) # Process a WITHDRAW withdraw = Withdraw(rib) route_messages, hijack_messages = withdraw.process(withdraw4_2) assert len(route_messages) == 0 assert hijack_messages == [ expected_specific_hijack_withdraw4 ] ri = RouteInformation(origin_asn=64497, peer_as=64496, peer_ip='127.0.0.1') nodes_data = map(lambda x: (x.prefix, x.data), rib.nodes()) assert nodes_data == [ ("1.2.3.0/24", { "routes_information": { ri: 0 } }) ]