api: set interface MTU API (VPP-442) 93/4093/3
authorMatus Fabian <matfabia@cisco.com>
Mon, 5 Dec 2016 09:05:35 +0000 (01:05 -0800)
committerDamjan Marion <dmarion.lists@gmail.com>
Mon, 5 Dec 2016 12:54:10 +0000 (12:54 +0000)
Change-Id: I67178f2703febb8ad3eb011606cb8a86fab5ee94
Signed-off-by: Matus Fabian <matfabia@cisco.com>
vnet/vnet/interface.api
vnet/vnet/interface_api.c
vpp-api-test/vat/api_format.c
vpp/vpp-api/custom_dump.c

index acc52a8..77f5cfe 100644 (file)
@@ -29,3 +29,27 @@ define sw_interface_set_flags_reply
   i32 retval;
 };
 
+/** \brief Set interface MTU
+    @param client_index - opaque cookie to identify the sender
+    @param context - sender context, to match reply w/ request
+    @param sw_if_index - index of the interface to set MTU on
+    @param mtu - MTU
+*/
+define sw_interface_set_mtu
+{
+  u32 client_index;
+  u32 context;
+  u32 sw_if_index;
+  u16 mtu;
+};
+
+/** \brief Reply to sw_interface_set_mtu
+    @param context - sender context which was passed in the request
+    @param retval - return code of the set flags request
+*/
+define sw_interface_set_mtu_reply
+{
+  u32 context;
+  i32 retval;
+};
+
index eeb1d81..41fded7 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <vnet/interface.h>
 #include <vnet/api_errno.h>
+#include <vnet/ethernet/ethernet.h>
 
 #include <vnet/vnet_msg_enum.h>
 
@@ -42,7 +43,8 @@
 #include <vlibapi/api_helper_macros.h>
 
 #define foreach_vpe_api_msg                             \
-_(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags)
+_(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags)       \
+_(SW_INTERFACE_SET_MTU, sw_interface_set_mtu)
 
 static void
 vl_api_sw_interface_set_flags_t_handler (vl_api_sw_interface_set_flags_t * mp)
@@ -68,6 +70,50 @@ vl_api_sw_interface_set_flags_t_handler (vl_api_sw_interface_set_flags_t * mp)
   REPLY_MACRO (VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
 }
 
+static void
+vl_api_sw_interface_set_mtu_t_handler (vl_api_sw_interface_set_mtu_t * mp)
+{
+  vl_api_sw_interface_set_mtu_reply_t *rmp;
+  vnet_main_t *vnm = vnet_get_main ();
+  u32 flags = ETHERNET_INTERFACE_FLAG_MTU;
+  u32 sw_if_index = ntohl (mp->sw_if_index);
+  u16 mtu = ntohs (mp->mtu);
+  ethernet_main_t *em = &ethernet_main;
+  int rv = 0;
+
+  VALIDATE_SW_IF_INDEX (mp);
+
+  vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, sw_if_index);
+  ethernet_interface_t *eif = ethernet_get_interface (em, sw_if_index);
+
+  if (!eif)
+    {
+      rv = VNET_API_ERROR_FEATURE_DISABLED;
+      goto bad_sw_if_index;
+    }
+
+  if (mtu < hi->min_supported_packet_bytes)
+    {
+      rv = VNET_API_ERROR_INVALID_VALUE;
+      goto bad_sw_if_index;
+    }
+
+  if (mtu > hi->max_supported_packet_bytes)
+    {
+      rv = VNET_API_ERROR_INVALID_VALUE;
+      goto bad_sw_if_index;
+    }
+
+  if (hi->max_packet_bytes != mtu)
+    {
+      hi->max_packet_bytes = mtu;
+      ethernet_set_flags (vnm, sw_if_index, flags);
+    }
+
+  BAD_SW_IF_INDEX_LABEL;
+  REPLY_MACRO (VL_API_SW_INTERFACE_SET_MTU_REPLY);
+}
+
 
 /*
  * vpe_api_hookup
index e93c89b..6392806 100644 (file)
@@ -3546,7 +3546,8 @@ _(delete_subif_reply)                                   \
 _(l2_interface_pbb_tag_rewrite_reply)                   \
 _(punt_reply)                                           \
 _(feature_enable_disable_reply)                                \
-_(sw_interface_tag_add_del_reply)
+_(sw_interface_tag_add_del_reply)                      \
+_(sw_interface_set_mtu_reply)
 
 #define _(n)                                    \
     static void vl_api_##n##_t_handler          \
@@ -3787,7 +3788,8 @@ _(IP_FIB_DETAILS, ip_fib_details)                                       \
 _(IP6_FIB_DETAILS, ip6_fib_details)                                     \
 _(FEATURE_ENABLE_DISABLE_REPLY, feature_enable_disable_reply)          \
 _(SW_INTERFACE_TAG_ADD_DEL_REPLY, sw_interface_tag_add_del_reply)      \
-_(L2_XCONNECT_DETAILS, l2_xconnect_details)
+_(L2_XCONNECT_DETAILS, l2_xconnect_details)                            \
+_(SW_INTERFACE_SET_MTU_REPLY, sw_interface_set_mtu_reply)
 
 /* M: construct, but don't yet send a message */
 
@@ -16358,6 +16360,49 @@ api_l2_xconnect_dump (vat_main_t * vam)
   W;
 }
 
+static int
+api_sw_interface_set_mtu (vat_main_t * vam)
+{
+  unformat_input_t *i = vam->input;
+  vl_api_sw_interface_set_mtu_t *mp;
+  f64 timeout;
+  u32 sw_if_index = ~0;
+  u32 mtu = 0;
+
+  while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+    {
+      if (unformat (i, "mtu %d", &mtu))
+       ;
+      if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
+       ;
+      else if (unformat (i, "sw_if_index %d", &sw_if_index))
+       ;
+      else
+       break;
+    }
+
+  if (sw_if_index == ~0)
+    {
+      errmsg ("missing interface name or sw_if_index\n");
+      return -99;
+    }
+
+  if (mtu == 0)
+    {
+      errmsg ("no mtu specified\n");
+      return -99;
+    }
+
+  /* Construct the API message */
+  M (SW_INTERFACE_SET_MTU, sw_interface_set_mtu);
+  mp->sw_if_index = ntohl (sw_if_index);
+  mp->mtu = ntohs ((u16) mtu);
+
+  S;
+  W;
+}
+
+
 static int
 q_or_quit (vat_main_t * vam)
 {
@@ -17031,7 +17076,8 @@ _(feature_enable_disable, "arc_name <arc_name> "                        \
   "feature_name <feature_name> <intfc> | sw_if_index <nn> [disable]")  \
 _(sw_interface_tag_add_del, "<intfc> | sw_if_index <nn> tag <text>"    \
 "[disable]")                                                           \
-_(l2_xconnect_dump, "")
+_(l2_xconnect_dump, "")                                                \
+_(sw_interface_set_mtu, "<intfc> | sw_if_index <nn> mtu <nn>")
 
 /* List of command functions, CLI names map directly to functions */
 #define foreach_cli_function                                    \
index 691defa..fdea941 100644 (file)
@@ -2879,6 +2879,18 @@ static void *vl_api_sw_interface_tag_add_del_t_print
   FINISH;
 }
 
+static void *vl_api_sw_interface_set_mtu_t_print
+  (vl_api_sw_interface_set_mtu_t * mp, void *handle)
+{
+  u8 *s;
+
+  s = format (0, "SCRIPT: sw_interface_set_mtu ");
+  s = format (s, "sw_if_index %d ", ntohl (mp->sw_if_index));
+  s = format (s, "tag %d ", ntohs (mp->mtu));
+
+  FINISH;
+}
+
 #define foreach_custom_print_no_arg_function                            \
 _(lisp_eid_table_vni_dump)                                              \
 _(lisp_map_resolver_dump)                                               \
@@ -3049,7 +3061,8 @@ _(IOAM_DISABLE, ioam_disable)                                           \
 _(IP_FIB_DUMP, ip_fib_dump)                                             \
 _(IP6_FIB_DUMP, ip6_fib_dump)                                           \
 _(FEATURE_ENABLE_DISABLE, feature_enable_disable)                      \
-_(SW_INTERFACE_TAG_ADD_DEL, sw_interface_tag_add_del)
+_(SW_INTERFACE_TAG_ADD_DEL, sw_interface_tag_add_del)                  \
+_(SW_INTERFACE_SET_MTU, sw_interface_set_mtu)
   void
 vl_msg_api_custom_dump_configure (api_main_t * am)
 {