You are on page 1of 20

Abstract Syntax Notation One

ASN.1 and snmp

Network Management (NETW-1001)


Dr. Mohamed Abdelwahab Saleh
Eng. Reham Fouad
IET-Networks, GUC

Spring 2014

Abstract Syntax Notation One

ASN.1 and snmp

TOC

Abstract Syntax Notation One

ASN.1 and snmp

Abstract Syntax Notation One

ASN.1 and snmp

Abstract Syntax Notation One


Abstract Syntax Notation One (ASN.1) is a language for specifying
the abstract syntax of new data types. We should differentiate
between:
Abstract syntax: A high-level description of data types based
on type constructors. This description does not specify how
these types will be implemented in programming languages,
e.g., as data structures.
Concrete syntax: The implementation of abstract syntax in a
particular programming language. For instance, the same
abstract syntax may lead to two different implementations as
concrete syntax, e.g., Java syntax is different than C++.
Transfer syntax: This describes how data structures should be
transmitted, as sequences of bits, during communication.
The rules that describe how to obtain the transfer syntax of a
particular abstract syntax are called encoding rules in ASN.1
notation.

Abstract Syntax Notation One

ASN.1 and snmp

What can we Specify with ASN.1


ASN.1 enables us to specify data types and declare values of these
types.
Specifying Types
Declaring Values
Type names begin with
upper-case letters.
New types are defined from other
types using type constructors.
Types are defined using a
top-down approach, by going from
the more general to the more
specific until we reach simple
built-in types.
For instance, we may say that a
class is a set of students, then
specify that a student is a fist name
followed by a family name, then
specify that each name is a string.

Value names begin with


lower-case letters.
A value is declared using defined
types.
To declare a value called count
of type integer we write:
count Integer::= 15

Abstract Syntax Notation One

ASN.1 and snmp

ASN.1 Built-in Types

Simple Types
These are the basic types:
BOOLEAN
INTEGER
BIT STRING
ENUMERATED
PRINTABLESTRING
NUMERICSTRING
...

Structured Types
Built using type constructors:
SEQUENCE
SEQUENCE OF
SET
SET OF
CHOICE

Abstract Syntax Notation One

ASN.1 and snmp

The ENUMERATED Type


An enumerated type is an integer type. However, values of an
enumerated type are taken from a finite defined set.
Example
Protocol-type ::= ENUMERATED{
tcp(1),
udp(2),
arp(3)
}
This means that a value of type Protocol-type can either be 1
(for tcp), 2 (for udp), or 3 (for arp).
To declare a value called prot of the type Protocol-type, we
can write any of the two alternatives:
prot Protocol-type::= 1
prot Protocol-type::= tcp
6

Abstract Syntax Notation One

ASN.1 and snmp

Structured TypeSEQUENCE
A SEQUENCE in ASN.1 is similar to a struct in C++ or a class
with data fields only (without methods). In other words, a
SEQUENCE is a data structure that contains values of several
types. The order of the values is important.
Example
PDU ::= SEQUENCE{
header HeaderType,
body PDUBody
}
The example above defines a type called PDU. It means that a value of
type PDU will contain a value called header whose type is HeaderType,
and a value called body whose type is PDUBody. This definition should
be followed by the definitions of both types: HeaderType and PDUBody.
7

Abstract Syntax Notation One

ASN.1 and snmp

The OPTIONAL and DEFAULT Keywords


Some of the fields in a SEQUENCE may be declared as
OPTIONAL or have a DEFAULT value:
OPTIONAL: field value may be missing.
DEFAULT v: If field value is missing, it is assumed to be v.
Example
IntSeq ::=SEQUENCE{
count INTEGER OPTIONAL,
order INTEGER DEFAULT 0
}
Possible values of type IntSeq:
val1 IntSeq::={count 5 order 2}
val2 IntSeq::={order 7}
8

Abstract Syntax Notation One

ASN.1 and snmp

Tags
Consider the example:
Example
IntSeq ::=SEQUENCE{
number [0] INTEGER OPTIONAL,
count [1] INTEGER OPTIONAL,
order [2] INTEGER DEFAULT 0
}
Suppose during a protocol exchange, a sender sent to a receiver
the value 7 5, the receiver needs to know if 7 is the value of
number or count. Both values have the same type
(INTEGER), so there needs to be some extra information that
helps identify both values. For this we add extra tagsthe values
in square brackets shown above. So inside the sequence, 0
identifies number, 1 identifies count, etc.
9

Abstract Syntax Notation One

ASN.1 and snmp

Structured TypeSEQUENCE OF

SEQUENCE OF constructs a data structure that contains ordered


values of the same type. SEQUENCE OF is similar to arrays in
programming languages.
Example
HeaderType::= SEQUENCE OF Header-part
Header-part::= SEQUENCE{
part-code NumericString(SIZE(16)),
part-data NumericString(SIZE(16))
}

10

Abstract Syntax Notation One

ASN.1 and snmp

Structured TypeCHOICE

A value of type CHOICE can be of one of many possible types.


Example
PDUBody::= CHOICE{
request Request-type,
response Response-type
}
The example above means that a value of type PDUBody can
either be a request (of type Request-type), or a response (of type
Response-type).

11

Abstract Syntax Notation One

ASN.1 and snmp

Structured TypeSET and SET OF

A SET type is an unordered collection of values of different types.


A SET OF type is an unordered collection of values of the same
type.
Example
Request-type::= SET{
requestId INTEGER
requestValue NumericString
}
SET OF is similar to SET except that all values have the same
type.

12

Abstract Syntax Notation One

ASN.1 and snmp

ASN.1 Modules

ASN.1 definitions can be grouped into modules.


A module can be saved as a file and its definitions used in
other modules.
Inside the module definitions follow the usual discussed order
of going from more general to more specific types.
ASN.1 modules are used in the definitions of various protocols
such as snmp.
The advantage is that protocol data structures, e.g., PDUs,
can be described in a standard way.
Moreover, encoding rules represent standard solutions that
can be readily used to specify the transfer syntax of protocols.

13

Abstract Syntax Notation One

ASN.1 and snmp

ASN.1 ModuleStructure
h module-name i DEFINTIONS ::=
BEGIN
IMPORTS h list of types i FROM h module-name i
h type definitions are put here i
END
A module has a name followed by the keyword DEFINTIONS. The
type definitions are put between the two keywords BEGIN and END.
The IMPORTS keyword makes it possible to use types defined in
another module (the one whose name comes after the keyword
FROM). The names of these types should be listed between
IMPORTS and FROM.
14

Abstract Syntax Notation One

ASN.1 and snmp

ASN.1 ModuleExample
protocol-def DEFINTIONS ::=
BEGIN
PDU ::= SEQUENCE{
header HeaderType,
body PDUBody
}
HeaderType::= SEQUENCE OF Header-part
Header-part::= SEQUENCE{
part-code NumericString(SIZE(16)),
part-data NumericString(SIZE(16))
}
PDUBody::= CHOICE{
request Request-type,
response Response-type
}
Request-type::= . . .
Response-type::= . . .
...
END
15

Abstract Syntax Notation One

ASN.1 and snmp

ASN.1 and MIBs

A subset of ASN.1 is used to specify data types (SYNTAX) of


objects in an MIB.
This subset includes:
Type constructors SEQUENCE (to define lists) and
SEQUENCE OF (to define tables).
The DEFAULT and OPTIONAL keywords are not allowed.
Defined simple types: IpAddress, Counter, Gauge, TimeTicks,
etc.

16

Abstract Syntax Notation One

ASN.1 and snmp

Object Definitions

In MIBs, an object definition consists of five fields:


OBJECT-TYPE: Follows the objects name, it starts the
objects definition. An objects name has a corresponding
Object ID (OID)
SYNTAX: This where an ASN.1 type is used.
DEFINITION: Textual description.
ACCESS: May be read-only, read-write, write-only, or
not-accessible.e read-only, read-write, write-only, or
not-accessible.
STATUS: May be of mandatory, optional, or obsolete.

17

Abstract Syntax Notation One

ASN.1 and snmp

Example Object Definition Basic Type

This is an example taken from the Java Virtual Machine (JVM)


MIB.
jvmClassesLoadedCount
OBJECT-TYPE
SYNTAX
Gauge32
ACCESS
read-only
STATUS
current
DESCRIPTION "The number of classes currently loaded in the JVM."
::= { jvmClassLoading 1 }
Here Gauge32 is a simple type.

18

Abstract Syntax Notation One

ASN.1 and snmp

Example Object Definition Structured Type


This is an example taken from the Java Virtual Machine (JVM)
MIB.
JvmMemManagerEntry is a structured type declared as a
SEQUENCE.
jvmMemManagerEntry OBJECT-TYPE
SYNTAX
JvmMemManagerEntry
ACCESS
not-accessible
STATUS
current
DESCRIPTION "A jvmMemManagerEntry conceptual row represent an instance
of the java.lang.management.MemoryManagerMXBean interface. REFERENCE:
J2SE 5.0 API Specification, java.lang.management.MemoryManagerMXBean"
INDEX { jvmMemManagerIndex }
::= { jvmMemManagerTable 1 }
JvmMemManagerEntry ::=
jvmMemManagerIndex
jvmMemManagerName
jvmMemManagerState
}

SEQUENCE {
JvmPositive32TC,
JvmJavaObjectNameTC,
JvmValidityStateTC

19

Abstract Syntax Notation One

ASN.1 and snmp

Assignment

Submit a two-page description of a protocol whose PDUs are


defined in ASN.1:
Briefly describe the protocol.
Describe the PDUs and give their ASN.1 definition.

Reading assignment: Read the JVM MIB.

20

You might also like