OpenTTCN/Training/TTCN-3 Basics/Exercises/2.3

From OpenTTCN

Jump to: navigation, search

Exercise 2.3: Defining TTCN-3 templates for message-based communication

Goal: In this exercise we are learning how to define templates to be used for message-based based communication.

Step 1: Defining templates used for message-based communication

Message-based communication of TTCN-3 uses so called templates when defining values of messages to be sent or values of messages to be expected to be received. In TTCN-2 a term "constraint" was used what is now called "template" in TTCN-3. Each template is defined for a specific message i.e. for a specific TTCN-3 type used as a message for message-based communication. Each template follows the same structure as the corresponding TTCN-3 type this template is defined for. Each template can be stand-alone, it can be paramterized (having a parameter list), or the template can be derived from a base template and only modified values can be specified.

Example of simple template definition for user-defined "TYPE_X_Message" type:

template TYPE_X_Message T_X_Message :=
   {
   typeCode := '00001010'B,
   data := '0F10000000000000000000000000C0FF'O
   }

The definition of "TYPE_X_Message" was:

type record TYPE_X_Message
   {
   bitstring  typeCode,
   octestring data
   }

Step 2: Current DNS message

If you have completed the previous exercises using instructions given, you shoudl have DNS messages defined as something like the following.

Instructions 1 of previous exercise: Modify the original "TYPE_DNS_Message" so that the DNS Header part is defined as a separate "record" type called "TYPE_DNS_Header". Use "header" as the name of the new field in the DNS message. This leads to a new type:

type record TYPE_DNS_Header
   {
   UInt16     id,
   Bit1       qr,
   Bit4       opcode,
   Bit1       aa,
   Bit1       tc,
   Bit1       rd,
   Bit1       ra,
   Bit3       z,
   Bit4       rcode,
   UInt16     qdcount,
   UInt16     ancount,
   UInt16     nscount,
   UInt16     arcount
   }

Instructions 2 of previous exercise: Modify the original "TYPE_DNS_Message" so that the DNS Question part is defined as a separate "record" type called "TYPE_DNS_Question". Use "question" as the name of the new field in the DNS message. This leads to a new type:

type record TYPE_DNS_Question

   {
   chartring  qname,
   UInt16     qtype,
   UInt16     qclass
   }

Finally, combining the use of new "TYPE_DNS_Header" and "TYPE_DNS_Question" types and after modifying the "TYPE_DNS_Message" we get a new "TYPE_DNS_Message" definition as follows:

type record TYPE_DNS_Message

   {
   TYPE_DNS_Header header,
   TYPE_DNS_Question question,
   chartring  answer optional
   // Even in this new message we have ignored the possibility of Authority and 
   // Additional sections of RFC 1035, we leave this for home work if you want
   // to add these sections as well.
   }

Step 3: Define templates for a DNS message

Instructions 1: Specify two simple templates for "TYPE_DNS_Header" type. One template called "T_DNS_Header_query" to be used in a DNS query and another template called "T_DNS_Header_answer" to be used in a DNS answer. Instructor will hand you information about the values to be used.

Instructions 2: Specify two simple templates for "TYPE_DNS_Question" type. One template called "T_DNS_Question_query" to be used in a DNS query and another template called "T_DNS_Question_answer" to be used in a DNS answer. Instructor will hand you information about the values to be used.

Instructions 3: Specify two simple templates for "TYPE_DNS_Message" type. One template called "T_DNS_query" to be used in a DNS query and another template called "T_DNS_answer" to be used in a DNS answer. Instructor will hand you information about the values to be used. Step 4: Try DNS send templates

Instructions 1: Create a test case "TC_header" that displays the values of "T_DNS_Header_query" template using a log statement.

Instructions 2: Create a test case "TC_question" that displays the values of "T_DNS_Question_query" template using a log statement.

Instructions 3: Create a test case "TC_query" that displays the values of "T_DNS_query" template using a log statement.

Summary

Good! You have just completed your third TTCN-3 exercise. During this exercise you learned how to define TTCN-3 templates to be used for message-based communication. You are now ready to proceed to the next exercise to learn how to specify main test component (MTC) and test system interface (TSI).

<< Previous   Next >>

Views
Personal tools