<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ashish's Tech Blog &#187; SNMP</title>
	<atom:link href="http://www.ashishpaliwal.com/blog/tag/snmp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ashishpaliwal.com/blog</link>
	<description>From Programmer, For Programmers</description>
	<lastBuildDate>Tue, 17 Aug 2010 12:04:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Implementing SNMP4J Decoder for Apache MINA</title>
		<link>http://www.ashishpaliwal.com/blog/2008/10/implementing-snmp4j-decoder-for-apache-mina/</link>
		<comments>http://www.ashishpaliwal.com/blog/2008/10/implementing-snmp4j-decoder-for-apache-mina/#comments</comments>
		<pubDate>Sat, 11 Oct 2008 14:01:40 +0000</pubDate>
		<dc:creator>ashish</dc:creator>
				<category><![CDATA[Apache MINA]]></category>
		<category><![CDATA[Application Programming]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Network Management]]></category>
		<category><![CDATA[SNMP]]></category>
		<category><![CDATA[SNMP4J]]></category>

		<guid isPermaLink="false">http://www.ashishpaliwal.com/blog/?p=10</guid>
		<description><![CDATA[Recently started evaluating Apache MINA. So thought about building a Trap Receiver using Apache MINA. Refer to one of my posting on What is Apache MINA? Design In this post we shall concentrate on just writing the ProtocolDecoder The code snippet using SNMP4J library is public class SNMP4JCodec extends ProtocolDecoderAdapter { static Logger logger = LoggerFactory.getLogger(SNMP4JCodec.class); [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">Recently started evaluating Apache MINA. So thought about building a Trap Receiver using Apache MINA. Refer to one of my posting on <a href="http://www.ashishpaliwal.com/blog/2008/09/11/what-is-apache-mina/">What is Apache MINA?</a></p>
<div><span><strong>Design</strong></span></div>
<div><a href="http://3.bp.blogspot.com/_1X9TSfIQfXM/SMkET4LY59I/AAAAAAAAAC8/CbVNzkPENvo/s1600-h/snmp4jcodec.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img id="BLOGGER_PHOTO_ID_5244727980593833938" class="aligncenter" src="http://3.bp.blogspot.com/_1X9TSfIQfXM/SMkET4LY59I/AAAAAAAAAC8/CbVNzkPENvo/s320/snmp4jcodec.JPG" border="0" alt="" /></a></div>
<div>In this post we shall concentrate on just writing the ProtocolDecoder</div>
<div>The code snippet using SNMP4J library is</div>
<div>
<pre class="brush: java">
public class SNMP4JCodec extends ProtocolDecoderAdapter {

 static Logger logger = LoggerFactory.getLogger(SNMP4JCodec.class);

 public void decode(IoSession ioSession, IoBuffer ioBuffer,
                    ProtocolDecoderOutput protocolDecoderOutput) throws Exception {
     ByteBuffer pduBuffer = ioBuffer.buf();
     // Decode the bytes using SNMP4J API&#039;s
     PDU pdu = new PDU();
     try {
         BERInputStream berStream = new BERInputStream(pduBuffer);
         BER.MutableByte mutableByte = new BER.MutableByte();
         int length = BER.decodeHeader(berStream, mutableByte);
         int startPos = (int)berStream.getPosition();

         if (mutableByte.getValue() != BER.SEQUENCE) {
           String txt = &quot;SNMPv2c PDU must start with a SEQUENCE&quot;;
           throw new IOException(txt);
         }
         Integer32 version = new Integer32();
         version.decodeBER(berStream);

         // decode community string
         OctetString securityName = new OctetString();
         securityName.decodeBER(berStream);

         // decode the remaining PDU
         pdu.decodeBER(berStream);
         logger.debug(&quot;PDU - &quot;+pdu);
     } catch (Exception ex) {
         ex.printStackTrace();
     }
     protocolDecoderOutput.write(pdu);
 }
}
</pre>
<p>The code converts ByteBuffer into an SNMP PDU using SNMP4J  library. Similarly, we can use Adventnet or joesnmp to convert the byte stream into SNMP PDU's</p>
<p>NOTE: Custome Error handling need to be implemented, as per the strategy</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.ashishpaliwal.com/blog/2008/10/implementing-snmp4j-decoder-for-apache-mina/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
