Download presentation
Presentation is loading. Please wait.
Published byTheodore Lynch Modified over 9 years ago
1
An Introduction to Abstract Syntax Notation 1 (ASN.1)
Steinar Andresen/Rolv Bræk/Finn Arve Aagesen Norwegian University of Science and Technology, Trondheim
2
The need of a “common language” In order to cooperate the following needs arise
A shared interpretation of what the data means and a common protocol for interchange A shared view on data structure The ASN.1 Notation Transfer coding rules The ASN.1 Encoding schemes: BER, PER, .. L A N - O r g A P U B L I C W A N L A N O r g C L A N O r g B
3
The history of ASN.1 General purpose notation and encoding scheme:
Developed to be applied to the MHS protocols (X.400) (“born” in 1982) Generalised as general tools ISO 8824 Notation and ISO 8825 Encoding rules in 1990, Revised in 1995 General use in many application fields today
4
The original “realm” of ASN
Applied first to the Presentation layer in the “Open Systems Interconnection”. Soon used to define the protocols of the Applications layer: FTAM, ROSE, MHS, etc. Also used for lower layers
5
Why ASN.1 and BER? ASN.1 for the data syntax PDU PDU BER for the
I P r o t o c o l S t a c k O S I P r o t o c o l S t a c k A p p l i c a t i o n A p p l i c a t i o n ASN.1 for the data syntax P r e s e n t a t i o n P r e s e n t a t i o n PDU PDU s S e s s i o n S e s s i o n n o T r a n s p o r t T r a n s p o r t N e t w o r k BER for the (sequential) transfer syntax N e t w o r k D a t a l i n k D a t a l i n k P h y s i c a l P h y s i c a l
6
ASN.1 Use PDU PDU ASN.1 ASN.1 BER Encode Decode
A PDU can be a complex element (letter, document, …) and: specified using datatypes of SDL, LOTOS, UML, ... implemented using datatypes of CHILL, C++, Java, ... ASN.1 provides a language independent syntax and ASN.1 compilers take care of the mapping C++, Java, SDL... PDU PDU C++, Java, SDL... ASN.1 ASN.1 BER Encode Decode C++, Java,... C++, Java,... 1 |
7
ASN.1 Module A module is a set of ASN.1 definitions assembled for a specific purpose. The structure of a module is: ModuleDefinition::= ModuleIdentifier DEFINITIONS DEFINITIONS::= BEGIN ModuleBody END
8
ASN.1 Module Identifier ModuleIdentifer is an element of type Object Identifiers Object Identifiers are adminstrered by ISO, ITU-T, etc. A Module Identifier represents an official reference to the Module.
9
Module Body ModuleBody::= Exports -- definitions that may be exported to other modules Imports -- definitions that are imported from other modules AssignmentList --this modules definitions | “|” means “or” empty
10
Assignments Type assignment Value assignment W h e a t r R p o : = S
EQUENCE{ . } N m f y n c d i Value assignment s a m p l e W R e p o r t W h e a t h e r R e p o r t : : = { . . . . . . } N a m e o f a v a l u e T h e t y p e o f t h i s v a l u e A c t u a l v a l u e s p e c .
11
Type assignment A type assignment has three syntactic elements:
the type reference (the name allocated to it), the symbol “::=“ (means defined as) and the appropriate type notation WheatherReport ::= SEQUENCE { stationNumber INTEGER { } timeOfReport UTCTime }
12
Value assignment A value assignment has four syntactic elements:
the value reference (the name allocated), the type to which the value belongs the symbol “::=“ (means defined as) and the appropriate value notation Sample value assignment: sampleReport WheatherReport ::= { stationNumber timeOfReport “ Z” }
13
Sequence Letter ::= SEQUENCE { opening OCTETSTRING, body OCTETSTRING,
closing OCTETSTRING, address AddressType } AddressType ::= SEQUENCE { name OCTETSTRING, number INTEGER, street OCTETSTRING, postOffice OCTETSTRING, state OCTETSTRING, zipCode INTEGER
14
Optional AddressType ::= SEQUENCE { name OCTETSTRING, number INTEGER,
street OCTETSTRING, apartNumber INTEGER OPTIONAL, postOffice OCTETSTRING, state OCTETSTRING, zipCode INTEGER }
15
Tags Letter ::= SEQUENCE { opening OCTETSTRING, body OCTETSTRING,
closing OCTETSTRING, receiverAddr AddressType OPTIONAL, senderAddr AddressType OPTIONAL } receiverAddr [0] AddressType OPTIONAL, senderAddr [1] AddressType OPTIONAL
16
Spelling Conventions Reserved words: only CAPITAL letters (INTEGER, CHOICE,…) Types: first letter Capital (TransactionID) Value reference: first letter Lowercase (application(0)) Identifier: first letter Lowercase (destination, responder) Macro: only CAPITAL letters
17
ASN.1 Tagged Types Four classes: 1. UNIVERSAL (ASN.1 In-build types)
2. Application specific types (non-ambiguous within module) 3. Context specific types (non-ambiguous within construct) 3. Private (non-ambiguous within some ”enterprise”) UNIVERSAL: Simple types (BOOLEAN, INTEGER, ENUMERATED, …) Constructor types (SEQUENCE, SEQUENCE OF, SET, SETOF) Additional predefined (NumericString, Teletxstring, GeneralizedTime, …) OBJECT IDENTIFIER Tagging is needed to recognise the types in the transfer syntaxt (when decoding a received PDU)
18
Universal Types Universal Tag ASN.1 Type 1 BOOLEAN 2 INTEGER
3 BITSTRING 4 OCTETSTRING 5 NULL 6 OBJECTIDENTIFIER 7 ObjectDescriptor 8 EXTERNAL 9 REAL 10 ENUMERATED 11-15 reserved for addenda 16 SEQUENCE, SEQUENCE OF 17 SET, SET OF … ...
19
Example Example DEFINITIONS::= BEGIN TransactionID ::= INTEGER
Component ::= INTEGER {application(0), networkManager(1), systemManager(2)} Request ::= PrintableString EntityIdentifier ::= [PRIVATE 1] IMPLICIT OCTETSTRING RequestPDU ::= SEQUENCE { responseRequired BOOLEAN, TransactionID, requestor EntityIdentifier, request CHOICE { command [0] IMPLICIT SET {destination Component, Request} shutdown [1] IMPLICIT NULL}} ResponsePDU ::= SEQUENCE { TransactionID, responder EntityIdentifier OPTIONAL, result INTEGER {success(0), failure(1)}} END
20
A Value assignment example
aRequestPDU RequestPDU ::= { ResponseRequired TRUE, 45, requestor “MySystem”, request { command {destination systemManager, ‘status’} }} aResponsePDU ResponsePDU::= { 45, result INTEGER {success}}
21
ASN.1 Transfer Syntax Type Length Value
Defines how to encode the values before sending over the line Basically it is a Type, Length, Value encoding scheme with one or more octets for each of the fields. Type Length Value identified by tagging Basic Encoding Rules BER Packed Encoding Rules PER Canonical Encoding Rules CER Disting. Encoding Rules DER
22
TLV encoding scheme Octet 1 Octet 2 Octet 3 ... Octet n Type Length
bit8 bit 7 ...bit1 Type Length Value … Data Element Data Element Data Element
23
ASN.1 Transfer Syntax ... T A G F I E L D (=Type identifier field)
class f n u m b e r | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | Class: 00 UNIVERSAL 01 APPLICATION 10 Context specific 11 Private f: 0 primitive encoding 1 constructed encoding number: <31 directly >=31 as below: last ... class f 11111 1 … 1 … 0 …
24
Examples BOOLEAN: UNIVERSAL 1 = 00000001 hex
INTEGER: UNIVERSAL 2 = hex SEQUENCE: UNIVERSAL 16 constructed = = 30 hex [PRIVATE 35] IMPLICIT INTEGER = | c l a s f n u m b e r 1 B O L E A N | c l a s f n u m b e r 1 I N T E G R
25
Length field ... ... Definite form short: length < 128
long: length > 128 Indefinite form: only for constructed types 0 <length> ... 1 <length of length field> <length field> <length field> ... <value> <value>
26
V A L U E F I E L D S B O O L E A N E x . F A L S E | | | | | 1 | | |
| | | | | 1 | | | | | | | 1 | | | | | | | | c l a s s | f | n u m b e r | | l e n g t h | | c o n t e n t s | ( T R U E w i t h c o n t e n t v a l u e d i f f e r e n t f r o m ) I N T E G E R E x . 1 ( d e c i m a l ) | c l a s f n u m b e r 1 | l e n g t h 1 | 1 | 1 | | | 1 | | | c o n t e n t s |
27
How to encode RequestPDU ::= SEQUENCE { responseRequired BOOLEAN, TransactionID, requestor EntityIdentifier, request CHOICE { command [0] IMPLICIT SET {destination Component, Request} shutdown [1] IMPLICIT NULL}} where: ResponseRequired = FALSE, TransactionID = 10, requestor = “MySystem”, request = command { destination = networkManager, Request = ‘status’} ??
28
Encoding summary ... class f 11111 1 … 1 … 0 …
Universal Tag ASN.1 Type 1 BOOLEAN 2 INTEGER 3 BITSTRING 4 OCTETSTRING 5 NULL 6 OBJECTIDENTIIER 7 ObjectDescriptor 8 EXTERNAL 9 REAL 10 ENUMERATED 11-15 reserved for addenda 16 SEQUENCE, SEQUENCE OF 17 SET, SET OF … ... Class: 00 UNIVERSAL 01 APPLICATION 10 Context specific 11 Private f: 0 primitive encoding 1 constructed encoding class f n u m b e r | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | number: <31 directly >=31 as below: ... class f 11111 1 … 1 … 0 …
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.