Change in osmo-bts[master]: Introduce NM BTS FSM

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

laforge gerrit-no-reply at lists.osmocom.org
Tue Oct 20 13:45:58 UTC 2020


laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-bts/+/20409 )

Change subject: Introduce NM BTS FSM
......................................................................

Introduce NM BTS FSM

Change-Id: Iae631bcc7acdf955296b124707e42d5e565af186
---
M include/osmo-bts/nm_common_fsm.h
M src/common/Makefile.am
M src/common/bts.c
A src/common/nm_bts_fsm.c
M src/osmo-bts-litecell15/oml.c
M src/osmo-bts-oc2g/oml.c
M src/osmo-bts-octphy/l1_oml.c
M src/osmo-bts-omldummy/bts_model.c
M src/osmo-bts-sysmo/oml.c
M src/osmo-bts-trx/l1_if.c
M src/osmo-bts-virtual/bts_model.c
11 files changed, 194 insertions(+), 24 deletions(-)

Approvals:
  laforge: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/include/osmo-bts/nm_common_fsm.h b/include/osmo-bts/nm_common_fsm.h
index bd8f8c1..93e4bde 100644
--- a/include/osmo-bts/nm_common_fsm.h
+++ b/include/osmo-bts/nm_common_fsm.h
@@ -42,3 +42,11 @@
 	NM_BTS_SM_ST_OP_ENABLED,
 };
 extern struct osmo_fsm nm_bts_sm_fsm;
+
+/* BTS */
+enum nm_bts_op_fsm_states {
+	NM_BTS_ST_OP_DISABLED_NOTINSTALLED,
+	NM_BTS_ST_OP_DISABLED_OFFLINE,
+	NM_BTS_ST_OP_ENABLED,
+};
+extern struct osmo_fsm nm_bts_fsm;
diff --git a/src/common/Makefile.am b/src/common/Makefile.am
index 458041e..463797e 100644
--- a/src/common/Makefile.am
+++ b/src/common/Makefile.am
@@ -39,6 +39,7 @@
 	ta_control.c \
 	nm_common_fsm.c \
 	nm_bts_sm_fsm.c \
+	nm_bts_fsm.c \
 	$(NULL)
 
 libl1sched_a_SOURCES = scheduler.c
diff --git a/src/common/bts.c b/src/common/bts.c
index 0770640..6fc0cb8 100644
--- a/src/common/bts.c
+++ b/src/common/bts.c
@@ -207,6 +207,10 @@
 		osmo_fsm_inst_free(bts->site_mgr.mo.fi);
 		bts->site_mgr.mo.fi = NULL;
 	}
+	if (bts->mo.fi) {
+		osmo_fsm_inst_free(bts->mo.fi);
+		bts->mo.fi = NULL;
+	}
 	return 0;
 }
 
@@ -236,8 +240,10 @@
 	gsm_mo_init(&bts->site_mgr.mo, bts, NM_OC_SITE_MANAGER,
 		    0xff, 0xff, 0xff);
 
-	gsm_mo_init(&bts->mo, bts, NM_OC_BTS,
-			bts->nr, 0xff, 0xff);
+	bts->mo.fi = osmo_fsm_inst_alloc(&nm_bts_fsm, bts, bts,
+					 LOGL_INFO, NULL);
+	osmo_fsm_inst_update_id_f(bts->mo.fi, "bts%d", bts->nr);
+	gsm_mo_init(&bts->mo, bts, NM_OC_BTS, bts->nr, 0xff, 0xff);
 
 	for (i = 0; i < ARRAY_SIZE(bts->gprs.nsvc); i++) {
 		bts->gprs.nsvc[i].bts = bts;
@@ -347,9 +353,9 @@
 
 	/* Start with the site manager */
 	oml_mo_state_init(&bts->site_mgr.mo, NM_OPSTATE_DISABLED, NM_AVSTATE_NOT_INSTALLED);
+	oml_mo_state_init(&bts->mo, NM_OPSTATE_DISABLED, NM_AVSTATE_NOT_INSTALLED);
 
-	/* set BTS to dependency */
-	oml_mo_state_init(&bts->mo, -1, NM_AVSTATE_DEPENDENCY);
+	/* set BTS attr to dependency */
 	oml_mo_state_init(&bts->gprs.nse.mo, -1, NM_AVSTATE_DEPENDENCY);
 	oml_mo_state_init(&bts->gprs.cell.mo, -1, NM_AVSTATE_DEPENDENCY);
 	oml_mo_state_init(&bts->gprs.nsvc[0].mo, -1, NM_AVSTATE_DEPENDENCY);
@@ -412,7 +418,7 @@
 
 	/* BTS SITE MGR becomes Offline (tx SW ACT Report), BTS is DEPENDENCY */
 	osmo_fsm_inst_dispatch(bts->site_mgr.mo.fi, NM_EV_SW_ACT, NULL);
-	oml_tx_state_changed(&bts->mo);
+	osmo_fsm_inst_dispatch(bts->mo.fi, NM_EV_SW_ACT, NULL);
 
 	/* those should all be in DEPENDENCY */
 	oml_tx_state_changed(&bts->gprs.nse.mo);
diff --git a/src/common/nm_bts_fsm.c b/src/common/nm_bts_fsm.c
new file mode 100644
index 0000000..12f1a61
--- /dev/null
+++ b/src/common/nm_bts_fsm.c
@@ -0,0 +1,145 @@
+/* NM BTS FSM */
+
+/* (C) 2020 by sysmocom - s.m.f.c. GmbH <info at sysmocom.de>
+ * Author: Pau Espin Pedrol <pespin at sysmocom.de>
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <errno.h>
+#include <unistd.h>
+#include <inttypes.h>
+
+#include <osmocom/core/fsm.h>
+#include <osmocom/core/tdef.h>
+#include <osmocom/gsm/protocol/gsm_12_21.h>
+
+#include <osmo-bts/logging.h>
+#include <osmo-bts/gsm_data.h>
+#include <osmo-bts/bts_model.h>
+#include <osmo-bts/bts.h>
+#include <osmo-bts/rsl.h>
+#include <osmo-bts/nm_common_fsm.h>
+#include <osmo-bts/phy_link.h>
+
+#define X(s) (1 << (s))
+
+#define nm_bts_fsm_state_chg(fi, NEXT_STATE) \
+	osmo_fsm_inst_state_chg(fi, NEXT_STATE, 0, 0)
+
+//////////////////////////
+// FSM STATE ACTIONS
+//////////////////////////
+
+static void st_op_disabled_notinstalled_on_enter(struct osmo_fsm_inst *fi, uint32_t prev_state)
+{
+	struct gsm_bts *bts = (struct gsm_bts *)fi->priv;
+	bts->mo.opstart_success = false;
+	oml_mo_state_chg(&bts->mo, NM_OPSTATE_DISABLED, NM_AVSTATE_NOT_INSTALLED);
+}
+
+static void st_op_disabled_notinstalled(struct osmo_fsm_inst *fi, uint32_t event, void *data)
+{
+	struct gsm_bts *bts = (struct gsm_bts *)fi->priv;
+
+	switch (event) {
+	case NM_EV_SW_ACT:
+		oml_mo_tx_sw_act_rep(&bts->mo);
+		nm_bts_fsm_state_chg(fi, NM_BTS_ST_OP_DISABLED_OFFLINE);
+		return;
+	default:
+		OSMO_ASSERT(0);
+	}
+}
+
+static void st_op_disabled_offline_on_enter(struct osmo_fsm_inst *fi, uint32_t prev_state)
+{
+	struct gsm_bts *bts = (struct gsm_bts *)fi->priv;
+	bts->mo.opstart_success = false;
+	oml_mo_state_chg(&bts->mo, NM_OPSTATE_DISABLED, NM_AVSTATE_OFF_LINE);
+}
+
+static void st_op_disabled_offline(struct osmo_fsm_inst *fi, uint32_t event, void *data)
+{
+	struct gsm_bts *bts = (struct gsm_bts *)fi->priv;
+
+	switch (event) {
+	case NM_EV_OPSTART_ACK:
+		bts->mo.opstart_success = true;
+		oml_mo_opstart_ack(&bts->mo);
+		nm_bts_fsm_state_chg(fi, NM_BTS_ST_OP_ENABLED);
+		break; /* check statechg below */
+	case NM_EV_OPSTART_NACK:
+		bts->mo.opstart_success = false;
+		oml_mo_opstart_nack(&bts->mo, (int)(intptr_t)data);
+		return;
+	default:
+		OSMO_ASSERT(0);
+	}
+}
+
+static void st_op_enabled_on_enter(struct osmo_fsm_inst *fi, uint32_t prev_state)
+{
+	struct gsm_bts *bts = (struct gsm_bts *)fi->priv;
+	oml_mo_state_chg(&bts->mo, NM_OPSTATE_ENABLED, NM_AVSTATE_OK);
+}
+
+static void st_op_enabled(struct osmo_fsm_inst *fi, uint32_t event, void *data)
+{
+}
+
+static struct osmo_fsm_state nm_bts_fsm_states[] = {
+	[NM_BTS_ST_OP_DISABLED_NOTINSTALLED] = {
+		.in_event_mask =
+			X(NM_EV_SW_ACT),
+		.out_state_mask =
+			X(NM_BTS_ST_OP_DISABLED_OFFLINE),
+		.name = "DISABLED_NOTINSTALLED",
+		.onenter = st_op_disabled_notinstalled_on_enter,
+		.action = st_op_disabled_notinstalled,
+	},
+	[NM_BTS_ST_OP_DISABLED_OFFLINE] = {
+		.in_event_mask =
+			X(NM_EV_OPSTART_ACK) |
+			X(NM_EV_OPSTART_NACK),
+		.out_state_mask =
+			X(NM_BTS_ST_OP_ENABLED),
+		.name = "DISABLED_OFFLINE",
+		.onenter = st_op_disabled_offline_on_enter,
+		.action = st_op_disabled_offline,
+	},
+	[NM_BTS_ST_OP_ENABLED] = {
+		.in_event_mask = 0,
+		.out_state_mask = 0,
+		.name = "ENABLED",
+		.onenter = st_op_enabled_on_enter,
+		.action = st_op_enabled,
+	},
+};
+
+struct osmo_fsm nm_bts_fsm = {
+	.name = "NM_BTS_OP",
+	.states = nm_bts_fsm_states,
+	.num_states = ARRAY_SIZE(nm_bts_fsm_states),
+	.event_names = nm_fsm_event_names,
+	.log_subsys = DOML,
+};
+
+static __attribute__((constructor)) void nm_bts_fsm_init(void)
+{
+	OSMO_ASSERT(osmo_fsm_register(&nm_bts_fsm) == 0);
+}
diff --git a/src/osmo-bts-litecell15/oml.c b/src/osmo-bts-litecell15/oml.c
index 6ae0492..03f787b 100644
--- a/src/osmo-bts-litecell15/oml.c
+++ b/src/osmo-bts-litecell15/oml.c
@@ -1891,13 +1891,15 @@
 	case NM_OC_SITE_MANAGER:
 		rc = osmo_fsm_inst_dispatch(bts->site_mgr.mo.fi, NM_EV_OPSTART_ACK, NULL);
 		break;
+	case NM_OC_BTS:
+		rc = osmo_fsm_inst_dispatch(bts->mo.fi, NM_EV_OPSTART_ACK, NULL);
+		break;
 	case NM_OC_RADIO_CARRIER:
 		rc = trx_init(obj);
 		break;
 	case NM_OC_CHANNEL:
 		rc = ts_opstart(obj);
 		break;
-	case NM_OC_BTS:
 	case NM_OC_BASEB_TRANSC:
 	case NM_OC_GPRS_NSE:
 	case NM_OC_GPRS_CELL:
diff --git a/src/osmo-bts-oc2g/oml.c b/src/osmo-bts-oc2g/oml.c
index 8dda1e9..15513d1 100644
--- a/src/osmo-bts-oc2g/oml.c
+++ b/src/osmo-bts-oc2g/oml.c
@@ -1900,25 +1900,25 @@
 	case NM_OC_SITE_MANAGER:
 		rc = osmo_fsm_inst_dispatch(bts->site_mgr.mo.fi, NM_EV_OPSTART_ACK, NULL);
 		break;
+	case NM_OC_BTS:
+		rc = osmo_fsm_inst_dispatch(bts->mo.fi, NM_EV_OPSTART_ACK, NULL);
+		oml_mo_state_chg(&bts->mo, -1, NM_AVSTATE_OK);
+		oml_mo_state_chg(&bts->gprs.nse.mo, -1, NM_AVSTATE_OK);
+		oml_mo_state_chg(&bts->gprs.cell.mo, -1, NM_AVSTATE_OK);
+		oml_mo_state_chg(&bts->gprs.nsvc[0].mo, -1, NM_AVSTATE_OK);
+		break;
 	case NM_OC_RADIO_CARRIER:
 		rc = trx_init(obj);
 		break;
 	case NM_OC_CHANNEL:
 		rc = ts_opstart(obj);
 		break;
-	case NM_OC_BTS:
 	case NM_OC_BASEB_TRANSC:
 	case NM_OC_GPRS_NSE:
 	case NM_OC_GPRS_CELL:
 	case NM_OC_GPRS_NSVC:
 		oml_mo_state_chg(mo, NM_OPSTATE_ENABLED, -1);
 		rc = oml_mo_opstart_ack(mo);
-		if (mo->obj_class == NM_OC_BTS) {
-			oml_mo_state_chg(&bts->mo, -1, NM_AVSTATE_OK);
-			oml_mo_state_chg(&bts->gprs.nse.mo, -1, NM_AVSTATE_OK);
-			oml_mo_state_chg(&bts->gprs.cell.mo, -1, NM_AVSTATE_OK);
-			oml_mo_state_chg(&bts->gprs.nsvc[0].mo, -1, NM_AVSTATE_OK);
-		}
 		break;
 	default:
 		rc = oml_mo_opstart_nack(mo, NM_NACK_OBJCLASS_NOTSUPP);
diff --git a/src/osmo-bts-octphy/l1_oml.c b/src/osmo-bts-octphy/l1_oml.c
index be84466..2062be3 100644
--- a/src/osmo-bts-octphy/l1_oml.c
+++ b/src/osmo-bts-octphy/l1_oml.c
@@ -1770,6 +1770,9 @@
 	case NM_OC_SITE_MANAGER:
 		rc = osmo_fsm_inst_dispatch(bts->site_mgr.mo.fi, NM_EV_OPSTART_ACK, NULL);
 		break;
+	case NM_OC_BTS:
+		rc = osmo_fsm_inst_dispatch(bts->mo.fi, NM_EV_OPSTART_ACK, NULL);
+		break;
 	case NM_OC_RADIO_CARRIER:
 		rc = trx_init(obj);
 		break;
@@ -1777,7 +1780,6 @@
 		ts = (struct gsm_bts_trx_ts*) obj;
 		rc = ts_connect_as(ts, ts->pchan, pchan_act_compl_cb, NULL);
 		break;
-	case NM_OC_BTS:
 	case NM_OC_BASEB_TRANSC:
 	case NM_OC_GPRS_NSE:
 	case NM_OC_GPRS_CELL:
diff --git a/src/osmo-bts-omldummy/bts_model.c b/src/osmo-bts-omldummy/bts_model.c
index 6762c4e..ad007ec 100644
--- a/src/osmo-bts-omldummy/bts_model.c
+++ b/src/osmo-bts-omldummy/bts_model.c
@@ -130,6 +130,9 @@
 	case NM_OC_SITE_MANAGER:
 		rc = osmo_fsm_inst_dispatch(bts->site_mgr.mo.fi, NM_EV_OPSTART_ACK, NULL);
 		break;
+	case NM_OC_BTS:
+		rc = osmo_fsm_inst_dispatch(bts->mo.fi, NM_EV_OPSTART_ACK, NULL);
+		break;
 	case NM_OC_RADIO_CARRIER:
 		trx = (struct gsm_bts_trx*) obj;
 		/* Mark Dependency TS as Offline (ready to be Opstarted) */
@@ -144,7 +147,6 @@
 		break;
 	case NM_OC_CHANNEL:
 	case NM_OC_BASEB_TRANSC:
-	case NM_OC_BTS:
 	case NM_OC_GPRS_NSE:
 	case NM_OC_GPRS_CELL:
 	case NM_OC_GPRS_NSVC:
diff --git a/src/osmo-bts-sysmo/oml.c b/src/osmo-bts-sysmo/oml.c
index 7e77a99..7d9aa2a 100644
--- a/src/osmo-bts-sysmo/oml.c
+++ b/src/osmo-bts-sysmo/oml.c
@@ -1777,25 +1777,25 @@
 	case NM_OC_SITE_MANAGER:
 		rc = osmo_fsm_inst_dispatch(bts->site_mgr.mo.fi, NM_EV_OPSTART_ACK, NULL);
 		break;
+	case NM_OC_BTS:
+		rc = osmo_fsm_inst_dispatch(bts->mo.fi, NM_EV_OPSTART_ACK, NULL);
+		oml_mo_state_chg(&bts->mo, -1, NM_AVSTATE_OK);
+		oml_mo_state_chg(&bts->gprs.nse.mo, -1, NM_AVSTATE_OK);
+		oml_mo_state_chg(&bts->gprs.cell.mo, -1, NM_AVSTATE_OK);
+		oml_mo_state_chg(&bts->gprs.nsvc[0].mo, -1, NM_AVSTATE_OK);
+		break;
 	case NM_OC_RADIO_CARRIER:
 		rc = trx_init(obj);
 		break;
 	case NM_OC_CHANNEL:
 		rc = ts_opstart(obj);
 		break;
-	case NM_OC_BTS:
 	case NM_OC_BASEB_TRANSC:
 	case NM_OC_GPRS_NSE:
 	case NM_OC_GPRS_CELL:
 	case NM_OC_GPRS_NSVC:
 		oml_mo_state_chg(mo, NM_OPSTATE_ENABLED, -1);
 		rc = oml_mo_opstart_ack(mo);
-		if (mo->obj_class == NM_OC_BTS) {
-			oml_mo_state_chg(&bts->mo, -1, NM_AVSTATE_OK);
-			oml_mo_state_chg(&bts->gprs.nse.mo, -1, NM_AVSTATE_OK);
-			oml_mo_state_chg(&bts->gprs.cell.mo, -1, NM_AVSTATE_OK);
-			oml_mo_state_chg(&bts->gprs.nsvc[0].mo, -1, NM_AVSTATE_OK);
-		}
 		break;
 	default:
 		rc = oml_mo_opstart_nack(mo, NM_NACK_OBJCLASS_NOTSUPP);
diff --git a/src/osmo-bts-trx/l1_if.c b/src/osmo-bts-trx/l1_if.c
index 6aa77cb..916f6a2 100644
--- a/src/osmo-bts-trx/l1_if.c
+++ b/src/osmo-bts-trx/l1_if.c
@@ -620,12 +620,14 @@
 	case NM_OC_SITE_MANAGER:
 		rc = osmo_fsm_inst_dispatch(bts->site_mgr.mo.fi, NM_EV_OPSTART_ACK, NULL);
 		break;
+	case NM_OC_BTS:
+		rc = osmo_fsm_inst_dispatch(bts->mo.fi, NM_EV_OPSTART_ACK, NULL);
+		break;
 	case NM_OC_RADIO_CARRIER:
 		/* activate transceiver */
 		rc = trx_init(obj);
 		break;
 	case NM_OC_CHANNEL:
-	case NM_OC_BTS:
 	case NM_OC_BASEB_TRANSC:
 	case NM_OC_GPRS_NSE:
 	case NM_OC_GPRS_CELL:
diff --git a/src/osmo-bts-virtual/bts_model.c b/src/osmo-bts-virtual/bts_model.c
index 4aedff4..9ba632c 100644
--- a/src/osmo-bts-virtual/bts_model.c
+++ b/src/osmo-bts-virtual/bts_model.c
@@ -147,6 +147,9 @@
 	case NM_OC_SITE_MANAGER:
 		rc = osmo_fsm_inst_dispatch(bts->site_mgr.mo.fi, NM_EV_OPSTART_ACK, NULL);
 		break;
+	case NM_OC_BTS:
+		rc = osmo_fsm_inst_dispatch(bts->mo.fi, NM_EV_OPSTART_ACK, NULL);
+		break;
 	case NM_OC_RADIO_CARRIER:
 		trx = (struct gsm_bts_trx*) obj;
 		/* Mark Dependency TS as Offline (ready to be Opstarted) */
@@ -161,7 +164,6 @@
 		break;
 	case NM_OC_CHANNEL:
 	case NM_OC_BASEB_TRANSC:
-	case NM_OC_BTS:
 	case NM_OC_GPRS_NSE:
 	case NM_OC_GPRS_CELL:
 	case NM_OC_GPRS_NSVC:

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

Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Change-Id: Iae631bcc7acdf955296b124707e42d5e565af186
Gerrit-Change-Number: 20409
Gerrit-PatchSet: 5
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20201020/09c44938/attachment.htm>


More information about the gerrit-log mailing list