hs-test: logging improvements
[vpp.git] / src / plugins / http_static / http_static_test.c
1 /*
2  * http_static.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
22 uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
23
24 /* Declare message IDs */
25 #include <http_static/http_static.api_enum.h>
26 #include <http_static/http_static.api_types.h>
27
28 typedef struct
29 {
30   /* API message ID base */
31   u16 msg_id_base;
32   vat_main_t *vat_main;
33 } http_static_test_main_t;
34
35 http_static_test_main_t http_static_test_main;
36
37 #define __plugin_msg_base http_static_test_main.msg_id_base
38 #include <vlibapi/vat_helper_macros.h>
39
40 static int
41 api_http_static_enable (vat_main_t * vam)
42 {
43   unformat_input_t *line_input = vam->input;
44   vl_api_http_static_enable_t *mp;
45   u64 tmp;
46   u8 *www_root = 0;
47   u8 *uri = 0;
48   u32 prealloc_fifos = 0;
49   u32 private_segment_size = 0;
50   u32 fifo_size = 8 << 10;
51   u32 cache_size_limit = 1 << 20;
52   int ret;
53
54   /* Parse args required to build the message */
55   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
56     {
57       if (unformat (line_input, "www-root %s", &www_root))
58         ;
59       else if (unformat (line_input, "prealloc-fifos %d", &prealloc_fifos))
60         ;
61       else if (unformat (line_input, "private-segment-size %U",
62                          unformat_memory_size, &tmp))
63         {
64           if (tmp >= 0x100000000ULL)
65             {
66               errmsg ("private segment size %llu, too large", tmp);
67               return -99;
68             }
69           private_segment_size = (u32) tmp;
70         }
71       else if (unformat (line_input, "fifo-size %U", unformat_memory_size,
72                          &tmp))
73         {
74           if (tmp >= 0x100000000ULL)
75             {
76               errmsg ("fifo-size %llu, too large", tmp);
77               return -99;
78             }
79           fifo_size = (u32) tmp;
80         }
81       else if (unformat (line_input, "cache-size %U", unformat_memory_size,
82                          &tmp))
83         {
84           if (tmp < (128ULL << 10))
85             {
86               errmsg ("cache-size must be at least 128kb");
87               return -99;
88             }
89           cache_size_limit = (u32) tmp;
90         }
91
92       else if (unformat (line_input, "uri %s", &uri))
93         ;
94       else
95         {
96           errmsg ("unknown input `%U'", format_unformat_error, line_input);
97           return -99;
98         }
99     }
100
101   if (www_root == 0)
102     {
103       errmsg ("Must specify www-root");
104       return -99;
105     }
106
107   if (uri == 0)
108     uri = format (0, "tcp://0.0.0.0/80%c", 0);
109
110
111
112   /* Construct the API message */
113   M (HTTP_STATIC_ENABLE, mp);
114   strncpy_s ((char *) mp->www_root, 256, (const char *) www_root, 256);
115   strncpy_s ((char *) mp->uri, 256, (const char *) uri, 256);
116   mp->fifo_size = ntohl (fifo_size);
117   mp->cache_size_limit = ntohl (cache_size_limit);
118   mp->prealloc_fifos = ntohl (prealloc_fifos);
119   mp->private_segment_size = ntohl (private_segment_size);
120
121   /* send it... */
122   S (mp);
123
124   /* Wait for a reply... */
125   W (ret);
126   return ret;
127 }
128
129 #include <http_static/http_static.api_test.c>
130
131 /*
132  * fd.io coding-style-patch-verification: ON
133  *
134  * Local Variables:
135  * eval: (c-set-style "gnu")
136  * End:
137  */