[SNMP4J] Have some questions regarding to receive response PDU.
Frank Fock
fock at agentpp.com
Fri Jun 29 20:17:14 CEST 2007
Hi,
This is a classic FAQ. You have missed to
call Snmp.listen() to get the response(s).
Best regards,
Frank
Shangkuan chen wrote:
> Hi,
>
> I`m new in snmp4j-1.8.2 and I have some questions regarding to receive
> response PDU. I'm use PDU's getResponse() methods receive respose PDU ,
> but I receive "Null" object. I'm use Ethereal capture packet. I found it
> have request and request packet. So, I'm very equivocal it. This is my java
> code and Ethereal trace log.
>
> ##### It's my code.
> public static void main(String[] args) throws IOException {
>
> Address targetAddress = GenericAddress.parse("udp:
> 192.168.254.254/161");
>
> //Community Target
> CommunityTarget target = new CommunityTarget();
> target.setCommunity(new OctetString("public"));
> target.setAddress(targetAddress);
> target.setRetries(3);
> target.setTimeout(2000);
>
> // timeout in 2 seconds before a confirmed request is resent or
> timed out.
> target.setVersion(SnmpConstants.version2c);
>
> // SNMPv1/v2c GETNEXT PDU
> PDU pdu = new PDU();
> pdu.add(new VariableBinding(new OID(".1.3.6.1.2.1.1.1"))); //
> sysDescr
>
> pdu.setType(PDU.GETNEXT);
> // dump request PDU
> System.out.println(pdu.toString());
>
> Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
> ResponseEvent response = snmp.send(pdu, target);
>
> // extract the response PDU (could be null if timed out)
> PDU responsePDU = response.getResponse();
> if (responsePDU != null){
> System.out.println("Received response from: "+
> response.getPeerAddress());
> // dump response PDU
> VariableBinding[] v = responsePDU.toArray();
>
> System.out.println("no. of varbind:" + v.length);
> for (int i=0; i<v.length; i++) {
> System.out.println(v[i].getVariable().toString());
> System.out.println(v[i].getVariable().getSyntaxString());
> }
> }else{
> System.out.println("timed out");
> }
> }
> ######### It's a Ethereal trace log
> No. Time Source Destination Protocol
> Info
> 2 2.015120 192.168.254.7 192.168.254.254 SNMP
> GET-NEXT SNMPv2-MIB::sysDescr
>
> Frame 2 (84 bytes on wire, 84 bytes captured)
> Arrival Time: Jun 29, 2007 21:05:38.233249000
> Time delta from previous packet: 2.015120000 seconds
> Time since reference or first frame: 2.015120000 seconds
> Frame Number: 2
> Packet Length: 84 bytes
> Capture Length: 84 bytes
> Protocols in frame: eth:ip:udp:snmp
> Coloring Rule Name: UDP
> Coloring Rule String: udp
> Ethernet II, Src: Wistron_21:9b:44 (00:16:d3:21:9b:44), Dst: Cisco_71:71:b8
> (00:0f:23:71:71:b8)
> Destination: Cisco_71:71:b8 (00:0f:23:71:71:b8)
> Address: Cisco_71:71:b8 (00:0f:23:71:71:b8)
> .... ...0 .... .... .... .... = Multicast: This is a UNICAST frame
> .... ..0. .... .... .... .... = Locally Administrated Address: This
> is a FACTORY DEFAULT address
> Source: Wistron_21:9b:44 (00:16:d3:21:9b:44)
> Address: Wistron_21:9b:44 (00:16:d3:21:9b:44)
> .... ...0 .... .... .... .... = Multicast: This is a UNICAST frame
> .... ..0. .... .... .... .... = Locally Administrated Address: This
> is a FACTORY DEFAULT address
> Type: IP (0x0800)
> Internet Protocol, Src: 192.168.254.7 (192.168.254.7), Dst:
> 192.168.254.254(
> 192.168.254.254)
> Version: 4
> Header length: 20 bytes
> Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00)
> 0000 00.. = Differentiated Services Codepoint: Default (0x00)
> .... ..0. = ECN-Capable Transport (ECT): 0
> .... ...0 = ECN-CE: 0
> Total Length: 70
> Identification: 0xb9d1 (47569)
> Flags: 0x00
> 0... = Reserved bit: Not set
> .0.. = Don't fragment: Not set
> ..0. = More fragments: Not set
> Fragment offset: 0
> Time to live: 128
> Protocol: UDP (0x11)
> Header checksum: 0x027e [correct]
> Good: True
> Bad : False
> Source: 192.168.254.7 (192.168.254.7)
> Destination: 192.168.254.254 (192.168.254.254)
> User Datagram Protocol, Src Port: 1621 (1621), Dst Port: snmp (161)
> Source port: 1621 (1621)
> Destination port: snmp (161)
> Length: 50
> Checksum: 0xd47c [correct]
> Simple Network Management Protocol
> Version: 2C (1)
> Community: public
> PDU type: GET-NEXT (1)
> Request Id: 0x29f4f1e2
> Error Status: NO ERROR (0)
> Error Index: 0
> Object identifier 1: 1.3.6.1.2.1.1.1 (SNMPv2-MIB::sysDescr)
> Value: NULL
>
> No. Time Source Destination Protocol
> Info
> 3 2.022010 192.168.254.254 192.168.254.7 SNMP
> RESPONSE SNMPv2-MIB::sysDescr.0
>
> Frame 3 (326 bytes on wire, 326 bytes captured)
> Arrival Time: Jun 29, 2007 21:05:38.240139000
> Time delta from previous packet: 0.006890000 seconds
> Time since reference or first frame: 2.022010000 seconds
> Frame Number: 3
> Packet Length: 326 bytes
> Capture Length: 326 bytes
> Protocols in frame: eth:ip:udp:snmp
> Coloring Rule Name: UDP
> Coloring Rule String: udp
> Ethernet II, Src: Cisco_71:71:b8 (00:0f:23:71:71:b8), Dst: Wistron_21:9b:44
> (00:16:d3:21:9b:44)
> Destination: Wistron_21:9b:44 (00:16:d3:21:9b:44)
> Address: Wistron_21:9b:44 (00:16:d3:21:9b:44)
> .... ...0 .... .... .... .... = Multicast: This is a UNICAST frame
> .... ..0. .... .... .... .... = Locally Administrated Address: This
> is a FACTORY DEFAULT address
> Source: Cisco_71:71:b8 (00:0f:23:71:71:b8)
> Address: Cisco_71:71:b8 (00:0f:23:71:71:b8)
> .... ...0 .... .... .... .... = Multicast: This is a UNICAST frame
> .... ..0. .... .... .... .... = Locally Administrated Address: This
> is a FACTORY DEFAULT address
> Type: IP (0x0800)
> Internet Protocol, Src: 192.168.254.254 (192.168.254.254), Dst:
> 192.168.254.7 (192.168.254.7)
> Version: 4
> Header length: 20 bytes
> Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00)
> 0000 00.. = Differentiated Services Codepoint: Default (0x00)
> .... ..0. = ECN-Capable Transport (ECT): 0
> .... ...0 = ECN-CE: 0
> Total Length: 312
> Identification: 0x02b5 (693)
> Flags: 0x00
> 0... = Reserved bit: Not set
> .0.. = Don't fragment: Not set
> ..0. = More fragments: Not set
> Fragment offset: 0
> Time to live: 255
> Protocol: UDP (0x11)
> Header checksum: 0x39a8 [correct]
> Good: True
> Bad : False
> Source: 192.168.254.254 (192.168.254.254)
> Destination: 192.168.254.7 (192.168.254.7)
> User Datagram Protocol, Src Port: snmp (161), Dst Port: 1621 (1621)
> Source port: snmp (161)
> Destination port: 1621 (1621)
> Length: 292
> Checksum: 0x984f [correct]
> Simple Network Management Protocol
> Version: 2C (1)
> Community: public
> PDU type: RESPONSE (2)
> Request Id: 0x29f4f1e2
> Error Status: NO ERROR (0)
> Error Index: 0
> Object identifier 1: 1.3.6.1.2.1.1.1.0 (SNMPv2-MIB::sysDescr.0)
> Value: STRING: Cisco IOS Software, C831 Software (C831-K9O3SY6-M),
> Version 12.4(1a), RELEASE SOFTWARE (fc2)
> Technical Support: http://www.cisco.com/techsupport
> Copyright (c) 1986-2005 by Cisco Systems, Inc.
> Compiled Fri 27-May-05 23:56
> ##### End trace log
>
>
> Can anyone tell me what I am missing here?
> Thanks
>
> Adam
> _______________________________________________
> 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