Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Titan » Simple test case with CoAP
Simple test case with CoAP [message #1737323] Thu, 07 July 2016 10:05 Go to next message
Naum Spaseski is currently offline Naum SpaseskiFriend
Messages: 81
Registered: February 2016
Location: Sophia Antipolis
Member

Hello everyone,

I am trying to test a CoAP server (send/receive requests) but I have some problems with TITAN. I use the ProtocolModule CoAP and UDP TestPort provided by Ericsson.

So, I wrote a simple test (it's the hello world from TITAN adapted to CoAP):
module MyExample
{

import from UDPasp_PortType all;
import from UDPasp_Types all;
import from CoAP_Types all;

type component MTCType
{
  port UDPasp_PT MyPCO_PT;
}

template ASP_UDP_message testMessage (in octetstring inputMessage)  :={
  data := inputMessage,
  remote_addr := "localhost",
  remote_port := 5683
}

testcase tc_HelloW() runs on MTCType system MTCType
{
  map(mtc:MyPCO_PT, system:MyPCO_PT);
  var CoAP_Message msg1;
  var octetstring sendMessage;
  var integer test;
  
  msg1.msg.header.version := 0;
  msg1.msg.header.msg_type := CONFIRMABLE;
  msg1.msg.header.code.class := 0;
  msg1.msg.header.code.detail := 0;
  msg1.msg.header.message_id := 0;
  
  msg1.msg.token := ''O;
  msg1.msg.payload := '123456'O;
  
  test := f_CoAP_enc(msg1,sendMessage);
  
  MyPCO_PT.send(testMessage(sendMessage));
  setverdict(pass);
}


The problem is because I haven't specified any CoAP_message options for the request, and the error that I get is: "Dynamic test case error: Using an unbound optional field. (No such file or directory)"

Is there a way to resolve this error without specifying the option?

Thanks in advance,
Naum
Re: Simple test case with CoAP [message #1737336 is a reply to message #1737323] Thu, 07 July 2016 11:25 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 1120
Registered: January 2015
Senior Member
Hi Naum,


two problems:

1) you did not specify the optional "options" field ; there are two legal ways of doing this:

-either using explicit omit , which means that you have to state that you want to omit the field in question
msg1.msg.options := omit;


-or using implicit omit on the module, stating that "any field I did not specify should be considered as omitted"
this could lead to confusions, so I'd recommend explicit omit, it's clearer for the user


2) usage of the UDP port

this can be done in two modes, basic and advanced

-in basic mode, which can handle only one UDP socket , one can use ASP_UDP only

-in advanced mode , which can handle multiple sockets, on has to use:

ASP_UDP_message send and receive data
ASP_UDP_open request a new socket
ASP_UDP_open_result the result of the open request
ASP_UDP_close close the socket


One has to open a socket first with ASP_UDP_open; the received ASP_UDP_open_result will contain an id that can be used as reference;

messages can be sent with ASP_UDP_message containing the message and the reference id

the socket can be closed with ASP_UDP_close


In your case both modes could be used but I have attached an example of advanced usage; the config file should contain the appropriate test port parameters; the socket parameters can be controlled through tsp_connectionParams


Here's MyExample.ttcn:
module MyExample
{

import from UDPasp_PortType all;
import from UDPasp_Types all;
import from CoAP_Types all;


  modulepar {    
    ConnectionParams tsp_connectionParams := {"127.0.0.1", 35000, "127.0.0.1", 0};   
  }


type record ConnectionParams 
{ 
  charstring  remHost,
  integer     remPort,
  charstring  locHost,
  integer     locPort 
}



type component MTCType
{
  port UDPasp_PT MyPCO_PT;
}

template ASP_UDP_message testMessage (in octetstring inputMessage, in integer p_id)  :={
  data := inputMessage,
  remote_addr := tsp_connectionParams.remHost,//"localhost",
  remote_port := tsp_connectionParams.remPort,//5683
  id:=p_id
}

template    ASP_UDP_close t_close (in integer p_id)  :={
	  id:=p_id
  }

function f_openConnection(in ConnectionParams pl_connectionParams, integer pl_connId)
runs on MTCType return integer
{

var  ASP_UDP_open  v_ASP_UDP_open := {
	  remote_addr := pl_connectionParams.remHost,
	  remote_port := pl_connectionParams.remPort,
	  local_addr := pl_connectionParams.locHost,
	  local_port := pl_connectionParams.locPort
  }

var ASP_UDP_open_result v_ASP_UDP_open_result
 
 MyPCO_PT.send(v_ASP_UDP_open);

   alt 
   {
    [] MyPCO_PT.receive(ASP_UDP_open_result  : ?) -> value v_ASP_UDP_open_result
       {

       }
    [] MyPCO_PT.receive 
       {log("Unexpected Msg received on UDP_PCO")}                
   } 
  


  log(v_ASP_UDP_open_result)
  return(v_ASP_UDP_open_result.id)
}





testcase tc_HelloW() runs on MTCType system MTCType
{
  map(mtc:MyPCO_PT, system:MyPCO_PT);
  var CoAP_Message msg1;
  var octetstring sendMessage;
  var integer test, v_id;
  
  msg1.msg.header.version := 0;
  msg1.msg.header.msg_type := CONFIRMABLE;
  msg1.msg.header.code.class := 0;
  msg1.msg.header.code.detail := 0;
  msg1.msg.header.message_id := 0;
  
  msg1.msg.token := ''O;
  msg1.msg.options := omit;
  msg1.msg.payload := '123456'O;


log("------------->",msg1)
  
  test := f_CoAP_enc(msg1,sendMessage);





v_id:=f_openConnection( tsp_connectionParams, -1) //Opens channel


  
  MyPCO_PT.send(testMessage(sendMessage,v_id));
  setverdict(pass);


  MyPCO_PT.send(t_close(v_id));  //closes channel




}

}



and CoAP.cfg :
[LOGGING]
#LogFile := "logs/%l/%e.%h-%t%r.%s"
FileMask := LOG_ALL | TTCN_ERROR | TTCN_USER
#|TTCN_DEBUG |LOG_ALL | TTCN_WARNING | TTCN_TESTCASE | TTCN_STATISTICS | TTCN_PORTEVENT
ConsoleMask := TTCN_ERROR | TTCN_USER
LogSourceInfo := Yes

[MODULE_PARAMETERS]


MyExample.tsp_connectionParams := {"127.0.0.1", 35000, "127.0.0.1", 0}

[TESTPORT_PARAMETERS]


*.MyPCO_PT.debugging := "yes"
*.MyPCO_PT.mode := "advanced"


[MAIN_CONTROLLER]
TCPPort := 9034


[EXECUTE]
MyExample.tc_HelloW



and here's the execution log:

13:06:13.375852 - TTCN-3 Main Test Component started on esekilxxen1845. Version: CRL 113 200/5 R5A.
13:06:13.376033 - TTCN Logger v2.2 options: TimeStampFormat:=Time; LogEntityName:=No; LogEventTypes:=No; SourceInfoFormat:=Single; *.FileMask:=LOG_ALL; *.ConsoleMask:=ERROR | USER; LogFileSize:=0; LogFileNumber:=1; DiskFullAction:=Error
13:06:13.376210 - Connected to MC.
13:06:13.384911 - Executing test case tc_HelloW in module MyExample.
13:06:13.384979 MyExample.ttcn:75 Test case tc_HelloW started.
13:06:13.385018 MyExample.ttcn:75 Initializing variables, timers and ports of component type MyExample.MTCType inside testcase tc_HelloW.
13:06:13.385145 MyExample.ttcn:75 Port MyPCO_PT was started.
13:06:13.385196 MyExample.ttcn:75 Component type MyExample.MTCType was initialized.
13:06:13.385234 MyExample.ttcn:77 Mapping port mtc:MyPCO_PT to system:MyPCO_PT.
13:06:13.385328 MyExample.ttcn:77 Port MyPCO_PT was mapped to system:MyPCO_PT.
13:06:13.385401 MyExample.ttcn:77 Map operation of mtc:MyPCO_PT to system:MyPCO_PT finished.
13:06:13.385457 MyExample.ttcn:93 ------------->{ msg := { header := { version := 0, msg_type := CONFIRMABLE (0), code := { class := 0, detail := 0 }, message_id := 0 }, token := ''O, options := omit, payload := '123456'O } }
13:06:13.385658 MyExample.ttcn:53 Sent on MyPCO_PT to system @UDPasp_Types.ASP_UDP_open : { remote_addr := "127.0.0.1", remote_port := 35000, local_addr := "127.0.0.1", local_port := 0 }
13:06:13.385734 MyExample.ttcn:53 Warning: The maximum number of open file descriptors (8193) is greater than FD_SETSIZE (1024). Ensure that Test Ports using Install_Handler do not try to wait for events of file descriptors with values greater than FD_SETSIZE (1024). (Current caller of Install_Handler is "MyPCO_PT")
13:06:13.385781 MyExample.ttcn:53 Message enqueued on MyPCO_PT from system @UDPasp_Types.ASP_UDP_open_result : { local_addr := "127.0.0.1", local_port := 59364, id := 0 } id 1
13:06:13.385824 MyExample.ttcn:57 Receive operation on port MyPCO_PT succeeded, message from system(): @UDPasp_Types.ASP_UDP_open_result : { local_addr := "127.0.0.1", local_port := 59364, id := 0 } id 1
13:06:13.385847 MyExample.ttcn:57 Message with id 1 was extracted from the queue of MyPCO_PT.
13:06:13.385866 MyExample.ttcn:67 { local_addr := "127.0.0.1", local_port := 59364, id := 0 }
13:06:13.385951 MyExample.ttcn:108 Sent on MyPCO_PT to system @UDPasp_Types.ASP_UDP_message : { data := '00000000FF123456'O, remote_addr := "127.0.0.1", remote_port := 35000, id := 0 }
13:06:13.386025 MyExample.ttcn:109 setverdict(pass): none -> pass
13:06:13.386068 MyExample.ttcn:112 Sent on MyPCO_PT to system @UDPasp_Types.ASP_UDP_close : { id := 0 }
13:06:13.386099 MyExample.ttcn:112 Terminating component type MyExample.MTCType.
13:06:13.386117 MyExample.ttcn:112 Removing unterminated mapping between port MyPCO_PT and system:MyPCO_PT.
13:06:13.386136 MyExample.ttcn:112 Port MyPCO_PT was unmapped from system:MyPCO_PT.
13:06:13.386173 MyExample.ttcn:112 Port MyPCO_PT was stopped.
13:06:13.386194 MyExample.ttcn:112 Component type MyExample.MTCType was shut down inside testcase tc_HelloW.
13:06:13.386211 MyExample.ttcn:112 Waiting for PTCs to finish.
13:06:13.386262 MyExample.ttcn:112 Setting final verdict of the test case.
13:06:13.386287 MyExample.ttcn:112 Local verdict of MTC: pass
13:06:13.386316 MyExample.ttcn:112 No PTCs were created.
13:06:13.386333 MyExample.ttcn:112 Test case tc_HelloW finished. Verdict: pass
13:06:13.393005 - Verdict statistics: 0 none (0.00 %), 1 pass (100.00 %), 0 inconc (0.00 %), 0 fail (0.00 %), 0 error (0.00 %).
13:06:13.393127 - Test execution summary: 1 test case was executed. Overall verdict: pass
13:06:13.393146 - Exit was requested from MC. Terminating MTC.



I have also attached the archive.


Best regards
Elemer

Re: Simple test case with CoAP [message #1737716 is a reply to message #1737336] Tue, 12 July 2016 08:30 Go to previous messageGo to next message
Naum Spaseski is currently offline Naum SpaseskiFriend
Messages: 81
Registered: February 2016
Location: Sophia Antipolis
Member

Hello Elemer,

Thanks for the help, I managed to send and receive CoAP data with success. I have another question regarding the UDP test port: How can I adapt it to use IPv6? As far as I know, the HTTP port supports IPv6.

Best regards,
Naum.

[Updated on: Tue, 12 July 2016 08:34]

Report message to a moderator

Re: Simple test case with CoAP [message #1737725 is a reply to message #1737716] Tue, 12 July 2016 09:12 Go to previous message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 1120
Registered: January 2015
Senior Member
Hi Naum,

I'm afraid the legacy UDP port does not support IPv6; we have a more modern test port called IPL4 that can be used as UDP , TCP or SCT port and that one does .

Please look into the IPL4 documentation the port is available here:

https://github.com/eclipse/titan.TestPorts.IPL4asp

It's slightly more complicated to use but a lot more flexible.

There's an SNMP/UDP example based on the IPL4 port described in

https://www.eclipse.org/forums/index.php/t/1072614/

that can be used as a starting point.


Best regards
Elemer


Previous Topic:Advanced TTCN-3 usage: The secret life of shorthand notations
Next Topic:Advanced TTCN-3 usage
Goto Forum:
  


Current Time: Wed Apr 24 22:56:04 GMT 2024

Powered by FUDForum. Page generated in 0.03241 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top