aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/mpls/mpls_api.c
diff options
context:
space:
mode:
authorPim van Pelt <pim@ipng.nl>2023-06-10 16:46:34 +0200
committerNeale Ranns <neale@graphiant.com>2023-08-29 12:42:13 +0000
commit8d61c59c3f1e05e49b89a700a1640aa9bcebc6b8 (patch)
tree813e853847debe8e51b80ff40494d823065fc247 /src/vnet/mpls/mpls_api.c
parent7e43005d4daea3614a216b582fa0870b3a91feb5 (diff)
mpls: add mpls_interface_dump
Add an API call mpls_interface_dump() which returns a list of mpls_interface_details: - If no sw_if_index is given, all MPLS enabled sw_if_index are returned. - If a particular sw_if_index is given, and it doesn't exist, an empty list is returned. - If a sw_if_index exists and has MPLS enabled, a list of that one sw_if_index is returned. Tested: - Create 3 loopback interfaces - Call for ~0 and for sw_if_index 0..5 all return empty lists - set int mpls loop0 enable - set int mpls loop1 enable - Call for ~0 returns 2, and the call for sw_if_index=1 and =2 (the loopbacks) returns each a list of one sw_if_index 1 resp 2, the other values of sw_if_index return empty list - set int mpls loop0 disable - Call for ~0 returns 1, and the call for sw_if_index=2 (loop1) returns both a list of one sw_if_index=2, the other values of sw_if_index return empty list - set int mpls loop1 disable - Call for ~0 and for sw_if_index 0..5 all return empty lists Example Python3 API program: ``` api_response = vpp.api.mpls_interface_dump() print(f"Response is {api_response}") for i in [ 0, 1, 2, 3, 4, 5 ]: api_response = vpp.api.mpls_interface_dump(sw_if_index=i) print(f"Response[{i}] = {api_response}") ``` Type: improvement Change-Id: If87f7d7f8972d99260e859757dbcb251c6fa54a8 Signed-off-by: Pim van Pelt <pim@ipng.nl>
Diffstat (limited to 'src/vnet/mpls/mpls_api.c')
-rw-r--r--src/vnet/mpls/mpls_api.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/vnet/mpls/mpls_api.c b/src/vnet/mpls/mpls_api.c
index fac52827e1d..dcda0a66310 100644
--- a/src/vnet/mpls/mpls_api.c
+++ b/src/vnet/mpls/mpls_api.c
@@ -410,6 +410,54 @@ vl_api_mpls_table_dump_t_handler (vl_api_mpls_table_dump_t * mp)
}
static void
+send_mpls_interface_details (vpe_api_main_t *am, vl_api_registration_t *reg,
+ u32 context, const u32 sw_if_index)
+{
+ vl_api_mpls_interface_details_t *mp;
+
+ mp = vl_msg_api_alloc_zero (sizeof (*mp));
+ mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_MPLS_INTERFACE_DETAILS);
+ mp->context = context;
+
+ mp->sw_if_index = htonl (sw_if_index);
+ vl_api_send_msg (reg, (u8 *) mp);
+}
+
+static void
+vl_api_mpls_interface_dump_t_handler (vl_api_mpls_interface_dump_t *mp)
+{
+ vpe_api_main_t *am = &vpe_api_main;
+ vl_api_registration_t *reg;
+ vnet_interface_main_t *im = &vnet_main.interface_main;
+ vnet_sw_interface_t *si;
+ u32 sw_if_index = ~0;
+
+ reg = vl_api_client_index_to_registration (mp->client_index);
+ if (!reg)
+ return;
+ sw_if_index = ntohl (mp->sw_if_index);
+
+ if (sw_if_index == ~0)
+ {
+ pool_foreach (si, im->sw_interfaces)
+ {
+ if (mpls_sw_interface_is_enabled (si->sw_if_index))
+ {
+ send_mpls_interface_details (am, reg, mp->context,
+ si->sw_if_index);
+ }
+ }
+ }
+ else
+ {
+ if (mpls_sw_interface_is_enabled (sw_if_index))
+ {
+ send_mpls_interface_details (am, reg, mp->context, sw_if_index);
+ }
+ }
+}
+
+static void
send_mpls_route_details (vpe_api_main_t * am,
vl_api_registration_t * reg,
u32 context, fib_node_index_t fib_entry_index)