Add RX statistics for nsh-gre tunnel

Change-Id: I045bb9d51c9a82ccba6e792485b9418bd78b8520
Signed-off-by: Hongjun Ni <hongjun.ni@intel.com>
This commit is contained in:
Hongjun Ni
2016-04-28 16:50:11 -07:00
committed by Dave Barach
parent 6337ab720b
commit 329e7d5905

View File

@ -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;
}