pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-pcap/+/39175?usp=email )
(
2 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one. )Change subject: pcap-client: Add per iface counter group instance ......................................................................
pcap-client: Add per iface counter group instance
Change-Id: I0a35f8258eedb785ddb3311f94b42707f0045c32 --- M include/osmo-pcap/osmo_pcap_client.h M src/osmo_client_core.c M src/osmo_client_stats.c 3 files changed, 54 insertions(+), 14 deletions(-)
Approvals: laforge: Looks good to me, but someone else must approve fixeria: Looks good to me, approved Jenkins Builder: Verified
diff --git a/include/osmo-pcap/osmo_pcap_client.h b/include/osmo-pcap/osmo_pcap_client.h index 44ca54b..250a41f 100644 --- a/include/osmo-pcap/osmo_pcap_client.h +++ b/include/osmo-pcap/osmo_pcap_client.h @@ -48,6 +48,14 @@ }; extern const struct rate_ctr_group_desc pcap_client_ctr_group_desc;
+enum pcap_handle_ctr { + PH_CTR_PERR, + PH_CTR_P_RECV, + PH_CTR_P_DROP, + PH_CTR_P_IFDROP, +}; +extern const struct rate_ctr_group_desc pcap_handle_ctr_group_desc; + enum osmo_pcap_protocol { PROTOCOL_OSMOPCAP, PROTOCOL_IPIP, @@ -85,6 +93,7 @@ struct osmo_pcap_handle { struct llist_head entry; /* item in (struct osmo_pcap_client)->handles */ struct osmo_pcap_client *client; /* back pointer */ + unsigned int idx; char *devname; pcap_t *handle; struct osmo_fd fd; @@ -93,10 +102,13 @@ u_int last_ps_ifdrop; struct osmo_timer_list pcap_stat_timer; struct bpf_program bpf; + /* statistics */ + struct rate_ctr_group *ctrg; };
struct osmo_pcap_client { struct llist_head handles; /* list of struct osmo_pcap_handle */ + unsigned int next_pcap_handle_idx;
char *filter_string; int filter_itself; @@ -141,4 +153,4 @@ LOGP(DCLIENT, lvl, "CONN(%s,%s:%d) " fmt, (conn)->name, (conn)->srv_ip, (conn)->srv_port, ## args)
#define LOGPH(ph, lvl, fmt, args...) \ - LOGP(DCLIENT, lvl, "PH(%s) " fmt, (ph)->devname, ## args) + LOGP(DCLIENT, lvl, "PH(%u,%s) " fmt, (ph)->idx, (ph)->devname, ## args) diff --git a/src/osmo_client_core.c b/src/osmo_client_core.c index 7338622..a2ab894 100644 --- a/src/osmo_client_core.c +++ b/src/osmo_client_core.c @@ -163,6 +163,7 @@
data = pcap_next(ph->handle, &hdr); if (!data) { + rate_ctr_inc2(ph->ctrg, PH_CTR_PERR); rate_ctr_inc2(client->ctrg, CLIENT_CTR_PERR); return -1; } @@ -199,22 +200,13 @@ return new_val - old_val; }
-static void add_psbl_wrapped_ctr(struct osmo_pcap_client *client, - u_int *old_val, u_int new_val, int ctr) -{ - uint64_t inc; - - inc = get_psbl_wrapped_ctr(*old_val, new_val); - rate_ctr_add2(client->ctrg, ctr, inc); - *old_val = new_val; -} - static void pcap_check_stats_cb(void *_ph) { struct pcap_stat stat; struct osmo_pcap_handle *ph = _ph; struct osmo_pcap_client *client = ph->client; int rc; + uint64_t inc;
/* reschedule */ osmo_timer_schedule(&ph->pcap_stat_timer, 10, 0); @@ -223,13 +215,25 @@ rc = pcap_stats(ph->handle, &stat); if (rc != 0) { LOGPH(ph, LOGL_ERROR, "Failed to query pcap stats: %s\n", pcap_geterr(ph->handle)); + rate_ctr_inc2(ph->ctrg, PH_CTR_PERR); rate_ctr_inc2(client->ctrg, CLIENT_CTR_PERR); return; }
- add_psbl_wrapped_ctr(client, &ph->last_ps_recv, stat.ps_recv, CLIENT_CTR_P_RECV); - add_psbl_wrapped_ctr(client, &ph->last_ps_drop, stat.ps_drop, CLIENT_CTR_P_DROP); - add_psbl_wrapped_ctr(client, &ph->last_ps_ifdrop, stat.ps_ifdrop, CLIENT_CTR_P_IFDROP); + inc = get_psbl_wrapped_ctr(ph->last_ps_recv, stat.ps_recv); + rate_ctr_add2(ph->ctrg, PH_CTR_P_RECV, inc); + rate_ctr_add2(client->ctrg, CLIENT_CTR_P_RECV, inc); + ph->last_ps_recv = stat.ps_recv; + + inc = get_psbl_wrapped_ctr(ph->last_ps_drop, stat.ps_drop); + rate_ctr_add2(ph->ctrg, PH_CTR_P_DROP, inc); + rate_ctr_add2(client->ctrg, CLIENT_CTR_P_DROP, inc); + ph->last_ps_drop = stat.ps_drop; + + inc = get_psbl_wrapped_ctr(ph->last_ps_ifdrop, stat.ps_ifdrop); + rate_ctr_add2(ph->ctrg, PH_CTR_P_IFDROP, inc); + rate_ctr_add2(client->ctrg, CLIENT_CTR_P_IFDROP, inc); + ph->last_ps_ifdrop = stat.ps_ifdrop; }
static int osmo_pcap_handle_install_filter(struct osmo_pcap_handle *ph) @@ -390,8 +394,14 @@ OSMO_ASSERT(ph->devname);
ph->client = client; + ph->idx = client->next_pcap_handle_idx++; ph->fd.fd = -1;
+ /* initialize the stats interface */ + ph->ctrg = rate_ctr_group_alloc(ph, &pcap_handle_ctr_group_desc, ph->idx); + OSMO_ASSERT(ph->ctrg); + rate_ctr_group_set_name(ph->ctrg, ph->devname); + llist_add_tail(&ph->entry, &client->handles); return ph; } @@ -416,6 +426,9 @@ ph->handle = NULL; }
+ rate_ctr_group_free(ph->ctrg); + ph->ctrg = NULL; + talloc_free(ph); }
diff --git a/src/osmo_client_stats.c b/src/osmo_client_stats.c index 07ff4a1..9522e7b 100644 --- a/src/osmo_client_stats.c +++ b/src/osmo_client_stats.c @@ -31,6 +31,21 @@
#include "osmopcapconfig.h"
+static const struct rate_ctr_desc pcap_client_handle_ctr_desc[] = { + [PH_CTR_PERR] = { "pcap:err", "libpcap error " }, + [PH_CTR_P_RECV] = { "pcap:recv", "PCAP received packets " }, + [PH_CTR_P_DROP] = { "pcap:drop", "PCAP dropped packets " }, + [PH_CTR_P_IFDROP] = { "pcap:ifdrop", "iface dropped packets " }, +}; + +const struct rate_ctr_group_desc pcap_handle_ctr_group_desc = { + .group_name_prefix = "pcap:client:handle", + .group_description = "PCAP Client Handle statistics", + .num_ctr = ARRAY_SIZE(pcap_client_handle_ctr_desc), + .ctr_desc = pcap_client_handle_ctr_desc, + .class_id = OSMO_STATS_CLASS_PEER, +}; + static const struct rate_ctr_desc pcap_client_ctr_desc[] = { [CLIENT_CTR_CONNECT] = { "server:connect", "Connects to the server" }, [CLIENT_CTR_BYTES] = { "captured:bytes", "Captured bytes " },