Add logging support
[vpp.git] / src / vnet / bfd / bfd_main.h
index d722a55..9e2a12e 100644 (file)
@@ -23,6 +23,7 @@
 #include <vnet/vnet.h>
 #include <vnet/bfd/bfd_protocol.h>
 #include <vnet/bfd/bfd_udp.h>
+#include <vlib/log.h>
 
 #define foreach_bfd_mode(F) \
   F (asynchronous)          \
@@ -66,6 +67,20 @@ typedef enum
 #undef F
 } bfd_poll_state_e;
 
+/**
+ * hop types
+ */
+#define foreach_bfd_hop(F)                     \
+  F (SINGLE, "single")                         \
+  F (MULTI,  "multi")                          \
+
+typedef enum
+{
+#define F(sym, str) BFD_HOP_TYPE_##sym,
+  foreach_bfd_hop (F)
+#undef F
+} bfd_hop_type_e;
+
 typedef struct bfd_session_s
 {
   /** index in bfd_main.sessions pool */
@@ -77,6 +92,9 @@ typedef struct bfd_session_s
   /** remote session state */
   bfd_state_e remote_state;
 
+  /** BFD hop type */
+  bfd_hop_type_e hop_type;
+
   /** local diagnostics */
   bfd_diag_code_e local_diag;
 
@@ -220,6 +238,26 @@ typedef struct bfd_session_s
   };
 } bfd_session_t;
 
+/**
+ * listener events
+ */
+#define foreach_bfd_listen_event(F)            \
+  F (CREATE, "sesion-created")                 \
+  F (UPDATE, "session-updated")                \
+  F (DELETE, "session-deleted")
+
+typedef enum
+{
+#define F(sym, str) BFD_LISTEN_EVENT_##sym,
+  foreach_bfd_listen_event (F)
+#undef F
+} bfd_listen_event_e;
+
+/**
+ * session nitification call back function type
+ */
+typedef void (*bfd_notify_fn_t) (bfd_listen_event_e, const bfd_session_t *);
+
 typedef struct
 {
   /** pool of bfd sessions context data */
@@ -259,6 +297,11 @@ typedef struct
   /** hashmap - index in pool auth_keys by conf_key_id */
   u32 *auth_key_by_conf_key_id;
 
+  /** vector of callback notification functions */
+  bfd_notify_fn_t *listeners;
+
+  /** log class */
+  vlib_log_class_t log_class;
 } bfd_main_t;
 
 extern bfd_main_t bfd_main;
@@ -319,6 +362,7 @@ void bfd_init_final_control_frame (vlib_main_t * vm, vlib_buffer_t * b,
                                   bfd_main_t * bm, bfd_session_t * bs,
                                   int is_local);
 u8 *format_bfd_session (u8 * s, va_list * args);
+u8 *format_bfd_session_brief (u8 * s, va_list * args);
 u8 *format_bfd_auth_key (u8 * s, va_list * args);
 void bfd_session_set_flags (bfd_session_t * bs, u8 admin_up_down);
 unsigned bfd_auth_type_supported (bfd_auth_type_e auth_type);
@@ -345,6 +389,11 @@ const char *bfd_poll_state_string (bfd_poll_state_e state);
  */
 #define BFD_REQUIRED_MIN_RX_USEC_WHILE_ECHO USEC_PER_SECOND
 
+/**
+ * Register a callback function to receive session notifications.
+ */
+void bfd_register_listener (bfd_notify_fn_t fn);
+
 #endif /* __included_bfd_main_h__ */
 
 /*