diff options
-rw-r--r-- | src/plugins/hs_apps/sapi/vpp_echo.c | 89 | ||||
-rw-r--r-- | src/plugins/hs_apps/sapi/vpp_echo_bapi.c | 21 | ||||
-rw-r--r-- | src/plugins/hs_apps/sapi/vpp_echo_common.c | 22 | ||||
-rw-r--r-- | src/plugins/hs_apps/sapi/vpp_echo_common.h | 40 | ||||
-rw-r--r-- | src/plugins/hs_apps/sapi/vpp_echo_proto_quic.c | 24 |
5 files changed, 152 insertions, 44 deletions
diff --git a/src/plugins/hs_apps/sapi/vpp_echo.c b/src/plugins/hs_apps/sapi/vpp_echo.c index c94ff9d6cd8..019860a47c7 100644 --- a/src/plugins/hs_apps/sapi/vpp_echo.c +++ b/src/plugins/hs_apps/sapi/vpp_echo.c @@ -394,7 +394,7 @@ echo_handle_data (echo_main_t * em, echo_session_t * s, u8 * rx_buf) if (em->send_stream_disconnects == ECHO_CLOSE_F_ACTIVE) { echo_send_rpc (em, echo_send_disconnect_session, - (void *) s->vpp_session_handle, 0); + (echo_rpc_args_t *) & s->vpp_session_handle); clib_atomic_fetch_add (&em->stats.active_count.s, 1); } else if (em->send_stream_disconnects == ECHO_CLOSE_F_NONE) @@ -488,14 +488,16 @@ echo_data_thread_fn (void *arg) } static void -session_unlisten_handler (session_unlisten_msg_t * mp) +session_unlisten_handler (session_unlisten_reply_msg_t * mp) { - echo_session_t *listen_session; + echo_session_t *ls; echo_main_t *em = &echo_main; - listen_session = pool_elt_at_index (em->sessions, em->listen_session_index); - em->proto_cb_vft->cleanup_cb (listen_session, 0 /* parent_died */ ); - listen_session->session_state = ECHO_SESSION_STATE_CLOSED; - em->state = STATE_DISCONNECTED; + + ls = echo_get_session_from_handle (em, mp->handle); + em->proto_cb_vft->cleanup_cb (ls, 0 /* parent_died */ ); + ls->session_state = ECHO_SESSION_STATE_CLOSED; + if (--em->listen_session_cnt == 0) + em->state = STATE_DISCONNECTED; } static void @@ -518,8 +520,9 @@ session_bound_handler (session_bound_msg_t * mp) listen_session->session_type = ECHO_SESSION_TYPE_LISTEN; listen_session->vpp_session_handle = mp->handle; echo_session_handle_add_del (em, mp->handle, listen_session->session_index); - em->state = STATE_LISTEN; - em->listen_session_index = listen_session->session_index; + vec_add1 (em->listen_session_indexes, listen_session->session_index); + if (++em->listen_session_cnt == em->n_uris) + em->state = STATE_LISTEN; if (em->proto_cb_vft->bound_uri_cb) em->proto_cb_vft->bound_uri_cb (mp, listen_session); } @@ -718,7 +721,8 @@ handle_mq_event (session_event_t * e) case SESSION_CTRL_EVT_RESET: return session_reset_handler ((session_reset_msg_t *) e->data); case SESSION_CTRL_EVT_UNLISTEN_REPLY: - return session_unlisten_handler ((session_unlisten_msg_t *) e->data); + return session_unlisten_handler ((session_unlisten_reply_msg_t *) + e->data); case SESSION_IO_EVT_RX: break; default: @@ -744,7 +748,7 @@ echo_process_rpcs (echo_main_t * em) svm_msg_q_sub_w_lock (mq, &msg); rpc = svm_msg_q_msg_data (mq, &msg); svm_msg_q_unlock (mq); - ((echo_rpc_t) rpc->fp) (rpc->arg, rpc->opaque); + ((echo_rpc_t) rpc->fp) (em, &rpc->args); svm_msg_q_free_msg (mq, &msg); } } @@ -798,13 +802,43 @@ echo_mq_thread_fn (void *arg) pthread_exit (0); } +static inline void +echo_cycle_ip (echo_main_t * em, ip46_address_t * ip, ip46_address_t * src_ip, + u32 i) +{ + u8 *ipu8; + u8 l; + if (i % em->n_uris == 0) + { + clib_memcpy_fast (ip, src_ip, sizeof (*ip)); + return; + } + l = em->uri_elts.is_ip4 ? 3 : 15; + ipu8 = em->uri_elts.is_ip4 ? ip->ip4.as_u8 : ip->ip6.as_u8; + while (ipu8[l] == 0xf) + ipu8[l--] = 0; + if (l) + ipu8[l]++; +} + static void clients_run (echo_main_t * em) { + echo_connect_args_t _a, *a = &_a; u64 i; + + a->context = SESSION_INVALID_INDEX; + a->parent_session_handle = SESSION_INVALID_HANDLE; + clib_memset (&a->lcl_ip, 0, sizeof (a->lcl_ip)); + echo_notify_event (em, ECHO_EVT_FIRST_QCONNECT); for (i = 0; i < em->n_connects; i++) - echo_send_connect (SESSION_INVALID_HANDLE, SESSION_INVALID_INDEX); + { + echo_cycle_ip (em, &a->ip, &em->uri_elts.ip, i); + if (em->lcl_ip_set) + echo_cycle_ip (em, &a->lcl_ip, &em->lcl_ip, i); + echo_send_connect (em, a); + } wait_for_state_change (em, STATE_READY, 0); ECHO_LOG (2, "App is ready"); echo_process_rpcs (em); @@ -814,14 +848,25 @@ static void server_run (echo_main_t * em) { echo_session_t *ls; - echo_send_listen (em); + ip46_address_t _ip, *ip = &_ip; + u32 *listen_session_index; + u32 i; + + for (i = 0; i < em->n_uris; i++) + { + echo_cycle_ip (em, ip, &em->uri_elts.ip, i); + echo_send_listen (em, ip); + } wait_for_state_change (em, STATE_READY, 0); ECHO_LOG (2, "App is ready"); echo_process_rpcs (em); /* Cleanup */ - ECHO_LOG (2, "Unbind listen port"); - ls = pool_elt_at_index (em->sessions, em->listen_session_index); - echo_send_unbind (em, ls); + vec_foreach (listen_session_index, em->listen_session_indexes) + { + ECHO_LOG (2, "Unbind listen port %d", em->listen_session_cnt); + ls = pool_elt_at_index (em->sessions, *listen_session_index); + echo_send_unbind (em, ls); + } if (wait_for_state_change (em, STATE_DISCONNECTED, TIMEOUT)) { ECHO_FAIL (ECHO_FAIL_SERVER_DISCONNECT_TIMEOUT, @@ -854,6 +899,8 @@ print_usage_and_exit (void) " secret SECRET set namespace secret\n" " chroot prefix PATH Use PATH as memory root path\n" " sclose=[Y|N|W] When stream is done, send[Y]|nop[N]|wait[W] for close\n" + " nuris N Cycle through N consecutive (src&dst) ips when creating connections\n" + " lcl IP Set the local ip to use as a client (use with nuris to set first src ip)\n" "\n" " time START:END Time between evts START & END, events being :\n" " start - Start of the app\n" @@ -931,6 +978,10 @@ echo_process_opts (int argc, char **argv) vl_set_memory_root_path ((char *) chroot_prefix); else if (unformat (a, "uri %s", &uri)) em->uri = format (0, "%s%c", uri, 0); + else if (unformat (a, "lcl %U", unformat_ip46_address, &em->lcl_ip)) + em->lcl_ip_set = 1; + else if (unformat (a, "nuris %u", &em->n_uris)) + em->n_sessions = em->n_clients + em->n_uris; else if (unformat (a, "server")) em->i_am_master = 1; else if (unformat (a, "client")) @@ -965,7 +1016,7 @@ echo_process_opts (int argc, char **argv) ; else if (unformat (a, "nclients %d", &em->n_clients)) { - em->n_sessions = em->n_clients + 1; + em->n_sessions = em->n_clients + em->n_uris; em->n_connects = em->n_clients; } else if (unformat (a, "nthreads %d", &em->n_rx_threads)) @@ -1113,6 +1164,8 @@ main (int argc, char **argv) em->i_am_master = 1; em->n_rx_threads = 4; em->evt_q_size = 256; + em->lcl_ip_set = 0; + clib_memset (&em->lcl_ip, 0, sizeof (em->lcl_ip)); em->test_return_packets = RETURN_PACKETS_NOTEST; em->timing.start_event = ECHO_EVT_FIRST_QCONNECT; em->timing.end_event = ECHO_EVT_LAST_BYTE; @@ -1122,7 +1175,9 @@ main (int argc, char **argv) em->tx_buf_size = 1 << 20; em->data_source = ECHO_INVALID_DATA_SOURCE; em->uri = format (0, "%s%c", "tcp://0.0.0.0/1234", 0); + em->n_uris = 1; em->max_sim_connects = 0; + em->listen_session_cnt = 0; em->crypto_engine = CRYPTO_ENGINE_NONE; echo_set_each_proto_defaults_before_opts (em); echo_process_opts (argc, argv); diff --git a/src/plugins/hs_apps/sapi/vpp_echo_bapi.c b/src/plugins/hs_apps/sapi/vpp_echo_bapi.c index f343ad12865..955d60697d9 100644 --- a/src/plugins/hs_apps/sapi/vpp_echo_bapi.c +++ b/src/plugins/hs_apps/sapi/vpp_echo_bapi.c @@ -103,7 +103,7 @@ echo_send_del_cert_key (echo_main_t * em) } void -echo_send_listen (echo_main_t * em) +echo_send_listen (echo_main_t * em, ip46_address_t * ip) { app_session_evt_t _app_evt, *app_evt = &_app_evt; session_listen_msg_t *mp; @@ -116,7 +116,7 @@ echo_send_listen (echo_main_t * em) mp->context = ntohl (0xfeedface); mp->wrk_index = 0; mp->is_ip4 = em->uri_elts.is_ip4; - clib_memcpy_fast (&mp->ip, &em->uri_elts.ip, sizeof (mp->ip)); + clib_memcpy_fast (&mp->ip, ip, sizeof (mp->ip)); mp->port = em->uri_elts.port; mp->proto = em->uri_elts.transport_proto; mp->ckpair_index = em->ckpair_index; @@ -142,11 +142,11 @@ echo_send_unbind (echo_main_t * em, echo_session_t * s) } void -echo_send_connect (u64 parent_session_handle, u32 opaque) +echo_send_connect (echo_main_t * em, void *args) { - echo_main_t *em = &echo_main; app_session_evt_t _app_evt, *app_evt = &_app_evt; session_connect_msg_t *mp; + echo_connect_args_t *a = (echo_connect_args_t *) args; svm_msg_q_t *mq = em->ctrl_mq; clib_atomic_sub_fetch (&em->max_sim_connects, 1); @@ -157,32 +157,33 @@ echo_send_connect (u64 parent_session_handle, u32 opaque) mp = (session_connect_msg_t *) app_evt->evt->data; memset (mp, 0, sizeof (*mp)); mp->client_index = em->my_client_index; - mp->context = ntohl (opaque); + mp->context = ntohl (a->context); mp->wrk_index = 0; mp->is_ip4 = em->uri_elts.is_ip4; - clib_memcpy_fast (&mp->ip, &em->uri_elts.ip, sizeof (mp->ip)); + clib_memcpy_fast (&mp->ip, &a->ip, sizeof (mp->ip)); + clib_memcpy_fast (&mp->lcl_ip, &a->lcl_ip, sizeof (mp->ip)); mp->port = em->uri_elts.port; mp->proto = em->uri_elts.transport_proto; - mp->parent_handle = parent_session_handle; + mp->parent_handle = a->parent_session_handle; mp->ckpair_index = em->ckpair_index; mp->crypto_engine = em->crypto_engine; app_send_ctrl_evt_to_vpp (mq, app_evt); } void -echo_send_disconnect_session (u64 handle, u32 opaque) +echo_send_disconnect_session (echo_main_t * em, void *args) { - echo_main_t *em = &echo_main; echo_session_t *s; app_session_evt_t _app_evt, *app_evt = &_app_evt; session_disconnect_msg_t *mp; svm_msg_q_t *mq = em->ctrl_mq; + echo_disconnect_args_t *a = (echo_disconnect_args_t *) args; app_alloc_ctrl_evt_to_vpp (mq, app_evt, SESSION_CTRL_EVT_DISCONNECT); mp = (session_disconnect_msg_t *) app_evt->evt->data; memset (mp, 0, sizeof (*mp)); mp->client_index = em->my_client_index; - mp->handle = handle; + mp->handle = a->session_handle; app_send_ctrl_evt_to_vpp (mq, app_evt); if (!(s = echo_get_session_from_handle (em, mp->handle))) diff --git a/src/plugins/hs_apps/sapi/vpp_echo_common.c b/src/plugins/hs_apps/sapi/vpp_echo_common.c index a5bdeb4f27b..e7829f3ab89 100644 --- a/src/plugins/hs_apps/sapi/vpp_echo_common.c +++ b/src/plugins/hs_apps/sapi/vpp_echo_common.c @@ -457,6 +457,20 @@ unformat_ip6_address (unformat_input_t * input, va_list * args) } } +uword +unformat_ip46_address (unformat_input_t * input, va_list * args) +{ + ip46_address_t *ip = va_arg (*args, ip46_address_t *); + + if (unformat (input, "%U", unformat_ip4_address, &ip->ip4)) + ; + else if (unformat (input, "%U", unformat_ip6_address, &ip->ip6)) + ; + else + return 0; + return 1; +} + u8 * echo_format_crypto_engine (u8 * s, va_list * args) { @@ -517,14 +531,15 @@ echo_session_handle_add_del (echo_main_t * em, u64 handle, u32 sid) echo_session_t * echo_session_new (echo_main_t * em) { - /* thread safe new prealloced session */ + /* thread safe new prealloced session + * see echo_session_prealloc */ return pool_elt_at_index (em->sessions, clib_atomic_fetch_add (&em->nxt_available_sidx, 1)); } int -echo_send_rpc (echo_main_t * em, void *fp, void *arg, u32 opaque) +echo_send_rpc (echo_main_t * em, void *fp, echo_rpc_args_t * args) { svm_msg_q_msg_t msg; echo_rpc_msg_t *evt; @@ -541,9 +556,8 @@ echo_send_rpc (echo_main_t * em, void *fp, void *arg, u32 opaque) } msg = svm_msg_q_alloc_msg_w_ring (em->rpc_msq_queue, 0); evt = (echo_rpc_msg_t *) svm_msg_q_msg_data (em->rpc_msq_queue, &msg); - evt->arg = arg; - evt->opaque = opaque; evt->fp = fp; + clib_memcpy (&evt->args, args, sizeof (evt->args)); svm_msg_q_add_and_unlock (em->rpc_msq_queue, &msg); return 0; diff --git a/src/plugins/hs_apps/sapi/vpp_echo_common.h b/src/plugins/hs_apps/sapi/vpp_echo_common.h index 00d54f83070..5588b279327 100644 --- a/src/plugins/hs_apps/sapi/vpp_echo_common.h +++ b/src/plugins/hs_apps/sapi/vpp_echo_common.h @@ -266,13 +266,17 @@ typedef struct svm_queue_t *vl_input_queue; /* vpe input queue */ u32 my_client_index; /* API client handle */ u8 *uri; /* The URI we're playing with */ + u32 n_uris; /* Cycle through adjacent ips */ + ip46_address_t lcl_ip; /* Local ip for client */ + u8 lcl_ip_set; echo_session_t *sessions; /* Session pool */ svm_msg_q_t *app_mq; /* Our receiveing event queue */ svm_msg_q_t *ctrl_mq; /* Our control queue (towards vpp) */ clib_time_t clib_time; /* For deadman timers */ u8 *socket_name; int i_am_master; - u32 listen_session_index; /* Index of vpp listener session */ + u32 *listen_session_indexes; /* vec of vpp listener sessions */ + volatile u32 listen_session_cnt; uword *session_index_by_vpp_handles; /* Hash table : quic_echo s_id -> vpp s_handle */ clib_spinlock_t sid_vpp_handles_lock; /* Hash table lock */ @@ -370,15 +374,35 @@ typedef struct extern echo_main_t echo_main; -typedef void (*echo_rpc_t) (void *arg, u32 opaque); + +typedef struct echo_connect_args_ +{ + u32 context; + u64 parent_session_handle; + ip46_address_t ip; + ip46_address_t lcl_ip; +} echo_connect_args_t; + +typedef struct echo_disconnect_args_ +{ + u64 session_handle; +} echo_disconnect_args_t; + +typedef union +{ + echo_connect_args_t connect; + echo_disconnect_args_t disconnect; +} echo_rpc_args_t; + +typedef void (*echo_rpc_t) (echo_main_t * em, echo_rpc_args_t * arg); typedef struct { void *fp; - void *arg; - u32 opaque; + echo_rpc_args_t args; } echo_rpc_msg_t; + u8 *format_ip4_address (u8 * s, va_list * args); u8 *format_ip6_address (u8 * s, va_list * args); u8 *format_ip46_address (u8 * s, va_list * args); @@ -398,7 +422,7 @@ uword unformat_ip6_address (unformat_input_t * input, va_list * args); void echo_session_handle_add_del (echo_main_t * em, u64 handle, u32 sid); echo_session_t *echo_session_new (echo_main_t * em); -int echo_send_rpc (echo_main_t * em, void *fp, void *arg, u32 opaque); +int echo_send_rpc (echo_main_t * em, void *fp, echo_rpc_args_t * args); echo_session_t *echo_get_session_from_handle (echo_main_t * em, u64 handle); int wait_for_segment_allocation (u64 segment_handle); int wait_for_state_change (echo_main_t * em, connection_state_t state, @@ -412,10 +436,10 @@ uword echo_unformat_crypto_engine (unformat_input_t * input, va_list * args); void echo_send_attach (echo_main_t * em); void echo_send_detach (echo_main_t * em); -void echo_send_listen (echo_main_t * em); +void echo_send_listen (echo_main_t * em, ip46_address_t * ip); void echo_send_unbind (echo_main_t * em, echo_session_t * s); -void echo_send_connect (u64 vpp_session_handle, u32 opaque); -void echo_send_disconnect_session (u64 handle, u32 opaque); +void echo_send_connect (echo_main_t * em, void *args); +void echo_send_disconnect_session (echo_main_t * em, void *args); void echo_api_hookup (echo_main_t * em); void echo_send_add_cert_key (echo_main_t * em); void echo_send_del_cert_key (echo_main_t * em); diff --git a/src/plugins/hs_apps/sapi/vpp_echo_proto_quic.c b/src/plugins/hs_apps/sapi/vpp_echo_proto_quic.c index 18b70dd2257..55fd89097f2 100644 --- a/src/plugins/hs_apps/sapi/vpp_echo_proto_quic.c +++ b/src/plugins/hs_apps/sapi/vpp_echo_proto_quic.c @@ -54,11 +54,17 @@ quic_echo_on_connected_connect (session_connected_msg_t * mp, { echo_main_t *em = &echo_main; quic_echo_proto_main_t *eqm = &quic_echo_proto_main; + echo_connect_args_t _a, *a = &_a; u64 i; + a->parent_session_handle = mp->handle; + a->context = session_index; + clib_memcpy_fast (&a->lcl_ip, &em->lcl_ip, sizeof (ip46_address_t)); + clib_memcpy_fast (&a->ip, &em->uri_elts.ip, sizeof (ip46_address_t)); + echo_notify_event (em, ECHO_EVT_FIRST_SCONNECT); for (i = 0; i < eqm->n_stream_clients; i++) - echo_send_rpc (em, echo_send_connect, (void *) mp->handle, session_index); + echo_send_rpc (em, echo_send_connect, (echo_rpc_args_t *) a); ECHO_LOG (1, "Qsession 0x%llx S[%d] connected to %U:%d", mp->handle, session_index, format_ip46_address, &mp->lcl.ip, @@ -107,11 +113,17 @@ quic_echo_on_accept_connect (session_accepted_msg_t * mp, u32 session_index) echo_main_t *em = &echo_main; quic_echo_proto_main_t *eqm = &quic_echo_proto_main; ECHO_LOG (2, "Accept on QSession 0x%lx S[%u]", mp->handle, session_index); + echo_connect_args_t _a, *a = &_a; u32 i; + a->parent_session_handle = mp->handle; + a->context = session_index; + clib_memcpy_fast (&a->lcl_ip, &em->lcl_ip, sizeof (ip46_address_t)); + clib_memcpy_fast (&a->ip, &em->uri_elts.ip, sizeof (ip46_address_t)); + echo_notify_event (em, ECHO_EVT_FIRST_SCONNECT); for (i = 0; i < eqm->n_stream_clients; i++) - echo_send_rpc (em, echo_send_connect, (void *) mp->handle, session_index); + echo_send_rpc (em, echo_send_connect, (echo_rpc_args_t *) a); } static void @@ -175,7 +187,7 @@ quic_echo_cleanup_listener (u32 listener_index, echo_main_t * em, if (eqm->send_quic_disconnects == ECHO_CLOSE_F_ACTIVE) { echo_send_rpc (em, echo_send_disconnect_session, - (void *) ls->vpp_session_handle, 0); + (echo_rpc_args_t *) & ls->vpp_session_handle); clib_atomic_fetch_add (&em->stats.active_count.q, 1); } else if (eqm->send_quic_disconnects == ECHO_CLOSE_F_NONE) @@ -236,7 +248,7 @@ quic_echo_initiate_qsession_close_no_stream (echo_main_t * em) { ECHO_LOG (2,"%U: ACTIVE close", echo_format_session, s); echo_send_rpc (em, echo_send_disconnect_session, - (void *) s->vpp_session_handle, 0); + (echo_rpc_args_t *) &s->vpp_session_handle); clib_atomic_fetch_add (&em->stats.active_count.q, 1); } else if (eqm->send_quic_disconnects == ECHO_CLOSE_F_NONE) @@ -466,7 +478,9 @@ quic_echo_set_defaults_after_opts_cb () em->n_connects = em->n_clients; em->n_sessions = - clib_max (1, eqm->n_stream_clients) * em->n_clients + em->n_clients + 1; + clib_max (1, + eqm->n_stream_clients) * em->n_clients + em->n_clients + + em->n_uris; em->n_clients = eqm->n_stream_clients * em->n_clients; if (em->i_am_master) |