From 532968d766549fc05916c38a08e11fd7f241181f Mon Sep 17 00:00:00 2001 From: Neels Janosch Hofmeyr Date: Mon, 8 Apr 2024 02:34:57 +0200 Subject: [PATCH] nft_kpi: add rate_ctr gtpu:ue_bytes:ul,dl So far we have the nftables based counters for total GTP-U bytes (UL, DL), as well as a packet count. Add another counter for the computed UE payload bytes: total_bytes - packets * (20 + 8 + 8) Related: SYS#6773 Change-Id: Ib2f0a9252715ea4b2fe9c367aa65f771357768ca --- include/osmocom/hnbgw/hnbgw.h | 2 ++ include/osmocom/hnbgw/nft_kpi.h | 3 ++- src/osmo-hnbgw/hnbgw.c | 8 ++++++++ src/osmo-hnbgw/nft_kpi.c | 16 +++++++++++++++- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/include/osmocom/hnbgw/hnbgw.h b/include/osmocom/hnbgw/hnbgw.h index d323bdf..c9142e9 100644 --- a/include/osmocom/hnbgw/hnbgw.h +++ b/include/osmocom/hnbgw/hnbgw.h @@ -139,8 +139,10 @@ enum hnb_rate_ctr { HNB_CTR_GTPU_PACKETS_UL, HNB_CTR_GTPU_TOTAL_BYTES_UL, + HNB_CTR_GTPU_UE_BYTES_UL, HNB_CTR_GTPU_PACKETS_DL, HNB_CTR_GTPU_TOTAL_BYTES_DL, + HNB_CTR_GTPU_UE_BYTES_DL, }; enum hnb_stat { diff --git a/include/osmocom/hnbgw/nft_kpi.h b/include/osmocom/hnbgw/nft_kpi.h index 95304ce..7b3153d 100644 --- a/include/osmocom/hnbgw/nft_kpi.h +++ b/include/osmocom/hnbgw/nft_kpi.h @@ -6,7 +6,8 @@ struct hnb_persistent; struct nft_kpi_val { uint64_t packets; - uint64_t bytes; + uint64_t total_bytes; + uint64_t ue_bytes; bool handle_present; int64_t handle; diff --git a/src/osmo-hnbgw/hnbgw.c b/src/osmo-hnbgw/hnbgw.c index a3ea265..6340d10 100644 --- a/src/osmo-hnbgw/hnbgw.c +++ b/src/osmo-hnbgw/hnbgw.c @@ -468,6 +468,10 @@ const struct rate_ctr_desc hnb_ctr_description[] = { "gtpu:total_bytes:ul", "Count of total GTP-U bytes received from the HNB, including the GTP-U/UDP/IP headers", }, + [HNB_CTR_GTPU_UE_BYTES_UL] = { + "gtpu:ue_bytes:ul", + "Assuming an IP header length of 20 bytes, GTP-U bytes received from the HNB, excluding the GTP-U/UDP/IP headers", + }, [HNB_CTR_GTPU_PACKETS_DL] = { "gtpu:packets:dl", "Count of GTP-U packets sent to the HNB", @@ -476,6 +480,10 @@ const struct rate_ctr_desc hnb_ctr_description[] = { "gtpu:total_bytes:dl", "Count of total GTP-U bytes sent to the HNB, including the GTP-U/UDP/IP headers", }, + [HNB_CTR_GTPU_UE_BYTES_DL] = { + "gtpu:ue_bytes:dl", + "Assuming an IP header length of 20 bytes, GTP-U bytes sent to the HNB, excluding the GTP-U/UDP/IP headers", + }, }; diff --git a/src/osmo-hnbgw/nft_kpi.c b/src/osmo-hnbgw/nft_kpi.c index 2eb5496..4a9dc34 100644 --- a/src/osmo-hnbgw/nft_kpi.c +++ b/src/osmo-hnbgw/nft_kpi.c @@ -268,7 +268,21 @@ static void hnb_update_counters(struct hnb_persistent *hnbp, bool ul, int64_t pa &val->packets, packets); update_ctr(hnbp->ctrs, ul ? HNB_CTR_GTPU_TOTAL_BYTES_UL : HNB_CTR_GTPU_TOTAL_BYTES_DL, - &val->bytes, bytes); + &val->total_bytes, bytes); + + /* Assuming an IP header of 20 bytes, derive the GTP-U payload size: + * + * [...] \ \ + * [ UDP ][ TCP ] | UE payload | nft reports these bytes + * [ IP ] / | + * -- payload -- | + * [ GTP-U 8 bytes ] | \ + * [ UDP 8 bytes ] | | need to subtract these, ~20 + 8 + 8 + * [ IP 20 bytes ] / / + */ + update_ctr(hnbp->ctrs, + ul ? HNB_CTR_GTPU_UE_BYTES_UL : HNB_CTR_GTPU_UE_BYTES_DL, + &val->ue_bytes, bytes - OSMO_MIN(bytes, packets * (20 + 8 + 8))); } /* In the string section *pos .. end, find the first occurrence of after_str and return the following token, which ends