diff --git a/IFW_CoAP_Peer_Definitions.ttcn b/IFW_CoAP_Peer_Definitions.ttcn index e043b506a7be1785ccf78199bbe31c9b675f469f..d8b6db398c0dbe3b5fb36e79576b3995e0ead53c 100644 --- a/IFW_CoAP_Peer_Definitions.ttcn +++ b/IFW_CoAP_Peer_Definitions.ttcn @@ -17,6 +17,7 @@ module IFW_CoAP_Peer_Definitions { import from CoAP_Types all; + import from IPL4asp_Types all; import from IPL4asp_PortType all; import from IFW_Common all; @@ -26,6 +27,8 @@ module IFW_CoAP_Peer_Definitions var CoAP_ReqResp msgToSend := c_CoAP_ReqResp_empty; var CoAP_ReqResp lastReceived := c_CoAP_ReqResp_empty; + + var ASP_SendTo_List buffer := {}; port IPL4asp_PT IPL4_PCO; } @@ -33,28 +36,46 @@ module IFW_CoAP_Peer_Definitions type record CoapContext { integer connId, + boolean temporarilyUnavailable, integer connId_listen, charstring remoteHost, integer remotePort, + ProtoTuple connectProtocol, + OptionList connectOptions, charstring localHost, integer localPort, + ProtoTuple listeningProtocol, + OptionList listeningOptions, boolean cherryPickOptionsCheck, Charstring_List locationPath - } + } with { extension "done" } + + type record CoapPSKParameters + { + charstring identity, + charstring key + } const CoapContext CoapContext_empty := { connId := -1, + temporarilyUnavailable := false, connId_listen := -1, remoteHost := "", remotePort := -1, + connectProtocol := { udp := {} }, + connectOptions := {{reuseAddress := {enable := true}}}, localHost := "", localPort := -1, + listeningProtocol := { udp := {} }, + listeningOptions := {{reuseAddress := {enable := true}}}, cherryPickOptionsCheck := false, locationPath := {} } + type record of ASP_SendTo ASP_SendTo_List; + const CoAP_ReqResp c_CoAP_ReqResp_empty := { header := diff --git a/IFW_CoAP_Peer_Functions.ttcn b/IFW_CoAP_Peer_Functions.ttcn index 1c1d7076278ce958c417c8ad15692e6dac934949..a23e9af18a4fd0e3a818a4b98177bbf217e50be5 100644 --- a/IFW_CoAP_Peer_Functions.ttcn +++ b/IFW_CoAP_Peer_Functions.ttcn @@ -35,17 +35,30 @@ module IFW_CoAP_Peer_Functions log("Mapping started"); map(self:IPL4_PCO,system:IPL4_PCO); - var f_IPL4_getMsgLen vl_f := refers(f_COAP_getMsgLength); - f_IPL4_setGetMsgLen(IPL4_PCO, -1, vl_f, {}); - log("Setting up the listening socket"); - vl_result := f_IPL4_listen(IPL4_PCO, ctx.localHost, ctx.localPort, {udp := {}}, {{reuseAddress := {enable := true}}}); - f_checkResult(vl_result); - ctx.connId_listen := vl_result.connId; - + if (ctx.localHost != "" and ctx.localPort != -1) + { + log("Setting up the listening socket"); + vl_result := f_IPL4_listen( + IPL4_PCO, + ctx.localHost, ctx.localPort, ctx.listeningProtocol, ctx.listeningOptions + ); + f_checkResult(vl_result); + + var f_IPL4_getMsgLen vl_f := refers(f_COAP_getMsgLength); + f_IPL4_setGetMsgLen(IPL4_PCO, vl_result.connId, vl_f, {}); + + ctx.connId_listen := vl_result.connId; + } + /* log("Connecting the socket to the remote"); - vl_result := f_IPL4_connect(IPL4_PCO, ctx.remoteHost, ctx.remotePort, ctx.localHost, ctx.localPort, -1,{udp := {}}, {{reuseAddress := {enable := true}}}); + + vl_result := f_IPL4_connect( + IPL4_PCO, + ctx.remoteHost, ctx.remotePort, ctx.localHost, ctx.localPort, -1, ctx.connectProtocol, ctx.connectOptions + ); f_checkResult(vl_result); + */ ctx.connId := vl_result.connId; ctx.cherryPickOptionsCheck := tsp_cherryPickOptionCheck; @@ -53,6 +66,44 @@ module IFW_CoAP_Peer_Functions log(%definitionId, " finished"); } + function f_CoAP_Peer_listen() runs on IFW_COAP_CT + { + log("Setting up the listening socket"); + var Result vl_result := f_IPL4_listen( + IPL4_PCO, + ctx.localHost, ctx.localPort, ctx.listeningProtocol, ctx.listeningOptions + ); + f_checkResult(vl_result); + + var f_IPL4_getMsgLen vl_f := refers(f_COAP_getMsgLength); + f_IPL4_setGetMsgLen(IPL4_PCO, vl_result.connId, vl_f, {}); + + ctx.connId_listen := vl_result.connId; + } + + function f_CoAP_Peer_connect() runs on IFW_COAP_CT + { + log("Connecting the socket to the remote"); + + var Result vl_result; + vl_result := f_IPL4_connect( + IPL4_PCO, + ctx.remoteHost, ctx.remotePort, ctx.localHost, ctx.localPort, -1, ctx.connectProtocol, ctx.connectOptions + ); + + f_checkResult(vl_result); + + if (ispresent(vl_result.errorCode) and vl_result.errorCode == ERROR_TEMPORARILY_UNAVAILABLE) + { + ctx.temporarilyUnavailable := true; + } + + var f_IPL4_getMsgLen vl_f := refers(f_COAP_getMsgLength); + f_IPL4_setGetMsgLen(IPL4_PCO, vl_result.connId, vl_f, {}); + + ctx.connId := vl_result.connId; + } + function f_CoAP_Peer_getContext() runs on IFW_COAP_CT return CoapContext { @@ -100,12 +151,20 @@ module IFW_CoAP_Peer_Functions vl_send.connId := ctx.connId; vl_send.remName := ctx.remoteHost; vl_send.remPort := ctx.remotePort; - vl_send.proto := {udp := {}} + vl_send.proto := ctx.connectProtocol vl_send.msg := v_encoded; - - log("COAP PDU: ", msgToSend); - IPL4_PCO.send(vl_send); + + if (not ctx.temporarilyUnavailable) + { + action("Sending: COAP PDU: ", msgToSend); + IPL4_PCO.send(vl_send); + } + else + { + action("Buffering: COAP PDU: ", msgToSend); + buffer[sizeof(buffer)] := vl_send; + } } function f_CoAP_Peer_receive() runs on IFW_COAP_CT @@ -130,12 +189,34 @@ module IFW_CoAP_Peer_Functions if (ischosen(v_coapMsg.msg)) { lastReceived := v_coapMsg.msg; - log("COAP PDU: ", lastReceived); + action("Received: COAP PDU: ", lastReceived); } } [] IPL4_PCO.receive(ASP_Event:?) -> value v_ipl4Event { log("Received: ", v_ipl4Event); + if (ischosen(v_ipl4Event.result)) + { + if (ctx.temporarilyUnavailable and + ispresent(v_ipl4Event.result.errorCode) and + v_ipl4Event.result.errorCode == ERROR_AVAILABLE + ) + { + if (sizeof(buffer)>0) + { + for (var integer i:=0; i<sizeof(buffer); i:=i+1) + { + action("Sending from buffer: ", buffer[i]); + IPL4_PCO.send(buffer[i]); + } + } + ctx.temporarilyUnavailable := false; + } + } + else if (ischosen(v_ipl4Event.connClosed)) + { + action("Remote closed the connection"); + } repeat; } [] t_Timeout.timeout diff --git a/IFW_CoAP_Peer_TestSteps.ttcn b/IFW_CoAP_Peer_TestSteps.ttcn index fac94765d081e58cf19e0a2627d05ba132eb99b9..45fbc684ae346995f0c1929fc02b849f800bd50f 100644 --- a/IFW_CoAP_Peer_TestSteps.ttcn +++ b/IFW_CoAP_Peer_TestSteps.ttcn @@ -35,6 +35,32 @@ module IFW_CoAP_Peer_TestSteps return true; } + + function f_IFW_CoapPeer_listen(in integer p_peerIdx) runs on IFW_MAIN_CT + return boolean + { + var IFW_COAP_CT v_peer := coapPeers[p_peerIdx]; + if (v_peer == null) { log("CFW: No coap peer found"); return false; } + f_isRunningGuard(v_peer); + + v_peer.start(f_CoAP_Peer_listen()); + v_peer.done; + + return true; + } + + function f_IFW_CoapPeer_connect(in integer p_peerIdx) runs on IFW_MAIN_CT + return boolean + { + var IFW_COAP_CT v_peer := coapPeers[p_peerIdx]; + if (v_peer == null) { log("CFW: No coap peer found"); return false; } + f_isRunningGuard(v_peer); + + v_peer.start(f_CoAP_Peer_connect()); + v_peer.done; + + return true; + } function f_IFW_CoapPeer_setRemote(in integer p_peerIdx, in charstring p_remoteAddrId) runs on IFW_MAIN_CT return boolean diff --git a/IFW_Common.ttcn b/IFW_Common.ttcn index e7c0704cfbdb02263323d279d421effd709479e0..73011065687466d85f787b4b814b2419c79ec9a7 100644 --- a/IFW_Common.ttcn +++ b/IFW_Common.ttcn @@ -114,9 +114,12 @@ module IFW_Common { { if (ispresent(pl_result.errorCode)) { + if (pl_result.errorCode != IPL4_ERROR_TEMPORARILY_UNAVAILABLE) + { log("Error: ", pl_result.errorCode, pl_result.os_error_text); setverdict(fail); stop; + } } } diff --git a/tests/Lwm2mTestSuite.ttcn b/tests/Lwm2mTestSuite.ttcn index 97ab0c50170b9ea2c2594b4529e2617857200262..ca7657e81d4ed9becd1d903442e423f3f67a0a10 100644 --- a/tests/Lwm2mTestSuite.ttcn +++ b/tests/Lwm2mTestSuite.ttcn @@ -286,6 +286,6 @@ module Lwm2mTestSuite { execute(tc_client_LightweightM2M_10_int_101_102_103_regdereg()); execute(tc_client_LightweightM2M_10_int_101_102_103_regdereg_lwm2mPDU()); - execute(tc_json_encdec()); + //execute(tc_json_encdec()); } }