[SNMP4J] Detect the receiving SNMP Message

Andrew Chan wingnin at gmail.com
Tue Sep 27 01:34:23 CEST 2005


Hi Frank,
  Yes!! It works! Thank a lot!!
 Best Regards,
Andrew

 On 9/27/05, Frank Fock <fock at agentpp.com> wrote:
>
> It is a "sender problem". Once again the Snmp.listen() is missing, isn't
> it?
>
> Frank
>
> Andrew Chan wrote:
>
> > Hi Frank,
> >
> > Amm... I tried the following but the same timeout problem happen
> >
> > to simplify the case, I modify my code as follow (BTW, I use SNMP v1)
> >
> > public synchronized void processPdu(CommandResponderEvent e) {
> > PDU command = e.getPDU();
> > if (command != null) {
> > MessageDispatcher md = e.getMessageDispatcher();
> > md.returnResponsePdu(e.getMessageProcessingModel(),
> > e.getSecurityModel(), e.getSecurityName(), e.getSecurityLevel(),
> > command, e.getMaxSizeResponsePDU(), e.getStateReference(), null);
> >
> > }
> > }
> >
> > Just in case you think might be the sender's problem, I also include
> > the code (simplified) here FYI
> >
> >
> > private static void sendTestSnmp()
> > {
> > CommunityTarget target = createCommunityTarget();
> >
> > try {
> > PDU pdu = new PDU();
> > pdu.add(new VariableBinding(MY_OID));
> >
> > pdu.setType(PDU.GET);
> >
> > Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
> >
> > ResponseEvent response = snmp.send(pdu, target);
> > if (response.getResponse() == null) {
> > // request timed out
> > System.out.println("Request " + pdu + " timed out");
> > }
> > else {
> > System.out.println("Received response from: "+
> > response.getPeerAddress ());
> > // dump response PDU
> > System.out.println(response.getResponse().toString());
> > }
> > } catch (Exception e) {
> > e.printStackTrace();
> > }
> >
> > }
> >
> >
> >
> >
> >
> >
> > On 9/27/05, *Frank Fock* <fock at agentpp.com <mailto:fock at agentpp.com>>
> > wrote:
> >
> > OK, to send a response it would be more straight forward to use
> > the MessageDispatcher.returnResponsePdu (..) method directly.
> >
> > Best regards,
> > Frank
> >
> > Andrew Chan wrote:
> >
> > > Hi Frank,
> > >
> > > I did, actually below are what I set for the repond pdu.
> > >
> > > public synchronized void processPdu(CommandResponderEvent e) {
> > > PDU command = e.getPDU();
> > > sendRespond(e, command);
> > > }
> > >
> > > private void sendRespond(CommandResponderEvent e, PDU command)
> > > {
> > > CommunityTarget target = createCommunityTarget(
> > e.getPeerAddress());
> > >
> > > PDU pdu = new PDU();
> > > pdu.add(new VariableBinding(new OID(My_OID), variable)); //please
> > > assume MY_OID and the variable has been set somewhere
> > > pdu.setType (PDU.RESPONSE); //Here I set the PDU type to RESPOND
> > > pdu.setRequestID(command.getRequestID()); //Here I set the
> > Request ID
> > >
> > > //Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
> > > Snmp snmp = new Snmp( e.getTransportMapping()); //I even set the
> > > TransportMapping
> > >
> > > snmp.send(pdu, target);
> > > }
> > >
> > > private CommunityTarget createCommunityTarget(Address addr)
> > > {
> > > CommunityTarget target = new CommunityTarget();
> > > target.setCommunity(new OctetString("public"));
> > > target.setAddress(addr);
> > > target.setVersion(SnmpConstants.version1);
> > >
> > > return target;
> > > }
> > >
> > > Do you have any idea? Thanks.
> > >
> > > Regards,
> > > Andrew
> > >
> > >
> > >
> > > On 9/27/05, *Frank Fock* <fock at agentpp.com
> > <mailto:fock at agentpp.com> <mailto:fock at agentpp.com
> > <mailto:fock at agentpp.com> >>
> > > wrote:
> > >
> > > You need probably to set the request ID of the response PDU
> > to the
> > > request
> > > ID you received.
> > >
> > > Best regards,
> > > Frank
> > >
> > > Andrew Chan wrote:
> > >
> > > > Thanks Frank,
> > > >
> > > > May I ask one more question? After I have recieved the SNMP
> > > Message,
> > > > I should construct an respond, right how do I do that? I try
> > > this by
> > > > sending a PDU.RESPOND type pdu to the
> > > > CommandResponderEvent.getPeerAddress(), but the manager
> > always got a
> > > > time out error, do you have any idea? Many thanks.
> > > >
> > > > Regards,
> > > > AC
> > > >
> > > >
> > > > On 9/27/05, *Frank Fock* <fock at agentpp.com
> > <mailto:fock at agentpp.com>
> > > <mailto: fock at agentpp.com <mailto:fock at agentpp.com>>
> > <mailto:fock at agentpp.com <mailto:fock at agentpp.com>
> > > <mailto:fock at agentpp.com <mailto:fock at agentpp.com>>>>
> > > > wrote:
> > > >
> > > > Hi Andrew,
> > > >
> > > > Just call
> > CommandResponderEvent.getMessageProcessingModel() and
> > > > you will
> > > > get the SNMP version.
> > > >
> > > > Best regards,
> > > > Frank
> > > >
> > > > Andrew Chan wrote:
> > > >
> > > > >Dear all,
> > > > > I am trying to writing code to receive SNMP request, I
> > > know how
> > > > to write
> > > > >it by referencing the example in Package org.snmp4j.
> > > However, how
> > > > do we know
> > > > >the SNMP version (v1, v2c or v3) of incoming message?
> > > > > What I am expecting is to get the "target" from the
> > > > CommandResponderEvent,
> > > > >but seems this is not the case.
> > > > > Am I doing something wrong?
> > > > > Thanks.
> > > > >AC
> > > > >_______________________________________________
> > > > >SNMP4J mailing list
> > > > > SNMP4J at agentpp.org <mailto:SNMP4J at agentpp.org>
> > <mailto:SNMP4J at agentpp.org <mailto:SNMP4J at agentpp.org>>
> > > <mailto:SNMP4J at agentpp.org <mailto:SNMP4J at agentpp.org>
> > <mailto: SNMP4J at agentpp.org <mailto:SNMP4J at agentpp.org>>>
> > > > > http://lists.agentpp.org/mailman/listinfo/snmp4j
> > > < http://lists.agentpp.org/mailman/listinfo/snmp4j>
> > > > >
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > > --
> > > > AGENT++
> > > > http://www.agentpp.com
> > > > http://www.mibexplorer.com < http://www.mibexplorer.com>
> > > > http://www.mibdesigner.com
> > > >
> > > >
> > > >
> > >
> > >
> > > --
> > > AGENT++
> > > http://www.agentpp.com
> > > http://www.mibexplorer.com
> > > http://www.mibdesigner.com <http://www.mibdesigner.com>
> > >
> > >
> > >
> >
> >
> > --
> > AGENT++
> > http://www.agentpp.com
> > http://www.mibexplorer.com
> > http://www.mibdesigner.com
> >
> >
> >
>
>
> --
> AGENT++
> http://www.agentpp.com
> http://www.mibexplorer.com
> http://www.mibdesigner.com
>
>
>



More information about the SNMP4J mailing list