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.
18 #include <vlib/vlib.h>
19 #include <vnet/vnet.h>
20 #include <svm/svm_fifo_segment.h>
21 #include <vlibmemory/api.h>
22 #include <vpp/api/vpe_msg_enum.h>
23 #include <vnet/session/application_interface.h>
25 #define vl_typedefs /* define message structures */
26 #include <vpp/api/vpe_all_api_h.h>
29 /* declare message handlers for each api */
31 #define vl_endianfun /* define message structures */
32 #include <vpp/api/vpe_all_api_h.h>
35 /* instantiate all the print functions we know about */
36 #define vl_print(handle, ...)
38 #include <vpp/api/vpe_all_api_h.h>
41 /* Satisfy external references when not linking with -lvlib */
42 vlib_main_t vlib_global_main;
43 vlib_main_t **vlib_mains;
47 svm_fifo_t *server_rx_fifo;
48 svm_fifo_t *server_tx_fifo;
50 u32 vpp_session_index;
51 u32 vpp_session_thread;
65 unix_shared_memory_queue_t *vl_input_queue;
67 /* API client handle */
70 /* The URI we're playing with */
76 /* Hash table for disconnect processing */
77 uword *session_index_by_vpp_handles;
79 /* intermediate rx buffer */
82 /* URI for slave's connect */
85 u32 connected_session_index;
89 /* drop all packets */
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;
100 /* For deadman timers */
101 clib_time_t clib_time;
103 /* State of the connection, shared between msg RX thread and main thread */
104 volatile connection_state_t state;
106 /* Signal variables */
107 volatile int time_to_stop;
108 volatile int time_to_print_stats;
110 u32 configured_segment_size;
112 /* VNET_API_ERROR_FOO -> "Foo" hash table */
113 uword *error_string_by_error_number;
115 u8 *connect_test_data;
116 pthread_t client_rx_thread_handle;
117 u32 client_bytes_received;
118 u8 test_return_packets;
121 svm_fifo_segment_main_t *segment_main;
122 } uri_tcp_test_main_t;
124 uri_tcp_test_main_t uri_tcp_test_main;
129 #define NITER 4000000
133 wait_for_state_change (uri_tcp_test_main_t * utm, connection_state_t state)
136 #define TIMEOUT 600.0
138 #define TIMEOUT 600.0
141 f64 timeout = clib_time_now (&utm->clib_time) + TIMEOUT;
143 while (clib_time_now (&utm->clib_time) < timeout)
145 if (utm->state == state)
147 if (utm->state == STATE_FAILED)
150 clib_warning ("timeout waiting for STATE_READY");
155 init_error_string_table (uri_tcp_test_main_t * utm)
157 utm->error_string_by_error_number = hash_create (0, sizeof (uword));
159 #define _(n,v,s) hash_set (utm->error_string_by_error_number, -v, s);
160 foreach_vnet_api_error;
163 hash_set (utm->error_string_by_error_number, 99, "Misc");
167 stop_signal (int signum)
169 uri_tcp_test_main_t *um = &uri_tcp_test_main;
171 um->time_to_stop = 1;
175 stats_signal (int signum)
177 uri_tcp_test_main_t *um = &uri_tcp_test_main;
179 um->time_to_print_stats = 1;
182 static clib_error_t *
183 setup_signal_handlers (void)
185 signal (SIGINT, stats_signal);
186 signal (SIGQUIT, stop_signal);
187 signal (SIGTERM, stop_signal);
193 vlib_cli_output (struct vlib_main_t *vm, char *fmt, ...)
195 clib_warning ("BUG");
199 connect_to_vpp (char *name)
201 uri_tcp_test_main_t *utm = &uri_tcp_test_main;
202 api_main_t *am = &api_main;
204 if (vl_client_connect_to_vlib ("/vpe-api", name, 32) < 0)
207 utm->vl_input_queue = am->shmem_hdr->vl_input_queue;
208 utm->my_client_index = am->my_client_index;
214 vl_api_map_another_segment_t_handler (vl_api_map_another_segment_t * mp)
216 svm_fifo_segment_create_args_t _a, *a = &_a;
219 a->segment_name = (char *) mp->segment_name;
220 a->segment_size = mp->segment_size;
221 /* Attach to the segment vpp created */
222 rv = svm_fifo_segment_attach (a);
225 clib_warning ("svm_fifo_segment_attach ('%s') failed",
229 clib_warning ("Mapped new segment '%s' size %d", mp->segment_name,
234 vl_api_disconnect_session_t_handler (vl_api_disconnect_session_t * mp)
236 uri_tcp_test_main_t *utm = &uri_tcp_test_main;
238 vl_api_disconnect_session_reply_t *rmp;
243 key = (((u64) mp->session_thread_index) << 32) | (u64) mp->session_index;
245 p = hash_get (utm->session_index_by_vpp_handles, key);
249 session = pool_elt_at_index (utm->sessions, p[0]);
250 hash_unset (utm->session_index_by_vpp_handles, key);
251 pool_put (utm->sessions, session);
255 clib_warning ("couldn't find session key %llx", key);
259 utm->time_to_stop = 1;
261 rmp = vl_msg_api_alloc (sizeof (*rmp));
262 memset (rmp, 0, sizeof (*rmp));
264 rmp->_vl_msg_id = ntohs (VL_API_DISCONNECT_SESSION_REPLY);
266 rmp->session_index = mp->session_index;
267 rmp->session_thread_index = mp->session_thread_index;
268 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & rmp);
272 vl_api_reset_session_t_handler (vl_api_reset_session_t * mp)
274 uri_tcp_test_main_t *utm = &uri_tcp_test_main;
276 vl_api_reset_session_reply_t *rmp;
281 key = (((u64) mp->session_thread_index) << 32) | (u64) mp->session_index;
283 p = hash_get (utm->session_index_by_vpp_handles, key);
287 session = pool_elt_at_index (utm->sessions, p[0]);
288 hash_unset (utm->session_index_by_vpp_handles, key);
289 pool_put (utm->sessions, session);
290 utm->time_to_stop = 1;
294 clib_warning ("couldn't find session key %llx", key);
298 rmp = vl_msg_api_alloc (sizeof (*rmp));
299 memset (rmp, 0, sizeof (*rmp));
300 rmp->_vl_msg_id = ntohs (VL_API_RESET_SESSION_REPLY);
302 rmp->session_index = mp->session_index;
303 rmp->session_thread_index = mp->session_thread_index;
304 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & rmp);
308 client_handle_fifo_event_rx (uri_tcp_test_main_t * utm,
309 session_fifo_event_t * e)
312 int n_read, bytes, i;
316 bytes = e->enqueue_length;
319 n_read = svm_fifo_dequeue_nowait (rx_fifo, 0, vec_len (utm->rx_buf),
324 for (i = 0; i < n_read; i++)
326 if (utm->rx_buf[i] != ((utm->client_bytes_received + i) & 0xff))
328 clib_warning ("error at byte %lld, 0x%x not 0x%x",
329 utm->client_bytes_received + i,
331 ((utm->client_bytes_received + i) & 0xff));
334 utm->client_bytes_received += n_read;
338 while (n_read < 0 || bytes > 0);
342 client_handle_event_queue (uri_tcp_test_main_t * utm)
344 session_fifo_event_t _e, *e = &_e;;
346 unix_shared_memory_queue_sub (utm->our_event_queue, (u8 *) e,
348 switch (e->event_type)
350 case FIFO_EVENT_SERVER_RX:
351 client_handle_fifo_event_rx (utm, e);
354 case FIFO_EVENT_SERVER_EXIT:
358 clib_warning ("unknown event type %d", e->event_type);
364 client_rx_thread_fn (void *arg)
366 session_fifo_event_t _e, *e = &_e;
367 uri_tcp_test_main_t *utm = &uri_tcp_test_main;
369 utm->client_bytes_received = 0;
372 unix_shared_memory_queue_sub (utm->our_event_queue, (u8 *) e,
374 switch (e->event_type)
376 case FIFO_EVENT_SERVER_RX:
377 client_handle_fifo_event_rx (utm, e);
380 case FIFO_EVENT_SERVER_EXIT:
383 clib_warning ("unknown event type %d", e->event_type);
387 if (PREDICT_FALSE (utm->time_to_stop == 1))
395 vl_api_connect_uri_reply_t_handler (vl_api_connect_uri_reply_t * mp)
397 uri_tcp_test_main_t *utm = &uri_tcp_test_main;
398 svm_fifo_segment_create_args_t _a, *a = &_a;
401 svm_fifo_t *rx_fifo, *tx_fifo;
407 clib_warning ("connection failed with code: %d", mp->retval);
408 utm->state = STATE_FAILED;
416 if (mp->segment_name_length == 0)
418 clib_warning ("segment_name_length zero");
419 utm->state = STATE_FAILED;
423 a->segment_name = (char *) mp->segment_name;
424 a->segment_size = mp->segment_size;
426 ASSERT (mp->client_event_queue_address);
428 /* Attach to the segment vpp created */
429 rv = svm_fifo_segment_attach (a);
432 clib_warning ("svm_fifo_segment_attach ('%s') failed",
441 utm->our_event_queue = (unix_shared_memory_queue_t *)
442 mp->client_event_queue_address;
444 utm->vpp_event_queue = (unix_shared_memory_queue_t *)
445 mp->vpp_event_queue_address;
451 pool_get (utm->sessions, session);
452 session_index = session - utm->sessions;
454 rx_fifo = (svm_fifo_t *) mp->server_rx_fifo;
455 rx_fifo->client_session_index = session_index;
456 tx_fifo = (svm_fifo_t *) mp->server_tx_fifo;
457 tx_fifo->client_session_index = session_index;
459 session->server_rx_fifo = rx_fifo;
460 session->server_tx_fifo = tx_fifo;
461 session->vpp_session_index = mp->session_index;
462 session->vpp_session_thread = mp->session_thread_index;
465 utm->connected_session_index = session_index;
466 utm->state = STATE_READY;
468 /* Add it to lookup table */
469 key = (((u64) mp->session_thread_index) << 32) | (u64) mp->session_index;
470 hash_set (utm->session_index_by_vpp_handles, key, session_index);
472 /* Start RX thread */
473 rv = pthread_create (&utm->client_rx_thread_handle,
474 NULL /*attr */ , client_rx_thread_fn, 0);
477 clib_warning ("pthread_create returned %d", rv);
478 rv = VNET_API_ERROR_SYSCALL_ERROR_1;
483 client_send_data (uri_tcp_test_main_t * utm)
485 u8 *test_data = utm->connect_test_data;
488 int mypid = getpid ();
491 int buffer_offset, bytes_to_send = 0;
492 session_fifo_event_t evt;
493 static int serial_number = 0;
495 u32 max_chunk = 64 << 10, write;
497 session = pool_elt_at_index (utm->sessions, utm->connected_session_index);
498 tx_fifo = session->server_tx_fifo;
500 vec_validate (utm->rx_buf, vec_len (test_data) - 1);
502 for (i = 0; i < 1; i++)
504 bytes_to_send = vec_len (test_data);
506 while (bytes_to_send > 0)
508 write = bytes_to_send > max_chunk ? max_chunk : bytes_to_send;
509 rv = svm_fifo_enqueue_nowait (tx_fifo, mypid, write,
510 test_data + buffer_offset);
518 /* Fabricate TX event, send to vpp */
520 evt.event_type = FIFO_EVENT_SERVER_TX;
521 /* $$$$ for event logging */
522 evt.enqueue_length = rv;
523 evt.event_id = serial_number++;
525 unix_shared_memory_queue_add (utm->vpp_event_queue,
527 0 /* do wait for mutex */ );
532 if (utm->test_return_packets)
534 f64 timeout = clib_time_now (&utm->clib_time) + 2;
536 /* Wait for the outstanding packets */
537 while (utm->client_bytes_received < vec_len (test_data))
539 if (clib_time_now (&utm->clib_time) > timeout)
541 clib_warning ("timed out waiting for the missing packets");
546 utm->time_to_stop = 1;
551 client_connect (uri_tcp_test_main_t * utm)
553 vl_api_connect_uri_t *cmp;
554 cmp = vl_msg_api_alloc (sizeof (*cmp));
555 memset (cmp, 0, sizeof (*cmp));
557 cmp->_vl_msg_id = ntohs (VL_API_CONNECT_URI);
558 cmp->client_index = utm->my_client_index;
559 cmp->context = ntohl (0xfeedface);
560 memcpy (cmp->uri, utm->connect_uri, vec_len (utm->connect_uri));
561 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & cmp);
565 client_disconnect (uri_tcp_test_main_t * utm)
567 session_t *connected_session;
568 vl_api_disconnect_session_t *dmp;
569 connected_session = pool_elt_at_index (utm->sessions,
570 utm->connected_session_index);
571 dmp = vl_msg_api_alloc (sizeof (*dmp));
572 memset (dmp, 0, sizeof (*dmp));
573 dmp->_vl_msg_id = ntohs (VL_API_DISCONNECT_SESSION);
574 dmp->client_index = utm->my_client_index;
575 dmp->session_index = connected_session->vpp_session_index;
576 dmp->session_thread_index = connected_session->vpp_session_thread;
577 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & dmp);
581 client_test (uri_tcp_test_main_t * utm)
585 client_connect (utm);
587 if (wait_for_state_change (utm, STATE_READY))
593 vec_validate (utm->connect_test_data, 64 * 1024 - 1);
594 for (i = 0; i < vec_len (utm->connect_test_data); i++)
595 utm->connect_test_data[i] = i & 0xff;
598 client_send_data (utm);
601 client_disconnect (utm);
605 vl_api_bind_uri_reply_t_handler (vl_api_bind_uri_reply_t * mp)
607 uri_tcp_test_main_t *utm = &uri_tcp_test_main;
608 svm_fifo_segment_create_args_t _a, *a = &_a;
613 clib_warning ("bind failed: %d", mp->retval);
614 utm->state = STATE_FAILED;
618 if (mp->segment_name_length == 0)
620 clib_warning ("segment_name_length zero");
624 a->segment_name = (char *) mp->segment_name;
625 a->segment_size = mp->segment_size;
627 ASSERT (mp->server_event_queue_address);
629 /* Attach to the segment vpp created */
630 rv = svm_fifo_segment_attach (a);
633 clib_warning ("svm_fifo_segment_attach ('%s') failed",
638 utm->our_event_queue =
639 (unix_shared_memory_queue_t *) mp->server_event_queue_address;
641 utm->state = STATE_READY;
645 vl_api_unbind_uri_reply_t_handler (vl_api_unbind_uri_reply_t * mp)
647 uri_tcp_test_main_t *utm = &uri_tcp_test_main;
650 clib_warning ("returned %d", ntohl (mp->retval));
652 utm->state = STATE_START;
656 vl_api_accept_session_t_handler (vl_api_accept_session_t * mp)
658 uri_tcp_test_main_t *utm = &uri_tcp_test_main;
659 vl_api_accept_session_reply_t *rmp;
660 svm_fifo_t *rx_fifo, *tx_fifo;
662 static f64 start_time;
666 if (start_time == 0.0)
667 start_time = clib_time_now (&utm->clib_time);
669 utm->vpp_event_queue = (unix_shared_memory_queue_t *)
670 mp->vpp_event_queue_address;
672 /* Allocate local session and set it up */
673 pool_get (utm->sessions, session);
674 session_index = session - utm->sessions;
676 rx_fifo = (svm_fifo_t *) mp->server_rx_fifo;
677 rx_fifo->client_session_index = session_index;
678 tx_fifo = (svm_fifo_t *) mp->server_tx_fifo;
679 tx_fifo->client_session_index = session_index;
681 session->server_rx_fifo = rx_fifo;
682 session->server_tx_fifo = tx_fifo;
684 /* Add it to lookup table */
685 key = (((u64) mp->session_thread_index) << 32) | (u64) mp->session_index;
686 hash_set (utm->session_index_by_vpp_handles, key, session_index);
688 utm->state = STATE_READY;
691 if (pool_elts (utm->sessions) && (pool_elts (utm->sessions) % 20000) == 0)
693 f64 now = clib_time_now (&utm->clib_time);
694 fformat (stdout, "%d active sessions in %.2f seconds, %.2f/sec...\n",
695 pool_elts (utm->sessions), now - start_time,
696 (f64) pool_elts (utm->sessions) / (now - start_time));
700 * Send accept reply to vpp
702 rmp = vl_msg_api_alloc (sizeof (*rmp));
703 memset (rmp, 0, sizeof (*rmp));
704 rmp->_vl_msg_id = ntohs (VL_API_ACCEPT_SESSION_REPLY);
705 rmp->session_type = mp->session_type;
706 rmp->session_index = mp->session_index;
707 rmp->session_thread_index = mp->session_thread_index;
708 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & rmp);
712 server_handle_fifo_event_rx (uri_tcp_test_main_t * utm,
713 session_fifo_event_t * e)
715 svm_fifo_t *rx_fifo, *tx_fifo;
718 session_fifo_event_t evt;
719 unix_shared_memory_queue_t *q;
723 tx_fifo = utm->sessions[rx_fifo->client_session_index].server_tx_fifo;
725 bytes = e->enqueue_length;
728 n_read = svm_fifo_dequeue_nowait (rx_fifo, 0, vec_len (utm->rx_buf),
731 /* Reflect if a non-drop session */
732 if (!utm->drop_packets && n_read > 0)
736 rv = svm_fifo_enqueue_nowait (tx_fifo, 0, n_read, utm->rx_buf);
738 while (rv == -2 && !utm->time_to_stop);
740 /* Fabricate TX event, send to vpp */
742 evt.event_type = FIFO_EVENT_SERVER_TX;
743 /* $$$$ for event logging */
744 evt.enqueue_length = n_read;
745 evt.event_id = e->event_id;
746 q = utm->vpp_event_queue;
747 unix_shared_memory_queue_add (q, (u8 *) & evt,
748 0 /* do wait for mutex */ );
754 while ((n_read < 0 || bytes > 0) && !utm->time_to_stop);
758 server_handle_event_queue (uri_tcp_test_main_t * utm)
760 session_fifo_event_t _e, *e = &_e;;
764 unix_shared_memory_queue_sub (utm->our_event_queue, (u8 *) e,
766 switch (e->event_type)
768 case FIFO_EVENT_SERVER_RX:
769 server_handle_fifo_event_rx (utm, e);
772 case FIFO_EVENT_SERVER_EXIT:
776 clib_warning ("unknown event type %d", e->event_type);
779 if (PREDICT_FALSE (utm->time_to_stop == 1))
781 if (PREDICT_FALSE (utm->time_to_print_stats == 1))
783 utm->time_to_print_stats = 0;
784 fformat (stdout, "%d connections\n", pool_elts (utm->sessions));
790 server_bind (uri_tcp_test_main_t * utm)
792 vl_api_bind_uri_t *bmp;
793 u32 fifo_size = 3 << 20;
794 bmp = vl_msg_api_alloc (sizeof (*bmp));
795 memset (bmp, 0, sizeof (*bmp));
797 bmp->_vl_msg_id = ntohs (VL_API_BIND_URI);
798 bmp->client_index = utm->my_client_index;
799 bmp->context = ntohl (0xfeedface);
800 bmp->initial_segment_size = 256 << 20; /* size of initial segment */
801 bmp->options[SESSION_OPTIONS_FLAGS] =
802 SESSION_OPTIONS_FLAGS_USE_FIFO | SESSION_OPTIONS_FLAGS_ADD_SEGMENT;
803 bmp->options[SESSION_OPTIONS_RX_FIFO_SIZE] = fifo_size;
804 bmp->options[SESSION_OPTIONS_TX_FIFO_SIZE] = fifo_size;
805 bmp->options[SESSION_OPTIONS_ADD_SEGMENT_SIZE] = 128 << 20;
806 memcpy (bmp->uri, utm->uri, vec_len (utm->uri));
807 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & bmp);
811 server_unbind (uri_tcp_test_main_t * utm)
813 vl_api_unbind_uri_t *ump;
815 ump = vl_msg_api_alloc (sizeof (*ump));
816 memset (ump, 0, sizeof (*ump));
818 ump->_vl_msg_id = ntohs (VL_API_UNBIND_URI);
819 ump->client_index = utm->my_client_index;
820 memcpy (ump->uri, utm->uri, vec_len (utm->uri));
821 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & ump);
825 server_test (uri_tcp_test_main_t * utm)
830 if (wait_for_state_change (utm, STATE_READY))
832 clib_warning ("timeout waiting for STATE_READY");
836 /* Enter handle event loop */
837 server_handle_event_queue (utm);
842 if (wait_for_state_change (utm, STATE_START))
844 clib_warning ("timeout waiting for STATE_START");
848 fformat (stdout, "Test complete...\n");
852 vl_api_disconnect_session_reply_t_handler (vl_api_disconnect_session_reply_t *
855 clib_warning ("retval %d", ntohl (mp->retval));
858 #define foreach_uri_msg \
859 _(BIND_URI_REPLY, bind_uri_reply) \
860 _(UNBIND_URI_REPLY, unbind_uri_reply) \
861 _(ACCEPT_SESSION, accept_session) \
862 _(CONNECT_URI_REPLY, connect_uri_reply) \
863 _(DISCONNECT_SESSION, disconnect_session) \
864 _(DISCONNECT_SESSION_REPLY, disconnect_session_reply) \
865 _(RESET_SESSION, reset_session) \
866 _(MAP_ANOTHER_SEGMENT, map_another_segment)
869 uri_api_hookup (uri_tcp_test_main_t * utm)
872 vl_msg_api_set_handlers(VL_API_##N, #n, \
873 vl_api_##n##_t_handler, \
875 vl_api_##n##_t_endian, \
876 vl_api_##n##_t_print, \
877 sizeof(vl_api_##n##_t), 1);
883 main (int argc, char **argv)
885 uri_tcp_test_main_t *utm = &uri_tcp_test_main;
886 unformat_input_t _argv, *a = &_argv;
889 u8 *bind_uri = (u8 *) "tcp://0.0.0.0/1234";
890 u8 *connect_uri = (u8 *) "tcp://6.0.1.2/1234";
895 int i_am_master = 1, drop_packets = 0, test_return_packets = 0;
897 clib_mem_init (0, 256 << 20);
899 heap = clib_mem_get_per_cpu_heap ();
900 h = mheap_header (heap);
902 /* make the main heap thread-safe */
903 h->flags |= MHEAP_FLAG_THREAD_SAFE;
905 vec_validate (utm->rx_buf, 65536);
907 utm->session_index_by_vpp_handles = hash_create (0, sizeof (uword));
909 utm->my_pid = getpid ();
910 utm->configured_segment_size = 1 << 20;
912 clib_time_init (&utm->clib_time);
913 init_error_string_table (utm);
914 svm_fifo_segment_init (0x200000000ULL, 20);
915 unformat_init_command_line (a, argv);
917 while (unformat_check_input (a) != UNFORMAT_END_OF_INPUT)
919 if (unformat (a, "chroot prefix %s", &chroot_prefix))
921 vl_set_memory_root_path ((char *) chroot_prefix);
923 else if (unformat (a, "uri %s", &uri))
925 else if (unformat (a, "segment-size %dM", &tmp))
926 utm->configured_segment_size = tmp << 20;
927 else if (unformat (a, "segment-size %dG", &tmp))
928 utm->configured_segment_size = tmp << 30;
929 else if (unformat (a, "master"))
931 else if (unformat (a, "slave"))
933 else if (unformat (a, "drop"))
935 else if (unformat (a, "test"))
936 test_return_packets = 1;
939 fformat (stderr, "%s: usage [master|slave]\n");
946 utm->uri = format (0, "%s%c", uri, 0);
947 utm->connect_uri = format (0, "%s%c", uri, 0);
951 utm->uri = format (0, "%s%c", bind_uri, 0);
952 utm->connect_uri = format (0, "%s%c", connect_uri, 0);
955 utm->i_am_master = i_am_master;
956 utm->segment_main = &svm_fifo_segment_main;
957 utm->drop_packets = drop_packets;
958 utm->test_return_packets = test_return_packets;
960 setup_signal_handlers ();
961 uri_api_hookup (utm);
963 if (connect_to_vpp (i_am_master ? "uri_tcp_server" : "uri_tcp_client") < 0)
966 fformat (stderr, "Couldn't connect to vpe, exiting...\n");
970 if (i_am_master == 0)
973 vl_client_disconnect_from_vlib ();
977 /* $$$$ hack preallocation */
978 for (i = 0; i < 200000; i++)
980 pool_get (utm->sessions, session);
981 memset (session, 0, sizeof (*session));
983 for (i = 0; i < 200000; i++)
984 pool_put_index (utm->sessions, i);
988 vl_client_disconnect_from_vlib ();
993 * fd.io coding-style-patch-verification: ON
996 * eval: (c-set-style "gnu")