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;
122 svm_fifo_segment_main_t *segment_main;
123 } uri_tcp_test_main_t;
125 uri_tcp_test_main_t uri_tcp_test_main;
130 #define NITER 4000000
134 wait_for_state_change (uri_tcp_test_main_t * utm, connection_state_t state)
137 #define TIMEOUT 600.0
139 #define TIMEOUT 600.0
142 f64 timeout = clib_time_now (&utm->clib_time) + TIMEOUT;
144 while (clib_time_now (&utm->clib_time) < timeout)
146 if (utm->state == state)
148 if (utm->state == STATE_FAILED)
151 clib_warning ("timeout waiting for STATE_READY");
156 init_error_string_table (uri_tcp_test_main_t * utm)
158 utm->error_string_by_error_number = hash_create (0, sizeof (uword));
160 #define _(n,v,s) hash_set (utm->error_string_by_error_number, -v, s);
161 foreach_vnet_api_error;
164 hash_set (utm->error_string_by_error_number, 99, "Misc");
168 stop_signal (int signum)
170 uri_tcp_test_main_t *um = &uri_tcp_test_main;
172 um->time_to_stop = 1;
176 stats_signal (int signum)
178 uri_tcp_test_main_t *um = &uri_tcp_test_main;
180 um->time_to_print_stats = 1;
183 static clib_error_t *
184 setup_signal_handlers (void)
186 signal (SIGINT, stats_signal);
187 signal (SIGQUIT, stop_signal);
188 signal (SIGTERM, stop_signal);
194 vlib_cli_output (struct vlib_main_t *vm, char *fmt, ...)
196 clib_warning ("BUG");
200 connect_to_vpp (char *name)
202 uri_tcp_test_main_t *utm = &uri_tcp_test_main;
203 api_main_t *am = &api_main;
205 if (vl_client_connect_to_vlib ("/vpe-api", name, 32) < 0)
208 utm->vl_input_queue = am->shmem_hdr->vl_input_queue;
209 utm->my_client_index = am->my_client_index;
215 vl_api_map_another_segment_t_handler (vl_api_map_another_segment_t * mp)
217 svm_fifo_segment_create_args_t _a, *a = &_a;
220 a->segment_name = (char *) mp->segment_name;
221 a->segment_size = mp->segment_size;
222 /* Attach to the segment vpp created */
223 rv = svm_fifo_segment_attach (a);
226 clib_warning ("svm_fifo_segment_attach ('%s') failed",
230 clib_warning ("Mapped new segment '%s' size %d", mp->segment_name,
235 vl_api_disconnect_session_t_handler (vl_api_disconnect_session_t * mp)
237 uri_tcp_test_main_t *utm = &uri_tcp_test_main;
239 vl_api_disconnect_session_reply_t *rmp;
244 key = (((u64) mp->session_thread_index) << 32) | (u64) mp->session_index;
246 p = hash_get (utm->session_index_by_vpp_handles, key);
250 session = pool_elt_at_index (utm->sessions, p[0]);
251 hash_unset (utm->session_index_by_vpp_handles, key);
252 pool_put (utm->sessions, session);
256 clib_warning ("couldn't find session key %llx", key);
260 utm->time_to_stop = 1;
262 rmp = vl_msg_api_alloc (sizeof (*rmp));
263 memset (rmp, 0, sizeof (*rmp));
265 rmp->_vl_msg_id = ntohs (VL_API_DISCONNECT_SESSION_REPLY);
267 rmp->session_index = mp->session_index;
268 rmp->session_thread_index = mp->session_thread_index;
269 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & rmp);
273 vl_api_reset_session_t_handler (vl_api_reset_session_t * mp)
275 uri_tcp_test_main_t *utm = &uri_tcp_test_main;
277 vl_api_reset_session_reply_t *rmp;
282 key = (((u64) mp->session_thread_index) << 32) | (u64) mp->session_index;
284 p = hash_get (utm->session_index_by_vpp_handles, key);
288 session = pool_elt_at_index (utm->sessions, p[0]);
289 hash_unset (utm->session_index_by_vpp_handles, key);
290 pool_put (utm->sessions, session);
291 utm->time_to_stop = 1;
295 clib_warning ("couldn't find session key %llx", key);
299 rmp = vl_msg_api_alloc (sizeof (*rmp));
300 memset (rmp, 0, sizeof (*rmp));
301 rmp->_vl_msg_id = ntohs (VL_API_RESET_SESSION_REPLY);
303 rmp->session_index = mp->session_index;
304 rmp->session_thread_index = mp->session_thread_index;
305 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & rmp);
309 client_handle_fifo_event_rx (uri_tcp_test_main_t * utm,
310 session_fifo_event_t * e)
313 int n_read, bytes, i;
317 bytes = svm_fifo_max_dequeue (rx_fifo);
318 /* Allow enqueuing of new event */
319 svm_fifo_unset_event (rx_fifo);
324 n_read = svm_fifo_dequeue_nowait (rx_fifo, 0,
325 clib_min (vec_len (utm->rx_buf),
326 bytes), utm->rx_buf);
330 for (i = 0; i < n_read; i++)
332 if (utm->rx_buf[i] != ((utm->client_bytes_received + i) & 0xff))
334 clib_warning ("error at byte %lld, 0x%x not 0x%x",
335 utm->client_bytes_received + i,
337 ((utm->client_bytes_received + i) & 0xff));
340 utm->client_bytes_received += n_read;
346 clib_warning ("weird!");
356 client_handle_event_queue (uri_tcp_test_main_t * utm)
358 session_fifo_event_t _e, *e = &_e;;
360 unix_shared_memory_queue_sub (utm->our_event_queue, (u8 *) e,
362 switch (e->event_type)
364 case FIFO_EVENT_SERVER_RX:
365 client_handle_fifo_event_rx (utm, e);
368 case FIFO_EVENT_SERVER_EXIT:
372 clib_warning ("unknown event type %d", e->event_type);
378 client_rx_thread_fn (void *arg)
380 session_fifo_event_t _e, *e = &_e;
381 uri_tcp_test_main_t *utm = &uri_tcp_test_main;
383 utm->client_bytes_received = 0;
386 unix_shared_memory_queue_sub (utm->our_event_queue, (u8 *) e,
388 switch (e->event_type)
390 case FIFO_EVENT_SERVER_RX:
391 client_handle_fifo_event_rx (utm, e);
394 case FIFO_EVENT_SERVER_EXIT:
397 clib_warning ("unknown event type %d", e->event_type);
401 if (PREDICT_FALSE (utm->time_to_stop == 1))
409 vl_api_connect_uri_reply_t_handler (vl_api_connect_uri_reply_t * mp)
411 uri_tcp_test_main_t *utm = &uri_tcp_test_main;
412 svm_fifo_segment_create_args_t _a, *a = &_a;
415 svm_fifo_t *rx_fifo, *tx_fifo;
421 clib_warning ("connection failed with code: %d", mp->retval);
422 utm->state = STATE_FAILED;
430 if (mp->segment_name_length == 0)
432 clib_warning ("segment_name_length zero");
433 utm->state = STATE_FAILED;
437 a->segment_name = (char *) mp->segment_name;
438 a->segment_size = mp->segment_size;
440 ASSERT (mp->client_event_queue_address);
442 /* Attach to the segment vpp created */
443 rv = svm_fifo_segment_attach (a);
446 clib_warning ("svm_fifo_segment_attach ('%s') failed",
455 utm->our_event_queue = (unix_shared_memory_queue_t *)
456 mp->client_event_queue_address;
458 utm->vpp_event_queue = (unix_shared_memory_queue_t *)
459 mp->vpp_event_queue_address;
465 pool_get (utm->sessions, session);
466 session_index = session - utm->sessions;
468 rx_fifo = (svm_fifo_t *) mp->server_rx_fifo;
469 rx_fifo->client_session_index = session_index;
470 tx_fifo = (svm_fifo_t *) mp->server_tx_fifo;
471 tx_fifo->client_session_index = session_index;
473 session->server_rx_fifo = rx_fifo;
474 session->server_tx_fifo = tx_fifo;
475 session->vpp_session_index = mp->session_index;
476 session->vpp_session_thread = mp->session_thread_index;
479 utm->connected_session_index = session_index;
480 utm->state = STATE_READY;
482 /* Add it to lookup table */
483 key = (((u64) mp->session_thread_index) << 32) | (u64) mp->session_index;
484 hash_set (utm->session_index_by_vpp_handles, key, session_index);
486 /* Start RX thread */
487 rv = pthread_create (&utm->client_rx_thread_handle,
488 NULL /*attr */ , client_rx_thread_fn, 0);
491 clib_warning ("pthread_create returned %d", rv);
492 rv = VNET_API_ERROR_SYSCALL_ERROR_1;
497 send_test_chunk (uri_tcp_test_main_t * utm, svm_fifo_t * tx_fifo, int mypid,
500 u8 *test_data = utm->connect_test_data;
502 int test_buf_offset = 0;
504 u32 queue_max_chunk = 64 << 10, actual_write;
505 session_fifo_event_t evt;
506 static int serial_number = 0;
509 bytes_to_snd = (bytes == 0) ? vec_len (test_data) : bytes;
510 if (bytes_to_snd > vec_len (test_data))
511 bytes_to_snd = vec_len (test_data);
513 while (bytes_to_snd > 0)
516 bytes_to_snd > queue_max_chunk ? queue_max_chunk : bytes_to_snd;
517 rv = svm_fifo_enqueue_nowait (tx_fifo, mypid, actual_write,
518 test_data + test_buf_offset);
523 test_buf_offset += rv;
526 if (svm_fifo_set_event (tx_fifo))
528 /* Fabricate TX event, send to vpp */
530 evt.event_type = FIFO_EVENT_SERVER_TX;
531 evt.event_id = serial_number++;
533 unix_shared_memory_queue_add (utm->vpp_event_queue,
535 0 /* do wait for mutex */ );
542 client_send_data (uri_tcp_test_main_t * utm)
544 u8 *test_data = utm->connect_test_data;
545 int mypid = getpid ();
548 u32 n_iterations, leftover;
551 session = pool_elt_at_index (utm->sessions, utm->connected_session_index);
552 tx_fifo = session->server_tx_fifo;
554 vec_validate (utm->rx_buf, vec_len (test_data) - 1);
555 n_iterations = utm->bytes_to_send / vec_len (test_data);
557 for (i = 0; i < n_iterations; i++)
559 send_test_chunk (utm, tx_fifo, mypid, 0);
562 leftover = utm->bytes_to_send % vec_len (test_data);
564 send_test_chunk (utm, tx_fifo, mypid, leftover);
566 if (utm->test_return_packets)
568 f64 timeout = clib_time_now (&utm->clib_time) + 2;
570 /* Wait for the outstanding packets */
571 while (utm->client_bytes_received <
572 vec_len (test_data) * n_iterations + leftover)
574 if (clib_time_now (&utm->clib_time) > timeout)
576 clib_warning ("timed out waiting for the missing packets");
581 utm->time_to_stop = 1;
585 client_connect (uri_tcp_test_main_t * utm)
587 vl_api_connect_uri_t *cmp;
588 cmp = vl_msg_api_alloc (sizeof (*cmp));
589 memset (cmp, 0, sizeof (*cmp));
591 cmp->_vl_msg_id = ntohs (VL_API_CONNECT_URI);
592 cmp->client_index = utm->my_client_index;
593 cmp->context = ntohl (0xfeedface);
594 memcpy (cmp->uri, utm->connect_uri, vec_len (utm->connect_uri));
595 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & cmp);
599 client_disconnect (uri_tcp_test_main_t * utm)
601 session_t *connected_session;
602 vl_api_disconnect_session_t *dmp;
603 connected_session = pool_elt_at_index (utm->sessions,
604 utm->connected_session_index);
605 dmp = vl_msg_api_alloc (sizeof (*dmp));
606 memset (dmp, 0, sizeof (*dmp));
607 dmp->_vl_msg_id = ntohs (VL_API_DISCONNECT_SESSION);
608 dmp->client_index = utm->my_client_index;
609 dmp->session_index = connected_session->vpp_session_index;
610 dmp->session_thread_index = connected_session->vpp_session_thread;
611 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & dmp);
615 client_test (uri_tcp_test_main_t * utm)
619 client_connect (utm);
621 if (wait_for_state_change (utm, STATE_READY))
627 vec_validate (utm->connect_test_data, 64 * 1024 - 1);
628 for (i = 0; i < vec_len (utm->connect_test_data); i++)
629 utm->connect_test_data[i] = i & 0xff;
632 client_send_data (utm);
635 client_disconnect (utm);
637 if (wait_for_state_change (utm, STATE_START))
644 vl_api_bind_uri_reply_t_handler (vl_api_bind_uri_reply_t * mp)
646 uri_tcp_test_main_t *utm = &uri_tcp_test_main;
647 svm_fifo_segment_create_args_t _a, *a = &_a;
652 clib_warning ("bind failed: %d", mp->retval);
653 utm->state = STATE_FAILED;
657 if (mp->segment_name_length == 0)
659 clib_warning ("segment_name_length zero");
663 a->segment_name = (char *) mp->segment_name;
664 a->segment_size = mp->segment_size;
666 ASSERT (mp->server_event_queue_address);
668 /* Attach to the segment vpp created */
669 rv = svm_fifo_segment_attach (a);
672 clib_warning ("svm_fifo_segment_attach ('%s') failed",
677 utm->our_event_queue =
678 (unix_shared_memory_queue_t *) mp->server_event_queue_address;
680 utm->state = STATE_READY;
684 vl_api_unbind_uri_reply_t_handler (vl_api_unbind_uri_reply_t * mp)
686 uri_tcp_test_main_t *utm = &uri_tcp_test_main;
689 clib_warning ("returned %d", ntohl (mp->retval));
691 utm->state = STATE_START;
695 vl_api_accept_session_t_handler (vl_api_accept_session_t * mp)
697 uri_tcp_test_main_t *utm = &uri_tcp_test_main;
698 vl_api_accept_session_reply_t *rmp;
699 svm_fifo_t *rx_fifo, *tx_fifo;
701 static f64 start_time;
705 if (start_time == 0.0)
706 start_time = clib_time_now (&utm->clib_time);
708 utm->vpp_event_queue = (unix_shared_memory_queue_t *)
709 mp->vpp_event_queue_address;
711 /* Allocate local session and set it up */
712 pool_get (utm->sessions, session);
713 session_index = session - utm->sessions;
715 rx_fifo = (svm_fifo_t *) mp->server_rx_fifo;
716 rx_fifo->client_session_index = session_index;
717 tx_fifo = (svm_fifo_t *) mp->server_tx_fifo;
718 tx_fifo->client_session_index = session_index;
720 session->server_rx_fifo = rx_fifo;
721 session->server_tx_fifo = tx_fifo;
723 /* Add it to lookup table */
724 key = (((u64) mp->session_thread_index) << 32) | (u64) mp->session_index;
725 hash_set (utm->session_index_by_vpp_handles, key, session_index);
727 utm->state = STATE_READY;
730 if (pool_elts (utm->sessions) && (pool_elts (utm->sessions) % 20000) == 0)
732 f64 now = clib_time_now (&utm->clib_time);
733 fformat (stdout, "%d active sessions in %.2f seconds, %.2f/sec...\n",
734 pool_elts (utm->sessions), now - start_time,
735 (f64) pool_elts (utm->sessions) / (now - start_time));
739 * Send accept reply to vpp
741 rmp = vl_msg_api_alloc (sizeof (*rmp));
742 memset (rmp, 0, sizeof (*rmp));
743 rmp->_vl_msg_id = ntohs (VL_API_ACCEPT_SESSION_REPLY);
744 rmp->session_type = mp->session_type;
745 rmp->session_index = mp->session_index;
746 rmp->session_thread_index = mp->session_thread_index;
747 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & rmp);
751 server_handle_fifo_event_rx (uri_tcp_test_main_t * utm,
752 session_fifo_event_t * e)
754 svm_fifo_t *rx_fifo, *tx_fifo;
756 session_fifo_event_t evt;
757 unix_shared_memory_queue_t *q;
761 tx_fifo = utm->sessions[rx_fifo->client_session_index].server_tx_fifo;
763 bytes = svm_fifo_max_dequeue (rx_fifo);
764 /* Allow enqueuing of a new event */
765 svm_fifo_unset_event (rx_fifo);
773 n_read = svm_fifo_dequeue_nowait (rx_fifo, 0, vec_len (utm->rx_buf),
778 if (utm->drop_packets)
781 /* Reflect if a non-drop session */
786 rv = svm_fifo_enqueue_nowait (tx_fifo, 0, n_read, utm->rx_buf);
788 while (rv <= 0 && !utm->time_to_stop);
790 /* If event wasn't set, add one */
791 if (svm_fifo_set_event (tx_fifo))
793 /* Fabricate TX event, send to vpp */
795 evt.event_type = FIFO_EVENT_SERVER_TX;
796 evt.event_id = e->event_id;
798 q = utm->vpp_event_queue;
799 unix_shared_memory_queue_add (q, (u8 *) & evt,
800 0 /* do wait for mutex */ );
804 while ((n_read < 0 || bytes > 0) && !utm->time_to_stop);
808 server_handle_event_queue (uri_tcp_test_main_t * utm)
810 session_fifo_event_t _e, *e = &_e;;
814 unix_shared_memory_queue_sub (utm->our_event_queue, (u8 *) e,
816 switch (e->event_type)
818 case FIFO_EVENT_SERVER_RX:
819 server_handle_fifo_event_rx (utm, e);
822 case FIFO_EVENT_SERVER_EXIT:
826 clib_warning ("unknown event type %d", e->event_type);
829 if (PREDICT_FALSE (utm->time_to_stop == 1))
831 if (PREDICT_FALSE (utm->time_to_print_stats == 1))
833 utm->time_to_print_stats = 0;
834 fformat (stdout, "%d connections\n", pool_elts (utm->sessions));
840 server_bind (uri_tcp_test_main_t * utm)
842 vl_api_bind_uri_t *bmp;
843 u32 fifo_size = 3 << 20;
844 bmp = vl_msg_api_alloc (sizeof (*bmp));
845 memset (bmp, 0, sizeof (*bmp));
847 bmp->_vl_msg_id = ntohs (VL_API_BIND_URI);
848 bmp->client_index = utm->my_client_index;
849 bmp->context = ntohl (0xfeedface);
850 bmp->initial_segment_size = 256 << 20; /* size of initial segment */
851 bmp->options[SESSION_OPTIONS_FLAGS] =
852 SESSION_OPTIONS_FLAGS_USE_FIFO | SESSION_OPTIONS_FLAGS_ADD_SEGMENT;
853 bmp->options[SESSION_OPTIONS_RX_FIFO_SIZE] = fifo_size;
854 bmp->options[SESSION_OPTIONS_TX_FIFO_SIZE] = fifo_size;
855 bmp->options[SESSION_OPTIONS_ADD_SEGMENT_SIZE] = 128 << 20;
856 memcpy (bmp->uri, utm->uri, vec_len (utm->uri));
857 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & bmp);
861 server_unbind (uri_tcp_test_main_t * utm)
863 vl_api_unbind_uri_t *ump;
865 ump = vl_msg_api_alloc (sizeof (*ump));
866 memset (ump, 0, sizeof (*ump));
868 ump->_vl_msg_id = ntohs (VL_API_UNBIND_URI);
869 ump->client_index = utm->my_client_index;
870 memcpy (ump->uri, utm->uri, vec_len (utm->uri));
871 vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & ump);
875 server_test (uri_tcp_test_main_t * utm)
880 if (wait_for_state_change (utm, STATE_READY))
882 clib_warning ("timeout waiting for STATE_READY");
886 /* Enter handle event loop */
887 server_handle_event_queue (utm);
892 if (wait_for_state_change (utm, STATE_START))
894 clib_warning ("timeout waiting for STATE_START");
898 fformat (stdout, "Test complete...\n");
902 vl_api_disconnect_session_reply_t_handler (vl_api_disconnect_session_reply_t *
905 uri_tcp_test_main_t *utm = &uri_tcp_test_main;
907 clib_warning ("retval %d", ntohl (mp->retval));
908 utm->state = STATE_START;
911 #define foreach_uri_msg \
912 _(BIND_URI_REPLY, bind_uri_reply) \
913 _(UNBIND_URI_REPLY, unbind_uri_reply) \
914 _(ACCEPT_SESSION, accept_session) \
915 _(CONNECT_URI_REPLY, connect_uri_reply) \
916 _(DISCONNECT_SESSION, disconnect_session) \
917 _(DISCONNECT_SESSION_REPLY, disconnect_session_reply) \
918 _(RESET_SESSION, reset_session) \
919 _(MAP_ANOTHER_SEGMENT, map_another_segment)
922 uri_api_hookup (uri_tcp_test_main_t * utm)
925 vl_msg_api_set_handlers(VL_API_##N, #n, \
926 vl_api_##n##_t_handler, \
928 vl_api_##n##_t_endian, \
929 vl_api_##n##_t_print, \
930 sizeof(vl_api_##n##_t), 1);
936 main (int argc, char **argv)
938 uri_tcp_test_main_t *utm = &uri_tcp_test_main;
939 unformat_input_t _argv, *a = &_argv;
942 u8 *bind_uri = (u8 *) "tcp://0.0.0.0/1234";
943 u8 *connect_uri = (u8 *) "tcp://6.0.1.2/1234";
944 u32 bytes_to_send = 64 << 10, mbytes;
949 int i_am_master = 1, drop_packets = 0, test_return_packets = 0;
951 clib_mem_init (0, 256 << 20);
953 heap = clib_mem_get_per_cpu_heap ();
954 h = mheap_header (heap);
956 /* make the main heap thread-safe */
957 h->flags |= MHEAP_FLAG_THREAD_SAFE;
959 vec_validate (utm->rx_buf, 65536);
961 utm->session_index_by_vpp_handles = hash_create (0, sizeof (uword));
963 utm->my_pid = getpid ();
964 utm->configured_segment_size = 1 << 20;
966 clib_time_init (&utm->clib_time);
967 init_error_string_table (utm);
968 svm_fifo_segment_init (0x200000000ULL, 20);
969 unformat_init_command_line (a, argv);
971 while (unformat_check_input (a) != UNFORMAT_END_OF_INPUT)
973 if (unformat (a, "chroot prefix %s", &chroot_prefix))
975 vl_set_memory_root_path ((char *) chroot_prefix);
977 else if (unformat (a, "uri %s", &uri))
979 else if (unformat (a, "segment-size %dM", &tmp))
980 utm->configured_segment_size = tmp << 20;
981 else if (unformat (a, "segment-size %dG", &tmp))
982 utm->configured_segment_size = tmp << 30;
983 else if (unformat (a, "master"))
985 else if (unformat (a, "slave"))
987 else if (unformat (a, "drop"))
989 else if (unformat (a, "test"))
990 test_return_packets = 1;
991 else if (unformat (a, "mbytes %d", &mbytes))
993 bytes_to_send = mbytes << 20;
997 fformat (stderr, "%s: usage [master|slave]\n");
1004 utm->uri = format (0, "%s%c", uri, 0);
1005 utm->connect_uri = format (0, "%s%c", uri, 0);
1009 utm->uri = format (0, "%s%c", bind_uri, 0);
1010 utm->connect_uri = format (0, "%s%c", connect_uri, 0);
1013 utm->i_am_master = i_am_master;
1014 utm->segment_main = &svm_fifo_segment_main;
1015 utm->drop_packets = drop_packets;
1016 utm->test_return_packets = test_return_packets;
1017 utm->bytes_to_send = bytes_to_send;
1019 setup_signal_handlers ();
1020 uri_api_hookup (utm);
1022 if (connect_to_vpp (i_am_master ? "uri_tcp_server" : "uri_tcp_client") < 0)
1025 fformat (stderr, "Couldn't connect to vpe, exiting...\n");
1029 if (i_am_master == 0)
1032 vl_client_disconnect_from_vlib ();
1036 /* $$$$ hack preallocation */
1037 for (i = 0; i < 200000; i++)
1039 pool_get (utm->sessions, session);
1040 memset (session, 0, sizeof (*session));
1042 for (i = 0; i < 200000; i++)
1043 pool_put_index (utm->sessions, i);
1047 vl_client_disconnect_from_vlib ();
1052 * fd.io coding-style-patch-verification: ON
1055 * eval: (c-set-style "gnu")