69 if (flags & L2FIB_ENTRY_RESULT_FLAG_##a) \ 70 s = format (s, "%s ", t); \ 82 tmp = clib_net_to_host_u64 (tmp);
84 tmp = clib_host_to_net_u64 (tmp);
95 if (sw_if_index == ~0)
101 return format (s,
"Stale");
122 result.
raw = kvp->value;
130 return (BIHASH_WALK_CONTINUE);
175 "%=19s%=7s%=7s%=8s%=9s%=7s%=7s%=5s%=30s",
176 "Mac-Address",
"BD-Idx",
"If-Idx",
177 "BSN-ISN",
"Age(min)",
"static",
"filter",
178 "bvi",
"Interface-Name");
182 result.
raw = kvp->value;
190 if (ctx->
learn && l2fib_entry_result_is_set_AGE_NOT (&result))
191 return (BIHASH_WALK_CONTINUE);
193 if (ctx->
add && !l2fib_entry_result_is_set_AGE_NOT (&result))
194 return (BIHASH_WALK_CONTINUE);
199 if (l2fib_entry_result_is_set_AGE_NOT (&result))
201 else if (bd_config->
mac_age == 0)
206 delta += delta < 0 ? 256 : 0;
207 s =
format (s,
"%d", delta);
211 "%=19U%=7d%=7d %3d/%-3d%=9v%=7s%=7s%=5s%=30U",
214 result.
fields.sw_if_index == ~0
215 ? -1 : result.
fields.sw_if_index,
217 l2fib_entry_result_is_set_STATIC (&result) ?
"*" :
"-",
218 l2fib_entry_result_is_set_FILTER (&result) ?
"*" :
"-",
219 l2fib_entry_result_is_set_BVI (&result) ?
"*" :
"-",
225 return (BIHASH_WALK_CONTINUE);
253 else if (
unformat (input,
"verbose"))
271 else if (
unformat (input,
"bd_id %d", &bd_id))
281 "bridge domain id %d doesn't exist\n",
297 "Last scan time: %.4esec Learn limit: %d ",
302 "Last e-scan time: %.4esec Delay: %.2esec " 303 "Max macs in event: %d",
310 BV (format_bihash), &msm->mac_table, 1 );
338 .path =
"show l2fib",
339 .short_help =
"show l2fib [all] | [bd_id <nn> | bd_index <nn>] [learn | add] | [raw]",
382 .path =
"clear l2fib",
383 .short_help =
"clear l2fib",
410 __attribute__ ((unused))
u32 bucket_contents;
413 BVT (clib_bihash_kv) kv;
420 if (BV (clib_bihash_search) (&fm->mac_table, &kv, &kv))
423 result.
raw = kv.value;
424 if ((!l2fib_entry_result_is_set_AGE_NOT (&result))
435 l2fib_entry_result_set_AGE_NOT (&result);
437 kv.value = result.
raw;
472 if (!
unformat (input,
"%d", &bd_id))
501 flags |= L2FIB_ENTRY_RESULT_FLAG_STATIC;
503 flags |= (L2FIB_ENTRY_RESULT_FLAG_STATIC | L2FIB_ENTRY_RESULT_FLAG_BVI);
548 .short_help =
"l2fib add <mac> <bridge-domain-id> filter | <intf> [static | bvi]",
559 u8 mac[6], save_mac[6];
579 else if (
unformat (input,
"count %d", &count))
588 if (is_add == 0 && is_del == 0 && is_check == 0)
590 "noop: pick at least one of (add,del,check)");
596 for (i = 0; i <
count; i++)
606 BVT (clib_bihash_kv) kv;
611 for (i = 0; i <
count; i++)
614 if (BV (clib_bihash_search) (&mp->mac_table, &kv, &kv))
627 for (i = 0; i <
count; i++)
676 .path =
"test l2fib",
677 .short_help =
"test l2fib [add|del|check] mac <base-addr> count <nn>",
693 BVT (clib_bihash_kv) kv;
698 if (BV (clib_bihash_search) (&mp->mac_table, &kv, &kv))
701 result.
raw = kv.value;
704 if ((sw_if_index != 0) && (sw_if_index != result.
fields.sw_if_index))
708 if ((!l2fib_entry_result_is_set_AGE_NOT (&result)) &&
740 if (!
unformat (input,
"%d", &bd_id))
777 .short_help =
"l2fib del <mac> <bridge-domain-id> []",
890 .path =
"l2fib flush-mac all",
891 .short_help =
"l2fib flush-mac all",
906 .path =
"l2fib flush-mac interface",
907 .short_help =
"l2fib flush-mac interface <if-name>",
926 if (!
unformat (input,
"%d", &bd_id))
955 .path =
"l2fib flush-mac bridge-domain",
956 .short_help =
"l2fib flush-mac bridge-domain <bd-id>",
972 BVT (clib_bihash) * get_mac_table (
void)
975 return &mp->mac_table;
984 mp->_vl_msg_id = htons (VL_API_L2_MACS_EVENT);
985 mp->
pid = htonl (client);
996 BVT (clib_bihash) *
h = &fm->mac_table;
998 f64 last_start = start_time;
1002 u32 learn_count = 0;
1009 if (alloc_arena (
h) == 0)
1018 for (i = 0; i <
h->nbuckets; i++)
1022 if (delta_t > 20e-6)
1029 if (i < (
h->nbuckets - 3))
1031 BVT (clib_bihash_bucket) * b = &
h->buckets[i + 3];
1033 b = &
h->buckets[i + 1];
1042 BVT (clib_bihash_bucket) * b = &
h->buckets[
i];
1046 for (j = 0; j < (1 << b->log2_pages); j++)
1050 if (v->kvp[k].key == ~0ULL && v->kvp[k].value == ~0ULL)
1056 if (!l2fib_entry_result_is_set_AGE_NOT (&result))
1066 mp->
n_macs = htonl (evt_idx);
1074 " %d MAC entries lost", client,
1080 if (l2fib_entry_result_is_set_LRN_EVT (&result))
1085 mp->
mac[evt_idx].action =
1086 l2fib_entry_result_is_set_LRN_MOV (&result) ?
1088 mp->
mac[evt_idx].sw_if_index =
1089 htonl (result.
fields.sw_if_index);
1091 l2fib_entry_result_clear_LRN_EVT (&result);
1092 l2fib_entry_result_clear_LRN_MOV (&result);
1093 BVT (clib_bihash_kv) kv;
1095 kv.value = result.
raw;
1102 if (event_only || l2fib_entry_result_is_set_AGE_NOT (&result))
1109 if (result.
fields.sn.as_u16 != sn)
1118 i16 delta = (
u8) (start_time / 60) - result.
fields.timestamp;
1119 delta += delta < 0 ? 256 : 0;
1121 if (delta < bd_config->mac_age)
1131 mp->
mac[evt_idx].sw_if_index =
1132 htonl (result.
fields.sw_if_index);
1136 BVT (clib_bihash_kv) kv;
1163 mp->
n_macs = htonl (evt_idx);
1170 " %d MAC entries lost", client, evt_idx);
1177 return delta_t + accum_t;
1184 uword event_type, *event_data = 0;
1207 { SCAN_MAC_AGE, SCAN_MAC_EVENT, SCAN_DISABLE } scan = SCAN_MAC_AGE;
1212 if (lm->
client_pid != 0 && start_time < next_age_scan_time)
1213 scan = SCAN_MAC_EVENT;
1222 scan = SCAN_DISABLE;
1232 if (scan == SCAN_MAC_EVENT)
1236 if (scan == SCAN_MAC_AGE)
1238 if (scan == SCAN_DISABLE)
1257 .name =
"l2fib-mac-age-scanner-process",
static_always_inline void * allocate_mac_evt_buf(u32 client, u32 client_index)
static clib_error_t * l2fib_test_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
l2_input_config_t * configs
u8 * format_vnet_sw_if_index_name_with_NA(u8 *s, va_list *args)
Format sw_if_index.
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...
#define BIHASH_KVP_PER_PAGE
static uword * vlib_process_wait_for_event(vlib_main_t *vm)
vnet_main_t * vnet_get_main(void)
void clib_bihash_free(clib_bihash *h)
Destroy a bounded index extensible hash table.
#define clib_memcpy_fast(a, b, c)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static f64 vlib_time_now(vlib_main_t *vm)
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
clib_error_t * l2fib_init(vlib_main_t *vm)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
static_always_inline u8 * l2fib_swif_seq_num(u32 sw_if_index)
static int l2fib_show_walk_cb(BVT(clib_bihash_kv) *kvp, void *arg)
#define L2FIB_MEMORY_SIZE
unformat_function_t unformat_vnet_sw_interface
enum l2fib_entry_result_flags_t_ l2fib_entry_result_flags_t
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.
u8 * format_l2fib_entry_result_flags(u8 *s, va_list *args)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
static uword vlib_process_suspend(vlib_main_t *vm, f64 dt)
Suspend a vlib cooperative multi-tasking thread for a period of time.
static int vl_api_can_send_msg(vl_api_registration_t *rp)
#define L2FIB_AGE_SCAN_INTERVAL
l2learn_main_t l2learn_main
#define static_always_inline
u8 * format_ethernet_address(u8 *s, va_list *args)
vl_api_interface_index_t sw_if_index
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)
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...
#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...)
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.
L2 MAC event for a list of learned or aged MACs.
uword * bd_index_by_bd_id
static int l2fib_dump_walk_cb(BVT(clib_bihash_kv) *kvp, void *arg)
void l2fib_start_ager_scan(vlib_main_t *vm)
Kick off ager to scan MACs to age/delete MAC entries.
format_function_t format_vnet_sw_interface_name
struct l2fib_dump_walk_ctx_t_ l2fib_dump_walk_ctx_t
void clib_bihash_foreach_key_value_pair(clib_bihash *h, clib_bihash_foreach_key_value_pair_cb *callback, void *arg)
Visit active (key,value) pairs in a bi-hash table.
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
struct l2fib_entry_result_t_::@376::@378 fields
void l2fib_flush_bd_mac(vlib_main_t *vm, u32 bd_index)
Flush all non static MACs in a bridge domain.
void l2fib_flush_all_mac(vlib_main_t *vm)
Flush all non static MACs - flushes all valid BDs.
l2fib_entry_key_t * l2fe_key
#define L2FIB_NUM_BUCKETS
static_always_inline f64 l2fib_scan(vlib_main_t *vm, f64 start_time, u8 event_only)
void clib_bihash_init(clib_bihash *h, char *name, u32 nbuckets, uword memory_size)
initialize a bounded index extensible hash table
static u32 bd_is_valid(l2_bridge_domain_t *bd_config)
static clib_error_t * clear_l2fib(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Clear all entries in L2FIB.
clib_error_t * l2fib_sw_interface_up_down(vnet_main_t *vnm, u32 sw_if_index, u32 flags)
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.
An API client registration, only in vpp/vlib.
#define VLIB_REGISTER_NODE(x,...)
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.
u32 l2fib_del_entry(const u8 *mac, u32 bd_index, u32 sw_if_index)
Delete an entry from the l2fib.
#define CLIB_PREFETCH(addr, size, type)
static void incr_mac_address(u8 *mac)
#define vec_free(V)
Free vector's memory (no header).
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...
#define clib_warning(format, args...)
static u64 l2fib_make_key(const u8 *mac_address, u16 bd_index)
void l2fib_clear_table(void)
static l2fib_seq_num_t l2fib_cur_seq_num(u32 bd_index, u32 sw_if_index)
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
#define VLIB_CLI_COMMAND(x,...)
uword unformat_ethernet_address(unformat_input_t *input, va_list *args)
static uword l2fib_mac_age_scanner_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
vl_api_mac_entry_t mac[n_macs]
VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION(l2fib_sw_interface_up_down)
void vl_msg_api_free(void *)
template key/value backing page structure
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.
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
l2fib_entry_result_t * l2fe_res
struct l2fib_entry_key_t::@368::@370 fields
l2_bridge_domain_t * bd_configs
static void l2fib_add_filter_entry(const u8 *mac, u32 bd_index)
void l2fib_table_dump(u32 bd_index, l2fib_entry_key_t **l2fe_key, l2fib_entry_result_t **l2fe_res)
#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.
#define CLIB_CACHE_LINE_BYTES
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.
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
void l2fib_flush_int_mac(vlib_main_t *vm, u32 sw_if_index)
Flush all non static MACs from an interface.
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