blob: b613b3ae5d53faeb6311d4dcf1d5d6d4671b2c92 [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 Corasd79b41e2017-03-04 05:37:52 -080021typedef struct
22{
Florin Corasf03a59a2017-06-09 21:07:32 -070023 /*
24 * Server app parameters
25 */
Florin Corasd79b41e2017-03-04 05:37:52 -080026 unix_shared_memory_queue_t **vpp_queue;
Florin Corasf03a59a2017-06-09 21:07:32 -070027 unix_shared_memory_queue_t *vl_input_queue; /**< Sever's event queue */
28
29 u32 app_index; /**< Server app index */
30 u32 my_client_index; /**< API client handle */
31 u32 node_index; /**< process node index for evnt scheduling */
32
33 /*
34 * Config params
35 */
36 u8 no_echo; /**< Don't echo traffic */
Florin Coras2245c0f2017-08-14 08:45:15 -070037 u32 fifo_size; /**< Fifo size */
Florin Corasf03a59a2017-06-09 21:07:32 -070038 u32 rcv_buffer_size; /**< Rcv buffer size */
39 u32 prealloc_fifos; /**< Preallocate fifos */
Dave Barach2c25a622017-06-26 11:35:07 -040040 u32 private_segment_count; /**< Number of private segments */
41 u32 private_segment_size; /**< Size of private segments */
Florin Coras2245c0f2017-08-14 08:45:15 -070042 char *server_uri; /**< Server URI */
Florin Corasf03a59a2017-06-09 21:07:32 -070043
44 /*
45 * Test state
46 */
47 u8 **rx_buf; /**< Per-thread RX buffer */
Florin Coras6cf30ad2017-04-04 23:08:23 -070048 u64 byte_index;
Dave Barach2c25a622017-06-26 11:35:07 -040049 u32 **rx_retries;
Florin Coras6cf30ad2017-04-04 23:08:23 -070050
Florin Corasd79b41e2017-03-04 05:37:52 -080051 vlib_main_t *vlib_main;
52} builtin_server_main_t;
53
54builtin_server_main_t builtin_server_main;
55
Florin Corase04c2992017-03-01 08:17:34 -080056int
57builtin_session_accept_callback (stream_session_t * s)
58{
Florin Corasd79b41e2017-03-04 05:37:52 -080059 builtin_server_main_t *bsm = &builtin_server_main;
Florin Corasd79b41e2017-03-04 05:37:52 -080060
61 bsm->vpp_queue[s->thread_index] =
62 session_manager_get_vpp_event_queue (s->thread_index);
Florin Corase04c2992017-03-01 08:17:34 -080063 s->session_state = SESSION_STATE_READY;
Florin Coras6792ec02017-03-13 03:49:51 -070064 bsm->byte_index = 0;
Dave Barach2c25a622017-06-26 11:35:07 -040065 vec_validate (bsm->rx_retries[s->thread_index], s->session_index);
66 bsm->rx_retries[s->thread_index][s->session_index] = 0;
Florin Corase04c2992017-03-01 08:17:34 -080067 return 0;
68}
69
70void
71builtin_session_disconnect_callback (stream_session_t * s)
72{
Florin Coras6cf30ad2017-04-04 23:08:23 -070073 builtin_server_main_t *bsm = &builtin_server_main;
74 vnet_disconnect_args_t _a, *a = &_a;
Florin Corasd79b41e2017-03-04 05:37:52 -080075
Florin Coras3cbc04b2017-10-02 00:18:51 -070076 a->handle = session_handle (s);
Florin Coras6cf30ad2017-04-04 23:08:23 -070077 a->app_index = bsm->app_index;
78 vnet_disconnect_session (a);
Florin Corase04c2992017-03-01 08:17:34 -080079}
80
Florin Corasd79b41e2017-03-04 05:37:52 -080081void
82builtin_session_reset_callback (stream_session_t * s)
83{
Florin Coras3eb50622017-07-13 01:24:57 -040084 clib_warning ("Reset session %U", format_stream_session, s, 2);
Florin Corasd79b41e2017-03-04 05:37:52 -080085 stream_session_cleanup (s);
86}
87
88
Florin Corase04c2992017-03-01 08:17:34 -080089int
Florin Coras6cf30ad2017-04-04 23:08:23 -070090builtin_session_connected_callback (u32 app_index, u32 api_context,
Florin Corase04c2992017-03-01 08:17:34 -080091 stream_session_t * s, u8 is_fail)
92{
93 clib_warning ("called...");
94 return -1;
95}
96
97int
98builtin_add_segment_callback (u32 client_index,
99 const u8 * seg_name, u32 seg_size)
100{
101 clib_warning ("called...");
102 return -1;
103}
104
105int
106builtin_redirect_connect_callback (u32 client_index, void *mp)
107{
108 clib_warning ("called...");
109 return -1;
110}
111
Florin Coras6792ec02017-03-13 03:49:51 -0700112void
113test_bytes (builtin_server_main_t * bsm, int actual_transfer)
Florin Corase04c2992017-03-01 08:17:34 -0800114{
Florin Coras6792ec02017-03-13 03:49:51 -0700115 int i;
Florin Coras93992a92017-05-24 18:03:56 -0700116 u32 my_thread_id = vlib_get_thread_index ();
Florin Coras6792ec02017-03-13 03:49:51 -0700117
118 for (i = 0; i < actual_transfer; i++)
119 {
Florin Coras93992a92017-05-24 18:03:56 -0700120 if (bsm->rx_buf[my_thread_id][i] != ((bsm->byte_index + i) & 0xff))
Florin Coras6792ec02017-03-13 03:49:51 -0700121 {
Florin Coras6cf30ad2017-04-04 23:08:23 -0700122 clib_warning ("at %lld expected %d got %d", bsm->byte_index + i,
Florin Coras93992a92017-05-24 18:03:56 -0700123 (bsm->byte_index + i) & 0xff,
124 bsm->rx_buf[my_thread_id][i]);
Florin Coras6792ec02017-03-13 03:49:51 -0700125 }
126 }
127 bsm->byte_index += actual_transfer;
128}
129
Florin Corasf03a59a2017-06-09 21:07:32 -0700130/*
131 * If no-echo, just read the data and be done with it
132 */
133int
134builtin_server_rx_callback_no_echo (stream_session_t * s)
135{
136 builtin_server_main_t *bsm = &builtin_server_main;
137 u32 my_thread_id = vlib_get_thread_index ();
138 int actual_transfer;
139 svm_fifo_t *rx_fifo;
140
141 rx_fifo = s->server_rx_fifo;
142
143 do
144 {
145 actual_transfer =
146 svm_fifo_dequeue_nowait (rx_fifo, bsm->rcv_buffer_size,
147 bsm->rx_buf[my_thread_id]);
148 }
149 while (actual_transfer > 0);
150 return 0;
151}
152
Florin Coras6792ec02017-03-13 03:49:51 -0700153int
154builtin_server_rx_callback (stream_session_t * s)
155{
156 u32 n_written, max_dequeue, max_enqueue, max_transfer;
157 int actual_transfer;
158 svm_fifo_t *tx_fifo, *rx_fifo;
Florin Corasd79b41e2017-03-04 05:37:52 -0800159 builtin_server_main_t *bsm = &builtin_server_main;
160 session_fifo_event_t evt;
Dave Barach2c25a622017-06-26 11:35:07 -0400161 u32 thread_index = vlib_get_thread_index ();
162
163 ASSERT (s->thread_index == thread_index);
Florin Corasd79b41e2017-03-04 05:37:52 -0800164
Dave Barachacd2a6a2017-05-16 17:41:34 -0400165 rx_fifo = s->server_rx_fifo;
Florin Corasf03a59a2017-06-09 21:07:32 -0700166 tx_fifo = s->server_tx_fifo;
Dave Barachacd2a6a2017-05-16 17:41:34 -0400167
Dave Barach2c25a622017-06-26 11:35:07 -0400168 ASSERT (rx_fifo->master_thread_index == thread_index);
169 ASSERT (tx_fifo->master_thread_index == thread_index);
170
Florin Coras6792ec02017-03-13 03:49:51 -0700171 max_dequeue = svm_fifo_max_dequeue (s->server_rx_fifo);
172 max_enqueue = svm_fifo_max_enqueue (s->server_tx_fifo);
173
174 if (PREDICT_FALSE (max_dequeue == 0))
Dave Barachacd2a6a2017-05-16 17:41:34 -0400175 return 0;
Florin Corasd79b41e2017-03-04 05:37:52 -0800176
177 /* Number of bytes we're going to copy */
Florin Coras6792ec02017-03-13 03:49:51 -0700178 max_transfer = (max_dequeue < max_enqueue) ? max_dequeue : max_enqueue;
Florin Corasd79b41e2017-03-04 05:37:52 -0800179
Florin Coras6792ec02017-03-13 03:49:51 -0700180 /* No space in tx fifo */
181 if (PREDICT_FALSE (max_transfer == 0))
Florin Corasd79b41e2017-03-04 05:37:52 -0800182 {
Florin Coras6792ec02017-03-13 03:49:51 -0700183 /* XXX timeout for session that are stuck */
184
Florin Coras3e350af2017-03-30 02:54:28 -0700185 rx_event:
Florin Coras6792ec02017-03-13 03:49:51 -0700186 /* Program self-tap to retry */
187 if (svm_fifo_set_event (rx_fifo))
188 {
Florin Corasf03a59a2017-06-09 21:07:32 -0700189 unix_shared_memory_queue_t *q;
Florin Coras6792ec02017-03-13 03:49:51 -0700190 evt.fifo = rx_fifo;
191 evt.event_type = FIFO_EVENT_BUILTIN_RX;
Florin Corasf03a59a2017-06-09 21:07:32 -0700192
Dave Barach2c25a622017-06-26 11:35:07 -0400193 q = bsm->vpp_queue[thread_index];
Florin Corasf03a59a2017-06-09 21:07:32 -0700194 if (PREDICT_FALSE (q->cursize == q->maxsize))
195 clib_warning ("out of event queue space");
Florin Coras6534b7a2017-07-18 05:38:03 -0400196 else if (unix_shared_memory_queue_add (q, (u8 *) & evt, 0))
Dave Barach2c25a622017-06-26 11:35:07 -0400197 clib_warning ("failed to enqueue self-tap");
198
Dave Barach2c25a622017-06-26 11:35:07 -0400199 if (bsm->rx_retries[thread_index][s->session_index] == 500000)
200 {
201 clib_warning ("session stuck: %U", format_stream_session, s, 2);
202 }
Florin Coras6534b7a2017-07-18 05:38:03 -0400203 if (bsm->rx_retries[thread_index][s->session_index] < 500001)
204 bsm->rx_retries[thread_index][s->session_index]++;
Dave Barach2c25a622017-06-26 11:35:07 -0400205 }
Florin Coras6792ec02017-03-13 03:49:51 -0700206
Florin Corasd79b41e2017-03-04 05:37:52 -0800207 return 0;
208 }
209
Dave Barach2c25a622017-06-26 11:35:07 -0400210 _vec_len (bsm->rx_buf[thread_index]) = max_transfer;
Florin Coras6792ec02017-03-13 03:49:51 -0700211
Florin Corasa5464812017-04-19 13:00:05 -0700212 actual_transfer = svm_fifo_dequeue_nowait (rx_fifo, max_transfer,
Dave Barach2c25a622017-06-26 11:35:07 -0400213 bsm->rx_buf[thread_index]);
Florin Coras6792ec02017-03-13 03:49:51 -0700214 ASSERT (actual_transfer == max_transfer);
215
216// test_bytes (bsm, actual_transfer);
Florin Corasd79b41e2017-03-04 05:37:52 -0800217
218 /*
219 * Echo back
220 */
221
Florin Coras93992a92017-05-24 18:03:56 -0700222 n_written = svm_fifo_enqueue_nowait (tx_fifo, actual_transfer,
Dave Barach2c25a622017-06-26 11:35:07 -0400223 bsm->rx_buf[thread_index]);
Florin Coras3e350af2017-03-30 02:54:28 -0700224
225 if (n_written != max_transfer)
226 clib_warning ("short trout!");
Florin Corasd79b41e2017-03-04 05:37:52 -0800227
Florin Coras6792ec02017-03-13 03:49:51 -0700228 if (svm_fifo_set_event (tx_fifo))
229 {
230 /* Fabricate TX event, send to vpp */
231 evt.fifo = tx_fifo;
Florin Corasa5464812017-04-19 13:00:05 -0700232 evt.event_type = FIFO_EVENT_APP_TX;
Florin Corasd79b41e2017-03-04 05:37:52 -0800233
Dave Barach2c25a622017-06-26 11:35:07 -0400234 if (unix_shared_memory_queue_add (bsm->vpp_queue[s->thread_index],
235 (u8 *) & evt,
236 0 /* do wait for mutex */ ))
237 clib_warning ("failed to enqueue tx evt");
Florin Coras6792ec02017-03-13 03:49:51 -0700238 }
Florin Corasd79b41e2017-03-04 05:37:52 -0800239
Dave Barach2c25a622017-06-26 11:35:07 -0400240 if (PREDICT_FALSE (n_written < max_dequeue))
Florin Coras3e350af2017-03-30 02:54:28 -0700241 goto rx_event;
242
Florin Corase04c2992017-03-01 08:17:34 -0800243 return 0;
244}
245
246static session_cb_vft_t builtin_session_cb_vft = {
247 .session_accept_callback = builtin_session_accept_callback,
248 .session_disconnect_callback = builtin_session_disconnect_callback,
249 .session_connected_callback = builtin_session_connected_callback,
250 .add_segment_callback = builtin_add_segment_callback,
251 .redirect_connect_callback = builtin_redirect_connect_callback,
Florin Corasd79b41e2017-03-04 05:37:52 -0800252 .builtin_server_rx_callback = builtin_server_rx_callback,
253 .session_reset_callback = builtin_session_reset_callback
Florin Corase04c2992017-03-01 08:17:34 -0800254};
255
Florin Coras6cf30ad2017-04-04 23:08:23 -0700256/* Abuse VPP's input queue */
Florin Corase04c2992017-03-01 08:17:34 -0800257static int
Florin Coras6cf30ad2017-04-04 23:08:23 -0700258create_api_loopback (vlib_main_t * vm)
Florin Corase04c2992017-03-01 08:17:34 -0800259{
Florin Coras6cf30ad2017-04-04 23:08:23 -0700260 builtin_server_main_t *bsm = &builtin_server_main;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700261 api_main_t *am = &api_main;
262 vl_shmem_hdr_t *shmem_hdr;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700263
264 shmem_hdr = am->shmem_hdr;
265 bsm->vl_input_queue = shmem_hdr->vl_input_queue;
Dave Barach52851e62017-08-07 09:35:25 -0400266 bsm->my_client_index =
Florin Corase87216f2017-08-17 16:59:22 -0700267 vl_api_memclnt_create_internal ("tcp_test_server", bsm->vl_input_queue);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700268 return 0;
269}
270
271static int
Florin Corascea194d2017-10-02 00:18:51 -0700272server_attach (u8 * appns_id, u64 appns_flags, u64 appns_secret)
Florin Coras6cf30ad2017-04-04 23:08:23 -0700273{
274 builtin_server_main_t *bsm = &builtin_server_main;
275 u8 segment_name[128];
276 u64 options[SESSION_OPTIONS_N_OPTIONS];
277 vnet_app_attach_args_t _a, *a = &_a;
Florin Corase04c2992017-03-01 08:17:34 -0800278
279 memset (a, 0, sizeof (*a));
280 memset (options, 0, sizeof (options));
281
Florin Corasf03a59a2017-06-09 21:07:32 -0700282 if (bsm->no_echo)
283 builtin_session_cb_vft.builtin_server_rx_callback =
284 builtin_server_rx_callback_no_echo;
285 else
286 builtin_session_cb_vft.builtin_server_rx_callback =
287 builtin_server_rx_callback;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700288 a->api_client_index = bsm->my_client_index;
Florin Corase04c2992017-03-01 08:17:34 -0800289 a->session_cb_vft = &builtin_session_cb_vft;
290 a->options = options;
Dave Barach10d8cc62017-05-30 09:30:07 -0400291 a->options[SESSION_OPTIONS_SEGMENT_SIZE] = 512 << 20;
Florin Corasf03a59a2017-06-09 21:07:32 -0700292 a->options[SESSION_OPTIONS_RX_FIFO_SIZE] = bsm->fifo_size;
293 a->options[SESSION_OPTIONS_TX_FIFO_SIZE] = bsm->fifo_size;
Dave Barach2c25a622017-06-26 11:35:07 -0400294 a->options[APP_OPTIONS_PRIVATE_SEGMENT_COUNT] = bsm->private_segment_count;
295 a->options[APP_OPTIONS_PRIVATE_SEGMENT_SIZE] = bsm->private_segment_size;
Florin Corasf03a59a2017-06-09 21:07:32 -0700296 a->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] =
297 bsm->prealloc_fifos ? bsm->prealloc_fifos : 1;
Dave Barach2c25a622017-06-26 11:35:07 -0400298
Florin Coras7999e832017-10-31 01:51:04 -0700299 a->options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN;
Florin Corascea194d2017-10-02 00:18:51 -0700300 if (appns_id)
301 {
302 a->namespace_id = appns_id;
303 a->options[APP_OPTIONS_FLAGS] |= appns_flags;
304 a->options[APP_OPTIONS_NAMESPACE_SECRET] = appns_secret;
305 }
Florin Corase04c2992017-03-01 08:17:34 -0800306 a->segment_name = segment_name;
307 a->segment_name_length = ARRAY_LEN (segment_name);
308
Florin Coras6cf30ad2017-04-04 23:08:23 -0700309 if (vnet_application_attach (a))
310 {
311 clib_warning ("failed to attach server");
312 return -1;
313 }
314 bsm->app_index = a->app_index;
315 return 0;
316}
317
318static int
319server_listen ()
320{
321 builtin_server_main_t *bsm = &builtin_server_main;
322 vnet_bind_args_t _a, *a = &_a;
323 memset (a, 0, sizeof (*a));
324 a->app_index = bsm->app_index;
Florin Coras2245c0f2017-08-14 08:45:15 -0700325 a->uri = bsm->server_uri;
Florin Corase04c2992017-03-01 08:17:34 -0800326 return vnet_bind_uri (a);
327}
328
Florin Coras6cf30ad2017-04-04 23:08:23 -0700329static int
Florin Corascea194d2017-10-02 00:18:51 -0700330server_create (vlib_main_t * vm, u8 * appns_id, u64 appns_flags,
331 u64 appns_secret)
Florin Coras6cf30ad2017-04-04 23:08:23 -0700332{
333 builtin_server_main_t *bsm = &builtin_server_main;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700334 vlib_thread_main_t *vtm = vlib_get_thread_main ();
Florin Corasf03a59a2017-06-09 21:07:32 -0700335 u32 num_threads;
336 int i;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700337
338 if (bsm->my_client_index == (u32) ~ 0)
339 {
340 if (create_api_loopback (vm))
Florin Corasf03a59a2017-06-09 21:07:32 -0700341 {
342 clib_warning ("failed to create api loopback");
343 return -1;
344 }
Florin Coras6cf30ad2017-04-04 23:08:23 -0700345 }
346
347 num_threads = 1 /* main thread */ + vtm->n_threads;
348 vec_validate (builtin_server_main.vpp_queue, num_threads - 1);
Florin Corasf03a59a2017-06-09 21:07:32 -0700349 vec_validate (bsm->rx_buf, num_threads - 1);
Dave Barach2c25a622017-06-26 11:35:07 -0400350 vec_validate (bsm->rx_retries, num_threads - 1);
351
Florin Corasf03a59a2017-06-09 21:07:32 -0700352 for (i = 0; i < num_threads; i++)
353 vec_validate (bsm->rx_buf[i], bsm->rcv_buffer_size);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700354
Florin Corascea194d2017-10-02 00:18:51 -0700355 if (server_attach (appns_id, appns_flags, appns_secret))
Florin Coras6cf30ad2017-04-04 23:08:23 -0700356 {
357 clib_warning ("failed to attach server");
358 return -1;
359 }
360 if (server_listen ())
361 {
362 clib_warning ("failed to start listening");
363 return -1;
364 }
365 return 0;
366}
367
Florin Corase04c2992017-03-01 08:17:34 -0800368static clib_error_t *
Florin Corasf03a59a2017-06-09 21:07:32 -0700369server_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
370 vlib_cli_command_t * cmd)
Florin Corase04c2992017-03-01 08:17:34 -0800371{
Florin Corasf03a59a2017-06-09 21:07:32 -0700372 builtin_server_main_t *bsm = &builtin_server_main;
Florin Corascea194d2017-10-02 00:18:51 -0700373 u8 server_uri_set = 0, *appns_id = 0;
374 u64 tmp, appns_flags = 0, appns_secret = 0;
Florin Corase04c2992017-03-01 08:17:34 -0800375 int rv;
Florin Corasf03a59a2017-06-09 21:07:32 -0700376
377 bsm->no_echo = 0;
378 bsm->fifo_size = 64 << 10;
379 bsm->rcv_buffer_size = 128 << 10;
380 bsm->prealloc_fifos = 0;
Dave Barach2c25a622017-06-26 11:35:07 -0400381 bsm->private_segment_count = 0;
382 bsm->private_segment_size = 0;
Florin Coras2245c0f2017-08-14 08:45:15 -0700383 vec_free (bsm->server_uri);
Florin Corasf03a59a2017-06-09 21:07:32 -0700384
Florin Corase04c2992017-03-01 08:17:34 -0800385 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
386 {
Florin Corasf03a59a2017-06-09 21:07:32 -0700387 if (unformat (input, "no-echo"))
388 bsm->no_echo = 1;
389 else if (unformat (input, "fifo-size %d", &bsm->fifo_size))
390 bsm->fifo_size <<= 10;
391 else if (unformat (input, "rcv-buf-size %d", &bsm->rcv_buffer_size))
392 ;
Dave Barach2c25a622017-06-26 11:35:07 -0400393 else if (unformat (input, "prealloc-fifos %d", &bsm->prealloc_fifos))
Florin Corase04c2992017-03-01 08:17:34 -0800394 ;
Dave Barach2c25a622017-06-26 11:35:07 -0400395 else if (unformat (input, "private-segment-count %d",
396 &bsm->private_segment_count))
397 ;
Dave Barach91f3e742017-09-01 19:12:11 -0400398 else if (unformat (input, "private-segment-size %U",
399 unformat_memory_size, &tmp))
400 {
401 if (tmp >= 0x100000000ULL)
402 return clib_error_return
403 (0, "private segment size %lld (%llu) too large", tmp, tmp);
404 bsm->private_segment_size = tmp;
405 }
Florin Coras2245c0f2017-08-14 08:45:15 -0700406 else if (unformat (input, "uri %s", &bsm->server_uri))
407 server_uri_set = 1;
Florin Corascea194d2017-10-02 00:18:51 -0700408 else if (unformat (input, "appns %_%v%_", &appns_id))
409 ;
410 else if (unformat (input, "all-scope"))
411 appns_flags |= (APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE
412 | APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE);
413 else if (unformat (input, "local-scope"))
414 appns_flags |= APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE;
415 else if (unformat (input, "global-scope"))
416 appns_flags |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
417 else if (unformat (input, "secret %lu", &appns_secret))
418 ;
Florin Corase04c2992017-03-01 08:17:34 -0800419 else
420 return clib_error_return (0, "unknown input `%U'",
421 format_unformat_error, input);
422 }
Florin Corase04c2992017-03-01 08:17:34 -0800423
Florin Corasd79b41e2017-03-04 05:37:52 -0800424 vnet_session_enable_disable (vm, 1 /* turn on TCP, etc. */ );
Florin Corasf03a59a2017-06-09 21:07:32 -0700425
Florin Coras2245c0f2017-08-14 08:45:15 -0700426 if (!server_uri_set)
427 bsm->server_uri = (char *) format (0, "tcp://0.0.0.0/1234%c", 0);
428
Florin Corascea194d2017-10-02 00:18:51 -0700429 rv = server_create (vm, appns_id, appns_flags, appns_secret);
430 vec_free (appns_id);
Florin Corase04c2992017-03-01 08:17:34 -0800431 switch (rv)
432 {
433 case 0:
434 break;
435 default:
436 return clib_error_return (0, "server_create returned %d", rv);
437 }
Florin Corasf03a59a2017-06-09 21:07:32 -0700438
Florin Corase04c2992017-03-01 08:17:34 -0800439 return 0;
440}
441
Florin Corasd79b41e2017-03-04 05:37:52 -0800442/* *INDENT-OFF* */
Florin Corase04c2992017-03-01 08:17:34 -0800443VLIB_CLI_COMMAND (server_create_command, static) =
444{
Florin Coras6cf30ad2017-04-04 23:08:23 -0700445 .path = "test tcp server",
Florin Coras2245c0f2017-08-14 08:45:15 -0700446 .short_help = "test tcp server [no echo][fifo-size <mbytes>] "
447 "[rcv-buf-size <bytes>][prealloc-fifos <count>]"
448 "[private-segment-count <count>][private-segment-size <bytes[m|g]>]"
449 "[uri <tcp://ip/port>]",
Florin Corasd79b41e2017-03-04 05:37:52 -0800450 .function = server_create_command_fn,
451};
452/* *INDENT-ON* */
Florin Corase04c2992017-03-01 08:17:34 -0800453
Florin Coras6cf30ad2017-04-04 23:08:23 -0700454clib_error_t *
455builtin_tcp_server_main_init (vlib_main_t * vm)
456{
457 builtin_server_main_t *bsm = &builtin_server_main;
458 bsm->my_client_index = ~0;
459 return 0;
460}
461
462VLIB_INIT_FUNCTION (builtin_tcp_server_main_init);
463
Florin Corase04c2992017-03-01 08:17:34 -0800464/*
465* fd.io coding-style-patch-verification: ON
466*
467* Local Variables:
468* eval: (c-set-style "gnu")
469* End:
470*/