session: improve cli
[vpp.git] / src / vnet / session / session.h
index 5af824a..cb0cac7 100644 (file)
@@ -62,12 +62,19 @@ typedef struct session_tx_context_
   session_dgram_hdr_t hdr;
 } session_tx_context_t;
 
+#define SESSION_CTRL_MSG_MAX_SIZE 64
+
 typedef struct session_evt_elt
 {
   clib_llist_anchor_t evt_list;
   session_event_t evt;
 } session_evt_elt_t;
 
+typedef struct session_ctrl_evt_data_
+{
+  u8 data[SESSION_CTRL_MSG_MAX_SIZE];
+} session_evt_ctrl_data_t;
+
 typedef struct session_worker_
 {
   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
@@ -96,6 +103,9 @@ typedef struct session_worker_
   /** Pool of session event list elements */
   session_evt_elt_t *event_elts;
 
+  /** Pool of ctrl events data buffers */
+  session_evt_ctrl_data_t *ctrl_evts_data;
+
   /** Head of control events list */
   clib_llist_index_t ctrl_head;
 
@@ -207,6 +217,14 @@ session_evt_add_old (session_worker_t * wrk, session_evt_elt_t * elt)
                       pool_elt_at_index (wrk->event_elts, wrk->old_head));
 }
 
+static inline u32
+session_evt_ctrl_data_alloc (session_worker_t * wrk)
+{
+  session_evt_ctrl_data_t *data;
+  pool_get (wrk->ctrl_evts_data, data);
+  return (data - wrk->ctrl_evts_data);
+}
+
 static inline session_evt_elt_t *
 session_evt_alloc_ctrl (session_worker_t * wrk)
 {
@@ -217,6 +235,20 @@ session_evt_alloc_ctrl (session_worker_t * wrk)
   return elt;
 }
 
+static inline void *
+session_evt_ctrl_data (session_worker_t * wrk, session_evt_elt_t * elt)
+{
+  return (void *) (pool_elt_at_index (wrk->ctrl_evts_data,
+                                     elt->evt.ctrl_data_index));
+}
+
+static inline void
+session_evt_ctrl_data_free (session_worker_t * wrk, session_evt_elt_t * elt)
+{
+  ASSERT (elt->evt.event_type > SESSION_IO_EVT_BUILTIN_TX);
+  pool_put_index (wrk->ctrl_evts_data, elt->evt.ctrl_data_index);
+}
+
 static inline session_evt_elt_t *
 session_evt_alloc_new (session_worker_t * wrk)
 {
@@ -376,7 +408,9 @@ int session_open (u32 app_index, session_endpoint_t * tep, u32 opaque);
 int session_listen (session_t * s, session_endpoint_cfg_t * sep);
 int session_stop_listen (session_t * s);
 void session_close (session_t * s);
+void session_reset (session_t * s);
 void session_transport_close (session_t * s);
+void session_transport_reset (session_t * s);
 void session_transport_cleanup (session_t * s);
 int session_send_io_evt_to_thread (svm_fifo_t * f,
                                   session_evt_type_t evt_type);
@@ -550,6 +584,14 @@ session_main_get_worker (u32 thread_index)
   return &session_main.wrk[thread_index];
 }
 
+static inline session_worker_t *
+session_main_get_worker_if_valid (u32 thread_index)
+{
+  if (pool_is_free_index (session_main.wrk, thread_index))
+    return 0;
+  return &session_main.wrk[thread_index];
+}
+
 always_inline svm_msg_q_t *
 session_main_get_vpp_event_queue (u32 thread_index)
 {
@@ -564,8 +606,8 @@ session_main_is_enabled ()
 
 #define session_cli_return_if_not_enabled()                            \
 do {                                                                   \
-    if (!session_main.is_enabled)                              \
-      return clib_error_return(0, "session layer is not enabled");     \
+    if (!session_main.is_enabled)                                      \
+      return clib_error_return (0, "session layer is not enabled");    \
 } while (0)
 
 int session_main_flush_enqueue_events (u8 proto, u32 thread_index);