FD.io VPP  v17.10-9-gd594711
Vector Packet Processing
bfd_main.h
Go to the documentation of this file.
1 /*
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:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 /**
16  * @file
17  * @brief BFD global declarations
18  */
19 #ifndef __included_bfd_main_h__
20 #define __included_bfd_main_h__
21 
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>
26 
27 #define foreach_bfd_mode(F) \
28  F (asynchronous) \
29  F (demand)
30 
31 typedef enum
32 {
33 #define F(x) BFD_MODE_##x,
35 #undef F
36 } bfd_mode_e;
37 
38 typedef struct
39 {
40  /** global configuration key ID */
42 
43  /** keeps track of how many sessions reference this key */
45 
46  /**
47  * key data directly usable for bfd purposes - already padded with zeroes
48  * (so we don't need the actual length)
49  */
50  u8 key[20];
51 
52  /** authentication type for this key */
55 
56 #define foreach_bfd_poll_state(F) \
57  F (NOT_NEEDED) \
58  F (NEEDED) \
59  F (IN_PROGRESS) \
60  F (IN_PROGRESS_AND_QUEUED)
61 
62 typedef enum
63 {
64 #define F(x) BFD_POLL_##x,
66 #undef F
68 
69 /**
70  * hop types
71  */
72 #define foreach_bfd_hop(F) \
73  F (SINGLE, "single") \
74  F (MULTI, "multi") \
75 
76 typedef enum
77 {
78 #define F(sym, str) BFD_HOP_TYPE_##sym,
80 #undef F
82 
83 typedef struct bfd_session_s
84 {
85  /** index in bfd_main.sessions pool */
87 
88  /** session state */
90 
91  /** remote session state */
93 
94  /** BFD hop type */
95  bfd_hop_type_e hop_type;
96 
97  /** local diagnostics */
99 
100  /** remote diagnostics */
102 
103  /** local discriminator */
105 
106  /** remote discriminator */
108 
109  /** configured desired min tx interval (microseconds) */
111 
112  /** configured desired min tx interval (clocks) */
114 
115  /** effective desired min tx interval (clocks) */
117 
118  /** configured required min rx interval (microseconds) */
120 
121  /** configured required min rx interval (clocks) */
123 
124  /** effective required min rx interval (clocks) */
126 
127  /** remote min rx interval (microseconds) */
129 
130  /** remote min rx interval (clocks) */
132 
133  /** remote min echo rx interval (microseconds) */
135 
136  /** remote min echo rx interval (clocks) */
138 
139  /** remote desired min tx interval (clocks) */
141 
142  /** configured detect multiplier */
144 
145  /** 1 if remote system sets demand mode, 0 otherwise */
147 
148  /** remote detect multiplier */
150 
151  /** 1 is echo function is active, 0 otherwise */
153 
154  /** set to value of timer in timing wheel, 0 if never set */
156 
157  /** transmit interval */
159 
160  /** next time at which to transmit a packet */
162 
163  /** timestamp of last packet transmitted */
165 
166  /** timestamp of last packet received */
168 
169  /** transmit interval for echo packets */
171 
172  /** next time at which to transmit echo packet */
174 
175  /** timestamp of last echo packet transmitted */
177 
178  /** timestamp of last echo packet received */
180 
181  /** secret used for calculating/checking checksum of echo packets */
183 
184  /** detection time */
186 
187  /** state info regarding poll sequence */
188  bfd_poll_state_e poll_state;
189 
190  /**
191  * helper for delayed poll sequence - marks either start of running poll
192  * sequence or timeout, after which we can start the next poll sequnce
193  */
195 
196  /** authentication information */
197  struct
198  {
199  /** current key in use */
201 
202  /**
203  * set to next key to use if delayed switch is enabled - in that case
204  * the key is switched when first incoming packet is signed with next_key
205  */
207 
208  /** sequence number incremented occasionally or always (if meticulous) */
210 
211  /** remote sequence number */
213 
214  /** set to 1 if remote sequence number is known */
216 
217  /** current key ID sent out in bfd packet */
219 
220  /** key ID to use when switched to next_key */
222 
223  /**
224  * set to 1 if delayed action is pending, which might be activation
225  * of authentication, change of key or deactivation
226  */
228  } auth;
229 
230  /** transport type for this session */
232 
233  /** union of transport-specific data */
234  union
235  {
237  };
238 } bfd_session_t;
239 
240 /**
241  * listener events
242  */
243 #define foreach_bfd_listen_event(F) \
244  F (CREATE, "sesion-created") \
245  F (UPDATE, "session-updated") \
246  F (DELETE, "session-deleted")
247 
248 typedef enum
249 {
250 #define F(sym, str) BFD_LISTEN_EVENT_##sym,
252 #undef F
254 
255 /**
256  * session nitification call back function type
257  */
259 
260 typedef struct
261 {
262  /** pool of bfd sessions context data */
264 
265  /** timing wheel for scheduling timeouts */
267 
268  /** timing wheel inaccuracy, in clocks */
270 
271  /** hashmap - bfd session by discriminator */
273 
274  /** background process node index */
276 
277  /** convenience variables */
280 
281  /** cpu clocks per second */
283 
284  /** default desired min tx in clocks */
286 
287  /** minimum required min rx while echo function is active - clocks */
289 
290  /** for generating random numbers */
292 
293  /** pool of authentication keys */
295 
296  /** hashmap - index in pool auth_keys by conf_key_id */
298 
299  /** A vector of callback notification functions */
301 } bfd_main_t;
302 
303 extern bfd_main_t bfd_main;
304 
305 /** Packet counters */
306 #define foreach_bfd_error(F) \
307  F (NONE, "good bfd packets (processed)") \
308  F (BAD, "invalid bfd packets") \
309  F (DISABLED, "bfd packets received on disabled interfaces")
310 
311 typedef enum
312 {
313 #define F(sym, str) BFD_ERROR_##sym,
315 #undef F
316  BFD_N_ERROR,
317 } bfd_error_t;
318 
319 /** bfd packet trace capture */
320 typedef struct
321 {
323  u8 data[400];
325 
326 enum
327 {
332 
333 /* *INDENT-OFF* */
334 /** echo packet structure */
335 typedef CLIB_PACKED (struct {
336  /** local discriminator */
337  u32 discriminator;
338  /** expire time of this packet - clocks */
339  u64 expire_time_clocks;
340  /** checksum - based on discriminator, local secret and expire time */
341  u64 checksum;
342 }) bfd_echo_pkt_t;
343 /* *INDENT-ON* */
344 
345 u8 *bfd_input_format_trace (u8 * s, va_list * args);
347 void bfd_put_session (bfd_main_t * bm, bfd_session_t * bs);
350 void bfd_session_start (bfd_main_t * bm, bfd_session_t * bs);
351 void bfd_consume_pkt (bfd_main_t * bm, const bfd_pkt_t * bfd, u32 bs_idx);
353 int bfd_verify_pkt_common (const bfd_pkt_t * pkt);
354 int bfd_verify_pkt_auth (const bfd_pkt_t * pkt, u16 pkt_size,
355  bfd_session_t * bs);
356 void bfd_event (bfd_main_t * bm, bfd_session_t * bs);
358  bfd_main_t * bm, bfd_session_t * bs,
359  int is_local);
360 u8 *format_bfd_session (u8 * s, va_list * args);
361 u8 *format_bfd_auth_key (u8 * s, va_list * args);
362 void bfd_session_set_flags (bfd_session_t * bs, u8 admin_up_down);
363 unsigned bfd_auth_type_supported (bfd_auth_type_e auth_type);
365  u8 bfd_key_id, u8 is_delayed);
368  u32 desired_min_tx_usec,
369  u32 required_min_rx_usec,
370  u8 detect_mult);
371 
372 u32 bfd_clocks_to_usec (const bfd_main_t * bm, u64 clocks);
373 const char *bfd_poll_state_string (bfd_poll_state_e state);
374 
375 #define USEC_PER_MS 1000LL
376 #define USEC_PER_SECOND (1000 * USEC_PER_MS)
377 
378 /** default, slow transmission interval for BFD packets, per spec at least 1s */
379 #define BFD_DEFAULT_DESIRED_MIN_TX_USEC USEC_PER_SECOND
380 
381 /**
382  * minimum required min rx set locally when echo function is used, per spec
383  * should be set to at least 1s
384  */
385 #define BFD_REQUIRED_MIN_RX_USEC_WHILE_ECHO USEC_PER_SECOND
386 
387 /**
388  * Register a callback function to receive session notifications.
389  */
391 
392 #endif /* __included_bfd_main_h__ */
393 
394 /*
395  * fd.io coding-style-patch-verification: ON
396  *
397  * Local Variables:
398  * eval: (c-set-style "gnu")
399  * End:
400  */
enum @46 bfd_process_event_e
bfd_notify_fn_t * listeners
A vector of callback notification functions.
Definition: bfd_main.h:300
vnet_api_error_t
Definition: api_errno.h:121
bfd_main_t bfd_main
Definition: bfd_main.c:2050
bfd_auth_type_e auth_type
authentication type for this key
Definition: bfd_main.h:53
u8 curr_bfd_key_id
current key ID sent out in bfd packet
Definition: bfd_main.h:218
bfd_session_t * bfd_get_session(bfd_main_t *bm, bfd_transport_e t)
Definition: bfd_main.c:1175
struct bfd_session_s bfd_session_t
u32 * auth_key_by_conf_key_id
hashmap - index in pool auth_keys by conf_key_id
Definition: bfd_main.h:297
u64 echo_last_rx_clocks
timestamp of last echo packet received
Definition: bfd_main.h:179
u32 echo_secret
secret used for calculating/checking checksum of echo packets
Definition: bfd_main.h:182
bfd_session_t * bfd_find_session_by_idx(bfd_main_t *bm, uword bs_idx)
Definition: bfd_main.c:1219
bfd_diag_code_e local_diag
local diagnostics
Definition: bfd_main.h:98
#define foreach_bfd_hop(F)
hop types
Definition: bfd_main.h:72
#define foreach_bfd_listen_event(F)
listener events
Definition: bfd_main.h:243
u64 last_tx_clocks
timestamp of last packet transmitted
Definition: bfd_main.h:164
void bfd_register_listener(bfd_notify_fn_t fn)
Register a callback function to receive session notifications.
Definition: bfd_main.c:1139
u8 remote_seq_number_known
set to 1 if remote sequence number is known
Definition: bfd_main.h:215
int bfd_verify_pkt_common(const bfd_pkt_t *pkt)
verify bfd packet - common checks
Definition: bfd_main.c:1247
bfd_diag_code_e
Definition: bfd_protocol.h:177
u32 bfd_process_node_index
background process node index
Definition: bfd_main.h:275
u64 remote_min_echo_rx_clocks
remote min echo rx interval (clocks)
Definition: bfd_main.h:137
bfd_hop_type_e
Definition: bfd_main.h:76
u64 effective_required_min_rx_clocks
effective required min rx interval (clocks)
Definition: bfd_main.h:125
void bfd_put_session(bfd_main_t *bm, bfd_session_t *bs)
Definition: bfd_main.c:1203
#define foreach_bfd_mode(F)
Definition: bfd_main.h:27
u8 * bfd_input_format_trace(u8 *s, va_list *args)
Definition: bfd_main.c:438
bfd_auth_type_e
Definition: bfd_protocol.h:36
u32 remote_seq_number
remote sequence number
Definition: bfd_main.h:212
unsigned bfd_auth_type_supported(bfd_auth_type_e auth_type)
Definition: bfd_main.c:1804
bfd_error_t
Definition: bfd_main.h:311
timing_wheel_t wheel
timing wheel for scheduling timeouts
Definition: bfd_main.h:266
u64 effective_desired_min_tx_clocks
effective desired min tx interval (clocks)
Definition: bfd_main.h:116
bfd_mode_e
Definition: bfd_main.h:31
u32 random_seed
for generating random numbers
Definition: bfd_main.h:291
int bfd_verify_pkt_auth(const bfd_pkt_t *pkt, u16 pkt_size, bfd_session_t *bs)
verify bfd packet - authentication
Definition: bfd_main.c:1523
#define foreach_bfd_error(F)
Packet counters.
Definition: bfd_main.h:306
void bfd_consume_pkt(bfd_main_t *bm, const bfd_pkt_t *bfd, u32 bs_idx)
Definition: bfd_main.c:1601
u64 remote_min_rx_usec
remote min rx interval (microseconds)
Definition: bfd_main.h:128
UDP transport specific data embedded in bfd_session&#39;s union.
Definition: bfd_udp.h:44
u64 tx_timeout_clocks
next time at which to transmit a packet
Definition: bfd_main.h:161
int bfd_consume_echo_pkt(bfd_main_t *bm, vlib_buffer_t *b)
Definition: bfd_main.c:1732
unsigned long u64
Definition: types.h:89
u64 config_required_min_rx_clocks
configured required min rx interval (clocks)
Definition: bfd_main.h:122
bfd_auth_key_t * next_key
set to next key to use if delayed switch is enabled - in that case the key is switched when first inc...
Definition: bfd_main.h:206
void bfd_event(bfd_main_t *bm, bfd_session_t *bs)
Definition: bfd_api.c:198
void bfd_session_set_flags(bfd_session_t *bs, u8 admin_up_down)
Definition: bfd_main.c:415
u8 remote_demand
1 if remote system sets demand mode, 0 otherwise
Definition: bfd_main.h:146
bfd_session_t * sessions
pool of bfd sessions context data
Definition: bfd_main.h:263
bfd_poll_state_e
Definition: bfd_main.h:62
bfd_auth_key_t * auth_keys
pool of authentication keys
Definition: bfd_main.h:294
bfd_transport_e transport
transport type for this session
Definition: bfd_main.h:231
u32 remote_discr
remote discriminator
Definition: bfd_main.h:107
u64 default_desired_min_tx_clocks
default desired min tx in clocks
Definition: bfd_main.h:285
u64 echo_last_tx_clocks
timestamp of last echo packet transmitted
Definition: bfd_main.h:176
bfd_poll_state_e poll_state
state info regarding poll sequence
Definition: bfd_main.h:188
f64 cpu_cps
cpu clocks per second
Definition: bfd_main.h:282
u8 * format_bfd_session(u8 *s, va_list *args)
Definition: bfd_main.c:1768
u64 echo_tx_timeout_clocks
next time at which to transmit echo packet
Definition: bfd_main.h:173
u8 local_detect_mult
configured detect multiplier
Definition: bfd_main.h:143
vnet_api_error_t bfd_auth_deactivate(bfd_session_t *bs, u8 is_delayed)
Definition: bfd_main.c:1861
u64 last_rx_clocks
timestamp of last packet received
Definition: bfd_main.h:167
bfd_udp_session_t udp
Definition: bfd_main.h:236
bfd_diag_code_e remote_diag
remote diagnostics
Definition: bfd_main.h:101
vnet_api_error_t bfd_session_set_params(bfd_main_t *bm, bfd_session_t *bs, u32 desired_min_tx_usec, u32 required_min_rx_usec, u8 detect_mult)
Definition: bfd_main.c:1899
u64 transmit_interval_clocks
transmit interval
Definition: bfd_main.h:158
vnet_main_t * vnet_main
Definition: bfd_main.h:279
#define foreach_bfd_poll_state(F)
Definition: bfd_main.h:56
vnet_api_error_t bfd_auth_activate(bfd_session_t *bs, u32 conf_key_id, u8 bfd_key_id, u8 is_delayed)
Definition: bfd_main.c:1815
BFD protocol declarations.
u32 config_desired_min_tx_usec
configured desired min tx interval (microseconds)
Definition: bfd_main.h:110
typedef CLIB_PACKED(struct{u32 discriminator;u64 expire_time_clocks;u64 checksum;}) bfd_echo_pkt_t
echo packet structure
u64 poll_state_start_or_timeout_clocks
helper for delayed poll sequence - marks either start of running poll sequence or timeout...
Definition: bfd_main.h:194
bfd_state_e
Definition: bfd_protocol.h:195
u64 detection_time_clocks
detection time
Definition: bfd_main.h:185
void bfd_session_start(bfd_main_t *bm, bfd_session_t *bs)
Definition: bfd_main.c:403
unsigned int u32
Definition: types.h:88
u64 config_desired_min_tx_clocks
configured desired min tx interval (clocks)
Definition: bfd_main.h:113
u32 bfd_clocks_to_usec(const bfd_main_t *bm, u64 clocks)
Definition: bfd_main.c:59
u8 echo
1 is echo function is active, 0 otherwise
Definition: bfd_main.h:152
#define F(x)
Definition: bfd_main.h:313
u64 wheel_time_clocks
set to value of timer in timing wheel, 0 if never set
Definition: bfd_main.h:155
u64 remote_desired_min_tx_clocks
remote desired min tx interval (clocks)
Definition: bfd_main.h:140
u8 * format_bfd_auth_key(u8 *s, va_list *args)
Definition: bfd_main.c:67
u32 local_discr
local discriminator
Definition: bfd_main.h:104
bfd_hop_type_e hop_type
BFD hop type.
Definition: bfd_main.h:95
u32 conf_key_id
global configuration key ID
Definition: bfd_main.h:41
vlib_main_t * vlib_main
convenience variables
Definition: bfd_main.h:278
bfd_state_e local_state
session state
Definition: bfd_main.h:89
u32 * session_by_disc
hashmap - bfd session by discriminator
Definition: bfd_main.h:272
u64 uword
Definition: types.h:112
void(* bfd_notify_fn_t)(bfd_listen_event_e, const bfd_session_t *)
session nitification call back function type
Definition: bfd_main.h:258
u64 echo_transmit_interval_clocks
transmit interval for echo packets
Definition: bfd_main.h:170
u32 local_seq_number
sequence number incremented occasionally or always (if meticulous)
Definition: bfd_main.h:209
u32 config_required_min_rx_usec
configured required min rx interval (microseconds)
Definition: bfd_main.h:119
BFD UDP transport layer declarations.
unsigned short u16
Definition: types.h:57
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)
Definition: bfd_main.c:894
double f64
Definition: types.h:142
unsigned char u8
Definition: types.h:56
u32 use_count
keeps track of how many sessions reference this key
Definition: bfd_main.h:44
u8 next_bfd_key_id
key ID to use when switched to next_key
Definition: bfd_main.h:221
u32 bs_idx
index in bfd_main.sessions pool
Definition: bfd_main.h:86
u64 remote_min_echo_rx_usec
remote min echo rx interval (microseconds)
Definition: bfd_main.h:134
bfd_state_e remote_state
remote session state
Definition: bfd_main.h:92
bfd_session_t * bfd_find_session_by_disc(bfd_main_t *bm, u32 disc)
Definition: bfd_main.c:1229
const char * bfd_poll_state_string(bfd_poll_state_e state)
Definition: bfd_main.c:145
struct bfd_session_s::@47 auth
authentication information
bfd packet trace capture
Definition: bfd_main.h:320
u64 min_required_min_rx_while_echo_clocks
minimum required min rx while echo function is active - clocks
Definition: bfd_main.h:288
bfd_auth_key_t * curr_key
current key in use
Definition: bfd_main.h:200
u8 remote_detect_mult
remote detect multiplier
Definition: bfd_main.h:149
u64 remote_min_rx_clocks
remote min rx interval (clocks)
Definition: bfd_main.h:131
u8 is_delayed
set to 1 if delayed action is pending, which might be activation of authentication, change of key or deactivation
Definition: bfd_main.h:227
bfd_transport_e
Definition: bfd_api.h:30
bfd_listen_event_e
Definition: bfd_main.h:248
u64 wheel_inaccuracy
timing wheel inaccuracy, in clocks
Definition: bfd_main.h:269