2 * http_static.c - skeleton vpp-api-test plug-in
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <vlibapi/api.h>
19 #include <vlibmemory/api.h>
20 #include <vppinfra/error.h>
21 #include <vlibapi/api_types_inlines.h>
23 uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
25 /* Declare message IDs */
26 #include <http_static/http_static_msg_enum.h>
28 /* define message structures */
30 #include <http_static/http_static_all_api_h.h>
33 /* declare message handlers for each api */
35 #define vl_endianfun /* define message structures */
36 #include <http_static/http_static_all_api_h.h>
39 /* instantiate all the print functions we know about */
40 #define vl_print(handle, ...)
42 #include <http_static/http_static_all_api_h.h>
45 /* Get the API version number. */
46 #define vl_api_version(n,v) static u32 api_version=(v);
47 #include <http_static/http_static_all_api_h.h>
53 /* API message ID base */
56 } http_static_test_main_t;
58 http_static_test_main_t http_static_test_main;
60 #define __plugin_msg_base http_static_test_main.msg_id_base
61 #include <vlibapi/vat_helper_macros.h>
63 #define foreach_standard_reply_retval_handler \
64 _(http_static_enable_reply)
67 static void vl_api_##n##_t_handler \
68 (vl_api_##n##_t * mp) \
70 vat_main_t * vam = http_static_test_main.vat_main; \
71 i32 retval = ntohl(mp->retval); \
72 if (vam->async_mode) { \
73 vam->async_errors += (retval < 0); \
75 vam->retval = retval; \
76 vam->result_ready = 1; \
79 foreach_standard_reply_retval_handler;
83 * Table of message reply handlers, must include boilerplate handlers
86 #define foreach_vpe_api_reply_msg \
87 _(HTTP_STATIC_ENABLE_REPLY, http_static_enable_reply)
91 api_http_static_enable (vat_main_t * vam)
93 unformat_input_t *line_input = vam->input;
94 vl_api_http_static_enable_t *mp;
98 u32 prealloc_fifos = 0;
99 u32 private_segment_size = 0;
100 u32 fifo_size = 8 << 10;
101 u32 cache_size_limit = 1 << 20;
104 /* Parse args required to build the message */
105 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
107 if (unformat (line_input, "www-root %s", &www_root))
109 else if (unformat (line_input, "prealloc-fifos %d", &prealloc_fifos))
111 else if (unformat (line_input, "private-segment-size %U",
112 unformat_memory_size, &tmp))
114 if (tmp >= 0x100000000ULL)
116 errmsg ("private segment size %llu, too large", tmp);
119 private_segment_size = (u32) tmp;
121 else if (unformat (line_input, "fifo-size %U", unformat_memory_size,
124 fifo_size = (u32) tmp;
126 else if (unformat (line_input, "cache-size %U", unformat_memory_size,
129 if (tmp < (128ULL << 10))
131 errmsg ("cache-size must be at least 128kb");
134 cache_size_limit = (u32) tmp;
137 else if (unformat (line_input, "uri %s", &uri))
141 errmsg ("unknown input `%U'", format_unformat_error, line_input);
148 errmsg ("Must specify www-root");
153 uri = format (0, "tcp://0.0.0.0/80%c", 0);
157 /* Construct the API message */
158 M (HTTP_STATIC_ENABLE, mp);
159 vl_api_to_api_string (strnlen ((const char *) www_root, 256),
160 (const char *) www_root,
161 (vl_api_string_t *) & mp->www_root);
162 vl_api_to_api_string (strnlen ((const char *) uri, 256), (const char *) uri,
163 (vl_api_string_t *) & mp->uri);
164 mp->fifo_size = ntohl (fifo_size);
165 mp->cache_size_limit = ntohl (cache_size_limit);
166 mp->prealloc_fifos = ntohl (prealloc_fifos);
167 mp->private_segment_size = ntohl (private_segment_size);
172 /* Wait for a reply... */
178 * List of messages that the api test plugin sends,
179 * and that the data plane plugin processes
181 #define foreach_vpe_api_msg \
182 _(http_static_enable, "www-root <path> [prealloc-fios <nn>]\n" \
183 "[private-segment-size <nnMG>] [fifo-size <nbytes>] [uri <uri>]\n")
186 http_static_api_hookup (vat_main_t * vam)
188 http_static_test_main_t *htmp = &http_static_test_main;
189 /* Hook up handlers for replies from the data plane plug-in */
191 vl_msg_api_set_handlers((VL_API_##N + htmp->msg_id_base), \
193 vl_api_##n##_t_handler, \
195 vl_api_##n##_t_endian, \
196 vl_api_##n##_t_print, \
197 sizeof(vl_api_##n##_t), 1);
198 foreach_vpe_api_reply_msg;
201 /* API messages we can send */
202 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
207 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
213 vat_plugin_register (vat_main_t * vam)
215 http_static_test_main_t *htmp = &http_static_test_main;
218 htmp->vat_main = vam;
220 /* Ask the vpp engine for the first assigned message-id */
221 name = format (0, "http_static_%08x%c", api_version, 0);
222 htmp->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
224 if (htmp->msg_id_base != (u16) ~ 0)
225 http_static_api_hookup (vam);
233 * fd.io coding-style-patch-verification: ON
236 * eval: (c-set-style "gnu")