sgsn: Add series of tests on suspend/resume and paging behavior

Let's test whether paging is triggered after T3314 expiration, as well
as suspend and explicit and implicit resume work as expected

Change-Id: I83b7a453958e30dfc727ba3140168217c209833f
Related: OS#4616
diff --git a/sgsn/SGSN_Tests.ttcn b/sgsn/SGSN_Tests.ttcn
index 4b4bbd9..0e656a3 100644
--- a/sgsn/SGSN_Tests.ttcn
+++ b/sgsn/SGSN_Tests.ttcn
@@ -2907,6 +2907,164 @@
 	f_cleanup();
 }
 
+private altstep as_nopaging_ps(integer ran_idx := 0) runs on BSSGP_ConnHdlr {
+var PDU_BSSGP rx;
+[] BSSGP_SIG[ran_idx].receive(tr_BSSGP_PS_PAGING(?)) -> value rx {
+	setverdict(fail, "Received unexpected PS PAGING: ", rx);
+	mtc.stop;
+	}
+}
+
+/* SUSPEND, then DL traffic: should not pass + no paging expected */
+private function f_TC_suspend_nopaging(charstring id) runs on BSSGP_ConnHdlr {
+	var PdpActPars apars := valueof(t_PdpActPars(mp_ggsn_ip));
+	var default d;
+
+	/* first perform regular attach */
+	f_TC_attach(id);
+	/* then activate PDP context */
+	f_pdp_ctx_act(apars);
+	/* then transceive a downlink PDU */
+	f_gtpu_xceive_mt(apars, f_rnd_octstring(100));
+
+	/* now suspend GPRS */
+	f_bssgp_suspend();
+
+	d := activate(as_nopaging_ps());
+
+	/* at this point we don't expect any downlink traffic at all, neither actual LLC/SNDCP data,
+	 * nor any related paging requests */
+	f_gtpu_xceive_mt(apars, f_rnd_octstring(100), expect_fwd := false);
+
+	deactivate(d);
+}
+testcase TC_suspend_nopaging() runs on test_CT {
+	var BSSGP_ConnHdlr vc_conn;
+	f_init();
+	f_sleep(1.0);
+	vc_conn := f_start_handler(refers(f_TC_suspend_nopaging), testcasename(), g_gb, 48);
+	vc_conn.done;
+	f_cleanup();
+}
+
+
+/* SUSPEND, then RESUME: data expected to flow after explicit resume */
+private function f_TC_suspend_resume(charstring id) runs on BSSGP_ConnHdlr {
+	var PdpActPars apars := valueof(t_PdpActPars(mp_ggsn_ip));
+	var OCT1 susp_ref;
+	var default d;
+
+	/* first perform regular attach */
+	f_TC_attach(id);
+	/* then activate PDP context */
+	f_pdp_ctx_act(apars);
+	/* then transceive a downlink PDU */
+	f_gtpu_xceive_mt(apars, f_rnd_octstring(100));
+
+	/* now suspend GPRS */
+	susp_ref := f_bssgp_suspend();
+
+	d := activate(as_nopaging_ps());
+
+	/* at this point we don't expect any downlink traffic at all, neither actual LLC/SNDCP data,
+	 * nor any related paging requests */
+	f_gtpu_xceive_mt(apars, f_rnd_octstring(100), expect_fwd := false);
+
+	deactivate(d);
+
+	/* resume GPRS */
+	f_bssgp_resume(susp_ref);
+
+	/* now data should be flowing again */
+	f_gtpu_xceive_mt(apars, f_rnd_octstring(100));
+}
+testcase TC_suspend_resume() runs on test_CT {
+	var BSSGP_ConnHdlr vc_conn;
+	f_init();
+	f_sleep(1.0);
+	vc_conn := f_start_handler(refers(f_TC_suspend_resume), testcasename(), g_gb, 49);
+	vc_conn.done;
+	f_cleanup();
+}
+
+/* SUSPEND, then RAU: data expected to flow after implicit resume */
+private function f_TC_suspend_rau(charstring id) runs on BSSGP_ConnHdlr {
+	var PdpActPars apars := valueof(t_PdpActPars(mp_ggsn_ip));
+	var default d;
+
+	/* first perform regular attach */
+	f_TC_attach(id);
+	/* then activate PDP context */
+	f_pdp_ctx_act(apars);
+	/* then transceive a downlink PDU */
+	f_gtpu_xceive_mt(apars, f_rnd_octstring(100));
+
+	/* now suspend GPRS */
+	f_bssgp_suspend();
+
+	d := activate(as_nopaging_ps());
+
+	/* at this point we don't expect any downlink traffic at all, neither actual LLC/SNDCP data,
+	 * nor any related paging requests */
+	f_gtpu_xceive_mt(apars, f_rnd_octstring(100), expect_fwd := false);
+
+	deactivate(d);
+
+	/* perform RAU (implicit RESUME) */
+	f_routing_area_update(g_pars.ra);
+
+	/* now data should be flowing again */
+	f_gtpu_xceive_mt(apars, f_rnd_octstring(100));
+
+}
+testcase TC_suspend_rau() runs on test_CT {
+	var BSSGP_ConnHdlr vc_conn;
+	f_init();
+	f_sleep(1.0);
+	vc_conn := f_start_handler(refers(f_TC_suspend_rau), testcasename(), g_gb, 50);
+	vc_conn.done;
+	f_cleanup();
+}
+
+
+/* wait for T3314 expiration and check that PS PAGING is created on DL PDU */
+private function f_TC_paging_ps(charstring id) runs on BSSGP_ConnHdlr {
+	var PdpActPars apars := valueof(t_PdpActPars(mp_ggsn_ip));
+	var default d;
+
+	/* first perform regular attach */
+	f_TC_attach(id);
+	/* then activate PDP context */
+	f_pdp_ctx_act(apars);
+	/* then transceive a downlink PDU */
+	f_gtpu_xceive_mt(apars, f_rnd_octstring(100));
+
+	/* now wait for T3314 expiration (test_CT below has reduced it to 3s) */
+	f_sleep(5.0);
+
+	/* now data should be flowing again, but with PS PAGING */
+	f_gtpu_xceive_mt(apars, f_rnd_octstring(100));
+	BSSGP_SIG[0].receive(tr_BSSGP_PS_PAGING(?));
+
+	/* FIXME: simulate paging response */
+	/* FIXME: verify PDU actually arrives only after paging response was successful */
+
+}
+testcase TC_paging_ps() runs on test_CT {
+	var BSSGP_ConnHdlr vc_conn;
+	f_init();
+	f_vty_config(SGSNVTY, "sgsn", "timer 3314 3");
+	f_sleep(1.0);
+	vc_conn := f_start_handler(refers(f_TC_paging_ps), testcasename(), g_gb, 51);
+	vc_conn.done;
+	f_vty_config(SGSNVTY, "sgsn", "timer 3314 default");
+	f_cleanup();
+}
+
+
+
+
+
 control {
 	execute( TC_attach() );
 	execute( TC_attach_mnc3() );
@@ -2964,6 +3122,11 @@
 	execute( TC_llc_sabm_dm_llgmm() );
 	execute( TC_llc_sabm_dm_ll5() );
 
+	execute( TC_suspend_nopaging() );
+	execute( TC_suspend_resume() );
+	execute( TC_suspend_rau() );
+	execute( TC_paging_ps() );
+
 	/* At the end, may crash osmo-sgsn, see OS#3957, OS#4245 */
 	execute( TC_attach_req_id_req_ra_update() );
 }