In the original implementation of the WindNet SNMP agent, all the work was handled by a single task. With the introduction of the SNMP subagent, additional tasks were added to the system. As mentioned above, each SNMP subagent runs its own task. However, the SNMP master agent requires not one but two tasks, tSnmpd and tMonQue.
Of course, the SNMP manager never sees any of this. As far as it knows, it exchanges SNMP packets with the WindNet SNMP master agent--just as it would with any standard SNMP agent. The SNMP master agent then decodes the packet, and parses its MIB tree looking for the variable specified in the decoded packet.
If the MIB variable is local, the SNMP master agent acts no differently than a standard SNMP agent. The tSnmpd task calls the appropriate method, encodes the generated data in an SNMP packet, and finally transmits the packet over the socket connection to the SNMP manager.
If the MIB variable is not local, its associated local methods do not directly handle the requested SNMP request. Instead, these local methods put SNMP requests on the message queue associated with the MIB variable's subagent. When the SNNP manager sends the SNMP master agent a query on a variable managed by a subagent, the tSnmpd process calls one of these special subagent-accessing methods. While the subagent reads and processes the request from the SNMP master agent, the tSnmpd task waits on a local message queue (not the tMonQue message queue) for a response from the subagent, see Figure 7-1.
When the subagent sees the message on its queue, it reads the message and then parses its local MIB tree looking for the variable specified in the message. Upon finding the variable, the subagent executes the appropriate local method. The generated data is then put into a message which the subagent puts on the SNMP master agent's tMonQue message queue. This message queue is dedicated to receiving messages from subagents. When the tMonQue task sees the message on its queue, it notes whether the message is a registration request from a new subagent or a response coming in from a previously registered subagent.
If the message is a response to a query, tMonQue transfers the message to the local queue upon which the tSnmpd task is waiting for a response from the subagent. The tSnmpd task then reads the response, encodes the data in an SNMP packet, and transmits the packet back to the SNMP manager on the other end of its socket connection.
If the message is a registration request, tMonQue tries to update the SNMP master agent's MIB tree with information on the MIB variables in the subagent. The tMonQue task also puts a success or failure message on the subagent's message queue. Currently, if the registration request fails, the subagent just shuts itself down. However, you can modify this code to try again or do whatever else you think is appropriate for the system you are designing.