i'm trying to create simple example of snmp manager and agent. all i need to do is just read the current value from given OID, write some new value to replace it, and read it back.
my get function working well but my set doesn't.
in the line: PDU responsePDU = event.getResponse();
responsePDU equal to null and i don't understand why?
any help will be very welcome!
public ResponseEvent set(OID oid,String val) throws IOException
{
PDU pdu = new PDU();
VariableBinding varBind = new VariableBinding(oid,new OctetString(val));
pdu.add(varBind);
pdu.setType(PDU.SET);
pdu.setRequestID(new Integer32(1));
Target target=getTargetForWrite();
ResponseEvent event = snmp.set(pdu, target);
if(event != null)
{
System.out.println("\nResponse:\nGot Snmp Set Response from Agent");
System.out.println("Snmp Set Request = " + event.getRequest().getVariableBindings());
PDU responsePDU = event.getResponse();
System.out.println("\nresponsePDU = "+responsePDU);
if (responsePDU != null)
{
int errorStatus = responsePDU.getErrorStatus();
int errorIndex = responsePDU.getErrorIndex();
String errorStatusText = responsePDU.getErrorStatusText();
System.out.println("\nresponsePDU = "+responsePDU);
if (errorStatus == PDU.noError)
{
System.out.println("Snmp Set Response = " + responsePDU.getVariableBindings());
}
else
{
System.out.println("errorStatus = "+responsePDU);
System.out.println("Error: Request Failed");
System.out.println("Error Status = " + errorStatus);
System.out.println("Error Index = " + errorIndex);
System.out.println("Error Status Text = " + errorStatusText);
}
}
return event;
}
throw new RuntimeException("GET timed out");
}
private Target getTargetForWrite()
{
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("private"));
target.setVersion(SnmpConstants.version2c);
target.setAddress(GenericAddress.parse(address));
target.setRetries(2);
target.setTimeout(1500);
return target;
}