aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeale Ranns <neale.ranns@cisco.com>2018-09-26 05:07:25 -0700
committerJohn Lo <loj@cisco.com>2018-09-26 16:54:46 +0000
commitf5fa5ae2b021f946fbb8ec56e692459cd34bc7fb (patch)
treec5ba2b4602d39d8a7b366706b5535c1c6ac01f81
parent2ac7edeeaf01dc21d9b87e764b6147c035a87c58 (diff)
MPLS tunnel dump: use sw_if_index not tunnel_index
Change-Id: I6c0d5aec6ee96a0d40358f0e09a0901b22265063 Signed-off-by: Neale Ranns <neale.ranns@cisco.com>
-rw-r--r--src/vat/api_format.c13
-rw-r--r--src/vnet/mpls/mpls.api8
-rw-r--r--src/vnet/mpls/mpls_api.c24
-rw-r--r--src/vnet/mpls/mpls_tunnel.c12
-rw-r--r--src/vnet/mpls/mpls_tunnel.h5
-rw-r--r--src/vpp/api/custom_dump.c2
-rw-r--r--test/test_mpls.py13
-rw-r--r--test/vpp_mpls_tunnel_interface.py7
-rw-r--r--test/vpp_papi_provider.py5
9 files changed, 60 insertions, 29 deletions
diff --git a/src/vat/api_format.c b/src/vat/api_format.c
index d334bcce870..9a31f187bef 100644
--- a/src/vat/api_format.c
+++ b/src/vat/api_format.c
@@ -20424,23 +20424,20 @@ api_mpls_tunnel_dump (vat_main_t * vam)
{
vl_api_mpls_tunnel_dump_t *mp;
vl_api_control_ping_t *mp_ping;
- i32 index = -1;
+ u32 sw_if_index = ~0;
int ret;
/* Parse args required to build the message */
while (unformat_check_input (vam->input) != UNFORMAT_END_OF_INPUT)
{
- if (!unformat (vam->input, "tunnel_index %d", &index))
- {
- index = -1;
- break;
- }
+ if (unformat (vam->input, "sw_if_index %d", &sw_if_index))
+ ;
}
- print (vam->ofp, " tunnel_index %d", index);
+ print (vam->ofp, " sw_if_index %d", sw_if_index);
M (MPLS_TUNNEL_DUMP, mp);
- mp->tunnel_index = htonl (index);
+ mp->sw_if_index = htonl (sw_if_index);
S (mp);
/* Use a control ping for synchronization */
diff --git a/src/vnet/mpls/mpls.api b/src/vnet/mpls/mpls.api
index 7d38ffc5bdc..ca1aa3a8513 100644
--- a/src/vnet/mpls/mpls.api
+++ b/src/vnet/mpls/mpls.api
@@ -70,17 +70,19 @@ define mpls_tunnel_add_del_reply
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 @@ manual_endian manual_print define mpls_tunnel_details
{
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 97b66965190..18eb748c423 100644
--- a/src/vnet/mpls/mpls_api.c
+++ b/src/vnet/mpls/mpls_api.c
@@ -311,12 +311,10 @@ mpls_table_create (u32 table_id, u8 is_api, const u8 * name)
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 @@ vl_api_mpls_tunnel_add_del_t_handler (vl_api_mpls_tunnel_add_del_t * mp)
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 @@ vl_api_mpls_tunnel_add_del_t_handler (vl_api_mpls_tunnel_add_del_t * mp)
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 @@ static void
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 @@ send_mpls_tunnel_entry (u32 mti, void *arg)
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 @@ send_mpls_tunnel_entry (u32 mti, void *arg)
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 @@ vl_api_mpls_tunnel_dump_t_handler (vl_api_mpls_tunnel_dump_t * mp)
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 55b60cdb1e5..f6e5dabdd8f 100644
--- a/src/vnet/mpls/mpls_tunnel.c
+++ b/src/vnet/mpls/mpls_tunnel.c
@@ -763,6 +763,18 @@ vnet_mpls_tunnel_path_remove (u32 sw_if_index,
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 285817c33c4..5685a0d8d6c 100644
--- a/src/vnet/mpls/mpls_tunnel.h
+++ b/src/vnet/mpls/mpls_tunnel.h
@@ -117,6 +117,11 @@ extern int vnet_mpls_tunnel_path_remove (u32 sw_if_index,
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);
diff --git a/src/vpp/api/custom_dump.c b/src/vpp/api/custom_dump.c
index 88b11635e11..f8a8b738b9a 100644
--- a/src/vpp/api/custom_dump.c
+++ b/src/vpp/api/custom_dump.c
@@ -2610,7 +2610,7 @@ static void *vl_api_mpls_tunnel_dump_t_print
s = format (0, "SCRIPT: mpls_tunnel_dump ");
- s = format (s, "tunnel_index %d ", ntohl (mp->tunnel_index));
+ s = format (s, "sw_if_index %d ", ntohl (mp->sw_if_index));
FINISH;
}
diff --git a/test/test_mpls.py b/test/test_mpls.py
index 1a4dad18e30..2595b039760 100644
--- a/test/test_mpls.py
+++ b/test/test_mpls.py
@@ -950,6 +950,19 @@ class TestMPLS(VppTestCase):
VppMplsLabel(46, ttl=47),
VppMplsLabel(33, ttl=47)])
+ def test_mpls_tunnel_many(self):
+ """ Multiple Tunnels """
+
+ for ii in range(10):
+ mpls_tun = VppMPLSTunnelInterface(
+ self,
+ [VppRoutePath(self.pg0.remote_ip4,
+ self.pg0.sw_if_index,
+ labels=[VppMplsLabel(44, ttl=32),
+ VppMplsLabel(46, MplsLspMode.UNIFORM)])])
+ mpls_tun.add_vpp_config()
+ mpls_tun.admin_up()
+
def test_v4_exp_null(self):
""" MPLS V4 Explicit NULL test """
diff --git a/test/vpp_mpls_tunnel_interface.py b/test/vpp_mpls_tunnel_interface.py
index 3cbf856dfc5..a2ab1bf27cb 100644
--- a/test/vpp_mpls_tunnel_interface.py
+++ b/test/vpp_mpls_tunnel_interface.py
@@ -32,6 +32,7 @@ class VppMPLSTunnelInterface(VppInterface):
is_multicast=self.is_multicast,
l2_only=self.is_l2)
sw_if_index = reply.sw_if_index
+ self.tunnel_index = reply.tunnel_index
self.set_sw_if_index(sw_if_index)
self._test.registry.register(self, self._test.logger)
@@ -54,7 +55,8 @@ class VppMPLSTunnelInterface(VppInterface):
def query_vpp_config(self):
dump = self._test.vapi.mpls_tunnel_dump()
for t in dump:
- if self.sw_if_index == t.mt_sw_if_index:
+ if self.sw_if_index == t.mt_sw_if_index and \
+ self.tunnel_index == t.mt_tunnel_index:
return True
return False
@@ -62,4 +64,5 @@ class VppMPLSTunnelInterface(VppInterface):
return self.object_id()
def object_id(self):
- return ("mpls-tunnel%d" % self.sw_if_index)
+ return ("mpls-tunnel%d-%d" % (self.tunnel_index,
+ self.sw_if_index))
diff --git a/test/vpp_papi_provider.py b/test/vpp_papi_provider.py
index ee45a5fb4cd..b814da27b33 100644
--- a/test/vpp_papi_provider.py
+++ b/test/vpp_papi_provider.py
@@ -1361,8 +1361,9 @@ class VppPapiProvider(object):
'mt_next_hop_via_label': next_hop_via_label,
'mt_next_hop_out_label_stack': next_hop_out_label_stack})
- def mpls_tunnel_dump(self):
- return self.api(self.papi.mpls_tunnel_dump, {})
+ def mpls_tunnel_dump(self, sw_if_index=0xffffffff):
+ return self.api(self.papi.mpls_tunnel_dump,
+ {'sw_if_index': sw_if_index})
def nat44_interface_add_del_feature(
self,