pespin has submitted this change. ( 
https://gerrit.osmocom.org/c/osmo-hnbgw/+/40253?usp=email )

Change subject: Move hnbgw_cnlink to cnlink.h and hnbgw_cnpool to hnbgw_cn.h
......................................................................

Move hnbgw_cnlink to cnlink.h and hnbgw_cnpool to hnbgw_cn.h

Simplify mastodontic hnbgw.h and properly split per object/entity.
We actually have that in C files (cnlink.c and hnbgw_cn.c), so do the
same here.

This makes it easier to spot where stuff is, and extend it later (like
adding stats, etc.).

Change-Id: I75988112cff6c8c17d2bdb166a0934934c523dfc
---
M include/osmocom/hnbgw/Makefile.am
A include/osmocom/hnbgw/cnlink.h
M include/osmocom/hnbgw/hnbgw.h
M include/osmocom/hnbgw/hnbgw_cn.h
4 files changed, 175 insertions(+), 157 deletions(-)

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




diff --git a/include/osmocom/hnbgw/Makefile.am 
b/include/osmocom/hnbgw/Makefile.am
index d3fbb07..ebc26ce 100644
--- a/include/osmocom/hnbgw/Makefile.am
+++ b/include/osmocom/hnbgw/Makefile.am
@@ -1,4 +1,5 @@
 noinst_HEADERS = \
+       cnlink.h \
        context_map.h \
        hnbgw.h \
        hnbgw_cn.h \
diff --git a/include/osmocom/hnbgw/cnlink.h b/include/osmocom/hnbgw/cnlink.h
new file mode 100644
index 0000000..9495041
--- /dev/null
+++ b/include/osmocom/hnbgw/cnlink.h
@@ -0,0 +1,122 @@
+#pragma once
+
+#include <stdbool.h>
+
+#include <osmocom/core/rate_ctr.h>
+#include <osmocom/gsm/gsm48.h>
+
+#include <osmocom/sigtran/sccp_sap.h>
+
+#include <osmocom/ranap/ranap_ies_defs.h>
+
+#include <osmocom/hnbgw/hnbgw_sccp.h>
+
+struct hnbgw_cnpool;
+
+struct hnbgw_cnlink *cnlink_alloc(struct hnbgw_cnpool *cnpool, int nr);
+
+void hnbgw_cnlink_drop_sccp(struct hnbgw_cnlink *cnlink);
+
+bool cnlink_is_conn_ready(const struct hnbgw_cnlink *cnlink);
+void cnlink_rx_reset_cmd(struct hnbgw_cnlink *cnlink);
+void cnlink_rx_reset_ack(struct hnbgw_cnlink *cnlink);
+void cnlink_resend_reset(struct hnbgw_cnlink *cnlink);
+void cnlink_set_disconnected(struct hnbgw_cnlink *cnlink);
+
+const char *cnlink_paging_add_ranap(struct hnbgw_cnlink *cnlink, const 
RANAP_PagingIEs_t *paging_ies);
+struct hnbgw_cnlink *cnlink_find_by_paging_mi(struct hnbgw_cnpool *cnpool, 
const struct osmo_mobile_identity *mi);
+
+enum hnbgw_cnlink_ctr {
+       /* TODO: basic counters completely missing
+        * ...
+        */
+       CNLINK_CTR_RANAP_RX_UDT_RESET,
+       CNLINK_CTR_RANAP_RX_UDT_RESET_ACK,
+       CNLINK_CTR_RANAP_RX_UDT_PAGING,
+       CNLINK_CTR_RANAP_RX_UDT_UNKNOWN,
+       CNLINK_CTR_RANAP_RX_UDT_UNSUPPORTED,
+       CNLINK_CTR_RANAP_RX_UDT_OVERLOAD_IND,
+       CNLINK_CTR_RANAP_RX_UDT_ERROR_IND,
+
+       CNLINK_CTR_RANAP_TX_UDT_RESET,
+       CNLINK_CTR_RANAP_TX_UDT_RESET_ACK,
+
+       /* SCCP Counters: */
+       CNLINK_CTR_SCCP_N_UNITDATA_REQ,
+       CNLINK_CTR_SCCP_N_UNITDATA_IND,
+       CNLINK_CTR_SCCP_N_CONNECT_REQ,
+       CNLINK_CTR_SCCP_N_CONNECT_CNF,
+       CNLINK_CTR_SCCP_N_DATA_REQ,
+       CNLINK_CTR_SCCP_N_DATA_IND,
+       CNLINK_CTR_SCCP_N_DISCONNECT_REQ,
+       CNLINK_CTR_SCCP_N_DISCONNECT_IND,
+       CNLINK_CTR_SCCP_N_PCSTATE_IND,
+       CNLINK_CTR_SCCP_RLSD_CN_ORIGIN,
+
+       /* Counters related to link selection from a CN pool. */
+       CNLINK_CTR_CNPOOL_SUBSCR_NEW,
+       CNLINK_CTR_CNPOOL_SUBSCR_REATTACH,
+       CNLINK_CTR_CNPOOL_SUBSCR_KNOWN,
+       CNLINK_CTR_CNPOOL_SUBSCR_PAGED,
+       CNLINK_CTR_CNPOOL_SUBSCR_ATTACH_LOST,
+       CNLINK_CTR_CNPOOL_EMERG_FORWARDED,
+};
+
+/* User provided configuration for struct hnbgw_cnlink. */
+struct hnbgw_cnlink_cfg {
+       /* cs7 address book entry to indicate both the remote point-code of the 
peer, as well as which cs7 instance to
+        * use. */
+       char *remote_addr_name;
+
+       struct osmo_nri_ranges *nri_ranges;
+};
+
+/* A CN peer, like 'msc 0' or 'sgsn 23' */
+struct hnbgw_cnlink {
+       struct llist_head entry;
+
+       /* backpointer to CS or PS CN pool. */
+       struct hnbgw_cnpool *pool;
+
+       struct osmo_fsm_inst *fi;
+
+       int nr;
+
+       struct hnbgw_cnlink_cfg vty;
+       struct hnbgw_cnlink_cfg use;
+
+       /* To print in logging/VTY */
+       char *name;
+
+       /* Copy of the address book entry use.remote_addr_name. */
+       struct osmo_sccp_addr remote_addr;
+
+       /* The SCCP instance for the cs7 instance indicated by 
remote_addr_name. (Multiple hnbgw_cnlinks may use the
+        * same hnbgw_sccp_user -- there is exactly one hnbgw_sccp_user per 
configured cs7 instance.) */
+       struct hnbgw_sccp_user *hnbgw_sccp_user;
+
+       /* linked list of hnbgw_context_map */
+       struct llist_head map_list;
+
+       bool allow_attach;
+       bool allow_emerg;
+       struct llist_head paging;
+
+       struct rate_ctr_group *ctrs;
+};
+
+static inline struct osmo_sccp_instance *cnlink_sccp(const struct hnbgw_cnlink 
*cnlink)
+{
+       if (!cnlink)
+               return NULL;
+       if (!cnlink->hnbgw_sccp_user)
+               return NULL;
+       if (!cnlink->hnbgw_sccp_user->ss7)
+               return NULL;
+       return osmo_ss7_get_sccp(cnlink->hnbgw_sccp_user->ss7);
+}
+
+#define LOG_CNLINK(CNLINK, SUBSYS, LEVEL, FMT, ARGS...) \
+       LOGP(SUBSYS, LEVEL, "(%s) " FMT, (CNLINK) ? (CNLINK)->name : "null", 
##ARGS)
+
+#define CNLINK_CTR_INC(cnlink, x) rate_ctr_inc2((cnlink)->ctrs, x)
diff --git a/include/osmocom/hnbgw/hnbgw.h b/include/osmocom/hnbgw/hnbgw.h
index 3995294..b253d7f 100644
--- a/include/osmocom/hnbgw/hnbgw.h
+++ b/include/osmocom/hnbgw/hnbgw.h
@@ -19,7 +19,8 @@
 #include <osmocom/mgcp_client/mgcp_client_pool.h>

 #include <osmocom/hnbgw/nft_kpi.h>
-#include <osmocom/hnbgw/hnbgw_sccp.h>
+#include <osmocom/hnbgw/cnlink.h>
+#include <osmocom/hnbgw/hnbgw_cn.h>

 #define STORE_UPTIME_INTERVAL  10 /* seconds */
 #define HNB_STORE_RAB_DURATIONS_INTERVAL 1 /* seconds */
@@ -202,93 +203,6 @@

 struct hnbgw_context_map;

-/* User provided configuration for struct hnbgw_cnpool. */
-struct hnbgw_cnpool_cfg {
-       uint8_t nri_bitlen;
-       struct osmo_nri_ranges *null_nri_ranges;
-};
-
-/* User provided configuration for struct hnbgw_cnlink. */
-struct hnbgw_cnlink_cfg {
-       /* cs7 address book entry to indicate both the remote point-code of the 
peer, as well as which cs7 instance to
-        * use. */
-       char *remote_addr_name;
-
-       struct osmo_nri_ranges *nri_ranges;
-};
-
-/* Collection of CN peers to distribute UE connections across. MSCs for 
DOMAIN_CS, SGSNs for DOMAIN_PS. */
-struct hnbgw_cnpool {
-       RANAP_CN_DomainIndicator_t domain;
-
-       /* CN pool string used in VTY config and logging, "iucs" or "iups". */
-       const char *pool_name;
-       /* CN peer string used in VTY config and logging, "msc" or "sgsn". */
-       const char *peer_name;
-       /* What we use as the remote MSC/SGSN point-code if the user does not 
configure any address. */
-       uint32_t default_remote_pc;
-
-       struct hnbgw_cnpool_cfg vty;
-       struct hnbgw_cnpool_cfg use;
-
-       /* List of struct hnbgw_cnlink */
-       struct llist_head cnlinks;
-
-       unsigned int round_robin_next_nr;
-       /* Emergency calls potentially select a different set of MSCs, so to 
not mess up the normal round-robin
-        * behavior, emergency calls need a separate round-robin counter. */
-       unsigned int round_robin_next_emerg_nr;
-
-       /* rate counter group that child hnbgw_cnlinks should use (points to 
msc_ctrg_desc or sgsn_ctrg_desc) */
-       const struct rate_ctr_group_desc *cnlink_ctrg_desc;
-
-       /* Running counters for this pool */
-       struct rate_ctr_group *ctrs;
-};
-
-#define CNPOOL_CTR_INC(cnpool, x) rate_ctr_inc2((cnpool)->ctrs, x)
-
-/* A CN peer, like 'msc 0' or 'sgsn 23' */
-struct hnbgw_cnlink {
-       struct llist_head entry;
-
-       /* backpointer to CS or PS CN pool. */
-       struct hnbgw_cnpool *pool;
-
-       struct osmo_fsm_inst *fi;
-
-       int nr;
-
-       struct hnbgw_cnlink_cfg vty;
-       struct hnbgw_cnlink_cfg use;
-
-       /* To print in logging/VTY */
-       char *name;
-
-       /* Copy of the address book entry use.remote_addr_name. */
-       struct osmo_sccp_addr remote_addr;
-
-       /* The SCCP instance for the cs7 instance indicated by 
remote_addr_name. (Multiple hnbgw_cnlinks may use the
-        * same hnbgw_sccp_user -- there is exactly one hnbgw_sccp_user per 
configured cs7 instance.) */
-       struct hnbgw_sccp_user *hnbgw_sccp_user;
-
-       /* linked list of hnbgw_context_map */
-       struct llist_head map_list;
-
-       bool allow_attach;
-       bool allow_emerg;
-       struct llist_head paging;
-
-       struct rate_ctr_group *ctrs;
-};
-
-#define LOG_CNLINK(CNLINK, SUBSYS, LEVEL, FMT, ARGS...) \
-       LOGP(SUBSYS, LEVEL, "(%s) " FMT, (CNLINK) ? (CNLINK)->name : "null", 
##ARGS)
-
-#define CNLINK_CTR_INC(cnlink, x) rate_ctr_inc2((cnlink)->ctrs, x)
-
-struct hnbgw_cnlink *cnlink_get_nr(struct hnbgw_cnpool *cnpool, int nr, bool 
create_if_missing);
-
 static inline bool cnlink_is_cs(const struct hnbgw_cnlink *cnlink)
 {
        return cnlink && cnlink->pool->domain == DOMAIN_CS;
@@ -299,17 +213,6 @@
        return cnlink && cnlink->pool->domain == DOMAIN_PS;
 }

-static inline struct osmo_sccp_instance *cnlink_sccp(const struct hnbgw_cnlink 
*cnlink)
-{
-       if (!cnlink)
-               return NULL;
-       if (!cnlink->hnbgw_sccp_user)
-               return NULL;
-       if (!cnlink->hnbgw_sccp_user->ss7)
-               return NULL;
-       return osmo_ss7_get_sccp(cnlink->hnbgw_sccp_user->ss7);
-}
-
 /* The lifecycle of the hnb_context object is the same as its conn */
 struct hnb_context {
        /*! Entry in HNB-global list of HNB */
diff --git a/include/osmocom/hnbgw/hnbgw_cn.h b/include/osmocom/hnbgw/hnbgw_cn.h
index fc33e5b..d6098b4 100644
--- a/include/osmocom/hnbgw/hnbgw_cn.h
+++ b/include/osmocom/hnbgw/hnbgw_cn.h
@@ -1,31 +1,13 @@
 #pragma once

+#include <stdint.h>
 #include <osmocom/core/rate_ctr.h>
-#include <osmocom/gsm/gsm48.h>

-#include <osmocom/ranap/ranap_ies_defs.h>
+#include <osmocom/sigtran/sccp_sap.h>

-#include <osmocom/hnbgw/hnbgw.h>
+#include <osmocom/ranap/RANAP_CN-DomainIndicator.h>

-struct hnbgw_cnlink *cnlink_alloc(struct hnbgw_cnpool *cnpool, int nr);
-struct hnbgw_cnlink *hnbgw_cnlink_select(struct hnbgw_context_map *map);
-
-void hnbgw_cnpool_start(struct hnbgw_cnpool *cnpool);
-void hnbgw_cnpool_apply_cfg(struct hnbgw_cnpool *cnpool);
-void hnbgw_cnpool_cnlinks_start_or_restart(struct hnbgw_cnpool *cnpool);
-int hnbgw_cnlink_start_or_restart(struct hnbgw_cnlink *cnlink);
-void hnbgw_cnlink_drop_sccp(struct hnbgw_cnlink *cnlink);
-
-char *cnlink_sccp_addr_to_str(struct hnbgw_cnlink *cnlink, const struct 
osmo_sccp_addr *addr);
-
-bool cnlink_is_conn_ready(const struct hnbgw_cnlink *cnlink);
-void cnlink_rx_reset_cmd(struct hnbgw_cnlink *cnlink);
-void cnlink_rx_reset_ack(struct hnbgw_cnlink *cnlink);
-void cnlink_resend_reset(struct hnbgw_cnlink *cnlink);
-void cnlink_set_disconnected(struct hnbgw_cnlink *cnlink);
-
-const char *cnlink_paging_add_ranap(struct hnbgw_cnlink *cnlink, const 
RANAP_PagingIEs_t *paging_ies);
-struct hnbgw_cnlink *cnlink_find_by_paging_mi(struct hnbgw_cnpool *cnpool, 
const struct osmo_mobile_identity *mi);
+struct hnbgw_context_map;

 enum hnbgw_cnpool_ctr {
        /* TODO: basic counters completely missing
@@ -37,45 +19,55 @@
        CNPOOL_CTR_EMERG_FORWARDED,
        CNPOOL_CTR_EMERG_LOST,
 };
+#define CNPOOL_CTR_INC(cnpool, x) rate_ctr_inc2((cnpool)->ctrs, x)
+
+/* User provided configuration for struct hnbgw_cnpool. */
+struct hnbgw_cnpool_cfg {
+       uint8_t nri_bitlen;
+       struct osmo_nri_ranges *null_nri_ranges;
+};
+
+/* Collection of CN peers to distribute UE connections across. MSCs for 
DOMAIN_CS, SGSNs for DOMAIN_PS. */
+struct hnbgw_cnpool {
+       RANAP_CN_DomainIndicator_t domain;
+
+       /* CN pool string used in VTY config and logging, "iucs" or "iups". */
+       const char *pool_name;
+       /* CN peer string used in VTY config and logging, "msc" or "sgsn". */
+       const char *peer_name;
+       /* What we use as the remote MSC/SGSN point-code if the user does not 
configure any address. */
+       uint32_t default_remote_pc;
+
+       struct hnbgw_cnpool_cfg vty;
+       struct hnbgw_cnpool_cfg use;
+
+       /* List of struct hnbgw_cnlink */
+       struct llist_head cnlinks;
+
+       unsigned int round_robin_next_nr;
+       /* Emergency calls potentially select a different set of MSCs, so to 
not mess up the normal round-robin
+        * behavior, emergency calls need a separate round-robin counter. */
+       unsigned int round_robin_next_emerg_nr;
+
+       /* rate counter group that child hnbgw_cnlinks should use (points to 
msc_ctrg_desc or sgsn_ctrg_desc) */
+       const struct rate_ctr_group_desc *cnlink_ctrg_desc;
+
+       /* Running counters for this pool */
+       struct rate_ctr_group *ctrs;
+};

 extern const struct rate_ctr_group_desc iucs_ctrg_desc;
 extern const struct rate_ctr_group_desc iups_ctrg_desc;

-enum hnbgw_cnlink_ctr {
-       /* TODO: basic counters completely missing
-        * ...
-        */
-       CNLINK_CTR_RANAP_RX_UDT_RESET,
-       CNLINK_CTR_RANAP_RX_UDT_RESET_ACK,
-       CNLINK_CTR_RANAP_RX_UDT_PAGING,
-       CNLINK_CTR_RANAP_RX_UDT_UNKNOWN,
-       CNLINK_CTR_RANAP_RX_UDT_UNSUPPORTED,
-       CNLINK_CTR_RANAP_RX_UDT_OVERLOAD_IND,
-       CNLINK_CTR_RANAP_RX_UDT_ERROR_IND,
-
-       CNLINK_CTR_RANAP_TX_UDT_RESET,
-       CNLINK_CTR_RANAP_TX_UDT_RESET_ACK,
-
-       /* SCCP Counters: */
-       CNLINK_CTR_SCCP_N_UNITDATA_REQ,
-       CNLINK_CTR_SCCP_N_UNITDATA_IND,
-       CNLINK_CTR_SCCP_N_CONNECT_REQ,
-       CNLINK_CTR_SCCP_N_CONNECT_CNF,
-       CNLINK_CTR_SCCP_N_DATA_REQ,
-       CNLINK_CTR_SCCP_N_DATA_IND,
-       CNLINK_CTR_SCCP_N_DISCONNECT_REQ,
-       CNLINK_CTR_SCCP_N_DISCONNECT_IND,
-       CNLINK_CTR_SCCP_N_PCSTATE_IND,
-       CNLINK_CTR_SCCP_RLSD_CN_ORIGIN,
-
-       /* Counters related to link selection from a CN pool. */
-       CNLINK_CTR_CNPOOL_SUBSCR_NEW,
-       CNLINK_CTR_CNPOOL_SUBSCR_REATTACH,
-       CNLINK_CTR_CNPOOL_SUBSCR_KNOWN,
-       CNLINK_CTR_CNPOOL_SUBSCR_PAGED,
-       CNLINK_CTR_CNPOOL_SUBSCR_ATTACH_LOST,
-       CNLINK_CTR_CNPOOL_EMERG_FORWARDED,
-};
-
 extern const struct rate_ctr_group_desc msc_ctrg_desc;
 extern const struct rate_ctr_group_desc sgsn_ctrg_desc;
+
+struct hnbgw_cnlink *hnbgw_cnlink_select(struct hnbgw_context_map *map);
+
+void hnbgw_cnpool_start(struct hnbgw_cnpool *cnpool);
+void hnbgw_cnpool_cnlinks_start_or_restart(struct hnbgw_cnpool *cnpool);
+struct hnbgw_cnlink *cnlink_get_nr(struct hnbgw_cnpool *cnpool, int nr, bool 
create_if_missing);
+void hnbgw_cnpool_apply_cfg(struct hnbgw_cnpool *cnpool);
+
+int hnbgw_cnlink_start_or_restart(struct hnbgw_cnlink *cnlink);
+char *cnlink_sccp_addr_to_str(struct hnbgw_cnlink *cnlink, const struct 
osmo_sccp_addr *addr);

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

Gerrit-MessageType: merged
Gerrit-Project: osmo-hnbgw
Gerrit-Branch: master
Gerrit-Change-Id: I75988112cff6c8c17d2bdb166a0934934c523dfc
Gerrit-Change-Number: 40253
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pes...@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <lafo...@osmocom.org>
Gerrit-Reviewer: osmith <osm...@sysmocom.de>
Gerrit-Reviewer: pespin <pes...@sysmocom.de>

Reply via email to