OpenTTCN/Training/TTCN-3 Basics/Exercises/3.4
From OpenTTCN
Exercise 3.4: Using module parameters / Using address
Goal: In this exercise we are learning two things: how to use module parameters to make modules independent of the System Under Test (SUT) and how to use address.
Step 1: Using module parameters
Module parameters are used to make TTCN-3 modules independent of the System Under Test (SUT) by allowing the behavior and data of the test suite to be altered without requiring changes to the test suite.
Module parameters are used mainly for two purposes: to select test cases that are applicable testing a certain type of SUT or when certaint type of configuration is used, and to provide information about SUT that affects for example to the messages sent and received by the test suite.
Module parameters are used 1) by giving specification of used module parameters by modulepar top-level definitions in TTCN-3 module, and 2) by supplying the current values of these module parameters by a method which is a tool specific.
Step 2: Using module parameters to provide information about SUT
Module parameters allow the test suite to be used to test multiple instances of a particular SUT configured or implemented differently. Module parameters allow also specify configuration settings related to the current testing environment. When testing a DNS server, the IP address and the UDP port number of the DNS server could be specified using module parameters.
Instructions 1:
Specify a module parameter called "PAR_DNS_SERVER" of type charstring without default value in your DNS TTCN-3 module.
Instructions 2:
Specify a module parameter called "PAR_DNS_PORT" of type integer with 53 as the default value in your DNS TTCN-3 module.
In this test suite we can also specify the used domain name and the expected IP address as module parameters.
Instructions 3:
Specify two module parameters called "PAR_DOMAIN_NAME" and "PAR_IP_ADDRESS" of type charstring without default value in your DNS TTCN-3 module.
Change the templates so that you use the values of "PAR_DOMAIN_NAME" and "PAR_IP_ADDRESS" instead of any hardcoded values.
Step 3: Using module parameters to select test cases
Module parameters of boolean type are used to select test cases by using an if statement and a module parameter in the TTCN-3 control part to select particular test cases. Also functions can be used in this process.
Instructions:
Define a module parameter called "PAR_LOOPBACK_USED" of TTCN-3 boolean type in the DNS TTCN-3 module. Use this module parameter to select the "TC_receive" test case for execution if the module parameter has a "true" value. Use a function that contains an execute statement for test cases that can be executed when "PAR_LOOPBACK_USED" module parameter has a "true" value.
Step 4: Supplying values of module parameters
The method of supplying values of module parameters is not specified in the TTCN-3 standard. TTCN-3 tool vendors implement tool specific method for supplying values of module parameters. Here we look how supplying values of module parametes is done with OpenTTCN Tester for TTCN-3 tool.
OpenTTCN Tester for TTCN-3 uses a module parameter values file having format of a TTCN-3 module containing definitions of module parameters with mandatory values.
Instructions 1:
Create a module parameter values file called "dns.par" containing the following specification:
module dns_parameters
{
modulepar boolean PAR_LOOPBACK_USED := true;
modulepar charstring PAR_DNS_SERVER := "192.168.2.1";
modulepar integer PAR_DNS_PORT := 53;
modulepar charstring PAR_DOMAIN_NAME := "select domain";
modulepar charstring PAR_IP_ADDRESS := "select IP address";
}
Instructions 2:
Take the values of module parameters in the "dns.par" file into use by invoking the following command:
importer3 parameterize dnsc dns.par
Step 5: Using address
So far we have been using send statements to send messages through certain port. It has been left to the implementation of the port in the form of a SUT Adapter to select the recipient of our messages. This is sometimes a valid solution. If we require more dynamic behaviour we can us "to" specification and data of type "address" to specify the recipient. In this case the SUT Adapter interprets the address value when sending the message. The same type of functionality is also available when specifying expected messages with receive statement.
Step 6: Enhance TC_receive with address
Instructions 1:
Add the following type of an address definition into your DNS TTCN-3 module:
type record address
{
charstring host, // IP address of the DNS server
integer portField // UDP port number of the DNS server
}
Instructions 2:
Add a variable of type address in the "MTC_DNSclient" test component having its value initialized using the associated module parameters you defined earlier.
Instructions 3:
Enhance "TC_receive" test case by adding "to" specification to the send statement and "from" specification to the receive statement and to the receive all statement of the related altstep.
Summary
Good! You have just completed your fourth TTCN-3 exercise of today. During this exercise you learned how to use module parameters and address. You are now ready to proceed to the next exercise to learn how to use multiple modules.
