Agent Modes

From Net-SNMP Wiki
Jump to: navigation, search
Good Answer

This is a Good Answer article. It was likely created as a response to a question on a Net-SNMP Mailing List and written up here for others to see. It likely covers material not yet in the FAQ or in the Tutorial but may someday be moved there

Question

What are the various modes that the agent goes through when answering requests.

Answer

Get processing

TBD

Set processing

All the various modes used during set processing can be confusing. Let's start with a simple state diagram: http://www.net-snmp.org/tutorial/tutorial-5/toolkit/mib_module/set-actions.jpg

Here is a brief overview of the reserve, free, action, undo and commit modes.

SET_RESERVE1

The purpose of SET_RESERVE1 is to try and detect invalid SET requests as soon as possible. If any of the columns are assigned an impossible value (wrong type, or out-of-range, etc), then the request fails.

SET_RESERVE2

The purpose of SET_RESERVE2 is to set up/allocate the data structure for a new row or perform any resource allocation needed for further processing (e.g. allocate memory or lock a database).

SET_FREE

The purpose of SET_FREE is to undo anything done in the two SET_RESERVE passes, if some aspect of the request proves unacceptable. This means possibly releasing the data structure for a new row, if one was just been created. No action was performed, so no undo is needed.

SET_ACTION

SET_ACTION assigns the appropriate column values to the data structure for this row (either the new structure created in the SET_RESERVE2 step, or an existing row structure).

SET_UNDO

SET_UNDO reverses anything done in the two SET_RESERVE steps or SET_ACTION - called if some part of the SET_ACTION processing fails. This is similar to the SET_FREE processing, but also needs to reverse any newly assigned values.

SET_COMMIT

The purpose of SET_COMMIT is to confirm that the processing of the SET request has completed successfully, and perform any "irreversible" actions. For example, committing database changes.

Notes

Note that there is no common final "I'm done" mode. You must keep track of what needs to be for the 3 final states (free, undo, commit). For example, all three of those modes may require you to release some resource, like a database lock.

Baby Steps

see agent/helpers/baby_steps.c

   /*
    * Baby Steps Flow Chart (2004.06.05)                                  *
    *                                                                     *
    * +--------------+    +================+    U = unconditional path    *
    * |optional state|    ||required state||    S = path for success      *
    * +--------------+    +================+    E = path for error        *
    ***********************************************************************
    *
    *                        +--------------+
    *                        |     pre      |
    *                        |   request    |
    *                        +--------------+
    *                               | U
    * +-------------+        +==============+
    * |    row    |f|<-------||  object    ||
    * |  create   |1|      E ||  lookup    ||
    * +-------------+        +==============+
    *     E |   | S                 | S
    *       |   +------------------>|
    *       |                +==============+
    *       |              E ||   check    ||
    *       |<---------------||   values   ||
    *       |                +==============+
    *       |                       | S
    *       |                +==============+
    *       |       +<-------||   undo     ||
    *       |       |      E ||   setup    ||
    *       |       |        +==============+
    *       |       |               | S
    *       |       |        +==============+
    *       |       |        ||    set     ||-------------------------->+
    *       |       |        ||   value    || E                         |
    *       |       |        +==============+                           |
    *       |       |               | S                                 |
    *       |       |        +--------------+                           |
    *       |       |        |    check     |-------------------------->|
    *       |       |        |  consistency | E                         |
    *       |       |        +--------------+                           |
    *       |       |               | S                                 |
    *       |       |        +==============+         +==============+  |
    *       |       |        ||   commit   ||-------->||     undo   ||  |
    *       |       |        ||            || E       ||    commit  ||  |
    *       |       |        +==============+         +==============+  |
    *       |       |               | S                     U |<--------+
    *       |       |        +--------------+         +==============+
    *       |       |        | irreversible |         ||    undo    ||
    *       |       |        |    commit    |         ||     set    ||
    *       |       |        +--------------+         +==============+
    *       |       |               | U                     U |
    *       |       +-------------->|<------------------------+
    *       |                +==============+
    *       |                ||   undo     ||
    *       |                ||  cleanup   ||
    *       |                +==============+
    *       +---------------------->| U
    *                               |
    *                          (err && f1)------------------->+
    *                               |                         |
    *                        +--------------+         +--------------+
    *                        |    post      |<--------|      row     |
    *                        |   request    |       U |    release   |
    *                        +--------------+         +--------------+
    *
    */