aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet
diff options
context:
space:
mode:
authorNeale Ranns <neale@graphiant.com>2021-07-16 14:00:16 +0000
committerBeno�t Ganne <bganne@cisco.com>2022-08-09 14:17:46 +0000
commitfd2417b2a42e34062e3d07875e5c4e11922513d5 (patch)
treeeec1ea914c259f685e2bca897e5853faec9339c1 /src/vnet
parent896b184b781a09ce5cefb94c471029c6a8d025aa (diff)
ip-neighbor: ARP and ND stats per-interface.
Type: feature stats of the like from: https://datatracker.ietf.org/doc/html/draft-ietf-rtgwg-arp-yang-model-03#section-4 Signed-off-by: Neale Ranns <neale@graphiant.com> Change-Id: Icb1bf4f6f7e6ccc2f44b0008d4774b61cae96184
Diffstat (limited to 'src/vnet')
-rw-r--r--src/vnet/arp/arp.c22
-rw-r--r--src/vnet/bonding/device.c6
-rw-r--r--src/vnet/ip-neighbor/ip4_neighbor.c12
-rw-r--r--src/vnet/ip-neighbor/ip4_neighbor.h23
-rw-r--r--src/vnet/ip-neighbor/ip6_neighbor.c20
-rw-r--r--src/vnet/ip-neighbor/ip6_neighbor.h23
-rw-r--r--src/vnet/ip-neighbor/ip_neighbor.c140
-rw-r--r--src/vnet/ip-neighbor/ip_neighbor.h5
-rw-r--r--src/vnet/ip-neighbor/ip_neighbor_types.c47
-rw-r--r--src/vnet/ip-neighbor/ip_neighbor_types.h30
-rw-r--r--src/vnet/ip6-nd/ip6_nd.c15
-rw-r--r--src/vnet/ip6-nd/ip6_nd_inline.h5
12 files changed, 297 insertions, 51 deletions
diff --git a/src/vnet/arp/arp.c b/src/vnet/arp/arp.c
index a2292f1c922..5765101701d 100644
--- a/src/vnet/arp/arp.c
+++ b/src/vnet/arp/arp.c
@@ -25,6 +25,7 @@
#include <vnet/pg/pg.h>
#include <vnet/ip-neighbor/ip_neighbor.h>
+#include <vnet/ip-neighbor/ip4_neighbor.h>
#include <vnet/ip-neighbor/ip_neighbor_dp.h>
#include <vlibmemory/api.h>
@@ -565,8 +566,14 @@ arp_reply (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
error0 = ETHERNET_ARP_ERROR_l3_dst_address_not_local;
else if (arp0->ip4_over_ethernet[0].ip4.as_u32 ==
arp0->ip4_over_ethernet[1].ip4.as_u32)
- error0 = arp_learn (sw_if_index0,
- &arp0->ip4_over_ethernet[0]);
+ {
+ vlib_increment_simple_counter (
+ &ip_neighbor_counters[AF_IP4]
+ .ipnc[VLIB_RX][IP_NEIGHBOR_CTR_GRAT],
+ vm->thread_index, sw_if_index0, 1);
+ error0 =
+ arp_learn (sw_if_index0, &arp0->ip4_over_ethernet[0]);
+ }
goto drop;
case ARP_DST_FIB_CONN:
/* destination is connected, continue to process */
@@ -600,6 +607,14 @@ arp_reply (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
goto drop;
}
+ vlib_increment_simple_counter (
+ &ip_neighbor_counters[AF_IP4]
+ .ipnc[VLIB_RX][arp0->opcode == clib_host_to_net_u16 (
+ ETHERNET_ARP_OPCODE_reply) ?
+ IP_NEIGHBOR_CTR_REPLY :
+ IP_NEIGHBOR_CTR_REQUEST],
+ vm->thread_index, sw_if_index0, 1);
+
/* Learn or update sender's mapping only for replies to addresses
* that are local to the subnet */
if (arp0->opcode ==
@@ -653,6 +668,9 @@ arp_reply (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
if (!error0)
error0 = arp_learn (sw_if_index0, &arp0->ip4_over_ethernet[1]);
+ vlib_increment_simple_counter (
+ &ip_neighbor_counters[AF_IP4].ipnc[VLIB_TX][IP_NEIGHBOR_CTR_REPLY],
+ vm->thread_index, sw_if_index0, 1);
n_replies_sent += 1;
goto enqueue;
diff --git a/src/vnet/bonding/device.c b/src/vnet/bonding/device.c
index dcf7203fe9e..ca48585fa0a 100644
--- a/src/vnet/bonding/device.c
+++ b/src/vnet/bonding/device.c
@@ -581,8 +581,10 @@ bond_active_interface_switch_cb (vnet_main_t * vnm, u32 sw_if_index,
{
bond_main_t *bm = &bond_main;
- ip4_neighbor_advertise (bm->vlib_main, bm->vnet_main, sw_if_index, NULL);
- ip6_neighbor_advertise (bm->vlib_main, bm->vnet_main, sw_if_index, NULL);
+ ip4_neighbor_advertise (bm->vlib_main, bm->vnet_main, sw_if_index,
+ vlib_get_thread_index (), NULL);
+ ip6_neighbor_advertise (bm->vlib_main, bm->vnet_main, sw_if_index,
+ vlib_get_thread_index (), NULL);
return (WALK_CONTINUE);
}
diff --git a/src/vnet/ip-neighbor/ip4_neighbor.c b/src/vnet/ip-neighbor/ip4_neighbor.c
index cf0e81a0b43..368703d595b 100644
--- a/src/vnet/ip-neighbor/ip4_neighbor.c
+++ b/src/vnet/ip-neighbor/ip4_neighbor.c
@@ -55,7 +55,8 @@ VLIB_REGISTER_LOG_CLASS (ip4_neighbor_log, static) = {
vlib_log_debug (ip4_neighbor_log.class, fmt, __VA_ARGS__)
void
-ip4_neighbor_probe_dst (u32 sw_if_index, const ip4_address_t * dst)
+ip4_neighbor_probe_dst (u32 sw_if_index, u32 thread_index,
+ const ip4_address_t *dst)
{
ip4_address_t src;
adj_index_t ai;
@@ -71,9 +72,8 @@ ip4_neighbor_probe_dst (u32 sw_if_index, const ip4_address_t * dst)
}
void
-ip4_neighbor_advertise (vlib_main_t * vm,
- vnet_main_t * vnm,
- u32 sw_if_index, const ip4_address_t * addr)
+ip4_neighbor_advertise (vlib_main_t *vm, vnet_main_t *vnm, u32 sw_if_index,
+ u32 thread_index, const ip4_address_t *addr)
{
vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
ip4_main_t *i4m = &ip4_main;
@@ -126,6 +126,10 @@ ip4_neighbor_advertise (vlib_main_t * vm,
to_next[0] = bi;
f->n_vectors = 1;
vlib_put_frame_to_node (vm, hi->output_node_index, f);
+
+ vlib_increment_simple_counter (
+ &ip_neighbor_counters[AF_IP4].ipnc[VLIB_TX][IP_NEIGHBOR_CTR_GRAT],
+ thread_index, sw_if_index, 1);
}
}
diff --git a/src/vnet/ip-neighbor/ip4_neighbor.h b/src/vnet/ip-neighbor/ip4_neighbor.h
index c330dfa59e7..8ace8d1a2d0 100644
--- a/src/vnet/ip-neighbor/ip4_neighbor.h
+++ b/src/vnet/ip-neighbor/ip4_neighbor.h
@@ -18,19 +18,18 @@
#include <vnet/ip/ip.h>
#include <vnet/ethernet/arp_packet.h>
+#include <vnet/ip-neighbor/ip_neighbor_types.h>
-extern void ip4_neighbor_probe_dst (u32 sw_if_index,
- const ip4_address_t * dst);
-extern void ip4_neighbor_advertise (vlib_main_t * vm,
- vnet_main_t * vnm,
- u32 sw_if_index,
- const ip4_address_t * addr);
+extern void ip4_neighbor_probe_dst (u32 sw_if_index, u32 thread_index,
+ const ip4_address_t *dst);
+extern void ip4_neighbor_advertise (vlib_main_t *vm, vnet_main_t *vnm,
+ u32 sw_if_index, u32 thread_index,
+ const ip4_address_t *addr);
always_inline vlib_buffer_t *
-ip4_neighbor_probe (vlib_main_t * vm,
- vnet_main_t * vnm,
- const ip_adjacency_t * adj0,
- const ip4_address_t * src, const ip4_address_t * dst)
+ip4_neighbor_probe (vlib_main_t *vm, vnet_main_t *vnm,
+ const ip_adjacency_t *adj0, const ip4_address_t *src,
+ const ip4_address_t *dst)
{
vnet_hw_interface_t *hw_if0;
ethernet_arp_header_t *h0;
@@ -73,6 +72,10 @@ ip4_neighbor_probe (vlib_main_t * vm,
vlib_put_frame_to_node (vm, hw_if0->output_node_index, f);
}
+ vlib_increment_simple_counter (
+ &ip_neighbor_counters[AF_IP4].ipnc[VLIB_TX][IP_NEIGHBOR_CTR_REQUEST],
+ vm->thread_index, adj0->rewrite_header.sw_if_index, 1);
+
return b0;
}
diff --git a/src/vnet/ip-neighbor/ip6_neighbor.c b/src/vnet/ip-neighbor/ip6_neighbor.c
index cf14954e96d..a59495edbc8 100644
--- a/src/vnet/ip-neighbor/ip6_neighbor.c
+++ b/src/vnet/ip-neighbor/ip6_neighbor.c
@@ -31,20 +31,20 @@ VLIB_REGISTER_LOG_CLASS (ip6_neighbor_log, static) = {
#define log_debug(fmt, ...) \
vlib_log_debug (ip6_neighbor_log.class, fmt, __VA_ARGS__)
void
-ip6_neighbor_probe_dst (u32 sw_if_index, const ip6_address_t * dst)
+ip6_neighbor_probe_dst (u32 sw_if_index, u32 thread_index,
+ const ip6_address_t *dst)
{
ip6_address_t src;
if (fib_sas6_get (sw_if_index, dst, &src) ||
ip6_sas_by_sw_if_index (sw_if_index, dst, &src))
- ip6_neighbor_probe (vlib_get_main (), vnet_get_main (),
- sw_if_index, &src, dst);
+ ip6_neighbor_probe (vlib_get_main (), vnet_get_main (), sw_if_index,
+ thread_index, &src, dst);
}
void
-ip6_neighbor_advertise (vlib_main_t * vm,
- vnet_main_t * vnm,
- u32 sw_if_index, const ip6_address_t * addr)
+ip6_neighbor_advertise (vlib_main_t *vm, vnet_main_t *vnm, u32 sw_if_index,
+ u32 thread_index, const ip6_address_t *addr)
{
vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
ip6_main_t *i6m = &ip6_main;
@@ -105,6 +105,10 @@ ip6_neighbor_advertise (vlib_main_t * vm,
to_next[0] = bi;
f->n_vectors = 1;
vlib_put_frame_to_node (vm, hi->output_node_index, f);
+
+ vlib_increment_simple_counter (
+ &ip_neighbor_counters[AF_IP6].ipnc[VLIB_TX][IP_NEIGHBOR_CTR_GRAT],
+ thread_index, sw_if_index, 1);
}
}
@@ -222,8 +226,8 @@ ip6_discover_neighbor_inline (vlib_main_t * vm,
continue;
}
- b0 = ip6_neighbor_probe (vm, vnm, sw_if_index0,
- &src, &ip0->dst_address);
+ b0 = ip6_neighbor_probe (vm, vnm, sw_if_index0, thread_index, &src,
+ &ip0->dst_address);
if (PREDICT_TRUE (NULL != b0))
{
diff --git a/src/vnet/ip-neighbor/ip6_neighbor.h b/src/vnet/ip-neighbor/ip6_neighbor.h
index ad2ace21948..c6e718dc2ff 100644
--- a/src/vnet/ip-neighbor/ip6_neighbor.h
+++ b/src/vnet/ip-neighbor/ip6_neighbor.h
@@ -25,23 +25,22 @@
#include <vnet/ip/icmp46_packet.h>
#include <vnet/ethernet/ethernet.h>
#include <vnet/adj/adj_internal.h>
+#include <vnet/ip-neighbor/ip_neighbor_types.h>
/* Template used to generate IP6 neighbor solicitation packets. */
extern vlib_packet_template_t ip6_neighbor_packet_template;
-extern void ip6_neighbor_advertise (vlib_main_t * vm,
- vnet_main_t * vnm,
- u32 sw_if_index,
- const ip6_address_t * addr);
+extern void ip6_neighbor_advertise (vlib_main_t *vm, vnet_main_t *vnm,
+ u32 sw_if_index, u32 thread_index,
+ const ip6_address_t *addr);
-extern void ip6_neighbor_probe_dst (u32 sw_if_index,
- const ip6_address_t * dst);
+extern void ip6_neighbor_probe_dst (u32 sw_if_index, u32 thread_index,
+ const ip6_address_t *dst);
always_inline vlib_buffer_t *
-ip6_neighbor_probe (vlib_main_t * vm,
- vnet_main_t * vnm,
- u32 sw_if_index,
- const ip6_address_t * src, const ip6_address_t * dst)
+ip6_neighbor_probe (vlib_main_t *vm, vnet_main_t *vnm, u32 sw_if_index,
+ u32 thread_index, const ip6_address_t *src,
+ const ip6_address_t *dst)
{
icmp6_neighbor_solicitation_header_t *h0;
vnet_hw_interface_t *hw_if0;
@@ -104,6 +103,10 @@ ip6_neighbor_probe (vlib_main_t * vm,
vlib_put_frame_to_node (vm, adj->ia_node_index, f);
}
+ vlib_increment_simple_counter (
+ &ip_neighbor_counters[AF_IP6].ipnc[VLIB_TX][IP_NEIGHBOR_CTR_REQUEST],
+ thread_index, sw_if_index, 1);
+
return b0;
}
diff --git a/src/vnet/ip-neighbor/ip_neighbor.c b/src/vnet/ip-neighbor/ip_neighbor.c
index 6ba191abaf6..b2d4fa0d8be 100644
--- a/src/vnet/ip-neighbor/ip_neighbor.c
+++ b/src/vnet/ip-neighbor/ip_neighbor.c
@@ -27,6 +27,74 @@
#include <vnet/fib/fib_table.h>
#include <vnet/adj/adj_mcast.h>
+ip_neighbor_counters_t ip_neighbor_counters[] =
+{
+ [AF_IP4] = {
+ .ipnc = {
+ [VLIB_RX] = {
+ [IP_NEIGHBOR_CTR_REPLY] = {
+ .name = "arp-rx-replies",
+ .stat_segment_name = "/net/arp/rx/replies",
+ },
+ [IP_NEIGHBOR_CTR_REQUEST] = {
+ .name = "arp-rx-requests",
+ .stat_segment_name = "/net/arp/rx/requests",
+ },
+ [IP_NEIGHBOR_CTR_GRAT] = {
+ .name = "arp-rx-gratuitous",
+ .stat_segment_name = "/net/arp/rx/gratuitous",
+ },
+ },
+ [VLIB_TX] = {
+ [IP_NEIGHBOR_CTR_REPLY] = {
+ .name = "arp-tx-replies",
+ .stat_segment_name = "/net/arp/tx/replies",
+ },
+ [IP_NEIGHBOR_CTR_REQUEST] = {
+ .name = "arp-tx-requests",
+ .stat_segment_name = "/net/arp/tx/requests",
+ },
+ [IP_NEIGHBOR_CTR_GRAT] = {
+ .name = "arp-tx-gratuitous",
+ .stat_segment_name = "/net/arp/tx/gratuitous",
+ },
+ },
+ },
+ },
+ [AF_IP6] = {
+ .ipnc = {
+ [VLIB_RX] = {
+ [IP_NEIGHBOR_CTR_REPLY] = {
+ .name = "ip6-nd-rx-replies",
+ .stat_segment_name = "/net/ip6-nd/rx/replies",
+ },
+ [IP_NEIGHBOR_CTR_REQUEST] = {
+ .name = "ip6-nd-rx-requests",
+ .stat_segment_name = "/net/ip6-nd/rx/requests",
+ },
+ [IP_NEIGHBOR_CTR_GRAT] = {
+ .name = "ip6-nd-rx-gratuitous",
+ .stat_segment_name = "/net/ip6-nd/rx/gratuitous",
+ },
+ },
+ [VLIB_TX] = {
+ [IP_NEIGHBOR_CTR_REPLY] = {
+ .name = "ip6-nd-tx-replies",
+ .stat_segment_name = "/net/ip6-nd/tx/replies",
+ },
+ [IP_NEIGHBOR_CTR_REQUEST] = {
+ .name = "ip6-nd-tx-requests",
+ .stat_segment_name = "/net/ip6-nd/tx/requests",
+ },
+ [IP_NEIGHBOR_CTR_GRAT] = {
+ .name = "ip6-nd-tx-gratuitous",
+ .stat_segment_name = "/net/ip6-nd/tx/gratuitous",
+ },
+ },
+ },
+ },
+};
+
/** Pool for All IP neighbors */
static ip_neighbor_t *ip_neighbor_pool;
@@ -1017,8 +1085,8 @@ ip_neighbor_register (ip_address_family_t af, const ip_neighbor_vft_t * vft)
}
void
-ip_neighbor_probe_dst (u32 sw_if_index,
- ip_address_family_t af, const ip46_address_t * dst)
+ip_neighbor_probe_dst (u32 sw_if_index, u32 thread_index,
+ ip_address_family_t af, const ip46_address_t *dst)
{
if (!vnet_sw_interface_is_admin_up (vnet_get_main (), sw_if_index))
return;
@@ -1026,10 +1094,10 @@ ip_neighbor_probe_dst (u32 sw_if_index,
switch (af)
{
case AF_IP6:
- ip6_neighbor_probe_dst (sw_if_index, &dst->ip6);
+ ip6_neighbor_probe_dst (sw_if_index, thread_index, &dst->ip6);
break;
case AF_IP4:
- ip4_neighbor_probe_dst (sw_if_index, &dst->ip4);
+ ip4_neighbor_probe_dst (sw_if_index, thread_index, &dst->ip4);
break;
}
}
@@ -1038,6 +1106,7 @@ void
ip_neighbor_probe (const ip_adjacency_t * adj)
{
ip_neighbor_probe_dst (adj->rewrite_header.sw_if_index,
+ vlib_get_thread_index (),
ip_address_family_from_fib_proto (adj->ia_nh_proto),
&adj->sub_type.nbr.next_hop);
}
@@ -1291,8 +1360,8 @@ VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (ip_neighbor_interface_admin_change);
* Remove any arp entries associated with the specified interface
*/
static clib_error_t *
-ip_neighbor_delete_sw_interface (vnet_main_t * vnm,
- u32 sw_if_index, u32 is_add)
+ip_neighbor_add_del_sw_interface (vnet_main_t *vnm, u32 sw_if_index,
+ u32 is_add)
{
IP_NEIGHBOR_DBG ("interface-change: %U %s",
format_vnet_sw_if_index_name, vnet_get_main (),
@@ -1305,10 +1374,16 @@ ip_neighbor_delete_sw_interface (vnet_main_t * vnm,
FOR_EACH_IP_ADDRESS_FAMILY (af) ip_neighbor_flush (af, sw_if_index);
}
+ if (is_add)
+ {
+ ip_neighbor_alloc_ctr (&ip_neighbor_counters[AF_IP4], sw_if_index);
+ ip_neighbor_alloc_ctr (&ip_neighbor_counters[AF_IP6], sw_if_index);
+ }
+
return (NULL);
}
-VNET_SW_INTERFACE_ADD_DEL_FUNCTION (ip_neighbor_delete_sw_interface);
+VNET_SW_INTERFACE_ADD_DEL_FUNCTION (ip_neighbor_add_del_sw_interface);
typedef struct ip_neighbor_walk_covered_ctx_t_
{
@@ -1519,8 +1594,9 @@ ip_neighbour_age_out (index_t ipni, f64 now, f64 * wait)
}
else
{
- ip_neighbor_probe_dst (ip_neighbor_get_sw_if_index (ipn),
- af, &ip_addr_46 (&ipn->ipn_key->ipnk_ip));
+ ip_neighbor_probe_dst (ip_neighbor_get_sw_if_index (ipn), af,
+ vlib_get_thread_index (),
+ &ip_addr_46 (&ipn->ipn_key->ipnk_ip));
ipn->ipn_n_probes++;
*wait = 1;
@@ -1745,6 +1821,47 @@ done:
return error;
}
+static void
+ip_neighbor_stats_show_one (vlib_main_t *vm, vnet_main_t *vnm, u32 sw_if_index)
+{
+ vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnm, sw_if_index);
+ vlib_cli_output (vm, " arp:%U", format_ip_neighbor_counters,
+ &ip_neighbor_counters[AF_IP4], sw_if_index);
+ vlib_cli_output (vm, " nd: %U", format_ip_neighbor_counters,
+ &ip_neighbor_counters[AF_IP6], sw_if_index);
+}
+
+static walk_rc_t
+ip_neighbor_stats_show_cb (vnet_main_t *vnm, vnet_sw_interface_t *si,
+ void *ctx)
+{
+ ip_neighbor_stats_show_one (ctx, vnm, si->sw_if_index);
+
+ return (WALK_CONTINUE);
+}
+
+static clib_error_t *
+ip_neighbor_stats_show (vlib_main_t *vm, unformat_input_t *input,
+ vlib_cli_command_t *cmd)
+{
+ vnet_main_t *vnm;
+ u32 sw_if_index;
+
+ vnm = vnet_get_main ();
+ sw_if_index = ~0;
+ (void) unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index);
+
+ if (~0 == sw_if_index)
+ {
+ vnet_sw_interface_walk (vnm, ip_neighbor_stats_show_cb, vm);
+ }
+ else
+ {
+ ip_neighbor_stats_show_one (vm, vnm, sw_if_index);
+ }
+ return (NULL);
+}
+
/* *INDENT-OFF* */
VLIB_CLI_COMMAND (show_ip_neighbor_cfg_cmd_node, static) = {
.path = "show ip neighbor-config",
@@ -1757,6 +1874,11 @@ VLIB_CLI_COMMAND (set_ip_neighbor_cfg_cmd_node, static) = {
.short_help = "set ip neighbor-config ip4|ip6 [limit <limit>] [age <age>] "
"[recycle|norecycle]",
};
+VLIB_CLI_COMMAND (show_ip_neighbor_stats_cmd_node, static) = {
+ .path = "show ip neighbor-stats",
+ .function = ip_neighbor_stats_show,
+ .short_help = "show ip neighbor-stats [interface]",
+};
/* *INDENT-ON* */
static clib_error_t *
diff --git a/src/vnet/ip-neighbor/ip_neighbor.h b/src/vnet/ip-neighbor/ip_neighbor.h
index 17028012dfd..8c07df86ba8 100644
--- a/src/vnet/ip-neighbor/ip_neighbor.h
+++ b/src/vnet/ip-neighbor/ip_neighbor.h
@@ -54,9 +54,9 @@ extern void ip_neighbor_learn (const ip_neighbor_learn_t * l);
extern void ip_neighbor_update (vnet_main_t * vnm, adj_index_t ai);
extern void ip_neighbor_probe (const ip_adjacency_t * adj);
-extern void ip_neighbor_probe_dst (u32 sw_if_index,
+extern void ip_neighbor_probe_dst (u32 sw_if_index, u32 thread_index,
ip_address_family_t af,
- const ip46_address_t * ip);
+ const ip46_address_t *ip);
extern void ip_neighbor_mark (ip_address_family_t af);
extern void ip_neighbor_sweep (ip_address_family_t af);
@@ -112,7 +112,6 @@ typedef struct ip_neighbor_vft_t_
extern void ip_neighbor_register (ip_address_family_t af,
const ip_neighbor_vft_t * vft);
-
#endif /* __INCLUDE_IP_NEIGHBOR_H__ */
/*
diff --git a/src/vnet/ip-neighbor/ip_neighbor_types.c b/src/vnet/ip-neighbor/ip_neighbor_types.c
index 76fbc5ac8a9..39039a48249 100644
--- a/src/vnet/ip-neighbor/ip_neighbor_types.c
+++ b/src/vnet/ip-neighbor/ip_neighbor_types.c
@@ -83,6 +83,53 @@ format_ip_neighbor (u8 * s, va_list * va)
ipn->ipn_key->ipnk_sw_if_index));
}
+static void
+ip_neighbor_alloc_one_ctr (ip_neighbor_counters_t *ctr, vlib_dir_t dir,
+ ip_neighbor_counter_type_t type, u32 sw_if_index)
+{
+ vlib_validate_simple_counter (&(ctr->ipnc[dir][type]), sw_if_index);
+ vlib_zero_simple_counter (&(ctr->ipnc[dir][type]), sw_if_index);
+}
+
+void
+ip_neighbor_alloc_ctr (ip_neighbor_counters_t *ctr, u32 sw_if_index)
+{
+ ip_neighbor_counter_type_t type;
+ vlib_dir_t dir;
+
+ FOREACH_VLIB_DIR (dir)
+ {
+ FOREACH_IP_NEIGHBOR_CTR (type)
+ {
+ ip_neighbor_alloc_one_ctr (ctr, dir, type, sw_if_index);
+ }
+ }
+}
+
+u8 *
+format_ip_neighbor_counters (u8 *s, va_list *args)
+{
+ ip_neighbor_counters_t *ctr = va_arg (*args, ip_neighbor_counters_t *);
+ u32 sw_if_index = va_arg (*args, u32);
+ vlib_dir_t dir;
+
+ FOREACH_VLIB_DIR (dir)
+ {
+ s = format (s, " %U:[", format_vlib_rx_tx, dir);
+
+#define _(a, b) \
+ s = format (s, "%s:%lld ", b, \
+ vlib_get_simple_counter (&ctr->ipnc[dir][IP_NEIGHBOR_CTR_##a], \
+ sw_if_index));
+ foreach_ip_neighbor_counter_type
+#undef _
+
+ s = format (s, "]");
+ }
+
+ return (s);
+}
+
/*
* fd.io coding-style-patch-verification: ON
*
diff --git a/src/vnet/ip-neighbor/ip_neighbor_types.h b/src/vnet/ip-neighbor/ip_neighbor_types.h
index 2eb8fd0841f..d7e818ba252 100644
--- a/src/vnet/ip-neighbor/ip_neighbor_types.h
+++ b/src/vnet/ip-neighbor/ip_neighbor_types.h
@@ -120,7 +120,37 @@ extern void ip_neighbor_clone (const ip_neighbor_t * ipn,
extern void ip_neighbor_free (ip_neighbor_t * ipn);
+/**
+ * Keep RX and TX counts per-AF
+ */
+#define foreach_ip_neighbor_counter_type \
+ _ (REPLY, "reply") \
+ _ (REQUEST, "request") \
+ _ (GRAT, "gratuitous")
+
+typedef enum ip_neighbor_counter_type_t_
+{
+#define _(a, b) IP_NEIGHBOR_CTR_##a,
+ foreach_ip_neighbor_counter_type
+#undef _
+} ip_neighbor_counter_type_t;
+
+#define N_IP_NEIGHBOR_CTRS (IP_NEIGHBOR_CTR_GRAT + 1)
+
+#define FOREACH_IP_NEIGHBOR_CTR(_type) \
+ for (_type = 0; _type < N_IP_NEIGHBOR_CTRS; _type++)
+
+typedef struct ip_neighbor_counters_t_
+{
+ vlib_simple_counter_main_t ipnc[VLIB_N_DIR][N_IP_NEIGHBOR_CTRS];
+} ip_neighbor_counters_t;
+
+extern u8 *format_ip_neighbor_counters (u8 *s, va_list *args);
+
+extern void ip_neighbor_alloc_ctr (ip_neighbor_counters_t *ctr,
+ u32 sw_if_index);
+extern ip_neighbor_counters_t ip_neighbor_counters[N_AF];
#endif /* __INCLUDE_IP_NEIGHBOR_H__ */
diff --git a/src/vnet/ip6-nd/ip6_nd.c b/src/vnet/ip6-nd/ip6_nd.c
index 772c811ae20..513d2bf6e87 100644
--- a/src/vnet/ip6-nd/ip6_nd.c
+++ b/src/vnet/ip6-nd/ip6_nd.c
@@ -90,6 +90,7 @@ icmp6_neighbor_solicitation_or_advertisement (vlib_main_t * vm,
icmp6_neighbor_discovery_ethernet_link_layer_address_option_t *o0;
u32 bi0, options_len0, sw_if_index0, next0, error0;
u32 ip6_sadd_link_local, ip6_sadd_unspecified;
+ ip_neighbor_counter_type_t c_type;
int is_rewrite0;
u32 ni0;
@@ -230,16 +231,24 @@ icmp6_neighbor_solicitation_or_advertisement (vlib_main_t * vm,
}
if (is_solicitation)
- next0 = (error0 != ICMP6_ERROR_NONE
- ? ICMP6_NEIGHBOR_SOLICITATION_NEXT_DROP
- : ICMP6_NEIGHBOR_SOLICITATION_NEXT_REPLY);
+ {
+ next0 = (error0 != ICMP6_ERROR_NONE ?
+ ICMP6_NEIGHBOR_SOLICITATION_NEXT_DROP :
+ ICMP6_NEIGHBOR_SOLICITATION_NEXT_REPLY);
+ c_type = IP_NEIGHBOR_CTR_REQUEST;
+ }
else
{
next0 = 0;
error0 = error0 == ICMP6_ERROR_NONE ?
ICMP6_ERROR_NEIGHBOR_ADVERTISEMENTS_RX : error0;
+ c_type = IP_NEIGHBOR_CTR_REPLY;
}
+ vlib_increment_simple_counter (
+ &ip_neighbor_counters[AF_IP6].ipnc[VLIB_RX][c_type],
+ vm->thread_index, sw_if_index0, 1);
+
if (is_solicitation && error0 == ICMP6_ERROR_NONE)
{
icmp6_send_neighbor_advertisement (vm, p0, ip0, h0, o0,
diff --git a/src/vnet/ip6-nd/ip6_nd_inline.h b/src/vnet/ip6-nd/ip6_nd_inline.h
index ad0c3a3a79b..5e8b9d6e4c0 100644
--- a/src/vnet/ip6-nd/ip6_nd_inline.h
+++ b/src/vnet/ip6-nd/ip6_nd_inline.h
@@ -22,6 +22,7 @@
#include <vnet/ethernet/ethernet.h>
#include <vnet/ip/icmp46_packet.h>
#include <vnet/ip/ip6.h>
+#include <vnet/ip-neighbor/ip_neighbor_types.h>
typedef enum
{
@@ -88,6 +89,10 @@ icmp6_send_neighbor_advertisement (
vnet_buffer (b)->sw_if_index[VLIB_TX] = sw_if_index0;
vnet_buffer (b)->sw_if_index[VLIB_RX] =
vnet_main.local_interface_sw_if_index;
+
+ vlib_increment_simple_counter (
+ &ip_neighbor_counters[AF_IP6].ipnc[VLIB_TX][IP_NEIGHBOR_CTR_REPLY],
+ vm->thread_index, sw_if_index0, 1);
}
#endif /* included_ip6_nd_inline_h */