api: Add to interface crud - read by sw_if_index.
Change-Id: I02c857da4cf6da5e0e55c1e48b63716af7ade0a9 Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
This commit is contained in:

committed by
Dave Wallace

parent
4bdfd59a87
commit
6407ba56a3
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
option version = "2.2.0";
|
||||
option version = "2.2.1";
|
||||
|
||||
import "vnet/interface_types.api";
|
||||
|
||||
@ -206,6 +206,7 @@ define sw_interface_details
|
||||
/** \brief Request all or filtered subset of sw_interface_details
|
||||
@param client_index - opaque cookie to identify the sender
|
||||
@param context - sender context, to match reply w/ request
|
||||
@param sw_if_index - ~0 if ignore, index of the interface to filter on
|
||||
@param name_filter_valid - 1 if requesting a filtered subset of records else 0
|
||||
@param name_filter - interface name substring filter. Eg. loop1 returns [loop1, loop10]
|
||||
*/
|
||||
@ -214,6 +215,7 @@ define sw_interface_dump
|
||||
{
|
||||
u32 client_index;
|
||||
u32 context;
|
||||
vl_api_interface_index_t sw_if_index;
|
||||
u8 name_filter_valid;
|
||||
u8 name_filter[49];
|
||||
};
|
||||
|
@ -295,6 +295,7 @@ vl_api_sw_interface_dump_t_handler (vl_api_sw_interface_dump_t * mp)
|
||||
vnet_sw_interface_t *swif;
|
||||
vnet_interface_main_t *im = &am->vnet_main->interface_main;
|
||||
vl_api_registration_t *rp;
|
||||
u32 sw_if_index;
|
||||
|
||||
rp = vl_api_client_index_to_registration (mp->client_index);
|
||||
|
||||
@ -305,6 +306,27 @@ vl_api_sw_interface_dump_t_handler (vl_api_sw_interface_dump_t * mp)
|
||||
}
|
||||
|
||||
u8 *filter = 0, *name = 0;
|
||||
sw_if_index = ntohl (mp->sw_if_index);
|
||||
|
||||
if (sw_if_index != ~0)
|
||||
{
|
||||
/* is it a valid sw_if_index/ */
|
||||
if (vec_len (im->sw_interfaces) <= sw_if_index)
|
||||
return;
|
||||
|
||||
swif = vec_elt_at_index (im->sw_interfaces, sw_if_index);
|
||||
|
||||
/* If we have a sw_if_index, ignore the name filter. */
|
||||
mp->name_filter_valid = 0;
|
||||
vec_reset_length (name);
|
||||
name =
|
||||
format (name, "%U%c", format_vnet_sw_interface_name, am->vnet_main,
|
||||
swif, 0);
|
||||
send_sw_interface_details (am, rp, swif, name, mp->context);
|
||||
vec_free (name);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mp->name_filter_valid)
|
||||
{
|
||||
mp->name_filter[ARRAY_LEN (mp->name_filter) - 1] = 0;
|
||||
|
@ -151,5 +151,38 @@ class TestLoopbackInterfaceCRUD(VppTestCase):
|
||||
self.pg0.assert_nothing_captured()
|
||||
|
||||
|
||||
class TestInterfaceDumpApiLocalOnly(VppTestCase):
|
||||
"""test_interface_crud.TestInterfaceDumpApiLocalOnly"""
|
||||
|
||||
def test_sw_if_index_0(self):
|
||||
rv = self.vapi.sw_interface_dump(sw_if_index=0)
|
||||
self.assertEqual(rv[0].sw_if_index, 0)
|
||||
|
||||
def test_sw_if_index_twiddle0(self):
|
||||
rv = self.vapi.sw_interface_dump(sw_if_index=0xffffffff)
|
||||
self.assertEqual(rv[0].sw_if_index, 0)
|
||||
|
||||
def test_sw_if_index_1_not_existing(self):
|
||||
rv = self.vapi.sw_interface_dump(sw_if_index=1)
|
||||
self.assertEqual(len(rv), 0, 'expected no records.')
|
||||
|
||||
|
||||
class TestInterfaceDumpApi(VppTestCase):
|
||||
"""test_interface_crud.TestInterfaceDumpApi"""
|
||||
|
||||
def test_sw_if_index_1(self):
|
||||
self.vapi.create_loopback_instance(is_specified=1,
|
||||
user_instance=10)
|
||||
self.vapi.create_loopback_instance(is_specified=1,
|
||||
user_instance=5)
|
||||
|
||||
# Can I get back the specified record?
|
||||
rv = self.vapi.sw_interface_dump(sw_if_index=1)
|
||||
self.assertEqual(rv[0].sw_if_index, 1, rv)
|
||||
|
||||
# verify 3 interfaces
|
||||
rv = self.vapi.sw_interface_dump(sw_if_index=0xffffffff)
|
||||
self.assertEqual(len(rv), 3, 'Expected 3 interfaces.')
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(testRunner=VppTestRunner)
|
||||
|
@ -170,6 +170,7 @@ defaultmapping = {
|
||||
'svs_route_add_del': {'is_add': 1, },
|
||||
'svs_table_add_del': {'is_add': 1, },
|
||||
'sw_interface_add_del_address': {'is_add': 1, },
|
||||
'sw_interface_dump': {'sw_if_index': 4294967295, },
|
||||
'sw_interface_ip6nd_ra_prefix': {'val_lifetime': 4294967295,
|
||||
'pref_lifetime': 4294967295, },
|
||||
'sw_interface_set_ip_directed_broadcast': {'enable': 1, },
|
||||
|
Reference in New Issue
Block a user