7.4   Messages Passed between Master Agents and Subagents

When tSnmpd spawns tMonQue, it assigns snmpQueMonitor( ) to manage the tMonQue task. This function waits on the message queue that subagents use to send messages to the master agent. The snmpQueMonitor( ) function interprets messages on its queue using an SA_MESSAGE_T structure, which is defined in ipcLib.h as:

typedef struct SA_MESSAGE_S 
    { 
    int            msgType; 
    MSG_Q_ID       saId; 
    EBUFFER_T      mesg; 
    } SA_MESSAGE_T;

A switch internal to snmpQueMonitor( ) handles the message according to the value of the msgType member.

If the message type is CALL_QUERY_HANDLER, the message is a response to a query from the master agent. The buffer referenced in the mesg is then transferred to the local message queue monitored by tSnmpd, which is waiting for a query response from a subagent.

If the message type is IPC_AYT, the message is an "are you there" message, which is forwarded to the local message queue monitored by tSnmpd, which is waiting for a response to its "are you there" query against the subagent.

If the message type is CALL_REG_HANDLER, the message is either a registration request or a deregistration request. To respond to such requests, snmpQueMonitor( ) passes the buffer in mesg to snmpMasterHandlerWR( ).


*   

NOTE: Because snmpQueMonitor( )is defined in masterIoLib.c as LOCAL, no reference entry is produced for this function. However, snmpQueMonitor( )is fully described in the reference entry for snmpMonitorSpawn( ). In addition, the source for masterIoLib.c is shipped, so you are free to study or even modify the source for snmpMonitorSpawn( ) as needed.
Serial versus Asynchronous Communication with Subagents

The requests that a master agent receives from the SNMP manager typically require information on several MIB variables. If those variables are managed by different subagents, the master agent must query each subagent. In the shipped version of WindNet SNMP, these requests are handled serially. That is, each subagent is queried in turn. For example, if the master agent needed to query three subagents to handle a request from the SNMP master, the master agent would query a subagent and wait for a response before it went on to query the next subagent.

However, if each subagent resides on its own target with its own processor, you might want to take advantage of the possibility for parallel processing. That is, you would want the master agent to send queries to each subagent without waiting for responses between requests. This lets the subagents work in parallel.

To implement this asynchronous interrogation of subagents, you must modify snmpQueMonitor( )to call snmpMasterHandlerAsync( ) instead of snmpMasterHandlerWR( ). For more information, see the reference entry for snmpMasterHandlerAsync( ).

Changing the IPC Mechanism

The asynchronous interaction with subagents with the master agent is an advantage only if the master agent and its subagents reside on different targets. However, the shipped version of WindNet SNMP uses message queues as the IPC that connects the master agent with its subagents. Because message queues rely on a shared memory space, it is not possible to use message queues as the IPC between a master agent and a subagent that execute on different targets.

Fortunately, it is relatively easy to replace the underlying technology of the IPC mechanism. For example, it is possible to replace message queues with socket connections. To help make this replacement easier, all the functions that implement the IPC mechanism have been isolated to the masterIoLib and saIoLib. These libraries are shipped as source code that you are free to modify according to your needs. For more information on how you can modify these libraries to use a different IPC mechanism, see the reference entries for masterIoLib and saIoLib.