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 | |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 34 | #include <vlibmemory/api.h> |
| 35 | #include <vnet/vnet_msg_enum.h> |
| 36 | |
| 37 | #define vl_typedefs /* define message structures */ |
| 38 | #include <vnet/vnet_all_api_h.h> |
| 39 | #undef vl_typedefs |
| 40 | |
| 41 | #define vl_endianfun /* define message structures */ |
| 42 | #include <vnet/vnet_all_api_h.h> |
| 43 | #undef vl_endianfun |
| 44 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 45 | /** |
| 46 | * @file |
| 47 | * @brief Ethernet MAC Address FIB Table Management. |
| 48 | * |
| 49 | * The MAC Address forwarding table for bridge-domains is called the l2fib. |
| 50 | * Entries are added automatically as part of mac learning, but MAC Addresses |
| 51 | * entries can also be added manually. |
| 52 | * |
| 53 | */ |
| 54 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 55 | l2fib_main_t l2fib_main; |
| 56 | |
Neale Ranns | 7d645f7 | 2018-10-24 02:25:06 -0700 | [diff] [blame] | 57 | u8 * |
| 58 | format_l2fib_entry_result_flags (u8 * s, va_list * args) |
| 59 | { |
| 60 | l2fib_entry_result_flags_t flags = va_arg (*args, int); |
| 61 | |
| 62 | if (L2FIB_ENTRY_RESULT_FLAG_NONE == flags) |
| 63 | { |
| 64 | s = format (s, "none"); |
| 65 | } |
| 66 | else |
| 67 | { |
| 68 | #define _(a,v,t) { \ |
| 69 | if (flags & L2FIB_ENTRY_RESULT_FLAG_##a) \ |
| 70 | s = format (s, "%s ", t); \ |
| 71 | } |
| 72 | foreach_l2fib_entry_result_attr |
| 73 | #undef _ |
| 74 | } |
| 75 | return (s); |
| 76 | } |
| 77 | |
Mohsin Kazmi | 57938f6 | 2017-10-27 21:28:07 +0200 | [diff] [blame] | 78 | static void |
| 79 | incr_mac_address (u8 * mac) |
| 80 | { |
| 81 | u64 tmp = *((u64 *) mac); |
| 82 | tmp = clib_net_to_host_u64 (tmp); |
| 83 | tmp += 1 << 16; /* skip unused (least significant) octets */ |
| 84 | tmp = clib_host_to_net_u64 (tmp); |
| 85 | |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 86 | clib_memcpy_fast (mac, &tmp, 6); |
Mohsin Kazmi | 57938f6 | 2017-10-27 21:28:07 +0200 | [diff] [blame] | 87 | } |
| 88 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 89 | /** Format sw_if_index. If the value is ~0, use the text "N/A" */ |
| 90 | u8 * |
| 91 | 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] | 92 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 93 | vnet_main_t *vnm = va_arg (*args, vnet_main_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 94 | u32 sw_if_index = va_arg (*args, u32); |
| 95 | if (sw_if_index == ~0) |
| 96 | return format (s, "N/A"); |
Eyal Bari | b823df5 | 2017-06-12 17:07:22 +0300 | [diff] [blame] | 97 | |
Dave Barach | 3940de3 | 2019-07-23 16:28:36 -0400 | [diff] [blame^] | 98 | vnet_sw_interface_t *swif = |
| 99 | vnet_get_sw_interface_or_null (vnm, sw_if_index); |
Eyal Bari | b823df5 | 2017-06-12 17:07:22 +0300 | [diff] [blame] | 100 | if (!swif) |
Eyal Bari | 0f360dc | 2017-06-14 13:11:20 +0300 | [diff] [blame] | 101 | return format (s, "Stale"); |
Eyal Bari | b823df5 | 2017-06-12 17:07:22 +0300 | [diff] [blame] | 102 | |
| 103 | return format (s, "%U", format_vnet_sw_interface_name, vnm, |
Dave Barach | 3940de3 | 2019-07-23 16:28:36 -0400 | [diff] [blame^] | 104 | vnet_get_sw_interface_or_null (vnm, sw_if_index)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Neale Ranns | 99a3c6c | 2018-08-07 02:54:31 -0700 | [diff] [blame] | 107 | typedef struct l2fib_dump_walk_ctx_t_ |
| 108 | { |
| 109 | u32 bd_index; |
| 110 | l2fib_entry_key_t *l2fe_key; |
| 111 | l2fib_entry_result_t *l2fe_res; |
| 112 | } l2fib_dump_walk_ctx_t; |
| 113 | |
| 114 | static void |
| 115 | l2fib_dump_walk_cb (BVT (clib_bihash_kv) * kvp, void *arg) |
| 116 | { |
| 117 | l2fib_dump_walk_ctx_t *ctx = arg; |
| 118 | l2fib_entry_result_t result; |
| 119 | l2fib_entry_key_t key; |
| 120 | |
| 121 | key.raw = kvp->key; |
| 122 | result.raw = kvp->value; |
| 123 | |
| 124 | if ((ctx->bd_index == ~0) || (ctx->bd_index == key.fields.bd_index)) |
| 125 | { |
| 126 | vec_add1 (ctx->l2fe_key, key); |
| 127 | vec_add1 (ctx->l2fe_res, result); |
| 128 | } |
| 129 | } |
| 130 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 131 | void |
Neale Ranns | 99a3c6c | 2018-08-07 02:54:31 -0700 | [diff] [blame] | 132 | l2fib_table_dump (u32 bd_index, |
| 133 | l2fib_entry_key_t ** l2fe_key, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 134 | l2fib_entry_result_t ** l2fe_res) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 135 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 136 | l2fib_main_t *msm = &l2fib_main; |
Neale Ranns | 99a3c6c | 2018-08-07 02:54:31 -0700 | [diff] [blame] | 137 | l2fib_dump_walk_ctx_t ctx = { |
| 138 | .bd_index = bd_index, |
| 139 | }; |
| 140 | |
| 141 | BV (clib_bihash_foreach_key_value_pair) |
| 142 | (&msm->mac_table, l2fib_dump_walk_cb, &ctx); |
| 143 | |
| 144 | *l2fe_key = ctx.l2fe_key; |
| 145 | *l2fe_res = ctx.l2fe_res; |
| 146 | } |
| 147 | |
| 148 | typedef struct l2fib_show_walk_ctx_t_ |
| 149 | { |
| 150 | u8 first_entry; |
| 151 | u8 verbose; |
| 152 | vlib_main_t *vm; |
| 153 | vnet_main_t *vnm; |
| 154 | u32 total_entries; |
| 155 | u32 bd_index; |
| 156 | u8 learn; |
| 157 | u8 add; |
| 158 | u8 now; |
| 159 | } l2fib_show_walk_ctx_t; |
| 160 | |
| 161 | static void |
| 162 | l2fib_show_walk_cb (BVT (clib_bihash_kv) * kvp, void *arg) |
| 163 | { |
| 164 | l2fib_show_walk_ctx_t *ctx = arg; |
| 165 | l2_bridge_domain_t *bd_config; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 166 | l2fib_entry_result_t result; |
Neale Ranns | 99a3c6c | 2018-08-07 02:54:31 -0700 | [diff] [blame] | 167 | l2fib_entry_key_t key; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 168 | |
Neale Ranns | 99a3c6c | 2018-08-07 02:54:31 -0700 | [diff] [blame] | 169 | if (ctx->verbose && ctx->first_entry) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 170 | { |
Neale Ranns | 99a3c6c | 2018-08-07 02:54:31 -0700 | [diff] [blame] | 171 | ctx->first_entry = 0; |
| 172 | vlib_cli_output (ctx->vm, |
| 173 | "%=19s%=7s%=7s%=8s%=9s%=7s%=7s%=5s%=30s", |
| 174 | "Mac-Address", "BD-Idx", "If-Idx", |
| 175 | "BSN-ISN", "Age(min)", "static", "filter", |
| 176 | "bvi", "Interface-Name"); |
| 177 | } |
| 178 | |
| 179 | key.raw = kvp->key; |
| 180 | result.raw = kvp->value; |
| 181 | ctx->total_entries++; |
| 182 | |
| 183 | if (ctx->verbose && |
| 184 | ((ctx->bd_index >> 31) || (ctx->bd_index == key.fields.bd_index))) |
| 185 | { |
| 186 | u8 *s = NULL; |
| 187 | |
Neale Ranns | b54d081 | 2018-09-06 06:22:56 -0700 | [diff] [blame] | 188 | if (ctx->learn && l2fib_entry_result_is_set_AGE_NOT (&result)) |
Neale Ranns | 99a3c6c | 2018-08-07 02:54:31 -0700 | [diff] [blame] | 189 | return; /* skip provisioned macs */ |
| 190 | |
Neale Ranns | b54d081 | 2018-09-06 06:22:56 -0700 | [diff] [blame] | 191 | if (ctx->add && !l2fib_entry_result_is_set_AGE_NOT (&result)) |
Neale Ranns | 99a3c6c | 2018-08-07 02:54:31 -0700 | [diff] [blame] | 192 | return; /* skip learned macs */ |
| 193 | |
| 194 | bd_config = vec_elt_at_index (l2input_main.bd_configs, |
| 195 | key.fields.bd_index); |
| 196 | |
Neale Ranns | b54d081 | 2018-09-06 06:22:56 -0700 | [diff] [blame] | 197 | if (l2fib_entry_result_is_set_AGE_NOT (&result)) |
Neale Ranns | 99a3c6c | 2018-08-07 02:54:31 -0700 | [diff] [blame] | 198 | s = format (s, "no"); |
| 199 | else if (bd_config->mac_age == 0) |
| 200 | s = format (s, "-"); |
| 201 | else |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 202 | { |
Neale Ranns | 99a3c6c | 2018-08-07 02:54:31 -0700 | [diff] [blame] | 203 | i16 delta = ctx->now - result.fields.timestamp; |
| 204 | delta += delta < 0 ? 256 : 0; |
| 205 | s = format (s, "%d", delta); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 206 | } |
Neale Ranns | 99a3c6c | 2018-08-07 02:54:31 -0700 | [diff] [blame] | 207 | |
| 208 | vlib_cli_output (ctx->vm, |
| 209 | "%=19U%=7d%=7d %3d/%-3d%=9v%=7s%=7s%=5s%=30U", |
| 210 | format_ethernet_address, key.fields.mac, |
| 211 | key.fields.bd_index, |
| 212 | result.fields.sw_if_index == ~0 |
| 213 | ? -1 : result.fields.sw_if_index, |
Neale Ranns | b54d081 | 2018-09-06 06:22:56 -0700 | [diff] [blame] | 214 | result.fields.sn.bd, result.fields.sn.swif, s, |
| 215 | l2fib_entry_result_is_set_STATIC (&result) ? "*" : "-", |
| 216 | l2fib_entry_result_is_set_FILTER (&result) ? "*" : "-", |
| 217 | l2fib_entry_result_is_set_BVI (&result) ? "*" : "-", |
Neale Ranns | 99a3c6c | 2018-08-07 02:54:31 -0700 | [diff] [blame] | 218 | format_vnet_sw_if_index_name_with_NA, |
| 219 | ctx->vnm, result.fields.sw_if_index); |
| 220 | vec_free (s); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 221 | } |
| 222 | } |
| 223 | |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 224 | /** Display the contents of the l2fib. */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 225 | static clib_error_t * |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 226 | show_l2fib (vlib_main_t * vm, |
| 227 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 228 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 229 | bd_main_t *bdm = &bd_main; |
| 230 | l2fib_main_t *msm = &l2fib_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 231 | u8 raw = 0; |
Neale Ranns | 99a3c6c | 2018-08-07 02:54:31 -0700 | [diff] [blame] | 232 | u32 bd_id; |
| 233 | l2fib_show_walk_ctx_t ctx = { |
| 234 | .first_entry = 1, |
| 235 | .bd_index = ~0, |
| 236 | .now = (u8) (vlib_time_now (vm) / 60), |
| 237 | .vm = vm, |
| 238 | .vnm = msm->vnet_main, |
| 239 | }; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 240 | |
John Lo | 7dbd726 | 2018-05-31 10:25:18 -0400 | [diff] [blame] | 241 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 242 | { |
John Lo | 7dbd726 | 2018-05-31 10:25:18 -0400 | [diff] [blame] | 243 | if (unformat (input, "raw")) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 244 | { |
John Lo | 7dbd726 | 2018-05-31 10:25:18 -0400 | [diff] [blame] | 245 | raw = 1; |
Neale Ranns | 99a3c6c | 2018-08-07 02:54:31 -0700 | [diff] [blame] | 246 | ctx.verbose = 0; |
John Lo | 7dbd726 | 2018-05-31 10:25:18 -0400 | [diff] [blame] | 247 | break; |
| 248 | } |
| 249 | else if (unformat (input, "verbose")) |
Neale Ranns | 99a3c6c | 2018-08-07 02:54:31 -0700 | [diff] [blame] | 250 | ctx.verbose = 1; |
John Lo | 7dbd726 | 2018-05-31 10:25:18 -0400 | [diff] [blame] | 251 | else if (unformat (input, "all")) |
Neale Ranns | 99a3c6c | 2018-08-07 02:54:31 -0700 | [diff] [blame] | 252 | ctx.verbose = 1; |
| 253 | else if (unformat (input, "bd_index %d", &ctx.bd_index)) |
| 254 | ctx.verbose = 1; |
John Lo | 7dbd726 | 2018-05-31 10:25:18 -0400 | [diff] [blame] | 255 | else if (unformat (input, "learn")) |
| 256 | { |
Neale Ranns | 99a3c6c | 2018-08-07 02:54:31 -0700 | [diff] [blame] | 257 | ctx.add = 0; |
| 258 | ctx.learn = 1; |
| 259 | ctx.verbose = 1; |
John Lo | 7dbd726 | 2018-05-31 10:25:18 -0400 | [diff] [blame] | 260 | } |
| 261 | else if (unformat (input, "add")) |
| 262 | { |
Neale Ranns | 99a3c6c | 2018-08-07 02:54:31 -0700 | [diff] [blame] | 263 | ctx.learn = 0; |
| 264 | ctx.add = 1; |
| 265 | ctx.verbose = 1; |
John Lo | 7dbd726 | 2018-05-31 10:25:18 -0400 | [diff] [blame] | 266 | } |
| 267 | else if (unformat (input, "bd_id %d", &bd_id)) |
| 268 | { |
| 269 | uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 270 | if (p) |
| 271 | { |
Neale Ranns | 99a3c6c | 2018-08-07 02:54:31 -0700 | [diff] [blame] | 272 | ctx.verbose = 1; |
| 273 | ctx.bd_index = p[0]; |
John Lo | 7dbd726 | 2018-05-31 10:25:18 -0400 | [diff] [blame] | 274 | } |
| 275 | else |
| 276 | return clib_error_return (0, |
| 277 | "bridge domain id %d doesn't exist\n", |
| 278 | bd_id); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 279 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 280 | else |
John Lo | 7dbd726 | 2018-05-31 10:25:18 -0400 | [diff] [blame] | 281 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Neale Ranns | 99a3c6c | 2018-08-07 02:54:31 -0700 | [diff] [blame] | 284 | BV (clib_bihash_foreach_key_value_pair) |
| 285 | (&msm->mac_table, l2fib_show_walk_cb, &ctx); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 286 | |
Neale Ranns | 99a3c6c | 2018-08-07 02:54:31 -0700 | [diff] [blame] | 287 | if (ctx.total_entries == 0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 288 | vlib_cli_output (vm, "no l2fib entries"); |
| 289 | else |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 290 | { |
| 291 | l2learn_main_t *lm = &l2learn_main; |
| 292 | vlib_cli_output (vm, "L2FIB total/learned entries: %d/%d " |
| 293 | "Last scan time: %.4esec Learn limit: %d ", |
Neale Ranns | 99a3c6c | 2018-08-07 02:54:31 -0700 | [diff] [blame] | 294 | ctx.total_entries, lm->global_learn_count, |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 295 | msm->age_scan_duration, lm->global_learn_limit); |
| 296 | if (lm->client_pid) |
| 297 | vlib_cli_output (vm, "L2MAC events client PID: %d " |
| 298 | "Last e-scan time: %.4esec Delay: %.2esec " |
| 299 | "Max macs in event: %d", |
| 300 | lm->client_pid, msm->evt_scan_duration, |
| 301 | msm->event_scan_delay, msm->max_macs_in_event); |
| 302 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 303 | |
| 304 | if (raw) |
| 305 | vlib_cli_output (vm, "Raw Hash Table:\n%U\n", |
Neale Ranns | 99a3c6c | 2018-08-07 02:54:31 -0700 | [diff] [blame] | 306 | BV (format_bihash), &msm->mac_table, 1 /* verbose */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 307 | |
| 308 | return 0; |
| 309 | } |
| 310 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 311 | /*? |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 312 | * This command displays the MAC Address entries of the L2 FIB table. |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 313 | * Output can be filtered to just get the number of MAC Addresses or display |
| 314 | * each MAC Address for all bridge domains or just a single bridge domain. |
| 315 | * |
| 316 | * @cliexpar |
| 317 | * Example of how to display the number of MAC Address entries in the L2 |
| 318 | * FIB table: |
| 319 | * @cliexstart{show l2fib} |
| 320 | * 3 l2fib entries |
| 321 | * @cliexend |
| 322 | * Example of how to display all the MAC Address entries in the L2 |
| 323 | * FIB table: |
John Lo | 7dbd726 | 2018-05-31 10:25:18 -0400 | [diff] [blame] | 324 | * @cliexstart{show l2fib all} |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 325 | * Mac Address BD Idx Interface Index static filter bvi refresh timestamp |
| 326 | * 52:54:00:53:18:33 1 GigabitEthernet0/8/0.200 3 0 0 0 0 0 |
| 327 | * 52:54:00:53:18:55 1 GigabitEthernet0/8/0.200 3 1 0 0 0 0 |
| 328 | * 52:54:00:53:18:77 1 N/A -1 1 1 0 0 0 |
| 329 | * 3 l2fib entries |
| 330 | * @cliexend |
| 331 | ?*/ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 332 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 333 | VLIB_CLI_COMMAND (show_l2fib_cli, static) = { |
| 334 | .path = "show l2fib", |
John Lo | 7dbd726 | 2018-05-31 10:25:18 -0400 | [diff] [blame] | 335 | .short_help = "show l2fib [all] | [bd_id <nn> | bd_index <nn>] [learn | add] | [raw]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 336 | .function = show_l2fib, |
| 337 | }; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 338 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 339 | |
| 340 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 341 | /* Remove all entries from the l2fib */ |
| 342 | void |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 343 | l2fib_clear_table (void) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 344 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 345 | l2fib_main_t *mp = &l2fib_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 346 | |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 347 | /* Remove all entries */ |
| 348 | BV (clib_bihash_free) (&mp->mac_table); |
| 349 | BV (clib_bihash_init) (&mp->mac_table, "l2fib mac table", |
| 350 | L2FIB_NUM_BUCKETS, L2FIB_MEMORY_SIZE); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 351 | l2learn_main.global_learn_count = 0; |
| 352 | } |
| 353 | |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 354 | /** Clear all entries in L2FIB. |
| 355 | * @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] | 356 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 357 | static clib_error_t * |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 358 | clear_l2fib (vlib_main_t * vm, |
| 359 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 360 | { |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 361 | l2fib_clear_table (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 362 | return 0; |
| 363 | } |
| 364 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 365 | /*? |
| 366 | * This command clears all the MAC Address entries from the L2 FIB table. |
| 367 | * |
| 368 | * @cliexpar |
| 369 | * Example of how to clear the L2 FIB Table: |
| 370 | * @cliexcmd{clear l2fib} |
| 371 | * Example to show the L2 FIB Table has been cleared: |
| 372 | * @cliexstart{show l2fib verbose} |
| 373 | * no l2fib entries |
| 374 | * @cliexend |
| 375 | ?*/ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 376 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 377 | VLIB_CLI_COMMAND (clear_l2fib_cli, static) = { |
| 378 | .path = "clear l2fib", |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 379 | .short_help = "clear l2fib", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 380 | .function = clear_l2fib, |
| 381 | }; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 382 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 383 | |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 384 | static inline l2fib_seq_num_t |
| 385 | l2fib_cur_seq_num (u32 bd_index, u32 sw_if_index) |
| 386 | { |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 387 | l2_bridge_domain_t *bd_config = l2input_bd_config (bd_index); |
| 388 | /* *INDENT-OFF* */ |
| 389 | return (l2fib_seq_num_t) { |
Eyal Bari | 0f360dc | 2017-06-14 13:11:20 +0300 | [diff] [blame] | 390 | .swif = *l2fib_swif_seq_num (sw_if_index), |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 391 | .bd = bd_config->seq_num, |
| 392 | }; |
| 393 | /* *INDENT-ON* */ |
| 394 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 395 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 396 | /** |
| 397 | * Add an entry to the l2fib. |
| 398 | * If the entry already exists then overwrite it |
| 399 | */ |
| 400 | void |
Neale Ranns | 3b81a1e | 2018-09-06 09:50:26 -0700 | [diff] [blame] | 401 | l2fib_add_entry (const u8 * mac, u32 bd_index, |
Neale Ranns | b54d081 | 2018-09-06 06:22:56 -0700 | [diff] [blame] | 402 | u32 sw_if_index, l2fib_entry_result_flags_t flags) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 403 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 404 | l2fib_entry_key_t key; |
| 405 | l2fib_entry_result_t result; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 406 | __attribute__ ((unused)) u32 bucket_contents; |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 407 | l2fib_main_t *fm = &l2fib_main; |
| 408 | l2learn_main_t *lm = &l2learn_main; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 409 | BVT (clib_bihash_kv) kv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 410 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 411 | /* set up key */ |
Mohsin Kazmi | 57938f6 | 2017-10-27 21:28:07 +0200 | [diff] [blame] | 412 | key.raw = l2fib_make_key (mac, bd_index); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 413 | |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 414 | /* check if entry already exist */ |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 415 | if (BV (clib_bihash_search) (&fm->mac_table, &kv, &kv)) |
| 416 | { |
| 417 | /* decrement counter if overwriting a learned mac */ |
| 418 | result.raw = kv.value; |
Neale Ranns | b54d081 | 2018-09-06 06:22:56 -0700 | [diff] [blame] | 419 | if ((!l2fib_entry_result_is_set_AGE_NOT (&result)) |
| 420 | && (lm->global_learn_count)) |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 421 | lm->global_learn_count--; |
| 422 | } |
| 423 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 424 | /* set up result */ |
| 425 | result.raw = 0; /* clear all fields */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 426 | result.fields.sw_if_index = sw_if_index; |
Neale Ranns | b54d081 | 2018-09-06 06:22:56 -0700 | [diff] [blame] | 427 | result.fields.flags = flags; |
| 428 | |
| 429 | /* no aging for provisioned entry */ |
| 430 | l2fib_entry_result_set_AGE_NOT (&result); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 431 | |
| 432 | kv.key = key.raw; |
| 433 | kv.value = result.raw; |
| 434 | |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 435 | BV (clib_bihash_add_del) (&fm->mac_table, &kv, 1 /* is_add */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 436 | } |
| 437 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 438 | /** |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 439 | * Add an entry to the L2FIB. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 440 | * The CLI format is: |
| 441 | * l2fib add <mac> <bd> <intf> [static] [bvi] |
| 442 | * l2fib add <mac> <bd> filter |
| 443 | * Note that filter and bvi entries are always static |
| 444 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 445 | static clib_error_t * |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 446 | l2fib_add (vlib_main_t * vm, |
| 447 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 448 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 449 | bd_main_t *bdm = &bd_main; |
| 450 | vnet_main_t *vnm = vnet_get_main (); |
| 451 | clib_error_t *error = 0; |
Mohsin Kazmi | 57938f6 | 2017-10-27 21:28:07 +0200 | [diff] [blame] | 452 | u8 mac[6]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 453 | u32 bd_id; |
| 454 | u32 bd_index; |
| 455 | u32 sw_if_index = ~0; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 456 | uword *p; |
Neale Ranns | b54d081 | 2018-09-06 06:22:56 -0700 | [diff] [blame] | 457 | l2fib_entry_result_flags_t flags; |
| 458 | |
| 459 | flags = L2FIB_ENTRY_RESULT_FLAG_NONE; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 460 | |
Mohsin Kazmi | 57938f6 | 2017-10-27 21:28:07 +0200 | [diff] [blame] | 461 | if (!unformat (input, "%U", unformat_ethernet_address, mac)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 462 | { |
| 463 | error = clib_error_return (0, "expected mac address `%U'", |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 464 | format_unformat_error, input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 465 | goto done; |
| 466 | } |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 467 | |
| 468 | if (!unformat (input, "%d", &bd_id)) |
| 469 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 470 | error = clib_error_return (0, "expected bridge domain ID `%U'", |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 471 | format_unformat_error, input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 472 | goto done; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 473 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 474 | |
| 475 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 476 | if (!p) |
| 477 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 478 | error = clib_error_return (0, "bridge domain ID %d invalid", bd_id); |
| 479 | goto done; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 480 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 481 | bd_index = p[0]; |
| 482 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 483 | if (unformat (input, "filter")) |
| 484 | { |
John Lo | 14edd97 | 2017-10-31 13:26:02 -0400 | [diff] [blame] | 485 | l2fib_add_filter_entry (mac, bd_index); |
| 486 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 487 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 488 | |
John Lo | 14edd97 | 2017-10-31 13:26:02 -0400 | [diff] [blame] | 489 | if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 490 | { |
| 491 | error = clib_error_return (0, "unknown interface `%U'", |
| 492 | format_unformat_error, input); |
| 493 | goto done; |
| 494 | } |
| 495 | |
| 496 | if (unformat (input, "static")) |
Neale Ranns | b54d081 | 2018-09-06 06:22:56 -0700 | [diff] [blame] | 497 | flags |= L2FIB_ENTRY_RESULT_FLAG_STATIC; |
John Lo | 14edd97 | 2017-10-31 13:26:02 -0400 | [diff] [blame] | 498 | else if (unformat (input, "bvi")) |
Neale Ranns | b54d081 | 2018-09-06 06:22:56 -0700 | [diff] [blame] | 499 | flags |= (L2FIB_ENTRY_RESULT_FLAG_STATIC | L2FIB_ENTRY_RESULT_FLAG_BVI); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 500 | |
John Lo | b2fd6cb | 2017-07-12 19:56:45 -0400 | [diff] [blame] | 501 | if (vec_len (l2input_main.configs) <= sw_if_index) |
| 502 | { |
| 503 | error = clib_error_return (0, "Interface sw_if_index %d not in L2 mode", |
| 504 | sw_if_index); |
| 505 | goto done; |
| 506 | } |
| 507 | |
Neale Ranns | b54d081 | 2018-09-06 06:22:56 -0700 | [diff] [blame] | 508 | l2fib_add_entry (mac, bd_index, sw_if_index, flags); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 509 | |
| 510 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 511 | return error; |
| 512 | } |
| 513 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 514 | /*? |
| 515 | * This command adds a MAC Address entry to the L2 FIB table |
| 516 | * of an existing bridge-domain. The MAC Address can be static |
| 517 | * or dynamic. This command also allows a filter to be added, |
| 518 | * such that packets with given MAC Addresses (source mac or |
| 519 | * destination mac match) are dropped. |
| 520 | * |
| 521 | * @cliexpar |
| 522 | * Example of how to add a dynamic MAC Address entry to the L2 FIB table |
| 523 | * of a bridge-domain (where 200 is the bridge-domain-id): |
| 524 | * @cliexcmd{l2fib add 52:54:00:53:18:33 200 GigabitEthernet0/8/0.200} |
| 525 | * Example of how to add a static MAC Address entry to the L2 FIB table |
| 526 | * of a bridge-domain (where 200 is the bridge-domain-id): |
| 527 | * @cliexcmd{l2fib add 52:54:00:53:18:55 200 GigabitEthernet0/8/0.200 static} |
| 528 | * Example of how to add a filter such that a packet with the given MAC |
| 529 | * Address will be dropped in a given bridge-domain (where 200 is the |
| 530 | * bridge-domain-id): |
| 531 | * @cliexcmd{l2fib add 52:54:00:53:18:77 200 filter} |
| 532 | * Example of show command of the provisioned MAC Addresses and filters: |
| 533 | * @cliexstart{show l2fib verbose} |
| 534 | * Mac Address BD Idx Interface Index static filter bvi refresh timestamp |
| 535 | * 52:54:00:53:18:33 1 GigabitEthernet0/8/0.200 3 0 0 0 0 0 |
| 536 | * 52:54:00:53:18:55 1 GigabitEthernet0/8/0.200 3 1 0 0 0 0 |
| 537 | * 52:54:00:53:18:77 1 N/A -1 1 1 0 0 0 |
| 538 | * 3 l2fib entries |
| 539 | * @cliexend |
| 540 | ?*/ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 541 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 542 | VLIB_CLI_COMMAND (l2fib_add_cli, static) = { |
| 543 | .path = "l2fib add", |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 544 | .short_help = "l2fib add <mac> <bridge-domain-id> filter | <intf> [static | bvi]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 545 | .function = l2fib_add, |
| 546 | }; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 547 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 548 | |
| 549 | |
| 550 | static clib_error_t * |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 551 | l2fib_test_command_fn (vlib_main_t * vm, |
| 552 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 553 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 554 | clib_error_t *error = 0; |
Mohsin Kazmi | 57938f6 | 2017-10-27 21:28:07 +0200 | [diff] [blame] | 555 | u8 mac[6], save_mac[6]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 556 | u32 bd_index = 0; |
| 557 | u32 sw_if_index = 8; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 558 | u32 is_add = 0; |
| 559 | u32 is_del = 0; |
| 560 | u32 is_check = 0; |
| 561 | u32 count = 1; |
| 562 | int mac_set = 0; |
| 563 | int i; |
| 564 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 565 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 566 | { |
Mohsin Kazmi | 57938f6 | 2017-10-27 21:28:07 +0200 | [diff] [blame] | 567 | if (unformat (input, "mac %U", unformat_ethernet_address, mac)) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 568 | mac_set = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 569 | else if (unformat (input, "add")) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 570 | is_add = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 571 | else if (unformat (input, "del")) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 572 | is_del = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 573 | else if (unformat (input, "check")) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 574 | is_check = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 575 | else if (unformat (input, "count %d", &count)) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 576 | ; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 577 | else |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 578 | break; |
| 579 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 580 | |
| 581 | if (mac_set == 0) |
| 582 | return clib_error_return (0, "mac not set"); |
| 583 | |
| 584 | if (is_add == 0 && is_del == 0 && is_check == 0) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 585 | return clib_error_return (0, |
| 586 | "noop: pick at least one of (add,del,check)"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 587 | |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 588 | clib_memcpy_fast (save_mac, mac, 6); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 589 | |
| 590 | if (is_add) |
| 591 | { |
| 592 | for (i = 0; i < count; i++) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 593 | { |
Neale Ranns | b54d081 | 2018-09-06 06:22:56 -0700 | [diff] [blame] | 594 | l2fib_add_entry (mac, bd_index, sw_if_index, |
| 595 | L2FIB_ENTRY_RESULT_FLAG_NONE); |
Mohsin Kazmi | 57938f6 | 2017-10-27 21:28:07 +0200 | [diff] [blame] | 596 | incr_mac_address (mac); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 597 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | if (is_check) |
| 601 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 602 | BVT (clib_bihash_kv) kv; |
| 603 | l2fib_main_t *mp = &l2fib_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 604 | |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 605 | clib_memcpy_fast (mac, save_mac, 6); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 606 | |
| 607 | for (i = 0; i < count; i++) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 608 | { |
Mohsin Kazmi | 57938f6 | 2017-10-27 21:28:07 +0200 | [diff] [blame] | 609 | kv.key = l2fib_make_key (mac, bd_index); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 610 | if (BV (clib_bihash_search) (&mp->mac_table, &kv, &kv)) |
| 611 | { |
Mohsin Kazmi | 57938f6 | 2017-10-27 21:28:07 +0200 | [diff] [blame] | 612 | clib_warning ("key %U AWOL", format_ethernet_address, mac); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 613 | break; |
| 614 | } |
Mohsin Kazmi | 57938f6 | 2017-10-27 21:28:07 +0200 | [diff] [blame] | 615 | incr_mac_address (mac); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 616 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | if (is_del) |
| 620 | { |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 621 | clib_memcpy_fast (mac, save_mac, 6); |
Mohsin Kazmi | 57938f6 | 2017-10-27 21:28:07 +0200 | [diff] [blame] | 622 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 623 | for (i = 0; i < count; i++) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 624 | { |
John Lo | 7dbd726 | 2018-05-31 10:25:18 -0400 | [diff] [blame] | 625 | l2fib_del_entry (mac, bd_index, 0); |
Mohsin Kazmi | 57938f6 | 2017-10-27 21:28:07 +0200 | [diff] [blame] | 626 | incr_mac_address (mac); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 627 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | return error; |
| 631 | } |
| 632 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 633 | /*? |
| 634 | * The set of '<em>test l2fib</em>' commands allow the L2 FIB table of the default |
| 635 | * bridge domain (bridge-domain-id of 0) to be modified. |
| 636 | * |
| 637 | * @cliexpar |
| 638 | * @parblock |
| 639 | * Example of how to add a set of 4 sequential MAC Address entries to L2 |
| 640 | * FIB table of the default bridge-domain: |
| 641 | * @cliexcmd{test l2fib add mac 52:54:00:53:00:00 count 4} |
| 642 | * |
| 643 | * Show the set of 4 sequential MAC Address entries that were added: |
| 644 | * @cliexstart{show l2fib verbose} |
| 645 | * Mac Address BD Idx Interface Index static filter bvi refresh timestamp |
| 646 | * 52:54:00:53:00:00 0 GigabitEthernet0/8/0.300 8 0 0 0 0 0 |
| 647 | * 52:54:00:53:00:01 0 GigabitEthernet0/8/0.300 8 0 0 0 0 0 |
| 648 | * 52:54:00:53:00:03 0 GigabitEthernet0/8/0.300 8 0 0 0 0 0 |
| 649 | * 52:54:00:53:00:02 0 GigabitEthernet0/8/0.300 8 0 0 0 0 0 |
| 650 | * 4 l2fib entries |
| 651 | * @cliexend |
| 652 | * |
| 653 | * Example of how to check that the set of 4 sequential MAC Address |
| 654 | * entries were added to L2 FIB table of the default |
| 655 | * bridge-domain. Used a count of 5 to produce an error: |
| 656 | * |
| 657 | * @cliexcmd{test l2fib check mac 52:54:00:53:00:00 count 5} |
| 658 | * The output of the check command is in the log files. Log file |
| 659 | * location may vary based on your OS and Version: |
| 660 | * |
| 661 | * <b><em># tail -f /var/log/messages | grep l2fib_test_command_fn</em></b> |
| 662 | * |
| 663 | * Sep 7 17:15:24 localhost vnet[4952]: l2fib_test_command_fn:446: key 52:54:00:53:00:04 AWOL |
| 664 | * |
| 665 | * Example of how to delete a set of 4 sequential MAC Address entries |
| 666 | * from L2 FIB table of the default bridge-domain: |
| 667 | * @cliexcmd{test l2fib del mac 52:54:00:53:00:00 count 4} |
| 668 | * @endparblock |
| 669 | ?*/ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 670 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 671 | VLIB_CLI_COMMAND (l2fib_test_command, static) = { |
| 672 | .path = "test l2fib", |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 673 | .short_help = "test l2fib [add|del|check] mac <base-addr> count <nn>", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 674 | .function = l2fib_test_command_fn, |
| 675 | }; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 676 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 677 | |
| 678 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 679 | /** |
| 680 | * Delete an entry from the l2fib. |
John Lo | 7dbd726 | 2018-05-31 10:25:18 -0400 | [diff] [blame] | 681 | * Return 0 if the entry was deleted, or 1 it was not found or if |
| 682 | * sw_if_index is non-zero and does not match that in the entry. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 683 | */ |
John Lo | 7dbd726 | 2018-05-31 10:25:18 -0400 | [diff] [blame] | 684 | u32 |
Neale Ranns | 3b81a1e | 2018-09-06 09:50:26 -0700 | [diff] [blame] | 685 | l2fib_del_entry (const u8 * mac, u32 bd_index, u32 sw_if_index) |
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 | l2fib_entry_result_t result; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 688 | l2fib_main_t *mp = &l2fib_main; |
| 689 | BVT (clib_bihash_kv) kv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 690 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 691 | /* set up key */ |
John Lo | 7dbd726 | 2018-05-31 10:25:18 -0400 | [diff] [blame] | 692 | kv.key = l2fib_make_key (mac, bd_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 693 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 694 | if (BV (clib_bihash_search) (&mp->mac_table, &kv, &kv)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 695 | return 1; |
| 696 | |
| 697 | result.raw = kv.value; |
| 698 | |
John Lo | 7dbd726 | 2018-05-31 10:25:18 -0400 | [diff] [blame] | 699 | /* check if sw_if_index of entry match */ |
| 700 | if ((sw_if_index != 0) && (sw_if_index != result.fields.sw_if_index)) |
| 701 | return 1; |
| 702 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 703 | /* decrement counter if dynamically learned mac */ |
Neale Ranns | b54d081 | 2018-09-06 06:22:56 -0700 | [diff] [blame] | 704 | if ((!l2fib_entry_result_is_set_AGE_NOT (&result)) && |
| 705 | (l2learn_main.global_learn_count)) |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 706 | l2learn_main.global_learn_count--; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 707 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 708 | /* Remove entry from hash table */ |
| 709 | BV (clib_bihash_add_del) (&mp->mac_table, &kv, 0 /* is_add */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 710 | return 0; |
| 711 | } |
| 712 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 713 | /** |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 714 | * Delete an entry from the L2FIB. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 715 | * The CLI format is: |
| 716 | * l2fib del <mac> <bd-id> |
| 717 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 718 | static clib_error_t * |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 719 | l2fib_del (vlib_main_t * vm, |
| 720 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 721 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 722 | bd_main_t *bdm = &bd_main; |
| 723 | clib_error_t *error = 0; |
Mohsin Kazmi | 57938f6 | 2017-10-27 21:28:07 +0200 | [diff] [blame] | 724 | u8 mac[6]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 725 | u32 bd_id; |
| 726 | u32 bd_index; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 727 | uword *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 728 | |
Mohsin Kazmi | 57938f6 | 2017-10-27 21:28:07 +0200 | [diff] [blame] | 729 | if (!unformat (input, "%U", unformat_ethernet_address, mac)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 730 | { |
| 731 | error = clib_error_return (0, "expected mac address `%U'", |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 732 | format_unformat_error, input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 733 | goto done; |
| 734 | } |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 735 | |
| 736 | if (!unformat (input, "%d", &bd_id)) |
| 737 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 738 | error = clib_error_return (0, "expected bridge domain ID `%U'", |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 739 | format_unformat_error, input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 740 | goto done; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 741 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 742 | |
| 743 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 744 | if (!p) |
| 745 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 746 | error = clib_error_return (0, "bridge domain ID %d invalid", bd_id); |
| 747 | goto done; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 748 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 749 | bd_index = p[0]; |
| 750 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 751 | /* Delete the entry */ |
John Lo | 7dbd726 | 2018-05-31 10:25:18 -0400 | [diff] [blame] | 752 | if (l2fib_del_entry (mac, bd_index, 0)) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 753 | { |
| 754 | error = clib_error_return (0, "mac entry not found"); |
| 755 | goto done; |
| 756 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 757 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 758 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 759 | return error; |
| 760 | } |
| 761 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 762 | /*? |
| 763 | * This command deletes an existing MAC Address entry from the L2 FIB |
| 764 | * table of an existing bridge-domain. |
| 765 | * |
| 766 | * @cliexpar |
| 767 | * 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): |
| 768 | * @cliexcmd{l2fib del 52:54:00:53:18:33 200} |
| 769 | ?*/ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 770 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 771 | VLIB_CLI_COMMAND (l2fib_del_cli, static) = { |
| 772 | .path = "l2fib del", |
John Lo | 7dbd726 | 2018-05-31 10:25:18 -0400 | [diff] [blame] | 773 | .short_help = "l2fib del <mac> <bridge-domain-id> []", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 774 | .function = l2fib_del, |
| 775 | }; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 776 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 777 | |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 778 | /** |
| 779 | Kick off ager to scan MACs to age/delete MAC entries |
| 780 | */ |
| 781 | void |
| 782 | l2fib_start_ager_scan (vlib_main_t * vm) |
| 783 | { |
Eyal Bari | 24db0ec | 2017-09-27 21:43:51 +0300 | [diff] [blame] | 784 | uword evt = L2_MAC_AGE_PROCESS_EVENT_ONE_PASS; |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 785 | |
| 786 | /* check if there is at least one bd with mac aging enabled */ |
Eyal Bari | 24db0ec | 2017-09-27 21:43:51 +0300 | [diff] [blame] | 787 | l2_bridge_domain_t *bd_config; |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 788 | vec_foreach (bd_config, l2input_main.bd_configs) |
Eyal Bari | 24db0ec | 2017-09-27 21:43:51 +0300 | [diff] [blame] | 789 | { |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 790 | if (bd_config->bd_id != ~0 && bd_config->mac_age != 0) |
Eyal Bari | 24db0ec | 2017-09-27 21:43:51 +0300 | [diff] [blame] | 791 | { |
| 792 | evt = L2_MAC_AGE_PROCESS_EVENT_START; |
| 793 | break; |
| 794 | } |
| 795 | } |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 796 | |
| 797 | vlib_process_signal_event (vm, l2fib_mac_age_scanner_process_node.index, |
Eyal Bari | 24db0ec | 2017-09-27 21:43:51 +0300 | [diff] [blame] | 798 | evt, 0); |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | /** |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 802 | Flush all non static MACs from an interface |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 803 | */ |
| 804 | void |
| 805 | l2fib_flush_int_mac (vlib_main_t * vm, u32 sw_if_index) |
| 806 | { |
Eyal Bari | 0f360dc | 2017-06-14 13:11:20 +0300 | [diff] [blame] | 807 | *l2fib_swif_seq_num (sw_if_index) += 1; |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 808 | l2fib_start_ager_scan (vm); |
| 809 | } |
| 810 | |
| 811 | /** |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 812 | Flush all non static MACs in a bridge domain |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 813 | */ |
| 814 | void |
| 815 | l2fib_flush_bd_mac (vlib_main_t * vm, u32 bd_index) |
| 816 | { |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 817 | l2_bridge_domain_t *bd_config = l2input_bd_config (bd_index); |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 818 | bd_config->seq_num += 1; |
| 819 | l2fib_start_ager_scan (vm); |
| 820 | } |
| 821 | |
| 822 | /** |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 823 | Flush all non static MACs - flushes all valid BDs |
| 824 | */ |
| 825 | void |
| 826 | l2fib_flush_all_mac (vlib_main_t * vm) |
| 827 | { |
| 828 | l2_bridge_domain_t *bd_config; |
| 829 | vec_foreach (bd_config, l2input_main.bd_configs) |
| 830 | if (bd_is_valid (bd_config)) |
| 831 | bd_config->seq_num += 1; |
| 832 | |
| 833 | l2fib_start_ager_scan (vm); |
| 834 | } |
| 835 | |
| 836 | |
| 837 | /** |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 838 | Flush MACs, except static ones, associated with an interface |
| 839 | The CLI format is: |
| 840 | l2fib flush-mac interface <if-name> |
| 841 | */ |
| 842 | static clib_error_t * |
| 843 | l2fib_flush_mac_int (vlib_main_t * vm, |
| 844 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 845 | { |
| 846 | vnet_main_t *vnm = vnet_get_main (); |
| 847 | clib_error_t *error = 0; |
| 848 | u32 sw_if_index; |
| 849 | |
| 850 | if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 851 | { |
| 852 | error = clib_error_return (0, "unknown interface `%U'", |
| 853 | format_unformat_error, input); |
| 854 | goto done; |
| 855 | } |
| 856 | |
| 857 | l2fib_flush_int_mac (vm, sw_if_index); |
| 858 | |
| 859 | done: |
| 860 | return error; |
| 861 | } |
| 862 | |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 863 | /** |
| 864 | Flush all MACs, except static ones |
| 865 | The CLI format is: |
| 866 | l2fib flush-mac all |
| 867 | */ |
| 868 | static clib_error_t * |
| 869 | l2fib_flush_mac_all (vlib_main_t * vm, |
| 870 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 871 | { |
| 872 | l2fib_flush_all_mac (vm); |
| 873 | return 0; |
| 874 | } |
| 875 | |
| 876 | /*? |
| 877 | * This command kick off ager to delete all existing MAC Address entries, |
| 878 | * except static ones, associated with an interface from the L2 FIB table. |
| 879 | * |
| 880 | * @cliexpar |
| 881 | * Example of how to flush MAC Address entries learned on an interface from the L2 FIB table: |
| 882 | * @cliexcmd{l2fib flush-mac interface GigabitEthernet2/1/0} |
| 883 | ?*/ |
| 884 | /* *INDENT-OFF* */ |
| 885 | VLIB_CLI_COMMAND (l2fib_flush_mac_all_cli, static) = { |
| 886 | .path = "l2fib flush-mac all", |
| 887 | .short_help = "l2fib flush-mac all", |
| 888 | .function = l2fib_flush_mac_all, |
| 889 | }; |
| 890 | /* *INDENT-ON* */ |
| 891 | |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 892 | /*? |
| 893 | * This command kick off ager to delete all existing MAC Address entries, |
| 894 | * except static ones, associated with an interface from the L2 FIB table. |
| 895 | * |
| 896 | * @cliexpar |
| 897 | * Example of how to flush MAC Address entries learned on an interface from the L2 FIB table: |
| 898 | * @cliexcmd{l2fib flush-mac interface GigabitEthernet2/1/0} |
| 899 | ?*/ |
| 900 | /* *INDENT-OFF* */ |
| 901 | VLIB_CLI_COMMAND (l2fib_flush_mac_int_cli, static) = { |
| 902 | .path = "l2fib flush-mac interface", |
| 903 | .short_help = "l2fib flush-mac interface <if-name>", |
| 904 | .function = l2fib_flush_mac_int, |
| 905 | }; |
| 906 | /* *INDENT-ON* */ |
| 907 | |
| 908 | /** |
| 909 | Flush bridge-domain MACs except static ones. |
| 910 | The CLI format is: |
| 911 | l2fib flush-mac bridge-domain <bd-id> |
| 912 | */ |
| 913 | static clib_error_t * |
| 914 | l2fib_flush_mac_bd (vlib_main_t * vm, |
| 915 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 916 | { |
| 917 | bd_main_t *bdm = &bd_main; |
| 918 | clib_error_t *error = 0; |
| 919 | u32 bd_index, bd_id; |
| 920 | uword *p; |
| 921 | |
| 922 | if (!unformat (input, "%d", &bd_id)) |
| 923 | { |
| 924 | error = clib_error_return (0, "expecting bridge-domain id but got `%U'", |
| 925 | format_unformat_error, input); |
| 926 | goto done; |
| 927 | } |
| 928 | |
| 929 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 930 | if (p) |
| 931 | bd_index = *p; |
| 932 | else |
| 933 | return clib_error_return (0, "No such bridge domain %d", bd_id); |
| 934 | |
| 935 | l2fib_flush_bd_mac (vm, bd_index); |
| 936 | |
| 937 | done: |
| 938 | return error; |
| 939 | } |
| 940 | |
| 941 | /*? |
| 942 | * This command kick off ager to delete all existing MAC Address entries, |
| 943 | * except static ones, in a bridge domain from the L2 FIB table. |
| 944 | * |
| 945 | * @cliexpar |
| 946 | * Example of how to flush MAC Address entries learned in a bridge domain from the L2 FIB table: |
| 947 | * @cliexcmd{l2fib flush-mac bridge-domain 1000} |
| 948 | ?*/ |
| 949 | /* *INDENT-OFF* */ |
| 950 | VLIB_CLI_COMMAND (l2fib_flush_mac_bd_cli, static) = { |
| 951 | .path = "l2fib flush-mac bridge-domain", |
| 952 | .short_help = "l2fib flush-mac bridge-domain <bd-id>", |
| 953 | .function = l2fib_flush_mac_bd, |
| 954 | }; |
| 955 | /* *INDENT-ON* */ |
| 956 | |
Eyal Bari | afc47aa | 2017-04-20 14:45:17 +0300 | [diff] [blame] | 957 | clib_error_t * |
| 958 | l2fib_sw_interface_up_down (vnet_main_t * vnm, u32 sw_if_index, u32 flags) |
| 959 | { |
| 960 | l2_input_config_t *config = l2input_intf_config (sw_if_index); |
| 961 | if ((flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) == 0 && config->bridge) |
| 962 | l2fib_flush_int_mac (vnm->vlib_main, sw_if_index); |
| 963 | return 0; |
| 964 | } |
| 965 | |
| 966 | VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (l2fib_sw_interface_up_down); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 967 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 968 | BVT (clib_bihash) * get_mac_table (void) |
| 969 | { |
| 970 | l2fib_main_t *mp = &l2fib_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 971 | return &mp->mac_table; |
| 972 | } |
| 973 | |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 974 | static_always_inline void * |
| 975 | allocate_mac_evt_buf (u32 client, u32 client_index) |
| 976 | { |
| 977 | l2fib_main_t *fm = &l2fib_main; |
| 978 | vl_api_l2_macs_event_t *mp = vl_msg_api_alloc |
| 979 | (sizeof (*mp) + (fm->max_macs_in_event * sizeof (vl_api_mac_entry_t))); |
| 980 | mp->_vl_msg_id = htons (VL_API_L2_MACS_EVENT); |
| 981 | mp->pid = htonl (client); |
| 982 | mp->client_index = client_index; |
| 983 | return mp; |
| 984 | } |
| 985 | |
| 986 | static_always_inline f64 |
| 987 | l2fib_scan (vlib_main_t * vm, f64 start_time, u8 event_only) |
| 988 | { |
| 989 | l2fib_main_t *fm = &l2fib_main; |
| 990 | l2learn_main_t *lm = &l2learn_main; |
| 991 | |
| 992 | BVT (clib_bihash) * h = &fm->mac_table; |
| 993 | int i, j, k; |
| 994 | f64 last_start = start_time; |
| 995 | f64 accum_t = 0; |
| 996 | f64 delta_t = 0; |
| 997 | u32 evt_idx = 0; |
| 998 | u32 learn_count = 0; |
| 999 | u32 client = lm->client_pid; |
| 1000 | u32 cl_idx = lm->client_index; |
| 1001 | vl_api_l2_macs_event_t *mp = 0; |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 1002 | vl_api_registration_t *reg = 0; |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 1003 | |
Dave Barach | 32dcd3b | 2019-07-08 12:25:38 -0400 | [diff] [blame] | 1004 | /* Don't scan the l2 fib if it hasn't been instantiated yet */ |
| 1005 | if (alloc_arena (h) == 0) |
| 1006 | return 0.0; |
| 1007 | |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 1008 | if (client) |
| 1009 | { |
| 1010 | mp = allocate_mac_evt_buf (client, cl_idx); |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 1011 | reg = vl_api_client_index_to_registration (lm->client_index); |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | for (i = 0; i < h->nbuckets; i++) |
| 1015 | { |
| 1016 | /* allow no more than 20us without a pause */ |
| 1017 | delta_t = vlib_time_now (vm) - last_start; |
| 1018 | if (delta_t > 20e-6) |
| 1019 | { |
| 1020 | vlib_process_suspend (vm, 100e-6); /* suspend for 100 us */ |
| 1021 | last_start = vlib_time_now (vm); |
| 1022 | accum_t += delta_t; |
| 1023 | } |
| 1024 | |
| 1025 | if (i < (h->nbuckets - 3)) |
| 1026 | { |
| 1027 | BVT (clib_bihash_bucket) * b = &h->buckets[i + 3]; |
| 1028 | CLIB_PREFETCH (b, CLIB_CACHE_LINE_BYTES, LOAD); |
| 1029 | b = &h->buckets[i + 1]; |
| 1030 | if (b->offset) |
| 1031 | { |
| 1032 | BVT (clib_bihash_value) * v = |
| 1033 | BV (clib_bihash_get_value) (h, b->offset); |
| 1034 | CLIB_PREFETCH (v, CLIB_CACHE_LINE_BYTES, LOAD); |
| 1035 | } |
| 1036 | } |
| 1037 | |
| 1038 | BVT (clib_bihash_bucket) * b = &h->buckets[i]; |
| 1039 | if (b->offset == 0) |
| 1040 | continue; |
| 1041 | BVT (clib_bihash_value) * v = BV (clib_bihash_get_value) (h, b->offset); |
| 1042 | for (j = 0; j < (1 << b->log2_pages); j++) |
| 1043 | { |
| 1044 | for (k = 0; k < BIHASH_KVP_PER_PAGE; k++) |
| 1045 | { |
| 1046 | if (v->kvp[k].key == ~0ULL && v->kvp[k].value == ~0ULL) |
| 1047 | continue; |
| 1048 | |
| 1049 | l2fib_entry_key_t key = {.raw = v->kvp[k].key }; |
| 1050 | l2fib_entry_result_t result = {.raw = v->kvp[k].value }; |
| 1051 | |
Neale Ranns | b54d081 | 2018-09-06 06:22:56 -0700 | [diff] [blame] | 1052 | if (!l2fib_entry_result_is_set_AGE_NOT (&result)) |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 1053 | learn_count++; |
| 1054 | |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 1055 | if (client) |
| 1056 | { |
Eyal Bari | 24db0ec | 2017-09-27 21:43:51 +0300 | [diff] [blame] | 1057 | if (PREDICT_FALSE (evt_idx >= fm->max_macs_in_event)) |
| 1058 | { |
| 1059 | /* event message full, send it and start a new one */ |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 1060 | if (reg && vl_api_can_send_msg (reg)) |
Eyal Bari | 24db0ec | 2017-09-27 21:43:51 +0300 | [diff] [blame] | 1061 | { |
| 1062 | mp->n_macs = htonl (evt_idx); |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 1063 | vl_api_send_msg (reg, (u8 *) mp); |
Eyal Bari | 24db0ec | 2017-09-27 21:43:51 +0300 | [diff] [blame] | 1064 | mp = allocate_mac_evt_buf (client, cl_idx); |
| 1065 | } |
| 1066 | else |
| 1067 | { |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 1068 | if (reg) |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 1069 | clib_warning ("MAC event to pid %d queue stuffed!" |
| 1070 | " %d MAC entries lost", client, |
| 1071 | evt_idx); |
Eyal Bari | 24db0ec | 2017-09-27 21:43:51 +0300 | [diff] [blame] | 1072 | } |
| 1073 | evt_idx = 0; |
| 1074 | } |
| 1075 | |
Neale Ranns | b54d081 | 2018-09-06 06:22:56 -0700 | [diff] [blame] | 1076 | if (l2fib_entry_result_is_set_LRN_EVT (&result)) |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 1077 | { |
| 1078 | /* copy mac entry to event msg */ |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1079 | clib_memcpy_fast (mp->mac[evt_idx].mac_addr, |
| 1080 | key.fields.mac, 6); |
Neale Ranns | b54d081 | 2018-09-06 06:22:56 -0700 | [diff] [blame] | 1081 | mp->mac[evt_idx].action = |
| 1082 | l2fib_entry_result_is_set_LRN_MOV (&result) ? |
John Lo | e23c99e | 2018-03-13 21:53:18 -0400 | [diff] [blame] | 1083 | MAC_EVENT_ACTION_MOVE : MAC_EVENT_ACTION_ADD; |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 1084 | mp->mac[evt_idx].sw_if_index = |
| 1085 | htonl (result.fields.sw_if_index); |
John Lo | e23c99e | 2018-03-13 21:53:18 -0400 | [diff] [blame] | 1086 | /* clear event bits and update mac entry */ |
Neale Ranns | b54d081 | 2018-09-06 06:22:56 -0700 | [diff] [blame] | 1087 | l2fib_entry_result_clear_LRN_EVT (&result); |
| 1088 | l2fib_entry_result_clear_LRN_MOV (&result); |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 1089 | BVT (clib_bihash_kv) kv; |
| 1090 | kv.key = key.raw; |
| 1091 | kv.value = result.raw; |
| 1092 | BV (clib_bihash_add_del) (&fm->mac_table, &kv, 1); |
| 1093 | evt_idx++; |
| 1094 | continue; /* skip aging */ |
| 1095 | } |
| 1096 | } |
| 1097 | |
Neale Ranns | b54d081 | 2018-09-06 06:22:56 -0700 | [diff] [blame] | 1098 | if (event_only || l2fib_entry_result_is_set_AGE_NOT (&result)) |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 1099 | continue; /* skip aging - static_mac always age_not */ |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 1100 | |
| 1101 | /* start aging processing */ |
| 1102 | u32 bd_index = key.fields.bd_index; |
| 1103 | u32 sw_if_index = result.fields.sw_if_index; |
| 1104 | u16 sn = l2fib_cur_seq_num (bd_index, sw_if_index).as_u16; |
| 1105 | if (result.fields.sn.as_u16 != sn) |
| 1106 | goto age_out; /* stale mac */ |
| 1107 | |
| 1108 | l2_bridge_domain_t *bd_config = |
| 1109 | vec_elt_at_index (l2input_main.bd_configs, bd_index); |
| 1110 | |
| 1111 | if (bd_config->mac_age == 0) |
| 1112 | continue; /* skip aging */ |
| 1113 | |
| 1114 | i16 delta = (u8) (start_time / 60) - result.fields.timestamp; |
| 1115 | delta += delta < 0 ? 256 : 0; |
| 1116 | |
| 1117 | if (delta < bd_config->mac_age) |
| 1118 | continue; /* still valid */ |
| 1119 | |
| 1120 | age_out: |
| 1121 | if (client) |
| 1122 | { |
| 1123 | /* copy mac entry to event msg */ |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1124 | clib_memcpy_fast (mp->mac[evt_idx].mac_addr, key.fields.mac, |
| 1125 | 6); |
John Lo | e23c99e | 2018-03-13 21:53:18 -0400 | [diff] [blame] | 1126 | mp->mac[evt_idx].action = MAC_EVENT_ACTION_DELETE; |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 1127 | mp->mac[evt_idx].sw_if_index = |
| 1128 | htonl (result.fields.sw_if_index); |
| 1129 | evt_idx++; |
| 1130 | } |
| 1131 | /* delete mac entry */ |
| 1132 | BVT (clib_bihash_kv) kv; |
| 1133 | kv.key = key.raw; |
| 1134 | BV (clib_bihash_add_del) (&fm->mac_table, &kv, 0); |
| 1135 | learn_count--; |
Dave Barach | 28374ca | 2018-08-07 12:46:18 -0400 | [diff] [blame] | 1136 | /* |
| 1137 | * Note: we may have just freed the bucket's backing |
| 1138 | * storage, so check right here... |
| 1139 | */ |
| 1140 | if (b->offset == 0) |
| 1141 | goto doublebreak; |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 1142 | } |
| 1143 | v++; |
| 1144 | } |
Dave Barach | 28374ca | 2018-08-07 12:46:18 -0400 | [diff] [blame] | 1145 | doublebreak: |
| 1146 | ; |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | /* keep learn count consistent */ |
| 1150 | l2learn_main.global_learn_count = learn_count; |
| 1151 | |
| 1152 | if (mp) |
| 1153 | { |
| 1154 | /* send any outstanding mac event message else free message buffer */ |
| 1155 | if (evt_idx) |
| 1156 | { |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 1157 | if (reg && vl_api_can_send_msg (reg)) |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 1158 | { |
| 1159 | mp->n_macs = htonl (evt_idx); |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 1160 | vl_api_send_msg (reg, (u8 *) mp); |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 1161 | } |
| 1162 | else |
| 1163 | { |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 1164 | if (reg) |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 1165 | clib_warning ("MAC event to pid %d queue stuffed!" |
| 1166 | " %d MAC entries lost", client, evt_idx); |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 1167 | vl_msg_api_free (mp); |
| 1168 | } |
| 1169 | } |
| 1170 | else |
| 1171 | vl_msg_api_free (mp); |
| 1172 | } |
| 1173 | return delta_t + accum_t; |
| 1174 | } |
| 1175 | |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 1176 | static uword |
| 1177 | l2fib_mac_age_scanner_process (vlib_main_t * vm, vlib_node_runtime_t * rt, |
| 1178 | vlib_frame_t * f) |
| 1179 | { |
| 1180 | uword event_type, *event_data = 0; |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 1181 | l2fib_main_t *fm = &l2fib_main; |
| 1182 | l2learn_main_t *lm = &l2learn_main; |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 1183 | bool enabled = 0; |
John Lo | 7f358b3 | 2018-04-28 01:19:24 -0400 | [diff] [blame] | 1184 | f64 start_time, next_age_scan_time = CLIB_TIME_MAX; |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 1185 | |
| 1186 | while (1) |
| 1187 | { |
Eyal Bari | 24db0ec | 2017-09-27 21:43:51 +0300 | [diff] [blame] | 1188 | if (lm->client_pid) |
| 1189 | vlib_process_wait_for_event_or_clock (vm, fm->event_scan_delay); |
| 1190 | else if (enabled) |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 1191 | { |
Eyal Bari | 24db0ec | 2017-09-27 21:43:51 +0300 | [diff] [blame] | 1192 | f64 t = next_age_scan_time - vlib_time_now (vm); |
| 1193 | vlib_process_wait_for_event_or_clock (vm, t); |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 1194 | } |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 1195 | else |
| 1196 | vlib_process_wait_for_event (vm); |
| 1197 | |
| 1198 | event_type = vlib_process_get_events (vm, &event_data); |
| 1199 | vec_reset_length (event_data); |
| 1200 | |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 1201 | start_time = vlib_time_now (vm); |
Eyal Bari | 24db0ec | 2017-09-27 21:43:51 +0300 | [diff] [blame] | 1202 | enum |
| 1203 | { SCAN_MAC_AGE, SCAN_MAC_EVENT, SCAN_DISABLE } scan = SCAN_MAC_AGE; |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 1204 | |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 1205 | switch (event_type) |
| 1206 | { |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 1207 | case ~0: /* timer expired */ |
Eyal Bari | 24db0ec | 2017-09-27 21:43:51 +0300 | [diff] [blame] | 1208 | if (lm->client_pid != 0 && start_time < next_age_scan_time) |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 1209 | scan = SCAN_MAC_EVENT; |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 1210 | break; |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 1211 | |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 1212 | case L2_MAC_AGE_PROCESS_EVENT_START: |
| 1213 | enabled = 1; |
| 1214 | break; |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 1215 | |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 1216 | case L2_MAC_AGE_PROCESS_EVENT_STOP: |
| 1217 | enabled = 0; |
Eyal Bari | 24db0ec | 2017-09-27 21:43:51 +0300 | [diff] [blame] | 1218 | scan = SCAN_DISABLE; |
| 1219 | break; |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 1220 | |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 1221 | case L2_MAC_AGE_PROCESS_EVENT_ONE_PASS: |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 1222 | break; |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 1223 | |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 1224 | default: |
| 1225 | ASSERT (0); |
| 1226 | } |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 1227 | |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 1228 | if (scan == SCAN_MAC_EVENT) |
| 1229 | l2fib_main.evt_scan_duration = l2fib_scan (vm, start_time, 1); |
| 1230 | else |
Eyal Bari | 24db0ec | 2017-09-27 21:43:51 +0300 | [diff] [blame] | 1231 | { |
| 1232 | if (scan == SCAN_MAC_AGE) |
| 1233 | l2fib_main.age_scan_duration = l2fib_scan (vm, start_time, 0); |
| 1234 | if (scan == SCAN_DISABLE) |
| 1235 | { |
| 1236 | l2fib_main.age_scan_duration = 0; |
| 1237 | l2fib_main.evt_scan_duration = 0; |
| 1238 | } |
| 1239 | /* schedule next scan */ |
| 1240 | if (enabled) |
| 1241 | next_age_scan_time = start_time + L2FIB_AGE_SCAN_INTERVAL; |
| 1242 | else |
John Lo | 7f358b3 | 2018-04-28 01:19:24 -0400 | [diff] [blame] | 1243 | next_age_scan_time = CLIB_TIME_MAX; |
Eyal Bari | 24db0ec | 2017-09-27 21:43:51 +0300 | [diff] [blame] | 1244 | } |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 1245 | } |
| 1246 | return 0; |
| 1247 | } |
| 1248 | |
| 1249 | /* *INDENT-OFF* */ |
| 1250 | VLIB_REGISTER_NODE (l2fib_mac_age_scanner_process_node) = { |
| 1251 | .function = l2fib_mac_age_scanner_process, |
| 1252 | .type = VLIB_NODE_TYPE_PROCESS, |
| 1253 | .name = "l2fib-mac-age-scanner-process", |
| 1254 | }; |
| 1255 | /* *INDENT-ON* */ |
| 1256 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1257 | clib_error_t * |
| 1258 | l2fib_init (vlib_main_t * vm) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1259 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1260 | l2fib_main_t *mp = &l2fib_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1261 | l2fib_entry_key_t test_key; |
| 1262 | u8 test_mac[6]; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1263 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1264 | mp->vlib_main = vm; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1265 | mp->vnet_main = vnet_get_main (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1266 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1267 | /* Create the hash table */ |
| 1268 | BV (clib_bihash_init) (&mp->mac_table, "l2fib mac table", |
| 1269 | L2FIB_NUM_BUCKETS, L2FIB_MEMORY_SIZE); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1270 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1271 | /* verify the key constructor is good, since it is endian-sensitive */ |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1272 | clib_memset (test_mac, 0, sizeof (test_mac)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1273 | test_mac[0] = 0x11; |
| 1274 | test_key.raw = 0; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1275 | test_key.raw = l2fib_make_key ((u8 *) & test_mac, 0x1234); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1276 | ASSERT (test_key.fields.mac[0] == 0x11); |
| 1277 | ASSERT (test_key.fields.bd_index == 0x1234); |
| 1278 | |
| 1279 | return 0; |
| 1280 | } |
| 1281 | |
| 1282 | VLIB_INIT_FUNCTION (l2fib_init); |
| 1283 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1284 | /* |
| 1285 | * fd.io coding-style-patch-verification: ON |
| 1286 | * |
| 1287 | * Local Variables: |
| 1288 | * eval: (c-set-style "gnu") |
| 1289 | * End: |
| 1290 | */ |