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 */
79 u32 required_min_rx_us;
81 /* remote min rx interval (microseconds) */
84 /* remote min rx interval (clocks) */
85 u64 remote_min_rx_clocks;
87 /* remote desired min tx interval */
88 u32 remote_desired_min_tx_us;
90 /* 1 if in demand mode, 0 otherwise */
93 /* 1 if remote system sets demand mode, 0 otherwise */
96 /* local detect multiplier */
99 /* remote detect multiplier */
100 u8 remote_detect_mult;
102 /* set to value of timer in timing wheel, 0 if never set */
103 u64 wheel_time_clocks;
105 /* transmit interval */
106 u64 transmit_interval_clocks;
108 /* next time at which to transmit a packet */
109 u64 tx_timeout_clocks;
111 /* timestamp of last packet received */
115 u64 detection_time_clocks;
117 /* transport type for this session */
118 bfd_transport_t transport;
122 bfd_udp_session_t udp;
130 } event_subscriber_t;
134 /* pool of bfd sessions context data */
135 bfd_session_t *sessions;
137 /* timing wheel for scheduling timeouts */
138 timing_wheel_t wheel;
140 /* timing wheel inaccuracy, in clocks */
141 u64 wheel_inaccuracy;
143 /* hashmap - bfd session by discriminator */
144 u32 *session_by_disc;
146 /* background process node index */
147 u32 bfd_process_node_index;
149 /* convenience variables */
150 vlib_main_t *vlib_main;
151 vnet_main_t *vnet_main;
153 /* cpu clocks per second */
156 /* for generating random numbers */
161 extern bfd_main_t bfd_main;
163 /* Packet counters */
164 #define foreach_bfd_error(F) \
165 F (NONE, "good bfd packets (processed)") \
166 F (BAD, "invalid bfd packets") \
167 F (DISABLED, "bfd packets received on disabled interfaces")
171 #define F(sym, str) BFD_ERROR_##sym,
172 foreach_bfd_error (F)
177 /* bfd packet trace capture */
186 BFD_EVENT_RESCHEDULE = 1,
187 BFD_EVENT_NEW_SESSION,
188 } bfd_process_event_e;
190 u8 *bfd_input_format_trace (u8 * s, va_list * args);
192 bfd_session_t *bfd_get_session (bfd_main_t * bm, bfd_transport_t t);
193 void bfd_put_session (bfd_main_t * bm, bfd_session_t * bs);
194 bfd_session_t *bfd_find_session_by_idx (bfd_main_t * bm, uword bs_idx);
195 bfd_session_t *bfd_find_session_by_disc (bfd_main_t * bm, u32 disc);
196 void bfd_session_start (bfd_main_t * bm, bfd_session_t * bs);
197 void bfd_consume_pkt (bfd_main_t * bm, const bfd_pkt_t * bfd, u32 bs_idx);
198 int bfd_verify_pkt_common (const bfd_pkt_t * pkt);
199 int bfd_verify_pkt_session (const bfd_pkt_t * pkt, u16 pkt_size,
200 const bfd_session_t * bs);
201 void bfd_event (bfd_main_t * bm, bfd_session_t * bs);
202 void bfd_send_final (vlib_main_t * vm, vlib_buffer_t * b, bfd_session_t * bs);
203 u8 *format_bfd_session (u8 * s, va_list * args);
206 #define USEC_PER_MS 1000LL
207 #define USEC_PER_SECOND (1000 * USEC_PER_MS)
209 /* default, slow transmission interval for BFD packets, per spec at least 1s */
210 #define BFD_DEFAULT_DESIRED_MIN_TX_US USEC_PER_SECOND
212 #endif /* __included_bfd_main_h__ */
215 * fd.io coding-style-patch-verification: ON
218 * eval: (c-set-style "gnu")