diff --git a/include/osmocom/hnbgw/hnbgw.h b/include/osmocom/hnbgw/hnbgw.h index 8183cbc..62e5392 100644 --- a/include/osmocom/hnbgw/hnbgw.h +++ b/include/osmocom/hnbgw/hnbgw.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -135,6 +136,12 @@ struct hnbgw_cnpool { /* 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; }; /* A CN peer, like 'msc 0' or 'sgsn 23' */ @@ -164,6 +171,8 @@ struct hnbgw_cnlink { bool allow_attach; bool allow_emerg; + + struct rate_ctr_group *ctrs; }; #define LOG_CNLINK(CNLINK, SUBSYS, LEVEL, FMT, ARGS...) \ diff --git a/include/osmocom/hnbgw/hnbgw_cn.h b/include/osmocom/hnbgw/hnbgw_cn.h index 79d3c27..bd54a1f 100644 --- a/include/osmocom/hnbgw/hnbgw_cn.h +++ b/include/osmocom/hnbgw/hnbgw_cn.h @@ -1,5 +1,6 @@ #pragma once +#include #include struct hnbgw_cnlink *hnbgw_cnlink_find_by_addr(const struct hnbgw_sccp_user *hsu, @@ -13,3 +14,33 @@ 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); +enum hnbgw_cnpool_ctr { + /* TODO: basic counters completely missing + * ... + */ + + /* Counters related to link selection from a CN pool. */ + CNPOOL_CTR_SUBSCR_NO_CNLINK, + CNPOOL_CTR_EMERG_FORWARDED, + CNPOOL_CTR_EMERG_LOST, +}; + +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 + * ... + */ + + /* 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; diff --git a/src/osmo-hnbgw/hnbgw.c b/src/osmo-hnbgw/hnbgw.c index e76dfde..4166ab3 100644 --- a/src/osmo-hnbgw/hnbgw.c +++ b/src/osmo-hnbgw/hnbgw.c @@ -36,6 +36,7 @@ #include #include #include +#include #include struct hnbgw *g_hnbgw = NULL; @@ -71,6 +72,9 @@ void g_hnbgw_alloc(void *ctx) .nri_bitlen = OSMO_NRI_BITLEN_DEFAULT, .null_nri_ranges = osmo_nri_ranges_alloc(g_hnbgw), }, + .cnlink_ctrg_desc = &msc_ctrg_desc, + + .ctrs = rate_ctr_group_alloc(g_hnbgw, &iucs_ctrg_desc, 0), }; INIT_LLIST_HEAD(&g_hnbgw->sccp.cnpool_iucs.cnlinks); @@ -83,6 +87,9 @@ void g_hnbgw_alloc(void *ctx) .nri_bitlen = OSMO_NRI_BITLEN_DEFAULT, .null_nri_ranges = osmo_nri_ranges_alloc(g_hnbgw), }, + .cnlink_ctrg_desc = &sgsn_ctrg_desc, + + .ctrs = rate_ctr_group_alloc(g_hnbgw, &iups_ctrg_desc, 0), }; INIT_LLIST_HEAD(&g_hnbgw->sccp.cnpool_iups.cnlinks); } diff --git a/src/osmo-hnbgw/hnbgw_cn.c b/src/osmo-hnbgw/hnbgw_cn.c index 9dc2016..486d30a 100644 --- a/src/osmo-hnbgw/hnbgw_cn.c +++ b/src/osmo-hnbgw/hnbgw_cn.c @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -655,6 +656,7 @@ static struct hnbgw_cnlink *cnlink_alloc(struct hnbgw_cnpool *cnpool, int nr) .nri_ranges = osmo_nri_ranges_alloc(cnlink), }, .allow_attach = true, + .ctrs = rate_ctr_group_alloc(g_hnbgw, cnpool->cnlink_ctrg_desc, nr), }; INIT_LLIST_HEAD(&cnlink->map_list); @@ -724,3 +726,81 @@ char *cnlink_sccp_addr_to_str(struct hnbgw_cnlink *cnlink, const struct osmo_scc return osmo_sccp_addr_dump(addr); return osmo_sccp_inst_addr_to_str_c(OTC_SELECT, sccp, addr); } + +static const struct rate_ctr_desc cnlink_ctr_description[] = { + + /* Indicators for CN pool usage */ + [CNLINK_CTR_CNPOOL_SUBSCR_NEW] = { + "cnpool:subscr:new", + "Complete Layer 3 requests assigned to this CN link by round-robin (no NRI was assigned yet).", + }, + [CNLINK_CTR_CNPOOL_SUBSCR_REATTACH] = { + "cnpool:subscr:reattach", + "Complete Layer 3 requests assigned to this CN link by round-robin because the subscriber indicates a" + " NULL-NRI (previously assigned by another CN link).", + }, + [CNLINK_CTR_CNPOOL_SUBSCR_KNOWN] = { + "cnpool:subscr:known", + "Complete Layer 3 requests directed to this CN link because the subscriber indicates an NRI of this CN link.", + }, + [CNLINK_CTR_CNPOOL_SUBSCR_PAGED] = { + "cnpool:subscr:paged", + "Paging Response directed to this CN link because the subscriber was recently paged by this CN link.", + }, + [CNLINK_CTR_CNPOOL_SUBSCR_ATTACH_LOST] = { + "cnpool:subscr:attach_lost", + "A subscriber indicates an NRI value matching this CN link, but the CN link is not connected:" + " a re-attach to another CN link (if available) was forced, with possible service failure.", + }, + [CNLINK_CTR_CNPOOL_EMERG_FORWARDED] = { + "cnpool:emerg:forwarded", + "Emergency call requests forwarded to this CN link.", + }, +}; + +const struct rate_ctr_group_desc msc_ctrg_desc = { + "msc", + "MSC", + OSMO_STATS_CLASS_GLOBAL, + ARRAY_SIZE(cnlink_ctr_description), + cnlink_ctr_description, +}; + +const struct rate_ctr_group_desc sgsn_ctrg_desc = { + "sgsn", + "SGSN", + OSMO_STATS_CLASS_GLOBAL, + ARRAY_SIZE(cnlink_ctr_description), + cnlink_ctr_description, +}; + +static const struct rate_ctr_desc cnpool_ctr_description[] = { + [CNPOOL_CTR_SUBSCR_NO_CNLINK] = { + "cnpool:subscr:no_cnlink", + "Complete Layer 3 requests lost because no connected CN link is found available", + }, + [CNPOOL_CTR_EMERG_FORWARDED] = { + "cnpool:emerg:forwarded", + "Emergency call requests forwarded to a CN link (see also per-CN-link counters)", + }, + [CNPOOL_CTR_EMERG_LOST] = { + "cnpool:emerg:lost", + "Emergency call requests lost because no CN link was found available", + }, +}; + +const struct rate_ctr_group_desc iucs_ctrg_desc = { + "iucs", + "IuCS", + OSMO_STATS_CLASS_GLOBAL, + ARRAY_SIZE(cnpool_ctr_description), + cnpool_ctr_description, +}; + +const struct rate_ctr_group_desc iups_ctrg_desc = { + "iups", + "IuPS", + OSMO_STATS_CLASS_GLOBAL, + ARRAY_SIZE(cnpool_ctr_description), + cnpool_ctr_description, +}; diff --git a/src/osmo-hnbgw/osmo_hnbgw_main.c b/src/osmo-hnbgw/osmo_hnbgw_main.c index 30f3de9..d371914 100644 --- a/src/osmo-hnbgw/osmo_hnbgw_main.c +++ b/src/osmo-hnbgw/osmo_hnbgw_main.c @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -32,6 +33,7 @@ #include #include #include +#include #include #include @@ -194,6 +196,13 @@ int main(int argc, char **argv) if (rc < 0) exit(1); + osmo_stats_init(g_hnbgw); + rc = rate_ctr_init(g_hnbgw); + if (rc) { + LOGP(DMAIN, LOGL_FATAL, "rate_ctr_init() failed with rc=%d\n", rc); + exit(1); + } + osmo_fsm_log_timeouts(true); rc = osmo_ss7_init(); @@ -211,6 +220,7 @@ int main(int argc, char **argv) ctrl_vty_init(g_hnbgw); logging_vty_add_cmds(); osmo_talloc_vty_add_cmds(); + osmo_stats_vty_add_cmds(); /* Handle options after vty_init(), for --version */ handle_options(argc, argv);