ip: fix udp/tcp checksum corner cases
[vpp.git] / src / plugins / oddbuf / oddbuf_test.c
1 /*
2  * oddbuf.c - skeleton vpp-api-test plug-in
3  *
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:
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 <oddbuf/oddbuf_msg_enum.h>
27
28 /* define message structures */
29 #define vl_typedefs
30 #include <oddbuf/oddbuf_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 <oddbuf/oddbuf_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 <oddbuf/oddbuf_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 <oddbuf/oddbuf_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 } oddbuf_test_main_t;
57
58 oddbuf_test_main_t oddbuf_test_main;
59
60 #define __plugin_msg_base oddbuf_test_main.msg_id_base
61 #include <vlibapi/vat_helper_macros.h>
62
63 #define foreach_standard_reply_retval_handler   \
64 _(oddbuf_enable_disable_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 = oddbuf_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 _(ODDBUF_ENABLE_DISABLE_REPLY, oddbuf_enable_disable_reply)
88
89
90 static int
91 api_oddbuf_enable_disable (vat_main_t * vam)
92 {
93   unformat_input_t *i = vam->input;
94   int enable_disable = 1;
95   u32 sw_if_index = ~0;
96   vl_api_oddbuf_enable_disable_t *mp;
97   int ret;
98
99   /* Parse args required to build the message */
100   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
101     {
102       if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
103         ;
104       else if (unformat (i, "sw_if_index %d", &sw_if_index))
105         ;
106       else if (unformat (i, "disable"))
107         enable_disable = 0;
108       else
109         break;
110     }
111
112   if (sw_if_index == ~0)
113     {
114       errmsg ("missing interface name / explicit sw_if_index number \n");
115       return -99;
116     }
117
118   /* Construct the API message */
119   M (ODDBUF_ENABLE_DISABLE, mp);
120   mp->sw_if_index = ntohl (sw_if_index);
121   mp->enable_disable = enable_disable;
122
123   /* send it... */
124   S (mp);
125
126   /* Wait for a reply... */
127   W (ret);
128   return ret;
129 }
130
131 /*
132  * List of messages that the api test plugin sends,
133  * and that the data plane plugin processes
134  */
135 #define foreach_vpe_api_msg \
136 _(oddbuf_enable_disable, "<intfc> [disable]")
137
138 static void
139 oddbuf_api_hookup (vat_main_t * vam)
140 {
141   oddbuf_test_main_t *otmp = &oddbuf_test_main;
142   /* Hook up handlers for replies from the data plane plug-in */
143 #define _(N,n)                                                  \
144     vl_msg_api_set_handlers((VL_API_##N + otmp->msg_id_base),     \
145                            #n,                                  \
146                            vl_api_##n##_t_handler,              \
147                            vl_noop_handler,                     \
148                            vl_api_##n##_t_endian,               \
149                            vl_api_##n##_t_print,                \
150                            sizeof(vl_api_##n##_t), 1);
151   foreach_vpe_api_reply_msg;
152 #undef _
153
154   /* API messages we can send */
155 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
156   foreach_vpe_api_msg;
157 #undef _
158
159   /* Help strings */
160 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
161   foreach_vpe_api_msg;
162 #undef _
163 }
164
165 VAT_PLUGIN_REGISTER (oddbuf);
166
167 /*
168  * fd.io coding-style-patch-verification: ON
169  *
170  * Local Variables:
171  * eval: (c-set-style "gnu")
172  * End:
173  */