MPLS tunnel dump: use sw_if_index not tunnel_index
Change-Id: I6c0d5aec6ee96a0d40358f0e09a0901b22265063
Signed-off-by: Neale Ranns <neale.ranns@cisco.com>
diff --git a/src/vnet/mpls/mpls.api b/src/vnet/mpls/mpls.api
index 7d38ffc..ca1aa3a 100644
--- a/src/vnet/mpls/mpls.api
+++ b/src/vnet/mpls/mpls.api
@@ -70,17 +70,19 @@
u32 context;
i32 retval;
u32 sw_if_index;
+ u32 tunnel_index;
};
/** \brief Dump mpls eth tunnel table
@param client_index - opaque cookie to identify the sender
- @param tunnel_index - eth tunnel identifier or -1 in case of all tunnels
+ @param sw_if_index - sw_if_index of the MPLS tunnel
+ (as returned from the create)
*/
define mpls_tunnel_dump
{
u32 client_index;
u32 context;
- i32 tunnel_index;
+ u32 sw_if_index;
};
/** \brief mpls tunnel details
@@ -89,7 +91,7 @@
{
u32 context;
u32 mt_sw_if_index;
- u8 mt_tunnel_index;
+ u32 mt_tunnel_index;
u8 mt_l2_only;
u8 mt_is_multicast;
u32 mt_count;
diff --git a/src/vnet/mpls/mpls_api.c b/src/vnet/mpls/mpls_api.c
index 97b6696..18eb748 100644
--- a/src/vnet/mpls/mpls_api.c
+++ b/src/vnet/mpls/mpls_api.c
@@ -311,12 +311,10 @@
static void
vl_api_mpls_tunnel_add_del_t_handler (vl_api_mpls_tunnel_add_del_t * mp)
{
+ u32 tunnel_sw_if_index, tunnel_index, next_hop_via_label;
vl_api_mpls_tunnel_add_del_reply_t *rmp;
- int rv = 0;
- u32 tunnel_sw_if_index;
- int ii;
fib_route_path_t rpath, *rpaths = NULL;
- u32 next_hop_via_label;
+ int ii, rv = 0;
memset (&rpath, 0, sizeof (rpath));
@@ -370,9 +368,12 @@
tunnel_sw_if_index = vnet_mpls_tunnel_create (mp->mt_l2_only,
mp->mt_is_multicast);
vnet_mpls_tunnel_path_add (tunnel_sw_if_index, rpaths);
+
+ tunnel_index = vnet_mpls_tunnel_get_index (tunnel_sw_if_index);
}
else
{
+ tunnel_index = vnet_mpls_tunnel_get_index (tunnel_sw_if_index);
tunnel_sw_if_index = ntohl (mp->mt_sw_if_index);
if (!vnet_mpls_tunnel_path_remove (tunnel_sw_if_index, rpaths))
vnet_mpls_tunnel_del (tunnel_sw_if_index);
@@ -386,6 +387,7 @@
REPLY_MACRO2(VL_API_MPLS_TUNNEL_ADD_DEL_REPLY,
({
rmp->sw_if_index = ntohl(tunnel_sw_if_index);
+ rmp->tunnel_index = ntohl(tunnel_index);
}));
/* *INDENT-ON* */
}
@@ -410,7 +412,7 @@
typedef struct mpls_tunnel_send_walk_ctx_t_
{
vl_api_registration_t *reg;
- u32 index;
+ u32 sw_if_index;
u32 context;
} mpls_tunnel_send_walk_ctx_t;
@@ -426,10 +428,11 @@
ctx = arg;
- if (~0 != ctx->index && mti != ctx->index)
+ mt = mpls_tunnel_get (mti);
+
+ if (~0 != ctx->sw_if_index && mt->mt_sw_if_index != ctx->sw_if_index)
return;
- mt = mpls_tunnel_get (mti);
n = fib_path_list_get_n_paths (mt->mt_path_list);
mp = vl_msg_api_alloc (sizeof (*mp) + n * sizeof (vl_api_fib_path_t));
@@ -451,11 +454,6 @@
fp++;
}
- // FIXME
- // memcpy (mp->mt_next_hop_out_labels,
- // mt->mt_label_stack, nlabels * sizeof (u32));
-
-
vl_api_send_msg (ctx->reg, (u8 *) mp);
}
@@ -470,7 +468,7 @@
mpls_tunnel_send_walk_ctx_t ctx = {
.reg = reg,
- .index = ntohl (mp->tunnel_index),
+ .sw_if_index = ntohl (mp->sw_if_index),
.context = mp->context,
};
mpls_tunnel_walk (send_mpls_tunnel_entry, &ctx);
diff --git a/src/vnet/mpls/mpls_tunnel.c b/src/vnet/mpls/mpls_tunnel.c
index 55b60cd..f6e5dab 100644
--- a/src/vnet/mpls/mpls_tunnel.c
+++ b/src/vnet/mpls/mpls_tunnel.c
@@ -763,6 +763,18 @@
return (fib_path_list_get_n_paths(mt->mt_path_list));
}
+int
+vnet_mpls_tunnel_get_index (u32 sw_if_index)
+{
+ mpls_tunnel_t *mt;
+
+ mt = mpls_tunnel_get_from_sw_if_index(sw_if_index);
+
+ if (NULL == mt)
+ return (~0);
+
+ return (mt - mpls_tunnel_pool);
+}
static clib_error_t *
vnet_create_mpls_tunnel_command_fn (vlib_main_t * vm,
diff --git a/src/vnet/mpls/mpls_tunnel.h b/src/vnet/mpls/mpls_tunnel.h
index 285817c..5685a0d 100644
--- a/src/vnet/mpls/mpls_tunnel.h
+++ b/src/vnet/mpls/mpls_tunnel.h
@@ -117,6 +117,11 @@
fib_route_path_t *rpath);
/**
+ * @vrief return the tunnel index from the sw_if_index
+ */
+extern int vnet_mpls_tunnel_get_index (u32 sw_if_index);
+
+/**
* @brief Delete an MPLS tunnel
*/
extern void vnet_mpls_tunnel_del (u32 sw_if_index);