diff options
-rw-r--r-- | vnet/vnet/nsh-gre/decap.c | 82 |
1 files changed, 81 insertions, 1 deletions
diff --git a/vnet/vnet/nsh-gre/decap.c b/vnet/vnet/nsh-gre/decap.c index 9ef52ffb6de..2b6ae9a7d4c 100644 --- a/vnet/vnet/nsh-gre/decap.c +++ b/vnet/vnet/nsh-gre/decap.c @@ -95,14 +95,20 @@ nsh_gre_input (vlib_main_t * vm, { u32 n_left_from, next_index, * from, * to_next; nsh_gre_main_t * ngm = &nsh_gre_main; + vnet_main_t * vnm = ngm->vnet_main; + vnet_interface_main_t * im = &vnm->interface_main; u32 last_tunnel_index = ~0; u64 last_key = ~0ULL; u32 pkts_decapsulated = 0; + u32 cpu_index = os_get_cpu_number(); + u32 stats_sw_if_index, stats_n_packets, stats_n_bytes; from = vlib_frame_vector_args (from_frame); n_left_from = from_frame->n_vectors; next_index = node->cached_next_index; + stats_sw_if_index = node->runtime_data[0]; + stats_n_packets = stats_n_bytes = 0; while (n_left_from > 0) { @@ -122,6 +128,7 @@ nsh_gre_input (vlib_main_t * vm, nsh_gre_tunnel_t * t0, * t1; u64 key0, key1; u32 error0, error1; + u32 sw_if_index0, sw_if_index1, len0, len1; /* Prefetch next iteration. */ { @@ -185,6 +192,10 @@ nsh_gre_input (vlib_main_t * vm, t0 = pool_elt_at_index (ngm->tunnels, tunnel_index0); + next0 = t0->decap_next_index; + sw_if_index0 = t0->sw_if_index; + len0 = vlib_buffer_length_in_chain(vm, b0); + /* Required to make the l2 tag push / pop code work on l2 subifs */ vnet_update_l2_len (b0); @@ -193,6 +204,23 @@ nsh_gre_input (vlib_main_t * vm, /* ip[46] lookup in the configured FIB, otherwise an opaque */ vnet_buffer(b0)->sw_if_index[VLIB_TX] = t0->decap_fib_index; + pkts_decapsulated++; + stats_n_packets += 1; + stats_n_bytes += len0; + + if (PREDICT_FALSE(sw_if_index0 != stats_sw_if_index)) + { + stats_n_packets -= 1; + stats_n_bytes -= len0; + if (stats_n_packets) + vlib_increment_combined_counter( + im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_RX, + cpu_index, stats_sw_if_index, stats_n_packets, stats_n_bytes); + stats_n_packets = 1; + stats_n_bytes = len0; + stats_sw_if_index = sw_if_index0; + } + trace0: b0->error = error0 ? node->errors[error0] : 0; @@ -224,6 +252,10 @@ nsh_gre_input (vlib_main_t * vm, t1 = pool_elt_at_index (ngm->tunnels, tunnel_index1); + next1 = t1->decap_next_index; + sw_if_index1 = t1->sw_if_index; + len1 = vlib_buffer_length_in_chain(vm, b1); + /* Required to make the l2 tag push / pop code work on l2 subifs */ vnet_update_l2_len (b1); @@ -232,7 +264,24 @@ nsh_gre_input (vlib_main_t * vm, /* ip[46] lookup in the configured FIB, otherwise an opaque */ vnet_buffer(b1)->sw_if_index[VLIB_TX] = t1->decap_fib_index; - pkts_decapsulated +=2; + pkts_decapsulated++; + stats_n_packets += 1; + stats_n_bytes += len1; + /* Batch stats increment on the same nsh-gre tunnel so counter + is not incremented per packet */ + if (PREDICT_FALSE(sw_if_index1 != stats_sw_if_index)) + { + stats_n_packets -= 1; + stats_n_bytes -= len1; + if (stats_n_packets) + vlib_increment_combined_counter( + im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_RX, + cpu_index, stats_sw_if_index, stats_n_packets, stats_n_bytes); + stats_n_packets = 1; + stats_n_bytes = len1; + stats_sw_if_index = sw_if_index1; + } + vnet_buffer(b1)->sw_if_index[VLIB_TX] = t1->decap_fib_index; trace1: b1->error = error1 ? node->errors[error1] : 0; @@ -263,6 +312,7 @@ nsh_gre_input (vlib_main_t * vm, nsh_gre_tunnel_t * t0; u64 key0; u32 error0; + u32 sw_if_index0, len0; bi0 = from[0]; to_next[0] = bi0; @@ -302,6 +352,10 @@ nsh_gre_input (vlib_main_t * vm, t0 = pool_elt_at_index (ngm->tunnels, tunnel_index0); + next0 = t0->decap_next_index; + sw_if_index0 = t0->sw_if_index; + len0 = vlib_buffer_length_in_chain(vm, b0); + /* Required to make the l2 tag push / pop code work on l2 subifs */ vnet_update_l2_len (b0); @@ -311,6 +365,24 @@ nsh_gre_input (vlib_main_t * vm, vnet_buffer(b0)->sw_if_index[VLIB_TX] = t0->decap_fib_index; pkts_decapsulated ++; + stats_n_packets += 1; + stats_n_bytes += len0; + + /* Batch stats increment on the same nsh-gre tunnel so counter + is not incremented per packet */ + if (PREDICT_FALSE(sw_if_index0 != stats_sw_if_index)) + { + stats_n_packets -= 1; + stats_n_bytes -= len0; + if (stats_n_packets) + vlib_increment_combined_counter( + im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_RX, + cpu_index, stats_sw_if_index, stats_n_packets, stats_n_bytes); + stats_n_packets = 1; + stats_n_bytes = len0; + stats_sw_if_index = sw_if_index0; + } + trace00: b0->error = error0 ? node->errors[error0] : 0; @@ -333,6 +405,14 @@ nsh_gre_input (vlib_main_t * vm, vlib_node_increment_counter (vm, nsh_gre_input_node.index, NSH_GRE_ERROR_DECAPSULATED, pkts_decapsulated); + /* Increment any remaining batch stats */ + if (stats_n_packets) + { + vlib_increment_combined_counter( + im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_RX, cpu_index, + stats_sw_if_index, stats_n_packets, stats_n_bytes); + node->runtime_data[0] = stats_sw_if_index; + } return from_frame->n_vectors; } |