2 * cdp.c - cdp protocol plug-in
4 * Copyright (c) 2011-2018 by Cisco and/or its affiliates.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <vnet/vnet.h>
19 #include <vnet/plugin/plugin.h>
22 #include <vlibapi/api.h>
23 #include <vlibmemory/api.h>
24 #include <vpp/app/version.h>
26 /* define message IDs */
27 #include <cdp/cdp_msg_enum.h>
29 /* define message structures */
31 #include <cdp/cdp_all_api_h.h>
34 /* define generated endian-swappers */
36 #include <cdp/cdp_all_api_h.h>
39 /* instantiate all the print functions we know about */
40 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
42 #include <cdp/cdp_all_api_h.h>
45 /* Get the API version number */
46 #define vl_api_version(n,v) static u32 api_version=(v);
47 #include <cdp/cdp_all_api_h.h>
50 #define REPLY_MSG_ID_BASE cm->msg_id_base
51 #include <vlibapi/api_helper_macros.h>
53 /* List of message types that this plugin understands */
55 #define foreach_cdp_plugin_api_msg \
56 _(CDP_ENABLE_DISABLE, cdp_enable_disable)
58 /* Action function shared between message handler and debug CLI */
61 cdp_enable_disable (cdp_main_t * cm, int enable_disable)
66 vlib_process_signal_event (cm->vlib_main, cdp_process_node.index,
69 vlib_process_signal_event (cm->vlib_main, cdp_process_node.index,
70 CDP_EVENT_DISABLE, 0);
71 cm->enabled = enable_disable;
77 cdp_command_fn (vlib_main_t * vm,
78 unformat_input_t * input, vlib_cli_command_t * cmd)
80 cdp_main_t *cm = &cdp_main;
81 int enable_disable = 1;
85 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
87 if (unformat (input, "disable"))
89 else if (unformat (input, "enable"))
95 rv = cdp_enable_disable (cm, enable_disable);
103 return clib_error_return (0, "cdp_enable_disable returned %d", rv);
109 VLIB_CLI_COMMAND (cdp_command, static) =
112 .short_help = "cdp enable | disable",
113 .function = cdp_command_fn,
117 /* API message handler */
118 static void vl_api_cdp_enable_disable_t_handler
119 (vl_api_cdp_enable_disable_t * mp)
121 vl_api_cdp_enable_disable_reply_t *rmp;
122 cdp_main_t *cm = &cdp_main;
125 rv = cdp_enable_disable (cm, (int) (mp->enable_disable));
127 REPLY_MACRO (VL_API_CDP_ENABLE_DISABLE_REPLY);
130 /* Set up the API message handling tables */
131 static clib_error_t *
132 cdp_plugin_api_hookup (vlib_main_t * vm)
134 cdp_main_t *cm = &cdp_main;
136 vl_msg_api_set_handlers((VL_API_##N + cm->msg_id_base), \
138 vl_api_##n##_t_handler, \
140 vl_api_##n##_t_endian, \
141 vl_api_##n##_t_print, \
142 sizeof(vl_api_##n##_t), 1);
143 foreach_cdp_plugin_api_msg;
149 #define vl_msg_name_crc_list
150 #include <cdp/cdp_all_api_h.h>
151 #undef vl_msg_name_crc_list
154 setup_message_id_table (cdp_main_t * cm, api_main_t * am)
156 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + cm->msg_id_base);
157 foreach_vl_msg_name_crc_cdp;
161 static clib_error_t *
162 cdp_init (vlib_main_t * vm)
164 cdp_main_t *cm = &cdp_main;
165 clib_error_t *error = 0;
170 name = format (0, "cdp_%08x%c", api_version, 0);
172 /* Ask for a correctly-sized block of API message decode slots */
173 cm->msg_id_base = vl_msg_api_get_msg_ids
174 ((char *) name, VL_MSG_FIRST_AVAILABLE);
176 error = cdp_plugin_api_hookup (vm);
178 /* Add our API messages to the global name_crc hash table */
179 setup_message_id_table (cm, &api_main);
186 VLIB_INIT_FUNCTION (cdp_init);
189 VLIB_PLUGIN_REGISTER () =
191 .version = VPP_BUILD_VER,
196 * fd.io coding-style-patch-verification: ON
199 * eval: (c-set-style "gnu")