summaryrefslogtreecommitdiffstats
path: root/src/tests/vnet/session/tcp_echo.c
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2017-12-19 04:50:01 -0800
committerDave Barach <openvpp@barachs.net>2018-01-05 19:00:45 +0000
commit90a63988fa01685626b6d6a01b79ea5370f7fbac (patch)
tree69951111b8f8c43c5dbfc61cc5b133f74a58ddda /src/tests/vnet/session/tcp_echo.c
parente6bfeab1c352ae73a19361c038e2a06a58c035db (diff)
sock api: add infra for bootstrapping shm clients
- add function to sock client that bootstraps shm api - allow sock clients to request custom shm ring configs Change-Id: Iabc1dd4f0dc8bbf8ba24de37f4966339fcf86107 Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/tests/vnet/session/tcp_echo.c')
-rw-r--r--src/tests/vnet/session/tcp_echo.c112
1 files changed, 73 insertions, 39 deletions
diff --git a/src/tests/vnet/session/tcp_echo.c b/src/tests/vnet/session/tcp_echo.c
index 8bdcac3a88c..30eb54dcdda 100644
--- a/src/tests/vnet/session/tcp_echo.c
+++ b/src/tests/vnet/session/tcp_echo.c
@@ -15,10 +15,12 @@
#include <stdio.h>
#include <signal.h>
+
+#include <vnet/session/application_interface.h>
#include <svm/svm_fifo_segment.h>
#include <vlibmemory/api.h>
+
#include <vpp/api/vpe_msg_enum.h>
-#include <vnet/session/application_interface.h>
#define vl_typedefs /* define message structures */
#include <vpp/api/vpe_all_api_h.h>
@@ -91,6 +93,8 @@ typedef struct
/* $$$ single thread only for the moment */
unix_shared_memory_queue_t *vpp_event_queue;
+ u8 *socket_name;
+
pid_t my_pid;
/* For deadman timers */
@@ -114,6 +118,11 @@ typedef struct
u8 test_return_packets;
u64 bytes_to_send;
+ /** Flag that decides if socket, instead of svm, api is used to connect to
+ * vpp. If sock api is used, shm binary api is subsequently bootstrapped
+ * and all other messages are exchanged using shm IPC. */
+ u8 use_sock_api;
+
/* convenience */
svm_fifo_segment_main_t *segment_main;
} uri_tcp_test_main_t;
@@ -313,15 +322,33 @@ connect_to_vpp (char *name)
uri_tcp_test_main_t *utm = &uri_tcp_test_main;
api_main_t *am = &api_main;
- if (vl_client_connect_to_vlib ("/vpe-api", name, 32) < 0)
- return -1;
-
- utm->vl_input_queue = am->shmem_hdr->vl_input_queue;
- utm->my_client_index = am->my_client_index;
+ if (utm->use_sock_api)
+ {
+ if (vl_socket_client_connect ((char *) utm->socket_name, name,
+ 0 /* default rx, tx buffer */ ))
+ return -1;
+ return vl_socket_client_init_shm (0);
+ }
+ else
+ {
+ if (vl_client_connect_to_vlib ("/vpe-api", name, 32) < 0)
+ return -1;
+ utm->vl_input_queue = am->shmem_hdr->vl_input_queue;
+ utm->my_client_index = am->my_client_index;
+ }
return 0;
}
+void
+disconnect_from_vpp (uri_tcp_test_main_t * utm)
+{
+ if (utm->use_sock_api)
+ vl_socket_client_disconnect ();
+ else
+ vl_client_disconnect_from_vlib ();
+}
+
static void
vl_api_map_another_segment_t_handler (vl_api_map_another_segment_t * mp)
{
@@ -733,7 +760,7 @@ client_disconnect (uri_tcp_test_main_t * utm)
}
static void
-client_test (uri_tcp_test_main_t * utm)
+client_run (uri_tcp_test_main_t * utm)
{
int i;
@@ -1085,8 +1112,20 @@ server_unbind (uri_tcp_test_main_t * utm)
}
void
-server_test (uri_tcp_test_main_t * utm)
+server_run (uri_tcp_test_main_t * utm)
{
+ session_t *session;
+ int i;
+
+ /* $$$$ hack preallocation */
+ for (i = 0; i < 200000; i++)
+ {
+ pool_get (utm->sessions, session);
+ memset (session, 0, sizeof (*session));
+ }
+ for (i = 0; i < 200000; i++)
+ pool_put_index (utm->sessions, i);
+
if (application_attach (utm))
return;
@@ -1124,17 +1163,17 @@ vl_api_disconnect_session_reply_t_handler (vl_api_disconnect_session_reply_t *
session_print_stats (utm, session);
}
-#define foreach_uri_msg \
-_(BIND_URI_REPLY, bind_uri_reply) \
-_(UNBIND_URI_REPLY, unbind_uri_reply) \
-_(ACCEPT_SESSION, accept_session) \
-_(CONNECT_SESSION_REPLY, connect_session_reply) \
-_(DISCONNECT_SESSION, disconnect_session) \
-_(DISCONNECT_SESSION_REPLY, disconnect_session_reply) \
-_(RESET_SESSION, reset_session) \
-_(APPLICATION_ATTACH_REPLY, application_attach_reply) \
-_(APPLICATION_DETACH_REPLY, application_detach_reply) \
-_(MAP_ANOTHER_SEGMENT, map_another_segment) \
+#define foreach_uri_msg \
+_(BIND_URI_REPLY, bind_uri_reply) \
+_(UNBIND_URI_REPLY, unbind_uri_reply) \
+_(ACCEPT_SESSION, accept_session) \
+_(CONNECT_SESSION_REPLY, connect_session_reply) \
+_(DISCONNECT_SESSION, disconnect_session) \
+_(DISCONNECT_SESSION_REPLY, disconnect_session_reply) \
+_(RESET_SESSION, reset_session) \
+_(APPLICATION_ATTACH_REPLY, application_attach_reply) \
+_(APPLICATION_DETACH_REPLY, application_detach_reply) \
+_(MAP_ANOTHER_SEGMENT, map_another_segment) \
void
uri_api_hookup (uri_tcp_test_main_t * utm)
@@ -1162,8 +1201,6 @@ main (int argc, char **argv)
u64 bytes_to_send = 64 << 10, mbytes;
u32 tmp;
mheap_t *h;
- session_t *session;
- int i;
int i_am_master = 1, drop_packets = 0, test_return_packets = 0;
clib_mem_init (0, 256 << 20);
@@ -1180,6 +1217,8 @@ main (int argc, char **argv)
utm->my_pid = getpid ();
utm->configured_segment_size = 1 << 20;
+ utm->socket_name = 0;
+ utm->use_sock_api = 1;
clib_time_init (&utm->clib_time);
init_error_string_table (utm);
@@ -1214,6 +1253,10 @@ main (int argc, char **argv)
{
bytes_to_send = mbytes << 30;
}
+ else if (unformat (a, "socket-name %s", &utm->socket_name))
+ ;
+ else if (unformat (a, "use-svm-api"))
+ utm->use_sock_api = 0;
else
{
fformat (stderr, "%s: usage [master|slave]\n");
@@ -1221,6 +1264,9 @@ main (int argc, char **argv)
}
}
+ if (!utm->socket_name)
+ utm->socket_name = format (0, "%s%c", API_SOCKET_FILE, 0);
+
if (uri)
{
utm->uri = format (0, "%s%c", uri, 0);
@@ -1242,7 +1288,8 @@ main (int argc, char **argv)
setup_signal_handlers ();
uri_api_hookup (utm);
- if (connect_to_vpp (i_am_master ? "uri_tcp_server" : "uri_tcp_client") < 0)
+ if (connect_to_vpp (i_am_master ? "tcp_echo_server" : "tcp_echo_client") <
+ 0)
{
svm_region_exit ();
fformat (stderr, "Couldn't connect to vpe, exiting...\n");
@@ -1250,24 +1297,11 @@ main (int argc, char **argv)
}
if (i_am_master == 0)
- {
- client_test (utm);
- vl_client_disconnect_from_vlib ();
- exit (0);
- }
-
- /* $$$$ hack preallocation */
- for (i = 0; i < 200000; i++)
- {
- pool_get (utm->sessions, session);
- memset (session, 0, sizeof (*session));
- }
- for (i = 0; i < 200000; i++)
- pool_put_index (utm->sessions, i);
-
- server_test (utm);
+ client_run (utm);
+ else
+ server_run (utm);
- vl_client_disconnect_from_vlib ();
+ disconnect_from_vpp (utm);
exit (0);
}