FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
interface_stats.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <vlib/vlib.h>
17 #include <vnet/vnet.h>
18 #include <vppinfra/error.h>
19 
20 #include <vnet/feature/feature.h>
21 #include <vnet/ethernet/ethernet.h>
22 
23 #ifndef CLIB_MARCH_VARIANT
24 int
26 {
29  ethernet_main_t *em;
30  vnet_main_t *vnm;
31 
32  vnm = vnet_get_main ();
33  em = &ethernet_main;
35 
36  /*
37  * only ethernet HW interfaces are supported at this time
38  */
40  {
41  return (VNET_API_ERROR_INVALID_VALUE);
42  }
43 
45 
46  if (!eif)
47  {
48  return (VNET_API_ERROR_FEATURE_DISABLED);
49  }
50 
51  vnet_feature_enable_disable ("device-input", "stats-collect-rx",
52  sw_if_index, enable, 0, 0);
53  vnet_feature_enable_disable ("interface-output", "stats-collect-tx",
54  sw_if_index, enable, 0, 0);
55 
56  return (0);
57 }
58 #endif /* CLIB_MARCH_VARIANT */
59 
60 static u8 *
61 format_stats_collect_trace (u8 * s, va_list * args)
62 {
63  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
64  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
65 
66  return s;
67 }
68 
69 #define inc_counter(ctype, rx_tx) \
70 { \
71 }
72 
77 {
79  u32 n_left_from, *from, *to_next;
81  u32 sw_if_index = 0;
82  u32 stats_n_packets[VNET_N_COMBINED_INTERFACE_COUNTER] = { 0 };
83  u64 stats_n_bytes[VNET_N_COMBINED_INTERFACE_COUNTER] = { 0 };
84 
86  n_left_from = frame->n_vectors;
87  next_index = node->cached_next_index;
88 
89  while (n_left_from > 0)
90  {
91  u32 n_left_to_next;
92 
93  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
94 
95  while (n_left_from > 0 && n_left_to_next > 0)
96  {
97  u32 bi0;
98  vlib_buffer_t *b0;
99  u32 next0 = 0;
100  int b0_ctype;
101 
102  /* speculatively enqueue b0 to the current next frame */
103  to_next[0] = bi0 = from[0];
104  to_next += 1;
105  n_left_to_next -= 1;
106  from += 1;
107  n_left_from -= 1;
108 
109  b0 = vlib_get_buffer (vm, bi0);
110  sw_if_index = vnet_buffer (b0)->sw_if_index[rxtx];
111 
112  if (VLIB_RX == rxtx)
113  {
114  b0_ctype =
116  }
117  else
118  {
119  b0_ctype =
121  }
122 
123  stats_n_bytes[b0_ctype] += vlib_buffer_length_in_chain (vm, b0);
124  stats_n_packets[b0_ctype] += 1;
125 
126  vnet_feature_next (&next0, b0);
127 
129  n_left_to_next, bi0, next0);
130  }
131 
132  if (VLIB_RX == rxtx)
133  {
135  {
139  sw_if_index, stats_n_packets[ct], stats_n_bytes[ct]);
140  }
141  }
142  else
143  {
145  {
149  sw_if_index, stats_n_packets[ct], stats_n_bytes[ct]);
150  }
151  }
152 
153  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
154  }
155 
156  return frame->n_vectors;
157 }
158 
162 {
164 }
165 
169 {
171 }
172 
173 /* *INDENT-OFF* */
175  .vector_size = sizeof (u32),
176  .format_trace = format_stats_collect_trace,
178  .n_errors = 0,
179  .n_next_nodes = 0,
180  .name = "stats-collect-rx",
181 };
182 
184  .vector_size = sizeof (u32),
185  .format_trace = format_stats_collect_trace,
187  .n_errors = 0,
188  .n_next_nodes = 0,
189  .name = "stats-collect-tx",
190 };
191 
193  .arc_name = "device-input",
194  .node_name = "stats-collect-rx",
195  .runs_before = VNET_FEATURES ("ethernet-input"),
196 };
197 
199  .arc_name = "interface-output",
200  .node_name = "stats-collect-tx",
201  .runs_before = VNET_FEATURES ("interface-output-arc-end"),
202 };
203 
204 /* *INDENT-ON* */
205 
206 static clib_error_t *
208 {
209  return 0;
210 }
211 
213 
214 
215 /*
216  * fd.io coding-style-patch-verification: ON
217  *
218  * Local Variables:
219  * eval: (c-set-style "gnu")
220  * End:
221  */
vlib.h
vnet_sw_interface_t::type
vnet_sw_interface_type_t type
Definition: interface.h:871
vnet_sw_interface_t
Definition: interface.h:869
frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: nat44_ei.c:3048
next_index
nat44_ei_hairpin_src_next_t next_index
Definition: nat44_ei_hairpinning.c:412
vlib_get_buffer
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:111
name
string name[64]
Definition: fib.api:25
VLIB_NODE_TYPE_INTERNAL
@ VLIB_NODE_TYPE_INTERNAL
Definition: node.h:72
eh_dst_addr_to_rx_ctype
static int eh_dst_addr_to_rx_ctype(const ethernet_header_t *eh)
Definition: packet.h:92
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
VLIB_RX
@ VLIB_RX
Definition: defs.h:46
vnet_get_sw_interface
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface_funcs.h:58
stats_collect_rx_node
vlib_node_registration_t stats_collect_rx_node
(constructor) VLIB_REGISTER_NODE (stats_collect_rx_node)
Definition: interface_stats.c:174
vlib_frame_t
Definition: node.h:372
vlib_buffer_length_in_chain
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
Definition: buffer_funcs.h:433
ethernet.h
vnet_interface_counter_type_t
vnet_interface_counter_type_t
Definition: interface.h:901
foreach_tx_combined_interface_counter
#define foreach_tx_combined_interface_counter(_x)
Definition: interface.h:931
error.h
VLIB_NODE_FN
#define VLIB_NODE_FN(node)
Definition: node.h:202
feature.h
ethernet_main_t_
Definition: ethernet.h:288
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:441
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
format_stats_collect_trace
static u8 * format_stats_collect_trace(u8 *s, va_list *args)
Definition: interface_stats.c:61
vlib_get_thread_index
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:187
vnet_feature_next
static_always_inline void vnet_feature_next(u32 *next0, vlib_buffer_t *b0)
Definition: feature.h:322
vlib_frame_vector_args
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:301
static_always_inline
#define static_always_inline
Definition: clib.h:112
uword
u64 uword
Definition: types.h:112
vlib_rx_or_tx_t
vlib_rx_or_tx_t
Definition: defs.h:44
ethernet_interface
Definition: ethernet.h:146
foreach_rx_combined_interface_counter
#define foreach_rx_combined_interface_counter(_x)
Definition: interface.h:926
stats_collect_inline
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)
Definition: interface_stats.c:74
stats_collect_tx_node
vlib_node_registration_t stats_collect_tx_node
(constructor) VLIB_REGISTER_NODE (stats_collect_tx_node)
Definition: interface_stats.c:183
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
vnet_interface_main_t::combined_sw_if_counters
vlib_combined_counter_main_t * combined_sw_if_counters
Definition: interface.h:1024
vnet_sw_interface_stats_collect_enable_disable
int vnet_sw_interface_stats_collect_enable_disable(u32 sw_if_index, u8 enable)
Definition: interface_stats.c:25
ethernet_get_interface
ethernet_interface_t * ethernet_get_interface(ethernet_main_t *em, u32 hw_if_index)
Definition: interface.c:982
vnet_main_t
Definition: vnet.h:76
vlib_validate_buffer_enqueue_x1
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:224
ethernet_main
ethernet_main_t ethernet_main
Definition: init.c:45
u64
unsigned long u64
Definition: types.h:89
vlib_put_next_frame
vlib_put_next_frame(vm, node, next_index, 0)
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
si
vnet_sw_interface_t * si
Definition: interface_output.c:418
vnet_feature_enable_disable
int vnet_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
Definition: pnat_test_stubs.h:50
stats_collect_init
static clib_error_t * stats_collect_init(vlib_main_t *vm)
Definition: interface_stats.c:207
vnet_main
vnet_main_t vnet_main
Definition: misc.c:43
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
eh_dst_addr_to_tx_ctype
static int eh_dst_addr_to_tx_ctype(const ethernet_header_t *eh)
Definition: packet.h:110
VNET_FEATURES
#define VNET_FEATURES(...)
Definition: feature.h:470
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
vlib_buffer_get_current
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:257
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
vnet_sw_interface_t::hw_if_index
u32 hw_if_index
Definition: interface.h:887
VNET_N_COMBINED_INTERFACE_COUNTER
@ VNET_N_COMBINED_INTERFACE_COUNTER
Definition: interface.h:923
vnet.h
VNET_FEATURE_INIT
VNET_FEATURE_INIT(stats_collect_rx_node, static)
VNET_SW_INTERFACE_TYPE_HARDWARE
@ VNET_SW_INTERFACE_TYPE_HARDWARE
Definition: interface.h:764
vlib_node_runtime_t
Definition: node.h:454
from
from
Definition: nat44_ei_hairpinning.c:415
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
vlib_get_next_frame
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
Definition: node_funcs.h:395
VLIB_TX
@ VLIB_TX
Definition: defs.h:47
n_left_from
n_left_from
Definition: nat44_ei_hairpinning.c:416
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
vnet_main_t::interface_main
vnet_interface_main_t interface_main
Definition: vnet.h:81
vlib_increment_combined_counter
vlib_increment_combined_counter(ccm, ti, sw_if_index, n_buffers, n_bytes)
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169