66 s =
format (s,
"l2-learn: sw_if_index %d dst %U src %U bd_index %d",
75 #define foreach_l2learn_error \ 76 _(L2LEARN, "L2 learn packets") \ 77 _(MISS, "L2 learn misses") \ 78 _(MAC_MOVE, "L2 mac moves") \ 79 _(MAC_MOVE_VIOLATE, "L2 mac move violations") \ 80 _(LIMIT, "L2 not learned due to limit") \ 81 _(HIT_UPDATE, "L2 learn hit updates") \ 82 _(FILTER_DROP, "L2 filter mac drops") 86 #define _(sym,str) L2LEARN_ERROR_##sym, 93 #define _(sym,string) string, 124 feature_bitmap =
vnet_buffer (b0)->l2.feature_bitmap & ~L2INPUT_FEAT_LEARN;
127 vnet_buffer (b0)->l2.feature_bitmap = feature_bitmap;
137 u32 dtime = timestamp - result0->
fields.timestamp;
144 if (result0->
fields.static_mac)
149 if ((*count > 2) && (dtime == 1))
152 counter_base[L2LEARN_ERROR_HIT_UPDATE] += 1;
155 else if (result0->
raw == ~0)
158 counter_base[L2LEARN_ERROR_MISS] += 1;
166 counter_base[L2LEARN_ERROR_LIMIT] += 1;
173 result0->
fields.sw_if_index = sw_if_index0;
178 if (result0->
fields.filter)
182 b0->
error = node->
errors[L2LEARN_ERROR_FILTER_DROP];
187 counter_base[L2LEARN_ERROR_MAC_MOVE] += 1;
189 if (result0->
fields.static_mac)
195 b0->
error = node->
errors[L2LEARN_ERROR_MAC_MOVE_VIOLATE];
204 result0->
fields.sw_if_index = sw_if_index0;
208 result0->
fields.timestamp = timestamp;
211 BVT (clib_bihash_kv) kv;
213 kv.value = result0->
raw;
217 cached_key->
raw = ~0;
225 u32 n_left_from, *from, *to_next;
242 cached_result.
raw = ~0;
244 while (n_left_from > 0)
251 while (n_left_from >= 8 && n_left_to_next >= 4)
253 u32 bi0, bi1, bi2, bi3;
255 u32 next0, next1, next2, next3;
256 u32 sw_if_index0, sw_if_index1, sw_if_index2, sw_if_index3;
260 u32 bucket0, bucket1, bucket2, bucket3;
284 to_next[0] = bi0 = from[0];
285 to_next[1] = bi1 = from[1];
286 to_next[2] = bi2 = from[2];
287 to_next[3] = bi3 = from[3];
353 L2LEARN_ERROR_L2LEARN, 4);
364 &key0, &key1, &key2, &key3,
365 &bucket0, &bucket1, &bucket2, &bucket3,
366 &result0, &result1, &result2, &result3);
369 b0, sw_if_index0, &key0, &cached_key,
370 &count, &result0, &next0, timestamp);
373 b1, sw_if_index1, &key1, &cached_key,
374 &count, &result1, &next1, timestamp);
377 b2, sw_if_index2, &key2, &cached_key,
378 &count, &result2, &next2, timestamp);
381 b3, sw_if_index3, &key3, &cached_key,
382 &count, &result3, &next3, timestamp);
387 to_next, n_left_to_next,
389 next0, next1, next2, next3);
392 while (n_left_from > 0 && n_left_to_next > 0)
428 L2LEARN_ERROR_L2LEARN, 1);
433 &key0, &bucket0, &result0);
436 b0, sw_if_index0, &key0, &cached_key,
437 &count, &result0, &next0, timestamp);
441 to_next, n_left_to_next,
464 .vector_size =
sizeof (
u32),
497 mp->mac_table = get_mac_table ();
558 .path =
"set interface l2 learn",
559 .short_help =
"set interface l2 learn <interface> [disable]",
vnet_main_t * vnet_get_main(void)
static f64 vlib_time_now(vlib_main_t *vm)
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
#define vlib_validate_buffer_enqueue_x4(vm, node, next_index, to_next, n_left_to_next, bi0, bi1, bi2, bi3, next0, next1, next2, next3)
Finish enqueueing four buffers forward in the graph.
struct _vlib_node_registration vlib_node_registration_t
clib_error_t * l2learn_init(vlib_main_t *vm)
unformat_function_t unformat_vnet_sw_interface
vlib_error_t * errors
Vector of errors for this node.
static_always_inline void l2learn_process(vlib_node_runtime_t *node, l2learn_main_t *msm, u64 *counter_base, vlib_buffer_t *b0, u32 sw_if_index0, l2fib_entry_key_t *key0, l2fib_entry_key_t *cached_key, u32 *count, l2fib_entry_result_t *result0, u32 *next0, u8 timestamp)
Perform learning on one packet based on the mac table lookup result.
#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)
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
#define clib_error_return(e, args...)
static char * l2learn_error_strings[]
vlib_error_main_t error_main
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
#define VLIB_CONFIG_FUNCTION(x, n,...)
static_always_inline uword l2learn_node_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, int do_trace)
#define L2FIB_NUM_BUCKETS
static u32 feat_bitmap_get_next_node_index(u32 *next_nodes, u32 bitmap)
Return the graph node index for the feature corresponding to the first set bit in the bitmap...
static u8 * format_l2learn_trace(u8 *s, va_list *args)
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
vlib_error_t error
Error code for buffers to be enqueued to error handler.
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
#define CLIB_PREFETCH(addr, size, type)
static void feat_bitmap_init_next_nodes(vlib_main_t *vm, u32 node_index, u32 num_features, char **feat_names, u32 *next_nodes)
Initialize the feature next-node indexes of a graph node.
#define foreach_l2learn_error
static clib_error_t * l2learn_config(vlib_main_t *vm, unformat_input_t *input)
#define VLIB_BUFFER_IS_TRACED
#define clib_memcpy(a, b, c)
static clib_error_t * int_learn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Set subinterface learn enable/disable.
u32 feat_next_node_index[32]
#define VLIB_CLI_COMMAND(x,...)
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
struct l2fib_entry_result_t::@184::@186 fields
#define VLIB_NODE_FLAG_TRACE
static uword l2learn_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
#define VLIB_NODE_FUNCTION_MULTIARCH(node, fn)
#define VLIB_REGISTER_NODE(x,...)
l2learn_main_t l2learn_main
static vlib_node_t * vlib_get_node(vlib_main_t *vm, u32 i)
Get vlib node by index.
static_always_inline void l2fib_lookup_4(BVT(clib_bihash)*mac_table, l2fib_entry_key_t *cached_key, l2fib_entry_result_t *cached_result, u8 *mac0, u8 *mac1, u8 *mac2, u8 *mac3, u16 bd_index0, u16 bd_index1, u16 bd_index2, u16 bd_index3, l2fib_entry_key_t *key0, l2fib_entry_key_t *key1, l2fib_entry_key_t *key2, l2fib_entry_key_t *key3, u32 *bucket0, u32 *bucket1, u32 *bucket2, u32 *bucket3, l2fib_entry_result_t *result0, l2fib_entry_result_t *result1, l2fib_entry_result_t *result2, l2fib_entry_result_t *result3)
u16 flags
Copy of main node flags.
static_always_inline void l2fib_lookup_1(BVT(clib_bihash)*mac_table, l2fib_entry_key_t *cached_key, l2fib_entry_result_t *cached_result, u8 *mac0, u16 bd_index0, l2fib_entry_key_t *key0, u32 *bucket0, l2fib_entry_result_t *result0)
Lookup the entry for mac and bd_index in the mac table for 1 packet.
#define CLIB_CACHE_LINE_BYTES
u32 flags
buffer flags: VLIB_BUFFER_IS_TRACED: trace this buffer.
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
static vlib_node_registration_t l2learn_node
(constructor) VLIB_REGISTER_NODE (l2learn_node)