SNMP Traps

Microchip TCP/IP Stack

Microchip TCP/IP Stack Help
SNMP Traps

The SNMP agent in version 5.25 and later of Microchip's TCP/IP Stack supports SNMP V1 and V2c formatted traps. Traps are notifications from the agent to the manager that are used when a predefined event occurs at the agent. 

Several preprocessor macro in the TCPIPConfig.h variant header file can be used to enable or disable traps in the agent. Commenting and un-commenting these macros in the file will have different effects. The SNMP_TRAP_DISABLED macro will disable traps entirely if it is not commented:

#define SNMP_TRAP_DISABLED

The user must configure the expected trap format at the SNMP Manager. SNMPv2 entities acting as an agent should be able to generate and transmit SNMP V2 trap PDUs when the manager is configured to received and process SNMP V2 trap PDUs. To configure the trap format, comment or uncomment the following macro in the TCPIPConfig.h header file:

#defiine SNMP_STACK_USE_V2_TRAP

If the macro has been commented out, the SNMP agent will send V1 formatted trap PDUs; otherwise, it will send V2 formatted trap PDUs. By default, the SNMP agent is configured to send V2 formatted traps. Note that the SNMP V2c agent should only send V2 formatted traps. 

To enable traps in SNMPv3, the #define SNMP_V1_V2_TRAP_WITH_SNMPv3 macro must be uncommented. 

The following table illustrates how to enable/disable traps for different versions of SNMP:

 
SNMPv1 
SNMPv2c 
SNMPv3 
TRAP v1 (Enabled by default) 
  • Comment out the #define SNMP_TRAP_DISABLED macro

 

  • Comment out the #define SNMP_TRAP_DISABLED macro

 

  • Comment out the #define SNMP_TRAP_DISABLED macro
  • Uncomment the #define SNMP_V1_V2_TRAP_WITH_SNMPV3 macro

 

TRAP v2 (Disabled by default) 
(Not supported) 
  • Comment out the #define SNMP_TRAP_DISABLED macro
  • Uncomment the #define SNMP_STACK_USE_V2_TRAP macro

 

  • Comment out the #define SNMP_TRAP_DISABLED macro
  • Uncomment the #define SNMP_V1_V2_TRAP_WITH_SNMPV3 macro
  • Uncomment the #define SNMP_STACK_USE_V2_TRAP macro

 

Demos 

Two trap demos are included with the TCP/IP Stack. The task functions for these demos are called in the main application function:

  • SNMPTrapDemo() - This API demonstrates V1 or V2 trap formats (depending of the status of the SNMP_STACK_USE_V2_TRAP macro). The trap PDU will only have one demo variable binding on the varbind list.
  • SNMPV2TrapDemo() - This API provides V2 format notifications with multiple (3) variable bindings. The user should modify or use this routine as a reference for sending V2 trap format notifications with multiple bindings on the varbind list.

The user should only enable one SNMP demo API at a time. By default, the SNMPTrapDemo() API is enabled and SNMPV2TrapDemo() is commented out. 

V1/V2 Formatted Traps with a Single Variable Binding 

In the TCPIPConfig.h header file:

  • Uncomment #define SNMP_TRAP_DISABLED
  • Comment //#define SNMP_STACK_USE_V2_TRAP

For the Trap demonstration, two events are defined within the V2c agent:

  • If the Analog Potentiometer value is greater than 512, the agent will send a Trap every 5 seconds to the configured 'trapReceiverIPAddress.'
  • If Button 3 on the demo board is pressed, an organization-specific PUSH_BUTTON trap will be sent.

The current implementation of the V2c agent also generates a standard "Authentication Failure Trap":

  • If a request is received to modify (Set) a private MIB variable, or
  • If the value of the variable is requested (get) by a browser with the wrong community name.

Procedure:

  1. Open the "Advanced" configuration menu, configure the SNMP version to '2,' and configure the Write Community to "public', 'write', or 'private'.
  2. Select the 'trapEnabled.0' variable from the MIB tree.
  3. Select 'Set' from the Operations menu.
  4. Enter '1' in the value field of the SNMP SET window.
  5. Select 'trapReceiverIPAddress.0' from the MIB tree.
  6. Set the value to the IP address of the PC on which the SNMP browser is installed and running.
  7. Select 'trapCommunity.0' from the MIB tree.
  8. Set the community name of the SNMP browser (the default community, if not set, is 'public'). The 'trapCommunity' name will work as a filter for the SNMP browsers on a trap-monitoring server.
  9. Open the "Trap Receiver' utility that was installed with the iReasoning MIB browser (Start->Programs->iReasoning->MIB Browser->Trap Receiver).

 

To test the analog potentiometer trap, adjust the potentiometer on the demo board so the value is greater than 512 (turn it clockwise). This is an enterprise-specific trap. The SNMP Manager will receive the source IP address, the OID (as the name of the variable), the value, the timestamp, etc. for each event. The browser will interpret the data as AnalogPot variable information based on the OID name. 

 

To test the push button trap, press the appropriate button on the development board (RB0 on the PICDEM.net 2 or S3 on the Explorer 16 board). 

To test the Authentication Failure trap, configure the Read Community in your browser to a community name that is not supported by the agent (the default supported names are 'public' and 'read'). For example:

  1. Configure 'mchp' as the Read Community name in the browser.
  2. Select the private MIB variable LED5 from the MIB tree and issue a 'Get' operation from the browser.

The result table of the browser won't display any result, but the Trap Receiver will receive and Authentication Failure trap. 

 

This is an intimation from the agent to the SNMP Manager that there was an unauthorized attempt to access the private MIB variable in the database. 

V2 Formatted Traps with a Multiple Variable Bindings 

In the TCPIPConfig.h header file:

  • Uncomment #define SNMP_TRAP_DISABLED
  • Uncomment #define SNMP_STACK_USE_V2_TRAP

The SNMP V2 Trap PDU structure is: 

Version (2) | community | SNMP-PDU pdu-type (TRAP=0xA7) | request-id | error-status | err-index | varbind List 

The first two variable varbinds in the variable binding list of an SNMPv2-TRAP-PDU are sysUpTime.0 and snmpTrapOID.0, respectively. If any additional variables are to be included, then each of these varbind structures must be copied to the variable binding list. 

For the SNMPv2 multiple TRAP variable varbind demonstration, ANALOG_POT0 is used to generate an event and transmit an SNMP v2 Trap PDU. Adjust the analog potentiometer to a value greater than 512 (turn it clockwise) on the demo board. In addition to the sysUpTime.0 and snmpTrapOID.0 varbinds, the additional varbinds that are included with the trap PDU are:

  • PUSH-BUTTON
  • LED0_IO
  • ANALOG_POT0

The following figure shows a V2 formatted trap with ANALOG_POT0 as the variable binding to be notified. 

 

The next figure shows a multiple-variable varbind for an SNMP V2 Trap PDU, with the three additional variable bindings: 

 

Module
Microchip TCP/IP Stack 5.42.08 - June 15, 2013
Copyright © 2012 Microchip Technology, Inc.  All rights reserved.