Editing SNMP MIB Implementation
Jump to navigation
Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 4: | Line 4: | ||
# Create a ASN.1 MIB script '''foo.mib''' (an ASCII text file) for the tree structure. | # Create a ASN.1 MIB script '''foo.mib''' (an ASCII text file) for the tree structure. | ||
# Convert foo.mib to binary file using '''mib2bin''' | # Convert foo.mib to binary file using '''mib2bin''' | ||
− | # Build [http://www.rane.com/note161.html | + | # Build [http://www.rane.com/note161.html snmp's PDU use BER (Base encoding rules)] encoder and decoder library to process data that's transfer between NMS and agents. |
− | # Build | + | # Build snmp API use [http://www.sics.se/~adam/uip/index.php/Main_Page uIP-stack] to communicate between NMS and Agents (open two ports: The manager speak to agents on one port, the agent responds manager on the other port). |
# Build binary MIB file reader library. | # Build binary MIB file reader library. | ||
# Build functions service oid tree. | # Build functions service oid tree. | ||
Line 14: | Line 14: | ||
* Build MIB file's written in [http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ANS.1 notation]. | * Build MIB file's written in [http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf ANS.1 notation]. | ||
* Tutorial: [http://www.scribd.com/doc/276412/Understanding-SNMP-Stack Understanding SNMP Stack] to create ASN.1 MIB Script. | * Tutorial: [http://www.scribd.com/doc/276412/Understanding-SNMP-Stack Understanding SNMP Stack] to create ASN.1 MIB Script. | ||
− | * Tools to create ASN.1 MIB Script | + | * Tools to create ASN.1 MIB Script: |
− | ** [http://www.asnlab.com/asndt/installing.html ASN.1 Editor plugin for Eclipse] | + | ** [http://www.asnlab.com/asndt/installing.html ASN.1 Editor plugin for Eclipse]. |
** [http://packages.ubuntu.com/karmic/asn1-mode Emacs mode for editing ASN.1 files]. | ** [http://packages.ubuntu.com/karmic/asn1-mode Emacs mode for editing ASN.1 files]. | ||
Line 24: | Line 24: | ||
==Convert MIB to Binary File== | ==Convert MIB to Binary File== | ||
− | * mib2bin tool is modified from [http://net-snmp.sourceforge.net/ net-snmp] to convert ASN.1 format file to | + | * mib2bin tool is modified from [http://net-snmp.sourceforge.net/ net-snmp] to convert ASN.1 format file to three files, because the microchip '''mib2bib''' converter only supports upto 255 OIDs. |
MIB compiler tools: '''mib2bin''' | MIB compiler tools: '''mib2bin''' | ||
− | [http://www.modtronix.com/products/sbc44ec/00870a.pdf foo.mib] (ANS.1 format) -----------------------------------> foo | + | [http://www.modtronix.com/products/sbc44ec/00870a.pdf foo.mib] (ANS.1 format) -----------------------------------> foo.bin + foo.h + foo_data.h |
* Syntax to use mib2bin tool: | * Syntax to use mib2bin tool: | ||
'''mib2bin <MIBfile>... | '''mib2bin <MIBfile>... | ||
* where MIBfile file is ASN.1 format file. MIBfile = <name>.<type> | * where MIBfile file is ASN.1 format file. MIBfile = <name>.<type> | ||
− | ** '''<name>.bin''' is the binary file storing information of OID tree. This file can be placed on an SD media card to be read by the | + | ** '''<name>.bin''' is the binary file storing information of OID tree. This file can be placed on an SD media card to be read by the FAT16 file system. |
− | |||
** '''<name>_data.h''' is C header file storing information of OID tree. This file is generated by converting mchip.bin file to the C header file. It's only used when a system don't have system file and place on program memory. | ** '''<name>_data.h''' is C header file storing information of OID tree. This file is generated by converting mchip.bin file to the C header file. It's only used when a system don't have system file and place on program memory. | ||
** '''<name>.h''' is C header file storing ID that's reference to function service of OID. | ** '''<name>.h''' is C header file storing ID that's reference to function service of OID. | ||
* Note: | * Note: | ||
** Subfolder '''mibs''' containing the basics MIB files (e.g.: RFC1155-SMI, RFC1213-MIB, RFC-1215, SNMPv2-MIB ... for us MIB file), must be present under the directory of execution. | ** Subfolder '''mibs''' containing the basics MIB files (e.g.: RFC1155-SMI, RFC1213-MIB, RFC-1215, SNMPv2-MIB ... for us MIB file), must be present under the directory of execution. | ||
− | ** If the | + | ** If the three files exist, mib2bin tool will overwrite the files. |
− | ===Binary File Format | + | ===Binary File Format=== |
* The binary file is an image of MIB file. It is generated by mib2bin tool. Agents will read binary file to respond NMS request. | * The binary file is an image of MIB file. It is generated by mib2bin tool. Agents will read binary file to respond NMS request. | ||
− | * In the binary file, A parent is stored first, followed by its | + | * In the binary file, A parent is stored first, followed by its last-child to first-child. Next, the structure of next this parent is stored. This structure is repeated until the entire tree is stored. |
* A parent or child is a record. Single record of binary file have format: | * A parent or child is a record. Single record of binary file have format: | ||
<oid>, <nodeInfo>, | <oid>, <nodeInfo>, | ||
− | [id], [siblingOffset] | + | [id], [siblingOffset], [distantSiblingOffset], [dataType], [dataLen], [data], |
− | [{<IndexNumber>}, {<IndexCount>, <IndexNodeInfo>, <IndexDataType>} ...] | + | [{<IndexNumber>},{<IndexCount>, <IndexNodeInfo>, <IndexDataType>} ...] |
− | + | ||
− | + | where: | |
− | + | fields indicated by angle brackets (< >) are always present | |
− | + | fields in square brackets ([ ]) are optional depending on characteristics of the current node. | |
+ | fields in braces ({}) are optional but always occur together. | ||
====<oid> field==== | ====<oid> field==== | ||
− | |||
* Format of OID: | * Format of OID: | ||
− | + | oid1 char(16) | |
− | + | oid2 char(16) | |
− | + | .... | |
− | + | * if oid_i < 254: oid_i = char (oid_i) | |
− | + | * else oid_i = char(255) + char(length of oid_i base 255) + oid_i (base 255) + char(16) | |
− | + | * where | |
+ | ** char(x) that's mean get ascii of x. | ||
+ | ** char(16) is used to separate two oids. | ||
+ | ** char(255) is determined that oid geater than 254. | ||
+ | ** "length of oid_i" is length string of oid_i that's converted base 255. | ||
+ | * The microchip format only supports OIDs upto 254. The above is an workaround to store OID greater than 254 | ||
* Example: | * Example: | ||
− | The OID | + | The OID for a node is '''.4.1.17095.''' After compiling to binary, the OID is represented as: |
− | 4 | + | The OID: <font color=blue>4</font> . <font color=blue>1</font> . <font color=blue>17095</font> . |
− | + | The result: <font color=blue>0x04</font> 0x10 <font color=blue>0x10</font> 0x10 <font color=green>0xFF</font> <font color=red>0x02</font> <font color=blue>0x0A 0x43</font> 0x10 | |
− | + | where: | |
− | + | <font color=blue>oid_1 = 4 </font> => <font color=blue> char(oid_1) = 0x04</font> | |
+ | <font color=blue>oid_2 = 2 </font> => <font color=blue> char(oid_2) = 0x01</font> | ||
+ | |||
+ | <font color=red>0x04 is not the ASCII of 4. The ASCII of 4 should be 0x34. I think you are saying the hexadecimal representation of 4. In such case, I think you can use HEX(.) instead of char(.)</font> | ||
+ | |||
+ | <font color=blue>oid_3 = 17095 </font> => <font color=green>char(255) = 0xFF</font> <font color=red>char(length of oid_3 base 255) = 0x02</font> <font color=blue> char(oid_3) = 0x0A43 (In little-endian format)</font> | ||
+ | char(16) = 0x10 | ||
+ | |||
+ | <font color=red>So, "length of oid_3 base 255" means the number of bytes representing oid_3? How can you calculate 0x0A43 from 17095? I still don't quite understand the meaning of "oid_i (base 255)"</font> | ||
+ | |||
+ | Note: When a node have no sibling and only has one child, the node's OID will be merged with its child's OID (reduce data's stored). | ||
+ | <font color=red>How can it be combined? Any example?</font> | ||
====<nodeInfo> field==== | ====<nodeInfo> field==== | ||
* information of node | * information of node | ||
bit when (set = 1) | bit when (set = 1) | ||
− | 0 Node | + | 0 Node is a parent (0: node is a leaf) |
− | 1 Node | + | 1 Node is sequence |
− | 2 Node is | + | 2 Node is readable |
− | 3 Node is | + | 3 Node is writable |
− | 4 Node is | + | 4 Node is able to create |
− | 5 Node | + | 5 Node has default data |
− | 6 | + | 6 (if node is sequence, this is mean implied index node) |
− | 7 | + | 7 always set 1 |
====[id] field==== | ====[id] field==== | ||
Line 94: | Line 109: | ||
distantSiblingOffset use with node. | distantSiblingOffset use with node. | ||
so it's same value. | so it's same value. | ||
+ | * <font color=red>So, can siblingOffset and distantSiblingOffset be combined to 1 field?</font> | ||
− | ====[dataType] | + | ====[dataType], [dataLen], [data] fields==== |
− | *If this record is a leaf | + | * If this record is a leaf and has default data |
** [dataType] is type of leaf's data. | ** [dataType] is type of leaf's data. | ||
− | * The tool supports the following | + | ** [dataLen] is length of data. |
+ | ** [data] is data on string. | ||
+ | * The tool supports the following data types: | ||
** '''INTEGER''': The integer data type is a signed integer in the range of -2,147,483,648 to 2,147,483,647. | ** '''INTEGER''': The integer data type is a signed integer in the range of -2,147,483,648 to 2,147,483,647. | ||
** '''OCTETSTRING''': Octet strings are ordered sequences of 0 to 65,535 octets. | ** '''OCTETSTRING''': Octet strings are ordered sequences of 0 to 65,535 octets. | ||
Line 109: | Line 127: | ||
** '''Opaque''': An arbitrary encoding that is used to pass arbitrary information strings that do not conform to the strict data typing used by the mib. | ** '''Opaque''': An arbitrary encoding that is used to pass arbitrary information strings that do not conform to the strict data typing used by the mib. | ||
** '''SEQUENCE''': An ordered list of objects, somewhat like a struct in the C language. Type of objects in sequence is same type of node. | ** '''SEQUENCE''': An ordered list of objects, somewhat like a struct in the C language. Type of objects in sequence is same type of node. | ||
+ | * <font color=red>Can you describe more about each datatype? For example, What is gauge? What kind of values it will take? Is this a complete list defined in SNMP protocol?</font> | ||
+ | The data types are described above. | ||
+ | This is the list base data types defined in SNMPv1. | ||
− | ====[ | + | ====[{<IndexNumber>}]==== |
− | * If this record is | + | * If this record is sequence (an order list of objects), index_number is number of INDEXes in sequence. |
− | + | ** [{<IndexCount>, <IndexNodeInfo>, <IndexDataType>}] | |
− | ** | + | * If this record is sequence |
− | + | ** <IndexCount>: is index of INDEX in table | |
− | + | ** <IndexNodeInfo>: is info of index_node | |
− | * If this record is sequence | + | ** <IndexDataType>: is data type of index_node |
− | + | * <font color=red>Can you give an example?</font> | |
− | ** <IndexCount>: is | + | The example, mchip.txt file has '''trap''' node is a sequence. This sequence has two INDEXes, so we have: |
− | ** <IndexNodeInfo>: is info of | + | IndexNumber = 0x2 |
− | ** <IndexDataType>: is data type of | + | with 1st INDEX: |
− | * | ||
− | |||
− | |||
− | |||
− | with | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
IndexCount = 0x04 | IndexCount = 0x04 | ||
− | IndexNodeInfo = | + | IndexNodeInfo = 0xCC |
IndexDataType = 0x02 | IndexDataType = 0x02 | ||
− | + | with 2nd INDEX: | |
IndexCount = 0x01 | IndexCount = 0x01 | ||
− | IndexNodeInfo = | + | IndexNodeInfo = 0x80 |
− | IndexDataType = | + | IndexDataType = 0x03 |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
===Example=== | ===Example=== | ||
− | + | * The example mchip.txt describe the OID tree given below: | |
− | |||
− | * | ||
[[File:Snmp mib oid tree example.jpg | thumb | center | 900px]] | [[File:Snmp mib oid tree example.jpg | thumb | center | 900px]] | ||
− | + | * The corresponding binary file is mchip.bin and it has data describe in table below: | |
− | * The corresponding binary file is | + | [[File:Snmp mib binary example.jpg | thumb | center | 900px]] |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | [[ | + | OID is <oid> fields. |
+ | Info is <nodeInfo> fields. | ||
+ | Dist is [distantSiblingOffset]/[siblingOffset] fields. | ||
+ | Id is [id] fields. | ||
+ | Defval is data fields, include [dataType], [dataLen], [data] fields. | ||
+ | Index is index fields of sequence, include [{index_number} , {<IndexCount>, <IndexNodeInfo>, <indexDataType>, ...}]. | ||
− | * The detail description of | + | * The detail description of mchip.bin is illuminated by structure diagram below: |
− | |||
− | |||
− | |||
[[File:Snmp mib binary detail example.jpg | thumb | center | 900px]] | [[File:Snmp mib binary detail example.jpg | thumb | center | 900px]] | ||
− | + | The hidden linear is oid tree structure. | |
− | + | The red and green continue linear is pointer of data. | |
− | + | The dist field point to next sibling record. After parent record is it's children. | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | The | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− |