#include <vpp/api/vpe_all_api_h.h>
#undef vl_printfun
-/* Satisfy external references when not linking with -lvlib */
-vlib_main_t vlib_global_main;
-vlib_main_t **vlib_mains;
-
typedef enum
{
STATE_START,
+ STATE_BOUND,
STATE_READY,
+ STATE_FAILED,
STATE_DISCONNECTING,
} connection_state_t;
/* $$$$ hack: cut-through session index */
volatile u32 cut_through_session_index;
+ volatile u32 connected_session;
/* unique segment name counter */
u32 unique_segment_index;
/* convenience */
svm_fifo_segment_main_t *segment_main;
+ u8 *connect_test_data;
} uri_udp_test_main_t;
#if CLIB_DEBUG > 0
return 0;
}
+void
+application_send_attach (uri_udp_test_main_t * utm)
+{
+ vl_api_application_attach_t *bmp;
+ u32 fifo_size = 1 << 20;
+ bmp = vl_msg_api_alloc (sizeof (*bmp));
+ memset (bmp, 0, sizeof (*bmp));
+
+ bmp->_vl_msg_id = ntohs (VL_API_APPLICATION_ATTACH);
+ bmp->client_index = utm->my_client_index;
+ bmp->context = ntohl (0xfeedface);
+ bmp->options[APP_OPTIONS_FLAGS] =
+ APP_OPTIONS_FLAGS_ACCEPT_REDIRECT | APP_OPTIONS_FLAGS_ADD_SEGMENT;
+ bmp->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] = 2;
+ bmp->options[APP_OPTIONS_RX_FIFO_SIZE] = fifo_size;
+ bmp->options[APP_OPTIONS_TX_FIFO_SIZE] = fifo_size;
+ bmp->options[APP_OPTIONS_ADD_SEGMENT_SIZE] = 128 << 20;
+ bmp->options[APP_OPTIONS_SEGMENT_SIZE] = 256 << 20;
+ bmp->options[APP_OPTIONS_EVT_QUEUE_SIZE] = 16768;
+ vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & bmp);
+}
+
+void
+application_detach (uri_udp_test_main_t * utm)
+{
+ vl_api_application_detach_t *bmp;
+ bmp = vl_msg_api_alloc (sizeof (*bmp));
+ memset (bmp, 0, sizeof (*bmp));
+
+ bmp->_vl_msg_id = ntohs (VL_API_APPLICATION_DETACH);
+ bmp->client_index = utm->my_client_index;
+ bmp->context = ntohl (0xfeedface);
+ vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & bmp);
+}
+
+static void
+vl_api_application_attach_reply_t_handler (vl_api_application_attach_reply_t *
+ mp)
+{
+ uri_udp_test_main_t *utm = &uri_udp_test_main;
+ svm_fifo_segment_create_args_t _a, *a = &_a;
+ int rv;
+
+ if (mp->retval)
+ {
+ clib_warning ("attach failed: %d", mp->retval);
+ utm->state = STATE_FAILED;
+ return;
+ }
+
+ if (mp->segment_name_length == 0)
+ {
+ clib_warning ("segment_name_length zero");
+ return;
+ }
+
+ a->segment_name = (char *) mp->segment_name;
+ a->segment_size = mp->segment_size;
+
+ ASSERT (mp->app_event_queue_address);
+
+ /* Attach to the segment vpp created */
+ rv = svm_fifo_segment_attach (a);
+ if (rv)
+ {
+ clib_warning ("svm_fifo_segment_attach ('%s') failed",
+ mp->segment_name);
+ return;
+ }
+
+ utm->our_event_queue =
+ uword_to_pointer (mp->app_event_queue_address,
+ unix_shared_memory_queue_t *);
+}
+
+static void
+vl_api_application_detach_reply_t_handler (vl_api_application_detach_reply_t *
+ mp)
+{
+ if (mp->retval)
+ clib_warning ("detach returned with err: %d", mp->retval);
+}
+
u8 *
format_api_error (u8 * s, va_list * args)
{
/* We read from the tx fifo and write to the rx fifo */
do
{
- actual_transfer = svm_fifo_dequeue_nowait (tx_fifo, 0,
+ actual_transfer = svm_fifo_dequeue_nowait (tx_fifo,
vec_len (my_copy_buffer),
my_copy_buffer);
}
buffer_offset = 0;
while (actual_transfer > 0)
{
- rv = svm_fifo_enqueue_nowait (rx_fifo, 0, actual_transfer,
+ rv = svm_fifo_enqueue_nowait (rx_fifo, actual_transfer,
my_copy_buffer + buffer_offset);
if (rv > 0)
{
}
static void
-uri_udp_slave_test (uri_udp_test_main_t * utm)
+udp_client_connect (uri_udp_test_main_t * utm)
{
vl_api_connect_uri_t *cmp;
+ cmp = vl_msg_api_alloc (sizeof (*cmp));
+ memset (cmp, 0, sizeof (*cmp));
+
+ cmp->_vl_msg_id = ntohs (VL_API_CONNECT_URI);
+ cmp->client_index = utm->my_client_index;
+ cmp->context = ntohl (0xfeedface);
+ memcpy (cmp->uri, utm->connect_uri, vec_len (utm->connect_uri));
+ vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & cmp);
+}
+
+static void
+client_send_cut_through (uri_udp_test_main_t * utm, session_t * session)
+{
int i;
u8 *test_data = 0;
u64 bytes_received = 0, bytes_sent = 0;
i32 bytes_to_read;
int rv;
- int mypid = getpid ();
f64 before, after, delta, bytes_per_second;
- session_t *session;
svm_fifo_t *rx_fifo, *tx_fifo;
int buffer_offset, bytes_to_send = 0;
+ /*
+ * Prepare test data
+ */
vec_validate (test_data, 64 * 1024 - 1);
for (i = 0; i < vec_len (test_data); i++)
test_data[i] = i & 0xff;
- cmp = vl_msg_api_alloc (sizeof (*cmp));
- memset (cmp, 0, sizeof (*cmp));
-
- cmp->_vl_msg_id = ntohs (VL_API_CONNECT_URI);
- cmp->client_index = utm->my_client_index;
- cmp->context = ntohl (0xfeedface);
- memcpy (cmp->uri, utm->connect_uri, vec_len (utm->connect_uri));
- vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & cmp);
-
- if (wait_for_state_change (utm, STATE_READY))
- {
- clib_warning ("timeout waiting for STATE_READY");
- return;
- }
-
- session = pool_elt_at_index (utm->sessions, utm->cut_through_session_index);
rx_fifo = session->server_rx_fifo;
tx_fifo = session->server_tx_fifo;
buffer_offset = 0;
while (bytes_to_send > 0)
{
- rv = svm_fifo_enqueue_nowait (tx_fifo, mypid,
- bytes_to_send,
+ rv = svm_fifo_enqueue_nowait (tx_fifo, bytes_to_send,
test_data + buffer_offset);
if (rv > 0)
}
bytes_to_read = svm_fifo_max_dequeue (rx_fifo);
-
bytes_to_read = vec_len (utm->rx_buf) > bytes_to_read ?
bytes_to_read : vec_len (utm->rx_buf);
buffer_offset = 0;
while (bytes_to_read > 0)
{
- rv = svm_fifo_dequeue_nowait (rx_fifo, mypid,
+ rv = svm_fifo_dequeue_nowait (rx_fifo,
bytes_to_read,
utm->rx_buf + buffer_offset);
if (rv > 0)
}
while (bytes_received < bytes_sent)
{
- rv = svm_fifo_dequeue_nowait (rx_fifo, mypid,
- vec_len (utm->rx_buf), utm->rx_buf);
+ rv =
+ svm_fifo_dequeue_nowait (rx_fifo, vec_len (utm->rx_buf), utm->rx_buf);
if (rv > 0)
{
#if CLIB_DEBUG > 0
}
static void
-vl_api_bind_uri_reply_t_handler (vl_api_bind_uri_reply_t * mp)
+send_test_chunk (uri_udp_test_main_t * utm, svm_fifo_t * tx_fifo, int mypid,
+ u32 bytes)
{
- uri_udp_test_main_t *utm = &uri_udp_test_main;
- svm_fifo_segment_create_args_t _a, *a = &_a;
+ u8 *test_data = utm->connect_test_data;
+ u64 bytes_sent = 0;
+ int test_buf_offset = 0;
+ u32 bytes_to_snd;
+ u32 queue_max_chunk = 128 << 10, actual_write;
+ session_fifo_event_t evt;
int rv;
- if (mp->segment_name_length == 0)
+ bytes_to_snd = (bytes == 0) ? vec_len (test_data) : bytes;
+ if (bytes_to_snd > vec_len (test_data))
+ bytes_to_snd = vec_len (test_data);
+
+ while (bytes_to_snd > 0 && !utm->time_to_stop)
{
- clib_warning ("segment_name_length zero");
- return;
+ actual_write = (bytes_to_snd > queue_max_chunk) ?
+ queue_max_chunk : bytes_to_snd;
+ rv = svm_fifo_enqueue_nowait (tx_fifo, actual_write,
+ test_data + test_buf_offset);
+
+ if (rv > 0)
+ {
+ bytes_to_snd -= rv;
+ test_buf_offset += rv;
+ bytes_sent += rv;
+
+ if (svm_fifo_set_event (tx_fifo))
+ {
+ /* Fabricate TX event, send to vpp */
+ evt.fifo = tx_fifo;
+ evt.event_type = FIFO_EVENT_APP_TX;
+
+ unix_shared_memory_queue_add (utm->vpp_event_queue,
+ (u8 *) & evt,
+ 0 /* do wait for mutex */ );
+ }
+ }
}
+}
- a->segment_name = (char *) mp->segment_name;
- a->segment_size = mp->segment_size;
+static void
+recv_test_chunk (uri_udp_test_main_t * utm, session_t * session)
+{
+ svm_fifo_t *rx_fifo;
+ int buffer_offset, bytes_to_read = 0, rv;
- ASSERT (mp->server_event_queue_address);
+ rx_fifo = session->server_rx_fifo;
+ bytes_to_read = svm_fifo_max_dequeue (rx_fifo);
+ bytes_to_read =
+ vec_len (utm->rx_buf) > bytes_to_read ?
+ bytes_to_read : vec_len (utm->rx_buf);
- /* Attach to the segment vpp created */
- rv = svm_fifo_segment_attach (a);
- if (rv)
+ buffer_offset = 0;
+ while (bytes_to_read > 0)
{
- clib_warning ("svm_fifo_segment_attach ('%s') failed",
- mp->segment_name);
+ rv = svm_fifo_dequeue_nowait (rx_fifo, bytes_to_read,
+ utm->rx_buf + buffer_offset);
+ if (rv > 0)
+ {
+ bytes_to_read -= rv;
+ buffer_offset += rv;
+ }
+ }
+}
+
+void
+client_send_data (uri_udp_test_main_t * utm)
+{
+ u8 *test_data;
+ int mypid = getpid ();
+ session_t *session;
+ svm_fifo_t *tx_fifo;
+ u32 n_iterations;
+ int i;
+
+ vec_validate (utm->connect_test_data, 64 * 1024 - 1);
+ for (i = 0; i < vec_len (utm->connect_test_data); i++)
+ utm->connect_test_data[i] = i & 0xff;
+
+ test_data = utm->connect_test_data;
+ session = pool_elt_at_index (utm->sessions, utm->connected_session);
+ tx_fifo = session->server_tx_fifo;
+
+ ASSERT (vec_len (test_data) > 0);
+
+ vec_validate (utm->rx_buf, vec_len (test_data) - 1);
+ n_iterations = NITER;
+
+ for (i = 0; i < n_iterations; i++)
+ {
+ send_test_chunk (utm, tx_fifo, mypid, 0);
+ recv_test_chunk (utm, session);
+ if (utm->time_to_stop)
+ break;
+ }
+
+ f64 timeout = clib_time_now (&utm->clib_time) + 5;
+ while (clib_time_now (&utm->clib_time) < timeout)
+ {
+ recv_test_chunk (utm, session);
+ }
+
+}
+
+static void
+client_test (uri_udp_test_main_t * utm)
+{
+ session_t *session;
+
+ application_send_attach (utm);
+ udp_client_connect (utm);
+
+ if (wait_for_state_change (utm, STATE_READY))
+ {
+ clib_warning ("timeout waiting for STATE_READY");
return;
}
- utm->our_event_queue = (unix_shared_memory_queue_t *)
- mp->server_event_queue_address;
+ if (utm->cut_through_session_index != ~0)
+ {
+ session = pool_elt_at_index (utm->sessions,
+ utm->cut_through_session_index);
+ client_send_cut_through (utm, session);
+ }
+ else
+ {
+ session = pool_elt_at_index (utm->sessions, utm->connected_session);
+ client_send_data (utm);
+ }
- utm->state = STATE_READY;
+ application_detach (utm);
+}
+
+static void
+vl_api_bind_uri_reply_t_handler (vl_api_bind_uri_reply_t * mp)
+{
+ uri_udp_test_main_t *utm = &uri_udp_test_main;
+
+ if (mp->retval)
+ {
+ clib_warning ("bind failed: %d", mp->retval);
+ utm->state = STATE_FAILED;
+ return;
+ }
+
+ utm->state = STATE_BOUND;
}
static void
svm_fifo_segment_create_args_t _a, *a = &_a;
int rv;
+ memset (a, 0, sizeof (*a));
a->segment_name = (char *) mp->segment_name;
a->segment_size = mp->segment_size;
/* Attach to the segment vpp created */
mp->segment_size);
}
+/**
+ * Acting as server for redirected connect requests
+ */
static void
vl_api_connect_uri_t_handler (vl_api_connect_uri_t * mp)
{
svm_fifo_segment_create_args_t _a, *a = &_a;
svm_fifo_segment_private_t *seg;
unix_shared_memory_queue_t *client_q;
- vl_api_connect_uri_reply_t *rmp;
- session_t *session;
+ vl_api_connect_session_reply_t *rmp;
+ session_t *session = 0;
int rv = 0;
/* Create the segment */
vec_add2 (utm->seg, seg, 1);
segment_index = vec_len (sm->segments) - 1;
-
memcpy (seg, sm->segments + segment_index, sizeof (utm->seg[0]));
pool_get (utm->sessions, session);
- /*
- * By construction the master's idea of the rx fifo ends up in
- * fsh->fifos[0], and the master's idea of the tx fifo ends up in
- * fsh->fifos[1].
- */
- session->server_rx_fifo = svm_fifo_segment_alloc_fifo (utm->seg,
- 128 * 1024);
+ session->server_rx_fifo = svm_fifo_segment_alloc_fifo
+ (utm->seg, 128 * 1024, FIFO_SEGMENT_RX_FREELIST);
ASSERT (session->server_rx_fifo);
- session->server_tx_fifo = svm_fifo_segment_alloc_fifo (utm->seg,
- 128 * 1024);
+ session->server_tx_fifo = svm_fifo_segment_alloc_fifo
+ (utm->seg, 128 * 1024, FIFO_SEGMENT_TX_FREELIST);
ASSERT (session->server_tx_fifo);
- session->server_rx_fifo->server_session_index = session - utm->sessions;
- session->server_tx_fifo->server_session_index = session - utm->sessions;
+ session->server_rx_fifo->master_session_index = session - utm->sessions;
+ session->server_tx_fifo->master_session_index = session - utm->sessions;
utm->cut_through_session_index = session - utm->sessions;
rv = pthread_create (&utm->cut_through_thread_handle,
rmp = vl_msg_api_alloc (sizeof (*rmp));
memset (rmp, 0, sizeof (*rmp));
- rmp->_vl_msg_id = ntohs (VL_API_CONNECT_URI_REPLY);
+ rmp->_vl_msg_id = ntohs (VL_API_CONNECT_SESSION_REPLY);
rmp->context = mp->context;
rmp->retval = ntohl (rv);
rmp->segment_name_length = vec_len (a->segment_name);
+ if (session)
+ {
+ rmp->server_rx_fifo = pointer_to_uword (session->server_rx_fifo);
+ rmp->server_tx_fifo = pointer_to_uword (session->server_tx_fifo);
+ }
+
memcpy (rmp->segment_name, a->segment_name, vec_len (a->segment_name));
vec_free (a->segment_name);
- client_q = (unix_shared_memory_queue_t *) mp->client_queue_address;
+ client_q =
+ uword_to_pointer (mp->client_queue_address, unix_shared_memory_queue_t *);
vl_msg_api_send_shmem (client_q, (u8 *) & rmp);
}
svm_fifo_t *rx_fifo, *tx_fifo;
session_t *session;
static f64 start_time;
- u64 key;
if (start_time == 0.0)
start_time = clib_time_now (&utm->clib_time);
- utm->vpp_event_queue = (unix_shared_memory_queue_t *)
- mp->vpp_event_queue_address;
+ utm->vpp_event_queue =
+ uword_to_pointer (mp->vpp_event_queue_address,
+ unix_shared_memory_queue_t *);
pool_get (utm->sessions, session);
- rx_fifo = (svm_fifo_t *) mp->server_rx_fifo;
+ rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *);
rx_fifo->client_session_index = session - utm->sessions;
- tx_fifo = (svm_fifo_t *) mp->server_tx_fifo;
+ tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *);
tx_fifo->client_session_index = session - utm->sessions;
session->server_rx_fifo = rx_fifo;
session->server_tx_fifo = tx_fifo;
- key = (((u64) mp->session_thread_index) << 32) | (u64) mp->session_index;
-
- hash_set (utm->session_index_by_vpp_handles, key, session - utm->sessions);
-
- utm->state = STATE_READY;
+ hash_set (utm->session_index_by_vpp_handles, mp->handle,
+ session - utm->sessions);
if (pool_elts (utm->sessions) && (pool_elts (utm->sessions) % 20000) == 0)
{
rmp = vl_msg_api_alloc (sizeof (*rmp));
memset (rmp, 0, sizeof (*rmp));
rmp->_vl_msg_id = ntohs (VL_API_ACCEPT_SESSION_REPLY);
- rmp->session_type = mp->session_type;
- rmp->session_index = mp->session_index;
- rmp->session_thread_index = mp->session_thread_index;
+ rmp->handle = mp->handle;
+ rmp->context = mp->context;
vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & rmp);
+
+ CLIB_MEMORY_BARRIER ();
+ utm->state = STATE_READY;
}
static void
vl_api_disconnect_session_reply_t *rmp;
uword *p;
int rv = 0;
- u64 key;
-
- key = (((u64) mp->session_thread_index) << 32) | (u64) mp->session_index;
- p = hash_get (utm->session_index_by_vpp_handles, key);
+ p = hash_get (utm->session_index_by_vpp_handles, mp->handle);
if (p)
{
session = pool_elt_at_index (utm->sessions, p[0]);
- hash_unset (utm->session_index_by_vpp_handles, key);
+ hash_unset (utm->session_index_by_vpp_handles, mp->handle);
pool_put (utm->sessions, session);
}
else
{
- clib_warning ("couldn't find session key %llx", key);
+ clib_warning ("couldn't find session key %llx", mp->handle);
rv = -11;
}
memset (rmp, 0, sizeof (*rmp));
rmp->_vl_msg_id = ntohs (VL_API_DISCONNECT_SESSION_REPLY);
rmp->retval = rv;
- rmp->session_index = mp->session_index;
- rmp->session_thread_index = mp->session_thread_index;
+ rmp->handle = mp->handle;
vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & rmp);
}
static void
-vl_api_connect_uri_reply_t_handler (vl_api_connect_uri_reply_t * mp)
+vl_api_connect_session_reply_t_handler (vl_api_connect_session_reply_t * mp)
{
- svm_fifo_segment_main_t *sm = &svm_fifo_segment_main;
uri_udp_test_main_t *utm = &uri_udp_test_main;
- svm_fifo_segment_create_args_t _a, *a = &_a;
- ssvm_shared_header_t *sh;
- svm_fifo_segment_private_t *seg;
- svm_fifo_segment_header_t *fsh;
session_t *session;
- u32 segment_index;
- int rv;
ASSERT (utm->i_am_master == 0);
- if (mp->segment_name_length == 0)
+ if (mp->retval)
{
- clib_warning ("segment_name_length zero");
+ clib_warning ("failed connect");
return;
}
- memset (a, 0, sizeof (*a));
-
- a->segment_name = (char *) mp->segment_name;
-
- sleep (1);
-
- rv = svm_fifo_segment_attach (a);
- if (rv)
+ /* We've been redirected */
+ if (mp->segment_name_length > 0)
{
- clib_warning ("sm_fifo_segment_create ('%v') failed", mp->segment_name);
- return;
- }
+ svm_fifo_segment_main_t *sm = &svm_fifo_segment_main;
+ svm_fifo_segment_create_args_t _a, *a = &_a;
+ u32 segment_index;
+ svm_fifo_segment_private_t *seg;
+ int rv;
- segment_index = vec_len (sm->segments) - 1;
+ memset (a, 0, sizeof (*a));
+ a->segment_name = (char *) mp->segment_name;
- vec_add2 (utm->seg, seg, 1);
+ sleep (1);
- memcpy (seg, sm->segments + segment_index, sizeof (*seg));
- sh = seg->ssvm.sh;
- fsh = (svm_fifo_segment_header_t *) sh->opaque[0];
+ rv = svm_fifo_segment_attach (a);
+ if (rv)
+ {
+ clib_warning ("sm_fifo_segment_create ('%v') failed",
+ mp->segment_name);
+ return;
+ }
- while (vec_len (fsh->fifos) < 2)
- sleep (1);
+ segment_index = a->new_segment_indices[0];
+ vec_add2 (utm->seg, seg, 1);
+ memcpy (seg, sm->segments + segment_index, sizeof (*seg));
+ sleep (1);
+ }
pool_get (utm->sessions, session);
- utm->cut_through_session_index = session - utm->sessions;
-
- session->server_rx_fifo = (svm_fifo_t *) fsh->fifos[0];
+ session->server_rx_fifo = uword_to_pointer (mp->server_rx_fifo,
+ svm_fifo_t *);
ASSERT (session->server_rx_fifo);
- session->server_tx_fifo = (svm_fifo_t *) fsh->fifos[1];
+ session->server_tx_fifo = uword_to_pointer (mp->server_tx_fifo,
+ svm_fifo_t *);
ASSERT (session->server_tx_fifo);
- /* security: could unlink /dev/shm/<mp->segment_name> here, maybe */
-
+ if (mp->segment_name_length > 0)
+ utm->cut_through_session_index = session - utm->sessions;
+ else
+ {
+ utm->connected_session = session - utm->sessions;
+ utm->vpp_event_queue = uword_to_pointer (mp->vpp_event_queue_address,
+ unix_shared_memory_queue_t *);
+ }
utm->state = STATE_READY;
}
-#define foreach_uri_msg \
-_(BIND_URI_REPLY, bind_uri_reply) \
-_(CONNECT_URI, connect_uri) \
-_(CONNECT_URI_REPLY, connect_uri_reply) \
-_(UNBIND_URI_REPLY, unbind_uri_reply) \
-_(ACCEPT_SESSION, accept_session) \
-_(DISCONNECT_SESSION, disconnect_session) \
-_(MAP_ANOTHER_SEGMENT, map_another_segment)
+#define foreach_uri_msg \
+_(BIND_URI_REPLY, bind_uri_reply) \
+_(CONNECT_URI, connect_uri) \
+_(CONNECT_SESSION_REPLY, connect_session_reply) \
+_(UNBIND_URI_REPLY, unbind_uri_reply) \
+_(ACCEPT_SESSION, accept_session) \
+_(DISCONNECT_SESSION, disconnect_session) \
+_(MAP_ANOTHER_SEGMENT, map_another_segment) \
+_(APPLICATION_ATTACH_REPLY, application_attach_reply) \
+_(APPLICATION_DETACH_REPLY, application_detach_reply) \
void
uri_api_hookup (uri_udp_test_main_t * utm)
}
-
int
connect_to_vpp (char *name)
{
{
svm_fifo_t *rx_fifo, *tx_fifo;
int nbytes;
-
session_fifo_event_t evt;
unix_shared_memory_queue_t *q;
int rv;
rx_fifo = e->fifo;
tx_fifo = utm->sessions[rx_fifo->client_session_index].server_tx_fifo;
+ svm_fifo_unset_event (rx_fifo);
do
{
- nbytes = svm_fifo_dequeue_nowait (rx_fifo, 0,
- vec_len (utm->rx_buf), utm->rx_buf);
+ nbytes = svm_fifo_dequeue_nowait (rx_fifo, vec_len (utm->rx_buf),
+ utm->rx_buf);
}
while (nbytes <= 0);
do
{
- rv = svm_fifo_enqueue_nowait (tx_fifo, 0, nbytes, utm->rx_buf);
+ rv = svm_fifo_enqueue_nowait (tx_fifo, nbytes, utm->rx_buf);
}
while (rv == -2);
- /* Fabricate TX event, send to vpp */
- evt.fifo = tx_fifo;
- evt.event_type = FIFO_EVENT_SERVER_TX;
- evt.event_id = e->event_id;
-
if (svm_fifo_set_event (tx_fifo))
{
+ /* Fabricate TX event, send to vpp */
+ evt.fifo = tx_fifo;
+ evt.event_type = FIFO_EVENT_APP_TX;
q = utm->vpp_event_queue;
unix_shared_memory_queue_add (q, (u8 *) & evt,
0 /* do wait for mutex */ );
{
session_fifo_event_t _e, *e = &_e;
+ while (utm->state != STATE_READY)
+ sleep (5);
+
while (1)
{
unix_shared_memory_queue_sub (utm->our_event_queue, (u8 *) e,
0 /* nowait */ );
switch (e->event_type)
{
- case FIFO_EVENT_SERVER_RX:
+ case FIFO_EVENT_APP_RX:
server_handle_fifo_event_rx (utm, e);
break;
- case FIFO_EVENT_SERVER_EXIT:
+ case FIFO_EVENT_DISCONNECT:
return;
default:
break;
}
if (PREDICT_FALSE (utm->time_to_stop == 1))
- break;
+ return;
if (PREDICT_FALSE (utm->time_to_print_stats == 1))
{
utm->time_to_print_stats = 0;
}
}
-void
-uri_udp_test (uri_udp_test_main_t * utm)
+static void
+server_unbind (uri_udp_test_main_t * utm)
{
- vl_api_bind_uri_t *bmp;
vl_api_unbind_uri_t *ump;
+ ump = vl_msg_api_alloc (sizeof (*ump));
+ memset (ump, 0, sizeof (*ump));
+
+ ump->_vl_msg_id = ntohs (VL_API_UNBIND_URI);
+ ump->client_index = utm->my_client_index;
+ memcpy (ump->uri, utm->uri, vec_len (utm->uri));
+ vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & ump);
+}
+
+static void
+server_bind (uri_udp_test_main_t * utm)
+{
+ vl_api_bind_uri_t *bmp;
+
bmp = vl_msg_api_alloc (sizeof (*bmp));
memset (bmp, 0, sizeof (*bmp));
bmp->_vl_msg_id = ntohs (VL_API_BIND_URI);
bmp->client_index = utm->my_client_index;
bmp->context = ntohl (0xfeedface);
- bmp->initial_segment_size = 256 << 20; /* size of initial segment */
- bmp->options[SESSION_OPTIONS_FLAGS] =
- SESSION_OPTIONS_FLAGS_USE_FIFO | SESSION_OPTIONS_FLAGS_ADD_SEGMENT;
- bmp->options[SESSION_OPTIONS_RX_FIFO_SIZE] = 16 << 10;
- bmp->options[SESSION_OPTIONS_TX_FIFO_SIZE] = 16 << 10;
- bmp->options[SESSION_OPTIONS_ADD_SEGMENT_SIZE] = 128 << 20;
memcpy (bmp->uri, utm->uri, vec_len (utm->uri));
vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & bmp);
+}
- if (wait_for_state_change (utm, STATE_READY))
+void
+udp_server_test (uri_udp_test_main_t * utm)
+{
+
+ application_send_attach (utm);
+
+ /* Bind to uri */
+ server_bind (utm);
+
+ if (wait_for_state_change (utm, STATE_BOUND))
{
- clib_warning ("timeout waiting for STATE_READY");
+ clib_warning ("timeout waiting for STATE_BOUND");
return;
}
server_handle_event_queue (utm);
- ump = vl_msg_api_alloc (sizeof (*ump));
- memset (ump, 0, sizeof (*ump));
-
- ump->_vl_msg_id = ntohs (VL_API_UNBIND_URI);
- ump->client_index = utm->my_client_index;
- memcpy (ump->uri, utm->uri, vec_len (utm->uri));
- vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & ump);
+ /* Cleanup */
+ server_unbind (utm);
if (wait_for_state_change (utm, STATE_START))
{
return;
}
+ application_detach (utm);
+
fformat (stdout, "Test complete...\n");
}
utm->i_am_master = i_am_master;
utm->segment_main = &svm_fifo_segment_main;
- utm->connect_uri = format (0, "udp://10.0.0.1/1234%c", 0);
+ utm->connect_uri = format (0, "udp://6.0.1.2/1234%c", 0);
setup_signal_handlers ();
if (i_am_master == 0)
{
- uri_udp_slave_test (utm);
+ client_test (utm);
exit (0);
}
for (i = 0; i < 200000; i++)
pool_put_index (utm->sessions, i);
- uri_udp_test (utm);
+ udp_server_test (utm);
vl_client_disconnect_from_vlib ();
exit (0);