|
The most important part of the simulation is to setup the simulated environment. You can setup the desired environment by defining the behavior of devices in the network, so that it will behave like a real device. The behavior of devices, is done through Jython scripts. For example, device values can be changed, rows can be dynamically added or deleted, Traps and Informs can be configured to be sent, SNMP agents can be added/deleted from the existing network etc. You can also define behavior in such a way that behavior of one device can affect another device.
AdventNet Simulation Toolkit provides a ScriptInterface, which defines methods to perform simple operations like update, insert and delete from a JPython script . The Script API is provided under the < simulator home >/examples/javadocs directory. The name of the Script API file is SNMP_TL1_SimScrIntf.html
If behavior is configured for a device in the device tree, this behavior will be reflected in all the devices dragged and dropped.
Enabling/Disabling Behavior Service
The Network Simulator provides option to enable/disable the execution of behavior scripts configured for the SNMP devices in the network, at agent runtime. If behavior service is disabled, the agent will not check for script configurations before sending the response. Hence, you can use this option to improve the performance of the network, if behavior scripts are not required to be executed.
By default, the service is enabled and the behavior scripts configured (if any), will be executed. To disable the service,
Select Run -> Initialize Services. The Initialize Service dialog is displayed.
Deselect the option Enable SNMP Behavior Service.
Start the Agent. Now, the behavior scripts configured in the simulator, will not be executed.
|
|
Note: The options in the Initialize Services dialog will be disabled when the SNMP agent is started. |
The Network Designer provides an intuitive UI to configure Behavior scripts. To invoke the Behavior dialog,
Select the Device in the Device Tree for which you would like to configure Behavior.
Click on the
icon in the toolbar or select
Configure ->SNMP Behavior option from the menu bar or right-click
and select SNMP Behavior option
from the pop up menu. This will display the Configure
Behavior dialog.
The Configure Behavior dialog will list the configured scripts files, the defined conditions and actions to execute the script files. You can configure new Behavior, modify or delete an existing Behavior configuration, add new conditions and actions, modify existing conditions and actions, from this dialog.
Steps in Configuring Behavior
Step I : Configuring the Conditions to Execute the Script : Here, you will define when the script should be executed. Scripts can be executed based on three conditions. Scripts can be executed based on a request, based on a threshold condition and value, or timer based.
Step 2 and Step 3 is used for generating the script file from the UI, with the necessary actions to be executed and the conditions to execute the actions (if any). The conditions and actions are defined using the Script API methods.
|
|
Note: Defining Step 2 and Step 3 is not required in the following cases :
In all the above cases, the conditions and actions defined in the script file will be executed only when the condition to execute the script (specified in step 1) is satisfied. |
Step 2 : Configuring the Conditions to Execute the Actions : In this step you can define on what conditions the actions are to be executed. You can define any number of conditions.
Step 3 : Configuring the Actions to be Executed : In this step, you can define the actions to be executed, when the condition to executed the script and the condition to execute the action (if any) are satisfied.
Step 1: Configuring the Conditions to Execute the script
To configure conditions to execute the script, select the Add button in the Behavior Configuration dialog. The Define Your Script dialog is invoked. Select any of the following conditions and configure the necessary details on the right-side of the dialog.
Request based Script
Threshold based script
Timer based script
Choose the Request based icon that is displayed on the left of the wizard.
Select the MIB node and instance based on which behavior will be configured.
The name of the selected MIB node will be displayed as the script filename. You can also specify your own script file name or browse and select the required file, if it already exists.
If you want the script to be copied on to the device directory, you can check the option Copy script file to local directory.
The script requires a trigger, in which particular instance it should be executed. It can also be executed in more than one instance. You have the following options:
Before processing Get
After processing Get
Before processing GetNext
After processing GetNext
Before processing Set
After processing Set
Click Next in the wizard to proceed to Step 2 or click Finish to finish Behavior configuration and exit the dialog.
Choose the Threshold Based icon that is displayed on the left of the wizard.
Threshold based scripts can be configured only for leaf nodes. Select the leaf node and instance based on which behavior will be configured.
The name of the selected node will be displayed as the script filename. You can also browse and select the required file, if it already exists.
If you want the script to copied on to the device directory, you can check the option Copy script file to local directory.
The script requires a trigger, in which particular instance it should be executed. It can also be executed in more than one instance. You can specify any one of the following threshold conditions and value. When the condition and value is satisfied, the script will be executed.
Equal to
Not equal to
Less than
Greater than
Custom range : For Custom range, the script will be executed if the value of the MIB node is not within the lower and upper threshold value. For example, if the lower threshold value is 10 and upper threshold value is 20, the script is executed if the variable value is less than or equal to 10 (or) greater than or equal to 20.
Specify the threshold value. For custom range, the lower threshold value and higher threshold value must be specified.
Click Next in the wizard to proceed to Step 2 or click Finish to finish Behavior configuration and exit the dialog.
Choose the Timer Based icon that is displayed on the left of the wizard.
The name of the script file will be displayed, based on the time specified to execute the script. You can also browse and select the required file, if it already exists.
If you want the script to copied on to the device directory, you can check the option Copy script file to local directory.
You can specify when you want the scripts to get executed.
Execute scripts when agent starts: The configured script would get executed as soon as agent starts.
Execute scripts when agent stops: The configured script would get executed when the agent stops.
Execute scripts at specified time: You can specify the date and time of script execution. Choose the date and time using the spinner buttons provided. The scripts will get executed at the specified time.
Execute scripts after specified time after agent startup: You can specify the time in hours, minutes and seconds after which the script will get executed after the agent startup time.
Periodically execute (once in) : If scripts are to be executed at specified time or after specified time, periodically, you can check this option. Specify the duration as once in number of hour(s)/day(s).
Specify a time interval between each script execution. Eg. Timer interval 1000 millisecs.
The number of times you want the script to execute at the specified time. Eg: Number of times 5.
Click Next in the wizard to proceed to Step 2 or click Finish
to finish Behavior configuration and exit the dialog.
Example : You have configured to periodically execute the
script once in every 5 days , the Number
of Times the script must be executed is 10 with a timer interval
of 2 seconds This configuration will execute the script once in every
5 days.
|
|
Note:
Selecting the device right-click option SNMP -> Stop Timer Scripts will stop the execution of timer scripts in Network Simulator. To stop the execution of timer scripts in all devices, right-click on the blank network area and select Stop All timer scripts. |
Step 2 : Configuring the Conditions to Execute the Action
In this step you can define on what conditions you want the actions defined in the scripts, to be executed. You can define any number of conditions.
Click Add button that brings up the Configure Condition to be Checked dialog. This dialog displays all the methods available for the selected node.
Select the desired method , for example, getCurrentInstance.
|
|
Note: : A few methods that start with "getCurrent" are applicable only for the agent implemented in the selected device. (i.e) the condition you are specifying is for the selected agent. When you select other methods like getNodeValue, this is valid for all the network elements. You will find the text field Select Agent enabled and network elements listed in the drop down box. |
If you wish to configure behavior across the network, select the agent from the network. Specify the OID and instance. The MIBs of the selected agent will only be displayed in the MIB tree.
Select the operator from the drop down box. The list of operators are listed as follows.
Not equal to !=
Lesser than <
Greater than >
Lesser than or equal to <=
Greater than or equal to >=
After choosing the operator you can specify the value to which the expression should be equated to.
Click ok, You will see that the conditions that you have specified gets added to the Conditions to execute actions list.
Click Add to define another condition (or) click Next to proceed to Step 3 or click Finish to finish Behavior configuration and exit the dialog.
As already mentioned, you can specify as many conditions as you want . Hence you have to specify whether you want to
Match all conditions added in the list
Match any of the conditions added in the list
Step 3 : Configuring the Actions to be Executed
In this step, you can configure the actions to be performed when the condition to execute the script and the condition to execute the action (if any) is satisfied.
Click Add, to brings up the Configure Actions to be Performed dialog.
Select a method from the drop down list. Methods are listed below
Select the Update Value method
When simulating behavior of devices across a network, the agents in the network are listed in the drop down list. When you select the agent the value will be updated in the specified agent.
To specify the OID and instance on which it should be updated, click on the Select OID button. Only the MIBs of the selected agent will be displayed. When selecting the OID and the instance, the details of the nodes are displayed.
The syntax of the node is displayed along with the simulation type. You can choose the simulation type the node should have, and specify values for the simulation type.
Click OK
to add the action to the list
Example :
If you select the OID .1.3.6.1.2.1.1.6 the syntax would
be Display String. The options that you have with this node is constant
and random. If you choose the random option , you will see the range button
being enabled. Specify value and click Add so that the value will be associated
at random.
This method is used to get the current value of a MIB node.
Choose the method GetNode Value from the drop down list.
When simulating behavior of devices across a network, the agents in the network will be listed in the drop down list. You will be able to select an agent from the network.
To specify the OID, click on the Select OID button. Only the MIBs of the selected agent will be displayed. Select the OID and the instance.
Now you have to specify a variable in the field that is displayed at the right corner.
The value of the selected OID will get updated in the specified variable.
Click OK for the action to be added to the list
This method is used to insert an entry in a table.
Choose the method Insert Row to Table from the drop down list.
When simulating behavior of devices across a network, the agents in the network will be listed in the drop down list. You will be able to select agent from the network.
To specify the OID, click on the Select OID button. Only the MIBs of the selected agent will be displayed. Select a table node and instance to insert row into the table.
Click Add to add a row. You will see dialog coming up with details that contain
Column name
Simulation type
value
You can make the desired changes to the row entries.
Click OK. You have chosen to insert the selected row when the script executes and condition that you have specified earlier is satisfied.
This method is used to delete a specific row from the table.
Select the method Delete a Row from Table from the drop down list.
When simulating behavior of devices across a network, the agents in the network will be listed in the drop down list. You will be able to select agent from the network.
To specify the OID, click on the Select OID button. Only the MIBs of the selected agent will be displayed. Specify the table OID and instance that you want to delete from the table.
Click OK to delete table
This method is used to delete all the rows from a given table.
Select the method Delete All Rows from Table from the drop down list.
When simulating behavior of devices across a network, the agents in the network will be listed in the drop down list. You will be able to select agent from the network.
To specify the OID, click on the Select OID button. Only the MIBs of the selected agent will be displayed. Specify the table OID, all rows from the specified table node will be deleted.
Click OK.
There are three trap versions available :Sending a V1 trap, Sending a V2 trap , Sending a V3 trap.
Trap Version
: Select the Trap Version from the list displayed. If the trap version
is v1, the trap type must be specified as either Generic type or Specific
type. The default trap version is SNMPv1.
If the trap version is v3, the v3 agent must be started and the user name
and context name of the v3 user must be specified. Please refer the topic
"Simulating a v3 Agent" to know more about starting the v3 agent,
the default user names and password, and configuring new user names and
password.
Generic Type : If the trap type value is zero through five, then the trap is one of the generic SNMP traps defined by the snmp group of MIB-II and the Specific trap type will be zero. If the trap type value is six, then the trap is an enterprise-specific trap that is defined in a private MIB.
coldStart (0),
warmStart (1),
linkDown (2),
linkUp (3),
authenticationFailure (4),
egpNeighborLoss (5),
enterpriseSpecific (6).
Specific Type : Specify an integer value for the enterprise-specific trap that is defined in a private MIB.
Enterprise OID : The OID specified in the Enterprises field indicates exactly which management enterprise defines the trap.
Manager Name : Specify the manager name. If the Manager is running on the same machine it will contain the value localhost. If the Manager is running on a different machine specify the manager name or IP address of that machine.
Manager Port : The default manage port is 162. If the manager is running on a different port, specify the port number.
Community : Specify the community name of the manager.
Variable Bindings : It enables the user to add more varbinds to the trap other than the trap variables/objects It is optional.
|
|
Note: When you configure a Timer based SNMP V3 trap, the trap will be sent regardless of the manager's presence. You need the User name and the context name only to receive the traps. But when the SNMP v3 trap is configured as request based, the trap will not be sent unless the request is generated from the manager with the user name and context name. |
Select the method Send Inform from the drop down list.
Manager name : Specify the manager name. By default it is given as localhost.
Manager port : Specify the port at which the manager is running. By default it is 162.
The community string is set to public by default.
You have
to specify the SysupTime and Enterprise OID.
Example: SysupTime can take value of 1101101 and Enterprise
OID can have take a value like 1.3.6.1.2162.2.1.1
To add varbinds to the inform, click on the Configure button. It is optional.
To generated random numbers, specify minimum value and a maximum value so that random numbers will be generated within the specified range.
Minumum value can be 100 and maximum value can 200, random numbers will be generated within this range.
You can introduce a delay in the action. Specify the value in milliseconds and the script execution will be delayed by the specified time.
This action can be configured before a GET/GETNEXT/SET. It will terminate the ongoing operation and send the corresponding error message specified. The error message can be specified from the drop down box. You can choose any one of the following error types.
tooBig
noSuchObject
noSuchInstance
endOfMibView
badvalue
readOnly
genErr
noAccess
You can add any number of conditions Click Add to define another condition or click Finish to finish Behavior configuration and exit the dialog.
Simulating Behavior Across Agents
You can simulate behavior across agents in the network. For example, you have a network with five devices ( device 1 ...device 5). You can simulate behavior in such a way that if a specific condition is satisfied define condition for execution in device1, define the condition for action in device2 and the action can be defined to take place on device5.
When you select an agent, the MIBs of the selected agent will only be displayed.
To modify a script,
Select the script to be modified, from the list displayed in the Configure Behavior dialog.
Click Modify, to display the existing configuration. Make the necessary changes and click Finish.
To delete a script,
Select the script to be deleted, from the list displayed in the Configure Behavior dialog.
Click Delete, to delete the script file. The conditions and actions configured for the script will also be deleted.
Modifying & Deleting Condition for Action
To modify a condition for action,
If you require to change an existing condition.
Select the condition from the Condition to execute action list and click Modify to change the defined condition.
The Configure Condition to be Checked dialog is brought up, you can make the required changes and click OK for the changes to take effect.
To delete a condition,
You can delete a condition if it is no longer required.
Select the condition from the Condition to execute action list.
Click Delete to remove the condition from the list.
Modifying and Deleting Action to be Executed
To modify an action,
Select the action from the Actions to be Performed list and click Modify to change the defined action.
The Configure Actions to be Performed dialog is brought up, you can make the required changes and click OK for the changes to take effect.
To delete an action,
Select the action from the Actions to be Performed list
Click Delete to delete the defined action.
Stopping Timer Script Execution
Selecting the device right-click option SNMP -> Stop Timer Scripts will stop the execution of timer scripts in Network Simulator. To stop the execution of timer scripts in all devices, right-click on the blank network area and select Stop All timer scripts.
The example scripts for SNMP devices are available in <SimulatorHome>/examples/scripting/snmp directory. Some of the example scripts are explained below:
1. DeleteAllRows.py
The script file uses the scriptAPI method deleteAllRows to delete all the entries in the ifTable. It takes the tableEntryOID as input.
Format :
|
scriptinterface.deleteAllRows(String tableEntryOid) |
2. DeleteRow.py
This script file uses the scriptAPI method deleteRow to delete the first entry in the ifTable. It takes the tableEntryOID and the instance of the entry to be deleted, as input.
Format :
|
scriptinterface.deleteRow(String tableEntryOid,String instance) |
where
tableEntryOid is the Object Id of the table entry node
instance is the instance of the entry to be deleted
3. DeleteRowWithValue.py
This script uses the scriptAPI method deleteRowWithValue to delete a specific entry from a table when the value of the specified column matches the specified value. It takes the tableEntryOID, the column name and value as input.
Format :
|
scriptinterface.deleteRowWithValue(String tableEntryOid,String columnName String value) |
where
tableEntryOid is the Object Id of the table entry node
columnName is the name of the column node in the table
value is the value of the specified column
4. GetAllTableValues.py
This script file uses the scriptAPI method getAllTableValues to return the values of all the nodes for all the rows present in Table. It takes the tableEntryOID as input.
Format :
|
scriptinterface.getAllTableValues(String tableEntryOid) |
where
tableEntryOid is the Object Id of the table entry node
5. GetCurrentInstanceAndValue.py
This script file uses the scriptAPI method getCurrentInstance( ) and getCurrentValue( ) to return the instance and value of an incoming SET request. It should be configured for the condition "Before Processing Set" on a columnar node. This script gets the instance of the OID in the incoming SET request and its value and saves it in a text file named instance.txt
Format :
|
scriptinterface.getCurrentInstance() scriptinterface.getCurrentValue() |
6. GetInstances.py
This script file uses the scriptAPI method getInstances( ) to get all the instances in a table. It takes the tableOID as input and will return the instances in a Vector.
Format:
|
scriptinterface.getInstances(String tableOid) |
where
tableOid is the Object Id of the table node
7. GetNextInstance.py
This script file uses the scriptAPI method getNextInstance( ) to get the instance next to the one specified. It takes the Table OID and the instance of a table as input. This will return the value as a String
Format :
|
scriptinterface.getNextInstance(String tableOid,String instance) |
where
tableOid is the Object Id of the table node
instance is the instance of a row present in the table
8. GetNodeValue.py
This script file uses the method getNodeValue( ), to get the current value of a scalar or a table node. It takes the OID of the MIB node and the instance as input. This method will return the value as a String
Format :
|
scriptinterface.getNodeValue(String objectId,String instance) |
where
objectId is the object identifier (without the instance) of the MIB Node
instance is the instance of the node whose value should be obtained, for scalar nodes this should be ".0"
9. GetRowCount.py
This script files uses the method getRowCount( ) to get the total number of rows in a table. It takes the Table OID as input and returns an integer value.
Format :
|
scriptinterface.getRowCount(String tableOid) |
where
tableOid is the Object Id of the table node
10. InsertRow.py
This script file uses the insertrow( ) method is used to insert an entry in the Table . It takes the Table OID, the Object Id of the columns in the table, the values of each column and its simulation type as input.
Format :
|
scriptinterface.insertRow(String tableOid, String[] objectId,String[] values String[] simTypes) |
where
tableOid is the object id of the table node in which the entry has to be added
objectId is an array of the object Id of the columns in the table
values is an array of values for the columns in the table
simTypes is an array of the simulation types for the columns
11. MaskNode.py
This script file uses the method maskNode( ) to mask a MIB node from the Manager.
Format :
|
scriptinterface.maskNode(String objectId,String instance,String maskValue). |
12. UpdateColumnarValue.py and UpdateScalarValue.py
This script file uses the method updateValue( ) to update the value of a scalar node and columnar node. It takes the OID and instance of the MIB node for which the value should be updated, the value to be assigned and the simulation type.
Format
|
scriptinterface.updateValue(String objectId,String instance,String value,String simType) |
where
objectId is the object identifier (without the instance) of the mib node whose value has to be updated
instance is the instance for which the value should be updated, for scalar nodes this should be ".0"
value is the value to be assigned to the node
simType is the type of simulation required
13. SendInform.py
This script file uses the method sendInform( ) to send an inform request with no extra varbinds. It takes the manager name, manager port, community, sysUpTime and SNMP Trap OID as input.
Format
|
scriptinterface.sendInform(String mgrName,String mgrPort,String community, String sysUpTime,String snmpTrapOid) |
where
mgrName - the name of the manager to which the inform has to be sent
mgrPort - the port at which the manager is listening for incoming inform requests
community - the snmp community
sysUpTime - the System UpTime
snmpTrapOid - the value of the snmpTrapOid
14. SendInform_varbinds.py
This script file uses the scriptAPI method sendInform( ) to send an inform request with extra varbinds. The varbind for the inform is specified with the following information :
varbindOid is OID of the inform varbind
varbindTypes is the type of the varbind
varbindValues is the value of the varbinds.
Format
|
scriptinterface.sendInform(String mgrName,String mgrPort,String community,String sysUpTime,String snmpTrapOid,String[] varbindOid,String[] varbindTypes,String[] varbindValues) |
15. SendV1Trap.py
This script file uses the scriptAPI method sendV1Trap( ) to send a v1 trap without varbinds. It takes the manager name, manager port, community, enterprise OID, generic type and specifi type as input.
Format
|
scriptinterface.sendV1Trap(String mgrName,int mgrPort,String community, String enterpriseOid,int genericType,int specificType) |
where
mgrName - the name of the manager to which the trap has to be sent
mgrPort - the port at which the manager is listening for incoming traps
community - the snmp community
enterpriseOid - the Enterprise OID
genericType - the Generic Type
specificType - the Specific Type
16. SendV1Trap_varbinds.py
This script file uses the scriptAPI method sendv1Trap( ) to send a v1 trap with varbinds. It takes the manager name, manager port, community, enterprise OID, generic type, specific type, varbind OID, type and value as input.
Format
|
scriptinterface.sendV1Trap(String mgrName,int mgrPort,String community, String enterpriseOid,int genericType,int specificType,String[] varbindOid,String[] varbindTypes,String[] varbindValues) |
where
mgrName - the name of the manager to which the trap has to be sent
mgrPort - the port at which the manager is listening for incoming traps
community - the snmp community
enterpriseOid - the Enterprise OID
genericType - the Generic Type
specificType - the Specific Type
varbindOid - oid of the varbind
varbindTypes - the type of the varbind
varbindValues - the value
17. SendV2Trap.py
This script file uses the sendv2Trap( ) method to send a v2 trap with no extra varbinds.
|
scriptinterface.sendV2Trap(String mgrName,int mgrPort,String community,String trapOID) |
18. SendV2Trap_varbinds.py
This script file uses the sendv2Trap( ) method to send a v2 trap with extra varbinds. The varbinds for the trap is specified with the following information:
varbindOid - oid of the varbind
varbindTypes - the type of the varbind
varbindValues - the value
|
scriptinterface.sendV2Trap(String mgrName,int mgrPort,String community, String trapOID,String[] varbindOid,String[] varbindTypes,String[] varbindValues) |
19. SendV3Trap.py
This script file uses the sendv3Trap( ) method to send a v3 trap with no extra varbinds.
|
scriptinterface.sendV3Trap(String mgrName,int mgrPort,String community, String trapOID,String userName,String contextName) |
20. SendV3Trap_varbinds.py
This script file uses the sendV3Trap( ) method to send a v3 trap with extra varbinds. The varbinds for the trap is specified with the following information:
varbindOid is oid of the varbind
varbindTypes is the type of the varbind
varbindValues is the value
|
scriptinterface.sendV3Trap(String mgrName,int mgrPort,String community,String trapOID,String userName,String contextName,String[] varbindOid,String[] varbindTypes,String[] varbindValues) |
21. TerminateOperation.py
This script file uses the scriptAPI method terminateOperation( ) for terminating the current operation i.e. a Get, GetNext or Set operation. The general format of the terminateOperation method is :
|
scriptinterface.terminateOperation(int errorNumber) |
where, errorNumber is the error to be thrown on terminating the operation.
24. GetTotalColumns.py
This script file invokes the method getTotalColumns( ) and returns the total number of columns in a table. It takes the table entry oid as input.
Format
|
scriptinterface.getTotalColumns(String tableEntryOid); |
25. GetAllColumnByNames.py
This script file invokes the method getAllColumnByNames( ) and returns the name of all the columns in the table. It takes the table entry oid as input.
Format
|
scriptinterface.getAllColumnByNames(String tableEntryOid); |
26. getAllColumnByOids.py
This script file uses the method getAllColumnByOids( ) and returns the OID value of all the columns in the table. It takes the table entry oid as input.
Format :
|
scriptinterface.getAllColumnByOids(String tableEntryOid); |
27. GetAllIndices.py
This script file uses the method getAllIndices( ) to return the string array having name of all the indices defined in a table. It takes the table entry oid as input.
Format :
|
scriptinterface.getAllIndices(String tableEntryOid); |
28. SendTrap.py
This script file uses the scriptAPI method sendTrap( ) to send traps configured in the Trap Configuration dialog. It takes the associated variable as input. The parameter 'associatedVariable' is the name with which the trap is configured in 'TrapConfiguration' dialog .
The manager details and trap details will be taken as such configured in the 'TrapConfiguration' dialog.
Format :
|
scriptinterface.sendTrap(String associatedVariable); |
29. SendTrapWithEnterpriseOid.py
The script file uses the method sendTrap( ) to send traps configured in the Trap Configuration dialog. It takes the associated variable as input. The parameter 'associatedVariable' is the name with which the trap is configured in 'TrapConfiguration' dialog . The 'enterpriceOid' is the one which is going to be sent in the trap.
The manager details and trap details will be taken as such configured in the 'TrapConfiguration' dialog. The enterpriceOid will be the one specified in the second argument irrespective of the one configured in 'TrapConfiguration' dialog.
Format :
|
scriptinterface.sendTrap(String associatedVariable, String enterpriseOid); |
30. GetConfigDirectory.py
This script file uses the scriptAPI method getConfigDirectory( ) to get the current working directory name . It returns the directory name as a string.
Format :
|
scriptinterface.getConfigDirectory(); |
31. SendV1TrapWhileAddingRow.py
This Script file will send the V1 Trap while adding the row in the tables. This Script file using the following Script API Methods:
getRowCount()
getCurrentInstance()
sendV1Trap()
32. SendV1TrapWithVarbindsWhileAddingRow.py
This Script file will send the V1 Trap with Varbinds while adding the row in the tables. This Script file uses the following Script API Methods:
getRowCount()
getCurrentInstance()
sendV1Trap()
33. StartSnmpAgent.py
This script file uses the scriptAPI method startAgent( ) to start an SNMP agent. This method is useful in the runtime to start any SNMP agent in the Network from any other agent. This file will work only for the Network Simulator and not for the SNMP Agent Simulator.
Format :
|
scriptinterface.startAgent(java.lang.String networkName, java.lang.String ipAddress, java.lang.String snmpPort,java.lang.String tl1Port); |
34. StopSnmpAgent.py
This script file uses the scriptAPI method stopAgent( ) to stop an SNMP agent. This method is useful in the runtime to stop any SNMP agent in the Network from any other agent. This file will work only for the Network Simulator and not for the SNMP Agent Simulator.
Format :
|
scriptinterface.stopAgent(java.lang.String networkName, java.lang.String ipAddress, java.lang.String snmpPort,java.lang.String tl1Port) ; |
Given below are some sample behavior scenarios. The steps to define the behavior scenario and the output script file are given.
Script with condition for execution alone
In this sample, the script DeleteAllRows.py will be executed, after a get request is made on the MIB node "ifDescr" in the ifTable of the RFC 1213 MIB, with instance as .1
Select the Add button in the Behavior Configuration dialog.
Choose the Request based icon that is displayed on the left of the wizard.
Select the MIB node "ifDescr" in the ifTable of the RFC 1213 MIB. Specify the instance as .1
The name of the selected MIB node will be displayed as the script filename. Browse and select the script file "DeleteAllRows.py" in the ./examples directory.
The script requires a trigger, in which particular instance it should be executed. Select the option "After processing Get"
Click Finish to end Behavior configuration and exit from the dialog.
Script with condition for execution, condition for action, action to be executed
In this sample, the script file, ifOutErrors.py will be executed, when a set request is made on the node ifOutErrors. The condition for action is "if current value of ifOutErrors is greater than 10", the action to be executed is "send a v2trap". Hence, the script will send a trap, when a set is made on ifOutErrors with value greater than 10. The steps given below, defines the above Behavior :
Select the Add button in the Behavior Configuration dialog.
Choose the Request based icon that is displayed on the left of the wizard.
Select the MIB node "ifOutErrors" in the ifTable of the RFC 1213 MIB. Specify the instance as .1
The name of the selected MIB node will be displayed as the script filename "ifOutErrors.py".
Specify the condition to execute the script, by selecting the option "Before processing Set"
Click Next button, to specify the condition for action.
Click Add and select the method getCurrentValue, with operator as > and value as 10.
Click OK to add the condition to list. Now, you will find the condition getCurrentValue() >10 , added to the list.
Click Next button, to specify the action to be executed.
Click Add and select the method Send Trap, specify the version as Snmp v2c, with other options like Manager, Port and Community as default.
Click OK to add the action to the list. Now, you will find the action Send a V2c trap to localhost and port 162, added to the list.
Click Finish to end Behavior configuration. You will find the script ifOutErrors.py, added to the list with the defined conditions and actions, in the main dialog. Click Close to exit from the dialog.
The script file ifOutErrors.py is given below:
|
# The Actions
def actionfunc0(): scriptinterface.sendV2Trap("localhost",162,"public",".1.3.6.1.2.1.11")
# The end of the Actions
# The Condition
if(scriptinterface.getCurrentValue() > "10"): actionfunc0()
# The end of Conditions |
Script with condition for execution and actions to be executed
In this sample, the script file, timer.py will be executed, when the agent is started. The following actions are configured to be executed at agent startup : Get the node value sysUpTime and store it in a variable., send v1Trap. The steps given below, defines the above Behavior :
Select the Add button in the Behavior Configuration dialog.
Choose the Timer based icon that is displayed on the left of the wizard.
Specify the script filename as timer.py
Select the option Execute Script while Agent Starts.
Specify the Time Interval and Number of Times the script must be executed.
Click Next. The dialog to define the condition for action will be displayed. In this sample, we are not defining any condition for action. Hence click Next, to go the next dialog.
Click Add to add the action to the list. Select GetNodeValue, browse and select the OID as sysUpTime in System group of RFC 1213 MIB, specify the variable name as agentUpTime. The value of the node will be stored in this variable.
Click OK. You will find the action GetValue of Node of oid .1.3.6.1.2.1.1.3 with Instance .0, added to the list.
Click Add again, to add the second action. Select the method Send Trap, with other options like version, Manager, Port and Community as default.
Click OK. You will find the second action Send a V1 trap to localhost and port 162, added to the list.
Click Finish to end Behavior configuration. You will find the script timer.py, added to the list with the defined actions, the main dialog. Click Close to exit from the dialog.
The script file timer.py is given below:
|
# The Actions
def actionfunc0(): agentUpTime = scriptinterface.getNodeValue(".1.3.6.1.2.1.1.3" , ".0") scriptinterface.sendV1Trap("localhost",162,"public",".1.3.6.1.2.1.11",1,0)
# The end of the Actions
# The Condition actionfunc0() # The end of Conditions |
Script with different sets of conditions for action and actions to be executed
In this sample, the script file, ifAdminStatus.py will be executed, when a get request is made on the node ifAdminStatus in ifTable of the RFC 1213 MIB. Two sets of conditions and actions are defined as given below:
If node value of IfAdminStatus with instance ".1" is not equal to 1, Send a V1 trap to localhost at port 162
If total number of rows in ifTable is less than 5, Insert a row in the ifTable.
The steps given below, defines the above Behavior :
Select the Add button in the Behavior Configuration dialog.
Choose the Request based icon that is displayed on the left of the wizard.
Select the MIB node "ifAdminStatus" in the ifTable of the RFC 1213 MIB. Specify the instance as .1
The name of the selected MIB node will be displayed as the script filename "ifAdminStatus.py".
Specify the condition to execute the script, by selecting the option "After processing Get"
Click Next button, to specify the condition for action.
Click Add and select the method getNodeValue, to specify the OID, browse and select the ifTable, with operator as != and value as 1.
Click OK to add the condition to list. Now, you will find the condition getNodeValue(".1.3.6.1.2.1.2.2.1.7" , ".1") != 1 , added to the list.
Click Next button, to specify the action to be executed.
Click Add and select the method Send Trap, specify the version as Snmp v1, with other options like Manager, Port and Community as default.
Click OK to add the action to the list. Now, you will find the actionSend a V1 trap to localhost and port 162 added to the list.
Click Finish. You will find the script ifAdminStatus.py, added to the list with the first set of condition and actions defined conditions and actions, in the main dialog.
To add the second set of condition and action to the list, click Add button .
To add the second condition, click Add and select the method getRowCount, to specify the OID, browse and select the ifTable, with operator as < and value as 5.
Click OK to add the condition to list. Now, you will find the condition getRowCount(".1.3.6.1.2.1.2.2") < 5 Insert a Row in the ifTable , added to the list.
Click Next button, to specify the action to be executed.
Click Add and select the method InsertRow, to specify the OID, browse and select the ifTable. To specify the values of the new row,click Add . The new row with default values will be displayed. Modify the ifIndex value as '2' and click OK.
Click OK to add the action to the list. Now, you will find the action Insert a Row in the ifTable, added to the list.
Click Finish to end Behavior configuration. Click Close to exit from the dialog.
The script file ifAdminStatus.py is given below:
|
# Imports required for the scripts # to create an array the following lines should be in the script file from java.lang import String from jarray import array # The end of imports ############################################################################# # Row values of Tables
objectid1 = array([".1.3.6.1.2.1.2.2.1.1",".1.3.6.1.2.1.2.2.1.2",".1.3.6.1.2.1.2.2.1.3",".1.3.6.1.2.1.2.2.1.4", ".1.3.6.1.2.1.2.2.1.5", ".1.3.6.1.2.1.2.2.1.6",".1.3.6.1.2.1.2.2.1.7",".1.3.6.1.2.1.2.2.1.8",".1.3.6.1.2.1.2.2.1.9" ,".1.3.6.1.2.1.2.2.1.10",".1.3.6.1.2.1.2.2.1.11",".1.3.6.1.2.1.2.2.1.12",".1.3.6.1.2.1.2.2.1.13", ".1.3.6.1.2.1.2.2.1.14",".1.3.6.1.2.1.2.2.1.15",".1.3.6.1.2.1.2.2.1.16",".1.3.6.1.2.1.2.2.1.17", ".1.3.6.1.2.1.2.2.1.18",".1.3.6.1.2.1.2.2.1.19",".1.3.6.1.2.1.2.2.1.20",".1.3.6.1.2.1.2.2.1.21", ".1.3.6.1.2.1.2.2.1.22"],String) nodetypes1 = array(["CONST","CONST","CONST","CONST","CONST","CONST","CONST","CONST","CONST", "LINEAR","LINEAR","LINEAR","LINEAR","LINEAR","LINEAR","LINEAR","LINEAR","LINEAR","LINEAR", "LINEAR","CONST","CONST"],String) values1 = array(["2","Test Interface","32","1","1","ifPhysAddress","1","1","101010","1|1|0","1|1|0","1|1|0","1|1|0", "1|1|0","1|1|0","1|1|0","1|1|0","1|1|0","1|1|0","1|1|0","1",".1.3.6.1.2.1.2.2.1.22"],String) # The end of the varbinds #############################################################################
# The Actions def actionfunc0(): scriptinterface.sendV1Trap("localhost",162,"public",".1.3.6.1.2.1.11",0,0)
def actionfunc1(): scriptinterface.insertRow(".1.3.6.1.2.1.2.2",objectid1,values1,nodetypes1) # The end of the Actions
# The Condition if(scriptinterface.getNodeValue(".1.3.6.1.2.1.2.2.1.7" , ".1") != "1"): actionfunc0()
if(scriptinterface.getRowCount(".1.3.6.1.2.1.2.2") < 5): actionfunc1() # The end of Conditions |
Script with condition for execution in device1, condition for action in device2, action to be executed in device3
In this sample, the network has three devices, with IP address 0.0.0.1, 0.0.0.2, 0.0.0.3 running at port 8001. All three devices, implement the same agent. The script file, device.py is configured on device 1 with IP address 0.0.0.1. This script file will be executed, when a set request is made on the node sysName. If sysName="simulation" in device 1, the node value sysName in device 2 and device 3 is updated with the same value.
The script file device.py is given below:
|
# The Actions def actionfunc0(): scriptinterface.updateValue("0.0.0.2","8001",".1.3.6.1.2.1.1.5" , ".0","simulation","CONST") scriptinterface.updateValue("0.0.0.3","8001",".1.3.6.1.2.1.1.5" , ".0","simulation","CONST") # The end of the Actions
# The Condition if(scriptinterface.getNodeValue(".1.3.6.1.2.1.1.5" , ".0") == "simulation"): actionfunc0() # The end of Conditions |
|