X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fl2%2Fl2_learn.c;h=732a1fc5d8534fa764c984b46299e1a564029eb4;hb=eb1525f1060569cc3dc03aca7696ce05e1401a09;hp=7f19f936d702aabd674b763f7df713014426bd3f;hpb=7cd468a3d7dee7d6c92f69a0bb7061ae208ec727;p=vpp.git diff --git a/src/vnet/l2/l2_learn.c b/src/vnet/l2/l2_learn.c index 7f19f936d70..732a1fc5d85 100644 --- a/src/vnet/l2/l2_learn.c +++ b/src/vnet/l2/l2_learn.c @@ -29,6 +29,10 @@ #include #include +#ifndef CLIB_MARCH_VARIANT +l2learn_main_t l2learn_main; +#endif + /** * @file * @brief Ethernet Bridge Learning. @@ -78,7 +82,7 @@ _(MISS, "L2 learn misses") \ _(MAC_MOVE, "L2 mac moves") \ _(MAC_MOVE_VIOLATE, "L2 mac move violations") \ _(LIMIT, "L2 not learned due to limit") \ -_(HIT, "L2 learn hits") \ +_(HIT_UPDATE, "L2 learn hit updates") \ _(FILTER_DROP, "L2 filter mac drops") typedef enum @@ -113,77 +117,80 @@ l2learn_process (vlib_node_runtime_t * node, u32 sw_if_index0, l2fib_entry_key_t * key0, l2fib_entry_key_t * cached_key, - u32 * bucket0, + u32 * count, l2fib_entry_result_t * result0, u32 * next0, u8 timestamp) { - u32 feature_bitmap; - /* Set up the default next node (typically L2FWD) */ - - /* Remove ourself from the feature bitmap */ - feature_bitmap = vnet_buffer (b0)->l2.feature_bitmap & ~L2INPUT_FEAT_LEARN; - - /* Save for next feature graph nodes */ - vnet_buffer (b0)->l2.feature_bitmap = feature_bitmap; - - /* Determine the next node */ - *next0 = feat_bitmap_get_next_node_index (msm->feat_next_node_index, - feature_bitmap); + *next0 = vnet_l2_feature_next (b0, msm->feat_next_node_index, + L2INPUT_FEAT_LEARN); /* Check mac table lookup result */ - if (PREDICT_TRUE (result0->fields.sw_if_index == sw_if_index0)) { - /* - * The entry was in the table, and the sw_if_index matched, the normal case - */ - counter_base[L2LEARN_ERROR_HIT] += 1; - if (PREDICT_FALSE (result0->fields.timestamp != timestamp)) - result0->fields.timestamp = timestamp; - + /* Entry in L2FIB with matching sw_if_index matched - normal fast path */ + u32 dtime = timestamp - result0->fields.timestamp; + u32 dsn = result0->fields.sn.as_u16 - vnet_buffer (b0)->l2.l2fib_sn; + u32 check = (dtime && vnet_buffer (b0)->l2.bd_age) || dsn; + + if (PREDICT_TRUE (check == 0)) + return; /* MAC entry up to date */ + if (l2fib_entry_result_is_set_AGE_NOT (result0)) + return; /* Static MAC always age_not */ + if (msm->global_learn_count > msm->global_learn_limit) + return; /* Above learn limit - do not update */ + + /* Limit updates per l2-learn node call to avoid prolonged update burst + * as dtime advance over 1 minute mark, unless more than 1 min behind + * or SN obsolete */ + if ((*count > 2) && (dtime == 1) && (dsn == 0)) + return; + + counter_base[L2LEARN_ERROR_HIT_UPDATE] += 1; + *count += 1; } else if (result0->raw == ~0) { - - /* The entry was not in table, so add it */ - + /* Entry not in L2FIB - add it */ counter_base[L2LEARN_ERROR_MISS] += 1; - if (msm->global_learn_count == msm->global_learn_limit) + if (msm->global_learn_count >= msm->global_learn_limit) { /* * Global limit reached. Do not learn the mac but forward the packet. * In the future, limits could also be per-interface or bridge-domain. */ counter_base[L2LEARN_ERROR_LIMIT] += 1; - goto done; - - } - else - { - BVT (clib_bihash_kv) kv; - /* It is ok to learn */ - - result0->raw = 0; /* clear all fields */ - result0->fields.sw_if_index = sw_if_index0; - result0->fields.timestamp = timestamp; - kv.key = key0->raw; - kv.value = result0->raw; - - BV (clib_bihash_add_del) (msm->mac_table, &kv, 1 /* is_add */ ); - - cached_key->raw = ~0; /* invalidate the cache */ - msm->global_learn_count++; + return; } + /* Do not learn if mac is 0 */ + l2fib_entry_key_t key = *key0; + key.fields.bd_index = 0; + if (key.raw == 0) + return; + + /* It is ok to learn */ + msm->global_learn_count++; + result0->raw = 0; /* clear all fields */ + result0->fields.sw_if_index = sw_if_index0; + if (msm->client_pid != 0) + l2fib_entry_result_set_LRN_EVT (result0); + else + l2fib_entry_result_clear_LRN_EVT (result0); } else { + /* Entry in L2FIB with different sw_if_index - mac move or filter */ + if (l2fib_entry_result_is_set_FILTER (result0)) + { + ASSERT (result0->fields.sw_if_index == ~0); + /* drop packet because lookup matched a filter mac entry */ + b0->error = node->errors[L2LEARN_ERROR_FILTER_DROP]; + *next0 = L2LEARN_NEXT_DROP; + return; + } - /* The entry was in the table, but with the wrong sw_if_index mapping (mac move) */ - counter_base[L2LEARN_ERROR_MAC_MOVE] += 1; - - if (result0->fields.static_mac) + if (l2fib_entry_result_is_set_STATIC (result0)) { /* * Don't overwrite a static mac @@ -191,49 +198,48 @@ l2learn_process (vlib_node_runtime_t * node, */ b0->error = node->errors[L2LEARN_ERROR_MAC_MOVE_VIOLATE]; *next0 = L2LEARN_NEXT_DROP; + return; } - else - { - /* - * Update the entry - * TODO: may want to rate limit mac moves - * TODO: check global/bridge domain/interface learn limits - */ - BVT (clib_bihash_kv) kv; - - result0->raw = 0; /* clear all fields */ - result0->fields.sw_if_index = sw_if_index0; - result0->fields.timestamp = timestamp; - kv.key = key0->raw; - kv.value = result0->raw; - - cached_key->raw = ~0; /* invalidate the cache */ - - BV (clib_bihash_add_del) (msm->mac_table, &kv, 1 /* is_add */ ); + /* + * TODO: may want to rate limit mac moves + * TODO: check global/bridge domain/interface learn limits + */ + result0->fields.sw_if_index = sw_if_index0; + if (l2fib_entry_result_is_set_AGE_NOT (result0)) + { + /* The mac was provisioned */ + msm->global_learn_count++; + l2fib_entry_result_clear_AGE_NOT (result0); } + if (msm->client_pid != 0) + l2fib_entry_result_set_bits (result0, + (L2FIB_ENTRY_RESULT_FLAG_LRN_EVT | + L2FIB_ENTRY_RESULT_FLAG_LRN_MOV)); + else + l2fib_entry_result_clear_bits (result0, + (L2FIB_ENTRY_RESULT_FLAG_LRN_EVT | + L2FIB_ENTRY_RESULT_FLAG_LRN_MOV)); + counter_base[L2LEARN_ERROR_MAC_MOVE] += 1; } - if (result0->fields.filter) - { - /* drop packet because lookup matched a filter mac entry */ + /* Update the entry */ + result0->fields.timestamp = timestamp; + result0->fields.sn.as_u16 = vnet_buffer (b0)->l2.l2fib_sn; - if (*next0 != L2LEARN_NEXT_DROP) - { - /* if we're not already dropping the packet, do it now */ - b0->error = node->errors[L2LEARN_ERROR_FILTER_DROP]; - *next0 = L2LEARN_NEXT_DROP; - } - } + BVT (clib_bihash_kv) kv; + kv.key = key0->raw; + kv.value = result0->raw; + BV (clib_bihash_add_del) (msm->mac_table, &kv, 1 /* is_add */ ); -done: - return; + /* Invalidate the cache */ + cached_key->raw = ~0; } -static uword -l2learn_node_fn (vlib_main_t * vm, - vlib_node_runtime_t * node, vlib_frame_t * frame) +static_always_inline uword +l2learn_node_inline (vlib_main_t * vm, vlib_node_runtime_t * node, + vlib_frame_t * frame, int do_trace) { u32 n_left_from, *from, *to_next; l2learn_next_t next_index; @@ -244,6 +250,7 @@ l2learn_node_fn (vlib_main_t * vm, l2fib_entry_key_t cached_key; l2fib_entry_result_t cached_result; u8 timestamp = (u8) (vlib_time_now (vm) / 60); + u32 count = 0; from = vlib_frame_vector_args (frame); n_left_from = frame->n_vectors; /* number of packets to process */ @@ -266,7 +273,7 @@ l2learn_node_fn (vlib_main_t * vm, vlib_buffer_t *b0, *b1, *b2, *b3; u32 next0, next1, next2, next3; u32 sw_if_index0, sw_if_index1, sw_if_index2, sw_if_index3; - ethernet_header_t *h0, *h1, *h2, *h3; + const ethernet_header_t *h0, *h1, *h2, *h3; l2fib_entry_key_t key0, key1, key2, key3; l2fib_entry_result_t result0, result1, result2, result3; u32 bucket0, bucket1, bucket2, bucket3; @@ -280,15 +287,17 @@ l2learn_node_fn (vlib_main_t * vm, p6 = vlib_get_buffer (vm, from[6]); p7 = vlib_get_buffer (vm, from[7]); + /* buffer header is read and written, so use LOAD + * prefetch */ vlib_prefetch_buffer_header (p4, LOAD); vlib_prefetch_buffer_header (p5, LOAD); vlib_prefetch_buffer_header (p6, LOAD); vlib_prefetch_buffer_header (p7, LOAD); - CLIB_PREFETCH (p4->data, CLIB_CACHE_LINE_BYTES, STORE); - CLIB_PREFETCH (p5->data, CLIB_CACHE_LINE_BYTES, STORE); - CLIB_PREFETCH (p6->data, CLIB_CACHE_LINE_BYTES, STORE); - CLIB_PREFETCH (p7->data, CLIB_CACHE_LINE_BYTES, STORE); + CLIB_PREFETCH (p4->data, CLIB_CACHE_LINE_BYTES, LOAD); + CLIB_PREFETCH (p5->data, CLIB_CACHE_LINE_BYTES, LOAD); + CLIB_PREFETCH (p6->data, CLIB_CACHE_LINE_BYTES, LOAD); + CLIB_PREFETCH (p7->data, CLIB_CACHE_LINE_BYTES, LOAD); } /* speculatively enqueue b0 and b1 to the current next frame */ @@ -320,7 +329,7 @@ l2learn_node_fn (vlib_main_t * vm, h2 = vlib_buffer_get_current (b2); h3 = vlib_buffer_get_current (b3); - if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE))) + if (do_trace) { if (b0->flags & VLIB_BUFFER_IS_TRACED) { @@ -379,19 +388,19 @@ l2learn_node_fn (vlib_main_t * vm, l2learn_process (node, msm, &em->counters[node_counter_base_index], b0, sw_if_index0, &key0, &cached_key, - &bucket0, &result0, &next0, timestamp); + &count, &result0, &next0, timestamp); l2learn_process (node, msm, &em->counters[node_counter_base_index], b1, sw_if_index1, &key1, &cached_key, - &bucket1, &result1, &next1, timestamp); + &count, &result1, &next1, timestamp); l2learn_process (node, msm, &em->counters[node_counter_base_index], b2, sw_if_index2, &key2, &cached_key, - &bucket2, &result2, &next2, timestamp); + &count, &result2, &next2, timestamp); l2learn_process (node, msm, &em->counters[node_counter_base_index], b3, sw_if_index3, &key3, &cached_key, - &bucket3, &result3, &next3, timestamp); + &count, &result3, &next3, timestamp); /* verify speculative enqueues, maybe switch current next frame */ /* if next0==next1==next_index then nothing special needs to be done */ @@ -426,8 +435,7 @@ l2learn_node_fn (vlib_main_t * vm, h0 = vlib_buffer_get_current (b0); - if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) - && (b0->flags & VLIB_BUFFER_IS_TRACED))) + if (do_trace && PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) { l2learn_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t)); t->sw_if_index = sw_if_index0; @@ -447,7 +455,7 @@ l2learn_node_fn (vlib_main_t * vm, l2learn_process (node, msm, &em->counters[node_counter_base_index], b0, sw_if_index0, &key0, &cached_key, - &bucket0, &result0, &next0, timestamp); + &count, &result0, &next0, timestamp); /* verify speculative enqueue, maybe switch current next frame */ vlib_validate_buffer_enqueue_x1 (vm, node, next_index, @@ -461,10 +469,16 @@ l2learn_node_fn (vlib_main_t * vm, return frame->n_vectors; } +VLIB_NODE_FN (l2learn_node) (vlib_main_t * vm, + vlib_node_runtime_t * node, vlib_frame_t * frame) +{ + if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE))) + return l2learn_node_inline (vm, node, frame, 1 /* do_trace */ ); + return l2learn_node_inline (vm, node, frame, 0 /* do_trace */ ); +} /* *INDENT-OFF* */ VLIB_REGISTER_NODE (l2learn_node,static) = { - .function = l2learn_node_fn, .name = "l2-learn", .vector_size = sizeof (u32), .format_trace = format_l2learn_trace, @@ -483,8 +497,9 @@ VLIB_REGISTER_NODE (l2learn_node,static) = { }; /* *INDENT-ON* */ -VLIB_NODE_FUNCTION_MULTIARCH (l2learn_node, l2learn_node_fn) - clib_error_t *l2learn_init (vlib_main_t * vm) +#ifndef CLIB_MARCH_VARIANT +clib_error_t * +l2learn_init (vlib_main_t * vm) { l2learn_main_t *mp = &l2learn_main; @@ -505,7 +520,7 @@ VLIB_NODE_FUNCTION_MULTIARCH (l2learn_node, l2learn_node_fn) * Set the default number of dynamically learned macs to the number * of buckets. */ - mp->global_learn_limit = L2FIB_NUM_BUCKETS * 16; + mp->global_learn_limit = L2LEARN_DEFAULT_LIMIT; return 0; } @@ -587,6 +602,8 @@ l2learn_config (vlib_main_t * vm, unformat_input_t * input) VLIB_CONFIG_FUNCTION (l2learn_config, "l2learn"); +#endif + /* * fd.io coding-style-patch-verification: ON