blob: a7540004dcc92f7296e1f18b89032e017f39880b [file] [log] [blame]
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001/*
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
Klement Sekera0e3c0de2016-09-29 14:43:44 +020022#include <vnet/vnet.h>
23#include <vnet/bfd/bfd_protocol.h>
24#include <vnet/bfd/bfd_udp.h>
Damjan Marion07a38572018-01-21 06:44:18 -080025#include <vlib/log.h>
Dave Barach1e3417f2018-07-25 08:30:27 -040026#include <vppinfra/os.h>
Klement Sekeraa3167442020-02-10 11:49:52 +000027#include <vppinfra/tw_timer_1t_3w_1024sl_ov.h>
Klement Sekera0e3c0de2016-09-29 14:43:44 +020028
Klement Sekera0e3c0de2016-09-29 14:43:44 +020029#define foreach_bfd_mode(F) \
30 F (asynchronous) \
31 F (demand)
32
33typedef enum
34{
35#define F(x) BFD_MODE_##x,
36 foreach_bfd_mode (F)
37#undef F
38} bfd_mode_e;
39
40typedef struct
41{
Klement Sekerab16bfe32017-02-28 11:56:48 +010042 /** global configuration key ID */
Klement Sekerab17dd962017-01-09 07:43:48 +010043 u32 conf_key_id;
44
Klement Sekerab16bfe32017-02-28 11:56:48 +010045 /** keeps track of how many sessions reference this key */
Klement Sekerab17dd962017-01-09 07:43:48 +010046 u32 use_count;
47
Klement Sekerab16bfe32017-02-28 11:56:48 +010048 /**
Klement Sekerab17dd962017-01-09 07:43:48 +010049 * key data directly usable for bfd purposes - already padded with zeroes
50 * (so we don't need the actual length)
51 */
52 u8 key[20];
53
Klement Sekerab16bfe32017-02-28 11:56:48 +010054 /** authentication type for this key */
Klement Sekerab17dd962017-01-09 07:43:48 +010055 bfd_auth_type_e auth_type;
56} bfd_auth_key_t;
57
Klement Sekera239790f2017-02-16 10:53:53 +010058#define foreach_bfd_poll_state(F) \
59 F (NOT_NEEDED) \
60 F (NEEDED) \
61 F (IN_PROGRESS) \
62 F (IN_PROGRESS_AND_QUEUED)
Klement Sekeraa57a9702017-02-02 06:58:07 +010063
64typedef enum
65{
Klement Sekera239790f2017-02-16 10:53:53 +010066#define F(x) BFD_POLL_##x,
Klement Sekeraa57a9702017-02-02 06:58:07 +010067 foreach_bfd_poll_state (F)
68#undef F
69} bfd_poll_state_e;
70
Neale Ranns88fc83e2017-04-05 08:11:14 -070071/**
72 * hop types
73 */
74#define foreach_bfd_hop(F) \
75 F (SINGLE, "single") \
76 F (MULTI, "multi") \
77
78typedef enum
79{
80#define F(sym, str) BFD_HOP_TYPE_##sym,
81 foreach_bfd_hop (F)
82#undef F
83} bfd_hop_type_e;
84
Klement Sekera2bce0332017-02-09 06:03:46 +010085typedef struct bfd_session_s
Klement Sekerab17dd962017-01-09 07:43:48 +010086{
Klement Sekerab16bfe32017-02-28 11:56:48 +010087 /** index in bfd_main.sessions pool */
Klement Sekera637b9c42016-12-08 05:19:14 +010088 u32 bs_idx;
Klement Sekera0e3c0de2016-09-29 14:43:44 +020089
Klement Sekerab16bfe32017-02-28 11:56:48 +010090 /** session state */
Klement Sekera0e3c0de2016-09-29 14:43:44 +020091 bfd_state_e local_state;
92
Klement Sekerab16bfe32017-02-28 11:56:48 +010093 /** remote session state */
Klement Sekera73884482017-02-23 09:26:30 +010094 bfd_state_e remote_state;
95
Neale Ranns88fc83e2017-04-05 08:11:14 -070096 /** BFD hop type */
97 bfd_hop_type_e hop_type;
98
Klement Sekerab16bfe32017-02-28 11:56:48 +010099 /** local diagnostics */
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200100 bfd_diag_code_e local_diag;
101
Klement Sekerab16bfe32017-02-28 11:56:48 +0100102 /** remote diagnostics */
Klement Sekera73884482017-02-23 09:26:30 +0100103 bfd_diag_code_e remote_diag;
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200104
Klement Sekerab16bfe32017-02-28 11:56:48 +0100105 /** local discriminator */
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200106 u32 local_discr;
107
Klement Sekerab16bfe32017-02-28 11:56:48 +0100108 /** remote discriminator */
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200109 u32 remote_discr;
110
Klement Sekerab16bfe32017-02-28 11:56:48 +0100111 /** configured desired min tx interval (microseconds) */
Klement Sekeraa57a9702017-02-02 06:58:07 +0100112 u32 config_desired_min_tx_usec;
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200113
Klement Sekeraa3167442020-02-10 11:49:52 +0000114 /** configured desired min tx interval (nsec) */
115 u64 config_desired_min_tx_nsec;
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200116
Klement Sekeraa3167442020-02-10 11:49:52 +0000117 /** effective desired min tx interval (nsec) */
118 u64 effective_desired_min_tx_nsec;
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200119
Klement Sekerab16bfe32017-02-28 11:56:48 +0100120 /** configured required min rx interval (microseconds) */
Klement Sekeraa57a9702017-02-02 06:58:07 +0100121 u32 config_required_min_rx_usec;
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200122
Klement Sekeraa3167442020-02-10 11:49:52 +0000123 /** configured required min rx interval (nsec) */
124 u64 config_required_min_rx_nsec;
Klement Sekeraa57a9702017-02-02 06:58:07 +0100125
Klement Sekeraa3167442020-02-10 11:49:52 +0000126 /** effective required min rx interval (nsec) */
127 u64 effective_required_min_rx_nsec;
Klement Sekera3e0a3562016-12-19 09:05:21 +0100128
Klement Sekerab16bfe32017-02-28 11:56:48 +0100129 /** remote min rx interval (microseconds) */
Klement Sekeraa57a9702017-02-02 06:58:07 +0100130 u64 remote_min_rx_usec;
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200131
Klement Sekeraa3167442020-02-10 11:49:52 +0000132 /** remote min rx interval (nsec) */
133 u64 remote_min_rx_nsec;
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200134
Klement Sekerab16bfe32017-02-28 11:56:48 +0100135 /** remote min echo rx interval (microseconds) */
Klement Sekera239790f2017-02-16 10:53:53 +0100136 u64 remote_min_echo_rx_usec;
137
Klement Sekeraa3167442020-02-10 11:49:52 +0000138 /** remote min echo rx interval (nsec) */
139 u64 remote_min_echo_rx_nsec;
Klement Sekera239790f2017-02-16 10:53:53 +0100140
Klement Sekeraa3167442020-02-10 11:49:52 +0000141 /** remote desired min tx interval (nsec) */
142 u64 remote_desired_min_tx_nsec;
Klement Sekeraa57a9702017-02-02 06:58:07 +0100143
Klement Sekerab16bfe32017-02-28 11:56:48 +0100144 /** configured detect multiplier */
Klement Sekeraa57a9702017-02-02 06:58:07 +0100145 u8 local_detect_mult;
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200146
Klement Sekerab16bfe32017-02-28 11:56:48 +0100147 /** 1 if remote system sets demand mode, 0 otherwise */
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200148 u8 remote_demand;
149
Klement Sekerab16bfe32017-02-28 11:56:48 +0100150 /** remote detect multiplier */
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200151 u8 remote_detect_mult;
152
Klement Sekerab16bfe32017-02-28 11:56:48 +0100153 /** 1 is echo function is active, 0 otherwise */
Klement Sekera239790f2017-02-16 10:53:53 +0100154 u8 echo;
155
Klement Sekeraa3167442020-02-10 11:49:52 +0000156 /** next event time in nsec for this session (0 if no event) */
157 u64 event_time_nsec;
158
159 /** timing wheel internal id used to manipulate timer (if set) */
160 u32 tw_id;
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200161
Klement Sekerab16bfe32017-02-28 11:56:48 +0100162 /** transmit interval */
Klement Sekeraa3167442020-02-10 11:49:52 +0000163 u64 transmit_interval_nsec;
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200164
Klement Sekerab16bfe32017-02-28 11:56:48 +0100165 /** next time at which to transmit a packet */
Klement Sekeraa3167442020-02-10 11:49:52 +0000166 u64 tx_timeout_nsec;
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200167
Klement Sekerab16bfe32017-02-28 11:56:48 +0100168 /** timestamp of last packet transmitted */
Klement Sekeraa3167442020-02-10 11:49:52 +0000169 u64 last_tx_nsec;
Klement Sekera3e0a3562016-12-19 09:05:21 +0100170
Klement Sekerab16bfe32017-02-28 11:56:48 +0100171 /** timestamp of last packet received */
Klement Sekeraa3167442020-02-10 11:49:52 +0000172 u64 last_rx_nsec;
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200173
Klement Sekerab16bfe32017-02-28 11:56:48 +0100174 /** transmit interval for echo packets */
Klement Sekeraa3167442020-02-10 11:49:52 +0000175 u64 echo_transmit_interval_nsec;
Klement Sekera239790f2017-02-16 10:53:53 +0100176
Klement Sekerab16bfe32017-02-28 11:56:48 +0100177 /** next time at which to transmit echo packet */
Klement Sekeraa3167442020-02-10 11:49:52 +0000178 u64 echo_tx_timeout_nsec;
Klement Sekera239790f2017-02-16 10:53:53 +0100179
Klement Sekerab16bfe32017-02-28 11:56:48 +0100180 /** timestamp of last echo packet transmitted */
Klement Sekeraa3167442020-02-10 11:49:52 +0000181 u64 echo_last_tx_nsec;
Klement Sekera239790f2017-02-16 10:53:53 +0100182
Klement Sekerab16bfe32017-02-28 11:56:48 +0100183 /** timestamp of last echo packet received */
Klement Sekeraa3167442020-02-10 11:49:52 +0000184 u64 echo_last_rx_nsec;
Klement Sekera239790f2017-02-16 10:53:53 +0100185
Klement Sekerab16bfe32017-02-28 11:56:48 +0100186 /** secret used for calculating/checking checksum of echo packets */
Klement Sekera239790f2017-02-16 10:53:53 +0100187 u32 echo_secret;
188
Klement Sekerab16bfe32017-02-28 11:56:48 +0100189 /** detection time */
Klement Sekeraa3167442020-02-10 11:49:52 +0000190 u64 detection_time_nsec;
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200191
Klement Sekerab16bfe32017-02-28 11:56:48 +0100192 /** state info regarding poll sequence */
Klement Sekeraa57a9702017-02-02 06:58:07 +0100193 bfd_poll_state_e poll_state;
194
Klement Sekerab16bfe32017-02-28 11:56:48 +0100195 /**
Klement Sekera239790f2017-02-16 10:53:53 +0100196 * helper for delayed poll sequence - marks either start of running poll
197 * sequence or timeout, after which we can start the next poll sequnce
198 */
Klement Sekeraa3167442020-02-10 11:49:52 +0000199 u64 poll_state_start_or_timeout_nsec;
Klement Sekera239790f2017-02-16 10:53:53 +0100200
Klement Sekerab16bfe32017-02-28 11:56:48 +0100201 /** authentication information */
Klement Sekerab17dd962017-01-09 07:43:48 +0100202 struct
203 {
Klement Sekerab16bfe32017-02-28 11:56:48 +0100204 /** current key in use */
Klement Sekerab17dd962017-01-09 07:43:48 +0100205 bfd_auth_key_t *curr_key;
206
Klement Sekerab16bfe32017-02-28 11:56:48 +0100207 /**
Klement Sekerab17dd962017-01-09 07:43:48 +0100208 * set to next key to use if delayed switch is enabled - in that case
209 * the key is switched when first incoming packet is signed with next_key
210 */
211 bfd_auth_key_t *next_key;
212
Klement Sekerab16bfe32017-02-28 11:56:48 +0100213 /** sequence number incremented occasionally or always (if meticulous) */
Klement Sekerab17dd962017-01-09 07:43:48 +0100214 u32 local_seq_number;
215
Klement Sekerab16bfe32017-02-28 11:56:48 +0100216 /** remote sequence number */
Klement Sekerab17dd962017-01-09 07:43:48 +0100217 u32 remote_seq_number;
218
Klement Sekerab16bfe32017-02-28 11:56:48 +0100219 /** set to 1 if remote sequence number is known */
Klement Sekerab17dd962017-01-09 07:43:48 +0100220 u8 remote_seq_number_known;
221
Klement Sekerab16bfe32017-02-28 11:56:48 +0100222 /** current key ID sent out in bfd packet */
Klement Sekerab17dd962017-01-09 07:43:48 +0100223 u8 curr_bfd_key_id;
224
Klement Sekerab16bfe32017-02-28 11:56:48 +0100225 /** key ID to use when switched to next_key */
Klement Sekerab17dd962017-01-09 07:43:48 +0100226 u8 next_bfd_key_id;
227
Klement Sekerab16bfe32017-02-28 11:56:48 +0100228 /**
Klement Sekerab17dd962017-01-09 07:43:48 +0100229 * set to 1 if delayed action is pending, which might be activation
230 * of authentication, change of key or deactivation
231 */
232 u8 is_delayed;
233 } auth;
234
Klement Sekerab16bfe32017-02-28 11:56:48 +0100235 /** transport type for this session */
Klement Sekera239790f2017-02-16 10:53:53 +0100236 bfd_transport_e transport;
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200237
Klement Sekerab16bfe32017-02-28 11:56:48 +0100238 /** union of transport-specific data */
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200239 union
240 {
241 bfd_udp_session_t udp;
242 };
243} bfd_session_t;
244
Neale Ranns88fc83e2017-04-05 08:11:14 -0700245/**
246 * listener events
247 */
248#define foreach_bfd_listen_event(F) \
249 F (CREATE, "sesion-created") \
250 F (UPDATE, "session-updated") \
251 F (DELETE, "session-deleted")
252
253typedef enum
254{
255#define F(sym, str) BFD_LISTEN_EVENT_##sym,
256 foreach_bfd_listen_event (F)
257#undef F
258} bfd_listen_event_e;
259
260/**
261 * session nitification call back function type
262 */
263typedef void (*bfd_notify_fn_t) (bfd_listen_event_e, const bfd_session_t *);
264
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200265typedef struct
266{
Dave Barach1e3417f2018-07-25 08:30:27 -0400267 /** lock to protect data structures */
268 clib_spinlock_t lock;
269 int lock_recursion_count;
270 uword owner_thread_index;
271
272 /** Number of event wakeup RPCs in flight. Should be 0 or 1 */
273 int bfd_process_wakeup_events_in_flight;
274
275 /** The timestamp of last wakeup event being sent */
Klement Sekeraa3167442020-02-10 11:49:52 +0000276 u64 bfd_process_wakeup_event_start_nsec;
Dave Barach1e3417f2018-07-25 08:30:27 -0400277
278 /** The time it took the last wakeup event to make it to handling */
Klement Sekeraa3167442020-02-10 11:49:52 +0000279 u64 bfd_process_wakeup_event_delay_nsec;
Dave Barach1e3417f2018-07-25 08:30:27 -0400280
281 /** When the bfd process is supposed to wake up next */
Klement Sekeraa3167442020-02-10 11:49:52 +0000282 u64 bfd_process_next_wakeup_nsec;
Dave Barach1e3417f2018-07-25 08:30:27 -0400283
Klement Sekerab16bfe32017-02-28 11:56:48 +0100284 /** pool of bfd sessions context data */
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200285 bfd_session_t *sessions;
286
Klement Sekerab16bfe32017-02-28 11:56:48 +0100287 /** timing wheel for scheduling timeouts */
Klement Sekeraa3167442020-02-10 11:49:52 +0000288 TWT (tw_timer_wheel) wheel;
Klement Sekera637b9c42016-12-08 05:19:14 +0100289
Klement Sekerab16bfe32017-02-28 11:56:48 +0100290 /** hashmap - bfd session by discriminator */
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200291 u32 *session_by_disc;
292
Klement Sekerab16bfe32017-02-28 11:56:48 +0100293 /** background process node index */
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200294 u32 bfd_process_node_index;
295
Klement Sekerab16bfe32017-02-28 11:56:48 +0100296 /** convenience variables */
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200297 vlib_main_t *vlib_main;
298 vnet_main_t *vnet_main;
299
Klement Sekeraa3167442020-02-10 11:49:52 +0000300 /** how many nanoseconds is one timing wheel tick */
301 u64 nsec_per_tw_tick;
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200302
Klement Sekeraa3167442020-02-10 11:49:52 +0000303 /** default desired min tx in nsec */
304 u64 default_desired_min_tx_nsec;
Klement Sekeraa57a9702017-02-02 06:58:07 +0100305
Klement Sekeraa3167442020-02-10 11:49:52 +0000306 /** minimum required min rx while echo function is active - nsec */
307 u64 min_required_min_rx_while_echo_nsec;
Klement Sekera239790f2017-02-16 10:53:53 +0100308
Klement Sekerab16bfe32017-02-28 11:56:48 +0100309 /** for generating random numbers */
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200310 u32 random_seed;
311
Klement Sekerab16bfe32017-02-28 11:56:48 +0100312 /** pool of authentication keys */
Klement Sekerab17dd962017-01-09 07:43:48 +0100313 bfd_auth_key_t *auth_keys;
314
Klement Sekerab16bfe32017-02-28 11:56:48 +0100315 /** hashmap - index in pool auth_keys by conf_key_id */
Klement Sekerab17dd962017-01-09 07:43:48 +0100316 u32 *auth_key_by_conf_key_id;
317
Damjan Marion07a38572018-01-21 06:44:18 -0800318 /** vector of callback notification functions */
Neale Ranns88fc83e2017-04-05 08:11:14 -0700319 bfd_notify_fn_t *listeners;
Damjan Marion07a38572018-01-21 06:44:18 -0800320
321 /** log class */
322 vlib_log_class_t log_class;
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200323} bfd_main_t;
324
325extern bfd_main_t bfd_main;
326
Klement Sekerab16bfe32017-02-28 11:56:48 +0100327/** Packet counters */
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200328#define foreach_bfd_error(F) \
329 F (NONE, "good bfd packets (processed)") \
330 F (BAD, "invalid bfd packets") \
331 F (DISABLED, "bfd packets received on disabled interfaces")
332
333typedef enum
334{
335#define F(sym, str) BFD_ERROR_##sym,
336 foreach_bfd_error (F)
337#undef F
338 BFD_N_ERROR,
339} bfd_error_t;
340
Klement Sekerab16bfe32017-02-28 11:56:48 +0100341/** bfd packet trace capture */
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200342typedef struct
343{
344 u32 len;
345 u8 data[400];
346} bfd_input_trace_t;
347
Benoît Ganne47727c02019-02-12 13:35:08 +0100348typedef enum
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200349{
350 BFD_EVENT_RESCHEDULE = 1,
351 BFD_EVENT_NEW_SESSION,
Klement Sekeraa57a9702017-02-02 06:58:07 +0100352 BFD_EVENT_CONFIG_CHANGED,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200353} bfd_process_event_e;
354
Klement Sekera239790f2017-02-16 10:53:53 +0100355/* *INDENT-OFF* */
Klement Sekerab16bfe32017-02-28 11:56:48 +0100356/** echo packet structure */
Klement Sekera239790f2017-02-16 10:53:53 +0100357typedef CLIB_PACKED (struct {
Klement Sekerab16bfe32017-02-28 11:56:48 +0100358 /** local discriminator */
Klement Sekera239790f2017-02-16 10:53:53 +0100359 u32 discriminator;
Klement Sekeraa3167442020-02-10 11:49:52 +0000360 /** expire time of this packet - nsec */
361 u64 expire_time_nsec;
Klement Sekerab16bfe32017-02-28 11:56:48 +0100362 /** checksum - based on discriminator, local secret and expire time */
Klement Sekera239790f2017-02-16 10:53:53 +0100363 u64 checksum;
364}) bfd_echo_pkt_t;
365/* *INDENT-ON* */
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200366
Dave Barach1e3417f2018-07-25 08:30:27 -0400367static inline void
368bfd_lock (bfd_main_t * bm)
369{
370 uword my_thread_index = __os_thread_index;
371
372 if (bm->owner_thread_index == my_thread_index
373 && bm->lock_recursion_count > 0)
374 {
375 bm->lock_recursion_count++;
376 return;
377 }
378
379 clib_spinlock_lock_if_init (&bm->lock);
380 bm->lock_recursion_count = 1;
381 bm->owner_thread_index = my_thread_index;
382}
383
384static inline void
385bfd_unlock (bfd_main_t * bm)
386{
387 uword my_thread_index = __os_thread_index;
388 ASSERT (bm->owner_thread_index == my_thread_index);
389
390 if (bm->lock_recursion_count > 1)
391 {
392 bm->lock_recursion_count--;
393 return;
394 }
395 bm->lock_recursion_count = 0;
396 bm->owner_thread_index = ~0;
397 clib_spinlock_unlock_if_init (&bm->lock);
398}
399
Dave Barach1e3417f2018-07-25 08:30:27 -0400400static inline void
401bfd_lock_check (bfd_main_t * bm)
402{
403 if (PREDICT_FALSE (bm->lock_recursion_count < 1))
Dave Barachccf444d2018-09-14 09:27:42 -0400404 clib_warning ("lock check failure");
Dave Barach1e3417f2018-07-25 08:30:27 -0400405}
406
Klement Sekera239790f2017-02-16 10:53:53 +0100407u8 *bfd_input_format_trace (u8 * s, va_list * args);
408bfd_session_t *bfd_get_session (bfd_main_t * bm, bfd_transport_e t);
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200409void bfd_put_session (bfd_main_t * bm, bfd_session_t * bs);
410bfd_session_t *bfd_find_session_by_idx (bfd_main_t * bm, uword bs_idx);
411bfd_session_t *bfd_find_session_by_disc (bfd_main_t * bm, u32 disc);
412void bfd_session_start (bfd_main_t * bm, bfd_session_t * bs);
Klement Sekeraa3167442020-02-10 11:49:52 +0000413void bfd_consume_pkt (vlib_main_t * vm, bfd_main_t * bm,
414 const bfd_pkt_t * bfd, u32 bs_idx);
415int bfd_consume_echo_pkt (vlib_main_t * vm, bfd_main_t * bm,
416 vlib_buffer_t * b);
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200417int bfd_verify_pkt_common (const bfd_pkt_t * pkt);
Klement Sekeraa3167442020-02-10 11:49:52 +0000418int bfd_verify_pkt_auth (vlib_main_t * vm, const bfd_pkt_t * pkt,
419 u16 pkt_size, bfd_session_t * bs);
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200420void bfd_event (bfd_main_t * bm, bfd_session_t * bs);
Klement Sekerab17dd962017-01-09 07:43:48 +0100421void bfd_init_final_control_frame (vlib_main_t * vm, vlib_buffer_t * b,
Klement Sekerae50e8562017-04-04 16:19:48 +0200422 bfd_main_t * bm, bfd_session_t * bs,
423 int is_local);
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200424u8 *format_bfd_session (u8 * s, va_list * args);
Damjan Marion07a38572018-01-21 06:44:18 -0800425u8 *format_bfd_session_brief (u8 * s, va_list * args);
Klement Sekera73884482017-02-23 09:26:30 +0100426u8 *format_bfd_auth_key (u8 * s, va_list * args);
Klement Sekeraa3167442020-02-10 11:49:52 +0000427void bfd_session_set_flags (vlib_main_t * vm, bfd_session_t * bs,
428 u8 admin_up_down);
Klement Sekerab17dd962017-01-09 07:43:48 +0100429unsigned bfd_auth_type_supported (bfd_auth_type_e auth_type);
430vnet_api_error_t bfd_auth_activate (bfd_session_t * bs, u32 conf_key_id,
431 u8 bfd_key_id, u8 is_delayed);
432vnet_api_error_t bfd_auth_deactivate (bfd_session_t * bs, u8 is_delayed);
Klement Sekera239790f2017-02-16 10:53:53 +0100433vnet_api_error_t bfd_session_set_params (bfd_main_t * bm, bfd_session_t * bs,
434 u32 desired_min_tx_usec,
435 u32 required_min_rx_usec,
436 u8 detect_mult);
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200437
Klement Sekeraa3167442020-02-10 11:49:52 +0000438u32 bfd_nsec_to_usec (u64 nsec);
Klement Sekera73884482017-02-23 09:26:30 +0100439const char *bfd_poll_state_string (bfd_poll_state_e state);
440
Klement Sekeraa3167442020-02-10 11:49:52 +0000441#define USEC_PER_MS (1000LL)
442#define MSEC_PER_SEC (1000LL)
443#define NSEC_PER_USEC (1000LL)
444#define USEC_PER_SEC (MSEC_PER_SEC * USEC_PER_MS)
445#define NSEC_PER_SEC (NSEC_PER_USEC * USEC_PER_SEC)
446#define SEC_PER_NSEC ((f64)1/NSEC_PER_SEC)
447
448/** timing wheel tick-rate, 1ms should be good enough */
449#define BFD_TW_TPS (MSEC_PER_SEC)
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200450
Klement Sekerab16bfe32017-02-28 11:56:48 +0100451/** default, slow transmission interval for BFD packets, per spec at least 1s */
Klement Sekeraa3167442020-02-10 11:49:52 +0000452#define BFD_DEFAULT_DESIRED_MIN_TX_USEC USEC_PER_SEC
Klement Sekera239790f2017-02-16 10:53:53 +0100453
Klement Sekerab16bfe32017-02-28 11:56:48 +0100454/**
Klement Sekera239790f2017-02-16 10:53:53 +0100455 * minimum required min rx set locally when echo function is used, per spec
456 * should be set to at least 1s
457 */
Klement Sekeraa3167442020-02-10 11:49:52 +0000458#define BFD_REQUIRED_MIN_RX_USEC_WHILE_ECHO USEC_PER_SEC
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200459
Neale Ranns88fc83e2017-04-05 08:11:14 -0700460/**
461 * Register a callback function to receive session notifications.
462 */
463void bfd_register_listener (bfd_notify_fn_t fn);
464
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200465#endif /* __included_bfd_main_h__ */
466
467/*
468 * fd.io coding-style-patch-verification: ON
469 *
470 * Local Variables:
471 * eval: (c-set-style "gnu")
472 * End:
473 */