Difference between revisions of "SNMP MIB Implementation"

From OpenCircuits
Jump to navigation Jump to search
Line 112: Line 112:
 
   | PDU  | Length |                                            Data of SNMP PDU                                                        |
 
   | PDU  | Length |                                            Data of SNMP PDU                                                        |
 
   | type |  Data  |                                                                                                                    |
 
   | type |  Data  |                                                                                                                    |
   +------+--------+---------------------------------------------------------------------------------------------------------------------+
+
   +------+--------+---------+---------+---------+---------------------------------------------------------------------------------------+
 
   | PDU  | Length | Request | Error  | Error  |                            VarBind List (Sequence)                                  |
 
   | PDU  | Length | Request | Error  | Error  |                            VarBind List (Sequence)                                  |
 
   | type |  PDU  |  ID    | Status  | Index  +------+--------+--------------------------------+--------------------------------+-----+
 
   | type |  PDU  |  ID    | Status  | Index  +------+--------+--------------------------------+--------------------------------+-----+
Line 143: Line 143:
 
* Error Index is an Integer. Only the response operation sets this field, if an Error occurs, the Error Index holds a pointer to the Object that caused the error. Other operations set this field to zero.
 
* Error Index is an Integer. Only the response operation sets this field, if an Error occurs, the Error Index holds a pointer to the Object that caused the error. Other operations set this field to zero.
 
* Varbind List is a Sequence of Varbinds.
 
* Varbind List is a Sequence of Varbinds.
* Varbind is a Sequence of two fields, an OID and the value of OID.
+
** Varbind is a Sequence of two fields, an OID and the value of OID.
* OID is an Object Identifier that points to a particular parameter in the SNMP agent.
+
*** OID is an Object Identifier that points to a particular parameter in the SNMP agent.
* Value is the value of OID.
+
*** Value is the value of OID.
 
   +--------------------+-----------------------------------------------------------------+
 
   +--------------------+-----------------------------------------------------------------+
 
   |    SNMP PDU type  |                            Value                                |
 
   |    SNMP PDU type  |                            Value                                |
Line 154: Line 154:
 
   | GetResponse PDU    | The returned Value from the specified OID of the SNMP agent.    |
 
   | GetResponse PDU    | The returned Value from the specified OID of the SNMP agent.    |
 
   +--------------------+-----------------------------------------------------------------+
 
   +--------------------+-----------------------------------------------------------------+
====Trap PDU Format====
+
====[http://docstore.mik.ua/orelly/networking_2ndEd/snmp/ch10_03.htm= Trap PDU Format]====
 +
* The format of the Trap PDU is shown below:
 +
  +------------------------------------------------------------------------------------------------------------------------------------------+
 +
  |                                                        TRAP SNMPv1 PDU                                                                  |
 +
  +----+------+------------------------------------------------------------------------------------------------------------------------------+
 +
  |PDU |Length|                                            Data of SNMP PDU                                                                |
 +
  |type| Data |                                                                                                                              |
 +
  +----+------+----------+-------+-------+--------+------+---------------------------------------------------- ------------------------------+
 +
  |0xA4|Length|Enterprise| Agent |Generic|Specific|Time  |                                VarBind List (Sequence)                            |
 +
  |    | PDU  |  OID    |Address| Trap  |  Trap  |Stamp +------+--------+------------------------------+------------------------------+-----+
 +
  |    |      |          |      | Type  | Number |      | 0x30 | Length |          Varbind 1          |        Varbind 22          | ... |
 +
  |    |      |  (OID)  |      |      |        |      |      |        |          (Sequence)          |        (Sequence)          | ... |
 +
  |    |      |          |      |      |        |      |      |        +----+-------+-------+---------+----+-------+-------+---------+-----+
 +
  |    |      |          |      |      |        |      |      |        |0x30| Len 1 | OID 1 | Value 1 |0x30| Len 2 | OID 1 | Value 2 | ... |
 +
  +----+------+----------+-------+-------+--------+------+------+--------+----+-------+-------+---------+----+-------+-------+---------+-----+
 +
                          |                                              |            |<-----Len 1----->|            |<-----Len 2----->|    |
 +
                          |                                              |<-----------------------------Length------------------------------>|
 +
                          |<--------------------------------------------Lenght PDU----------------------------------------------------------->|
 +
* PDU type is TRAP PDU = 0xA4.
 +
* Length Data is a number bytes of Data of SNMP PDU field.
 +
* Enterprise OID identifies the type of managed object generating the trap.
 +
* Agent Address is the IP address of the agent that is sending the trap.
 +
* [http://docstore.mik.ua/orelly/networking_2ndEd/snmp/ch02_06.htm#enettdg-CHP-2-TABLE-8= Generic Trap Type] indicates one of a number of generic trap types.
 +
  Generic Trap Type has seven values are defined:
 +
  +------------------------------+---------------------------------------------------------------------------+
 +
  |      Generic Trap Type      |                                                                          |
 +
  +-----------------------+------+                                Description                                |
 +
  |        Name          | Code |                                                                          |
 +
  +-----------------------+------+---------------------------------------------------------------------------+
 +
  | coldStart            | 0x00 | Indicates that the agent has rebooted. All management variables will be  |
 +
  |                      |      | reset; specifically, Counters and Gauges will be reset to zero (0).      |
 +
  +-----------------------+------+---------------------------------------------------------------------------+
 +
  | warmStart            | 0x01 | Indicates that the agent has reinitialized itself. None of the management |
 +
  |                      |      | variables will be reset.                                                  |
 +
  +-----------------------+------+---------------------------------------------------------------------------+
 +
  | linkDown              | 0x02 | Sent when an interface on a device goes down. The first variable binding  |
 +
  |                      |      | identifies which interface went down.                                    |
 +
  +-----------------------+------+---------------------------------------------------------------------------+
 +
  | linkUp                | 0x03 | Sent when an interface on a device comes back up. The first variable      |
 +
  |                      |      | binding identifies which interface came back up.                          |
 +
  +-----------------------+------+---------------------------------------------------------------------------+
 +
  | authenticationFailure | 0x04 | Indicates that someone has tried to query your agent with an incorrect    |
 +
  |                      |      | community string; useful in determining if someone is trying to gain      |
 +
  |                      |      | unauthorized access to one of your devices.                              |
 +
  +-----------------------+------+---------------------------------------------------------------------------+
 +
  | egpNeighborLoss      | 0x05 | Indicates that an Exterior Gateway Protocol (EGP) neighbor has gone down. |
 +
  +-----------------------+------+---------------------------------------------------------------------------+
 +
  | enterpriseSpecific    | 0x06 | Indicates that the trap is enterprise-specific. SNMP vendors and users    |
 +
  |                      |      | define their own traps under the private-enterprise branch of the SMI    |
 +
  |                      |      | object tree. To process this trap properly, the NMS has to decode the    |
 +
  |                      |      | specific trap number that is part of the SNMP message.                    |
 +
  +-----------------------+------+---------------------------------------------------------------------------+
 +
* Specific trap number is a number indicating the specific trap you want to send. If you're sending a generic trap, this parameter is ignored -- you're probably better off setting it to zero.
 +
* Time stamp is the time elapsed between the last initialization of the network entity and the generation of the trap.
 +
* Varbind List is a Sequence of Varbinds to be included in the trap.
 +
** Varbind is a Sequence of two fields, an OID and the value of OID.
 +
*** OID is an Object Identifier that points to a particular parameter in the SNMP agent.
 +
*** Value is the value of OID

Revision as of 10:22, 3 May 2011

SNMP's PDU using BER

  • SNMP is the protocol that allows communicate between NMS and agents by exchanging SNMP messages. the SNMP message is a single field, of the Sequence type. SNMP message use data types specified by ASN.1 and use Basic Encoding Rules (BER) to encode data. The entire SNMP message is a Sequence of three smaller fields: the SNMP Version (Integer), the SNMP Community String (Octet String), and the SNMP PDU.
  • The SNMP's PDU is reference to SNMP version 1 (SNMPv1) PDU.
  • SNMPv1 PDU have five different PDU types:GetRequest, GetNextRequest, GetResponse, SetRequest and Trap.
  • Get Request, GetNext Request, Get Response, Set Request are same format PDU. Trap use other format PDU.

ASN.1 data types

  • ASN.1 data types fall into two categories: primitive and complex.
  • ASN.1 data types is used to build SNMP messages.
    • ASN.1 primitive data types include Integer, Octet (byte, character) String, Null, Boolean and Object Identifier.
    • ASN.1 complex data types are used to build SNMP message are Sequence type, Sequence-of type.

Encoding Rules (BER)

  • BER has three parts: Type, Length and Data field.
  BER format: 
     +------+--------+------+
     | Type | Length | Data |
     +------+--------+------+
  • Type field is single byte identifier.
  Constructing byte Data type.
  Format of byte Data type
     +--+-+-----+
     |  | |     +
     +--+-+-----+
      2  1   5
  Bits 8 and 7 shall be encoded to represent the class of Data type follow table:
     +------------------+-------+-------+
     |      Class       | Bit 8 | Bit 7 |
     +------------------+-------+-------+
     | Universal        |   0   |   0   |
     | Application      |   0   |   1   |
     | Context-specific |   1   |   0   |
     | Private          |   1   |   1   |
     +------------------+-------+-------+
  Bit 6 is encoded data is Primitive or Constructed follow table:
     +-------+-------------+
     | Bit 6 |   Type      |
     +-------+-------------+
     |   0   | Primitive   |
     |   1   | Constructed |
     +-------+-------------+ 
  Bits 5 to 1 encode the number of Data type as a integer number.     
  Data type identifier in SNMP
     Data type                 Identifier      Note
     Integer                      0x02         Primitive ASN.1 types
     Octet String                 0x04         Primitive ASN.1 types  
     Null                         0x05         Primitive ASN.1 types
     Object identifier            0x06         Primitive ASN.1 types
     Sequence                     0x30         Constructed ASN.1 types
     IpAddress                    0x40         Primitive SNMP application types
     Counter                      0x41         Primitive SNMP application types
     Gauge                        0x42         Primitive SNMP application types
     TimeTicks                    0x43         Primitive SNMP application types 
     Opaque                       0x44         Primitive SNMP application types
     NsapAddress                  0x45         Primitive SNMP application types
     GetRequest PDU               0xA0         Context-specific Constructed SNMP types
     GetNextRequest PDU           0xA1         Context-specific Constructed SNMP types
     GetResponse PDU              0xA2         Context-specific Constructed SNMP types
     SetRequest PDU               0xA3         Context-specific Constructed SNMP types
     Trap PDU                     0xA4         Context-specific Constructed SNMP types
  • Length field is the number of bytes in Data field.
    • Length field is used either the short form or the long form as a option depend on Data field.
      • The short form, Length field is a single octet in which bit 8 is zero and bits 7 to 1 encode the number of bytes in Data field, as an unsigned binary integer with bit 7 as the most significant bit.
      • The long form, Length field shall consists of an initial octet and one or more subsequent octets.
        • The initial octet is encoded as follows:
          • Bit 8 shall be one.
          • Bits 7 to 1 shall encode the number of subsequent octets in the length field, as an unsigned binary integer with bit 7 as the most significant bit.
          • The value 0xFF shall not be used.
        • Subsequent octets:
          • From the first subsequent octet to the last subsequent octet, shall be the encoding of an unsigned binary integer equal to the number bytes in Data field, with bit 8 of the first subsequent octet as the most significant bit.
  • Data field is actual data content.
  • Example:
  Actual Data is an integer, the value 100 can be encode as:
  The short form:
     +------+--------+-------+
     | Type | Length | Data  |
     +------+--------+-------+
     | 0x02 |  0x01  | 0x64  |
     +------+--------+-------+
  The long form:
     +------+-----------+-------+
     | Type |  Length   | Data  |
     +------+-----------+-------+
     | 0x02 | 0x81 0x01 | 0x64  |
     +------+-----------+-------+

SNMP Message Format

  • SNMP Message is a Sequence of three smaller fields: the SNMP Version (Integer), the SNMP Community String (Octet String), and the SNMP PDU.
  SNMP Message Format use BER.
     +------------------------------------------------------------------------+
     |                      SNMP Message (Sequence type)                      |
     +------+----------------+------------------------------------------------+
     | Type | Length of Data |                      Data                      |
     +------+----------------+-------------+-----------------------+----------+
     | 0x30 |     Length     |SNMP Version | SNMP Community String | SNMP PDU |                      
     |      |                |  (Integer)  |    (Octet String)     |          |
     +------+----------------+-------------+-----------------------+----------+
                             |<--------------------Length-------------------->|
  • Length is bytes of Data field (SNMP Version, SNMP Community String and SNMP PDU).
  • SNMP Version is an integer that identifies the version of SNMP, SNMP version 1 = 0.
  • SNMP Community String is an Octet String to add security to Agents.
  • SNMP PDU is a SNMP verion 1 (SNMPv1) PDU.

SNMP PDU Format

  • SNMP PDU is is reference to SNMP version 1 (SNMPv1) PDU.

GetRequest PDU, GetNextRequest PDU, GetResponse PDU, SetRequest PDU Format

  • GetRequest PDU, GetNextRequest PDU, GetResponse PDU, SetRequest PDU Format is shown here.
  +-------------------------------------------------------------------------------------------------------------------------------------+
  |                               SNMPv1 PDU (GetRequest, GetNextRequest, GetResponse, SetRequest                                       |
  +------+--------+---------------------------------------------------------------------------------------------------------------------+
  | PDU  | Length |                                             Data of SNMP PDU                                                        |
  | type |  Data  |                                                                                                                     |
  +------+--------+---------+---------+---------+---------------------------------------------------------------------------------------+
  | PDU  | Length | Request | Error   | Error   |                             VarBind List (Sequence)                                   |
  | type |  PDU   |   ID    | Status  | Index   +------+--------+--------------------------------+--------------------------------+-----+
  |      |        |         |         |         | 0x30 | Length |           Varbind 1            |           Varbind 2            | ... |
  |      |        |(Integer)|(Integer)|(Integer)|      |        |          (Sequence)            |          (Sequence)            | ... | 
  |      |        |         |         |         |      |        +------+-------+-------+---------+------+-------+-------+---------+-----+
  |      |        |         |         |         |      |        | 0x30 | Len 1 | OID 1 | Value 1 | 0x30 | Len 2 | OID 1 | Value 2 | ... |
  +------+--------+---------+---------+---------+------+--------+------+-------+-------+---------+------+-------+-------+---------+-----+
                  |                                             |              |<-----Len 1----->|              |<-----Len 2----->|     |
                  |                                             |<-------------------------------Length-------------------------------->|
                  |<----------------------------------------------Lenght PDU----------------------------------------------------------->| 
  • PDU Type is specific type of PDU, PDU Type is a single byte identifier.
  • Length Data is a number bytes of Data of SNMP PDU field.
  • Data of SNMP PDU is data content in SNMP PDU.
  • Request ID is an Integer that identifies a particular SNMP request. This index is echoed back in the response from the SNMP agent, allowing the SNMP manager to match an incoming response to the appropriate request.
  • Error Status is an Integer set to 0x00 in the request sent by the NMS. The SNMP agent places an error code in this field in the response message if an error occurred processing the request.
  Some error codes include:
  +-------------------+---------------------------------------------------------------------------+
  |    Error Status   |                                                                           |
  +------------+------+                                Description                                |
  |    Name    | Code |                                                                           |
  +------------+------+---------------------------------------------------------------------------+
  | noError    | 0x00 | No error occurred.                                                        |
  | tooBig     | 0x01 | The response to your request was too big to fit into one response.        |
  | noSuchName | 0x02 | The OID in the request was not found.the OID doesn't exist.               |
  | badValue   | 0x03 | A data type in the request did not match the data type in the SNMP agent. |
  | readOnly   | 0x04 | The SNMP manager attempted to set a read-only parameter.                  |
  | genErr     | 0x05 | General Error (some error other than the ones listed above).              |
  +------------+------+---------------------------------------------------------------------------+
  • Error Index is an Integer. Only the response operation sets this field, if an Error occurs, the Error Index holds a pointer to the Object that caused the error. Other operations set this field to zero.
  • Varbind List is a Sequence of Varbinds.
    • Varbind is a Sequence of two fields, an OID and the value of OID.
      • OID is an Object Identifier that points to a particular parameter in the SNMP agent.
      • Value is the value of OID.
  +--------------------+-----------------------------------------------------------------+
  |    SNMP PDU type   |                            Value                                |
  +--------------------+-----------------------------------------------------------------+
  | SetRequest PDU     | Value is applied to the specified OID of the SNMP agent.        |
  | GetRequest PDU     | Value is a Null that acts as a placeholder for the return data. |
  | GetNextRequest PDU | Value is a Null that acts as a placeholder for the return data. |
  | GetResponse PDU    | The returned Value from the specified OID of the SNMP agent.    |
  +--------------------+-----------------------------------------------------------------+

Trap PDU Format

  • The format of the Trap PDU is shown below:
  +------------------------------------------------------------------------------------------------------------------------------------------+
  |                                                         TRAP SNMPv1 PDU                                                                  |
  +----+------+------------------------------------------------------------------------------------------------------------------------------+
  |PDU |Length|                                             Data of SNMP PDU                                                                 |
  |type| Data |                                                                                                                              |
  +----+------+----------+-------+-------+--------+------+---------------------------------------------------- ------------------------------+
  |0xA4|Length|Enterprise| Agent |Generic|Specific|Time  |                                VarBind List (Sequence)                            |
  |    | PDU  |   OID    |Address| Trap  |  Trap  |Stamp +------+--------+------------------------------+------------------------------+-----+
  |    |      |          |       | Type  | Number |      | 0x30 | Length |           Varbind 1          |         Varbind 22           | ... |
  |    |      |  (OID)   |       |       |        |      |      |        |          (Sequence)          |         (Sequence)           | ... |
  |    |      |          |       |       |        |      |      |        +----+-------+-------+---------+----+-------+-------+---------+-----+
  |    |      |          |       |       |        |      |      |        |0x30| Len 1 | OID 1 | Value 1 |0x30| Len 2 | OID 1 | Value 2 | ... |
  +----+------+----------+-------+-------+--------+------+------+--------+----+-------+-------+---------+----+-------+-------+---------+-----+
                         |                                               |            |<-----Len 1----->|            |<-----Len 2----->|     |
                         |                                               |<-----------------------------Length------------------------------>|
                         |<--------------------------------------------Lenght PDU----------------------------------------------------------->|
  • PDU type is TRAP PDU = 0xA4.
  • Length Data is a number bytes of Data of SNMP PDU field.
  • Enterprise OID identifies the type of managed object generating the trap.
  • Agent Address is the IP address of the agent that is sending the trap.
  • Generic Trap Type indicates one of a number of generic trap types.
  Generic Trap Type has seven values are defined: 
  +------------------------------+---------------------------------------------------------------------------+
  |       Generic Trap Type      |                                                                           |
  +-----------------------+------+                                Description                                |
  |         Name          | Code |                                                                           |
  +-----------------------+------+---------------------------------------------------------------------------+
  | coldStart             | 0x00 | Indicates that the agent has rebooted. All management variables will be   |
  |                       |      | reset; specifically, Counters and Gauges will be reset to zero (0).       |
  +-----------------------+------+---------------------------------------------------------------------------+
  | warmStart             | 0x01 | Indicates that the agent has reinitialized itself. None of the management |
  |                       |      | variables will be reset.                                                  |
  +-----------------------+------+---------------------------------------------------------------------------+
  | linkDown              | 0x02 | Sent when an interface on a device goes down. The first variable binding  |
  |                       |      | identifies which interface went down.                                     |
  +-----------------------+------+---------------------------------------------------------------------------+
  | linkUp                | 0x03 | Sent when an interface on a device comes back up. The first variable      | 
  |                       |      | binding identifies which interface came back up.                          |
  +-----------------------+------+---------------------------------------------------------------------------+
  | authenticationFailure | 0x04 | Indicates that someone has tried to query your agent with an incorrect    |
  |                       |      | community string; useful in determining if someone is trying to gain      |
  |                       |      | unauthorized access to one of your devices.                               |
  +-----------------------+------+---------------------------------------------------------------------------+
  | egpNeighborLoss       | 0x05 | Indicates that an Exterior Gateway Protocol (EGP) neighbor has gone down. |
  +-----------------------+------+---------------------------------------------------------------------------+
  | enterpriseSpecific    | 0x06 | Indicates that the trap is enterprise-specific. SNMP vendors and users    |
  |                       |      | define their own traps under the private-enterprise branch of the SMI     |
  |                       |      | object tree. To process this trap properly, the NMS has to decode the     |
  |                       |      | specific trap number that is part of the SNMP message.                    |
  +-----------------------+------+---------------------------------------------------------------------------+
  • Specific trap number is a number indicating the specific trap you want to send. If you're sending a generic trap, this parameter is ignored -- you're probably better off setting it to zero.
  • Time stamp is the time elapsed between the last initialization of the network entity and the generation of the trap.
  • Varbind List is a Sequence of Varbinds to be included in the trap.
    • Varbind is a Sequence of two fields, an OID and the value of OID.
      • OID is an Object Identifier that points to a particular parameter in the SNMP agent.
      • Value is the value of OID