Newer
Older
* @author ETSI / STF405
* @version $URL$
* $Id$
* @desc Module containing common functions for ITS
// LibCommon
import from LibCommon_Sync all;
import from LibCommon_VerdictControl all;
// LibIts
import from DENM_PDU_Descriptions language "ASN.1:1997" all; // TODO LibCommon shall be protocol independant?
import from LibItsCommon_Pixits all;
import from LibIts_Interface all;
import from LibItsCommon_TypesAndValues all;
/**
* @desc Requests to bring the IUT in an initial state
* @param p_init The initialisation to trigger.
*/
function f_utInitializeIut(template (value) UtInitialize p_init) runs on ItsAdapterComponent {
utPort.send(p_init);
tc_wait.start;
alt {
[] utPort.receive(UtResult:true) {
tc_wait.stop;
log("*** f_utInitializeIut: INFO: IUT initialized ***");
}
[] utPort.receive {
tc_wait.stop;
log("*** f_utInitializeIut: INFO: IUT could not be initialized ***");
f_selfOrClientSyncAndVerdict("error", e_error);
}
[] tc_wait.timeout {
log("*** f_utInitializeIut: INFO: IUT could not be initialized in time ***");
f_selfOrClientSyncAndVerdict("error", e_timeout);
}
[else] { // Shortcut defaults
repeat;
}
berge
committed
}
/**
* @desc Triggers event from the application layer
* @param p_event The event to trigger.
*/
function f_utTriggerEvent(template (value) UtEvent p_event) runs on ItsAdapterComponent {
var template (value) UtTrigger v_utMsg := { p_event };
utPort.send(v_utMsg);
alt {
[] utPort.receive(UtResult:true) {
tc_wait.stop;
}
[] utPort.receive {
tc_wait.stop;
}
[] tc_wait.timeout {
}
[else] { // Shortcut defaults
repeat;
}
berge
committed
}
/**
* @desc Checks that the event was indicated at the application layer
* @param p_event The event to check.
* @param p_discard The event should not appear. Default value: FALSE.
*/
function f_utCheckEvent(template (value) UtEvent p_event, boolean p_discard) runs on ItsAdapterComponent {
var template (value) UtCheck v_utMsg := { p_event };
utPort.send(v_utMsg);
tc_wait.start;
alt {
[] utPort.receive(UtResult:true) {
tc_wait.stop;
if (p_discard == false) {
log("*** f_utCheckEvent: INFO: Event correctly indicated at application layer ***");
}
else {
log("*** f_utCheckEvent: ERROR: Event indicated at application layer where it should be discarded ***");
f_selfOrClientSyncAndVerdict("error", e_error);
}
[] utPort.receive(UtResult:false) {
tc_wait.stop;
if (p_discard == false) {
log("*** f_utCheckEvent: ERROR: Event not correctly indicated at application layer ***");
f_selfOrClientSyncAndVerdict("error", e_error);
}
else {
log("*** f_utCheckEvent: INFO: Event not indicated at application layer***");
}
[] tc_wait.timeout {
log("*** f_utCheckEvent: ERROR: Timeout while waiting for event check result ***");
f_selfOrClientSyncAndVerdict("error", e_timeout);
}
[else] { // Shortcut defaults
repeat;
berge
committed
}
* @desc Send a command request primitive and wait for the command confirm response
* @param p_commandReq The command request
* @param p_commandConf The command confirm response
* @param p_discard Set to true if command confirm responses shall be discard, otherwise the function failed
* @param p_result The command/request confirm response
* @verdict Unchanged on success, fail otherwise
*/
in template (value) UtCommandRequest p_commandReq,
in template (present) UtCommandConfirm p_commandConf,
in boolean p_discard,
out UtCommandConfirm p_result)
runs on ItsAdapterComponent {
utPort.send(p_commandReq);
tc_wait.start;
alt {
[] utPort.receive(p_commandConf) -> value p_result{
tc_wait.stop;
}
[] utPort.receive {
tc_wait.stop;
if (p_discard == false) {
log("*** f_utCommandRequestConfirm: ERROR: Event not correctly indicated at application layer ***");
f_selfOrClientSyncAndVerdict("error", e_error);
}
else {
log("*** f_utCommandRequestConfirm: INFO: Another event indicated at application layer, repeating check ***");
repeat;
}
}
[] tc_wait.timeout {
if (p_discard == false) {
log("*** f_utCommandRequestConfirm: ERROR: Timeout while waiting for event check result ***");
f_selfOrClientSyncAndVerdict("error", e_timeout);
}
else {
log("*** f_utCommandRequestConfirm: INFO: Event not indicated at application layer ***");
/**
* @desc Send a command request primitive and do not wait for the command confirm response
* @param p_commandReq The command request
* @verdict Unchanged on success, fail otherwise
*/
function f_utCommandRequestWithoutConfirm(
in template (value) UtCommandRequest p_commandReq
) runs on ItsAdapterComponent {
utPort.send(p_commandReq);
} // End of function f_utCommandRequestWithoutConfirm
/**
* @desc Capture the next event sent to the Upper Tester
* @param p_event Receive template of the expected event
* @param p_result Return the value of the received event if template matchs
*/
function f_utCommandIndication(
in template UtCommandIndication p_event,
out UtCommandIndication p_result
) runs on ItsAdapterComponent {
tc_wait.start;
alt {
[] utPort.receive(p_event) -> value p_result {
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
tc_wait.stop;
}
[] utPort.receive {
tc_wait.stop;
log("*** f_utCommandIndication: INFO: Another event indicated at application layer, repeating check ***");
}
[] tc_wait.timeout {
log("*** f_utCommandIndication: ERROR: Timeout while waiting for event check result ***");
}
} // end of 'alt' statement
} // End of function f_utCommandIndication
} // End of group utFunctions
// /**
// * @desc Upper tester altsteps
// */
// group utAltstep {
//
//
// altstep a_utCommandRequest(in template UtCommandRequest p_commandReq) runs on ItsAdapterComponent {
// [] utPort.receive(p_commandReq) {
// log("*** a_utCommandRequest: INFO: Receive Command Request message ***");
// }
// } // End of altsetp a_utCommandRequest
//
// } // End of group utAltstep
group generalFunctions {
/**
* @desc function to generate integer random values
*
* @see ttcn-3 - rnd()
* @param p_lowerbound lowest number in range
* @param p_upperbound highest number in range
* @return random integer
*
*/
function f_random( in integer p_lowerbound,
in integer p_upperbound )
return integer {
//Variables
var integer v_random := 0;
v_random := float2int(int2float(p_upperbound - p_lowerbound +1)*rnd()) + p_lowerbound;
log("*** f_random: INFO: OK - random value = " & int2str(v_random) & " ***");
return v_random;
/**
* @desc Computes the absolute value of an integer
* @param p_number the number
* @return Absolute value of the number
*/
function f_abs(in integer p_number)
return integer {
if(p_number < 0) {
return 0 - p_number;
}
return p_number;
}
/**
* @desc Compares two values and returns the lowest onde
* @param p_a First value
* @param p_b Second value
* @return Lowest value
*/
function f_min(in integer p_a, in integer p_b)
return integer {
if(p_a < p_b) {
return p_a;
}
return p_b;
}
/**
* @desc Removes unsignificant right-most 0 bits of a bitstring
*
* @param p_bitstring Bitstring to be reduced
* @return Reduced bitstring
*
*/
function f_removeUnsignificantBits(in bitstring p_bitstring)
return bitstring {
var integer i, len;
len := lengthof(p_bitstring);
for(i:=len-1; i >=0 and p_bitstring[i] == '0'B; i:=i-1) {}
return substr(p_bitstring, 0, i + 1);
}
/**
* @desc Gets the current time
* @return Timestamp - current time in Epoch format
*/
function f_getCurrentTime() return TimeStamp {
var TimeStamp v_timeStamp := 0;
log("*** f_getCurrentTime: INFO: calling fx_getCurrentTime() ***");
v_timeStamp := fx_getCurrentTime();
return v_timeStamp;
}
} // end generalFunctions
group itsFunctions {
/**
* @desc Gets the station identifier of test system
* @return Test system's station ID
* @see PX_TESTER_STATION_ID
*/
function f_getTsStationId()
return StationID {
return PX_TESTER_STATION_ID;
} // end f_getTsStationId
/**
* @desc Gets the current position of test system
* @return Test system's position
*/
function f_getTsCurrentPosition() return ReferencePosition {
/* TODO: consider getting position from TA (as it is done for GN) */
} // end f_getTsCurrentPosition
} // end itsFunctions
group externalFunctions {
/**
* @desc This external function gets the current time
* @return Timestamp - current time in Epoch format
*/
external function fx_getCurrentTime() return TimeStamp;
} // end externalFunctions