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>
50 /* Satisfy external references when not linking with -lvlib */
51 vlib_main_t vlib_global_main;
52 vlib_main_t **vlib_mains;
64 svm_fifo_t *server_rx_fifo;
65 svm_fifo_t *server_tx_fifo;
71 unix_shared_memory_queue_t *vl_input_queue;
73 /* API client handle */
76 /* The URI we're playing with */
82 /* Hash table for disconnect processing */
83 uword *session_index_by_vpp_handles;
86 svm_fifo_segment_private_t *seg;
88 /* intermediate rx buffer */
97 unix_shared_memory_queue_t *our_event_queue;
99 /* $$$ single thread only for the moment */
100 unix_shared_memory_queue_t *vpp_event_queue;
102 /* $$$$ hack: cut-through session index */
103 volatile u32 cut_through_session_index;
105 /* unique segment name counter */
106 u32 unique_segment_index;
111 pthread_t cut_through_thread_handle;
113 /* For deadman timers */
114 clib_time_t clib_time;
116 /* State of the connection, shared between msg RX thread and main thread */
117 volatile connection_state_t state;
119 volatile int time_to_stop;
120 volatile int time_to_print_stats;
122 u32 configured_segment_size;
124 /* VNET_API_ERROR_FOO -> "Foo" hash table */
125 uword *error_string_by_error_number;
128 svm_fifo_segment_main_t *segment_main;
130 } uri_udp_test_main_t;
135 #define NITER 4000000
138 uri_udp_test_main_t uri_udp_test_main;
141 stop_signal (int signum)
143 uri_udp_test_main_t *um = &uri_udp_test_main;
145 um->time_to_stop = 1;
149 stats_signal (int signum)
151 uri_udp_test_main_t *um = &uri_udp_test_main;
153 um->time_to_print_stats = 1;
156 static clib_error_t *
157 setup_signal_handlers (void)
159 signal (SIGINT, stats_signal);
160 signal (SIGQUIT, stop_signal);
161 signal (SIGTERM, stop_signal);
167 application_send_attach (uri_udp_test_main_t * utm)
169 vl_api_application_attach_t *bmp;
170 u32 fifo_size = 3 << 20;
171 bmp = vl_msg_api_alloc (sizeof (*bmp));
172 memset (bmp, 0, sizeof (*bmp));
174 bmp->_vl_msg_id = ntohs (VL_API_APPLICATION_ATTACH);
175 bmp->client_index = utm->my_client_index;
176 bmp->context = ntohl (0xfeedface);
177 bmp->options[APP_OPTIONS_FLAGS] =
178 APP_OPTIONS_FLAGS_USE_FIFO | APP_OPTIONS_FLAGS_ADD_SEGMENT;
179 bmp->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] = 16;
180 bmp->options[SESSION_OPTIONS_RX_FIFO_SIZE] = fifo_size;
181 bmp->options[SESSION_OPTIONS_TX_FIFO_SIZE] = fifo_size;
182 bmp->options[SESSION_OPTIONS_ADD_SEGMENT_SIZE] = 128 << 20;
183 bmp->options[SESSION_OPTIONS_SEGMENT_SIZE] = 256 << 20;
184 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & bmp);
188 application_detach (uri_udp_test_main_t * utm)
190 vl_api_application_detach_t *bmp;
191 bmp = vl_msg_api_alloc (sizeof (*bmp));
192 memset (bmp, 0, sizeof (*bmp));
194 bmp->_vl_msg_id = ntohs (VL_API_APPLICATION_DETACH);
195 bmp->client_index = utm->my_client_index;
196 bmp->context = ntohl (0xfeedface);
197 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & bmp);
201 vl_api_application_attach_reply_t_handler (vl_api_application_attach_reply_t *
204 uri_udp_test_main_t *utm = &uri_udp_test_main;
205 svm_fifo_segment_create_args_t _a, *a = &_a;
210 clib_warning ("attach failed: %d", mp->retval);
211 utm->state = STATE_FAILED;
215 if (mp->segment_name_length == 0)
217 clib_warning ("segment_name_length zero");
221 a->segment_name = (char *) mp->segment_name;
222 a->segment_size = mp->segment_size;
224 ASSERT (mp->app_event_queue_address);
226 /* Attach to the segment vpp created */
227 rv = svm_fifo_segment_attach (a);
230 clib_warning ("svm_fifo_segment_attach ('%s') failed",
235 utm->our_event_queue =
236 uword_to_pointer (mp->app_event_queue_address,
237 unix_shared_memory_queue_t *);
241 vl_api_application_detach_reply_t_handler (vl_api_application_detach_reply_t *
245 clib_warning ("detach returned with err: %d", mp->retval);
249 format_api_error (u8 * s, va_list * args)
251 uri_udp_test_main_t *utm = va_arg (*args, uri_udp_test_main_t *);
252 i32 error = va_arg (*args, u32);
255 p = hash_get (utm->error_string_by_error_number, -error);
258 s = format (s, "%s", p[0]);
260 s = format (s, "%d", error);
265 wait_for_state_change (uri_udp_test_main_t * utm, connection_state_t state)
268 #define TIMEOUT 600.0
270 #define TIMEOUT 600.0
273 f64 timeout = clib_time_now (&utm->clib_time) + TIMEOUT;
275 while (clib_time_now (&utm->clib_time) < timeout)
277 if (utm->state == state)
283 u64 server_bytes_received, server_bytes_sent;
286 cut_through_thread_fn (void *arg)
291 u8 *my_copy_buffer = 0;
292 uri_udp_test_main_t *utm = &uri_udp_test_main;
297 while (utm->cut_through_session_index == ~0)
300 s = pool_elt_at_index (utm->sessions, utm->cut_through_session_index);
302 rx_fifo = s->server_rx_fifo;
303 tx_fifo = s->server_tx_fifo;
305 vec_validate (my_copy_buffer, 64 * 1024 - 1);
309 /* We read from the tx fifo and write to the rx fifo */
312 actual_transfer = svm_fifo_dequeue_nowait (tx_fifo,
313 vec_len (my_copy_buffer),
316 while (actual_transfer <= 0);
318 server_bytes_received += actual_transfer;
321 while (actual_transfer > 0)
323 rv = svm_fifo_enqueue_nowait (rx_fifo, actual_transfer,
324 my_copy_buffer + buffer_offset);
327 actual_transfer -= rv;
329 server_bytes_sent += rv;
333 if (PREDICT_FALSE (utm->time_to_stop))
341 udp_client_connect (uri_udp_test_main_t * utm)
343 vl_api_connect_uri_t *cmp;
344 cmp = vl_msg_api_alloc (sizeof (*cmp));
345 memset (cmp, 0, sizeof (*cmp));
347 cmp->_vl_msg_id = ntohs (VL_API_CONNECT_URI);
348 cmp->client_index = utm->my_client_index;
349 cmp->context = ntohl (0xfeedface);
350 memcpy (cmp->uri, utm->connect_uri, vec_len (utm->connect_uri));
351 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & cmp);
355 client_send (uri_udp_test_main_t * utm, session_t * session)
359 u64 bytes_received = 0, bytes_sent = 0;
362 f64 before, after, delta, bytes_per_second;
363 svm_fifo_t *rx_fifo, *tx_fifo;
364 int buffer_offset, bytes_to_send = 0;
369 vec_validate (test_data, 64 * 1024 - 1);
370 for (i = 0; i < vec_len (test_data); i++)
371 test_data[i] = i & 0xff;
373 rx_fifo = session->server_rx_fifo;
374 tx_fifo = session->server_tx_fifo;
376 before = clib_time_now (&utm->clib_time);
378 vec_validate (utm->rx_buf, vec_len (test_data) - 1);
380 for (i = 0; i < NITER; i++)
382 bytes_to_send = vec_len (test_data);
384 while (bytes_to_send > 0)
386 rv = svm_fifo_enqueue_nowait (tx_fifo, bytes_to_send,
387 test_data + buffer_offset);
397 bytes_to_read = svm_fifo_max_dequeue (rx_fifo);
399 bytes_to_read = vec_len (utm->rx_buf) > bytes_to_read ?
400 bytes_to_read : vec_len (utm->rx_buf);
403 while (bytes_to_read > 0)
405 rv = svm_fifo_dequeue_nowait (rx_fifo,
407 utm->rx_buf + buffer_offset);
412 bytes_received += rv;
416 while (bytes_received < bytes_sent)
419 svm_fifo_dequeue_nowait (rx_fifo, vec_len (utm->rx_buf), utm->rx_buf);
424 for (j = 0; j < rv; j++)
426 if (utm->rx_buf[j] != ((bytes_received + j) & 0xff))
428 clib_warning ("error at byte %lld, 0x%x not 0x%x",
431 ((bytes_received + j) & 0xff));
435 bytes_received += (u64) rv;
439 after = clib_time_now (&utm->clib_time);
440 delta = after - before;
441 bytes_per_second = 0.0;
444 bytes_per_second = (f64) bytes_received / delta;
447 "Done: %lld recv bytes in %.2f seconds, %.2f bytes/sec...\n\n",
448 bytes_received, delta, bytes_per_second);
450 "Done: %lld sent bytes in %.2f seconds, %.2f bytes/sec...\n\n",
451 bytes_sent, delta, bytes_per_second);
453 "client -> server -> client round trip: %.2f Gbit/sec \n\n",
454 (bytes_per_second * 8.0) / 1e9);
458 uri_udp_client_test (uri_udp_test_main_t * utm)
462 application_send_attach (utm);
463 udp_client_connect (utm);
465 if (wait_for_state_change (utm, STATE_READY))
467 clib_warning ("timeout waiting for STATE_READY");
471 /* Only works with cut through sessions */
472 session = pool_elt_at_index (utm->sessions, utm->cut_through_session_index);
474 client_send (utm, session);
475 application_detach (utm);
479 vl_api_bind_uri_reply_t_handler (vl_api_bind_uri_reply_t * mp)
481 uri_udp_test_main_t *utm = &uri_udp_test_main;
485 clib_warning ("bind failed: %d", mp->retval);
486 utm->state = STATE_FAILED;
490 utm->state = STATE_READY;
494 vl_api_map_another_segment_t_handler (vl_api_map_another_segment_t * mp)
496 svm_fifo_segment_create_args_t _a, *a = &_a;
499 a->segment_name = (char *) mp->segment_name;
500 a->segment_size = mp->segment_size;
501 /* Attach to the segment vpp created */
502 rv = svm_fifo_segment_attach (a);
505 clib_warning ("svm_fifo_segment_attach ('%s') failed",
509 clib_warning ("Mapped new segment '%s' size %d", mp->segment_name,
514 * Acting as server for redirected connect requests
517 vl_api_connect_uri_t_handler (vl_api_connect_uri_t * mp)
520 uri_udp_test_main_t *utm = &uri_udp_test_main;
521 svm_fifo_segment_main_t *sm = &svm_fifo_segment_main;
522 svm_fifo_segment_create_args_t _a, *a = &_a;
523 svm_fifo_segment_private_t *seg;
524 unix_shared_memory_queue_t *client_q;
525 vl_api_connect_uri_reply_t *rmp;
526 session_t *session = 0;
529 /* Create the segment */
530 a->segment_name = (char *) format (0, "%d:segment%d%c", utm->my_pid,
531 utm->unique_segment_index++, 0);
532 a->segment_size = utm->configured_segment_size;
534 rv = svm_fifo_segment_create (a);
537 clib_warning ("sm_fifo_segment_create ('%s') failed", a->segment_name);
538 rv = VNET_API_ERROR_URI_FIFO_CREATE_FAILED;
542 vec_add2 (utm->seg, seg, 1);
544 segment_index = vec_len (sm->segments) - 1;
545 memcpy (seg, sm->segments + segment_index, sizeof (utm->seg[0]));
547 pool_get (utm->sessions, session);
549 session->server_rx_fifo = svm_fifo_segment_alloc_fifo
550 (utm->seg, 128 * 1024, FIFO_SEGMENT_RX_FREELIST);
551 ASSERT (session->server_rx_fifo);
553 session->server_tx_fifo = svm_fifo_segment_alloc_fifo
554 (utm->seg, 128 * 1024, FIFO_SEGMENT_TX_FREELIST);
555 ASSERT (session->server_tx_fifo);
557 session->server_rx_fifo->master_session_index = session - utm->sessions;
558 session->server_tx_fifo->master_session_index = session - utm->sessions;
559 utm->cut_through_session_index = session - utm->sessions;
561 rv = pthread_create (&utm->cut_through_thread_handle,
562 NULL /*attr */ , cut_through_thread_fn, 0);
565 clib_warning ("pthread_create returned %d", rv);
566 rv = VNET_API_ERROR_SYSCALL_ERROR_1;
570 rmp = vl_msg_api_alloc (sizeof (*rmp));
571 memset (rmp, 0, sizeof (*rmp));
573 rmp->_vl_msg_id = ntohs (VL_API_CONNECT_URI_REPLY);
574 rmp->context = mp->context;
575 rmp->retval = ntohl (rv);
576 rmp->segment_name_length = vec_len (a->segment_name);
579 rmp->server_rx_fifo = pointer_to_uword (session->server_rx_fifo);
580 rmp->server_tx_fifo = pointer_to_uword (session->server_tx_fifo);
583 memcpy (rmp->segment_name, a->segment_name, vec_len (a->segment_name));
585 vec_free (a->segment_name);
588 uword_to_pointer (mp->client_queue_address, unix_shared_memory_queue_t *);
589 vl_msg_api_send_shmem (client_q, (u8 *) & rmp);
593 vl_api_unbind_uri_reply_t_handler (vl_api_unbind_uri_reply_t * mp)
595 uri_udp_test_main_t *utm = &uri_udp_test_main;
598 clib_warning ("returned %d", ntohl (mp->retval));
600 utm->state = STATE_START;
604 vl_api_accept_session_t_handler (vl_api_accept_session_t * mp)
606 uri_udp_test_main_t *utm = &uri_udp_test_main;
607 vl_api_accept_session_reply_t *rmp;
608 svm_fifo_t *rx_fifo, *tx_fifo;
610 static f64 start_time;
612 if (start_time == 0.0)
613 start_time = clib_time_now (&utm->clib_time);
615 utm->vpp_event_queue =
616 uword_to_pointer (mp->vpp_event_queue_address,
617 unix_shared_memory_queue_t *);
619 pool_get (utm->sessions, session);
621 rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *);
622 rx_fifo->client_session_index = session - utm->sessions;
623 tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *);
624 tx_fifo->client_session_index = session - utm->sessions;
626 session->server_rx_fifo = rx_fifo;
627 session->server_tx_fifo = tx_fifo;
629 hash_set (utm->session_index_by_vpp_handles, mp->handle,
630 session - utm->sessions);
632 utm->state = STATE_READY;
634 if (pool_elts (utm->sessions) && (pool_elts (utm->sessions) % 20000) == 0)
636 f64 now = clib_time_now (&utm->clib_time);
637 fformat (stdout, "%d active sessions in %.2f seconds, %.2f/sec...\n",
638 pool_elts (utm->sessions), now - start_time,
639 (f64) pool_elts (utm->sessions) / (now - start_time));
642 rmp = vl_msg_api_alloc (sizeof (*rmp));
643 memset (rmp, 0, sizeof (*rmp));
644 rmp->_vl_msg_id = ntohs (VL_API_ACCEPT_SESSION_REPLY);
645 rmp->handle = mp->handle;
646 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & rmp);
650 vl_api_disconnect_session_t_handler (vl_api_disconnect_session_t * mp)
652 uri_udp_test_main_t *utm = &uri_udp_test_main;
654 vl_api_disconnect_session_reply_t *rmp;
658 p = hash_get (utm->session_index_by_vpp_handles, mp->handle);
662 session = pool_elt_at_index (utm->sessions, p[0]);
663 hash_unset (utm->session_index_by_vpp_handles, mp->handle);
664 pool_put (utm->sessions, session);
668 clib_warning ("couldn't find session key %llx", mp->handle);
672 rmp = vl_msg_api_alloc (sizeof (*rmp));
673 memset (rmp, 0, sizeof (*rmp));
674 rmp->_vl_msg_id = ntohs (VL_API_DISCONNECT_SESSION_REPLY);
676 rmp->handle = mp->handle;
677 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & rmp);
681 vl_api_connect_uri_reply_t_handler (vl_api_connect_uri_reply_t * mp)
683 uri_udp_test_main_t *utm = &uri_udp_test_main;
685 ASSERT (utm->i_am_master == 0);
687 /* We've been redirected */
688 if (mp->segment_name_length > 0)
690 svm_fifo_segment_main_t *sm = &svm_fifo_segment_main;
691 svm_fifo_segment_create_args_t _a, *a = &_a;
694 svm_fifo_segment_private_t *seg;
697 memset (a, 0, sizeof (*a));
698 a->segment_name = (char *) mp->segment_name;
702 rv = svm_fifo_segment_attach (a);
705 clib_warning ("sm_fifo_segment_create ('%v') failed",
710 segment_index = a->new_segment_index;
711 vec_add2 (utm->seg, seg, 1);
712 memcpy (seg, sm->segments + segment_index, sizeof (*seg));
715 pool_get (utm->sessions, session);
716 utm->cut_through_session_index = session - utm->sessions;
718 session->server_rx_fifo = uword_to_pointer (mp->server_rx_fifo,
720 ASSERT (session->server_rx_fifo);
721 session->server_tx_fifo = uword_to_pointer (mp->server_tx_fifo,
723 ASSERT (session->server_tx_fifo);
726 /* security: could unlink /dev/shm/<mp->segment_name> here, maybe */
728 utm->state = STATE_READY;
731 #define foreach_uri_msg \
732 _(BIND_URI_REPLY, bind_uri_reply) \
733 _(CONNECT_URI, connect_uri) \
734 _(CONNECT_URI_REPLY, connect_uri_reply) \
735 _(UNBIND_URI_REPLY, unbind_uri_reply) \
736 _(ACCEPT_SESSION, accept_session) \
737 _(DISCONNECT_SESSION, disconnect_session) \
738 _(MAP_ANOTHER_SEGMENT, map_another_segment) \
739 _(APPLICATION_ATTACH_REPLY, application_attach_reply) \
740 _(APPLICATION_DETACH_REPLY, application_detach_reply) \
743 uri_api_hookup (uri_udp_test_main_t * utm)
746 vl_msg_api_set_handlers(VL_API_##N, #n, \
747 vl_api_##n##_t_handler, \
749 vl_api_##n##_t_endian, \
750 vl_api_##n##_t_print, \
751 sizeof(vl_api_##n##_t), 1);
758 connect_to_vpp (char *name)
760 uri_udp_test_main_t *utm = &uri_udp_test_main;
761 api_main_t *am = &api_main;
763 if (vl_client_connect_to_vlib ("/vpe-api", name, 32) < 0)
766 utm->vl_input_queue = am->shmem_hdr->vl_input_queue;
767 utm->my_client_index = am->my_client_index;
773 vlib_cli_output (struct vlib_main_t *vm, char *fmt, ...)
775 clib_warning ("BUG");
779 init_error_string_table (uri_udp_test_main_t * utm)
781 utm->error_string_by_error_number = hash_create (0, sizeof (uword));
783 #define _(n,v,s) hash_set (utm->error_string_by_error_number, -v, s);
784 foreach_vnet_api_error;
787 hash_set (utm->error_string_by_error_number, 99, "Misc");
791 server_handle_fifo_event_rx (uri_udp_test_main_t * utm,
792 session_fifo_event_t * e)
794 svm_fifo_t *rx_fifo, *tx_fifo;
797 session_fifo_event_t evt;
798 unix_shared_memory_queue_t *q;
802 tx_fifo = utm->sessions[rx_fifo->client_session_index].server_tx_fifo;
806 nbytes = svm_fifo_dequeue_nowait (rx_fifo, vec_len (utm->rx_buf),
812 rv = svm_fifo_enqueue_nowait (tx_fifo, nbytes, utm->rx_buf);
816 /* Fabricate TX event, send to vpp */
818 evt.event_type = FIFO_EVENT_APP_TX;
819 evt.event_id = e->event_id;
821 if (svm_fifo_set_event (tx_fifo))
823 q = utm->vpp_event_queue;
824 unix_shared_memory_queue_add (q, (u8 *) & evt,
825 0 /* do wait for mutex */ );
830 server_handle_event_queue (uri_udp_test_main_t * utm)
832 session_fifo_event_t _e, *e = &_e;
836 unix_shared_memory_queue_sub (utm->our_event_queue, (u8 *) e,
838 switch (e->event_type)
840 case FIFO_EVENT_APP_RX:
841 server_handle_fifo_event_rx (utm, e);
844 case FIFO_EVENT_DISCONNECT:
848 clib_warning ("unknown event type %d", e->event_type);
851 if (PREDICT_FALSE (utm->time_to_stop == 1))
853 if (PREDICT_FALSE (utm->time_to_print_stats == 1))
855 utm->time_to_print_stats = 0;
856 fformat (stdout, "%d connections\n", pool_elts (utm->sessions));
862 server_unbind (uri_udp_test_main_t * utm)
864 vl_api_unbind_uri_t *ump;
866 ump = vl_msg_api_alloc (sizeof (*ump));
867 memset (ump, 0, sizeof (*ump));
869 ump->_vl_msg_id = ntohs (VL_API_UNBIND_URI);
870 ump->client_index = utm->my_client_index;
871 memcpy (ump->uri, utm->uri, vec_len (utm->uri));
872 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & ump);
876 server_listen (uri_udp_test_main_t * utm)
878 vl_api_bind_uri_t *bmp;
880 bmp = vl_msg_api_alloc (sizeof (*bmp));
881 memset (bmp, 0, sizeof (*bmp));
883 bmp->_vl_msg_id = ntohs (VL_API_BIND_URI);
884 bmp->client_index = utm->my_client_index;
885 bmp->context = ntohl (0xfeedface);
886 memcpy (bmp->uri, utm->uri, vec_len (utm->uri));
887 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & bmp);
891 udp_server_test (uri_udp_test_main_t * utm)
894 application_send_attach (utm);
899 if (wait_for_state_change (utm, STATE_READY))
901 clib_warning ("timeout waiting for STATE_READY");
905 server_handle_event_queue (utm);
910 if (wait_for_state_change (utm, STATE_START))
912 clib_warning ("timeout waiting for STATE_START");
916 application_detach (utm);
918 fformat (stdout, "Test complete...\n");
922 main (int argc, char **argv)
924 uri_udp_test_main_t *utm = &uri_udp_test_main;
925 unformat_input_t _argv, *a = &_argv;
928 u8 *bind_name = (u8 *) "udp://0.0.0.0/1234";
935 clib_mem_init (0, 256 << 20);
937 heap = clib_mem_get_per_cpu_heap ();
938 h = mheap_header (heap);
940 /* make the main heap thread-safe */
941 h->flags |= MHEAP_FLAG_THREAD_SAFE;
943 vec_validate (utm->rx_buf, 8192);
945 utm->session_index_by_vpp_handles = hash_create (0, sizeof (uword));
947 utm->my_pid = getpid ();
948 utm->configured_segment_size = 1 << 20;
950 clib_time_init (&utm->clib_time);
951 init_error_string_table (utm);
952 svm_fifo_segment_init (0x200000000ULL, 20);
953 unformat_init_command_line (a, argv);
955 while (unformat_check_input (a) != UNFORMAT_END_OF_INPUT)
957 if (unformat (a, "chroot prefix %s", &chroot_prefix))
959 vl_set_memory_root_path ((char *) chroot_prefix);
961 else if (unformat (a, "uri %s", &bind_name))
963 else if (unformat (a, "segment-size %dM", &tmp))
964 utm->configured_segment_size = tmp << 20;
965 else if (unformat (a, "segment-size %dG", &tmp))
966 utm->configured_segment_size = tmp << 30;
967 else if (unformat (a, "master"))
969 else if (unformat (a, "slave"))
973 fformat (stderr, "%s: usage [master|slave]\n");
978 utm->cut_through_session_index = ~0;
979 utm->uri = format (0, "%s%c", bind_name, 0);
980 utm->i_am_master = i_am_master;
981 utm->segment_main = &svm_fifo_segment_main;
983 utm->connect_uri = format (0, "udp://6.0.0.1/1234%c", 0);
985 setup_signal_handlers ();
987 uri_api_hookup (utm);
989 if (connect_to_vpp (i_am_master ? "uri_udp_master" : "uri_udp_slave") < 0)
992 fformat (stderr, "Couldn't connect to vpe, exiting...\n");
996 if (i_am_master == 0)
998 uri_udp_client_test (utm);
1002 /* $$$$ hack preallocation */
1003 for (i = 0; i < 200000; i++)
1005 pool_get (utm->sessions, session);
1006 memset (session, 0, sizeof (*session));
1008 for (i = 0; i < 200000; i++)
1009 pool_put_index (utm->sessions, i);
1011 udp_server_test (utm);
1013 vl_client_disconnect_from_vlib ();
1017 #undef vl_api_version
1018 #define vl_api_version(n,v) static u32 vpe_api_version = v;
1019 #include <vpp/api/vpe.api.h>
1020 #undef vl_api_version
1023 vl_client_add_api_signatures (vl_api_memclnt_create_t * mp)
1026 * Send the main API signature in slot 0. This bit of code must
1027 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
1029 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);
1039 * fd.io coding-style-patch-verification: ON
1042 * eval: (c-set-style "gnu")