session: add session stats

Type: feature

Signed-off-by: Filip Tehlar <ftehlar@cisco.com>
Change-Id: I02d9bb5292b32ffb1b2f05daccd8a7d5dba05125
diff --git a/src/vnet/session/session.h b/src/vnet/session/session.h
index 456718a..e92b1f0 100644
--- a/src/vnet/session/session.h
+++ b/src/vnet/session/session.h
@@ -40,6 +40,11 @@
     SESSION_N_ERROR,
 } session_input_error_t;
 
+typedef struct session_wrk_stats_
+{
+  u32 errors[SESSION_N_ERRORS];
+} session_wrk_stats_t;
+
 typedef struct session_tx_context_
 {
   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
@@ -169,6 +174,8 @@
   u16 batch_num;
   vlib_dma_batch_t *batch;
 
+  session_wrk_stats_t stats;
+
 #if SESSION_DEBUG
   /** last event poll time by thread */
   clib_time_type_t last_event_poll;
@@ -732,6 +739,23 @@
   return session_main.is_enabled == 1;
 }
 
+always_inline void
+session_worker_stat_error_inc (session_worker_t *wrk, int error, int value)
+{
+  if ((-(error) >= 0 && -(error) < SESSION_N_ERRORS))
+    wrk->stats.errors[-error] += value;
+  else
+    SESSION_DBG ("unknown session counter");
+}
+
+always_inline void
+session_stat_error_inc (int error, int value)
+{
+  session_worker_t *wrk;
+  wrk = session_main_get_worker (vlib_get_thread_index ());
+  session_worker_stat_error_inc (wrk, error, value);
+}
+
 #define session_cli_return_if_not_enabled()				\
 do {									\
     if (!session_main.is_enabled)					\