volatile u32 connected_session_thread = ~0;
int
dummy_session_connected_callback (u32 app_index, u32 api_context,
- session_t * s, u8 is_fail)
+ session_t * s, session_error_t err)
{
if (s)
{
{
/* fails spectacularly */
/* vnet_delete_loopback_interface (sw_if_index); */
+
+ vnet_sw_interface_set_flags (vnet_get_main (), sw_if_index, 0);
}
static int
session_test_basic (vlib_main_t * vm, unformat_input_t * input)
{
- session_endpoint_t server_sep = SESSION_ENDPOINT_NULL;
+ session_endpoint_cfg_t server_sep = SESSION_ENDPOINT_CFG_NULL;
u64 options[APP_OPTIONS_N_OPTIONS], bind4_handle, bind6_handle;
u32 server_index;
int error = 0;
server_sep.is_ip4 = 1;
vnet_listen_args_t bind_args = {
- .sep = server_sep,
+ .sep_ext = server_sep,
.app_index = 0,
+ .wrk_map_index = 0,
};
bind_args.app_index = server_index;
u32 server_index, client_index, sw_if_index[2], tries = 0;
u64 options[APP_OPTIONS_N_OPTIONS], dummy_secret = 1234;
u16 dummy_server_port = 1234, dummy_client_port = 5678;
- session_endpoint_t server_sep = SESSION_ENDPOINT_NULL;
+ session_endpoint_cfg_t server_sep = SESSION_ENDPOINT_CFG_NULL;
ip4_address_t intf_addr[3];
transport_connection_t *tc;
session_t *s;
server_sep.is_ip4 = 1;
server_sep.port = dummy_server_port;
vnet_listen_args_t bind_args = {
- .sep = server_sep,
+ .sep_ext = server_sep,
.app_index = server_index,
};
error = vnet_listen (&bind_args);
SESSION_TEST ((error == 0), "connect should work");
/* wait for stuff to happen */
- while ((connected_session_index == ~0
- || vec_len (tcp_main.wrk_ctx[0].pending_acks)) && ++tries < 100)
+ while (connected_session_index == ~0 && ++tries < 100)
vlib_process_suspend (vm, 100e-3);
clib_warning ("waited %.1f seconds for connections", tries / 10.0);
SESSION_TEST ((connected_session_index != ~0), "session should exist");
connect_args.app_index = client_index;
error = vnet_connect (&connect_args);
SESSION_TEST ((error != 0), "client connect should return error code");
- SESSION_TEST ((error == VNET_API_ERROR_INVALID_VALUE),
+ SESSION_TEST ((error == SESSION_E_INVALID_RMT_IP),
"error code should be invalid value (zero ip)");
SESSION_TEST ((dummy_segment_count == 0),
"shouldn't have received request to map new segment");
SESSION_TEST ((error == 0), "client attachment should work");
error = vnet_connect (&connect_args);
SESSION_TEST ((error != 0), "client connect should return error code");
- SESSION_TEST ((error == VNET_API_ERROR_SESSION_CONNECT),
+ SESSION_TEST ((error == SESSION_E_NOINTF),
"error code should be connect (nothing in local scope)");
detach_args.app_index = client_index;
vnet_application_detach (&detach_args);
vnet_application_attach (&attach_args);
error = vnet_connect (&connect_args);
SESSION_TEST ((error != 0), "client connect should return error code");
- SESSION_TEST ((error == VNET_API_ERROR_SESSION_CONNECT),
- "error code should be connect (not in same ns)");
+ SESSION_TEST ((error == SESSION_E_NOROUTE),
+ "error code should be noroute (not in same ns)");
detach_args.app_index = client_index;
vnet_application_detach (&detach_args);
/* Try connecting */
error = vnet_connect (&connect_args);
SESSION_TEST ((error != 0), "connect should fail");
- SESSION_TEST ((error == VNET_API_ERROR_APP_CONNECT_FILTERED),
- "connect should be filtered");
+ SESSION_TEST ((error == SESSION_E_FILTERED), "connect should be filtered");
sep.ip.ip4.as_u32 -= 1 << 24;
error = vnet_connect (&connect_args);
SESSION_TEST ((error != 0), "connect should fail");
- SESSION_TEST ((error == VNET_API_ERROR_APP_CONNECT_FILTERED),
- "connect should be filtered");
+ SESSION_TEST ((error == SESSION_E_FILTERED), "connect should be filtered");
/*
* Lookup test namespace
connect_args.app_index = server_index;
error = vnet_connect (&connect_args);
SESSION_TEST ((error != 0), "connect should fail");
- SESSION_TEST ((error == VNET_API_ERROR_APP_CONNECT_FILTERED),
- "connect should be filtered");
+ SESSION_TEST ((error == SESSION_E_FILTERED), "connect should be filtered");
args.table_args.is_add = 0;
vnet_session_rule_add_del (&args);
if (verbose)
unformat_free (&tmp_input);
vec_free (attach_args.name);
+ session_delete_loopback (sw_if_index);
return 0;
}
}
static int
-session_test_mq (vlib_main_t * vm, unformat_input_t * input)
+session_test_mq_speed (vlib_main_t * vm, unformat_input_t * input)
{
int error, __clib_unused verbose, use_eventfd = 0;
u64 i, n_test_msgs = 1 << 10, *counter;
vl_api_registration_t *reg;
struct epoll_event ep_evt;
u32 app_index, api_index;
- u32 fifo_segment_index;
app_worker_t *app_wrk;
segment_manager_t *sm;
svm_msg_q_msg_t msg;
}
sm = app_worker_get_or_alloc_connect_segment_manager (app_wrk);
- segment_manager_alloc_session_fifos (sm, &rx_fifo, &tx_fifo,
- &fifo_segment_index);
+ segment_manager_alloc_session_fifos (sm, 0, &rx_fifo, &tx_fifo);
s.rx_fifo = rx_fifo;
s.tx_fifo = tx_fifo;
s.session_state = SESSION_STATE_READY;
return 0;
}
+static int
+session_test_mq_basic (vlib_main_t * vm, unformat_input_t * input)
+{
+ svm_msg_q_cfg_t _cfg, *cfg = &_cfg;
+ svm_msg_q_msg_t msg1, msg2, msg[12];
+ int __clib_unused verbose, i, rv;
+ svm_msg_q_t *mq;
+ svm_msg_q_ring_t *ring;
+ u8 *rings_ptr;
+
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (input, "verbose"))
+ verbose = 1;
+ else
+ {
+ vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
+ input);
+ return -1;
+ }
+ }
+
+ svm_msg_q_ring_cfg_t rc[2] = { {8, 8, 0}
+ , {8, 16, 0}
+ };
+ cfg->consumer_pid = ~0;
+ cfg->n_rings = 2;
+ cfg->q_nitems = 16;
+ cfg->ring_cfgs = rc;
+
+ mq = svm_msg_q_alloc (cfg);
+ SESSION_TEST (mq != 0, "svm_msg_q_alloc");
+ SESSION_TEST (vec_len (mq->rings) == 2, "ring allocation");
+ rings_ptr = (u8 *) mq->rings + vec_bytes (mq->rings);
+ vec_foreach (ring, mq->rings)
+ {
+ SESSION_TEST (ring->data == rings_ptr, "ring data");
+ rings_ptr += (uword) ring->nitems * ring->elsize;
+ }
+
+ msg1 = svm_msg_q_alloc_msg (mq, 8);
+ rv = (mq->rings[0].cursize != 1
+ || msg1.ring_index != 0 || msg1.elt_index != 0);
+ SESSION_TEST (rv == 0, "msg alloc1");
+
+ msg2 = svm_msg_q_alloc_msg (mq, 15);
+ rv = (mq->rings[1].cursize != 1
+ || msg2.ring_index != 1 || msg2.elt_index != 0);
+ SESSION_TEST (rv == 0, "msg alloc2");
+
+ svm_msg_q_free_msg (mq, &msg1);
+ SESSION_TEST (mq->rings[0].cursize == 0, "free msg");
+
+ for (i = 0; i < 12; i++)
+ {
+ msg[i] = svm_msg_q_alloc_msg (mq, 7);
+ *(u32 *) svm_msg_q_msg_data (mq, &msg[i]) = i;
+ }
+
+ rv = (mq->rings[0].cursize != 8 || mq->rings[1].cursize != 5);
+ SESSION_TEST (rv == 0, "msg alloc3");
+
+ *(u32 *) svm_msg_q_msg_data (mq, &msg2) = 123;
+ svm_msg_q_add (mq, &msg2, SVM_Q_NOWAIT);
+ for (i = 0; i < 12; i++)
+ svm_msg_q_add (mq, &msg[i], SVM_Q_NOWAIT);
+
+ rv = svm_msg_q_sub (mq, &msg2, SVM_Q_NOWAIT, 0);
+ SESSION_TEST (rv == 0, "dequeue1");
+
+ SESSION_TEST (msg2.ring_index == 1 && msg2.elt_index == 0,
+ "dequeue1 result");
+ rv = (*(u32 *) svm_msg_q_msg_data (mq, &msg2) == 123);
+ SESSION_TEST (rv, "dequeue 1 data");
+
+ svm_msg_q_free_msg (mq, &msg2);
+
+ for (i = 0; i < 12; i++)
+ {
+ if (svm_msg_q_sub (mq, &msg[i], SVM_Q_NOWAIT, 0))
+ SESSION_TEST (0, "dequeue2");
+ if (i < 8)
+ {
+ if (msg[i].ring_index != 0 || msg[i].elt_index != (i + 1) % 8)
+ SESSION_TEST (0, "dequeue2 result2");
+ }
+ else
+ {
+ if (msg[i].ring_index != 1 || msg[i].elt_index != (i - 8) + 1)
+ SESSION_TEST (0, "dequeue2 result3");
+ }
+ if (*(u32 *) svm_msg_q_msg_data (mq, &msg[i]) != i)
+ SESSION_TEST (0, "dequeue2 wrong data");
+ svm_msg_q_free_msg (mq, &msg[i]);
+ }
+ rv = (mq->rings[0].cursize == 0 && mq->rings[1].cursize == 0);
+ SESSION_TEST (rv, "post dequeue");
+
+ return 0;
+}
+
static clib_error_t *
session_test (vlib_main_t * vm,
unformat_input_t * input, vlib_cli_command_t * cmd_arg)
res = session_test_proxy (vm, input);
else if (unformat (input, "endpt-cfg"))
res = session_test_endpoint_cfg (vm, input);
- else if (unformat (input, "mq"))
- res = session_test_mq (vm, input);
+ else if (unformat (input, "mq-speed"))
+ res = session_test_mq_speed (vm, input);
+ else if (unformat (input, "mq-basic"))
+ res = session_test_mq_basic (vm, input);
else if (unformat (input, "all"))
{
if ((res = session_test_basic (vm, input)))
goto done;
if ((res = session_test_endpoint_cfg (vm, input)))
goto done;
- if ((res = session_test_mq (vm, input)))
+ if ((res = session_test_mq_speed (vm, input)))
+ goto done;
+ if ((res = session_test_mq_basic (vm, input)))
goto done;
}
else