blob: 42962acf2b7110e00611522194592306e0a6eafe [file] [log] [blame]
Dave Barachb852bfa2016-01-04 15:27:42 -05001;;; plugin-test-skel.el - vpp-api-test plug-in skeleton
2;;;
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:
7;;;
8;;; http://www.apache.org/licenses/LICENSE-2.0
9;;;
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.
15
16(require 'skeleton)
17
Keith Burns (alagalah)ca46d8c2016-03-18 07:22:15 -070018(define-skeleton skel-plugin-test
Dave Barachb852bfa2016-01-04 15:27:42 -050019"Insert a plug-in vpp-api-test skeleton "
20nil
21'(if (not (boundp 'plugin-name))
22 (setq plugin-name (read-string "Plugin name: ")))
23'(setq PLUGIN-NAME (upcase plugin-name))
Dave Barachfed79e82017-02-10 11:57:46 -050024'(setq capital-oh-en "ON")
Dave Barach82842442018-10-31 09:54:34 -040025'(setq main-p (concat (substring plugin-name 0 1) "tmp"))
Dave Barachfed79e82017-02-10 11:57:46 -050026"/*
Dave Barach913f4c92019-05-29 09:59:51 -040027 * " plugin-name ".c - skeleton vpp-api-test plug-in
Dave Barachb852bfa2016-01-04 15:27:42 -050028 *
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:
33 *
34 * http://www.apache.org/licenses/LICENSE-2.0
35 *
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.
41 */
42#include <vat/vat.h>
43#include <vlibapi/api.h>
44#include <vlibmemory/api.h>
Dave Barachb852bfa2016-01-04 15:27:42 -050045#include <vppinfra/error.h>
Dave Barach913f4c92019-05-29 09:59:51 -040046#include <stdbool.h>
Dave Barachb852bfa2016-01-04 15:27:42 -050047
48uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
49
50/* Declare message IDs */
51#include <" plugin-name "/" plugin-name "_msg_enum.h>
52
53/* define message structures */
54#define vl_typedefs
Dave Barach913f4c92019-05-29 09:59:51 -040055#include <" plugin-name "/" plugin-name "_all_api_h.h>
Dave Barachb852bfa2016-01-04 15:27:42 -050056#undef vl_typedefs
57
58/* declare message handlers for each api */
59
60#define vl_endianfun /* define message structures */
Dave Barach913f4c92019-05-29 09:59:51 -040061#include <" plugin-name "/" plugin-name "_all_api_h.h>
Dave Barachb852bfa2016-01-04 15:27:42 -050062#undef vl_endianfun
63
64/* instantiate all the print functions we know about */
65#define vl_print(handle, ...)
66#define vl_printfun
Dave Barach913f4c92019-05-29 09:59:51 -040067#include <" plugin-name "/" plugin-name "_all_api_h.h>
Dave Barachb852bfa2016-01-04 15:27:42 -050068#undef vl_printfun
69
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>
73#undef vl_api_version
74
75
Dave Barach913f4c92019-05-29 09:59:51 -040076typedef struct
Dave Barachfed79e82017-02-10 11:57:46 -050077{
78 /* API message ID base */
79 u16 msg_id_base;
80 vat_main_t *vat_main;
Dave Barachb852bfa2016-01-04 15:27:42 -050081} " plugin-name "_test_main_t;
82
83" plugin-name "_test_main_t " plugin-name "_test_main;
84
Dave Barachfed79e82017-02-10 11:57:46 -050085#define __plugin_msg_base " plugin-name"_test_main.msg_id_base
86#include <vlibapi/vat_helper_macros.h>
87
Dave Barachb852bfa2016-01-04 15:27:42 -050088#define foreach_standard_reply_retval_handler \\
89_(" plugin-name "_enable_disable_reply)
90
91#define _(n) \\
92 static void vl_api_##n##_t_handler \\
93 (vl_api_##n##_t * mp) \\
94 { \\
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); \\
99 } else { \\
100 vam->retval = retval; \\
101 vam->result_ready = 1; \\
102 } \\
103 }
104foreach_standard_reply_retval_handler;
105#undef _
106
Dave Barach913f4c92019-05-29 09:59:51 -0400107/*
Dave Barachb852bfa2016-01-04 15:27:42 -0500108 * Table of message reply handlers, must include boilerplate handlers
109 * we just generated
110 */
111#define foreach_vpe_api_reply_msg \\
112_(" PLUGIN-NAME "_ENABLE_DISABLE_REPLY, " plugin-name "_enable_disable_reply)
113
114
Dave Barachb852bfa2016-01-04 15:27:42 -0500115static int api_" plugin-name "_enable_disable (vat_main_t * vam)
116{
Dave Barachfed79e82017-02-10 11:57:46 -0500117 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;
121 int ret;
Dave Barachb852bfa2016-01-04 15:27:42 -0500122
Dave Barachfed79e82017-02-10 11:57:46 -0500123 /* Parse args required to build the message */
Dave Barach913f4c92019-05-29 09:59:51 -0400124 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Dave Barachfed79e82017-02-10 11:57:46 -0500125 {
126 if (unformat (i, \"%U\", unformat_sw_if_index, vam, &sw_if_index))
127 ;
128 else if (unformat (i, \"sw_if_index %d\", &sw_if_index))
129 ;
130 else if (unformat (i, \"disable\"))
131 enable_disable = 0;
132 else
133 break;
Dave Barachb852bfa2016-01-04 15:27:42 -0500134 }
Dave Barach913f4c92019-05-29 09:59:51 -0400135
136 if (sw_if_index == ~0)
Dave Barachfed79e82017-02-10 11:57:46 -0500137 {
138 errmsg (\"missing interface name / explicit sw_if_index number \\n\");
139 return -99;
Dave Barachb852bfa2016-01-04 15:27:42 -0500140 }
Dave Barach913f4c92019-05-29 09:59:51 -0400141
Dave Barachfed79e82017-02-10 11:57:46 -0500142 /* 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;
Dave Barachb852bfa2016-01-04 15:27:42 -0500146
Dave Barachfed79e82017-02-10 11:57:46 -0500147 /* send it... */
148 S(mp);
Dave Barachb852bfa2016-01-04 15:27:42 -0500149
Dave Barachfed79e82017-02-10 11:57:46 -0500150 /* Wait for a reply... */
151 W (ret);
152 return ret;
Dave Barachb852bfa2016-01-04 15:27:42 -0500153}
154
Dave Barach913f4c92019-05-29 09:59:51 -0400155/*
Dave Barachb852bfa2016-01-04 15:27:42 -0500156 * List of messages that the api test plugin sends,
157 * and that the data plane plugin processes
158 */
159#define foreach_vpe_api_msg \\
160_(" plugin-name "_enable_disable, \"<intfc> [disable]\")
161
Dave Barach99617f72017-03-04 08:35:48 -0500162static void " plugin-name "_api_hookup (vat_main_t *vam)
Dave Barachb852bfa2016-01-04 15:27:42 -0500163{
Dave Barach82842442018-10-31 09:54:34 -0400164 " plugin-name "_test_main_t * " main-p " = &" plugin-name "_test_main;
Dave Barachb852bfa2016-01-04 15:27:42 -0500165 /* Hook up handlers for replies from the data plane plug-in */
166#define _(N,n) \\
Dave Barach82842442018-10-31 09:54:34 -0400167 vl_msg_api_set_handlers((VL_API_##N + " main-p "->msg_id_base), \\
Dave Barachb852bfa2016-01-04 15:27:42 -0500168 #n, \\
169 vl_api_##n##_t_handler, \\
170 vl_noop_handler, \\
171 vl_api_##n##_t_endian, \\
172 vl_api_##n##_t_print, \\
Dave Barach913f4c92019-05-29 09:59:51 -0400173 sizeof(vl_api_##n##_t), 1);
Dave Barachb852bfa2016-01-04 15:27:42 -0500174 foreach_vpe_api_reply_msg;
175#undef _
176
177 /* API messages we can send */
178#define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
179 foreach_vpe_api_msg;
Dave Barach913f4c92019-05-29 09:59:51 -0400180#undef _
181
Dave Barachb852bfa2016-01-04 15:27:42 -0500182 /* Help strings */
183#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
184 foreach_vpe_api_msg;
185#undef _
186}
187
Dave Barache5a7d592019-07-09 14:22:21 -0400188VAT_PLUGIN_REGISTER(" plugin-name");
Dave Barachb852bfa2016-01-04 15:27:42 -0500189
Dave Barachfed79e82017-02-10 11:57:46 -0500190/*
191 * fd.io coding-style-patch-verification: " capital-oh-en "
192 *
193 * Local Variables:
194 * eval: (c-set-style \"gnu\")
195 * End:
196 */
Dave Barachb852bfa2016-01-04 15:27:42 -0500197")