[SNMP4J] GETBULK Problem
Ricardo Bandeira
ricardobandeira at clix.pt
Thu Mar 22 21:43:40 CET 2007
Hello,
I´m trying to use snmp4j to comunnicate with an DSLAM using snmpV2 . I make a simple example for make a GETBULK to a table of a MIB, and the Response is like a GETNEXT, I just have 1 result in the response.
If somebody knows who I do wrong please help. My client example is below.
public class client{
public client(){
}
public static void main(String[] args){
ResponseEvent response=null;
PDU responsePDU = null;
Vector vb = new Vector();
VariableBinding[] variableB = null;
try{
String NeIPaddress = "udp:"+args[0]+"/161";
System.out.println("NeIPaddress: "+NeIPaddress);
Address targetAddress = GenericAddress.parse(NeIPaddress);
TransportMapping transport = new DefaultUdpTransportMapping();
Snmp snmp = new Snmp(transport);
transport.listen();
//setting up target
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setAddress(targetAddress);
target.setRetries(4);
target.setTimeout(1500);
target.setVersion(SnmpConstants.version2c);
// creating PDU
PDU pdu = new PDU();
pdu.add(new VariableBinding(new OID("1.3.6.1.4.1.231.7.1.2.2.1.4.2.1.1.2.901")));
pdu.setType(PDU.GETBULK);
pdu.setNonRepeaters(0);
pdu.setMaxRepetitions(10);
response = snmp.send(pdu, target);
if (response.getResponse() == null) {
// request timed out
System.out.println("Requested Timed out");
}
else {
System.out.println("Received response from: "+response.getPeerAddress());
// dump response PDU
System.out.println(response.getResponse().toString());
responsePDU = response.getResponse();
vb = responsePDU.getVariableBindings();
System.out.println("Size: "+vb.size());
Iterator iter = vb.iterator();
while(iter.hasNext()){
VariableBinding v = (VariableBinding) iter.next();
System.out.println(v.getOid()+"\n"+v.getVariable().toString());
}catch(IOException e){
System.out.println("<Main Error: "+e);
}
}//main()
}//client
Regards,
Ricardo Bandeira
More information about the SNMP4J
mailing list