2 * Copyright (c) 2011-2016 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
17 * @brief BFD global declarations
19 #ifndef __included_bfd_main_h__
20 #define __included_bfd_main_h__
22 #include <vppinfra/timing_wheel.h>
23 #include <vnet/vnet.h>
24 #include <vnet/bfd/bfd_protocol.h>
25 #include <vnet/bfd/bfd_udp.h>
27 #define foreach_bfd_transport(F) \
28 F (UDP4, "ip4-rewrite") \
29 F (UDP6, "ip6-rewrite")
33 #define F(t, n) BFD_TRANSPORT_##t,
34 foreach_bfd_transport (F)
38 #define foreach_bfd_mode(F) \
44 #define F(x) BFD_MODE_##x,
51 /* index in bfd_main.sessions pool */
55 bfd_state_e local_state;
57 /* local diagnostics */
58 bfd_diag_code_e local_diag;
60 /* remote session state */
61 bfd_state_e remote_state;
63 /* local discriminator */
66 /* remote discriminator */
69 /* configured desired min tx interval (microseconds) */
70 u32 config_desired_min_tx_us;
72 /* desired min tx interval (microseconds) */
73 u32 desired_min_tx_us;
75 /* desired min tx interval (clocks) */
76 u64 desired_min_tx_clocks;
78 /* required min rx interval (microseconds) */
79 u32 required_min_rx_us;
81 /* required min echo rx interval (microseconds) */
82 u32 required_min_echo_rx_us;
84 /* remote min rx interval (microseconds) */
87 /* remote min rx interval (clocks) */
88 u64 remote_min_rx_clocks;
90 /* remote desired min tx interval (microseconds) */
91 u32 remote_desired_min_tx_us;
93 /* 1 if in demand mode, 0 otherwise */
96 /* 1 if remote system sets demand mode, 0 otherwise */
99 /* local detect multiplier */
100 u8 local_detect_mult;
102 /* remote detect multiplier */
103 u8 remote_detect_mult;
105 /* set to value of timer in timing wheel, 0 if never set */
106 u64 wheel_time_clocks;
108 /* transmit interval */
109 u64 transmit_interval_clocks;
111 /* next time at which to transmit a packet */
112 u64 tx_timeout_clocks;
114 /* timestamp of last packet transmitted */
117 /* timestamp of last packet received */
121 u64 detection_time_clocks;
123 /* transport type for this session */
124 bfd_transport_t transport;
128 bfd_udp_session_t udp;
136 } event_subscriber_t;
140 /* pool of bfd sessions context data */
141 bfd_session_t *sessions;
143 /* timing wheel for scheduling timeouts */
144 timing_wheel_t wheel;
146 /* timing wheel inaccuracy, in clocks */
147 u64 wheel_inaccuracy;
149 /* hashmap - bfd session by discriminator */
150 u32 *session_by_disc;
152 /* background process node index */
153 u32 bfd_process_node_index;
155 /* convenience variables */
156 vlib_main_t *vlib_main;
157 vnet_main_t *vnet_main;
159 /* cpu clocks per second */
162 /* for generating random numbers */
167 extern bfd_main_t bfd_main;
169 /* Packet counters */
170 #define foreach_bfd_error(F) \
171 F (NONE, "good bfd packets (processed)") \
172 F (BAD, "invalid bfd packets") \
173 F (DISABLED, "bfd packets received on disabled interfaces")
177 #define F(sym, str) BFD_ERROR_##sym,
178 foreach_bfd_error (F)
183 /* bfd packet trace capture */
192 BFD_EVENT_RESCHEDULE = 1,
193 BFD_EVENT_NEW_SESSION,
194 } bfd_process_event_e;
196 u8 *bfd_input_format_trace (u8 * s, va_list * args);
198 bfd_session_t *bfd_get_session (bfd_main_t * bm, bfd_transport_t t);
199 void bfd_put_session (bfd_main_t * bm, bfd_session_t * bs);
200 bfd_session_t *bfd_find_session_by_idx (bfd_main_t * bm, uword bs_idx);
201 bfd_session_t *bfd_find_session_by_disc (bfd_main_t * bm, u32 disc);
202 void bfd_session_start (bfd_main_t * bm, bfd_session_t * bs);
203 void bfd_consume_pkt (bfd_main_t * bm, const bfd_pkt_t * bfd, u32 bs_idx);
204 int bfd_verify_pkt_common (const bfd_pkt_t * pkt);
205 int bfd_verify_pkt_session (const bfd_pkt_t * pkt, u16 pkt_size,
206 const bfd_session_t * bs);
207 void bfd_event (bfd_main_t * bm, bfd_session_t * bs);
208 void bfd_send_final (vlib_main_t * vm, vlib_buffer_t * b, bfd_session_t * bs);
209 u8 *format_bfd_session (u8 * s, va_list * args);
212 #define USEC_PER_MS 1000LL
213 #define USEC_PER_SECOND (1000 * USEC_PER_MS)
215 /* default, slow transmission interval for BFD packets, per spec at least 1s */
216 #define BFD_DEFAULT_DESIRED_MIN_TX_US USEC_PER_SECOND
218 #endif /* __included_bfd_main_h__ */
221 * fd.io coding-style-patch-verification: ON
224 * eval: (c-set-style "gnu")