diff --git a/include/osmocom/smlc/smlc_data.h b/include/osmocom/smlc/smlc_data.h index dc77507..2e17dd0 100644 --- a/include/osmocom/smlc/smlc_data.h +++ b/include/osmocom/smlc/smlc_data.h @@ -37,6 +37,7 @@ enum smlc_ctrl_node { _LAST_CTRL_NODE_SMLC }; +/* rate_ctr */ enum { SMLC_CTR_BSSMAP_LE_RX_UDT_RESET, SMLC_CTR_BSSMAP_LE_RX_UDT_RESET_ACK, @@ -58,3 +59,9 @@ enum { SMLC_CTR_BSSMAP_LE_TX_DT1_PERFORM_LOCATION_RESPONSE, SMLC_CTR_BSSMAP_LE_TX_DT1_BSSLAP_TA_REQUEST, }; + +/* osmo_stat */ +enum { + SMLC_STAT_LB_PEERS_TOTAL, + SMLC_STAT_LB_PEERS_ACTIVE, +}; diff --git a/src/osmo-smlc/lb_peer.c b/src/osmo-smlc/lb_peer.c index fa2bc17..d9d3b38 100644 --- a/src/osmo-smlc/lb_peer.c +++ b/src/osmo-smlc/lb_peer.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -57,6 +58,7 @@ static struct lb_peer *lb_peer_alloc(struct sccp_lb_inst *sli, const struct osmo fi->priv = lbp; llist_add(&lbp->entry, &sli->lb_peers); + osmo_stat_item_inc(osmo_stat_item_group_get_item(g_smlc->statg, SMLC_STAT_LB_PEERS_TOTAL), 1); return lbp; } @@ -303,6 +305,12 @@ static void lb_peer_st_wait_rx_reset_ack(struct osmo_fsm_inst *fi, uint32_t even } } +static void lb_peer_st_ready_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state) +{ + if (prev_state != LB_PEER_ST_READY) + osmo_stat_item_inc(osmo_stat_item_group_get_item(g_smlc->statg, SMLC_STAT_LB_PEERS_ACTIVE), 1); +} + static void lb_peer_st_ready(struct osmo_fsm_inst *fi, uint32_t event, void *data) { struct lb_peer *lbp = fi->priv; @@ -377,6 +385,12 @@ static void lb_peer_st_ready(struct osmo_fsm_inst *fi, uint32_t event, void *dat } } +static void lb_peer_st_ready_onleave(struct osmo_fsm_inst *fi, uint32_t next_state) +{ + if (next_state != LB_PEER_ST_READY) + osmo_stat_item_dec(osmo_stat_item_group_get_item(g_smlc->statg, SMLC_STAT_LB_PEERS_ACTIVE), 1); +} + static int lb_peer_fsm_timer_cb(struct osmo_fsm_inst *fi) { struct lb_peer *lbp = fi->priv; @@ -384,10 +398,17 @@ static int lb_peer_fsm_timer_cb(struct osmo_fsm_inst *fi) return 0; } +/* struct lb_peer destructor: */ static void lb_peer_fsm_cleanup(struct osmo_fsm_inst *fi, enum osmo_fsm_term_cause cause) { struct lb_peer *lbp = fi->priv; + lb_peer_discard_all_conns(lbp); + + if (lbp->fi->state == LB_PEER_ST_READY) + osmo_stat_item_dec(osmo_stat_item_group_get_item(g_smlc->statg, SMLC_STAT_LB_PEERS_ACTIVE), 1); + osmo_stat_item_dec(osmo_stat_item_group_get_item(g_smlc->statg, SMLC_STAT_LB_PEERS_TOTAL), 1); + llist_del(&lbp->entry); } @@ -446,6 +467,8 @@ static const struct osmo_fsm_state lb_peer_fsm_states[] = { [LB_PEER_ST_READY] = { .name = "READY", .action = lb_peer_st_ready, + .onenter = lb_peer_st_ready_onenter, + .onleave = lb_peer_st_ready_onleave, .in_event_mask = 0 | S(LB_PEER_EV_RX_RESET) | S(LB_PEER_EV_MSG_UP_CO_INITIAL) diff --git a/src/osmo-smlc/smlc_data.c b/src/osmo-smlc/smlc_data.c index d51bceb..1e25e39 100644 --- a/src/osmo-smlc/smlc_data.c +++ b/src/osmo-smlc/smlc_data.c @@ -54,6 +54,19 @@ static const struct rate_ctr_group_desc smlc_ctrg_desc = { smlc_ctr_description, }; +static const struct osmo_stat_item_desc smlc_stat_item_description[] = { + [SMLC_STAT_LB_PEERS_TOTAL] = { "lb_peers.total", "Total Lb peers seen since startup", OSMO_STAT_ITEM_NO_UNIT, 4, 0}, + [SMLC_STAT_LB_PEERS_ACTIVE] = { "lb_peers.active", "Currently active Lb peers", OSMO_STAT_ITEM_NO_UNIT, 4, 0}, +}; + +static const struct osmo_stat_item_group_desc smlc_statg_desc = { + "smlc", + "serving mobile location center", + OSMO_STATS_CLASS_GLOBAL, + ARRAY_SIZE(smlc_stat_item_description), + smlc_stat_item_description, +}; + struct smlc_state *smlc_state_alloc(void *ctx) { struct smlc_state *smlc = talloc_zero(ctx, struct smlc_state); @@ -61,5 +74,14 @@ struct smlc_state *smlc_state_alloc(void *ctx) INIT_LLIST_HEAD(&smlc->subscribers); INIT_LLIST_HEAD(&smlc->cell_locations); smlc->ctrs = rate_ctr_group_alloc(smlc, &smlc_ctrg_desc, 0); + + smlc->statg = osmo_stat_item_group_alloc(smlc, &smlc_statg_desc, 0); + if (!smlc->statg) + goto ret_free; return smlc; + +ret_free: + rate_ctr_group_free(smlc->ctrs); + talloc_free(smlc); + return NULL; } diff --git a/src/osmo-smlc/smlc_vty.c b/src/osmo-smlc/smlc_vty.c index 36ca47e..c6ae83a 100644 --- a/src/osmo-smlc/smlc_vty.c +++ b/src/osmo-smlc/smlc_vty.c @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include #include @@ -37,6 +39,7 @@ void smlc_vty_init(struct vty_app_info *vty_app_info) osmo_talloc_vty_add_cmds(); ctrl_vty_init(vty_app_info->tall_ctx); osmo_fsm_vty_add_cmds(); + osmo_stats_vty_add_cmds(); osmo_ss7_vty_init_asp(vty_app_info->tall_ctx); osmo_sccp_vty_init();