[M] Change in osmo-hnbgw[master]: Introduce counter for per-hnb cumulative active CS RAB duration

2024-03-13 Thread laforge
laforge has submitted this change. ( 
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, 95 insertions(+), 1 deletion(-)

Approvals:
  laforge: Looks good to me, approved
  osmith: Looks good to me, but someone else must approve
  Jenkins Builder: Verified
  pespin: Looks good to me, but someone else must approve




diff --git a/include/osmocom/hnbgw/hnbgw.h b/include/osmocom/hnbgw/hnbgw.h
index 23c1239..f2982de 100644
--- a/include/osmocom/hnbgw/hnbgw.h
+++ b/include/osmocom/hnbgw/hnbgw.h
@@ -19,6 +19,7 @@
 #include 

 #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 {
@@ -385,6 +388,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 2c919e5..d662fcc 100644
--- a/include/osmocom/hnbgw/mgw_fsm.h
+++ b/include/osmocom/hnbgw/mgw_fsm.h
@@ -5,3 +5,5 @@
 int handle_cs_rab_ass_req(struct hnbgw_context_map *map, struct msgb 
*ranap_msg, ranap_message *message);
 int mgw_fsm_handle_cs_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 c2d86e8..055b438 100644
--- a/src/osmo-hnbgw/hnbgw.c
+++ b/src/osmo-hnbgw/hnbgw.c
@@ -42,6 +42,7 @@
 #include 
 #include 
 #include 
+#include 

 struct hnbgw *g_hnbgw = NULL;

@@ -51,6 +52,41 @@
{}
 };

+/* 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, );
+
+   /* iterate over all context_maps (subscribers) */
+   llist_for_each_entry(map, >map_list, hnb_list) {
+   /* skip any PS maps, we care about CS RABs only here */
+   if (map->is_ps)
+   continue;
+   elapsed_cs_rab_ms += mgw_fsm_get_elapsed_ms(map, );
+   }
+
+   /* 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, _hnbgw->hnb_list, list) {
+   if (!hnb->persistent)
+   continue;
+   hnb_store_rab_durations(hnb);
+   }
+
+   /* Keep this timer ticking */
+   osmo_timer_schedule(_hnbgw->hnb_store_rab_durations_timer, 
HNB_STORE_RAB_DURATIONS_INTERVAL, 0);
+}
+

 /***
  * UE Context
@@ -358,6 +394,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 = {
@@ -821,4 +860,7 @@

osmo_timer_setup(_hnbgw->store_uptime_timer, hnbgw_store_hnb_uptime, 
g_hnbgw);
osmo_timer_schedule(_hnbgw->store_uptime_timer, 
STORE_UPTIME_INTERVAL, 0);
+
+   osmo_timer_setup(_hnbgw->hnb_store_rab_durations_timer, 
hnbgw_store_hnb_rab_durations, g_hnbgw);
+   osmo_timer_schedule(_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 d405d85..6d23790 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 
+/* (C) 2021-2024 by sysmocom s.f.m.c. GmbH 
  * 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;
+
+   /* 

[M] Change in osmo-hnbgw[master]: Introduce counter for per-hnb cumulative active CS RAB duration

2024-03-13 Thread laforge
laforge has posted comments on this change. ( 
https://gerrit.osmocom.org/c/osmo-hnbgw/+/36205?usp=email )

Change subject: Introduce counter for per-hnb cumulative active CS RAB duration
..


Patch Set 5: Code-Review+2


--
To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/36205?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-hnbgw
Gerrit-Branch: master
Gerrit-Change-Id: Iffb6a3f38239094551a12c872cd8474d02a5ad56
Gerrit-Change-Number: 36205
Gerrit-PatchSet: 5
Gerrit-Owner: laforge 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge 
Gerrit-Reviewer: osmith 
Gerrit-Reviewer: pespin 
Gerrit-Comment-Date: Wed, 13 Mar 2024 13:08:55 +
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


[M] Change in osmo-hnbgw[master]: Introduce counter for per-hnb cumulative active CS RAB duration

2024-03-13 Thread pespin
Attention is currently required from: laforge.

pespin has posted comments on this change. ( 
https://gerrit.osmocom.org/c/osmo-hnbgw/+/36205?usp=email )

Change subject: Introduce counter for per-hnb cumulative active CS RAB duration
..


Patch Set 5: Code-Review+1


--
To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/36205?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-hnbgw
Gerrit-Branch: master
Gerrit-Change-Id: Iffb6a3f38239094551a12c872cd8474d02a5ad56
Gerrit-Change-Number: 36205
Gerrit-PatchSet: 5
Gerrit-Owner: laforge 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: osmith 
Gerrit-Reviewer: pespin 
Gerrit-Attention: laforge 
Gerrit-Comment-Date: Wed, 13 Mar 2024 12:04:24 +
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


[M] Change in osmo-hnbgw[master]: Introduce counter for per-hnb cumulative active CS RAB duration

2024-03-13 Thread osmith
Attention is currently required from: laforge, pespin.

osmith has posted comments on this change. ( 
https://gerrit.osmocom.org/c/osmo-hnbgw/+/36205?usp=email )

Change subject: Introduce counter for per-hnb cumulative active CS RAB duration
..


Patch Set 5: Code-Review+1


--
To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/36205?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-hnbgw
Gerrit-Branch: master
Gerrit-Change-Id: Iffb6a3f38239094551a12c872cd8474d02a5ad56
Gerrit-Change-Number: 36205
Gerrit-PatchSet: 5
Gerrit-Owner: laforge 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: osmith 
Gerrit-Reviewer: pespin 
Gerrit-Attention: laforge 
Gerrit-Attention: pespin 
Gerrit-Comment-Date: Wed, 13 Mar 2024 11:09:55 +
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


[M] Change in osmo-hnbgw[master]: Introduce counter for per-hnb cumulative active CS RAB duration

2024-03-12 Thread laforge
Attention is currently required from: pespin.

laforge has posted comments on this change. ( 
https://gerrit.osmocom.org/c/osmo-hnbgw/+/36205?usp=email )

Change subject: Introduce counter for per-hnb cumulative active CS RAB duration
..


Patch Set 4:

(1 comment)

File src/osmo-hnbgw/hnbgw.c:

https://gerrit.osmocom.org/c/osmo-hnbgw/+/36205/comment/d68eb590_18db39ba
PS3, Line 78:   if (!hnb->persistent)
> I think you're understanding the code wrong. […]
See the comment:

/*! pointer to the associated hnb persistent state. Always present 
after HNB-Register */
struct hnb_persistent *persistent;



--
To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/36205?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-hnbgw
Gerrit-Branch: master
Gerrit-Change-Id: Iffb6a3f38239094551a12c872cd8474d02a5ad56
Gerrit-Change-Number: 36205
Gerrit-PatchSet: 4
Gerrit-Owner: laforge 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin 
Gerrit-Attention: pespin 
Gerrit-Comment-Date: Tue, 12 Mar 2024 20:41:18 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: laforge 
Comment-In-Reply-To: pespin 
Gerrit-MessageType: comment


[M] Change in osmo-hnbgw[master]: Introduce counter for per-hnb cumulative active CS RAB duration

2024-03-12 Thread laforge
Attention is currently required from: pespin.

laforge has posted comments on this change. ( 
https://gerrit.osmocom.org/c/osmo-hnbgw/+/36205?usp=email )

Change subject: Introduce counter for per-hnb cumulative active CS RAB duration
..


Patch Set 4:

(1 comment)

File src/osmo-hnbgw/hnbgw.c:

https://gerrit.osmocom.org/c/osmo-hnbgw/+/36205/comment/753ff269_b0484ca7
PS3, Line 78:   if (!hnb->persistent)
> That's for a weird consequence of all the persistent stuff: […]
I think you're understanding the code wrong.  A 'persistent' data structure is 
always allocated on-demand whenever it does not exist upon the first connect of 
the HNB with the related "UMTS CGI-like" identity.

So every hnb_context will always have a "persistent" struct associated with it 
after the HNB-REGISTER-ACCEPT.

"persistent" just means that the data persists across re-connect.



--
To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/36205?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-hnbgw
Gerrit-Branch: master
Gerrit-Change-Id: Iffb6a3f38239094551a12c872cd8474d02a5ad56
Gerrit-Change-Number: 36205
Gerrit-PatchSet: 4
Gerrit-Owner: laforge 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin 
Gerrit-Attention: pespin 
Gerrit-Comment-Date: Tue, 12 Mar 2024 20:39:39 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: pespin 
Gerrit-MessageType: comment


[M] Change in osmo-hnbgw[master]: Introduce counter for per-hnb cumulative active CS RAB duration

2024-03-12 Thread laforge
Attention is currently required from: laforge.

Hello Jenkins Builder, pespin,

I'd like you to reexamine a change. Please visit

https://gerrit.osmocom.org/c/osmo-hnbgw/+/36205?usp=email

to look at the new patch set (#4).

The following approvals got outdated and were removed:
Verified+1 by Jenkins Builder


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, 95 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-hnbgw refs/changes/05/36205/4
--
To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/36205?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-hnbgw
Gerrit-Branch: master
Gerrit-Change-Id: Iffb6a3f38239094551a12c872cd8474d02a5ad56
Gerrit-Change-Number: 36205
Gerrit-PatchSet: 4
Gerrit-Owner: laforge 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin 
Gerrit-Attention: laforge 
Gerrit-MessageType: newpatchset


[M] Change in osmo-hnbgw[master]: Introduce counter for per-hnb cumulative active CS RAB duration

2024-03-08 Thread pespin
Attention is currently required from: laforge.

pespin has posted comments on this change. ( 
https://gerrit.osmocom.org/c/osmo-hnbgw/+/36205?usp=email )

Change subject: Introduce counter for per-hnb cumulative active CS RAB duration
..


Patch Set 3:

(1 comment)

File src/osmo-hnbgw/hnbgw.c:

https://gerrit.osmocom.org/c/osmo-hnbgw/+/36205/comment/8a220353_238b004f
PS3, Line 78:   if (!hnb->persistent)
That's for a weird consequence of all the persistent stuff:
If the HNB is dynamically added, then suddenly the user has no way to access 
the metrics. WHY?



--
To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/36205?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-hnbgw
Gerrit-Branch: master
Gerrit-Change-Id: Iffb6a3f38239094551a12c872cd8474d02a5ad56
Gerrit-Change-Number: 36205
Gerrit-PatchSet: 3
Gerrit-Owner: laforge 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin 
Gerrit-Attention: laforge 
Gerrit-Comment-Date: Fri, 08 Mar 2024 14:50:40 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment


[M] Change in osmo-hnbgw[master]: Introduce counter for per-hnb cumulative active CS RAB duration

2024-03-08 Thread laforge
Attention is currently required from: pespin.

laforge has posted comments on this change. ( 
https://gerrit.osmocom.org/c/osmo-hnbgw/+/36205?usp=email )

Change subject: Introduce counter for per-hnb cumulative active CS RAB duration
..


Patch Set 3:

(1 comment)

File src/osmo-hnbgw/mgw_fsm.c:

https://gerrit.osmocom.org/c/osmo-hnbgw/+/36205/comment/3c42078a_f84461f4
PS1, Line 940:  if (mgw_fsm_priv->active_stored.tv_sec == 0 && 
mgw_fsm_priv->active_stored.tv_nsec == 0)
> You can use here: […]
timespecisset, but yes, got your message. Will also clean-up osmo-bsc where I 
lifted this from.



--
To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/36205?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-hnbgw
Gerrit-Branch: master
Gerrit-Change-Id: Iffb6a3f38239094551a12c872cd8474d02a5ad56
Gerrit-Change-Number: 36205
Gerrit-PatchSet: 3
Gerrit-Owner: laforge 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin 
Gerrit-Attention: pespin 
Gerrit-Comment-Date: Fri, 08 Mar 2024 14:34:24 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: pespin 
Gerrit-MessageType: comment


[M] Change in osmo-hnbgw[master]: Introduce counter for per-hnb cumulative active CS RAB duration

2024-03-08 Thread laforge
Attention is currently required from: laforge, pespin.

Hello Jenkins Builder, pespin,

I'd like you to reexamine a change. Please visit

https://gerrit.osmocom.org/c/osmo-hnbgw/+/36205?usp=email

to look at the new patch set (#3).

The following approvals got outdated and were removed:
Verified+1 by Jenkins Builder


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, 92 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-hnbgw refs/changes/05/36205/3
--
To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/36205?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-hnbgw
Gerrit-Branch: master
Gerrit-Change-Id: Iffb6a3f38239094551a12c872cd8474d02a5ad56
Gerrit-Change-Number: 36205
Gerrit-PatchSet: 3
Gerrit-Owner: laforge 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin 
Gerrit-Attention: laforge 
Gerrit-Attention: pespin 
Gerrit-MessageType: newpatchset


[M] Change in osmo-hnbgw[master]: Introduce counter for per-hnb cumulative active CS RAB duration

2024-03-08 Thread laforge
Attention is currently required from: laforge, pespin.

laforge has posted comments on this change. ( 
https://gerrit.osmocom.org/c/osmo-hnbgw/+/36205?usp=email )

Change subject: Introduce counter for per-hnb cumulative active CS RAB duration
..


Set Ready For Review


--
To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/36205?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-hnbgw
Gerrit-Branch: master
Gerrit-Change-Id: Iffb6a3f38239094551a12c872cd8474d02a5ad56
Gerrit-Change-Number: 36205
Gerrit-PatchSet: 2
Gerrit-Owner: laforge 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin 
Gerrit-Attention: laforge 
Gerrit-Attention: pespin 
Gerrit-Comment-Date: Fri, 08 Mar 2024 13:22:14 +
Gerrit-HasComments: No
Gerrit-Has-Labels: No
Gerrit-MessageType: comment


[M] Change in osmo-hnbgw[master]: Introduce counter for per-hnb cumulative active CS RAB duration

2024-03-08 Thread laforge
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 

 #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 
 #include 
 #include 
+#include 

 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, );
+
+   /* iterate over all context_maps (subscribers) */
+   llist_for_each_entry(map, >map_list, hnb_list) {
+   elapsed_cs_rab_ms += mgw_fsm_get_elapsed_ms(map, );
+   }
+
+   /* 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, _hnbgw->hnb_list, list)
+   hnb_store_rab_durations(hnb);
+
+   /* Keep this timer ticking */
+   osmo_timer_schedule(_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(_hnbgw->store_uptime_timer, hnbgw_store_hnb_uptime, 
g_hnbgw);
osmo_timer_schedule(_hnbgw->store_uptime_timer, 
STORE_UPTIME_INTERVAL, 0);
+
+   osmo_timer_setup(_hnbgw->hnb_store_rab_durations_timer, 
hnbgw_store_hnb_rab_durations, g_hnbgw);
+   osmo_timer_schedule(_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 
+/* (C) 2021-2024 by sysmocom s.f.m.c. GmbH 
  * 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,