diff options
author | Matus Fabian <matfabia@cisco.com> | 2016-12-05 01:05:35 -0800 |
---|---|---|
committer | Damjan Marion <dmarion.lists@gmail.com> | 2016-12-05 12:54:10 +0000 |
commit | d162f3dcfd54c133fdb335a1c1c89223e8e1a1cd (patch) | |
tree | 44377b841ba70e84c266dd8b2b9d54a2b61fc60b | |
parent | ff82ed6ccf09b93e1bf1432d9f26e66f91b60191 (diff) |
api: set interface MTU API (VPP-442)
Change-Id: I67178f2703febb8ad3eb011606cb8a86fab5ee94
Signed-off-by: Matus Fabian <matfabia@cisco.com>
-rw-r--r-- | vnet/vnet/interface.api | 24 | ||||
-rw-r--r-- | vnet/vnet/interface_api.c | 48 | ||||
-rw-r--r-- | vpp-api-test/vat/api_format.c | 52 | ||||
-rw-r--r-- | vpp/vpp-api/custom_dump.c | 15 |
4 files changed, 134 insertions, 5 deletions
diff --git a/vnet/vnet/interface.api b/vnet/vnet/interface.api index acc52a81724..77f5cfe3e2a 100644 --- a/vnet/vnet/interface.api +++ b/vnet/vnet/interface.api @@ -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; +}; + diff --git a/vnet/vnet/interface_api.c b/vnet/vnet/interface_api.c index eeb1d81d4d0..41fded791d9 100644 --- a/vnet/vnet/interface_api.c +++ b/vnet/vnet/interface_api.c @@ -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 = ðernet_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 diff --git a/vpp-api-test/vat/api_format.c b/vpp-api-test/vat/api_format.c index e93c89bf076..63928063137 100644 --- a/vpp-api-test/vat/api_format.c +++ b/vpp-api-test/vat/api_format.c @@ -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 */ @@ -16359,6 +16361,49 @@ api_l2_xconnect_dump (vat_main_t * vam) } 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) { longjmp (vam->jump_buf, 1); @@ -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 \ diff --git a/vpp/vpp-api/custom_dump.c b/vpp/vpp-api/custom_dump.c index 691defaaffe..fdea94164b4 100644 --- a/vpp/vpp-api/custom_dump.c +++ b/vpp/vpp-api/custom_dump.c @@ -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) { |