Brrr....Its Hot : -
The compilation rules for converting data-types into bits and bytes is called the transfer syntax.Basic Encoding Rules or BER is the transfer syntax for SNMP and LDAP. BER and ASN.1 were designed by the same people (not network administrators alone) and hence go hand in hand. This fact makes life simpler on this planet. But how does BER manage to do all this, after all it has to take case of so many data-types, and it is used to write hundreds of protocols. It is indeed mind boggling. To know more about BER lets get cracking Fortunately we will only discuss BER in the context of ASN.1 implementation of SNMP and LDAP.
BER uses the concept of an 'identifier'. An identifier is a unique code assigned to every data-type. This identifier acts as the calling code for that data-type. We distinguish between two data-types using these identifiers. The data-types are further classified into groups. But before we proceed any further answer this simple question. Are the books in your college or school library piled one over the other with no semblance of order? The answer is a definite NO. (Those answering yes will have to get a new librarian). The books out there are classified into various groups according to a pre-defined order like subject, ISBN number etc. The designers of BER being an inspired lot, did the same thing. They classified the BER identifiers into 4 classes.
Lets look at the structure of a BER identifier
Bit No. | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | Implication |
0 | 0 | Universal | |||||||
0 | 1 | Application | |||||||
1 | 0 | Context | |||||||
1 | 1 | Private | |||||||
  | 0 | Primitive Data-type | |||||||
  | 1 | Non Primitive Data-type - Constructed |
The eighth and the seventh bits combine to denote the class of the BER identifier. The implications of these bits have been summarized in the table shown above. The sixth bit of the identifier indicates whether the represented data-type is a primitive or constructed one. The remaining bits of the identifier represent a numeric tag associated with a data-type. Some of the data-types and the numeric tag associated with them are as shown below.
Decimal | Hexa-decimal | |
02 | 0 0010 | INTEGER |
04 | 0 0100 | OCTET String |
16 | 1 0000 | SEQUENCE |
It makes a very interesting observation that when we are representing the length of a structure, integer etc. the byte following the structure tag, or the 'keyword' integer is used to indicate the length of the corresponding data type. Does this mean that the maximum length that can be indicated in BER related 'languages' is 255 bytes long. Wrong!, BER is far too advanced to be held back by such a drawback. In a situation where the length of the datatype exceeds one byte, the byte succeeding the data-type declaration has '1' in the 8th field followed by the length of the succeeding bytes which are used to represent the datatype. For example to indicate a length of an structure which is '0xabcd' bytes (43981) large we will use the following representation
0x30 | structure tag |
0x82 | length of structure is spread over two byte |
0xab | the actual length |
0xcd |
Thus we assign a unique numeric tag to each of the countless data-types possible. These data-types along with their class names and their type name uniquely identifies the variable in the protocol. These rules are adopted across the board irrespective of the protocol in which they are used. We believe that this much background information is sufficient for knowing the basics of BER. So it's time we took a peek at how the BER is used in the various protocols
Click here for BER implementation for SNMP
Click here for BER implementation for LDAP
Mr. Vijay Mukhi
Ms. Sonal Kotecha
Mr. Arsalan Zaidi
Mr. Vinesh Kurup
Vijay Mukhi's Computer
Institute
VMCI, B-13, Everest Building, Tardeo, Mumbai 400 034, India
Tel : 91-22-496 4335 /6/7/8/9
Fax : 91-22-307 28 59
e-mail : vmukhi@giasbm01.vsnl.net.in
http://www.vijaymukhi.com