Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * l2_fib.h : layer 2 forwarding table (aka mac table) |
| 3 | * |
| 4 | * Copyright (c) 2013 Cisco and/or its affiliates. |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #ifndef included_l2fib_h |
| 19 | #define included_l2fib_h |
| 20 | |
| 21 | #include <vlib/vlib.h> |
| 22 | #include <vppinfra/bihash_8_8.h> |
| 23 | |
| 24 | /* |
| 25 | * The size of the hash table |
| 26 | */ |
| 27 | #define L2FIB_NUM_BUCKETS (64 * 1024) |
John Lo | dbfa574 | 2017-09-02 08:27:36 -0400 | [diff] [blame] | 28 | #define L2FIB_MEMORY_SIZE (512<<20) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 29 | |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 30 | /* Ager scan interval is 1 minute for aging */ |
| 31 | #define L2FIB_AGE_SCAN_INTERVAL (60.0) |
| 32 | |
| 33 | /* MAC event scan delay is 100 msec unless specified by MAC event client */ |
| 34 | #define L2FIB_EVENT_SCAN_DELAY_DEFAULT (0.1) |
| 35 | |
| 36 | /* Max MACs in a event message is 100 unless specified by MAC event client */ |
| 37 | #define L2FIB_EVENT_MAX_MACS_DEFAULT (100) |
| 38 | |
| 39 | /* MAC event learn limit is 1000 unless specified by MAC event client */ |
| 40 | #define L2FIB_EVENT_LEARN_LIMIT_DEFAULT (1000) |
| 41 | |
Eyal Bari | 0f360dc | 2017-06-14 13:11:20 +0300 | [diff] [blame] | 42 | typedef struct |
| 43 | { |
| 44 | |
| 45 | /* hash table */ |
| 46 | BVT (clib_bihash) mac_table; |
| 47 | |
| 48 | /* per swif vector of sequence number for interface based flush of MACs */ |
| 49 | u8 *swif_seq_num; |
| 50 | |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 51 | /* last event or ager scan duration */ |
| 52 | f64 evt_scan_duration; |
| 53 | f64 age_scan_duration; |
| 54 | |
| 55 | /* delay between event scans, default to 100 msec */ |
| 56 | f64 event_scan_delay; |
| 57 | |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 58 | /* max macs in event message, default to 100 entries */ |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 59 | u32 max_macs_in_event; |
| 60 | |
Eyal Bari | 0f360dc | 2017-06-14 13:11:20 +0300 | [diff] [blame] | 61 | /* convenience variables */ |
| 62 | vlib_main_t *vlib_main; |
| 63 | vnet_main_t *vnet_main; |
| 64 | } l2fib_main_t; |
| 65 | |
| 66 | extern l2fib_main_t l2fib_main; |
| 67 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 68 | /* |
| 69 | * The L2fib key is the mac address and bridge domain ID |
| 70 | */ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 71 | typedef struct |
| 72 | { |
| 73 | union |
| 74 | { |
| 75 | struct |
| 76 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 77 | u16 bd_index; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 78 | u8 mac[6]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 79 | } fields; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 80 | struct |
| 81 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 82 | u32 w0; |
| 83 | u32 w1; |
| 84 | } words; |
| 85 | u64 raw; |
| 86 | }; |
| 87 | } l2fib_entry_key_t; |
| 88 | |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 89 | STATIC_ASSERT_SIZEOF (l2fib_entry_key_t, 8); |
| 90 | |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 91 | |
| 92 | typedef struct |
| 93 | { |
| 94 | union |
| 95 | { |
| 96 | struct |
| 97 | { |
| 98 | u8 swif; |
| 99 | u8 bd; |
| 100 | }; |
| 101 | u16 as_u16; |
| 102 | }; |
| 103 | } l2fib_seq_num_t; |
| 104 | |
Neale Ranns | b54d081 | 2018-09-06 06:22:56 -0700 | [diff] [blame] | 105 | /** |
| 106 | * Flags associated with an L2 Fib Entry |
| 107 | * - static mac, no MAC move |
| 108 | * - not subject to age |
| 109 | * - mac is for a bridged virtual interface |
| 110 | * - drop packets to/from this mac |
| 111 | * - MAC learned to be sent in L2 MAC event |
| 112 | * -MAC learned is a MAC move |
| 113 | */ |
| 114 | #define foreach_l2fib_entry_result_attr \ |
| 115 | _(STATIC, 0, "static") \ |
| 116 | _(AGE_NOT, 1, "age-not") \ |
| 117 | _(BVI, 2, "bvi") \ |
| 118 | _(FILTER, 3, "filter") \ |
| 119 | _(LRN_EVT, 4, "learn-event") \ |
| 120 | _(LRN_MOV, 5, "learn-move") |
| 121 | |
| 122 | typedef enum l2fib_entry_result_flags_t_ |
| 123 | { |
| 124 | L2FIB_ENTRY_RESULT_FLAG_NONE = 0, |
| 125 | #define _(a,v,s) L2FIB_ENTRY_RESULT_FLAG_##a = (1 << v), |
| 126 | foreach_l2fib_entry_result_attr |
| 127 | #undef _ |
| 128 | } __attribute__ ((packed)) l2fib_entry_result_flags_t; |
| 129 | |
| 130 | STATIC_ASSERT_SIZEOF (l2fib_entry_result_flags_t, 1); |
| 131 | |
Neale Ranns | 7d645f7 | 2018-10-24 02:25:06 -0700 | [diff] [blame] | 132 | extern u8 *format_l2fib_entry_result_flags (u8 * s, va_list * args); |
| 133 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 134 | /* |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 135 | * The l2fib entry results |
| 136 | */ |
Neale Ranns | b54d081 | 2018-09-06 06:22:56 -0700 | [diff] [blame] | 137 | typedef struct l2fib_entry_result_t_ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 138 | { |
| 139 | union |
| 140 | { |
| 141 | struct |
| 142 | { |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 143 | u32 sw_if_index; /* output sw_if_index (L3 intf if bvi==1) */ |
Neale Ranns | b54d081 | 2018-09-06 06:22:56 -0700 | [diff] [blame] | 144 | l2fib_entry_result_flags_t flags; |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 145 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 146 | u8 timestamp; /* timestamp for aging */ |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 147 | l2fib_seq_num_t sn; /* bd/int seq num */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 148 | } fields; |
| 149 | u64 raw; |
| 150 | }; |
| 151 | } l2fib_entry_result_t; |
| 152 | |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 153 | STATIC_ASSERT_SIZEOF (l2fib_entry_result_t, 8); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 154 | |
Neale Ranns | b54d081 | 2018-09-06 06:22:56 -0700 | [diff] [blame] | 155 | #define _(a,v,s) \ |
| 156 | always_inline int \ |
| 157 | l2fib_entry_result_is_set_##a (const l2fib_entry_result_t *r) { \ |
| 158 | return (r->fields.flags & L2FIB_ENTRY_RESULT_FLAG_##a); \ |
| 159 | } |
| 160 | foreach_l2fib_entry_result_attr |
| 161 | #undef _ |
| 162 | #define _(a,v,s) \ |
| 163 | always_inline void \ |
| 164 | l2fib_entry_result_set_##a (l2fib_entry_result_t *r) { \ |
| 165 | r->fields.flags |= L2FIB_ENTRY_RESULT_FLAG_##a; \ |
| 166 | } |
| 167 | foreach_l2fib_entry_result_attr |
| 168 | #undef _ |
| 169 | #define _(a,v,s) \ |
| 170 | always_inline void \ |
| 171 | l2fib_entry_result_clear_##a (l2fib_entry_result_t *r) { \ |
| 172 | r->fields.flags &= ~L2FIB_ENTRY_RESULT_FLAG_##a; \ |
| 173 | } |
| 174 | foreach_l2fib_entry_result_attr |
| 175 | #undef _ |
| 176 | static inline void |
| 177 | l2fib_entry_result_set_bits (l2fib_entry_result_t * r, |
| 178 | l2fib_entry_result_flags_t bits) |
| 179 | { |
| 180 | r->fields.flags |= bits; |
| 181 | } |
| 182 | |
| 183 | static inline void |
| 184 | l2fib_entry_result_clear_bits (l2fib_entry_result_t * r, |
| 185 | l2fib_entry_result_flags_t bits) |
| 186 | { |
| 187 | r->fields.flags &= ~bits; |
| 188 | } |
| 189 | |
John Lo | e23c99e | 2018-03-13 21:53:18 -0400 | [diff] [blame] | 190 | /* L2 MAC event entry action enums (see mac_entry definition in l2.api) */ |
| 191 | typedef enum |
| 192 | { |
| 193 | MAC_EVENT_ACTION_ADD = 0, |
| 194 | MAC_EVENT_ACTION_DELETE = 1, |
| 195 | MAC_EVENT_ACTION_MOVE = 2, |
| 196 | } l2_mac_event_action_t; |
| 197 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 198 | /** |
| 199 | * Compute the hash for the given key and return |
| 200 | * the corresponding bucket index |
| 201 | */ |
| 202 | always_inline u32 |
| 203 | l2fib_compute_hash_bucket (l2fib_entry_key_t * key) |
| 204 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 205 | u32 result; |
| 206 | u32 temp_a; |
| 207 | u32 temp_b; |
| 208 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 209 | result = 0xa5a5a5a5; /* some seed */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 210 | temp_a = key->words.w0; |
| 211 | temp_b = key->words.w1; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 212 | hash_mix32 (temp_a, temp_b, result); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 213 | |
| 214 | return result % L2FIB_NUM_BUCKETS; |
| 215 | } |
| 216 | |
Benoît Ganne | 9fb6d40 | 2019-04-15 15:28:21 +0200 | [diff] [blame^] | 217 | always_inline u64 |
Neale Ranns | 3b81a1e | 2018-09-06 09:50:26 -0700 | [diff] [blame] | 218 | l2fib_make_key (const u8 * mac_address, u16 bd_index) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 219 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 220 | u64 temp; |
| 221 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 222 | /* |
| 223 | * The mac address in memory is A:B:C:D:E:F |
| 224 | * The bd id in register is H:L |
| 225 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 226 | #if CLIB_ARCH_IS_LITTLE_ENDIAN |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 227 | /* |
| 228 | * Create the in-register key as F:E:D:C:B:A:H:L |
| 229 | * In memory the key is L:H:A:B:C:D:E:F |
| 230 | */ |
Benoît Ganne | 9fb6d40 | 2019-04-15 15:28:21 +0200 | [diff] [blame^] | 231 | temp = CLIB_MEM_OVERFLOW_LOAD (*, (u64 *) mac_address) << 16; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 232 | temp = (temp & ~0xffff) | (u64) (bd_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 233 | #else |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 234 | /* |
| 235 | * Create the in-register key as H:L:A:B:C:D:E:F |
| 236 | * In memory the key is H:L:A:B:C:D:E:F |
| 237 | */ |
Benoît Ganne | 9fb6d40 | 2019-04-15 15:28:21 +0200 | [diff] [blame^] | 238 | temp = CLIB_MEM_OVERFLOW_LOAD (*, (u64 *) mac_address) >> 16; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 239 | temp = temp | (((u64) bd_index) << 48); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 240 | #endif |
| 241 | |
| 242 | return temp; |
| 243 | } |
| 244 | |
| 245 | |
| 246 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 247 | /** |
| 248 | * Lookup the entry for mac and bd_index in the mac table for 1 packet. |
| 249 | * Cached_key and cached_result are used as a one-entry cache. |
| 250 | * The function reads and updates them as needed. |
| 251 | * |
| 252 | * mac0 and bd_index0 are the keys. The entry is written to result0. |
| 253 | * If the entry was not found, result0 is set to ~0. |
| 254 | * |
Eyal Bari | 11d47af | 2018-10-31 10:55:33 +0200 | [diff] [blame] | 255 | * key0 return with the computed key, convenient if the entry needs, |
| 256 | * to be updated afterward. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 257 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 258 | |
| 259 | static_always_inline void |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 260 | l2fib_lookup_1 (BVT (clib_bihash) * mac_table, |
| 261 | l2fib_entry_key_t * cached_key, |
| 262 | l2fib_entry_result_t * cached_result, |
| 263 | u8 * mac0, |
| 264 | u16 bd_index0, |
Eyal Bari | 11d47af | 2018-10-31 10:55:33 +0200 | [diff] [blame] | 265 | l2fib_entry_key_t * key0, l2fib_entry_result_t * result0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 266 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 267 | /* set up key */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 268 | key0->raw = l2fib_make_key (mac0, bd_index0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 269 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 270 | if (key0->raw == cached_key->raw) |
| 271 | { |
| 272 | /* Hit in the one-entry cache */ |
| 273 | result0->raw = cached_result->raw; |
| 274 | } |
| 275 | else |
| 276 | { |
| 277 | /* Do a regular mac table lookup */ |
| 278 | BVT (clib_bihash_kv) kv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 279 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 280 | kv.key = key0->raw; |
| 281 | kv.value = ~0ULL; |
| 282 | BV (clib_bihash_search_inline) (mac_table, &kv); |
| 283 | result0->raw = kv.value; |
| 284 | |
| 285 | /* Update one-entry cache */ |
| 286 | cached_key->raw = key0->raw; |
| 287 | cached_result->raw = result0->raw; |
| 288 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 292 | /** |
| 293 | * Lookup the entry for mac and bd_index in the mac table for 2 packets. |
| 294 | * The lookups for the two packets are interleaved. |
| 295 | * |
| 296 | * Cached_key and cached_result are used as a one-entry cache. |
| 297 | * The function reads and updates them as needed. |
| 298 | * |
| 299 | * mac0 and bd_index0 are the keys. The entry is written to result0. |
| 300 | * If the entry was not found, result0 is set to ~0. The same |
| 301 | * holds for mac1/bd_index1/result1. |
| 302 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 303 | static_always_inline void |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 304 | l2fib_lookup_2 (BVT (clib_bihash) * mac_table, |
| 305 | l2fib_entry_key_t * cached_key, |
| 306 | l2fib_entry_result_t * cached_result, |
| 307 | u8 * mac0, |
| 308 | u8 * mac1, |
| 309 | u16 bd_index0, |
| 310 | u16 bd_index1, |
| 311 | l2fib_entry_key_t * key0, |
| 312 | l2fib_entry_key_t * key1, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 313 | l2fib_entry_result_t * result0, |
| 314 | l2fib_entry_result_t * result1) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 315 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 316 | /* set up key */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 317 | key0->raw = l2fib_make_key (mac0, bd_index0); |
| 318 | key1->raw = l2fib_make_key (mac1, bd_index1); |
| 319 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 320 | if ((key0->raw == cached_key->raw) && (key1->raw == cached_key->raw)) |
| 321 | { |
| 322 | /* Both hit in the one-entry cache */ |
| 323 | result0->raw = cached_result->raw; |
| 324 | result1->raw = cached_result->raw; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 325 | } |
| 326 | else |
| 327 | { |
| 328 | BVT (clib_bihash_kv) kv0, kv1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 329 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 330 | /* |
| 331 | * Do a regular mac table lookup |
| 332 | * Interleave lookups for packet 0 and packet 1 |
| 333 | */ |
| 334 | kv0.key = key0->raw; |
| 335 | kv1.key = key1->raw; |
| 336 | kv0.value = ~0ULL; |
| 337 | kv1.value = ~0ULL; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 338 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 339 | BV (clib_bihash_search_inline) (mac_table, &kv0); |
| 340 | BV (clib_bihash_search_inline) (mac_table, &kv1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 341 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 342 | result0->raw = kv0.value; |
| 343 | result1->raw = kv1.value; |
| 344 | |
| 345 | /* Update one-entry cache */ |
| 346 | cached_key->raw = key1->raw; |
| 347 | cached_result->raw = result1->raw; |
| 348 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Damjan Marion | daa2cd1 | 2016-11-22 21:10:25 -0800 | [diff] [blame] | 351 | static_always_inline void |
| 352 | l2fib_lookup_4 (BVT (clib_bihash) * mac_table, |
| 353 | l2fib_entry_key_t * cached_key, |
| 354 | l2fib_entry_result_t * cached_result, |
Neale Ranns | eb1525f | 2018-09-09 04:41:02 -0400 | [diff] [blame] | 355 | const u8 * mac0, |
| 356 | const u8 * mac1, |
| 357 | const u8 * mac2, |
| 358 | const u8 * mac3, |
Damjan Marion | daa2cd1 | 2016-11-22 21:10:25 -0800 | [diff] [blame] | 359 | u16 bd_index0, |
| 360 | u16 bd_index1, |
| 361 | u16 bd_index2, |
| 362 | u16 bd_index3, |
| 363 | l2fib_entry_key_t * key0, |
| 364 | l2fib_entry_key_t * key1, |
| 365 | l2fib_entry_key_t * key2, |
| 366 | l2fib_entry_key_t * key3, |
Damjan Marion | daa2cd1 | 2016-11-22 21:10:25 -0800 | [diff] [blame] | 367 | l2fib_entry_result_t * result0, |
| 368 | l2fib_entry_result_t * result1, |
| 369 | l2fib_entry_result_t * result2, |
| 370 | l2fib_entry_result_t * result3) |
| 371 | { |
| 372 | /* set up key */ |
| 373 | key0->raw = l2fib_make_key (mac0, bd_index0); |
| 374 | key1->raw = l2fib_make_key (mac1, bd_index1); |
| 375 | key2->raw = l2fib_make_key (mac2, bd_index2); |
| 376 | key3->raw = l2fib_make_key (mac3, bd_index3); |
| 377 | |
| 378 | if ((key0->raw == cached_key->raw) && (key1->raw == cached_key->raw) && |
| 379 | (key2->raw == cached_key->raw) && (key3->raw == cached_key->raw)) |
| 380 | { |
| 381 | /* Both hit in the one-entry cache */ |
| 382 | result0->raw = cached_result->raw; |
| 383 | result1->raw = cached_result->raw; |
| 384 | result2->raw = cached_result->raw; |
| 385 | result3->raw = cached_result->raw; |
Damjan Marion | daa2cd1 | 2016-11-22 21:10:25 -0800 | [diff] [blame] | 386 | } |
| 387 | else |
| 388 | { |
| 389 | BVT (clib_bihash_kv) kv0, kv1, kv2, kv3; |
| 390 | |
| 391 | /* |
| 392 | * Do a regular mac table lookup |
| 393 | * Interleave lookups for packet 0 and packet 1 |
| 394 | */ |
| 395 | kv0.key = key0->raw; |
| 396 | kv1.key = key1->raw; |
| 397 | kv2.key = key2->raw; |
| 398 | kv3.key = key3->raw; |
| 399 | kv0.value = ~0ULL; |
| 400 | kv1.value = ~0ULL; |
| 401 | kv2.value = ~0ULL; |
| 402 | kv3.value = ~0ULL; |
| 403 | |
| 404 | BV (clib_bihash_search_inline) (mac_table, &kv0); |
| 405 | BV (clib_bihash_search_inline) (mac_table, &kv1); |
| 406 | BV (clib_bihash_search_inline) (mac_table, &kv2); |
| 407 | BV (clib_bihash_search_inline) (mac_table, &kv3); |
| 408 | |
| 409 | result0->raw = kv0.value; |
| 410 | result1->raw = kv1.value; |
| 411 | result2->raw = kv2.value; |
| 412 | result3->raw = kv3.value; |
| 413 | |
| 414 | /* Update one-entry cache */ |
| 415 | cached_key->raw = key1->raw; |
| 416 | cached_result->raw = result1->raw; |
| 417 | } |
| 418 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 419 | |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 420 | void l2fib_clear_table (void); |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 421 | |
| 422 | void |
Neale Ranns | 3b81a1e | 2018-09-06 09:50:26 -0700 | [diff] [blame] | 423 | l2fib_add_entry (const u8 * mac, |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 424 | u32 bd_index, |
Neale Ranns | b54d081 | 2018-09-06 06:22:56 -0700 | [diff] [blame] | 425 | u32 sw_if_index, l2fib_entry_result_flags_t flags); |
Eyal Bari | 31a71ab | 2017-06-25 14:42:33 +0300 | [diff] [blame] | 426 | |
| 427 | static inline void |
Neale Ranns | 3b81a1e | 2018-09-06 09:50:26 -0700 | [diff] [blame] | 428 | l2fib_add_filter_entry (const u8 * mac, u32 bd_index) |
Eyal Bari | 31a71ab | 2017-06-25 14:42:33 +0300 | [diff] [blame] | 429 | { |
Neale Ranns | b54d081 | 2018-09-06 06:22:56 -0700 | [diff] [blame] | 430 | l2fib_add_entry (mac, bd_index, ~0, |
| 431 | (L2FIB_ENTRY_RESULT_FLAG_FILTER | |
| 432 | L2FIB_ENTRY_RESULT_FLAG_STATIC)); |
Eyal Bari | 31a71ab | 2017-06-25 14:42:33 +0300 | [diff] [blame] | 433 | } |
| 434 | |
Neale Ranns | 3b81a1e | 2018-09-06 09:50:26 -0700 | [diff] [blame] | 435 | u32 l2fib_del_entry (const u8 * mac, u32 bd_index, u32 sw_if_index); |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 436 | |
| 437 | void l2fib_start_ager_scan (vlib_main_t * vm); |
| 438 | |
| 439 | void l2fib_flush_int_mac (vlib_main_t * vm, u32 sw_if_index); |
| 440 | |
| 441 | void l2fib_flush_bd_mac (vlib_main_t * vm, u32 bd_index); |
| 442 | |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 443 | void l2fib_flush_all_mac (vlib_main_t * vm); |
| 444 | |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 445 | void |
| 446 | l2fib_table_dump (u32 bd_index, l2fib_entry_key_t ** l2fe_key, |
| 447 | l2fib_entry_result_t ** l2fe_res); |
| 448 | |
| 449 | u8 *format_vnet_sw_if_index_name_with_NA (u8 * s, va_list * args); |
| 450 | |
Eyal Bari | 0f360dc | 2017-06-14 13:11:20 +0300 | [diff] [blame] | 451 | static_always_inline u8 * |
| 452 | l2fib_swif_seq_num (u32 sw_if_index) |
| 453 | { |
| 454 | l2fib_main_t *mp = &l2fib_main; |
Eyal Bari | 0f360dc | 2017-06-14 13:11:20 +0300 | [diff] [blame] | 455 | return vec_elt_at_index (mp->swif_seq_num, sw_if_index); |
| 456 | } |
| 457 | |
Eyal Bari | b12ac56 | 2017-07-18 13:25:19 +0300 | [diff] [blame] | 458 | static_always_inline u8 * |
| 459 | l2fib_valid_swif_seq_num (u32 sw_if_index) |
| 460 | { |
| 461 | l2fib_main_t *mp = &l2fib_main; |
| 462 | vec_validate (mp->swif_seq_num, sw_if_index); |
| 463 | return l2fib_swif_seq_num (sw_if_index); |
| 464 | } |
| 465 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 466 | BVT (clib_bihash) * get_mac_table (void); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 467 | |
| 468 | #endif |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 469 | |
| 470 | /* |
| 471 | * fd.io coding-style-patch-verification: ON |
| 472 | * |
| 473 | * Local Variables: |
| 474 | * eval: (c-set-style "gnu") |
| 475 | * End: |
| 476 | */ |