分类:
2010-03-05 00:09:00
Introduction to the subset of ASN.1 required for MMS.
6.1 Problem Definition
For the encoding of messages to be exchanged the red pencil tactics are too often used, in the opinion: The shorter the message, the better. See also the Y2K problem that has mainly been caused by this red pencil tactic: save bits. We want to counter this common opinion with a short story, before we deal with the question of coding generally and in connection with MMS.
Salcia Landmann writes in the book "The Jewish joke":
"A young father proudly telegraphs to the parents of his wife: "Rebekka happy given birth son". This scarce but quite informative text is written in the typical telegram style. One certainly cannot reproach this text for language abundance. Nevertheless the father-in-law takes the sender of the telegram to task and bombards him with the following reproaches: "How can one be so reckless and throw his money down the drain for superfluous words in a telegram! Look for yourself: You write "Rebekka" - who else? Would you actually telegraph if a completely strange woman is going to have babies? And then "happy" - Since when does one telegraph if a birth does not go well? And now even "given birth" - what else? Were you afraid I might believe, the stork had brought the child? And finally "son" - with daughters the joy is never so great that one would run to the telegraph office. Therefore, we would have guessed this certainly!"
The teaching of this story is that with adequate knowledge of the context an empty message (an implicit information) suffices to convey a complete message to the receiver. However, our language generally lives on even superfluous statements or redundancies. These have the feature that they often help to recognize and to correct errors. This is valid also in the area of communication between technical systems.
If the communication between technical systems is predominantly defined by implicit suppositions, then it is frequently difficult for receivers (these can be applications like diagnostic tools) to recognize errors in the structure and in the contents. At the beginning of our considerations, a technical example is helpful to understand the difficulties.
Technical example
Let's assume two Integer16 (= four octets) were transmitted by a device till now. Only the four octets were transmitted without any further identifications (transparent transmission of the values). Because from now on four data shall be transmitted and because for all four only values smaller than 100 decimal need to be transmitted, it makes sense to divide the four octets up into four Integer8. Regarding the transmission on the line, nothing changes - four octets will continue to be transmitted. However, the receiver must know that the structure of the data has changed. It must be informed that the four octets are to be interpreted as four data of one octet each.
The information that the structure has been changed can be communicated to him via local configuration. At least, this is always necessary for the application because it receives now four instead of two values. These four values must be integrated into the application.
Since such changes of the configuration must possibly be carried out in many devices under various responsibility, it must generally be assumed that at the time of the re-configuration the modification still was not carried out in some places. In this case unnoticed errors will occur in these places which cannot be recognized by the communication either.
If, however, the data types for the values were enclosed during the communication, the receiving side could immediately see the missing agreement of the types: The receiver has expected two integers till now, and suddenly it receives four integers. This error could immediately be recognized and dealt with on the receiving side.
This example clarifies that in addition to the user data further information is important and helps to figure out changes in the data structure. The additional information is necessary, primarily then, if the data to be transmitted vary in their length from transmission to transmission. If of ten values one can be missing, then it must be possible to indicate this.
The opinion - sometimes still to be found today - that modern encoding rules are too complicated and consume too many resources is often caused by the missing understanding of these rules. Current implementations show that these encoding rules are - with regard to performance and real-time ability - much less problematic than generally assumed. In most cases, the communication is by far quicker than the programs of the connected applications. In the following, the most essential features and capabilities of ASN.1 (the commonly used syntax notation) are introduced and discussed with a real example.
MMS defines an external interface (line interface) or the externally visible behavior, the (abstract but also actual) coding as well as sequences and meanings of the interchanged requests and their answers. Client and server can be connected - via a communication network - locally (just some meters from each other) but also over a distance of thousands of kilometers.
As shown in figure 26, the information to be exchanged (in MMS this information is called PDU - Protocol Data Units) must be agreed upon between transmitter and receiver. These agreements are for example:
Figure 26: Requirement for formal syntax (principle)
Figure 27: Levels of encoding
SEQUENCE OF Integer8
Possibility 1:
Description of equal values only in one place:
Number of equal elements (= 3)
+ Type of every element (= integer)
+ length of every element (= 1 octet)
+ value of the 1st element (= 1 octet)
+ value of the 2nd element (= 1 octet)
+ value of the 3rd element (= 1 octet)
Possibility 2:
Description of every value independently of the others:
Type of the 1st element (= integer)
+ length of the 1st element (= 1 octet)
+ value of the 1st element (= 1 octet)
Type of the 2nd element (= integer)
+ length of the 2nd element (= 1 octet)
+ value of the 2nd element (= 1 octet)
Type of the 3rd element (= integer)
+ length of the 3rd element (= 1 octet)
+ value of the 3rd element (= 1 octet)
Assuming that every line corresponds to one octet, six octets are transmitted in the first case and nine octets in the second case for the same information. The substantial difference consists in the structure of the description and in the overhead for the interpretation of both messages. In the first case, having interpreted the first three lines, a loop can run through the following values. In the second case, for every value, first the type must be interpreted, then the length and then the value.
The first possibility is obviously much more efficient than the second one - primarily for many equal values. In the case that the values are of various types and lengths, the second method (3 lines per value) is more efficient than the first one (4 lines per value, if all values are different from each other).
This example makes clear that the optimal encoding rule does not exist. What may be optimal for one case, is less efficient for another case. Since MMS supports flexible structures in services and has an extensive data modeling language (variable model), a flexible encoding rule is also necessary - and this is ASN.1. The communication and the description of the application data (data model) converge in this place. Thus, ASN.1 is more than a rule for the encoding during the transmission over the line.
MMS uses a small subset of the ASN.1 description language and of the affiliated BER encoding rules. The following explanations are sufficient to understand in principle the data modeling and the encoding rules. The syntax of the MMS definitions can thus be understood. The latest version of ASN.1 offers a complete object-oriented description method which is also used in the MMS revision (international standard of the MMS revision will be published in 2000).
6.2 Basic principles of the abstract syntax description (ASN.1)?
The applications are generally implemented by means of a specific programming language (see figure 28). The language ASN.1 can be used both for the definition of the services and for the modeling of the application data. The variable model defines the structure discussed above in the form of e. g. Named Variables or Named Variable Lists, Type Descriptions (paths or subpaths) etc. The "bits on the line" are defined by ASN.1 BER.
An excellent ASN.1 Book is available for free download at:
Figure 28: Use of ASN.1 in MMS
At first the encoding of messages is discussed.
6.2.1 ASN.1 for the description of the MMS Messages
The ASN.1 basic elements, represented in figure 29, are important for the description of the MMS Message syntax. Most MMS definitions can be described by these four "LEGO bricks" of the description language. The examples in figure 29 merely provide the fundamental understanding of ASN.1.
CHOICE: The first element is the CHOICE. If from a given number of possibilities one shall be selected, then this is indicated by the keyword "CHOICE" preceding the curly brakkets. The possibilities are listed in the curved bracket. The square brackets [x] contain a serial number which starts with 0 and which needs to be unambiguous only within the square brackets. Thus, many of such branches can be defined quite simply – only the possibilities need to be written down and provided with a number respectively.
SEQUENCE OF: Simple and complex expressions which are in the curved bracket can be repeated arbitrarily often or strung together by using SEQUENCE OF. If there is more than one expression within the curved bracket, then these expressions must also be put in brackets. This is done using the simple SEQUENCE expression.
SEQUENCE: If several simple or complex expressions are listed, then these must be marked by the keyword SEQUENCE and a curved bracket around the expressions.
OPTIONAL: If an element can alternatively be inserted or left out, then this is indicated by the keyword OPTIONAL. In the sequence it is mandatory for the tags [0] and [1] to be included in a received message with this syntax; otherwise the message will be rejected and an error be sent to the transmitter. If the second tag is marked by OPTIONAL, then the element may be missing.
DEFAULT: Another keyword (not represented in the figure) is DEFAULT. It indicates to the transmitter which value is registered in the message, if the application doesn't specify any other value.
Recursion: A recursive structure results whenever the beginning of the definition is referred to within a definition. As example, refer to the MMS specification in figure 10.20 where the type specification was used within the arrays and structures. Of course, the definition of a path must end some time at a simple type (the leaves). There isn't any specific keyword for recursive structures.
Figure 29: Basic elements of ASN.1 used in MMS
These recursive structures and the referencing of definitions, which are defined somewhere else in the MMS specification, allow very compact definitions. This compact representation aggravates the readability, though. Because we cannot imagine nested structures so easily, some that tried to understand the MMS syntax believe it were to complicated. The reading of the following pages will certainly make clear that the system is not complicated but complex, at the most. What we cannot (easily) imagine isn't necessarily complicated.
The structures defined with these modules form, if represented graphically, complex syntax trees. A Hypertext database with the complete MMS syntax can give further insight. It is found at the following address:
ASN.1 defines further keywords such as the basic data types integer, octet string etc.
6.2.2 Extract from the MMS syntax tree
Some extracts from the MMS syntax (ISO 9506-2) are shown and discussed in the following analysis. The structure shown in figure 30 defines some MMS PDU, namely those which know both a request and an answer (Confirmed Service Request) - there are also Unconfirmed Service Requests, for example Information Report. It has to be taken into account here that this branch (Confirmed Service Request) is not at the beginning of the complete MMS syntax tree - the beginning is not represented.
MMS defines about 70 different Confirmed Services, of which the first eight are listed in figure 30.
Figure 30: Excerpt of MMS syntax tree
The service write (write request) - in yellow shade - is analyzed a little more precisely. The corresponding tag is [5]. The keyword IMPLICIT is irrelevant for the comprehension of the parameters of the write request. The expression write (written in small letters!) is replaced by the expression Write Request (written in capital letters). Now we must search for the definition of Write Request and replace the expression. This replacing must be continued till the "end" of the definitions is reached, i.e. till no expressions need to be replaced any more. We will have arrived then at a so-called terminal expression.
Figure 31 shows the further syntax. The Write Request gets replaced by a SEQUENCE of two elements (Variable Access Specification and List of Data). It is plausible that the variable and the affiliated data must be specified. We don't want to discuss the SEQUENCE OF of data any longer here.
Figure 31: Write syntax
The Variable Access Specification is replaced by a CHOICE with the two possibilities List of Variable and Variable List Name. If data are written to a Named Variable List, then the name is directly specified here (Variable List Name). Thus, just the Object Name still needs to be replaced.
If something shall be written to a Named Variable, then the possibility List of Variable will be selected. Since we want to disregard the Alternate Access here (is OPTIONAL anyway), the List of Variable will be replaced by repeating the variable specification. Here, we merely want to discuss the variant Name which is replaced by the Object Name. If writing to a Named Variable List Object, only the name (Object Name) needs to be specified.
After having discussed the Write Request syntax, we can - for the case "write of an individual variable" - reduce the syntax to three elements: Write Request, Variable Name and value (see figure 32).
Figure 32: Write syntax expanded for one example
If the Write Service merely included the write of a single variable with Object Name, the definition would be correspondingly simple. Then most elements from the Write Request syntax tree would not need to be part of the definition. Due to the high flexibility (one or several variables, with/without Alternate Access etc.), an extensive syntax tree results which, however, for simple applications also gets simple (such as the writing of just one variable). Minimal additional expenses are necessary for coding to be able to distinguish the individual possibilities - a receiver must be able to recognize for example whether only one name and one value instead of several names/values were received.
The MMS syntax has the feature that it offers a compact representation for a variety of possibilities. Only when expanding the syntax (i.e. replacing the expressions as carried out above) the variety will be recognized. This variety cannot be represented easily and therefore is not easily comprehensible. Actually, this syntax is intended for the automatic check of the completeness and consistency (on both sides - sender and receiver) as well as for the implementation of MMS syntax generators and interpreters.
The support which is offered in this place is rather intended for experts who want to get occupied with MMS in detail. For the understanding of the MMS functionality this knowledge isn't required. The MMS service description (ISO/IEC 9506 part 1) contains the description of the functionality without ASN.1. However, it has turned out to be favorable to read the syntax because it is much more compact and precise than a verbal description.
6.2.3 The basis of the ASN.1 Basic Encoding Rules (BER, ISO 8825)
For the further analysis of the MMS messages, the most important details for the actual coding are introduced now. Since ASN.1 - BER included - contains many more definitions than used by MMS, only the features most important for MMS shall be discussed here. With the definition of the MMS syntax for Address (attribute of a Named or Unnamed Variable), shown in figure 33, the individual steps are explained - down to the actual bit coding.
At first, the definition of the OCTET STRING is considered isolated (without tag [2] and without IMPLICIT). This definition is written with capital characters indicating an ASN.1 keyword. The definition OCTET STRING can be found in ASN.1 (ISO 8824).
ASN.1 has, among other things, the following keywords with a tag of their own relevant to MMS:
UNIVERSAL
16
UNIVERSAL 2
UNIVERSAL 3
UNIVERSAL
4
...
...
Boolean
type
Integer type
Bitstring type
Octetstring type
Sequence
and Sequence-of
types
The keyword IMPLICIT which is explained below and the keywords OPTIONAL as well as DEFAULT have no tag of their own. These tags will merely be needed for encoding/decoding. All definitions in MMS which aren't replaced in the MMS syntax are written in capital characters. The definition OCTET STRING in MMS is identical to the definition UNIVERSAL 4 octet string in ASN.1. The keyword UNIVERSAL 4 marks this element as an ASN.1 Univeral Class. Universal means that for example octet strings are defined here - and thus only once - for all applications that use ASN.1. The value 4 specifies the selection.
Figure 33: Abstract encoding of the MMS Address
For the actual coding we consider a given value of the octet string in hexadecimal format (figure 34). The three elements: Type (= OCTET STRING), Length (= 5 Octets) and Content (= 24 65 4F EF F3 hex) are necessary for the interpretation on the receiving side. The ASN.1 BER code all three elements; however, the keyword IMPLICIT also offers optimizations which allow an optimized encoding.
Figure 34: T-L-C Definition used in ASN.1-BER
The type integer offers further optimization. Even if the TypeDescription of a variable contains an integer, for example of length 64 bits (Integer64), only the actual length will be transmitted. If the value is smaller than 256, then only one instead of eight octets will be transmitted.
Figure 35 shows the actual coding according to ASN.1-BER. The values for all three elements can be seen in the upper row: 04 hex, 05 hex and 24 65 4F EF F3 hex. The definition of the three elements is below. The eight bits of the type are subdivided in three groups. The first two bits define the class which specifies the scope. All tags defined in ASN.1 are defined as Universal Class. The tags defined in MMS have context-specific Class.
The second group (one bit) describes, whether or not the Content is structured further - with ASN.1 BER. If the Content is structured, then this element in turn contains three elements (T-L-C); the contents of the second Content can also be constructed again etc. This algorithm allows arbitrary nestings. If it is a primitive representation, then only one Length and one Content field follow. The third group (5 bits) defines the number of the tag. The tag can also be longer than 5 bits; this case isn't considered here because it doesn't occur in MMS.
Figure 35: Concrete encoding in ASN.1-BER
Figure 36: Bits on the wire in hexadecimal representation
So far, the consideration has viewed the octet string as isolated. Yet very often it is clear in a given context, that the encoded data is of type octet string. Then, the explicit coding of the octet string - as octet string - is not necessary. To this we consider the example in figure 37.
Figure 37: OCTET STRING in a context
Figure 38: OCTET STRING encoding in a context
Figure 39: Bits on the wire when encoded in the context
Without the implicit coding, both the tag [2] (Unconstrained Address) and the OCTET STRING must be coded explicitly. This coding would - as shown in figure 40 - add two octets and increase the length to nine octets. For this case, the bits on the line are shown in figure 41.
Figure 40: Explicit encoding of an OCTET STRING
Figure 41: Bits on the wire with explicit encoding
Read-Request
::= SEQUENCE?{
SpecificationWithResult
variableAccessSpecification
[0] IMPLICIT
BOOLEAN DEFAULT FALSE,
[1] VariableAccessSpecification }
The three variables not specified here in detail with the names "feeder205load", "feeder206load", and "feeder-207load" shall be read. The coding of the affiliated Read-Message is as follows:
MMSpdu ::=
CHOICE {
A0
42
02 01 04
A4 3D
A1 3B
A0 39
30 11
A0 0F
80 0D 66
65 65 64 65 72 32
30 35 6C 6F 61 64
30 11
A0 0F
80 0D 66 65 65 64 65
72 32
30 36 6C 6F 61 64
30 11
A0 0F
80 0D 66 65 65 64 65 72 32
30
37 6C 6F 61 64? }
}}}
confirmed-RequestPDU [0]
IMPLICIT SEQUENCE {
invokeID,
read [4]
SEQUENCE {
varaibleAccessSpecification [1],
listOfVariable [0]
IMPLICIT
SEQUENCE OF
SEQUENCE {
name [0],
vmd-specific
[0]
"feeder205load",
name [0]
vmd-specific
[0]
"feeder206load",
name [0]
vmd-specific
[0]
"feeder207load"
The bit patterns which result from the coding with BER are listed in the left column. An abstract representation of the Message (Read) is shown on the right. In this application case (read of three variables feeder205load", "feeder206load", and "feeder-207load"), the MMS PDU (Protocol Data Unit) is a sequence of Invoke ID and Read. Because several requests can be on the line simultaneously, they must be distinguished by the Invoke ID. Read contains the list of the three variables (List of Variable) which shall be read. The three names are listed with their scope here.
The bit patterns on the left side will be transmitted as MMS Message. The octets on the very left express something about the type of the transmitted information. The "A0" in the first line says that it is a MMS definition (A = 1010 hex for the first four bits of the ASN.1 types - context-specific and constructed). The "0" is the tag that contains the number in square brackets on the right. The tags distinguish different definitions.
The second column of octets is the length indication. The "42hex" indicates that 66 octets follow. This length indication allows also a syntactic check when receiving the messages because all of the length indications must agree with the actual lengths of the received octets.
6.3 Use of ASN.1 for object modeling
Figure 42: Example of a Message according to IEC 870-5-103
NAMED-TYPE ::= { | |
name vmd
Specific [0] "ASDU",
type Description structure [2] { components?[1] { component
Name |
[0] "Type Identification", [1] type-ident}, [0] "Cause of Transmission", [1] cot}, [0] "Function Type", [1] fct-Type}, [0] "information Number", [1] info-Number}, [0] "Information Element", [1] dpi}, [0] "Time Stamp", [1] four-Octet-Binary-Time}}}} |
dpi NAMED-TYPE ::= { | ||
name vmdSpecific [0] "DPI",
typeDescription integer [5] { | ||
off on not-used |
(1), (2), (3) }} |
Figure 43: InformationReport from a Named Variable
The fact that the six components (List of Access Result with Type Identification, Cause of Transmission and Time Stamp) aren't coded explicitly but implicitly as Octet String results in a further simplification. This would also correspond to the method of the standard IEC 60870-5-103. Thereby, the Information Report of an Unnamed Variable, as shown in figure 44, is reduced to 22 octets. Of course, the MMS services have remained unchanged in all examples.
Figure 44: InformationReport without explicit structures
As the examples above show, the application of the MMS variables, of the ASN.1 description language and of the ASN.1-BER results in a negligible additional need for transmission capacity for the coded data. An additional need by factor two is negligible in regard of the available transmission capacities and the expected higher transmission capacities. This is especially true if one considers that the available transmission bandwidths are generally made use of only to a small extent.
When discussing efficiency, it has to be taken into account also that polling mechanisms, as they are mostly used with solutions according to IEC 60870-5, have a much higher consumption of transmission capacity, because a master permanently polls slaves even if there aren't data. In systems in which data are transmitted only when there are current data, the transmission bandwidth can be considerably smaller than with the shortest coding - even when applying MMS.
Therefore, coding is only one of many influences on the efficiency of communication systems.
Objects according to IEC 870-6 TASE.2 mapped to MMS
The following Named Type Object defines a structure of 12 different components which have a definite meaning in TASE.2 (IEC 61870-6-503, Services and Protocol). A variable of that type can be used to describe an event or time controlled transmission of data from a server to a client. An extensive functionality, which is defined in TASE.2, is hidden "behind" this MMS variable (for further details see article about TASE.2 earlier in this report).
This Named Type Object "DS Transfer Set" (Data Set Transfer Set) is an object of TASE.2. It represents a SCADA (communication) functionality - not application data in the literal sense.
Key
Attribute: Type Name = "DS Transfer Set"
Attribute: MMS Deletable =
FALSE
Attribute: Type Description = STRUCTURE {
{component
Name
component Type
{component Name
component Type
{component
Name
component Type
{component Name
component Type
{component
Name
component Type
{component Name
component Type
{component
Name
component Type
{component Name
component Type
{component
Name
component Type
{component Name
component Type
{component
Name
component Type
{component Name
component Type"Data Set
Name"
MMS
Object Name},
"Start Time"
GMT Based S},
"Interval"
Time Interval
S},
"TLE"
Time Interval S,
"Buffer Time"
Time Interval
S},
"Integrity Check"
Time Interval S},
"DS Conditions Requested"
DS
Conditions},
"Block Data"
Boolean {TRUE (non-zero), FALSE
(0)}},
"Critical"
Boolean {TRUE (non-zero), FALSE
(0)}},
"RBE"
Boolean {TRUE (non-zero), FALSE (0)}},
"Status"
Boolean
{ENABLED(1), DISABLED(0)}},
"Event Code
Requested"
Integer16}
For example, the seventh Component Type (= DS Conditions) is represented below without further explanation:
Attribute: MMS Deletable =
FALSE Attribute:
Type Description = BITSTRING{
Key
Attribute: Type Name = "DS Conditions"
"Interval
Time Out"
"Integrity Time Out"
"Object Change"
"Operator
Request"
"Other External Event"bit position
0
bit position 1
bit position 2
bit position 3
bit position
4}