/
dropstats.c
268 lines (234 loc) · 8.38 KB
/
dropstats.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/*
* dropstats.c - drop statistics
*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <inttypes.h>
#include <stdlib.h>
#include <stdbool.h>
#include <getopt.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#include "ini_parser.h"
#include "vr_os.h"
#include "vr_types.h"
#include "vr_nexthop.h"
#include "ini_parser.h"
#include "nl_util.h"
#include "ini_parser.h"
static struct nl_client *cl;
static int help_set, core_set;
static unsigned int core = (unsigned)-1;
void
vr_drop_stats_req_process(void *s_req)
{
vr_drop_stats_req *stats = (vr_drop_stats_req *)s_req;
int platform = get_platform();
if (core != (unsigned)-1)
printf("Statistics for core %u\n\n", core);
printf("GARP %" PRIu64 "\n",
stats->vds_garp_from_vm);
printf("ARP no where to go %" PRIu64 "\n",
stats->vds_arp_no_where_to_go);
printf("Invalid ARPs %" PRIu64 "\n",
stats->vds_invalid_arp);
printf("\n");
printf("Invalid IF %" PRIu64 "\n",
stats->vds_invalid_if);
printf("Trap No IF %" PRIu64 "\n",
stats->vds_trap_no_if);
printf("IF TX Discard %" PRIu64 "\n",
stats->vds_interface_tx_discard);
printf("IF Drop %" PRIu64 "\n",
stats->vds_interface_drop);
printf("IF RX Discard %" PRIu64 "\n",
stats->vds_interface_rx_discard);
printf("\n");
printf("Flow Unusable %" PRIu64 "\n",
stats->vds_flow_unusable);
printf("Flow No Memory %" PRIu64 "\n",
stats->vds_flow_no_memory);
printf("Flow Table Full %" PRIu64 "\n",
stats->vds_flow_table_full);
printf("Flow NAT no rflow %" PRIu64 "\n",
stats->vds_flow_nat_no_rflow);
printf("Flow Action Drop %" PRIu64 "\n",
stats->vds_flow_action_drop);
printf("Flow Action Invalid %" PRIu64 "\n",
stats->vds_flow_action_invalid);
printf("Flow Invalid Protocol %" PRIu64 "\n",
stats->vds_flow_invalid_protocol);
printf("Flow Queue Limit Exceeded %" PRIu64 "\n",
stats->vds_flow_queue_limit_exceeded);
printf("Flow Unusable (Eviction) %" PRIu64 "\n",
stats->vds_flow_evict);
printf("\n");
printf("Original Packet Trapped %" PRIu64 "\n",
stats->vds_trap_original);
printf("\n");
printf("Discards %" PRIu64 "\n",
stats->vds_discard);
printf("TTL Exceeded %" PRIu64 "\n",
stats->vds_ttl_exceeded);
printf("Mcast Clone Fail %" PRIu64 "\n",
stats->vds_mcast_clone_fail);
printf("Cloned Original %" PRIu64 "\n",
stats->vds_cloned_original);
printf("\n");
printf("Invalid NH %" PRIu64 "\n",
stats->vds_invalid_nh);
printf("Invalid Label %" PRIu64 "\n",
stats->vds_invalid_label);
printf("Invalid Protocol %" PRIu64 "\n",
stats->vds_invalid_protocol);
printf("Rewrite Fail %" PRIu64 "\n",
stats->vds_rewrite_fail);
printf("Invalid Mcast Source %" PRIu64 "\n",
stats->vds_invalid_mcast_source);
printf("\n");
printf("Push Fails %" PRIu64 "\n",
stats->vds_push);
printf("Pull Fails %" PRIu64 "\n",
stats->vds_pull);
printf("Duplicated %" PRIu64 "\n",
stats->vds_duplicated);
printf("Head Alloc Fails %" PRIu64 "\n",
stats->vds_head_alloc_fail);
printf("Head Space Reserve Fails %" PRIu64 "\n",
stats->vds_head_space_reserve_fail);
printf("PCOW fails %" PRIu64 "\n",
stats->vds_pcow_fail);
printf("Invalid Packets %" PRIu64 "\n",
stats->vds_invalid_packet);
printf("\n");
printf("Misc %" PRIu64 "\n",
stats->vds_misc);
printf("Nowhere to go %" PRIu64 "\n",
stats->vds_nowhere_to_go);
printf("Checksum errors %" PRIu64 "\n",
stats->vds_cksum_err);
printf("No Fmd %" PRIu64 "\n",
stats->vds_no_fmd);
printf("Invalid VNID %" PRIu64 "\n",
stats->vds_invalid_vnid);
printf("Fragment errors %" PRIu64 "\n",
stats->vds_frag_err);
printf("Invalid Source %" PRIu64 "\n",
stats->vds_invalid_source);
printf("Jumbo Mcast Pkt with DF Bit %" PRIu64 "\n",
stats->vds_mcast_df_bit);
printf("ARP No Route %" PRIu64 "\n",
stats->vds_arp_no_route);
printf("No L2 Route %" PRIu64 "\n",
stats->vds_l2_no_route);
printf("Memory Failures %" PRIu64 "\n",
stats->vds_no_memory);
printf("Fragment Queueing Failures %" PRIu64 "\n",
stats->vds_fragment_queue_fail);
printf("\n");
if (platform == DPDK_PLATFORM) {
printf("VLAN fwd intf failed TX %" PRIu64 "\n",
stats->vds_vlan_fwd_tx);
printf("VLAN fwd intf failed enq %" PRIu64 "\n",
stats->vds_vlan_fwd_enq);
}
return;
}
static int
vr_get_drop_stats(struct nl_client *cl)
{
int ret;
/*
* Implementation of getting per-core drop statistics is based on this
* little trick to avoid making changes in how agent makes requests for
* statistics. From vRouter's and agent's point of view, request for
* stats for 0th core means a request for stats summed up for all the
* cores. So cores are enumerated starting with 1.
* Meanwhile, from user's point of view they are enumerated starting
* with 0 (e.g. dropstats --core 0 means 'drop statistics for the very
* first (0th) core'). This is how Linux enumerates CPUs, so it should
* be more intuitive for the user.
*
* Agent is not aware of possibility of asking for per-core stats. Its
* requests have vds_core implicitly set to 0. So we need to make a
* conversion between those enumerating systems. The dropstats utility
* increments by 1 the core number user asked for. Then it is
* decremented back in vRouter.
*/
ret = vr_send_drop_stats_get(cl, 0, core + 1);
if (ret < 0)
return ret;
ret = vr_recvmsg(cl, false);
if (ret <= 0)
return ret;
return 0;
}
enum opt_index {
HELP_OPT_INDEX,
CORE_OPT_INDEX,
MAX_OPT_INDEX,
};
static struct option long_options[] = {
[HELP_OPT_INDEX] = {"help", no_argument, &help_set, 1},
[CORE_OPT_INDEX] = {"core", required_argument, &core_set, 1},
[MAX_OPT_INDEX] = {NULL, 0, 0, 0},
};
static void
Usage()
{
printf("Usage: dropstats [--help]\n");
printf("Usage: dropstats [--core|-c] <core number>\n\n");
printf("--core <core number>\t Show statistics for a specified CPU core\n");
exit(-EINVAL);
}
static void
parse_long_opts(int opt_index, char *opt_arg)
{
errno = 0;
switch (opt_index) {
case CORE_OPT_INDEX:
core = (unsigned)strtol(opt_arg, NULL, 0);
if (errno) {
printf("Error parsing core %s: %s (%d)\n", opt_arg,
strerror(errno), errno);
Usage();
}
break;
case HELP_OPT_INDEX:
default:
Usage();
}
return;
}
int
main(int argc, char *argv[])
{
char opt;
int ret, option_index;
while (((opt = getopt_long(argc, argv, "h:c:",
long_options, &option_index)) >= 0)) {
switch (opt) {
case 'c':
core_set = 1;
parse_long_opts(CORE_OPT_INDEX, optarg);
break;
case 0:
parse_long_opts(option_index, optarg);
break;
case 'h':
default:
Usage();
}
}
cl = vr_get_nl_client(VR_NETLINK_PROTO_DEFAULT);
if (!cl)
return -1;
vr_get_drop_stats(cl);
return 0;
}