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 clib_strncpy ((char *) mp->www_root, (char *) www_root,
159 ARRAY_LEN (mp->www_root) - 1);
160 clib_strncpy ((char *) mp->uri, (char *) uri, ARRAY_LEN (mp->uri) - 1);
161 mp->fifo_size = ntohl (fifo_size);
162 mp->cache_size_limit = ntohl (cache_size_limit);
163 mp->prealloc_fifos = ntohl (prealloc_fifos);
164 mp->private_segment_size = ntohl (private_segment_size);
169 /* Wait for a reply... */
175 * List of messages that the api test plugin sends,
176 * and that the data plane plugin processes
178 #define foreach_vpe_api_msg \
179 _(http_static_enable, "www-root <path> [prealloc-fios <nn>]\n" \
180 "[private-segment-size <nnMG>] [fifo-size <nbytes>] [uri <uri>]\n")
183 http_static_api_hookup (vat_main_t * vam)
185 http_static_test_main_t *htmp = &http_static_test_main;
186 /* Hook up handlers for replies from the data plane plug-in */
188 vl_msg_api_set_handlers((VL_API_##N + htmp->msg_id_base), \
190 vl_api_##n##_t_handler, \
192 vl_api_##n##_t_endian, \
193 vl_api_##n##_t_print, \
194 sizeof(vl_api_##n##_t), 1);
195 foreach_vpe_api_reply_msg;
198 /* API messages we can send */
199 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
204 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
210 vat_plugin_register (vat_main_t * vam)
212 http_static_test_main_t *htmp = &http_static_test_main;
215 htmp->vat_main = vam;
217 /* Ask the vpp engine for the first assigned message-id */
218 name = format (0, "http_static_%08x%c", api_version, 0);
219 htmp->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
221 if (htmp->msg_id_base != (u16) ~ 0)
222 http_static_api_hookup (vam);
230 * fd.io coding-style-patch-verification: ON
233 * eval: (c-set-style "gnu")