X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fbfd%2Fbfd_main.h;h=c587c86801f63d359817fa6a6ac741c13ad2a7a8;hb=2af0e3a;hp=4d460f41f468cc8a15ed9661c1381825a9d2484f;hpb=b16bfe3f94739821c7382bd0849630b21e03a8b7;p=vpp.git diff --git a/src/vnet/bfd/bfd_main.h b/src/vnet/bfd/bfd_main.h index 4d460f41f46..c587c86801f 100644 --- a/src/vnet/bfd/bfd_main.h +++ b/src/vnet/bfd/bfd_main.h @@ -23,6 +23,8 @@ #include #include #include +#include +#include #define foreach_bfd_mode(F) \ F (asynchronous) \ @@ -66,6 +68,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 +93,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,8 +239,45 @@ 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 { + /** lock to protect data structures */ + clib_spinlock_t lock; + int lock_recursion_count; + uword owner_thread_index; + + /** Number of event wakeup RPCs in flight. Should be 0 or 1 */ + int bfd_process_wakeup_events_in_flight; + + /** The timestamp of last wakeup event being sent */ + u64 bfd_process_wakeup_event_start_clocks; + + /** The time it took the last wakeup event to make it to handling */ + u64 bfd_process_wakeup_event_delay_clocks; + + /** When the bfd process is supposed to wake up next */ + u64 bfd_process_next_wakeup_clocks; + /** pool of bfd sessions context data */ bfd_session_t *sessions; @@ -259,6 +315,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; @@ -303,6 +364,46 @@ typedef CLIB_PACKED (struct { }) bfd_echo_pkt_t; /* *INDENT-ON* */ +static inline void +bfd_lock (bfd_main_t * bm) +{ + uword my_thread_index = __os_thread_index; + + if (bm->owner_thread_index == my_thread_index + && bm->lock_recursion_count > 0) + { + bm->lock_recursion_count++; + return; + } + + clib_spinlock_lock_if_init (&bm->lock); + bm->lock_recursion_count = 1; + bm->owner_thread_index = my_thread_index; +} + +static inline void +bfd_unlock (bfd_main_t * bm) +{ + uword my_thread_index = __os_thread_index; + ASSERT (bm->owner_thread_index == my_thread_index); + + if (bm->lock_recursion_count > 1) + { + bm->lock_recursion_count--; + return; + } + bm->lock_recursion_count = 0; + bm->owner_thread_index = ~0; + clib_spinlock_unlock_if_init (&bm->lock); +} + +static inline void +bfd_lock_check (bfd_main_t * bm) +{ + if (PREDICT_FALSE (bm->lock_recursion_count < 1)) + clib_warning ("lock check failure"); +} + u8 *bfd_input_format_trace (u8 * s, va_list * args); bfd_session_t *bfd_get_session (bfd_main_t * bm, bfd_transport_e t); void bfd_put_session (bfd_main_t * bm, bfd_session_t * bs); @@ -316,8 +417,10 @@ int bfd_verify_pkt_auth (const bfd_pkt_t * pkt, u16 pkt_size, bfd_session_t * bs); void bfd_event (bfd_main_t * bm, bfd_session_t * bs); void bfd_init_final_control_frame (vlib_main_t * vm, vlib_buffer_t * b, - bfd_main_t * bm, bfd_session_t * bs); + 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); @@ -344,6 +447,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__ */ /*