From aaacfbc5b15b0653489ad2e80db48151a4375ece Mon Sep 17 00:00:00 2001 From: Dave Barach Date: Sat, 10 Mar 2018 14:57:00 -0500 Subject: [PATCH] Move the vnet cdp protocol implementation to a plugin Add a binary API and debug cli to enable/disable cdp. cdp is disabled by default. Change-Id: I307c7e38dfda38e36ff3325f65de7036c34d89b1 Signed-off-by: Dave Barach --- src/configure.ac | 1 + src/plugins/Makefile.am | 4 + src/plugins/cdp.am | 40 +++++ src/plugins/cdp/cdp.api | 36 ++++ src/plugins/cdp/cdp.c | 222 +++++++++++++++++++++++++ src/{vnet/cdp/cdp_node.h => plugins/cdp/cdp.h} | 27 +-- src/{vnet => plugins}/cdp/cdp.pg | 0 src/plugins/cdp/cdp_all_api_h.h | 19 +++ src/{vnet => plugins}/cdp/cdp_input.c | 16 +- src/plugins/cdp/cdp_msg_enum.h | 31 ++++ src/{vnet => plugins}/cdp/cdp_node.c | 23 ++- src/{vnet => plugins}/cdp/cdp_periodic.c | 4 +- src/{vnet => plugins}/cdp/cdp_protocol.h | 2 +- src/plugins/cdp/cdp_test.c | 179 ++++++++++++++++++++ src/vnet.am | 11 -- 15 files changed, 574 insertions(+), 41 deletions(-) create mode 100644 src/plugins/cdp.am create mode 100644 src/plugins/cdp/cdp.api create mode 100644 src/plugins/cdp/cdp.c rename src/{vnet/cdp/cdp_node.h => plugins/cdp/cdp.h} (89%) rename src/{vnet => plugins}/cdp/cdp.pg (100%) create mode 100644 src/plugins/cdp/cdp_all_api_h.h rename src/{vnet => plugins}/cdp/cdp_input.c (97%) create mode 100644 src/plugins/cdp/cdp_msg_enum.h rename src/{vnet => plugins}/cdp/cdp_node.c (93%) rename src/{vnet => plugins}/cdp/cdp_periodic.c (99%) rename src/{vnet => plugins}/cdp/cdp_protocol.h (99%) create mode 100644 src/plugins/cdp/cdp_test.c diff --git a/src/configure.ac b/src/configure.ac index 041849e4312..cf050b8bc9a 100644 --- a/src/configure.ac +++ b/src/configure.ac @@ -211,6 +211,7 @@ AC_SUBST(AR_FLAGS) # Please keep alphabetical order PLUGIN_ENABLED(acl) +PLUGIN_ENABLED(cdp) PLUGIN_ENABLED(dpdk) PLUGIN_ENABLED(flowprobe) PLUGIN_ENABLED(gbp) diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index 1acca70a6dc..f8b1139cb4f 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -34,6 +34,10 @@ if ENABLE_ACL_PLUGIN include acl.am endif +if ENABLE_CDP_PLUGIN +include cdp.am +endif + if ENABLE_DPDK_PLUGIN include dpdk.am endif diff --git a/src/plugins/cdp.am b/src/plugins/cdp.am new file mode 100644 index 00000000000..1d9d77e1f15 --- /dev/null +++ b/src/plugins/cdp.am @@ -0,0 +1,40 @@ + +# Copyright (c) 2011-2018 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. + +vppapitestplugins_LTLIBRARIES += cdp_test_plugin.la +vppplugins_LTLIBRARIES += cdp_plugin.la + +cdp_plugin_la_SOURCES = \ + cdp/cdp_all_api_h.h \ + cdp/cdp.c \ + cdp/cdp.h \ + cdp/cdp_input.c \ + cdp/cdp_msg_enum.h \ + cdp/cdp_node.c \ + cdp/cdp_periodic.c + +API_FILES += cdp/cdp.api + +nobase_apiinclude_HEADERS += \ + cdp/cdp_all_api_h.h \ + cdp/cdp.api.h \ + cdp/cdp.h \ + cdp/cdp_msg_enum.h \ + cdp/cdp_protocol.h + +cdp_test_plugin_la_SOURCES = \ + cdp/cdp_test.c \ + cdp/cdp.api.h + +# vi:syntax=automake diff --git a/src/plugins/cdp/cdp.api b/src/plugins/cdp/cdp.api new file mode 100644 index 00000000000..34507025f42 --- /dev/null +++ b/src/plugins/cdp/cdp.api @@ -0,0 +1,36 @@ +/* + * Simple enable/disable API for the cdp protocol + * + * Copyright (c) 2011-2018 by 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. + */ + +option version = "1.0.0"; + +autoreply define cdp_enable_disable +{ + /* Client identifier, set from api_main.my_client_index */ + u32 client_index; + + /* Arbitrary context, so client can match reply to request */ + u32 context; + + /* Enable / disable the feature */ + u8 enable_disable; +}; + +/* + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/cdp/cdp.c b/src/plugins/cdp/cdp.c new file mode 100644 index 00000000000..a88a06bc9c5 --- /dev/null +++ b/src/plugins/cdp/cdp.c @@ -0,0 +1,222 @@ +/* + * cdp.c - cdp protocol plug-in + * + * Copyright (c) 2011-2018 by 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 +#include +#include + +#include +#include +#include + +/* define message IDs */ +#include + +/* define message structures */ +#define vl_typedefs +#include +#undef vl_typedefs + +/* define generated endian-swappers */ +#define vl_endianfun +#include +#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 +#undef vl_printfun + +/* Get the API version number */ +#define vl_api_version(n,v) static u32 api_version=(v); +#include +#undef vl_api_version + +/* + * A handy macro to set up a message reply. + * Assumes that the following variables are available: + * mp - pointer to request message + * rmp - pointer to reply message type + * rv - return value + */ + +#define REPLY_MACRO(t) \ +do { \ + unix_shared_memory_queue_t * q = \ + vl_api_client_index_to_input_queue (mp->client_index); \ + if (!q) \ + return; \ + \ + rmp = vl_msg_api_alloc (sizeof (*rmp)); \ + rmp->_vl_msg_id = ntohs((t)+cm->msg_id_base); \ + rmp->context = mp->context; \ + rmp->retval = ntohl(rv); \ + \ + vl_msg_api_send_shmem (q, (u8 *)&rmp); \ +} while(0); + + +/* List of message types that this plugin understands */ + +#define foreach_cdp_plugin_api_msg \ +_(CDP_ENABLE_DISABLE, cdp_enable_disable) + +/* Action function shared between message handler and debug CLI */ + +int +cdp_enable_disable (cdp_main_t * cm, int enable_disable) +{ + int rv = 0; + + if (enable_disable) + vlib_process_signal_event (cm->vlib_main, cdp_process_node.index, + CDP_EVENT_ENABLE, 0); + else + vlib_process_signal_event (cm->vlib_main, cdp_process_node.index, + CDP_EVENT_DISABLE, 0); + cm->enabled = enable_disable; + + return rv; +} + +static clib_error_t * +cdp_command_fn (vlib_main_t * vm, + unformat_input_t * input, vlib_cli_command_t * cmd) +{ + cdp_main_t *cm = &cdp_main; + int enable_disable = 1; + + int rv; + + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "disable")) + enable_disable = 0; + else if (unformat (input, "enable")) + enable_disable = 1; + else + break; + } + + rv = cdp_enable_disable (cm, enable_disable); + + switch (rv) + { + case 0: + break; + + default: + return clib_error_return (0, "cdp_enable_disable returned %d", rv); + } + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (cdp_command, static) = +{ + .path = "cdp", + .short_help = "cdp enable | disable", + .function = cdp_command_fn, +}; +/* *INDENT-ON* */ + +/* API message handler */ +static void vl_api_cdp_enable_disable_t_handler + (vl_api_cdp_enable_disable_t * mp) +{ + vl_api_cdp_enable_disable_reply_t *rmp; + cdp_main_t *cm = &cdp_main; + int rv; + + rv = cdp_enable_disable (cm, (int) (mp->enable_disable)); + + REPLY_MACRO (VL_API_CDP_ENABLE_DISABLE_REPLY); +} + +/* Set up the API message handling tables */ +static clib_error_t * +cdp_plugin_api_hookup (vlib_main_t * vm) +{ + cdp_main_t *cm = &cdp_main; +#define _(N,n) \ + vl_msg_api_set_handlers((VL_API_##N + cm->msg_id_base), \ + #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_cdp_plugin_api_msg; +#undef _ + + return 0; +} + +#define vl_msg_name_crc_list +#include +#undef vl_msg_name_crc_list + +static void +setup_message_id_table (cdp_main_t * cm, api_main_t * am) +{ +#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n #crc, id + cm->msg_id_base); + foreach_vl_msg_name_crc_cdp; +#undef _ +} + +static clib_error_t * +cdp_init (vlib_main_t * vm) +{ + cdp_main_t *cm = &cdp_main; + clib_error_t *error = 0; + u8 *name; + + cm->vlib_main = vm; + + name = format (0, "cdp_%08x%c", api_version, 0); + + /* Ask for a correctly-sized block of API message decode slots */ + cm->msg_id_base = vl_msg_api_get_msg_ids + ((char *) name, VL_MSG_FIRST_AVAILABLE); + + error = cdp_plugin_api_hookup (vm); + + /* Add our API messages to the global name_crc hash table */ + setup_message_id_table (cm, &api_main); + + vec_free (name); + + return error; +} + +VLIB_INIT_FUNCTION (cdp_init); + +/* *INDENT-OFF* */ +VLIB_PLUGIN_REGISTER () = +{ + .version = VPP_BUILD_VER, +}; +/* *INDENT-ON* */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/vnet/cdp/cdp_node.h b/src/plugins/cdp/cdp.h similarity index 89% rename from src/vnet/cdp/cdp_node.h rename to src/plugins/cdp/cdp.h index 21086c02527..32a07825ecb 100644 --- a/src/vnet/cdp/cdp_node.h +++ b/src/plugins/cdp/cdp.h @@ -1,5 +1,8 @@ + /* - * Copyright (c) 2011-2016 Cisco and/or its affiliates. + * cdp.h - cdp protocol plug-in + * + * Copyright (c) 2011-2018 by 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: @@ -12,8 +15,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __included_cdp_node_h__ -#define __included_cdp_node_h__ +#ifndef __included_cdp_h__ +#define __included_cdp_h__ #include #include @@ -25,7 +28,7 @@ #include #include -#include +#include "cdp_protocol.h" typedef enum { @@ -78,6 +81,9 @@ typedef struct /* pool of cdp neighbors */ cdp_neighbor_t *neighbors; + /* plugin message id base */ + u16 msg_id_base; + /* tx pcap debug enable */ u8 tx_pcap_debug; @@ -87,6 +93,9 @@ typedef struct /* Background process node index */ u32 cdp_process_node_index; + /* top-level state */ + int enabled; + /* Packet templates for different encap types */ vlib_packet_template_t packet_templates[CDP_N_PACKET_TEMPLATES]; @@ -96,6 +105,7 @@ typedef struct } cdp_main_t; extern cdp_main_t cdp_main; +extern vlib_node_registration_t cdp_process_node; /* Packet counters */ #define foreach_cdp_error \ @@ -123,20 +133,17 @@ typedef struct typedef enum { - CDP_EVENT_SEND_NEIGHBOR, - CDP_EVENT_SEND_KEEPALIVE, + CDP_EVENT_ENABLE, + CDP_EVENT_DISABLE, } cdp_process_event_t; - cdp_error_t cdp_input (vlib_main_t * vm, vlib_buffer_t * b0, u32 bi0); void cdp_periodic (vlib_main_t * vm); void cdp_keepalive (cdp_main_t * cm, cdp_neighbor_t * n); u16 cdp_checksum (void *p, int count); u8 *cdp_input_format_trace (u8 * s, va_list * args); -serialize_function_t serialize_cdp_main, unserialize_cdp_main; - -#endif /* __included_cdp_node_h__ */ +#endif /* __included_cdp_h__ */ /* * fd.io coding-style-patch-verification: ON diff --git a/src/vnet/cdp/cdp.pg b/src/plugins/cdp/cdp.pg similarity index 100% rename from src/vnet/cdp/cdp.pg rename to src/plugins/cdp/cdp.pg diff --git a/src/plugins/cdp/cdp_all_api_h.h b/src/plugins/cdp/cdp_all_api_h.h new file mode 100644 index 00000000000..cc0047e6399 --- /dev/null +++ b/src/plugins/cdp/cdp_all_api_h.h @@ -0,0 +1,19 @@ + +/* + * cdp_all_api_h.h - cdp plug-in api #include file + * + * Copyright (c) 2011-2018 by 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 the generated file, see BUILT_SOURCES in Makefile.am */ +#include diff --git a/src/vnet/cdp/cdp_input.c b/src/plugins/cdp/cdp_input.c similarity index 97% rename from src/vnet/cdp/cdp_input.c rename to src/plugins/cdp/cdp_input.c index 3574de68534..fa993b84def 100644 --- a/src/vnet/cdp/cdp_input.c +++ b/src/plugins/cdp/cdp_input.c @@ -12,16 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include +#include cdp_main_t cdp_main; #define DEBUG_TLV_DUMP 0 /* 1=> dump TLV's to stdout while processing them */ -/* Reliable multicast messages we use to keep peers updated */ -mc_serialize_msg_t serialize_cdp_neighbor_msg; -mc_serialize_msg_t serialize_cdp_keepalive_msg; - /* * ported from an unspecified Cisco cdp implementation. * Compute / return in HOST byte order. 0 => good checksum. @@ -384,7 +380,7 @@ cdp_input (vlib_main_t * vm, vlib_buffer_t * b0, u32 bi0) * setup neighbor hash table */ static clib_error_t * -cdp_init (vlib_main_t * vm) +cdp_input_init (vlib_main_t * vm) { clib_error_t *error; cdp_main_t *cm = &cdp_main; @@ -402,7 +398,7 @@ cdp_init (vlib_main_t * vm) return 0; } -VLIB_INIT_FUNCTION (cdp_init); +VLIB_INIT_FUNCTION (cdp_input_init); static u8 * @@ -432,14 +428,16 @@ format_cdp_neighbors (u8 * s, va_list * va) return s; } - static clib_error_t * show_cdp (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { cdp_main_t *cm = &cdp_main; - vlib_cli_output (vm, "%U\n", format_cdp_neighbors, vm, cm); + if (cm->enabled == 0) + vlib_cli_output (vm, "CDP is not enabled..."); + else + vlib_cli_output (vm, "%U\n", format_cdp_neighbors, vm, cm); return 0; } diff --git a/src/plugins/cdp/cdp_msg_enum.h b/src/plugins/cdp/cdp_msg_enum.h new file mode 100644 index 00000000000..0a7bf063b67 --- /dev/null +++ b/src/plugins/cdp/cdp_msg_enum.h @@ -0,0 +1,31 @@ + +/* + * cdp_msg_enum.h - cdp plug-in message enumeration + * + * Copyright (c) 2011-2018 by 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. + */ +#ifndef included_cdp_msg_enum_h +#define included_cdp_msg_enum_h + +#include + +#define vl_msg_id(n,h) n, +typedef enum { +#include + /* We'll want to know how many messages IDs we need... */ + VL_MSG_FIRST_AVAILABLE, +} vl_msg_id_t; +#undef vl_msg_id + +#endif /* included_cdp_msg_enum_h */ diff --git a/src/vnet/cdp/cdp_node.c b/src/plugins/cdp/cdp_node.c similarity index 93% rename from src/vnet/cdp/cdp_node.c rename to src/plugins/cdp/cdp_node.c index 39ac4a908fb..1336c567287 100644 --- a/src/vnet/cdp/cdp_node.c +++ b/src/plugins/cdp/cdp_node.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2016 Cisco and/or its affiliates. + * Copyright (c) 2011-2018 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: @@ -12,11 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include +#include #include -static vlib_node_registration_t cdp_process_node; - /** \file 2 x CDP graph nodes: an "interior" node to process @@ -152,7 +150,9 @@ cdp_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) ethernet_register_input_type (vm, ETHERNET_TYPE_CDP /* CDP */ , cdp_input_node.index); - poll_time_remaining = 10.0 /* seconds */ ; + /* Start w/ cdp effectively disabled */ + poll_time_remaining = 86400.0; + while (1) { /* sleep until next poll time, or msg serialize event occurs */ @@ -165,12 +165,19 @@ cdp_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) case ~0: /* no events => timeout */ break; + case CDP_EVENT_ENABLE: + poll_time_remaining = 10.0; + break; + + case CDP_EVENT_DISABLE: + poll_time_remaining = 86400.0; + break; + default: clib_warning ("BUG: event type 0x%wx", event_type); break; } - if (event_data) - _vec_len (event_data) = 0; + vec_reset_length (event_data); /* peer timeout scan, send announcements */ if (vlib_process_suspend_time_is_zero (poll_time_remaining)) @@ -187,7 +194,7 @@ cdp_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) * cdp periodic node declaration */ /* *INDENT-OFF* */ -VLIB_REGISTER_NODE (cdp_process_node, static) = { +VLIB_REGISTER_NODE (cdp_process_node) = { .function = cdp_process, .type = VLIB_NODE_TYPE_PROCESS, .name = "cdp-process", diff --git a/src/vnet/cdp/cdp_periodic.c b/src/plugins/cdp/cdp_periodic.c similarity index 99% rename from src/vnet/cdp/cdp_periodic.c rename to src/plugins/cdp/cdp_periodic.c index 8899c49ce9c..c67af00c7a5 100644 --- a/src/vnet/cdp/cdp_periodic.c +++ b/src/plugins/cdp/cdp_periodic.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2016 Cisco and/or its affiliates. + * Copyright (c) 2011-2018 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: @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include +#include #include #include #include diff --git a/src/vnet/cdp/cdp_protocol.h b/src/plugins/cdp/cdp_protocol.h similarity index 99% rename from src/vnet/cdp/cdp_protocol.h rename to src/plugins/cdp/cdp_protocol.h index dc6c66d52c3..46a5603aa70 100644 --- a/src/vnet/cdp/cdp_protocol.h +++ b/src/plugins/cdp/cdp_protocol.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2016 Cisco and/or its affiliates. + * Copyright (c) 2011-2018 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: diff --git a/src/plugins/cdp/cdp_test.c b/src/plugins/cdp/cdp_test.c new file mode 100644 index 00000000000..33b54498f7f --- /dev/null +++ b/src/plugins/cdp/cdp_test.c @@ -0,0 +1,179 @@ +/* + * cdp.c - vpp-api-test cdp protocol plug-in + * + * Copyright (c) 2011-2018 by 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 +#include +#include +#include + +uword unformat_sw_if_index (unformat_input_t * input, va_list * args); + +/* Declare message IDs */ +#include + +/* define message structures */ +#define vl_typedefs +#include +#undef vl_typedefs + +/* declare message handlers for each api */ + +#define vl_endianfun /* define message structures */ +#include +#undef vl_endianfun + +/* instantiate all the print functions we know about */ +#define vl_print(handle, ...) +#define vl_printfun +#include +#undef vl_printfun + +/* Get the API version number. */ +#define vl_api_version(n,v) static u32 api_version=(v); +#include +#undef vl_api_version + + +typedef struct +{ + /* API message ID base */ + u16 msg_id_base; + vat_main_t *vat_main; +} cdp_test_main_t; + +cdp_test_main_t cdp_test_main; + +#define __plugin_msg_base cdp_test_main.msg_id_base +#include + +#define foreach_standard_reply_retval_handler \ +_(cdp_enable_disable_reply) + +#define _(n) \ + static void vl_api_##n##_t_handler \ + (vl_api_##n##_t * mp) \ + { \ + vat_main_t * vam = cdp_test_main.vat_main; \ + i32 retval = ntohl(mp->retval); \ + if (vam->async_mode) { \ + vam->async_errors += (retval < 0); \ + } else { \ + vam->retval = retval; \ + vam->result_ready = 1; \ + } \ + } +foreach_standard_reply_retval_handler; +#undef _ + +/* + * Table of message reply handlers, must include boilerplate handlers + * we just generated + */ +#define foreach_vpe_api_reply_msg \ +_(CDP_ENABLE_DISABLE_REPLY, cdp_enable_disable_reply) + +static int +api_cdp_enable_disable (vat_main_t * vam) +{ + unformat_input_t *i = vam->input; + int enable_disable = 1; + vl_api_cdp_enable_disable_t *mp; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "disable")) + enable_disable = 0; + else if (unformat (i, "enable")) + enable_disable = 1; + else + break; + } + + /* Construct the API message */ + M (CDP_ENABLE_DISABLE, mp); + mp->enable_disable = enable_disable; + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +/* + * List of messages that the api test plugin sends, + * and that the data plane plugin processes + */ +#define foreach_vpe_api_msg \ +_(cdp_enable_disable, "enable | disable") + +static void +cdp_api_hookup (vat_main_t * vam) +{ + cdp_test_main_t *sm = &cdp_test_main; + /* Hook up handlers for replies from the data plane plug-in */ +#define _(N,n) \ + vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \ + #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_reply_msg; +#undef _ + + /* API messages we can send */ +#define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n); + foreach_vpe_api_msg; +#undef _ + + /* Help strings */ +#define _(n,h) hash_set_mem (vam->help_by_name, #n, h); + foreach_vpe_api_msg; +#undef _ +} + +clib_error_t * +vat_plugin_register (vat_main_t * vam) +{ + cdp_test_main_t *sm = &cdp_test_main; + u8 *name; + + sm->vat_main = vam; + + /* Ask the vpp engine for the first assigned message-id */ + name = format (0, "cdp_%08x%c", api_version, 0); + sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name); + + if (sm->msg_id_base != (u16) ~ 0) + cdp_api_hookup (vam); + + vec_free (name); + + return 0; +} + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/vnet.am b/src/vnet.am index a08b4bb5108..9548509715d 100644 --- a/src/vnet.am +++ b/src/vnet.am @@ -272,17 +272,6 @@ nobase_include_HEADERS += \ API_FILES += vnet/geneve/geneve.api -######################################## -# Layer 2 / CDP -######################################## -libvnet_la_SOURCES += \ - vnet/cdp/cdp_input.c \ - vnet/cdp/cdp_node.c \ - vnet/cdp/cdp_periodic.c - -nobase_include_HEADERS += \ - vnet/cdp/cdp_protocol.h - ######################################## # Layer 2 / LLDP ######################################## -- 2.16.6