diff options
author | Neale Ranns <neale.ranns@cisco.com> | 2018-05-01 05:17:55 -0700 |
---|---|---|
committer | Ole Trøan <otroan@employees.org> | 2019-06-18 13:31:39 +0000 |
commit | 097fa66b986f06281f603767d321ab13ab6c88c3 (patch) | |
tree | ed052819615d08ee4bd0afbc34de7e64e4598105 /test/test_ip4.py | |
parent | 39baa32186fd3e4b20d9f58afbbfe7b8daebed62 (diff) |
fib: fib api updates
Enhance the route add/del APIs to take a set of paths rather than just one.
Most unicast routing protocols calcualte all the available paths in one
run of the algorithm so updating all the paths at once is beneficial for the client.
two knobs control the behaviour:
is_multipath - if set the the set of paths passed will be added to those
that already exist, otherwise the set will replace them.
is_add - add or remove the set
is_add=0, is_multipath=1 and an empty set, results in deleting the route.
It is also considerably faster to add multiple paths at once, than one at a time:
vat# ip_add_del_route 1.1.1.1/32 count 100000 multipath via 10.10.10.11
100000 routes in .572240 secs, 174751.80 routes/sec
vat# ip_add_del_route 1.1.1.1/32 count 100000 multipath via 10.10.10.12
100000 routes in .528383 secs, 189256.54 routes/sec
vat# ip_add_del_route 1.1.1.1/32 count 100000 multipath via 10.10.10.13
100000 routes in .757131 secs, 132077.52 routes/sec
vat# ip_add_del_route 1.1.1.1/32 count 100000 multipath via 10.10.10.14
100000 routes in .878317 secs, 113854.12 routes/sec
vat# ip_route_add_del 1.1.1.1/32 count 100000 multipath via 10.10.10.11 via 10.10.10.12 via 10.10.10.13 via 10.10.10.14
100000 routes in .900212 secs, 111084.93 routes/sec
Change-Id: I416b93f7684745099c1adb0b33edac58c9339c1a
Signed-off-by: Neale Ranns <neale.ranns@cisco.com>
Signed-off-by: Ole Troan <ot@cisco.com>
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
Diffstat (limited to 'test/test_ip4.py')
-rw-r--r-- | test/test_ip4.py | 201 |
1 files changed, 69 insertions, 132 deletions
diff --git a/test/test_ip4.py b/test/test_ip4.py index 6d6aeb0a5d9..933958911fe 100644 --- a/test/test_ip4.py +++ b/test/test_ip4.py @@ -15,7 +15,7 @@ from framework import VppTestCase, VppTestRunner from util import ppp from vpp_ip_route import VppIpRoute, VppRoutePath, VppIpMRoute, \ VppMRoutePath, MRouteItfFlags, MRouteEntryFlags, VppMplsIpBind, \ - VppMplsTable, VppIpTable + VppMplsTable, VppIpTable, FibPathType, find_route from vpp_sub_interface import VppSubInterface, VppDot1QSubint, VppDot1ADSubint from vpp_papi import VppEnum @@ -80,7 +80,6 @@ class TestIPv4(VppTestCase): i.resolve_arp() # config 2M FIB entries - self.config_fib_entries(200) def tearDown(self): """Run standard test teardown and log ``show ip arp``.""" @@ -90,33 +89,6 @@ class TestIPv4(VppTestCase): self.logger.info(self.vapi.cli("show ip arp")) # info(self.vapi.cli("show ip fib")) # many entries - def config_fib_entries(self, count): - """For each interface add to the FIB table *count* routes to - "10.0.0.1/32" destination with interface's local address as next-hop - address. - - :param int count: Number of FIB entries. - - - *TODO:* check if the next-hop address shouldn't be remote address - instead of local address. - """ - n_int = len(self.interfaces) - percent = 0 - counter = 0.0 - dest_addr = socket.inet_pton(socket.AF_INET, "10.0.0.1") - dest_addr_len = 32 - for i in self.interfaces: - next_hop_address = i.local_ip4n - for j in range(count / n_int): - self.vapi.ip_add_del_route(dst_address=dest_addr, - dst_address_length=dest_addr_len, - next_hop_address=next_hop_address) - counter += 1 - if counter / count * 100 > percent: - self.logger.info("Configure %d FIB entries .. %d%% done" % - (count, percent)) - percent += 1 - def modify_packet(self, src_if, packet_size, pkt): """Add load, set destination IP and extend packet to required packet size for defined interface. @@ -318,7 +290,8 @@ class TestIPv4FibCrud(VppTestCase): ..note:: Python API is too slow to add many routes, needs replacement. """ - def config_fib_many_to_one(self, start_dest_addr, next_hop_addr, count): + def config_fib_many_to_one(self, start_dest_addr, next_hop_addr, + count, start=0): """ :param start_dest_addr: @@ -326,42 +299,30 @@ class TestIPv4FibCrud(VppTestCase): :param count: :return list: added ips with 32 prefix """ - added_ips = [] - dest_addr = int(binascii.hexlify(socket.inet_pton(socket.AF_INET, - start_dest_addr)), 16) - dest_addr_len = 32 - n_next_hop_addr = socket.inet_pton(socket.AF_INET, next_hop_addr) - for _ in range(count): - n_dest_addr = binascii.unhexlify('{:08x}'.format(dest_addr)) - self.vapi.ip_add_del_route(dst_address=n_dest_addr, - dst_address_length=dest_addr_len, - next_hop_address=n_next_hop_addr) - added_ips.append(socket.inet_ntoa(n_dest_addr)) - dest_addr += 1 - return added_ips - - def unconfig_fib_many_to_one(self, start_dest_addr, next_hop_addr, count): - - removed_ips = [] - dest_addr = int(binascii.hexlify(socket.inet_pton(socket.AF_INET, - start_dest_addr)), 16) - dest_addr_len = 32 - n_next_hop_addr = socket.inet_pton(socket.AF_INET, next_hop_addr) - for _ in range(count): - n_dest_addr = binascii.unhexlify('{:08x}'.format(dest_addr)) - self.vapi.ip_add_del_route(dst_address=n_dest_addr, - dst_address_length=dest_addr_len, - next_hop_address=n_next_hop_addr, - is_add=0) - removed_ips.append(socket.inet_ntoa(n_dest_addr)) - dest_addr += 1 - return removed_ips - - def create_stream(self, src_if, dst_if, dst_ips, count): + routes = [] + for i in range(count): + r = VppIpRoute(self, start_dest_addr % (i + start), 32, + [VppRoutePath(next_hop_addr, 0xffffffff)]) + r.add_vpp_config() + routes.append(r) + return routes + + def unconfig_fib_many_to_one(self, start_dest_addr, next_hop_addr, + count, start=0): + + routes = [] + for i in range(count): + r = VppIpRoute(self, start_dest_addr % (i + start), 32, + [VppRoutePath(next_hop_addr, 0xffffffff)]) + r.remove_vpp_config() + routes.append(r) + return routes + + def create_stream(self, src_if, dst_if, routes, count): pkts = [] for _ in range(count): - dst_addr = random.choice(dst_ips) + dst_addr = random.choice(routes).prefix.address info = self.create_packet_info(src_if, dst_if) payload = self.info_to_payload(info) p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) / @@ -389,18 +350,6 @@ class TestIPv4FibCrud(VppTestCase): return p return None - @staticmethod - def _match_route_detail(route_detail, ip, address_length=32, table_id=0): - if route_detail.address == socket.inet_pton(socket.AF_INET, ip): - if route_detail.table_id != table_id: - return False - elif route_detail.address_length != address_length: - return False - else: - return True - else: - return False - def verify_capture(self, dst_interface, received_pkts, expected_pkts): self.assertEqual(len(received_pkts), len(expected_pkts)) to_verify = list(expected_pkts) @@ -411,27 +360,13 @@ class TestIPv4FibCrud(VppTestCase): to_verify.remove(x) self.assertListEqual(to_verify, []) - def verify_route_dump(self, fib_dump, ips): - - def _ip_in_route_dump(ip, fib_dump): - return next((route for route in fib_dump - if self._match_route_detail(route, ip)), - False) - - for ip in ips: - self.assertTrue(_ip_in_route_dump(ip, fib_dump), - 'IP {!s} is not in fib dump.'.format(ip)) - - def verify_not_in_route_dump(self, fib_dump, ips): - - def _ip_in_route_dump(ip, fib_dump): - return next((route for route in fib_dump - if self._match_route_detail(route, ip)), - False) + def verify_route_dump(self, routes): + for r in routes: + self.assertTrue(find_route(self, r.prefix.address, r.prefix.len)) - for ip in ips: - self.assertFalse(_ip_in_route_dump(ip, fib_dump), - 'IP {!s} is in fib dump.'.format(ip)) + def verify_not_in_route_dump(self, routes): + for r in routes: + self.assertFalse(find_route(self, r.prefix.address, r.prefix.len)) @classmethod def setUpClass(cls): @@ -474,16 +409,13 @@ class TestIPv4FibCrud(VppTestCase): self.deleted_routes = [] def test_1_add_routes(self): - """ Add 1k routes + """ Add 1k routes """ - - add 100 routes check with traffic script. - """ - # config 1M FIB entries + # add 100 routes check with traffic script. self.configured_routes.extend(self.config_fib_many_to_one( - "10.0.0.0", self.pg0.remote_ip4, 100)) + "10.0.0.%d", self.pg0.remote_ip4, 100)) - fib_dump = self.vapi.ip_fib_dump() - self.verify_route_dump(fib_dump, self.configured_routes) + self.verify_route_dump(self.configured_routes) self.stream_1 = self.create_stream( self.pg1, self.pg0, self.configured_routes, 100) @@ -505,14 +437,13 @@ class TestIPv4FibCrud(VppTestCase): """ # config 1M FIB entries self.configured_routes.extend(self.config_fib_many_to_one( - "10.0.0.0", self.pg0.remote_ip4, 100)) + "10.0.0.%d", self.pg0.remote_ip4, 100)) self.deleted_routes.extend(self.unconfig_fib_many_to_one( - "10.0.0.10", self.pg0.remote_ip4, 10)) + "10.0.0.%d", self.pg0.remote_ip4, 10, start=10)) for x in self.deleted_routes: self.configured_routes.remove(x) - fib_dump = self.vapi.ip_fib_dump() - self.verify_route_dump(fib_dump, self.configured_routes) + self.verify_route_dump(self.configured_routes) self.stream_1 = self.create_stream( self.pg1, self.pg0, self.configured_routes, 100) @@ -538,23 +469,22 @@ class TestIPv4FibCrud(VppTestCase): """ # config 1M FIB entries self.configured_routes.extend(self.config_fib_many_to_one( - "10.0.0.0", self.pg0.remote_ip4, 100)) + "10.0.0.%d", self.pg0.remote_ip4, 100)) self.deleted_routes.extend(self.unconfig_fib_many_to_one( - "10.0.0.10", self.pg0.remote_ip4, 10)) + "10.0.0.%d", self.pg0.remote_ip4, 10, start=10)) for x in self.deleted_routes: self.configured_routes.remove(x) tmp = self.config_fib_many_to_one( - "10.0.0.10", self.pg0.remote_ip4, 5) + "10.0.0.%d", self.pg0.remote_ip4, 5, start=10) self.configured_routes.extend(tmp) for x in tmp: self.deleted_routes.remove(x) self.configured_routes.extend(self.config_fib_many_to_one( - "10.0.1.0", self.pg0.remote_ip4, 100)) + "10.0.1.%d", self.pg0.remote_ip4, 100)) - fib_dump = self.vapi.ip_fib_dump() - self.verify_route_dump(fib_dump, self.configured_routes) + self.verify_route_dump(self.configured_routes) self.stream_1 = self.create_stream( self.pg1, self.pg0, self.configured_routes, 300) @@ -573,20 +503,15 @@ class TestIPv4FibCrud(VppTestCase): pkts = self.pg0.get_capture(len(self.stream_1) + len(self.stream_2)) self.verify_capture(self.pg0, pkts, self.stream_1 + self.stream_2) - def test_4_del_routes(self): - """ Delete 1.5k routes - - - delete 5 routes check with traffic script. - - add 100 routes check with traffic script. - """ + # delete 5 routes check with traffic script. + # add 100 routes check with traffic script. self.deleted_routes.extend(self.unconfig_fib_many_to_one( - "10.0.0.0", self.pg0.remote_ip4, 15)) + "10.0.0.%d", self.pg0.remote_ip4, 15)) self.deleted_routes.extend(self.unconfig_fib_many_to_one( - "10.0.0.20", self.pg0.remote_ip4, 85)) + "10.0.0.%d", self.pg0.remote_ip4, 85)) self.deleted_routes.extend(self.unconfig_fib_many_to_one( - "10.0.1.0", self.pg0.remote_ip4, 100)) - fib_dump = self.vapi.ip_fib_dump() - self.verify_not_in_route_dump(fib_dump, self.deleted_routes) + "10.0.1.%d", self.pg0.remote_ip4, 100)) + self.verify_not_in_route_dump(self.deleted_routes) class TestIPNull(VppTestCase): @@ -623,7 +548,11 @@ class TestIPNull(VppTestCase): # # A route via IP NULL that will reply with ICMP unreachables # - ip_unreach = VppIpRoute(self, "10.0.0.1", 32, [], is_unreach=1) + ip_unreach = VppIpRoute( + self, "10.0.0.1", 32, + [VppRoutePath("0.0.0.0", + 0xffffffff, + type=FibPathType.FIB_PATH_TYPE_ICMP_UNREACH)]) ip_unreach.add_vpp_config() p_unreach = (Ether(src=self.pg0.remote_mac, @@ -631,7 +560,6 @@ class TestIPNull(VppTestCase): IP(src=self.pg0.remote_ip4, dst="10.0.0.1") / UDP(sport=1234, dport=1234) / Raw('\xa5' * 100)) - self.pg0.add_stream(p_unreach) self.pg_enable_capture(self.pg_interfaces) self.pg_start() @@ -653,7 +581,11 @@ class TestIPNull(VppTestCase): # # A route via IP NULL that will reply with ICMP prohibited # - ip_prohibit = VppIpRoute(self, "10.0.0.2", 32, [], is_prohibit=1) + ip_prohibit = VppIpRoute( + self, "10.0.0.2", 32, + [VppRoutePath("0.0.0.0", + 0xffffffff, + type=FibPathType.FIB_PATH_TYPE_ICMP_PROHIBIT)]) ip_prohibit.add_vpp_config() p_prohibit = (Ether(src=self.pg0.remote_mac, @@ -695,7 +627,10 @@ class TestIPNull(VppTestCase): # # insert a more specific as a drop # - r2 = VppIpRoute(self, "1.1.1.1", 32, [], is_drop=1) + r2 = VppIpRoute(self, "1.1.1.1", 32, + [VppRoutePath("0.0.0.0", + 0xffffffff, + type=FibPathType.FIB_PATH_TYPE_DROP)]) r2.add_vpp_config() self.send_and_assert_no_replies(self.pg0, p * NUM_PKTS, "Drop Route") @@ -1452,11 +1387,12 @@ class TestIPDeag(VppTestCase): [VppRoutePath("0.0.0.0", 0xffffffff, nh_table_id=1)]) - route_to_src = VppIpRoute(self, "1.1.1.2", 32, - [VppRoutePath("0.0.0.0", - 0xffffffff, - nh_table_id=2, - is_source_lookup=1)]) + route_to_src = VppIpRoute( + self, "1.1.1.2", 32, + [VppRoutePath("0.0.0.0", + 0xffffffff, + nh_table_id=2, + type=FibPathType.FIB_PATH_TYPE_SOURCE_LOOKUP)]) route_to_dst.add_vpp_config() route_to_src.add_vpp_config() @@ -1490,6 +1426,7 @@ class TestIPDeag(VppTestCase): self.pg1.sw_if_index)], table_id=1) route_in_dst.add_vpp_config() + self.send_and_expect(self.pg0, pkts_dst, self.pg1) # |