session: add support for application namespacing
[vpp.git] / src / vnet / session / session.h
index 180b9f8..b1a03d2 100644 (file)
@@ -38,6 +38,28 @@ typedef enum
   FIFO_EVENT_RPC,
 } fifo_event_type_t;
 
+static inline const char *
+fifo_event_type_str (fifo_event_type_t et)
+{
+  switch (et)
+    {
+    case FIFO_EVENT_APP_RX:
+      return "FIFO_EVENT_APP_RX";
+    case FIFO_EVENT_APP_TX:
+      return "FIFO_EVENT_APP_TX";
+    case FIFO_EVENT_TIMEOUT:
+      return "FIFO_EVENT_TIMEOUT";
+    case FIFO_EVENT_DISCONNECT:
+      return "FIFO_EVENT_DISCONNECT";
+    case FIFO_EVENT_BUILTIN_RX:
+      return "FIFO_EVENT_BUILTIN_RX";
+    case FIFO_EVENT_RPC:
+      return "FIFO_EVENT_RPC";
+    default:
+      return "UNKNOWN FIFO EVENT";
+    }
+}
+
 #define foreach_session_input_error                                            \
 _(NO_SESSION, "No session drops")                                       \
 _(NO_LISTENER, "No listener for dst port drops")                        \
@@ -133,6 +155,16 @@ struct _session_manager_main
   /** vpp fifo event queue configured length */
   u32 configured_event_queue_length;
 
+  /** session table size parameters */
+  u32 configured_v4_session_table_buckets;
+  u32 configured_v4_session_table_memory;
+  u32 configured_v4_halfopen_table_buckets;
+  u32 configured_v4_halfopen_table_memory;
+  u32 configured_v6_session_table_buckets;
+  u32 configured_v6_session_table_memory;
+  u32 configured_v6_halfopen_table_buckets;
+  u32 configured_v6_halfopen_table_memory;
+
   /** Unique segment name counter */
   u32 unique_segment_name_counter;
 
@@ -173,16 +205,16 @@ stream_session_is_valid (u32 si, u8 thread_index)
   stream_session_t *s;
   s = pool_elt_at_index (session_manager_main.sessions[thread_index], si);
   if (s->thread_index != thread_index || s->session_index != si
-      || s->server_rx_fifo->master_session_index != si
-      || s->server_tx_fifo->master_session_index != si
-      || s->server_rx_fifo->master_thread_index != thread_index
-      || s->server_tx_fifo->master_thread_index != thread_index)
+      /* || s->server_rx_fifo->master_session_index != si
+         || s->server_tx_fifo->master_session_index != si
+         || s->server_rx_fifo->master_thread_index != thread_index
+         || s->server_tx_fifo->master_thread_index != thread_index */ )
     return 0;
   return 1;
 }
 
 always_inline stream_session_t *
-stream_session_get (u32 si, u32 thread_index)
+session_get (u32 si, u32 thread_index)
 {
   ASSERT (stream_session_is_valid (si, thread_index));
   return pool_elt_at_index (session_manager_main.sessions[thread_index], si);
@@ -208,31 +240,31 @@ stream_session_handle (stream_session_t * s)
 }
 
 always_inline u32
-stream_session_index_from_handle (u64 handle)
+session_index_from_handle (u64 handle)
 {
   return handle & 0xFFFFFFFF;
 }
 
 always_inline u32
-stream_session_thread_from_handle (u64 handle)
+session_thread_from_handle (u64 handle)
 {
   return handle >> 32;
 }
 
 always_inline void
-stream_session_parse_handle (u64 handle, u32 * index, u32 * thread_index)
+session_parse_handle (u64 handle, u32 * index, u32 * thread_index)
 {
-  *index = stream_session_index_from_handle (handle);
-  *thread_index = stream_session_thread_from_handle (handle);
+  *index = session_index_from_handle (handle);
+  *thread_index = session_thread_from_handle (handle);
 }
 
 always_inline stream_session_t *
-stream_session_get_from_handle (u64 handle)
+session_get_from_handle (u64 handle)
 {
   session_manager_main_t *smm = &session_manager_main;
-  return pool_elt_at_index (smm->sessions[stream_session_thread_from_handle
-                                         (handle)],
-                           stream_session_index_from_handle (handle));
+  return
+    pool_elt_at_index (smm->sessions[session_thread_from_handle (handle)],
+                      session_index_from_handle (handle));
 }
 
 always_inline stream_session_t *
@@ -253,14 +285,14 @@ stream_session_get_index (stream_session_t * s)
 always_inline u32
 stream_session_max_rx_enqueue (transport_connection_t * tc)
 {
-  stream_session_t *s = stream_session_get (tc->s_index, tc->thread_index);
+  stream_session_t *s = session_get (tc->s_index, tc->thread_index);
   return svm_fifo_max_enqueue (s->server_rx_fifo);
 }
 
 always_inline u32
 stream_session_rx_fifo_size (transport_connection_t * tc)
 {
-  stream_session_t *s = stream_session_get (tc->s_index, tc->thread_index);
+  stream_session_t *s = session_get (tc->s_index, tc->thread_index);
   return s->server_rx_fifo->nitems;
 }
 
@@ -284,12 +316,11 @@ void stream_session_delete_notify (transport_connection_t * tc);
 void stream_session_reset_notify (transport_connection_t * tc);
 int
 stream_session_accept (transport_connection_t * tc, u32 listener_index,
-                      u8 sst, u8 notify);
+                      u8 notify);
 int
-stream_session_open (u32 app_index, session_type_t st,
-                    transport_endpoint_t * tep,
+stream_session_open (u32 app_index, session_endpoint_t * tep,
                     transport_connection_t ** tc);
-int stream_session_listen (stream_session_t * s, transport_endpoint_t * tep);
+int stream_session_listen (stream_session_t * s, session_endpoint_t * tep);
 int stream_session_stop_listen (stream_session_t * s);
 void stream_session_disconnect (stream_session_t * s);
 void stream_session_cleanup (stream_session_t * s);
@@ -369,6 +400,10 @@ listen_session_del (stream_session_t * s)
   pool_put (session_manager_main.listen_sessions[s->session_type], s);
 }
 
+int
+listen_session_get_local_session_endpoint (stream_session_t * listener,
+                                          session_endpoint_t * sep);
+
 always_inline stream_session_t *
 session_manager_get_listener (u8 type, u32 index)
 {
@@ -393,6 +428,12 @@ session_manager_is_enabled ()
   return session_manager_main.is_enabled == 1;
 }
 
+#define session_cli_return_if_not_enabled()                            \
+do {                                                                   \
+    if (!session_manager_main.is_enabled)                              \
+      return clib_error_return(0, "session layer is not enabled");     \
+} while (0)
+
 #endif /* __included_session_h__ */
 
 /*