ASN.1 (Abstract Syntax Notation )
📘 ASN.1 (Abstract Syntax Notation )
ASN.1 is a formal language used to define the structure and data types of information exchanged between computer systems. In network management, it helps describe the management objects and their values used by protocols such as SNMP.
The important idea is that ASN.1 defines what the data means and how it is structured, independently of how the data is transmitted as bits.
1. Why do we need ASN.1?
Suppose a computer sends the following information to another computer:
Student name:
AnuAge:
20
The receiver must know which bits represent the name and which represent the age. For more complex data, such as an array or a record, interpreting the received bits becomes even more difficult.
ASN.1 solves this problem by providing a standard way to define data types and structures.
Note that ASN.1 defines the abstract data structure; a separate encoding rule, such as BER (Basic Encoding Rules), specifies how values are represented in transmitted bytes.
2. Basic symbols used in ASN.1
Your textbook introduces the following symbols.
Symbol | Meaning | Example |
|---|---|---|
| Defined as / assignment |
|
| Choice or alternative |
|
| Defines a list or collection |
|
| Defines a range or subtype constraint |
|
| Starts a comment |
|
Square brackets [] are used for tags, and parentheses can also enclose subtype constraints, depending on the construct.
3. ASN.1 data types
ASN.1 provides built-in data types, which can be combined to define new types.
A. Simple data types
Data type | Purpose | Example |
|---|---|---|
| Positive, negative, or zero integers |
|
| Logical values |
|
| Real numbers |
|
| Sequence of bits |
|
| Sequence of 8-bit bytes | Binary data |
| Represents a null value | No value |
| Selects from named alternatives |
|
| Identifies an object in a hierarchy | An object ID |
These types allow systems to represent numbers, flags, binary information, text-related data, and uniquely identified objects.
B. Defining new data types
ASN.1 allows us to create new types from existing types using ::=.
Example:
Age ::= INTEGER
DayOfWeek ::= ENUMERATED {
sun, mon, tue, wed, thu, fri, sat
}Here:
Ageis a new type based onINTEGER.DayOfWeekis a type whose values are selected from seven named alternatives.
C. Defining subtypes
A subtype restricts the values allowed by an existing type.
NumberOfStudents ::= INTEGER (15..40)
Grade ::= REAL (1.0..5.0)In this example, NumberOfStudents can have integer values from 15 to 40, while Grade can have real values from 1.0 to 5.0.
A value outside the specified range would not satisfy the subtype constraint.
4. Assigning values to variables
After defining a type, we can declare a value of that type.
The general form is:
variableName Type ::= valueExample:
numberOfComputers INTEGER ::= 2
classSize NumberOfStudents ::= 22
herAge INTEGER ::= 35The variable name starts with a lowercase letter in the textbook's convention, while a type name starts with an uppercase letter.
5. Structured data types
ASN.1 can represent more complex structures, similar to struct and arrays in C or C++.
A. SEQUENCE — similar to a structure or record
A SEQUENCE contains an ordered collection of fields that may have different types.
StudentAccount ::= SEQUENCE {
userName VisibleString,
password VisibleString,
accountNumber INTEGER
}A value can be assigned as follows:
johnNewton StudentAccount ::= {
userName "JohnN",
password "120007",
accountNumber 25579
}The StudentAccount type contains three fields: a username, a password, and an account number.
B. SEQUENCE OF — similar to an array
SEQUENCE OF represents an ordered collection of elements of the same type.
For example:
StudentAges ::= SEQUENCE OF INTEGERA value of this type could contain:
18, 19, 20, 21
This is useful when defining lists or tables of values, such as entries in a router's forwarding table.
6. How ASN.1 relates to SNMP, SMI, and MIB
This is especially important for Network Management
ASN.1
A general notation for defining data types and structures.
SMI
Uses a subset of ASN.1 concepts and defines rules for naming and describing management objects and their types.
MIB
Defines the management objects available for a managed device and associates them with appropriate types.
SNMP
Exchanges management messages to read or change the values of supported objects.
For example, a router may have a management object representing the number of packets received. SMI specifies the rules for describing the object, MIB defines the object and its type, and SNMP allows a manager to retrieve its value.
7. ASN.1 encoding
Defining a data type is not enough; the data must also be converted into a representation that can be transmitted.
ASN.1 works with encoding rules such as BER (Basic Encoding Rules). BER specifies how data values are encoded into bytes and decoded by the receiver.
For example, BER commonly represents a value using three parts:
Tag: Identifies the data type.
Length: Specifies the size of the encoded value.
Value: Contains the encoded data itself.
This is often called the TLV (Tag-Length-Value) format.
Quick Summary
ASN.1: Defines data types and structures.
SMI: Defines rules for describing management objects.
MIB: Defines the actual management objects for a device.
SNMP: Reads and changes management object values.
SEQUENCE: An ordered record containing fields that may have different types.
SEQUENCE OF: An ordered collection of elements of the same type.
BER: Defines how ASN.1 values are encoded into bytes.
Key takeaway: ASN.1 describes the structure of data, while encoding rules such as BER describe how that data is represented for transmission.

Comments
Post a Comment