Neil Cohen | 1 Mar 2011 16:49
Picon
Favicon

Invalid trap checksum??

I have created a java program using SNMP4J which generates and sends an 
SNMP v1 trap. The basic code looks like this:

private void sendTrap(String alertMsg) {
         OID oid = new OID("1.2.3.4.5.2");

         try {
             PDUv1 pdu = new PDUv1();
             pdu.setType(PDU.V1TRAP);
             pdu.setAgentAddress(new IpAddress("2.2.2.2"));
             pdu.setGenericTrap(PDUv1.ENTERPRISE_SPECIFIC);
             pdu.setSpecificTrap(1);
             pdu.setEnterprise(oid);
             pdu.add(new VariableBinding(oid, new OctetString(alertMsg)));

             CommunityTarget comTarget = new CommunityTarget();
             comTarget.setCommunity(new OctetString(snmpCommunity));
             comTarget.setVersion(SnmpConstants.version1);
             comTarget.setAddress(new UdpAddress("1.2.3.4/162"));    // 
Host address is actuall a valid address...
             comTarget.setRetries(2);
             comTarget.setTimeout(5000);

             TransportMapping transport = new DefaultUdpTransportMapping();

             Snmp snmp = new Snmp(transport);
             snmp.send(pdu, comTarget);
             snmp.close();
             transport.close();
             transport = null;
(Continue reading)

Jochen Katz | 1 Mar 2011 21:02
Favicon

Re: Invalid trap checksum??

Hi,

> I ran tcpdump on the receiving system and got this:

are you sure that this was on the receiving system?

> [root <at> nbc-verisign ~]# tcpdump -vvv port 162
> tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 
> 65535 bytes
> 10:41:34.724763 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto 
> UDP (17), length 357)
>      nbc.vrsn.com.49834 > 1.2.3.4.snmp: [bad udp cksum 52d!]{ SNMPv1 
> C=<communityString> { Trap(310)  .2.11etc. etc.
> 
> The incoming string looks to be correct. But I'm concerned about the 
> 'bad udp cksum' section. Is there a way to create the checksum before 
> the message is sent? If not, what would be the error here, and how do I 
> correct it??

As the application is not responsible for the UDP checksum, you cannot
correct it in the application.

With not too old hardware, the network card generates the checksum,
therefore the network stack of the operating system passes packets with
invalid checksums to the network card. So on the sending system, tcpdump
will allways report an invalid checksum.

Regards,
  Jochen
(Continue reading)

Giuseppe Sarno | 2 Mar 2011 23:21
Favicon

Setting Local port in DefaultUdpTransport causes null responses.

Hello,
new to SNMP and to this API.
I am trying to use code snippet from http://www.snmp4j.org/doc/org/snmp4j/Snmp.html to build a SNMP
manager that sends a SET between 2 nodes (SNMP4J 1.11.2).
I use Java executors to invoke the task that will actually perform the work. I noticed that this works ok if I
don't set the LocalPort in the UDP transport.
I actually would like to fix the port to a specific value so I set it in the transport constructor.
Unfortunately after this change the PDU response is always "null".
Messages are correctly sent and replied back (checked with wireshark). I am not too sure whether there is
any threading issue as the transport is bound to a specific port or simply my code is not correct.

Can anybody please let me know if there is any problem with this approach and what the problme could be ?

Thanks.

 
The task will:

1)  Creates DefaultUdpTransportMapping (note I need to set the local port and I to add to set the option
"reuse" to true as I was getting bind exception)

	DefaultUdpTransportMapping(new UdpAddress(InetAddress.getLocalHost(),localport),true);

2)  Creates community target.

    	CommunityTarget comtarget = new CommunityTarget();
    	comtarget.setCommunity(new OctetString(community));
    	comtarget.setVersion(snmpVersion);
   	comtarget.setAddress(new UdpAddress(ip + "/" + port));
    	comtarget.setRetries(0);
(Continue reading)

Frank Fock | 2 Mar 2011 23:30
Favicon

Re: Setting Local port in DefaultUdpTransport causes null responses.

Hi,

You need to close the transport in order
to be able to bind the port again.
The OS might block a rebind for several
seconds/minutes.

What are you trying to test/show with
the code?

Why do you want to specify a specific
local port? (I do not recommend that
for several reasons)

Best regards,
Frank

On 02.03.2011 23:21, Giuseppe Sarno wrote:
> Hello,
> new to SNMP and to this API.
> I am trying to use code snippet from http://www.snmp4j.org/doc/org/snmp4j/Snmp.html to build a SNMP
manager that sends a SET between 2 nodes (SNMP4J 1.11.2).
> I use Java executors to invoke the task that will actually perform the work. I noticed that this works ok if I
don't set the LocalPort in the UDP transport.
> I actually would like to fix the port to a specific value so I set it in the transport constructor.
Unfortunately after this change the PDU response is always "null".
> Messages are correctly sent and replied back (checked with wireshark). I am not too sure whether there is
any threading issue as the transport is bound to a specific port or simply my code is not correct.
>
> Can anybody please let me know if there is any problem with this approach and what the problme could be ?
(Continue reading)

Giuseppe Sarno | 2 Mar 2011 23:44
Favicon

Re: Setting Local port in DefaultUdpTransport causes null responses.

Hello,
one of the reason is because I would like agents to reply to this specific port (Firewall etc.)

Thanks.

-----Original Message-----
From: snmp4j-bounces@...
[mailto:snmp4j-bounces@...] On Behalf Of Frank Fock
Sent: 02 March 2011 22:30
To: snmp4j@...
Subject: Re: [SNMP4J] Setting Local port in DefaultUdpTransport causes null responses.

Hi,

You need to close the transport in order to be able to bind the port again.
The OS might block a rebind for several
seconds/minutes.

What are you trying to test/show with
the code?

Why do you want to specify a specific
local port? (I do not recommend that
for several reasons)

Best regards,
Frank

On 02.03.2011 23:21, Giuseppe Sarno wrote:
> Hello,
(Continue reading)

Frank Fock | 3 Mar 2011 00:13
Favicon

Re: Setting Local port in DefaultUdpTransport causes null responses.

OK, understood. But then it does not make
sense to open and close the port after
one request/response pair.

On 02.03.2011 23:44, Giuseppe Sarno wrote:
> Hello,
> one of the reason is because I would like agents to reply to this specific port (Firewall etc.)
>
> Thanks.
>
> -----Original Message-----
> From: snmp4j-bounces@...
[mailto:snmp4j-bounces@...] On Behalf Of Frank Fock
> Sent: 02 March 2011 22:30
> To: snmp4j@...
> Subject: Re: [SNMP4J] Setting Local port in DefaultUdpTransport causes null responses.
>
> Hi,
>
> You need to close the transport in order to be able to bind the port again.
> The OS might block a rebind for several
> seconds/minutes.
>
> What are you trying to test/show with
> the code?
>
> Why do you want to specify a specific
> local port? (I do not recommend that
> for several reasons)
>
(Continue reading)

Giuseppe Sarno | 3 Mar 2011 00:28
Favicon

Re: Setting Local port in DefaultUdpTransport causes null responses.

Yes, absolutely,
I was trying to achieve both. I guess the problem could be that the socket is sending and receiving response
on the same local port.

-----Original Message-----
From: Frank Fock [mailto:fock@...] 
Sent: 02 March 2011 23:13
To: Giuseppe Sarno
Cc: snmp4j@...
Subject: Re: [SNMP4J] Setting Local port in DefaultUdpTransport causes null responses.

OK, understood. But then it does not make sense to open and close the port after one request/response pair.

On 02.03.2011 23:44, Giuseppe Sarno wrote:
> Hello,
> one of the reason is because I would like agents to reply to this 
> specific port (Firewall etc.)
>
> Thanks.
>
> -----Original Message-----
> From: snmp4j-bounces@...
[mailto:snmp4j-bounces@...] 
> On Behalf Of Frank Fock
> Sent: 02 March 2011 22:30
> To: snmp4j@...
> Subject: Re: [SNMP4J] Setting Local port in DefaultUdpTransport causes null responses.
>
> Hi,
>
(Continue reading)

Giuseppe Sarno | 8 Mar 2011 23:18
Favicon

Snmp object reuse.

Hello,
I seem to have memory issue using the code below. I seem to have a large number of snmp instances (almost 1 per
message been sent).Same more the messageDispacherImpl.
I am wondering whether the snmp should be cached instead of created every single time. Is it enough to call
snmp.close() ?   

Thanks.

-----Original Message-----
From: snmp4j-bounces@...
[mailto:snmp4j-bounces@...] On Behalf Of Giuseppe Sarno
Sent: 02 March 2011 22:21
To: snmp4j@...
Subject: [SNMP4J] Setting Local port in DefaultUdpTransport causes null responses.

Hello,
new to SNMP and to this API.
I am trying to use code snippet from http://www.snmp4j.org/doc/org/snmp4j/Snmp.html to build a SNMP
manager that sends a SET between 2 nodes (SNMP4J 1.11.2).
I use Java executors to invoke the task that will actually perform the work. I noticed that this works ok if I
don't set the LocalPort in the UDP transport.
I actually would like to fix the port to a specific value so I set it in the transport constructor.
Unfortunately after this change the PDU response is always "null".
Messages are correctly sent and replied back (checked with wireshark). I am not too sure whether there is
any threading issue as the transport is bound to a specific port or simply my code is not correct.

Can anybody please let me know if there is any problem with this approach and what the problme could be ?

Thanks.

(Continue reading)

Frank Fock | 8 Mar 2011 23:34
Favicon

Re: Snmp object reuse.

Hi,

You should reuse a Snmp instance for subsequent requests.
Creating and closing/destroying it for each request
is overkill and guarantees bad performance and other
issues on OS level (running out of ports, etc.)

Best regards
Frank

On 08.03.2011 23:18, Giuseppe Sarno wrote:
> Hello,
> I seem to have memory issue using the code below. I seem to have a large number of snmp instances (almost 1 per
message been sent).Same more the messageDispacherImpl.
> I am wondering whether the snmp should be cached instead of created every single time. Is it enough to call
snmp.close() ?
>
> Thanks.
>
>
> -----Original Message-----
> From: snmp4j-bounces@...
[mailto:snmp4j-bounces@...] On Behalf Of Giuseppe Sarno
> Sent: 02 March 2011 22:21
> To: snmp4j@...
> Subject: [SNMP4J] Setting Local port in DefaultUdpTransport causes null responses.
>
> Hello,
> new to SNMP and to this API.
> I am trying to use code snippet from http://www.snmp4j.org/doc/org/snmp4j/Snmp.html to build a SNMP
(Continue reading)

Giuseppe Sarno | 8 Mar 2011 23:49
Favicon

Re: Snmp object reuse.

Thanks,

So should smnp.close() not be invoked when the snmp object is reused or should it still be called ?

-----Original Message-----
From: snmp4j-bounces@...
[mailto:snmp4j-bounces@...] On Behalf Of Frank Fock
Sent: 08 March 2011 22:34
To: snmp4j@...
Subject: Re: [SNMP4J] Snmp object reuse.

Hi,

You should reuse a Snmp instance for subsequent requests.
Creating and closing/destroying it for each request is overkill and guarantees bad performance and other
issues on OS level (running out of ports, etc.)

Best regards
Frank

On 08.03.2011 23:18, Giuseppe Sarno wrote:
> Hello,
> I seem to have memory issue using the code below. I seem to have a large number of snmp instances (almost 1 per
message been sent).Same more the messageDispacherImpl.
> I am wondering whether the snmp should be cached instead of created every single time. Is it enough to call
snmp.close() ?
>
> Thanks.
>
>
(Continue reading)


Gmane