2 * ct6.c - skeleton vpp-api-test plug-in
4 * Copyright (c) <current-year> <your-organization>
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 <ct6/ct6_msg_enum.h>
27 /* define message structures */
29 #include <ct6/ct6_all_api_h.h>
32 /* declare message handlers for each api */
34 #define vl_endianfun /* define message structures */
35 #include <ct6/ct6_all_api_h.h>
38 /* instantiate all the print functions we know about */
39 #define vl_print(handle, ...)
41 #include <ct6/ct6_all_api_h.h>
44 /* Get the API version number. */
45 #define vl_api_version(n,v) static u32 api_version=(v);
46 #include <ct6/ct6_all_api_h.h>
52 /* API message ID base */
57 ct6_test_main_t ct6_test_main;
59 #define __plugin_msg_base ct6_test_main.msg_id_base
60 #include <vlibapi/vat_helper_macros.h>
62 #define foreach_standard_reply_retval_handler \
63 _(ct6_enable_disable_reply)
66 static void vl_api_##n##_t_handler \
67 (vl_api_##n##_t * mp) \
69 vat_main_t * vam = ct6_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 _(CT6_ENABLE_DISABLE_REPLY, ct6_enable_disable_reply)
90 api_ct6_enable_disable (vat_main_t * vam)
92 unformat_input_t *i = vam->input;
93 int enable_disable = 1;
95 vl_api_ct6_enable_disable_t *mp;
99 /* Parse args required to build the message */
100 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
102 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
104 else if (unformat (i, "sw_if_index %d", &sw_if_index))
106 else if (unformat (i, "disable"))
108 else if (unformat (i, "inside") || unformat (i, "in"))
110 else if (unformat (i, "outside") || unformat (i, "out"))
118 errmsg ("must specify inside or outside");
122 if (sw_if_index == ~0)
124 errmsg ("missing interface name / explicit sw_if_index number \n");
128 /* Construct the API message */
129 M (CT6_ENABLE_DISABLE, mp);
130 mp->sw_if_index = ntohl (sw_if_index);
131 mp->enable_disable = enable_disable;
132 mp->is_inside = (u8) inside;
137 /* Wait for a reply... */
143 * List of messages that the api test plugin sends,
144 * and that the data plane plugin processes
146 #define foreach_vpe_api_msg \
147 _(ct6_enable_disable, "<intfc> [disable]")
150 ct6_api_hookup (vat_main_t * vam)
152 ct6_test_main_t *ctmp = &ct6_test_main;
153 /* Hook up handlers for replies from the data plane plug-in */
155 vl_msg_api_set_handlers((VL_API_##N + ctmp->msg_id_base), \
157 vl_api_##n##_t_handler, \
159 vl_api_##n##_t_endian, \
160 vl_api_##n##_t_print, \
161 sizeof(vl_api_##n##_t), 1);
162 foreach_vpe_api_reply_msg;
165 /* API messages we can send */
166 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
171 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
177 vat_plugin_register (vat_main_t * vam)
179 ct6_test_main_t *ctmp = &ct6_test_main;
182 ctmp->vat_main = vam;
184 /* Ask the vpp engine for the first assigned message-id */
185 name = format (0, "ct6_%08x%c", api_version, 0);
186 ctmp->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
188 if (ctmp->msg_id_base != (u16) ~ 0)
189 ct6_api_hookup (vam);
197 * fd.io coding-style-patch-verification: ON
200 * eval: (c-set-style "gnu")