![]() ![]() ![]() |
When a request is made by the SNMP Manager, the network simulator creates the response SNMP PDU in a memory buffer and writes the PDU in the socket layer, where the IP and UDP headers get added before sending the packet to the SNMP Manager. The "SNMP PDU Scrambler" supports customizing the request/response SNMP PDU by exposing it to the user for customization.
The PDU Scrambler Interface enables you to,
Access to the request PDU for customization, before sending it to the simulator for further processing.
Update the request PDU with error status and error index values, if the incoming PDU is valid.
Access the SNMPScriptInterface object, for working with behavior API methods before processing the request/response PDU. The api implementation here is equivalent to configuring jython scripts to be executed before/after processing request condition.
Access to the response PDU for customization, before sending it to the socket layer.
Update the response PDU with proper error status and error index values, if invalid and send a error response to the manager.
For example, a request SNMP PDU can be customized to send garbled/invalid responses to test the SNMP managers robustness in the event of receiving bad packets.
Enabling the PDU Scrambler Feature
The PDU Scrambler feature will be enabled if the option Scramble the PDU is selected in the Settings -> Runtime Settings dialog. If the network is started from commandline, the -ps <enable/disable> is used to enable or disable the PDU scrambler feature.
Customizing the request SNMP PDU
The method processRequestPDU(SimulatorSnmpPdu snmpPdu) in <Simulator_Home>/examples/pduscrambler/NetsimPduScrambler.java is used to customize the request PDU.
If the option Scramble the PDU is selected, this method will be called with the SnmpPDU object when a SNMP GET, GET NEXT, SET request is made, before sending the packet to the simulator for processing the request. You can add your code inside this method to do the required PDU processing. After the processing, this method returns the modified or scrambled PDU to the simulator.
The prototype of this method is given below :
import com.adventnet.simulator.scripting.SimScrIntf; import com.adventnet.simulator.netsim.snmp.SimulatorSnmpPdu
public class NetsimPduScrambler {
/*Describe processRequestPDU method here*/
public void processRequestPDU(SimulatorSnmpPdu snmpPdu) {
/*add User Code here*/
/** * Here user can use the scriptIntf obj ref for working with behavior API * The api implementation here is equivalent to configuring jython scripts * to be executed before processing request condition */
/*doProcessWithScriptAPI(); setErrorStatAndIndex(1,1,snmpPdu);*/ } |
After adding the desired code, compile the NetsimPduScrambler.java file. The compiled class file must be placed in <Simulator_Home>/conf directory.
Refer to Simulator SNMP PDU Javadocs for customizing the response PDU.
Refer to Script Interface Javadocs to access the script API methods.
Customizing the response SNMP PDU
The method processResponsePDU(SimulatorSnmpPdu snmpPdu) in <Simulator_Home>/examples/pduscrambler/SimulatorPDUScrambler.java is used to customize the response PDU.
If the option Scramble the PDU is selected, this method will be called with the SnmpPDU object when a SNMP GET, GET NEXT, SET request is made, before sending the packet to the socket layer. You can add your code inside this method to do the required PDU processing. After the processing, this method returns the modified or scrambled PDU to the simulator.
The prototype of this method is given below :
import com.adventnet.simulator.scripting.SimScrIntf; import com.adventnet.simulator.netsim.snmp.SimulatorSnmpPdu
public class NetsimPduScrambler {
* Describe <code>processResponsePDU</code> method here * * @param snmpPdu <code>SimulatorSnmpPdu</code> value. * The response PDU created by the Simulator sent for scrambling */ public void processResponsePDU(SimulatorSnmpPdu snmpPdu) { /** * add User Code here. */ /** * Here user can use the scriptIntf obj ref for working with behavior API * The api implementation here is equivalent to configuring jython scripts * to be executed after processing request condition */ /*doProcessWithScriptAPI(); if(snmpPdu.getIPAddress().equalsIgnoreCase("192.168.1.129") && snmpPdu.getPort() == 8001) { setErrorStatAndIndex(1,1,snmpPdu); }*/ } } |
After adding the desired code, compile the NetsimPduScrambler.java file. The compiled class file must be placed in <Simulator_Home>/conf directory.
Refer to Simulator SNMP PDU Javadocs for customizing the response PDU.
Refer to Script Interface Javadocs to access the SNMP and TL1 script API methods.
![]() ![]() ![]() |