Presentation is loading. Please wait.

Presentation is loading. Please wait.

IHA præsentation1 Outline for today Standard Formal Notations for data structures and messages Motivation Abstract Syntax Notation One (ASN.1)

Similar presentations


Presentation on theme: "IHA præsentation1 Outline for today Standard Formal Notations for data structures and messages Motivation Abstract Syntax Notation One (ASN.1)"— Presentation transcript:

1 IHA præsentation1 Outline for today Standard Formal Notations for data structures and messages Motivation Abstract Syntax Notation One (ASN.1)

2 IHA præsentation2 Standard Formal Notations for Data Structures and Messages

3 IHA præsentation3 Protocol Definition A well-defined set of messages (bit-patterns or - increasingly today - octet strings) each of which carries a defined meaning (semantics), together with the rules governing when a particular message can be sent.

4 IHA præsentation4 Motivation Linux, ARM11, Protocol implemented in C Example – 4 layered protocol stack Windows CE, Intel, Protocol implemented in C#

5 IHA præsentation5 The problem Q: Why not just specify the data in a C/C++ structure as below”? problem: different data format, storage conventions (endianess) struct { char code; int x; } test; test.x = 256; test.code=‘a’ a 00000001 00000011 a 00000011 00000001 test.code test.x test.code test.x host 1 format host 2 format

6 IHA præsentation6 Solutions 1. Sender learns receiver’s format. Sender translates into receiver’s format. Sender sends. –real-world analogy? –pros and cons? 2. Sender sends. Receiver learns sender’s format. Receiver translate into receiver-local format –real-world-analogy –pros and cons? 3. Sender translates host-independent format. Sends. Receiver translates to receiver-local format. –real-world analogy? –pros and cons?

7 IHA præsentation7 Protocol Specification Goal/Motivation for specifying messages To have a platform-independent Notation To have language-independent Notation Vendor-independent Internationally-standardised

8 IHA præsentation8 Protocol Specification Protocols can be specified in many ways One fundamental distinction is between text-based specifications and binary- based specification. Text-based specification: The "protocol" is defined as a series of lines of ASCII encoded text Binary-based specification: The “protocol” is defined as a string of octets or of bits

9 IHA præsentation9 Abstract Syntax Notation One (ASN.1)

10 IHA præsentation10 Abstract Syntax Notation One (ASN.1) It is an internationally-standardized (ISO standard X.680), vendor- independent, platform-independent and language-independent notation for specifying data-structures at a high level of abstraction It is supported by rules which determine the precise bit-patterns (again platform independent and language-independent) to represent values of these data-structures when they have to be transferred over a computer network, using encodings that are not unnecessarily verbose It is supported by tools available for most platforms and several programming languages that map the ASN.1 notation into data-structure definitions in a computer programming language of choice, and which support the automatic conversion between values of those data-structures in memory and the defined bit-patterns for transfer over a communications line.

11 IHA præsentation11 Abstract Syntax Notation One (ASN.1) The design of some form of data-structure (at about the level of generality of a high-level programming language, and using a defined notation) which is capable of carrying the required semantics. The set of values of this data- structure are called the abstract syntax of the messages or application. We call the notation we use to define this data structure or set of values we the abstract syntax notation for our messages. ASN.1 is just one of many possible abstract syntax notations, but is probably the one most commonly used.

12 IHA præsentation12 Abstract Syntax Notation One (ASN.1) The crafting of a set of rules for encoding messages such that, given any message defined using the abstract syntax notation, the actual bits on the line to carry the semantics of that message are determined by an algorithm specified once and once only (independent of the application). We call such rules encoding rules, and we say that the result of applying them to the set of (abstract syntax) messages for a given application defines a transfer syntax for that application. A transfer syntax is the set of bit-patterns to be used to represent the abstract values in the abstract syntax, with each bit- pattern representing just one abstract value. (In ASN.1, the bit-patterns in a transfer syntax are always a multiple of 8 bits, for easy carriage in a wide range of carrier protocols)

13 IHA præsentation13 Abstract Syntax Notation One (ASN.1)

14 IHA præsentation14 Abstract Syntax Notation One (ASN.1) Machine A (C#) Machine B (C++) ASN.1 Specification Step 1. We need a ASN.1 compiler ASN.1 -> C# + ASN.1 -> C++ Step 2. Agree on encoding rules (BER or PER?) ASN.1 TOOLS ARE AVAILABLE

15 IHA præsentation15 Abstract Syntax Notation One (ASN.1) A top-level type definition, supported by other type and value definitions ASN.1 Specification All possible values of this top-level type Values Abstract values The Abstract Syntax ASN.1 Encoding Rules Apply a specific ASN.1 Encoding Rule Bit pattern Transfer Syntaxes

16 IHA præsentation16 Abstract Syntax Notation One (ASN.1) ASN.1 is for: Representing data types and structures (abstract syntax) Encoding rules (transfer syntax) ASN.1 is not another programming language –No control flow (if-else, while etc.) –No pointers –Bitwise operators Let us look at ASN.1 in more details!

17 IHA præsentation17 ASN.1 - Modules Fundamental unit of ASN.1 Module Sole purpose to name a collection of type definitions and/or value definitions (assignments) The module constitutes a data specification -- ASN1START EUTRA-RRC-Def DEFINITIONS AUTOMATIC TAGS ::= BEGIN …. END --ASN!STOP Type & value definitions (assignments)

18 IHA præsentation18 ASN.1 - Basics How do we define types and assign values to them ? The main concept of ASN.1 is that of type Two main ASN.1 build-in types: Basic types Constructed types

19 IHA præsentation19 ASN.1 – Basic Types Simple TypesTagTypical use BOOLEAN1Logical values TRUE and FALSE NULL5Includes the single value NULL, used for delivery report or some alternatives of the CHOICE type INTEGER2Whole numbers (positive or negative), possibly named REAL9Real numbers represented as floats ENUMERATED10Enumeration of identifiers BIT STRING3Bit strings OCTET STRING4Byte strings OBJECT IDENTIFIERS 6Unambigous identification of an entity registered in a worldwide tree CHARACTER STRING *Allows negotiation of a specific alphabet for character strings

20 IHA præsentation20 ASN.1 – Constructed Types Structured TypesTagTypical use CHOICE*Choice between types SEQUENCE16Ordered structure of values (generally) different types SET17Non-ordered structure of values of (generally) different types SEQUENCE OF16Ordered structure of values of the same type SET OF17Non-ordered structure of values of the same type

21 IHA præsentation21 ASN.1 – Type & Value Assignment All ASN.1 assignments use the symbol ”::=”; so do the type assignment: Married ::= BOOLEAN Cancel ::= BOOLEAN DEFAULT FALSE Age ::= INTEGER ColorType ::= INTEGER { red (0) white (1) blue (2) } Picture ::= BIT STRING Occupation ::= BIT STRING { clerk (1) editor (2) } Positions in string myMarried Married ::= TRUE myAge Age ::= 25 myColor ColorType ::= red myColor ColorType ::= 35 myPicture Picture ::= ’0101011011110’B myWork Occupation ::= { clerk, editor }

22 IHA præsentation22 ASN.1 – Type & Value Assignment Form ::= SEQUENCE { name PrintableString, age Age, married Married } Coordinates ::= SET { x [1] INTEGER, y [2] INTEGER, z [3] INTEGER OPTIONAL } Maybe present f FORM ::= { name ”Peter”, age 25, married TRUE } c Coordinates ::= { z 10, x 5, y 30 } c Coordinates ::= { x 5, y 30 }

23 IHA præsentation23 ASN.1 – Type & Value Assignment RAT-Type ::= ENUMERATED { eutra, utra, geran-cs, geran-ps, cdma2000-1XRTT, spare3, spare2, spare1,...} Afters ::= CHOICE{ cheese IA5String, dessert IA5String } CarType ::= ENUMERATED { audi (0), bmw (1) scoda (2), citroen(3),...} rat RAT-Type ::= geran-cs car CarType ::= audi myAfter Afters ::= dessert ”ice” How can the received decode this? Cheese or dessert string received? SOLUTION: TAGGING

24 IHA præsentation24 ASN.1 – Type Assignment MeasIdToAddModList ::= SEQUENCE OF MeasIdToAddMod MeasIdToAddMod ::= SEQUENCE { measIdMeasId, measObjectId MeasObjectId, reportConfigIdReportConfigId }

25 IHA præsentation25 ASN.1 – Subtyping Allows us to customise our types to just the precise values we need – it can reduce the number of bits-on-the-line and gives clear guidance to implementors for memory allocation decisions Usage: reduce the range of an integer specify a minimum and/or maximum length of a string specify a min and/or max number of iterations in a SEQUENCE OF or SET OF HOW?

26 IHA præsentation26 ASN.1 – Subtyping Reducing the range of an integer: RRC-TransactionIdentifier ::= INTEGER (0..3) Length of a string: My-string ::= PrintableString (SIZE (1..10)) FROM (”A”..”Z”)) restricting the range of the integer field to the values 0 to 3 restict the size of the string between 1 and 10 characters string can only contain the characters ”A” to ”Z”

27 IHA præsentation27 ASN.1 – Subtyping UE-CapabilityRAT-ContainerList ::=SEQUENCE (SIZE (0..2)) OF UE-CapRAT-Container UE-CapRAT-Container ::= SEQUENCE { rat-Type RAT-Type, ueCapabilityRAT-Container OCTET STRING } Number of iterations in a SEQUENCE OF or SET OF: Minimum number of iterations is 0 – maximum is 2

28 IHA præsentation28 ASN.1 – Extensions Versioning ASN.1 Specification Ver.1 Type ::= SEQUENCE { comp1 INTEGER, comp2 BOOLEAN, } ASN.1 Specification Ver.2 Type ::= SEQUENCE { comp1 INTEGER, comp2 BOOLEAN, comp3 REAL } ???

29 IHA præsentation29 ASN.1 – Extensions & Versioning ASN.1 Specification Ver.1 Type ::= SEQUENCE { comp1 INTEGER, comp2 BOOLEAN … } ASN.1 Specification Ver.2 Type ::= SEQUENCE { comp1 INTEGER, comp2 BOOLEAN, [[ comp3 REAL]], … } extension marker (ellipsis) version brackets

30 IHA præsentation30 Abstract Syntax Notation One (ASN.1) ASN.1 Encoding Rules 1. Basic Encoding Rule (BER) 2. Packet Encoding Rules (PER) 3. XML Encoding Rules (XER)

31 IHA præsentation31 ASN.1 – Basic Encoding Rules The BER transfer syntax always has the format of a triplet TLV T L TLTLVTL V Recursive principle

32 IHA præsentation32 ASN.1 – Basic Encoding Rules bit 7bit 6class 0 0UNIVERSAL 01APPLICATION 10context-specific 11PRIVATE Two formats of the Tag Octets (Primitive or Constructed) bit 5form 0Primitive 2Constructed

33 IHA præsentation33 Abstract Syntax Notation One (ASN.1) Example: age INTEGER ::= 5 + UNIVERSAL Primitive + INTEGER

34 IHA præsentation34 ASN.1 – Basic Encoding Rules The length octet represents the length of the value (V) The three formats of the length octets Short definite length Long definite length Indefinite length

35 IHA præsentation35 ASN.1 Basic Encoding Rules Short definite length can be used if V part is less than 127 octets V part can be primitive or constructed type short form is identified by encoding bit 8 as zero 0

36 IHA præsentation36 ASN.1 Basic Encoding Rules Long definite length Bit 8 set to one 1 Following N octets is Length fields

37 IHA præsentation37 ASN.1 – Basic Encoding Rules Short form Options for encoding a length of 5 (1 0 1) Long form Length of length N = 2

38 IHA præsentation38 ASN.1 – Basic Encoding Rules Encoding a BOOLEAN value The values of b1 BOOLEAN ::= TRUE b2 BOOLEAN ::= FALSE are encoded as T L V b1: 01 01 FF b2: 01 01 00 Encoding of the V part of the main types Encoding an INTEGER value The values of i1 INTEGER ::= 72 i2 INTEGER ::= 127 i3 INTEGER ::= 128 are encoded as T L V i1: 02 01 4B i2: 02 01 80 i3: 02 02 0080

39 IHA præsentation39 ASN.1 – Basic Encoding Rules seq SEQUENCE { age INTEGER, single BOOLEAN } ::= {age 24, single TRUE } is encodes as:

40 IHA præsentation40 ASN.1 Tagging Why do we need tagging? All ASN.1 types are assigned a default ”tag” (for the ”T” part of encoding) Sometimes use of the default tag would produce ambiguous encoding, for example: Afters ::= CHOICE { cheese IA5String, dessert IA5String } IA5String in both cases Identification ::= CHOICE { security_no INTEGER, work_no INTEGER }

41 IHA præsentation41 ASN.1 Tagging A tag is a number between square brackets before a type Coordinates ::= SET { x [1] INTEGER, y [2] INTEGER, z [3] INTEGER OPTIONAL } Afters ::= CHOICE { cheese [0] IA5String, dessert [1] IA5String }

42 IHA præsentation42 ASN.1 Tagging When we tag, we can Override the current tag (called IMPLICIT tagging) Add a new tag on the front (called EXPLICIT tagging) giving a ”TL TLV” encoding Sometimes explicit tagging is needed to avoid ambiguity, but implicit tagging is more common

43 IHA præsentation43 ASN.1 Tagging We can add as many new tags as we like t a type! We say that each value of that type (any type) has associated with it a tag-list Usually the tag-list contains only one or two tags, but … there is no limit In almost all cases, every value in a type has the same tag list

44 IHA præsentation44 ASN.1 Tagging [1][0][null] O [1][1][null] O ”basic” value ”product-based” value ”Research-division” type Research-division ::= [1] CHOICE { product-based [0] NULL, basic [1] NULL }

45 IHA præsentation45 ASN.1 Tagging Tag classes UNIVERSAL (not for users) APPLICATION e.g. [APPLICATION 6] PRIVATE e.g. [PRIVATE 3] Context specific e.g. [2]

46 IHA præsentation46 ASN.1 Tagging Tag rules Numbers are non-negative Context specific most common APPLICATION normally used for global types or for top-level messages PRIVATE rarely used UNIVERSAL assigned only by ASN.1

47 IHA præsentation47 ASN.1 Tagging Syntax: tag type definition tag IMPLICIT type definition tag EXPLICIT type definition Examples: SpecialEncoding ::= [PRIVATE 8] EXPLICIT BIT STRING BinaryFile ::= [APPLICATION 3] IMPLICIT OCTET STRING

48 IHA præsentation48 ASN.1 – Packet Encoding Rules (PER) ”Obtain the most compact encoding using encoding rules as simple as possible” 40% - 60% gain compared to BER Appropriate for protocols that need to transfer data at a high rate VoIP Videophone Multimedia HOW?

49 IHA præsentation49 ASN.1 – Packet Encoding Rules Motivation Encoding a BOOLEAN value in BER The values of b1 BOOLEAN ::= TRUE b2 BOOLEAN ::= FALSE are encoded as T L V b1: 01 01 FF b2: 01 01 00 3 octets to send a BOOLEAN ONLY 1 bit needed

50 IHA præsentation50 ASN.1 – Packet Encoding Rules PER-visible constraints Used by PER to produce less verbose encodings Example: INTEGER (0..7) encodes into just three bits because the (0..7) constraint is PER-visible No ”T”, no ”L” => efficient coding Same ASN.1 type definition used, same specification

51 IHA præsentation51 ASN.1 – Developing Applications Stage 1 – Specification development Stage 2 – Syntax check and compile Stage 3 – Writing your Application Stage 4 – Putting your Application to use

52 IHA præsentation52 ASN.1 – Developing Applications Stage 1 – Specification development Decide on types of messages the application will need Draft a new ASN.1 specification or use an existing one When drafting a new, decide on encoding rules To take advantage subtyping constraindts Have extensibility in mind for future requirements

53 IHA præsentation53 ASN.1 – Developing Applications Stage 2 – Syntax check & compile Use an available ASN.1 Compile Compile to your preferred target language C,C++, C#, Java, Cobol, Pascal… ASN.1 compiler produces data structures and related code for inclusion into the Application

54 IHA præsentation54 ASN.1 – Developing Applications Stage 3 – Write your Application Use the compiled structures in your code Use the vendor (tool) provided runtime library functions/methods like eg. oosEncode() and ossDecode()

55 IHA præsentation55 ASN.1 – Developing Applications Stage 4 – Putting your Application to use Test it and use it FINISHED – Questions?


Download ppt "IHA præsentation1 Outline for today Standard Formal Notations for data structures and messages Motivation Abstract Syntax Notation One (ASN.1)"

Similar presentations


Ads by Google