Change in libosmocore[master]: WIP: implement BLOCK/UNBLOCK of a NSVC by vty

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/.

lynxis lazus gerrit-no-reply at lists.osmocom.org
Fri Jan 15 03:49:29 UTC 2021


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


Change subject: WIP: implement BLOCK/UNBLOCK of a NSVC by vty
......................................................................

WIP: implement BLOCK/UNBLOCK of a NSVC by vty

The vty should be able to block or unblock a specific NSVC.
Further more this case is special for the UNITDATA as those
can be still received until the other side response to the BLOCK PDU.

TODO: unit or ttcn3 tests

Related: OS#4939
Change-Id: Ic0ce3c5fabc8644cc1ee71a8f6dd783fadf7b84d
---
M src/gb/gprs_ns2_internal.h
M src/gb/gprs_ns2_vc_fsm.c
M src/gb/gprs_ns2_vty2.c
3 files changed, 107 insertions(+), 7 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/10/22210/1

diff --git a/src/gb/gprs_ns2_internal.h b/src/gb/gprs_ns2_internal.h
index c33f7f8..954671f 100644
--- a/src/gb/gprs_ns2_internal.h
+++ b/src/gb/gprs_ns2_internal.h
@@ -311,6 +311,8 @@
 int gprs_ns2_vc_rx(struct gprs_ns2_vc *nsvc, struct msgb *msg, struct tlv_parsed *tp);
 int gprs_ns2_vc_is_alive(struct gprs_ns2_vc *nsvc);
 int gprs_ns2_vc_is_unblocked(struct gprs_ns2_vc *nsvc);
+int ns2_vc_block(struct gprs_ns2_vc *nsvc);
+int ns2_vc_unblock(struct gprs_ns2_vc *nsvc);
 
 /* nse */
 void ns2_nse_notify_unblocked(struct gprs_ns2_vc *nsvc, bool unblocked);
diff --git a/src/gb/gprs_ns2_vc_fsm.c b/src/gb/gprs_ns2_vc_fsm.c
index 641fcc3..4af4700 100644
--- a/src/gb/gprs_ns2_vc_fsm.c
+++ b/src/gb/gprs_ns2_vc_fsm.c
@@ -59,6 +59,10 @@
 	 * It can change during runtime. The side which blocks an unblocked side.*/
 	bool initiate_block;
 	bool initiate_reset;
+	/* if blocked by O&M/vty */
+	bool om_blocked;
+	/* if unitdata is forwarded to the user */
+	bool accept_unitdata;
 
 	/* the alive counter is present in all states */
 	struct {
@@ -112,6 +116,8 @@
 	GPRS_NS2_EV_UNITDATA,
 
 	GPRS_NS2_EV_FORCE_UNCONFIGURED, /* called via vty for tests */
+	GPRS_NS2_EV_OM_BLOCK, /* vty cmd: block */
+	GPRS_NS2_EV_OM_UNBLOCK, /* vty cmd: unblock*/
 };
 
 static const struct value_string gprs_ns2_vc_event_names[] = {
@@ -127,6 +133,8 @@
 	{ GPRS_NS2_EV_STATUS,			"STATUS" },
 	{ GPRS_NS2_EV_UNITDATA,			"UNITDATA" },
 	{ GPRS_NS2_EV_FORCE_UNCONFIGURED,	"FORCE_UNCONFIGURED" },
+	{ GPRS_NS2_EV_OM_BLOCK,			"O&M_BLOCK"},
+	{ GPRS_NS2_EV_OM_UNBLOCK,		"O&M_UNBLOCK"},
 	{ 0, NULL }
 };
 
@@ -245,6 +253,7 @@
 	if (old_state != GPRS_NS2_ST_RESET)
 		priv->N = 0;
 
+	priv->accept_unitdata = false;
 	if (priv->initiate_reset)
 		ns2_tx_reset(priv->nsvc, NS_CAUSE_OM_INTERVENTION);
 
@@ -283,8 +292,12 @@
 	if (old_state != GPRS_NS2_ST_BLOCKED)
 		priv->N = 0;
 
-	if (priv->initiate_block)
-		ns2_tx_unblock(priv->nsvc);
+	if (priv->initiate_block) {
+		if (priv->om_blocked)
+			ns2_tx_block(priv->nsvc, NS_CAUSE_OM_INTERVENTION);
+		else
+			ns2_tx_unblock(priv->nsvc);
+	 }
 
 	start_test_procedure(priv);
 }
@@ -293,7 +306,24 @@
 {
 	struct gprs_ns2_vc_priv *priv = fi->priv;
 
-	if (priv->initiate_block) {
+	if (priv->om_blocked) {
+		switch (event) {
+		case GPRS_NS2_EV_BLOCK_ACK:
+			priv->accept_unitdata = false;
+			osmo_timer_del(&fi->timer);
+			break;
+		case GPRS_NS2_EV_BLOCK:
+			priv->accept_unitdata = false;
+			ns2_tx_block_ack(priv->nsvc);
+			osmo_timer_del(&fi->timer);
+			break;
+		case GPRS_NS2_EV_UNBLOCK:
+			priv->accept_unitdata = false;
+			ns2_tx_block(priv->nsvc, NS_CAUSE_OM_INTERVENTION);
+			osmo_timer_add(&fi->timer);
+			break;
+		}
+	} else if (priv->initiate_block) {
 		switch (event) {
 		case GPRS_NS2_EV_BLOCK:
 			/* TODO: BLOCK is a UNBLOCK_NACK */
@@ -303,6 +333,7 @@
 			ns2_tx_unblock_ack(priv->nsvc);
 			/* fall through */
 		case GPRS_NS2_EV_UNBLOCK_ACK:
+			priv->accept_unitdata = true;
 			osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_UNBLOCKED,
 						0, NS_TOUT_TNS_TEST);
 			break;
@@ -325,6 +356,7 @@
 	struct gprs_ns2_vc *nsvc = priv->nsvc;
 	struct gprs_ns2_nse *nse = nsvc->nse;
 
+	priv->accept_unitdata = true;
 	ns2_nse_notify_unblocked(nsvc, true);
 	ns2_prim_status_ind(nse, nsvc, 0, NS_AFF_CAUSE_VC_RECOVERY);
 }
@@ -446,10 +478,19 @@
 	case GPRS_NS2_ST_BLOCKED:
 		if (priv->initiate_block) {
 			priv->N++;
-			if (priv->N <= nsi->timeout[NS_TOUT_TNS_BLOCK_RETRIES]) {
-				osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, nsi->timeout[NS_TOUT_TNS_BLOCK], 0);
+			if (priv->om_blocked) {
+				if (priv->N <= nsi->timeout[NS_TOUT_TNS_BLOCK_RETRIES]) {
+					osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, nsi->timeout[NS_TOUT_TNS_BLOCK], 0);
+				} else {
+					/* 7.2 stop accepting data when BLOCK PDU not responded */
+					priv->accept_unitdata = false;
+				}
 			} else {
-				osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], 0);
+				if (priv->N <= nsi->timeout[NS_TOUT_TNS_BLOCK_RETRIES]) {
+					osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, nsi->timeout[NS_TOUT_TNS_BLOCK], 0);
+				} else {
+					osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], 0);
+				}
 			}
 		}
 		break;
@@ -550,7 +591,7 @@
 		switch (fi->state) {
 		case GPRS_NS2_ST_BLOCKED:
 			/* 7.2.1: the BLOCKED_ACK might be lost */
-			if (priv->initiate_block) {
+			if (priv->accept_unitdata) {
 				gprs_ns2_recv_unitdata(fi, msg);
 				return;
 			}
@@ -576,6 +617,20 @@
 			return;
 		}
 		break;
+	case GPRS_NS2_EV_OM_BLOCK:
+		/* vty cmd: block */
+		priv->initiate_block = true;
+		priv->om_blocked = true;
+		osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, nsi->timeout[NS_TOUT_TNS_BLOCK], 0);
+		break;
+	case GPRS_NS2_EV_OM_UNBLOCK:
+		/* vty cmd: unblock*/
+		if (!priv->om_blocked)
+			return;
+		priv->om_blocked = false;
+		if (fi->state == GPRS_NS2_ST_BLOCKED)
+			osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, nsi->timeout[NS_TOUT_TNS_BLOCK], 0);
+		break;
 	}
 }
 
@@ -653,6 +708,22 @@
 	return osmo_fsm_inst_dispatch(nsvc->fi, GPRS_NS2_EV_FORCE_UNCONFIGURED, NULL);
 }
 
+/*! Block a NS-VC.
+ *  \param nsvc the virtual circuit
+ *  \return 0 on success; negative on error */
+int ns2_vc_block(struct gprs_ns2_vc *nsvc)
+{
+	return osmo_fsm_inst_dispatch(nsvc->fi, GPRS_NS2_EV_BLOCK, NULL);
+}
+
+/*! Unblock a NS-VC.
+ *  \param nsvc the virtual circuit
+ *  \return 0 on success; negative on error */
+int ns2_vc_unblock(struct gprs_ns2_vc *nsvc)
+{
+	return osmo_fsm_inst_dispatch(nsvc->fi, GPRS_NS2_EV_UNBLOCK, NULL);
+}
+
 /*! entry point for messages from the driver/VL
  *  \param nsvc virtual circuit on which the message was received
  *  \param msg message that was received
diff --git a/src/gb/gprs_ns2_vty2.c b/src/gb/gprs_ns2_vty2.c
index 5af8fbc..87e891d 100644
--- a/src/gb/gprs_ns2_vty2.c
+++ b/src/gb/gprs_ns2_vty2.c
@@ -1503,6 +1503,32 @@
 	return CMD_SUCCESS;
 }
 
+DEFUN(nsvc_block, nsvc_block_cmd,
+      "nsvci <0-65535> (block|unblock)",
+      "NS Virtual Connection\n"
+      "NS Virtual Connection\n"
+      "Block or Unblock a NSVC. As cause code O&M intervention will be used.\n")
+{
+	struct gprs_ns2_inst *nsi = vty_nsi;
+	struct gprs_ns2_vc *nsvc;
+
+	uint16_t id = atoi(argv[0]);
+
+	nsvc = gprs_ns2_nsvc_by_nsvci(nsi, id);
+	if (!nsvc) {
+		vty_out(vty, "Could not find NSVCI %u%s", id, VTY_NEWLINE);
+		return CMD_WARNING;
+	}
+
+	if (!strcmp(argv[1], "block")) {
+		ns2_vc_block(nsvc);
+	} else {
+		ns2_vc_unblock(nsvc);
+	}
+
+	return CMD_SUCCESS;
+}
+
 static void log_set_nse_filter(struct log_target *target,
 				struct gprs_ns2_nse *nse)
 {
@@ -1608,6 +1634,7 @@
 	install_lib_element_ve(&logging_fltr_nsvc_cmd);
 
 	install_lib_element(ENABLE_NODE, &nsvc_force_unconf_cmd);
+	install_lib_element(ENABLE_NODE, &nsvc_block_cmd);
 
 	install_lib_element(CFG_LOG_NODE, &logging_fltr_nse_cmd);
 	install_lib_element(CFG_LOG_NODE, &logging_fltr_nsvc_cmd);

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ic0ce3c5fabc8644cc1ee71a8f6dd783fadf7b84d
Gerrit-Change-Number: 22210
Gerrit-PatchSet: 1
Gerrit-Owner: lynxis lazus <lynxis at fe80.eu>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210115/4a61b1e0/attachment.htm>


More information about the gerrit-log mailing list