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>
22 uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
24 /* Declare message IDs */
25 #include <http_static/http_static_msg_enum.h>
27 /* define message structures */
29 #include <http_static/http_static_all_api_h.h>
32 /* declare message handlers for each api */
34 #define vl_endianfun /* define message structures */
35 #include <http_static/http_static_all_api_h.h>
38 /* instantiate all the print functions we know about */
39 #define vl_print(handle, ...)
41 #include <http_static/http_static_all_api_h.h>
44 /* Get the API version number. */
45 #define vl_api_version(n,v) static u32 api_version=(v);
46 #include <http_static/http_static_all_api_h.h>
52 /* API message ID base */
55 } http_static_test_main_t;
57 http_static_test_main_t http_static_test_main;
59 #define __plugin_msg_base http_static_test_main.msg_id_base
60 #include <vlibapi/vat_helper_macros.h>
62 #define foreach_standard_reply_retval_handler \
63 _(http_static_enable_reply)
66 static void vl_api_##n##_t_handler \
67 (vl_api_##n##_t * mp) \
69 vat_main_t * vam = http_static_test_main.vat_main; \
70 i32 retval = ntohl(mp->retval); \
71 if (vam->async_mode) { \
72 vam->async_errors += (retval < 0); \
74 vam->retval = retval; \
75 vam->result_ready = 1; \
78 foreach_standard_reply_retval_handler;
82 * Table of message reply handlers, must include boilerplate handlers
85 #define foreach_vpe_api_reply_msg \
86 _(HTTP_STATIC_ENABLE_REPLY, http_static_enable_reply)
90 api_http_static_enable (vat_main_t * vam)
92 unformat_input_t *line_input = vam->input;
93 vl_api_http_static_enable_t *mp;
97 u32 prealloc_fifos = 0;
98 u32 private_segment_size = 0;
99 u32 fifo_size = 8 << 10;
100 u32 cache_size_limit = 1 << 20;
103 /* Parse args required to build the message */
104 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
106 if (unformat (line_input, "www-root %s", &www_root))
108 else if (unformat (line_input, "prealloc-fifos %d", &prealloc_fifos))
110 else if (unformat (line_input, "private-segment-size %U",
111 unformat_memory_size, &tmp))
113 if (tmp >= 0x100000000ULL)
115 errmsg ("private segment size %llu, too large", tmp);
118 private_segment_size = (u32) tmp;
120 else if (unformat (line_input, "fifo-size %U", unformat_memory_size,
123 fifo_size = (u32) tmp;
125 else if (unformat (line_input, "cache-size %U", unformat_memory_size,
128 if (tmp < (128ULL << 10))
130 errmsg ("cache-size must be at least 128kb");
133 cache_size_limit = (u32) tmp;
136 else if (unformat (line_input, "uri %s", &uri))
140 errmsg ("unknown input `%U'", format_unformat_error, line_input);
147 errmsg ("Must specify www-root");
152 uri = format (0, "tcp://0.0.0.0/80%c", 0);
156 /* Construct the API message */
157 M (HTTP_STATIC_ENABLE, mp);
158 vl_api_to_api_string (strnlen ((const char *) www_root, 256),
159 (const char *) www_root,
160 (vl_api_string_t *) & mp->www_root);
161 vl_api_to_api_string (strnlen ((const char *) uri, 256), (const char *) uri,
162 (vl_api_string_t *) & mp->uri);
163 mp->fifo_size = ntohl (fifo_size);
164 mp->cache_size_limit = ntohl (cache_size_limit);
165 mp->prealloc_fifos = ntohl (prealloc_fifos);
166 mp->private_segment_size = ntohl (private_segment_size);
171 /* Wait for a reply... */
177 * List of messages that the api test plugin sends,
178 * and that the data plane plugin processes
180 #define foreach_vpe_api_msg \
181 _(http_static_enable, "www-root <path> [prealloc-fios <nn>]\n" \
182 "[private-segment-size <nnMG>] [fifo-size <nbytes>] [uri <uri>]\n")
185 http_static_api_hookup (vat_main_t * vam)
187 http_static_test_main_t *htmp = &http_static_test_main;
188 /* Hook up handlers for replies from the data plane plug-in */
190 vl_msg_api_set_handlers((VL_API_##N + htmp->msg_id_base), \
192 vl_api_##n##_t_handler, \
194 vl_api_##n##_t_endian, \
195 vl_api_##n##_t_print, \
196 sizeof(vl_api_##n##_t), 1);
197 foreach_vpe_api_reply_msg;
200 /* API messages we can send */
201 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
206 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
211 VAT_PLUGIN_REGISTER (http_static);
214 * fd.io coding-style-patch-verification: ON
217 * eval: (c-set-style "gnu")