blob: 8e958ac0b450cdb4a379285d83e8cc89f5d430b0 [file] [log] [blame]
Florin Corase04c2992017-03-01 08:17:34 -08001/*
2* Copyright (c) 2015-2017 Cisco and/or its affiliates.
3* Licensed under the Apache License, Version 2.0 (the "License");
4* you may not use this file except in compliance with the License.
5* You may obtain a copy of the License at:
6*
7* http://www.apache.org/licenses/LICENSE-2.0
8*
9* Unless required by applicable law or agreed to in writing, software
10* distributed under the License is distributed on an "AS IS" BASIS,
11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12* See the License for the specific language governing permissions and
13* limitations under the License.
14*/
15
16#include <vnet/vnet.h>
17#include <vlibmemory/api.h>
18#include <vnet/session/application.h>
19#include <vnet/session/application_interface.h>
20
Florin Coras6cf30ad2017-04-04 23:08:23 -070021/* define message IDs */
22#include <vpp/api/vpe_msg_enum.h>
23
24/* define message structures */
25#define vl_typedefs
26#include <vpp/api/vpe_all_api_h.h>
27#undef vl_typedefs
28
29/* define generated endian-swappers */
30#define vl_endianfun
31#include <vpp/api/vpe_all_api_h.h>
32#undef vl_endianfun
33
34/* instantiate all the print functions we know about */
35#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
36#define vl_printfun
37#include <vpp/api/vpe_all_api_h.h>
38#undef vl_printfun
39
Florin Corasd79b41e2017-03-04 05:37:52 -080040typedef struct
41{
Florin Corasf03a59a2017-06-09 21:07:32 -070042 /*
43 * Server app parameters
44 */
Florin Corasd79b41e2017-03-04 05:37:52 -080045 unix_shared_memory_queue_t **vpp_queue;
Florin Corasf03a59a2017-06-09 21:07:32 -070046 unix_shared_memory_queue_t *vl_input_queue; /**< Sever's event queue */
47
48 u32 app_index; /**< Server app index */
49 u32 my_client_index; /**< API client handle */
50 u32 node_index; /**< process node index for evnt scheduling */
51
52 /*
53 * Config params
54 */
55 u8 no_echo; /**< Don't echo traffic */
56 u32 fifo_size; /**< Fifo size */
57 u32 rcv_buffer_size; /**< Rcv buffer size */
58 u32 prealloc_fifos; /**< Preallocate fifos */
Dave Barach2c25a622017-06-26 11:35:07 -040059 u32 private_segment_count; /**< Number of private segments */
60 u32 private_segment_size; /**< Size of private segments */
Florin Corasf03a59a2017-06-09 21:07:32 -070061
62 /*
63 * Test state
64 */
65 u8 **rx_buf; /**< Per-thread RX buffer */
Florin Coras6cf30ad2017-04-04 23:08:23 -070066 u64 byte_index;
Dave Barach2c25a622017-06-26 11:35:07 -040067 u32 **rx_retries;
Florin Coras6cf30ad2017-04-04 23:08:23 -070068
Florin Corasd79b41e2017-03-04 05:37:52 -080069 vlib_main_t *vlib_main;
70} builtin_server_main_t;
71
72builtin_server_main_t builtin_server_main;
73
Florin Corase04c2992017-03-01 08:17:34 -080074int
75builtin_session_accept_callback (stream_session_t * s)
76{
Florin Corasd79b41e2017-03-04 05:37:52 -080077 builtin_server_main_t *bsm = &builtin_server_main;
Florin Corasd79b41e2017-03-04 05:37:52 -080078
79 bsm->vpp_queue[s->thread_index] =
80 session_manager_get_vpp_event_queue (s->thread_index);
Florin Corase04c2992017-03-01 08:17:34 -080081 s->session_state = SESSION_STATE_READY;
Florin Coras6792ec02017-03-13 03:49:51 -070082 bsm->byte_index = 0;
Dave Barach2c25a622017-06-26 11:35:07 -040083 vec_validate (bsm->rx_retries[s->thread_index], s->session_index);
84 bsm->rx_retries[s->thread_index][s->session_index] = 0;
Florin Corase04c2992017-03-01 08:17:34 -080085 return 0;
86}
87
88void
89builtin_session_disconnect_callback (stream_session_t * s)
90{
Florin Coras6cf30ad2017-04-04 23:08:23 -070091 builtin_server_main_t *bsm = &builtin_server_main;
92 vnet_disconnect_args_t _a, *a = &_a;
Florin Corasd79b41e2017-03-04 05:37:52 -080093
Florin Coras6cf30ad2017-04-04 23:08:23 -070094 a->handle = stream_session_handle (s);
95 a->app_index = bsm->app_index;
96 vnet_disconnect_session (a);
Florin Corase04c2992017-03-01 08:17:34 -080097}
98
Florin Corasd79b41e2017-03-04 05:37:52 -080099void
100builtin_session_reset_callback (stream_session_t * s)
101{
102 clib_warning ("called.. ");
103
104 stream_session_cleanup (s);
105}
106
107
Florin Corase04c2992017-03-01 08:17:34 -0800108int
Florin Coras6cf30ad2017-04-04 23:08:23 -0700109builtin_session_connected_callback (u32 app_index, u32 api_context,
Florin Corase04c2992017-03-01 08:17:34 -0800110 stream_session_t * s, u8 is_fail)
111{
112 clib_warning ("called...");
113 return -1;
114}
115
116int
117builtin_add_segment_callback (u32 client_index,
118 const u8 * seg_name, u32 seg_size)
119{
120 clib_warning ("called...");
121 return -1;
122}
123
124int
125builtin_redirect_connect_callback (u32 client_index, void *mp)
126{
127 clib_warning ("called...");
128 return -1;
129}
130
Florin Coras6792ec02017-03-13 03:49:51 -0700131void
132test_bytes (builtin_server_main_t * bsm, int actual_transfer)
Florin Corase04c2992017-03-01 08:17:34 -0800133{
Florin Coras6792ec02017-03-13 03:49:51 -0700134 int i;
Florin Coras93992a92017-05-24 18:03:56 -0700135 u32 my_thread_id = vlib_get_thread_index ();
Florin Coras6792ec02017-03-13 03:49:51 -0700136
137 for (i = 0; i < actual_transfer; i++)
138 {
Florin Coras93992a92017-05-24 18:03:56 -0700139 if (bsm->rx_buf[my_thread_id][i] != ((bsm->byte_index + i) & 0xff))
Florin Coras6792ec02017-03-13 03:49:51 -0700140 {
Florin Coras6cf30ad2017-04-04 23:08:23 -0700141 clib_warning ("at %lld expected %d got %d", bsm->byte_index + i,
Florin Coras93992a92017-05-24 18:03:56 -0700142 (bsm->byte_index + i) & 0xff,
143 bsm->rx_buf[my_thread_id][i]);
Florin Coras6792ec02017-03-13 03:49:51 -0700144 }
145 }
146 bsm->byte_index += actual_transfer;
147}
148
Florin Corasf03a59a2017-06-09 21:07:32 -0700149/*
150 * If no-echo, just read the data and be done with it
151 */
152int
153builtin_server_rx_callback_no_echo (stream_session_t * s)
154{
155 builtin_server_main_t *bsm = &builtin_server_main;
156 u32 my_thread_id = vlib_get_thread_index ();
157 int actual_transfer;
158 svm_fifo_t *rx_fifo;
159
160 rx_fifo = s->server_rx_fifo;
161
162 do
163 {
164 actual_transfer =
165 svm_fifo_dequeue_nowait (rx_fifo, bsm->rcv_buffer_size,
166 bsm->rx_buf[my_thread_id]);
167 }
168 while (actual_transfer > 0);
169 return 0;
170}
171
Florin Coras6792ec02017-03-13 03:49:51 -0700172int
173builtin_server_rx_callback (stream_session_t * s)
174{
175 u32 n_written, max_dequeue, max_enqueue, max_transfer;
176 int actual_transfer;
177 svm_fifo_t *tx_fifo, *rx_fifo;
Florin Corasd79b41e2017-03-04 05:37:52 -0800178 builtin_server_main_t *bsm = &builtin_server_main;
179 session_fifo_event_t evt;
180 static int serial_number = 0;
Dave Barach2c25a622017-06-26 11:35:07 -0400181 u32 thread_index = vlib_get_thread_index ();
182
183 ASSERT (s->thread_index == thread_index);
Florin Corasd79b41e2017-03-04 05:37:52 -0800184
Dave Barachacd2a6a2017-05-16 17:41:34 -0400185 rx_fifo = s->server_rx_fifo;
Florin Corasf03a59a2017-06-09 21:07:32 -0700186 tx_fifo = s->server_tx_fifo;
Dave Barachacd2a6a2017-05-16 17:41:34 -0400187
Dave Barach2c25a622017-06-26 11:35:07 -0400188 ASSERT (rx_fifo->master_thread_index == thread_index);
189 ASSERT (tx_fifo->master_thread_index == thread_index);
190
Florin Coras6792ec02017-03-13 03:49:51 -0700191 max_dequeue = svm_fifo_max_dequeue (s->server_rx_fifo);
192 max_enqueue = svm_fifo_max_enqueue (s->server_tx_fifo);
193
194 if (PREDICT_FALSE (max_dequeue == 0))
Dave Barachacd2a6a2017-05-16 17:41:34 -0400195 return 0;
Florin Corasd79b41e2017-03-04 05:37:52 -0800196
197 /* Number of bytes we're going to copy */
Florin Coras6792ec02017-03-13 03:49:51 -0700198 max_transfer = (max_dequeue < max_enqueue) ? max_dequeue : max_enqueue;
Florin Corasd79b41e2017-03-04 05:37:52 -0800199
Florin Coras6792ec02017-03-13 03:49:51 -0700200 /* No space in tx fifo */
201 if (PREDICT_FALSE (max_transfer == 0))
Florin Corasd79b41e2017-03-04 05:37:52 -0800202 {
Florin Coras6792ec02017-03-13 03:49:51 -0700203 /* XXX timeout for session that are stuck */
204
Florin Coras3e350af2017-03-30 02:54:28 -0700205 rx_event:
Florin Coras6792ec02017-03-13 03:49:51 -0700206 /* Program self-tap to retry */
207 if (svm_fifo_set_event (rx_fifo))
208 {
Florin Corasf03a59a2017-06-09 21:07:32 -0700209 unix_shared_memory_queue_t *q;
Florin Coras6792ec02017-03-13 03:49:51 -0700210 evt.fifo = rx_fifo;
211 evt.event_type = FIFO_EVENT_BUILTIN_RX;
212 evt.event_id = 0;
Florin Corasf03a59a2017-06-09 21:07:32 -0700213
Dave Barach2c25a622017-06-26 11:35:07 -0400214 q = bsm->vpp_queue[thread_index];
Florin Corasf03a59a2017-06-09 21:07:32 -0700215 if (PREDICT_FALSE (q->cursize == q->maxsize))
216 clib_warning ("out of event queue space");
Dave Barach2c25a622017-06-26 11:35:07 -0400217 else if (unix_shared_memory_queue_add (q, (u8 *) & evt, 0 /* don't wait for mutex */
218 ))
219 clib_warning ("failed to enqueue self-tap");
220
221 bsm->rx_retries[thread_index][s->session_index]++;
222 if (bsm->rx_retries[thread_index][s->session_index] == 500000)
223 {
224 clib_warning ("session stuck: %U", format_stream_session, s, 2);
225 }
226 }
227 else
228 {
229 bsm->rx_retries[thread_index][s->session_index] = 0;
Florin Coras6792ec02017-03-13 03:49:51 -0700230 }
231
Florin Corasd79b41e2017-03-04 05:37:52 -0800232 return 0;
233 }
234
Dave Barach2c25a622017-06-26 11:35:07 -0400235 _vec_len (bsm->rx_buf[thread_index]) = max_transfer;
Florin Coras6792ec02017-03-13 03:49:51 -0700236
Florin Corasa5464812017-04-19 13:00:05 -0700237 actual_transfer = svm_fifo_dequeue_nowait (rx_fifo, max_transfer,
Dave Barach2c25a622017-06-26 11:35:07 -0400238 bsm->rx_buf[thread_index]);
Florin Coras6792ec02017-03-13 03:49:51 -0700239 ASSERT (actual_transfer == max_transfer);
240
241// test_bytes (bsm, actual_transfer);
Florin Corasd79b41e2017-03-04 05:37:52 -0800242
243 /*
244 * Echo back
245 */
246
Florin Coras93992a92017-05-24 18:03:56 -0700247 n_written = svm_fifo_enqueue_nowait (tx_fifo, actual_transfer,
Dave Barach2c25a622017-06-26 11:35:07 -0400248 bsm->rx_buf[thread_index]);
Florin Coras3e350af2017-03-30 02:54:28 -0700249
250 if (n_written != max_transfer)
251 clib_warning ("short trout!");
Florin Corasd79b41e2017-03-04 05:37:52 -0800252
Florin Coras6792ec02017-03-13 03:49:51 -0700253 if (svm_fifo_set_event (tx_fifo))
254 {
255 /* Fabricate TX event, send to vpp */
256 evt.fifo = tx_fifo;
Florin Corasa5464812017-04-19 13:00:05 -0700257 evt.event_type = FIFO_EVENT_APP_TX;
Florin Coras6792ec02017-03-13 03:49:51 -0700258 evt.event_id = serial_number++;
Florin Corasd79b41e2017-03-04 05:37:52 -0800259
Dave Barach2c25a622017-06-26 11:35:07 -0400260 if (unix_shared_memory_queue_add (bsm->vpp_queue[s->thread_index],
261 (u8 *) & evt,
262 0 /* do wait for mutex */ ))
263 clib_warning ("failed to enqueue tx evt");
Florin Coras6792ec02017-03-13 03:49:51 -0700264 }
Florin Corasd79b41e2017-03-04 05:37:52 -0800265
Dave Barach2c25a622017-06-26 11:35:07 -0400266 if (PREDICT_FALSE (n_written < max_dequeue))
Florin Coras3e350af2017-03-30 02:54:28 -0700267 goto rx_event;
268
Florin Corase04c2992017-03-01 08:17:34 -0800269 return 0;
270}
271
272static session_cb_vft_t builtin_session_cb_vft = {
273 .session_accept_callback = builtin_session_accept_callback,
274 .session_disconnect_callback = builtin_session_disconnect_callback,
275 .session_connected_callback = builtin_session_connected_callback,
276 .add_segment_callback = builtin_add_segment_callback,
277 .redirect_connect_callback = builtin_redirect_connect_callback,
Florin Corasd79b41e2017-03-04 05:37:52 -0800278 .builtin_server_rx_callback = builtin_server_rx_callback,
279 .session_reset_callback = builtin_session_reset_callback
Florin Corase04c2992017-03-01 08:17:34 -0800280};
281
Florin Coras6cf30ad2017-04-04 23:08:23 -0700282/* Abuse VPP's input queue */
Florin Corase04c2992017-03-01 08:17:34 -0800283static int
Florin Coras6cf30ad2017-04-04 23:08:23 -0700284create_api_loopback (vlib_main_t * vm)
Florin Corase04c2992017-03-01 08:17:34 -0800285{
Florin Coras6cf30ad2017-04-04 23:08:23 -0700286 builtin_server_main_t *bsm = &builtin_server_main;
287 vl_api_memclnt_create_t _m, *mp = &_m;
288 extern void vl_api_memclnt_create_t_handler (vl_api_memclnt_create_t *);
289 api_main_t *am = &api_main;
290 vl_shmem_hdr_t *shmem_hdr;
291 uword *event_data = 0, event_type;
292 int resolved = 0;
Florin Corasd79b41e2017-03-04 05:37:52 -0800293
Florin Coras6cf30ad2017-04-04 23:08:23 -0700294 /*
295 * Create a "loopback" API client connection
296 * Don't do things like this unless you know what you're doing...
297 */
298
299 shmem_hdr = am->shmem_hdr;
300 bsm->vl_input_queue = shmem_hdr->vl_input_queue;
301 memset (mp, 0, sizeof (*mp));
302 mp->_vl_msg_id = VL_API_MEMCLNT_CREATE;
303 mp->context = 0xFEEDFACE;
Damjan Marion7bee80c2017-04-26 15:32:12 +0200304 mp->input_queue = pointer_to_uword (bsm->vl_input_queue);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700305 strncpy ((char *) mp->name, "tcp_test_server", sizeof (mp->name) - 1);
306
307 vl_api_memclnt_create_t_handler (mp);
308
309 /* Wait for reply */
310 bsm->node_index = vlib_get_current_process (vm)->node_runtime.node_index;
311 vlib_process_wait_for_event_or_clock (vm, 1.0);
312 event_type = vlib_process_get_events (vm, &event_data);
313 switch (event_type)
314 {
315 case 1:
316 resolved = 1;
317 break;
318 case ~0:
319 /* timed out */
320 break;
321 default:
322 clib_warning ("unknown event_type %d", event_type);
323 }
324 if (!resolved)
325 return -1;
326
327 return 0;
328}
329
330static int
331server_attach ()
332{
333 builtin_server_main_t *bsm = &builtin_server_main;
334 u8 segment_name[128];
335 u64 options[SESSION_OPTIONS_N_OPTIONS];
336 vnet_app_attach_args_t _a, *a = &_a;
Florin Corase04c2992017-03-01 08:17:34 -0800337
338 memset (a, 0, sizeof (*a));
339 memset (options, 0, sizeof (options));
340
Florin Corasf03a59a2017-06-09 21:07:32 -0700341 if (bsm->no_echo)
342 builtin_session_cb_vft.builtin_server_rx_callback =
343 builtin_server_rx_callback_no_echo;
344 else
345 builtin_session_cb_vft.builtin_server_rx_callback =
346 builtin_server_rx_callback;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700347 a->api_client_index = bsm->my_client_index;
Florin Corase04c2992017-03-01 08:17:34 -0800348 a->session_cb_vft = &builtin_session_cb_vft;
349 a->options = options;
Dave Barach10d8cc62017-05-30 09:30:07 -0400350 a->options[SESSION_OPTIONS_SEGMENT_SIZE] = 512 << 20;
Florin Corasf03a59a2017-06-09 21:07:32 -0700351 a->options[SESSION_OPTIONS_RX_FIFO_SIZE] = bsm->fifo_size;
352 a->options[SESSION_OPTIONS_TX_FIFO_SIZE] = bsm->fifo_size;
Dave Barach2c25a622017-06-26 11:35:07 -0400353 a->options[APP_OPTIONS_PRIVATE_SEGMENT_COUNT] = bsm->private_segment_count;
354 a->options[APP_OPTIONS_PRIVATE_SEGMENT_SIZE] = bsm->private_segment_size;
Florin Corasf03a59a2017-06-09 21:07:32 -0700355 a->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] =
356 bsm->prealloc_fifos ? bsm->prealloc_fifos : 1;
Dave Barach2c25a622017-06-26 11:35:07 -0400357
358 a->options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_BUILTIN_APP;
359
Florin Corase04c2992017-03-01 08:17:34 -0800360 a->segment_name = segment_name;
361 a->segment_name_length = ARRAY_LEN (segment_name);
362
Florin Coras6cf30ad2017-04-04 23:08:23 -0700363 if (vnet_application_attach (a))
364 {
365 clib_warning ("failed to attach server");
366 return -1;
367 }
368 bsm->app_index = a->app_index;
369 return 0;
370}
371
372static int
373server_listen ()
374{
375 builtin_server_main_t *bsm = &builtin_server_main;
376 vnet_bind_args_t _a, *a = &_a;
377 memset (a, 0, sizeof (*a));
378 a->app_index = bsm->app_index;
379 a->uri = "tcp://0.0.0.0/1234";
Florin Corase04c2992017-03-01 08:17:34 -0800380 return vnet_bind_uri (a);
381}
382
Florin Coras6cf30ad2017-04-04 23:08:23 -0700383static int
384server_create (vlib_main_t * vm)
385{
386 builtin_server_main_t *bsm = &builtin_server_main;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700387 vlib_thread_main_t *vtm = vlib_get_thread_main ();
Florin Corasf03a59a2017-06-09 21:07:32 -0700388 u32 num_threads;
389 int i;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700390
391 if (bsm->my_client_index == (u32) ~ 0)
392 {
393 if (create_api_loopback (vm))
Florin Corasf03a59a2017-06-09 21:07:32 -0700394 {
395 clib_warning ("failed to create api loopback");
396 return -1;
397 }
Florin Coras6cf30ad2017-04-04 23:08:23 -0700398 }
399
400 num_threads = 1 /* main thread */ + vtm->n_threads;
401 vec_validate (builtin_server_main.vpp_queue, num_threads - 1);
Florin Corasf03a59a2017-06-09 21:07:32 -0700402 vec_validate (bsm->rx_buf, num_threads - 1);
Dave Barach2c25a622017-06-26 11:35:07 -0400403 vec_validate (bsm->rx_retries, num_threads - 1);
404
Florin Corasf03a59a2017-06-09 21:07:32 -0700405 for (i = 0; i < num_threads; i++)
406 vec_validate (bsm->rx_buf[i], bsm->rcv_buffer_size);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700407
408 if (server_attach ())
409 {
410 clib_warning ("failed to attach server");
411 return -1;
412 }
413 if (server_listen ())
414 {
415 clib_warning ("failed to start listening");
416 return -1;
417 }
418 return 0;
419}
420
421/* Get our api client index */
422static void
423vl_api_memclnt_create_reply_t_handler (vl_api_memclnt_create_reply_t * mp)
424{
425 vlib_main_t *vm = vlib_get_main ();
426 builtin_server_main_t *bsm = &builtin_server_main;
427 bsm->my_client_index = mp->index;
428 vlib_process_signal_event (vm, bsm->node_index, 1 /* evt */ ,
429 0 /* data */ );
430}
431
432#define foreach_tcp_builtin_server_api_msg \
433_(MEMCLNT_CREATE_REPLY, memclnt_create_reply) \
434
435static clib_error_t *
436tcp_builtin_server_api_hookup (vlib_main_t * vm)
437{
438 vl_msg_api_msg_config_t _c, *c = &_c;
439
440 /* Hook up client-side static APIs to our handlers */
441#define _(N,n) do { \
442 c->id = VL_API_##N; \
443 c->name = #n; \
444 c->handler = vl_api_##n##_t_handler; \
445 c->cleanup = vl_noop_handler; \
446 c->endian = vl_api_##n##_t_endian; \
447 c->print = vl_api_##n##_t_print; \
448 c->size = sizeof(vl_api_##n##_t); \
449 c->traced = 1; /* trace, so these msgs print */ \
450 c->replay = 0; /* don't replay client create/delete msgs */ \
451 c->message_bounce = 0; /* don't bounce this message */ \
452 vl_msg_api_config(c);} while (0);
453
454 foreach_tcp_builtin_server_api_msg;
455#undef _
456
457 return 0;
458}
459
Florin Corase04c2992017-03-01 08:17:34 -0800460static clib_error_t *
Florin Corasf03a59a2017-06-09 21:07:32 -0700461server_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
462 vlib_cli_command_t * cmd)
Florin Corase04c2992017-03-01 08:17:34 -0800463{
Florin Corasf03a59a2017-06-09 21:07:32 -0700464 builtin_server_main_t *bsm = &builtin_server_main;
Florin Corase04c2992017-03-01 08:17:34 -0800465 int rv;
Dave Barach2c25a622017-06-26 11:35:07 -0400466 u32 tmp;
Florin Corasf03a59a2017-06-09 21:07:32 -0700467
468 bsm->no_echo = 0;
469 bsm->fifo_size = 64 << 10;
470 bsm->rcv_buffer_size = 128 << 10;
471 bsm->prealloc_fifos = 0;
Dave Barach2c25a622017-06-26 11:35:07 -0400472 bsm->private_segment_count = 0;
473 bsm->private_segment_size = 0;
Florin Corasf03a59a2017-06-09 21:07:32 -0700474
Florin Corase04c2992017-03-01 08:17:34 -0800475 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
476 {
Florin Corasf03a59a2017-06-09 21:07:32 -0700477 if (unformat (input, "no-echo"))
478 bsm->no_echo = 1;
479 else if (unformat (input, "fifo-size %d", &bsm->fifo_size))
480 bsm->fifo_size <<= 10;
481 else if (unformat (input, "rcv-buf-size %d", &bsm->rcv_buffer_size))
482 ;
Dave Barach2c25a622017-06-26 11:35:07 -0400483 else if (unformat (input, "prealloc-fifos %d", &bsm->prealloc_fifos))
Florin Corase04c2992017-03-01 08:17:34 -0800484 ;
Dave Barach2c25a622017-06-26 11:35:07 -0400485 else if (unformat (input, "private-segment-count %d",
486 &bsm->private_segment_count))
487 ;
488 else if (unformat (input, "private-segment-size %dm", &tmp))
489 bsm->private_segment_size = tmp << 20;
490 else if (unformat (input, "private-segment-size %dg", &tmp))
491 bsm->private_segment_size = tmp << 30;
492 else if (unformat (input, "private-segment-size %d", &tmp))
493 bsm->private_segment_size = tmp;
Florin Corase04c2992017-03-01 08:17:34 -0800494 else
495 return clib_error_return (0, "unknown input `%U'",
496 format_unformat_error, input);
497 }
Florin Corase04c2992017-03-01 08:17:34 -0800498
Florin Coras6cf30ad2017-04-04 23:08:23 -0700499 tcp_builtin_server_api_hookup (vm);
Florin Corasd79b41e2017-03-04 05:37:52 -0800500 vnet_session_enable_disable (vm, 1 /* turn on TCP, etc. */ );
Florin Corasf03a59a2017-06-09 21:07:32 -0700501
Florin Corase04c2992017-03-01 08:17:34 -0800502 rv = server_create (vm);
503 switch (rv)
504 {
505 case 0:
506 break;
507 default:
508 return clib_error_return (0, "server_create returned %d", rv);
509 }
Florin Corasf03a59a2017-06-09 21:07:32 -0700510
Florin Corase04c2992017-03-01 08:17:34 -0800511 return 0;
512}
513
Florin Corasd79b41e2017-03-04 05:37:52 -0800514/* *INDENT-OFF* */
Florin Corase04c2992017-03-01 08:17:34 -0800515VLIB_CLI_COMMAND (server_create_command, static) =
516{
Florin Coras6cf30ad2017-04-04 23:08:23 -0700517 .path = "test tcp server",
518 .short_help = "test tcp server",
Florin Corasd79b41e2017-03-04 05:37:52 -0800519 .function = server_create_command_fn,
520};
521/* *INDENT-ON* */
Florin Corase04c2992017-03-01 08:17:34 -0800522
Florin Coras6cf30ad2017-04-04 23:08:23 -0700523clib_error_t *
524builtin_tcp_server_main_init (vlib_main_t * vm)
525{
526 builtin_server_main_t *bsm = &builtin_server_main;
527 bsm->my_client_index = ~0;
528 return 0;
529}
530
531VLIB_INIT_FUNCTION (builtin_tcp_server_main_init);
532
Florin Corase04c2992017-03-01 08:17:34 -0800533/*
534* fd.io coding-style-patch-verification: ON
535*
536* Local Variables:
537* eval: (c-set-style "gnu")
538* End:
539*/