Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Titan » Help needed on Structure UDP Example
Help needed on Structure UDP Example [message #1772756] Thu, 14 September 2017 19:25 Go to next message
Philip Weber is currently offline Philip WeberFriend
Messages: 6
Registered: June 2017
Junior Member
Hey Guys,

I need to create some examples with TTCN3 and Titan. I already created some samples sending an integer or string to an udp server and receiving something again. Now I want to do the same with a structure but I encounter some problems.

In my udp server I have to "decode" the received message. So I included "StructUdpExample.hh" to use the decode and encode function but I can't even compile it. I get the following message: Titan/include/version.h:78:4 error: #error "No supported platform has been defined in the Makefile. The supported ones: SOLARIS, SOLARIS8, LINUX, WIN32"
I created an makefile and set the platform to Linux. What am I doing wrong?

And how exactly should I encode and decode the structure I want to send? Should I do this in the PCOType.cc file?

Thats what I already succesfully did. Just sending and receiving a string.

........... ---------------------String--------------------------->
TTCN3........................................................................UDP Server
............<--------------------String----------------------------

And thats what I want to do now. Sending and receiving a structure.

..................----------Struct(string, int, float)-------------->
TTCN3............................................................................UDP Server
..................<---------Struct(int, string)----------------------

Would be really great if someone could help me. I am very new to TTCN3 and Titan. I attached my project.

Best regards



Re: Help needed on Structure UDP Example [message #1772805 is a reply to message #1772756] Fri, 15 September 2017 13:39 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 807
Registered: January 2015
Senior Member
Hi Philip,

welcome to TTCN-3 and Titan.

A few generic observations:

-it's great you write your own test port, I don't want to discourage you , but please be aware that for UDP you can use the
legacy UDP test port :
https://github.com/eclipse/titan.TestPorts.UDPasp
or the IPL4 test port in UDP mode (this is maybe somewhat more complex, so maybe you should wait with this...):
https://github.com/eclipse/titan.TestPorts.IPL4asp

-I see that you use Titan 5 R5A which is probably OK for a this project, but 6 R2A is already available.

-in your Makefile you should specify your platform as below:

# Your platform: (SOLARIS, SOLARIS8, LINUX, FREEBSD or WIN32)
PLATFORM = LINUX


WIN32 is for Cygwin/MinGW; Linux is the recommended platform


-when one sends complex messages between systems then the rules converting these structures to a binary form (which will be sent on the "wire" ) have to be established; the other end will have to use the same rules to reassemble the sent structures.
for this you can use your proprietary encoding/decoding functions which will take abstract structures as input and result in a binary output in one direction, and take binary and result in structures in the other direction;
you can also use the RAW codec which is built into Titan; please search this forum for "RAW" ; i have published a few posts about it;

The use of RAW is convenient as one can control the encoding with instructions embedded in TTCN-3 code. Based on these instructions Titan will generate the appropriate codecs.

The typical flow is that the codec function is called for the structured variable/template ; the binary output is then fed to the test port as UDP payload.
For the opposite direction the UDP port delivers the payload which is the decode by the appropriate function.

You can call these codecs from the port directly as well, but that will transform the port from a UDP port to a message specific port.

I hope this will give you some pointers to start with


Best regards
Elemer




Re: Help needed on Structure UDP Example [message #1772808 is a reply to message #1772805] Fri, 15 September 2017 14:41 Go to previous messageGo to next message
Philip Weber is currently offline Philip WeberFriend
Messages: 6
Registered: June 2017
Junior Member
Hey Elemer,

First of all, thanks for your fast reply! This sample is for learning purposes at university. So it should be as simple and minimalistic as possible. So I guess I will stick to the self created test port because the students are already used to that. But I will definitely have a look in the legacy UDP test port for personal use, thanks!

I am trying to include the "StructUdpExample.hh" file to my server.c to get access to the encode and decode function but than I receive this Linux error. I already set the platform to Linux. Here is the makefile for my UDP port:

# Your platform: (SOLARIS, SOLARIS8, LINUX, FREEBSD or WIN32)
PLATFORM = LINUX

# Your C++ compiler:
# (if you change the platform, you may need to change the compiler)
CXX = g++

# Flags for the C++ preprocessor (and makedepend as well):
CPPFLAGS = -D$(PLATFORM) -I$(TTCN3_DIR)/include

# Flags for the C++ compiler:
CXXFLAGS = -Wall

ifeq ($(PLATFORM), WIN32)
# Silence linker warnings.
LDFLAGS += -Wl,--enable-auto-import,--enable-runtime-pseudo-reloc
endif

compile:
	g++ -o server server.c ../StructUdpExample.cc -I/home/philip/Titan/include
Re: Help needed on Structure UDP Example [message #1772812 is a reply to message #1772808] Fri, 15 September 2017 15:03 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 807
Registered: January 2015
Senior Member
Hi Philip,

I'm not sure you are using the Makefile as intended:

you can generate the Makefile with:
makefilegen  ...options ...list of TTCN files...list of  cc/hh files ...list of c/h files

e.g.
makefilegen   -s  file1.ttcn    file2cc file3.hh file4.c file5.h


(for options see makefilegen -h)

then the generated Makefile can be used with
make

which should build the executable


BTW I think something is missing in your post, I see no Linux error.


P.S, There's an older post that might be useful:
https://www.eclipse.org/forums/index.php/t/1068004/

BR

Elemer


Re: Help needed on Structure UDP Example [message #1772823 is a reply to message #1772812] Fri, 15 September 2017 18:26 Go to previous messageGo to next message
Philip Weber is currently offline Philip WeberFriend
Messages: 6
Registered: June 2017
Junior Member
Hey Elemer,

Okay I guess I have to explain more in detail what I want to do. My self created UDP "server" is in a different folder and should also start in a different console as the titan executable. So the "server.c" has its own makefile. I just want to start the server first and after that the titan executable, so I can see in both consoles how they are communicating.

I attached my working example with sending an integer. A integer value is send to the UDP "server". After that it is squared and send back.

Now I want to create the same example again, but with sending a structure instead of an integer. So I guess at some point I have to encode the struct (in the PCOType::outgoing_send method?). After that I have to decode it somehow in my "server.c" file (can't use the decode function because of this supported platform error) and send another encoded structure back.
Maybe I'm doing something wrong. I am very new to ttcn3 and titan.

[Updated on: Fri, 15 September 2017 18:27]

Report message to a moderator

Re: Help needed on Structure UDP Example [message #1772835 is a reply to message #1772823] Sat, 16 September 2017 06:34 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 807
Registered: January 2015
Senior Member
Hi Philip,

your test port , although uses UDP as transport , it's not a generic UDP port, but a port which accepts integers:
  type port PCOType message
    {
	inout integer;
    }


A generic UDP port should accept octetstring , which is a different name for binary.
This octetstring can hold any kind of information, even structures, but they have to go through encoding first.
The other end will receive the binary and using the same rules, can decode the contained info.
Pls take a look into the code of the UDP port I have indicated.


I have modified your code to include an example of RAW encoding/decoding:

module IntegerUdpExample
{
    type port PCOType message
    {
	inout integer;
    }

    type component MTCType
    {
	port PCOType MyPCO;
    }

external function f_encode_Structure(in Structure pdu) return octetstring 
with { extension "prototype(convert) encode(RAW)" }
external function f_decode_Structure(in octetstring data) return Structure
with { extension "prototype(convert) decode(RAW)" }


type integer  UInt16 (0 .. 65535) with { variant "FIELDLENGTH(16),BYTEORDER(last)" };
type charstring CSL6 with { variant "FIELDLENGTH(6)" };
type record Structure
{
CSL6        f1,
UInt16      f2,
float       f3
}
with {variant "" }
 


testcase TC_encdec()  runs on MTCType system MTCType
{

var Structure v_struct:={f1:="abcd",f2:=666, f3:=3.14}

log(f_encode_Structure(v_struct))

log(f_decode_Structure(f_encode_Structure(v_struct)))
}

    control
    {
	//execute(Square(2, 4));	
	
	execute(TC_encdec())
	
    }
}with { encode "RAW" }



Best regards
Elemer
Re: Help needed on Structure UDP Example [message #1772849 is a reply to message #1772835] Sun, 17 September 2017 14:19 Go to previous messageGo to next message
Philip Weber is currently offline Philip WeberFriend
Messages: 6
Registered: June 2017
Junior Member
Hey Elemer,

Thanks, this helped me a lot! I am using the legacy UDP test port now, too. Nevertheless I get some warnings and an error. I attached my code and here is my error message:
/home/philip/Titan/bin/compiler -L  \
StructUdpExample.ttcn UDPasp_PortType.ttcn UDPasp_Types.ttcn  - StructUdpExample.ttcn UDPasp_PortType.ttcn UDPasp_Types.ttcn
Notify: Parsing TTCN-3 module `StructUdpExample.ttcn'...
Notify: Parsing TTCN-3 module `UDPasp_PortType.ttcn'...
Notify: Parsing TTCN-3 module `UDPasp_Types.ttcn'...
Notify: Checking modules...
StructUdpExample.ttcn: In TTCN-3 module `StructUdpExample':
 StructUdpExample.ttcn:56.5-77: In external function definition `f_encode_Structure':
  StructUdpExample.ttcn:56.41-58: In formal parameter list:
   StructUdpExample.ttcn:56.42-57: In parameter `pdu':
    StructUdpExample.ttcn:64.5-69.5: In type definition `Structure':
     StructUdpExample.ttcn:70.11-20: warning: This variant does not belong to an encode
     StructUdpExample.ttcn:66.5-18: In record field `f1':
      StructUdpExample.ttcn:63.5-24: In type definition `CSL6':
       StructUdpExample.ttcn:63.33-56: warning: This variant does not belong to an encode
     StructUdpExample.ttcn:67.5-18: In record field `f2':
      StructUdpExample.ttcn:62.5-37: In type definition `UInt16':
       StructUdpExample.ttcn:62.46-86: warning: This variant does not belong to an encode
 StructUdpExample.ttcn:117.5-148.5: In function definition `f_server':
  StructUdpExample.ttcn:138.2-147.6: In while statement:
   StructUdpExample.ttcn:140.4-59: In receive statement:
    StructUdpExample.ttcn:140.15-31: error: '*' cannot be used as a matching template for a 'receive' operation
Notify: Error found in the input modules. Code will not be generated.
Makefile:152: die Regel für Ziel „compile" scheiterte
make: *** [compile] Fehler 1

Re: Help needed on Structure UDP Example [message #1772850 is a reply to message #1772849] Sun, 17 September 2017 15:14 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 807
Registered: January 2015
Senior Member
Hi Philip,

1)you need a final with {encode "RAW"} at the end of the module
2) pt.receive(ASP_UDP_message:*) -> value v_ASP_UDP_message

should be changed to

pt.receive(ASP_UDP_message:?) -> value v_ASP_UDP_message


and then it compiles (see attached)

BR

Elemer
Re: Help needed on Structure UDP Example [message #1772858 is a reply to message #1772850] Sun, 17 September 2017 19:16 Go to previous messageGo to next message
Philip Weber is currently offline Philip WeberFriend
Messages: 6
Registered: June 2017
Junior Member
Hey Elemer,

Great it's working, thanks! I modified the code so an other structure is send back as response, but when decoding this structure I get the following error. What am I doing wrong? Encoding and sending the second structure is not really different from the first one.

Client(4)@philip-VirtualBox: Dynamic test case error: While RAW-decoding type '@StructUdpExample.RequestStructure': There is not enough bits in the buffer to decode type REAL.
Re: Help needed on Structure UDP Example [message #1772864 is a reply to message #1772858] Mon, 18 September 2017 05:39 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 807
Registered: January 2015
Senior Member
Hi Philip,

from the error message it is apparent that the error occurs when a Request Structure is decoded ( not a Response Structure);

in lack of a log , I only suspect that teh problem is here:

alt {
	  // Handle the case when the expected answer comes in
	  [] pt.receive(ASP_UDP_message:?) -> value v_ASP_UDP_message {
	 	  log(f_decode_RequestStructure(v_ASP_UDP_message.data))
                  var ResponseStructure respStruct := f_decode_ResponseStructure(v_ASP_UDP_message.data)	  
	  	  setverdict(pass);
	  	  log("Expected message from server was received");
	  	  replyTimer.stop;
	  } 




log(f_decode_RequestStructure(v_ASP_UDP_message.data)) <----------------------
var ResponseStructure respStruct := f_decode_ResponseStructure(v_ASP_UDP_message.data)

On the client side you should encode Requests and decode Responses, never the opposite.

v_ASP_UDP_message.data contains a Response and you are trying to decode it as a Request.

BR

Elemer
Re: Help needed on Structure UDP Example [message #1772930 is a reply to message #1772864] Mon, 18 September 2017 20:31 Go to previous message
Philip Weber is currently offline Philip WeberFriend
Messages: 6
Registered: June 2017
Junior Member
Hey Elemer,

Of course you're right. I just forgot to delete this log line. Everything is working now! Thank you very much for your solid and fast help!
I modified the code so the client and server are checking the received structures now. I attached the project so it can help someone with similar problems in future!
Previous Topic:TEXT codec and unions
Next Topic:[Solved] Incorrect bit order Bitstring
Goto Forum:
  


Current Time: Sat Sep 22 11:42:38 GMT 2018

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

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

Back to the top