Beruflich Dokumente
Kultur Dokumente
Table of Contents
Abstract Syntax Notation One (ASN.1)
Overview Properties & Restrictions Type and Value Definitions ASN.1 Simple Types ASN.1 Structured Types ASN.1 Macro Definitions
Overview of ASN.1
a machine independent data description language CCITT (X.208) and ISO (ISO 8824) standard define abstract syntax of application data define the structure of application and presentation protocol data units (PDUs) define SNMP and OSI Management Information Base (MIB)
ASN.1 Terminology
Abstract Syntax
describes the generic structure of data allows data types and values to be defined
Data Type
a named set of values -- may be simple or structured
Encoding
sequence of octets used to represent a data value
Encoding Rules
specifies the mapping from one syntax to another
Transfer Syntax
describes how data are actually represented in terms of bit patterns while in transit
4
local mapping
Application component
Application component
local mapping
encoding rules
encoding rules
<modulereference> DEFINITIONS ::= Definitions in this module that may BEGIN be imported by other modules. EXPORTS Definitions that are to be imported IMPORTS from other modules. AssignmentList Type assignments, value assignments, and macro definitions END
that are defined in this module.
6
Lexical Conventions
Comments begin with two hyphens (--) and terminated either by another set (--) or the end of line character Identifiers begin with a letter, and may contain letters, digits, and hyphens, but may not end with a hyphen or contain two consecutive hyphens The type identifier must start with an uppercase letter The value identifier must start with a lowercase letter Reserved keywords are all uppercase Multiple spaces and blank lines can be considered as a single space
Structured
types with components
Tagged
types derived from other types
Other
CHOICE and ANY types
Every ASN.1 data type, with the exception of CHOICE and ANY types, has an associated TAG, which consists of a class name and nonnegative integer tag number
8
Classes of TAG
UNIVERSAL
Built-in types, application independent types See Table B.2
APPLICATION
Application specific types
CONTEXT-SPECIFIC
limited to a context within an application
PRIVATE
defined by users and not covered by any standard
OCTET STRING
a sequence of zero or more octets (8-bit bytes)
NULL
the single value NULL
Other ASN.1 simple types include boolean, bit string, real, enumerated, PrintableString, etc.
10
SET OF
a collection of zero or more occurrences of a given type
SEQUENCE
an ordered collection of one or more types
SEQUENCE OF
an ordered collection of zero or more occurrences of a given type
CHOICE
a list of alternatives
11
ASN.1 Example
Informal Description of Personnel Record
Name: Title: Employee Number: Date of Hire: Name of Spouse: Number of Children:
Child Information Name: Date of Birth: Child Information Name: Date of Birth:
James W Hong Associate Professor 20292 May 26, 1995 In-Young B Hong 2
Suk D Hong 29 March 1988 Myungdo M Hong 10 August 1994
12
13
<macroname> MACRO ::= BEGIN TYPE NOTATION ::= <new-type-syntax> VALUE NOTATION ::= <new-value-syntax> <supporting-productions> END
16
17
Overview of BER
BER Basic Encoding Rules an encoding specification CCITT (X.209) and ISO (ISO 8825) standard describes a method for encoding values of each ASN.1 type as a string of octets based on the use of a type-length-value (TLV) structure
Type Length Value
18
BIT
Constructed
Most significant Least significant
Tag number
CLASS
Universal Application
Bit 8
0 0
Bit 7 Description
0 1 0 1 Built-in types SNMP defined types Used in context Not used in the SNMP protocol
19
Context-Specific 1 Private 1
SNMPv1 protocol
SNMPv2 protocol
ASN.1 Tag
UNIVERSAL 2 UNIVERSAL 4 UNIVERSAL 5 UNIVERSAL 6 UNIVERSAL 16 APPLICATION 0 APPLICATION 1 APPLICATION 2 APPLICATION 3 APPLICATION 4
0x04
0x05 0x06 0x10 0x00 0x01 0x02 0x03 0x04
0x04
0x05 0x06 0x30 0x40 0x41 0x42 0x43 0x44
APPLICATION 6
0x06
0x46 20
Encoding Methods
The TLV structure is recursive for any ASN.1 value that consists of one or more components, the value portion of its TLV encoding itself consists of one or more TLV structures Three methods for encoding an ASN.1 value: 1. Primitive, definite-length encoding 2. Constructed, definite-length encoding 3. Constructed, indefinite-length encoding
The method chosen depends on the ASN.1 type of the value to be encoded and whether or not the length of the value is known based on the type (see Table B.4)
21
= 102
= 7559605
Tag Universal 2 0 0 0 0 0 0 0 0
Length 1
Value 0
Tag Universal 2 1 0 0 1 0 1 1 0
Length 2 1 0 1 1 0 1 0 1
Value (1 of 2)
Value (2 of 2)
Tag Universal 4 1 1 1 0 1 0 1 1
Length 4 0 0 0 0 0 1 1 0
1st octet 1 0 0 1 1 0 0 1
2nd octet 0 0 1 1 0 1 1 1
3rd octet
4th octet
Overall Length = 6
0
1
0 0
0
0
0
0
0
0
0
0
1
0
0
0
0 0
1
1
Length 9
Value (3 of 9) integer 0 0 0 0 0
26
Summary
We have covered a subset of ASN.1 and BER which are used in SNMP and OSI Management Frameworks ASN.1 is widely used in defining application data and protocol data units BER is widely used in defining transfer syntaxes READ:
Stallings, SNMP, SNMPv2, SNMPv3 and RMON 1 and 2, 3rd Edition, Addison-Wesley, Appendix B
27