pespin has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-sgsn/+/15214


Change subject: Replace own timer infra with libosmocore osmo_tdef
......................................................................

Replace own timer infra with libosmocore osmo_tdef

Change-Id: Ia0cf5f0a49737fbc419e2ccc86312d01c6e0056e
---
M include/osmocom/sgsn/sgsn.h
M src/gprs/gprs_gmm.c
M src/gprs/gprs_gmm_attach.c
M src/gprs/sgsn_vty.c
4 files changed, 127 insertions(+), 126 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-sgsn refs/changes/14/15214/1

diff --git a/include/osmocom/sgsn/sgsn.h b/include/osmocom/sgsn/sgsn.h
index 0a6ea29..6e4f5ca 100644
--- a/include/osmocom/sgsn/sgsn.h
+++ b/include/osmocom/sgsn/sgsn.h
@@ -86,20 +86,8 @@
        /* CDR configuration */
        struct sgsn_cdr cdr;

-       struct {
-               int T3312;
-               int T3322;
-               int T3350;
-               int T3360;
-               int T3370;
-               int T3313;
-               int T3314;
-               int T3316;
-               int T3385;
-               int T3386;
-               int T3395;
-               int T3397;
-       } timers;
+       /* Timer defintions */
+       struct osmo_tdef *T_defs;

        int dynamic_lookup;

diff --git a/src/gprs/gprs_gmm.c b/src/gprs/gprs_gmm.c
index 5d03923..c223f2a 100644
--- a/src/gprs/gprs_gmm.c
+++ b/src/gprs/gprs_gmm.c
@@ -40,6 +40,7 @@
 #include <osmocom/core/talloc.h>
 #include <osmocom/core/rate_ctr.h>
 #include <osmocom/core/utils.h>
+#include <osmocom/core/tdef.h>
 #include <osmocom/crypt/auth.h>
 #include <osmocom/gsm/apn.h>
 #include <osmocom/gsm/protocol/gsm_04_08_gprs.h>
@@ -231,12 +232,15 @@

 static void mmctx_timer_cb(void *_mm);

-static void mmctx_timer_start(struct sgsn_mm_ctx *mm, unsigned int T,
-                               unsigned int seconds)
+static void mmctx_timer_start(struct sgsn_mm_ctx *mm, unsigned int T)
 {
+       unsigned long seconds;
        if (osmo_timer_pending(&mm->timer))
                LOGMMCTXP(LOGL_ERROR, mm, "Starting MM timer %u while old "
                        "timer %u pending\n", T, mm->T);
+
+       seconds = osmo_tdef_get(sgsn->cfg.T_defs, T, OSMO_TDEF_S, -1);
+
        mm->T = T;
        mm->num_T_exp = 0;

@@ -255,7 +259,11 @@

 time_t gprs_max_time_to_idle(void)
 {
-       return sgsn->cfg.timers.T3314 + (sgsn->cfg.timers.T3312 + 4 * 60);
+       unsigned long T3314, T3312;
+
+       T3314 = osmo_tdef_get(sgsn->cfg.T_defs, 3314, OSMO_TDEF_S, -1);
+       T3312 = osmo_tdef_get(sgsn->cfg.T_defs, 3312, OSMO_TDEF_S, -1);
+       return T3314 + (T3312 + 4 * 60);
 }

 /* Send a message through the underlying layer.
@@ -447,6 +455,7 @@
        struct gsm48_hdr *gh;
        struct gsm48_attach_ack *aa;
        uint8_t *mid;
+       unsigned long t;
 #if 0
        uint8_t *ptsig;
 #endif
@@ -463,7 +472,8 @@
        aa = (struct gsm48_attach_ack *) msgb_put(msg, sizeof(*aa));
        aa->force_stby = 0;     /* not indicated */
        aa->att_result = 1;     /* GPRS only */
-       aa->ra_upd_timer = gprs_secs_to_tmr_floor(sgsn->cfg.timers.T3312);
+       t = osmo_tdef_get(sgsn->cfg.T_defs, 3312, OSMO_TDEF_S, -1);
+       aa->ra_upd_timer = gprs_secs_to_tmr_floor(t);
        aa->radio_prio = 4;     /* lowest */
        gsm48_encode_ra(&aa->ra_id, &mm->ra);

@@ -480,8 +490,8 @@
         * (fixed 44s, default value, GSM 04.08, table 11.4a) to safely limit
         * the inactivity time READY->STANDBY.
         */
-       msgb_tv_put(msg, GSM48_IE_GMM_TIMER_READY,
-                   gprs_secs_to_tmr_floor(sgsn->cfg.timers.T3314));
+       t = osmo_tdef_get(sgsn->cfg.T_defs, 3314, OSMO_TDEF_S, -1);
+       msgb_tv_put(msg, GSM48_IE_GMM_TIMER_READY, gprs_secs_to_tmr_floor(t));

 #ifdef PTMSI_ALLOC
        /* Optional: Allocated P-TMSI */
@@ -1017,12 +1027,12 @@
        /* Request IMSI and IMEI from the MS if they are unknown */
        if (!strlen(ctx->imei)) {
                ctx->t3370_id_type = GSM_MI_TYPE_IMEI;
-               mmctx_timer_start(ctx, 3370, sgsn->cfg.timers.T3370);
+               mmctx_timer_start(ctx, 3370);
                return gsm48_tx_gmm_id_req(ctx, GSM_MI_TYPE_IMEI);
        }
        if (!strlen(ctx->imsi)) {
                ctx->t3370_id_type = GSM_MI_TYPE_IMSI;
-               mmctx_timer_start(ctx, 3370, sgsn->cfg.timers.T3370);
+               mmctx_timer_start(ctx, 3370);
                return gsm48_tx_gmm_id_req(ctx, GSM_MI_TYPE_IMSI);
        }

@@ -1045,7 +1055,7 @@
            && !sgsn_mm_ctx_is_authenticated(ctx)) {
                struct gsm_auth_tuple *at = &ctx->auth_triplet;

-               mmctx_timer_start(ctx, 3360, sgsn->cfg.timers.T3360);
+               mmctx_timer_start(ctx, 3360);
                return gsm48_tx_gmm_auth_ciph_req(ctx, &at->vec, at->key_seq,
                                                  false);
        }
@@ -1084,7 +1094,7 @@
                extract_subscr_hlr(ctx);
 #ifdef PTMSI_ALLOC
                /* Start T3350 and re-transmit up to 5 times until ATTACH 
COMPLETE */
-               mmctx_timer_start(ctx, 3350, sgsn->cfg.timers.T3350);
+               mmctx_timer_start(ctx, 3350);
                ctx->t3350_mode = GMM_T3350_MODE_ATT;
 #else
                memset(&sig_data, 0, sizeof(sig_data));
@@ -1533,6 +1543,7 @@
        struct gsm48_hdr *gh;
        struct gsm48_ra_upd_ack *rua;
        uint8_t *mid;
+       unsigned long t;

        rate_ctr_inc(&sgsn->rate_ctrs->ctr[CTR_GPRS_ROUTING_AREA_ACKED]);
        LOGMMCTXP(LOGL_INFO, mm, "<- ROUTING AREA UPDATE ACCEPT\n");
@@ -1546,7 +1557,8 @@
        rua = (struct gsm48_ra_upd_ack *) msgb_put(msg, sizeof(*rua));
        rua->force_stby = 0;    /* not indicated */
        rua->upd_result = 0;    /* RA updated */
-       rua->ra_upd_timer = gprs_secs_to_tmr_floor(sgsn->cfg.timers.T3312);
+       t = osmo_tdef_get(sgsn->cfg.T_defs, 3312, OSMO_TDEF_S, -1);
+       rua->ra_upd_timer = gprs_secs_to_tmr_floor(t);

        gsm48_encode_ra(&rua->ra_id, &mm->ra);

@@ -1567,8 +1579,8 @@
 #endif

        /* Optional: Negotiated READY timer value */
-       msgb_tv_put(msg, GSM48_IE_GMM_TIMER_READY,
-                   gprs_secs_to_tmr_floor(sgsn->cfg.timers.T3314));
+       t = osmo_tdef_get(sgsn->cfg.T_defs, 3314, OSMO_TDEF_S, -1);
+       msgb_tv_put(msg, GSM48_IE_GMM_TIMER_READY, gprs_secs_to_tmr_floor(t));

        /* Option: MS ID, ... */
        return gsm48_gmm_sendmsg(msg, 0, mm, true);
@@ -1791,7 +1803,7 @@

        /* Start T3350 and re-transmit up to 5 times until ATTACH COMPLETE */
        mmctx->t3350_mode = GMM_T3350_MODE_RAU;
-       mmctx_timer_start(mmctx, 3350, sgsn->cfg.timers.T3350);
+       mmctx_timer_start(mmctx, 3350);
 #else
        /* Make sure we are NORMAL (i.e. not SUSPENDED anymore) */
        mmctx->gmm_state = GMM_REGISTERED_NORMAL;
@@ -2185,6 +2197,7 @@
        struct sgsn_mm_ctx *mm = _mm;
        struct gsm_auth_tuple *at;
        int rc;
+       unsigned long seconds;

        mm->num_T_exp++;

@@ -2212,7 +2225,8 @@
                                  "T3350 mode wasn't set, ignoring timeout\n");
                        break;
                }
-               osmo_timer_schedule(&mm->timer, sgsn->cfg.timers.T3350, 0);
+               seconds = osmo_tdef_get(sgsn->cfg.T_defs, 3350, OSMO_TDEF_S, 
-1);
+               osmo_timer_schedule(&mm->timer, seconds, 0);
                break;
        case 3360:      /* waiting for AUTH AND CIPH RESP */
                if (mm->num_T_exp >= 5) {
@@ -2230,10 +2244,12 @@
                at = &mm->auth_triplet;

                rc = gsm48_tx_gmm_auth_ciph_req(mm, &at->vec, at->key_seq, 
false);
-               if (rc < 0)
+               if (rc < 0) {
                        LOGMMCTXP(LOGL_ERROR, mm, "failed sending Auth. & Ciph. 
Request: %s \n", strerror(-rc));
-               else
-                       osmo_timer_schedule(&mm->timer, sgsn->cfg.timers.T3360, 
0);
+               } else {
+                       seconds = osmo_tdef_get(sgsn->cfg.T_defs, 3360, 
OSMO_TDEF_S, -1);
+                       osmo_timer_schedule(&mm->timer, seconds, 0);
+               }
                break;
        case 3370:      /* waiting for IDENTITY RESPONSE */
                if (mm->num_T_exp >= 5) {
@@ -2244,7 +2260,8 @@
                }
                /* re-tranmit IDENTITY REQUEST and re-start timer */
                gsm48_tx_gmm_id_req(mm, mm->t3370_id_type);
-               osmo_timer_schedule(&mm->timer, sgsn->cfg.timers.T3370, 0);
+               seconds = osmo_tdef_get(sgsn->cfg.T_defs, 3370, OSMO_TDEF_S, 
-1);
+               osmo_timer_schedule(&mm->timer, seconds, 0);
                break;
        default:
                LOGMMCTXP(LOGL_ERROR, mm, "timer expired in unknown mode %u\n",
@@ -2257,25 +2274,28 @@
 static void pdpctx_timer_cb(void *_mm);


-static void pdpctx_timer_rearm(struct sgsn_pdp_ctx *pdp, unsigned int T, 
unsigned int seconds)
+static void pdpctx_timer_rearm(struct sgsn_pdp_ctx *pdp, unsigned int T)
 {
+       unsigned long seconds;
        if (osmo_timer_pending(&pdp->timer))
                LOGPDPCTXP(LOGL_ERROR, pdp, "Scheduling PDP timer %u while old "
                        "timer %u pending\n", T, pdp->T);
+       seconds = osmo_tdef_get(sgsn->cfg.T_defs, T, OSMO_TDEF_S, -1);
        osmo_timer_schedule(&pdp->timer, seconds, 0);
 }

-static void pdpctx_timer_start(struct sgsn_pdp_ctx *pdp, unsigned int T,
-                               unsigned int seconds)
+static void pdpctx_timer_start(struct sgsn_pdp_ctx *pdp, unsigned int T)
 {
+
        if (osmo_timer_pending(&pdp->timer))
                LOGPDPCTXP(LOGL_ERROR, pdp, "Starting PDP timer %u while old "
                        "timer %u pending\n", T, pdp->T);
+
        pdp->T = T;
        pdp->num_T_exp = 0;

        osmo_timer_setup(&pdp->timer, pdpctx_timer_cb, pdp);
-       pdpctx_timer_rearm(pdp, pdp->T, seconds);
+       pdpctx_timer_rearm(pdp, pdp->T);
 }

 static void pdpctx_timer_stop(struct sgsn_pdp_ctx *pdp, unsigned int T)
@@ -2412,7 +2432,7 @@
 }
 int gsm48_tx_gsm_deact_pdp_req(struct sgsn_pdp_ctx *pdp, uint8_t sm_cause, 
bool teardown)
 {
-       pdpctx_timer_start(pdp, 3395, sgsn->cfg.timers.T3395);
+       pdpctx_timer_start(pdp, 3395);

        return _gsm48_tx_gsm_deact_pdp_req(pdp->mm, pdp->ti, sm_cause, 
teardown);
 }
@@ -2828,7 +2848,7 @@
                        break;
                }
                _gsm48_tx_gsm_deact_pdp_req(pdp->mm, pdp->ti, 
GSM_CAUSE_NET_FAIL, true);
-               pdpctx_timer_rearm(pdp, 3395, sgsn->cfg.timers.T3395);
+               pdpctx_timer_rearm(pdp, 3395);
                break;
        default:
                LOGPDPCTXP(LOGL_ERROR, pdp, "timer expired in unknown mode 
%u\n",
diff --git a/src/gprs/gprs_gmm_attach.c b/src/gprs/gprs_gmm_attach.c
index 84a2cf5..39efb0d 100644
--- a/src/gprs/gprs_gmm_attach.c
+++ b/src/gprs/gprs_gmm_attach.c
@@ -1,3 +1,5 @@
+#include <osmocom/core/tdef.h>
+
 #include <osmocom/sgsn/gprs_gmm_attach.h>

 #include <osmocom/gsm/protocol/gsm_04_08_gprs.h>
@@ -10,6 +12,18 @@
 static int require_identity_imei = 1;
 static int require_auth = 1;

+static const struct osmo_tdef_state_timeout gmm_attach_fsm_timeouts[] = {
+       [ST_IDENTIY] = { .T=3370 },
+       [ST_AUTH] = { .T=3360 },
+       [ST_ACCEPT] = { .T=3350 },
+       [ST_ASK_VLR] = { .T=3350 },
+       [ST_IU_SECURITY_CMD] = { .T=3350 },
+};
+
+#define gmm_attach_fsm_state_chg(fi, NEXT_STATE) \
+       osmo_tdef_fsm_inst_state_chg(fi, NEXT_STATE, gmm_attach_fsm_timeouts, 
sgsn->cfg.T_defs, -1)
+
+
 static void st_init(struct osmo_fsm_inst *fi, uint32_t event, void *data)
 {
        struct sgsn_mm_ctx *ctx = fi->priv;
@@ -33,14 +47,14 @@

        if (require_identity_imei) {
                ctx->gmm_att_req.id_type = GSM_MI_TYPE_IMEI;
-               osmo_fsm_inst_state_chg(fi, ST_IDENTIY, sgsn->cfg.timers.T3370, 
3370);
+               gmm_attach_fsm_state_chg(fi, ST_IDENTIY);
        } else if (!strlen(ctx->imsi)) {
                ctx->gmm_att_req.id_type = GSM_MI_TYPE_IMSI;
-               osmo_fsm_inst_state_chg(fi, ST_IDENTIY, sgsn->cfg.timers.T3370, 
3370);
+               gmm_attach_fsm_state_chg(fi, ST_IDENTIY);
        } else if (require_auth)
-               osmo_fsm_inst_state_chg(fi, ST_AUTH, sgsn->cfg.timers.T3360, 
3360);
+               gmm_attach_fsm_state_chg(fi, ST_AUTH);
        else
-               osmo_fsm_inst_state_chg(fi, ST_ACCEPT, sgsn->cfg.timers.T3350, 
3350);
+               gmm_attach_fsm_state_chg(fi, ST_ACCEPT);
 }

 static void st_identity_on_enter(struct osmo_fsm_inst *fi, uint32_t prev_state)
@@ -94,11 +108,11 @@

        if (type == GSM_MI_TYPE_IMEI && !strlen(ctx->imsi)) {
                ctx->gmm_att_req.id_type = GSM_MI_TYPE_IMSI;
-               osmo_fsm_inst_state_chg(fi, ST_IDENTIY, sgsn->cfg.timers.T3370, 
3370);
+               gmm_attach_fsm_state_chg(fi, ST_IDENTIY);
        } else if (require_auth)
-               osmo_fsm_inst_state_chg(fi, ST_AUTH, sgsn->cfg.timers.T3360, 
3360);
+               gmm_attach_fsm_state_chg(fi, ST_AUTH);
        else
-               osmo_fsm_inst_state_chg(fi, ST_ACCEPT, sgsn->cfg.timers.T3350, 
3350);
+               gmm_attach_fsm_state_chg(fi, ST_ACCEPT);
 }

 static void st_auth_on_enter(struct osmo_fsm_inst *fi, uint32_t prev_state)
@@ -124,19 +138,19 @@
        switch(auth_state) {
        case SGSN_AUTH_UMTS_RESYNC: /* ask the vlr for a new vector to match 
the simcards seq */
        case SGSN_AUTH_UNKNOWN: /* the SGSN doesn know this MS */
-               osmo_fsm_inst_state_chg(fi, ST_ASK_VLR, sgsn->cfg.timers.T3350, 
3350);
+               gmm_attach_fsm_state_chg(fi, ST_ASK_VLR);
                break;
        case SGSN_AUTH_REJECTED:
                /* TODO: correct GMM cause */
                osmo_fsm_inst_dispatch(fi, E_REJECT, (void *) 
GMM_CAUSE_GPRS_NOTALLOWED);
                break;
        case SGSN_AUTH_ACCEPTED:
-               osmo_fsm_inst_state_chg(fi, ST_ACCEPT, sgsn->cfg.timers.T3350, 
3350);
+               gmm_attach_fsm_state_chg(fi, ST_ACCEPT);
                break;
        case SGSN_AUTH_AUTHENTICATE:
                if (ctx->auth_triplet.key_seq == GSM_KEY_SEQ_INVAL) {
                        /* invalid key material */
-                       osmo_fsm_inst_state_chg(fi, ST_ASK_VLR, 
sgsn->cfg.timers.T3350, 3350);
+                       gmm_attach_fsm_state_chg(fi, ST_ASK_VLR);
                }

                struct gsm_auth_tuple *at = &ctx->auth_triplet;
@@ -159,14 +173,14 @@
                sgsn_auth_request(ctx);
 #ifdef BUILD_IU
                if (ctx->ran_type == MM_CTX_T_UTRAN_Iu && 
!ctx->iu.ue_ctx->integrity_active)
-                       osmo_fsm_inst_state_chg(fi, ST_IU_SECURITY_CMD, 
sgsn->cfg.timers.T3350, 3350);
+                       gmm_attach_fsm_state_chg(fi, ST_IU_SECURITY_CMD);
                else
 #endif /* BUILD_IU */
-                       osmo_fsm_inst_state_chg(fi, ST_ACCEPT, 
sgsn->cfg.timers.T3350, 3350);
+                       gmm_attach_fsm_state_chg(fi, ST_ACCEPT);
                break;
        case E_AUTH_RESP_RECV_RESYNC:
                if (ctx->gmm_att_req.auth_reattempt <= 1)
-                       osmo_fsm_inst_state_chg(fi, ST_ASK_VLR, 
sgsn->cfg.timers.T3350, 3350);
+                       gmm_attach_fsm_state_chg(fi, ST_ASK_VLR);
                else
                        osmo_fsm_inst_dispatch(fi, E_REJECT, (void *) 
GMM_CAUSE_SYNC_FAIL);
                break;
@@ -234,7 +248,7 @@
 {
        switch(event) {
        case E_VLR_ANSWERED:
-               osmo_fsm_inst_state_chg(fi, ST_AUTH, sgsn->cfg.timers.T3360, 
3360);
+               gmm_attach_fsm_state_chg(fi, ST_AUTH);
                break;
        }
 }
@@ -246,7 +260,7 @@

        /* TODO: shouldn't this set always? not only when the integrity_active? 
*/
        if (ctx->iu.ue_ctx->integrity_active) {
-               osmo_fsm_inst_state_chg(fi, ST_ACCEPT, sgsn->cfg.timers.T3350, 
3350);
+               gmm_attach_fsm_state_chg(fi, ST_ACCEPT);
                return;
        }

@@ -259,7 +273,7 @@
 {
        switch(event) {
        case E_IU_SECURITY_CMD_COMPLETE:
-               osmo_fsm_inst_state_chg(fi, ST_ACCEPT, sgsn->cfg.timers.T3350, 
3350);
+               gmm_attach_fsm_state_chg(fi, ST_ACCEPT);
                break;
        }
 }
@@ -373,6 +387,7 @@
 {
        struct sgsn_mm_ctx *ctx = fi->priv;
        struct gsm_auth_tuple *at = &ctx->auth_triplet;
+       unsigned long t_secs;

        ctx->num_T_exp++;

@@ -392,7 +407,9 @@
                        break;
                }
                gsm48_tx_gmm_id_req(ctx, ctx->gmm_att_req.id_type);
-               osmo_timer_schedule(&fi->timer, sgsn->cfg.timers.T3370, 0);
+               t_secs = osmo_tdef_get(sgsn->cfg.T_defs, 3370, OSMO_TDEF_S, -1);
+               osmo_timer_schedule(&fi->timer, t_secs, 0);
+
                break;
        case ST_AUTH:
                /* T3360 */
@@ -401,7 +418,8 @@
                        break;
                }
                gsm48_tx_gmm_auth_ciph_req(ctx, &at->vec, at->key_seq, false);
-               osmo_timer_schedule(&fi->timer, sgsn->cfg.timers.T3360, 0);
+               t_secs = osmo_tdef_get(sgsn->cfg.T_defs, 3360, OSMO_TDEF_S, -1);
+               osmo_timer_schedule(&fi->timer, t_secs, 0);
                break;
        case ST_ACCEPT:
                /* T3350 */
@@ -410,7 +428,8 @@
                        break;
                }
                gsm48_tx_gmm_att_ack(ctx);
-               osmo_timer_schedule(&fi->timer, sgsn->cfg.timers.T3350, 0);
+               t_secs = osmo_tdef_get(sgsn->cfg.T_defs, 3350, OSMO_TDEF_S, -1);
+               osmo_timer_schedule(&fi->timer, t_secs, 0);
                break;
        }

diff --git a/src/gprs/sgsn_vty.c b/src/gprs/sgsn_vty.c
index d1d53e6..ae26cbe 100644
--- a/src/gprs/sgsn_vty.c
+++ b/src/gprs/sgsn_vty.c
@@ -28,6 +28,7 @@
 #include <osmocom/core/talloc.h>
 #include <osmocom/core/utils.h>
 #include <osmocom/core/rate_ctr.h>
+#include <osmocom/core/tdef.h>
 #include <osmocom/gsm/protocol/gsm_04_08_gprs.h>
 #include <osmocom/gsm/apn.h>

@@ -39,6 +40,7 @@
 #include <osmocom/sgsn/vty.h>
 #include <osmocom/gsupclient/gsup_client.h>
 
+#include <osmocom/vty/tdef_vty.h>
 #include <osmocom/vty/command.h>
 #include <osmocom/vty/vty.h>
 #include <osmocom/vty/misc.h>
@@ -88,39 +90,42 @@
 #define GSM0408_T3395_SECS     8       /* wait for DEACT PDP CTX ACK */
 #define GSM0408_T3397_SECS     8       /* wait for DEACT AA PDP CTX ACK */

-#define DECLARE_TIMER(number, doc) \
-    DEFUN(cfg_sgsn_T##number,                                  \
-      cfg_sgsn_T##number##_cmd,                                        \
-      "timer t" #number  " <0-65535>",                         \
-      "Configure GPRS Timers\n"                                        \
-      doc "\nTimer Value in seconds\n")                                \
-{                                                              \
-       int value = atoi(argv[0]);                              \
-                                                               \
-       if (value < 0 || value > 65535) {                       \
-               vty_out(vty, "Timer value %s out of range.%s",  \
-                       argv[0], VTY_NEWLINE);                  \
-               return CMD_WARNING;                             \
-       }                                                       \
-                                                               \
-       g_cfg->timers.T##number = value;                        \
-       return CMD_SUCCESS;                                     \
+
+static struct osmo_tdef sgsn_T_defs[] = {
+       { .T=3312, .default_val=GSM0408_T3312_SECS, .desc="Periodic RA Update 
timer (s)" },
+       { .T=3313, .default_val=GSM0408_T3313_SECS, .desc="Waiting for paging 
response timer (s)" },
+       { .T=3314, .default_val=GSM0408_T3314_SECS, .desc="Force to STANDBY on 
expiry timer (s)" },
+       { .T=3316, .default_val=GSM0408_T3316_SECS, .desc="AA-Ready timer (s)" 
},
+       { .T=3322, .default_val=GSM0408_T3322_SECS, .desc="Detach request -> 
accept timer (s)" },
+       { .T=3350, .default_val=GSM0408_T3350_SECS, .desc="Waiting for 
ATT/RAU/TMSI_COMPL timer (s)" },
+       { .T=3360, .default_val=GSM0408_T3360_SECS, .desc="Waiting for 
AUTH/CIPH response timer (s)" },
+       { .T=3370, .default_val=GSM0408_T3370_SECS, .desc="Waiting for IDENTITY 
response timer (s)" },
+       { .T=3385, .default_val=GSM0408_T3385_SECS, .desc="Wait for ACT PDP CTX 
REQ timer (s)" },
+       { .T=3386, .default_val=GSM0408_T3386_SECS, .desc="Wait for MODIFY PDP 
CTX ACK timer (s)" },
+       { .T=3395, .default_val=GSM0408_T3395_SECS, .desc="Wait for DEACT PDP 
CTX ACK timer (s)" },
+       { .T=3397, .default_val=GSM0408_T3397_SECS, .desc="Wait for DEACT AA 
PDP CTX ACK timer (s)" },
+       {}
+};
+
+DEFUN(show_timer, show_timer_cmd,
+      "show timer " OSMO_TDEF_VTY_ARG_T_OPTIONAL,
+      SHOW_STR "Show timers\n"
+      OSMO_TDEF_VTY_DOC_T)
+{
+       const char *T_arg = argc > 0 ? argv[0] : NULL;
+       return osmo_tdef_vty_show_cmd(vty, g_cfg->T_defs, T_arg, NULL);
 }

-DECLARE_TIMER(3312, "Periodic RA Update timer (s)")
-DECLARE_TIMER(3322, "Detach request -> accept timer (s)")
-DECLARE_TIMER(3350, "Waiting for ATT/RAU/TMSI_COMPL timer (s)")
-DECLARE_TIMER(3360, "Waiting for AUTH/CIPH response timer (s)")
-DECLARE_TIMER(3370, "Waiting for IDENTITY response timer (s)")
-
-DECLARE_TIMER(3313, "Waiting for paging response timer (s)")
-DECLARE_TIMER(3314, "Force to STANDBY on expiry timer (s)")
-DECLARE_TIMER(3316, "AA-Ready timer (s)")
-
-DECLARE_TIMER(3385, "Wait for ACT PDP CTX REQ timer (s)")
-DECLARE_TIMER(3386, "Wait for MODIFY PDP CTX ACK timer (s)")
-DECLARE_TIMER(3395, "Wait for DEACT PDP CTX ACK timer (s)")
-DECLARE_TIMER(3397, "Wait for DEACT AA PDP CTX ACK timer (s)")
+DEFUN(cfg_sgsn_timer, cfg_sgsn_timer_cmd,
+      "timer " OSMO_TDEF_VTY_ARG_SET_OPTIONAL,
+      "Configure or show timers\n"
+      OSMO_TDEF_VTY_DOC_SET)
+{
+       /* If any arguments are missing, redirect to 'show' */
+       if (argc < 2)
+               return show_timer(self, vty, argc, argv);
+       return osmo_tdef_vty_set_cmd(vty, g_cfg->T_defs, argv);
+}

 char *gprs_pdpaddr2str(uint8_t *pdpa, uint8_t len)
 {
@@ -253,18 +258,7 @@
                vty_out(vty, " no cdr trap%s", VTY_NEWLINE);
        vty_out(vty, " cdr interval %d%s", g_cfg->cdr.interval, VTY_NEWLINE);

-       vty_out(vty, " timer t3312 %d%s", g_cfg->timers.T3312, VTY_NEWLINE);
-       vty_out(vty, " timer t3322 %d%s", g_cfg->timers.T3322, VTY_NEWLINE);
-       vty_out(vty, " timer t3350 %d%s", g_cfg->timers.T3350, VTY_NEWLINE);
-       vty_out(vty, " timer t3360 %d%s", g_cfg->timers.T3360, VTY_NEWLINE);
-       vty_out(vty, " timer t3370 %d%s", g_cfg->timers.T3370, VTY_NEWLINE);
-       vty_out(vty, " timer t3313 %d%s", g_cfg->timers.T3313, VTY_NEWLINE);
-       vty_out(vty, " timer t3314 %d%s", g_cfg->timers.T3314, VTY_NEWLINE);
-       vty_out(vty, " timer t3316 %d%s", g_cfg->timers.T3316, VTY_NEWLINE);
-       vty_out(vty, " timer t3385 %d%s", g_cfg->timers.T3385, VTY_NEWLINE);
-       vty_out(vty, " timer t3386 %d%s", g_cfg->timers.T3386, VTY_NEWLINE);
-       vty_out(vty, " timer t3395 %d%s", g_cfg->timers.T3395, VTY_NEWLINE);
-       vty_out(vty, " timer t3397 %d%s", g_cfg->timers.T3397, VTY_NEWLINE);
+       osmo_tdef_vty_write(vty, g_cfg->T_defs, " timer ");

        if (g_cfg->pcomp_rfc1144.active) {
                vty_out(vty, " compression rfc1144 active slots %d%s",
@@ -1388,12 +1382,16 @@
 {
        g_cfg = cfg;

+       g_cfg->T_defs = sgsn_T_defs;
+       osmo_tdefs_reset(g_cfg->T_defs);
+
        install_element_ve(&show_sgsn_cmd);
        //install_element_ve(&show_mmctx_tlli_cmd);
        install_element_ve(&show_mmctx_imsi_cmd);
        install_element_ve(&show_mmctx_all_cmd);
        install_element_ve(&show_pdpctx_all_cmd);
        install_element_ve(&show_subscr_cache_cmd);
+       install_element_ve(&show_timer_cmd);

        install_element(ENABLE_NODE, &update_subscr_insert_auth_triplet_cmd);
        install_element(ENABLE_NODE, &update_subscr_create_cmd);
@@ -1433,18 +1431,7 @@
        install_element(SGSN_NODE, &cfg_ggsn_dynamic_lookup_cmd);
        install_element(SGSN_NODE, &cfg_grx_ggsn_cmd);

-       install_element(SGSN_NODE, &cfg_sgsn_T3312_cmd);
-       install_element(SGSN_NODE, &cfg_sgsn_T3322_cmd);
-       install_element(SGSN_NODE, &cfg_sgsn_T3350_cmd);
-       install_element(SGSN_NODE, &cfg_sgsn_T3360_cmd);
-       install_element(SGSN_NODE, &cfg_sgsn_T3370_cmd);
-       install_element(SGSN_NODE, &cfg_sgsn_T3313_cmd);
-       install_element(SGSN_NODE, &cfg_sgsn_T3314_cmd);
-       install_element(SGSN_NODE, &cfg_sgsn_T3316_cmd);
-       install_element(SGSN_NODE, &cfg_sgsn_T3385_cmd);
-       install_element(SGSN_NODE, &cfg_sgsn_T3386_cmd);
-       install_element(SGSN_NODE, &cfg_sgsn_T3395_cmd);
-       install_element(SGSN_NODE, &cfg_sgsn_T3397_cmd);
+       install_element(SGSN_NODE, &cfg_sgsn_timer_cmd);

        install_element(SGSN_NODE, &cfg_no_comp_rfc1144_cmd);
        install_element(SGSN_NODE, &cfg_comp_rfc1144_cmd);
@@ -1466,19 +1453,6 @@
        /* make sure sgsn_vty_init() was called before this */
        OSMO_ASSERT(g_cfg);

-       g_cfg->timers.T3312 = GSM0408_T3312_SECS;
-       g_cfg->timers.T3322 = GSM0408_T3322_SECS;
-       g_cfg->timers.T3350 = GSM0408_T3350_SECS;
-       g_cfg->timers.T3360 = GSM0408_T3360_SECS;
-       g_cfg->timers.T3370 = GSM0408_T3370_SECS;
-       g_cfg->timers.T3313 = GSM0408_T3313_SECS;
-       g_cfg->timers.T3314 = GSM0408_T3314_SECS;
-       g_cfg->timers.T3316 = GSM0408_T3316_SECS;
-       g_cfg->timers.T3385 = GSM0408_T3385_SECS;
-       g_cfg->timers.T3386 = GSM0408_T3386_SECS;
-       g_cfg->timers.T3395 = GSM0408_T3395_SECS;
-       g_cfg->timers.T3397 = GSM0408_T3397_SECS;
-
        rc = vty_read_config_file(config_file, NULL);
        if (rc < 0) {
                fprintf(stderr, "Failed to parse the config file: '%s'\n", 
config_file);

--
To view, visit https://gerrit.osmocom.org/c/osmo-sgsn/+/15214
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-sgsn
Gerrit-Branch: master
Gerrit-Change-Id: Ia0cf5f0a49737fbc419e2ccc86312d01c6e0056e
Gerrit-Change-Number: 15214
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pes...@sysmocom.de>
Gerrit-MessageType: newchange

Reply via email to