summaryrefslogtreecommitdiffstats
path: root/vnet/vnet/nsh-vxlan-gpe/encap.c
diff options
context:
space:
mode:
authorHongjun Ni <hongjun.ni@intel.com>2016-04-06 16:20:22 -0700
committerGerrit Code Review <gerrit@fd.io>2016-04-08 14:38:43 +0000
commitb2cdd2f5f040dc45cb54d2d3fc2dedc19833fcf9 (patch)
tree250b8fa56cecdbd238d96c68ed36495d88791daa /vnet/vnet/nsh-vxlan-gpe/encap.c
parent639b4bded649dd510b7c1c288bda413ce1d98613 (diff)
Add Rx and Tx statistics within nsh-vxlan-gpe node
PatchSet2: Modify the code according to review comments. PatchSet3: modify sw_if_index1 in encap.c. Change-Id: Ic4d3ee19a0ba0fa10568e570a79a3cb85cfbc9ab Signed-off-by: Hongjun Ni <hongjun.ni@intel.com>
Diffstat (limited to 'vnet/vnet/nsh-vxlan-gpe/encap.c')
-rw-r--r--vnet/vnet/nsh-vxlan-gpe/encap.c103
1 files changed, 88 insertions, 15 deletions
diff --git a/vnet/vnet/nsh-vxlan-gpe/encap.c b/vnet/vnet/nsh-vxlan-gpe/encap.c
index 0ccdf60c6aa..b5ff5851a9e 100644
--- a/vnet/vnet/nsh-vxlan-gpe/encap.c
+++ b/vnet/vnet/nsh-vxlan-gpe/encap.c
@@ -58,7 +58,7 @@ u8 * format_nsh_vxlan_gpe_encap_trace (u8 * s, va_list * args)
}
#define foreach_fixed_header_offset \
-_(0) _(1) _(2) _(3) _(4) _(5) _(6)
+_(0) _(1) _(2) _(3) _(4) _(5) _(6)
static uword
nsh_vxlan_gpe_encap (vlib_main_t * vm,
@@ -68,13 +68,18 @@ nsh_vxlan_gpe_encap (vlib_main_t * vm,
u32 n_left_from, next_index, * from, * to_next;
nsh_vxlan_gpe_main_t * ngm = &nsh_vxlan_gpe_main;
vnet_main_t * vnm = ngm->vnet_main;
+ vnet_interface_main_t * im = &vnm->interface_main;
u32 pkts_encapsulated = 0;
u16 old_l0 = 0, old_l1 = 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)
{
@@ -89,6 +94,7 @@ nsh_vxlan_gpe_encap (vlib_main_t * vm,
vlib_buffer_t * b0, * b1;
u32 next0 = NSH_VXLAN_GPE_ENCAP_NEXT_IP4_LOOKUP;
u32 next1 = NSH_VXLAN_GPE_ENCAP_NEXT_IP4_LOOKUP;
+ u32 sw_if_index0, sw_if_index1, len0, len1;
vnet_hw_interface_t * hi0, * hi1;
ip4_header_t * ip0, * ip1;
udp_header_t * udp0, * udp1;
@@ -127,9 +133,11 @@ nsh_vxlan_gpe_encap (vlib_main_t * vm,
b1 = vlib_get_buffer (vm, bi1);
/* 1-wide cache? */
- hi0 = vnet_get_sup_hw_interface
+ sw_if_index0 = vnet_buffer(b0)->sw_if_index[VLIB_TX];
+ sw_if_index1 = vnet_buffer(b1)->sw_if_index[VLIB_TX];
+ hi0 = vnet_get_sup_hw_interface
(vnm, vnet_buffer(b0)->sw_if_index[VLIB_TX]);
- hi1 = vnet_get_sup_hw_interface
+ hi1 = vnet_get_sup_hw_interface
(vnm, vnet_buffer(b1)->sw_if_index[VLIB_TX]);
t0 = pool_elt_at_index (ngm->tunnels, hi0->dev_instance);
@@ -206,24 +214,59 @@ nsh_vxlan_gpe_encap (vlib_main_t * vm,
udp1 = (udp_header_t *)(ip1+1);
new_l1 = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b1)
- sizeof (*ip1));
-
+
udp0->length = new_l0;
udp1->length = new_l1;
/* Reset to look up tunnel partner in the configured FIB */
vnet_buffer(b0)->sw_if_index[VLIB_TX] = t0->encap_fib_index;
vnet_buffer(b1)->sw_if_index[VLIB_TX] = t1->encap_fib_index;
+ vnet_buffer(b0)->sw_if_index[VLIB_RX] = sw_if_index0;
+ vnet_buffer(b1)->sw_if_index[VLIB_RX] = sw_if_index1;
+ pkts_encapsulated += 2;
+
+ len0 = vlib_buffer_length_in_chain(vm, b0);
+ len1 = vlib_buffer_length_in_chain(vm, b0);
+ stats_n_packets += 2;
+ stats_n_bytes += len0 + len1;
+
+ /* Batch stats increment on the same vxlan tunnel so counter is not
+ incremented per packet. Note stats are still incremented for deleted
+ and admin-down tunnel where packets are dropped. It is not worthwhile
+ to check for this rare case and affect normal path performance. */
+ if (PREDICT_FALSE(
+ (sw_if_index0 != stats_sw_if_index)
+ || (sw_if_index1 != stats_sw_if_index))) {
+ stats_n_packets -= 2;
+ stats_n_bytes -= len0 + len1;
+ if (sw_if_index0 == sw_if_index1) {
+ if (stats_n_packets)
+ vlib_increment_combined_counter(
+ im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_TX,
+ cpu_index, stats_sw_if_index, stats_n_packets, stats_n_bytes);
+ stats_sw_if_index = sw_if_index0;
+ stats_n_packets = 2;
+ stats_n_bytes = len0 + len1;
+ } else {
+ vlib_increment_combined_counter(
+ im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_TX,
+ cpu_index, sw_if_index0, 1, len0);
+ vlib_increment_combined_counter(
+ im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_TX,
+ cpu_index, sw_if_index1, 1, len1);
+ }
+ }
- if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
+ if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
{
- nsh_vxlan_gpe_encap_trace_t *tr =
+ nsh_vxlan_gpe_encap_trace_t *tr =
vlib_add_trace (vm, node, b0, sizeof (*tr));
tr->tunnel_index = t0 - ngm->tunnels;
}
- if (PREDICT_FALSE(b1->flags & VLIB_BUFFER_IS_TRACED))
+ if (PREDICT_FALSE(b1->flags & VLIB_BUFFER_IS_TRACED))
{
- nsh_vxlan_gpe_encap_trace_t *tr =
+ nsh_vxlan_gpe_encap_trace_t *tr =
vlib_add_trace (vm, node, b1, sizeof (*tr));
tr->tunnel_index = t1 - ngm->tunnels;
}
@@ -238,6 +281,7 @@ nsh_vxlan_gpe_encap (vlib_main_t * vm,
u32 bi0;
vlib_buffer_t * b0;
u32 next0 = NSH_VXLAN_GPE_ENCAP_NEXT_IP4_LOOKUP;
+ u32 sw_if_index0, len0;
vnet_hw_interface_t * hi0;
ip4_header_t * ip0;
udp_header_t * udp0;
@@ -257,7 +301,8 @@ nsh_vxlan_gpe_encap (vlib_main_t * vm,
b0 = vlib_get_buffer (vm, bi0);
/* 1-wide cache? */
- hi0 = vnet_get_sup_hw_interface
+ sw_if_index0 = vnet_buffer(b0)->sw_if_index[VLIB_TX];
+ hi0 = vnet_get_sup_hw_interface
(vnm, vnet_buffer(b0)->sw_if_index[VLIB_TX]);
t0 = pool_elt_at_index (ngm->tunnels, hi0->dev_instance);
@@ -299,21 +344,41 @@ nsh_vxlan_gpe_encap (vlib_main_t * vm,
length /* changed member */);
ip0->checksum = ip_csum_fold (sum0);
ip0->length = new_l0;
-
+
/* Fix UDP length */
udp0 = (udp_header_t *)(ip0+1);
new_l0 = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0)
- sizeof (*ip0));
-
+
udp0->length = new_l0;
/* Reset to look up tunnel partner in the configured FIB */
vnet_buffer(b0)->sw_if_index[VLIB_TX] = t0->encap_fib_index;
+ vnet_buffer(b0)->sw_if_index[VLIB_RX] = sw_if_index0;
pkts_encapsulated ++;
- if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
+ len0 = vlib_buffer_length_in_chain(vm, b0);
+ stats_n_packets += 1;
+ stats_n_bytes += len0;
+
+ /* Batch stats increment on the same vxlan tunnel so counter is not
+ incremented per packet. Note stats are still incremented for deleted
+ and admin-down tunnel where packets are dropped. It is not worthwhile
+ to check for this rare case and affect normal path performance. */
+ 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_TX,
+ 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;
+ }
+ if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
{
- nsh_vxlan_gpe_encap_trace_t *tr =
+ nsh_vxlan_gpe_encap_trace_t *tr =
vlib_add_trace (vm, node, b0, sizeof (*tr));
tr->tunnel_index = t0 - ngm->tunnels;
}
@@ -324,9 +389,17 @@ nsh_vxlan_gpe_encap (vlib_main_t * vm,
vlib_put_next_frame (vm, node, next_index, n_left_to_next);
}
- vlib_node_increment_counter (vm, node->node_index,
- NSH_VXLAN_GPE_ENCAP_ERROR_ENCAPSULATED,
+ vlib_node_increment_counter (vm, node->node_index,
+ NSH_VXLAN_GPE_ENCAP_ERROR_ENCAPSULATED,
pkts_encapsulated);
+ /* Increment any remaining batch stats */
+ if (stats_n_packets) {
+ vlib_increment_combined_counter(
+ im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_TX, 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;
}