Reference

SNMP Walk Data File

This file stores data from one or more SNMP walks of a single agent.

A simulator can use multiple SNMP walk data files. Each file must have a different community name (community-string indexing); otherwise, only the first file is used.

Root Node

<SnmpSimulatorData
    sysUpTimeOffset="111111111"
    delayRange="50-200"
>

sysUpTimeOffset: offset applied to sysUpTime, in milliseconds. The value returned by getSysUpTime() is shifted by this amount.

delayRange: range of response delays, in milliseconds. For example, delayRange="50-200" selects a random delay between 50 and 200 milliseconds. If this attribute is absent, no intentional delay is added.

Instances Section

The Instances section stores MIB walk instances. Each Instance node represents a MIB node.

Sample:

    <Instances
        interval="10"
        readCommunity="public"
        writeCommunity="public"
    >

interval: time between SNMP walks, in seconds. After each interval, the simulator advances to the next set of walk data. If this attribute is absent, only the first set is used.

readCommunity: SNMP community name for read operations, such as GET, GET_NEXT, and GET_BULK.

writeCommunity: SNMP community name for SET operations.

Instance Node

Each Instance node represents a MIB instance.

Sample:

        <Instance
            oid=".1.3.6.1.2.1.1.6.0"
            valueType="OctetString"
            trapOnSet="trap1"
            trapOnSetCount="2"
            name="sysLocation"
        >
             <Value> <![CDATA[sysLocationValue1]]> </Value>
             <Value na="yes"/>
             <Value> <![CDATA[sysLocationValue3/4]]> </Value>
             <Value same="yes"/>
        </Instance>

Field

Description

oid

Object identifier of this node.

valueType

Data type of this node. Possible values are:

{OctetString, Null , OID , BITS , UnsignedInteger , Counter32 , Gauge , TimeTicks , IpAddress , Opaque , Integer , Counter64 }

trapOnSet

Optional. If specified, a trap is generated for each SET request for this node. The value names the trap.

trapOnSetCount

Number of traps to send.

name

Optional. Name used by other nodes to reference this node.

Data Types

Name

Description

BITS

A set of integers in mathematical notation, such as {1, 3, 8}.

Counter32

A nonnegative 32-bit SNMP counter that increases monotonically until it reaches its maximum value.

Counter64

A nonnegative 64-bit SNMP counter that increases monotonically until it reaches its maximum value.

Gauge

A nonnegative 32-bit gauge that can increase or decrease.

Integer

A positive or negative integer. The minimum value is -2147483648; the maximum value is 2147483648.

IpAddress

An IP address, such as 121.12.77.126.

Null

Indicates the effective absence of a sequence element.

OctetString

An octet string. A hexadecimal string can use the format (0x[0-9A-Fa-f][0-9A-Fa-f] )+, such as 0x12 0xA1 0x30 or 0x12A130.

OID

An object identifier, such as 1.3.6.1.4.6.

TimeTicks

A non-negative integer.

UnsignedInteger

Unsigned 32-bit integer.

ScriptOnSet

Optional. Runs a script when a SET request is received.

Example:

  <Instance
            oid=".1.3.6.1.2.1.1.6.0"
            valueType="OctetString"
            trapOnSet="trap1"
            trapOnSetCount="2"
            name="sysLocation"
        >
             <Value> <![CDATA[sysLocationValue1]]> </Value>
            <ScriptOnSet>
<![CDATA[
    print("pdu is :" + pdu);
    exec("an external command");
   		 ]]>
</ScriptOnSet>
        </Instance>

Value Node

Value nodes store the values of a MIB node. A node can have one or more Value nodes, each corresponding to an SNMP walk. The Instances node specifies the interval between walks. For example, if the interval is one minute and each Instance node has three Value nodes, the simulator uses the first value when it starts, the second after one minute, and the third after two minutes. It continues to use the third value until it stops.

If an Instance node has fewer Value nodes than other Instance nodes, the simulator continues to use its last value after the earlier values are exhausted.

1. Static value

         <Value> <![CDATA[sysLocationValue1]]> </Value>

The CDATA node stores a static value that does not change.

2. Same value

         <Value same="yes"/>

This cannot be the first Value node. It uses the same value as the preceding Value node.

3. Disabled value

          <Value na="yes"/>

The simulator skips this MIB node and returns no value for SNMP requests.

4. Error simulation

         <Value errorOnSet="badValue" errorOnGet="noSuchName">
     <![CDATA[90]]>
         </Value>

Field

Description

errorOnSet

If specified, the response PDU uses this error status for an SNMP SET request.

errorOnGet

If specified, the response PDU uses this error status for an SNMP GET, GET_NEXT, or GET_BULK request.

CDATA

If the error condition is not met, the response has no error and returns the CDATA value.

5. Simple script

         <Value isSimpleScript="y" depends="sysName">
   <![CDATA[sysName + " was used as sysDescr"]]>
         </Value>

isSimpleScript: If set to "y" or "yes", the CDATA value is treated as a one-line script, and the expression result is returned.

6. Full script

         <Value script="script2"/>

script: Names the script whose result is returned. In this example, the result of the script named “script2” is used as the value of this MIB node.

Scripts Section (optional)

This section contains one or more Script nodes. Each Script node defines a function.

Example:

<?xml version="1.0" encoding="UTF-8"?>
<SnmpSimulatorData>
<Instances readCommunity="public">
        <Instance oid=".1.3.6.1.2.1.1.4.0" valueType="OctetString" >
            <Value><![CDATA[[email protected]]]></Value>
        </Instance>
    </Instances>
<Scripts>
    <ScriptInit>
            <![CDATA[
		int global_count = 0;
		open_db_connection();
            ]]>
    </ScriptInit>
        <Script name="script1"><![CDATA[
            Object getValue(String oid, SnmpPdu pdu)
            {
                exec("execute a command.");
	     return “value 1”;
            }
            ]]>
</Script>
    </Scripts>
</SnmpSimulatorData>

ScriptInit Node

Sample:

        <ScriptInit>
            <![CDATA[
		int global_count = 0;
		open_db_connection();
            ]]>
        </ScriptInit>

Scripts in this node run when the simulator starts.

ScriptDestroy Node

Sample:

        <ScriptDestroy>
            <![CDATA[
           	close_db_connection();
            ]]>
        </ScriptDestroy>

Scripts in this node run when the simulator stops.

Script Node

Sample:

<?xml version="1.0" encoding="UTF-8"?>
<SnmpSimulatorData>
<Instances readCommunity="public">
        <Instance oid=".1.3.6.1.2.1.1.4.0" valueType="OctetString">
<Value script="script2"/>
        </Instance>
    </Instances>
<Scripts>
<Script name="script2" depends="sysName, sysLocation">
            <![CDATA[
            Object getValue(String oid, SnmpPdu pdu)
            {
                return "testvalue";
            }
            ]]>
 </Script>
    </Scripts>
</SnmpSimulatorData>

Field

Description

name

Name of this script, used by other nodes to reference it.

depends (optional)

Names of nodes used in this script, separated by commas.

getValue function:

            Object getValue(String oid, SnmpPdu pdu)

Parameters:

oid: object identifier in the SNMP request being processed

pdu: SNMP PDU being processed

Returns:

The return value must be a string or an object implementing the SnmpDataType interface, such as SnmpOctetString or SnmpOID.

Traps Section (optional)

This section contains one or more Trap nodes that define SNMP traps.

Trap Node

1. SNMPv1 trap

Sample:

<?xml version="1.0" encoding="UTF-8"?>
<SnmpSimulatorData>
<Instances readCommunity="public">
        <Instance oid=".1.3.6.1.2.1.1.4.0" valueType="OctetString" >
            <Value><![CDATA[[email protected]]]></Value>
        </Instance>
    </Instances>
<Scripts>
        <Script name="script2" depends="sysName, sysLocation">
            <![CDATA[
            Object getValue(String oid, SnmpPdu pdu)
            {
                sendTrap("trap1");
            }
            ]]>
        </Script>
         </Scripts>
<Traps>
        <Trap
            name="trap1"
            generic="linkDown"
            specific="0"
        >
          <Variable use="sysDescr"/>
          <Variable
            oid=".1.3.6.1.2.1.1.2.0"
            valueType="OctetString"
          >
        </Trap>
</Traps>
</SnmpSimulatorData>

Field

Description

name

Name of this trap, used by other nodes to reference it.

generic

Generic-trap field; accepts a numeric or string value.

specific

Specific-trap field; accepts a numeric value.

2. SNMPv2c/v3 trap

        <Trap
        name="trap1"
        snmpTrapOID=".1.3.6.1.2.1.1.15135"
        >
     <Variable use="sysDescr"/>
        </Trap>

Field

Description

name

Name of this trap, used by other nodes to reference it.

snmpTrapOID

Object identifier of the snmpTrapOID object.

Trap's Variable Node

A Trap node can have one or more Variable nodes. Each Variable node defines a variable binding in one of the following formats:

1. Static value

The value is stored in a CDATA node.

                     <Variable
                        oid=".1.3.6.1.2.1.1.2.0"
                        valueType="OctetString"
                        >
                       	 <![CDATA[222etest faf a]]>
                     </Variable>

Field

Description

oid

Object identifier of this variable.

valueType

Data type of this value.

CDATA

Value of this variable.

2. Reference

The value comes from the referenced node.

               <Variable use="sysDescr"/>

Uses the OID and value of the “sysDescr” node.

3. Simple script

The value is the result of the simple script in the CDATA node.

              <Variable
                oid=".1.3.6.1.2.1.1.3.0"
                valueType="TimeTicks"
                isSimpleScript="yes"
                depends="sysName"
              >
                <![CDATA[getSysUpTime() + 1000]]>
              </Variable>

Field

Description

oid

Object identifier of this variable.

valueType

Data type of value.

isSimpleScript

If set to yes, the CDATA content is treated as a simple script.

depends

Optional. Names of nodes used in the simple script, separated by commas.

CDATA

Contains the simple script.

4. Full script

The value is the result of the script named by the script attribute.

              <Variable
                oid=".1.3.6.1.2.1.1.4.0"
                valueType="OctetString"
                script="script2"
              />

Field

Description

oid

Object identifier of this variable.

valueType

Data type of value.

script

Name of the script whose result is used as this variable’s value.

Thresholds Section (optional)

This section contains one or more Threshold nodes.

Sample:

      <Thresholds interval="1">

interval: time between calls to isTimeToSendTrap() on each Threshold node, in seconds. The simulator calls this function periodically to check whether a threshold has been crossed.

Threshold Node

This node defines the isTimeToSendTrap() function, which determines whether to send a trap.

Sample:

    <Threshold trapName="trap1" trapCount="1" depends="sysint">
    <![CDATA[
    boolean isTimeToSendTrap()
    {
        int i = Integer.parseInt(sysint) ;
        if(i <= 200)
        {
            return true;
        }
        return true;
    }
    ]]>
    </Threshold>

trapName: name of the trap sent when isTimeToSendTrap() returns true.

trapCount: number of traps sent when isTimeToSendTrap() returns true.

depends: Optional. Names of nodes used in isTimeToSendTrap(), separated by commas.

isTimeToSendTrap() function:

Return true to send a trap to all destinations defined in the simulator configuration file; otherwise, return false.