FD.io VPP  v17.01.1-3-gc6833f8
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_transport(F) \
28  F (UDP4, "ip4-rewrite") \
29  F (UDP6, "ip6-rewrite")
30 
31 typedef enum
32 {
33 #define F(t, n) BFD_TRANSPORT_##t,
35 #undef F
37 
38 #define foreach_bfd_mode(F) \
39  F (asynchronous) \
40  F (demand)
41 
42 typedef enum
43 {
44 #define F(x) BFD_MODE_##x,
46 #undef F
47 } bfd_mode_e;
48 
49 typedef struct
50 {
51  /* index in bfd_main.sessions pool */
53 
54  /* session state */
56 
57  /* local diagnostics */
59 
60  /* remote session state */
62 
63  /* local discriminator */
65 
66  /* remote discriminator */
68 
69  /* configured desired min tx interval (microseconds) */
71 
72  /* desired min tx interval (microseconds) */
74 
75  /* desired min tx interval (clocks) */
77 
78  /* required min rx interval */
80 
81  /* remote min rx interval (microseconds) */
83 
84  /* remote min rx interval (clocks) */
86 
87  /* remote desired min tx interval */
89 
90  /* 1 if in demand mode, 0 otherwise */
92 
93  /* 1 if remote system sets demand mode, 0 otherwise */
95 
96  /* local detect multiplier */
98 
99  /* remote detect multiplier */
101 
102  /* set to value of timer in timing wheel, 0 if never set */
104 
105  /* transmit interval */
107 
108  /* next time at which to transmit a packet */
110 
111  /* timestamp of last packet received */
113 
114  /* detection time */
116 
117  /* transport type for this session */
118  bfd_transport_t transport;
119 
120  union
121  {
123  };
124 } bfd_session_t;
125 
126 typedef struct
127 {
131 
132 typedef struct
133 {
134  /* pool of bfd sessions context data */
136 
137  /* timing wheel for scheduling timeouts */
139 
140  /* timing wheel inaccuracy, in clocks */
142 
143  /* hashmap - bfd session by discriminator */
145 
146  /* background process node index */
148 
149  /* convenience variables */
152 
153  /* cpu clocks per second */
155 
156  /* for generating random numbers */
158 
159 } bfd_main_t;
160 
161 extern bfd_main_t bfd_main;
162 
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")
168 
169 typedef enum
170 {
171 #define F(sym, str) BFD_ERROR_##sym,
173 #undef F
174  BFD_N_ERROR,
175 } bfd_error_t;
176 
177 /* bfd packet trace capture */
178 typedef struct
179 {
181  u8 data[400];
183 
184 enum
185 {
189 
190 u8 *bfd_input_format_trace (u8 * s, va_list * args);
191 
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);
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);
203 u8 *format_bfd_session (u8 * s, va_list * args);
204 
205 
206 #define USEC_PER_MS 1000LL
207 #define USEC_PER_SECOND (1000 * USEC_PER_MS)
208 
209 /* default, slow transmission interval for BFD packets, per spec at least 1s */
210 #define BFD_DEFAULT_DESIRED_MIN_TX_US USEC_PER_SECOND
211 
212 #endif /* __included_bfd_main_h__ */
213 
214 /*
215  * fd.io coding-style-patch-verification: ON
216  *
217  * Local Variables:
218  * eval: (c-set-style "gnu")
219  * End:
220  */
bfd_main_t bfd_main
Definition: bfd_main.c:961
u8 remote_demand
Definition: bfd_main.h:94
enum @33 bfd_process_event_e
bfd_session_t * bfd_find_session_by_idx(bfd_main_t *bm, uword bs_idx)
Definition: bfd_main.c:764
u8 local_demand
Definition: bfd_main.h:91
int bfd_verify_pkt_common(const bfd_pkt_t *pkt)
verify bfd packet - common checks
Definition: bfd_main.c:792
u32 config_desired_min_tx_us
Definition: bfd_main.h:70
bfd_diag_code_e
Definition: bfd_protocol.h:119
u32 bfd_process_node_index
Definition: bfd_main.h:147
void bfd_put_session(bfd_main_t *bm, bfd_session_t *bs)
Definition: bfd_main.c:757
u32 remote_desired_min_tx_us
Definition: bfd_main.h:88
#define foreach_bfd_mode(F)
Definition: bfd_main.h:38
u8 * bfd_input_format_trace(u8 *s, va_list *args)
Definition: bfd_main.c:354
u64 last_rx_clocks
Definition: bfd_main.h:112
#define foreach_bfd_transport(F)
Definition: bfd_main.h:27
bfd_error_t
Definition: bfd_main.h:169
u64 tx_timeout_clocks
Definition: bfd_main.h:109
timing_wheel_t wheel
Definition: bfd_main.h:138
u32 local_discr
Definition: bfd_main.h:64
bfd_transport_t transport
Definition: bfd_main.h:118
bfd_mode_e
Definition: bfd_main.h:42
u32 random_seed
Definition: bfd_main.h:157
u64 transmit_interval_clocks
Definition: bfd_main.h:106
#define foreach_bfd_error(F)
Definition: bfd_main.h:164
void bfd_consume_pkt(bfd_main_t *bm, const bfd_pkt_t *bfd, u32 bs_idx)
Definition: bfd_main.c:875
unsigned long u64
Definition: types.h:89
void bfd_event(bfd_main_t *bm, bfd_session_t *bs)
Definition: api.c:6889
bfd_session_t * sessions
Definition: bfd_main.h:135
bfd_state_e remote_state
Definition: bfd_main.h:61
f64 cpu_cps
Definition: bfd_main.h:154
void bfd_send_final(vlib_main_t *vm, vlib_buffer_t *b, bfd_session_t *bs)
Definition: bfd_main.c:534
u8 * format_bfd_session(u8 *s, va_list *args)
Definition: bfd_main.c:939
u8 remote_detect_mult
Definition: bfd_main.h:100
vnet_main_t * vnet_main
Definition: bfd_main.h:151
u64 wheel_time_clocks
Definition: bfd_main.h:103
u32 remote_discr
Definition: bfd_main.h:67
BFD protocol declarations.
bfd_state_e
Definition: bfd_protocol.h:137
u32 remote_min_rx_us
Definition: bfd_main.h:82
void bfd_session_start(bfd_main_t *bm, bfd_session_t *bs)
Definition: bfd_main.c:279
unsigned int u32
Definition: types.h:88
#define F(t, n)
Definition: bfd_main.h:171
bfd_state_e local_state
Definition: bfd_main.h:55
u32 desired_min_tx_us
Definition: bfd_main.h:73
bfd_transport_t
Definition: bfd_main.h:31
u64 desired_min_tx_clocks
Definition: bfd_main.h:76
vlib_main_t * vlib_main
Definition: bfd_main.h:150
u32 * session_by_disc
Definition: bfd_main.h:144
u64 uword
Definition: types.h:112
u32 required_min_rx_us
Definition: bfd_main.h:79
BFD global declarations.
unsigned short u16
Definition: types.h:57
bfd_diag_code_e local_diag
Definition: bfd_main.h:58
double f64
Definition: types.h:142
unsigned char u8
Definition: types.h:56
int bfd_verify_pkt_session(const bfd_pkt_t *pkt, u16 pkt_size, const bfd_session_t *bs)
verify bfd packet - authentication
Definition: bfd_main.c:848
u64 detection_time_clocks
Definition: bfd_main.h:115
u64 remote_min_rx_clocks
Definition: bfd_main.h:85
bfd_session_t * bfd_find_session_by_disc(bfd_main_t *bm, u32 disc)
Definition: bfd_main.c:774
u8 local_detect_mult
Definition: bfd_main.h:97
bfd_udp_session_t udp
Definition: bfd_main.h:122
bfd_session_t * bfd_get_session(bfd_main_t *bm, bfd_transport_t t)
Definition: bfd_main.c:743
u64 wheel_inaccuracy
Definition: bfd_main.h:141