FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
l2_fib.c
Go to the documentation of this file.
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>
27 #include <vnet/l2/l2_input.h>
28 #include <vnet/l2/l2_fib.h>
29 #include <vnet/l2/l2_learn.h>
30 #include <vnet/l2/l2_bd.h>
31 
33 
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 
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 
56 
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  }
73 #undef _
74  }
75  return (s);
76 }
77 
78 static void
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 
86  clib_memcpy_fast (mac, &tmp, 6);
87 }
88 
89 /** Format sw_if_index. If the value is ~0, use the text "N/A" */
90 u8 *
92 {
93  vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
94  u32 sw_if_index = va_arg (*args, u32);
95  if (sw_if_index == ~0)
96  return format (s, "N/A");
97 
98  vnet_sw_interface_t *swif =
99  vnet_get_sw_interface_or_null (vnm, sw_if_index);
100  if (!swif)
101  return format (s, "Stale");
102 
103  return format (s, "%U", format_vnet_sw_interface_name, vnm,
104  vnet_get_sw_interface_or_null (vnm, sw_if_index));
105 }
106 
108 {
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;
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 
131 void
135 {
136  l2fib_main_t *msm = &l2fib_main;
138  .bd_index = bd_index,
139  };
140 
142  (&msm->mac_table, l2fib_dump_walk_cb, &ctx);
143 
144  *l2fe_key = ctx.l2fe_key;
145  *l2fe_res = ctx.l2fe_res;
146 }
147 
149 {
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;
166  l2fib_entry_result_t result;
168 
169  if (ctx->verbose && ctx->first_entry)
170  {
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 
188  if (ctx->learn && l2fib_entry_result_is_set_AGE_NOT (&result))
189  return; /* skip provisioned macs */
190 
191  if (ctx->add && !l2fib_entry_result_is_set_AGE_NOT (&result))
192  return; /* skip learned macs */
193 
195  key.fields.bd_index);
196 
197  if (l2fib_entry_result_is_set_AGE_NOT (&result))
198  s = format (s, "no");
199  else if (bd_config->mac_age == 0)
200  s = format (s, "-");
201  else
202  {
203  i16 delta = ctx->now - result.fields.timestamp;
204  delta += delta < 0 ? 256 : 0;
205  s = format (s, "%d", delta);
206  }
207 
208  vlib_cli_output (ctx->vm,
209  "%=19U%=7d%=7d %3d/%-3d%=9v%=7s%=7s%=5s%=30U",
211  key.fields.bd_index,
212  result.fields.sw_if_index == ~0
213  ? -1 : result.fields.sw_if_index,
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) ? "*" : "-",
219  ctx->vnm, result.fields.sw_if_index);
220  vec_free (s);
221  }
222 }
223 
224 /** Display the contents of the l2fib. */
225 static clib_error_t *
227  unformat_input_t * input, vlib_cli_command_t * cmd)
228 {
229  bd_main_t *bdm = &bd_main;
230  l2fib_main_t *msm = &l2fib_main;
231  u8 raw = 0;
232  u32 bd_id;
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  };
240 
242  {
243  if (unformat (input, "raw"))
244  {
245  raw = 1;
246  ctx.verbose = 0;
247  break;
248  }
249  else if (unformat (input, "verbose"))
250  ctx.verbose = 1;
251  else if (unformat (input, "all"))
252  ctx.verbose = 1;
253  else if (unformat (input, "bd_index %d", &ctx.bd_index))
254  ctx.verbose = 1;
255  else if (unformat (input, "learn"))
256  {
257  ctx.add = 0;
258  ctx.learn = 1;
259  ctx.verbose = 1;
260  }
261  else if (unformat (input, "add"))
262  {
263  ctx.learn = 0;
264  ctx.add = 1;
265  ctx.verbose = 1;
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  {
272  ctx.verbose = 1;
273  ctx.bd_index = p[0];
274  }
275  else
276  return clib_error_return (0,
277  "bridge domain id %d doesn't exist\n",
278  bd_id);
279  }
280  else
281  break;
282  }
283 
285  (&msm->mac_table, l2fib_show_walk_cb, &ctx);
286 
287  if (ctx.total_entries == 0)
288  vlib_cli_output (vm, "no l2fib entries");
289  else
290  {
292  vlib_cli_output (vm, "L2FIB total/learned entries: %d/%d "
293  "Last scan time: %.4esec Learn limit: %d ",
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,
302  }
303 
304  if (raw)
305  vlib_cli_output (vm, "Raw Hash Table:\n%U\n",
306  BV (format_bihash), &msm->mac_table, 1 /* verbose */ );
307 
308  return 0;
309 }
310 
311 /*?
312  * This command displays the MAC Address entries of the L2 FIB table.
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:
324  * @cliexstart{show l2fib all}
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 ?*/
332 /* *INDENT-OFF* */
333 VLIB_CLI_COMMAND (show_l2fib_cli, static) = {
334  .path = "show l2fib",
335  .short_help = "show l2fib [all] | [bd_id <nn> | bd_index <nn>] [learn | add] | [raw]",
336  .function = show_l2fib,
337 };
338 /* *INDENT-ON* */
339 
340 
341 /* Remove all entries from the l2fib */
342 void
344 {
345  l2fib_main_t *mp = &l2fib_main;
346 
347  /* Remove all entries */
348  BV (clib_bihash_free) (&mp->mac_table);
349  BV (clib_bihash_init) (&mp->mac_table, "l2fib mac table",
352 }
353 
354 /** Clear all entries in L2FIB.
355  * @TODO: Later we may want a way to remove only the non-static entries
356  */
357 static clib_error_t *
359  unformat_input_t * input, vlib_cli_command_t * cmd)
360 {
362  return 0;
363 }
364 
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 ?*/
376 /* *INDENT-OFF* */
377 VLIB_CLI_COMMAND (clear_l2fib_cli, static) = {
378  .path = "clear l2fib",
379  .short_help = "clear l2fib",
380  .function = clear_l2fib,
381 };
382 /* *INDENT-ON* */
383 
384 static inline l2fib_seq_num_t
386 {
387  l2_bridge_domain_t *bd_config = l2input_bd_config (bd_index);
388  /* *INDENT-OFF* */
389  return (l2fib_seq_num_t) {
390  .swif = *l2fib_swif_seq_num (sw_if_index),
391  .bd = bd_config->seq_num,
392  };
393  /* *INDENT-ON* */
394 }
395 
396 /**
397  * Add an entry to the l2fib.
398  * If the entry already exists then overwrite it
399  */
400 void
403 {
405  l2fib_entry_result_t result;
406  __attribute__ ((unused)) u32 bucket_contents;
409  BVT (clib_bihash_kv) kv;
410 
411  /* set up key */
412  key.raw = l2fib_make_key (mac, bd_index);
413 
414  /* check if entry already exist */
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;
419  if ((!l2fib_entry_result_is_set_AGE_NOT (&result))
420  && (lm->global_learn_count))
421  lm->global_learn_count--;
422  }
423 
424  /* set up result */
425  result.raw = 0; /* clear all fields */
426  result.fields.sw_if_index = sw_if_index;
427  result.fields.flags = flags;
428 
429  /* no aging for provisioned entry */
430  l2fib_entry_result_set_AGE_NOT (&result);
431 
432  kv.key = key.raw;
433  kv.value = result.raw;
434 
435  BV (clib_bihash_add_del) (&fm->mac_table, &kv, 1 /* is_add */ );
436 }
437 
438 /**
439  * Add an entry to the L2FIB.
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  */
445 static clib_error_t *
447  unformat_input_t * input, vlib_cli_command_t * cmd)
448 {
449  bd_main_t *bdm = &bd_main;
450  vnet_main_t *vnm = vnet_get_main ();
451  clib_error_t *error = 0;
452  u8 mac[6];
453  u32 bd_id;
454  u32 bd_index;
455  u32 sw_if_index = ~0;
456  uword *p;
458 
460 
461  if (!unformat (input, "%U", unformat_ethernet_address, mac))
462  {
463  error = clib_error_return (0, "expected mac address `%U'",
464  format_unformat_error, input);
465  goto done;
466  }
467 
468  if (!unformat (input, "%d", &bd_id))
469  {
470  error = clib_error_return (0, "expected bridge domain ID `%U'",
471  format_unformat_error, input);
472  goto done;
473  }
474 
475  p = hash_get (bdm->bd_index_by_bd_id, bd_id);
476  if (!p)
477  {
478  error = clib_error_return (0, "bridge domain ID %d invalid", bd_id);
479  goto done;
480  }
481  bd_index = p[0];
482 
483  if (unformat (input, "filter"))
484  {
485  l2fib_add_filter_entry (mac, bd_index);
486  return 0;
487  }
488 
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"))
497  flags |= L2FIB_ENTRY_RESULT_FLAG_STATIC;
498  else if (unformat (input, "bvi"))
499  flags |= (L2FIB_ENTRY_RESULT_FLAG_STATIC | L2FIB_ENTRY_RESULT_FLAG_BVI);
500 
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 
508  l2fib_add_entry (mac, bd_index, sw_if_index, flags);
509 
510 done:
511  return error;
512 }
513 
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 ?*/
541 /* *INDENT-OFF* */
542 VLIB_CLI_COMMAND (l2fib_add_cli, static) = {
543  .path = "l2fib add",
544  .short_help = "l2fib add <mac> <bridge-domain-id> filter | <intf> [static | bvi]",
545  .function = l2fib_add,
546 };
547 /* *INDENT-ON* */
548 
549 
550 static clib_error_t *
552  unformat_input_t * input, vlib_cli_command_t * cmd)
553 {
554  clib_error_t *error = 0;
555  u8 mac[6], save_mac[6];
556  u32 bd_index = 0;
557  u32 sw_if_index = 8;
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 
566  {
567  if (unformat (input, "mac %U", unformat_ethernet_address, mac))
568  mac_set = 1;
569  else if (unformat (input, "add"))
570  is_add = 1;
571  else if (unformat (input, "del"))
572  is_del = 1;
573  else if (unformat (input, "check"))
574  is_check = 1;
575  else if (unformat (input, "count %d", &count))
576  ;
577  else
578  break;
579  }
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)
585  return clib_error_return (0,
586  "noop: pick at least one of (add,del,check)");
587 
588  clib_memcpy_fast (save_mac, mac, 6);
589 
590  if (is_add)
591  {
592  for (i = 0; i < count; i++)
593  {
594  l2fib_add_entry (mac, bd_index, sw_if_index,
596  incr_mac_address (mac);
597  }
598  }
599 
600  if (is_check)
601  {
602  BVT (clib_bihash_kv) kv;
603  l2fib_main_t *mp = &l2fib_main;
604 
605  clib_memcpy_fast (mac, save_mac, 6);
606 
607  for (i = 0; i < count; i++)
608  {
609  kv.key = l2fib_make_key (mac, bd_index);
610  if (BV (clib_bihash_search) (&mp->mac_table, &kv, &kv))
611  {
612  clib_warning ("key %U AWOL", format_ethernet_address, mac);
613  break;
614  }
615  incr_mac_address (mac);
616  }
617  }
618 
619  if (is_del)
620  {
621  clib_memcpy_fast (mac, save_mac, 6);
622 
623  for (i = 0; i < count; i++)
624  {
625  l2fib_del_entry (mac, bd_index, 0);
626  incr_mac_address (mac);
627  }
628  }
629 
630  return error;
631 }
632 
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 ?*/
670 /* *INDENT-OFF* */
671 VLIB_CLI_COMMAND (l2fib_test_command, static) = {
672  .path = "test l2fib",
673  .short_help = "test l2fib [add|del|check] mac <base-addr> count <nn>",
674  .function = l2fib_test_command_fn,
675 };
676 /* *INDENT-ON* */
677 
678 
679 /**
680  * Delete an entry from the l2fib.
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.
683  */
684 u32
686 {
687  l2fib_entry_result_t result;
688  l2fib_main_t *mp = &l2fib_main;
689  BVT (clib_bihash_kv) kv;
690 
691  /* set up key */
692  kv.key = l2fib_make_key (mac, bd_index);
693 
694  if (BV (clib_bihash_search) (&mp->mac_table, &kv, &kv))
695  return 1;
696 
697  result.raw = kv.value;
698 
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 
703  /* decrement counter if dynamically learned mac */
704  if ((!l2fib_entry_result_is_set_AGE_NOT (&result)) &&
707 
708  /* Remove entry from hash table */
709  BV (clib_bihash_add_del) (&mp->mac_table, &kv, 0 /* is_add */ );
710  return 0;
711 }
712 
713 /**
714  * Delete an entry from the L2FIB.
715  * The CLI format is:
716  * l2fib del <mac> <bd-id>
717  */
718 static clib_error_t *
720  unformat_input_t * input, vlib_cli_command_t * cmd)
721 {
722  bd_main_t *bdm = &bd_main;
723  clib_error_t *error = 0;
724  u8 mac[6];
725  u32 bd_id;
726  u32 bd_index;
727  uword *p;
728 
729  if (!unformat (input, "%U", unformat_ethernet_address, mac))
730  {
731  error = clib_error_return (0, "expected mac address `%U'",
732  format_unformat_error, input);
733  goto done;
734  }
735 
736  if (!unformat (input, "%d", &bd_id))
737  {
738  error = clib_error_return (0, "expected bridge domain ID `%U'",
739  format_unformat_error, input);
740  goto done;
741  }
742 
743  p = hash_get (bdm->bd_index_by_bd_id, bd_id);
744  if (!p)
745  {
746  error = clib_error_return (0, "bridge domain ID %d invalid", bd_id);
747  goto done;
748  }
749  bd_index = p[0];
750 
751  /* Delete the entry */
752  if (l2fib_del_entry (mac, bd_index, 0))
753  {
754  error = clib_error_return (0, "mac entry not found");
755  goto done;
756  }
757 
758 done:
759  return error;
760 }
761 
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 ?*/
770 /* *INDENT-OFF* */
771 VLIB_CLI_COMMAND (l2fib_del_cli, static) = {
772  .path = "l2fib del",
773  .short_help = "l2fib del <mac> <bridge-domain-id> []",
774  .function = l2fib_del,
775 };
776 /* *INDENT-ON* */
777 
778 /**
779  Kick off ager to scan MACs to age/delete MAC entries
780 */
781 void
783 {
785 
786  /* check if there is at least one bd with mac aging enabled */
787  l2_bridge_domain_t *bd_config;
788  vec_foreach (bd_config, l2input_main.bd_configs)
789  {
790  if (bd_config->bd_id != ~0 && bd_config->mac_age != 0)
791  {
793  break;
794  }
795  }
796 
797  vlib_process_signal_event (vm, l2fib_mac_age_scanner_process_node.index,
798  evt, 0);
799 }
800 
801 /**
802  Flush all non static MACs from an interface
803 */
804 void
806 {
807  *l2fib_swif_seq_num (sw_if_index) += 1;
809 }
810 
811 /**
812  Flush all non static MACs in a bridge domain
813 */
814 void
816 {
817  l2_bridge_domain_t *bd_config = l2input_bd_config (bd_index);
818  bd_config->seq_num += 1;
820 }
821 
822 /**
823  Flush all non static MACs - flushes all valid BDs
824 */
825 void
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 
834 }
835 
836 
837 /**
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 *
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;
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 
863 /**
864  Flush all MACs, except static ones
865  The CLI format is:
866  l2fib flush-mac all
867 */
868 static clib_error_t *
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 
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 *
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 
957 clib_error_t *
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 
967 
968 BVT (clib_bihash) * get_mac_table (void)
969 {
970  l2fib_main_t *mp = &l2fib_main;
971  return &mp->mac_table;
972 }
973 
975 allocate_mac_evt_buf (u32 client, u32 client_index)
976 {
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 
987 l2fib_scan (vlib_main_t * vm, f64 start_time, u8 event_only)
988 {
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;
1002  vl_api_registration_t *reg = 0;
1003 
1004  if (client)
1005  {
1006  mp = allocate_mac_evt_buf (client, cl_idx);
1008  }
1009 
1010  for (i = 0; i < h->nbuckets; i++)
1011  {
1012  /* allow no more than 20us without a pause */
1013  delta_t = vlib_time_now (vm) - last_start;
1014  if (delta_t > 20e-6)
1015  {
1016  vlib_process_suspend (vm, 100e-6); /* suspend for 100 us */
1017  last_start = vlib_time_now (vm);
1018  accum_t += delta_t;
1019  }
1020 
1021  if (i < (h->nbuckets - 3))
1022  {
1023  BVT (clib_bihash_bucket) * b = &h->buckets[i + 3];
1025  b = &h->buckets[i + 1];
1026  if (b->offset)
1027  {
1028  BVT (clib_bihash_value) * v =
1029  BV (clib_bihash_get_value) (h, b->offset);
1031  }
1032  }
1033 
1034  BVT (clib_bihash_bucket) * b = &h->buckets[i];
1035  if (b->offset == 0)
1036  continue;
1037  BVT (clib_bihash_value) * v = BV (clib_bihash_get_value) (h, b->offset);
1038  for (j = 0; j < (1 << b->log2_pages); j++)
1039  {
1040  for (k = 0; k < BIHASH_KVP_PER_PAGE; k++)
1041  {
1042  if (v->kvp[k].key == ~0ULL && v->kvp[k].value == ~0ULL)
1043  continue;
1044 
1045  l2fib_entry_key_t key = {.raw = v->kvp[k].key };
1046  l2fib_entry_result_t result = {.raw = v->kvp[k].value };
1047 
1048  if (!l2fib_entry_result_is_set_AGE_NOT (&result))
1049  learn_count++;
1050 
1051  if (client)
1052  {
1053  if (PREDICT_FALSE (evt_idx >= fm->max_macs_in_event))
1054  {
1055  /* event message full, send it and start a new one */
1056  if (reg && vl_api_can_send_msg (reg))
1057  {
1058  mp->n_macs = htonl (evt_idx);
1059  vl_api_send_msg (reg, (u8 *) mp);
1060  mp = allocate_mac_evt_buf (client, cl_idx);
1061  }
1062  else
1063  {
1064  if (reg)
1065  clib_warning ("MAC event to pid %d queue stuffed!"
1066  " %d MAC entries lost", client,
1067  evt_idx);
1068  }
1069  evt_idx = 0;
1070  }
1071 
1072  if (l2fib_entry_result_is_set_LRN_EVT (&result))
1073  {
1074  /* copy mac entry to event msg */
1075  clib_memcpy_fast (mp->mac[evt_idx].mac_addr,
1076  key.fields.mac, 6);
1077  mp->mac[evt_idx].action =
1078  l2fib_entry_result_is_set_LRN_MOV (&result) ?
1080  mp->mac[evt_idx].sw_if_index =
1081  htonl (result.fields.sw_if_index);
1082  /* clear event bits and update mac entry */
1083  l2fib_entry_result_clear_LRN_EVT (&result);
1084  l2fib_entry_result_clear_LRN_MOV (&result);
1085  BVT (clib_bihash_kv) kv;
1086  kv.key = key.raw;
1087  kv.value = result.raw;
1088  BV (clib_bihash_add_del) (&fm->mac_table, &kv, 1);
1089  evt_idx++;
1090  continue; /* skip aging */
1091  }
1092  }
1093 
1094  if (event_only || l2fib_entry_result_is_set_AGE_NOT (&result))
1095  continue; /* skip aging - static_mac always age_not */
1096 
1097  /* start aging processing */
1098  u32 bd_index = key.fields.bd_index;
1099  u32 sw_if_index = result.fields.sw_if_index;
1100  u16 sn = l2fib_cur_seq_num (bd_index, sw_if_index).as_u16;
1101  if (result.fields.sn.as_u16 != sn)
1102  goto age_out; /* stale mac */
1103 
1104  l2_bridge_domain_t *bd_config =
1106 
1107  if (bd_config->mac_age == 0)
1108  continue; /* skip aging */
1109 
1110  i16 delta = (u8) (start_time / 60) - result.fields.timestamp;
1111  delta += delta < 0 ? 256 : 0;
1112 
1113  if (delta < bd_config->mac_age)
1114  continue; /* still valid */
1115 
1116  age_out:
1117  if (client)
1118  {
1119  /* copy mac entry to event msg */
1120  clib_memcpy_fast (mp->mac[evt_idx].mac_addr, key.fields.mac,
1121  6);
1122  mp->mac[evt_idx].action = MAC_EVENT_ACTION_DELETE;
1123  mp->mac[evt_idx].sw_if_index =
1124  htonl (result.fields.sw_if_index);
1125  evt_idx++;
1126  }
1127  /* delete mac entry */
1128  BVT (clib_bihash_kv) kv;
1129  kv.key = key.raw;
1130  BV (clib_bihash_add_del) (&fm->mac_table, &kv, 0);
1131  learn_count--;
1132  /*
1133  * Note: we may have just freed the bucket's backing
1134  * storage, so check right here...
1135  */
1136  if (b->offset == 0)
1137  goto doublebreak;
1138  }
1139  v++;
1140  }
1141  doublebreak:
1142  ;
1143  }
1144 
1145  /* keep learn count consistent */
1146  l2learn_main.global_learn_count = learn_count;
1147 
1148  if (mp)
1149  {
1150  /* send any outstanding mac event message else free message buffer */
1151  if (evt_idx)
1152  {
1153  if (reg && vl_api_can_send_msg (reg))
1154  {
1155  mp->n_macs = htonl (evt_idx);
1156  vl_api_send_msg (reg, (u8 *) mp);
1157  }
1158  else
1159  {
1160  if (reg)
1161  clib_warning ("MAC event to pid %d queue stuffed!"
1162  " %d MAC entries lost", client, evt_idx);
1163  vl_msg_api_free (mp);
1164  }
1165  }
1166  else
1167  vl_msg_api_free (mp);
1168  }
1169  return delta_t + accum_t;
1170 }
1171 
1172 static uword
1174  vlib_frame_t * f)
1175 {
1176  uword event_type, *event_data = 0;
1179  bool enabled = 0;
1180  f64 start_time, next_age_scan_time = CLIB_TIME_MAX;
1181 
1182  while (1)
1183  {
1184  if (lm->client_pid)
1186  else if (enabled)
1187  {
1188  f64 t = next_age_scan_time - vlib_time_now (vm);
1190  }
1191  else
1193 
1194  event_type = vlib_process_get_events (vm, &event_data);
1195  vec_reset_length (event_data);
1196 
1197  start_time = vlib_time_now (vm);
1198  enum
1199  { SCAN_MAC_AGE, SCAN_MAC_EVENT, SCAN_DISABLE } scan = SCAN_MAC_AGE;
1200 
1201  switch (event_type)
1202  {
1203  case ~0: /* timer expired */
1204  if (lm->client_pid != 0 && start_time < next_age_scan_time)
1205  scan = SCAN_MAC_EVENT;
1206  break;
1207 
1209  enabled = 1;
1210  break;
1211 
1213  enabled = 0;
1214  scan = SCAN_DISABLE;
1215  break;
1216 
1218  break;
1219 
1220  default:
1221  ASSERT (0);
1222  }
1223 
1224  if (scan == SCAN_MAC_EVENT)
1225  l2fib_main.evt_scan_duration = l2fib_scan (vm, start_time, 1);
1226  else
1227  {
1228  if (scan == SCAN_MAC_AGE)
1229  l2fib_main.age_scan_duration = l2fib_scan (vm, start_time, 0);
1230  if (scan == SCAN_DISABLE)
1231  {
1232  l2fib_main.age_scan_duration = 0;
1233  l2fib_main.evt_scan_duration = 0;
1234  }
1235  /* schedule next scan */
1236  if (enabled)
1237  next_age_scan_time = start_time + L2FIB_AGE_SCAN_INTERVAL;
1238  else
1239  next_age_scan_time = CLIB_TIME_MAX;
1240  }
1241  }
1242  return 0;
1243 }
1244 
1245 /* *INDENT-OFF* */
1246 VLIB_REGISTER_NODE (l2fib_mac_age_scanner_process_node) = {
1247  .function = l2fib_mac_age_scanner_process,
1248  .type = VLIB_NODE_TYPE_PROCESS,
1249  .name = "l2fib-mac-age-scanner-process",
1250 };
1251 /* *INDENT-ON* */
1252 
1253 clib_error_t *
1255 {
1256  l2fib_main_t *mp = &l2fib_main;
1257  l2fib_entry_key_t test_key;
1258  u8 test_mac[6];
1259 
1260  mp->vlib_main = vm;
1261  mp->vnet_main = vnet_get_main ();
1262 
1263  /* Create the hash table */
1264  BV (clib_bihash_init) (&mp->mac_table, "l2fib mac table",
1266 
1267  /* verify the key constructor is good, since it is endian-sensitive */
1268  clib_memset (test_mac, 0, sizeof (test_mac));
1269  test_mac[0] = 0x11;
1270  test_key.raw = 0;
1271  test_key.raw = l2fib_make_key ((u8 *) & test_mac, 0x1234);
1272  ASSERT (test_key.fields.mac[0] == 0x11);
1273  ASSERT (test_key.fields.bd_index == 0x1234);
1274 
1275  return 0;
1276 }
1277 
1279 
1280 /*
1281  * fd.io coding-style-patch-verification: ON
1282  *
1283  * Local Variables:
1284  * eval: (c-set-style "gnu")
1285  * End:
1286  */
static_always_inline void * allocate_mac_evt_buf(u32 client, u32 client_index)
Definition: l2_fib.c:975
u32 sw_if_index
Definition: ipsec_gre.api:37
f64 evt_scan_duration
Definition: l2_fib.h:52
static clib_error_t * l2fib_test_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: l2_fib.c:551
u32 global_learn_count
Definition: l2_learn.h:32
l2_input_config_t * configs
Definition: l2_input.h:61
u32 flags
Definition: vhost_user.h:115
u8 * format_vnet_sw_if_index_name_with_NA(u8 *s, va_list *args)
Format sw_if_index.
Definition: l2_fib.c:91
vlib_main_t * vlib_main
Definition: l2_fib.h:62
vnet_main_t * vnm
Definition: l2_fib.c:153
static f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
Suspend a cooperative multi-tasking thread Waits for an event, or for the indicated number of seconds...
Definition: node_funcs.h:673
#define BIHASH_KVP_PER_PAGE
Definition: bihash_16_8.h:19
static uword * vlib_process_wait_for_event(vlib_main_t *vm)
Definition: node_funcs.h:593
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
vnet_main_t * vnet_main
Definition: l2_fib.h:63
void clib_bihash_free(clib_bihash *h)
Destroy a bounded index extensible hash table.
unsigned long u64
Definition: types.h:89
u64 raw
Definition: l2_fib.h:149
l2_input_config_t * l2input_intf_config(u32 sw_if_index)
Get a pointer to the config for the given interface.
Definition: l2_input.c:526
#define clib_memcpy_fast(a, b, c)
Definition: string.h:81
#define NULL
Definition: clib.h:58
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:255
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:34
clib_error_t * l2fib_init(vlib_main_t *vm)
Definition: l2_fib.c:1254
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:522
int i
static_always_inline u8 * l2fib_swif_seq_num(u32 sw_if_index)
Definition: l2_fib.h:457
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:983
#define L2FIB_MEMORY_SIZE
Definition: l2_fib.h:28
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
unformat_function_t unformat_vnet_sw_interface
u32 max_macs_in_event
Definition: l2_fib.h:59
enum l2fib_entry_result_flags_t_ l2fib_entry_result_flags_t
vlib_main_t * vm
Definition: l2_fib.c:152
void * vl_msg_api_alloc(int nbytes)
static clib_error_t * l2fib_del(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Delete an entry from the L2FIB.
Definition: l2_fib.c:719
unsigned char u8
Definition: types.h:56
u8 * format_l2fib_entry_result_flags(u8 *s, va_list *args)
Definition: l2_fib.c:58
u8 action
Definition: l2.api:172
u32 client_index
Definition: l2_learn.h:39
Entry for learned or aged MAC in L2 MAC Events.
Definition: l2.api:168
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
double f64
Definition: types.h:142
#define fm
Definition: l2_fib.h:137
static uword vlib_process_suspend(vlib_main_t *vm, f64 dt)
Suspend a vlib cooperative multi-tasking thread for a period of time.
Definition: node_funcs.h:422
static int vl_api_can_send_msg(vl_api_registration_t *rp)
Definition: api.h:47
#define L2FIB_AGE_SCAN_INTERVAL
Definition: l2_fib.h:31
l2learn_main_t l2learn_main
Definition: l2_learn.c:33
#define static_always_inline
Definition: clib.h:99
u8 * format_ethernet_address(u8 *s, va_list *args)
Definition: format.c:44
int clib_bihash_add_del(clib_bihash *h, clib_bihash_kv *add_v, int is_add)
Add or delete a (key,value) pair from a bi-hash table.
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:163
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type...
Definition: node_funcs.h:516
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define clib_error_return(e, args...)
Definition: error.h:99
void l2fib_add_entry(const u8 *mac, u32 bd_index, u32 sw_if_index, l2fib_entry_result_flags_t flags)
Add an entry to the l2fib.
Definition: l2_fib.c:401
unsigned int u32
Definition: types.h:88
L2 MAC event for a list of learned or aged MACs.
Definition: l2.api:182
uword * bd_index_by_bd_id
Definition: l2_bd.h:36
struct l2fib_entry_result_t_::@262::@264 fields
u32 sw_if_index
Definition: l2.api:170
void l2fib_start_ager_scan(vlib_main_t *vm)
Kick off ager to scan MACs to age/delete MAC entries.
Definition: l2_fib.c:782
#define hash_get(h, key)
Definition: hash.h:249
f64 event_scan_delay
Definition: l2_fib.h:56
format_function_t format_vnet_sw_interface_name
struct l2fib_dump_walk_ctx_t_ l2fib_dump_walk_ctx_t
vlib_main_t * vlib_main
Definition: vnet.h:80
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:934
static void l2fib_show_walk_cb(BVT(clib_bihash_kv) *kvp, void *arg)
Definition: l2_fib.c:162
long ctx[MAX_CONNS]
Definition: main.c:144
u32 bd_id
Definition: gbp.api:269
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
void l2fib_flush_bd_mac(vlib_main_t *vm, u32 bd_index)
Flush all non static MACs in a bridge domain.
Definition: l2_fib.c:815
#define PREDICT_FALSE(x)
Definition: clib.h:111
void l2fib_flush_all_mac(vlib_main_t *vm)
Flush all non static MACs - flushes all valid BDs.
Definition: l2_fib.c:826
l2fib_entry_key_t * l2fe_key
Definition: l2_fib.c:110
#define L2FIB_NUM_BUCKETS
Definition: l2_fib.h:27
static_always_inline f64 l2fib_scan(vlib_main_t *vm, f64 start_time, u8 event_only)
Definition: l2_fib.c:987
void clib_bihash_init(clib_bihash *h, char *name, u32 nbuckets, uword memory_size)
initialize a bounded index extensible hash table
l2fib_main_t l2fib_main
Definition: l2_fib.c:55
static u32 bd_is_valid(l2_bridge_domain_t *bd_config)
Definition: l2_bd.h:133
static clib_error_t * clear_l2fib(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Clear all entries in L2FIB.
Definition: l2_fib.c:358
BVT(clib_bihash)
Definition: l2_fib.c:968
clib_error_t * l2fib_sw_interface_up_down(vnet_main_t *vnm, u32 sw_if_index, u32 flags)
Definition: l2_fib.c:958
static clib_error_t * show_l2fib(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Display the contents of the l2fib.
Definition: l2_fib.c:226
struct l2fib_entry_key_t::@254::@256 fields
An API client registration, only in vpp/vlib.
Definition: api_common.h:45
void clib_bihash_foreach_key_value_pair(clib_bihash *h, void *callback, void *arg)
Visit active (key,value) pairs in a bi-hash table.
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
#define UNFORMAT_END_OF_INPUT
Definition: format.h:144
static clib_error_t * l2fib_flush_mac_all(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Flush all MACs, except static ones The CLI format is: l2fib flush-mac all.
Definition: l2_fib.c:869
u32 l2fib_del_entry(const u8 *mac, u32 bd_index, u32 sw_if_index)
Delete an entry from the l2fib.
Definition: l2_fib.c:685
#define CLIB_PREFETCH(addr, size, type)
Definition: cache.h:80
vlib_main_t * vm
Definition: buffer.c:312
static void incr_mac_address(u8 *mac)
Definition: l2_fib.c:79
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
static clib_error_t * l2fib_flush_mac_int(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Flush MACs, except static ones, associated with an interface The CLI format is: l2fib flush-mac inter...
Definition: l2_fib.c:843
#define clib_warning(format, args...)
Definition: error.h:59
f64 age_scan_duration
Definition: l2_fib.h:53
static u64 l2fib_make_key(const u8 *mac_address, u16 bd_index)
make address sanitizer skip this: The 6-Bytes mac-address is cast into an 8-Bytes u64...
Definition: l2_fib.h:223
void l2fib_clear_table(void)
Definition: l2_fib.c:343
static l2fib_seq_num_t l2fib_cur_seq_num(u32 bd_index, u32 sw_if_index)
Definition: l2_fib.c:385
static_always_inline l2_bridge_domain_t * l2input_bd_config(u32 bd_index)
Definition: l2_input.h:85
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:56
u8 mac_addr[6]
Definition: l2.api:171
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:155
static void l2fib_dump_walk_cb(BVT(clib_bihash_kv) *kvp, void *arg)
Definition: l2_fib.c:115
uword unformat_ethernet_address(unformat_input_t *input, va_list *args)
Definition: format.c:233
#define ASSERT(truth)
u8 is_add
Definition: ipsec_gre.api:36
#define CLIB_TIME_MAX
Definition: time.h:212
Definition: l2_fib.h:71
static uword l2fib_mac_age_scanner_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Definition: l2_fib.c:1173
vl_api_mac_entry_t mac[n_macs]
Definition: l2.api:187
size_t count
Definition: vapi.c:47
VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION(l2fib_sw_interface_up_down)
u32 global_learn_limit
Definition: l2_learn.h:35
void vl_msg_api_free(void *)
template key/value backing page structure
Definition: bihash_doc.h:44
static clib_error_t * l2fib_flush_mac_bd(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Flush bridge-domain MACs except static ones.
Definition: l2_fib.c:914
l2input_main_t l2input_main
Definition: l2_input.c:128
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u64 uword
Definition: types.h:112
typedef key
Definition: ipsec.api:244
l2fib_entry_result_t * l2fe_res
Definition: l2_fib.c:111
l2_bridge_domain_t * bd_configs
Definition: l2_input.h:64
static void l2fib_add_filter_entry(const u8 *mac, u32 bd_index)
Definition: l2_fib.h:433
void l2fib_table_dump(u32 bd_index, l2fib_entry_key_t **l2fe_key, l2fib_entry_result_t **l2fe_res)
Definition: l2_fib.c:132
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
#define vec_foreach(var, vec)
Vector iterator.
static void * clib_bihash_get_value(clib_bihash *h, uword offset)
Get pointer to value page given its clib mheap offset.
bd_main_t bd_main
Definition: l2_bd.c:44
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
static clib_error_t * l2fib_add(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Add an entry to the L2FIB.
Definition: l2_fib.c:446
u32 client_pid
Definition: l2_learn.h:38
vl_api_mac_address_t mac
Definition: gbp.api:120
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:762
void l2fib_flush_int_mac(vlib_main_t *vm, u32 sw_if_index)
Flush all non static MACs from an interface.
Definition: l2_fib.c:805
static vnet_sw_interface_t * vnet_get_sw_interface_or_null(vnet_main_t *vnm, u32 sw_if_index)
struct l2fib_show_walk_ctx_t_ l2fib_show_walk_ctx_t
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
u64 raw
Definition: l2_fib.h:85
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:170
signed short i16
Definition: types.h:46