![]() |
![]() |
![]() |
![]() |
![]() |
ASN.1 Types and Values
ASN.1 is used to describe data types. It is often used as a means for defining the PDU structures of many OSI protocols. In the following we shall give an overview of the ASN.1 type and value notation.
Type References, Value References and Identifiers
A type reference is the "name" of an ASN.1 type constructed by the ASN.1 user. The ASN.1 standard requires that the initial character of a type reference is always an upper case letter.
A value reference is the "name" of an ASN.1 value constructed by the ASN.1 user. The ASN.1 standard requires that the initial character of a value reference is always a lower case letter.
Many test suite specifiers ignore this convention, indeed, so does ISO/IEC 9646-3!
As you will see shortly, type references in SETs and SEQUENCEs etc. may be "labeled". Such labels are called identifiers. The ASN.1 standard requires that the initial character of an identifier is always a lower case letter. Value references and identifiers are distinguished by context.
Identifiers and Underscore
The ASN.1 standard allows the character dash (-) in identifiers. TTCN does not (otherwise there would be ambiguity in arithmetic expressions between dash and minus). TTCN uses underscore (_) instead. If ASN.1 definitions are imported, copied, borrowed etc. from external specifications (e.g. the PDU definitions for a particular protocol) then all occurrences of dash in identifiers should be changed to underscore.
ASN.1 Simple Types
BOOLEAN
BOOLEAN is a type denoted by two distinguished values: TRUE and FALSE. The TTCN has operators for values of any type whose base type is BOOLEAN.
INTEGER
INTEGER is a type denoted by the distinguished values which are the positive and negative whole numbers, including zero. TTCN has operators for any values whose base type is INTEGER.
REAL
REAL is a data type specified as a triple of three INTEGERS consisting of:
The base is limited to 2 or 10.
TTCN does not have any operators for values of REAL types. If REAL arithmetic is absolutely necessary this can be achieved by user defined operations.
BIT STRING
BIT STRING is a type whose distinguished values are the ordered sequences of zero, one, or more BITs. Individual BITs in the BIT STRING may be named.
OCTET STRING
OCTET STRING is a type whose distinguished values are the ordered sequences of zero or an even number of HEX digits, each digit corresponding to an ordered sequence of four bits. Individual OCTETSs in the OCTET STRING may be named.
There is an incompatibility between TTCN and ASN.1 over the value denotation of OCTET STRING. TTCN terminates OCTET STRING values with the keyword `O' rather than the keyword `H'.
CharacterString
A variety of character sets are supported. For the purposes of this guideline we shall restrict ourselves to using the ITU character set IA5String.
ENUMERATED
ENUMERATED types represent the complete set of values (domain) that an instance of a data type may take.
No TTCN operators can be applied to values of ENUMERATED type.
OBJECT IDENTIFIER
OBJECT IDENTIFIER denotes a named object as a sequence of non-negative INTEGERs. The naming hierarchy of specific objects is decided by the relevant authority (e.g. ISO or ITU). An OBJECT IDENTIFIER specifies a unique path in this hierarchy, i.e. all objects are uniquely named.
The OBJECT IDENTIFIER for ISO/IEC 9646-3 would be 1.0.9646.3
Objects that TTCN needs to reference in this manner might be ASN.1 modules (PDUs etc.) and PICS, PXIT documents.
OBJECT DESCRIPTOR
OBJECT DESCRIPTOR denotes a text string that references an object. The difference between an OBJECT IDENTIFIER and an OBJECT DESCRIPTOR is that the former is unique, while the latter may not be.
ASN.1 Constructors
Complex data types can be built from the simple predefined types (excepting HEXSTRING) using ASN.1 constructors. This process is recursive, i.e. constructors can use other constructors (including themselves) to an arbitrary level of nesting. The constructor types are:
SEQUENCE
SEQUENCE is a data type denoting an ordered set of elements. This set may be empty. The elements of this set may be of any ASN.1 type and may be of different types. The elements in the set may be named.
- ASequence ::= SEQUENCE {field1 INTEGER, field2 BOOLEAN}
- a-value ASequence ::= { field1 123, field2 TRUE }
SEQUENCE OF
SEQUENCE OF is a data type denoting an ordered set of elements. This set may be empty. The elements of this set may be of any ASN.1 type but they shall all be of the same type. The elements in the set may be named.
SET
SET is a data type denoting an unordered set of elements. This set may be empty. The elements of this set may be of any ASN.1 type and may be of different types. The elements in the set may be named.
SET OF
SET OF is a data type denoting an unordered set of elements. This set may be empty. The elements of this set may be of any ASN.1 type but shall all be of the same type. The elements in the set may be named.
At first glance SEQUENCE and SET may appear the same. The difference is that a SEQUENCE is ordered, a SET is not. For instance, in the previous examples when the SET is eventually encoded it can be transmitted by sending field2 before field1, if wished. In the case of SEQUENCE field1 must always precede field2. This has implications when testing, which will be discussed later.
The same applies to SEQUENCE OF and SET OF.
In short, SEQUENCE and SEQUENCE OF rely on ordering to avoid ambiguity. SET and SET OF rely on the data type and/or tag of each element to uniquely distinguish each element.
OPTIONAL
The keyword OPTIONAL in a SEQUENCE or SET indicates that the presence of that element in the SEQUENCE is not mandatory and may be included or omitted at will.
- ASequence ::= SEQUENCE { field1 INTEGER OPTIONAL, field2 BOOLEAN }
- a-value1 ASequence ::= { 123, TRUE }
- a-value2 ASequence ::= { TRUE }
The same applies for SEQUENCE OF, SET and SET OF.
DEFAULT
In certain cases it is useful to be able to specify a DEFAULT value to be used (in encoding) if the element is not present in the data type.
CHOICE
A CHOICE type is a data type that defines the union of one or more data types. The alternatives in this union may be named. Any given instance, i.e. value, of a CHOICE shall be exactly one of the alternatives of the CHOICE. This has implications for testing which will be discussed later.
- AllPDUs ::= CHOICE {pdu1 SEQUENCE { ..... }, pdu2 SEQUENCE { ..... }, pdu3 SEQUENCE { ..... } }
- a_pdu AllPDUs ::= pdu2
TAGGED TYPES
Tags are used to distinguish between different occurrences of the same type. Tags are denoted by a non-negative INTEGER enclosed in square brackets. Tags are included in the encoding of the data type. There are four classes of tags:
IMPLICIT
The keyword IMPLICIT may be used together with the definition of the tagged type. IMPLICIT is an instruction to an ASN.1 encoder that only the tag need be encoded and thus transmitted over the network. This is done to reduce the amount of transmitted data. IMPLICIT may only be used where no loss of essential information would occur. For example, it should not be used with CHOICE.
EXTERNAL
http://www.ibm.com/rational |
![]() |
![]() |
![]() |
![]() |