tap: implement sw_interface_tap_v2_dump filtering by sw_if_index

Type: feature

Change-Id: I6f607f383dc77a71e8712124f7613b38b4ac065a
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
This commit is contained in:
Paul Vinciguerra
2020-04-27 01:12:48 -04:00
committed by Neale Ranns
parent e891ac2f19
commit 073d74d0ba
5 changed files with 31 additions and 22 deletions

View File

@ -7,8 +7,5 @@ features:
- attach to existing tap at host - attach to existing tap at host
description: "Create a tap v2 device interface, which connects to a description: "Create a tap v2 device interface, which connects to a
tap interface on the host system." tap interface on the host system."
missing:
- API dump filtering by sw_if_index
state: production state: production
properties: [API, CLI, STATS, MULTITHREAD] properties: [API, CLI, STATS, MULTITHREAD]

View File

@ -40,8 +40,8 @@ enum tap_flags {
@param use_random_mac - let the system generate a unique mac address @param use_random_mac - let the system generate a unique mac address
@param mac_address - mac addr to assign to the interface if use_random not set @param mac_address - mac addr to assign to the interface if use_random not set
@param num_rx_queues - number of rx queues @param num_rx_queues - number of rx queues
@param tx_ring_sz - the number of entries of TX ring @param tx_ring_sz - the number of entries of TX ring, optional, default is 256 entries, must be power of 2
@param rx_ring_sz - the number of entries of RX ring @param rx_ring_sz - the number of entries of RX ring, optional, default is 256 entries, must be power of 2
@param host_mtu_set - host MTU should be set @param host_mtu_set - host MTU should be set
@param host_mtu_size - host MTU size @param host_mtu_size - host MTU size
@param host_mac_addr_set - host side interface mac address should be set @param host_mac_addr_set - host side interface mac address should be set
@ -57,7 +57,7 @@ enum tap_flags {
@param tap_flags - flags for the TAP interface creation @param tap_flags - flags for the TAP interface creation
@param host_if_name_set - host side interface name should be set @param host_if_name_set - host side interface name should be set
@param host_if_name - host side interface name @param host_if_name - host side interface name
@param host_namespace_set - host namespece should be set @param host_namespace_set - host namespace should be set
@param host_namespace - host namespace to attach interface to @param host_namespace - host namespace to attach interface to
@param host_bridge_set - host bridge should be set @param host_bridge_set - host bridge should be set
@param host_bridge - host bridge to attach interface to @param host_bridge - host bridge to attach interface to
@ -71,8 +71,8 @@ define tap_create_v2
bool use_random_mac [default=true]; bool use_random_mac [default=true];
vl_api_mac_address_t mac_address; vl_api_mac_address_t mac_address;
u8 num_rx_queues [default=1]; u8 num_rx_queues [default=1];
u16 tx_ring_sz; /* optional, default is 256 entries, must be power of 2 */ u16 tx_ring_sz [default=256];
u16 rx_ring_sz; /* optional, default is 256 entries, must be power of 2 */ u16 rx_ring_sz [default=256];
bool host_mtu_set; bool host_mtu_set;
u32 host_mtu_size; u32 host_mtu_size;
bool host_mac_addr_set; bool host_mac_addr_set;
@ -120,7 +120,7 @@ autoreply define tap_delete_v2
}; };
/** \brief Dump tap interfaces request /** \brief Dump tap interfaces request
@param sw_if_index - filter by sw_if_index UNIMPLEMENTED @param sw_if_index - filter by sw_if_index
*/ */
define sw_interface_tap_v2_dump define sw_interface_tap_v2_dump
{ {

View File

@ -232,8 +232,8 @@ vl_api_sw_interface_tap_v2_dump_t_handler (vl_api_sw_interface_tap_v2_dump_t *
return; return;
filter_sw_if_index = htonl (mp->sw_if_index); filter_sw_if_index = htonl (mp->sw_if_index);
if (filter_sw_if_index != ~0) if (mp->sw_if_index != ~0)
return; /* UNIMPLEMENTED */ VALIDATE_SW_IF_INDEX (mp);
rv = tap_dump_ifs (&tapifs); rv = tap_dump_ifs (&tapifs);
if (rv) if (rv)
@ -241,9 +241,11 @@ vl_api_sw_interface_tap_v2_dump_t_handler (vl_api_sw_interface_tap_v2_dump_t *
vec_foreach (tap_if, tapifs) vec_foreach (tap_if, tapifs)
{ {
tap_send_sw_interface_details (am, reg, tap_if, mp->context); if ((filter_sw_if_index == ~0)
|| (tap_if->sw_if_index == filter_sw_if_index))
tap_send_sw_interface_details (am, reg, tap_if, mp->context);
} }
BAD_SW_IF_INDEX_LABEL;
vec_free (tapifs); vec_free (tapifs);
} }

View File

@ -19,6 +19,20 @@ class TestTAP(VppTestCase):
tap0.add_vpp_config() tap0.add_vpp_config()
self.assertTrue(tap0.query_vpp_config()) self.assertTrue(tap0.query_vpp_config())
def test_tap_dump(self):
""" Test api dump w/ and w/o sw_if_index filtering"""
MAX_INSTANCES = 10
tap_instances = []
for instance in range(MAX_INSTANCES):
i = VppTAPInterface(self, tap_id=instance)
i.add_vpp_config()
tap_instances.append(i)
details = self.vapi.sw_interface_tap_v2_dump()
self.assertEqual(MAX_INSTANCES, len(details))
details = self.vapi.sw_interface_tap_v2_dump(
tap_instances[5].sw_if_index)
self.assertEqual(1, len(details))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main(testRunner=VppTestRunner) unittest.main(testRunner=VppTestRunner)

View File

@ -14,16 +14,14 @@ class VppTAPInterface(VppInterface):
self._mac_addr = mac_addr self._mac_addr = mac_addr
def get_vpp_dump(self): def get_vpp_dump(self):
dump = self._test.vapi.sw_interface_tap_v2_dump() dump = self._test.vapi.sw_interface_tap_v2_dump(
for entry in dump: sw_if_index=self.sw_if_index)
if entry.sw_if_index == self.sw_if_index: return dump
return entry
def add_vpp_config(self): def add_vpp_config(self):
use_random_mac = True if self._mac_addr else False
reply = self._test.vapi.tap_create_v2( reply = self._test.vapi.tap_create_v2(
id=self._tap_id, id=self._tap_id,
use_random_mac=use_random_mac, use_random_mac=bool(self._mac_addr),
mac_address=self._mac_addr) mac_address=self._mac_addr)
self.set_sw_if_index(reply.sw_if_index) self.set_sw_if_index(reply.sw_if_index)
self._test.registry.register(self, self.test.logger) self._test.registry.register(self, self.test.logger)
@ -33,9 +31,7 @@ class VppTAPInterface(VppInterface):
def query_vpp_config(self): def query_vpp_config(self):
dump = self.get_vpp_dump() dump = self.get_vpp_dump()
if dump: return bool(dump)
return True
return False
def object_id(self): def object_id(self):
return "tap-%s" % self._tap_id return "tap-%s" % self._tap_id