1 ;;; plugin-test-skel.el - vpp-api-test plug-in skeleton
3 ;;; Copyright (c) 2016 Cisco and/or its affiliates.
4 ;;; Licensed under the Apache License, Version 2.0 (the "License");
5 ;;; you may not use this file except in compliance with the License.
6 ;;; You may obtain a copy of the License at:
8 ;;; http://www.apache.org/licenses/LICENSE-2.0
10 ;;; Unless required by applicable law or agreed to in writing, software
11 ;;; distributed under the License is distributed on an "AS IS" BASIS,
12 ;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ;;; See the License for the specific language governing permissions and
14 ;;; limitations under the License.
18 (define-skeleton skel-plugin-test
19 "Insert a plug-in vpp-api-test skeleton "
21 '(if (not (boundp 'plugin-name))
22 (setq plugin-name (read-string "Plugin name: ")))
23 '(setq PLUGIN-NAME (upcase plugin-name))
24 '(setq capital-oh-en "ON")
25 '(setq main-p (concat (substring plugin-name 0 1) "tmp"))
27 * " plugin-name ".c - skeleton vpp-api-test plug-in
29 * Copyright (c) <current-year> <your-organization>
30 * Licensed under the Apache License, Version 2.0 (the \"License\");
31 * you may not use this file except in compliance with the License.
32 * You may obtain a copy of the License at:
34 * http://www.apache.org/licenses/LICENSE-2.0
36 * Unless required by applicable law or agreed to in writing, software
37 * distributed under the License is distributed on an \"AS IS\" BASIS,
38 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
39 * See the License for the specific language governing permissions and
40 * limitations under the License.
43 #include <vlibapi/api.h>
44 #include <vlibmemory/api.h>
45 #include <vppinfra/error.h>
48 uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
50 /* Declare message IDs */
51 #include <" plugin-name "/" plugin-name "_msg_enum.h>
53 /* define message structures */
55 #include <" plugin-name "/" plugin-name "_all_api_h.h>
58 /* declare message handlers for each api */
60 #define vl_endianfun /* define message structures */
61 #include <" plugin-name "/" plugin-name "_all_api_h.h>
64 /* instantiate all the print functions we know about */
65 #define vl_print(handle, ...)
67 #include <" plugin-name "/" plugin-name "_all_api_h.h>
70 /* Get the API version number. */
71 #define vl_api_version(n,v) static u32 api_version=(v);
72 #include <" plugin-name "/" plugin-name "_all_api_h.h>
78 /* API message ID base */
81 } " plugin-name "_test_main_t;
83 " plugin-name "_test_main_t " plugin-name "_test_main;
85 #define __plugin_msg_base " plugin-name"_test_main.msg_id_base
86 #include <vlibapi/vat_helper_macros.h>
88 #define foreach_standard_reply_retval_handler \\
89 _(" plugin-name "_enable_disable_reply)
92 static void vl_api_##n##_t_handler \\
93 (vl_api_##n##_t * mp) \\
95 vat_main_t * vam = " plugin-name "_test_main.vat_main; \\
96 i32 retval = ntohl(mp->retval); \\
97 if (vam->async_mode) { \\
98 vam->async_errors += (retval < 0); \\
100 vam->retval = retval; \\
101 vam->result_ready = 1; \\
104 foreach_standard_reply_retval_handler;
108 * Table of message reply handlers, must include boilerplate handlers
111 #define foreach_vpe_api_reply_msg \\
112 _(" PLUGIN-NAME "_ENABLE_DISABLE_REPLY, " plugin-name "_enable_disable_reply)
115 static int api_" plugin-name "_enable_disable (vat_main_t * vam)
117 unformat_input_t * i = vam->input;
118 int enable_disable = 1;
119 u32 sw_if_index = ~0;
120 vl_api_" plugin-name "_enable_disable_t * mp;
123 /* Parse args required to build the message */
124 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
126 if (unformat (i, \"%U\", unformat_sw_if_index, vam, &sw_if_index))
128 else if (unformat (i, \"sw_if_index %d\", &sw_if_index))
130 else if (unformat (i, \"disable\"))
136 if (sw_if_index == ~0)
138 errmsg (\"missing interface name / explicit sw_if_index number \\n\");
142 /* Construct the API message */
143 M(" PLUGIN-NAME "_ENABLE_DISABLE, mp);
144 mp->sw_if_index = ntohl (sw_if_index);
145 mp->enable_disable = enable_disable;
150 /* Wait for a reply... */
156 * List of messages that the api test plugin sends,
157 * and that the data plane plugin processes
159 #define foreach_vpe_api_msg \\
160 _(" plugin-name "_enable_disable, \"<intfc> [disable]\")
162 static void " plugin-name "_api_hookup (vat_main_t *vam)
164 " plugin-name "_test_main_t * " main-p " = &" plugin-name "_test_main;
165 /* Hook up handlers for replies from the data plane plug-in */
167 vl_msg_api_set_handlers((VL_API_##N + " main-p "->msg_id_base), \\
169 vl_api_##n##_t_handler, \\
171 vl_api_##n##_t_endian, \\
172 vl_api_##n##_t_print, \\
173 sizeof(vl_api_##n##_t), 1);
174 foreach_vpe_api_reply_msg;
177 /* API messages we can send */
178 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
183 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
188 clib_error_t * vat_plugin_register (vat_main_t *vam)
190 " plugin-name "_test_main_t * " main-p " = &" plugin-name "_test_main;
193 " main-p "->vat_main = vam;
195 /* Ask the vpp engine for the first assigned message-id */
196 name = format (0, \"" plugin-name "_%08x%c\", api_version, 0);
197 " main-p "->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
199 if (" main-p "->msg_id_base != (u16) ~0)
200 " plugin-name "_api_hookup (vam);
207 * fd.io coding-style-patch-verification: " capital-oh-en "
210 * eval: (c-set-style \"gnu\")