mpls: CLI to show the MPLS forwarding state of an interface 34/32734/3
authorNeale Ranns <neale@graphiant.com>
Tue, 15 Jun 2021 12:43:12 +0000 (12:43 +0000)
committerBeno�t Ganne <bganne@cisco.com>
Thu, 17 Jun 2021 07:58:41 +0000 (07:58 +0000)
Type: improvement

Signed-off-by: Neale Ranns <neale@graphiant.com>
Change-Id: I28b98154bbff36e8391a09a2b30302dda4349946

src/vnet/mpls/interface.c
test/test_mpls.py

index 1d10cab..fd075c9 100644 (file)
@@ -140,3 +140,72 @@ VLIB_CLI_COMMAND (set_interface_ip_table_command, static) = {
   .function = mpls_interface_enable_disable,
   .short_help = "Enable/Disable an interface for MPLS forwarding",
 };
+
+static void
+show_mpls_one_interface (vnet_main_t *vnm, vlib_main_t *vm, u32 sw_if_index,
+                        bool verbose)
+{
+  mpls_main_t *mm = &mpls_main;
+  u8 enabled;
+
+  enabled = mm->mpls_enabled_by_sw_if_index[sw_if_index];
+
+  if (enabled)
+    {
+      vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name, vnm,
+                      sw_if_index);
+      vlib_cli_output (vm, "  MPLS enabled");
+    }
+  else if (verbose)
+    {
+      vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name, vnm,
+                      sw_if_index);
+      vlib_cli_output (vm, "  MPLS disabled");
+    }
+}
+
+static walk_rc_t
+show_mpls_interface_walk (vnet_main_t *vnm, vnet_sw_interface_t *si, void *ctx)
+{
+  show_mpls_one_interface (vnm, ctx, si->sw_if_index, false);
+
+  return (WALK_CONTINUE);
+}
+
+static clib_error_t *
+show_mpls_interface (vlib_main_t *vm, unformat_input_t *input,
+                    vlib_cli_command_t *cmd)
+{
+  vnet_main_t *vnm = vnet_get_main ();
+  u32 sw_if_index;
+
+  sw_if_index = ~0;
+
+  if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
+    ;
+
+  if (~0 == sw_if_index)
+    {
+      vnet_sw_interface_walk (vnm, show_mpls_interface_walk, vm);
+    }
+  else
+    {
+      show_mpls_one_interface (vnm, vm, sw_if_index, true);
+    }
+
+  return NULL;
+}
+
+/*?
+ * This command displays the MPLS forwarding state of an interface
+ *
+ * @cliexpar
+ * @cliexstart{show mpls interface}
+ *  set mpls interface GigEthernet0/8/0
+ * @cliexend
+ ?*/
+VLIB_CLI_COMMAND (show_mpls_interface_command, static) = {
+  .path = "show mpls interface",
+  .function = show_mpls_interface,
+  .short_help = "Show MPLS interface forwarding",
+};
index f0c3b0f..2c40e8d 100644 (file)
@@ -1594,6 +1594,10 @@ class TestMPLSDisabled(VppTestCase):
     def test_mpls_disabled(self):
         """ MPLS Disabled """
 
+        self.logger.info(self.vapi.cli("show mpls interface"))
+        self.logger.info(self.vapi.cli("show mpls interface pg1"))
+        self.logger.info(self.vapi.cli("show mpls interface pg0"))
+
         tx = (Ether(src=self.pg1.remote_mac,
                     dst=self.pg1.local_mac) /
               MPLS(label=32, ttl=64) /
@@ -1620,6 +1624,9 @@ class TestMPLSDisabled(VppTestCase):
         #
         self.pg1.enable_mpls()
 
+        self.logger.info(self.vapi.cli("show mpls interface"))
+        self.logger.info(self.vapi.cli("show mpls interface pg1"))
+
         #
         # Now we get packets through
         #