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")
26 * " plugin-name ".c - skeleton vpp-api-test plug-in
28 * Copyright (c) <current-year> <your-organization>
29 * Licensed under the Apache License, Version 2.0 (the \"License\");
30 * you may not use this file except in compliance with the License.
31 * You may obtain a copy of the License at:
33 * http://www.apache.org/licenses/LICENSE-2.0
35 * Unless required by applicable law or agreed to in writing, software
36 * distributed under the License is distributed on an \"AS IS\" BASIS,
37 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38 * See the License for the specific language governing permissions and
39 * limitations under the License.
42 #include <vlibapi/api.h>
43 #include <vlibmemory/api.h>
44 #include <vppinfra/error.h>
46 uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
48 /* Declare message IDs */
49 #include <" plugin-name "/" plugin-name "_msg_enum.h>
51 /* define message structures */
53 #include <" plugin-name "/" plugin-name "_all_api_h.h>
56 /* declare message handlers for each api */
58 #define vl_endianfun /* define message structures */
59 #include <" plugin-name "/" plugin-name "_all_api_h.h>
62 /* instantiate all the print functions we know about */
63 #define vl_print(handle, ...)
65 #include <" plugin-name "/" plugin-name "_all_api_h.h>
68 /* Get the API version number. */
69 #define vl_api_version(n,v) static u32 api_version=(v);
70 #include <" plugin-name "/" plugin-name "_all_api_h.h>
76 /* API message ID base */
79 } " plugin-name "_test_main_t;
81 " plugin-name "_test_main_t " plugin-name "_test_main;
83 #define __plugin_msg_base " plugin-name"_test_main.msg_id_base
84 #include <vlibapi/vat_helper_macros.h>
86 #define foreach_standard_reply_retval_handler \\
87 _(" plugin-name "_enable_disable_reply)
90 static void vl_api_##n##_t_handler \\
91 (vl_api_##n##_t * mp) \\
93 vat_main_t * vam = " plugin-name "_test_main.vat_main; \\
94 i32 retval = ntohl(mp->retval); \\
95 if (vam->async_mode) { \\
96 vam->async_errors += (retval < 0); \\
98 vam->retval = retval; \\
99 vam->result_ready = 1; \\
102 foreach_standard_reply_retval_handler;
106 * Table of message reply handlers, must include boilerplate handlers
109 #define foreach_vpe_api_reply_msg \\
110 _(" PLUGIN-NAME "_ENABLE_DISABLE_REPLY, " plugin-name "_enable_disable_reply)
113 static int api_" plugin-name "_enable_disable (vat_main_t * vam)
115 unformat_input_t * i = vam->input;
116 int enable_disable = 1;
117 u32 sw_if_index = ~0;
118 vl_api_" plugin-name "_enable_disable_t * mp;
121 /* Parse args required to build the message */
122 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
124 if (unformat (i, \"%U\", unformat_sw_if_index, vam, &sw_if_index))
126 else if (unformat (i, \"sw_if_index %d\", &sw_if_index))
128 else if (unformat (i, \"disable\"))
134 if (sw_if_index == ~0)
136 errmsg (\"missing interface name / explicit sw_if_index number \\n\");
140 /* Construct the API message */
141 M(" PLUGIN-NAME "_ENABLE_DISABLE, mp);
142 mp->sw_if_index = ntohl (sw_if_index);
143 mp->enable_disable = enable_disable;
148 /* Wait for a reply... */
154 * List of messages that the api test plugin sends,
155 * and that the data plane plugin processes
157 #define foreach_vpe_api_msg \\
158 _(" plugin-name "_enable_disable, \"<intfc> [disable]\")
160 static void " plugin-name "_api_hookup (vat_main_t *vam)
162 " plugin-name "_test_main_t * sm = &" plugin-name "_test_main;
163 /* Hook up handlers for replies from the data plane plug-in */
165 vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \\
167 vl_api_##n##_t_handler, \\
169 vl_api_##n##_t_endian, \\
170 vl_api_##n##_t_print, \\
171 sizeof(vl_api_##n##_t), 1);
172 foreach_vpe_api_reply_msg;
175 /* API messages we can send */
176 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
181 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
186 clib_error_t * vat_plugin_register (vat_main_t *vam)
188 " plugin-name "_test_main_t * sm = &" plugin-name "_test_main;
193 /* Ask the vpp engine for the first assigned message-id */
194 name = format (0, \"" plugin-name "_%08x%c\", api_version, 0);
195 sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
197 if (sm->msg_id_base != (u16) ~0)
198 " plugin-name "_api_hookup (vam);
205 * fd.io coding-style-patch-verification: " capital-oh-en "
208 * eval: (c-set-style \"gnu\")