[SNMP4J] Fwd: Re: Fwd: processPdu does not receive all the traps

jctaboada jctaboada at ntsp.nec.co.jp
Tue Mar 16 05:33:21 CET 2010


Hi Frank,

Thank you for the response.

With the possible causes you pointed out, please see below for my reply:

 * UDP buffer overflow - how do I prevent this? do you have any
suggestions? I'm using Windows for my manager.
 * main task finishes too early - I've used a while loop so process will
not end after opening the port to listen and will continue to receive the
traps
 * errors in your queueing stuff - I've used a success flag to count how
many traps are received by processPdu before the queue

Also, is it possible that processPdu has a performance limitation?
processPdu receives the alarms in 7 seconds but losses occurs and trap
losses occur in the middle part of the traps.
First traps and end traps are successully received. 
Before I forget, I'm using snmp4j version 1.10.0 for my manager.

Best regards,
JC


On Tue, 16 Mar 2010 01:07:47 +0100, Frank Fock <fock at agentpp.com> wrote:
> Hi,
> 
> There are many possible causes:
> 
> * UDP buffer overflow
> * main task finishes too early
> * errors in your queuing stuff
> ...
> 
> Regards,
> Frank
> 
> On 16.03.2010 00:29, jctaboada wrote:
>>
>>
>> -------- Original Message --------
>> Subject: processPdu does not receive all the traps
>> Date: Mon, 15 Mar 2010 20:22:52 +0800
>> From: jctaboada<jctaboada at ntsp.nec.co.jp>
>> To: "snmp4j at agentpp.org"<snmp4j at agentpp.org>
>>
>> Good day.
>>
>> Could someone help me why I cannot receive all the traps from my snmp
>> agent?
>> My snmp agent sends 27,000 traps to my manager but not all is received
in
>> the manager there are losses.
>> I've been using wireshark to check if my manager receives the 27,000
>> traps
>> and tcmdump to check if my agent sends the 27,000 trap.
>> For both wireshark and tcpdump, trap count is 27,000. Only in
processPdu
>> where all traps are not received.
>>
>> Please see my code below:
>>
>> public void initListen() throws UnknownHostException, IOException
>>      {
>>          logger_.debug("initListen start");
>>
>>          System.out.println("listen start");
>>          TransportMapping transport;
>>          int version = 3;
>>          USM usm = null;
>>          MultiThreadedMessageDispatcher dispatcher;
>>          ThreadPool threadPool;
>>
>>          threadPool = ThreadPool.create("Trap", 1);
>>          dispatcher = new MultiThreadedMessageDispatcher(threadPool,
new
>> MessageDispatcherImpl());
>>
>>          // initialize trap listen port
>>          transport = new DefaultUdpTransportMapping(
>>                  new UdpAddress("0.0.0.0/"+trapPort));
>>
>> //        session = new Snmp(transport);
>> //        session.getMessageDispatcher().addMessageProcessingModel(new
>> MPv3());
>>
>>          if(localEngineID == null)
>>          {
>>              localEngineID = new
OctetString(MPv3.createLocalEngineID());
>>          }
>>
>>          // add usm to session for snmp version 3
>>          if (version == SnmpConstants.version3)
>>          {
>>              usm = new USM(SecurityProtocols.getInstance(),
>>              localEngineID,
>> 0);
>>
>>              SecurityModels.getInstance().addSecurityModel(usm);
>>
>>              // adds all users to the USM
>>              UsmUser usmUser = null;
>>
>>              // check security level for usm user
>>              if (securityLevel == 0)
>>              {
>>                  usmUser = new UsmUser( new OctetString(user), null,
>>                  null,
>> null, null);
>>              }
>>              else if (securityLevel == 1 )
>>              {
>>                  usmUser = new UsmUser( new OctetString(user),
>>                  AuthSHA.ID,
>> new OctetString(password), null, null);
>>              }
>>              else if ( securityLevel == 2 )
>>              {
>>                  usmUser = new UsmUser( new OctetString(user),
>>                  AuthSHA.ID,
>> new OctetString(password), PrivAES128.ID, new OctetString(password));
>>              }
>>              usm.addUser(usmUser.getSecurityName(), usmUser);
>>          }
>>
>> System.out.println(usm.getUserTable().getUserEntries().toString());
>>
>>          dispatcher.addMessageProcessingModel(new MPv3(usm));
>>          SecurityProtocols.getInstance().addDefaultProtocols();
>>
>>          session = new Snmp(dispatcher, transport);
>>
>> //        ((MPv3) session.getMessageProcessingModel(MPv3.ID))
>> //        .setLocalEngineID(localEngineID.getValue());
>>
>>          session.addCommandResponder(this);
>>
>>          // initilize queue
>>          logQueue = new LinkedBlockingQueue<CommandResponderEvent>();
>>
>>          try {
>>              logger_.debug("listen start");
>>              // open port for trap
>>              session.listen();
>>              System.out.println("Ready to accept notifications.");
>>          } catch (UnknownHostException e1) {
>>              e1.printStackTrace();
>>              logger_.error(e1);
>>              logger_.debug("trap port fails");
>>              try
>>              {
>>                  logger_.debug("closing session");
>>                  session.close();
>>              }
>>              catch (IOException e3)
>>              {
>>                  e3.printStackTrace();
>>                  logger_.debug("close session fails");
>>                  logger_.error(e3);
>>              }
>>          } catch (IOException e1) {
>>              e1.printStackTrace();
>>              logger_.error(e1);
>>              logger_.debug("trap port fails");
>>              try
>>              {
>>                  logger_.debug("closing session");
>>                  session.close();
>>              }
>>              catch (IOException e4)
>>              {
>>                  e4.printStackTrace();
>>                  logger_.debug("close session fails");
>>                  logger_.error(e4);
>>              }
>>          }
>>          logger_.debug("initListen end");
>>      }
>>
>>      public synchronized void processPdu(CommandResponderEvent
comEvent)
>>      {
>>          logger_.debug("processPdu start");
>>
>>          boolean flag = false;
>>
>>          try
>>          {
>>              flag = logQueue.offer(comEvent);
>>              successflag++;
>>              System.out.println(successflag);
>>              if(flag)
>>              {
>>                  logger_.debug("offer success");
>>              }
>>              else
>>              {
>>                  logger_.error("offer fail");
>>              }
>>          }
>>          catch (NullPointerException e)
>>          {
>>              logger_.error(e);
>>              logger_.debug("offer fail");
>>          }
>>
>>          logger_.debug("processPdu end");
>>      }
>>
>>      public void getFromQueue()
>>      {
>>          logger_.debug("getFromQueue start");
>>
>>          CommandResponderEvent event = null;
>>
>>          PDU pdu = null;
>>
>>          while(!logQueue.isEmpty())
>>          {
>>              try
>>              {
>>                  event = logQueue.take();
>>                  logger_.debug("take end");
>>              }
>>              catch (InterruptedException e)
>>              {
>>                  logger_.debug("take fails");
>>                  logger_.error(e);
>>              }
>>
>>              pdu = event.getPDU();
>>
>>              if(pdu != null)
>>              {
>>                  if(logger_.isDebugEnabled())
>>                  {
>>                      logger_.debug("pdu is not null");
>>                      System.out.println("Trap received = " +
>> pdu.getVariableBindings());
>>                  }
>>                  logger_.info(pdu.getVariableBindings());
>> //                logger_.info(event);
>>              }
>>              else
>>              {
>>                  logger_.info("pdu is null");
>>              }
>>          }
>>
>>          logger_.debug("getFromQueue end");
>>      }
>>
>> Please give me some advice on how to fix this.
>>
>> Best regards,
>>
>> JC
>> _______________________________________________
>> SNMP4J mailing list
>> SNMP4J at agentpp.org
>> http://lists.agentpp.org/mailman/listinfo/snmp4j



More information about the SNMP4J mailing list