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_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[SESSION_OPTIONS_FLAGS] =
178 SESSION_OPTIONS_FLAGS_USE_FIFO | SESSION_OPTIONS_FLAGS_ADD_SEGMENT;
179 bmp->options[SESSION_OPTIONS_RX_FIFO_SIZE] = fifo_size;
180 bmp->options[SESSION_OPTIONS_TX_FIFO_SIZE] = fifo_size;
181 bmp->options[SESSION_OPTIONS_ADD_SEGMENT_SIZE] = 128 << 20;
182 bmp->options[SESSION_OPTIONS_SEGMENT_SIZE] = 256 << 20;
183 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & bmp);
187 application_detach (uri_udp_test_main_t * utm)
189 vl_api_application_detach_t *bmp;
190 bmp = vl_msg_api_alloc (sizeof (*bmp));
191 memset (bmp, 0, sizeof (*bmp));
193 bmp->_vl_msg_id = ntohs (VL_API_APPLICATION_DETACH);
194 bmp->client_index = utm->my_client_index;
195 bmp->context = ntohl (0xfeedface);
196 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & bmp);
200 vl_api_application_attach_reply_t_handler (vl_api_application_attach_reply_t *
203 uri_udp_test_main_t *utm = &uri_udp_test_main;
204 svm_fifo_segment_create_args_t _a, *a = &_a;
209 clib_warning ("attach failed: %d", mp->retval);
210 utm->state = STATE_FAILED;
214 if (mp->segment_name_length == 0)
216 clib_warning ("segment_name_length zero");
220 a->segment_name = (char *) mp->segment_name;
221 a->segment_size = mp->segment_size;
223 ASSERT (mp->app_event_queue_address);
225 /* Attach to the segment vpp created */
226 rv = svm_fifo_segment_attach (a);
229 clib_warning ("svm_fifo_segment_attach ('%s') failed",
234 utm->our_event_queue =
235 (unix_shared_memory_queue_t *) mp->app_event_queue_address;
239 vl_api_application_detach_reply_t_handler (vl_api_application_detach_reply_t *
243 clib_warning ("detach returned with err: %d", mp->retval);
247 format_api_error (u8 * s, va_list * args)
249 uri_udp_test_main_t *utm = va_arg (*args, uri_udp_test_main_t *);
250 i32 error = va_arg (*args, u32);
253 p = hash_get (utm->error_string_by_error_number, -error);
256 s = format (s, "%s", p[0]);
258 s = format (s, "%d", error);
263 wait_for_state_change (uri_udp_test_main_t * utm, connection_state_t state)
266 #define TIMEOUT 600.0
268 #define TIMEOUT 600.0
271 f64 timeout = clib_time_now (&utm->clib_time) + TIMEOUT;
273 while (clib_time_now (&utm->clib_time) < timeout)
275 if (utm->state == state)
281 u64 server_bytes_received, server_bytes_sent;
284 cut_through_thread_fn (void *arg)
289 u8 *my_copy_buffer = 0;
290 uri_udp_test_main_t *utm = &uri_udp_test_main;
295 while (utm->cut_through_session_index == ~0)
298 s = pool_elt_at_index (utm->sessions, utm->cut_through_session_index);
300 rx_fifo = s->server_rx_fifo;
301 tx_fifo = s->server_tx_fifo;
303 vec_validate (my_copy_buffer, 64 * 1024 - 1);
307 /* We read from the tx fifo and write to the rx fifo */
310 actual_transfer = svm_fifo_dequeue_nowait (tx_fifo, 0,
311 vec_len (my_copy_buffer),
314 while (actual_transfer <= 0);
316 server_bytes_received += actual_transfer;
319 while (actual_transfer > 0)
321 rv = svm_fifo_enqueue_nowait (rx_fifo, 0, actual_transfer,
322 my_copy_buffer + buffer_offset);
325 actual_transfer -= rv;
327 server_bytes_sent += rv;
331 if (PREDICT_FALSE (utm->time_to_stop))
339 udp_client_connect (uri_udp_test_main_t * utm)
341 vl_api_connect_uri_t *cmp;
342 cmp = vl_msg_api_alloc (sizeof (*cmp));
343 memset (cmp, 0, sizeof (*cmp));
345 cmp->_vl_msg_id = ntohs (VL_API_CONNECT_URI);
346 cmp->client_index = utm->my_client_index;
347 cmp->context = ntohl (0xfeedface);
348 memcpy (cmp->uri, utm->connect_uri, vec_len (utm->connect_uri));
349 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & cmp);
353 client_send (uri_udp_test_main_t * utm, session_t * session)
357 u64 bytes_received = 0, bytes_sent = 0;
360 int mypid = getpid ();
361 f64 before, after, delta, bytes_per_second;
362 svm_fifo_t *rx_fifo, *tx_fifo;
363 int buffer_offset, bytes_to_send = 0;
368 vec_validate (test_data, 64 * 1024 - 1);
369 for (i = 0; i < vec_len (test_data); i++)
370 test_data[i] = i & 0xff;
372 rx_fifo = session->server_rx_fifo;
373 tx_fifo = session->server_tx_fifo;
375 before = clib_time_now (&utm->clib_time);
377 vec_validate (utm->rx_buf, vec_len (test_data) - 1);
379 for (i = 0; i < NITER; i++)
381 bytes_to_send = vec_len (test_data);
383 while (bytes_to_send > 0)
385 rv = svm_fifo_enqueue_nowait (tx_fifo, mypid,
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, mypid,
407 utm->rx_buf + buffer_offset);
412 bytes_received += rv;
416 while (bytes_received < bytes_sent)
418 rv = svm_fifo_dequeue_nowait (rx_fifo, mypid,
419 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_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;
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);
550 * By construction the master's idea of the rx fifo ends up in
551 * fsh->fifos[0], and the master's idea of the tx fifo ends up in
554 session->server_rx_fifo = svm_fifo_segment_alloc_fifo (utm->seg,
556 ASSERT (session->server_rx_fifo);
558 session->server_tx_fifo = svm_fifo_segment_alloc_fifo (utm->seg,
560 ASSERT (session->server_tx_fifo);
562 session->server_rx_fifo->server_session_index = session - utm->sessions;
563 session->server_tx_fifo->server_session_index = session - utm->sessions;
564 utm->cut_through_session_index = session - utm->sessions;
566 rv = pthread_create (&utm->cut_through_thread_handle,
567 NULL /*attr */ , cut_through_thread_fn, 0);
570 clib_warning ("pthread_create returned %d", rv);
571 rv = VNET_API_ERROR_SYSCALL_ERROR_1;
575 rmp = vl_msg_api_alloc (sizeof (*rmp));
576 memset (rmp, 0, sizeof (*rmp));
578 rmp->_vl_msg_id = ntohs (VL_API_CONNECT_URI_REPLY);
579 rmp->context = mp->context;
580 rmp->retval = ntohl (rv);
581 rmp->segment_name_length = vec_len (a->segment_name);
582 memcpy (rmp->segment_name, a->segment_name, vec_len (a->segment_name));
584 vec_free (a->segment_name);
586 client_q = (unix_shared_memory_queue_t *) mp->client_queue_address;
587 vl_msg_api_send_shmem (client_q, (u8 *) & rmp);
591 vl_api_unbind_uri_reply_t_handler (vl_api_unbind_uri_reply_t * mp)
593 uri_udp_test_main_t *utm = &uri_udp_test_main;
596 clib_warning ("returned %d", ntohl (mp->retval));
598 utm->state = STATE_START;
602 vl_api_accept_session_t_handler (vl_api_accept_session_t * mp)
604 uri_udp_test_main_t *utm = &uri_udp_test_main;
605 vl_api_accept_session_reply_t *rmp;
606 svm_fifo_t *rx_fifo, *tx_fifo;
608 static f64 start_time;
610 if (start_time == 0.0)
611 start_time = clib_time_now (&utm->clib_time);
613 utm->vpp_event_queue = (unix_shared_memory_queue_t *)
614 mp->vpp_event_queue_address;
616 pool_get (utm->sessions, session);
618 rx_fifo = (svm_fifo_t *) mp->server_rx_fifo;
619 rx_fifo->client_session_index = session - utm->sessions;
620 tx_fifo = (svm_fifo_t *) mp->server_tx_fifo;
621 tx_fifo->client_session_index = session - utm->sessions;
623 session->server_rx_fifo = rx_fifo;
624 session->server_tx_fifo = tx_fifo;
626 hash_set (utm->session_index_by_vpp_handles, mp->handle,
627 session - utm->sessions);
629 utm->state = STATE_READY;
631 if (pool_elts (utm->sessions) && (pool_elts (utm->sessions) % 20000) == 0)
633 f64 now = clib_time_now (&utm->clib_time);
634 fformat (stdout, "%d active sessions in %.2f seconds, %.2f/sec...\n",
635 pool_elts (utm->sessions), now - start_time,
636 (f64) pool_elts (utm->sessions) / (now - start_time));
639 rmp = vl_msg_api_alloc (sizeof (*rmp));
640 memset (rmp, 0, sizeof (*rmp));
641 rmp->_vl_msg_id = ntohs (VL_API_ACCEPT_SESSION_REPLY);
642 rmp->handle = mp->handle;
643 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & rmp);
647 vl_api_disconnect_session_t_handler (vl_api_disconnect_session_t * mp)
649 uri_udp_test_main_t *utm = &uri_udp_test_main;
651 vl_api_disconnect_session_reply_t *rmp;
655 p = hash_get (utm->session_index_by_vpp_handles, mp->handle);
659 session = pool_elt_at_index (utm->sessions, p[0]);
660 hash_unset (utm->session_index_by_vpp_handles, mp->handle);
661 pool_put (utm->sessions, session);
665 clib_warning ("couldn't find session key %llx", mp->handle);
669 rmp = vl_msg_api_alloc (sizeof (*rmp));
670 memset (rmp, 0, sizeof (*rmp));
671 rmp->_vl_msg_id = ntohs (VL_API_DISCONNECT_SESSION_REPLY);
673 rmp->handle = mp->handle;
674 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & rmp);
678 vl_api_connect_uri_reply_t_handler (vl_api_connect_uri_reply_t * mp)
680 uri_udp_test_main_t *utm = &uri_udp_test_main;
682 ASSERT (utm->i_am_master == 0);
684 /* We've been redirected */
685 if (mp->segment_name_length > 0)
687 svm_fifo_segment_main_t *sm = &svm_fifo_segment_main;
688 svm_fifo_segment_create_args_t _a, *a = &_a;
691 ssvm_shared_header_t *sh;
692 svm_fifo_segment_private_t *seg;
693 svm_fifo_segment_header_t *fsh;
696 memset (a, 0, sizeof (*a));
697 a->segment_name = (char *) mp->segment_name;
701 rv = svm_fifo_segment_attach (a);
704 clib_warning ("sm_fifo_segment_create ('%v') failed",
709 segment_index = vec_len (sm->segments) - 1;
710 vec_add2 (utm->seg, seg, 1);
712 memcpy (seg, sm->segments + segment_index, sizeof (*seg));
714 fsh = (svm_fifo_segment_header_t *) sh->opaque[0];
716 while (vec_len (fsh->fifos) < 2)
719 pool_get (utm->sessions, session);
720 utm->cut_through_session_index = session - utm->sessions;
722 session->server_rx_fifo = (svm_fifo_t *) fsh->fifos[0];
723 ASSERT (session->server_rx_fifo);
724 session->server_tx_fifo = (svm_fifo_t *) fsh->fifos[1];
725 ASSERT (session->server_tx_fifo);
728 /* security: could unlink /dev/shm/<mp->segment_name> here, maybe */
730 utm->state = STATE_READY;
733 #define foreach_uri_msg \
734 _(BIND_URI_REPLY, bind_uri_reply) \
735 _(CONNECT_URI, connect_uri) \
736 _(CONNECT_URI_REPLY, connect_uri_reply) \
737 _(UNBIND_URI_REPLY, unbind_uri_reply) \
738 _(ACCEPT_SESSION, accept_session) \
739 _(DISCONNECT_SESSION, disconnect_session) \
740 _(MAP_ANOTHER_SEGMENT, map_another_segment) \
741 _(APPLICATION_ATTACH_REPLY, application_attach_reply) \
742 _(APPLICATION_DETACH_REPLY, application_detach_reply) \
745 uri_api_hookup (uri_udp_test_main_t * utm)
748 vl_msg_api_set_handlers(VL_API_##N, #n, \
749 vl_api_##n##_t_handler, \
751 vl_api_##n##_t_endian, \
752 vl_api_##n##_t_print, \
753 sizeof(vl_api_##n##_t), 1);
760 connect_to_vpp (char *name)
762 uri_udp_test_main_t *utm = &uri_udp_test_main;
763 api_main_t *am = &api_main;
765 if (vl_client_connect_to_vlib ("/vpe-api", name, 32) < 0)
768 utm->vl_input_queue = am->shmem_hdr->vl_input_queue;
769 utm->my_client_index = am->my_client_index;
775 vlib_cli_output (struct vlib_main_t *vm, char *fmt, ...)
777 clib_warning ("BUG");
781 init_error_string_table (uri_udp_test_main_t * utm)
783 utm->error_string_by_error_number = hash_create (0, sizeof (uword));
785 #define _(n,v,s) hash_set (utm->error_string_by_error_number, -v, s);
786 foreach_vnet_api_error;
789 hash_set (utm->error_string_by_error_number, 99, "Misc");
793 server_handle_fifo_event_rx (uri_udp_test_main_t * utm,
794 session_fifo_event_t * e)
796 svm_fifo_t *rx_fifo, *tx_fifo;
799 session_fifo_event_t evt;
800 unix_shared_memory_queue_t *q;
804 tx_fifo = utm->sessions[rx_fifo->client_session_index].server_tx_fifo;
808 nbytes = svm_fifo_dequeue_nowait (rx_fifo, 0,
809 vec_len (utm->rx_buf), utm->rx_buf);
814 rv = svm_fifo_enqueue_nowait (tx_fifo, 0, nbytes, utm->rx_buf);
818 /* Fabricate TX event, send to vpp */
820 evt.event_type = FIFO_EVENT_SERVER_TX;
821 evt.event_id = e->event_id;
823 if (svm_fifo_set_event (tx_fifo))
825 q = utm->vpp_event_queue;
826 unix_shared_memory_queue_add (q, (u8 *) & evt,
827 0 /* do wait for mutex */ );
832 server_handle_event_queue (uri_udp_test_main_t * utm)
834 session_fifo_event_t _e, *e = &_e;
838 unix_shared_memory_queue_sub (utm->our_event_queue, (u8 *) e,
840 switch (e->event_type)
842 case FIFO_EVENT_SERVER_RX:
843 server_handle_fifo_event_rx (utm, e);
846 case FIFO_EVENT_SERVER_EXIT:
850 clib_warning ("unknown event type %d", e->event_type);
853 if (PREDICT_FALSE (utm->time_to_stop == 1))
855 if (PREDICT_FALSE (utm->time_to_print_stats == 1))
857 utm->time_to_print_stats = 0;
858 fformat (stdout, "%d connections\n", pool_elts (utm->sessions));
864 server_unbind (uri_udp_test_main_t * utm)
866 vl_api_unbind_uri_t *ump;
868 ump = vl_msg_api_alloc (sizeof (*ump));
869 memset (ump, 0, sizeof (*ump));
871 ump->_vl_msg_id = ntohs (VL_API_UNBIND_URI);
872 ump->client_index = utm->my_client_index;
873 memcpy (ump->uri, utm->uri, vec_len (utm->uri));
874 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & ump);
878 server_listen (uri_udp_test_main_t * utm)
880 vl_api_bind_uri_t *bmp;
882 bmp = vl_msg_api_alloc (sizeof (*bmp));
883 memset (bmp, 0, sizeof (*bmp));
885 bmp->_vl_msg_id = ntohs (VL_API_BIND_URI);
886 bmp->client_index = utm->my_client_index;
887 bmp->context = ntohl (0xfeedface);
888 memcpy (bmp->uri, utm->uri, vec_len (utm->uri));
889 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & bmp);
893 udp_server_test (uri_udp_test_main_t * utm)
896 application_attach (utm);
901 if (wait_for_state_change (utm, STATE_READY))
903 clib_warning ("timeout waiting for STATE_READY");
907 server_handle_event_queue (utm);
912 if (wait_for_state_change (utm, STATE_START))
914 clib_warning ("timeout waiting for STATE_START");
918 application_detach (utm);
920 fformat (stdout, "Test complete...\n");
924 main (int argc, char **argv)
926 uri_udp_test_main_t *utm = &uri_udp_test_main;
927 unformat_input_t _argv, *a = &_argv;
930 u8 *bind_name = (u8 *) "udp://0.0.0.0/1234";
937 clib_mem_init (0, 256 << 20);
939 heap = clib_mem_get_per_cpu_heap ();
940 h = mheap_header (heap);
942 /* make the main heap thread-safe */
943 h->flags |= MHEAP_FLAG_THREAD_SAFE;
945 vec_validate (utm->rx_buf, 8192);
947 utm->session_index_by_vpp_handles = hash_create (0, sizeof (uword));
949 utm->my_pid = getpid ();
950 utm->configured_segment_size = 1 << 20;
952 clib_time_init (&utm->clib_time);
953 init_error_string_table (utm);
954 svm_fifo_segment_init (0x200000000ULL, 20);
955 unformat_init_command_line (a, argv);
957 while (unformat_check_input (a) != UNFORMAT_END_OF_INPUT)
959 if (unformat (a, "chroot prefix %s", &chroot_prefix))
961 vl_set_memory_root_path ((char *) chroot_prefix);
963 else if (unformat (a, "uri %s", &bind_name))
965 else if (unformat (a, "segment-size %dM", &tmp))
966 utm->configured_segment_size = tmp << 20;
967 else if (unformat (a, "segment-size %dG", &tmp))
968 utm->configured_segment_size = tmp << 30;
969 else if (unformat (a, "master"))
971 else if (unformat (a, "slave"))
975 fformat (stderr, "%s: usage [master|slave]\n");
980 utm->cut_through_session_index = ~0;
981 utm->uri = format (0, "%s%c", bind_name, 0);
982 utm->i_am_master = i_am_master;
983 utm->segment_main = &svm_fifo_segment_main;
985 utm->connect_uri = format (0, "udp://6.0.0.1/1234%c", 0);
987 setup_signal_handlers ();
989 uri_api_hookup (utm);
991 if (connect_to_vpp (i_am_master ? "uri_udp_master" : "uri_udp_slave") < 0)
994 fformat (stderr, "Couldn't connect to vpe, exiting...\n");
998 if (i_am_master == 0)
1000 uri_udp_client_test (utm);
1004 /* $$$$ hack preallocation */
1005 for (i = 0; i < 200000; i++)
1007 pool_get (utm->sessions, session);
1008 memset (session, 0, sizeof (*session));
1010 for (i = 0; i < 200000; i++)
1011 pool_put_index (utm->sessions, i);
1013 udp_server_test (utm);
1015 vl_client_disconnect_from_vlib ();
1019 #undef vl_api_version
1020 #define vl_api_version(n,v) static u32 vpe_api_version = v;
1021 #include <vpp/api/vpe.api.h>
1022 #undef vl_api_version
1025 vl_client_add_api_signatures (vl_api_memclnt_create_t * mp)
1028 * Send the main API signature in slot 0. This bit of code must
1029 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
1031 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);
1041 * fd.io coding-style-patch-verification: ON
1044 * eval: (c-set-style "gnu")