OpenTTCN/Training/TTCN-3 Basics/Exercises/2.5
From OpenTTCN
Exercise 2.5: Sending and receiving messages
Goal: In this exercise we are learning how to send and receive messages. In addition we are learning how to find more information about processing of received messages during a test case execution.
Step 1: Sending and receiving messages
Sending messages in TTCN-3 includes invoking the send statement that causes sending of a message.
Receiving messages in TTCN-3 includes multiple steps: First the message arriving from a SUT adapter is "enqueued" into an incoming message queue (FIFO). Second the first message in the incoming message queue is "matched" against a single receive statement or multiple receive statements presented as alternatives. This matching is continued until a match is found which is the moment when that first message in the incoming message queue is removed from the queue.
Step 2: Setting a loopback
Because we don't yet have a DNS SUT adapter we need to try this test suite using a loopback adapter included to OpenTTCN Tester.
Instructions:
- In Windows XP:
start robo -s 127.0.0.1:5500:dnsc TRI TRI
The above command creates a loopback for "TRI" interface used in the "dnsc" testing session running in IP address "127.0.0.1" and in port number 5500.
Step 3: How to send a message
Instructions 1:
- Enhance the "TC_send" test case from the previous 2.4 exercise. Add message-based send statement between the map and unmap statements sending to port "port_A" a message specified by "T_DNS_query".
Instructions 2:
- Try to run the "TC_send" test case and observe the log and the debug output of the robo loopback adapter.
Instructions 3:
- Re-run the "TC_send" test case with "-i" (--indent) option.
Step 4: How a message enters a test component
Messages are received by a test component automatically. When a message is enters to a test component, the message is appended to the incoming input queue. By default this operation is not shown in the log, but the append operation can be made visible using the "tester run" "-e" (--log-enqueued-events) option. The message stays in the incoming input queue until it is processed, see Step 5.
Instructions:
- Re-run the "TC_send" test case with "-e" (--log-enqueued-events) option.
Step 5: How to specify an expected message ("receive a message")
Messages stay in the incoming input queueu until they are processed by some TTCN-3 statements that removes them such as receive, trigger, interleave, etc.
Instructions 1:
- Copy the current "TC_send" test case to the same module with name "TC_receive".
Instructions 2:
- Enhance the "TC_receive" test case just copied. Add message-based receive statement between the send and unmap statements expecting from port "port_A" a message specified by "T_DNS_query".
Summary
Congratulations! You have just completed the last exercise from the set of five TTCN-3 exercises. During this exercise you learned how to send and receive DNS messages using templates from exercise 2.3 and MTC and TSI of previous 2.4 exercise. Tomorrow, in the next exercise we will learn to define alternatives.
