-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathcp_stats.c
171 lines (151 loc) · 4.22 KB
/
cp_stats.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
/* SPDX-License-Identifier: Apache-2.0
* Copyright(c) 2017 Intel Corporation
*/
#include <stdio.h>
#include <inttypes.h>
#include <unistd.h>
#include <string.h>
#ifdef SDN_ODL_BUILD
#include "nb.h"
#endif
#include "cp_stats.h"
struct cp_stats_t cp_stats;
/**
* @brief callback used to display rx packets per second
* @return number of packets received by the control plane s11 interface
*/
static uint64_t
rx_pkts_per_sec(void)
{
uint64_t ret = cp_stats.rx - cp_stats.rx_last;
cp_stats.rx_last = cp_stats.rx;
return ret;
}
/**
* @brief callback used to display tx packets per second
* @return number of packets transmitted by the control plane s11 interface
*/
static uint64_t
tx_pkts_per_sec(void)
{
uint64_t ret = cp_stats.tx - cp_stats.tx_last;
cp_stats.tx_last = cp_stats.tx;
return ret;
}
/**
* @brief callback used to display control plane uptime
* @return control plane uptime in seconds
*/
static uint64_t
stats_time(void)
{
uint64_t ret = cp_stats.time;
cp_stats.time++;
return ret;
}
#ifdef SDN_ODL_BUILD
static uint64_t
nb_ok_delta(void)
{
uint64_t nb_ok = cp_stats.nb_ok;
uint64_t nb_sent = cp_stats.nb_sent;
return (nb_ok < nb_sent ? nb_sent - nb_ok : 0);
}
static uint64_t
nb_cnr_delta(void)
{
uint64_t nb_cnr = cp_stats.nb_cnr;
uint64_t nb_sent = cp_stats.nb_sent;
return (nb_cnr < nb_sent ? nb_sent - nb_cnr : 0);
}
#endif
/**
* @brief statistics entry
* used to simplify statistics by providing a common interface for statistic
* values or calculations and their names
*/
struct stat_entry_t {
enum {VALUE, LAMBDA} type;
uint8_t spacing; /** variable length stat entry specifier */
union {
uint64_t *value; /** value used by stat */
uint64_t (*lambda)(void); /** stat callback function */
};
const char *top; /** top collumn stat name string */
const char *bottom; /** bottom collumn stat name string */
};
#define DEFINE_VALUE_STAT(spacing, function, top, bottom) \
{VALUE, spacing, {.value = function}, top, bottom}
#define DEFINE_LAMBDA_STAT(spacing, function, top, bottom) \
{LAMBDA, spacing, {.lambda = function}, top, bottom}
#define PRINT_STAT_ENTRY_HEADER(entry_index, header) \
printf("%*s ",\
stat_entries[entry_index].spacing, \
stat_entries[entry_index].header)
/**
* statistic entry definitions
*/
struct stat_entry_t stat_entries[] = {
DEFINE_LAMBDA_STAT(5, stats_time, "", "time"),
DEFINE_VALUE_STAT(8, &cp_stats.rx, "rx", "pkts"),
DEFINE_VALUE_STAT(8, &cp_stats.tx, "tx", "pkts"),
DEFINE_LAMBDA_STAT(8, rx_pkts_per_sec, "rx pkts", "/sec"),
DEFINE_LAMBDA_STAT(8, tx_pkts_per_sec, "tx pkts", "/sec"),
DEFINE_VALUE_STAT(8, &cp_stats.create_session, "create", "session"),
DEFINE_VALUE_STAT(8, &cp_stats.modify_bearer, "modify", "bearer"),
DEFINE_VALUE_STAT(8, &cp_stats.bearer_resource, "b resrc", "cmd"),
DEFINE_VALUE_STAT(8, &cp_stats.create_bearer, "create", "bearer"),
DEFINE_VALUE_STAT(8, &cp_stats.delete_bearer, "delete", "bearer"),
DEFINE_VALUE_STAT(8, &cp_stats.delete_session, "delete", "session"),
DEFINE_VALUE_STAT(8, &cp_stats.echo, "", "echo"),
DEFINE_VALUE_STAT(8, &cp_stats.rel_access_bearer, "rel acc", "bearer"),
DEFINE_VALUE_STAT(8, &cp_stats.ddn, "", "ddn"),
DEFINE_VALUE_STAT(8, &cp_stats.ddn_ack, "ddn", "ack"),
#ifdef SDN_ODL_BUILD
DEFINE_VALUE_STAT(8, &cp_stats.nb_sent, "nb", "sent"),
DEFINE_LAMBDA_STAT(8, nb_ok_delta, "nb ok", "delta"),
DEFINE_LAMBDA_STAT(8, nb_cnr_delta, "nb cnr", "delta"),
#endif
};
/**
* @brief prints out statistics entries
*/
static inline void
print_stat_entries(void) {
unsigned i;
if (!(cp_stats.time % 32)) {
puts("");
for (i = 0; i < RTE_DIM(stat_entries); ++i)
PRINT_STAT_ENTRY_HEADER(i, top);
puts("");
for (i = 0; i < RTE_DIM(stat_entries); ++i)
PRINT_STAT_ENTRY_HEADER(i, bottom);
puts("");
}
for (i = 0; i < RTE_DIM(stat_entries); ++i) {
printf("%*"PRIu64" ", stat_entries[i].spacing,
(stat_entries[i].type == VALUE) ?
*stat_entries[i].value :
(*stat_entries[i].lambda)());
}
puts("");
}
int
do_stats(__rte_unused void *ptr)
{
while (1) {
#ifdef SDN_ODL_BUILD
/* Only print stats when dpn_id is set to display CP is ready
* to handle signaling
*/
if (dpn_id)
#endif
print_stat_entries();
sleep(1);
}
return 0;
}
void
reset_cp_stats(void) {
memset(&cp_stats, 0, sizeof(cp_stats));
}