diff options
-rw-r--r-- | vnet/Makefile.am | 9 | ||||
-rw-r--r-- | vnet/vnet/l2/l2.api | 38 | ||||
-rw-r--r-- | vnet/vnet/l2/l2_api.c | 140 | ||||
-rw-r--r-- | vnet/vnet/vnet_all_api_h.h | 1 | ||||
-rw-r--r-- | vpp-api-test/vat/api_format.c | 59 |
5 files changed, 242 insertions, 5 deletions
diff --git a/vnet/Makefile.am b/vnet/Makefile.am index 7d6abc60840..fc91bcd2a7a 100644 --- a/vnet/Makefile.am +++ b/vnet/Makefile.am @@ -15,7 +15,8 @@ AUTOMAKE_OPTIONS = foreign subdir-objects AM_CFLAGS = -Wall -Werror @DPDK@ @DPDK_CRYPTO@ @IPSEC@ @IPV6SR@ -BUILT_SOURCES = vnet/interface.api.h vnet/interface.api.json +BUILT_SOURCES = vnet/interface.api.h vnet/interface.api.json vnet/l2/l2.api.h \ + vnet/l2/l2.api.json libvnet_la_SOURCES = libvnetplugin_la_SOURCES = @@ -116,6 +117,7 @@ nobase_include_HEADERS += \ ######################################## libvnet_la_SOURCES += \ vnet/l2/feat_bitmap.c \ + vnet/l2/l2_api.c \ vnet/l2/l2_bd.c \ vnet/l2/l2_bvi.c \ vnet/l2/l2_input_classify.c \ @@ -149,7 +151,8 @@ nobase_include_HEADERS += \ vnet/l2/l2_fib.h \ vnet/l2/l2_rw.h \ vnet/l2/l2_xcrw.h \ - vnet/l2/l2_classify.h + vnet/l2/l2_classify.h \ + vnet/l2/l2.api.h ######################################## # Layer 2 protocol: SRP @@ -892,7 +895,7 @@ SUFFIXES = .api.h .api .api.json # install the API definition, so we can produce java bindings, etc. apidir = $(prefix)/vnet -api_DATA = vnet/interface.api.json +api_DATA = vnet/interface.api.json vnet/l2/l2.api.json # The actual %.api.h rule is in .../build-data/packages/suffix-rules.mk # and requires a symbolic link at the top of the vnet source tree diff --git a/vnet/vnet/l2/l2.api b/vnet/vnet/l2/l2.api new file mode 100644 index 00000000000..5fce7944b58 --- /dev/null +++ b/vnet/vnet/l2/l2.api @@ -0,0 +1,38 @@ +/* Hey Emacs use -*- mode: C -*- */ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** \brief Reply to l2_xconnect_dump + @param context - sender context which was passed in the request + @param rx_sw_if_index - Receive interface index + @param tx_sw_if_index - Transmit interface index + */ +define l2_xconnect_details +{ + u32 context; + u32 rx_sw_if_index; + u32 tx_sw_if_index; +}; + +/** \brief Dump L2 XConnects + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request +*/ +define l2_xconnect_dump +{ + u32 client_index; + u32 context; +}; + diff --git a/vnet/vnet/l2/l2_api.c b/vnet/vnet/l2/l2_api.c new file mode 100644 index 00000000000..ca4f593f1ec --- /dev/null +++ b/vnet/vnet/l2/l2_api.c @@ -0,0 +1,140 @@ +/* + *------------------------------------------------------------------ + * l2_api.c - layer 2 forwarding api + * + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------ + */ + +#include <vnet/vnet.h> +#include <vlibmemory/api.h> + +#include <vnet/interface.h> +#include <vnet/api_errno.h> +#include <vnet/l2/l2_input.h> + +#include <vnet/vnet_msg_enum.h> + +#define vl_typedefs /* define message structures */ +#include <vnet/vnet_all_api_h.h> +#undef vl_typedefs + +#define vl_endianfun /* define message structures */ +#include <vnet/vnet_all_api_h.h> +#undef vl_endianfun + +/* instantiate all the print functions we know about */ +#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) +#define vl_printfun +#include <vnet/vnet_all_api_h.h> +#undef vl_printfun + +#include <vlibapi/api_helper_macros.h> + +#define foreach_vpe_api_msg \ +_(L2_XCONNECT_DUMP, l2_xconnect_dump) + +static void +send_l2_xconnect_details (unix_shared_memory_queue_t * q, u32 context, + u32 rx_sw_if_index, u32 tx_sw_if_index) +{ + vl_api_l2_xconnect_details_t *mp; + + mp = vl_msg_api_alloc (sizeof (*mp)); + memset (mp, 0, sizeof (*mp)); + mp->_vl_msg_id = ntohs (VL_API_L2_XCONNECT_DETAILS); + mp->context = context; + mp->rx_sw_if_index = htonl (rx_sw_if_index); + mp->tx_sw_if_index = htonl (tx_sw_if_index); + + vl_msg_api_send_shmem (q, (u8 *) & mp); +} + +static void +vl_api_l2_xconnect_dump_t_handler (vl_api_l2_xconnect_dump_t * mp) +{ + unix_shared_memory_queue_t *q; + vnet_main_t *vnm = vnet_get_main (); + vnet_interface_main_t *im = &vnm->interface_main; + l2input_main_t *l2im = &l2input_main; + vnet_sw_interface_t *swif; + l2_input_config_t *config; + + q = vl_api_client_index_to_input_queue (mp->client_index); + if (q == 0) + return; + + /* *INDENT-OFF* */ + pool_foreach (swif, im->sw_interfaces, + ({ + config = vec_elt_at_index (l2im->configs, swif->sw_if_index); + if (config->xconnect) + send_l2_xconnect_details (q, mp->context, swif->sw_if_index, + config->output_sw_if_index); + })); + /* *INDENT-ON* */ +} + + +/* + * vpe_api_hookup + * Add vpe's API message handlers to the table. + * vlib has alread mapped shared memory and + * added the client registration handlers. + * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() + */ +#define vl_msg_name_crc_list +#include <vnet/vnet_all_api_h.h> +#undef vl_msg_name_crc_list + +static void +setup_message_id_table (api_main_t * am) +{ +#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); + foreach_vl_msg_name_crc_l2; +#undef _ +} + +static clib_error_t * +l2_api_hookup (vlib_main_t * vm) +{ + api_main_t *am = &api_main; + +#define _(N,n) \ + vl_msg_api_set_handlers(VL_API_##N, #n, \ + vl_api_##n##_t_handler, \ + vl_noop_handler, \ + vl_api_##n##_t_endian, \ + vl_api_##n##_t_print, \ + sizeof(vl_api_##n##_t), 1); + foreach_vpe_api_msg; +#undef _ + + /* + * Set up the (msg_name, crc, message-id) table + */ + setup_message_id_table (am); + + return 0; +} + +VLIB_API_INIT_FUNCTION (l2_api_hookup); + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/vnet/vnet/vnet_all_api_h.h b/vnet/vnet/vnet_all_api_h.h index 0dacdc1f543..b975f93ab6a 100644 --- a/vnet/vnet/vnet_all_api_h.h +++ b/vnet/vnet/vnet_all_api_h.h @@ -30,6 +30,7 @@ #endif /* included_from_layer_3 */ #include <vnet/interface.api.h> +#include <vnet/l2/l2.api.h> /* * fd.io coding-style-patch-verification: ON diff --git a/vpp-api-test/vat/api_format.c b/vpp-api-test/vat/api_format.c index 0bbed5c49c7..e93c89bf076 100644 --- a/vpp-api-test/vat/api_format.c +++ b/vpp-api-test/vat/api_format.c @@ -3786,7 +3786,8 @@ _(PUNT_REPLY, punt_reply) \ _(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) +_(SW_INTERFACE_TAG_ADD_DEL_REPLY, sw_interface_tag_add_del_reply) \ +_(L2_XCONNECT_DETAILS, l2_xconnect_details) /* M: construct, but don't yet send a message */ @@ -16304,6 +16305,59 @@ api_sw_interface_tag_add_del (vat_main_t * vam) W; } +static void vl_api_l2_xconnect_details_t_handler + (vl_api_l2_xconnect_details_t * mp) +{ + vat_main_t *vam = &vat_main; + + fformat (vam->ofp, "%15d%15d\n", + ntohl (mp->rx_sw_if_index), ntohl (mp->tx_sw_if_index)); +} + +static void vl_api_l2_xconnect_details_t_handler_json + (vl_api_l2_xconnect_details_t * mp) +{ + vat_main_t *vam = &vat_main; + vat_json_node_t *node = NULL; + + if (VAT_JSON_ARRAY != vam->json_tree.type) + { + ASSERT (VAT_JSON_NONE == vam->json_tree.type); + vat_json_init_array (&vam->json_tree); + } + node = vat_json_array_add (&vam->json_tree); + + vat_json_init_object (node); + vat_json_object_add_uint (node, "rx_sw_if_index", + ntohl (mp->rx_sw_if_index)); + vat_json_object_add_uint (node, "tx_sw_if_index", + ntohl (mp->tx_sw_if_index)); +} + +static int +api_l2_xconnect_dump (vat_main_t * vam) +{ + vl_api_l2_xconnect_dump_t *mp; + f64 timeout; + + if (!vam->json_output) + { + fformat (vam->ofp, "%15s%15s\n", "rx_sw_if_index", "tx_sw_if_index"); + } + + M (L2_XCONNECT_DUMP, l2_xconnect_dump); + + S; + + /* Use a control ping for synchronization */ + { + vl_api_control_ping_t *mp; + M (CONTROL_PING, control_ping); + S; + } + W; +} + static int q_or_quit (vat_main_t * vam) { @@ -16976,7 +17030,8 @@ _(ip6_fib_dump, "") \ _(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]") +"[disable]") \ +_(l2_xconnect_dump, "") /* List of command functions, CLI names map directly to functions */ #define foreach_cli_function \ |