blob: 32892b3fcc9f1328f3165e38c85e4f693df060f0 [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 v2.0
// which accompanies this distribution, and is available at
// https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
///////////////////////////////////////////////////////////////////////////////
//
// File: SCTP_Daemon_Dynamic_Test.ttcn
// Description: SDD test
// Rev: <RnXnn>
// Prodnr: CNL 113 630
// Updated: 2010-11-26
// Contact: http://ttcn.ericsson.se
module SCTP_Daemon_Dynamic_Test
{
//=========================================================================
// Import Part
//=========================================================================
import from SCTP_Daemon_Dynamic_Interface_Definitions all;
import from IPL4asp_Types all;
import from SCTP_Daemon_Dynamic_IPL4_CtrlFunct all;
//=========================================================================
// Module Parameters
//=========================================================================
modulepar {
// Host name where the SCTP Daemon listens for the testcases
charstring tsp_SDD_Host := "127.0.0.1";
// Port number where the SCTP Daemon listens for the testcases
integer tsp_SDD_Port := 1314;
//charstring tsp_remoteHost := "127.0.0.1";
//integer tsp_remotePort := 1315;
charstring tsp_serverInterface := "127.0.0.1";
integer tsp_serverPort := 1315;
}
//=========================================================================
// Data Types
//=========================================================================
// Insert data type defintions here if applicable!
// You can use the data_type skeleton!
//=========================================================================
//Port Types
//=========================================================================
// Insert port type defintions here if applicable!
// You can use the port_type skeleton!
//=========================================================================
//Component Types
//=========================================================================
type component MAIN_CT {
port SDD_Interface_PT daemonPort;
var SDD_Message_with_ClientId vc_daemonMessage;
var integer vc_tcp_client_id;
var integer vc_serverAssociationId := -1;
var integer vc_clientAssociationId := -1;
var integer vc_connectedClientAssociationId := -1;
}
//=========================================================================
// Constants
//=========================================================================
// Insert constants here if applicable!
// You can use the constant skeleton!
//=========================================================================
// Templates
//=========================================================================
// Insert templates here if applicable!
// You can use the template skeleton!
//=========================================================================
// Altsteps
//=========================================================================
// Insert altsteps here if applicable!
// You can use the altstep skeleton!
//=========================================================================
// Functions
//=========================================================================
function f_Connect_to_SDD() runs on MAIN_CT {
timer t_wait;
var Result vl_result := { errorCode := omit, connId := omit, os_error_code:=omit, os_error_text:= omit };
vl_result := SCTP_Daemon_Dynamic_IPL4_CtrlFunct.f_IPL4_connect
(
daemonPort,
tsp_SDD_Host,
tsp_SDD_Port,
tsp_serverInterface,
0,
connId := -1,
proto :={tcp:={}},
options := {}
);
if ((vl_result.errorCode == omit) or (vl_result.errorCode == IPL4_ERROR_TEMPORARILY_UNAVAILABLE)) //if not error
{
log("Connected to the SCTP Daemon2 on " & tsp_SDD_Host & ":" & int2str(tsp_SDD_Port));
vc_tcp_client_id := vl_result.connId;
var f_IPL4_getMsgLen sdd_msglen := refers(f_SDD_getMsgLen);
f_IPL4_setGetMsgLen(daemonPort,vc_tcp_client_id,sdd_msglen,{});
}else{
log("Could not connect to the SCTP Daemon2 on " & tsp_SDD_Host & ":" & int2str(tsp_SDD_Port));
}
t_wait.start(2.0); t_wait.timeout;
}
// initialize a server and a client connection if they are not already present
function f_Init_SCTP_Client(in charstring remoteIf, in integer remotePort) runs on MAIN_CT {
daemonPort.send(SDD_Message_with_ClientId : { vc_tcp_client_id, { queryAssociations := { 0 } } });
timer t_wait := 5.0; t_wait.start;
alt {
[] daemonPort.receive(SDD_Message_with_ClientId : { ?, { associations := ? } }) -> value vc_daemonMessage {
vc_clientAssociationId := -1;
for(var integer i := 0; i < sizeof(vc_daemonMessage.msg.associations.associationList); i := i + 1) {
if((vc_clientAssociationId < 0) and ispresent(vc_daemonMessage.msg.associations.associationList[i].remoteInterface)) {
if(vc_daemonMessage.msg.associations.associationList[i].remoteInterface.hostName == remoteIf and
vc_daemonMessage.msg.associations.associationList[i].remoteInterface.portNumber == remotePort) {
vc_clientAssociationId := vc_daemonMessage.msg.associations.associationList[i].associationId;
}
}
}
if(vc_clientAssociationId < 0) {
daemonPort.send(SDD_Message_with_ClientId : { vc_tcp_client_id, {
sctpConnect := {
messageType := 0, // use dummy value
autoReconnect := true,
localInterfacePresent := false, // enter always false
localInterface :={
hostNameLength := 0, // use dummy value
hostName := remoteIf,
portNumber := remotePort + 1000
},
remoteInterface := {
hostNameLength := 0, // use dummy value
hostName := remoteIf,
portNumber := remotePort
}
}
}});
t_wait.stop; t_wait.start;
alt {
[] daemonPort.receive(SDD_Message_with_ClientId : { vc_tcp_client_id, { sctpResult := ? } }) -> value vc_daemonMessage {
if(not vc_daemonMessage.msg.sctpResult.errorStatus) {
vc_clientAssociationId := vc_daemonMessage.msg.sctpResult.associationId;
} else {
log("*** ERROR: error response received for defineClientAssociation: " ,vc_daemonMessage.msg.sctpResult);
setverdict(fail);
}
repeat;
}
[] daemonPort.receive(SDD_Message_with_ClientId : { vc_tcp_client_id, { sctpConnected := ? } }) -> value vc_daemonMessage {
log("*** INFO: Client connected: ", vc_daemonMessage);
vc_connectedClientAssociationId := vc_daemonMessage.msg.sctpConnected.associationId;
repeat;
}
[] t_wait.timeout {
if((vc_clientAssociationId==-1) and (vc_connectedClientAssociationId==-1)){
log("*** ERROR: no response to defineClientAssociation!");
setverdict(fail);
}
}
}
} else {
log("*** INFO: Client association is already defined, subscribing to it...");
daemonPort.send(SDD_Message_with_ClientId : { vc_tcp_client_id, {
subscribeToAssociation := {
messageType := 0,
associationId := vc_clientAssociationId
}
}
});
}
}
[] daemonPort.receive {
log("INFO: dropping this message.");
}
[] t_wait.timeout {
log("Error: there is no response for association list query!");
}
}
log("vc_clientAssociationId: ",vc_clientAssociationId);
log("vc_connectedClientAssociationId: ",vc_connectedClientAssociationId);
}
function f_Init_SCTP_Server(in charstring localIf, in integer localPort) runs on MAIN_CT {
daemonPort.send(SDD_Message_with_ClientId : { vc_tcp_client_id, { queryAssociations := { 0 } } });
timer t_wait := 5.0; t_wait.start;
alt {
[] daemonPort.receive(SDD_Message_with_ClientId : { ?, { associations := ? } }) -> value vc_daemonMessage {
vc_serverAssociationId := -1;
for(var integer i := 0; i < sizeof(vc_daemonMessage.msg.associations.associationList); i := i + 1) {
if((vc_serverAssociationId < 0) and ispresent(vc_daemonMessage.msg.associations.associationList[i].localInterface)) {
if(vc_daemonMessage.msg.associations.associationList[i].localInterface.hostName == localIf and
vc_daemonMessage.msg.associations.associationList[i].localInterface.portNumber == localPort) {
vc_serverAssociationId := vc_daemonMessage.msg.associations.associationList[i].associationId;
}
}
// connected client: not server and the local interface is the same as the server's local interface
if((vc_connectedClientAssociationId < 0) and ispresent(vc_daemonMessage.msg.associations.associationList[i].localInterface)) {
if(not vc_daemonMessage.msg.associations.associationList[i].serverAssociation and
vc_daemonMessage.msg.associations.associationList[i].localInterface.hostName == localIf and
vc_daemonMessage.msg.associations.associationList[i].localInterface.portNumber == localPort) {
vc_connectedClientAssociationId := vc_daemonMessage.msg.associations.associationList[i].associationId;
}
}
}
if(vc_connectedClientAssociationId > -1) {
log("*** INFO: Server's connected client association is already present, subscribing to it...");
daemonPort.send(SDD_Message_with_ClientId : { vc_tcp_client_id, {
subscribeToAssociation := {
messageType := 0,
associationId := vc_connectedClientAssociationId
}
}
});
}
if(vc_serverAssociationId < 0) {
daemonPort.send(SDD_Message_with_ClientId : { vc_tcp_client_id, {
sctpListen := {
messageType := 0, // use dummy value
localInterface := {
hostNameLength := 0, // use dummy value
hostName := localIf,
portNumber := localPort
}
}
} });
t_wait.stop; t_wait.start;
alt {
[] daemonPort.receive(SDD_Message_with_ClientId : { vc_tcp_client_id, { sctpResult := ? } }) -> value vc_daemonMessage {
log("Received result message: ",vc_daemonMessage);
if(not vc_daemonMessage.msg.sctpResult.errorStatus) {
vc_serverAssociationId := vc_daemonMessage.msg.sctpResult.associationId;
} else {
log("*** ERROR: error response received for defineServerAssociation: ", vc_daemonMessage.msg.sctpResult);
setverdict(fail);
}
}
[] daemonPort.receive(SDD_Message_with_ClientId:?) {
log("Message ignored.");
repeat;
}
[] t_wait.timeout {
log("*** ERROR: no response to defineServerAssociation!");
setverdict(fail);
}
}
} else {
log("*** INFO: Server association is already defined, subscribing to it...");
daemonPort.send(SDD_Message_with_ClientId : { vc_tcp_client_id, {
subscribeToAssociation := {
messageType := 0,
associationId := vc_serverAssociationId
}
}
});
}
}
[] daemonPort.receive {
log("INFO: dropping this message.");
repeat;
}
[] t_wait.timeout {
log("Error: there is no response for association list query!");
}
}
log("vc_serverAssociationId: ",vc_serverAssociationId);
log("vc_connectedClientAssociationId: ",vc_connectedClientAssociationId);
}
function f_StopServer() runs on MAIN_CT {
if(vc_connectedClientAssociationId > 0) {
daemonPort.send(SDD_Message_with_ClientId : { vc_tcp_client_id, {
sctpClose := { messageType := 0, associationId := vc_connectedClientAssociationId }
}});
}
daemonPort.send(SDD_Message_with_ClientId : { vc_tcp_client_id, {
sctpClose := { messageType := 0, associationId := vc_serverAssociationId }
}});
}
function f_StopClient() runs on MAIN_CT {
daemonPort.send(SDD_Message_with_ClientId : { vc_tcp_client_id, {
sctpClose := { messageType := 0, associationId := vc_clientAssociationId }
}});
}
// initialize a server and a client connection if they are not already present
function f_StopMyAssociations() runs on MAIN_CT {
daemonPort.send(SDD_Message_with_ClientId : { vc_tcp_client_id, { queryAssociations := { 0 } } });
timer t_wait := 5.0; t_wait.start;
alt {
[] daemonPort.receive(SDD_Message_with_ClientId : { ?, { associations := ? } }) -> value vc_daemonMessage {
log("Current associations: ", vc_daemonMessage.msg.associations.associationList);
vc_clientAssociationId := -1;
for(var integer i := 0; i < sizeof(vc_daemonMessage.msg.associations.associationList); i := i + 1) {
if(ispresent(vc_daemonMessage.msg.associations.associationList[i].localInterface)) {
if(vc_daemonMessage.msg.associations.associationList[i].localInterface.hostName == tsp_serverInterface) {
daemonPort.send(SDD_Message_with_ClientId : { vc_tcp_client_id, {
sctpClose := { messageType := 0, associationId := vc_daemonMessage.msg.associations.associationList[i].associationId }
}});
}
}
if(ispresent(vc_daemonMessage.msg.associations.associationList[i].remoteInterface)) {
if(vc_daemonMessage.msg.associations.associationList[i].remoteInterface.hostName == tsp_serverInterface) {
daemonPort.send(SDD_Message_with_ClientId : { vc_tcp_client_id, {
sctpClose := { messageType := 0, associationId := vc_daemonMessage.msg.associations.associationList[i].associationId }
}});
}
}
}
}
[] t_wait.timeout {
log("Error: there is no response for association list query!");
}
}
}
function f_CheckClientAssociation_Gets(in SAC_STATE pl_state) runs on MAIN_CT {
timer t_wait := 55.0; t_wait.start;
log("WAITING: waiting client association #", vc_clientAssociationId, " to report state: ", pl_state);
alt {
[] daemonPort.receive(SDD_Message_with_ClientId : {
client_id := vc_tcp_client_id,
msg := {
associationChanged := {
messageType := ?,
associationId := vc_clientAssociationId,
state := pl_state
}
}
}) {
log("*** PASS: associationStateChanged ", pl_state, " received!");
setverdict(pass);
/*if(pl_state == SCTP_COMM_LOST) {
daemonPort.send(SDD_Message_with_ClientId : { vc_tcp_client_id, {
closeAssociation := { messageType := 0, associationId := vc_clientAssociationId }
}});
}*/
}
[] daemonPort.receive(SDD_Message_with_ClientId:?){
log("Message ignored.");
repeat;
}
[] t_wait.timeout {
log("*** FAIL: No associationStateChanged ", pl_state," received!");
setverdict(fail);
}
}
}
function f_serverWaitForConnection() runs on MAIN_CT {
timer t_wait := 55.0; t_wait.start;
log("WAITING: waiting for client connection");
var SDD_Message_with_ClientId vl_msg;
alt {
[] daemonPort.receive(SDD_Message_with_ClientId : {
client_id := vc_tcp_client_id,
msg := {
sctpConnected := ?
}
}) -> value vl_msg
{
log("*** PASS: Connected! ");
vc_serverAssociationId := vl_msg.msg.sctpConnected.associationId;
setverdict(pass);
}
[] daemonPort.receive(SDD_Message_with_ClientId:?) {
log("Message ignored.");
repeat;
}
[] t_wait.timeout {
log("*** FAIL: No connection was received!");
setverdict(fail);
}
}
}
function f_sendDataFromClient(in octetstring dataToSend) runs on MAIN_CT {
daemonPort.send(SDD_Message_with_ClientId : { vc_tcp_client_id, {
sctpData := {
messageType := 0, // encoder will replace
associationId := vc_clientAssociationId,
sinfo_stream := 11,
sinfo_ppid := 22,
dataLength := 0, // encoder will replace
data := dataToSend
}
}});
}
function f_sendDataFromServer(in octetstring dataToSend) runs on MAIN_CT {
daemonPort.send(SDD_Message_with_ClientId : { vc_tcp_client_id, {
sctpData := {
messageType := 0, // encoder will replace
associationId := vc_serverAssociationId,
sinfo_stream := 11,
sinfo_ppid := 22,
dataLength := 0, // encoder will replace
data := dataToSend
}
}});
}
function f_sendData(in integer assocId, in octetstring dataToSend) runs on MAIN_CT {
daemonPort.send(SDD_Message_with_ClientId : { vc_tcp_client_id, {
sctpData := {
messageType := 0, // encoder will replace
associationId := assocId,
sinfo_stream := 11,
sinfo_ppid := 22,
dataLength := 0, // encoder will replace
data := dataToSend
}
}});
}
function f_CheckDataReceive(in integer associationId, in octetstring dataToReceive) runs on MAIN_CT {
timer t_wait := 5.0; t_wait.start;
alt {
[] daemonPort.receive(SDD_Message_with_ClientId : {
client_id := vc_tcp_client_id,
msg := {
sctpData := {
messageType := ?,
associationId := associationId,
sinfo_stream := 11,
sinfo_ppid := ?,//22,
dataLength := ?,
data := dataToReceive
}
}
}) {
log("*** PASS: sctpData ", dataToReceive, " received!");
setverdict(pass);
}
[] daemonPort.receive(SDD_Message_with_ClientId:?) {
log("Message ignored.");
repeat;
}
[] t_wait.timeout {
log("*** FAIL: No sctpData ", dataToReceive, " received!");
setverdict(fail);
}
}
}
function f_CheckDataReceive_noOtherData(in template integer associationId, in template octetstring dataToReceive) runs on MAIN_CT {
timer t_wait := 5.0; t_wait.start;
alt {
[] daemonPort.receive(SDD_Message_with_ClientId : {
client_id := vc_tcp_client_id,
msg := {
sctpData := {
messageType := ?,
associationId := associationId,
sinfo_stream := 11,
sinfo_ppid := ?,//22,
dataLength := ?,
data := dataToReceive
}
}
}) {
log("*** PASS: sctpData ", dataToReceive, " received!");
setverdict(pass);
}
[] daemonPort.receive(SDD_Message_with_ClientId : {
client_id := vc_tcp_client_id,
msg := {
sctpData := {
messageType := ?,
associationId := associationId,
sinfo_stream := 11,
sinfo_ppid := ?,//22,
dataLength := ?,
data := ?
}
}
}) {
log("*** FAIL: invalid sctpData received!");
setverdict(fail);
repeat;
}
[] daemonPort.receive(SDD_Message_with_ClientId:?) {
log("Message ignored.");
repeat;
}
[] t_wait.timeout {
log("*** FAIL: No sctpData ", dataToReceive, " received!");
setverdict(fail);
}
}
}
function f_ServerEchoBack(in float p_serviceTime := 5.0) runs on MAIN_CT {
timer t_wait := p_serviceTime; t_wait.start;
var SDD_Message_with_ClientId vl_inc;
alt {
[] daemonPort.receive(SDD_Message_with_ClientId : {
client_id := vc_tcp_client_id,
msg := {
sctpData := {
messageType := ?,
associationId := ?,
sinfo_stream := 11,
sinfo_ppid := ?,//22,
dataLength := ?,
data := ?
}
}
}) -> value vl_inc
{
daemonPort.send(SDD_Message_with_ClientId : { vc_tcp_client_id, {
sctpData := {
messageType := 0, // encoder will replace
associationId := vc_serverAssociationId,
sinfo_stream := 11,
sinfo_ppid := 22,
dataLength := 0, // encoder will replace
data := vl_inc.msg.sctpData.data
}
}});
repeat;
}
[] daemonPort.receive(SDD_Message_with_ClientId:?) {
log("Message ignored in Echo mode");
repeat;
}
[] t_wait.timeout {
log("Exiting from echo service");
}
}
}
//=========================================================================
// Testcases
//=========================================================================
testcase tc_InitClientServer_StopServer_CheckClientAssocChange() runs on MAIN_CT {
map(mtc:daemonPort, system:daemonPort);
f_Connect_to_SDD();
f_Init_SCTP_Server(tsp_serverInterface, tsp_serverPort);
f_Init_SCTP_Client(tsp_serverInterface, tsp_serverPort);
f_StopServer();
f_CheckClientAssociation_Gets(SCTP_COMM_LOST);
f_StopClient();
//timer t_wait := 5.0; t_wait.start; t_wait.timeout;
unmap(mtc:daemonPort, system:daemonPort);
}
testcase tc_InitClientServer_StopServer_StartServer_CheckClientAssocChange() runs on MAIN_CT {
map(mtc:daemonPort, system:daemonPort);
f_Connect_to_SDD();
f_Init_SCTP_Server(tsp_serverInterface, tsp_serverPort);
f_Init_SCTP_Client(tsp_serverInterface, tsp_serverPort);
f_CheckClientAssociation_Gets(SCTP_COMM_UP);
f_StopServer();
f_Init_SCTP_Server(tsp_serverInterface, tsp_serverPort);
f_CheckClientAssociation_Gets(SCTP_COMM_UP);
f_StopServer();
f_StopClient();
unmap(mtc:daemonPort, system:daemonPort);
}
testcase tc_InitClientServer_Disconnect_Connect_InitClientServer_SendDataFromClient_CheckDataReceiveOnServer() runs on MAIN_CT {
map(mtc:daemonPort, system:daemonPort);
f_Connect_to_SDD();
f_Init_SCTP_Server(tsp_serverInterface, tsp_serverPort);
f_Init_SCTP_Client(tsp_serverInterface, tsp_serverPort);
// could be sending ASP_TCP_Close too
unmap(mtc:daemonPort, system:daemonPort);
map(mtc:daemonPort, system:daemonPort);
f_Connect_to_SDD();
f_Init_SCTP_Server(tsp_serverInterface, tsp_serverPort);
f_Init_SCTP_Client(tsp_serverInterface, tsp_serverPort);
f_sendDataFromClient('EEDDAADD'O);
f_CheckDataReceive(vc_connectedClientAssociationId, 'EEDDAADD'O);
f_StopServer();
f_StopClient();
unmap(mtc:daemonPort, system:daemonPort);
}
testcase tc_3Servers_and_3Clients() runs on MAIN_CT {
map(mtc:daemonPort, system:daemonPort);
f_Connect_to_SDD();
vc_connectedClientAssociationId := -1;
f_Init_SCTP_Server(tsp_serverInterface, tsp_serverPort + 2);
f_Init_SCTP_Client(tsp_serverInterface, tsp_serverPort + 2);
f_sendDataFromClient('EEDDAADD00'O);
f_CheckDataReceive(vc_connectedClientAssociationId, 'EEDDAADD00'O);
vc_connectedClientAssociationId := -1;
f_Init_SCTP_Server(tsp_serverInterface, tsp_serverPort + 1);
f_Init_SCTP_Client(tsp_serverInterface, tsp_serverPort + 1);
f_sendDataFromClient('EEDDAADD11'O);
f_CheckDataReceive(vc_connectedClientAssociationId, 'EEDDAADD11'O);
vc_connectedClientAssociationId := -1;
f_Init_SCTP_Server(tsp_serverInterface, tsp_serverPort);
f_Init_SCTP_Client(tsp_serverInterface, tsp_serverPort);
f_sendDataFromClient('EEDDAADD22'O);
f_CheckDataReceive(vc_connectedClientAssociationId, 'EEDDAADD22'O);
f_StopMyAssociations();
unmap(mtc:daemonPort, system:daemonPort);
}
testcase tc_AutoReplyDeviceWatchdog() runs on MAIN_CT {
map(mtc:daemonPort, system:daemonPort);
f_Connect_to_SDD();
f_Init_SCTP_Server(tsp_serverInterface, tsp_serverPort);
f_Init_SCTP_Client(tsp_serverInterface, tsp_serverPort);
// 4th byte/bit1: request == 0
// 5-7th byte: 280 == hex 118
f_sendDataFromClient('00112200000118778899AABBCCDDEEFF'O);
// 4th byte/bit1: reply == 1
f_CheckDataReceive(vc_clientAssociationId, '00112280000118778899AABBCCDDEEFF'O);
f_StopServer();
f_StopClient();
unmap(mtc:daemonPort, system:daemonPort);
}
//=========================================================================
// Control
//=========================================================================
control {
execute(tc_InitClientServer_StopServer_CheckClientAssocChange());
execute(tc_InitClientServer_StopServer_StartServer_CheckClientAssocChange());
execute(tc_InitClientServer_Disconnect_Connect_InitClientServer_SendDataFromClient_CheckDataReceiveOnServer());
execute(tc_AutoReplyDeviceWatchdog());
}
} // end of module