BSC_Tests_VAMOS: fix TC_vamos_multiplex_tch_h_tch_h_tch_h_tch_h

Properly clean up conns in the end. Use COORD and new COORD2 ports to
daisy-chain coordination between the four components.

Related: OS#5444
Change-Id: I3b1dfc3b11e990893cbf182fb9f8840e198eb8aa
diff --git a/bsc/BSC_Tests_VAMOS.ttcn b/bsc/BSC_Tests_VAMOS.ttcn
index 9a53200..5caeeed 100644
--- a/bsc/BSC_Tests_VAMOS.ttcn
+++ b/bsc/BSC_Tests_VAMOS.ttcn
@@ -677,19 +677,52 @@
 	f_shutdown_helper();
 }
 
+const charstring DONE := "DONE";
+
+/*
+ * f1               f2                  f3                 f4
+ *  COORD <--> COORD | COORD2 <--> COORD | COORD2 <--> COORD
+ *     ---DONE----->     ---DONE----->       ---DONE----->
+ *     <----DONE----     <----DONE----       <----DONE----
+ */
+
 /* First, primary lchan of TC_vamos_multiplex_tch_h_tch_h_tch_h_tch_h() */
 private function f_TC_vamos_multiplex_tch_h_tch_h1(charstring id) runs on MSC_ConnHdlr {
 	f_est_lchan_and_mode_modify_to_vamos();
 	f_logp(BSCVTY, "f_est_lchan_and_mode_modify_to_vamos done");
+	COORD.send(DONE);
+	COORD.receive(DONE);
+	f_perform_clear(RSL);
 }
 
 /* Second, VAMOS shadow lchan of TC_vamos_multiplex_tch_h_tch_h_tch_h_tch_h() */
 private function f_TC_vamos_multiplex_tch_h_tch_h2(charstring id) runs on MSC_ConnHdlr {
+	f_sleep(1.0);
+	COORD.receive(DONE);
 	f_est_and_reassign_to_secondary_lchan(valueof(t_RslChanNr_Osmo_VAMOS_Lm(5, 0)));
+	COORD2.send(DONE);
+	COORD2.receive(DONE)
+	COORD.send(DONE);
+	f_perform_clear(RSL);
+}
+
+private function f_TC_vamos_multiplex_tch_h_tch_h3(charstring id) runs on MSC_ConnHdlr {
+	f_sleep(1.0);
+	COORD.receive(DONE);
+	f_est_lchan_and_mode_modify_to_vamos();
+	f_logp(BSCVTY, "f_est_lchan_and_mode_modify_to_vamos done");
+	COORD2.send(DONE);
+	COORD2.receive(DONE);
+	COORD.send(DONE);
+	f_perform_clear(RSL);
 }
 
 private function f_TC_vamos_multiplex_tch_h_tch_h4(charstring id) runs on MSC_ConnHdlr {
+	f_sleep(1.0);
+	COORD.receive(DONE);
 	f_est_and_reassign_to_secondary_lchan(valueof(t_RslChanNr_Osmo_VAMOS_Lm(5, 1)));
+	COORD.send(DONE);
+	f_perform_clear(RSL);
 }
 
 /* Establish a primary lchan and modify it to VAMOS speech mode. Then establish
@@ -725,17 +758,22 @@
 	pars4.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
 
 	vc_conn1 := f_start_handler(refers(f_TC_vamos_multiplex_tch_h_tch_h1), pars1);
-	vc_conn1.done;
-
 	vc_conn2 := f_start_handler(refers(f_TC_vamos_multiplex_tch_h_tch_h2), pars2);
-	vc_conn2.done;
 
 	/* Also fill up the second subslot of the TCH/H timeslot */
-	vc_conn3 := f_start_handler(refers(f_TC_vamos_multiplex_tch_h_tch_h1), pars3);
-	vc_conn3.done;
-
+	vc_conn3 := f_start_handler(refers(f_TC_vamos_multiplex_tch_h_tch_h3), pars3);
 	vc_conn4 := f_start_handler(refers(f_TC_vamos_multiplex_tch_h_tch_h4), pars4);
+
+	/* see diagram above (search for "---DONE") */
+	connect(vc_conn1:COORD, vc_conn2:COORD);
+	connect(vc_conn2:COORD2, vc_conn3:COORD);
+	connect(vc_conn3:COORD2, vc_conn4:COORD);
+
+	vc_conn1.done;
+	vc_conn2.done;
+	vc_conn3.done;
 	vc_conn4.done;
+
 	f_shutdown_helper();
 }
 
diff --git a/bsc/MSC_ConnectionHandler.ttcn b/bsc/MSC_ConnectionHandler.ttcn
index 4aeb539..109194b 100644
--- a/bsc/MSC_ConnectionHandler.ttcn
+++ b/bsc/MSC_ConnectionHandler.ttcn
@@ -447,6 +447,7 @@
 	port RAN_PROC_PT RAN;
 	port TELNETasp_PT BSCVTY;
 	port Coord_PT COORD;
+	port Coord_PT COORD2;
 
 	/* Proxy MGCP-over-IPA and MGCP-over-UDP */
 	port IPA_MGCP_PT MGCP_MSC_CLIENT;