2 * cdp.c - vpp-api-test 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 <vlibapi/api.h>
19 #include <vlibmemory/api.h>
20 #include <vppinfra/error.h>
22 uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
24 /* Declare message IDs */
25 #include <cdp/cdp_msg_enum.h>
27 /* define message structures */
29 #include <cdp/cdp_all_api_h.h>
32 /* declare message handlers for each api */
34 #define vl_endianfun /* define message structures */
35 #include <cdp/cdp_all_api_h.h>
38 /* instantiate all the print functions we know about */
39 #define vl_print(handle, ...)
41 #include <cdp/cdp_all_api_h.h>
44 /* Get the API version number. */
45 #define vl_api_version(n,v) static u32 api_version=(v);
46 #include <cdp/cdp_all_api_h.h>
52 /* API message ID base */
57 cdp_test_main_t cdp_test_main;
59 #define __plugin_msg_base cdp_test_main.msg_id_base
60 #include <vlibapi/vat_helper_macros.h>
62 #define foreach_standard_reply_retval_handler \
63 _(cdp_enable_disable_reply)
66 static void vl_api_##n##_t_handler \
67 (vl_api_##n##_t * mp) \
69 vat_main_t * vam = cdp_test_main.vat_main; \
70 i32 retval = ntohl(mp->retval); \
71 if (vam->async_mode) { \
72 vam->async_errors += (retval < 0); \
74 vam->retval = retval; \
75 vam->result_ready = 1; \
78 foreach_standard_reply_retval_handler;
82 * Table of message reply handlers, must include boilerplate handlers
85 #define foreach_vpe_api_reply_msg \
86 _(CDP_ENABLE_DISABLE_REPLY, cdp_enable_disable_reply)
89 api_cdp_enable_disable (vat_main_t * vam)
91 unformat_input_t *i = vam->input;
92 int enable_disable = 1;
93 vl_api_cdp_enable_disable_t *mp;
96 /* Parse args required to build the message */
97 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
99 if (unformat (i, "disable"))
101 else if (unformat (i, "enable"))
107 /* Construct the API message */
108 M (CDP_ENABLE_DISABLE, mp);
109 mp->enable_disable = enable_disable;
114 /* Wait for a reply... */
120 * List of messages that the api test plugin sends,
121 * and that the data plane plugin processes
123 #define foreach_vpe_api_msg \
124 _(cdp_enable_disable, "enable | disable")
127 cdp_api_hookup (vat_main_t * vam)
129 cdp_test_main_t *sm = &cdp_test_main;
130 /* Hook up handlers for replies from the data plane plug-in */
132 vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
134 vl_api_##n##_t_handler, \
136 vl_api_##n##_t_endian, \
137 vl_api_##n##_t_print, \
138 sizeof(vl_api_##n##_t), 1);
139 foreach_vpe_api_reply_msg;
142 /* API messages we can send */
143 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
148 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
154 vat_plugin_register (vat_main_t * vam)
156 cdp_test_main_t *sm = &cdp_test_main;
161 /* Ask the vpp engine for the first assigned message-id */
162 name = format (0, "cdp_%08x%c", api_version, 0);
163 sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
165 if (sm->msg_id_base != (u16) ~ 0)
166 cdp_api_hookup (vam);
174 * fd.io coding-style-patch-verification: ON
177 * eval: (c-set-style "gnu")