blob: d29e43cf66a527c046e917cac5193337c943f279 [file] [log] [blame]
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2000-2018 Ericsson Telecom AB
//
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// which accompanies this distribution, and is available at
// http://www.eclipse.org/legal/epl-v10.html
///////////////////////////////////////////////////////////////////////////////
//
// File: MBT_Qtronic_Main.ttcn
// Rev: <RnXnn>
// Prodnr: CNL 113 659
// Updated: 2010-10-01
// Contact: http://ttcn.ericsson.se
///////////////////////////////////////////////////////////////////////////////
module MBT_Qtronic_Main
{
import from EPTF_MBT_LGen_Definitions all;
import from EPTF_MBT_LGen_Functions all;
import from EPTF_CLL_Common_Definitions all;
import from EPTF_CLL_Base_Definitions all;
import from EPTF_CLL_Base_Functions all;
import from EPTF_CLL_LGenBase_Definitions all;
import from EPTF_GTP_LGen_Definitions all;
import from EPTF_GTP_LGen_Functions all;
import from EPTF_GTP_Transport_Definitions all;
import from EPTF_GTP_Transport_Functions all;
import from EPTF_TELNET_Transport_Definitions all;
import from EPTF_TELNET_Transport_Functions all;
import from EPTF_TELNET_LGen_Definitions all;
import from EPTF_TELNET_LGen_Functions all;
import from EPTF_LANL2_Transport_Definitions all;
import from EPTF_LANL2_Transport_Functions all;
import from EPTF_LANL2_LGen_Definitions all;
import from EPTF_LANL2_LGen_Functions all;
import from MBT_Qtronic_Types all;
import from MBT_Qtronic_TestSystem all;
modulepar
{
boolean tsp_Mapper_enableDebug := false;
}
function f_Mapper_log(in charstring p_log)
{
if (tsp_Mapper_enableDebug) { log(p_log); }
}
type component MBT_Demo_LGen_CT extends EPTF_MBT_LGen_CT,
EPTF_GTP_LGen_CT, EPTF_GTP_LocalTransport_CT,
EPTF_TELNET_LGen_CT, EPTF_TELNET_LocalTransport_CT,
EPTF_LANL2_LGen_CT, EPTF_LANL2_LocalTransport_CT
{
}
type component MBT_Demo_Tester_CT extends EPTF_MBT_Tester_CT
{
port GnInPort GN_IN_LGEN_PCO;
port GnOutPort GN_OUT_LGEN_PCO;
port GiInPort GI_IN_LGEN_PCO;
port GiOutPort GI_OUT_LGEN_PCO;
}
type component MBT_Qtronic_Main_CT extends MBT_Demo_Tester_CT, MBT_Demo_LGen_CT
{
}
type component MBT_Demo_Main_CT extends EPTF_Base_CT {}
///////////////////////////////////////////////////////////////////////////////////
// Initialization
///////////////////////////////////////////////////////////////////////////////////
function f_cq_beginTestcase()
runs on QtronicCT
{
f_Mapper_log(log2str(%definitionId, " enter"));
// MBT Applib initialization
f_EPTF_MBT_Tester_init("MBT_Demo");
f_EPTF_MBT_init("MBT_Demo",0, "MBT_");
f_EPTF_MBT_initLGenFsm(refers(f_MBT_Demo_LGen_createUserMessage), null);
// GTP Applib initialization
f_EPTF_GTP_init(
pl_selfName:="GTP_LoadGen",
pl_selfId:=0,
pl_entityNamePrefix:="GTP_AppLib_",
pl_numEntities:=0);
f_EPTF_GTP_LocalTransport_init_CT();
vf_EPTF_GTP_sendMessage:=refers(f_EPTF_GTP_LocalTransport_sendMessage);
vf_EPTF_GTP_handleMessage:=refers(f_EPTF_GTP_LocalTransport_handleMessage);
vf_EPTF_GTP_cleanUpTransport:=refers(f_EPTF_GTP_LocalTransport_cleanUpTransport);
vf_EPTF_GTP_LocalTransport_receive:=refers(f_EPTF_GTP_messageHandler);
// TELNET Applib initialization
f_EPTF_TELNET_init(
pl_selfName := "TELNET_AppLib",
pl_selfId := 0,
pl_entityNamePrefix := "TELNET_",
pl_numEntities := 0,
pl_bind := refers(f_EPTF_TELNET_bindEntity4Behavior)
);
f_EPTF_TELNET_LocalTransport_init_CT(
pl_selfName:= "EPTF_TELNET_LocalTransport",
pl_receiveFunction:= refers(f_EPTF_TELNET_messageReceived),
pl_eventReceiveFunction:= refers(f_EPTF_TELNET_eventReceived)
);
vf_EPTF_TELNET_newTransportUser:=refers( f_EPTF_TELNET_LocalTransport_newTransportUser);
vf_EPTF_TELNET_sendMessage := refers(f_EPTF_TELNET_LocalTransport_sendMessage)
vf_EPTF_TELNET_playList:=refers(f_EPTF_TELNET_LocalTransport_playListElement)
// LANL2 Applib initialization
f_EPTF_LANL2_init(
pl_selfName := "IPL2_AppLib",
pl_selfId := 0,
pl_entityNamePrefix := "IPL2_",
pl_numEntities := 0,
pl_bind := refers(f_EPTF_LANL2_bindEntity4Behavior)
);
f_EPTF_LANL2_LocalTransport_init_CT(
pl_selfName:= c_EPTF_LANL2_Transport_LGenType,
pl_receiveFunction:= refers(f_EPTF_LANL2_messageReceived),
pl_eventReceiveFunction:= refers(f_EPTF_LANL2_eventReceived)
);
f_EPTF_LANL2_setSendMessageFunction(plf_sendMessageFunction := refers(f_EPTF_LANL2_LocalTransport_sendMessage));
f_EPTF_LANL2_setEchoMessageFunction(plf_echoMessageFunction := refers(f_EPTF_LANL2_LocalTransport_echoMessage));
f_EPTF_LANL2_setListenFunction(plf_listenFunction := refers(f_EPTF_LANL2_LocalTransport_listen));
f_EPTF_LANL2_setCloseFunction(plf_closeFunction := refers(f_EPTF_LANL2_LocalTransport_close));
// Connecting the MBT Test Harness with the Tester component
connect(self:EPTF_MBT_PCO, self:EPTF_MBT_TESTER_PCO);
connect(self:GN_IN_LGEN_PCO, self:GnIn);
connect(self:GN_OUT_LGEN_PCO, self:GnOut);
connect(self:GI_IN_LGEN_PCO, self:GiIn);
connect(self:GI_OUT_LGEN_PCO, self:GiOut);
// Creating 1 entity with 1 MBT_FSM
EPTF_MBT_TESTER_PCO.send(EPTF_MBT_ConfigRequest:
{
entityGroupName := "MBT_EntityType",
noEntities := 1,
behaviors := {c_EPTF_MBT_myBName, c_EPTF_GTP_behavior, c_EPTF_TELNET_behavior},
fsmName := "FSM_MBT"
}
);
// TODO: activate default altstep, with timeout handling
EPTF_MBT_TESTER_PCO.receive(EPTF_MBT_ConfigResponse:?);
//Activating GTP Echo Handler
f_MBT_Demo_LGen_activateEchoHandler();
f_Mapper_log(log2str(%definitionId, " finished"));
}
function f_cq_endTestcase()
runs on MBT_Qtronic_Main_CT
{
f_Mapper_log(log2str(%definitionId, " enter"));
f_EPTF_Base_stopAll(none);
f_Mapper_log(log2str(%definitionId, " finished"));
}
///////////////////////////////////////////////////////////////////////////////////
// Mapping Testcase -> Test Harness
///////////////////////////////////////////////////////////////////////////////////
function f_Model_sendCreatePDPContext(in CreatePDPcontext p_CreatePDPcontext)
runs on MBT_Qtronic_Main_CT
{
f_Mapper_log(log2str(%definitionId, " enter ", p_CreatePDPcontext));
// Creating a GTP session in the test harness
f_MBT_execute(c_EPTF_GTP_stepName_init, valueof(t_addr(0)));
// Start listening on Gi
f_MBT_execute(c_EPTF_LANL2_stepName_init, valueof(t_addr(0)), {0});
f_MBT_execute(c_EPTF_LANL2_stepName_listen, valueof(t_addr(0)));
// Example of setting the parameters for the GTP session
var EPTF_GTP_FSM_Ctx p_client_ctx;
f_EPTF_GTP_getContext(f_convert_FsmAddr2TestStepArgs(valueof(t_addr(0))), p_client_ctx);
p_client_ctx.primaryCtx.imsi := f_getIMSI_str2hex(p_CreatePDPcontext.imsi);
p_client_ctx.primaryCtx.apn := f_getAPN_char2oct(p_CreatePDPcontext.apn);
p_client_ctx.primaryCtx.msisdn := f_getMSISDN_str2hex(p_CreatePDPcontext.imsi);
f_EPTF_GTP_setContext(f_convert_FsmAddr2TestStepArgs(valueof(t_addr(0))), p_client_ctx);
// Example ends
// Generating a PDP context request
f_MBT_execute(c_EPTF_GTP_stepName_createPDPContextRequest, valueof(t_addr(0)));
// Example of how to update the generated message
f_EPTF_GTP_getContext(f_convert_FsmAddr2TestStepArgs(valueof(t_addr(0))), p_client_ctx);
p_client_ctx.gtpcMsgToSend.gtpc_pdu.createPDPContextRequest.charging_char.chargingChar := '0800'O;
f_EPTF_GTP_setContext(f_convert_FsmAddr2TestStepArgs(valueof(t_addr(0))), p_client_ctx);
// Example ends
// Sending the message
f_MBT_execute(c_EPTF_GTP_stepName_sendMessage, valueof(t_addr(0)));
f_Mapper_log(log2str(%definitionId, " finished"));
}
function f_Model_sendUpdatePDPContext(in UpdatePDPcontext p_UpdatePDPcontext)
runs on MBT_Qtronic_Main_CT
{
f_Mapper_log(log2str(%definitionId, " enter ", p_UpdatePDPcontext));
// Generating an update PDP context message by the test harness
f_MBT_execute(c_EPTF_GTP_stepName_updatePDPContextRequest, valueof(t_addr(0)));
// Sending the message
f_MBT_execute(c_EPTF_GTP_stepName_sendMessage, valueof(t_addr(0)));
f_Mapper_log(log2str(%definitionId, " finished"));
}
function f_Model_sendDeletePDPContext(in DeletePDPcontext p_DeletePDPcontext)
runs on MBT_Qtronic_Main_CT
{
f_Mapper_log(log2str(%definitionId, " enter ", p_DeletePDPcontext));
f_MBT_execute(c_EPTF_GTP_stepName_deletePDPContextRequest, valueof(t_addr(0)));
f_MBT_execute(c_EPTF_GTP_stepName_sendMessage, valueof(t_addr(0)));
f_Mapper_log(log2str(%definitionId, " finished"));
}
function f_Model_sendGPDU(in GPDU p_gpdu)
runs on MBT_Qtronic_Main_CT
{
f_Mapper_log(log2str(%definitionId, " enter ", p_gpdu));
// First we load the Payload we want to send in the GTP tunnel into the GTP Context
var EPTF_GTP_FSM_Ctx p_client_ctx;
f_EPTF_GTP_getContext(f_convert_FsmAddr2TestStepArgs(valueof(t_addr(0))), p_client_ctx);
p_client_ctx.primaryCtx.payload :=
f_EPTF_GTP_createUDPpacket(
f_EPTF_GTP_convertIP_oct2str(p_client_ctx.primaryCtx.end_user_address), //"20.46.0.2",
tsp_EPTF_LANL2_connectionInfoList[0].remPort,
tsp_EPTF_LANL2_connectionInfoList[0].locHost,
tsp_EPTF_LANL2_connectionInfoList[0].locPort,
tsp_EPTF_LANL2_connectionInfoList[0].payload
);
f_EPTF_GTP_setContext(f_convert_FsmAddr2TestStepArgs(valueof(t_addr(0))), p_client_ctx);
// Then we generate the GPDU. The previously loaded payload will be in the generated PDU.
f_MBT_execute(c_EPTF_GTP_stepName_createGTPU, valueof(t_addr(0)));
// It can be now sent out.
f_MBT_execute(c_EPTF_GTP_stepName_sendGTPU, valueof(t_addr(0)));
f_Mapper_log(log2str(%definitionId, " finished"));
}
function f_Model_sendUDPpdu(in UDPpdu p_UDPpdu)
runs on MBT_Qtronic_Main_CT
{
f_Mapper_log(log2str(%definitionId, " enter ", p_UDPpdu));
f_MBT_execute(c_EPTF_LANL2_stepName_sendMessage, valueof(t_addr(0)), {0});
f_Mapper_log(log2str(%definitionId, " finished"));
}
///////////////////////////////////////////////////////////////////////////////////
// Message handling: Test Harness -> Testcase
///////////////////////////////////////////////////////////////////////////////////
function f_MBT_Demo_LGen_createUserMessage(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on MBT_Qtronic_Main_CT
return boolean
{
// This function catches the events that are generated by the test harness when a message is received.
// The purpose of this function to create the message structure that is expected by the model (and thus by the generated test case code)
f_Mapper_log(log2str(%definitionId & " creating message for:\n", pl_ptr, "\n", pl_ptr.reportedEvent));
// CreatePDPContextResponse
if (pl_ptr.reportedEvent.event.bIdx == v_EPTF_GTP_myBIdx and pl_ptr.reportedEvent.event.iIdx == c_EPTF_GTP_inputIdx_createPDPContextResponse)
{
f_MBT_execute(c_EPTF_GTP_stepName_handleIncomingMessage, valueof(t_addr(0)));
var integer vl_cause :=
oct2int(v_EPTF_GTP_lastReceived.msg.gtpc.gtpc_pdu.createPDPContextResponse.cause.causevalue);
GN_OUT_LGEN_PCO.send(CreatePDPresponse:{vl_cause});
}
// UpdatePDPContextResponse
else if (pl_ptr.reportedEvent.event.bIdx == v_EPTF_GTP_myBIdx and pl_ptr.reportedEvent.event.iIdx == c_EPTF_GTP_inputIdx_updatePDPContextResponse)
{
f_MBT_execute(c_EPTF_GTP_stepName_handleIncomingMessage, valueof(t_addr(0)));
var integer vl_cause :=
oct2int(v_EPTF_GTP_lastReceived.msg.gtpc.gtpc_pdu.updatePDPContextResponse.updatePDPContextResponseSGSN.cause.causevalue);
GN_OUT_LGEN_PCO.send(UpdatePDPresponse:{vl_cause});
}
// DeletePDPContextResponse
else if (pl_ptr.reportedEvent.event.bIdx == v_EPTF_GTP_myBIdx and pl_ptr.reportedEvent.event.iIdx == c_EPTF_GTP_inputIdx_deletePDPContextResponse)
{
f_MBT_execute(c_EPTF_GTP_stepName_handleIncomingMessage, valueof(t_addr(0)));
var integer vl_cause :=
oct2int(v_EPTF_GTP_lastReceived.msg.gtpc.gtpc_pdu.deletePDPContextResponse.cause.causevalue);
GN_OUT_LGEN_PCO.send(DeletePDPresponse:{vl_cause});
f_MBT_execute(c_EPTF_GTP_stepName_cleanUp, valueof(t_addr(0)));
}
// Incoming GTPU
else if (pl_ptr.reportedEvent.event.bIdx == v_EPTF_GTP_myBIdx and pl_ptr.reportedEvent.event.iIdx == c_EPTF_GTP_inputIdx_GTPU)
{
// Access and convert the payload here
var octetstring vl_payload := ''O;
var integer vl_data := 0;
if (f_EPTF_GTP_getUDPpayload(vl_payload))
{
vl_data := oct2int(vl_payload);
}
GN_OUT_LGEN_PCO.send(GPDU:{data := vl_data});
}
// Incmoing LANL2
else if (pl_ptr.reportedEvent.event.bIdx == v_EPTF_LANL2_myBIdx and pl_ptr.reportedEvent.event.iIdx == c_EPTF_LANL2_inputIdx_incomingMessage)
{
// Access and convert the payload here
var octetstring vl_payload := ''O;
var integer vl_data := 0;
if (f_EPTF_LANL2_getLastUDP(f_convert_FsmAddr2TestStepArgs(valueof(t_addr(0))), vl_payload))
{
vl_data := oct2int(vl_payload);
}
GI_OUT_LGEN_PCO.send(UDPpdu:{data := vl_data});
}
else
{
f_Mapper_log(log2str(%definitionId & "(): unhandled incoming message"));
return false;
}
return true;
}
///////////////////////////////////////////////////////////////////////////////////
// FSM Activation
///////////////////////////////////////////////////////////////////////////////////
function f_MBT_Demo_LGen_activateEchoHandler() runs on MBT_Qtronic_Main_CT
{
f_EPTF_GTP_declareEchoHandlerFsm();
var EPTF_MBT_LGen_Definitions.FsmAddr vl_addr;
f_MBT_activateFsm("MBT_EntityType", 0, "FSM_GTP_EchoHandler", vl_addr);
f_MBT_dispatch(c_EPTF_LGenBase_behavior, c_EPTF_LGenBase_inputIdx_testMgmt_startTC, vl_addr);
}
///////////////////////////////////////////////////////////////////////////////////
// Utility functions
///////////////////////////////////////////////////////////////////////////////////
function f_EPTF_TELNET_bindEntity4Behavior(
in integer pl_eIdx)
runs on QtronicCT
return EPTF_IntegerList
{
return {pl_eIdx};
}
function f_getAPN_char2oct(in charstring p_apn)
return octetstring
{
var octetstring vl_ret := '04'O & char2oct(p_apn)
for (var integer i:=0; i<lengthof(vl_ret); i:=i+1){ if (vl_ret[i]=='2E'O) { vl_ret[i] := '03'O } }
f_Mapper_log(log2str(%definitionId, " in ", p_apn, " -> ", vl_ret));
return vl_ret;
}
function f_getIMSI_str2hex(in charstring p_imsi_str)
return hexstring
{
var hexstring vl_ret := f_str2tbcd(p_imsi_str);
f_Mapper_log(log2str(%definitionId, " in ", p_imsi_str, " -> ", vl_ret));
return vl_ret;
}
function f_getMSISDN_str2hex(in charstring p_imsi_str)
return octetstring
{
var octetstring vl_ret := ''O;
var hexstring vl_imsi := f_str2tbcd(p_imsi_str);
vl_imsi := substr(vl_imsi, lengthof(vl_imsi)-6, 6);
vl_ret := '916464'O & f_encodeTBCD_hex2oct(vl_imsi);
f_Mapper_log(log2str(%definitionId, " in ", p_imsi_str, " -> ", vl_ret));
return vl_ret;
}
function f_str2tbcd(in charstring p_str)
return hexstring
{
var hexstring vl_ret := ''H;
for (var integer i:=0; i<lengthof(p_str); i:=i+1)
{
vl_ret[i] := int2hex(str2int(p_str[i]),1);
}
return vl_ret;
}
function f_encodeTBCD_hex2oct( in hexstring pl_hex )
return octetstring
{
var integer vl_size:= lengthof(pl_hex);
if((vl_size mod 2) == 1)
{
pl_hex := pl_hex & 'F'H;
vl_size := vl_size + 1;
}
vl_size := vl_size / 2;
var integer vl_i;
var octetstring vl_oct := ''O;
for (vl_i := 0; vl_i < vl_size; vl_i := vl_i + 1)
{
vl_oct := vl_oct & hex2oct(pl_hex[(2*vl_i) + 1] & pl_hex[2*vl_i]);
}
return vl_oct;
}
template EPTF_MBT_LGen_Definitions.FsmAddr t_addr(integer eIdx) :=
{
entityGroupName := "MBT_EntityType",
eIdx := eIdx,
fIdx := 0
}
}