Change in libosmocore[master]: gprs_ns2_sns: refactor SNS failures into a function

laforge gerrit-no-reply at lists.osmocom.org
Fri Aug 13 09:55:52 UTC 2021


laforge has submitted this change. ( 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, 25 insertions(+), 10 deletions(-)

Approvals:
  laforge: Looks good to me, but someone else must approve
  daniel: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/gb/gprs_ns2_sns.c b/src/gb/gprs_ns2_sns.c
index 367f77c..5e43d8c 100644
--- a/src/gb/gprs_ns2_sns.c
+++ b/src/gb/gprs_ns2_sns.c
@@ -171,6 +171,26 @@
 	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) {
+		if (!gss->nse->persistent)
+			gprs_ns2_free_nse(gss->nse);
+		else
+			_osmo_fsm_inst_state_chg(fi, GPRS_SNS_ST_UNCONFIGURED, 0, 0, file, line);
+	} 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 +1447,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 +1589,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: 5
Gerrit-Owner: lynxis lazus <lynxis at fe80.eu>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: lynxis lazus <lynxis at fe80.eu>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210813/5d93bf79/attachment.htm>


More information about the gerrit-log mailing list