[snmp] decoding traps from a mulit homed host - raw pdu listener

Nookala, Sridevi (Sridevi) snookala at alcatel-lucent.com
Wed Mar 19 12:57:08 GMT 2008


Dear westhawk,

 

In my code I am listening for traps on a specific port using Listening
context pool, I am using my own trap listener this way

 

New ListeningContextPool( port).addListener( listener);

 

Where listener = new MyRawPduListenerImp();

 

public class MyRawPduListenerImp implements RawPduListener

 {

      public void rawPduReceived(RawPduEvent evt)

      {

        try

        {

          //RawPduEvent is always undecoded

          //If it is an undecoded trap, then the version number, the
hostAddress and the byte array is available

 

          //The SNMP version number of the trap. The version is part of
an undecoded trap event.

 

          int version = evt.getVersion();

 

          //The IP address of the host where the trap came from. The
host address is part of an undecoded the trap event

.

          String host = evt.getHostAddress();

 

          //To decode an undecoded trap event, you create a context on
the fly and call processIncomingPdu

          //The context should contain all the parameters needed to
decode the message.

 

          if ( ( version == SnmpConstants.SNMP_VERSION_1 ) ||

               ( version == SnmpConstants.SNMP_VERSION_2c ) )

          {

              SnmpContextBasisFace context = getSnmpContext( host,
port,version );

 

              System.err.println("context is " + context.toString() );

 

              if( context instanceof SnmpContextv2c )

                ((SnmpContextv2c)context).setCommunity(
getCommunity(host) );

              else if (  context instanceof SnmpContext )

                ((SnmpContext)context).setCommunity( getCommunity(host)
);

 

              System.err.println("context again is " +
context.toString() );

 

              Pdu trapPdu =
context.processIncomingPdu(evt.getMessage());

         }

      }

      Catch(Exception e) { }

   }

 

  Now the trap sender for me is a multihomed host. So the "FROM ADDRESS"
got via evt.getHostAddress() is header. The actual instance address/
Ethernet address is not available until I have a PDU as it is one of the
varbinds.

 

  The trap pdu is not available unless I decode it and for decoding the
trap from raw byte array, I need the correct community. 

 

  I don't have the community for this Header IP. I have the community
configured only for each of its "interface address"

 

  So I kind of have a chicken / egg issue. I need the community to get
pdu on the fly and I do not know the community unless I have the pdu as
one of the varbinds is the interface address.

 

  Is there any way, I can get the actual interface address from
RawPduEvt and not the base address/ header ip

 

Thx,

Sri



More information about the snmp mailing list