[SNMP4J] Multiple Send Requests Doesn't Works.

Frank Fock fock at agentpp.com
Wed Sep 10 20:24:08 CEST 2008


Hi,

You are reusing the PDU object without resetting
its request ID. If the request ID is zero or not
set SNMP4J will create an unique one. In your
case, for each PDU, the same request ID is used
and the agent ignores the additional requests
because it assumes that these are retries.

See also:
http://www.snmp4j.org/doc/org/snmp4j/PDU.html#setRequestID(org.snmp4j.smi.Integer32)

Best regards,
Frank


RAVI GUPTA wrote:
> Dear All,
> 
> I had written a program using snmp4j to set values in a SNMP agent, but when I run the program and send SNMP Set requests, only the first set request sets the value in the agent and other not. Can anybody tell me what is the problem in my code.
> 
> 
> import java.io.IOException;
> import org.snmp4j.CommunityTarget;
> import org.snmp4j.PDU;
> import org.snmp4j.Snmp;
> import org.snmp4j.mp.SnmpConstants;
> import org.snmp4j.smi.GenericAddress;
> import org.snmp4j.smi.Integer32;
> import org.snmp4j.smi.OID;
> import org.snmp4j.smi.OctetString;
> import org.snmp4j.smi.VariableBinding;
> import org.snmp4j.transport.DefaultUdpTransportMapping;
> 
> public class SNMP 
> {
>     private Snmp snmp;
>     private CommunityTarget target;
>     private PDU requestPDU;
>     
>     /**
>      * Create a new SNMP session.
>      * 
>      * @throws java.io.IOException - if session cannot be created successfully.
>      */
>     public SNMP() throws IOException
>     {
>         snmp = new Snmp(new DefaultUdpTransportMapping());
>         snmp.listen();
>         
>         target = new CommunityTarget();
>         target.setVersion(SnmpConstants.version1);
>         target.setRetries(3);
>         
>         requestPDU = new PDU();
>         requestPDU.setNonRepeaters(0);
>         requestPDU.add(new VariableBinding());
>     }
> 
>     /**
>      * Sends a SNMP set request to the specified target.
>      * @param address IP address of the target.
>      * @param objectID Object ID of the target.
>      * @param value Value to set.
>      * @throws java.io.IOException if the message could not be send.
>      */
>     public void send(String address, String objectID, int value) throws IOException
>     {
>         target.setCommunity(new OctetString("public"));
>         target.setAddress(GenericAddress.parse("udp:" + address + "/161"));
>         
>         requestPDU.setType(PDU.SET);
>         requestPDU.set(0, new VariableBinding(new OID(objectID), new Integer32(value)));
>         snmp.send(requestPDU, target);
>     }
>     
>     public void close() throws IOException
>     {
>         snmp.close();
>     }
>     
>     public static void main(String args[]) throws Exception
>     {
>         SNMP snmp = new SNMP();
>         snmp.send("10.20.50.232", ".1.3.6.1.4.1.33000.10.1.0" , 2);
>         snmp.send("10.20.50.232", ".1.3.6.1.4.1.33000.10.1.1" , 3);
>         snmp.send("10.20.50.232", ".1.3.6.1.4.1.33000.10.1.2" , 4);
>         snmp.send("10.20.50.232", ".1.3.6.1.4.1.33000.10.1.3" , 5);
>         snmp.send("10.20.50.232", ".1.3.6.1.4.1.33000.10.1.4" , 6);
>         snmp.send("10.20.50.232", ".1.3.6.1.4.1.33000.10.1.5" , 7);
>         snmp.close();
>     }
>     
> }
> 
> Thanks in Advance.
> 
> 
> 
> 
>       Add more friends to your messenger and enjoy! Go to http://in.messenger.yahoo.com/invite/
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j

-- 
AGENT++
http://www.agentpp.com
http://www.mibexplorer.com
http://www.mibdesigner.com




More information about the SNMP4J mailing list