Skip to main content



      Home
Home » Eclipse Projects » Eclipse Titan » DNS Example from "Introduction to TTCN-3"
DNS Example from "Introduction to TTCN-3" [message #1713903] Sat, 07 November 2015 19:09 Go to next message
Eclipse UserFriend
Hi,
I am following the book "Intro to TTCN-3 2nd edition" to step in TTCN-3 Testing. I have developed a new project in Titan in accordance with the example from this book.The DNSTester.ttcn appears like it:
module DNSTester
{

type integer Identification (0..65535);
type enumerated MessageKind{e_Question,e_Answer};
type charstring Question;
type charstring Answer;

type record DNSMessage{			
    Identification 	identification,
  MessageKind 		messageKind,
  Question 			question,
  Answer	 		answer	optional
}

type port DNSPort message{
  inout DNSMessage	//DNSMessage is allowed to move in and out through this
}

type component DNSClient{
  port DNSPort serverPort	//component use only one port for in/out
}



template DNSMessage a_DNSQuestion(Identification p_id, Question p_question):={
  //template defines the exact message that will be communicated
  identification:=p_id,
  messageKind 	:=e_Question,
  question 		:=p_question,
  answer	 	:=omit		//since wuestion do not contain answer part so omit it
    
}


template DNSMessage a_DNSAnswer(Identification p_id, Answer p_Answer):={
  //template defines the exact message that will be communicated
  identification:=p_id,
  messageKind 	:=e_Answer,
  question 		:=?,
  answer	 	:=omit		//since wuestion do not contain answer part so omit it
    
}




testcase tc_ExampleTestResolveNokia1() runs on DNSClient{
  timer replyTimer;
  //send question on serverPort
  serverPort.send(a_DNSQuestion(12345,"www.nokia.com"));
  replyTimer.start(20.0);
  alt{
	
      //receive answer from DNS
    []  serverPort.receive(a_DNSAnswer(12345,"172.21.56.98")){
      		setverdict(pass);
      		replyTimer.stop;
    }
    []	serverPort.receive{
      		setverdict(fail,"Unexpected Response");
      		replyTimer.stop;
    } 	 
    []	replyTimer.timeout{
      		setverdict(fail,"No respons since 20 sec from SUT");	
    }
  }
  stop;
  
}

control{
	execute(tc_ExampleTestResolveNokia1());  
}

}  // end of module




The Problem is when i RunAs>>RunConfigurations>>Test Sets i cannot see the test case to be included in test set for execution, although i have executed it in control part.

It will be very helpful,if someone correct me, where i am going wrong.

Regards,
Burhan

[Updated on: Sat, 07 November 2015 19:23] by Moderator

Re: DNS Example from "Introduction to TTCN-3" [message #1713908 is a reply to message #1713903] Sun, 08 November 2015 02:47 Go to previous messageGo to next message
Eclipse UserFriend
Hi Muhammad,

as a first step, please confirm that your Titan installation is in place, that is , you can build and execute your code from the command line.

Best regards

Elemer
Re: DNS Example from "Introduction to TTCN-3" [message #1714076 is a reply to message #1713908] Mon, 09 November 2015 12:50 Go to previous messageGo to next message
Eclipse UserFriend
Hi Elemer,

I started with command line with a example of HelloWorld. And i can execute it from cli.

The only problem i think is, i did not include Test Ports with make command in this DNS Example, because when i try to make it(without Test Ports, due to lack of knowledge Smile ), it said "could not find DNSPort.hh and .cc" files. Am i right?

I want to give try to use TCP Test Ports and will create a sample example for it.
Can you tell if in the above mentioned paragraph, i am correct or not..

Regards,
Burhan



Re: DNS Example from "Introduction to TTCN-3" [message #1714144 is a reply to message #1714076] Tue, 10 November 2015 03:59 Go to previous messageGo to next message
Eclipse UserFriend
Hi Muhammad,

yes, you are right , one of the problems is that a real , physical test port is not included.
Besides that , there are other problems with example. Let's go through them:

I. The first problem is that DNS messages are more complex than suggested:

type record DNSMessage{			
  Identification 	identification,
  MessageKind 		messageKind,
  Question 			question,
  Answer	 		answer	optional
}


For a full implementation, please see https://github.com/eclipse/titan.ProtocolModules.DNS.

Due to this, we cannot send valid messages, and if the DNS server responds at all, the response will probably be some form of error message,
which we cannot decode correctly as the message format differs.

II. We need to add encoding so we can express DNS message structures in a binary form.
(This can be done in the test port, but that would affect the portability of the test port: if we take a UDP test port and add a DNS codec than that test port will become a DNS test port , and will will not be usabel for anything else, so we prefer to do encoding in the layer above the test port, as seen in the next section)

We can use the RAW encoder for that;
for this wee need (see previous forum posts about the RAW encoder) :
1. to add encoding instructions:


type integer Identification (0..65535) with{ variant "FIELDLENGTH(16)"} ;
type enumerated MessageKind{e_Question,e_Answer} with{ variant "FIELDLENGTH(16)"} ; 
type charstring Question with{ variant ""}; 
type charstring Answer with{ variant ""};

type record DNSMessage{			
  Identification 	identification,
  MessageKind 		messageKind,
  Question 			question,
  Answer	 		answer	optional
}with{ variant ""};


MessageKind is an enumerated value that can be encoded on one bit; I have encoded it on 16 bits to try to align with a real DNS message.

2. a final "encode "RAW" :


}  // end of module
with {encode "RAW" }



3. declare codec external functions

external function enc_DNSMessage(in DNSMessage pdu) return octetstring
 with { extension "prototype(convert) encode(RAW)" };
external function dec_DNSMessage(in octetstring stream) return DNSMessage
 with { extension "prototype(convert) decode(RAW)" };


III. as you noticed , a real test port should be added so we can send DNS messages to the external world

for this , we can use the UDP test port https://github.com/eclipse/titan.TestPorts.UDPasp;
most DNS transactions are over UDP; TCP is used for long messages only.

To use the test port, copy all files in /src to the same directory where you have the DNSTester.ttcn and generate the Makefile:

 makefilegen -s *.ttcn *.cc *.hh
 

We also need to change the code:
1. first we need to import from the UDP port all necessarry info:

 import from UDPasp_Types all;
import from UDPasp_PortType all; 


2. we need to change the declaration of the test port so we use UDP port in dual faced mode (see previous posts in forum , for example the "SNMP over UDP" post)

/*
type port DNSPort message{
  inout DNSMessage	//DNSMessage is allowed to move in and out through this
}

*/


type port DNSPort message  //DualFace port
{
 out 
     DNSMessage    
 in      
     DNSMessage,
     ASP_UDP_open_result          
}with 
{ extension 
   "user UDPasp_PT
      out(
        DNSMessage -> ASP_UDP: function(f_enc_DNS)
    )    
      in(
        ASP_UDP ->   DNSMessage : function(f_dec_DNS);
        ASP_UDP_message    ->       -              : discard;           
        ASP_UDP_open_result -> - : discard
    )
   " 
   
}



3. we also need to declare the appropriate converion functions taht wil take a DNS Message and convert it to a UDP PDU, and vice-versa:



function f_enc_DNS
( in DNSMessage pl_in,
  out ASP_UDP pl_out) return integer
{
  pl_out.data := enc_DNSMessage(pl_in);         
  pl_out.addressf := tsp_remHost; 
  pl_out.portf := tsp_remPort;
    
  return 0;
}with {extension "prototype(backtrack)" }


function f_dec_DNS
 (in ASP_UDP pl_in, 
  out DNSMessage pl_out) return integer
{

  pl_out := dec_DNSMessage(pl_in.data);

  return 0;
} with {extension "prototype(backtrack)" }




as the first function refers to a remote host and port, I have added also two module parameters for that:

modulepar {

charstring tsp_remHost:="127.0.1.1"
integer    tsp_remPort:=53;

}




assumption here is that the DNS server is located at the adress 127.0.1.1 ; you need to replace this address with the real address of a DNS server.



And one final detail: the map operation for the test port is missing, so we need to add it:

testcase tc_ExampleTestResolveNokia1() runs on DNSClient{
  timer replyTimer;
  
   map(self:serverPort, system:serverPort);
:
:








All we need now is a config file DNS.cfg:

[LOGGING]

FileMask := LOG_ALL | TTCN_ERROR | TTCN_USER | MATCHING  | TTCN_DEBUG 
#|LOG_ALL | TTCN_WARNING | TTCN_TESTCASE | TTCN_STATISTICS | TTCN_PORTEVENT
ConsoleMask := TTCN_ERROR | TTCN_USER 
#| TTCN_PORTEVENT
LogSourceInfo := Yes
TimeStampFormat := DateTime
LogEventTypes := Yes
SourceInfoFormat := Single
LogSourceInfo := Yes


[MODULE_PARAMETERS]

tsp_remHost:="127.0.1.1"
tsp_remPort:=53;

[TESTPORT_PARAMETERS]


*.serverPort.debugging := "yes"
*.serverPort.mode := "basic"
*.serverPort.localIPAddr := "localhost"
*.serverPort.localPort := "35000"


[EXECUTE]
DNSTester.tc_ExampleTestResolveNokia1



If we compile and run:

make 
./DNSTester DNS.cfg




2015/Nov/09 20:55:25.684040 PARALLEL DNSTester.ttcn:117 Component type DNSTester.DNSClient was initialized.
2015/Nov/09 20:55:25.684090 PARALLEL DNSTester.ttcn:120 Mapping port mtc:serverPort to system:serverPort.
2015/Nov/09 20:55:25.684186 PORTEVENT DNSTester.ttcn:120 Port serverPort was mapped to system:serverPort.
2015/Nov/09 20:55:25.684248 PARALLEL DNSTester.ttcn:120 Map operation of mtc:serverPort to system:serverPort finished.
2015/Nov/09 20:55:25.684342 PORTEVENT DNSTester.ttcn:124 Sent on serverPort to system @DNSTester.DNSMessage : { identification := 12345, messageKind := e_Question (0), question := "www.nokia.com", answer := omit }
2015/Nov/09 20:55:25.684434 PORTEVENT DNSTester.ttcn:124 Outgoing message was mapped to @UDPasp_Types.ASP_UDP : { data := '393000007777772E6E6F6B69612E636F6D'O, addressf := "127.0.1.1", portf := 53 }
2015/Nov/09 20:55:25.684545 TIMEROP DNSTester.ttcn:125 Start timer replyTimer: 20 s
2015/Nov/09 20:55:25.723836 PORTEVENT DNSTester.ttcn:126 Message enqueued on serverPort from system @UDPasp_Types.ASP_UDP : { data := '393080817777772E6E6F6B69612E636F6D'O, addressf := "127.0.1.1", portf := 53 } id 1
2015/Nov/09 20:55:25.723984 WARNING DNSTester.ttcn:83 Warning: While RAW-decoding type '@DNSTester.DNSMessage': Invalid enum value '33152' for '@DNSTester.MessageKind': 
2015/Nov/09 20:55:25.724058 PORTEVENT DNSTester.ttcn:126 Incoming message was mapped to @DNSTester.DNSMessage : { identification := 12345, messageKind := <unknown> (2), question := "www.nokia.com", answer := omit } id 1
2015/Nov/09 20:55:25.724135 MATCHING DNSTester.ttcn:129 Matching on port serverPort <unknown> (2) with e_Answer (1) unmatched: First message in the queue does not match the template: 
2015/Nov/09 20:55:25.724210 MATCHING DNSTester.ttcn:133 Matching on port serverPort succeeded.
2015/Nov/09 20:55:25.724262 PORTEVENT DNSTester.ttcn:133 Receive operation on port serverPort succeeded, message from system(): @DNSTester.DNSMessage: { identification := 12345, messageKind := <unknown> (2), question := "www.nokia.com", answer := omit } id 1
2015/



we can see that we send some message , we receive some answer, so the codec, and port is working, but all is a jumble because the DNSMessage is not correct.

You can take it from here and refine the code if you wish so you get the expected result.
For a real DNS test code, see https://github.com/eclipse/titan.ProtocolModules.DNS
section /demo

Best regards

Elemer
Re: DNS Example from "Introduction to TTCN-3" [message #1714416 is a reply to message #1714144] Thu, 12 November 2015 09:04 Go to previous message
Eclipse UserFriend
Dear Elmer,

That was indeed an informative and helpful description. I will work on it and then will update you soon. But first i will give a try to create a small project to use UDP and then will move to DNS.
Thanks for your support.
Regards,
Burhan
Previous Topic:Very large size of generated C++ files
Next Topic:Eclipse Titan core and plug-ins source code updated in github to 5.4.0
Goto Forum:
  


Current Time: Wed Jul 16 18:20:42 EDT 2025

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

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

Back to the top