[PATCH] osmo-ttcn3-hacks[master]: sgsn: Add TC_detach_* for various GPRS DETACH use cases

Harald Welte gerrit-no-reply at lists.osmocom.org
Sun Feb 18 09:28:14 UTC 2018


Review at  https://gerrit.osmocom.org/6564

sgsn: Add TC_detach_* for various GPRS DETACH use cases

Change-Id: I2243b850400482b911d687585929a2eef3490954
---
M library/GSUP_Types.ttcn
M library/L3_Templates.ttcn
M sgsn/SGSN_Tests.ttcn
3 files changed, 165 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks refs/changes/64/6564/1

diff --git a/library/GSUP_Types.ttcn b/library/GSUP_Types.ttcn
index fda9549..0a21999 100644
--- a/library/GSUP_Types.ttcn
+++ b/library/GSUP_Types.ttcn
@@ -286,6 +286,14 @@
 	tr_GSUP(OSMO_GSUP_MSGT_LOCATION_CANCEL_ERROR, {
 			tr_GSUP_IE_IMSI(imsi), tr_GSUP_IE_Cause(cause) });
 
+template GSUP_PDU tr_GSUP_PURGE_MS_REQ(template hexstring imsi, template GSUP_CnDomain dom := ?) :=
+	tr_GSUP(OSMO_GSUP_MSGT_PURGE_MS_REQUEST, {
+			tr_GSUP_IE_IMSI(imsi), *, tr_GSUP_IE_CnDomain(dom) });
+
+template (value) GSUP_PDU ts_GSUP_PURGE_MS_RES(hexstring imsi) :=
+	ts_GSUP(OSMO_GSUP_MSGT_PURGE_MS_RESULT, {
+		valueof(ts_GSUP_IE_IMSI(imsi)) });
+
 
 template (value) GSUP_IE ts_GSUP_IE_CancelType(GSUP_CancelType ctype) := {
 	tag := OSMO_GSUP_CANCEL_TYPE_IE,
@@ -298,6 +306,9 @@
 template GSUP_IE tr_GSUP_IE_CancelType(template GSUP_CancelType ctype) :=
 	tr_GSUP_IE(OSMO_GSUP_CANCEL_TYPE_IE, GSUP_IeValue:{cancel_type:=ctype});
 
+template GSUP_IE tr_GSUP_IE_CnDomain(template GSUP_CnDomain domain) :=
+	tr_GSUP_IE(OSMO_GSUP_CN_DOMAIN_IE, GSUP_IeValue:{cn_domain:=domain});
+
 template GSUP_IE tr_GSUP_IE(template GSUP_IEI iei, template GSUP_IeValue val := ?) := {
 	tag := iei,
 	len := ?,
diff --git a/library/L3_Templates.ttcn b/library/L3_Templates.ttcn
index 5b6b481..9bd74db 100644
--- a/library/L3_Templates.ttcn
+++ b/library/L3_Templates.ttcn
@@ -65,10 +65,18 @@
 }
 
 /* send template fro Mobile Identity (TMSI) */
-template MobileIdentityTLV ts_MI_TMSI_TLV(OCT4 tmsi) := {
-	elementIdentifier := '0100011'B,
-	spare1 := '0'B,
-	mobileIdentityLV := ts_MI_TMSI_LV(tmsi)
+function ts_MI_TMSI_TLV(template (omit) OCT4 tmsi) return template (omit) MobileIdentityTLV {
+	var template (omit) MobileIdentityTLV ret;
+	if (istemplatekind(tmsi, "omit")) {
+		return omit;
+	} else {
+		ret := {
+			elementIdentifier := '0100011'B,
+			spare1 := '0'B,
+			mobileIdentityLV := ts_MI_TMSI_LV(valueof(tmsi))
+		}
+		return ret;
+	}
 }
 
 template MobileIdentityTLV ts_MI_IMEISV_TLV(hexstring imeisv) := {
@@ -1689,12 +1697,42 @@
 const BIT3 c_GMM_DTT_MO_IMSI := '010'B;
 const BIT3 c_GMM_DTT_MO_GPRS_IMSI_COMBINED := '011'B;
 
-template (value) DetachTypeV ts_GMM_DetType(BIT3 dtt) := {
+template (value) DetachTypeV ts_GMM_DetType(BIT3 dtt, boolean power_off := false) := {
 	detachType := dtt,
-	powerOffFlag := '0'B
+	powerOffFlag := bool2bit(power_off)
 }
 
-template (value) PDU_L3_MS_SGSN ts_GMM_DET_REQ_MO(BIT3 dtt := c_GMM_DTT_MO_GPRS) := {
+function ts_PtmsiSigTV(template (omit) OCT3 val) return template (omit) P_TMSISignatureTV {
+	var template (omit) P_TMSISignatureTV ret;
+	if (istemplatekind(val, "omit")) {
+		return omit;
+	} else {
+		ret := {
+			elementIdentifier := '19'O,
+			valueField := valueof(val)
+		}
+		return ret;
+	}
+}
+
+function ts_PtmsiSigTLV(template (omit) OCT3 val) return template (omit) P_TMSISignature2TLV {
+	var template (omit) P_TMSISignature2TLV ret;
+	if (istemplatekind(val, "omit")) {
+		return omit;
+	} else {
+		ret := {
+			elementIdentifier := '19'O,
+			lengthIndicator := 3,
+			valueField := valueof(val)
+		}
+		return ret;
+	}
+}
+
+template (value) PDU_L3_MS_SGSN ts_GMM_DET_REQ_MO(BIT3 dtt := c_GMM_DTT_MO_GPRS,
+						  boolean power_off := false,
+						  template (omit) OCT4 p_tmsi := omit,
+						  template (omit) OCT3 p_tmsi_sig := omit) := {
 	discriminator := '0000'B, /* overwritten */
 	tiOrSkip := {
 		skipIndicator := '0000'B
@@ -1703,10 +1741,26 @@
 		gprs_mm := {
 			detachRequest_MS_SGSN := {
 				messageType := '00000000'B, /* overwritten */
-				detachType := valueof(ts_GMM_DetType(dtt)),
+				detachType := valueof(ts_GMM_DetType(dtt, power_off)),
 				spare := '0000'B,
-				ptmsi := omit, /* TODO */
-				ptmsiSignature := omit /* TODO */
+				ptmsi := ts_MI_TMSI_TLV(p_tmsi),
+				ptmsiSignature := ts_PtmsiSigTLV(p_tmsi_sig)
+			}
+		}
+	}
+}
+
+template PDU_L3_SGSN_MS tr_GMM_DET_ACCEPT_MT := {
+	discriminator := '1000'B,
+	tiOrSkip := {
+		skipIndicator := '0000'B
+	},
+	msgs := {
+		gprs_mm := {
+			detachAccept_SGSN_MS := {
+				messageType := '00000110'B,
+				forceToStandby := ?,
+				spare := '0000'B
 			}
 		}
 	}
diff --git a/sgsn/SGSN_Tests.ttcn b/sgsn/SGSN_Tests.ttcn
index 9e00a13..3cf1657 100644
--- a/sgsn/SGSN_Tests.ttcn
+++ b/sgsn/SGSN_Tests.ttcn
@@ -635,6 +635,92 @@
 	vc_conn.done;
 }
 
+/* general GPRS DETACH helper */
+function f_detach_mo(BIT3 detach_type, boolean power_off, boolean expect_purge) runs on BSSGP_ConnHdlr {
+	var BssgpDecoded bd;
+	timer T := 5.0;
+	BSSGP.send(ts_GMM_DET_REQ_MO(detach_type, power_off));
+	if (expect_purge) {
+		GSUP.receive(tr_GSUP_PURGE_MS_REQ(g_pars.imsi, OSMO_GSUP_CN_DOMAIN_PS));
+		GSUP.send(ts_GSUP_PURGE_MS_RES(g_pars.imsi));
+	}
+	T.start;
+	alt {
+	[not expect_purge] GSUP.receive(tr_GSUP_PURGE_MS_REQ(?)) {
+		setverdict(fail, "Unexpected GSUP PURGE MS for unregistered TLLI");
+		}
+	[power_off] BSSGP.receive(tr_BD_L3_MT(tr_GMM_DET_ACCEPT_MT)) -> value bd {
+		g_pars.ra := omit;
+		setverdict(fail, "Unexpected ATTACH ACCEPT in no-power-off DETACH");
+		/* TODO: check if any PDP contexts are deactivated on network side? */
+		}
+	[power_off] T.timeout {
+		setverdict(pass);
+		}
+	[not power_off] BSSGP.receive(tr_BD_L3_MT(tr_GMM_DET_ACCEPT_MT)) -> value bd {
+		g_pars.ra := omit;
+		setverdict(pass);
+		/* TODO: check if any PDP contexts are deactivated on network side? */
+		}
+	[] BSSGP.receive { repeat; }
+	}
+}
+
+/* IMSI DETACH (non-power-off) for unknown TLLI */
+private function f_TC_detach_unknown_nopoweroff(charstring id) runs on BSSGP_ConnHdlr {
+	f_detach_mo(c_GMM_DTT_MO_GPRS, false, false);
+}
+testcase TC_detach_unknown_nopoweroff() runs on test_CT {
+	var BSSGP_ConnHdlr vc_conn;
+	f_init();
+	f_sleep(1.0);
+	vc_conn := f_start_handler(refers(f_TC_detach_unknown_nopoweroff), testcasename(), g_gb[0], 13);
+	vc_conn.done;
+}
+
+/* IMSI DETACH (power-off) for unknown TLLI */
+private function f_TC_detach_unknown_poweroff(charstring id) runs on BSSGP_ConnHdlr {
+	f_detach_mo(c_GMM_DTT_MO_GPRS,  true, false);
+}
+testcase TC_detach_unknown_poweroff() runs on test_CT {
+	var BSSGP_ConnHdlr vc_conn;
+	f_init();
+	f_sleep(1.0);
+	vc_conn := f_start_handler(refers(f_TC_detach_unknown_poweroff), testcasename(), g_gb[0], 14);
+	vc_conn.done;
+}
+
+/* IMSI DETACH (non-power-off) for known TLLI */
+private function f_TC_detach_nopoweroff(charstring id) runs on BSSGP_ConnHdlr {
+	/* first perform regular attach */
+	f_TC_attach(id);
+
+	f_detach_mo(c_GMM_DTT_MO_GPRS, false, true);
+}
+testcase TC_detach_nopoweroff() runs on test_CT {
+	var BSSGP_ConnHdlr vc_conn;
+	f_init();
+	f_sleep(1.0);
+	vc_conn := f_start_handler(refers(f_TC_detach_nopoweroff), testcasename(), g_gb[0], 15);
+	vc_conn.done;
+}
+
+/* IMSI DETACH (power-off) for known TLLI */
+private function f_TC_detach_poweroff(charstring id) runs on BSSGP_ConnHdlr {
+	/* first perform regular attach */
+	f_TC_attach(id);
+
+	f_detach_mo(c_GMM_DTT_MO_GPRS, true, true);
+}
+testcase TC_detach_poweroff() runs on test_CT {
+	var BSSGP_ConnHdlr vc_conn;
+	f_init();
+	f_sleep(1.0);
+	vc_conn := f_start_handler(refers(f_TC_detach_poweroff), testcasename(), g_gb[0], 16);
+	vc_conn.done;
+}
+
+
 
 
 control {
@@ -649,6 +735,10 @@
 	execute( TC_attach_closed() );
 	execute( TC_rau_unknown() );
 	execute( TC_attach_rau() );
+	execute( TC_detach_unknown_nopoweroff() );
+	execute( TC_detach_unknown_poweroff() );
+	execute( TC_detach_nopoweroff() );
+	execute( TC_detach_poweroff() );
 }
 
 

-- 
To view, visit https://gerrit.osmocom.org/6564
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2243b850400482b911d687585929a2eef3490954
Gerrit-PatchSet: 1
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>


More information about the gerrit-log mailing list