c71be664608c304078e41436c26f5fe3cb0f6557
[vpp.git] / src / plugins / builtinurl / builtinurl_test.c
1 /*
2  * builtinurl.c - skeleton vpp-api-test plug-in
3  *
4  * Copyright (c) 2019 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:
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17 #include <vat/vat.h>
18 #include <vlibapi/api.h>
19 #include <vlibmemory/api.h>
20 #include <vppinfra/error.h>
21 #include <stdbool.h>
22
23 uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
24
25 /* Declare message IDs */
26 #include <builtinurl/builtinurl_msg_enum.h>
27
28 /* define message structures */
29 #define vl_typedefs
30 #include <builtinurl/builtinurl_all_api_h.h>
31 #undef vl_typedefs
32
33 /* declare message handlers for each api */
34
35 #define vl_endianfun            /* define message structures */
36 #include <builtinurl/builtinurl_all_api_h.h>
37 #undef vl_endianfun
38
39 /* instantiate all the print functions we know about */
40 #define vl_print(handle, ...)
41 #define vl_printfun
42 #include <builtinurl/builtinurl_all_api_h.h>
43 #undef vl_printfun
44
45 /* Get the API version number. */
46 #define vl_api_version(n,v) static u32 api_version=(v);
47 #include <builtinurl/builtinurl_all_api_h.h>
48 #undef vl_api_version
49
50
51 typedef struct
52 {
53   /* API message ID base */
54   u16 msg_id_base;
55   vat_main_t *vat_main;
56 } builtinurl_test_main_t;
57
58 builtinurl_test_main_t builtinurl_test_main;
59
60 #define __plugin_msg_base builtinurl_test_main.msg_id_base
61 #include <vlibapi/vat_helper_macros.h>
62
63 #define foreach_standard_reply_retval_handler   \
64 _(builtinurl_enable_reply)
65
66 #define _(n)                                            \
67     static void vl_api_##n##_t_handler                  \
68     (vl_api_##n##_t * mp)                               \
69     {                                                   \
70         vat_main_t * vam = builtinurl_test_main.vat_main;   \
71         i32 retval = ntohl(mp->retval);                 \
72         if (vam->async_mode) {                          \
73             vam->async_errors += (retval < 0);          \
74         } else {                                        \
75             vam->retval = retval;                       \
76             vam->result_ready = 1;                      \
77         }                                               \
78     }
79 foreach_standard_reply_retval_handler;
80 #undef _
81
82 /*
83  * Table of message reply handlers, must include boilerplate handlers
84  * we just generated
85  */
86 #define foreach_vpe_api_reply_msg                                       \
87 _(BUILTINURL_ENABLE_REPLY, builtinurl_enable_reply)
88
89
90 static int
91 api_builtinurl_enable_disable (vat_main_t * vam)
92 {
93   vl_api_builtinurl_enable_t *mp;
94   int ret;
95
96   /* Construct the API message */
97   M (BUILTINURL_ENABLE, mp);
98
99   /* send it... */
100   S (mp);
101
102   /* Wait for a reply... */
103   W (ret);
104   return ret;
105 }
106
107 /*
108  * List of messages that the api test plugin sends,
109  * and that the data plane plugin processes
110  */
111 #define foreach_vpe_api_msg \
112 _(builtinurl_enable_disable, "")
113
114 static void
115 builtinurl_api_hookup (vat_main_t * vam)
116 {
117   builtinurl_test_main_t *btmp = &builtinurl_test_main;
118   /* Hook up handlers for replies from the data plane plug-in */
119 #define _(N,n)                                                  \
120     vl_msg_api_set_handlers((VL_API_##N + btmp->msg_id_base),     \
121                            #n,                                  \
122                            vl_api_##n##_t_handler,              \
123                            vl_noop_handler,                     \
124                            vl_api_##n##_t_endian,               \
125                            vl_api_##n##_t_print,                \
126                            sizeof(vl_api_##n##_t), 1);
127   foreach_vpe_api_reply_msg;
128 #undef _
129
130   /* API messages we can send */
131 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
132   foreach_vpe_api_msg;
133 #undef _
134
135   /* Help strings */
136 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
137   foreach_vpe_api_msg;
138 #undef _
139 }
140
141 VAT_PLUGIN_REGISTER (builtinurl);
142
143 /*
144  * fd.io coding-style-patch-verification: ON
145  *
146  * Local Variables:
147  * eval: (c-set-style "gnu")
148  * End:
149  */