diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/test_ip6.py | 104 | ||||
-rw-r--r-- | test/vpp_ip_route.py | 104 | ||||
-rw-r--r-- | test/vpp_papi_provider.py | 11 |
3 files changed, 217 insertions, 2 deletions
diff --git a/test/test_ip6.py b/test/test_ip6.py index 16726798008..db90b84ed0f 100644 --- a/test/test_ip6.py +++ b/test/test_ip6.py @@ -28,7 +28,7 @@ from vpp_ip_route import VppIpRoute, VppRoutePath, find_route, VppIpMRoute, \ VppMRoutePath, VppMplsIpBind, \ VppMplsRoute, VppMplsTable, VppIpTable, FibPathType, FibPathProto, \ VppIpInterfaceAddress, find_route_in_dump, find_mroute_in_dump, \ - VppIp6LinkLocalAddress + VppIp6LinkLocalAddress, VppIpRouteV2 from vpp_neighbor import find_nbr, VppNeighbor from vpp_ipip_tun_interface import VppIpIpTunInterface from vpp_pg_interface import is_ipv6_misc @@ -3269,5 +3269,107 @@ class TestIPv6PathMTU(VppTestCase): self.send_and_expect(self.pg0, [p_1k], self.pg1) +class TestIPFibSource(VppTestCase): + """ IPv6 Table FibSource """ + + @classmethod + def setUpClass(cls): + super(TestIPFibSource, cls).setUpClass() + + @classmethod + def tearDownClass(cls): + super(TestIPFibSource, cls).tearDownClass() + + def setUp(self): + super(TestIPFibSource, self).setUp() + + self.create_pg_interfaces(range(2)) + + for i in self.pg_interfaces: + i.admin_up() + i.config_ip6() + i.resolve_arp() + i.generate_remote_hosts(2) + i.configure_ipv6_neighbors() + + def tearDown(self): + super(TestIPFibSource, self).tearDown() + for i in self.pg_interfaces: + i.admin_down() + i.unconfig_ip4() + + def test_fib_source(self): + """ IP Table FibSource """ + + routes = self.vapi.ip_route_v2_dump(0, True) + + # 2 interfaces (4 routes) + 2 specials + 4 neighbours = 10 routes + self.assertEqual(len(routes), 10) + + # dump all the sources in the FIB + sources = self.vapi.fib_source_dump() + for source in sources: + if (source.src.name == "API"): + api_source = source.src + if (source.src.name == "interface"): + intf_source = source.src + if (source.src.name == "adjacency"): + adj_source = source.src + if (source.src.name == "special"): + special_source = source.src + if (source.src.name == "default-route"): + dr_source = source.src + + # dump the individual route types + routes = self.vapi.ip_route_v2_dump(0, True, src=adj_source.id) + self.assertEqual(len(routes), 4) + routes = self.vapi.ip_route_v2_dump(0, True, src=intf_source.id) + self.assertEqual(len(routes), 4) + routes = self.vapi.ip_route_v2_dump(0, True, src=special_source.id) + self.assertEqual(len(routes), 1) + routes = self.vapi.ip_route_v2_dump(0, True, src=dr_source.id) + self.assertEqual(len(routes), 1) + + # add a new soure that'a better than the API + self.vapi.fib_source_add(src={'name': "bgp", + "priority": api_source.priority - 1}) + + # dump all the sources to check our new one is there + sources = self.vapi.fib_source_dump() + + for source in sources: + if (source.src.name == "bgp"): + bgp_source = source.src + + self.assertTrue(bgp_source) + self.assertEqual(bgp_source.priority, + api_source.priority - 1) + + # add a route with the default API source + r1 = VppIpRouteV2( + self, "2001::1", 128, + [VppRoutePath(self.pg0.remote_ip6, + self.pg0.sw_if_index)]).add_vpp_config() + + r2 = VppIpRouteV2(self, "2001::1", 128, + [VppRoutePath(self.pg1.remote_ip6, + self.pg1.sw_if_index)], + src=bgp_source.id).add_vpp_config() + + # ensure the BGP source takes priority + p = (Ether(src=self.pg0.remote_mac, + dst=self.pg0.local_mac) / + IPv6(src=self.pg0.remote_ip6, dst="2001::1") / + inet6.UDP(sport=1234, dport=1234) / + Raw(b'\xa5' * 100)) + + self.send_and_expect(self.pg0, [p], self.pg1) + + r2.remove_vpp_config() + r1.remove_vpp_config() + + self.assertFalse(find_route(self, "2001::1", 128)) + + if __name__ == '__main__': unittest.main(testRunner=VppTestRunner) diff --git a/test/vpp_ip_route.py b/test/vpp_ip_route.py index a50693c4f26..b6059485275 100644 --- a/test/vpp_ip_route.py +++ b/test/vpp_ip_route.py @@ -606,6 +606,110 @@ class VppIpRoute(VppObject): return c[0][self.stats_index] +class VppIpRouteV2(VppObject): + """ + IP Route V2 + """ + + def __init__(self, test, dest_addr, + dest_addr_len, paths, table_id=0, + register=True, src=0): + self._test = test + self.paths = paths + self.table_id = table_id + self.prefix = mk_network(dest_addr, dest_addr_len) + self.register = register + self.stats_index = None + self.modified = False + self.src = src + + self.encoded_paths = [] + for path in self.paths: + self.encoded_paths.append(path.encode()) + + def __eq__(self, other): + if self.table_id == other.table_id and \ + self.prefix == other.prefix: + return True + return False + + def modify(self, paths): + self.paths = paths + self.encoded_paths = [] + for path in self.paths: + self.encoded_paths.append(path.encode()) + self.modified = True + + self._test.vapi.ip_route_add_del_v2(route={'table_id': self.table_id, + 'prefix': self.prefix, + 'src': self.src, + 'n_paths': len( + self.encoded_paths), + 'paths': self.encoded_paths, + }, + is_add=1, + is_multipath=0) + + def add_vpp_config(self): + r = self._test.vapi.ip_route_add_del_v2( + route={'table_id': self.table_id, + 'prefix': self.prefix, + 'n_paths': len(self.encoded_paths), + 'paths': self.encoded_paths, + 'src': self.src, + }, + is_add=1, + is_multipath=0) + self.stats_index = r.stats_index + if self.register: + self._test.registry.register(self, self._test.logger) + return self + + def remove_vpp_config(self): + # there's no need to issue different deletes for modified routes + # we do this only to test the two different ways to delete routes + # eiter by passing all the paths to remove and mutlipath=1 or + # passing no paths and multipath=0 + if self.modified: + self._test.vapi.ip_route_add_del_v2( + route={'table_id': self.table_id, + 'prefix': self.prefix, + 'src': self.src, + 'n_paths': len( + self.encoded_paths), + 'paths': self.encoded_paths}, + is_add=0, + is_multipath=1) + else: + self._test.vapi.ip_route_add_del_v2( + route={'table_id': self.table_id, + 'prefix': self.prefix, + 'src': self.src, + 'n_paths': 0}, + is_add=0, + is_multipath=0) + + def query_vpp_config(self): + return find_route(self._test, + self.prefix.network_address, + self.prefix.prefixlen, + self.table_id) + + def object_id(self): + return ("%s:table-%d-%s" % ( + 'ip6-route' if self.prefix.version == 6 else 'ip-route', + self.table_id, + self.prefix)) + + def get_stats_to(self): + c = self._test.statistics.get_counter("/net/route/to") + return c[0][self.stats_index] + + def get_stats_via(self): + c = self._test.statistics.get_counter("/net/route/via") + return c[0][self.stats_index] + + class VppIpMRoute(VppObject): """ IP Multicast Route diff --git a/test/vpp_papi_provider.py b/test/vpp_papi_provider.py index da693c73e2a..d677ab316b2 100644 --- a/test/vpp_papi_provider.py +++ b/test/vpp_papi_provider.py @@ -48,7 +48,6 @@ defaultmapping = { 'classify_table_index': 4294967295, 'is_add': 1, }, 'ip_mroute_add_del': {'is_add': 1, }, 'ip_neighbor_add_del': {'is_add': 1, }, - 'ip_route_add_del': {'is_add': 1, }, 'ipsec_interface_add_del_spd': {'is_add': 1, }, 'ipsec_spd_add_del': {'is_add': 1, }, 'ipsec_spd_dump': {'sa_id': 4294967295, }, @@ -410,6 +409,16 @@ class VppPapiProvider(object): 'is_ip6': is_ip6 }}) + def ip_route_v2_dump(self, table_id, is_ip6=False, src=0): + return self.api(self.papi.ip_route_v2_dump, + { + 'src': src, + 'table': { + 'table_id': table_id, + 'is_ip6': is_ip6 + } + }) + def ip_neighbor_add_del(self, sw_if_index, mac_address, |