laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-hnbgw/+/36205?usp=email )
Change subject: Introduce counter for per-hnb cumulative active CS RAB duration ......................................................................
Introduce counter for per-hnb cumulative active CS RAB duration
This counter can be used to determine the traffic in Erlangs per HNB.
Change-Id: Iffb6a3f38239094551a12c872cd8474d02a5ad56 --- M include/osmocom/hnbgw/hnbgw.h M include/osmocom/hnbgw/mgw_fsm.h M src/osmo-hnbgw/hnbgw.c M src/osmo-hnbgw/mgw_fsm.c 4 files changed, 89 insertions(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-hnbgw refs/changes/05/36205/1
diff --git a/include/osmocom/hnbgw/hnbgw.h b/include/osmocom/hnbgw/hnbgw.h index 3653838..98cdc34 100644 --- a/include/osmocom/hnbgw/hnbgw.h +++ b/include/osmocom/hnbgw/hnbgw.h @@ -19,6 +19,7 @@ #include <osmocom/mgcp_client/mgcp_client_pool.h>
#define STORE_UPTIME_INTERVAL 10 /* seconds */ +#define HNB_STORE_RAB_DURATIONS_INTERVAL 1 /* seconds */
enum { DMAIN, @@ -96,6 +97,8 @@
HNB_CTR_RUA_UDT_UL, HNB_CTR_RUA_UDT_DL, + + HNB_CTR_RAB_ACTIVE_MILLISECONDS_TOTAL, };
enum hnb_stat { @@ -381,6 +384,8 @@ struct osmo_pfcp_endpoint *ep; struct osmo_pfcp_cp_peer *cp_peer; } pfcp; + + struct osmo_timer_list hnb_store_rab_durations_timer; };
extern struct hnbgw *g_hnbgw; diff --git a/include/osmocom/hnbgw/mgw_fsm.h b/include/osmocom/hnbgw/mgw_fsm.h index d4e989d..c96308d 100644 --- a/include/osmocom/hnbgw/mgw_fsm.h +++ b/include/osmocom/hnbgw/mgw_fsm.h @@ -5,3 +5,5 @@ int handle_rab_ass_req(struct hnbgw_context_map *map, struct msgb *ranap_msg, ranap_message *message); int mgw_fsm_handle_rab_ass_resp(struct hnbgw_context_map *map, struct msgb *ranap_msg, ranap_message *message); int mgw_fsm_release(struct hnbgw_context_map *map); + +uint64_t mgw_fsm_get_elapsed_ms(struct hnbgw_context_map *map, const struct timespec *now); diff --git a/src/osmo-hnbgw/hnbgw.c b/src/osmo-hnbgw/hnbgw.c index 418742e..773ac7b 100644 --- a/src/osmo-hnbgw/hnbgw.c +++ b/src/osmo-hnbgw/hnbgw.c @@ -42,6 +42,7 @@ #include <osmocom/hnbgw/hnbgw_rua.h> #include <osmocom/hnbgw/hnbgw_cn.h> #include <osmocom/hnbgw/context_map.h> +#include <osmocom/hnbgw/mgw_fsm.h>
struct hnbgw *g_hnbgw = NULL;
@@ -51,6 +52,35 @@ {} };
+/* update the active RAB duration rate_ctr for given HNB */ +static void hnb_store_rab_durations(struct hnb_context *hnb) +{ + struct hnbgw_context_map *map; + struct timespec now; + uint64_t elapsed_cs_rab_ms = 0; + + osmo_clock_gettime(CLOCK_MONOTONIC, &now); + + /* iterate over all context_maps (subscribers) */ + llist_for_each_entry(map, &hnb->map_list, hnb_list) { + elapsed_cs_rab_ms += mgw_fsm_get_elapsed_ms(map, &now); + } + + /* Export to rate countes. */ + rate_ctr_add(HNBP_CTR(hnb->persistent, HNB_CTR_RAB_ACTIVE_MILLISECONDS_TOTAL), elapsed_cs_rab_ms); +} + +static void hnbgw_store_hnb_rab_durations(void *data) +{ + struct hnb_context *hnb; + + llist_for_each_entry(hnb, &g_hnbgw->hnb_list, list) + hnb_store_rab_durations(hnb); + + /* Keep this timer ticking */ + osmo_timer_schedule(&g_hnbgw->hnb_store_rab_durations_timer, HNB_STORE_RAB_DURATIONS_INTERVAL, 0); +} +
/*********************************************************************** * UE Context @@ -358,6 +388,9 @@ "rua:unit_data:ul", "Received RUA UnitData (UDT) in uplink" }, [HNB_CTR_RUA_UDT_DL] = { "rua:unit_data:dl", "Transmitted RUA UnitData (UDT) in downlink" }, + + [HNB_CTR_RAB_ACTIVE_MILLISECONDS_TOTAL] = { + "rab:cs:active_milliseconds:total", "Cumulative number of milliseconds of CS RAB activity" }, };
const struct rate_ctr_group_desc hnb_ctrg_desc = { @@ -814,4 +847,7 @@
osmo_timer_setup(&g_hnbgw->store_uptime_timer, hnbgw_store_hnb_uptime, g_hnbgw); osmo_timer_schedule(&g_hnbgw->store_uptime_timer, STORE_UPTIME_INTERVAL, 0); + + osmo_timer_setup(&g_hnbgw->hnb_store_rab_durations_timer, hnbgw_store_hnb_rab_durations, g_hnbgw); + osmo_timer_schedule(&g_hnbgw->hnb_store_rab_durations_timer, HNB_STORE_RAB_DURATIONS_INTERVAL, 0); } diff --git a/src/osmo-hnbgw/mgw_fsm.c b/src/osmo-hnbgw/mgw_fsm.c index 6fd0e6a..864fd5d 100644 --- a/src/osmo-hnbgw/mgw_fsm.c +++ b/src/osmo-hnbgw/mgw_fsm.c @@ -1,4 +1,4 @@ -/* (C) 2021 by sysmocom s.f.m.c. GmbH info@sysmocom.de +/* (C) 2021-2024 by sysmocom s.f.m.c. GmbH info@sysmocom.de * All Rights Reserved * * Author: Philipp Maier @@ -123,6 +123,10 @@ struct osmo_sockaddr ci_hnb_crcx_ack_addr; char msc_rtp_addr[INET6_ADDRSTRLEN]; uint16_t msc_rtp_port; + + /* Timestamps to track active duration */ + struct timespec active_start; + struct timespec active_stored; };
struct osmo_tdef_state_timeout mgw_fsm_timeouts[32] = { @@ -554,6 +558,9 @@ }
LOGPFSML(fi, LOGL_DEBUG, "HNB and MSC side call-legs completed!\n"); + + osmo_clock_gettime(CLOCK_MONOTONIC, &mgw_fsm_priv->active_start); + mgw_fsm_priv->active_stored = mgw_fsm_priv->active_start; }
static void mgw_fsm_release_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state) @@ -915,3 +922,30 @@ osmo_fsm_inst_dispatch(map->mgw_fi, MGW_EV_RELEASE, NULL); return 0; } + +/* determine the number of elapsed active RAB milli-seconds since last call */ +uint64_t mgw_fsm_get_elapsed_ms(struct hnbgw_context_map *map, const struct timespec *now) +{ + struct mgw_fsm_priv *mgw_fsm_priv; + struct timespec elapsed; + uint64_t elapsed_ms; + + if (!map->mgw_fi) + return 0; + + OSMO_ASSERT(map->mgw_fi->fsm == &mgw_fsm); + mgw_fsm_priv = map->mgw_fi->priv; + + /* Ignore RABs whose activation timestamps are not yet set. */ + if (mgw_fsm_priv->active_stored.tv_sec == 0 && mgw_fsm_priv->active_stored.tv_nsec == 0) + return 0; + + /* Calculate elapsed time since last storage */ + timespecsub(now, &mgw_fsm_priv->active_stored, &elapsed); + elapsed_ms = elapsed.tv_sec * 1000 + elapsed.tv_nsec / 1000000; + + /* Update storage time */ + mgw_fsm_priv->active_stored = *now; + + return elapsed_ms; +}