Customizing SNMP PDU in SNMP Agent Simulator

 



 

Overview

 

When a request is made by the SNMP Manager, the snmp agent 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,

For example,  a request SNMP PDU can be customized to validate that it contains multiple varbinds before the agent  performs SNMP operation in OIDs. The response SNMP PDU can be customized, for example,  to send garbled/invalid responses to test the SNMP managers robustness in the event of receiving bad packets.

 

The level of customization varies depending on your requirement. For example, you can change the initial ASN.1 length value to a smaller or bigger value, change the length of a varbind OID to be very large, to see if the SNMP manager can read the full packet and give an error or to test other problem involved in dealing with un-initialized memory.

 

Customizing the request  SNMP PDU

 

The method processRequestPDU( SnmpPDU reqPDU ) in <Simulator_Home>/examples/pduscrambler/SimulatorPDUScrambler.java is used to customize the request PDU. 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.snmp.snmp2.SnmpPDU;

import com.adventnet.simulator.scripting.SimScrIntf;

 

public class SimulatorPduScrambler implements SimPDUScramInterface {

 

/*Describe processRequestPDU method here. */

 

public SnmpPDU processRequestPDU(SnmpPDU reqPdu) throws com.adventnet.snmp.snmp2.SnmpException {

 

/*

 * 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();

 

/**

* if you need to terminate the operation you have to throw the error. In this case * simulator will skip the normal SNMP processing and send updated PDU as response * * PDU.

 */

 

updateErrStatAndTerminate(reqPdu);

return reqPdu;

} // End of the method processRequestPDU()

 

After adding the desired code, compile the SimulatorPDUScrambler.java file. The compiled class file must be placed in <Simulator_Home>/conf directory.

 

Refer to 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( SnmpPDU resPDU ) in <Simulator_Home>/examples/pduscrambler/SimulatorPDUScrambler.java is used to customize the response PDU. 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.snmp.snmp2.SnmpPDU;

public class SimulatorPduScrambler implements SimPDUScramInterface {

 

/*Describe processResponsePDU method here. */

 

public SnmpPDU processResponsePDU(SnmpPDU respPdu)  {

 

/**

 * 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();

 

 

/* Here user can set the ErrorStatus and ErrorIndex vlaue in the PDU,for example */

// setErrorIndexAndErrorStatus((byte)1,byte(1),respPdu);

 

        return respPdu;

    } // End of the method processResponsePDU()

 

After adding the desired code, compile the SimulatorPDUScrambler.java file. The compiled class file must be placed in <Simulator_Home>/conf directory.

 

Refer to SNMP PDU Javadocs for customizing the response PDU.

Refer to SNMPScriptInterface.html to access the script API methods.

Copyright © 2012, ZOHO Corp. All Rights Reserved.
Network Monitoring Software from ManageEngine