Skip to content
Snippets Groups Projects
Commit 5f8aea27 authored by Antal Wu-Hen-Chang's avatar Antal Wu-Hen-Chang
Browse files

Coap connection handling in CoapPeer updated to support testing over DTLS


Signed-off-by: default avatarAntal Wu-Hen-Chang <antal.wu-hen-chang@ericsson.com>
parent 4bb90518
No related branches found
No related tags found
No related merge requests found
......@@ -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 :=
......
......@@ -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
......
......@@ -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
......
......@@ -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;
}
}
}
......
......@@ -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());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment