diff options
Diffstat (limited to 'src/libbsc/bsc_init.c')
-rw-r--r-- | src/libbsc/bsc_init.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/libbsc/bsc_init.c b/src/libbsc/bsc_init.c index f5f265f14..674813c71 100644 --- a/src/libbsc/bsc_init.c +++ b/src/libbsc/bsc_init.c @@ -37,6 +37,8 @@ #include <osmocom/bsc/e1_config.h> #include <osmocom/bsc/common_bsc.h> #include <osmocom/bsc/pcu_if.h> + +#include <time.h> #include <limits.h> #include <stdbool.h> @@ -98,6 +100,24 @@ int bsc_shutdown_net(struct gsm_network *net) return 0; } +unsigned long long bts_uptime(const struct gsm_bts *bts) +{ + struct timespec tp; + + if (!bts->uptime || !bts->oml_link) { + LOGP(DNM, LOGL_ERROR, "BTS %u OML link uptime unavailable\n", bts->nr); + return 0; + } + + if (clock_gettime(CLOCK_MONOTONIC, &tp) != 0) { + LOGP(DNM, LOGL_ERROR, "BTS %u uptime computation failure: %s\n", bts->nr, strerror(errno)); + return 0; + } + + /* monotonic clock helps to ensure that the conversion is valid */ + return difftime(tp.tv_sec, bts->uptime); +} + static int rsl_si(struct gsm_bts_trx *trx, enum osmo_sysinfo_type i, int si_len) { struct gsm_bts *bts = trx->bts; |