Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * l2_fib.c : 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 | |
| 19 | #include <vlib/vlib.h> |
| 20 | #include <vnet/vnet.h> |
| 21 | #include <vnet/pg/pg.h> |
| 22 | #include <vnet/ethernet/ethernet.h> |
| 23 | #include <vlib/cli.h> |
| 24 | |
| 25 | #include <vppinfra/error.h> |
| 26 | #include <vppinfra/hash.h> |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 27 | #include <vnet/l2/l2_input.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 28 | #include <vnet/l2/l2_fib.h> |
| 29 | #include <vnet/l2/l2_learn.h> |
| 30 | #include <vnet/l2/l2_bd.h> |
| 31 | |
| 32 | #include <vppinfra/bihash_template.c> |
| 33 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 34 | /** |
| 35 | * @file |
| 36 | * @brief Ethernet MAC Address FIB Table Management. |
| 37 | * |
| 38 | * The MAC Address forwarding table for bridge-domains is called the l2fib. |
| 39 | * Entries are added automatically as part of mac learning, but MAC Addresses |
| 40 | * entries can also be added manually. |
| 41 | * |
| 42 | */ |
| 43 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 44 | typedef struct |
| 45 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 46 | |
| 47 | /* hash table */ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 48 | BVT (clib_bihash) mac_table; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 49 | |
| 50 | /* convenience variables */ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 51 | vlib_main_t *vlib_main; |
| 52 | vnet_main_t *vnet_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 53 | } l2fib_main_t; |
| 54 | |
| 55 | l2fib_main_t l2fib_main; |
| 56 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 57 | /** Format sw_if_index. If the value is ~0, use the text "N/A" */ |
| 58 | u8 * |
| 59 | format_vnet_sw_if_index_name_with_NA (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 60 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 61 | vnet_main_t *vnm = va_arg (*args, vnet_main_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 62 | u32 sw_if_index = va_arg (*args, u32); |
| 63 | if (sw_if_index == ~0) |
| 64 | return format (s, "N/A"); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 65 | else |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 66 | return format (s, "%U", |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 67 | format_vnet_sw_interface_name, vnm, |
| 68 | vnet_get_sw_interface (vnm, sw_if_index)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 71 | void |
| 72 | l2fib_table_dump (u32 bd_index, l2fib_entry_key_t ** l2fe_key, |
| 73 | l2fib_entry_result_t ** l2fe_res) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 74 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 75 | l2fib_main_t *msm = &l2fib_main; |
| 76 | BVT (clib_bihash) * h = &msm->mac_table; |
| 77 | clib_bihash_bucket_t *b; |
| 78 | BVT (clib_bihash_value) * v; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 79 | l2fib_entry_key_t key; |
| 80 | l2fib_entry_result_t result; |
| 81 | int i, j, k; |
| 82 | |
| 83 | for (i = 0; i < h->nbuckets; i++) |
| 84 | { |
| 85 | b = &h->buckets[i]; |
| 86 | if (b->offset == 0) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 87 | continue; |
| 88 | v = BV (clib_bihash_get_value) (h, b->offset); |
| 89 | for (j = 0; j < (1 << b->log2_pages); j++) |
| 90 | { |
| 91 | for (k = 0; k < BIHASH_KVP_PER_PAGE; k++) |
| 92 | { |
| 93 | if (v->kvp[k].key == ~0ULL && v->kvp[k].value == ~0ULL) |
| 94 | continue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 95 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 96 | key.raw = v->kvp[k].key; |
| 97 | result.raw = v->kvp[k].value; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 98 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 99 | if ((bd_index == ~0) || (bd_index == key.fields.bd_index)) |
| 100 | { |
| 101 | vec_add1 (*l2fe_key, key); |
| 102 | vec_add1 (*l2fe_res, result); |
| 103 | } |
| 104 | } |
| 105 | v++; |
| 106 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 107 | } |
| 108 | } |
| 109 | |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 110 | /** Display the contents of the l2fib. */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 111 | static clib_error_t * |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 112 | show_l2fib (vlib_main_t * vm, |
| 113 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 114 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 115 | bd_main_t *bdm = &bd_main; |
| 116 | l2fib_main_t *msm = &l2fib_main; |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 117 | l2_bridge_domain_t *bd_config; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 118 | BVT (clib_bihash) * h = &msm->mac_table; |
| 119 | clib_bihash_bucket_t *b; |
| 120 | BVT (clib_bihash_value) * v; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 121 | l2fib_entry_key_t key; |
| 122 | l2fib_entry_result_t result; |
| 123 | u32 first_entry = 1; |
| 124 | u64 total_entries = 0; |
| 125 | int i, j, k; |
| 126 | u8 verbose = 0; |
| 127 | u8 raw = 0; |
| 128 | u32 bd_id, bd_index = ~0; |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 129 | u8 now = (u8) (vlib_time_now (vm) / 60); |
| 130 | u8 *s = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 131 | |
| 132 | if (unformat (input, "raw")) |
| 133 | raw = 1; |
| 134 | else if (unformat (input, "verbose")) |
| 135 | verbose = 1; |
| 136 | else if (unformat (input, "bd_index %d", &bd_index)) |
| 137 | verbose = 1; |
| 138 | else if (unformat (input, "bd_id %d", &bd_id)) |
| 139 | { |
| 140 | uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 141 | if (p) |
| 142 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 143 | verbose = 1; |
| 144 | bd_index = p[0]; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 145 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 146 | else |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 147 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 148 | vlib_cli_output (vm, "no such bridge domain id"); |
| 149 | return 0; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 150 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | for (i = 0; i < h->nbuckets; i++) |
| 154 | { |
| 155 | b = &h->buckets[i]; |
| 156 | if (b->offset == 0) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 157 | continue; |
| 158 | v = BV (clib_bihash_get_value) (h, b->offset); |
| 159 | for (j = 0; j < (1 << b->log2_pages); j++) |
| 160 | { |
| 161 | for (k = 0; k < BIHASH_KVP_PER_PAGE; k++) |
| 162 | { |
| 163 | if (v->kvp[k].key == ~0ULL && v->kvp[k].value == ~0ULL) |
| 164 | continue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 165 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 166 | if (verbose && first_entry) |
| 167 | { |
| 168 | first_entry = 0; |
| 169 | vlib_cli_output (vm, |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 170 | "%=19s%=7s%=7s%=8s%=9s%=7s%=7s%=5s%=30s", |
| 171 | "Mac-Address", "BD-Idx", "If-Idx", |
| 172 | "BSN-ISN", "Age(min)", "static", "filter", |
| 173 | "bvi", "Interface-Name"); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 174 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 175 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 176 | key.raw = v->kvp[k].key; |
| 177 | result.raw = v->kvp[k].value; |
| 178 | |
| 179 | if (verbose |
| 180 | & ((bd_index >> 31) || (bd_index == key.fields.bd_index))) |
| 181 | { |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 182 | bd_config = vec_elt_at_index (l2input_main.bd_configs, |
| 183 | key.fields.bd_index); |
| 184 | |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 185 | if (bd_config->mac_age && !result.fields.static_mac) |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 186 | { |
| 187 | i16 delta = now - result.fields.timestamp; |
| 188 | delta += delta < 0 ? 256 : 0; |
| 189 | s = format (s, "%d", delta); |
| 190 | } |
| 191 | else |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 192 | s = format (s, "-"); |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 193 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 194 | vlib_cli_output (vm, |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 195 | "%=19U%=7d%=7d %3d/%-3d%=9v%=7s%=7s%=5s%=30U", |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 196 | format_ethernet_address, key.fields.mac, |
| 197 | key.fields.bd_index, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 198 | result.fields.sw_if_index == ~0 |
| 199 | ? -1 : result.fields.sw_if_index, |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 200 | result.fields.sn.bd, result.fields.sn.swif, |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 201 | s, result.fields.static_mac ? "*" : "-", |
| 202 | result.fields.filter ? "*" : "-", |
| 203 | result.fields.bvi ? "*" : "-", |
| 204 | format_vnet_sw_if_index_name_with_NA, |
| 205 | msm->vnet_main, result.fields.sw_if_index); |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 206 | vec_reset_length (s); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 207 | } |
| 208 | total_entries++; |
| 209 | } |
| 210 | v++; |
| 211 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | if (total_entries == 0) |
| 215 | vlib_cli_output (vm, "no l2fib entries"); |
| 216 | else |
John Lo | d48c8eb | 2017-05-05 12:35:25 -0400 | [diff] [blame] | 217 | vlib_cli_output (vm, |
| 218 | "%lld l2fib entries with %d learned (or non-static) entries", |
| 219 | total_entries, l2learn_main.global_learn_count); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 220 | |
| 221 | if (raw) |
| 222 | vlib_cli_output (vm, "Raw Hash Table:\n%U\n", |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 223 | BV (format_bihash), h, 1 /* verbose */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 224 | |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 225 | vec_free (s); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 226 | return 0; |
| 227 | } |
| 228 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 229 | /*? |
| 230 | * This command dispays the MAC Address entries of the L2 FIB table. |
| 231 | * Output can be filtered to just get the number of MAC Addresses or display |
| 232 | * each MAC Address for all bridge domains or just a single bridge domain. |
| 233 | * |
| 234 | * @cliexpar |
| 235 | * Example of how to display the number of MAC Address entries in the L2 |
| 236 | * FIB table: |
| 237 | * @cliexstart{show l2fib} |
| 238 | * 3 l2fib entries |
| 239 | * @cliexend |
| 240 | * Example of how to display all the MAC Address entries in the L2 |
| 241 | * FIB table: |
| 242 | * @cliexstart{show l2fib verbose} |
| 243 | * Mac Address BD Idx Interface Index static filter bvi refresh timestamp |
| 244 | * 52:54:00:53:18:33 1 GigabitEthernet0/8/0.200 3 0 0 0 0 0 |
| 245 | * 52:54:00:53:18:55 1 GigabitEthernet0/8/0.200 3 1 0 0 0 0 |
| 246 | * 52:54:00:53:18:77 1 N/A -1 1 1 0 0 0 |
| 247 | * 3 l2fib entries |
| 248 | * @cliexend |
| 249 | ?*/ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 250 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 251 | VLIB_CLI_COMMAND (show_l2fib_cli, static) = { |
| 252 | .path = "show l2fib", |
| 253 | .short_help = "show l2fib [verbose | bd_id <nn> | bd_index <nn> | raw]", |
| 254 | .function = show_l2fib, |
| 255 | }; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 256 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 257 | |
| 258 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 259 | /* Remove all entries from the l2fib */ |
| 260 | void |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 261 | l2fib_clear_table (void) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 262 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 263 | l2fib_main_t *mp = &l2fib_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 264 | |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 265 | /* Remove all entries */ |
| 266 | BV (clib_bihash_free) (&mp->mac_table); |
| 267 | BV (clib_bihash_init) (&mp->mac_table, "l2fib mac table", |
| 268 | L2FIB_NUM_BUCKETS, L2FIB_MEMORY_SIZE); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 269 | l2learn_main.global_learn_count = 0; |
| 270 | } |
| 271 | |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 272 | /** Clear all entries in L2FIB. |
| 273 | * @TODO: Later we may want a way to remove only the non-static entries |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 274 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 275 | static clib_error_t * |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 276 | clear_l2fib (vlib_main_t * vm, |
| 277 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 278 | { |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 279 | l2fib_clear_table (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 280 | return 0; |
| 281 | } |
| 282 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 283 | /*? |
| 284 | * This command clears all the MAC Address entries from the L2 FIB table. |
| 285 | * |
| 286 | * @cliexpar |
| 287 | * Example of how to clear the L2 FIB Table: |
| 288 | * @cliexcmd{clear l2fib} |
| 289 | * Example to show the L2 FIB Table has been cleared: |
| 290 | * @cliexstart{show l2fib verbose} |
| 291 | * no l2fib entries |
| 292 | * @cliexend |
| 293 | ?*/ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 294 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 295 | VLIB_CLI_COMMAND (clear_l2fib_cli, static) = { |
| 296 | .path = "clear l2fib", |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 297 | .short_help = "clear l2fib", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 298 | .function = clear_l2fib, |
| 299 | }; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 300 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 301 | |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 302 | static inline l2fib_seq_num_t |
| 303 | l2fib_cur_seq_num (u32 bd_index, u32 sw_if_index) |
| 304 | { |
| 305 | l2_input_config_t *int_config = l2input_intf_config (sw_if_index); |
| 306 | l2_bridge_domain_t *bd_config = l2input_bd_config (bd_index); |
| 307 | /* *INDENT-OFF* */ |
| 308 | return (l2fib_seq_num_t) { |
| 309 | .swif = int_config->seq_num, |
| 310 | .bd = bd_config->seq_num, |
| 311 | }; |
| 312 | /* *INDENT-ON* */ |
| 313 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 314 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 315 | /** |
| 316 | * Add an entry to the l2fib. |
| 317 | * If the entry already exists then overwrite it |
| 318 | */ |
| 319 | void |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 320 | l2fib_add_entry (u64 mac, u32 bd_index, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 321 | u32 sw_if_index, u32 static_mac, u32 filter_mac, u32 bvi_mac) |
| 322 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 323 | l2fib_entry_key_t key; |
| 324 | l2fib_entry_result_t result; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 325 | __attribute__ ((unused)) u32 bucket_contents; |
| 326 | l2fib_main_t *mp = &l2fib_main; |
| 327 | BVT (clib_bihash_kv) kv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 328 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 329 | /* set up key */ |
| 330 | key.raw = l2fib_make_key ((u8 *) & mac, bd_index); |
| 331 | |
| 332 | /* set up result */ |
| 333 | result.raw = 0; /* clear all fields */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 334 | result.fields.sw_if_index = sw_if_index; |
| 335 | result.fields.static_mac = static_mac; |
| 336 | result.fields.filter = filter_mac; |
| 337 | result.fields.bvi = bvi_mac; |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 338 | if (!static_mac) |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 339 | result.fields.sn = l2fib_cur_seq_num (bd_index, sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 340 | |
| 341 | kv.key = key.raw; |
| 342 | kv.value = result.raw; |
| 343 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 344 | BV (clib_bihash_add_del) (&mp->mac_table, &kv, 1 /* is_add */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 345 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 346 | /* increment counter if dynamically learned mac */ |
John Lo | d48c8eb | 2017-05-05 12:35:25 -0400 | [diff] [blame] | 347 | if (result.fields.static_mac == 0) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 348 | { |
| 349 | l2learn_main.global_learn_count++; |
| 350 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 353 | /** |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 354 | * Add an entry to the L2FIB. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 355 | * The CLI format is: |
| 356 | * l2fib add <mac> <bd> <intf> [static] [bvi] |
| 357 | * l2fib add <mac> <bd> filter |
| 358 | * Note that filter and bvi entries are always static |
| 359 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 360 | static clib_error_t * |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 361 | l2fib_add (vlib_main_t * vm, |
| 362 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 363 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 364 | bd_main_t *bdm = &bd_main; |
| 365 | vnet_main_t *vnm = vnet_get_main (); |
| 366 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 367 | u64 mac; |
| 368 | u32 bd_id; |
| 369 | u32 bd_index; |
| 370 | u32 sw_if_index = ~0; |
| 371 | u32 filter_mac = 0; |
| 372 | u32 static_mac = 0; |
| 373 | u32 bvi_mac = 0; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 374 | uword *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 375 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 376 | if (!unformat_user (input, unformat_ethernet_address, &mac)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 377 | { |
| 378 | error = clib_error_return (0, "expected mac address `%U'", |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 379 | format_unformat_error, input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 380 | goto done; |
| 381 | } |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 382 | |
| 383 | if (!unformat (input, "%d", &bd_id)) |
| 384 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 385 | error = clib_error_return (0, "expected bridge domain ID `%U'", |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 386 | format_unformat_error, input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 387 | goto done; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 388 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 389 | |
| 390 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 391 | if (!p) |
| 392 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 393 | error = clib_error_return (0, "bridge domain ID %d invalid", bd_id); |
| 394 | goto done; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 395 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 396 | bd_index = p[0]; |
| 397 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 398 | if (unformat (input, "filter")) |
| 399 | { |
| 400 | filter_mac = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 401 | static_mac = 1; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 402 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 403 | } |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 404 | else |
| 405 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 406 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 407 | if (!unformat_user |
| 408 | (input, unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 409 | { |
| 410 | error = clib_error_return (0, "unknown interface `%U'", |
| 411 | format_unformat_error, input); |
| 412 | goto done; |
| 413 | } |
| 414 | if (unformat (input, "static")) |
| 415 | { |
| 416 | static_mac = 1; |
| 417 | } |
| 418 | else if (unformat (input, "bvi")) |
| 419 | { |
| 420 | bvi_mac = 1; |
| 421 | static_mac = 1; |
| 422 | } |
| 423 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 424 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 425 | l2fib_add_entry (mac, bd_index, sw_if_index, static_mac, filter_mac, |
| 426 | bvi_mac); |
| 427 | |
| 428 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 429 | return error; |
| 430 | } |
| 431 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 432 | /*? |
| 433 | * This command adds a MAC Address entry to the L2 FIB table |
| 434 | * of an existing bridge-domain. The MAC Address can be static |
| 435 | * or dynamic. This command also allows a filter to be added, |
| 436 | * such that packets with given MAC Addresses (source mac or |
| 437 | * destination mac match) are dropped. |
| 438 | * |
| 439 | * @cliexpar |
| 440 | * Example of how to add a dynamic MAC Address entry to the L2 FIB table |
| 441 | * of a bridge-domain (where 200 is the bridge-domain-id): |
| 442 | * @cliexcmd{l2fib add 52:54:00:53:18:33 200 GigabitEthernet0/8/0.200} |
| 443 | * Example of how to add a static MAC Address entry to the L2 FIB table |
| 444 | * of a bridge-domain (where 200 is the bridge-domain-id): |
| 445 | * @cliexcmd{l2fib add 52:54:00:53:18:55 200 GigabitEthernet0/8/0.200 static} |
| 446 | * Example of how to add a filter such that a packet with the given MAC |
| 447 | * Address will be dropped in a given bridge-domain (where 200 is the |
| 448 | * bridge-domain-id): |
| 449 | * @cliexcmd{l2fib add 52:54:00:53:18:77 200 filter} |
| 450 | * Example of show command of the provisioned MAC Addresses and filters: |
| 451 | * @cliexstart{show l2fib verbose} |
| 452 | * Mac Address BD Idx Interface Index static filter bvi refresh timestamp |
| 453 | * 52:54:00:53:18:33 1 GigabitEthernet0/8/0.200 3 0 0 0 0 0 |
| 454 | * 52:54:00:53:18:55 1 GigabitEthernet0/8/0.200 3 1 0 0 0 0 |
| 455 | * 52:54:00:53:18:77 1 N/A -1 1 1 0 0 0 |
| 456 | * 3 l2fib entries |
| 457 | * @cliexend |
| 458 | ?*/ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 459 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 460 | VLIB_CLI_COMMAND (l2fib_add_cli, static) = { |
| 461 | .path = "l2fib add", |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 462 | .short_help = "l2fib add <mac> <bridge-domain-id> filter | <intf> [static | bvi]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 463 | .function = l2fib_add, |
| 464 | }; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 465 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 466 | |
| 467 | |
| 468 | static clib_error_t * |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 469 | l2fib_test_command_fn (vlib_main_t * vm, |
| 470 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 471 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 472 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 473 | u64 mac, save_mac; |
| 474 | u32 bd_index = 0; |
| 475 | u32 sw_if_index = 8; |
| 476 | u32 filter_mac = 0; |
| 477 | u32 bvi_mac = 0; |
| 478 | u32 is_add = 0; |
| 479 | u32 is_del = 0; |
| 480 | u32 is_check = 0; |
| 481 | u32 count = 1; |
| 482 | int mac_set = 0; |
| 483 | int i; |
| 484 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 485 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 486 | { |
| 487 | if (unformat (input, "mac %U", unformat_ethernet_address, &mac)) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 488 | mac_set = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 489 | else if (unformat (input, "add")) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 490 | is_add = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 491 | else if (unformat (input, "del")) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 492 | is_del = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 493 | else if (unformat (input, "check")) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 494 | is_check = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 495 | else if (unformat (input, "count %d", &count)) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 496 | ; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 497 | else |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 498 | break; |
| 499 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 500 | |
| 501 | if (mac_set == 0) |
| 502 | return clib_error_return (0, "mac not set"); |
| 503 | |
| 504 | if (is_add == 0 && is_del == 0 && is_check == 0) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 505 | return clib_error_return (0, |
| 506 | "noop: pick at least one of (add,del,check)"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 507 | |
| 508 | save_mac = mac; |
| 509 | |
| 510 | if (is_add) |
| 511 | { |
| 512 | for (i = 0; i < count; i++) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 513 | { |
| 514 | u64 tmp; |
| 515 | l2fib_add_entry (mac, bd_index, sw_if_index, mac, |
| 516 | filter_mac, bvi_mac); |
| 517 | tmp = clib_net_to_host_u64 (mac); |
| 518 | tmp >>= 16; |
| 519 | tmp++; |
| 520 | tmp <<= 16; |
| 521 | mac = clib_host_to_net_u64 (tmp); |
| 522 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | if (is_check) |
| 526 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 527 | BVT (clib_bihash_kv) kv; |
| 528 | l2fib_main_t *mp = &l2fib_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 529 | |
| 530 | mac = save_mac; |
| 531 | |
| 532 | for (i = 0; i < count; i++) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 533 | { |
| 534 | u64 tmp; |
| 535 | kv.key = l2fib_make_key ((u8 *) & mac, bd_index); |
| 536 | if (BV (clib_bihash_search) (&mp->mac_table, &kv, &kv)) |
| 537 | { |
| 538 | clib_warning ("key %U AWOL", format_ethernet_address, &mac); |
| 539 | break; |
| 540 | } |
| 541 | tmp = clib_net_to_host_u64 (mac); |
| 542 | tmp >>= 16; |
| 543 | tmp++; |
| 544 | tmp <<= 16; |
| 545 | mac = clib_host_to_net_u64 (tmp); |
| 546 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | if (is_del) |
| 550 | { |
| 551 | for (i = 0; i < count; i++) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 552 | { |
| 553 | u64 tmp; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 554 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 555 | l2fib_del_entry (mac, bd_index); |
| 556 | |
| 557 | tmp = clib_net_to_host_u64 (mac); |
| 558 | tmp >>= 16; |
| 559 | tmp++; |
| 560 | tmp <<= 16; |
| 561 | mac = clib_host_to_net_u64 (tmp); |
| 562 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | return error; |
| 566 | } |
| 567 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 568 | /*? |
| 569 | * The set of '<em>test l2fib</em>' commands allow the L2 FIB table of the default |
| 570 | * bridge domain (bridge-domain-id of 0) to be modified. |
| 571 | * |
| 572 | * @cliexpar |
| 573 | * @parblock |
| 574 | * Example of how to add a set of 4 sequential MAC Address entries to L2 |
| 575 | * FIB table of the default bridge-domain: |
| 576 | * @cliexcmd{test l2fib add mac 52:54:00:53:00:00 count 4} |
| 577 | * |
| 578 | * Show the set of 4 sequential MAC Address entries that were added: |
| 579 | * @cliexstart{show l2fib verbose} |
| 580 | * Mac Address BD Idx Interface Index static filter bvi refresh timestamp |
| 581 | * 52:54:00:53:00:00 0 GigabitEthernet0/8/0.300 8 0 0 0 0 0 |
| 582 | * 52:54:00:53:00:01 0 GigabitEthernet0/8/0.300 8 0 0 0 0 0 |
| 583 | * 52:54:00:53:00:03 0 GigabitEthernet0/8/0.300 8 0 0 0 0 0 |
| 584 | * 52:54:00:53:00:02 0 GigabitEthernet0/8/0.300 8 0 0 0 0 0 |
| 585 | * 4 l2fib entries |
| 586 | * @cliexend |
| 587 | * |
| 588 | * Example of how to check that the set of 4 sequential MAC Address |
| 589 | * entries were added to L2 FIB table of the default |
| 590 | * bridge-domain. Used a count of 5 to produce an error: |
| 591 | * |
| 592 | * @cliexcmd{test l2fib check mac 52:54:00:53:00:00 count 5} |
| 593 | * The output of the check command is in the log files. Log file |
| 594 | * location may vary based on your OS and Version: |
| 595 | * |
| 596 | * <b><em># tail -f /var/log/messages | grep l2fib_test_command_fn</em></b> |
| 597 | * |
| 598 | * Sep 7 17:15:24 localhost vnet[4952]: l2fib_test_command_fn:446: key 52:54:00:53:00:04 AWOL |
| 599 | * |
| 600 | * Example of how to delete a set of 4 sequential MAC Address entries |
| 601 | * from L2 FIB table of the default bridge-domain: |
| 602 | * @cliexcmd{test l2fib del mac 52:54:00:53:00:00 count 4} |
| 603 | * @endparblock |
| 604 | ?*/ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 605 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 606 | VLIB_CLI_COMMAND (l2fib_test_command, static) = { |
| 607 | .path = "test l2fib", |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 608 | .short_help = "test l2fib [add|del|check] mac <base-addr> count <nn>", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 609 | .function = l2fib_test_command_fn, |
| 610 | }; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 611 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 612 | |
| 613 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 614 | /** |
| 615 | * Delete an entry from the l2fib. |
| 616 | * Return 0 if the entry was deleted, or 1 if it was not found |
| 617 | */ |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 618 | static u32 |
| 619 | l2fib_del_entry_by_key (u64 raw_key) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 620 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 621 | |
| 622 | l2fib_entry_result_t result; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 623 | l2fib_main_t *mp = &l2fib_main; |
| 624 | BVT (clib_bihash_kv) kv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 625 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 626 | /* set up key */ |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 627 | kv.key = raw_key; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 628 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 629 | if (BV (clib_bihash_search) (&mp->mac_table, &kv, &kv)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 630 | return 1; |
| 631 | |
| 632 | result.raw = kv.value; |
| 633 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 634 | /* decrement counter if dynamically learned mac */ |
John Lo | d48c8eb | 2017-05-05 12:35:25 -0400 | [diff] [blame] | 635 | if (result.fields.static_mac == 0) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 636 | { |
| 637 | if (l2learn_main.global_learn_count > 0) |
| 638 | { |
| 639 | l2learn_main.global_learn_count--; |
| 640 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 641 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 642 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 643 | /* Remove entry from hash table */ |
| 644 | BV (clib_bihash_add_del) (&mp->mac_table, &kv, 0 /* is_add */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 645 | return 0; |
| 646 | } |
| 647 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 648 | /** |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 649 | * Delete an entry from the l2fib. |
| 650 | * Return 0 if the entry was deleted, or 1 if it was not found |
| 651 | */ |
| 652 | u32 |
| 653 | l2fib_del_entry (u64 mac, u32 bd_index) |
| 654 | { |
| 655 | return l2fib_del_entry_by_key (l2fib_make_key ((u8 *) & mac, bd_index)); |
| 656 | } |
| 657 | |
| 658 | /** |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 659 | * Delete an entry from the L2FIB. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 660 | * The CLI format is: |
| 661 | * l2fib del <mac> <bd-id> |
| 662 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 663 | static clib_error_t * |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 664 | l2fib_del (vlib_main_t * vm, |
| 665 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 666 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 667 | bd_main_t *bdm = &bd_main; |
| 668 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 669 | u64 mac; |
| 670 | u32 bd_id; |
| 671 | u32 bd_index; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 672 | uword *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 673 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 674 | if (!unformat_user (input, unformat_ethernet_address, &mac)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 675 | { |
| 676 | error = clib_error_return (0, "expected mac address `%U'", |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 677 | format_unformat_error, input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 678 | goto done; |
| 679 | } |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 680 | |
| 681 | if (!unformat (input, "%d", &bd_id)) |
| 682 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 683 | error = clib_error_return (0, "expected bridge domain ID `%U'", |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 684 | format_unformat_error, input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 685 | goto done; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 686 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 687 | |
| 688 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 689 | if (!p) |
| 690 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 691 | error = clib_error_return (0, "bridge domain ID %d invalid", bd_id); |
| 692 | goto done; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 693 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 694 | bd_index = p[0]; |
| 695 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 696 | /* Delete the entry */ |
| 697 | if (l2fib_del_entry (mac, bd_index)) |
| 698 | { |
| 699 | error = clib_error_return (0, "mac entry not found"); |
| 700 | goto done; |
| 701 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 702 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 703 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 704 | return error; |
| 705 | } |
| 706 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 707 | /*? |
| 708 | * This command deletes an existing MAC Address entry from the L2 FIB |
| 709 | * table of an existing bridge-domain. |
| 710 | * |
| 711 | * @cliexpar |
| 712 | * Example of how to delete a MAC Address entry from the L2 FIB table of a bridge-domain (where 200 is the bridge-domain-id): |
| 713 | * @cliexcmd{l2fib del 52:54:00:53:18:33 200} |
| 714 | ?*/ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 715 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 716 | VLIB_CLI_COMMAND (l2fib_del_cli, static) = { |
| 717 | .path = "l2fib del", |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 718 | .short_help = "l2fib del <mac> <bridge-domain-id>", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 719 | .function = l2fib_del, |
| 720 | }; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 721 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 722 | |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 723 | /** |
| 724 | Kick off ager to scan MACs to age/delete MAC entries |
| 725 | */ |
| 726 | void |
| 727 | l2fib_start_ager_scan (vlib_main_t * vm) |
| 728 | { |
| 729 | l2_bridge_domain_t *bd_config; |
| 730 | int enable = 0; |
| 731 | |
| 732 | /* check if there is at least one bd with mac aging enabled */ |
| 733 | vec_foreach (bd_config, l2input_main.bd_configs) |
| 734 | if (bd_config->bd_id != ~0 && bd_config->mac_age != 0) |
| 735 | enable = 1; |
| 736 | |
| 737 | vlib_process_signal_event (vm, l2fib_mac_age_scanner_process_node.index, |
| 738 | enable ? L2_MAC_AGE_PROCESS_EVENT_START : |
| 739 | L2_MAC_AGE_PROCESS_EVENT_ONE_PASS, 0); |
| 740 | } |
| 741 | |
| 742 | /** |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 743 | Flush all non static MACs from an interface |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 744 | */ |
| 745 | void |
| 746 | l2fib_flush_int_mac (vlib_main_t * vm, u32 sw_if_index) |
| 747 | { |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 748 | l2_input_config_t *int_config = l2input_intf_config (sw_if_index); |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 749 | int_config->seq_num += 1; |
| 750 | l2fib_start_ager_scan (vm); |
| 751 | } |
| 752 | |
| 753 | /** |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 754 | Flush all non static MACs in a bridge domain |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 755 | */ |
| 756 | void |
| 757 | l2fib_flush_bd_mac (vlib_main_t * vm, u32 bd_index) |
| 758 | { |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 759 | l2_bridge_domain_t *bd_config = l2input_bd_config (bd_index); |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 760 | bd_config->seq_num += 1; |
| 761 | l2fib_start_ager_scan (vm); |
| 762 | } |
| 763 | |
| 764 | /** |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 765 | Flush all non static MACs - flushes all valid BDs |
| 766 | */ |
| 767 | void |
| 768 | l2fib_flush_all_mac (vlib_main_t * vm) |
| 769 | { |
| 770 | l2_bridge_domain_t *bd_config; |
| 771 | vec_foreach (bd_config, l2input_main.bd_configs) |
| 772 | if (bd_is_valid (bd_config)) |
| 773 | bd_config->seq_num += 1; |
| 774 | |
| 775 | l2fib_start_ager_scan (vm); |
| 776 | } |
| 777 | |
| 778 | |
| 779 | /** |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 780 | Flush MACs, except static ones, associated with an interface |
| 781 | The CLI format is: |
| 782 | l2fib flush-mac interface <if-name> |
| 783 | */ |
| 784 | static clib_error_t * |
| 785 | l2fib_flush_mac_int (vlib_main_t * vm, |
| 786 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 787 | { |
| 788 | vnet_main_t *vnm = vnet_get_main (); |
| 789 | clib_error_t *error = 0; |
| 790 | u32 sw_if_index; |
| 791 | |
| 792 | if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 793 | { |
| 794 | error = clib_error_return (0, "unknown interface `%U'", |
| 795 | format_unformat_error, input); |
| 796 | goto done; |
| 797 | } |
| 798 | |
| 799 | l2fib_flush_int_mac (vm, sw_if_index); |
| 800 | |
| 801 | done: |
| 802 | return error; |
| 803 | } |
| 804 | |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 805 | /** |
| 806 | Flush all MACs, except static ones |
| 807 | The CLI format is: |
| 808 | l2fib flush-mac all |
| 809 | */ |
| 810 | static clib_error_t * |
| 811 | l2fib_flush_mac_all (vlib_main_t * vm, |
| 812 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 813 | { |
| 814 | l2fib_flush_all_mac (vm); |
| 815 | return 0; |
| 816 | } |
| 817 | |
| 818 | /*? |
| 819 | * This command kick off ager to delete all existing MAC Address entries, |
| 820 | * except static ones, associated with an interface from the L2 FIB table. |
| 821 | * |
| 822 | * @cliexpar |
| 823 | * Example of how to flush MAC Address entries learned on an interface from the L2 FIB table: |
| 824 | * @cliexcmd{l2fib flush-mac interface GigabitEthernet2/1/0} |
| 825 | ?*/ |
| 826 | /* *INDENT-OFF* */ |
| 827 | VLIB_CLI_COMMAND (l2fib_flush_mac_all_cli, static) = { |
| 828 | .path = "l2fib flush-mac all", |
| 829 | .short_help = "l2fib flush-mac all", |
| 830 | .function = l2fib_flush_mac_all, |
| 831 | }; |
| 832 | /* *INDENT-ON* */ |
| 833 | |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 834 | /*? |
| 835 | * This command kick off ager to delete all existing MAC Address entries, |
| 836 | * except static ones, associated with an interface from the L2 FIB table. |
| 837 | * |
| 838 | * @cliexpar |
| 839 | * Example of how to flush MAC Address entries learned on an interface from the L2 FIB table: |
| 840 | * @cliexcmd{l2fib flush-mac interface GigabitEthernet2/1/0} |
| 841 | ?*/ |
| 842 | /* *INDENT-OFF* */ |
| 843 | VLIB_CLI_COMMAND (l2fib_flush_mac_int_cli, static) = { |
| 844 | .path = "l2fib flush-mac interface", |
| 845 | .short_help = "l2fib flush-mac interface <if-name>", |
| 846 | .function = l2fib_flush_mac_int, |
| 847 | }; |
| 848 | /* *INDENT-ON* */ |
| 849 | |
| 850 | /** |
| 851 | Flush bridge-domain MACs except static ones. |
| 852 | The CLI format is: |
| 853 | l2fib flush-mac bridge-domain <bd-id> |
| 854 | */ |
| 855 | static clib_error_t * |
| 856 | l2fib_flush_mac_bd (vlib_main_t * vm, |
| 857 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 858 | { |
| 859 | bd_main_t *bdm = &bd_main; |
| 860 | clib_error_t *error = 0; |
| 861 | u32 bd_index, bd_id; |
| 862 | uword *p; |
| 863 | |
| 864 | if (!unformat (input, "%d", &bd_id)) |
| 865 | { |
| 866 | error = clib_error_return (0, "expecting bridge-domain id but got `%U'", |
| 867 | format_unformat_error, input); |
| 868 | goto done; |
| 869 | } |
| 870 | |
| 871 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 872 | if (p) |
| 873 | bd_index = *p; |
| 874 | else |
| 875 | return clib_error_return (0, "No such bridge domain %d", bd_id); |
| 876 | |
| 877 | l2fib_flush_bd_mac (vm, bd_index); |
| 878 | |
| 879 | done: |
| 880 | return error; |
| 881 | } |
| 882 | |
| 883 | /*? |
| 884 | * This command kick off ager to delete all existing MAC Address entries, |
| 885 | * except static ones, in a bridge domain from the L2 FIB table. |
| 886 | * |
| 887 | * @cliexpar |
| 888 | * Example of how to flush MAC Address entries learned in a bridge domain from the L2 FIB table: |
| 889 | * @cliexcmd{l2fib flush-mac bridge-domain 1000} |
| 890 | ?*/ |
| 891 | /* *INDENT-OFF* */ |
| 892 | VLIB_CLI_COMMAND (l2fib_flush_mac_bd_cli, static) = { |
| 893 | .path = "l2fib flush-mac bridge-domain", |
| 894 | .short_help = "l2fib flush-mac bridge-domain <bd-id>", |
| 895 | .function = l2fib_flush_mac_bd, |
| 896 | }; |
| 897 | /* *INDENT-ON* */ |
| 898 | |
Eyal Bari | afc47aa | 2017-04-20 14:45:17 +0300 | [diff] [blame] | 899 | clib_error_t * |
| 900 | l2fib_sw_interface_up_down (vnet_main_t * vnm, u32 sw_if_index, u32 flags) |
| 901 | { |
| 902 | l2_input_config_t *config = l2input_intf_config (sw_if_index); |
| 903 | if ((flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) == 0 && config->bridge) |
| 904 | l2fib_flush_int_mac (vnm->vlib_main, sw_if_index); |
| 905 | return 0; |
| 906 | } |
| 907 | |
| 908 | VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (l2fib_sw_interface_up_down); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 909 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 910 | BVT (clib_bihash) * get_mac_table (void) |
| 911 | { |
| 912 | l2fib_main_t *mp = &l2fib_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 913 | return &mp->mac_table; |
| 914 | } |
| 915 | |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 916 | static uword |
| 917 | l2fib_mac_age_scanner_process (vlib_main_t * vm, vlib_node_runtime_t * rt, |
| 918 | vlib_frame_t * f) |
| 919 | { |
| 920 | uword event_type, *event_data = 0; |
| 921 | l2fib_main_t *msm = &l2fib_main; |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 922 | bool enabled = 0; |
| 923 | f64 start_time, last_run_duration = 0, t; |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 924 | |
| 925 | while (1) |
| 926 | { |
| 927 | if (enabled) |
| 928 | vlib_process_wait_for_event_or_clock (vm, 60 - last_run_duration); |
| 929 | else |
| 930 | vlib_process_wait_for_event (vm); |
| 931 | |
| 932 | event_type = vlib_process_get_events (vm, &event_data); |
| 933 | vec_reset_length (event_data); |
| 934 | |
| 935 | switch (event_type) |
| 936 | { |
| 937 | case ~0: |
| 938 | break; |
| 939 | case L2_MAC_AGE_PROCESS_EVENT_START: |
| 940 | enabled = 1; |
| 941 | break; |
| 942 | case L2_MAC_AGE_PROCESS_EVENT_STOP: |
| 943 | enabled = 0; |
| 944 | continue; |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 945 | case L2_MAC_AGE_PROCESS_EVENT_ONE_PASS: |
| 946 | enabled = 0; |
| 947 | break; |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 948 | default: |
| 949 | ASSERT (0); |
| 950 | } |
| 951 | last_run_duration = start_time = vlib_time_now (vm); |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 952 | |
| 953 | BVT (clib_bihash) * h = &msm->mac_table; |
| 954 | int i, j, k; |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 955 | for (i = 0; i < h->nbuckets; i++) |
| 956 | { |
| 957 | /* Allow no more than 10us without a pause */ |
| 958 | t = vlib_time_now (vm); |
| 959 | if (t > start_time + 10e-6) |
| 960 | { |
| 961 | vlib_process_suspend (vm, 100e-6); /* suspend for 100 us */ |
| 962 | start_time = vlib_time_now (vm); |
| 963 | } |
| 964 | |
| 965 | if (i < (h->nbuckets - 3)) |
| 966 | { |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 967 | clib_bihash_bucket_t *b = &h->buckets[i + 3]; |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 968 | CLIB_PREFETCH (b, CLIB_CACHE_LINE_BYTES, LOAD); |
| 969 | b = &h->buckets[i + 1]; |
| 970 | if (b->offset) |
| 971 | { |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 972 | BVT (clib_bihash_value) * v = |
| 973 | BV (clib_bihash_get_value) (h, b->offset); |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 974 | CLIB_PREFETCH (v, CLIB_CACHE_LINE_BYTES, LOAD); |
| 975 | } |
| 976 | } |
| 977 | |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 978 | clib_bihash_bucket_t *b = &h->buckets[i]; |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 979 | if (b->offset == 0) |
| 980 | continue; |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 981 | BVT (clib_bihash_value) * v = |
| 982 | BV (clib_bihash_get_value) (h, b->offset); |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 983 | for (j = 0; j < (1 << b->log2_pages); j++) |
| 984 | { |
| 985 | for (k = 0; k < BIHASH_KVP_PER_PAGE; k++) |
| 986 | { |
| 987 | if (v->kvp[k].key == ~0ULL && v->kvp[k].value == ~0ULL) |
| 988 | continue; |
| 989 | |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 990 | l2fib_entry_key_t key = {.raw = v->kvp[k].key }; |
| 991 | l2fib_entry_result_t result = {.raw = v->kvp[k].value }; |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 992 | |
| 993 | if (result.fields.static_mac) |
| 994 | continue; |
| 995 | |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 996 | u32 bd_index = key.fields.bd_index; |
| 997 | u32 sw_if_index = result.fields.sw_if_index; |
| 998 | u16 sn = l2fib_cur_seq_num (bd_index, sw_if_index).as_u16; |
| 999 | if (result.fields.sn.as_u16 != sn) |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 1000 | { |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 1001 | l2fib_del_entry_by_key (key.raw); |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 1002 | continue; |
| 1003 | } |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 1004 | l2_bridge_domain_t *bd_config = |
| 1005 | vec_elt_at_index (l2input_main.bd_configs, bd_index); |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 1006 | |
| 1007 | if (bd_config->mac_age == 0) |
| 1008 | continue; |
| 1009 | |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 1010 | i16 delta = |
| 1011 | (u8) (start_time / 60) - result.fields.timestamp; |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 1012 | delta += delta < 0 ? 256 : 0; |
| 1013 | |
| 1014 | if (delta > bd_config->mac_age) |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 1015 | l2fib_del_entry_by_key (key.raw); |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 1016 | } |
| 1017 | v++; |
| 1018 | } |
| 1019 | } |
| 1020 | last_run_duration = vlib_time_now (vm) - last_run_duration; |
| 1021 | } |
| 1022 | return 0; |
| 1023 | } |
| 1024 | |
| 1025 | /* *INDENT-OFF* */ |
| 1026 | VLIB_REGISTER_NODE (l2fib_mac_age_scanner_process_node) = { |
| 1027 | .function = l2fib_mac_age_scanner_process, |
| 1028 | .type = VLIB_NODE_TYPE_PROCESS, |
| 1029 | .name = "l2fib-mac-age-scanner-process", |
| 1030 | }; |
| 1031 | /* *INDENT-ON* */ |
| 1032 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1033 | clib_error_t * |
| 1034 | l2fib_init (vlib_main_t * vm) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1035 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1036 | l2fib_main_t *mp = &l2fib_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1037 | l2fib_entry_key_t test_key; |
| 1038 | u8 test_mac[6]; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1039 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1040 | mp->vlib_main = vm; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1041 | mp->vnet_main = vnet_get_main (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1042 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1043 | /* Create the hash table */ |
| 1044 | BV (clib_bihash_init) (&mp->mac_table, "l2fib mac table", |
| 1045 | L2FIB_NUM_BUCKETS, L2FIB_MEMORY_SIZE); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1046 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1047 | /* verify the key constructor is good, since it is endian-sensitive */ |
| 1048 | memset (test_mac, 0, sizeof (test_mac)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1049 | test_mac[0] = 0x11; |
| 1050 | test_key.raw = 0; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1051 | test_key.raw = l2fib_make_key ((u8 *) & test_mac, 0x1234); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1052 | ASSERT (test_key.fields.mac[0] == 0x11); |
| 1053 | ASSERT (test_key.fields.bd_index == 0x1234); |
| 1054 | |
| 1055 | return 0; |
| 1056 | } |
| 1057 | |
| 1058 | VLIB_INIT_FUNCTION (l2fib_init); |
| 1059 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1060 | /* |
| 1061 | * fd.io coding-style-patch-verification: ON |
| 1062 | * |
| 1063 | * Local Variables: |
| 1064 | * eval: (c-set-style "gnu") |
| 1065 | * End: |
| 1066 | */ |