summaryrefslogtreecommitdiffstats
path: root/src/vnet/bfd/bfd_main.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/vnet/bfd/bfd_main.h')
-rw-r--r--src/vnet/bfd/bfd_main.h220
1 files changed, 220 insertions, 0 deletions
diff --git a/src/vnet/bfd/bfd_main.h b/src/vnet/bfd/bfd_main.h
new file mode 100644
index 00000000000..c72ea92a70f
--- /dev/null
+++ b/src/vnet/bfd/bfd_main.h
@@ -0,0 +1,220 @@
+/*
+ * Copyright (c) 2011-2016 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file
+ * @brief BFD global declarations
+ */
+#ifndef __included_bfd_main_h__
+#define __included_bfd_main_h__
+
+#include <vppinfra/timing_wheel.h>
+#include <vnet/vnet.h>
+#include <vnet/bfd/bfd_protocol.h>
+#include <vnet/bfd/bfd_udp.h>
+
+#define foreach_bfd_transport(F) \
+ F (UDP4, "ip4-rewrite") \
+ F (UDP6, "ip6-rewrite")
+
+typedef enum
+{
+#define F(t, n) BFD_TRANSPORT_##t,
+ foreach_bfd_transport (F)
+#undef F
+} bfd_transport_t;
+
+#define foreach_bfd_mode(F) \
+ F (asynchronous) \
+ F (demand)
+
+typedef enum
+{
+#define F(x) BFD_MODE_##x,
+ foreach_bfd_mode (F)
+#undef F
+} bfd_mode_e;
+
+typedef struct
+{
+ /* index in bfd_main.sessions pool */
+ u32 bs_idx;
+
+ /* session state */
+ bfd_state_e local_state;
+
+ /* local diagnostics */
+ bfd_diag_code_e local_diag;
+
+ /* remote session state */
+ bfd_state_e remote_state;
+
+ /* local discriminator */
+ u32 local_discr;
+
+ /* remote discriminator */
+ u32 remote_discr;
+
+ /* configured desired min tx interval (microseconds) */
+ u32 config_desired_min_tx_us;
+
+ /* desired min tx interval (microseconds) */
+ u32 desired_min_tx_us;
+
+ /* desired min tx interval (clocks) */
+ u64 desired_min_tx_clocks;
+
+ /* required min rx interval */
+ u32 required_min_rx_us;
+
+ /* remote min rx interval (microseconds) */
+ u32 remote_min_rx_us;
+
+ /* remote min rx interval (clocks) */
+ u64 remote_min_rx_clocks;
+
+ /* remote desired min tx interval */
+ u32 remote_desired_min_tx_us;
+
+ /* 1 if in demand mode, 0 otherwise */
+ u8 local_demand;
+
+ /* 1 if remote system sets demand mode, 0 otherwise */
+ u8 remote_demand;
+
+ /* local detect multiplier */
+ u8 local_detect_mult;
+
+ /* remote detect multiplier */
+ u8 remote_detect_mult;
+
+ /* set to value of timer in timing wheel, 0 if never set */
+ u64 wheel_time_clocks;
+
+ /* transmit interval */
+ u64 transmit_interval_clocks;
+
+ /* next time at which to transmit a packet */
+ u64 tx_timeout_clocks;
+
+ /* timestamp of last packet received */
+ u64 last_rx_clocks;
+
+ /* detection time */
+ u64 detection_time_clocks;
+
+ /* transport type for this session */
+ bfd_transport_t transport;
+
+ union
+ {
+ bfd_udp_session_t udp;
+ };
+} bfd_session_t;
+
+typedef struct
+{
+ u32 client_index;
+ u32 client_pid;
+} event_subscriber_t;
+
+typedef struct
+{
+ /* pool of bfd sessions context data */
+ bfd_session_t *sessions;
+
+ /* timing wheel for scheduling timeouts */
+ timing_wheel_t wheel;
+
+ /* timing wheel inaccuracy, in clocks */
+ u64 wheel_inaccuracy;
+
+ /* hashmap - bfd session by discriminator */
+ u32 *session_by_disc;
+
+ /* background process node index */
+ u32 bfd_process_node_index;
+
+ /* convenience variables */
+ vlib_main_t *vlib_main;
+ vnet_main_t *vnet_main;
+
+ /* cpu clocks per second */
+ f64 cpu_cps;
+
+ /* for generating random numbers */
+ u32 random_seed;
+
+} bfd_main_t;
+
+extern bfd_main_t bfd_main;
+
+/* Packet counters */
+#define foreach_bfd_error(F) \
+ F (NONE, "good bfd packets (processed)") \
+ F (BAD, "invalid bfd packets") \
+ F (DISABLED, "bfd packets received on disabled interfaces")
+
+typedef enum
+{
+#define F(sym, str) BFD_ERROR_##sym,
+ foreach_bfd_error (F)
+#undef F
+ BFD_N_ERROR,
+} bfd_error_t;
+
+/* bfd packet trace capture */
+typedef struct
+{
+ u32 len;
+ u8 data[400];
+} bfd_input_trace_t;
+
+enum
+{
+ BFD_EVENT_RESCHEDULE = 1,
+ BFD_EVENT_NEW_SESSION,
+} bfd_process_event_e;
+
+u8 *bfd_input_format_trace (u8 * s, va_list * args);
+
+bfd_session_t *bfd_get_session (bfd_main_t * bm, bfd_transport_t t);
+void bfd_put_session (bfd_main_t * bm, bfd_session_t * bs);
+bfd_session_t *bfd_find_session_by_idx (bfd_main_t * bm, uword bs_idx);
+bfd_session_t *bfd_find_session_by_disc (bfd_main_t * bm, u32 disc);
+void bfd_session_start (bfd_main_t * bm, bfd_session_t * bs);
+void bfd_consume_pkt (bfd_main_t * bm, const bfd_pkt_t * bfd, u32 bs_idx);
+int bfd_verify_pkt_common (const bfd_pkt_t * pkt);
+int bfd_verify_pkt_session (const bfd_pkt_t * pkt, u16 pkt_size,
+ const bfd_session_t * bs);
+void bfd_event (bfd_main_t * bm, bfd_session_t * bs);
+void bfd_send_final (vlib_main_t * vm, vlib_buffer_t * b, bfd_session_t * bs);
+u8 *format_bfd_session (u8 * s, va_list * args);
+
+
+#define USEC_PER_MS 1000LL
+#define USEC_PER_SECOND (1000 * USEC_PER_MS)
+
+/* default, slow transmission interval for BFD packets, per spec at least 1s */
+#define BFD_DEFAULT_DESIRED_MIN_TX_US USEC_PER_SECOND
+
+#endif /* __included_bfd_main_h__ */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */