Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 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 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 27 | #define foreach_bfd_mode(F) \ |
| 28 | F (asynchronous) \ |
| 29 | F (demand) |
| 30 | |
| 31 | typedef enum |
| 32 | { |
| 33 | #define F(x) BFD_MODE_##x, |
| 34 | foreach_bfd_mode (F) |
| 35 | #undef F |
| 36 | } bfd_mode_e; |
| 37 | |
| 38 | typedef struct |
| 39 | { |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 40 | /** global configuration key ID */ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 41 | u32 conf_key_id; |
| 42 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 43 | /** keeps track of how many sessions reference this key */ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 44 | u32 use_count; |
| 45 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 46 | /** |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 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 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 52 | /** authentication type for this key */ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 53 | bfd_auth_type_e auth_type; |
| 54 | } bfd_auth_key_t; |
| 55 | |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 56 | #define foreach_bfd_poll_state(F) \ |
| 57 | F (NOT_NEEDED) \ |
| 58 | F (NEEDED) \ |
| 59 | F (IN_PROGRESS) \ |
| 60 | F (IN_PROGRESS_AND_QUEUED) |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 61 | |
| 62 | typedef enum |
| 63 | { |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 64 | #define F(x) BFD_POLL_##x, |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 65 | foreach_bfd_poll_state (F) |
| 66 | #undef F |
| 67 | } bfd_poll_state_e; |
| 68 | |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 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, |
| 79 | foreach_bfd_hop (F) |
| 80 | #undef F |
| 81 | } bfd_hop_type_e; |
| 82 | |
Klement Sekera | 2bce033 | 2017-02-09 06:03:46 +0100 | [diff] [blame] | 83 | typedef struct bfd_session_s |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 84 | { |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 85 | /** index in bfd_main.sessions pool */ |
Klement Sekera | 637b9c4 | 2016-12-08 05:19:14 +0100 | [diff] [blame] | 86 | u32 bs_idx; |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 87 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 88 | /** session state */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 89 | bfd_state_e local_state; |
| 90 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 91 | /** remote session state */ |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 92 | bfd_state_e remote_state; |
| 93 | |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 94 | /** BFD hop type */ |
| 95 | bfd_hop_type_e hop_type; |
| 96 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 97 | /** local diagnostics */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 98 | bfd_diag_code_e local_diag; |
| 99 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 100 | /** remote diagnostics */ |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 101 | bfd_diag_code_e remote_diag; |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 102 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 103 | /** local discriminator */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 104 | u32 local_discr; |
| 105 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 106 | /** remote discriminator */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 107 | u32 remote_discr; |
| 108 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 109 | /** configured desired min tx interval (microseconds) */ |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 110 | u32 config_desired_min_tx_usec; |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 111 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 112 | /** configured desired min tx interval (clocks) */ |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 113 | u64 config_desired_min_tx_clocks; |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 114 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 115 | /** effective desired min tx interval (clocks) */ |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 116 | u64 effective_desired_min_tx_clocks; |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 117 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 118 | /** configured required min rx interval (microseconds) */ |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 119 | u32 config_required_min_rx_usec; |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 120 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 121 | /** configured required min rx interval (clocks) */ |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 122 | u64 config_required_min_rx_clocks; |
| 123 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 124 | /** effective required min rx interval (clocks) */ |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 125 | u64 effective_required_min_rx_clocks; |
Klement Sekera | 3e0a356 | 2016-12-19 09:05:21 +0100 | [diff] [blame] | 126 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 127 | /** remote min rx interval (microseconds) */ |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 128 | u64 remote_min_rx_usec; |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 129 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 130 | /** remote min rx interval (clocks) */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 131 | u64 remote_min_rx_clocks; |
| 132 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 133 | /** remote min echo rx interval (microseconds) */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 134 | u64 remote_min_echo_rx_usec; |
| 135 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 136 | /** remote min echo rx interval (clocks) */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 137 | u64 remote_min_echo_rx_clocks; |
| 138 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 139 | /** remote desired min tx interval (clocks) */ |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 140 | u64 remote_desired_min_tx_clocks; |
| 141 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 142 | /** configured detect multiplier */ |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 143 | u8 local_detect_mult; |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 144 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 145 | /** 1 if remote system sets demand mode, 0 otherwise */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 146 | u8 remote_demand; |
| 147 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 148 | /** remote detect multiplier */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 149 | u8 remote_detect_mult; |
| 150 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 151 | /** 1 is echo function is active, 0 otherwise */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 152 | u8 echo; |
| 153 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 154 | /** set to value of timer in timing wheel, 0 if never set */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 155 | u64 wheel_time_clocks; |
| 156 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 157 | /** transmit interval */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 158 | u64 transmit_interval_clocks; |
| 159 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 160 | /** next time at which to transmit a packet */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 161 | u64 tx_timeout_clocks; |
| 162 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 163 | /** timestamp of last packet transmitted */ |
Klement Sekera | 3e0a356 | 2016-12-19 09:05:21 +0100 | [diff] [blame] | 164 | u64 last_tx_clocks; |
| 165 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 166 | /** timestamp of last packet received */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 167 | u64 last_rx_clocks; |
| 168 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 169 | /** transmit interval for echo packets */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 170 | u64 echo_transmit_interval_clocks; |
| 171 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 172 | /** next time at which to transmit echo packet */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 173 | u64 echo_tx_timeout_clocks; |
| 174 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 175 | /** timestamp of last echo packet transmitted */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 176 | u64 echo_last_tx_clocks; |
| 177 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 178 | /** timestamp of last echo packet received */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 179 | u64 echo_last_rx_clocks; |
| 180 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 181 | /** secret used for calculating/checking checksum of echo packets */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 182 | u32 echo_secret; |
| 183 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 184 | /** detection time */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 185 | u64 detection_time_clocks; |
| 186 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 187 | /** state info regarding poll sequence */ |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 188 | bfd_poll_state_e poll_state; |
| 189 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 190 | /** |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 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 | */ |
| 194 | u64 poll_state_start_or_timeout_clocks; |
| 195 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 196 | /** authentication information */ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 197 | struct |
| 198 | { |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 199 | /** current key in use */ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 200 | bfd_auth_key_t *curr_key; |
| 201 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 202 | /** |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 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 | */ |
| 206 | bfd_auth_key_t *next_key; |
| 207 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 208 | /** sequence number incremented occasionally or always (if meticulous) */ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 209 | u32 local_seq_number; |
| 210 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 211 | /** remote sequence number */ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 212 | u32 remote_seq_number; |
| 213 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 214 | /** set to 1 if remote sequence number is known */ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 215 | u8 remote_seq_number_known; |
| 216 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 217 | /** current key ID sent out in bfd packet */ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 218 | u8 curr_bfd_key_id; |
| 219 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 220 | /** key ID to use when switched to next_key */ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 221 | u8 next_bfd_key_id; |
| 222 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 223 | /** |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 224 | * set to 1 if delayed action is pending, which might be activation |
| 225 | * of authentication, change of key or deactivation |
| 226 | */ |
| 227 | u8 is_delayed; |
| 228 | } auth; |
| 229 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 230 | /** transport type for this session */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 231 | bfd_transport_e transport; |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 232 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 233 | /** union of transport-specific data */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 234 | union |
| 235 | { |
| 236 | bfd_udp_session_t udp; |
| 237 | }; |
| 238 | } bfd_session_t; |
| 239 | |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 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, |
| 251 | foreach_bfd_listen_event (F) |
| 252 | #undef F |
| 253 | } bfd_listen_event_e; |
| 254 | |
| 255 | /** |
| 256 | * session nitification call back function type |
| 257 | */ |
| 258 | typedef void (*bfd_notify_fn_t) (bfd_listen_event_e, const bfd_session_t *); |
| 259 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 260 | typedef struct |
| 261 | { |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 262 | /** pool of bfd sessions context data */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 263 | bfd_session_t *sessions; |
| 264 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 265 | /** timing wheel for scheduling timeouts */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 266 | timing_wheel_t wheel; |
| 267 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 268 | /** timing wheel inaccuracy, in clocks */ |
Klement Sekera | 637b9c4 | 2016-12-08 05:19:14 +0100 | [diff] [blame] | 269 | u64 wheel_inaccuracy; |
| 270 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 271 | /** hashmap - bfd session by discriminator */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 272 | u32 *session_by_disc; |
| 273 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 274 | /** background process node index */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 275 | u32 bfd_process_node_index; |
| 276 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 277 | /** convenience variables */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 278 | vlib_main_t *vlib_main; |
| 279 | vnet_main_t *vnet_main; |
| 280 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 281 | /** cpu clocks per second */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 282 | f64 cpu_cps; |
| 283 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 284 | /** default desired min tx in clocks */ |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 285 | u64 default_desired_min_tx_clocks; |
| 286 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 287 | /** minimum required min rx while echo function is active - clocks */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 288 | u64 min_required_min_rx_while_echo_clocks; |
| 289 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 290 | /** for generating random numbers */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 291 | u32 random_seed; |
| 292 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 293 | /** pool of authentication keys */ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 294 | bfd_auth_key_t *auth_keys; |
| 295 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 296 | /** hashmap - index in pool auth_keys by conf_key_id */ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 297 | u32 *auth_key_by_conf_key_id; |
| 298 | |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 299 | /** A vector of callback notification functions */ |
| 300 | bfd_notify_fn_t *listeners; |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 301 | } bfd_main_t; |
| 302 | |
| 303 | extern bfd_main_t bfd_main; |
| 304 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 305 | /** Packet counters */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 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, |
| 314 | foreach_bfd_error (F) |
| 315 | #undef F |
| 316 | BFD_N_ERROR, |
| 317 | } bfd_error_t; |
| 318 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 319 | /** bfd packet trace capture */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 320 | typedef struct |
| 321 | { |
| 322 | u32 len; |
| 323 | u8 data[400]; |
| 324 | } bfd_input_trace_t; |
| 325 | |
| 326 | enum |
| 327 | { |
| 328 | BFD_EVENT_RESCHEDULE = 1, |
| 329 | BFD_EVENT_NEW_SESSION, |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 330 | BFD_EVENT_CONFIG_CHANGED, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 331 | } bfd_process_event_e; |
| 332 | |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 333 | /* *INDENT-OFF* */ |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 334 | /** echo packet structure */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 335 | typedef CLIB_PACKED (struct { |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 336 | /** local discriminator */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 337 | u32 discriminator; |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 338 | /** expire time of this packet - clocks */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 339 | u64 expire_time_clocks; |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 340 | /** checksum - based on discriminator, local secret and expire time */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 341 | u64 checksum; |
| 342 | }) bfd_echo_pkt_t; |
| 343 | /* *INDENT-ON* */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 344 | |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 345 | u8 *bfd_input_format_trace (u8 * s, va_list * args); |
| 346 | bfd_session_t *bfd_get_session (bfd_main_t * bm, bfd_transport_e t); |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 347 | void bfd_put_session (bfd_main_t * bm, bfd_session_t * bs); |
| 348 | bfd_session_t *bfd_find_session_by_idx (bfd_main_t * bm, uword bs_idx); |
| 349 | bfd_session_t *bfd_find_session_by_disc (bfd_main_t * bm, u32 disc); |
| 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); |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 352 | int bfd_consume_echo_pkt (bfd_main_t * bm, vlib_buffer_t * b); |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 353 | int bfd_verify_pkt_common (const bfd_pkt_t * pkt); |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 354 | int bfd_verify_pkt_auth (const bfd_pkt_t * pkt, u16 pkt_size, |
| 355 | bfd_session_t * bs); |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 356 | void bfd_event (bfd_main_t * bm, bfd_session_t * bs); |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 357 | void bfd_init_final_control_frame (vlib_main_t * vm, vlib_buffer_t * b, |
Klement Sekera | e50e856 | 2017-04-04 16:19:48 +0200 | [diff] [blame] | 358 | bfd_main_t * bm, bfd_session_t * bs, |
| 359 | int is_local); |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 360 | u8 *format_bfd_session (u8 * s, va_list * args); |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 361 | u8 *format_bfd_auth_key (u8 * s, va_list * args); |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 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); |
| 364 | vnet_api_error_t bfd_auth_activate (bfd_session_t * bs, u32 conf_key_id, |
| 365 | u8 bfd_key_id, u8 is_delayed); |
| 366 | vnet_api_error_t bfd_auth_deactivate (bfd_session_t * bs, u8 is_delayed); |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 367 | vnet_api_error_t bfd_session_set_params (bfd_main_t * bm, bfd_session_t * bs, |
| 368 | u32 desired_min_tx_usec, |
| 369 | u32 required_min_rx_usec, |
| 370 | u8 detect_mult); |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 371 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 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 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 375 | #define USEC_PER_MS 1000LL |
| 376 | #define USEC_PER_SECOND (1000 * USEC_PER_MS) |
| 377 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 378 | /** default, slow transmission interval for BFD packets, per spec at least 1s */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 379 | #define BFD_DEFAULT_DESIRED_MIN_TX_USEC USEC_PER_SECOND |
| 380 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 381 | /** |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 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 |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 386 | |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 387 | /** |
| 388 | * Register a callback function to receive session notifications. |
| 389 | */ |
| 390 | void bfd_register_listener (bfd_notify_fn_t fn); |
| 391 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 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 | */ |