4.12   SNMP Agent Data Flow

The remainder of this chapter describes the data flow through a standard SNMP agent. If you are using a distributed SNMP agent, you will also need to see 7.3 Data Flow between SNMP Master Agents and Subagents.

4.12.1   Initialization

VxWorks starts SNMP by invoking usrSnmpInit( ) at boot-time, which eventually spawns a task which appears in the system task table as tSnmpd. The main entry point into this task is snmpIoMain( ); this routine is provided in source and can be customized by the agent writer to perform user-defined initialization functions, such as reading a configuration file.

The following diagram describes the agent's initialization. Routines are shown with the files in which they appear.


*   

NOTE: Part of configuring WindNet SNMPv1/v2c for your site likely involved editing the file snmpIoLib.c to reflect your local network-management paradigm; see 5.2 Configuring snmpIoLib for details.

Initialization proceeds with the following stages:

  1. As VxWorks boots, usrSnmpInit( ) calls snmpdInit( ), thus starting the agent.

  1. snmpdInit( ) spawns the routine snmpIoMain( ), which handles multiple user-defined aspects of initialization. Possible user-defined initializations include:

  • reading user-defined configuration files
  • any private initialization code
  • user-defined view-management tables
  • user-defined community-view map table
  • user-defined trap configuration tables

  1. snmpIoMain( ) must invoke snmpdInitFinish( )to complete the initialization process. The snmpInitFinish( ) routine sends a coldStart trap (see 4.7 Traps) via a user-customized routine snmpIoTrapSend( ), which notifies the appropriate Network Management Stations that the SNMP agent is online.

  1. snmpInitFinish( ) returns to snmpIoMain( ), which invokes the packet-processing loop to handle incoming PDUs from Network Management Stations.

For more information on individual routines, see F. SNMP Reference.

4.12.2   Packet-Processing Loop

The following diagram describes the SNMP agent's main activities, which involve:

The loop occurs in snmpIoBody( ), which listens on the specified UDP port for incoming SNMP PDUs.

Routines are shown with the files in which they appear, if relevant. Arrows represent data flow.

The stages involved in packet processing can be described as follows.

  1. The user-defined routine snmpIoBody( ) listens for incoming requests on UDP port 161. When a request is received, it is handed off to snmpdPktProcess( ) for processing.

  1. The routine snmpdPktProcess( ) begins processing the packet and hands the information to the user-defined routine snmpIoCommunityValidate( ).

  1. snmpIoCommunityValidate( ) validates the PDU's community name by checking it against a table which specifies permissions for various communities, translates the community to a view index, and allocates private packet memory; if needed, this memory can be deallocated with a private-memory-deallocation hook (see 4.8 Hooks).

  1. The request is then processed by user-defined method routines. For SET requests, hooks are activated at the appropriate time. For any asynchronous routines, a thread must take over processing from the main method routine code.

  1. The information presented by the method routines is framed as a response PDU. The user-defined routine snmpIoWrite( ) issues a response to the calling Network Management Station.

  1. Resources allocated for hooks, for variable-binding in generating the response PDU, and for other agent activities are freed, and the process returns to its calling environment.

For more information on individual routines, see F. SNMP Reference.

4.12.3   Trap Processing

The following diagram describes the processing of traps, which are generated when a significant event occurs (see 4.7 Traps). Traps can be generated in two ways:

Also, if variables are to be relayed in the trap, a routine can be defined to bind those variables for transport. (For information on variable binding, see 4.10 Access to MIB Variables).

The stages involved in trap processing can be described as follows.

  1. A significant event occurs (see 4.7 Traps).

  1. snmpdTrapSend( ) is invoked, either from a call to the user-defined routine snmpIoTrapSend( ) or directly from user-defined trap code.

  1. snmpdTrapSend( ) creates an SNMPv1- or SNMPv2c-style trap message, depending on the trap's input parameter.

  1. If required, snmpdTrapSend( ) invokes a user-defined variable-binding routine to bind any variables in the trap.

  1. snmpdTrapSend( ) encodes the message as an SNMP packet, which is then handed off to snmpIoWrite( ) for delivery to Network Management Stations.

  1. Resources allocated for the variable-binding routine and for other agent activities are freed, and the process returns to its calling environment.

For more information on individual routines, see F. SNMP Reference.

4.12.4   Exiting the Agent

In the event that the agent designer's code determines that the SNMP agent must exit, the code must free its allocated resources and then invoke the function snmpdExit( ).

snmpdExit( ) calls MIB termination routines and frees all resources allocated by the agent itself. The user's code must then delete the associated task. After snmpdExit( ) is called, no other SNMP services should be invoked.

For information on hook routines, see the reference entry for snmpdInitFinish( ) in F. SNMP Reference.