aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet
diff options
context:
space:
mode:
Diffstat (limited to 'src/vnet')
-rw-r--r--src/vnet/l2/l2_learn.c342
1 files changed, 147 insertions, 195 deletions
diff --git a/src/vnet/l2/l2_learn.c b/src/vnet/l2/l2_learn.c
index 732a1fc5d85..2c9966148bc 100644
--- a/src/vnet/l2/l2_learn.c
+++ b/src/vnet/l2/l2_learn.c
@@ -118,7 +118,7 @@ l2learn_process (vlib_node_runtime_t * node,
l2fib_entry_key_t * key0,
l2fib_entry_key_t * cached_key,
u32 * count,
- l2fib_entry_result_t * result0, u32 * next0, u8 timestamp)
+ l2fib_entry_result_t * result0, u16 * next0, u8 timestamp)
{
/* Set up the default next node (typically L2FWD) */
*next0 = vnet_l2_feature_next (b0, msm->feat_next_node_index,
@@ -241,8 +241,7 @@ 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;
+ u32 n_left, *from;
l2learn_main_t *msm = &l2learn_main;
vlib_node_t *n = vlib_get_node (vm, l2learn_node.index);
u32 node_counter_base_index = n->error_heap_index;
@@ -251,221 +250,174 @@ l2learn_node_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
l2fib_entry_result_t cached_result;
u8 timestamp = (u8) (vlib_time_now (vm) / 60);
u32 count = 0;
+ vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
+ u16 nexts[VLIB_FRAME_SIZE], *next;
from = vlib_frame_vector_args (frame);
- n_left_from = frame->n_vectors; /* number of packets to process */
- next_index = node->cached_next_index;
+ n_left = frame->n_vectors; /* number of packets to process */
+ vlib_get_buffers (vm, from, bufs, n_left);
+ next = nexts;
+ b = bufs;
/* Clear the one-entry cache in case mac table was updated */
cached_key.raw = ~0;
cached_result.raw = ~0; /* warning be gone */
- while (n_left_from > 0)
+ while (n_left > 8)
{
- u32 n_left_to_next;
-
- /* get space to enqueue frame to graph node "next_index" */
- vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
-
- while (n_left_from >= 8 && n_left_to_next >= 4)
- {
- u32 bi0, bi1, bi2, bi3;
- 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;
- 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;
-
- /* Prefetch next iteration. */
- {
- vlib_buffer_t *p4, *p5, *p6, *p7;;
-
- p4 = vlib_get_buffer (vm, from[4]);
- p5 = vlib_get_buffer (vm, from[5]);
- 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, 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 */
- /* bi is "buffer index", b is pointer to the buffer */
- to_next[0] = bi0 = from[0];
- to_next[1] = bi1 = from[1];
- to_next[2] = bi2 = from[2];
- to_next[3] = bi3 = from[3];
- from += 4;
- to_next += 4;
- n_left_from -= 4;
- n_left_to_next -= 4;
-
- b0 = vlib_get_buffer (vm, bi0);
- b1 = vlib_get_buffer (vm, bi1);
- b2 = vlib_get_buffer (vm, bi2);
- b3 = vlib_get_buffer (vm, bi3);
-
- /* RX interface handles */
- sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
- sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_RX];
- sw_if_index2 = vnet_buffer (b2)->sw_if_index[VLIB_RX];
- sw_if_index3 = vnet_buffer (b3)->sw_if_index[VLIB_RX];
-
- /* Process 4 x pkts */
-
- h0 = vlib_buffer_get_current (b0);
- h1 = vlib_buffer_get_current (b1);
- h2 = vlib_buffer_get_current (b2);
- h3 = vlib_buffer_get_current (b3);
-
- if (do_trace)
- {
- if (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;
- t->bd_index = vnet_buffer (b0)->l2.bd_index;
- clib_memcpy (t->src, h0->src_address, 6);
- clib_memcpy (t->dst, h0->dst_address, 6);
- }
- if (b1->flags & VLIB_BUFFER_IS_TRACED)
- {
- l2learn_trace_t *t =
- vlib_add_trace (vm, node, b1, sizeof (*t));
- t->sw_if_index = sw_if_index1;
- t->bd_index = vnet_buffer (b1)->l2.bd_index;
- clib_memcpy (t->src, h1->src_address, 6);
- clib_memcpy (t->dst, h1->dst_address, 6);
- }
- if (b2->flags & VLIB_BUFFER_IS_TRACED)
- {
- l2learn_trace_t *t =
- vlib_add_trace (vm, node, b2, sizeof (*t));
- t->sw_if_index = sw_if_index2;
- t->bd_index = vnet_buffer (b2)->l2.bd_index;
- clib_memcpy (t->src, h2->src_address, 6);
- clib_memcpy (t->dst, h2->dst_address, 6);
- }
- if (b3->flags & VLIB_BUFFER_IS_TRACED)
- {
- l2learn_trace_t *t =
- vlib_add_trace (vm, node, b3, sizeof (*t));
- t->sw_if_index = sw_if_index3;
- t->bd_index = vnet_buffer (b3)->l2.bd_index;
- clib_memcpy (t->src, h3->src_address, 6);
- clib_memcpy (t->dst, h3->dst_address, 6);
- }
- }
-
- /* process 4 pkts */
- vlib_node_increment_counter (vm, l2learn_node.index,
- L2LEARN_ERROR_L2LEARN, 4);
-
- l2fib_lookup_4 (msm->mac_table, &cached_key, &cached_result,
- h0->src_address,
- h1->src_address,
- h2->src_address,
- h3->src_address,
- vnet_buffer (b0)->l2.bd_index,
- vnet_buffer (b1)->l2.bd_index,
- vnet_buffer (b2)->l2.bd_index,
- vnet_buffer (b3)->l2.bd_index,
- &key0, &key1, &key2, &key3,
- &bucket0, &bucket1, &bucket2, &bucket3,
- &result0, &result1, &result2, &result3);
-
- l2learn_process (node, msm, &em->counters[node_counter_base_index],
- b0, sw_if_index0, &key0, &cached_key,
- &count, &result0, &next0, timestamp);
-
- l2learn_process (node, msm, &em->counters[node_counter_base_index],
- b1, sw_if_index1, &key1, &cached_key,
- &count, &result1, &next1, timestamp);
-
- l2learn_process (node, msm, &em->counters[node_counter_base_index],
- b2, sw_if_index2, &key2, &cached_key,
- &count, &result2, &next2, timestamp);
-
- l2learn_process (node, msm, &em->counters[node_counter_base_index],
- b3, sw_if_index3, &key3, &cached_key,
- &count, &result3, &next3, timestamp);
-
- /* verify speculative enqueues, maybe switch current next frame */
- /* if next0==next1==next_index then nothing special needs to be done */
- vlib_validate_buffer_enqueue_x4 (vm, node, next_index,
- to_next, n_left_to_next,
- bi0, bi1, bi2, bi3,
- next0, next1, next2, next3);
- }
-
- while (n_left_from > 0 && n_left_to_next > 0)
+ u32 sw_if_index0, sw_if_index1, sw_if_index2, sw_if_index3;
+ 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;
+
+ /* Prefetch next iteration. */
+ {
+ /* buffer header is read and written, so use LOAD
+ * prefetch */
+ vlib_prefetch_buffer_header (b[4], LOAD);
+ vlib_prefetch_buffer_header (b[5], LOAD);
+ vlib_prefetch_buffer_header (b[6], LOAD);
+ vlib_prefetch_buffer_header (b[7], LOAD);
+
+ CLIB_PREFETCH (b[4]->data, CLIB_CACHE_LINE_BYTES, LOAD);
+ CLIB_PREFETCH (b[5]->data, CLIB_CACHE_LINE_BYTES, LOAD);
+ CLIB_PREFETCH (b[6]->data, CLIB_CACHE_LINE_BYTES, LOAD);
+ CLIB_PREFETCH (b[7]->data, CLIB_CACHE_LINE_BYTES, LOAD);
+ }
+
+ /* RX interface handles */
+ sw_if_index0 = vnet_buffer (b[0])->sw_if_index[VLIB_RX];
+ sw_if_index1 = vnet_buffer (b[1])->sw_if_index[VLIB_RX];
+ sw_if_index2 = vnet_buffer (b[2])->sw_if_index[VLIB_RX];
+ sw_if_index3 = vnet_buffer (b[3])->sw_if_index[VLIB_RX];
+
+ /* Process 4 x pkts */
+
+ h0 = vlib_buffer_get_current (b[0]);
+ h1 = vlib_buffer_get_current (b[1]);
+ h2 = vlib_buffer_get_current (b[2]);
+ h3 = vlib_buffer_get_current (b[3]);
+
+ if (do_trace)
{
- u32 bi0;
- vlib_buffer_t *b0;
- u32 next0;
- u32 sw_if_index0;
- ethernet_header_t *h0;
- l2fib_entry_key_t key0;
- l2fib_entry_result_t result0;
- u32 bucket0;
-
- /* speculatively enqueue b0 to the current next frame */
- bi0 = from[0];
- to_next[0] = bi0;
- from += 1;
- to_next += 1;
- n_left_from -= 1;
- n_left_to_next -= 1;
-
- b0 = vlib_get_buffer (vm, bi0);
-
- sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
-
- h0 = vlib_buffer_get_current (b0);
-
- if (do_trace && PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
+ if (b[0]->flags & VLIB_BUFFER_IS_TRACED)
{
- l2learn_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
+ l2learn_trace_t *t =
+ vlib_add_trace (vm, node, b[0], sizeof (*t));
t->sw_if_index = sw_if_index0;
- t->bd_index = vnet_buffer (b0)->l2.bd_index;
+ t->bd_index = vnet_buffer (b[0])->l2.bd_index;
clib_memcpy (t->src, h0->src_address, 6);
clib_memcpy (t->dst, h0->dst_address, 6);
}
+ if (b[1]->flags & VLIB_BUFFER_IS_TRACED)
+ {
+ l2learn_trace_t *t =
+ vlib_add_trace (vm, node, b[1], sizeof (*t));
+ t->sw_if_index = sw_if_index1;
+ t->bd_index = vnet_buffer (b[1])->l2.bd_index;
+ clib_memcpy (t->src, h1->src_address, 6);
+ clib_memcpy (t->dst, h1->dst_address, 6);
+ }
+ if (b[2]->flags & VLIB_BUFFER_IS_TRACED)
+ {
+ l2learn_trace_t *t =
+ vlib_add_trace (vm, node, b[2], sizeof (*t));
+ t->sw_if_index = sw_if_index2;
+ t->bd_index = vnet_buffer (b[2])->l2.bd_index;
+ clib_memcpy (t->src, h2->src_address, 6);
+ clib_memcpy (t->dst, h2->dst_address, 6);
+ }
+ if (b[3]->flags & VLIB_BUFFER_IS_TRACED)
+ {
+ l2learn_trace_t *t =
+ vlib_add_trace (vm, node, b[3], sizeof (*t));
+ t->sw_if_index = sw_if_index3;
+ t->bd_index = vnet_buffer (b[3])->l2.bd_index;
+ clib_memcpy (t->src, h3->src_address, 6);
+ clib_memcpy (t->dst, h3->dst_address, 6);
+ }
+ }
- /* process 1 pkt */
- vlib_node_increment_counter (vm, l2learn_node.index,
- L2LEARN_ERROR_L2LEARN, 1);
+ /* process 4 pkts */
+ vlib_node_increment_counter (vm, l2learn_node.index,
+ L2LEARN_ERROR_L2LEARN, 4);
+
+ l2fib_lookup_4 (msm->mac_table, &cached_key, &cached_result,
+ h0->src_address,
+ h1->src_address,
+ h2->src_address,
+ h3->src_address,
+ vnet_buffer (b[0])->l2.bd_index,
+ vnet_buffer (b[1])->l2.bd_index,
+ vnet_buffer (b[2])->l2.bd_index,
+ vnet_buffer (b[3])->l2.bd_index,
+ &key0, &key1, &key2, &key3,
+ &bucket0, &bucket1, &bucket2, &bucket3,
+ &result0, &result1, &result2, &result3);
+
+ l2learn_process (node, msm, &em->counters[node_counter_base_index],
+ b[0], sw_if_index0, &key0, &cached_key,
+ &count, &result0, next, timestamp);
+
+ l2learn_process (node, msm, &em->counters[node_counter_base_index],
+ b[1], sw_if_index1, &key1, &cached_key,
+ &count, &result1, next + 1, timestamp);
+
+ l2learn_process (node, msm, &em->counters[node_counter_base_index],
+ b[2], sw_if_index2, &key2, &cached_key,
+ &count, &result2, next + 2, timestamp);
+
+ l2learn_process (node, msm, &em->counters[node_counter_base_index],
+ b[3], sw_if_index3, &key3, &cached_key,
+ &count, &result3, next + 3, timestamp);
+
+ next += 4;
+ b += 4;
+ n_left -= 4;
+ }
+ while (n_left > 0)
+ {
+ u32 sw_if_index0;
+ ethernet_header_t *h0;
+ l2fib_entry_key_t key0;
+ l2fib_entry_result_t result0;
+ u32 bucket0;
- l2fib_lookup_1 (msm->mac_table, &cached_key, &cached_result,
- h0->src_address, vnet_buffer (b0)->l2.bd_index,
- &key0, &bucket0, &result0);
+ sw_if_index0 = vnet_buffer (b[0])->sw_if_index[VLIB_RX];
- l2learn_process (node, msm, &em->counters[node_counter_base_index],
- b0, sw_if_index0, &key0, &cached_key,
- &count, &result0, &next0, timestamp);
+ h0 = vlib_buffer_get_current (b[0]);
- /* verify speculative enqueue, maybe switch current next frame */
- vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
- to_next, n_left_to_next,
- bi0, next0);
+ if (do_trace && PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ l2learn_trace_t *t = vlib_add_trace (vm, node, b[0], sizeof (*t));
+ t->sw_if_index = sw_if_index0;
+ t->bd_index = vnet_buffer (b[0])->l2.bd_index;
+ clib_memcpy (t->src, h0->src_address, 6);
+ clib_memcpy (t->dst, h0->dst_address, 6);
}
- vlib_put_next_frame (vm, node, next_index, n_left_to_next);
+ /* process 1 pkt */
+ vlib_node_increment_counter (vm, l2learn_node.index,
+ L2LEARN_ERROR_L2LEARN, 1);
+
+
+ l2fib_lookup_1 (msm->mac_table, &cached_key, &cached_result,
+ h0->src_address, vnet_buffer (b[0])->l2.bd_index,
+ &key0, &bucket0, &result0);
+
+ l2learn_process (node, msm, &em->counters[node_counter_base_index],
+ b[0], sw_if_index0, &key0, &cached_key,
+ &count, &result0, next, timestamp);
+
+ next += 1;
+ b += 1;
+ n_left -= 1;
}
+ vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors);
+
return frame->n_vectors;
}