2 * Copyright (c) 2016 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <vppinfra/clib.h>
20 #include <vppinfra/format.h>
21 #include <vppinfra/error.h>
22 #include <vppinfra/time.h>
23 #include <vppinfra/macros.h>
24 #include <vnet/vnet.h>
25 #include <vlib/vlib.h>
26 #include <vlib/unix/unix.h>
27 #include <vlibapi/api.h>
28 #include <vlibmemory/api.h>
29 #include <vpp/api/vpe_msg_enum.h>
30 #include <svm/svm_fifo_segment.h>
32 #include <vnet/session/application_interface.h>
34 #define vl_typedefs /* define message structures */
35 #include <vpp/api/vpe_all_api_h.h>
38 /* declare message handlers for each api */
40 #define vl_endianfun /* define message structures */
41 #include <vpp/api/vpe_all_api_h.h>
44 /* instantiate all the print functions we know about */
45 #define vl_print(handle, ...)
47 #include <vpp/api/vpe_all_api_h.h>
60 svm_fifo_t *server_rx_fifo;
61 svm_fifo_t *server_tx_fifo;
67 unix_shared_memory_queue_t *vl_input_queue;
69 /* API client handle */
72 /* The URI we're playing with */
78 /* Hash table for disconnect processing */
79 uword *session_index_by_vpp_handles;
82 svm_fifo_segment_private_t *seg;
84 /* intermediate rx buffer */
93 unix_shared_memory_queue_t *our_event_queue;
95 /* $$$ single thread only for the moment */
96 unix_shared_memory_queue_t *vpp_event_queue;
98 /* $$$$ hack: cut-through session index */
99 volatile u32 cut_through_session_index;
101 /* unique segment name counter */
102 u32 unique_segment_index;
107 pthread_t cut_through_thread_handle;
109 /* For deadman timers */
110 clib_time_t clib_time;
112 /* State of the connection, shared between msg RX thread and main thread */
113 volatile connection_state_t state;
115 volatile int time_to_stop;
116 volatile int time_to_print_stats;
118 u32 configured_segment_size;
120 /* VNET_API_ERROR_FOO -> "Foo" hash table */
121 uword *error_string_by_error_number;
124 svm_fifo_segment_main_t *segment_main;
126 } uri_udp_test_main_t;
131 #define NITER 4000000
134 uri_udp_test_main_t uri_udp_test_main;
137 stop_signal (int signum)
139 uri_udp_test_main_t *um = &uri_udp_test_main;
141 um->time_to_stop = 1;
145 stats_signal (int signum)
147 uri_udp_test_main_t *um = &uri_udp_test_main;
149 um->time_to_print_stats = 1;
152 static clib_error_t *
153 setup_signal_handlers (void)
155 signal (SIGINT, stats_signal);
156 signal (SIGQUIT, stop_signal);
157 signal (SIGTERM, stop_signal);
163 application_send_attach (uri_udp_test_main_t * utm)
165 vl_api_application_attach_t *bmp;
166 u32 fifo_size = 3 << 20;
167 bmp = vl_msg_api_alloc (sizeof (*bmp));
168 memset (bmp, 0, sizeof (*bmp));
170 bmp->_vl_msg_id = ntohs (VL_API_APPLICATION_ATTACH);
171 bmp->client_index = utm->my_client_index;
172 bmp->context = ntohl (0xfeedface);
173 bmp->options[APP_OPTIONS_FLAGS] =
174 APP_OPTIONS_FLAGS_USE_FIFO | APP_OPTIONS_FLAGS_ADD_SEGMENT;
175 bmp->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] = 16;
176 bmp->options[SESSION_OPTIONS_RX_FIFO_SIZE] = fifo_size;
177 bmp->options[SESSION_OPTIONS_TX_FIFO_SIZE] = fifo_size;
178 bmp->options[SESSION_OPTIONS_ADD_SEGMENT_SIZE] = 128 << 20;
179 bmp->options[SESSION_OPTIONS_SEGMENT_SIZE] = 256 << 20;
180 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & bmp);
184 application_detach (uri_udp_test_main_t * utm)
186 vl_api_application_detach_t *bmp;
187 bmp = vl_msg_api_alloc (sizeof (*bmp));
188 memset (bmp, 0, sizeof (*bmp));
190 bmp->_vl_msg_id = ntohs (VL_API_APPLICATION_DETACH);
191 bmp->client_index = utm->my_client_index;
192 bmp->context = ntohl (0xfeedface);
193 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & bmp);
197 vl_api_application_attach_reply_t_handler (vl_api_application_attach_reply_t *
200 uri_udp_test_main_t *utm = &uri_udp_test_main;
201 svm_fifo_segment_create_args_t _a, *a = &_a;
206 clib_warning ("attach failed: %d", mp->retval);
207 utm->state = STATE_FAILED;
211 if (mp->segment_name_length == 0)
213 clib_warning ("segment_name_length zero");
217 a->segment_name = (char *) mp->segment_name;
218 a->segment_size = mp->segment_size;
220 ASSERT (mp->app_event_queue_address);
222 /* Attach to the segment vpp created */
223 rv = svm_fifo_segment_attach (a);
226 clib_warning ("svm_fifo_segment_attach ('%s') failed",
231 utm->our_event_queue =
232 uword_to_pointer (mp->app_event_queue_address,
233 unix_shared_memory_queue_t *);
237 vl_api_application_detach_reply_t_handler (vl_api_application_detach_reply_t *
241 clib_warning ("detach returned with err: %d", mp->retval);
245 format_api_error (u8 * s, va_list * args)
247 uri_udp_test_main_t *utm = va_arg (*args, uri_udp_test_main_t *);
248 i32 error = va_arg (*args, u32);
251 p = hash_get (utm->error_string_by_error_number, -error);
254 s = format (s, "%s", p[0]);
256 s = format (s, "%d", error);
261 wait_for_state_change (uri_udp_test_main_t * utm, connection_state_t state)
264 #define TIMEOUT 600.0
266 #define TIMEOUT 600.0
269 f64 timeout = clib_time_now (&utm->clib_time) + TIMEOUT;
271 while (clib_time_now (&utm->clib_time) < timeout)
273 if (utm->state == state)
279 u64 server_bytes_received, server_bytes_sent;
282 cut_through_thread_fn (void *arg)
287 u8 *my_copy_buffer = 0;
288 uri_udp_test_main_t *utm = &uri_udp_test_main;
293 while (utm->cut_through_session_index == ~0)
296 s = pool_elt_at_index (utm->sessions, utm->cut_through_session_index);
298 rx_fifo = s->server_rx_fifo;
299 tx_fifo = s->server_tx_fifo;
301 vec_validate (my_copy_buffer, 64 * 1024 - 1);
305 /* We read from the tx fifo and write to the rx fifo */
308 actual_transfer = svm_fifo_dequeue_nowait (tx_fifo,
309 vec_len (my_copy_buffer),
312 while (actual_transfer <= 0);
314 server_bytes_received += actual_transfer;
317 while (actual_transfer > 0)
319 rv = svm_fifo_enqueue_nowait (rx_fifo, actual_transfer,
320 my_copy_buffer + buffer_offset);
323 actual_transfer -= rv;
325 server_bytes_sent += rv;
329 if (PREDICT_FALSE (utm->time_to_stop))
337 udp_client_connect (uri_udp_test_main_t * utm)
339 vl_api_connect_uri_t *cmp;
340 cmp = vl_msg_api_alloc (sizeof (*cmp));
341 memset (cmp, 0, sizeof (*cmp));
343 cmp->_vl_msg_id = ntohs (VL_API_CONNECT_URI);
344 cmp->client_index = utm->my_client_index;
345 cmp->context = ntohl (0xfeedface);
346 memcpy (cmp->uri, utm->connect_uri, vec_len (utm->connect_uri));
347 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & cmp);
351 client_send (uri_udp_test_main_t * utm, session_t * session)
355 u64 bytes_received = 0, bytes_sent = 0;
358 f64 before, after, delta, bytes_per_second;
359 svm_fifo_t *rx_fifo, *tx_fifo;
360 int buffer_offset, bytes_to_send = 0;
365 vec_validate (test_data, 64 * 1024 - 1);
366 for (i = 0; i < vec_len (test_data); i++)
367 test_data[i] = i & 0xff;
369 rx_fifo = session->server_rx_fifo;
370 tx_fifo = session->server_tx_fifo;
372 before = clib_time_now (&utm->clib_time);
374 vec_validate (utm->rx_buf, vec_len (test_data) - 1);
376 for (i = 0; i < NITER; i++)
378 bytes_to_send = vec_len (test_data);
380 while (bytes_to_send > 0)
382 rv = svm_fifo_enqueue_nowait (tx_fifo, bytes_to_send,
383 test_data + buffer_offset);
393 bytes_to_read = svm_fifo_max_dequeue (rx_fifo);
395 bytes_to_read = vec_len (utm->rx_buf) > bytes_to_read ?
396 bytes_to_read : vec_len (utm->rx_buf);
399 while (bytes_to_read > 0)
401 rv = svm_fifo_dequeue_nowait (rx_fifo,
403 utm->rx_buf + buffer_offset);
408 bytes_received += rv;
412 while (bytes_received < bytes_sent)
415 svm_fifo_dequeue_nowait (rx_fifo, vec_len (utm->rx_buf), utm->rx_buf);
420 for (j = 0; j < rv; j++)
422 if (utm->rx_buf[j] != ((bytes_received + j) & 0xff))
424 clib_warning ("error at byte %lld, 0x%x not 0x%x",
427 ((bytes_received + j) & 0xff));
431 bytes_received += (u64) rv;
435 after = clib_time_now (&utm->clib_time);
436 delta = after - before;
437 bytes_per_second = 0.0;
440 bytes_per_second = (f64) bytes_received / delta;
443 "Done: %lld recv bytes in %.2f seconds, %.2f bytes/sec...\n\n",
444 bytes_received, delta, bytes_per_second);
446 "Done: %lld sent bytes in %.2f seconds, %.2f bytes/sec...\n\n",
447 bytes_sent, delta, bytes_per_second);
449 "client -> server -> client round trip: %.2f Gbit/sec \n\n",
450 (bytes_per_second * 8.0) / 1e9);
454 uri_udp_client_test (uri_udp_test_main_t * utm)
458 application_send_attach (utm);
459 udp_client_connect (utm);
461 if (wait_for_state_change (utm, STATE_READY))
463 clib_warning ("timeout waiting for STATE_READY");
467 /* Only works with cut through sessions */
468 session = pool_elt_at_index (utm->sessions, utm->cut_through_session_index);
470 client_send (utm, session);
471 application_detach (utm);
475 vl_api_bind_uri_reply_t_handler (vl_api_bind_uri_reply_t * mp)
477 uri_udp_test_main_t *utm = &uri_udp_test_main;
481 clib_warning ("bind failed: %d", mp->retval);
482 utm->state = STATE_FAILED;
486 utm->state = STATE_READY;
490 vl_api_map_another_segment_t_handler (vl_api_map_another_segment_t * mp)
492 svm_fifo_segment_create_args_t _a, *a = &_a;
495 a->segment_name = (char *) mp->segment_name;
496 a->segment_size = mp->segment_size;
497 /* Attach to the segment vpp created */
498 rv = svm_fifo_segment_attach (a);
501 clib_warning ("svm_fifo_segment_attach ('%s') failed",
505 clib_warning ("Mapped new segment '%s' size %d", mp->segment_name,
510 * Acting as server for redirected connect requests
513 vl_api_connect_uri_t_handler (vl_api_connect_uri_t * mp)
516 uri_udp_test_main_t *utm = &uri_udp_test_main;
517 svm_fifo_segment_main_t *sm = &svm_fifo_segment_main;
518 svm_fifo_segment_create_args_t _a, *a = &_a;
519 svm_fifo_segment_private_t *seg;
520 unix_shared_memory_queue_t *client_q;
521 vl_api_connect_uri_reply_t *rmp;
522 session_t *session = 0;
525 /* Create the segment */
526 a->segment_name = (char *) format (0, "%d:segment%d%c", utm->my_pid,
527 utm->unique_segment_index++, 0);
528 a->segment_size = utm->configured_segment_size;
530 rv = svm_fifo_segment_create (a);
533 clib_warning ("sm_fifo_segment_create ('%s') failed", a->segment_name);
534 rv = VNET_API_ERROR_URI_FIFO_CREATE_FAILED;
538 vec_add2 (utm->seg, seg, 1);
540 segment_index = vec_len (sm->segments) - 1;
541 memcpy (seg, sm->segments + segment_index, sizeof (utm->seg[0]));
543 pool_get (utm->sessions, session);
545 session->server_rx_fifo = svm_fifo_segment_alloc_fifo
546 (utm->seg, 128 * 1024, FIFO_SEGMENT_RX_FREELIST);
547 ASSERT (session->server_rx_fifo);
549 session->server_tx_fifo = svm_fifo_segment_alloc_fifo
550 (utm->seg, 128 * 1024, FIFO_SEGMENT_TX_FREELIST);
551 ASSERT (session->server_tx_fifo);
553 session->server_rx_fifo->master_session_index = session - utm->sessions;
554 session->server_tx_fifo->master_session_index = session - utm->sessions;
555 utm->cut_through_session_index = session - utm->sessions;
557 rv = pthread_create (&utm->cut_through_thread_handle,
558 NULL /*attr */ , cut_through_thread_fn, 0);
561 clib_warning ("pthread_create returned %d", rv);
562 rv = VNET_API_ERROR_SYSCALL_ERROR_1;
566 rmp = vl_msg_api_alloc (sizeof (*rmp));
567 memset (rmp, 0, sizeof (*rmp));
569 rmp->_vl_msg_id = ntohs (VL_API_CONNECT_URI_REPLY);
570 rmp->context = mp->context;
571 rmp->retval = ntohl (rv);
572 rmp->segment_name_length = vec_len (a->segment_name);
575 rmp->server_rx_fifo = pointer_to_uword (session->server_rx_fifo);
576 rmp->server_tx_fifo = pointer_to_uword (session->server_tx_fifo);
579 memcpy (rmp->segment_name, a->segment_name, vec_len (a->segment_name));
581 vec_free (a->segment_name);
584 uword_to_pointer (mp->client_queue_address, unix_shared_memory_queue_t *);
585 vl_msg_api_send_shmem (client_q, (u8 *) & rmp);
589 vl_api_unbind_uri_reply_t_handler (vl_api_unbind_uri_reply_t * mp)
591 uri_udp_test_main_t *utm = &uri_udp_test_main;
594 clib_warning ("returned %d", ntohl (mp->retval));
596 utm->state = STATE_START;
600 vl_api_accept_session_t_handler (vl_api_accept_session_t * mp)
602 uri_udp_test_main_t *utm = &uri_udp_test_main;
603 vl_api_accept_session_reply_t *rmp;
604 svm_fifo_t *rx_fifo, *tx_fifo;
606 static f64 start_time;
608 if (start_time == 0.0)
609 start_time = clib_time_now (&utm->clib_time);
611 utm->vpp_event_queue =
612 uword_to_pointer (mp->vpp_event_queue_address,
613 unix_shared_memory_queue_t *);
615 pool_get (utm->sessions, session);
617 rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *);
618 rx_fifo->client_session_index = session - utm->sessions;
619 tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *);
620 tx_fifo->client_session_index = session - utm->sessions;
622 session->server_rx_fifo = rx_fifo;
623 session->server_tx_fifo = tx_fifo;
625 hash_set (utm->session_index_by_vpp_handles, mp->handle,
626 session - utm->sessions);
628 utm->state = STATE_READY;
630 if (pool_elts (utm->sessions) && (pool_elts (utm->sessions) % 20000) == 0)
632 f64 now = clib_time_now (&utm->clib_time);
633 fformat (stdout, "%d active sessions in %.2f seconds, %.2f/sec...\n",
634 pool_elts (utm->sessions), now - start_time,
635 (f64) pool_elts (utm->sessions) / (now - start_time));
638 rmp = vl_msg_api_alloc (sizeof (*rmp));
639 memset (rmp, 0, sizeof (*rmp));
640 rmp->_vl_msg_id = ntohs (VL_API_ACCEPT_SESSION_REPLY);
641 rmp->handle = mp->handle;
642 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & rmp);
646 vl_api_disconnect_session_t_handler (vl_api_disconnect_session_t * mp)
648 uri_udp_test_main_t *utm = &uri_udp_test_main;
650 vl_api_disconnect_session_reply_t *rmp;
654 p = hash_get (utm->session_index_by_vpp_handles, mp->handle);
658 session = pool_elt_at_index (utm->sessions, p[0]);
659 hash_unset (utm->session_index_by_vpp_handles, mp->handle);
660 pool_put (utm->sessions, session);
664 clib_warning ("couldn't find session key %llx", mp->handle);
668 rmp = vl_msg_api_alloc (sizeof (*rmp));
669 memset (rmp, 0, sizeof (*rmp));
670 rmp->_vl_msg_id = ntohs (VL_API_DISCONNECT_SESSION_REPLY);
672 rmp->handle = mp->handle;
673 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & rmp);
677 vl_api_connect_uri_reply_t_handler (vl_api_connect_uri_reply_t * mp)
679 uri_udp_test_main_t *utm = &uri_udp_test_main;
681 ASSERT (utm->i_am_master == 0);
683 /* We've been redirected */
684 if (mp->segment_name_length > 0)
686 svm_fifo_segment_main_t *sm = &svm_fifo_segment_main;
687 svm_fifo_segment_create_args_t _a, *a = &_a;
690 svm_fifo_segment_private_t *seg;
693 memset (a, 0, sizeof (*a));
694 a->segment_name = (char *) mp->segment_name;
698 rv = svm_fifo_segment_attach (a);
701 clib_warning ("sm_fifo_segment_create ('%v') failed",
706 segment_index = a->new_segment_indices[0];
707 vec_add2 (utm->seg, seg, 1);
708 memcpy (seg, sm->segments + segment_index, sizeof (*seg));
711 pool_get (utm->sessions, session);
712 utm->cut_through_session_index = session - utm->sessions;
714 session->server_rx_fifo = uword_to_pointer (mp->server_rx_fifo,
716 ASSERT (session->server_rx_fifo);
717 session->server_tx_fifo = uword_to_pointer (mp->server_tx_fifo,
719 ASSERT (session->server_tx_fifo);
722 /* security: could unlink /dev/shm/<mp->segment_name> here, maybe */
724 utm->state = STATE_READY;
727 #define foreach_uri_msg \
728 _(BIND_URI_REPLY, bind_uri_reply) \
729 _(CONNECT_URI, connect_uri) \
730 _(CONNECT_URI_REPLY, connect_uri_reply) \
731 _(UNBIND_URI_REPLY, unbind_uri_reply) \
732 _(ACCEPT_SESSION, accept_session) \
733 _(DISCONNECT_SESSION, disconnect_session) \
734 _(MAP_ANOTHER_SEGMENT, map_another_segment) \
735 _(APPLICATION_ATTACH_REPLY, application_attach_reply) \
736 _(APPLICATION_DETACH_REPLY, application_detach_reply) \
739 uri_api_hookup (uri_udp_test_main_t * utm)
742 vl_msg_api_set_handlers(VL_API_##N, #n, \
743 vl_api_##n##_t_handler, \
745 vl_api_##n##_t_endian, \
746 vl_api_##n##_t_print, \
747 sizeof(vl_api_##n##_t), 1);
754 connect_to_vpp (char *name)
756 uri_udp_test_main_t *utm = &uri_udp_test_main;
757 api_main_t *am = &api_main;
759 if (vl_client_connect_to_vlib ("/vpe-api", name, 32) < 0)
762 utm->vl_input_queue = am->shmem_hdr->vl_input_queue;
763 utm->my_client_index = am->my_client_index;
769 vlib_cli_output (struct vlib_main_t *vm, char *fmt, ...)
771 clib_warning ("BUG");
775 init_error_string_table (uri_udp_test_main_t * utm)
777 utm->error_string_by_error_number = hash_create (0, sizeof (uword));
779 #define _(n,v,s) hash_set (utm->error_string_by_error_number, -v, s);
780 foreach_vnet_api_error;
783 hash_set (utm->error_string_by_error_number, 99, "Misc");
787 server_handle_fifo_event_rx (uri_udp_test_main_t * utm,
788 session_fifo_event_t * e)
790 svm_fifo_t *rx_fifo, *tx_fifo;
793 session_fifo_event_t evt;
794 unix_shared_memory_queue_t *q;
798 tx_fifo = utm->sessions[rx_fifo->client_session_index].server_tx_fifo;
802 nbytes = svm_fifo_dequeue_nowait (rx_fifo, vec_len (utm->rx_buf),
808 rv = svm_fifo_enqueue_nowait (tx_fifo, nbytes, utm->rx_buf);
812 /* Fabricate TX event, send to vpp */
814 evt.event_type = FIFO_EVENT_APP_TX;
815 evt.event_id = e->event_id;
817 if (svm_fifo_set_event (tx_fifo))
819 q = utm->vpp_event_queue;
820 unix_shared_memory_queue_add (q, (u8 *) & evt,
821 0 /* do wait for mutex */ );
826 server_handle_event_queue (uri_udp_test_main_t * utm)
828 session_fifo_event_t _e, *e = &_e;
832 unix_shared_memory_queue_sub (utm->our_event_queue, (u8 *) e,
834 switch (e->event_type)
836 case FIFO_EVENT_APP_RX:
837 server_handle_fifo_event_rx (utm, e);
840 case FIFO_EVENT_DISCONNECT:
844 clib_warning ("unknown event type %d", e->event_type);
847 if (PREDICT_FALSE (utm->time_to_stop == 1))
849 if (PREDICT_FALSE (utm->time_to_print_stats == 1))
851 utm->time_to_print_stats = 0;
852 fformat (stdout, "%d connections\n", pool_elts (utm->sessions));
858 server_unbind (uri_udp_test_main_t * utm)
860 vl_api_unbind_uri_t *ump;
862 ump = vl_msg_api_alloc (sizeof (*ump));
863 memset (ump, 0, sizeof (*ump));
865 ump->_vl_msg_id = ntohs (VL_API_UNBIND_URI);
866 ump->client_index = utm->my_client_index;
867 memcpy (ump->uri, utm->uri, vec_len (utm->uri));
868 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & ump);
872 server_listen (uri_udp_test_main_t * utm)
874 vl_api_bind_uri_t *bmp;
876 bmp = vl_msg_api_alloc (sizeof (*bmp));
877 memset (bmp, 0, sizeof (*bmp));
879 bmp->_vl_msg_id = ntohs (VL_API_BIND_URI);
880 bmp->client_index = utm->my_client_index;
881 bmp->context = ntohl (0xfeedface);
882 memcpy (bmp->uri, utm->uri, vec_len (utm->uri));
883 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & bmp);
887 udp_server_test (uri_udp_test_main_t * utm)
890 application_send_attach (utm);
895 if (wait_for_state_change (utm, STATE_READY))
897 clib_warning ("timeout waiting for STATE_READY");
901 server_handle_event_queue (utm);
906 if (wait_for_state_change (utm, STATE_START))
908 clib_warning ("timeout waiting for STATE_START");
912 application_detach (utm);
914 fformat (stdout, "Test complete...\n");
918 main (int argc, char **argv)
920 uri_udp_test_main_t *utm = &uri_udp_test_main;
921 unformat_input_t _argv, *a = &_argv;
924 u8 *bind_name = (u8 *) "udp://0.0.0.0/1234";
931 clib_mem_init (0, 256 << 20);
933 heap = clib_mem_get_per_cpu_heap ();
934 h = mheap_header (heap);
936 /* make the main heap thread-safe */
937 h->flags |= MHEAP_FLAG_THREAD_SAFE;
939 vec_validate (utm->rx_buf, 8192);
941 utm->session_index_by_vpp_handles = hash_create (0, sizeof (uword));
943 utm->my_pid = getpid ();
944 utm->configured_segment_size = 1 << 20;
946 clib_time_init (&utm->clib_time);
947 init_error_string_table (utm);
948 svm_fifo_segment_init (0x200000000ULL, 20);
949 unformat_init_command_line (a, argv);
951 while (unformat_check_input (a) != UNFORMAT_END_OF_INPUT)
953 if (unformat (a, "chroot prefix %s", &chroot_prefix))
955 vl_set_memory_root_path ((char *) chroot_prefix);
957 else if (unformat (a, "uri %s", &bind_name))
959 else if (unformat (a, "segment-size %dM", &tmp))
960 utm->configured_segment_size = tmp << 20;
961 else if (unformat (a, "segment-size %dG", &tmp))
962 utm->configured_segment_size = tmp << 30;
963 else if (unformat (a, "master"))
965 else if (unformat (a, "slave"))
969 fformat (stderr, "%s: usage [master|slave]\n");
974 utm->cut_through_session_index = ~0;
975 utm->uri = format (0, "%s%c", bind_name, 0);
976 utm->i_am_master = i_am_master;
977 utm->segment_main = &svm_fifo_segment_main;
979 utm->connect_uri = format (0, "udp://6.0.0.1/1234%c", 0);
981 setup_signal_handlers ();
983 uri_api_hookup (utm);
985 if (connect_to_vpp (i_am_master ? "uri_udp_master" : "uri_udp_slave") < 0)
988 fformat (stderr, "Couldn't connect to vpe, exiting...\n");
992 if (i_am_master == 0)
994 uri_udp_client_test (utm);
998 /* $$$$ hack preallocation */
999 for (i = 0; i < 200000; i++)
1001 pool_get (utm->sessions, session);
1002 memset (session, 0, sizeof (*session));
1004 for (i = 0; i < 200000; i++)
1005 pool_put_index (utm->sessions, i);
1007 udp_server_test (utm);
1009 vl_client_disconnect_from_vlib ();
1013 #undef vl_api_version
1014 #define vl_api_version(n,v) static u32 vpe_api_version = v;
1015 #include <vpp/api/vpe.api.h>
1016 #undef vl_api_version
1019 vl_client_add_api_signatures (vl_api_memclnt_create_t * mp)
1022 * Send the main API signature in slot 0. This bit of code must
1023 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
1025 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);
1035 * fd.io coding-style-patch-verification: ON
1038 * eval: (c-set-style "gnu")