61 tmp = clib_net_to_host_u64 (tmp);
63 tmp = clib_host_to_net_u64 (tmp);
73 u32 sw_if_index = va_arg (*args,
u32);
74 if (sw_if_index == ~0)
79 return format (s,
"Stale");
90 BVT (clib_bihash) *
h = &msm->mac_table;
91 BVT (clib_bihash_bucket) * b;
97 for (i = 0; i <
h->nbuckets; i++)
103 for (j = 0; j < (1 << b->log2_pages); j++)
107 if (
v->kvp[k].key == ~0ULL &&
v->kvp[k].value == ~0ULL)
110 key.
raw =
v->kvp[k].key;
111 result.
raw =
v->kvp[k].value;
113 if ((bd_index == ~0) || (bd_index == key.
fields.bd_index))
132 BVT (clib_bihash) *
h = &msm->mac_table;
133 BVT (clib_bihash_bucket) * b;
138 u64 total_entries = 0;
143 u32 bd_id, bd_index = ~0;
149 else if (
unformat (input,
"verbose"))
151 else if (
unformat (input,
"bd_index %d", &bd_index))
158 else if (
unformat (input,
"bd_id %d", &bd_id))
174 for (i = 0; i <
h->nbuckets; i++)
180 for (j = 0; j < (1 << b->log2_pages); j++)
184 if (
v->kvp[k].key == ~0ULL &&
v->kvp[k].value == ~0ULL)
187 if ((verbose || learn) && first_entry)
191 "%=19s%=7s%=7s%=8s%=9s%=7s%=7s%=5s%=30s",
192 "Mac-Address",
"BD-Idx",
"If-Idx",
193 "BSN-ISN",
"Age(min)",
"static",
"filter",
194 "bvi",
"Interface-Name");
197 key.
raw =
v->kvp[k].key;
198 result.
raw =
v->kvp[k].value;
200 if ((verbose || learn)
201 & ((bd_index >> 31) || (bd_index == key.
fields.bd_index)))
203 if (learn && result.
fields.age_not)
214 i16 delta = now - result.
fields.timestamp;
215 delta += delta < 0 ? 256 : 0;
216 s =
format (s,
"%d", delta);
222 "%=19U%=7d%=7d %3d/%-3d%=9v%=7s%=7s%=5s%=30U",
225 result.
fields.sw_if_index == ~0
226 ? -1 : result.
fields.sw_if_index,
228 s, result.
fields.static_mac ?
"*" :
"-",
229 result.
fields.filter ?
"*" :
"-",
230 result.
fields.bvi ?
"*" :
"-",
241 if (total_entries == 0)
247 "Last scan time: %.4esec Learn limit: %d ",
252 "Last e-scan time: %.4esec Delay: %.2esec " 253 "Max macs in event: %d",
260 BV (format_bihash),
h, 1 );
289 .path =
"show l2fib",
290 .short_help =
"show l2fib [verbose | learn | bd_id <nn> | bd_index <nn> | raw",
333 .path =
"clear l2fib",
334 .short_help =
"clear l2fib",
357 u32 sw_if_index,
u8 static_mac,
u8 filter_mac,
u8 bvi_mac)
361 __attribute__ ((unused))
u32 bucket_contents;
364 BVT (clib_bihash_kv) kv;
373 result.
raw = kv.value;
380 result.
fields.sw_if_index = sw_if_index;
381 result.
fields.static_mac = static_mac;
382 result.
fields.filter = filter_mac;
383 result.
fields.bvi = bvi_mac;
384 result.
fields.age_not = 1;
387 kv.value = result.
raw;
409 u32 sw_if_index = ~0;
421 if (!
unformat (input,
"%d", &bd_id))
502 .short_help =
"l2fib add <mac> <bridge-domain-id> filter | <intf> [static | bvi]",
513 u8 mac[6], save_mac[6];
534 else if (
unformat (input,
"count %d", &count))
543 if (is_add == 0 && is_del == 0 && is_check == 0)
545 "noop: pick at least one of (add,del,check)");
551 for (i = 0; i <
count; i++)
560 BVT (clib_bihash_kv) kv;
565 for (i = 0; i <
count; i++)
581 for (i = 0; i <
count; i++)
630 .path =
"test l2fib",
631 .short_help =
"test l2fib [add|del|check] mac <base-addr> count <nn>",
647 BVT (clib_bihash_kv) kv;
655 result.
raw = kv.value;
699 if (!
unformat (input,
"%d", &bd_id))
736 .short_help =
"l2fib del <mac> <bridge-domain-id>",
849 .path =
"l2fib flush-mac all",
850 .short_help =
"l2fib flush-mac all",
865 .path =
"l2fib flush-mac interface",
866 .short_help =
"l2fib flush-mac interface <if-name>",
885 if (!
unformat (input,
"%d", &bd_id))
914 .path =
"l2fib flush-mac bridge-domain",
915 .short_help =
"l2fib flush-mac bridge-domain <bd-id>",
931 BVT (clib_bihash) * get_mac_table (
void)
934 return &mp->mac_table;
943 mp->_vl_msg_id = htons (VL_API_L2_MACS_EVENT);
944 mp->
pid = htonl (client);
955 BVT (clib_bihash) *
h = &fm->mac_table;
957 f64 last_start = start_time;
973 for (i = 0; i <
h->nbuckets; i++)
984 if (i < (
h->nbuckets - 3))
986 BVT (clib_bihash_bucket) * b = &
h->buckets[i + 3];
988 b = &
h->buckets[i + 1];
997 BVT (clib_bihash_bucket) * b = &
h->buckets[
i];
1001 for (j = 0; j < (1 << b->log2_pages); j++)
1005 if (
v->kvp[k].key == ~0ULL &&
v->kvp[k].value == ~0ULL)
1011 if (result.
fields.age_not == 0)
1019 if (q && (q->cursize < q->maxsize))
1021 mp->
n_macs = htonl (evt_idx);
1029 " %d MAC entries lost", client,
1035 if (result.
fields.lrn_evt)
1042 htonl (result.
fields.sw_if_index);
1044 result.
fields.lrn_evt = 0;
1045 BVT (clib_bihash_kv) kv;
1047 kv.value = result.
raw;
1054 if (event_only || result.
fields.age_not)
1059 u32 sw_if_index = result.
fields.sw_if_index;
1061 if (result.
fields.sn.as_u16 != sn)
1070 i16 delta = (
u8) (start_time / 60) - result.
fields.timestamp;
1071 delta += delta < 0 ? 256 : 0;
1073 if (delta < bd_config->mac_age)
1083 htonl (result.
fields.sw_if_index);
1087 BVT (clib_bihash_kv) kv;
1104 if (q && (q->cursize < q->maxsize))
1106 mp->
n_macs = htonl (evt_idx);
1113 " %d MAC entries lost", client, evt_idx);
1120 return delta_t + accum_t;
1124 #define TIME_MAX (1.7976931348623157e+308) 1130 uword event_type, *event_data = 0;
1153 { SCAN_MAC_AGE, SCAN_MAC_EVENT, SCAN_DISABLE } scan = SCAN_MAC_AGE;
1158 if (lm->
client_pid != 0 && start_time < next_age_scan_time)
1159 scan = SCAN_MAC_EVENT;
1168 scan = SCAN_DISABLE;
1178 if (scan == SCAN_MAC_EVENT)
1182 if (scan == SCAN_MAC_AGE)
1184 if (scan == SCAN_DISABLE)
1203 .name =
"l2fib-mac-age-scanner-process",
1222 memset (test_mac, 0,
sizeof (test_mac));
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
sll srl srl sll sra u16x4 i
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.
static f64 vlib_time_now(vlib_main_t *vm)
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)
#define L2FIB_MEMORY_SIZE
unformat_function_t unformat_vnet_sw_interface
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.
Entry for learned or aged MAC in L2 MAC Events.
#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.
#define L2FIB_AGE_SCAN_INTERVAL
l2learn_main_t l2learn_main
#define static_always_inline
u8 * format_ethernet_address(u8 *s, va_list *args)
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...
void l2fib_add_entry(u8 *mac, u32 bd_index, u32 sw_if_index, u8 static_mac, u8 filter_mac, u8 bvi_mac)
Add an entry to the l2fib.
#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...)
L2 MAC event for a list of learned or aged MACs.
uword * bd_index_by_bd_id
void * vl_msg_api_alloc(int nbytes)
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
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
void vl_msg_api_free(void *)
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.
#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 void l2fib_add_fwd_entry(u8 *mac, u32 bd_index, u32 sw_if_index, u8 static_mac, u8 bvi_mac)
static u32 bd_is_valid(l2_bridge_domain_t *bd_config)
struct l2fib_entry_key_t::@206::@208 fields
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.
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.
#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...)
#define clib_memcpy(a, b, c)
static vnet_sw_interface_t * vnet_get_sw_interface_safe(vnet_main_t *vnm, u32 sw_if_index)
unix_shared_memory_queue_t * vl_api_client_index_to_input_queue(u32 index)
void l2fib_clear_table(void)
static l2fib_seq_num_t l2fib_cur_seq_num(u32 bd_index, u32 sw_if_index)
#define VLIB_CLI_COMMAND(x,...)
struct l2fib_entry_result_t::@214::@216 fields
#define VNET_SW_INTERFACE_FLAG_ADMIN_UP
void vl_msg_api_send_shmem(unix_shared_memory_queue_t *q, u8 *elem)
uword unformat_ethernet_address(unformat_input_t *input, va_list *args)
int clib_bihash_search(clib_bihash *h, clib_bihash_kv *search_v, clib_bihash_kv *return_v)
Search a bi-hash table.
static void l2fib_add_filter_entry(u8 *mac, u32 bd_index)
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)
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)
static u64 l2fib_make_key(u8 *mac_address, u16 bd_index)
make address sanitizer skip this: The 6-Bytes mac-address is cast into an 8-Bytes u64...
l2_bridge_domain_t * bd_configs
void l2fib_table_dump(u32 bd_index, l2fib_entry_key_t **l2fe_key, l2fib_entry_result_t **l2fe_res)
u32 l2fib_del_entry(u8 *mac, u32 bd_index)
Delete an entry from the l2fib.
#define VLIB_REGISTER_NODE(x,...)
#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.
vlib_node_registration_t l2fib_mac_age_scanner_process_node
(constructor) VLIB_REGISTER_NODE (l2fib_mac_age_scanner_process_node)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
static u32 l2fib_del_entry_by_key(u64 raw_key)
Delete an entry from the l2fib.
void l2fib_flush_int_mac(vlib_main_t *vm, u32 sw_if_index)
Flush all non static MACs from an interface.
struct _unix_shared_memory_queue unix_shared_memory_queue_t