lynxis lazus has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/libosmocore/+/24649 )


Change subject: gprs_ns2_sns: refactor SNS failures into a function
......................................................................

gprs_ns2_sns: refactor SNS failures into a function

The SNS fsm is similar for BSS and SGSN.
Terminate the SGSN failures by freeing the NSE.

Change-Id: I1896f6c3ddb4f98ca261139c1cc77aa8f1558c6f
---
M src/gb/gprs_ns2_sns.c
1 file changed, 21 insertions(+), 10 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/49/24649/1

diff --git a/src/gb/gprs_ns2_sns.c b/src/gb/gprs_ns2_sns.c
index 367f77c..c2d5a96 100644
--- a/src/gb/gprs_ns2_sns.c
+++ b/src/gb/gprs_ns2_sns.c
@@ -171,6 +171,22 @@
        return gss->nse;
 }

+/* The SNS has failed. Etither restart the SNS (BSS) or remove the SNS (SGSN) 
*/
+#define sns_failed(fi, reason) \
+       _sns_failed(fi, reason, __FILE__, __LINE__)
+static void _sns_failed(struct osmo_fsm_inst *fi, const char *reason, const 
char *file, int line)
+{
+       struct ns2_sns_state *gss = fi->priv;
+
+       if (reason)
+               LOGPFSML(fi, LOGL_ERROR, "NSE %d: SNS failed: %s\n", 
gss->nse->nsei, reason);
+       if (gss->role == GPRS_SNS_ROLE_SGSN) {
+               gprs_ns2_free_nse(gss->nse);
+       } else {
+               _osmo_fsm_inst_dispatch(fi, GPRS_SNS_EV_REQ_SELECT_ENDPOINT, 
NULL, file, line);
+       }
+}
+
 /* helper function to compute the sum of all (data or signaling) weights */
 static int ip4_weight_sum(const struct ns2_sns_elems *elems, bool data_weight)
 {
@@ -1427,31 +1443,27 @@
        switch (fi->T) {
        case 1:
                if (gss->N >= nsi->timeout[NS_TOUT_TSNS_SIZE_RETRIES]) {
-                       LOGPFSML(fi, LOGL_ERROR, "NSE %d: Size retries failed. 
Selecting next IP-SNS endpoint.\n", nse->nsei);
-                       osmo_fsm_inst_dispatch(fi, 
GPRS_SNS_EV_REQ_SELECT_ENDPOINT, NULL);
+                       sns_failed(fi, "Size retries failed. Selecting next 
IP-SNS endpoint.");
                } else {
                        osmo_fsm_inst_state_chg(fi, GPRS_SNS_ST_BSS_SIZE, 
nsi->timeout[NS_TOUT_TSNS_PROV], 1);
                }
                break;
        case 2:
                if (gss->N >= nsi->timeout[NS_TOUT_TSNS_CONFIG_RETRIES]) {
-                       LOGPFSML(fi, LOGL_ERROR, "NSE %d: BSS Config retries 
failed. Selecting next IP-SNS endpoint.\n", nse->nsei);
-                       osmo_fsm_inst_dispatch(fi, 
GPRS_SNS_EV_REQ_SELECT_ENDPOINT, NULL);
+                       sns_failed(fi, "BSS Config retries failed. Selecting 
next IP-SNS endpoint");
                } else {
                        osmo_fsm_inst_state_chg(fi, GPRS_SNS_ST_BSS_CONFIG_BSS, 
nsi->timeout[NS_TOUT_TSNS_PROV], 2);
                }
                break;
        case 3:
                if (gss->N >= nsi->timeout[NS_TOUT_TSNS_CONFIG_RETRIES]) {
-                       LOGPFSML(fi, LOGL_ERROR, "NSE %d: SGSN Config retries 
failed. Selecting next IP-SNS endpoint.\n", nse->nsei);
-                       osmo_fsm_inst_dispatch(fi, 
GPRS_SNS_EV_REQ_SELECT_ENDPOINT, NULL);
+                       sns_failed(fi, "SGSN Config retries failed. Selecting 
next IP-SNS endpoint.");
                } else {
                        osmo_fsm_inst_state_chg(fi, 
GPRS_SNS_ST_BSS_CONFIG_SGSN, nsi->timeout[NS_TOUT_TSNS_PROV], 3);
                }
                break;
        case 4:
-               LOGPFSML(fi, LOGL_ERROR, "NSE %d: Config succeeded but no NS-VC 
came online. Selecting next IP-SNS endpoint.\n", nse->nsei);
-               osmo_fsm_inst_dispatch(fi, GPRS_SNS_EV_REQ_SELECT_ENDPOINT, 
NULL);
+               sns_failed(fi, "Config succeeded but no NS-VC came online. 
Selecting next IP-SNS endpoint.");
                break;
        }
        return 0;
@@ -1573,8 +1585,7 @@
                if (gss->reselection_running)
                        break;

-               LOGPFSML(fi, LOGL_ERROR, "NSE %d: no remaining NSVC, resetting 
SNS FSM\n", nse->nsei);
-               osmo_fsm_inst_dispatch(fi, GPRS_SNS_EV_REQ_SELECT_ENDPOINT, 
NULL);
+               sns_failed(fi, "no remaining NSVC, resetting SNS FSM");
                break;
        case GPRS_SNS_EV_REQ_SELECT_ENDPOINT:
                /* tear down previous state

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I1896f6c3ddb4f98ca261139c1cc77aa8f1558c6f
Gerrit-Change-Number: 24649
Gerrit-PatchSet: 1
Gerrit-Owner: lynxis lazus <lyn...@fe80.eu>
Gerrit-MessageType: newchange

Reply via email to