| /////////////////////////////////////////////////////////////////////////////// |
| // Copyright (c) 2000-2019 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: IP_Daemon_Dynamic_Test.ttcn |
| // Description: IPDD test |
| // Rev: <RnXnn> |
| // Prodnr: CNL 113 630 |
| // Updated: 2012-05-07 |
| // Contact: http://ttcn.ericsson.se |
| |
| module IP_Daemon_Dynamic_Test |
| { |
| |
| //========================================================================= |
| // Import Part |
| //========================================================================= |
| |
| import from IP_Daemon_Dynamic_Interface_Definitions all; |
| |
| import from IPL4asp_Types all; |
| import from IP_Daemon_Dynamic_IPL4_CtrlFunct all; |
| //========================================================================= |
| // Module Parameters |
| //========================================================================= |
| |
| modulepar { |
| |
| // Host name where the IP Daemon listens for the testcases |
| charstring tsp_IPDD_Host := "127.0.0.1"; |
| |
| // Port number where the IP Daemon listens for the testcases |
| integer tsp_IPDD_Port := 1314; |
| |
| charstring tsp_serverInterface := "127.0.0.1"; |
| integer tsp_serverPort := 1315; |
| } |
| |
| //========================================================================= |
| // Data Types |
| //========================================================================= |
| |
| type record of integer clientConnectionIds; |
| |
| //========================================================================= |
| //Port Types |
| //========================================================================= |
| |
| // Insert port type defintions here if applicable! |
| // You can use the port_type skeleton! |
| |
| //========================================================================= |
| //Component Types |
| //========================================================================= |
| |
| type component MAIN_CT { |
| port IPDD_Interface_PT daemonPort; |
| |
| var IPDD_Message_with_ClientId vc_daemonMessage; |
| |
| var clientConnectionIds vc_clientConnIds := {}; |
| |
| var integer vc_tcp_client_id; |
| var integer vc_serverConnectionId := -1; |
| var integer vc_clientConnectionId := -1; |
| var integer vc_connectedClientConnectionId := -1; |
| var boolean vc_isClientConnected := false; |
| } |
| |
| //========================================================================= |
| // 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_IPDD() 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 := IP_Daemon_Dynamic_IPL4_CtrlFunct.f_IPL4_connect |
| ( |
| daemonPort, |
| tsp_IPDD_Host, |
| tsp_IPDD_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 IP Daemon on " & tsp_IPDD_Host & ":" & int2str(tsp_IPDD_Port)); |
| vc_tcp_client_id := vl_result.connId; |
| |
| var f_IPL4_getMsgLen sdd_msglen := refers(f_IPDD_getMsgLen); |
| f_IPL4_setGetMsgLen(daemonPort, vc_tcp_client_id,sdd_msglen, {}); |
| |
| }else{ |
| log("Could not connect to the IP Daemon on " & tsp_IPDD_Host & ":" & int2str(tsp_IPDD_Port)); |
| } |
| } |
| |
| // initialize a server and a client connection if they are not already present |
| function f_Init_IP_Client(in charstring remoteIf, in integer remotePort, in ProtoTupleEnum proto) runs on MAIN_CT { |
| daemonPort.send(IPDD_Message_with_ClientId : { vc_tcp_client_id, { ipdd_queryConnections := { 0 } } }); |
| |
| timer t_wait := 5.0; t_wait.start; |
| alt { |
| [] daemonPort.receive(IPDD_Message_with_ClientId : { ?, { ipdd_connections := ? } }) -> value vc_daemonMessage { |
| |
| vc_clientConnectionId := -1; |
| |
| for(var integer i := 0; i < sizeof(vc_daemonMessage.msg.ipdd_connections.connectionList); i := i + 1) { |
| if((vc_clientConnectionId < 0) and ispresent(vc_daemonMessage.msg.ipdd_connections.connectionList[i].remoteInterface)) { |
| if(vc_daemonMessage.msg.ipdd_connections.connectionList[i].remoteInterface.hostName == remoteIf and |
| vc_daemonMessage.msg.ipdd_connections.connectionList[i].remoteInterface.portNumber == remotePort) { |
| vc_clientConnectionId := vc_daemonMessage.msg.ipdd_connections.connectionList[i].connectionId; |
| } |
| } |
| } |
| |
| if(vc_clientConnectionId < 0) { |
| daemonPort.send(IPDD_Message_with_ClientId : { vc_tcp_client_id, { |
| ipdd_connect := { |
| messageType := 0, // use dummy value |
| autoReconnect := true, |
| localInterfacePresent := false, // enter always false |
| localInterface :={ |
| hostNameLength := 0, // use dummy value |
| hostName := remoteIf, |
| portNumber := 0 |
| }, |
| remoteInterface := { |
| hostNameLength := 0, // use dummy value |
| hostName := remoteIf, |
| portNumber := remotePort |
| }, |
| proto := proto, |
| sctpProtoAttributesPresent := false, |
| sctpProtoAttributes := omit |
| } |
| }}); |
| |
| t_wait.stop; t_wait.start; |
| alt { |
| [] daemonPort.receive(IPDD_Message_with_ClientId : { vc_tcp_client_id, { ipdd_result := ? } }) -> value vc_daemonMessage { |
| if(not vc_daemonMessage.msg.ipdd_result.errorStatus) { |
| vc_clientConnectionId := vc_daemonMessage.msg.ipdd_result.connectionId; |
| } else { |
| log("*** ERROR: error response received for f_Init_IP_Client: " ,vc_daemonMessage.msg.ipdd_result); |
| setverdict(fail); |
| } |
| repeat; |
| } |
| [] daemonPort.receive(IPDD_Message_with_ClientId : { vc_tcp_client_id, { ipdd_connected := ? } }) -> value vc_daemonMessage { |
| log("*** INFO: client connected: ", vc_daemonMessage); |
| vc_connectedClientConnectionId := vc_daemonMessage.msg.ipdd_connected.connectionId; |
| vc_isClientConnected := true; |
| repeat; |
| } |
| [] t_wait.timeout { |
| if((vc_clientConnectionId == -1) and (vc_connectedClientConnectionId == -1)){ |
| log("*** ERROR: no response to f_Init_IP_Client!"); |
| setverdict(fail); |
| } |
| } |
| } |
| } else { |
| log("*** INFO: client connection is already defined, subscribing to it..."); |
| daemonPort.send(IPDD_Message_with_ClientId : { vc_tcp_client_id, { |
| ipdd_subscribeToConnection := { |
| messageType := 0, |
| connectionId := vc_clientConnectionId |
| } |
| } |
| }); |
| } |
| } |
| |
| [] daemonPort.receive { |
| log("*** INFO: message ignored."); |
| } |
| |
| [] t_wait.timeout { |
| log("*** ERROR: there is no response for connection list query!"); |
| } |
| } |
| log("vc_clientConnectionId: ",vc_clientConnectionId); |
| log("vc_connectedClientConnectionId: ",vc_connectedClientConnectionId); |
| } |
| |
| function f_Init_IP_Server(in charstring localIf, in integer localPort, in ProtoTupleEnum pl_proto) runs on MAIN_CT { |
| daemonPort.send(IPDD_Message_with_ClientId : { vc_tcp_client_id, { ipdd_queryConnections := { 0 } } }); |
| |
| timer t_wait := 5.0; t_wait.start; |
| alt { |
| [] daemonPort.receive(IPDD_Message_with_ClientId : { ?, { ipdd_connections := ? } }) -> value vc_daemonMessage { |
| |
| vc_serverConnectionId := -1; |
| vc_connectedClientConnectionId := -1; |
| |
| for(var integer i := 0; i < sizeof(vc_daemonMessage.msg.ipdd_connections.connectionList); i := i + 1) { |
| if((vc_serverConnectionId < 0) and ispresent(vc_daemonMessage.msg.ipdd_connections.connectionList[i].localInterface)) { |
| if(vc_daemonMessage.msg.ipdd_connections.connectionList[i].serverConnection and |
| vc_daemonMessage.msg.ipdd_connections.connectionList[i].localInterface.hostName == localIf and |
| vc_daemonMessage.msg.ipdd_connections.connectionList[i].localInterface.portNumber == localPort) { |
| vc_serverConnectionId := vc_daemonMessage.msg.ipdd_connections.connectionList[i].connectionId; |
| } |
| } |
| |
| // connected client: not server and the local interface is the same as the server's local interface |
| if((vc_connectedClientConnectionId < 0) and ispresent(vc_daemonMessage.msg.ipdd_connections.connectionList[i].localInterface)) { |
| if(not vc_daemonMessage.msg.ipdd_connections.connectionList[i].serverConnection and |
| vc_daemonMessage.msg.ipdd_connections.connectionList[i].localInterface.hostName == localIf and |
| vc_daemonMessage.msg.ipdd_connections.connectionList[i].localInterface.portNumber == localPort) { |
| vc_connectedClientConnectionId := vc_daemonMessage.msg.ipdd_connections.connectionList[i].connectionId; |
| } |
| } |
| } |
| |
| if(vc_connectedClientConnectionId > -1) { |
| log("*** INFO: server's connected client connection is already present, subscribing to it..."); |
| daemonPort.send(IPDD_Message_with_ClientId : { vc_tcp_client_id, { |
| ipdd_subscribeToConnection := { |
| messageType := 0, |
| connectionId := vc_connectedClientConnectionId |
| } |
| } |
| }); |
| } |
| |
| if(vc_serverConnectionId < 0) { |
| daemonPort.send(IPDD_Message_with_ClientId : { vc_tcp_client_id, { |
| ipdd_listen := { |
| messageType := 0, // use dummy value |
| localInterface := { |
| hostNameLength := 0, // use dummy value |
| hostName := localIf, |
| portNumber := localPort |
| }, |
| proto := pl_proto, |
| sctpProtoAttributesPresent := false, |
| sctpProtoAttributes := omit |
| } |
| } }); |
| |
| t_wait.stop; t_wait.start; |
| alt { |
| [] daemonPort.receive(IPDD_Message_with_ClientId : { vc_tcp_client_id, { ipdd_result := ? } }) -> value vc_daemonMessage { |
| log("*** INFO: received result message: ",vc_daemonMessage); |
| if(not vc_daemonMessage.msg.ipdd_result.errorStatus) { |
| vc_serverConnectionId := vc_daemonMessage.msg.ipdd_result.connectionId; |
| } else { |
| log("*** ERROR: error response received for f_Init_IP_Server: ", vc_daemonMessage.msg.ipdd_result); |
| setverdict(fail); |
| } |
| } |
| [] daemonPort.receive(IPDD_Message_with_ClientId : ?) { |
| log("*** INFO: message ignored."); |
| repeat; |
| } |
| [] t_wait.timeout { |
| log("*** ERROR: no response to f_Init_IP_Server!"); |
| setverdict(fail); |
| } |
| } |
| } else { |
| log("*** INFO: server connection is already defined, subscribing to it..."); |
| daemonPort.send(IPDD_Message_with_ClientId : { vc_tcp_client_id, { |
| ipdd_subscribeToConnection := { |
| messageType := 0, |
| connectionId := vc_serverConnectionId |
| } |
| } |
| }); |
| } |
| } |
| |
| [] daemonPort.receive { |
| log("*** INFO: message ignored."); |
| repeat; |
| } |
| |
| [] t_wait.timeout { |
| log("*** ERROR: there is no response for connection list query!"); |
| } |
| } |
| log("vc_serverConnectionId: ",vc_serverConnectionId); |
| log("vc_connectedClientConnectionId: ",vc_connectedClientConnectionId); |
| } |
| |
| function f_StopServer() runs on MAIN_CT { |
| if(vc_connectedClientConnectionId > 0) { |
| daemonPort.send(IPDD_Message_with_ClientId : { vc_tcp_client_id, { |
| ipdd_close := { messageType := 0, connectionId := vc_connectedClientConnectionId } |
| }}); |
| } |
| |
| daemonPort.send(IPDD_Message_with_ClientId : { vc_tcp_client_id, { |
| ipdd_close := { messageType := 0, connectionId := vc_serverConnectionId } |
| }}); |
| } |
| |
| function f_StopClient() runs on MAIN_CT { |
| daemonPort.send(IPDD_Message_with_ClientId : { vc_tcp_client_id, { |
| ipdd_close := { messageType := 0, connectionId := vc_clientConnectionId } |
| }}); |
| } |
| |
| function f_StopMultipleClients() runs on MAIN_CT { |
| for(var integer i := 0; i < sizeof(vc_clientConnIds); i := i + 1) { |
| daemonPort.send(IPDD_Message_with_ClientId : { vc_tcp_client_id, { |
| ipdd_close := { messageType := 0, connectionId := vc_clientConnIds[i] } |
| }}); |
| } |
| |
| vc_clientConnIds := {}; |
| } |
| |
| // initialize a server and a client connection if they are not already present |
| function f_StopMyConnections() runs on MAIN_CT { |
| daemonPort.send(IPDD_Message_with_ClientId : { vc_tcp_client_id, { ipdd_queryConnections := { 0 } } }); |
| |
| timer t_wait := 5.0; t_wait.start; |
| alt { |
| [] daemonPort.receive(IPDD_Message_with_ClientId : { ?, { ipdd_connections := ? } }) -> value vc_daemonMessage { |
| log("*** INFO: current ipdd_connections: ", vc_daemonMessage.msg.ipdd_connections.connectionList); |
| vc_clientConnectionId := -1; |
| for(var integer i := 0; i < sizeof(vc_daemonMessage.msg.ipdd_connections.connectionList); i := i + 1) { |
| if(ispresent(vc_daemonMessage.msg.ipdd_connections.connectionList[i].localInterface)) { |
| if(vc_daemonMessage.msg.ipdd_connections.connectionList[i].localInterface.hostName == tsp_serverInterface) { |
| daemonPort.send(IPDD_Message_with_ClientId : { vc_tcp_client_id, { |
| ipdd_close := { messageType := 0, connectionId := vc_daemonMessage.msg.ipdd_connections.connectionList[i].connectionId } |
| }}); |
| } |
| } |
| |
| if(ispresent(vc_daemonMessage.msg.ipdd_connections.connectionList[i].remoteInterface)) { |
| if(vc_daemonMessage.msg.ipdd_connections.connectionList[i].remoteInterface.hostName == tsp_serverInterface) { |
| daemonPort.send(IPDD_Message_with_ClientId : { vc_tcp_client_id, { |
| ipdd_close := { messageType := 0, connectionId := vc_daemonMessage.msg.ipdd_connections.connectionList[i].connectionId } |
| }}); |
| } |
| } |
| } |
| } |
| |
| [] t_wait.timeout { |
| log("*** ERROR: there is no response for connection list query!"); |
| } |
| } |
| } |
| |
| function f_CheckClientConnection_Gets(in SAC_STATE pl_state) runs on MAIN_CT { |
| timer t_wait := 55.0; t_wait.start; |
| |
| log("*** INFO: waiting client connection #", vc_clientConnectionId, " to report state: ", pl_state, "."); |
| |
| alt { |
| [] daemonPort.receive(IPDD_Message_with_ClientId : { |
| client_id := vc_tcp_client_id, |
| msg := { |
| ipdd_connectionChanged := { |
| messageType := ?, |
| connectionId := vc_clientConnectionId, |
| eventPresent := false, |
| event := omit, |
| sctpStatePresent := true, |
| sctpState := pl_state |
| } |
| } |
| }) { |
| log("*** PASS: connectionChanged ", pl_state, " received!"); |
| setverdict(pass); |
| } |
| [] daemonPort.receive(IPDD_Message_with_ClientId : { vc_tcp_client_id, { ipdd_connected := ? } }) -> value vc_daemonMessage { |
| log("*** INFO: client connected: ", vc_daemonMessage); |
| vc_connectedClientConnectionId := vc_daemonMessage.msg.ipdd_connected.connectionId; |
| repeat; |
| } |
| [] daemonPort.receive(IPDD_Message_with_ClientId:?) { |
| log("*** INFO: message ignored."); |
| repeat; |
| } |
| [] t_wait.timeout { |
| log("*** FAIL: no connectionChanged ", pl_state," received!"); |
| setverdict(fail); |
| } |
| } |
| } |
| |
| function f_serverWaitForConnection() runs on MAIN_CT { |
| timer t_wait := 55.0; t_wait.start; |
| log("*** INFO: waiting for client connection..."); |
| var IPDD_Message_with_ClientId vl_msg; |
| alt { |
| [] daemonPort.receive(IPDD_Message_with_ClientId : { |
| client_id := vc_tcp_client_id, |
| msg := { |
| ipdd_connected := ? |
| } |
| }) -> value vl_msg |
| { |
| log("*** PASS: Connected! "); |
| vc_serverConnectionId := vl_msg.msg.ipdd_connected.connectionId; |
| setverdict(pass); |
| } |
| [] daemonPort.receive(IPDD_Message_with_ClientId:?) { |
| log("*** INFO: message ignored."); |
| repeat; |
| } |
| [] t_wait.timeout { |
| log("*** FAIL: no connection was received!"); |
| setverdict(fail); |
| } |
| } |
| } |
| |
| function f_sendDataFromClient(in octetstring dataToSend, in ProtoTupleEnum proto) runs on MAIN_CT { |
| if(proto == sctp) { |
| daemonPort.send(IPDD_Message_with_ClientId : { vc_tcp_client_id, { |
| ipdd_data := { |
| messageType := 0, // encoder will replace |
| connectionId := vc_clientConnectionId, |
| sctpAttributesPresent := true, |
| sctpAttributes := { |
| sinfo_stream := 11, |
| sinfo_ppid := 22 |
| }, |
| dataLength := 0, // encoder will replace |
| data := dataToSend |
| } |
| }}); |
| } |
| if(proto == tcp or proto == udp) { |
| daemonPort.send(IPDD_Message_with_ClientId : { vc_tcp_client_id, { |
| ipdd_data := { |
| messageType := 0, // encoder will replace |
| connectionId := vc_clientConnectionId, |
| sctpAttributesPresent := false, |
| sctpAttributes := omit, |
| dataLength := 0, // encoder will replace |
| data := dataToSend |
| } |
| }}); |
| } |
| } |
| |
| function f_sendDataFromServer(in octetstring dataToSend, in ProtoTupleEnum proto) runs on MAIN_CT { |
| if(proto == sctp) { |
| daemonPort.send(IPDD_Message_with_ClientId : { vc_tcp_client_id, { |
| ipdd_data := { |
| messageType := 0, // encoder will replace |
| connectionId := vc_serverConnectionId, |
| sctpAttributesPresent := true, |
| sctpAttributes := { |
| sinfo_stream := 11, |
| sinfo_ppid := 22 |
| }, |
| dataLength := 0, // encoder will replace |
| data := dataToSend |
| } |
| }}); |
| } |
| if(proto == tcp or proto == udp) { |
| daemonPort.send(IPDD_Message_with_ClientId : { vc_tcp_client_id, { |
| ipdd_data := { |
| messageType := 0, // encoder will replace |
| connectionId := vc_serverConnectionId, |
| sctpAttributesPresent := false, |
| sctpAttributes := omit, |
| dataLength := 0, // encoder will replace |
| data := dataToSend |
| } |
| }}); |
| } |
| } |
| |
| function f_sendData(in integer connId, in octetstring dataToSend, in ProtoTupleEnum proto) runs on MAIN_CT { |
| if(proto == sctp) { |
| daemonPort.send(IPDD_Message_with_ClientId : { vc_tcp_client_id, { |
| ipdd_data := { |
| messageType := 0, // encoder will replace |
| connectionId := connId, |
| sctpAttributesPresent := true, |
| sctpAttributes := { |
| sinfo_stream := 11, |
| sinfo_ppid := 22 |
| }, |
| dataLength := 0, // encoder will replace |
| data := dataToSend |
| } |
| }}); |
| } |
| if(proto == tcp or proto == udp) { |
| daemonPort.send(IPDD_Message_with_ClientId : { vc_tcp_client_id, { |
| ipdd_data := { |
| messageType := 0, // encoder will replace |
| connectionId := connId, |
| sctpAttributesPresent := false, |
| sctpAttributes := omit, |
| dataLength := 0, // encoder will replace |
| data := dataToSend |
| } |
| }}); |
| } |
| } |
| |
| function f_CheckDataReceive(in integer connectionId, in octetstring dataToReceive) runs on MAIN_CT { |
| timer t_wait := 5.0; t_wait.start; |
| |
| log("*** INFO: waiting for incoming data: ", dataToReceive, "..."); |
| |
| alt { |
| [] daemonPort.receive(IPDD_Message_with_ClientId : { |
| client_id := vc_tcp_client_id, |
| msg := { |
| ipdd_data := { |
| messageType := ?, |
| connectionId := connectionId, |
| sctpAttributesPresent := true, |
| sctpAttributes := { |
| sinfo_stream := 11, |
| sinfo_ppid := ? //22 |
| }, |
| dataLength := ?, |
| data := dataToReceive |
| } |
| } |
| }) { |
| log("*** PASS: ipdd_data ", dataToReceive, " received!"); |
| setverdict(pass); |
| } |
| |
| [] daemonPort.receive(IPDD_Message_with_ClientId : { |
| client_id := vc_tcp_client_id, |
| msg := { |
| ipdd_data := { |
| messageType := ?, |
| connectionId := connectionId, |
| sctpAttributesPresent := false, |
| sctpAttributes := omit, |
| dataLength := ?, |
| data := dataToReceive |
| } |
| } |
| }) { |
| log("*** PASS: ipdd_data ", dataToReceive, " received!"); |
| setverdict(pass); |
| } |
| |
| [] daemonPort.receive(IPDD_Message_with_ClientId:?) { |
| log("*** INFO: message ignored."); |
| repeat; |
| } |
| |
| [] t_wait.timeout { |
| log("*** FAIL: no ipdd_data ", dataToReceive, " received!"); |
| setverdict(fail); |
| } |
| } |
| } |
| |
| function f_CheckDataReceive_noOtherData(in template integer connectionId, in template octetstring dataToReceive) runs on MAIN_CT { |
| timer t_wait := 5.0; t_wait.start; |
| |
| alt { |
| [] daemonPort.receive(IPDD_Message_with_ClientId : { |
| client_id := vc_tcp_client_id, |
| msg := { |
| ipdd_data := { |
| messageType := ?, |
| connectionId := connectionId, |
| sctpAttributesPresent := true, |
| sctpAttributes := { |
| sinfo_stream := 11, |
| sinfo_ppid := ? //22 |
| }, |
| dataLength := ?, |
| data := dataToReceive |
| } |
| } |
| }) { |
| log("*** PASS: ipdd_data ", dataToReceive, " received!"); |
| setverdict(pass); |
| } |
| |
| [] daemonPort.receive(IPDD_Message_with_ClientId : { |
| client_id := vc_tcp_client_id, |
| msg := { |
| ipdd_data := { |
| messageType := ?, |
| connectionId := connectionId, |
| sctpAttributesPresent := true, |
| sctpAttributes := { |
| sinfo_stream := 11, |
| sinfo_ppid := ? //22 |
| }, |
| dataLength := ?, |
| data := ? |
| } |
| } |
| }) { |
| log("*** FAIL: invalid ipdd_data received!"); |
| setverdict(fail); |
| repeat; |
| } |
| |
| [] daemonPort.receive(IPDD_Message_with_ClientId:?) { |
| log("*** INFO: message ignored."); |
| repeat; |
| } |
| |
| [] t_wait.timeout { |
| log("*** FAIL: no ipdd_data ", 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 IPDD_Message_with_ClientId vl_inc; |
| |
| alt { |
| [] daemonPort.receive(IPDD_Message_with_ClientId : { |
| client_id := vc_tcp_client_id, |
| msg := { |
| ipdd_data := { |
| messageType := ?, |
| connectionId := ?, |
| sctpAttributesPresent := true, |
| sctpAttributes := { |
| sinfo_stream := 11, |
| sinfo_ppid := ? //22 |
| }, |
| dataLength := ?, |
| data := ? |
| } |
| } |
| }) -> value vl_inc |
| { |
| daemonPort.send(IPDD_Message_with_ClientId : { vc_tcp_client_id, { |
| ipdd_data := { |
| messageType := 0, // encoder will replace |
| connectionId := vc_serverConnectionId, |
| sctpAttributesPresent := true, |
| sctpAttributes := { |
| sinfo_stream := 11, |
| sinfo_ppid := 22 |
| }, |
| dataLength := 0, // encoder will replace |
| data := vl_inc.msg.ipdd_data.data |
| } |
| }}); |
| repeat; |
| } |
| |
| [] daemonPort.receive(IPDD_Message_with_ClientId:?) { |
| log("*** INFO: message ignored in Echo mode."); |
| repeat; |
| } |
| |
| [] t_wait.timeout { |
| log("*** INFO: exiting from echo service."); |
| } |
| } |
| } |
| |
| function f_Check_ConnClosed_Received(in integer pl_connId) runs on MAIN_CT { |
| timer t := 5.0; t.start; |
| |
| alt { |
| [] daemonPort.receive(IPDD_Message_with_ClientId : { |
| client_id := vc_tcp_client_id, |
| msg := { |
| ipdd_closed := { |
| messageType := ?, |
| connectionId := pl_connId |
| } |
| } |
| }) { |
| log("*** PASS: ipdd_closed message from IPDD received for connectionId: ", pl_connId, "!"); |
| setverdict(pass); |
| t.stop; t.start; |
| repeat; |
| } |
| |
| [] daemonPort.receive { |
| log("*** INFO: message ignored."); |
| repeat; |
| } |
| |
| [] t.timeout { |
| log("*** INFO: no more relevant messages received."); |
| } |
| } |
| } |
| |
| function f_Init_IP_Client_with_localInterface( |
| in charstring localIf, in integer localPort, in charstring remoteIf, in integer remotePort, in ProtoTupleEnum proto) runs on MAIN_CT { |
| |
| daemonPort.send(IPDD_Message_with_ClientId : { vc_tcp_client_id, { ipdd_queryConnections := { 0 } } }); |
| |
| timer t_wait := 5.0; t_wait.start; |
| alt { |
| [] daemonPort.receive(IPDD_Message_with_ClientId : { ?, { ipdd_connections := ? } }) -> value vc_daemonMessage { |
| |
| vc_clientConnectionId := -1; |
| |
| for(var integer i := 0; i < sizeof(vc_daemonMessage.msg.ipdd_connections.connectionList); i := i + 1) { |
| if((vc_clientConnectionId < 0) and ispresent(vc_daemonMessage.msg.ipdd_connections.connectionList[i].remoteInterface)) { |
| if(vc_daemonMessage.msg.ipdd_connections.connectionList[i].remoteInterface.hostName == remoteIf and |
| vc_daemonMessage.msg.ipdd_connections.connectionList[i].remoteInterface.portNumber == remotePort) { |
| vc_clientConnectionId := vc_daemonMessage.msg.ipdd_connections.connectionList[i].connectionId; |
| } |
| } |
| } |
| |
| if(vc_clientConnectionId < 0) { |
| daemonPort.send(IPDD_Message_with_ClientId : { vc_tcp_client_id, { |
| ipdd_connect := { |
| messageType := 0, // use dummy value |
| autoReconnect := true, |
| localInterfacePresent := true, |
| localInterface :={ |
| hostNameLength := 0, // use dummy value |
| hostName := localIf, |
| portNumber := localPort |
| }, |
| remoteInterface := { |
| hostNameLength := 0, // use dummy value |
| hostName := remoteIf, |
| portNumber := remotePort |
| }, |
| proto := proto, |
| sctpProtoAttributesPresent := false, |
| sctpProtoAttributes := omit |
| } |
| }}); |
| |
| t_wait.stop; t_wait.start; |
| alt { |
| [] daemonPort.receive(IPDD_Message_with_ClientId : { vc_tcp_client_id, { ipdd_result := ? } }) -> value vc_daemonMessage { |
| if(not vc_daemonMessage.msg.ipdd_result.errorStatus) { |
| vc_clientConnectionId := vc_daemonMessage.msg.ipdd_result.connectionId; |
| vc_clientConnIds[sizeof(vc_clientConnIds)] := vc_clientConnectionId; |
| } else { |
| log("*** ERROR: error response received for ipdd_connect: " ,vc_daemonMessage.msg.ipdd_result); |
| setverdict(fail); |
| } |
| repeat; |
| } |
| [] daemonPort.receive(IPDD_Message_with_ClientId : { vc_tcp_client_id, { ipdd_connected := ? } }) -> value vc_daemonMessage { |
| log("*** INFO: client connected: ", vc_daemonMessage); |
| vc_connectedClientConnectionId := vc_daemonMessage.msg.ipdd_connected.connectionId; |
| vc_isClientConnected := true; |
| repeat; |
| } |
| [] t_wait.timeout { |
| if((vc_clientConnectionId == -1) and (vc_connectedClientConnectionId == -1)){ |
| log("*** ERROR: no response to ipdd_connect!"); |
| setverdict(fail); |
| } |
| } |
| } |
| } else { |
| log("*** INFO: client connection is already defined, subscribing to it..."); |
| daemonPort.send(IPDD_Message_with_ClientId : { vc_tcp_client_id, { |
| ipdd_subscribeToConnection := { |
| messageType := 0, |
| connectionId := vc_clientConnectionId |
| } |
| } |
| }); |
| } |
| } |
| |
| [] daemonPort.receive { |
| log("*** INFO: message ignored."); |
| } |
| |
| [] t_wait.timeout { |
| log("*** ERROR: there is no response for connection list query!"); |
| } |
| } |
| log("vc_clientConnectionId: ",vc_clientConnectionId); |
| log("vc_connectedClientConnectionId: ",vc_connectedClientConnectionId); |
| } |
| |
| //========================================================================= |
| // Testcases |
| //========================================================================= |
| |
| testcase tc_Init_2_UDP_Clients_sendData_checkDataReceived() runs on MAIN_CT { |
| map(mtc:daemonPort, system:daemonPort); |
| |
| f_Connect_to_IPDD(); |
| |
| f_Init_IP_Client_with_localInterface(tsp_serverInterface, tsp_serverPort, tsp_serverInterface, tsp_serverPort + 1, udp); |
| f_Init_IP_Client_with_localInterface(tsp_serverInterface, tsp_serverPort + 1, tsp_serverInterface, tsp_serverPort, udp); |
| |
| f_sendData(vc_clientConnIds[0], '0123456789ABCDEF'O, udp); |
| |
| f_CheckDataReceive(vc_clientConnIds[1], '0123456789ABCDEF'O); |
| |
| f_StopMultipleClients(); |
| |
| unmap(mtc:daemonPort, system:daemonPort); |
| } |
| |
| testcase tc_Init_TCP_ClientServer_StopServer_CheckClientConnClosed() runs on MAIN_CT { |
| map(mtc:daemonPort, system:daemonPort); |
| |
| f_Connect_to_IPDD(); |
| |
| f_Init_IP_Server(tsp_serverInterface, tsp_serverPort, tcp); |
| f_Init_IP_Client(tsp_serverInterface, tsp_serverPort, tcp); |
| |
| f_StopServer(); |
| |
| f_Check_ConnClosed_Received(vc_clientConnectionId); |
| |
| f_StopClient(); |
| |
| unmap(mtc:daemonPort, system:daemonPort); |
| } |
| |
| testcase tc_Init_SCTP_ClientServer_StopServer_CheckClientConnChange() runs on MAIN_CT { |
| map(mtc:daemonPort, system:daemonPort); |
| |
| f_Connect_to_IPDD(); |
| |
| f_Init_IP_Server(tsp_serverInterface, tsp_serverPort, sctp); |
| f_Init_IP_Client(tsp_serverInterface, tsp_serverPort, sctp); |
| f_StopServer(); |
| |
| f_CheckClientConnection_Gets(SCTP_COMM_LOST); |
| |
| f_StopClient(); |
| |
| unmap(mtc:daemonPort, system:daemonPort); |
| } |
| |
| testcase tc_Init_SCTP_ClientServer_CheckClientConnChange_StopServer_CheckClientConnChange_StartServer_CheckClientConnChange() runs on MAIN_CT { |
| map(mtc:daemonPort, system:daemonPort); |
| |
| f_Connect_to_IPDD(); |
| |
| f_Init_IP_Server(tsp_serverInterface, tsp_serverPort, sctp); |
| f_Init_IP_Client(tsp_serverInterface, tsp_serverPort, sctp); |
| f_CheckClientConnection_Gets(SCTP_COMM_UP); |
| |
| f_StopServer(); |
| f_CheckClientConnection_Gets(SCTP_COMM_LOST); |
| |
| f_Init_IP_Server(tsp_serverInterface, tsp_serverPort, sctp); |
| f_CheckClientConnection_Gets(SCTP_COMM_UP); |
| |
| f_StopClient(); |
| f_StopServer(); |
| |
| unmap(mtc:daemonPort, system:daemonPort); |
| } |
| |
| testcase tc_Init_TCP_CLientServer_SendDataFromClient_CheckDataReceiveOnServer() runs on MAIN_CT { |
| map(mtc:daemonPort, system:daemonPort); |
| |
| f_Connect_to_IPDD(); |
| |
| f_Init_IP_Server(tsp_serverInterface, tsp_serverPort, sctp); |
| f_Init_IP_Client(tsp_serverInterface, tsp_serverPort, sctp); |
| |
| f_sendDataFromClient('DB4720FFCA'O, sctp); |
| |
| f_CheckDataReceive(vc_connectedClientConnectionId, 'DB4720FFCA'O); |
| |
| f_StopClient(); |
| f_StopServer(); |
| |
| unmap(mtc:daemonPort, system:daemonPort); |
| } |
| |
| testcase tc_Init_SCTP_ClientServer_Disconnect_Connect_InitClientServer_SendDataFromClient_CheckDataReceiveOnServer() runs on MAIN_CT { |
| map(mtc:daemonPort, system:daemonPort); |
| |
| f_Connect_to_IPDD(); |
| |
| f_Init_IP_Server(tsp_serverInterface, tsp_serverPort, sctp); |
| f_Init_IP_Client(tsp_serverInterface, tsp_serverPort, sctp); |
| |
| // could be sending ASP_TCP_Close too |
| unmap(mtc:daemonPort, system:daemonPort); |
| |
| map(mtc:daemonPort, system:daemonPort); |
| |
| f_Connect_to_IPDD(); |
| |
| f_Init_IP_Server(tsp_serverInterface, tsp_serverPort, sctp); |
| f_Init_IP_Client(tsp_serverInterface, tsp_serverPort, sctp); |
| |
| f_sendDataFromClient('EEDDAADD'O, sctp); |
| |
| f_CheckDataReceive(vc_connectedClientConnectionId, 'EEDDAADD'O); |
| |
| f_StopServer(); |
| f_StopClient(); |
| |
| unmap(mtc:daemonPort, system:daemonPort); |
| } |
| |
| testcase tc_Init_TCP_ClientServer_Disconnect_Connect_InitClientServer_SendDataFromClient_CheckDataReceiveOnServer() runs on MAIN_CT { |
| map(mtc:daemonPort, system:daemonPort); |
| |
| f_Connect_to_IPDD(); |
| |
| f_Init_IP_Server(tsp_serverInterface, tsp_serverPort, tcp); |
| f_Init_IP_Client(tsp_serverInterface, tsp_serverPort, tcp); |
| |
| // could be sending ASP_TCP_Close too |
| unmap(mtc:daemonPort, system:daemonPort); |
| |
| map(mtc:daemonPort, system:daemonPort); |
| |
| f_Connect_to_IPDD(); |
| |
| f_Init_IP_Server(tsp_serverInterface, tsp_serverPort, tcp); |
| f_Init_IP_Client(tsp_serverInterface, tsp_serverPort, tcp); |
| |
| f_sendDataFromClient('DF07A9FB'O, tcp); |
| |
| f_CheckDataReceive(vc_connectedClientConnectionId, 'DF07A9FB'O); |
| |
| f_StopServer(); |
| f_StopClient(); |
| |
| unmap(mtc:daemonPort, system:daemonPort); |
| } |
| |
| testcase tc_3_SCTP_Servers_and_3_SCTP_Clients() runs on MAIN_CT { |
| map(mtc:daemonPort, system:daemonPort); |
| |
| f_Connect_to_IPDD(); |
| |
| vc_connectedClientConnectionId := -1; |
| f_Init_IP_Server(tsp_serverInterface, tsp_serverPort + 2, sctp); |
| f_Init_IP_Client(tsp_serverInterface, tsp_serverPort + 2, sctp); |
| f_sendDataFromClient('EEDDAADD00'O, sctp); |
| f_CheckDataReceive(vc_connectedClientConnectionId, 'EEDDAADD00'O); |
| |
| vc_connectedClientConnectionId := -1; |
| f_Init_IP_Server(tsp_serverInterface, tsp_serverPort + 1, sctp); |
| f_Init_IP_Client(tsp_serverInterface, tsp_serverPort + 1, sctp); |
| f_sendDataFromClient('EEDDAADD11'O, sctp); |
| f_CheckDataReceive(vc_connectedClientConnectionId, 'EEDDAADD11'O); |
| |
| vc_connectedClientConnectionId := -1; |
| f_Init_IP_Server(tsp_serverInterface, tsp_serverPort, sctp); |
| f_Init_IP_Client(tsp_serverInterface, tsp_serverPort, sctp); |
| f_sendDataFromClient('EEDDAADD22'O, sctp); |
| f_CheckDataReceive(vc_connectedClientConnectionId, 'EEDDAADD22'O); |
| |
| f_StopMyConnections(); |
| |
| unmap(mtc:daemonPort, system:daemonPort); |
| } |
| |
| testcase tc_2_TCP_Servers_and_2_TCP_Clients() runs on MAIN_CT { |
| map(mtc:daemonPort, system:daemonPort); |
| |
| f_Connect_to_IPDD(); |
| |
| vc_connectedClientConnectionId := -1; |
| f_Init_IP_Server(tsp_serverInterface, tsp_serverPort + 1, tcp); |
| f_Init_IP_Client(tsp_serverInterface, tsp_serverPort + 1, tcp); |
| f_sendDataFromClient('BC579C4D00'O, tcp); |
| f_CheckDataReceive(vc_connectedClientConnectionId, 'BC579C4D00'O); |
| |
| vc_connectedClientConnectionId := -1; |
| f_Init_IP_Server(tsp_serverInterface, tsp_serverPort, tcp); |
| f_Init_IP_Client(tsp_serverInterface, tsp_serverPort, tcp); |
| f_sendDataFromClient('BC579C4D11'O, tcp); |
| f_CheckDataReceive(vc_connectedClientConnectionId, 'BC579C4D11'O); |
| |
| f_StopMyConnections(); |
| |
| unmap(mtc:daemonPort, system:daemonPort); |
| } |
| |
| testcase tc_SCTP_AutoReplyDeviceWatchdog() runs on MAIN_CT { |
| map(mtc:daemonPort, system:daemonPort); |
| |
| f_Connect_to_IPDD(); |
| |
| f_Init_IP_Server(tsp_serverInterface, tsp_serverPort, sctp); |
| f_Init_IP_Client(tsp_serverInterface, tsp_serverPort, sctp); |
| |
| // 4th byte/bit1: request == 0 |
| // 5-7th byte: 280 == hex 118 |
| f_sendDataFromClient('00112200000118778899AABBCCDDEEFF'O, sctp); |
| |
| // 4th byte/bit1: reply == 1 |
| f_CheckDataReceive(vc_clientConnectionId, '00112280000118778899AABBCCDDEEFF'O); |
| |
| f_StopServer(); |
| f_StopClient(); |
| |
| unmap(mtc:daemonPort, system:daemonPort); |
| } |
| |
| testcase tc_TCP_AutoReplyDeviceWatchdog() runs on MAIN_CT { |
| map(mtc:daemonPort, system:daemonPort); |
| |
| f_Connect_to_IPDD(); |
| |
| f_Init_IP_Server(tsp_serverInterface, tsp_serverPort, tcp); |
| f_Init_IP_Client(tsp_serverInterface, tsp_serverPort, tcp); |
| |
| // 4th byte/bit1: request == 0 |
| // 5-7th byte: 280 == hex 118 |
| f_sendDataFromClient('EE81F300000118C98B6FF4'O, tcp); |
| |
| // 4th byte/bit1: reply == 1 |
| f_CheckDataReceive(vc_clientConnectionId, 'EE81F380000118C98B6FF4'O); |
| |
| f_StopServer(); |
| f_StopClient(); |
| |
| unmap(mtc:daemonPort, system:daemonPort); |
| } |
| |
| testcase tc_UDP_CheckStartupCallback() runs on MAIN_CT { |
| map(mtc:daemonPort, system:daemonPort); |
| |
| f_Connect_to_IPDD(); |
| |
| f_Init_IP_Client_with_localInterface(tsp_serverInterface, tsp_serverPort, tsp_serverInterface, tsp_serverPort + 1, udp); |
| var integer vl_firstConnectionId := vc_clientConnectionId; |
| f_Init_IP_Client_with_localInterface(tsp_serverInterface, tsp_serverPort + 1, tsp_serverInterface, tsp_serverPort, udp); |
| f_CheckDataReceive(vl_firstConnectionId, 'BBCCDDEE'O); |
| |
| f_StopClient(); |
| |
| unmap(mtc:daemonPort, system:daemonPort); |
| } |
| |
| //========================================================================= |
| // Control |
| //========================================================================= |
| |
| control { |
| //execute(tc_InitClientServer_StopServer_CheckClientConnChange()); |
| //execute(tc_InitClientServer_StopServer_StartServer_CheckClientConnChange()); |
| //execute(tc_InitClientServer_Disconnect_Connect_InitClientServer_SendDataFromClient_CheckDataReceiveOnServer()); |
| //execute(tc_AutoReplyDeviceWatchdog()); |
| } |
| |
| } // end of module |