hnbgw: TC_apply_sccp()

Change-Id: Ia1ff0cb56893edf045ea3cb3233882ca93445d21
diff --git a/hnbgw/HNBGW_Tests.ttcn b/hnbgw/HNBGW_Tests.ttcn
index d2854d5..c3849b8 100644
--- a/hnbgw/HNBGW_Tests.ttcn
+++ b/hnbgw/HNBGW_Tests.ttcn
@@ -2529,6 +2529,77 @@
 	f_shutdown_helper();
 }
 
+private function f_vty_add_sccp_addr(TELNETasp_PT pt, charstring addr_name, charstring pc, integer cs7_nr := 0)
+{
+	f_vty_enter_config(pt);
+	f_vty_transceive(pt, "cs7 instance 0");
+	f_vty_transceive(pt, "sccp-address " & addr_name);
+	f_vty_transceive(pt, "point-code " & pc);
+	f_vty_transceive(pt, "end");
+}
+
+private function f_vty_set_cnlink_addr(TELNETasp_PT pt, charstring cnlink_and_nr, charstring addr_name)
+{
+	f_vty_enter_config(pt);
+	f_vty_transceive(pt, cnlink_and_nr);
+	f_vty_transceive(pt, "remote-addr " & addr_name);
+	f_vty_transceive(pt, "end");
+}
+
+private function f_vty_apply_sccp(TELNETasp_PT pt)
+{
+	f_vty_enter_config(pt);
+	f_vty_transceive(pt, "apply sccp");
+	f_vty_transceive(pt, "end");
+}
+
+template (present) RUA_Disc_Req tr_RUA_Disc_Req := {
+	ranap := ?,
+	cause := ?
+};
+
+/* With a cnlink up, change the SCCP address, and verify that it restarts upon vty 'apply sccp' */
+private function f_tc_apply_sccp(charstring id, TestHdlrParams pars) runs on ConnHdlr
+{
+	f_init_handler(pars);
+	f_perform_compl_l3(f_gen_compl3_by_domain(pars.ps_domain, 1)[0]);
+
+	f_sleep(1.0);
+	f_logp(HNBGWVTY, "Changing SCCP address, don't apply yet");
+
+	f_vty_add_sccp_addr(HNBGWVTY, "msc-foo", "0.42.4");
+	f_vty_set_cnlink_addr(HNBGWVTY, "msc 0", "msc-foo");
+
+	/* No effect yet, link still open both ways */
+	f_sleep(1.0);
+	f_iuh2iu(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
+	f_iu2iuh(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
+
+	f_logp(HNBGWVTY, "Apply SCCP address changes");
+	f_vty_apply_sccp(HNBGWVTY);
+
+	/* We modified the SCCP configuration, expect disconnect of UE that was active on the aborted link. */
+	RUA.receive(RUA_Disc_Ind:?);
+	BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
+
+	/* Would be nice to test reconnection on the other point-code, too. That would require another cnlink in
+	 * osmo-stp.cfg and module parameters... */
+
+	f_sleep(1.0);
+}
+testcase TC_apply_sccp() runs on test_CT
+{
+	f_init();
+	f_sleep(1.0);
+
+	var ConnHdlr vc_conn;
+	var template (value) TestHdlrParams pars := t_pars(0);
+	vc_conn := f_start_handler_with_pars(refers(f_tc_apply_sccp), pars);
+	vc_conn.done;
+
+	f_shutdown_helper();
+}
+
 control {
 	execute(TC_hnb_register());
 	execute(TC_hnb_register_duplicate());
@@ -2578,6 +2649,9 @@
 
 	/* Run at the end since it makes osmo-hnbgw <= 1.3.0 crash: OS#5676 */
 	execute(TC_hnb_reregister_reuse_sctp_assoc());
+
+	/* Run at the end since it messes with the SCCP config */
+	execute( TC_apply_sccp() );
 }
 
 }