Search

Building SNMP Trap Receiver Using Apache MINA

August 06, 2009


SNMP Trap is a message initiated by a Network Element to notify the Management Station of a significant event. Trap Receiver play a very crucial role in Fault Management Applications, by receiving and parsing the bytes into meaningful messages. In this article we shall discuss the implementation of a SNMP Trap receiver using Apache MINA (Multipurpose Infrastructure for Network Applications). Apache MINA is network application frameworks which help the users develop high performance and highly scalable network applications easily. It provides an abstract - event-driven - asynchronous API over various transports such as TCP/IP and UDP/IP via Java NIO.

The article focuses on developing a Trap Receiver using Apache MINA and available SNMP stacks like SNMP4J, joesnmp etc.

Introducing Apache MINA

Figure 1: Apache MINA Architecture

 Apache MINA is a simple, yet, full-featured network application framework which provides: 

  • Unified API for various transport types 
  • Filter interface as an extension point; similar to Servlet filters 
  • Low-level and high-level API got IO operations 
  • Highly customizable thread model 
  • Out-of-the-box SSL · TLS · StartTLS support using Java 5 SSLEngine 
  • Overload shielding & traffic throttling 
  • Unit testability using mock objects 
  • JMX manageability 
  • Stream-based I/O support via StreamIoHandler 
  • Integration with well known containers such as PicoContainer and Spring 
  • Smooth migration from Netty, an ancestor of Apache MINA. 

Desirable Implementation Aspects

 A “good” Trap Receiver should be able to handle sustained high Trap rate and have virtually no dependencies towards the SNMP stack used for decoding. Such a Trap Receiver should have: 

  • • Flexibility to use any available SNMP stack for Trap Decoding with minimal changes 
  • • Shall use SEDA (Staged Event Driven Architecture) based Design to achieve high throughput. 
  • • Able to handle a sustained a high Trap Rate (2000 Traps/Sec or greater) 

 Functional View of Trap Receiver Application 

 The figure below describes a high level Functional View of a Trap Receiver Processing Layer 

   

Figure 2: Functional View of Trap Receiver

 The conventional Trap Receiver implementation comprises of three layers with distinct functional role at each level: 

  • The Network layer is responsible for receiving the Trap packet from the network and passing onto next layer 
  • The Decoding Layer is responsible for converting the bytes into SNMP Trap representation 
  • The Processing Layer is responsible for processing the SNMP Trap, like persisting in database etc 

 In the conventional architecture, these three layers functions are performed using a single thread and many a times, a thread pool is used for higher performance. 

 Design aspects unique to HSC Trap Receiver 

  • Upon reception of raw packet, the packet shall be inserted in a receive Queue, without processing, in order to achieve high packet reception rate 
  • Decoding shall be done by separate threads, by picking the packets from the receive queue 
  • SNMP Packet decoder shall pass the processed packets to Packet processor which shall dump them into log files 

Architecture of a Custom Trap Receiver

This section describes the Architecture of HSC Trap Receiver. The architecture has been redefined to achieve high processing rate, along with minimum dependencies on any SNMP stacks. The steps briefly describe what all shall be needed: 

  • Receive UDP packets on the Socket and push them into input Queue without processing, to achieve a very high 
  • Thread pull the raw SNMP packet from the Queue in Step 1 and uses SNMP library to convert the packets into SNMP packets 
  • The SNMP packets are placed into Queue of subsequent stages. The stages are implemented as MINA I/O filters. An example of a Stage is OSSJ Converter in Figure 3: Architecture of HSC Trap Receiver 
  • The packets from Queue in Step 3 are picked up by Thread and Business processing is performed over the SNMP packets 

Figure 3: Architecture of HSC Trap Receiver

Apache MINA framework takes care of all IO related and housekeeping functions like creating input Queue and passing the message through the processing chain. 

With the IO infrastructure in place, we can concentrate on our prime Business Logic, of decoding the byte array into an SNMP messages. An implementation of MINA’s protocol Decoder shall convert bytes into SNMP object representation using SNMP4J. MINA ProtocolDecoder’s being the added into the protocol chain can easily be replaced with other implementation, without changing the remaining code. 

Sample SNMP4J based MINA codec is listed below 

With Protocol codec in place, its time to put the glue code in place 

SNMP Codec factory return a new instance of SNMP4JCodec. With SNMP4J codec added into Filter chain MINA uses the codec to decode the byte array into SNMP object of SNMP4J and pass onto next filter, and subsequently to IOHandler. 

 The SNMP4J codec can be easily replaced with joesnmp codec or Adventnet codec, by implementing a Protocol decoder using the library and returning the instance from ProtocolCodec factory class. 

 To use SEDA, Executors can be added in between filter’s to achieve threadpool based processing, within each filter/ 

 Advantages of the HSC Trap Receiver Architecture 

  • Ease of replacing the decoding function with other implementation, without changing core logic 
  • Easy Unit testing using MockObjects 
  • Adding features is easy adding filters to the Filter chain. 

  HSC Trap Receiver vs. Fault Management Frameworks 

  • Most of Fault Management frameworks come bundled with custom SNMP stacks, which limits the Users capability to use any custom stack for their applications 
  • Customization of FM tools is strictly governed by the extensibility of the tools. In our implementation, customization such as black listing IP’s etc can be achieved by adding I/O filter in the MINA IO Filter chain. 
  • MINA, can be embedded in Spring and PicoContainer, thus we can take full advantages of Clustering, Dependency Injection 

Summary

Apache MINA eases creation of high performance Network applications. The Design of HSC Trap Receiver, based on Apache MINA, makes it easy to use any SNMP stack in the Fault Management application. Additionally, the design based on IOFilter chain, gives flexibility in adding additional functionality like blacklisting IP, managing throughput without modifying the Decoding logic or Trap processing. Under the Test environment (Intel Core2 Duo 2.2 GHz, Windows XP, 1 GB RAM), the implementation achieved a sustained rate of 3000 Traps/sec without dropping any packets. 

References 

  •  http://mina.apache.org/ 
  •  http://www.eecs.harvard.edu/~mdw/proj/seda/ 
  •  http://www.snmp4j.org/ 
  •  http://sourceforge.net/projects/joesnmp/ 
  •  http://www.springframework.org/ 
  •  http://www.picocontainer.org/ 





1 Comments


  • Jan 26, 2015
    HR Admin
    This is a comment HERE

    Reply


Add Comment