summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/vnet.am1
-rw-r--r--src/vnet/ethernet/packet.h45
-rw-r--r--src/vnet/interface.h30
-rw-r--r--src/vnet/interface_api.c11
-rw-r--r--src/vnet/interface_funcs.h3
-rw-r--r--src/vnet/interface_stats.c224
-rw-r--r--src/vpp-api/vom/interface.cpp14
-rw-r--r--src/vpp-api/vom/interface.hpp19
-rw-r--r--src/vpp-api/vom/interface_cmds.cpp42
-rw-r--r--src/vpp-api/vom/interface_cmds.hpp46
-rw-r--r--src/vpp-api/vom/interface_types.cpp8
-rw-r--r--src/vpp/stats/stats.c32
12 files changed, 434 insertions, 41 deletions
diff --git a/src/vnet.am b/src/vnet.am
index a58bdcae6f0..058948dce0e 100644
--- a/src/vnet.am
+++ b/src/vnet.am
@@ -41,6 +41,7 @@ libvnet_la_SOURCES += \
vnet/interface_cli.c \
vnet/interface_format.c \
vnet/interface_output.c \
+ vnet/interface_stats.c \
vnet/misc.c \
vnet/replication.c
diff --git a/src/vnet/ethernet/packet.h b/src/vnet/ethernet/packet.h
index 09f5e7f3d0b..1a0506dc4d6 100644
--- a/src/vnet/ethernet/packet.h
+++ b/src/vnet/ethernet/packet.h
@@ -40,6 +40,8 @@
#ifndef included_ethernet_packet_h
#define included_ethernet_packet_h
+#include <vnet/interface.h>
+
typedef enum
{
#define ethernet_type(n,s) ETHERNET_TYPE_##s = n,
@@ -67,6 +69,13 @@ ethernet_address_cast (u8 * a)
return (a[0] >> 0) & 1;
}
+always_inline int
+ethernet_address_is_broadcast (u8 * a)
+{
+ return clib_mem_unaligned (a, u32) == 0xffffffff &&
+ clib_mem_unaligned (a + 4, u16) == 0xffff;
+}
+
always_inline uword
ethernet_address_is_locally_administered (u8 * a)
{
@@ -79,6 +88,42 @@ ethernet_address_set_locally_administered (u8 * a)
a[0] |= 1 << 1;
}
+always_inline int
+eh_dst_addr_to_rx_ctype (ethernet_header_t * eh)
+{
+ if (PREDICT_TRUE (ethernet_address_cast (eh->dst_address) ==
+ ETHERNET_ADDRESS_UNICAST))
+ {
+ return VNET_INTERFACE_COUNTER_RX_UNICAST;
+ }
+ else if (ethernet_address_is_broadcast (eh->dst_address))
+ {
+ return VNET_INTERFACE_COUNTER_RX_BROADCAST;
+ }
+ else
+ {
+ return VNET_INTERFACE_COUNTER_RX_MULTICAST;
+ }
+}
+
+always_inline int
+eh_dst_addr_to_tx_ctype (ethernet_header_t * eh)
+{
+ if (PREDICT_TRUE (ethernet_address_cast (eh->dst_address) ==
+ ETHERNET_ADDRESS_UNICAST))
+ {
+ return VNET_INTERFACE_COUNTER_TX_UNICAST;
+ }
+ else if (ethernet_address_is_broadcast (eh->dst_address))
+ {
+ return VNET_INTERFACE_COUNTER_TX_BROADCAST;
+ }
+ else
+ {
+ return VNET_INTERFACE_COUNTER_TX_MULTICAST;
+ }
+}
+
/* For VLAN ethernet type. */
typedef struct
{
diff --git a/src/vnet/interface.h b/src/vnet/interface.h
index 62fdc601e99..00a7353d701 100644
--- a/src/vnet/interface.h
+++ b/src/vnet/interface.h
@@ -633,25 +633,25 @@ typedef enum
VNET_N_SIMPLE_INTERFACE_COUNTER = 9,
/* Combined counters. */
VNET_INTERFACE_COUNTER_RX = 0,
- VNET_INTERFACE_COUNTER_TX = 1,
- VNET_INTERFACE_COUNTER_RX_UNICAST = 2,
- VNET_INTERFACE_COUNTER_TX_UNICAST = 3,
- VNET_INTERFACE_COUNTER_RX_MULTICAST = 4,
- VNET_INTERFACE_COUNTER_TX_MULTICAST = 5,
- VNET_INTERFACE_COUNTER_RX_BROADCAST = 6,
+ VNET_INTERFACE_COUNTER_RX_UNICAST = 1,
+ VNET_INTERFACE_COUNTER_RX_MULTICAST = 2,
+ VNET_INTERFACE_COUNTER_RX_BROADCAST = 3,
+ VNET_INTERFACE_COUNTER_TX = 4,
+ VNET_INTERFACE_COUNTER_TX_UNICAST = 5,
+ VNET_INTERFACE_COUNTER_TX_MULTICAST = 6,
VNET_INTERFACE_COUNTER_TX_BROADCAST = 7,
VNET_N_COMBINED_INTERFACE_COUNTER = 8,
} vnet_interface_counter_type_t;
-#define foreach_combined_interface_counter(X) \
- X(VNET_INTERFACE_COUNTER_RX, rx) \
- X(VNET_INTERFACE_COUNTER_TX, tx) \
- X(VNET_INTERFACE_COUNTER_RX_UNICAST, rx_unicast) \
- X(VNET_INTERFACE_COUNTER_TX_UNICAST, tx_unicast) \
- X(VNET_INTERFACE_COUNTER_RX_MULTICAST, rx_multicast) \
- X(VNET_INTERFACE_COUNTER_TX_MULTICAST, tx_multicast) \
- X(VNET_INTERFACE_COUNTER_RX_BROADCAST, rx_broadcast) \
- X(VNET_INTERFACE_COUNTER_TX_BROADCAST, tx_broadcast)
+#define foreach_rx_combined_interface_counter(_x) \
+ for (_x = VNET_INTERFACE_COUNTER_RX; \
+ _x <= VNET_INTERFACE_COUNTER_RX_BROADCAST; \
+ _x++)
+
+#define foreach_tx_combined_interface_counter(_x) \
+ for (_x = VNET_INTERFACE_COUNTER_TX; \
+ _x <= VNET_INTERFACE_COUNTER_TX_BROADCAST; \
+ _x++)
typedef enum
{
diff --git a/src/vnet/interface_api.c b/src/vnet/interface_api.c
index 3d9bb30f142..8d982e36b73 100644
--- a/src/vnet/interface_api.c
+++ b/src/vnet/interface_api.c
@@ -1177,14 +1177,9 @@ static void
vl_api_collect_detailed_interface_stats_reply_t *rmp;
int rv = 0;
- if (mp->enable_disable)
- {
- collect_detailed_interface_stats_flag_set ();
- }
- else
- {
- collect_detailed_interface_stats_flag_clear ();
- }
+ rv =
+ vnet_sw_interface_stats_collect_enable_disable (ntohl (mp->sw_if_index),
+ mp->enable_disable);
REPLY_MACRO (VL_API_COLLECT_DETAILED_INTERFACE_STATS_REPLY);
}
diff --git a/src/vnet/interface_funcs.h b/src/vnet/interface_funcs.h
index 3d045f84d2b..6e188f7f543 100644
--- a/src/vnet/interface_funcs.h
+++ b/src/vnet/interface_funcs.h
@@ -299,6 +299,9 @@ void vnet_hw_interface_set_mtu (vnet_main_t * vnm, u32 hw_if_index, u32 mtu);
void vnet_sw_interface_update_unnumbered (u32 sw_if_index,
u32 ip_sw_if_index, u8 enable);
+int vnet_sw_interface_stats_collect_enable_disable (u32 sw_if_index,
+ u8 enable);
+
/* Formats sw/hw interface. */
format_function_t format_vnet_hw_interface;
format_function_t format_vnet_hw_interface_rx_mode;
diff --git a/src/vnet/interface_stats.c b/src/vnet/interface_stats.c
new file mode 100644
index 00000000000..1b07552727c
--- /dev/null
+++ b/src/vnet/interface_stats.c
@@ -0,0 +1,224 @@
+/*
+ * Copyright (c) 2018 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <vlib/vlib.h>
+#include <vnet/vnet.h>
+#include <vppinfra/error.h>
+
+#include <vnet/feature/feature.h>
+#include <vnet/ethernet/ethernet.h>
+
+int
+vnet_sw_interface_stats_collect_enable_disable (u32 sw_if_index, u8 enable)
+{
+ ethernet_interface_t *eif;
+ vnet_sw_interface_t *si;
+ ethernet_main_t *em;
+ vnet_main_t *vnm;
+
+ vnm = vnet_get_main ();
+ em = &ethernet_main;
+ si = vnet_get_sw_interface (vnm, sw_if_index);
+
+ /*
+ * only ethernet HW interfaces are supported at this time
+ */
+ if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE)
+ {
+ return (VNET_API_ERROR_INVALID_VALUE);
+ }
+
+ eif = ethernet_get_interface (em, si->hw_if_index);
+
+ if (!eif)
+ {
+ return (VNET_API_ERROR_FEATURE_DISABLED);
+ }
+
+ vnet_feature_enable_disable ("device-input", "stats-collect-rx",
+ sw_if_index, enable, 0, 0);
+ vnet_feature_enable_disable ("interface-output", "stats-collect-tx",
+ sw_if_index, enable, 0, 0);
+
+ return (0);
+}
+
+static u8 *
+format_stats_collect_trace (u8 * s, va_list * args)
+{
+ CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
+ CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
+
+ return s;
+}
+
+#define inc_counter(ctype, rx_tx) \
+{ \
+}
+
+static_always_inline uword
+stats_collect_inline (vlib_main_t * vm,
+ vlib_node_runtime_t * node,
+ vlib_frame_t * frame, vlib_rx_or_tx_t rxtx)
+{
+ vnet_interface_counter_type_t ct;
+ u32 n_left_from, *from, *to_next;
+ u32 next_index;
+ u32 sw_if_index = 0;
+ u32 stats_n_packets[VNET_N_COMBINED_INTERFACE_COUNTER] = { 0 };
+ u64 stats_n_bytes[VNET_N_COMBINED_INTERFACE_COUNTER] = { 0 };
+
+ from = vlib_frame_vector_args (frame);
+ n_left_from = frame->n_vectors;
+ next_index = node->cached_next_index;
+
+ while (n_left_from > 0)
+ {
+ u32 n_left_to_next;
+
+ vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
+
+ while (n_left_from > 0 && n_left_to_next > 0)
+ {
+ u32 bi0;
+ vlib_buffer_t *b0;
+ u32 next0 = 0;
+ int b0_ctype;
+
+ /* speculatively enqueue b0 to the current next frame */
+ to_next[0] = bi0 = from[0];
+ to_next += 1;
+ n_left_to_next -= 1;
+ from += 1;
+ n_left_from -= 1;
+
+ b0 = vlib_get_buffer (vm, bi0);
+ sw_if_index = vnet_buffer (b0)->sw_if_index[rxtx];
+
+ if (VLIB_RX == rxtx)
+ {
+ b0_ctype =
+ eh_dst_addr_to_rx_ctype (vlib_buffer_get_current (b0));
+ }
+ else
+ {
+ b0_ctype =
+ eh_dst_addr_to_tx_ctype (vlib_buffer_get_current (b0));
+ }
+
+ stats_n_bytes[b0_ctype] += vlib_buffer_length_in_chain (vm, b0);
+ stats_n_packets[b0_ctype] += 1;
+
+ vnet_feature_next (sw_if_index, &next0, b0);
+
+ vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
+ n_left_to_next, bi0, next0);
+ }
+
+ if (VLIB_RX == rxtx)
+ {
+ foreach_rx_combined_interface_counter (ct)
+ {
+ vlib_increment_combined_counter
+ (vnet_main.interface_main.combined_sw_if_counters + ct,
+ vlib_get_thread_index (),
+ sw_if_index, stats_n_packets[ct], stats_n_bytes[ct]);
+ }
+ }
+ else
+ {
+ foreach_tx_combined_interface_counter (ct)
+ {
+ vlib_increment_combined_counter
+ (vnet_main.interface_main.combined_sw_if_counters + ct,
+ vlib_get_thread_index (),
+ sw_if_index, stats_n_packets[ct], stats_n_bytes[ct]);
+ }
+ }
+
+ vlib_put_next_frame (vm, node, next_index, n_left_to_next);
+ }
+
+ return frame->n_vectors;
+}
+
+static uword
+stats_collect_rx (vlib_main_t * vm,
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
+{
+ return stats_collect_inline (vm, node, frame, VLIB_RX);
+}
+
+static uword
+stats_collect_tx (vlib_main_t * vm,
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
+{
+ return stats_collect_inline (vm, node, frame, VLIB_TX);
+}
+
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (stats_collect_rx_node) = {
+ .vector_size = sizeof (u32),
+ .format_trace = format_stats_collect_trace,
+ .type = VLIB_NODE_TYPE_INTERNAL,
+ .n_errors = 0,
+ .n_next_nodes = 0,
+ .function = stats_collect_rx,
+ .name = "stats-collect-rx",
+};
+
+VLIB_REGISTER_NODE (stats_collect_tx_node) = {
+ .vector_size = sizeof (u32),
+ .format_trace = format_stats_collect_trace,
+ .type = VLIB_NODE_TYPE_INTERNAL,
+ .n_errors = 0,
+ .n_next_nodes = 0,
+ .function = stats_collect_tx,
+ .name = "stats-collect-tx",
+};
+
+VLIB_NODE_FUNCTION_MULTIARCH (stats_collect_rx_node, stats_collect_rx);
+VLIB_NODE_FUNCTION_MULTIARCH (stats_collect_tx_node, stats_collect_tx);
+
+VNET_FEATURE_INIT (stats_collect_rx_node, static) = {
+ .arc_name = "device-input",
+ .node_name = "stats-collect-rx",
+ .runs_before = VNET_FEATURES ("ethernet-input"),
+};
+
+VNET_FEATURE_INIT (stats_collect_tx_node, static) = {
+ .arc_name = "interface-output",
+ .node_name = "stats-collect-tx",
+ .runs_before = VNET_FEATURES ("interface-tx"),
+};
+
+/* *INDENT-ON* */
+
+static clib_error_t *
+stats_collect_init (vlib_main_t * vm)
+{
+ return 0;
+}
+
+VLIB_INIT_FUNCTION (stats_collect_init);
+
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vpp-api/vom/interface.cpp b/src/vpp-api/vom/interface.cpp
index f323727b052..435002a1067 100644
--- a/src/vpp-api/vom/interface.cpp
+++ b/src/vpp-api/vom/interface.cpp
@@ -49,6 +49,7 @@ interface::interface(const std::string& name,
, m_state(itf_state)
, m_table_id(route::DEFAULT_TABLE)
, m_l2_address(l2_address_t::ZERO, rc_t::UNSET)
+ , m_stats_type(stats_type_t::NORMAL)
, m_oper(oper_state_t::DOWN)
, m_tag(tag)
{
@@ -66,6 +67,7 @@ interface::interface(const std::string& name,
, m_state(itf_state)
, m_table_id(m_rd->table_id())
, m_l2_address(l2_address_t::ZERO, rc_t::UNSET)
+ , m_stats_type(stats_type_t::NORMAL)
, m_oper(oper_state_t::DOWN)
, m_tag(tag)
{
@@ -79,6 +81,7 @@ interface::interface(const interface& o)
, m_state(o.m_state)
, m_table_id(o.m_table_id)
, m_l2_address(o.m_l2_address)
+ , m_stats_type(o.m_stats_type)
, m_oper(o.m_oper)
, m_tag(o.m_tag)
{
@@ -403,9 +406,14 @@ interface::set(const std::string& tag)
}
void
-interface::enable_stats_i(interface::stat_listener& el)
+interface::enable_stats_i(interface::stat_listener& el, const stats_type_t& st)
{
if (!m_stats) {
+ if (stats_type_t::DETAILED == st) {
+ m_stats_type = st;
+ HW::enqueue(new interface_cmds::collect_detail_stats_change_cmd(
+ m_stats_type, handle_i(), true));
+ }
m_stats.reset(new interface_cmds::stats_enable_cmd(el, handle_i()));
HW::enqueue(m_stats);
HW::write();
@@ -413,9 +421,9 @@ interface::enable_stats_i(interface::stat_listener& el)
}
void
-interface::enable_stats(interface::stat_listener& el)
+interface::enable_stats(interface::stat_listener& el, const stats_type_t& st)
{
- singular()->enable_stats_i(el);
+ singular()->enable_stats_i(el, st);
}
std::shared_ptr<interface>
diff --git a/src/vpp-api/vom/interface.hpp b/src/vpp-api/vom/interface.hpp
index 0099bde42ba..29903b5623b 100644
--- a/src/vpp-api/vom/interface.hpp
+++ b/src/vpp-api/vom/interface.hpp
@@ -41,6 +41,15 @@ class events_cmd;
class interface : public object_base
{
public:
+ struct stats_type_t : public enum_base<stats_type_t>
+ {
+ const static stats_type_t DETAILED;
+ const static stats_type_t NORMAL;
+
+ private:
+ stats_type_t(int v, const std::string& s);
+ };
+
/**
* The key for interface's key
*/
@@ -447,7 +456,8 @@ public:
/**
* Enable stats for this interface
*/
- void enable_stats(stat_listener& el);
+ void enable_stats(stat_listener& el,
+ const stats_type_t& st = stats_type_t::NORMAL);
protected:
/**
@@ -540,7 +550,7 @@ private:
/**
* enable the interface stats in the singular instance
*/
- void enable_stats_i(stat_listener& el);
+ void enable_stats_i(stat_listener& el, const stats_type_t& st);
/**
* Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
@@ -600,6 +610,11 @@ private:
HW::item<l2_address_t> m_l2_address;
/**
+ * The state of the detailed stats collection
+ */
+ HW::item<stats_type_t> m_stats_type;
+
+ /**
* Operational state of the interface
*/
oper_state_t m_oper;
diff --git a/src/vpp-api/vom/interface_cmds.cpp b/src/vpp-api/vom/interface_cmds.cpp
index 084d6d5cb08..b1decd2bf7c 100644
--- a/src/vpp-api/vom/interface_cmds.cpp
+++ b/src/vpp-api/vom/interface_cmds.cpp
@@ -412,6 +412,48 @@ set_mac_cmd::to_string() const
return (s.str());
}
+collect_detail_stats_change_cmd::collect_detail_stats_change_cmd(
+ HW::item<interface::stats_type_t>& item,
+ const handle_t& hdl,
+ bool enable)
+ : rpc_cmd(item)
+ , m_hdl(hdl)
+ , m_enable(enable)
+{
+}
+
+bool
+collect_detail_stats_change_cmd::operator==(
+ const collect_detail_stats_change_cmd& other) const
+{
+ return ((m_hdl == other.m_hdl) && (m_hw_item == other.m_hw_item) &&
+ (m_enable == other.m_enable));
+}
+
+rc_t
+collect_detail_stats_change_cmd::issue(connection& con)
+{
+ msg_t req(con.ctx(), std::ref(*this));
+
+ auto& payload = req.get_request().get_payload();
+ payload.sw_if_index = m_hdl.value();
+ payload.enable_disable = m_enable;
+
+ VAPI_CALL(req.execute());
+
+ m_hw_item.set(wait());
+
+ return (rc_t::OK);
+}
+
+std::string
+collect_detail_stats_change_cmd::to_string() const
+{
+ std::ostringstream s;
+ s << "itf-stats: " << m_hw_item.to_string() << " hdl:" << m_hdl.to_string();
+ return (s.str());
+}
+
events_cmd::events_cmd(interface::event_listener& el)
: event_cmd(el.status())
, m_listener(el)
diff --git a/src/vpp-api/vom/interface_cmds.hpp b/src/vpp-api/vom/interface_cmds.hpp
index 62762ef7c41..41ec5caf0e3 100644
--- a/src/vpp-api/vom/interface_cmds.hpp
+++ b/src/vpp-api/vom/interface_cmds.hpp
@@ -332,7 +332,7 @@ private:
};
/**
- * A command class that binds an interface to an L3 table
+ * A command class that changes the MAC address on an interface
*/
class set_mac_cmd : public rpc_cmd<HW::item<l2_address_t>,
rc_t,
@@ -368,6 +368,50 @@ private:
};
/**
+ * A command class that enables detailed stats collection on an interface
+ */
+class collect_detail_stats_change_cmd
+ : public rpc_cmd<HW::item<interface::stats_type_t>,
+ rc_t,
+ vapi::Collect_detailed_interface_stats>
+{
+public:
+ /**
+ * Constructor taking the HW::item to update
+ * and the handle of the interface
+ */
+ collect_detail_stats_change_cmd(HW::item<interface::stats_type_t>& item,
+ const handle_t& h,
+ bool enable);
+
+ /**
+ * Issue the command to VPP/HW
+ */
+ rc_t issue(connection& con);
+
+ /**
+ * convert to string format for debug purposes
+ */
+ std::string to_string() const;
+
+ /**
+ * Comparison operator - only used for UT
+ */
+ bool operator==(const collect_detail_stats_change_cmd& i) const;
+
+private:
+ /**
+ * the handle of the interface to update
+ */
+ const handle_t& m_hdl;
+
+ /**
+ * enable or disable the detailed stats collection
+ */
+ bool m_enable;
+};
+
+/**
* A command class represents our desire to recieve interface events
*/
class events_cmd
diff --git a/src/vpp-api/vom/interface_types.cpp b/src/vpp-api/vom/interface_types.cpp
index 2e7eee3ce7c..1272302d383 100644
--- a/src/vpp-api/vom/interface_types.cpp
+++ b/src/vpp-api/vom/interface_types.cpp
@@ -35,6 +35,9 @@ const interface::oper_state_t interface::oper_state_t::UP(1, "up");
const interface::admin_state_t interface::admin_state_t::DOWN(0, "down");
const interface::admin_state_t interface::admin_state_t::UP(1, "up");
+const interface::stats_type_t interface::stats_type_t::DETAILED(0, "detailed");
+const interface::stats_type_t interface::stats_type_t::NORMAL(1, "normal");
+
interface::type_t
interface::type_t::from_string(const std::string& str)
{
@@ -77,6 +80,11 @@ interface::admin_state_t::admin_state_t(int v, const std::string& s)
{
}
+interface::stats_type_t::stats_type_t(int v, const std::string& s)
+ : enum_base<interface::stats_type_t>(v, s)
+{
+}
+
interface::admin_state_t
interface::admin_state_t::from_int(uint8_t v)
{
diff --git a/src/vpp/stats/stats.c b/src/vpp/stats/stats.c
index 3fe03e4ec0f..5787b9e14e9 100644
--- a/src/vpp/stats/stats.c
+++ b/src/vpp/stats/stats.c
@@ -848,18 +848,26 @@ do_combined_per_interface_counters (stats_main_t * sm)
vp->sw_if_index = htonl (reg->item);
im = &vnet_get_main ()->interface_main;
- cm = im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_RX;
- vlib_get_combined_counter (cm, reg->item, &v);
- clib_mem_unaligned (&vp->rx_packets, u64) =
- clib_host_to_net_u64 (v.packets);
- clib_mem_unaligned (&vp->rx_bytes, u64) =
- clib_host_to_net_u64 (v.bytes);
- cm = im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_TX;
- vlib_get_combined_counter (cm, reg->item, &v);
- clib_mem_unaligned (&vp->tx_packets, u64) =
- clib_host_to_net_u64 (v.packets);
- clib_mem_unaligned (&vp->tx_bytes, u64) =
- clib_host_to_net_u64 (v.bytes);
+
+#define _(X, x) \
+ cm = im->combined_sw_if_counters + X; \
+ vlib_get_combined_counter (cm, reg->item, &v); \
+ clib_mem_unaligned (&vp->x##_packets, u64) = \
+ clib_host_to_net_u64 (v.packets); \
+ clib_mem_unaligned (&vp->x##_bytes, u64) = \
+ clib_host_to_net_u64 (v.bytes);
+
+
+ _(VNET_INTERFACE_COUNTER_RX, rx);
+ _(VNET_INTERFACE_COUNTER_TX, tx);
+ _(VNET_INTERFACE_COUNTER_RX_UNICAST, rx_unicast);
+ _(VNET_INTERFACE_COUNTER_TX_UNICAST, tx_unicast);
+ _(VNET_INTERFACE_COUNTER_RX_MULTICAST, rx_multicast);
+ _(VNET_INTERFACE_COUNTER_TX_MULTICAST, tx_multicast);
+ _(VNET_INTERFACE_COUNTER_RX_BROADCAST, rx_broadcast);
+ _(VNET_INTERFACE_COUNTER_TX_BROADCAST, tx_broadcast);
+
+#undef _
vl_api_send_msg (vl_reg, (u8 *) mp);
}