module STP_Tests_Common {

/* Osmocom STP test suite in in TTCN-3
 * (C) 2019 Harald Welte <laforge@gnumonks.org>
 * All rights reserved.
 *
 * Released under the terms of GNU General Public License, Version 2 or
 * (at your option) any later version.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

friend module STP_Tests_M3UA;
friend module STP_Tests_IPA;
friend module STP_Tests_IPA_M3UA;
friend module STP_Tests_TCAP;

import from General_Types all;
import from Osmocom_Types all;

import from TELNETasp_PortType all;
import from Osmocom_VTY_Functions all;

import from IPL4asp_Types all;

import from SCCP_Types all;
import from SCCP_Templates all;
import from SCCPasp_Types all;
import from SCCP_Emulation all;

function f_SCCP_UDT(template (value) SCCP_PAR_Address calling := ts_SccpAddr_GT('5678'H),
		    template (value) SCCP_PAR_Address called := ts_SccpAddr_GT('1234'H),
		    template (omit) octetstring data := omit) return octetstring
{
	if (istemplatekind(data, "omit")) {
		data := f_rnd_octstring_rnd_len(100);
	}
	var PDU_SCCP sccp := valueof(ts_SCCP_UDT(calling, called, valueof(data)));
	var octetstring sccp_enc := enc_PDU_SCCP(sccp);
	return sccp_enc;
}

type component Test_CT {
	port TELNETasp_PT VTY;
	timer g_Tguard := 30.0;
	var boolean g_test_initialized := false;
}

private altstep as_gTguard() runs on Test_CT {
	[] g_Tguard.timeout {
		setverdict(fail, "Global guard timer timed out");
		mtc.stop;
		}
}

friend function f_init_common() runs on Test_CT {
	if (g_test_initialized) {
		return;
	}
	g_test_initialized := true;

	map(self:VTY, system:VTY);
	f_vty_set_prompts(VTY);
	f_vty_transceive(VTY, "enable");

	activate(as_gTguard());
	g_Tguard.start;
}



}
