![]() |
![]() |
![]() |
![]() |
![]() |
Support for External ASN.1 in the TTCN Suite
The ASN.1 Utilities are also used by the TTCN Suite if a TTCN test suite contains data types and constraints that are defined in the tables "ASN.1 Type Definitions By Reference" and "ASN.1 Constraints By Reference". For more information, see ASN.1 External Type/Value References.
Since TTCN is based on the older X.228 standard, while the ASN.1 Utilities are based on the new X.680 standard, users should be careful to use the common subset of X.680 and X.228 if an ASN.1 module is to be used in TTCN. In particular there are a number of differences:
- In ENUMERATED types, a value must be supplied for all values. For example:
E ::= ENUMERATED { a, b }E ::= ENUMERATED { a(0), b(1) }- X.680 offers more possibilities for specifying constraints than X.228 does. X.228 does not have the keywords ALL, EXCEPT, UNION, and INTERSECTION.
- For ASN.1 types that have components (e.g. SET or SEQUENCE), an identifier must be provided for every component (according to X.680), while in X.228 identifiers can be omitted. For example:
S ::= SEQUENCE { INTEGER } -- valid X.228S ::= SEQUENCE { field1 INTEGER }General
- `-' (dash) in ASN.1 names is transformed to `_' (underscore), e.g. long-name in ASN.1 is transformed to long_name in TTCN.
- In general ASN.1 to TTCN translation look like pretty printing of ASN.1 modules into TTCN tables for most of the constructs, but not all of them. Some ASN.1 concepts are not supported in TTCN Suite, they have to be modified during TTCN generation:
- Concepts defined in X.681, X.682 and X.683 (see Information from Object Classes, Objects and Object Sets, CONSTRAINED BY notation and Parameterization)
- automatic tagging (see Keywords substitution)
- COMPONENTS OF Type notation (see COMPONENTS OF Type notation)
- selection types (see Selection types)
- enumerated types without numbers for enum identifiers (see Enumerated types)
- extensibility (see Extensibility)
Keywords substitution
ASN.1 generators can be configured to be sensitive to a certain number of identifiers. There is a special text file named `asn1util_kwd.txt' that contains a list of identifiers and a list of their substitution during mapping. By default this file is used to configure target languages keywords substitution. It can be edited to get another functionality or another set of keywords to be replaced.
`asn1util_kwd.txt' should contain pairs of identifiers where the first one is the identifier from the original ASN.1 specification that will be replaced by the second identifier during generation. `asn1util_kwd.txt' should conform to the following syntax:
Example 63 Configuration file syntax
<identifier1> <identifier1 substitution><identifier2> <identifier2 substitution>...<identifierN> <identifierN substitution>ASN.1 Utility reads the first configuration file it finds. It searches for `asn1util_kwd.txt' file first in the current folder, then in the home folder and finally in the installation. If a configuration file named `asn1util_kwd.txt' is put in the home folder or in the current working folder, it will override the default configuration file from the installation. The configuration file to be used can also be specified in the command line with the `-K' option (see Command-Line Interface), for example,
Example 64 Configuration file specification
asn1util -K my_config.txt -i File.ttcn File.asn`asn1util_kwd.txt' is always present in the installation and it is configured to replace keywords from the SDL, TTCN, C and C++ languages: the ASN.1 identifier name, that is a keyword in SDL, TTCN or C++, is replaced by name_SDL_KEYWORD, name_TTCN_KEYWORD or name_CPP_KEYWORD to avoid syntax errors in the target languages (see Appendix A: List of recognized keywords). If an original ASN.1 identifier has been modified, a warning message is reported. See ERROR 2077 ASN.1 identifier #1 is a keyword, it will be replaced by #2).
Example 65 Keywords default substitution
CASE ::= ENUMERATED { upper, lower }T ::= SEQUENCE {int INTEGER,explicit BOOLEAN,case CASE,signal INTEGER}value1 T ::= {int 5,explicit TRUE,case lower,signal 27 }With default keywords substitution file the following TTCN is generated:
CASE_TTCN_KEYWORD ::=ENUMERATED {upper(0), lower(1)}T ::= SEQUENCE {int_CPP_KEYWORD INTEGER,explicit_CPP_KEYWORD BOOLEAN,case_CPP_KEYWORD CASE_TTCN_KEYWORD,signal_SDL_KEYWORD INTEGER}value1 T ::= {int_CPP_KEYWORD 5,explicit_CPP_KEYWORD TRUE,case_CPP_KEYWORD lower,signal_SDL_KEYWORD 27}A configuration file allows user to control the set of keywords to be replaced. Removing lines with SDL keywords, for example, will switch off SDL keywords sensitivity. Providing an empty configuration file will result in switching off keywords substitution completely.
Automatic tagging
If 'AUTOMATIC TAGS' is written in the header of an external ASN.1 module, then implicit tags are inserted into SET, SEQUENCE and CHOICE types. During the TTCN generation they are inserted in the type definitions explicitly.
M1DEFINITIONS AUTOMATIC TAGS ::=BEGINT ::= SEQUENCE{a INTEGER OPTIONAL,b INTEGER DEFAULT 5}C ::= CHOICE{x INTEGER,y BOOLEAN,z REAL}ENDis translated to TTCNSEQUENCE{a [0] INTEGER OPTIONAL,b [1] INTEGER DEFAULT 5}CHOICE{x [0] INTEGER,y [1] BOOLEAN,z [2] REAL}COMPONENTS OF Type notation
COMPONENTS OF Type can appear in SET or SEQUENCE field types. Instead of COMPONENTS OF Type a list of components of the referenced type is included, except extension addition components.
S1 ::= SEQUENCE{x INTEGER,g NULL,... ,[[y BOOLEAN,z BIT STRING]],[[c IA5String]],d SET OFINTEGER OPTIONAL,... ,f REAL}S2 ::= SEQUENCE{a IA5String,COMPONENTS OF S1,b OCTET STRING}Type S2 is translated to TTCNSEQUENCE{a IA5String,x INTEGER,g NULL,f REAL,b OCTET STRING}Selection types
A selection type is mapped to the type it denotes.
C ::= CHOICE{a INTEGER,b BOOLEAN}T1 ::= a < CT1 is translated to TTCNINTEGERT2 ::= b < CT2 is translated to TTCNBOOLEANEnumerated types
Enumerated items can be defined using "identifier" notation or "identifier and number" notation. For "identifier" notations, implicit numbers are assigned to the identifiers according to the rules described in X.680 (1997), 19.
For TTCN, all enumeration items are generated with their corresponding numbers using "identifier and number" notation, and they are arranged according to their number values in ascending order in the generated enumeration.
Extension markers are ignored.
A ::= ENUMERATED { a, b, c(0), d, e(2) }is translated to TTCNENUMERATED { c(0), a(1), e(2), b(3), d(4) }B ::= ENUMERATED { a, b(3), ... , c(1) }is translated to TTCNENUMERATED { a(0), c(1), b(3) }Extensibility
Extensibility was introduced in X.680 (1997). In ASN.1 extensibility is represented with extension markers and extension addition groups, that can be specified inside SET, SEQUENCE, CHOICE, ENUMERATED types and constraints.
Extension markers are not visible in TTCN translation. All square brackets are ignored and all components from extension addition groups are translated into TTCN as individual fields. All required components from extension additions, individual or from extension addition groups, are mapped to optional ones.
S1 ::= SET{x [100] INTEGER,... ,[[gr11 REAL]],t BIT STRING,[[gr21 BOOLEAN OPTIONAL,gr22 SET OF INTEGER]],... ,y INTEGER}is translated to TTCNSET{x [100] INTEGER,gr11 REAL OPTIONAL,t BIT STRING OPTIONAL,gr21 BOOLEAN OPTIONAL,gr22 SET OF INTEGER OPTIONAL,y INTEGER}
Extension markers are ignored in constraints. If both root and additional constraints are present, they are translated to the union constraint.T1 ::= INTEGER ( 1..10 ^ 2..20, ... , 12 )is translated to TTCNINTEGER (( 1..10 ^ 2..20 ) | ( 12 ) )T2 ::= INTEGER (1 | 3, ... )is translated to TTCNINTEGER (1 | 3 )Information from Object Classes, Objects and Object Sets
Object classes, object and objects sets are not translated to TTCN. Only types and values are translated to TTCN, but it is possible in ASN.1 to use information from object classes, objects and object sets when specifying types and values. This information is translated into TTCN.
ObjectClassFieldType
ObjectClassFieldType is a reference to an object class and a field in that class. The translation to TTCN depends on the kind of field name used.
An open type is defined if the field name references a type field, a variable type value field or variable type value set field. An open type can be any ASN.1 type. Open types are translated to OCTET STRING types in TTCN.
OPERATION ::= CLASS {&ArgumentType,&arg &ArgumentType}T1 ::= SEQUENCE { a OPERATION.&ArgumentType }SEQUENCE { a OCTET STRING }T2 ::= OPERATION.&argOCTET STRINGIf the field name in the class references a fixed type value or fixed type value set fields, then the fixed type is used when translated to TTCN.
OPERATION ::= CLASS {&ValueSet INTEGER}T ::= OPERATION.&ValueSetINTEGERObjectClassFieldType with table constraint (object set constraint)
A table constraint applied to ObjectClassFieldType restricts the set of possible types or values to those specified in a column of the table. A table corresponds to an object set. The columns of the table correspond to the object class fields and the rows correspond to the objects in the set.
If the field name in ObjectClassFieldType is a type field and constrained with a table, then it is translated to a CHOICE type with fields of the types specified in the table column. The names of the fields in the choice are the same as the names of the types in the column but the first letter is changed from upper case to lower case.
If the type in the field is inline then the name in the field will be an implicitly generated inline name, like t_INLINE_4.
If the field name in ObjectClassFieldType is a fixed type value or a fixed type value set, then this is translated to a constrained type where only values that are specified in the table column are permitted.
If the field name in ObjectClassFieldType is a variable type value or variable type value set field, then this is translated to a CHOICE type with types, that are constrained to have values specified in the corresponding cell in the same row of the table.
OPERATION ::= CLASS {&ArgumentType,&operationCode INTEGER UNIQUE,&ValueSet INTEGER,&ArgSet &ArgumentType}C1 ::= OPERATION.&ArgumentType ( {My-Operations} )CHOICE {integer INTEGER,c1_INLINE_2 SET OF INTEGER}C2 ::= OPERATION.&operationCode ( {My-Operations} )INTEGER ( 1 | 2 )C3 ::= OPERATION.&ValueSet ( {My-Operations} )INTEGER ( ( 1 | 2 | 5..8 ) | ( 2..8 ) )C4 ::= OPERATION.&ArgSet ( {My-Operations} )CHOICE {c4_INLINE_1 INTEGER ( (111..444) ),c4_INLINE_2 SET OF INTEGER ( ( {1,2,3} | {888} ) ) }If an open type is constrained by the table for which all type settings are omitted, then it is translated to TTCN OCTET STRING instead of an empty CHOICE type.
MY-CLASS ::= CLASS {&id INTEGER,&OpenType OPTIONAL}S ::= SEQUENCE {id MY-CLASS.&id({My-Set}),val MY-CLASS.&OpenType({My-Set}{@id})}SEQUENCE {id INTEGER ( 1 | 2 ),val OCTET STRING}TypeFromObject
TypeFromObject is a reference to an object and a type field in that object. This is simply translated to the that type in TTCN. If the field is optional in the class and not set in the object, then TypeFromObject cannot be translated.
OPERATION ::= CLASS {&ArgumentType,&ResultType}operationA OPERATION ::= {&ArgumentType INTEGER,&ResultType BOOLEAN}O1 ::= operationA.&ArgumentTypeINTEGERO2 ::= operationB.&ResultTypeBOOLEANValueSetFromObject
ValueSetFromObject is a reference to an object and a field with a set of values in that object. This is translated to a constrained type in TTCN, allowing only values from the value set.
OPERATION ::= CLASS {&ValueSet INTEGER}operationA OPERATION ::= {&ValueSet { 1 | 2 | 5..8 }}V1 ::= operationA.&ValueSetINTEGER ( 1 | 2 | 5..8 )ValueFromObject
ValueFromObject is a reference to an object and a field with a value in that object. This is translated to the same value in TTCN.
OPERATION ::= CLASS {&operationCode INTEGER UNIQUE}operationA OPERATION ::= { &operationCode 1 }val2 INTEGER ::= operationA.&operationCodeval2 of type INTEGER equal to 1CONSTRAINED BY notation
CONSTRAINED BY is treated like a comment and is not translated to TTCN.
Parameterization
Wherever a parameterized type or value is used, it is translated to TTCN after all dummy references are replaced by the actual parameters. A parameterized value is also translated after all dummy references are replaced by the actual parameters.
Parameterized assignments are ignored when translating to TTCN.
Container { ElemType, INTEGER : maxelements } ::=
SET SIZE (0..maxelements ) OF ElemTypeIntcontainer ::= Container {INTEGER, 25}SET SIZE ( 0..25 ) OF INTEGER
http://www.ibm.com/rational |
![]() |
![]() |
![]() |
![]() |