X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fsession-apps%2Fproxy.c;h=06c095440bcc7b22f2042bfd3bb7b08b55683288;hb=ad9d528;hp=2fdb63f1780265e7e1c0113b4e38556738a4185e;hpb=4399c2eb848b79762ff52a95fa5d9fab222c73bd;p=vpp.git diff --git a/src/vnet/session-apps/proxy.c b/src/vnet/session-apps/proxy.c index 2fdb63f1780..06c095440bc 100644 --- a/src/vnet/session-apps/proxy.c +++ b/src/vnet/session-apps/proxy.c @@ -21,6 +21,43 @@ proxy_main_t proxy_main; +typedef struct +{ + char uri[128]; + u32 app_index; + u32 api_context; +} proxy_connect_args_t; + +static void +proxy_cb_fn (void *data, u32 data_len) +{ + proxy_connect_args_t *pa = (proxy_connect_args_t *) data; + vnet_connect_args_t a; + + memset (&a, 0, sizeof (a)); + a.api_context = pa->api_context; + a.app_index = pa->app_index; + a.uri = pa->uri; + vnet_connect_uri (&a); +} + +static void +proxy_call_main_thread (vnet_connect_args_t * a) +{ + if (vlib_get_thread_index () == 0) + { + vnet_connect_uri (a); + } + else + { + proxy_connect_args_t args; + args.api_context = a->api_context; + args.app_index = a->app_index; + clib_memcpy (args.uri, a->uri, vec_len (a->uri)); + vl_api_rpc_call_main_thread (proxy_cb_fn, (u8 *) & args, sizeof (args)); + } +} + static void delete_proxy_session (stream_session_t * s, int is_active_open) { @@ -46,7 +83,7 @@ delete_proxy_session (stream_session_t * s, int is_active_open) is_active_open ? "active open" : "server", handle, handle); } - else + else if (!pool_is_free_index (pm->sessions, p[0])) { ps = pool_elt_at_index (pm->sessions, p[0]); if (ps->vpp_server_handle != ~0) @@ -66,12 +103,12 @@ delete_proxy_session (stream_session_t * s, int is_active_open) is_active_open ? "active open" : "server", handle, handle); } - else + else if (!pool_is_free_index (pm->sessions, p[0])) { ps = pool_elt_at_index (pm->sessions, p[0]); - if (ps->vpp_server_handle != ~0) + if (ps->vpp_active_open_handle != ~0) active_open_session = session_get_from_handle - (ps->vpp_server_handle); + (ps->vpp_active_open_handle); else active_open_session = 0; } @@ -80,7 +117,7 @@ delete_proxy_session (stream_session_t * s, int is_active_open) if (ps) { if (CLIB_DEBUG > 0) - memset (ps, 0xFE, sizeof (*ps)); + clib_memset (ps, 0xFE, sizeof (*ps)); pool_put (pm->sessions, ps); } @@ -139,14 +176,7 @@ proxy_connected_callback (u32 app_index, u32 api_context, } static int -proxy_add_segment_callback (u32 client_index, const ssvm_private_t * sp) -{ - clib_warning ("called..."); - return -1; -} - -static int -proxy_redirect_connect_callback (u32 client_index, void *mp) +proxy_add_segment_callback (u32 client_index, u64 segment_handle) { clib_warning ("called..."); return -1; @@ -165,7 +195,6 @@ proxy_rx_callback (stream_session_t * s) int proxy_index; uword *p; svm_fifo_t *active_open_tx_fifo; - session_fifo_event_t evt; ASSERT (s->thread_index == thread_index); @@ -182,11 +211,10 @@ proxy_rx_callback (stream_session_t * s) */ if (svm_fifo_set_event (active_open_tx_fifo)) { - evt.fifo = active_open_tx_fifo; - evt.event_type = FIFO_EVENT_APP_TX; - if (svm_queue_add - (pm->active_open_event_queue[thread_index], (u8 *) & evt, - 0 /* do wait for mutex */ )) + u32 ao_thread_index = active_open_tx_fifo->master_thread_index; + if (session_send_io_evt_to_thread_custom (active_open_tx_fifo, + ao_thread_index, + FIFO_EVENT_APP_TX)) clib_warning ("failed to enqueue tx evt"); } } @@ -208,11 +236,11 @@ proxy_rx_callback (stream_session_t * s) /* $$$ your message in this space: parse url, etc. */ - memset (a, 0, sizeof (*a)); + clib_memset (a, 0, sizeof (*a)); clib_spinlock_lock_if_init (&pm->sessions_lock); pool_get (pm->sessions, ps); - memset (ps, 0, sizeof (*ps)); + clib_memset (ps, 0, sizeof (*ps)); ps->server_rx_fifo = rx_fifo; ps->server_tx_fifo = tx_fifo; ps->vpp_server_handle = session_handle (s); @@ -227,8 +255,7 @@ proxy_rx_callback (stream_session_t * s) a->uri = (char *) pm->client_uri; a->api_context = proxy_index; a->app_index = pm->active_open_app_index; - a->mp = 0; - vnet_connect_uri (a); + proxy_call_main_thread (a); } return 0; @@ -239,8 +266,7 @@ static session_cb_vft_t proxy_session_cb_vft = { .session_disconnect_callback = proxy_disconnect_callback, .session_connected_callback = proxy_connected_callback, .add_segment_callback = proxy_add_segment_callback, - .redirect_connect_callback = proxy_redirect_connect_callback, - .builtin_server_rx_callback = proxy_rx_callback, + .builtin_app_rx_callback = proxy_rx_callback, .session_reset_callback = proxy_reset_callback }; @@ -251,7 +277,6 @@ active_open_connected_callback (u32 app_index, u32 opaque, proxy_main_t *pm = &proxy_main; proxy_session_t *ps; u8 thread_index = vlib_get_thread_index (); - session_fifo_event_t evt; if (is_fail) { @@ -293,15 +318,9 @@ active_open_connected_callback (u32 app_index, u32 opaque, /* * Send event for active open tx fifo */ + ASSERT (s->thread_index == thread_index); if (svm_fifo_set_event (s->server_tx_fifo)) - { - evt.fifo = s->server_tx_fifo; - evt.event_type = FIFO_EVENT_APP_TX; - if (svm_queue_add - (pm->active_open_event_queue[thread_index], (u8 *) & evt, - 0 /* do wait for mutex */ )) - clib_warning ("failed to enqueue tx evt"); - } + session_send_io_evt_to_thread (s->server_tx_fifo, FIFO_EVENT_APP_TX); return 0; } @@ -327,24 +346,19 @@ active_open_disconnect_callback (stream_session_t * s) static int active_open_rx_callback (stream_session_t * s) { - proxy_main_t *pm = &proxy_main; - session_fifo_event_t evt; - svm_fifo_t *server_rx_fifo; - u32 thread_index = vlib_get_thread_index (); + svm_fifo_t *proxy_tx_fifo; - server_rx_fifo = s->server_rx_fifo; + proxy_tx_fifo = s->server_rx_fifo; /* * Send event for server tx fifo */ - if (svm_fifo_set_event (server_rx_fifo)) + if (svm_fifo_set_event (proxy_tx_fifo)) { - evt.fifo = server_rx_fifo; - evt.event_type = FIFO_EVENT_APP_TX; - if (svm_queue_add - (pm->server_event_queue[thread_index], (u8 *) & evt, - 0 /* do wait for mutex */ )) - clib_warning ("failed to enqueue server rx evt"); + u8 thread_index = proxy_tx_fifo->master_thread_index; + return session_send_io_evt_to_thread_custom (proxy_tx_fifo, + thread_index, + FIFO_EVENT_APP_TX); } return 0; @@ -356,7 +370,7 @@ static session_cb_vft_t active_open_clients = { .session_connected_callback = active_open_connected_callback, .session_accept_callback = active_open_create_callback, .session_disconnect_callback = active_open_disconnect_callback, - .builtin_server_rx_callback = active_open_rx_callback + .builtin_app_rx_callback = active_open_rx_callback }; /* *INDENT-ON* */ @@ -384,8 +398,8 @@ proxy_server_attach () vnet_app_attach_args_t _a, *a = &_a; u32 segment_size = 512 << 20; - memset (a, 0, sizeof (*a)); - memset (options, 0, sizeof (options)); + clib_memset (a, 0, sizeof (*a)); + clib_memset (options, 0, sizeof (options)); if (pm->private_segment_size) segment_size = pm->private_segment_size; @@ -397,7 +411,7 @@ proxy_server_attach () a->options[APP_OPTIONS_TX_FIFO_SIZE] = pm->fifo_size; a->options[APP_OPTIONS_PRIVATE_SEGMENT_COUNT] = pm->private_segment_count; a->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] = - pm->prealloc_fifos ? pm->prealloc_fifos : 1; + pm->prealloc_fifos ? pm->prealloc_fifos : 0; a->options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN; @@ -418,8 +432,8 @@ active_open_attach (void) vnet_app_attach_args_t _a, *a = &_a; u64 options[16]; - memset (a, 0, sizeof (*a)); - memset (options, 0, sizeof (options)); + clib_memset (a, 0, sizeof (*a)); + clib_memset (options, 0, sizeof (options)); a->api_client_index = pm->active_open_client_index; a->session_cb_vft = &active_open_clients; @@ -430,7 +444,7 @@ active_open_attach (void) options[APP_OPTIONS_TX_FIFO_SIZE] = pm->fifo_size; options[APP_OPTIONS_PRIVATE_SEGMENT_COUNT] = pm->private_segment_count; options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] = - pm->prealloc_fifos ? pm->prealloc_fifos : 1; + pm->prealloc_fifos ? pm->prealloc_fifos : 0; options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN | APP_OPTIONS_FLAGS_IS_PROXY; @@ -450,7 +464,7 @@ proxy_server_listen () { proxy_main_t *pm = &proxy_main; vnet_bind_args_t _a, *a = &_a; - memset (a, 0, sizeof (*a)); + clib_memset (a, 0, sizeof (*a)); a->app_index = pm->server_app_index; a->uri = (char *) pm->server_uri; return vnet_bind_uri (a); @@ -543,7 +557,7 @@ proxy_server_create_command_fn (vlib_main_t * vm, unformat_input_t * input, else if (unformat (input, "server-uri %s", &pm->server_uri)) ; else if (unformat (input, "client-uri %s", &pm->client_uri)) - ; + pm->client_uri = format (0, "%s%c", pm->client_uri, 0); else return clib_error_return (0, "unknown input `%U'", format_unformat_error, input);