OpenTTCN/Training/TTCN-3 Basics/Exercises/3.6
From OpenTTCN
Exercise 3.6: Specifying attributes to instruct coding and decoding
Goal: In this exercise we are learning how to specify attributes to instruct coding and decoding performed when sending and receiving messages.
Step 1: Specifying attributes to instruct coding and decoding
When a message is sent it is first encoded and then given to the SUT Adapter so that the adapter can send the message to the SUT. Before a message is processed using a receive statement it is first decoded.
The coding and decoding that performs both encoding (coding) and decoding gets information about types defined in the TTCN-3 modules to help during encoding and decoding. The coding and decoding (entity) is sometimes also called "codec".
Step 2: Information available for message DNS codec
The DNS TTCN-3 test suite define various types. The following information is available about them to the codec:
Type Name Typecode ============================================================== TYPE_DNS_Message TYPE_DNS_Message TCI_RECORD_TYPE TYPE_DNS_Header TYPE_DNS_Header TCI_RECORD_TYPE TYPE_DNS_Question TYPE_DNS_Question TCI_RECORD_TYPE UInt16 UInt16 TCI_INTEGER_TYPE Bit1 Bit1 TCI_BITSTRING_TYPE Bit3 Bit3 TCI_BITSTRING_TYPE Bit4 Bit4 TCI_BITSTRING_TYPE charstring charstring TCI_CHARSTRING_TYPE
We could settle to parse the necessary length information for integer, bistring, and charstring types from the name of the type in case of integer and bitstring.
Alternatively we can attach something called "encoding attributes" to these types. See the table below.
In case of the charstring, the length of that type (or field) is variable. The length is deduced by using other methods (when encoding, the length is taken from the length of the charstring; when decoding, the length is taken from the encoded messages).
Type Name Typecode Encode attribute ================================================================ TYPE_DNS_Message TYPE_DNS_Message record N/A TYPE_DNS_Header TYPE_DNS_Header record N/A TYPE_DNS_Question TYPE_DNS_Question record N/A UInt16 UInt16 integer length=16 Bit1 Bit1 bitstring 1 bits Bit3 Bit3 bitstring 3 bits Bit4 Bit4 bitstring 4 bits charstring charstring charstring N/A
Step 3: Add encoding attributes
Instructions:
Add the above "encode" attributes to the DNS types mentioned.
Step 4: Using a DNS SUT Adapter
Copy the "TC_receive" test case to "TC_query" and change it so that the test case expects "T_DNS_answer" using the receive statement instead of "T_DNS_query" that we used when "TC_receive" was used with the loopback adapter. After this and after we added the encoding attributes during Step 3, we are ready to use the DNS SUT Adapter that is ready for our exercises.
Instructions:
In Windows XP:
startif_adapter
Try the test case!
Step 5: What if you receive something unexpected
When you tried the "TC_query" test case, you might have received an answer that was not that you expected using your specific receive statement. It would be handy to find out why the template for the expected message did not match with the received message. You can find this information by running the test case with mismatch log events enabled.
Instructions:
Re-run the "TC_query" test case with "-i -m" (--indent and --log-mismatch-events) options.
Summary
Congratulations! You have just completed the sixth exercise of today. During this exercise you learned how to specify encoding attributes for types to facilitate coding and decoding. This course is almost over, but we still have one thing to learn, how to use dynamic test configurations.
