[PATCH] osmo-ttcn3-hacks[master]: sgsn: Reduce code duplication by introducing f_mi_get_lv()

Harald Welte gerrit-no-reply at lists.osmocom.org
Sat Feb 17 09:17:22 UTC 2018


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

sgsn: Reduce code duplication by introducing f_mi_get_lv()

Change-Id: I8b970049074f5de9051a5a791278cd5d29f9d5ed
---
M sgsn/SGSN_Tests.ttcn
1 file changed, 19 insertions(+), 79 deletions(-)


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

diff --git a/sgsn/SGSN_Tests.ttcn b/sgsn/SGSN_Tests.ttcn
index 410921e..755957e 100644
--- a/sgsn/SGSN_Tests.ttcn
+++ b/sgsn/SGSN_Tests.ttcn
@@ -312,18 +312,20 @@
 	return f_RAI(mcc, mnc, f_rnd_octstring(2), f_rnd_octstring(1));
 }
 
+/* return a MobileIdentityLV: P-TMSI if we have one, IMSI otherwise */
+private function f_mi_get_lv() runs on BSSGP_ConnHdlr return MobileIdentityLV {
+	if (ispresent(g_pars.p_tmsi)) {
+		return valueof(ts_MI_TMSI_LV(g_pars.p_tmsi));
+	} else {
+		return valueof(ts_MI_IMSI_LV(g_pars.imsi));
+	}
+}
+
 private function f_TC_attach(charstring id) runs on BSSGP_ConnHdlr {
 	var BssgpDecoded bd;
-	var MobileIdentityLV mi;
 	var RoutingAreaIdentificationV old_ra := f_random_RAI();
 
-	if (ispresent(g_pars.p_tmsi)) {
-		mi := valueof(ts_MI_TMSI_LV(g_pars.p_tmsi));
-	} else {
-		mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
-	}
-
-	BSSGP.send(ts_GMM_ATTACH_REQ(mi, old_ra, false, false, omit, omit));
+	BSSGP.send(ts_GMM_ATTACH_REQ(f_mi_get_lv(), old_ra, false, false, omit, omit));
 	f_gmm_auth();
 	/* Expect MSC to perform LU with HLR */
 	GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi));
@@ -349,16 +351,9 @@
 
 /* MS never responds to ID REQ, expect ATTACH REJECT */
 private function f_TC_attach_auth_id_timeout(charstring id) runs on BSSGP_ConnHdlr {
-	var MobileIdentityLV mi;
 	var RoutingAreaIdentificationV old_ra := f_random_RAI();
 
-	if (ispresent(g_pars.p_tmsi)) {
-		mi := valueof(ts_MI_TMSI_LV(g_pars.p_tmsi));
-	} else {
-		mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
-	}
-
-	BSSGP.send(ts_GMM_ATTACH_REQ(mi, old_ra, false, false, omit, omit));
+	BSSGP.send(ts_GMM_ATTACH_REQ(f_mi_get_lv(), old_ra, false, false, omit, omit));
 	alt {
 	[] BSSGP.receive(tr_BD_L3(tr_GMM_ID_REQ(?))) {
 		/* don't send ID Response */
@@ -381,16 +376,9 @@
 
 /* HLR never responds to SAI REQ, expect ATTACH REJECT */
 private function f_TC_attach_auth_sai_timeout(charstring id) runs on BSSGP_ConnHdlr {
-	var MobileIdentityLV mi;
 	var RoutingAreaIdentificationV old_ra := f_random_RAI();
 
-	if (ispresent(g_pars.p_tmsi)) {
-		mi := valueof(ts_MI_TMSI_LV(g_pars.p_tmsi));
-	} else {
-		mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
-	}
-
-	BSSGP.send(ts_GMM_ATTACH_REQ(mi, old_ra, false, false, omit, omit));
+	BSSGP.send(ts_GMM_ATTACH_REQ(f_mi_get_lv(), old_ra, false, false, omit, omit));
 	alt {
 	[] as_mm_identity();
 	[] GSUP.receive(tr_GSUP_SAI_REQ(g_pars.imsi)); { }
@@ -408,16 +396,9 @@
 
 /* HLR rejects SAI, expect ATTACH REJECT */
 private function f_TC_attach_auth_sai_reject(charstring id) runs on BSSGP_ConnHdlr {
-	var MobileIdentityLV mi;
 	var RoutingAreaIdentificationV old_ra := f_random_RAI();
 
-	if (ispresent(g_pars.p_tmsi)) {
-		mi := valueof(ts_MI_TMSI_LV(g_pars.p_tmsi));
-	} else {
-		mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
-	}
-
-	BSSGP.send(ts_GMM_ATTACH_REQ(mi, old_ra, false, false, omit, omit));
+	BSSGP.send(ts_GMM_ATTACH_REQ(f_mi_get_lv(), old_ra, false, false, omit, omit));
 	alt {
 	[] as_mm_identity();
 	[] GSUP.receive(tr_GSUP_SAI_REQ(g_pars.imsi)); {
@@ -437,16 +418,9 @@
 /* HLR never responds to UL REQ, expect ATTACH REJECT */
 private function f_TC_attach_gsup_lu_timeout(charstring id) runs on BSSGP_ConnHdlr {
 	var BssgpDecoded bd;
-	var MobileIdentityLV mi;
 	var RoutingAreaIdentificationV old_ra := f_random_RAI();
 
-	if (ispresent(g_pars.p_tmsi)) {
-		mi := valueof(ts_MI_TMSI_LV(g_pars.p_tmsi));
-	} else {
-		mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
-	}
-
-	BSSGP.send(ts_GMM_ATTACH_REQ(mi, old_ra, false, false, omit, omit));
+	BSSGP.send(ts_GMM_ATTACH_REQ(f_mi_get_lv(), old_ra, false, false, omit, omit));
 	f_gmm_auth();
 	/* Expect MSC to perform LU with HLR */
 	GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi));
@@ -472,16 +446,9 @@
 /* HLR rejects UL REQ, expect ATTACH REJECT */
 private function f_TC_attach_gsup_lu_reject(charstring id) runs on BSSGP_ConnHdlr {
 	var BssgpDecoded bd;
-	var MobileIdentityLV mi;
 	var RoutingAreaIdentificationV old_ra := f_random_RAI();
 
-	if (ispresent(g_pars.p_tmsi)) {
-		mi := valueof(ts_MI_TMSI_LV(g_pars.p_tmsi));
-	} else {
-		mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
-	}
-
-	BSSGP.send(ts_GMM_ATTACH_REQ(mi, old_ra, false, false, omit, omit));
+	BSSGP.send(ts_GMM_ATTACH_REQ(f_mi_get_lv(), old_ra, false, false, omit, omit));
 	f_gmm_auth();
 	/* Expect MSC to perform LU with HLR */
 	GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi)) {
@@ -509,16 +476,9 @@
 /* Attempt of combined GPRS + IMSI attach: network should ACK only GPRS attach  */
 private function f_TC_attach_combined(charstring id) runs on BSSGP_ConnHdlr {
 	var BssgpDecoded bd;
-	var MobileIdentityLV mi;
 	var RoutingAreaIdentificationV old_ra := f_random_RAI();
 
-	if (ispresent(g_pars.p_tmsi)) {
-		mi := valueof(ts_MI_TMSI_LV(g_pars.p_tmsi));
-	} else {
-		mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
-	}
-
-	BSSGP.send(ts_GMM_ATTACH_REQ(mi, old_ra, true, false, omit, omit));
+	BSSGP.send(ts_GMM_ATTACH_REQ(f_mi_get_lv(), old_ra, true, false, omit, omit));
 	f_gmm_auth();
 	/* Expect MSC to perform LU with HLR */
 	GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi));
@@ -543,18 +503,11 @@
 /* Attempt of GPRS ATTACH in 'accept all' mode */
 private function f_TC_attach_accept_all(charstring id) runs on BSSGP_ConnHdlr {
 	var BssgpDecoded bd;
-	var MobileIdentityLV mi;
 	var RoutingAreaIdentificationV old_ra := f_random_RAI();
 
 	g_pars.net.expect_auth := false;
 
-	if (ispresent(g_pars.p_tmsi)) {
-		mi := valueof(ts_MI_TMSI_LV(g_pars.p_tmsi));
-	} else {
-		mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
-	}
-
-	BSSGP.send(ts_GMM_ATTACH_REQ(mi, old_ra, false, false, omit, omit));
+	BSSGP.send(ts_GMM_ATTACH_REQ(f_mi_get_lv(), old_ra, false, false, omit, omit));
 	f_gmm_auth();
 	BSSGP.receive(tr_BD_L3(tr_GMM_ATTACH_ACCEPT('001'B, ?, ?))) -> value bd {
 		f_process_attach_accept(bd.l3_mt.msgs.gprs_mm.attachAccept);
@@ -573,7 +526,6 @@
 
 /* Attempt of GPRS ATTACH in 'accept all' mode */
 private function f_TC_attach_closed_foreign(charstring id) runs on BSSGP_ConnHdlr {
-	var MobileIdentityLV mi;
 	var RoutingAreaIdentificationV old_ra := f_random_RAI();
 
 	/* Simulate a foreign IMSI */
@@ -582,12 +534,7 @@
 
 	g_pars.net.expect_auth := false;
 
-	if (ispresent(g_pars.p_tmsi)) {
-		mi := valueof(ts_MI_TMSI_LV(g_pars.p_tmsi));
-	} else {
-		mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
-	}
-	BSSGP.send(ts_GMM_ATTACH_REQ(mi, old_ra, false, false, omit, omit));
+	BSSGP.send(ts_GMM_ATTACH_REQ(f_mi_get_lv(), old_ra, false, false, omit, omit));
 	alt {
 	[] as_mm_identity();
 	[] BSSGP.receive(tr_BD_L3(tr_GMM_ATTACH_REJECT('07'O))) {
@@ -613,16 +560,9 @@
 
 /* Routing Area Update from Unknown TLLI -> REJECT */
 private function f_TC_rau_unknown(charstring id) runs on BSSGP_ConnHdlr {
-	var MobileIdentityLV mi;
 	var RoutingAreaIdentificationV old_ra := f_random_RAI();
 
-	if (ispresent(g_pars.p_tmsi)) {
-		mi := valueof(ts_MI_TMSI_LV(g_pars.p_tmsi));
-	} else {
-		mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
-	}
-
-	BSSGP.send(ts_GMM_RAU_REQ(mi, GPRS_UPD_T_RA, old_ra, false, omit, omit));
+	BSSGP.send(ts_GMM_RAU_REQ(f_mi_get_lv(), GPRS_UPD_T_RA, old_ra, false, omit, omit));
 	alt {
 	[] BSSGP.receive(tr_BD_L3(tr_GMM_RAU_REJECT('0a'O))) {
 		setverdict(pass);

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8b970049074f5de9051a5a791278cd5d29f9d5ed
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