module SGSN_Tests_Iu {

import from Osmocom_Types all;

import from SGSN_Tests all;

import from RAN_Adapter all;
import from RAN_Emulation all;
import from RANAP_Templates all;
import from RANAP_PDU_Descriptions all;
import from RANAP_IEs all;


private function f_TC_iu_attach(charstring id) runs on BSSGP_ConnHdlr {
	var PdpActPars apars := valueof(t_PdpActPars(mp_ggsn_ip));

	/* first perform regular attach */
	f_gmm_attach(umts_aka_challenge := true, force_gsm_sres := false, ran_index := 3);
	setverdict(pass);
}
testcase TC_iu_attach() runs on test_CT {
	/* MS -> SGSN: Attach Request IMSI
	 * MS <- SGSN: Identity Request IMEI
	 * MS -> SGSN: Identity Response IMEI
	 * MS <- SGSN: Auth Request
	 * MS -> SGSN: Auth Response
	 * MS <- SGSN: Attach Accept
	 * MS -> SGSN: Attach Complete
	 */
	var BSSGP_ConnHdlr vc_conn;
	g_ranap_enable := true;
	f_init();
	f_sleep(1.0);
	vc_conn := f_start_handler(refers(f_TC_iu_attach), testcasename(), g_gb, 1001);
	vc_conn.done;
	f_cleanup();
}

private function f_TC_iu_attach_geran_rau(charstring id) runs on BSSGP_ConnHdlr {
	var PdpActPars apars := valueof(t_PdpActPars(mp_ggsn_ip));

	/* first perform regular attach */
	f_gmm_attach(umts_aka_challenge := true, force_gsm_sres := false, ran_index := 3);

	/* do a routing area update */
	f_routing_area_update(g_pars.ra);
}

testcase TC_iu_attach_geran_rau() runs on test_CT {
	/* MS <-> SGSN: Successful Attach over Iu
	 * MS <-> SGSN: Routing Area Update over Geran
	 */
	var BSSGP_ConnHdlr vc_conn;
	g_ranap_enable := true;
	f_init();
	f_sleep(1.0);
	vc_conn := f_start_handler(refers(f_TC_iu_attach_geran_rau), testcasename(), g_gb, 1002);
	vc_conn.done;
	f_cleanup();
}

private function f_TC_geran_attach_iu_rau(charstring id) runs on BSSGP_ConnHdlr {
	var PdpActPars apars := valueof(t_PdpActPars(mp_ggsn_ip));

	/* first perform regular attach */
	f_gmm_attach(umts_aka_challenge := true, force_gsm_sres := false, ran_index := 0);

	/* do a routing area update */
	f_routing_area_update(g_pars.ra, ran_index := 3);
	setverdict(pass);
}

testcase TC_geran_attach_iu_rau() runs on test_CT {
	/* MS <-> SGSN: Successful Attach over Geran
	 * MS <-> SGSN: Routing Area Update over Iu
	 */
	var BSSGP_ConnHdlr vc_conn;
	g_ranap_enable := true;
	f_init();
	f_sleep(1.0);
	vc_conn := f_start_handler(refers(f_TC_geran_attach_iu_rau), testcasename(), g_gb, 1003);
	vc_conn.done;
	f_cleanup();
}

control {
	execute( TC_iu_attach() );
	execute( TC_iu_attach_geran_rau() );
	execute( TC_geran_attach_iu_rau() );
}


}
