session: api to add new transport types
[vpp.git] / src / vnet / session / session_types.h
index 9e51d69..aa0e865 100644 (file)
@@ -19,7 +19,9 @@
 #include <svm/svm_fifo.h>
 #include <vnet/session/transport_types.h>
 
-#define SESSION_LISTENER_PREFIX                0x5FFFFFFF
+#define SESSION_INVALID_INDEX ((u32)~0)
+#define SESSION_INVALID_HANDLE ((u64)~0)
+#define SESSION_CTRL_MSG_MAX_SIZE 84
 
 #define foreach_session_endpoint_fields                                \
   foreach_transport_endpoint_cfg_fields                                \
@@ -42,6 +44,10 @@ typedef struct _session_endpoint_cfg
   u32 ns_index;
   u8 original_tp;
   u8 *hostname;
+  u64 parent_handle;
+  u32 ckpair_index;
+  u8 crypto_engine;
+  u8 flags;
 } session_endpoint_cfg_t;
 
 #define SESSION_IP46_ZERO                      \
@@ -81,6 +87,8 @@ typedef struct _session_endpoint_cfg
   .app_wrk_index = ENDPOINT_INVALID_INDEX,     \
   .opaque = ENDPOINT_INVALID_INDEX,            \
   .hostname = 0,                               \
+  .parent_handle = SESSION_INVALID_HANDLE,     \
+  .ckpair_index = 0                            \
 }
 
 #define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep)
@@ -109,84 +117,109 @@ session_endpoint_is_zero (session_endpoint_t * sep)
 typedef u8 session_type_t;
 typedef u64 session_handle_t;
 
+typedef enum
+{
+  SESSION_CLEANUP_TRANSPORT,
+  SESSION_CLEANUP_SESSION,
+} session_cleanup_ntf_t;
+
+typedef enum session_ft_action_
+{
+  SESSION_FT_ACTION_ENQUEUED,
+  SESSION_FT_ACTION_DEQUEUED,
+  SESSION_FT_ACTION_N_ACTIONS
+} session_ft_action_t;
+
 /*
- * Application session state
+ * Session states
  */
+#define foreach_session_state                          \
+  _(CREATED, "created")                                        \
+  _(LISTENING, "listening")                            \
+  _(CONNECTING, "connecting")                          \
+  _(ACCEPTING, "accepting")                            \
+  _(READY, "ready")                                    \
+  _(OPENED, "opened")                                  \
+  _(TRANSPORT_CLOSING, "transport-closing")            \
+  _(CLOSING, "closing")                                        \
+  _(APP_CLOSED, "app-closed")                          \
+  _(TRANSPORT_CLOSED, "transport-closed")              \
+  _(CLOSED, "closed")                                  \
+  _(TRANSPORT_DELETED, "transport-deleted")            \
+
 typedef enum
 {
-  SESSION_STATE_CREATED,
-  SESSION_STATE_LISTENING,
-  SESSION_STATE_CONNECTING,
-  SESSION_STATE_ACCEPTING,
-  SESSION_STATE_READY,
-  SESSION_STATE_OPENED,
-  SESSION_STATE_TRANSPORT_CLOSING,
-  SESSION_STATE_CLOSING,
-  SESSION_STATE_CLOSED_WAITING,
-  SESSION_STATE_TRANSPORT_CLOSED,
-  SESSION_STATE_CLOSED,
-  SESSION_STATE_N_STATES,
+#define _(sym, str) SESSION_STATE_ ## sym,
+  foreach_session_state
+#undef _
+    SESSION_N_STATES,
 } session_state_t;
 
-typedef struct generic_session_
+#define foreach_session_flag                           \
+  _(RX_EVT, "rx-event")                                        \
+  _(PROXY, "proxy")                                    \
+  _(CUSTOM_TX, "custom-tx")                            \
+  _(IS_MIGRATING, "migrating")                         \
+  _(UNIDIRECTIONAL, "unidirectional")                  \
+  _(CUSTOM_FIFO_TUNING, "custom-fifo-tuning")          \
+
+typedef enum session_flags_bits_
+{
+#define _(sym, str) SESSION_F_BIT_ ## sym,
+  foreach_session_flag
+#undef _
+  SESSION_N_FLAGS
+} session_flag_bits_t;
+
+typedef enum session_flags_
 {
-  svm_fifo_t *rx_fifo;         /**< rx fifo */
-  svm_fifo_t *tx_fifo;         /**< tx fifo */
-  session_type_t session_type; /**< session type */
-  volatile u8 session_state;   /**< session state */
-  u32 session_index;           /**< index in owning pool */
-} generic_session_t;
+#define _(sym, str) SESSION_F_ ## sym = 1 << SESSION_F_BIT_ ## sym,
+  foreach_session_flag
+#undef _
+} session_flags_t;
 
 typedef struct session_
 {
-  /** fifo pointers. Once allocated, these do not move */
+  /** Pointers to rx/tx buffers. Once allocated, these do not move */
   svm_fifo_t *rx_fifo;
   svm_fifo_t *tx_fifo;
 
-  /** Type */
+  /** Type built from transport and network protocol types */
   session_type_t session_type;
 
-  /** State */
+  /** State in session layer state machine. See @ref session_state_t */
   volatile u8 session_state;
 
-  /** Session index in per_thread pool */
+  /** Index in thread pool where session was allocated */
   u32 session_index;
 
-  /** App worker pool index */
+  /** Index of the app worker that owns the session */
   u32 app_wrk_index;
 
+  /** Index of the thread that allocated the session */
   u8 thread_index;
 
-  /** To avoid n**2 "one event per frame" check */
-  u64 enqueue_epoch;
-
-  /** svm segment index where fifos were allocated */
-  u32 svm_segment_index;
+  /** Session flags. See @ref session_flags_t */
+  u32 flags;
 
-  /** Transport specific */
+  /** Index of the transport connection associated to the session */
   u32 connection_index;
 
-  union
-  {
-    /** Parent listener session if the result of an accept */
-    u32 listener_index;
-
-    /** Application index if a listener */
-    u32 app_index;
-  };
+  /** Index of application that owns the listener. Set only if a listener */
+  u32 app_index;
 
   union
   {
-    /** Transport app index for apps acting as transports */
-    u32 t_app_index;
+    /** Parent listener session index if the result of an accept */
+    session_handle_t listener_handle;
 
-    /** App listener index */
+    /** App listener index in app's listener pool if a listener */
     u32 al_index;
-
-    /** Opaque, for general use */
-    u32 opaque;
   };
 
+  /** Opaque, for general use */
+  u32 opaque;
+
     CLIB_CACHE_LINE_ALIGN_MARK (pad);
 } session_t;
 
@@ -275,6 +308,12 @@ session_parse_handle (session_handle_t handle, u32 * index,
   *thread_index = session_thread_from_handle (handle);
 }
 
+static inline session_handle_t
+session_make_handle (u32 session_index, u32 thread_index)
+{
+  return (((u64) thread_index << 32) | (u64) session_index);
+}
+
 typedef enum
 {
   SESSION_IO_EVT_RX,
@@ -284,21 +323,55 @@ typedef enum
   SESSION_IO_EVT_BUILTIN_TX,
   SESSION_CTRL_EVT_RPC,
   SESSION_CTRL_EVT_CLOSE,
+  SESSION_CTRL_EVT_RESET,
   SESSION_CTRL_EVT_BOUND,
   SESSION_CTRL_EVT_UNLISTEN_REPLY,
   SESSION_CTRL_EVT_ACCEPTED,
   SESSION_CTRL_EVT_ACCEPTED_REPLY,
   SESSION_CTRL_EVT_CONNECTED,
-  SESSION_CTRL_EVT_CONNECTED_REPLY,
   SESSION_CTRL_EVT_DISCONNECTED,
   SESSION_CTRL_EVT_DISCONNECTED_REPLY,
-  SESSION_CTRL_EVT_RESET,
   SESSION_CTRL_EVT_RESET_REPLY,
   SESSION_CTRL_EVT_REQ_WORKER_UPDATE,
   SESSION_CTRL_EVT_WORKER_UPDATE,
   SESSION_CTRL_EVT_WORKER_UPDATE_REPLY,
+  SESSION_CTRL_EVT_DISCONNECT,
+  SESSION_CTRL_EVT_CONNECT,
+  SESSION_CTRL_EVT_CONNECT_URI,
+  SESSION_CTRL_EVT_LISTEN,
+  SESSION_CTRL_EVT_LISTEN_URI,
+  SESSION_CTRL_EVT_UNLISTEN,
+  SESSION_CTRL_EVT_APP_DETACH,
+  SESSION_CTRL_EVT_APP_ADD_SEGMENT,
+  SESSION_CTRL_EVT_APP_DEL_SEGMENT,
+  SESSION_CTRL_EVT_MIGRATED,
+  SESSION_CTRL_EVT_CLEANUP,
 } session_evt_type_t;
 
+#define foreach_session_ctrl_evt                               \
+  _(LISTEN, listen)                                            \
+  _(LISTEN_URI, listen_uri)                                    \
+  _(BOUND, bound)                                              \
+  _(UNLISTEN, unlisten)                                                \
+  _(UNLISTEN_REPLY, unlisten_reply)                            \
+  _(ACCEPTED, accepted)                                                \
+  _(ACCEPTED_REPLY, accepted_reply)                            \
+  _(CONNECT, connect)                                          \
+  _(CONNECT_URI, connect_uri)                                  \
+  _(CONNECTED, connected)                                      \
+  _(DISCONNECT, disconnect)                                    \
+  _(DISCONNECTED, disconnected)                                        \
+  _(DISCONNECTED_REPLY, disconnected_reply)                    \
+  _(RESET_REPLY, reset_reply)                                  \
+  _(REQ_WORKER_UPDATE, req_worker_update)                      \
+  _(WORKER_UPDATE, worker_update)                              \
+  _(WORKER_UPDATE_REPLY, worker_update_reply)                  \
+  _(APP_DETACH, app_detach)                                    \
+  _(APP_ADD_SEGMENT, app_add_segment)                          \
+  _(APP_DEL_SEGMENT, app_del_segment)                          \
+  _(MIGRATED, migrated)                                                \
+  _(CLEANUP, cleanup)                                          \
+
 /* Deprecated and will be removed. Use types above */
 #define FIFO_EVENT_APP_RX SESSION_IO_EVT_RX
 #define FIFO_EVENT_APP_TX SESSION_IO_EVT_TX
@@ -319,23 +392,22 @@ typedef struct
   void *arg;
 } session_rpc_args_t;
 
-/* *INDENT-OFF* */
 typedef struct
 {
   u8 event_type;
   u8 postponed;
   union
   {
-    svm_fifo_t *fifo;
+    u32 session_index;
     session_handle_t session_handle;
     session_rpc_args_t rpc_args;
+    u32 ctrl_data_index;
     struct
     {
       u8 data[0];
     };
   };
 } __clib_packed session_event_t;
-/* *INDENT-ON* */
 
 #define SESSION_MSG_NULL { }
 
@@ -345,8 +417,7 @@ typedef struct session_dgram_pre_hdr_
   u32 data_offset;
 } session_dgram_pre_hdr_t;
 
-/* *INDENT-OFF* */
-typedef CLIB_PACKED (struct session_dgram_header_
+typedef struct session_dgram_header_
 {
   u32 data_length;
   u32 data_offset;
@@ -355,8 +426,7 @@ typedef CLIB_PACKED (struct session_dgram_header_
   u16 rmt_port;
   u16 lcl_port;
   u8 is_ip4;
-}) session_dgram_hdr_t;
-/* *INDENT-ON* */
+} __clib_packed session_dgram_hdr_t;
 
 #define SESSION_CONN_ID_LEN 37
 #define SESSION_CONN_HDR_LEN 45