[SNMP4J] Setting Local port in DefaultUdpTransport causes null responses.

Giuseppe Sarno giuseppe.sarno at genband.com
Thu Mar 3 00:28:30 CET 2011


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 at agentpp.com] 
Sent: 02 March 2011 23:13
To: Giuseppe Sarno
Cc: snmp4j at agentpp.org
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 at agentpp.org [mailto:snmp4j-bounces at agentpp.org] 
> On Behalf Of Frank Fock
> Sent: 02 March 2011 22:30
> To: snmp4j at agentpp.org
> 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,
>> 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);
>>      	 comtarget.setTimeout(100);
>>
>> 3)  Creates a PDU
>>
>>         PDU pdu = new PDU();
>>
>> 4) Creates SNMP with the UDP transport (above)
>>
>> 	Snmp snmp = new Snmp(this.getUDPTransport());
>>
>> 5) Sends and wait for the resposne:
>>
>> 	ResponseEvent response = snmp.set(pdu, comtarget);
>> 	// Process Agent Response
>> 	if (response != null)
>> 	{
>>      		>>   do work<<
>> 	}
>>
>> Excecutor that wraps the code above:
>>
>> ExecutorService threadExecutor = Executors.newFixedThreadPool( 
>> Data.POOL ); for ( int i=1;i<=100000;i++) {
>>    RunnableTask t = new RunnableTask(Integer.toString(i));
>>    threadExecutor.execute(t);
>> }
>>    threadExecutor.shutdown(); // shutdown worker threads } 
>> _______________________________________________
>> SNMP4J mailing list
>> SNMP4J at agentpp.org
>> http://lists.agentpp.org/mailman/listinfo/snmp4j
>

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




More information about the SNMP4J mailing list