blob: 4ecaf56a70cf20c9e606678f551551dbdac638b3 [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{
Florin Coras3eb50622017-07-13 01:24:57 -0400102 clib_warning ("Reset session %U", format_stream_session, s, 2);
Florin Corasd79b41e2017-03-04 05:37:52 -0800103 stream_session_cleanup (s);
104}
105
106
Florin Corase04c2992017-03-01 08:17:34 -0800107int
Florin Coras6cf30ad2017-04-04 23:08:23 -0700108builtin_session_connected_callback (u32 app_index, u32 api_context,
Florin Corase04c2992017-03-01 08:17:34 -0800109 stream_session_t * s, u8 is_fail)
110{
111 clib_warning ("called...");
112 return -1;
113}
114
115int
116builtin_add_segment_callback (u32 client_index,
117 const u8 * seg_name, u32 seg_size)
118{
119 clib_warning ("called...");
120 return -1;
121}
122
123int
124builtin_redirect_connect_callback (u32 client_index, void *mp)
125{
126 clib_warning ("called...");
127 return -1;
128}
129
Florin Coras6792ec02017-03-13 03:49:51 -0700130void
131test_bytes (builtin_server_main_t * bsm, int actual_transfer)
Florin Corase04c2992017-03-01 08:17:34 -0800132{
Florin Coras6792ec02017-03-13 03:49:51 -0700133 int i;
Florin Coras93992a92017-05-24 18:03:56 -0700134 u32 my_thread_id = vlib_get_thread_index ();
Florin Coras6792ec02017-03-13 03:49:51 -0700135
136 for (i = 0; i < actual_transfer; i++)
137 {
Florin Coras93992a92017-05-24 18:03:56 -0700138 if (bsm->rx_buf[my_thread_id][i] != ((bsm->byte_index + i) & 0xff))
Florin Coras6792ec02017-03-13 03:49:51 -0700139 {
Florin Coras6cf30ad2017-04-04 23:08:23 -0700140 clib_warning ("at %lld expected %d got %d", bsm->byte_index + i,
Florin Coras93992a92017-05-24 18:03:56 -0700141 (bsm->byte_index + i) & 0xff,
142 bsm->rx_buf[my_thread_id][i]);
Florin Coras6792ec02017-03-13 03:49:51 -0700143 }
144 }
145 bsm->byte_index += actual_transfer;
146}
147
Florin Corasf03a59a2017-06-09 21:07:32 -0700148/*
149 * If no-echo, just read the data and be done with it
150 */
151int
152builtin_server_rx_callback_no_echo (stream_session_t * s)
153{
154 builtin_server_main_t *bsm = &builtin_server_main;
155 u32 my_thread_id = vlib_get_thread_index ();
156 int actual_transfer;
157 svm_fifo_t *rx_fifo;
158
159 rx_fifo = s->server_rx_fifo;
160
161 do
162 {
163 actual_transfer =
164 svm_fifo_dequeue_nowait (rx_fifo, bsm->rcv_buffer_size,
165 bsm->rx_buf[my_thread_id]);
166 }
167 while (actual_transfer > 0);
168 return 0;
169}
170
Florin Coras6792ec02017-03-13 03:49:51 -0700171int
172builtin_server_rx_callback (stream_session_t * s)
173{
174 u32 n_written, max_dequeue, max_enqueue, max_transfer;
175 int actual_transfer;
176 svm_fifo_t *tx_fifo, *rx_fifo;
Florin Corasd79b41e2017-03-04 05:37:52 -0800177 builtin_server_main_t *bsm = &builtin_server_main;
178 session_fifo_event_t evt;
179 static int serial_number = 0;
Dave Barach2c25a622017-06-26 11:35:07 -0400180 u32 thread_index = vlib_get_thread_index ();
181
182 ASSERT (s->thread_index == thread_index);
Florin Corasd79b41e2017-03-04 05:37:52 -0800183
Dave Barachacd2a6a2017-05-16 17:41:34 -0400184 rx_fifo = s->server_rx_fifo;
Florin Corasf03a59a2017-06-09 21:07:32 -0700185 tx_fifo = s->server_tx_fifo;
Dave Barachacd2a6a2017-05-16 17:41:34 -0400186
Dave Barach2c25a622017-06-26 11:35:07 -0400187 ASSERT (rx_fifo->master_thread_index == thread_index);
188 ASSERT (tx_fifo->master_thread_index == thread_index);
189
Florin Coras6792ec02017-03-13 03:49:51 -0700190 max_dequeue = svm_fifo_max_dequeue (s->server_rx_fifo);
191 max_enqueue = svm_fifo_max_enqueue (s->server_tx_fifo);
192
193 if (PREDICT_FALSE (max_dequeue == 0))
Dave Barachacd2a6a2017-05-16 17:41:34 -0400194 return 0;
Florin Corasd79b41e2017-03-04 05:37:52 -0800195
196 /* Number of bytes we're going to copy */
Florin Coras6792ec02017-03-13 03:49:51 -0700197 max_transfer = (max_dequeue < max_enqueue) ? max_dequeue : max_enqueue;
Florin Corasd79b41e2017-03-04 05:37:52 -0800198
Florin Coras6792ec02017-03-13 03:49:51 -0700199 /* No space in tx fifo */
200 if (PREDICT_FALSE (max_transfer == 0))
Florin Corasd79b41e2017-03-04 05:37:52 -0800201 {
Florin Coras6792ec02017-03-13 03:49:51 -0700202 /* XXX timeout for session that are stuck */
203
Florin Coras3e350af2017-03-30 02:54:28 -0700204 rx_event:
Florin Coras6792ec02017-03-13 03:49:51 -0700205 /* Program self-tap to retry */
206 if (svm_fifo_set_event (rx_fifo))
207 {
Florin Corasf03a59a2017-06-09 21:07:32 -0700208 unix_shared_memory_queue_t *q;
Florin Coras6792ec02017-03-13 03:49:51 -0700209 evt.fifo = rx_fifo;
210 evt.event_type = FIFO_EVENT_BUILTIN_RX;
211 evt.event_id = 0;
Florin Corasf03a59a2017-06-09 21:07:32 -0700212
Dave Barach2c25a622017-06-26 11:35:07 -0400213 q = bsm->vpp_queue[thread_index];
Florin Corasf03a59a2017-06-09 21:07:32 -0700214 if (PREDICT_FALSE (q->cursize == q->maxsize))
215 clib_warning ("out of event queue space");
Dave Barach2c25a622017-06-26 11:35:07 -0400216 else if (unix_shared_memory_queue_add (q, (u8 *) & evt, 0 /* don't wait for mutex */
217 ))
218 clib_warning ("failed to enqueue self-tap");
219
220 bsm->rx_retries[thread_index][s->session_index]++;
221 if (bsm->rx_retries[thread_index][s->session_index] == 500000)
222 {
223 clib_warning ("session stuck: %U", format_stream_session, s, 2);
224 }
225 }
Florin Coras6792ec02017-03-13 03:49:51 -0700226
Florin Corasd79b41e2017-03-04 05:37:52 -0800227 return 0;
228 }
229
Dave Barach2c25a622017-06-26 11:35:07 -0400230 _vec_len (bsm->rx_buf[thread_index]) = max_transfer;
Florin Coras6792ec02017-03-13 03:49:51 -0700231
Florin Corasa5464812017-04-19 13:00:05 -0700232 actual_transfer = svm_fifo_dequeue_nowait (rx_fifo, max_transfer,
Dave Barach2c25a622017-06-26 11:35:07 -0400233 bsm->rx_buf[thread_index]);
Florin Coras6792ec02017-03-13 03:49:51 -0700234 ASSERT (actual_transfer == max_transfer);
235
236// test_bytes (bsm, actual_transfer);
Florin Corasd79b41e2017-03-04 05:37:52 -0800237
238 /*
239 * Echo back
240 */
241
Florin Coras93992a92017-05-24 18:03:56 -0700242 n_written = svm_fifo_enqueue_nowait (tx_fifo, actual_transfer,
Dave Barach2c25a622017-06-26 11:35:07 -0400243 bsm->rx_buf[thread_index]);
Florin Coras3e350af2017-03-30 02:54:28 -0700244
245 if (n_written != max_transfer)
246 clib_warning ("short trout!");
Florin Corasd79b41e2017-03-04 05:37:52 -0800247
Florin Coras6792ec02017-03-13 03:49:51 -0700248 if (svm_fifo_set_event (tx_fifo))
249 {
250 /* Fabricate TX event, send to vpp */
251 evt.fifo = tx_fifo;
Florin Corasa5464812017-04-19 13:00:05 -0700252 evt.event_type = FIFO_EVENT_APP_TX;
Florin Coras6792ec02017-03-13 03:49:51 -0700253 evt.event_id = serial_number++;
Florin Corasd79b41e2017-03-04 05:37:52 -0800254
Dave Barach2c25a622017-06-26 11:35:07 -0400255 if (unix_shared_memory_queue_add (bsm->vpp_queue[s->thread_index],
256 (u8 *) & evt,
257 0 /* do wait for mutex */ ))
258 clib_warning ("failed to enqueue tx evt");
Florin Coras6792ec02017-03-13 03:49:51 -0700259 }
Florin Corasd79b41e2017-03-04 05:37:52 -0800260
Dave Barach2c25a622017-06-26 11:35:07 -0400261 if (PREDICT_FALSE (n_written < max_dequeue))
Florin Coras3e350af2017-03-30 02:54:28 -0700262 goto rx_event;
263
Florin Corase04c2992017-03-01 08:17:34 -0800264 return 0;
265}
266
267static session_cb_vft_t builtin_session_cb_vft = {
268 .session_accept_callback = builtin_session_accept_callback,
269 .session_disconnect_callback = builtin_session_disconnect_callback,
270 .session_connected_callback = builtin_session_connected_callback,
271 .add_segment_callback = builtin_add_segment_callback,
272 .redirect_connect_callback = builtin_redirect_connect_callback,
Florin Corasd79b41e2017-03-04 05:37:52 -0800273 .builtin_server_rx_callback = builtin_server_rx_callback,
274 .session_reset_callback = builtin_session_reset_callback
Florin Corase04c2992017-03-01 08:17:34 -0800275};
276
Florin Coras6cf30ad2017-04-04 23:08:23 -0700277/* Abuse VPP's input queue */
Florin Corase04c2992017-03-01 08:17:34 -0800278static int
Florin Coras6cf30ad2017-04-04 23:08:23 -0700279create_api_loopback (vlib_main_t * vm)
Florin Corase04c2992017-03-01 08:17:34 -0800280{
Florin Coras6cf30ad2017-04-04 23:08:23 -0700281 builtin_server_main_t *bsm = &builtin_server_main;
282 vl_api_memclnt_create_t _m, *mp = &_m;
283 extern void vl_api_memclnt_create_t_handler (vl_api_memclnt_create_t *);
284 api_main_t *am = &api_main;
285 vl_shmem_hdr_t *shmem_hdr;
286 uword *event_data = 0, event_type;
287 int resolved = 0;
Florin Corasd79b41e2017-03-04 05:37:52 -0800288
Florin Coras6cf30ad2017-04-04 23:08:23 -0700289 /*
290 * Create a "loopback" API client connection
291 * Don't do things like this unless you know what you're doing...
292 */
293
294 shmem_hdr = am->shmem_hdr;
295 bsm->vl_input_queue = shmem_hdr->vl_input_queue;
296 memset (mp, 0, sizeof (*mp));
297 mp->_vl_msg_id = VL_API_MEMCLNT_CREATE;
298 mp->context = 0xFEEDFACE;
Damjan Marion7bee80c2017-04-26 15:32:12 +0200299 mp->input_queue = pointer_to_uword (bsm->vl_input_queue);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700300 strncpy ((char *) mp->name, "tcp_test_server", sizeof (mp->name) - 1);
301
302 vl_api_memclnt_create_t_handler (mp);
303
304 /* Wait for reply */
305 bsm->node_index = vlib_get_current_process (vm)->node_runtime.node_index;
306 vlib_process_wait_for_event_or_clock (vm, 1.0);
307 event_type = vlib_process_get_events (vm, &event_data);
308 switch (event_type)
309 {
310 case 1:
311 resolved = 1;
312 break;
313 case ~0:
314 /* timed out */
315 break;
316 default:
317 clib_warning ("unknown event_type %d", event_type);
318 }
319 if (!resolved)
320 return -1;
321
322 return 0;
323}
324
325static int
326server_attach ()
327{
328 builtin_server_main_t *bsm = &builtin_server_main;
329 u8 segment_name[128];
330 u64 options[SESSION_OPTIONS_N_OPTIONS];
331 vnet_app_attach_args_t _a, *a = &_a;
Florin Corase04c2992017-03-01 08:17:34 -0800332
333 memset (a, 0, sizeof (*a));
334 memset (options, 0, sizeof (options));
335
Florin Corasf03a59a2017-06-09 21:07:32 -0700336 if (bsm->no_echo)
337 builtin_session_cb_vft.builtin_server_rx_callback =
338 builtin_server_rx_callback_no_echo;
339 else
340 builtin_session_cb_vft.builtin_server_rx_callback =
341 builtin_server_rx_callback;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700342 a->api_client_index = bsm->my_client_index;
Florin Corase04c2992017-03-01 08:17:34 -0800343 a->session_cb_vft = &builtin_session_cb_vft;
344 a->options = options;
Dave Barach10d8cc62017-05-30 09:30:07 -0400345 a->options[SESSION_OPTIONS_SEGMENT_SIZE] = 512 << 20;
Florin Corasf03a59a2017-06-09 21:07:32 -0700346 a->options[SESSION_OPTIONS_RX_FIFO_SIZE] = bsm->fifo_size;
347 a->options[SESSION_OPTIONS_TX_FIFO_SIZE] = bsm->fifo_size;
Dave Barach2c25a622017-06-26 11:35:07 -0400348 a->options[APP_OPTIONS_PRIVATE_SEGMENT_COUNT] = bsm->private_segment_count;
349 a->options[APP_OPTIONS_PRIVATE_SEGMENT_SIZE] = bsm->private_segment_size;
Florin Corasf03a59a2017-06-09 21:07:32 -0700350 a->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] =
351 bsm->prealloc_fifos ? bsm->prealloc_fifos : 1;
Dave Barach2c25a622017-06-26 11:35:07 -0400352
353 a->options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_BUILTIN_APP;
354
Florin Corase04c2992017-03-01 08:17:34 -0800355 a->segment_name = segment_name;
356 a->segment_name_length = ARRAY_LEN (segment_name);
357
Florin Coras6cf30ad2017-04-04 23:08:23 -0700358 if (vnet_application_attach (a))
359 {
360 clib_warning ("failed to attach server");
361 return -1;
362 }
363 bsm->app_index = a->app_index;
364 return 0;
365}
366
367static int
368server_listen ()
369{
370 builtin_server_main_t *bsm = &builtin_server_main;
371 vnet_bind_args_t _a, *a = &_a;
372 memset (a, 0, sizeof (*a));
373 a->app_index = bsm->app_index;
374 a->uri = "tcp://0.0.0.0/1234";
Florin Corase04c2992017-03-01 08:17:34 -0800375 return vnet_bind_uri (a);
376}
377
Florin Coras6cf30ad2017-04-04 23:08:23 -0700378static int
379server_create (vlib_main_t * vm)
380{
381 builtin_server_main_t *bsm = &builtin_server_main;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700382 vlib_thread_main_t *vtm = vlib_get_thread_main ();
Florin Corasf03a59a2017-06-09 21:07:32 -0700383 u32 num_threads;
384 int i;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700385
386 if (bsm->my_client_index == (u32) ~ 0)
387 {
388 if (create_api_loopback (vm))
Florin Corasf03a59a2017-06-09 21:07:32 -0700389 {
390 clib_warning ("failed to create api loopback");
391 return -1;
392 }
Florin Coras6cf30ad2017-04-04 23:08:23 -0700393 }
394
395 num_threads = 1 /* main thread */ + vtm->n_threads;
396 vec_validate (builtin_server_main.vpp_queue, num_threads - 1);
Florin Corasf03a59a2017-06-09 21:07:32 -0700397 vec_validate (bsm->rx_buf, num_threads - 1);
Dave Barach2c25a622017-06-26 11:35:07 -0400398 vec_validate (bsm->rx_retries, num_threads - 1);
399
Florin Corasf03a59a2017-06-09 21:07:32 -0700400 for (i = 0; i < num_threads; i++)
401 vec_validate (bsm->rx_buf[i], bsm->rcv_buffer_size);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700402
403 if (server_attach ())
404 {
405 clib_warning ("failed to attach server");
406 return -1;
407 }
408 if (server_listen ())
409 {
410 clib_warning ("failed to start listening");
411 return -1;
412 }
413 return 0;
414}
415
416/* Get our api client index */
417static void
418vl_api_memclnt_create_reply_t_handler (vl_api_memclnt_create_reply_t * mp)
419{
420 vlib_main_t *vm = vlib_get_main ();
421 builtin_server_main_t *bsm = &builtin_server_main;
422 bsm->my_client_index = mp->index;
423 vlib_process_signal_event (vm, bsm->node_index, 1 /* evt */ ,
424 0 /* data */ );
425}
426
427#define foreach_tcp_builtin_server_api_msg \
428_(MEMCLNT_CREATE_REPLY, memclnt_create_reply) \
429
430static clib_error_t *
431tcp_builtin_server_api_hookup (vlib_main_t * vm)
432{
433 vl_msg_api_msg_config_t _c, *c = &_c;
434
435 /* Hook up client-side static APIs to our handlers */
436#define _(N,n) do { \
437 c->id = VL_API_##N; \
438 c->name = #n; \
439 c->handler = vl_api_##n##_t_handler; \
440 c->cleanup = vl_noop_handler; \
441 c->endian = vl_api_##n##_t_endian; \
442 c->print = vl_api_##n##_t_print; \
443 c->size = sizeof(vl_api_##n##_t); \
444 c->traced = 1; /* trace, so these msgs print */ \
445 c->replay = 0; /* don't replay client create/delete msgs */ \
446 c->message_bounce = 0; /* don't bounce this message */ \
447 vl_msg_api_config(c);} while (0);
448
449 foreach_tcp_builtin_server_api_msg;
450#undef _
451
452 return 0;
453}
454
Florin Corase04c2992017-03-01 08:17:34 -0800455static clib_error_t *
Florin Corasf03a59a2017-06-09 21:07:32 -0700456server_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
457 vlib_cli_command_t * cmd)
Florin Corase04c2992017-03-01 08:17:34 -0800458{
Florin Corasf03a59a2017-06-09 21:07:32 -0700459 builtin_server_main_t *bsm = &builtin_server_main;
Florin Corase04c2992017-03-01 08:17:34 -0800460 int rv;
Dave Barach2c25a622017-06-26 11:35:07 -0400461 u32 tmp;
Florin Corasf03a59a2017-06-09 21:07:32 -0700462
463 bsm->no_echo = 0;
464 bsm->fifo_size = 64 << 10;
465 bsm->rcv_buffer_size = 128 << 10;
466 bsm->prealloc_fifos = 0;
Dave Barach2c25a622017-06-26 11:35:07 -0400467 bsm->private_segment_count = 0;
468 bsm->private_segment_size = 0;
Florin Corasf03a59a2017-06-09 21:07:32 -0700469
Florin Corase04c2992017-03-01 08:17:34 -0800470 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
471 {
Florin Corasf03a59a2017-06-09 21:07:32 -0700472 if (unformat (input, "no-echo"))
473 bsm->no_echo = 1;
474 else if (unformat (input, "fifo-size %d", &bsm->fifo_size))
475 bsm->fifo_size <<= 10;
476 else if (unformat (input, "rcv-buf-size %d", &bsm->rcv_buffer_size))
477 ;
Dave Barach2c25a622017-06-26 11:35:07 -0400478 else if (unformat (input, "prealloc-fifos %d", &bsm->prealloc_fifos))
Florin Corase04c2992017-03-01 08:17:34 -0800479 ;
Dave Barach2c25a622017-06-26 11:35:07 -0400480 else if (unformat (input, "private-segment-count %d",
481 &bsm->private_segment_count))
482 ;
483 else if (unformat (input, "private-segment-size %dm", &tmp))
484 bsm->private_segment_size = tmp << 20;
485 else if (unformat (input, "private-segment-size %dg", &tmp))
486 bsm->private_segment_size = tmp << 30;
487 else if (unformat (input, "private-segment-size %d", &tmp))
488 bsm->private_segment_size = tmp;
Florin Corase04c2992017-03-01 08:17:34 -0800489 else
490 return clib_error_return (0, "unknown input `%U'",
491 format_unformat_error, input);
492 }
Florin Corase04c2992017-03-01 08:17:34 -0800493
Florin Coras6cf30ad2017-04-04 23:08:23 -0700494 tcp_builtin_server_api_hookup (vm);
Florin Corasd79b41e2017-03-04 05:37:52 -0800495 vnet_session_enable_disable (vm, 1 /* turn on TCP, etc. */ );
Florin Corasf03a59a2017-06-09 21:07:32 -0700496
Florin Corase04c2992017-03-01 08:17:34 -0800497 rv = server_create (vm);
498 switch (rv)
499 {
500 case 0:
501 break;
502 default:
503 return clib_error_return (0, "server_create returned %d", rv);
504 }
Florin Corasf03a59a2017-06-09 21:07:32 -0700505
Florin Corase04c2992017-03-01 08:17:34 -0800506 return 0;
507}
508
Florin Corasd79b41e2017-03-04 05:37:52 -0800509/* *INDENT-OFF* */
Florin Corase04c2992017-03-01 08:17:34 -0800510VLIB_CLI_COMMAND (server_create_command, static) =
511{
Florin Coras6cf30ad2017-04-04 23:08:23 -0700512 .path = "test tcp server",
513 .short_help = "test tcp server",
Florin Corasd79b41e2017-03-04 05:37:52 -0800514 .function = server_create_command_fn,
515};
516/* *INDENT-ON* */
Florin Corase04c2992017-03-01 08:17:34 -0800517
Florin Coras6cf30ad2017-04-04 23:08:23 -0700518clib_error_t *
519builtin_tcp_server_main_init (vlib_main_t * vm)
520{
521 builtin_server_main_t *bsm = &builtin_server_main;
522 bsm->my_client_index = ~0;
523 return 0;
524}
525
526VLIB_INIT_FUNCTION (builtin_tcp_server_main_init);
527
Florin Corase04c2992017-03-01 08:17:34 -0800528/*
529* fd.io coding-style-patch-verification: ON
530*
531* Local Variables:
532* eval: (c-set-style "gnu")
533* End:
534*/