summaryrefslogtreecommitdiffstats
path: root/src/vnet/session/application_local.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vnet/session/application_local.c')
-rw-r--r--src/vnet/session/application_local.c134
1 files changed, 78 insertions, 56 deletions
diff --git a/src/vnet/session/application_local.c b/src/vnet/session/application_local.c
index 9378e5e6380..745b202f580 100644
--- a/src/vnet/session/application_local.c
+++ b/src/vnet/session/application_local.c
@@ -16,9 +16,28 @@
#include <vnet/session/application_local.h>
#include <vnet/session/session.h>
-ct_connection_t *connections;
+static ct_connection_t *connections;
-ct_connection_t *
+static void
+ct_enable_disable_main_pre_input_node (u8 is_add)
+{
+ u32 n_conns;
+
+ n_conns = pool_elts (connections);
+ if (n_conns > 2)
+ return;
+
+ if (n_conns > 0 && is_add)
+ vlib_node_set_state (vlib_get_main (),
+ session_queue_pre_input_node.index,
+ VLIB_NODE_STATE_POLLING);
+ else if (n_conns == 0)
+ vlib_node_set_state (vlib_get_main (),
+ session_queue_pre_input_node.index,
+ VLIB_NODE_STATE_DISABLED);
+}
+
+static ct_connection_t *
ct_connection_alloc (void)
{
ct_connection_t *ct;
@@ -31,7 +50,7 @@ ct_connection_alloc (void)
return ct;
}
-ct_connection_t *
+static ct_connection_t *
ct_connection_get (u32 ct_index)
{
if (pool_is_free_index (connections, ct_index))
@@ -39,7 +58,7 @@ ct_connection_get (u32 ct_index)
return pool_elt_at_index (connections, ct_index);
}
-void
+static void
ct_connection_free (ct_connection_t * ct)
{
if (CLIB_DEBUG)
@@ -110,8 +129,14 @@ ct_session_connect_notify (session_t * ss)
cs->session_state = SESSION_STATE_CONNECTING;
cs->app_wrk_index = client_wrk->wrk_index;
cs->connection_index = cct->c_c_index;
+ cs->t_app_index = client_wrk->app_index;
cct->c_s_index = cs->session_index;
+ cct->client_rx_fifo = ss->tx_fifo;
+ cct->client_tx_fifo = ss->rx_fifo;
+
+ cct->client_rx_fifo->refcnt++;
+ cct->client_tx_fifo->refcnt++;
/* This will allocate fifos for the session. They won't be used for
* exchanging data but they will be used to close the connection if
@@ -135,47 +160,25 @@ ct_session_connect_notify (session_t * ss)
return 0;
}
-static void
-ct_session_fix_eventds (svm_msg_q_t * sq, svm_msg_q_t * cq)
-{
- int fd;
-
- /*
- * segment manager initializes only the producer eventds, since vpp is
- * typically the producer. But for local sessions, we also pass to the
- * apps the mqs they listen on for events from peer apps, so they are also
- * consumer fds.
- */
- fd = svm_msg_q_get_producer_eventfd (sq);
- svm_msg_q_set_consumer_eventfd (sq, fd);
- fd = svm_msg_q_get_producer_eventfd (cq);
- svm_msg_q_set_consumer_eventfd (cq, fd);
-}
-
-int
+static int
ct_init_local_session (app_worker_t * client_wrk, app_worker_t * server_wrk,
ct_connection_t * ct, session_t * ls, session_t * ll)
{
- u32 seg_size, evt_q_sz, evt_q_elts, margin = 16 << 10;
- u32 round_rx_fifo_sz, round_tx_fifo_sz, sm_index;
- segment_manager_properties_t *props, *cprops;
+ u32 round_rx_fifo_sz, round_tx_fifo_sz, sm_index, seg_size;
+ segment_manager_properties_t *props;
svm_fifo_segment_private_t *seg;
- application_t *server, *client;
+ application_t *server;
segment_manager_t *sm;
- svm_msg_q_t *sq, *cq;
+ u32 margin = 16 << 10;
u64 segment_handle;
int seg_index, rv;
server = application_get (server_wrk->app_index);
- client = application_get (client_wrk->app_index);
props = application_segment_manager_properties (server);
- cprops = application_segment_manager_properties (client);
- evt_q_elts = props->evt_q_size + cprops->evt_q_size;
- evt_q_sz = segment_manager_evt_q_expected_size (evt_q_elts);
round_rx_fifo_sz = 1 << max_log2 (props->rx_fifo_size);
round_tx_fifo_sz = 1 << max_log2 (props->tx_fifo_size);
- seg_size = round_rx_fifo_sz + round_tx_fifo_sz + evt_q_sz + margin;
+ seg_size = round_rx_fifo_sz + round_tx_fifo_sz + margin;
sm = app_worker_get_listen_segment_manager (server_wrk, ll);
seg_index = segment_manager_add_segment (sm, seg_size);
@@ -185,14 +188,7 @@ ct_init_local_session (app_worker_t * client_wrk, app_worker_t * server_wrk,
return seg_index;
}
seg = segment_manager_get_segment_w_lock (sm, seg_index);
- sq = segment_manager_alloc_queue (seg, props);
- cq = segment_manager_alloc_queue (seg, cprops);
-
- if (props->use_mq_eventfd)
- ct_session_fix_eventds (sq, cq);
- ct->server_evt_q = pointer_to_uword (sq);
- ct->client_evt_q = pointer_to_uword (cq);
rv = segment_manager_try_alloc_fifos (seg, props->rx_fifo_size,
props->tx_fifo_size, &ls->rx_fifo,
&ls->tx_fifo);
@@ -204,8 +200,8 @@ ct_init_local_session (app_worker_t * client_wrk, app_worker_t * server_wrk,
}
sm_index = segment_manager_index (sm);
- ls->rx_fifo->ct_session_index = ls->session_index;
- ls->tx_fifo->ct_session_index = ls->session_index;
+ ls->rx_fifo->master_session_index = ls->session_index;
+ ls->tx_fifo->master_session_index = ls->session_index;
ls->rx_fifo->segment_manager = sm_index;
ls->tx_fifo->segment_manager = sm_index;
ls->rx_fifo->segment_index = seg_index;
@@ -228,7 +224,7 @@ failed:
return rv;
}
-int
+static int
ct_connect (app_worker_t * client_wrk, session_t * ll,
session_endpoint_cfg_t * sep)
{
@@ -255,6 +251,7 @@ ct_connect (app_worker_t * client_wrk, session_t * ll,
cct->c_is_ip4 = sep->is_ip4;
clib_memcpy (&cct->c_rmt_ip, &sep->ip, sizeof (sep->ip));
cct->actual_tp = ll_ct->actual_tp;
+ cct->is_client = 1;
/*
* Init server transport
@@ -285,6 +282,7 @@ ct_connect (app_worker_t * client_wrk, session_t * ll,
server_wrk = application_listener_select_worker (ll);
ss->app_wrk_index = server_wrk->wrk_index;
+ ss->t_app_index = server_wrk->app_index;
sct->c_s_index = ss->session_index;
sct->server_wrk = ss->app_wrk_index;
@@ -306,14 +304,12 @@ ct_connect (app_worker_t * client_wrk, session_t * ll,
return -1;
}
- cct->client_evt_q = sct->client_evt_q;
- cct->server_evt_q = sct->server_evt_q;
cct->segment_handle = sct->segment_handle;
-
+ ct_enable_disable_main_pre_input_node (1 /* is_add */ );
return 0;
}
-u32
+static u32
ct_start_listen (u32 app_listener_index, transport_endpoint_t * tep)
{
session_endpoint_cfg_t *sep;
@@ -326,25 +322,27 @@ ct_start_listen (u32 app_listener_index, transport_endpoint_t * tep)
clib_memcpy (&ct->c_lcl_ip, &sep->ip, sizeof (sep->ip));
ct->c_lcl_port = sep->port;
ct->actual_tp = sep->transport_proto;
+ ct_enable_disable_main_pre_input_node (1 /* is_add */ );
return ct->c_c_index;
}
-u32
+static u32
ct_stop_listen (u32 ct_index)
{
ct_connection_t *ct;
ct = ct_connection_get (ct_index);
ct_connection_free (ct);
+ ct_enable_disable_main_pre_input_node (0 /* is_add */ );
return 0;
}
-transport_connection_t *
+static transport_connection_t *
ct_listener_get (u32 ct_index)
{
return (transport_connection_t *) ct_connection_get (ct_index);
}
-int
+static int
ct_session_connect (transport_endpoint_cfg_t * tep)
{
session_endpoint_cfg_t *sep_ext;
@@ -407,10 +405,11 @@ global_scope:
return 1;
}
-void
+static void
ct_session_close (u32 ct_index, u32 thread_index)
{
ct_connection_t *ct, *peer_ct;
+ app_worker_t *app_wrk;
session_t *s;
ct = ct_connection_get (ct_index);
@@ -422,13 +421,18 @@ ct_session_close (u32 ct_index, u32 thread_index)
}
s = session_get (ct->c_s_index, 0);
- app_worker_del_segment_notify (app_worker_get (s->app_wrk_index),
- ct->segment_handle);
+ app_wrk = app_worker_get_if_valid (s->app_wrk_index);
+ if (app_wrk)
+ app_worker_del_segment_notify (app_wrk, ct->segment_handle);
session_free_w_fifos (s);
+ if (ct->is_client)
+ segment_manager_dealloc_fifos (ct->client_rx_fifo, ct->client_tx_fifo);
+
ct_connection_free (ct);
+ ct_enable_disable_main_pre_input_node (0 /* is_add */ );
}
-transport_connection_t *
+static transport_connection_t *
ct_session_get (u32 ct_index, u32 thread_index)
{
return (transport_connection_t *) ct_connection_get (ct_index);
@@ -460,7 +464,7 @@ format_ct_connection_id (u8 * s, va_list * args)
return s;
}
-u8 *
+static u8 *
format_ct_listener (u8 * s, va_list * args)
{
u32 tc_index = va_arg (*args, u32);
@@ -472,7 +476,7 @@ format_ct_listener (u8 * s, va_list * args)
return s;
}
-u8 *
+static u8 *
format_ct_connection (u8 * s, va_list * args)
{
ct_connection_t *ct = va_arg (*args, ct_connection_t *);
@@ -492,7 +496,7 @@ format_ct_connection (u8 * s, va_list * args)
return s;
}
-u8 *
+static u8 *
format_ct_session (u8 * s, va_list * args)
{
u32 ct_index = va_arg (*args, u32);
@@ -526,11 +530,29 @@ const static transport_proto_vft_t cut_thru_proto = {
};
/* *INDENT-ON* */
+int
+ct_session_tx (session_t * s)
+{
+ ct_connection_t *ct, *peer_ct;
+ session_t *peer_s;
+
+ ct = (ct_connection_t *) session_get_transport (s);
+ peer_ct = ct_connection_get (ct->peer_index);
+ if (!peer_ct)
+ return -1;
+ peer_s = session_get (peer_ct->c_s_index, 0);
+ if (peer_s->session_state >= SESSION_STATE_TRANSPORT_CLOSING)
+ return 0;
+ return session_enqueue_notify (peer_s);
+}
+
static clib_error_t *
ct_transport_init (vlib_main_t * vm)
{
transport_register_protocol (TRANSPORT_PROTO_NONE, &cut_thru_proto,
FIB_PROTOCOL_IP4, ~0);
+ transport_register_protocol (TRANSPORT_PROTO_NONE, &cut_thru_proto,
+ FIB_PROTOCOL_IP6, ~0);
return 0;
}