You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
(7) |
Nov
(2) |
Dec
(1) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
|
Feb
|
Mar
(8) |
Apr
(1) |
May
|
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
2006 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2008 |
Jan
(2) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Arie O. <ao...@us...> - 2008-01-03 19:18:44
|
User: aozarov Date: 08/01/03 11:18:43 |
From: Arie O. <ao...@us...> - 2008-01-03 19:18:44
|
User: aozarov Date: 08/01/03 11:18:43 Modified: src/joesnmp/org/opennms/examples SimpleClient.java Log: Add set operation to the example Revision Changes Path |
From: Dimitris A. <an...@us...> - 2006-04-05 21:28:12
|
User: andd Date: 06/04/05 14:28:11 Modified: . CHANGELOG.txt build.xml build.properties Log: Make Arie Ozarov's changes, joesnmp release v0.3.4 Revision Changes Path 1.8 +3 -1 joesnmp/CHANGELOG.txt Index: CHANGELOG.txt =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/CHANGELOG.txt,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- CHANGELOG.txt 5 Apr 2005 17:34:15 -0000 1.7 +++ CHANGELOG.txt 5 Apr 2006 21:28:06 -0000 1.8 @@ -1,4 +1,6 @@ -- optimize BerEncoder (replace old copy with System.arraycopy) +v0.3.4, 2006 Apr 6 +--------------------------------------------------------------------- +- optimize BerEncoder (replace old copy with System.arraycopy) (Arie Ozarov) - Replace SnmpTimer with OptimizedTimer (does not perform linear search) - SnmpAgent will now provide SnmpPeer with the sender information instead of null - SnmpAgent response generated (for get/getnext/set) will use the caller snmp version 1.6 +11 -3 joesnmp/build.xml Index: build.xml =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/build.xml,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- build.xml 7 Oct 2004 14:09:39 -0000 1.5 +++ build.xml 5 Apr 2006 21:28:06 -0000 1.6 @@ -1,7 +1,7 @@ <?xml version="1.0" ?> <!-- ======================================================================== - $Id: build.xml,v 1.5 2004/10/07 14:09:39 andd Exp $ + $Id: build.xml,v 1.6 2006/04/05 21:28:06 andd Exp $ ======================================================================== --> <project name="joesnmp" default="build" basedir="."> @@ -33,7 +33,7 @@ </target> <target name="zip" depends="build-joesnmp" - description="-->create a distribution of joesnmp lib"> + description="--> create a distribution of joesnmp lib"> <mkdir dir="${output.dist}"/> <zip zipfile="${output.dist}/joesnmp-${joesnmp.version}.zip" update="false"> <zipfileset dir="." prefix="joesnmp-${joesnmp.version}"> @@ -66,6 +66,7 @@ <!-- joesnmp --> <!-- ============================================================ --> <property name="joesnmp.jar" value="joesnmp.jar"/> +<property name="joesnmp-examples.jar" value="joesnmp-examples.jar"/> <property name="joesnmp.java" value="${src.dir}/joesnmp"/> <property name="joesnmp.classes" value="${output.classes}/joesnmp"/> @@ -97,8 +98,15 @@ </filterset> </copy> <jar jarfile="${output.lib}/${joesnmp.jar}" manifest="${output.etc}/Manifest.mf"> - <fileset dir="${joesnmp.classes}"/> + <fileset dir="${joesnmp.classes}"> + <include name="org/opennms/protocols/**"/> + </fileset> </jar> + <jar jarfile="${output.lib}/${joesnmp-examples.jar}" manifest="${output.etc}/Manifest.mf"> + <fileset dir="${joesnmp.classes}"> + <include name="org/opennms/examples/**"/> + </fileset> + </jar> </target> <target name="clean-joesnmp" 1.8 +1 -1 joesnmp/build.properties Index: build.properties =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/build.properties,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- build.properties 10 Nov 2004 23:48:00 -0000 1.7 +++ build.properties 5 Apr 2006 21:28:06 -0000 1.8 @@ -1,3 +1,3 @@ # joesnmp version -joesnmp.version = 0.3.3 +joesnmp.version = 0.3.4 |
From: Arie O. <ao...@us...> - 2005-10-25 16:53:54
|
User: aozarov Date: 05/10/25 09:53:41 Added: src/joesnmp/org/opennms/examples SnmpBulkRequestExample.java Log: Added SnmpBulk request example Revision Changes Path 1.1 joesnmp/src/joesnmp/org/opennms/examples/SnmpBulkRequestExample.java Index: SnmpBulkRequestExample.java =================================================================== // //This file is part of the joeSNMP Java Library. // //joeSNMP is Copyright (C) 2002-2003 Blast Internet Services, Inc. All rights reserved. //joeSNMP is a derivative work, containing both original code, included code and modified //code that was published under the GNU Lesser General Public License. Copyrights for modified //and included code are below. // //Copyright (C) 1999-2001 Oculan Corp. All rights reserved. // //This library is free software; you can redistribute it and/or //modify it under the terms of the GNU Lesser General Public //License as published by the Free Software Foundation; either //version 2.1 of the License, or (at your option) any later version. // //This library is distributed in the hope that it will be useful, //but WITHOUT ANY WARRANTY; without even the implied warranty of //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //Lesser General Public License for more details. // //You should have received a copy of the GNU Lesser General Public //License along with this library; if not, write to the Free Software //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // //See: http://www.fsf.org/copyleft/lesser.html // //For more information contact: // joeSNMP Licensing <joe...@li...> // http://sourceforge.net/projects/joesnmp/ // package org.opennms.examples; import java.net.InetAddress; import org.opennms.protocols.snmp.SnmpHandler; import org.opennms.protocols.snmp.SnmpParameters; import org.opennms.protocols.snmp.SnmpPduBulk; import org.opennms.protocols.snmp.SnmpPduPacket; import org.opennms.protocols.snmp.SnmpPeer; import org.opennms.protocols.snmp.SnmpSMI; import org.opennms.protocols.snmp.SnmpSession; import org.opennms.protocols.snmp.SnmpSyntax; import org.opennms.protocols.snmp.SnmpVarBind; public class SnmpBulkRequestExample { public static void main(String st[]) throws Exception { if (st.length != 2) { System.out.println("Usage: java SnmpBulkRequestExample host oid..."); System.exit(0); } InetAddress remote = InetAddress.getByName(st[0]); SnmpPeer peer = new SnmpPeer(remote); peer.setPort(161); peer.setTimeout(5000); peer.setRetries(1); // it is actually number of tries SnmpParameters parms = peer.getParameters(); parms.setVersion(SnmpSMI.SNMPV2); parms.setReadCommunity("public"); final SnmpSession session = new SnmpSession(peer); session.setDefaultHandler(new SnmpHandler() { public void snmpTimeoutError(SnmpSession session, SnmpSyntax pdu) { System.out.println("SnmpTimeout"); synchronized (session) { session.notify(); } } public void snmpInternalError(SnmpSession session, int err, SnmpSyntax pdu) { System.out.println("InternalError"); synchronized (session) { session.notify(); } } public void snmpReceivedPdu(SnmpSession session, int command, SnmpPduPacket pdu) { int responseLength = pdu.getLength(); for (int i = 0; i < responseLength; i++) { SnmpVarBind varBind = pdu.getVarBindAt(i); System.out.println("Received value: " + varBind.getName() + "=" + varBind.getValue()); } synchronized (session) { session.notify(); } } }); SnmpVarBind[] vblist = new SnmpVarBind[st.length - 1]; for (int i = 1; i < st.length ; i++) vblist[i - 1] = new SnmpVarBind(st[i]); int nonRepeaters = 0; int maxRepitition = 100; // Change this to get a bigger/smaller result set SnmpPduPacket requestPDU = new SnmpPduBulk(nonRepeaters, maxRepitition, vblist); requestPDU.setRequestId(1); try { synchronized (session) { session.send(requestPDU); session.wait(); } } catch (InterruptedException e) { // do nothing } finally { session.close(); } } } |
From: Arie O. <ao...@us...> - 2005-07-11 16:48:21
|
User: aozarov Date: 05/07/11 09:48:15 Modified: src/joesnmp/org/opennms/protocols/snmp SnmpUtil.java Log: Exposing registerSyntax and getSyntaxObject as they can be useful by clients/agents Revision Changes Path 1.2 +5 -7 joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpUtil.java Index: SnmpUtil.java =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpUtil.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SnmpUtil.java 19 Sep 2004 23:01:11 -0000 1.1 +++ SnmpUtil.java 11 Jul 2005 16:48:15 -0000 1.2 @@ -30,7 +30,7 @@ // // Modifications: // -// $Id: SnmpUtil.java,v 1.1 2004/09/19 23:01:11 andd Exp $ +// $Id: SnmpUtil.java,v 1.2 2005/07/11 16:48:15 aozarov Exp $ // package org.opennms.protocols.snmp; @@ -40,8 +40,7 @@ /** * This class provides a set of utilities that may be used - * by other package members. This class is not accessable - * to non-package classes. + * by other package members. * * The util class maintains a dynamically created list of * SnmpSyntax object that is uses to lookup received @@ -58,8 +57,7 @@ * * @author <a href="mailto:we...@oc...">Brian Weaver</a> */ -class SnmpUtil - extends Object +public class SnmpUtil { /** * The array of dynamically registred SnmpSyntax objects @@ -87,7 +85,7 @@ * @return True if the object is successfully added * */ - static boolean registerSyntax(SnmpSyntax obj) + public static boolean registerSyntax(SnmpSyntax obj) { boolean rc = false; synchronized(m_syntaxArray) @@ -120,7 +118,7 @@ * @return A new SnmpSyntax object of the appropiate type * */ - static SnmpSyntax getSyntaxObject(byte asnType) + public static SnmpSyntax getSyntaxObject(byte asnType) { SnmpSyntax obj = null; switch(asnType) |
From: Arie O. <ao...@us...> - 2005-07-11 16:46:29
|
User: aozarov Date: 05/07/11 09:46:22 Added: src/joesnmp/org/opennms/examples SimpleClient.java SimpleAgent.java agent-mib.properties Log: Adding examples of an snmp agent and client Revision Changes Path 1.1 joesnmp/src/joesnmp/org/opennms/examples/SimpleClient.java Index: SimpleClient.java =================================================================== // //This file is part of the joeSNMP Java Library. // //joeSNMP is Copyright (C) 2002-2003 Blast Internet Services, Inc. All rights reserved. //joeSNMP is a derivative work, containing both original code, included code and modified //code that was published under the GNU Lesser General Public License. Copyrights for modified //and included code are below. // //Copyright (C) 1999-2001 Oculan Corp. All rights reserved. // //This library is free software; you can redistribute it and/or //modify it under the terms of the GNU Lesser General Public //License as published by the Free Software Foundation; either //version 2.1 of the License, or (at your option) any later version. // //This library is distributed in the hope that it will be useful, //but WITHOUT ANY WARRANTY; without even the implied warranty of //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //Lesser General Public License for more details. // //You should have received a copy of the GNU Lesser General Public //License along with this library; if not, write to the Free Software //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // //See: http://www.fsf.org/copyleft/lesser.html // //For more information contact: // joeSNMP Licensing <joe...@li...> // http://sourceforge.net/projects/joesnmp/ // package org.opennms.examples; import java.net.InetAddress; import org.opennms.protocols.snmp.SnmpHandler; import org.opennms.protocols.snmp.SnmpParameters; import org.opennms.protocols.snmp.SnmpPduPacket; import org.opennms.protocols.snmp.SnmpPduRequest; import org.opennms.protocols.snmp.SnmpPeer; import org.opennms.protocols.snmp.SnmpSMI; import org.opennms.protocols.snmp.SnmpSession; import org.opennms.protocols.snmp.SnmpSyntax; import org.opennms.protocols.snmp.SnmpVarBind; public class SimpleClient { public static void main(String st[]) throws Exception { if (st.length != 2) { System.out.println("Usage: java SimpleClient host oid"); System.exit(0); } InetAddress remote = InetAddress.getByName(st[0]); SnmpPeer peer = new SnmpPeer(remote); peer.setPort(161); peer.setTimeout(5000); peer.setRetries(1); // it is actually number of tries SnmpParameters parms = peer.getParameters(); parms.setVersion(SnmpSMI.SNMPV2); parms.setReadCommunity("public"); final SnmpSession session = new SnmpSession(peer); session.setDefaultHandler(new SnmpHandler() { public void snmpTimeoutError(SnmpSession session, SnmpSyntax pdu) { System.out.println("SnmpTimeout"); synchronized (session) { session.notify(); } } public void snmpInternalError(SnmpSession session, int err, SnmpSyntax pdu) { System.out.println("InternalError"); synchronized (session) { session.notify(); } } public void snmpReceivedPdu(SnmpSession session, int command, SnmpPduPacket pdu) { SnmpVarBind varBind = pdu.getVarBindAt(0); System.out.println("Received value: " + varBind.getName() + "=" + varBind.getValue()); synchronized (session) { session.notify(); } } }); SnmpVarBind[] vblist = {new SnmpVarBind(st[1])}; SnmpPduRequest pdu = new SnmpPduRequest(st[1].endsWith(".0") ? SnmpPduPacket.GET : SnmpPduPacket.GETNEXT, vblist); pdu.setRequestId(1); try { synchronized (session) { session.send(pdu); session.wait(); } } catch (InterruptedException e) { // do nothing } finally { session.close(); } } } 1.1 joesnmp/src/joesnmp/org/opennms/examples/SimpleAgent.java Index: SimpleAgent.java =================================================================== // // jSNMP - SNMPv1 & v2 Compliant Libraries for Java // Copyright (C) 2000 PlatformWorks, Inc. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // For more information contact: // Brian Weaver <we...@op...> // http://www.opennms.org/ // // joeSNMP Licensing <joe...@li...> // http://sourceforge.net/projects/joesnmp/ // package org.opennms.examples; import java.io.InputStream; import java.net.InetAddress; import java.util.ArrayList; import java.util.Comparator; import java.util.Iterator; import java.util.List; import java.util.Properties; import java.util.SortedMap; import java.util.StringTokenizer; import java.util.TreeMap; import org.opennms.protocols.snmp.SnmpAgentHandler; import org.opennms.protocols.snmp.SnmpAgentSession; import org.opennms.protocols.snmp.SnmpEndOfMibView; import org.opennms.protocols.snmp.SnmpInt32; import org.opennms.protocols.snmp.SnmpOctetString; import org.opennms.protocols.snmp.SnmpParameters; import org.opennms.protocols.snmp.SnmpPduBulk; import org.opennms.protocols.snmp.SnmpPduPacket; import org.opennms.protocols.snmp.SnmpPduRequest; import org.opennms.protocols.snmp.SnmpPeer; import org.opennms.protocols.snmp.SnmpSMI; import org.opennms.protocols.snmp.SnmpSyntax; import org.opennms.protocols.snmp.SnmpVarBind; import org.opennms.protocols.snmp.asn1.AsnEncodingException; public class SimpleAgent implements SnmpAgentHandler { private SnmpAgentSession m_session; private TreeMap m_mib = new TreeMap(new Comparator() { public int compare(Object o1, Object o2) { StringTokenizer stTokens1 = new StringTokenizer(o1.toString().trim(), "."); StringTokenizer stTokens2 = new StringTokenizer(o2.toString().trim(), "."); while (true) { if (stTokens1.hasMoreTokens()) { int value1 = Integer.parseInt(stTokens1.nextToken()); if (stTokens2.hasMoreTokens()) { int value2 = Integer.parseInt(stTokens2.nextToken()); if (value1 != value2) return value1 - value2; } else { return 1; } } else if (stTokens2.hasMoreTokens()) { return 1; } else { return 0; } } } }); private static SimpleAgent ms_agent; private static final boolean DEBUG = false; SimpleAgent(String mibProperties) throws Exception { SnmpPeer peer = new SnmpPeer(InetAddress.getLocalHost(), 161); SnmpParameters params = peer.getParameters(); params.setVersion(SnmpSMI.SNMPV2); params.setReadCommunity("public"); params.setWriteCommunity("public"); m_session = new SnmpAgentSession(this, peer); Properties pr = new Properties(); InputStream input = SimpleAgent.class.getResourceAsStream(mibProperties); pr.load(input); input.close(); for (Iterator i = pr.keySet().iterator(); i.hasNext();) { String oid = ((String) i.next()).trim(); String value = pr.getProperty(oid).trim(); if (value.startsWith("?")) { final long factor = value.equals("?") ? 1000 : Long.parseLong(value.substring(1)); m_mib.put(oid, new SnmpInt32() { private int counter; private long lastSec = System.currentTimeMillis() / factor; public SnmpSyntax duplicate() { SnmpInt32 dup = new SnmpInt32(); dup.setValue(getValue()); return dup; } public int getValue() { counter += System.currentTimeMillis() / factor - lastSec; lastSec = System.currentTimeMillis() / factor; return counter; } }); } else if (value.startsWith("#")) { StringTokenizer stTokens = new StringTokenizer(value.substring(1), ", "); final ArrayList list = new ArrayList(); while (stTokens.hasMoreTokens()) list.add(new Integer(stTokens.nextToken())); m_mib.put(oid, new SnmpInt32() { private int counter; public SnmpSyntax duplicate() { SnmpInt32 dup = new SnmpInt32(); dup.setValue(getValue()); return dup; } public int getValue() { int value = ((Integer) list.get(counter)).intValue(); counter = ++counter % list.size(); return value; } }); } else m_mib.put(oid, new SnmpOctetString(value.getBytes())); } } public void SnmpAgentSessionError(SnmpAgentSession session, int error, Object ref) { new Exception().printStackTrace(); System.exit(-1); } public void snmpReceivedPdu(SnmpAgentSession session, InetAddress manager, int port, SnmpOctetString community, SnmpPduPacket pdu) { if (pdu instanceof SnmpPduBulk) { SnmpPduRequest response = new SnmpPduRequest(SnmpPduRequest.RESPONSE); response.setRequestId(pdu.getRequestId()); doBulk(pdu.toVarBindArray(), pdu, response); try { session.send(new SnmpPeer(manager, port), response); } catch (AsnEncodingException ex) { try { response = new SnmpPduRequest(SnmpPduRequest.RESPONSE); response.setRequestId(pdu.getRequestId()); response.setErrorStatus(SnmpPduRequest.ErrTooBig); response.setErrorIndex(0); session.send(new SnmpPeer(manager, port), response); } catch (Exception exp) { exp.printStackTrace(); } } catch (Exception ex) { ex.printStackTrace(); } } else { if (DEBUG) System.out.println("snmpReceivedPdu was called (and ignored) -> " + manager + ", " + port + ", " + community + ", " + pdu.getClass().getName()); } } public SnmpPduRequest snmpReceivedGet(SnmpPduPacket pdu, boolean getNext) { if (DEBUG) System.out.println("snmpReceivedGet was called with -> " + pdu.getClass().getName() + ", getnext='" + getNext + "'"); SnmpVarBind[] binds = pdu.toVarBindArray(); SnmpPduRequest response = new SnmpPduRequest(SnmpPduRequest.RESPONSE); response.setRequestId(pdu.getRequestId()); if (binds.length > 20) { if (DEBUG) System.out.println(">> Responding with to Big -> " + pdu.getRequestId() + ", " + getOidList(binds)); response.setErrorStatus(SnmpPduRequest.ErrTooBig); response.setErrorIndex(0); return response; } if (pdu instanceof SnmpPduRequest) // treat as V1 { int errorIndex = 0; if (getNext) { if (DEBUG) System.out .println("snmpReceivedGet.getNext(" + pdu.getRequestId() + ", " + getOidList(binds) + ")"); for (int i = 0; i < binds.length; i++) { String oid = binds[i].getName().toString(); SortedMap map = m_mib.tailMap(oid + ".0"); if (!map.isEmpty()) { oid = (String) map.firstKey(); response.addVarBind(new SnmpVarBind(oid, (SnmpSyntax) map.get(oid))); } else { response.addVarBind(new SnmpVarBind(oid)); errorIndex = i + 1; break; } } } else { if (DEBUG) System.out.println("snmpReceivedGet.get(" + pdu.getRequestId() + ", " + getOidList(binds) + ")"); for (int i = 0; i < binds.length; i++) { String oid = binds[i].getName().toString(); SnmpSyntax value = (SnmpSyntax) m_mib.get(oid); if (value != null) { response.addVarBind(new SnmpVarBind(oid, value)); } else { response.addVarBind(new SnmpVarBind(oid)); errorIndex = i + 1; break; } } } if (errorIndex > 0) { if (DEBUG) System.out.println("snmpReceivedGet.get/getNext '" + pdu.getRequestId() + "' index '" + errorIndex + "' was not found"); response.setErrorStatus(SnmpPduRequest.ErrNoSuchName); response.setErrorIndex(errorIndex); } } else if (pdu instanceof SnmpPduBulk) // Treat as V2 { doBulk(binds, pdu, response); } else { if (DEBUG) System.out.println("snmpReceivedGet.unknownCMD"); response.setErrorStatus(SnmpPduRequest.ErrGenError); response.setErrorIndex(1); } return response; } private void doBulk(SnmpVarBind binds[], SnmpPduPacket pdu, SnmpPduRequest response) { if (DEBUG) System.out.println("snmpReceivedGet.getBulk(" + pdu.getRequestId() + ", " + getOidList(binds) + ")"); SnmpPduBulk bulk = (SnmpPduBulk) pdu; int nonRepeaters = bulk.getNonRepeaters(); int maxRep = bulk.getMaxRepititions(); for (int i = 0; i < Math.min(nonRepeaters, binds.length); i++) { String oid = binds[i].getName().toString(); SortedMap map = m_mib.tailMap(oid + ".0"); if (!map.isEmpty()) { oid = (String) map.firstKey(); response.addVarBind(new SnmpVarBind(oid, (SnmpSyntax) map.get(oid))); } else { response.addVarBind(new SnmpVarBind(oid, new SnmpEndOfMibView())); } } for (int i = nonRepeaters; i < binds.length; i++) { String oid = binds[i].getName().toString(); SortedMap map = m_mib.tailMap(oid + ".0"); if (!map.isEmpty()) { Iterator it = map.keySet().iterator(); for (int j = 0; j < maxRep; j++) { if (!it.hasNext()) { response.addVarBind(new SnmpVarBind(".1.9", new SnmpEndOfMibView())); break; } oid = (String) it.next(); response.addVarBind(new SnmpVarBind(oid, (SnmpSyntax) map.get(oid))); } } else { response.addVarBind(new SnmpVarBind(oid, new SnmpEndOfMibView())); } } } private static List getOidList(SnmpVarBind[] binds) { List list = new ArrayList(binds.length); for (int i = 0; i < binds.length; i++) list.add(binds[i].getName()); return list; } public SnmpPduRequest snmpReceivedSet(SnmpPduPacket pdu) { if (DEBUG) System.out.println("snmpReceivedSet was called with -> " + pdu.getClass().getName()); SnmpVarBind[] binds = pdu.toVarBindArray(); SnmpPduRequest response = new SnmpPduRequest(SnmpPduRequest.RESPONSE); int errorIndex = 0; response.setRequestId(pdu.getRequestId()); if (binds.length > 20) { if (DEBUG) System.out.println(">> Responding with to Big -> " + pdu.getRequestId() + ", " + getOidList(binds)); response.setErrorStatus(SnmpPduRequest.ErrTooBig); response.setErrorIndex(0); return response; } for (int i = 0; i < binds.length; i++) { String oid = binds[i].getName().toString(); SnmpSyntax newValue = binds[i].getValue(); SnmpSyntax value = (SnmpSyntax) m_mib.get(oid); if (DEBUG) System.out.println("oid value is -> " + oid + ", " + binds[i].getName()); if (DEBUG) System.out.println("old value is -> " + value); if (DEBUG) System.out.println("New value is -> " + newValue); if (value != null) { m_mib.put(oid, newValue); response.addVarBind(new SnmpVarBind(oid, newValue)); } else { response.addVarBind(new SnmpVarBind(oid)); errorIndex = i + 1; break; } } if (errorIndex > 0) { if (DEBUG) System.out.println("snmpReceivedSet '" + pdu.getRequestId() + "' index '" + errorIndex + "' was not found"); response.setErrorStatus(SnmpPduRequest.ErrNoSuchName); response.setErrorIndex(errorIndex); } return response; } public static void startAgent(String mibProperties) throws Exception { stopAgent(); System.out.println("Starting SNMP Agent on " + InetAddress.getLocalHost() + ":161 ...."); ms_agent = new SimpleAgent(mibProperties); } public static void stopAgent() { if (ms_agent != null) { if (DEBUG) System.out.println("Stoping SNMP Agent...."); ms_agent.m_session.close(); ms_agent = null; } } public static void main(final String st[]) throws Exception { startAgent(st.length == 0 ? "agent-mib.properties" : st[0]); Thread.currentThread().join(); } } 1.1 joesnmp/src/joesnmp/org/opennms/examples/agent-mib.properties Index: agent-mib.properties =================================================================== .1.3.6.1.2.1.1.1.0 1.1_value # vendor ID .1.3.6.1.2.1.1.2.0 CISCO .1.3.6.1.2.1.1.3.0 1.3_value .1.3.6.1.2.1.1.80.1.1.2 1.80.1.2_value .1.3.6.1.2.1.1.80.1.1.3 1.80.1.3_value .1.3.6.1.2.1.1.80.1.2.1 1.80.2.1_value .1.3.6.1.2.1.1.80.1.2.2 1.80.2.2_value .1.3.6.1.2.1.1.100.7.0 76 .1.3.6.1.2.1.2.0 1.2_value .1.3.6.1.2.1.2.1.0 5 .1.3.6.1.2.1.2.2.1.20.3 2.1.20.3_value .1.3.6.1.2.2.1.1.1 2.1.1_value .1.3.6.1.2.2.1.1.2 2.1.2_value .1.3.6.1.2.2.1.1.3 2.1.3_value .1.3.6.1.2.2.1.2.1 2.2.1_value .1.3.6.1.2.2.1.2.2 2.2.2_value .1.3.6.1.2.2.1.3.4 2.3.4_value .1.3.6.1.2.3.1.2.2 3.2.2_value .1.3.6.1.2.3.1.3.1 3.3.1_value .1.3.6.1.2.5.1.1.4.1.3.1 4.3.1_value .1.3.6.1.2.5.1.1.4.1.3.2 4.3.2_value .1.3.6.1.2.5.1.1.5.1.1.1 5.1.1_value .1.3.6.1.2.5.1.1.5.1.2.1 5.2.1_value .1.3.6.1.2.8.1.0 8.1_value .1.3.6.1.2.8.2.0 8.2_value .1.3.6.1.3.1.0 1 .1.3.6.1.3.2.0 2 .1.3.6.1.3.3.0 3 .1.3.6.1.4.1.0 ? .1.3.6.1.4.1.1 ? .1.3.6.1.4.1.2 ? .1.3.6.1.4.1.3 ? .1.3.6.1.4.1.4 ? .1.3.6.1.4.1.5 ? 1.3.6.1.2.1.69.1.1.3.0 0 |
From: Arie O. <ao...@us...> - 2005-04-05 17:34:19
|
User: aozarov Date: 05/04/05 10:34:11 joesnmp/src/joesnmp/org/opennms/examples - New directory |
From: Arie O. <ao...@us...> - 2005-03-23 14:17:07
|
User: aozarov Date: 05/03/23 06:16:59 Modified: src/joesnmp/org/opennms/protocols/snmp SnmpSession.java Added: src/joesnmp/org/opennms/protocols/snmp SnmpTimer.java Removed: src/joesnmp/org/opennms/protocols/snmp OptimizedSnmpTimer.java Log: Rename OptimizedSnmpTimer to the old SnmpTimer name Revision Changes Path 1.6 +4 -4 joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpSession.java Index: SnmpSession.java =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpSession.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- SnmpSession.java 22 Mar 2005 20:09:14 -0000 1.5 +++ SnmpSession.java 23 Mar 2005 14:16:59 -0000 1.6 @@ -30,7 +30,7 @@ // // Modifications: // -// $Id: SnmpSession.java,v 1.5 2005/03/22 20:09:14 aozarov Exp $ +// $Id: SnmpSession.java,v 1.6 2005/03/23 14:16:59 aozarov Exp $ // // 2005 Mar 21: ao...@ho... // Change interaction with SnmpRequest (deprecate the need for Cleanup task) @@ -155,7 +155,7 @@ * @see org.opennms.protocols.snmp.SnmpSession.CleanupRequest * @see SnmpRequest */ - private OptimizedSnmpTimer m_timer; + private SnmpTimer m_timer; /** * The default SNMP callback handler. If this is not @@ -498,7 +498,7 @@ * @return The internal timer object * */ - OptimizedSnmpTimer getTimer() + SnmpTimer getTimer() { return m_timer; } @@ -701,7 +701,7 @@ receiveBuffer, sendBuffer); - m_timer = new OptimizedSnmpTimer(); + m_timer = new SnmpTimer(); m_timer.schedule(new CleanupRequest(), EXPIRED_REQUEST_CLEANUP_FREQUENCY); } 1.4 +196 -307 joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpTimer.java |
From: Arie O. <ao...@us...> - 2005-03-22 20:09:39
|
User: aozarov Date: 05/03/22 12:09:17 Modified: src/joesnmp/org/opennms/protocols/snmp SnmpSession.java OptimizedSnmpTimer.java Log: Fix spelling mistake (cancle -> cancel) Revision Changes Path 1.5 +2 -2 joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpSession.java Index: SnmpSession.java =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpSession.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- SnmpSession.java 22 Mar 2005 19:02:28 -0000 1.4 +++ SnmpSession.java 22 Mar 2005 20:09:14 -0000 1.5 @@ -30,7 +30,7 @@ // // Modifications: // -// $Id: SnmpSession.java,v 1.4 2005/03/22 19:02:28 aozarov Exp $ +// $Id: SnmpSession.java,v 1.5 2005/03/22 20:09:14 aozarov Exp $ // // 2005 Mar 21: ao...@ho... // Change interaction with SnmpRequest (deprecate the need for Cleanup task) @@ -958,7 +958,7 @@ m_stopRun = true; } - m_timer.cancle(true); + m_timer.cancel(true); m_portal.close(); } 1.2 +3 -3 joesnmp/src/joesnmp/org/opennms/protocols/snmp/OptimizedSnmpTimer.java Index: OptimizedSnmpTimer.java =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/src/joesnmp/org/opennms/protocols/snmp/OptimizedSnmpTimer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- OptimizedSnmpTimer.java 22 Mar 2005 19:02:32 -0000 1.1 +++ OptimizedSnmpTimer.java 22 Mar 2005 20:09:16 -0000 1.2 @@ -75,9 +75,9 @@ * Cancel pending tasks and call interrupt on the thread of the current running task (if such exists) * @param waitForAll true if you want to wait until the current task is completed */ - public void cancle(boolean waitForAll) + public void cancel(boolean waitForAll) { - m_timerLogic.cancle(waitForAll); + m_timerLogic.cancel(waitForAll); } private static class TimerElement implements Comparable @@ -169,7 +169,7 @@ } } - public synchronized void cancle(boolean waitForAll) + public synchronized void cancel(boolean waitForAll) { if (m_isActive) { |
From: Arie O. <ao...@us...> - 2005-03-22 19:16:36
|
User: aozarov Date: 05/03/22 11:16:30 Removed: src/joesnmp/org/opennms/protocols/snmp SnmpTimer.java Log: Remove old and unused SnmpTimer (use OptimizedSnmpTimer instead) |
From: Arie O. <ao...@us...> - 2005-03-22 19:09:06
|
User: aozarov Date: 05/03/22 11:08:53 Added: .settings org.eclipse.jdt.ui.prefs Log: Add class header to eclipse settings Revision Changes Path 1.1 joesnmp/.settings/org.eclipse.jdt.ui.prefs Index: org.eclipse.jdt.ui.prefs =================================================================== #Fri Mar 18 14:29:15 EST 2005 eclipse.preferences.version=1 org.eclipse.jdt.ui.javadoc=false org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8"?><templates><template context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment"></template><template context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template><template context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">//\r\n//This file is part of the joeSNMP Java Library.\r\n//\r\n//joeSNMP is Copyright (C) 2002-2003 Blast Internet Services, Inc. All rights reserved.\r\n//joeSNMP is a derivative work, containing both original code, included code and modified\r\n//code that was published under the GNU Lesser General Public License. Copyrights for modified \r\n//and included code are below.\r\n//\r\n//Copyright (C) 1999-2001 Oculan Corp. All rights reserved.\r\n//\r\n//This library is free software; you can redistribute it and/or\r\n//modify it under the terms of the GNU Lesser General Public\r\n//License as published by the Free Software Foundation; either\r\n//version 2.1 of the License, or (at your option) any later version.\r\n//\r\n//This library is distributed in the hope that it will be useful,\r\n//but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r\n//Lesser General Public License for more details.\r\n//\r\n//You should have received a copy of the GNU Lesser General Public\r\n//License along with this library; if not, write to the Free Software\r\n//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r\n//\r\n//See\: http\://www.fsf.org/copyleft/lesser.html\r\n//\r\n//For more information contact\:\r\n// joeSNMP Licensing <joe...@li...>\r\n// http\://sourceforge.net/projects/joesnmp/\r\n//\r\n\r\n${package_declaration}\r\n\r\n${typecomment}\r\n${type_declaration}</template><template context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\r\n * Title\: ${type_name}\r\n * Description\:\r\n * Copyright\: Copyright (c) 2003\r\n * Company\: Stargus, Inc\r\n * @author ${user}\r\n * @version 1.0\r\n */</template><template context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\r\n// ${todo} Auto-generated constructor stub</template><template context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment"></template><template context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment"></template><template context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\r\n${exception_var}.printStackTrace();</template><template context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/**\r\n * \r\n */</template><template context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\r\n${body_statement}</template><template context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment"></template><template context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment"></template><template context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment"></template></templates> |
From: Arie O. <ao...@us...> - 2005-03-22 19:09:03
|
User: aozarov Date: 05/03/22 11:08:36 joesnmp/.settings - New directory |
From: Arie O. <ao...@us...> - 2005-03-22 19:03:38
|
User: aozarov Date: 05/03/22 11:02:52 Modified: src/joesnmp/org/opennms/protocols/snmp/asn1 BerEncoder.java Log: Code optimization, SnmpSession.send considers SnmpPeer community string, Fix bug in SnmpPortal receiver queue handling and more. Revision Changes Path 1.2 +14 -115 joesnmp/src/joesnmp/org/opennms/protocols/snmp/asn1/BerEncoder.java Index: BerEncoder.java =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/src/joesnmp/org/opennms/protocols/snmp/asn1/BerEncoder.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- BerEncoder.java 19 Sep 2004 23:01:12 -0000 1.1 +++ BerEncoder.java 22 Mar 2005 19:02:43 -0000 1.2 @@ -30,7 +30,10 @@ // // Modifications: // -// $Id: BerEncoder.java,v 1.1 2004/09/19 23:01:12 andd Exp $ +// $Id: BerEncoder.java,v 1.2 2005/03/22 19:02:43 aozarov Exp $ +// +// 2005 Mar 18: ao...@ho... +// Replace copy method with System.arraycopy // package org.opennms.protocols.snmp.asn1; @@ -81,7 +84,7 @@ */ protected static int byteToInt(byte b) { - return (b < 0) ? 256 + (int)b : (int)b; + return 0xff & b; } /** @@ -94,7 +97,7 @@ */ protected static long byteToLong(byte b) { - return (b < 0) ? 256 + (long)b : (long)b; + return 0xffl & b; } /** @@ -126,68 +129,6 @@ } /** - * Used to copy data from one buffer to another. The method has the - * flexability to allow the caller to specify an offset in each buffer - * and the total number of bytes to copy - * - * @param src The source buffer - * @param srcOff The offset of the first byte in the source buffer - * @param dest The destination buffer - * @param destOff The offset of the first byte in the destination buffer - * @param intsToCopy The number of integer elements to copy - * - * @exception ArrayIndexOutOfBoundsException Thrown if there is insufficent - * space in either array to copy the data. - * - */ - protected static void copy(byte[] src, - int srcOff, - byte[] dest, - int destOff, - int bytesToCopy) throws ArrayIndexOutOfBoundsException - { - if((dest.length - destOff) < bytesToCopy || - (src.length - srcOff) < bytesToCopy) - throw new ArrayIndexOutOfBoundsException("Destination or source buffer is insufficent"); - - for(int x = bytesToCopy-1; x >= 0; x--) - { - dest[destOff + x] = src[srcOff + x]; - } - } - - /** - * Used to copy data from one buffer to another. The method has the - * flexability to allow the caller to specify an offset in each buffer - * and the total number of integers to copy - * - * @param src The source buffer - * @param srcOff The offset of the first integer in the source buffer - * @param dest The destination buffer - * @param destOff The offset of the first integer in the destination buffer - * @param intsToCopy The number of integer elements to copy - * - * @exception ArrayIndexOutOfBoundsException Thrown if there is insufficent - * space in either array to copy the data. - * - */ - protected static void copy(int[] src, - int srcOff, - int[] dest, - int destOff, - int intsToCopy) throws ArrayIndexOutOfBoundsException - { - if((dest.length - destOff) < intsToCopy || - (src.length - srcOff) < intsToCopy) - throw new ArrayIndexOutOfBoundsException("Destination or source buffer is insufficent"); - - for(int x = intsToCopy-1; x >= 0; x--) - { - dest[destOff + x] = src[srcOff + x]; - } - } - - /** * Rotates a give buffer area marked by begin, pivot, and end. * The pivot marks the point where the bytes between [pivot..end) * are moved to the position marked by begin. The bytes between @@ -209,39 +150,11 @@ int dist = end - pivot; byte[] hold = new byte[dist]; - copy(buf, // source - pivot, // source offset - hold, // destination - 0, // destination offset - dist); // length - - // - // shift from end of buffer to front. This - // way we do not have to worry about data - // corruption - // - for(int x = (pivot-begin)-1; x >= 0; x--) - { - buf[begin + dist + x] = buf[begin + x]; // SHIFT! - } - - copy(hold, // source - 0, // source offset - buf, // destination - begin, // destination offset - dist); // length + System.arraycopy(buf, pivot, hold, 0, dist); + System.arraycopy(buf, begin, buf, begin + dist, pivot - begin); + System.arraycopy(hold, 0, buf, begin, dist); } - /** - * Default constructor for the BER Encoder. - * - */ - public BerEncoder() - { - // default class constructor. - // Does nothing - } - /** * * The buildLength() method is used to encode an ASN.1 length @@ -648,7 +561,7 @@ // // effectively checking to see if (asnUInt32 & 0x80000000L) != 0 // - if(asnUInt32 > (long)(Integer.MAX_VALUE)) + if(asnUInt32 > Integer.MAX_VALUE) { bAddNullByte = true; intSz++; @@ -993,11 +906,7 @@ try { - copy(opaque, // source - 0, // source offset - buf, // destination - startOffset, // destination offset - opaque.length); // bytes to copy + System.arraycopy(opaque, 0, buf, startOffset, opaque.length); } catch(ArrayIndexOutOfBoundsException err) { @@ -1051,11 +960,7 @@ byte[] opaque = new byte[asnLength]; try { - copy(buf, // source buffer - startOffset, // source offset - opaque, // destination buffer - 0, // destination offset - asnLength); // number of items to copy + System.arraycopy(buf, startOffset, opaque, 0, asnLength); } catch(ArrayIndexOutOfBoundsException err) { @@ -1265,8 +1170,6 @@ if(asnLength == 0) { int[] ids = new int[2]; - ids[0] = ids[1] = 0; - Object[] rVals = new Object[3]; rVals[0] = new Integer(startOffset); rVals[1] = asnType; @@ -1305,7 +1208,7 @@ { --asnLength; byte b = buf[startOffset++]; - oid = (oid << 7) | (int)(b & 0x7f); + oid = (oid << 7) | (b & 0x7f); if((b & HIGH_BIT) == 0) done = true; @@ -1324,11 +1227,7 @@ else { retOids = new int[idsOff]; - copy(ids, // source - 0, // source offset - retOids, // destination - 0, // destination offset - idsOff); // number of items to copy + System.arraycopy(ids, 0, retOids, 0, idsOff); } // |
From: Arie O. <ao...@us...> - 2005-03-22 19:03:20
|
User: aozarov Date: 05/03/22 11:02:41 Modified: . CHANGELOG.txt Log: Code optimization, SnmpSession.send considers SnmpPeer community string, Fix bug in SnmpPortal receiver queue handling and more. Revision Changes Path 1.6 +15 -0 joesnmp/CHANGELOG.txt Index: CHANGELOG.txt =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/CHANGELOG.txt,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- CHANGELOG.txt 10 Nov 2004 23:47:59 -0000 1.5 +++ CHANGELOG.txt 22 Mar 2005 19:02:41 -0000 1.6 @@ -1,3 +1,18 @@ +- optimize BerEncoder (replace old copy with System.arraycopy) +- Replace SnmpTimer with OptimizedTimer (does not perform linear search) +- SnmpAgent will now provide SnmpPeer with the sender information instead of null +- SnmpAgent response generated (for get/getnext/set) will use the caller snmp version +- New constructor were added to set receive/send buffers +- Fixed a bug in fast receiver queue handling (SnmpPortal) +- Changed SnmpRequest / SnmpSession interaction to avoid the need of the cleaner task +- Optimized request handling in SnmpSession (use non-linear structure to hold/manage the requests) +- SnmpSession will now consider the community string from the peer (if provided) when sending requests +- Removed from SnmpSession the check that compares the community string in the received PDU with the community + string of the sent PDU as there are not few devices which will not comply with that rule and removing the check + will is not a realistic compromise in security + + + v0.3.3, 2004 Nov 11 --------------------------------------------------------------------- - fix references, a few remaining references to org.joesnmp - brozow |
From: Arie O. <ao...@us...> - 2005-03-22 19:02:46
|
User: aozarov Date: 05/03/22 11:02:33 Modified: src/joesnmp/org/opennms/protocols/snmp SnmpPortal.java SnmpSession.java SnmpTrapSession.java SnmpAgentSession.java SnmpRequest.java SnmpTimer.java Added: src/joesnmp/org/opennms/protocols/snmp OptimizedSnmpTimer.java Log: Code optimization, SnmpSession.send considers SnmpPeer community string, Fix bug in SnmpPortal receiver queue handling and more. Revision Changes Path 1.6 +378 -360 joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpPortal.java Index: SnmpPortal.java =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpPortal.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- SnmpPortal.java 16 Oct 2004 02:58:09 -0000 1.5 +++ SnmpPortal.java 22 Mar 2005 19:02:27 -0000 1.6 @@ -30,9 +30,13 @@ // // Modifications: // -// $Id: SnmpPortal.java,v 1.5 2004/10/16 02:58:09 brozow Exp $ +// $Id: SnmpPortal.java,v 1.6 2005/03/22 19:02:27 aozarov Exp $ // -//2004 Oct 04: kri...@ie... +// 2005 Mar 21: ao...@ho... +// Enable to set receive/send UDP buffers +// Fixed fastReceiverQ (was calling wait without obtaining the monitor) +// +// 2004 Oct 04: kri...@ie... // Changed the default scope of the thread pool variables & Executor class, // and added the logic to terminate the threads of Thread pool in close() // @@ -94,6 +98,9 @@ { public static final int DEFAULT_THREADPOOL_SIZE=0; public static final int MAXIMUM_THREADPOOL_SIZE = 12; + public static final int DEFAULT_RECEIVE_BUFFER_SIZE = 64 * 1024; + public static final int DEFAULT_SEND_BUFFER_SIZE = 64 * 1024; + public static final int DATAGRAM_SOCKET_BUFFER_SIZE = 64 * 1024; /** * The packet handler that is used to process @@ -114,7 +121,7 @@ /** * the receiver thread that runs the inner class Receiver. */ - private Thread m_recvThread; + private Receiver m_recvThread; /** * the number of executor threads in the thread pool @@ -125,8 +132,13 @@ /** * The thread pool that holds the executor threads */ - Vector m_threadPool; + private Vector m_threadPool; + /** + * Cache used bufferes + */ + private LinkedList m_usedBuffers = new LinkedList(); + /** * ASN.1 encoder used to decode the SNMP messages. * If the decoded fails to decode the specific messages @@ -168,8 +180,26 @@ * Identifies the system property that may be used to specify the number of milliseconds to use for the * socket timeout. */ - private static final String PROP_SOCKET_TIMEOUT_PERIOD = "org.opennms.joeSNMP.vmhacks.socketSoTimeoutPeriod"; + private static final String PROP_SOCKET_TIMEOUT_PERIOD = "org.opennms.joeSNMP.vmhacks.socketSoTimeoutPeriod"; + private static final Class THREAD_CATEGORY_CLASS = findThreadCategoryClass(); + + private static Class findThreadCategoryClass() + { + Class tmp = null; + + try + { + tmp = Class.forName("org.opennms.core.utils.ThreadCategory"); + } + catch (ClassNotFoundException e) + { + // Do nothing + } + + return tmp; + } + /** * Private constructor used to disallow the * default constructor. @@ -200,8 +230,8 @@ SnmpPortal(SnmpPacketHandler handler, AsnEncoder encoder, int port) throws SocketException { - // Call the other constructor with default number of threads - this(handler, encoder, port, null, DEFAULT_THREADPOOL_SIZE); + // Call the other constructor with default number of threads and default buffer size + this(handler, encoder, port, null, DEFAULT_THREADPOOL_SIZE, DEFAULT_RECEIVE_BUFFER_SIZE, DEFAULT_SEND_BUFFER_SIZE); } /** @@ -223,29 +253,38 @@ SnmpPortal(SnmpPacketHandler handler, AsnEncoder encoder, int port, InetAddress laddr) throws SocketException { - // Call the other constructor with default number of threads - this(handler, encoder, port, laddr, DEFAULT_THREADPOOL_SIZE); + // Call the other constructor with default number of threads and default buffer size + this(handler, encoder, port, laddr, DEFAULT_THREADPOOL_SIZE, DEFAULT_RECEIVE_BUFFER_SIZE, DEFAULT_SEND_BUFFER_SIZE); } - /** - * The SnmpPortal constructor. The constructor is used to build a portal - * on the specified port, and forward messages to the defined handler. - * All messages are decoded using the encoder specified during construction. - * - * @param handler The SNMP packet handler. - * @param encoder The ASN.1 codec object. - * @param port The port to send and receive datagram from. - * @param laddr The local address to bind. - * @param numOfThreads The number of Executor threads in pool. - * - * @exception java.net.SocketException Thrown if an error occurs setting - * up the communication channel. - * @exception java.lang.IllegalArgumentException Thrown if any of the parameters - * are null or invalid. - * - */ SnmpPortal(SnmpPacketHandler handler, AsnEncoder encoder, int port, InetAddress laddr, int numOfThreads) - throws SocketException + throws SocketException + { + // Call the other constructor with default buffers size + this(handler, encoder, port, laddr, numOfThreads, DEFAULT_RECEIVE_BUFFER_SIZE, DEFAULT_SEND_BUFFER_SIZE); + } + + /** + * The SnmpPortal constructor. The constructor is used to build a portal + * on the specified port, and forward messages to the defined handler. + * All messages are decoded using the encoder specified during construction. + * + * @param handler The SNMP packet handler. + * @param encoder The ASN.1 codec object. + * @param port The port to send and receive datagram from. + * @param laddr The local address to bind. + * @param numOfThreads The number of Executor threads in pool. + * @param receiveBufferSize Sets the SO_RCVBUF option to the specified value for this DatagramSocket + * @param sendBufferSize Sets the SO_SNDBUF option to the specified value for this DatagramSocket. + * + * @exception java.net.SocketException Thrown if an error occurs setting + * up the communication channel. + * @exception java.lang.IllegalArgumentException Thrown if any of the parameters + * are null or invalid. + * + */ + SnmpPortal(SnmpPacketHandler handler, AsnEncoder encoder, int port, InetAddress laddr, int numOfThreads, + int receiveBufferSize, int sendBufferSize) throws SocketException { if(handler == null || encoder == null) throw new IllegalArgumentException("Invalid argument"); @@ -259,6 +298,9 @@ m_comm = new DatagramSocket(0, laddr); } + m_comm.setReceiveBufferSize(receiveBufferSize); + m_comm.setSendBufferSize(sendBufferSize); + // // Determine whether or not it is necessary to use the socket.setSoTimeout() // method to set the socket timeout value thereby mimic'ing non-blocking socket I/O. @@ -322,7 +364,7 @@ fastExecutor.start(); } - m_recvThread = new Thread(new Receiver(), "SnmpPortal-" + m_comm.getPort()); + m_recvThread = new Receiver("SnmpPortal-" + m_comm.getPort()); m_encoder = encoder; m_recvThread.start(); @@ -337,10 +379,8 @@ * */ private class Executor extends Thread - { - - DatagramPacket pkt = null; - boolean suspendFlag = false; + { + DatagramPacket pkt; public Executor(String str) { @@ -349,47 +389,55 @@ public void run() { - while(false == m_isClosing) + while(!m_isClosing) { try { if(null != pkt) + { + try + { + invokeHandlePkt(pkt); + } + catch (Throwable e) + { + e.printStackTrace(); + } + finally + { + pkt = null; + } + } + + synchronized(this) { - invokeHandlePkt(pkt); - pkt = null; - } - mySuspend(); - - synchronized(this) - { - while(suspendFlag) - { + while(!m_isClosing && pkt == null) wait(); - } } } catch (InterruptedException e) { - e.printStackTrace(); + + // ignore (probably need to close) } } } - synchronized void mySuspend() - { - suspendFlag = true; - } - - synchronized boolean isSuspended() - { - return suspendFlag; - } - - synchronized void myResume() - { - suspendFlag = false; - notify(); - } + synchronized boolean acceptPacket(DatagramPacket newPkt) + { + if (pkt != null) + return false; + + pkt = newPkt; + notify(); + return true; + } + + synchronized void close() + { + // assuming m_isClosing is set to true + notify(); + } } @@ -401,48 +449,91 @@ * to raise(). * */ - private class Receiver implements Runnable + private class Receiver extends Thread { - /** - * Called to setup the communications channel buffers. - * The method attempts to set the received buffer size - * to 64k. If it fails then the default buffer size - * is recovered. If the default buffer size cannot be - * recovered then a zero is returned. - * - * @return The communications channel receive buffer size. - * A zero is returned on error - */ - private int setup() - { - int bufSz = 64*1024; + private final LinkedList m_fastReceiverQ = new LinkedList(); + private final Thread m_fastReceiver = new Thread(new Runnable() + { + public void run() + { + LinkedList fastReceiverQ = m_fastReceiverQ; + while(!m_isClosing && Thread.interrupted() == false) + { + byte[] buf = getBuffer(); + + try + { + DatagramPacket pkt = new DatagramPacket(buf, buf.length); + m_comm.receive(pkt); + synchronized(fastReceiverQ) + { + fastReceiverQ.addLast(pkt); + + if (fastReceiverQ.size() == 1) + fastReceiverQ.notify(); + } + } + catch(InterruptedIOException ioe) + { + // recycle the buffer if possible + cacheBuffer(buf); + } + catch(Exception e) + { + if(!m_isClosing) + { + // recycle the buffer if possible + cacheBuffer(buf); + + if (THREAD_CATEGORY_CLASS != null) + { + boolean handled = true; + try + { + + Class[] methodParmList = { Class.class }; + Method loggerM = THREAD_CATEGORY_CLASS.getMethod("getInstance", methodParmList); - // - // set the receiver buffer - // - try - { - m_comm.setReceiveBufferSize(bufSz); - } - catch(SocketException err) - { - bufSz = 0; - } + Object[] parmList = { this.getClass() }; + Object loggerI = loggerM.invoke(null, parmList); - if(bufSz == 0) - { - try - { - bufSz = m_comm.getReceiveBufferSize(); - } - catch(SocketException err) - { - bufSz = 0; - } - } - return bufSz; - } + methodParmList = new Class[] { Object.class, Throwable.class }; + Method infoM = THREAD_CATEGORY_CLASS.getMethod("info", methodParmList); + parmList = new Object[] { "An unknown error occured decoding the packet", e }; + infoM.invoke(loggerI, parmList); + } + catch(Throwable t) + { + handled = false; + } + + if(!handled) + { + System.out.println(new Date() + " - Exception: " + e.getMessage()); + } + } + + m_handler.processException(e); + } + } + } + } + }, Thread.currentThread().getName() + "-FastReceiver"); + + public Receiver(String name) + { + super(name); + } + + private void notifyOnClose() + { + synchronized(m_fastReceiverQ) + { + m_fastReceiverQ.notifyAll(); + } + } + /** * The run method is an infinite loop method that * receives all datagrams for the session. If an @@ -456,93 +547,15 @@ */ public void run() { - final int bufSz = setup(); - if(bufSz == 0) - { - return; - } - - final LinkedList fastReceiverQ = new LinkedList(); - final LinkedList usedBuffers = new LinkedList(); - Thread fastReceiver = new Thread(new Runnable() - { - public void run() - { - while(!m_isClosing && Thread.interrupted() == false) - { - byte[] buf = null; - synchronized(usedBuffers) - { - if(!usedBuffers.isEmpty()) - buf = (byte[])usedBuffers.removeFirst(); - } - - if(buf == null || buf.length != bufSz) - buf = new byte[bufSz]; - - try - { - DatagramPacket pkt = new DatagramPacket(buf, buf.length); - m_comm.receive(pkt); - synchronized(fastReceiverQ) - { - fastReceiverQ.addLast(pkt); - fastReceiverQ.notify(); - } - } - catch(InterruptedIOException ioe) - { - synchronized(usedBuffers) - { - usedBuffers.addLast(buf); - } - continue; - } - catch(Exception e) - { - if(!m_isClosing) - { - boolean handled = true; - try - { - - Class loggerC = Class.forName("org.opennms.core.utils.ThreadCategory"); - - Class[] methodParmList = { Class.class }; - Method loggerM = loggerC.getMethod("getInstance", methodParmList); - - Object[] parmList = { this.getClass() }; - Object loggerI = loggerM.invoke(null, parmList); - - methodParmList = new Class[] { Object.class, Throwable.class }; - Method infoM = loggerC.getMethod("info", methodParmList); - - parmList = new Object[] { "An unknown error occured decoding the packet", e }; - infoM.invoke(loggerI, parmList); - } - catch(Throwable t) - { - handled = false; - } - - if(!handled) - { - System.out.println(new Date() + " - Exception: " + e.getMessage()); - } - m_handler.processException(e); - } - } - } - } - }, Thread.currentThread().getName() + "-FastReceiver"); - fastReceiver.start(); - + m_fastReceiver.start(); + LinkedList fastReceiverQ = m_fastReceiverQ; // // get a buffer for the datagrams // while(!m_isClosing) { DatagramPacket pkt = null; + try { // @@ -551,97 +564,79 @@ synchronized(fastReceiverQ) { while(fastReceiverQ.isEmpty() && !m_isClosing) - fastReceiverQ.wait(300); + fastReceiverQ.wait(); - if(m_isClosing) - continue; - - pkt = (DatagramPacket) fastReceiverQ.removeFirst(); - - if(null == pkt) - { - continue; - } - //System.out.println(new Date() + "PKT Contents are :: " + pkt.toString()); + if(!m_isClosing) + pkt = (DatagramPacket) fastReceiverQ.removeFirst(); } - - if(m_numOfExecutorThreads > 0) - { - for(int nThreadIndex = 0; nThreadIndex < m_numOfExecutorThreads; ++nThreadIndex) - { - Executor fastExecutor = (Executor)m_threadPool.elementAt(nThreadIndex); - if(true == fastExecutor.isSuspended()){ - - //System.out.println("Index of thread that is idle and can again start is :: " + nThreadIndex); - - fastExecutor.pkt = pkt; - fastExecutor.myResume(); - - break; - } - - if(nThreadIndex + 1 >= m_numOfExecutorThreads){ - // about to terminate the loop - // sleep for a while and start over - nThreadIndex = -1; - wait(100); - } - } - } - else - { - // Thread pool is not used so Receiver thread should handle the packet - invokeHandlePkt(pkt); - } - + + + if(null != pkt) + { + //System.out.println(new Date() + "PKT Contents are :: " + pkt.toString()); + + if(m_numOfExecutorThreads > 0) + { + boolean wasAccepted = false; + + for (int nThreadIndex = 0; nThreadIndex < m_numOfExecutorThreads; ++nThreadIndex) + { + Executor fastExecutor = (Executor) m_threadPool.elementAt(nThreadIndex); + + if (fastExecutor.acceptPacket(pkt)) + { + wasAccepted = true; + break; + } + } + + // Thread pool is full (use the Receiver thread instead to handle the packet) + if (!wasAccepted) + invokeHandlePkt(pkt); + } + else + { + // Thread pool is not used so Receiver thread should handle the packet + invokeHandlePkt(pkt); + } + } } catch(Exception e) { if(!m_isClosing) { boolean handled = true; - try - { - Class loggerC = Class.forName("org.opennms.core.utils.ThreadCategory"); - - Class[] methodParmList = { Class.class }; - Method loggerM = loggerC.getMethod("getInstance", methodParmList); - - Object[] parmList = { this.getClass() }; - Object loggerI = loggerM.invoke(null, parmList); - - methodParmList = new Class[] { Object.class, Throwable.class }; - Method infoM = loggerC.getMethod("info", methodParmList); - - parmList = new Object[] { "An unknown error occured decoding the packet", e }; - infoM.invoke(loggerI, parmList); - } - catch(Throwable t) - { - handled = false; - } - - if(!handled) - { - System.out.println(new Date() + " - Exception: " + e.getMessage()); - } + + if (THREAD_CATEGORY_CLASS != null) + { + try + { + Class[] methodParmList = { Class.class }; + Method loggerM = THREAD_CATEGORY_CLASS.getMethod("getInstance", methodParmList); + + Object[] parmList = { this.getClass() }; + Object loggerI = loggerM.invoke(null, parmList); + + methodParmList = new Class[] { Object.class, Throwable.class }; + Method infoM = THREAD_CATEGORY_CLASS.getMethod("info", methodParmList); + + parmList = new Object[] { "An unknown error occured decoding the packet", e }; + infoM.invoke(loggerI, parmList); + } + catch(Throwable t) + { + handled = false; + } + + if(!handled) + { + System.out.println(new Date() + " - Exception: " + e.getMessage()); + } + } + m_handler.processException(e); } } - - // recycle the packet buffer if possible - // - if(pkt != null) - { - synchronized(usedBuffers) - { - // only keep 20 * 16k, or 520k worth - // of buffers around - // - if(usedBuffers.size() < 20) - usedBuffers.addLast(pkt.getData()); - } - } } } // end run() } @@ -664,104 +659,134 @@ } catch(SnmpPduEncodingException err) { - boolean handled = true; - try - { - Class loggerC = Class.forName("org.opennms.core.utils.ThreadCategory"); - - Class[] methodParmList = { Class.class }; - Method loggerM = loggerC.getMethod("getInstance", methodParmList); - - Object[] parmList = { this.getClass() }; - Object loggerI = loggerM.invoke(null, parmList); - - methodParmList = new Class[] { Object.class, Throwable.class }; - Method infoM = loggerC.getMethod("info", methodParmList); - - parmList = new Object[] { "An error occured decoding the protocol data unit", err }; - infoM.invoke(loggerI, parmList); - - methodParmList = new Class[0]; - Method debugEnabledM = loggerC.getMethod("isDebugEnabled", methodParmList); - - parmList = new Object[0]; - Boolean isEnabled = (Boolean) debugEnabledM.invoke(loggerI, parmList); - - if(isEnabled.booleanValue()) - { - methodParmList = new Class[] { Object.class }; - Method debugM = loggerC.getMethod("debug", methodParmList); - - OutputStream ostream = new ByteArrayOutputStream(); - SnmpUtil.dumpHex(new PrintStream(ostream), pkt.getData(), 0, pkt.getLength()); - - parmList = new Object[] { ostream }; - debugM.invoke(loggerI, parmList); - } - } - catch(Throwable t) - { - handled = false; - } - - if(!handled) - { - System.out.println(new Date() + " - SnmpPortal.Receiver.run: SnmpPduEncodingException: " + err.getMessage()); - SnmpUtil.dumpHex(System.out, pkt.getData(), 0, pkt.getLength()); - } + if (THREAD_CATEGORY_CLASS != null) + { + boolean handled = true; + try + { + + Class[] methodParmList = { Class.class }; + Method loggerM = THREAD_CATEGORY_CLASS.getMethod("getInstance", methodParmList); + + Object[] parmList = { this.getClass() }; + Object loggerI = loggerM.invoke(null, parmList); + + methodParmList = new Class[] { Object.class, Throwable.class }; + Method infoM = THREAD_CATEGORY_CLASS.getMethod("info", methodParmList); + + parmList = new Object[] { "An error occured decoding the protocol data unit", err }; + infoM.invoke(loggerI, parmList); + + methodParmList = new Class[0]; + Method debugEnabledM = THREAD_CATEGORY_CLASS.getMethod("isDebugEnabled", methodParmList); + + parmList = new Object[0]; + Boolean isEnabled = (Boolean) debugEnabledM.invoke(loggerI, parmList); + + if(isEnabled.booleanValue()) + { + methodParmList = new Class[] { Object.class }; + Method debugM = THREAD_CATEGORY_CLASS.getMethod("debug", methodParmList); + + OutputStream ostream = new ByteArrayOutputStream(); + SnmpUtil.dumpHex(new PrintStream(ostream), pkt.getData(), 0, pkt.getLength()); + + parmList = new Object[] { ostream }; + debugM.invoke(loggerI, parmList); + } + } + catch(Throwable t) + { + handled = false; + } + + if(!handled) + { + System.out.println(new Date() + " - SnmpPortal.Receiver.run: SnmpPduEncodingException: " + err.getMessage()); + SnmpUtil.dumpHex(System.out, pkt.getData(), 0, pkt.getLength()); + } + } + m_handler.processBadDatagram(pkt); } catch(AsnDecodingException err) { - boolean handled = true; - try - { - Class loggerC = Class.forName("org.opennms.core.utils.ThreadCategory"); - - Class[] methodParmList = { Class.class }; - Method loggerM = loggerC.getMethod("getInstance", methodParmList); - - Object[] parmList = { this.getClass() }; - Object loggerI = loggerM.invoke(null, parmList); - - methodParmList = new Class[] { Object.class, Throwable.class }; - Method infoM = loggerC.getMethod("info", methodParmList); - - parmList = new Object[] { "An ASN.1 error occured decoding the packet", err }; - infoM.invoke(loggerI, parmList); - - methodParmList = new Class[0]; - Method debugEnabledM = loggerC.getMethod("isDebugEnabled", methodParmList); - - parmList = new Object[0]; - Boolean isEnabled = (Boolean) debugEnabledM.invoke(loggerI, parmList); - - if(isEnabled.booleanValue()) - { - methodParmList = new Class[] { Object.class }; - Method debugM = loggerC.getMethod("debug", methodParmList); - - OutputStream ostream = new ByteArrayOutputStream(); - SnmpUtil.dumpHex(new PrintStream(ostream), pkt.getData(), 0, pkt.getLength()); - - parmList = new Object[] { ostream }; - debugM.invoke(loggerI, parmList); - } - } - catch(Throwable t) - { - handled = false; - } - - if(!handled) - { - System.out.println(new Date() + " - SnmpPortal.Receiver.run: AsnEncodingException: " + err.getMessage()); - SnmpUtil.dumpHex(System.out, pkt.getData(), 0, pkt.getLength()); - } + if (THREAD_CATEGORY_CLASS != null) + { + boolean handled = true; + + try + { + Class[] methodParmList = { Class.class }; + Method loggerM = THREAD_CATEGORY_CLASS.getMethod("getInstance", methodParmList); + + Object[] parmList = { this.getClass() }; + Object loggerI = loggerM.invoke(null, parmList); + + methodParmList = new Class[] { Object.class, Throwable.class }; + Method infoM = THREAD_CATEGORY_CLASS.getMethod("info", methodParmList); + + parmList = new Object[] { "An ASN.1 error occured decoding the packet", err }; + infoM.invoke(loggerI, parmList); + + methodParmList = new Class[0]; + Method debugEnabledM = THREAD_CATEGORY_CLASS.getMethod("isDebugEnabled", methodParmList); + + parmList = new Object[0]; + Boolean isEnabled = (Boolean) debugEnabledM.invoke(loggerI, parmList); + + if(isEnabled.booleanValue()) + { + methodParmList = new Class[] { Object.class }; + Method debugM = THREAD_CATEGORY_CLASS.getMethod("debug", methodParmList); + + OutputStream ostream = new ByteArrayOutputStream(); + SnmpUtil.dumpHex(new PrintStream(ostream), pkt.getData(), 0, pkt.getLength()); + + parmList = new Object[] { ostream }; + debugM.invoke(loggerI, parmList); + } + } + catch(Throwable t) + { + handled = false; + } + + if(!handled) + { + System.out.println(new Date() + " - SnmpPortal.Receiver.run: AsnEncodingException: " + err.getMessage()); + SnmpUtil.dumpHex(System.out, pkt.getData(), 0, pkt.getLength()); + } + } + m_handler.processBadDatagram(pkt); } + + // recycle the packet buffer if possible + cacheBuffer(pkt.getData()); } + byte[] getBuffer() + { + synchronized(m_usedBuffers) + { + if(!m_usedBuffers.isEmpty()) + return (byte[]) m_usedBuffers.removeFirst(); + } + + return new byte[DATAGRAM_SOCKET_BUFFER_SIZE]; + } + + void cacheBuffer(byte[] buffer) + { + synchronized(m_usedBuffers) + { + // only keep 20 * 64k of buffers around + if(m_usedBuffers.size() < 20) + m_usedBuffers.addLast(buffer); + } + } + /** * Recovers a SnmpPduPacket or SnmpPduTrap from the passed datagram * and calls the appropriate method in the handler. @@ -784,7 +809,7 @@ * @see org.opennms.protocols.snmp.asn1.AsnEncoder * */ - void handlePkt(DatagramPacket pkt) + private void handlePkt(DatagramPacket pkt) throws SnmpPduEncodingException, AsnDecodingException { // @@ -1027,7 +1052,8 @@ { m_isClosing = true; m_comm.close(); - + m_recvThread.notifyOnClose(); + try { //Now try to close the threads in pool just by invoking resume... @@ -1037,16 +1063,8 @@ for(int nThreadIndex = 0; nThreadIndex < m_numOfExecutorThreads; ++nThreadIndex) { Executor fastExecutor = (Executor)m_threadPool.elementAt(nThreadIndex); - if(true == fastExecutor.isSuspended()) - { - fastExecutor.myResume(); // This resume will actually kill the thread as the m_isClosing flag is set - } - else - { - //Since the thread is doing something lets just wait for a moment and then try again - --nThreadIndex; - wait(100); - } + fastExecutor.close(); + fastExecutor.join(); } } 1.4 +317 -373 joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpSession.java Index: SnmpSession.java =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpSession.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- SnmpSession.java 16 Oct 2004 02:58:09 -0000 1.3 +++ SnmpSession.java 22 Mar 2005 19:02:28 -0000 1.4 @@ -30,8 +30,16 @@ // // Modifications: // -// $Id: SnmpSession.java,v 1.3 2004/10/16 02:58:09 brozow Exp $ +// $Id: SnmpSession.java,v 1.4 2005/03/22 19:02:28 aozarov Exp $ // +// 2005 Mar 21: ao...@ho... +// Change interaction with SnmpRequest (deprecate the need for Cleanup task) +// Added more constructors to enable setting send/receive buffers +// Optimize access to the current requests set +// Consider the community string from peer when sending requests +// Remove the check that compares the community string in the received pdu +// with the community string of the sent pdu +// // 2004 Sep 20: Dim...@jb... // Added local binding address // @@ -51,7 +59,7 @@ // and linked list was faster. When the ArrayList was being used // the search was O(N), just like a linked list (actually N/2 on average). // So the performance gains from the faster add/remove should help -// until a better structure for searching, adding, and deleteing +// until a better structure for searching, adding, and deleting // can be used. // @@ -60,8 +68,9 @@ import java.net.DatagramPacket; import java.net.InetAddress; import java.net.SocketException; -import java.util.LinkedList; -import java.util.ListIterator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; import org.opennms.protocols.snmp.asn1.ASN1; import org.opennms.protocols.snmp.asn1.AsnEncoder; @@ -87,7 +96,7 @@ */ public class SnmpSession extends Object { - /** + /** * This is the command passed to the SnmpHandler * if a timeout occurs. All errors are less than * zero. @@ -114,12 +123,21 @@ */ public static final int ERROR_ENCODING = -3; + /** + * This is the command passed to the SnmpHandler + * if an unexpected runtime exception was generated when + * attempting to send an SnmpPduRequest message + * + * @see SnmpHandler + */ + public static final int ERROR_RUNTIME = -4; + /** * Used to contain a list of outstanding request * for the session. The list should only * contain SnmpRequest objects! */ - private LinkedList m_requests; + private Map m_requestsMap = new HashMap(); /** * The SNMP peer to whom this session will communicate @@ -137,7 +155,7 @@ * @see org.opennms.protocols.snmp.SnmpSession.CleanupRequest * @see SnmpRequest */ - private SnmpTimer m_timer; + private OptimizedSnmpTimer m_timer; /** * The default SNMP callback handler. If this is not @@ -158,7 +176,7 @@ /** * Provides a synchronization point */ - private Object m_sync; + private Object m_sync = new Object(); /** * If the boolean variable is set then @@ -171,20 +189,9 @@ */ private SnmpPortal m_portal; - /** - * If this boolean value is set then the receiver - * thread is terminated due to an exception that - * was generated in either a handler or a socket - * error. This is considered a fatal exception. - */ - private boolean m_threadException; - - /** - * This is the saved fatal excetion that - * can be rethrown by the application - */ - private Throwable m_why; - + + private static final int EXPIRED_REQUEST_CLEANUP_FREQUENCY = 30000; + /** * Inner class SessionHandler implements the interface * SnmpPacketHandler to handle callbacks from the SnmpPortal @@ -197,77 +204,84 @@ SnmpOctetString community, int pduType, SnmpPduPacket pdu) - throws SnmpPduEncodingException { + /* + // - // now find the request and - // inform + // now find the request and inform // - boolean isExpired = false; SnmpRequest req = null; - synchronized(m_requests) - { - // - // ensures that we get the proper - // state information - // - req = findRequest(pdu); - if(req != null) - isExpired = req.m_expired; - } - - - if(isExpired == false) - { - int cmd = -1; - if(req != null && req.m_pdu instanceof SnmpPduPacket) - cmd = ((SnmpPduPacket)req.m_pdu).getCommand(); - else { - cmd= pdu.getCommand(); - pdu.setPeer(new SnmpPeer(agent,port)); - } + synchronized (m_requestsMap) + { + Integer key = new Integer(pdu.getRequestId()); + req = (SnmpRequest) m_requestsMap.get(key); + if (req == null || req.isExpired()) + return; + } + + if(!(req.getPdu() instanceof SnmpPduPacket)) + throw new SnmpPduEncodingException("Invalid PDU Type for session received"); + + // No need for check here as there are quite few devices which don't follow + // The rule of returning the community string that was sent to them + // This doesn't seem a compromise of security - switch(cmd) - { - case SnmpPduPacket.SET: - { - String tst = new String(community.getString()); - String wr = m_peer.getParameters().getWriteCommunity(); - if(!tst.equals(wr)) - { - throw new SnmpPduEncodingException("Invalid community string"); - } - } - break; - - case SnmpPduPacket.GET: - case SnmpPduPacket.GETNEXT: - case SnmpPduPacket.RESPONSE: - case SnmpPduPacket.INFORM: - case SnmpPduPacket.GETBULK: - case SnmpPduPacket.REPORT: - { - String tst = new String(community.getString()); - String rd = m_peer.getParameters().getReadCommunity(); - if(!tst.equals(rd)) - { - throw new SnmpPduEncodingException("Invalid community string"); - } - } - break; + SnmpPduPacket reqPdu = (SnmpPduPacket) req.getPdu(); + int cmd = reqPdu.getCommand(); - default: - throw new SnmpPduEncodingException("Invalid PDU Type for session received"); - } - if (req != null) { - req.m_expired = true; // mark it as expired - req.m_handler.snmpReceivedPdu(req.m_session, - ((SnmpPduRequest)pdu).getCommand(), - (SnmpPduRequest)pdu); - } else { - m_defHandler.snmpReceivedPdu(null,cmd,pdu); - } + switch(cmd) + { + case SnmpPduPacket.SET: + { + String tst = new String(community.getString()); + String wr = reqPdu.getPeer() == null ? m_peer.getParameters().getWriteCommunity() : + reqPdu.getPeer().getParameters().getWriteCommunity(); + + if(!tst.equals(wr)) + throw new SnmpPduEncodingException("Invalid community string"); + } + break; + + + case SnmpPduPacket.GET: + case SnmpPduPacket.GETNEXT: + case SnmpPduPacket.INFORM: + case SnmpPduPacket.GETBULK: + case SnmpPduPacket.REPORT: + { + String tst = new String(community.getString()); + String rd = reqPdu.getPeer() == null ? m_peer.getParameters().getReadCommunity() : + reqPdu.getPeer().getParameters().getReadCommunity(); + + if(!tst.equals(rd)) + throw new SnmpPduEncodingException("Invalid community string"); + } + break; + + default: + throw new SnmpPduEncodingException("Invalid PDU Type for session received"); } +*/ + Integer key = new Integer(pdu.getRequestId()); + + SnmpRequest req = null; + synchronized (m_requestsMap) + { + req = (SnmpRequest) m_requestsMap.remove(key); + if (req == null) + return; + + req.setExpired(true); + } + + try + { + req.getHandler().snmpReceivedPdu(SnmpSession.this, pdu.getCommand(), pdu); + } + catch (Exception ex) + { + // ignore + } } public void processSnmpTrap(InetAddress agent, @@ -289,48 +303,6 @@ // do nothing - discard? } } - - /** - * This class is used to periodically cleanup the - * outstanding request that have expired. The cleanup - * interval is nominally once every 5 to 10 seconds. - * It's used like the garbage collector for the m_requests - * list. This is used in hopes of minimizing the contention - * for the request array - * - */ - private class CleanupRequest implements Runnable - { - /** - * Preforms the actual removal of the expired - * SnmpRequest elements. - * - * @see SnmpRequest - * - */ - public void run() - { - synchronized(m_requests) - { - if(m_requests.size() > 0) - { - ListIterator iter = m_requests.listIterator(0); - while(iter.hasNext()) - { - SnmpRequest req = (SnmpRequest)iter.next(); - if(req.m_expired) - iter.remove(); - } - } - } - - // - // reschedule - // - if(!m_stopRun && !m_threadException) - m_timer.schedule(this, 1000); - } - } /** * <P>Encapsulates a byte array and the number of @@ -397,18 +369,17 @@ * @exception org.opennms.protocols.snmp.asn1.AsnEncodingException Thrown * if an encoding exception occurs in the AsnEncoder object. */ - private ByteArrayInfo encode(SnmpPduPacket pdu) throws SnmpPduEncodingException, AsnEncodingException + private ByteArrayInfo encode(SnmpPeer peer, SnmpPduPacket pdu) throws SnmpPduEncodingException, AsnEncodingException { - SnmpPeer peer = m_peer; - SnmpParameters parms = peer.getParameters(); - + SnmpParameters parms = peer.getParameters(); + AsnEncoder encoder = peer.getParameters().getEncoder(); + // // Get the encoder and start // the encoding process // // get a suitable buffer (16k) // - int begin = 0; int offset = 0; byte[] buf= new byte[16 * 1024]; @@ -416,7 +387,7 @@ // encode the snmp version // SnmpInt32 version = new SnmpInt32(parms.getVersion()); - offset = version.encodeASN(buf, offset, m_encoder); + offset = version.encodeASN(buf, offset, encoder); // // get the correct community string. The @@ -439,15 +410,15 @@ // // encode the community strings // - offset = community.encodeASN(buf, offset, m_encoder); - offset = pdu.encodeASN(buf, offset, m_encoder); + offset = community.encodeASN(buf, offset, encoder); + offset = pdu.encodeASN(buf, offset, encoder); // // build the header, don't forget to mark the // pivot point // int pivot = offset; - offset = m_encoder.buildHeader(buf, + offset = encoder.buildHeader(buf, offset, (byte)(ASN1.SEQUENCE | ASN1.CONSTRUCTOR), pivot); @@ -474,14 +445,13 @@ * @exception org.opennms.protocols.snmp.asn1.AsnEncodingException Thrown * if an encoding exception occurs in the AsnEncoder object. */ - private ByteArrayInfo encode(SnmpPduTrap pdu) throws SnmpPduEncodingException, AsnEncodingException + private ByteArrayInfo encode(SnmpPduTrap pdu) throws AsnEncodingException { SnmpPeer peer = m_peer; SnmpParameters parms = peer.getParameters(); // // get a suitable buffer (16k) // - int begin = 0; int offset = 0; byte[] buf= new byte[16 * 1024]; @@ -522,92 +492,13 @@ } /** - * Adds an outstanding request to the session. The - * access to the list is synchronized on the actual - * list of request. This is done to allow synchronization - * between addRequest(), removeRequest(), and findRequest() - * - * @param req The request reference to add (not cloned) - */ - void addRequest(SnmpRequest req) - { - synchronized(m_requests) - { - m_requests.addLast(req); - } - } - - /** - * Removes an outstanding request from the session. The - * method uses the Object.equals() to find a matching request. - * If the SnmpRequest object does not override the equals() - * method the a "by reference" equality is used. - * - * @param req The request to remove. All matching request are removed. - */ - void removeRequest(SnmpRequest req) - { - synchronized(m_requests) - { - if(m_requests.size() > 0) - { - ListIterator iter = m_requests.listIterator(0); - while(iter.hasNext()) - { - SnmpRequest cmp = (SnmpRequest)iter.next(); - if(req.equals(cmp)) - { - req.m_expired = true; - iter.remove(); - } - } - } - } - } - - /** - * Finds the first matching request in the list of outstanding - * request and returns it to the caller. The matching is done - * by means using the SNMP Protocol Data Unit's request id. If - * no match is found then a null is returned - * - * @param pdu The source pdu for the search. - * - * @return Returns a SnmpRequest if a match is found. Otherwise a - * null is returned. - * - */ - SnmpRequest findRequest(SnmpPduPacket pdu) - { - synchronized(m_requests) - { - if(m_requests.size() > 0) - { - ListIterator iter = m_requests.listIterator(0); - - while(iter.hasNext()) - { - SnmpRequest req = (SnmpRequest) iter.next(); - if(!req.m_expired - && req.m_pdu instanceof SnmpPduPacket - && ((SnmpPduPacket)req.m_pdu).getRequestId() == pdu.getRequestId()) - { - return req; - } - } - } - } - return null; - } - - /** * Returns the internal timer object for the * SNMP Session. * * @return The internal timer object * */ - SnmpTimer getTimer() + OptimizedSnmpTimer getTimer() { return m_timer; } @@ -619,7 +510,8 @@ * SnmpParameters. Once the packet is encoded it is transmitted * to the agent defined by SnmpPeer. If an error occurs an * appropiate exception is generated. - * + * This method is called by SnmpRequest. + * * @param req The SnmpRequest to transmit * * @exception SnmpPduEncodingException Thrown if an encoding exception @@ -634,9 +526,7 @@ * @see SnmpPeer * */ - void transmit(SnmpRequest req) - throws SnmpPduEncodingException, AsnEncodingException, - java.io.IOException + void transmit(SnmpRequest req) throws SnmpPduEncodingException, AsnEncodingException, java.io.IOException { // // break down the pieces into usable variables @@ -646,11 +536,14 @@ SnmpPeer peer = m_peer; SnmpParameters parms = peer.getParameters(); - if(req.m_pdu instanceof SnmpPduPacket) - pdu = (SnmpPduPacket) req.m_pdu; - - if(req.m_pdu instanceof SnmpPduTrap) - trap = (SnmpPduTrap) req.m_pdu; + if(req.getPdu() instanceof SnmpPduPacket) + { + pdu = (SnmpPduPacket) req.getPdu(); + if (pdu.getPeer() != null) + peer = pdu.getPeer(); + } + else if(req.getPdu() instanceof SnmpPduTrap) + trap = (SnmpPduTrap) req.getPdu(); // // verify that for a SNMPV1 session that no @@ -673,11 +566,8 @@ // // transmit the datagram // - ByteArrayInfo msg = encode(pdu); - if (pdu.getPeer() == null) - m_portal.send(m_peer, msg.array(), msg.size()); - else - m_portal.send(pdu.getPeer(), msg.array(), msg.size()); + ByteArrayInfo msg = encode(peer, pdu); + m_portal.send(peer, msg.array(), msg.size()); } else if(trap != null) { @@ -690,6 +580,60 @@ } } + // Called by SnmpRequest + void snmpInternalError(SnmpRequest request, int errorCode) + { + if (request.isExpired()) + return; + + Integer id = request.getRequestID(); + synchronized (m_requestsMap) + { + Object tmp = m_requestsMap.get(id); + if (tmp != request) + return; + + m_requestsMap.remove(id); + request.setExpired(true); + } + + try + { + request.getHandler().snmpInternalError(this,errorCode, request.getPdu()); + } + catch(Exception e) + { + // ignore + } + } + + // Called by SnmpRequest + public void snmpTimeoutError(SnmpRequest request) + { + if (request.isExpired()) + return; + + Integer id = request.getRequestID(); + synchronized (m_requestsMap) + { + Object tmp = m_requestsMap.get(id); + if (tmp != request) + return; + + m_requestsMap.remove(id); + request.setExpired(true); + } + + try + { + request.getHandler().snmpTimeoutError(this, request.getPdu()); + } + catch(Exception e) + { + // ignore + } + } + /** * The default SnmpSession constructor. The object * is constructed with a default SnmpPeer object. @@ -704,23 +648,7 @@ */ public SnmpSession(InetAddress peer) throws SocketException { - m_sync = new Object(); - m_requests = new LinkedList(); - m_peer = new SnmpPeer(peer); - m_timer = new SnmpTimer(); - m_defHandler = null; - - m_stopRun = false; - - m_encoder = (new SnmpParameters()).getEncoder(); - m_portal = new SnmpPortal(new SessionHandler(), - m_encoder, - 0); - - m_threadException= false; - m_why = null; - - m_timer.schedule(new CleanupRequest(), 1000); + this(new SnmpPeer(peer)) ; } /** @@ -735,47 +663,46 @@ * */ public SnmpSession(SnmpPeer peer) throws SocketException - { - m_requests = new LinkedList(); - m_timer = new SnmpTimer(); - m_defHandler = null; - - m_sync = new Object(); - m_stopRun = false; + { + this(peer, SnmpPortal.DEFAULT_THREADPOOL_SIZE, SnmpPortal.DEFAULT_RECEIVE_BUFFER_SIZE, + SnmpPortal.DEFAULT_SEND_BUFFER_SIZE); + } + + /** + * Constructs the SnmpSession with the specific + * parameters. The parameters are associated with + * the default SnmpPeer object. + * + * @param peer The peer address for agent + * @param params The SnmpParameters to configure with this session + * + * @see SnmpPeer + * @see SnmpParameters + * + * @exception java.net.SocketException If thrown it is from the creation + * of a DatagramSocket. + * + */ + public SnmpSession(InetAddress peer, SnmpParameters params) throws SocketException + { + this(peer); + m_peer.setParameters(params); + } + public SnmpSession(SnmpPeer peer, int threadPoolSize, int receiveBuffer, int sendBuffer) throws SocketException + { + m_peer = peer; m_encoder = peer.getParameters().getEncoder(); m_portal = new SnmpPortal(new SessionHandler(), m_encoder, peer.getServerPort(), - peer.getServerAddress()); - - m_threadException= false; - m_why = null; - - m_peer = peer; + peer.getServerAddress(), + threadPoolSize, + receiveBuffer, + sendBuffer); - m_timer.schedule(new CleanupRequest(), 5000); - } - - /** - * Constructs the SnmpSession with the specific - * parameters. The parameters are associated with - * the default SnmpPeer object. - * - * @param peer The peer address for agent - * @param params The SnmpParameters to configure with this session - * - * @see SnmpPeer - * @see SnmpParameters - * - * @exception java.net.SocketException If thrown it is from the creation - * of a DatagramSocket. - * - */ - public SnmpSession(InetAddress peer, SnmpParameters params) throws SocketException - { - this(peer); - m_peer.setParameters(params); + m_timer = new OptimizedSnmpTimer(); + m_timer.schedule(new CleanupRequest(), EXPIRED_REQUEST_CLEANUP_FREQUENCY); } /** @@ -846,26 +773,13 @@ { if(m_stopRun) // session has been closed! throw new IllegalStateException("illegal operation, the session has been closed"); - } - - synchronized(m_requests) - { - // - // need to do cleanup in order - // to make this happen! - // - if(m_requests.size() > 0) - { - ListIterator iter = m_requests.listIterator(); - while(iter.hasNext()) - { - SnmpRequest req = (SnmpRequest) iter.next(); - if(req.m_expired) - iter.remove(); - } - } - return m_requests.size(); - } + + synchronized(m_requestsMap) + { + cleanupExpiredRequests(); + return m_requestsMap.size(); + } + } } /** @@ -880,6 +794,8 @@ */ public void cancel(int requestId) { + Integer requestID = new Integer(requestId); + // // check to ensure that the session is still open // @@ -887,29 +803,14 @@ { if(m_stopRun) // session has been closed! throw new IllegalStateException("illegal operation, the session has been closed"); - } - - synchronized(m_requests) - { - if(m_requests.size() > 0) - { - ListIterator iter = m_requests.listIterator(); - while(iter.hasNext()) - { - // - // While the method owns the lock remove any expired - // request and any request with a matching request id - // - SnmpRequest req = (SnmpRequest)iter.next(); - if(req.m_expired || (req.m_pdu instanceof SnmpPduPacket - && ((SnmpPduPacket)req.m_pdu).getRequestId() == requestId)) - { - req.m_expired = true; - iter.remove(); - } - } - } - } + + synchronized(m_requestsMap) + { + SnmpRequest req = (SnmpRequest) m_requestsMap.remove(requestID); + if (req != null) + req.setExpired(true); + } + } } /** @@ -930,26 +831,33 @@ if(handler == null) throw new SnmpHandlerNotDefinedException("No Handler Defined"); - // + Integer requestId = new Integer(pdu.getRequestId()); + SnmpRequest req = new SnmpRequest(this, requestId, pdu, handler); + boolean shouldHoldRequest = !req.isTrap(); + + // // check to ensure that the session is still open // synchronized(m_sync) { if(m_stopRun) // session has been closed! throw new IllegalStateException("illegal operation, the session has been closed"); - } - - SnmpRequest req = new SnmpRequest(this, pdu, handler); - if(pdu.getCommand() != SnmpPduPacket.V2TRAP || pdu.getPeer() == null ) // traps and responses don't get answers! - addRequest(req); + if(shouldHoldRequest) // traps and responses don't get answers! + { + synchronized(m_requestsMap) + { + SnmpRequest old = (SnmpRequest) m_requestsMap.get(requestId); + if (old == null || old.isExpired()) + m_requestsMap.put(requestId, req); + else + throw new IllegalStateException("Session has an active request with the same id"); + } + } + } + req.run(); - if(req.m_expired == true) - { - return 0; - } - - return ((SnmpPduPacket)req.m_pdu).getRequestId(); + return shouldHoldRequest ? 0 : requestId.intValue(); } /** @@ -966,9 +874,6 @@ */ public int send(SnmpPduPacket pdu) { - if(m_defHandler == null) - throw new SnmpHandlerNotDefinedException("No Handler Defined"); - return send(pdu, m_defHandler); } @@ -1016,9 +921,6 @@ */ public int send(SnmpPduTrap pdu) { - if(m_defHandler == null) - throw new SnmpHandlerNotDefinedException("No Handler Defined"); - return send(pdu, m_defHandler); } @@ -1054,33 +956,10 @@ throw new IllegalStateException("The session is already closed"); m_stopRun = true; - m_timer.cancel(); - m_portal.close(); - } - - // - // remove all items from the list - // - synchronized(m_requests) - { - m_requests.clear(); - } - } - - /** - * If an exception occurs in the SNMP receiver - * thread then raise() will rethrow the exception. - * - * @exception java.lang.Throwable The base for thrown - * exceptions. - */ - public void raise() throws Throwable - { - synchronized(m_sync) - { - if(m_threadException) - throw m_why; } + + m_timer.cancle(true); + m_portal.close(); } /** @@ -1119,5 +998,70 @@ SnmpUtil.registerSyntax(object); } - + private void cleanupExpiredRequests() + { + if(!m_requestsMap.isEmpty()) + { + Iterator iter = m_requestsMap.values().iterator(); + + while(iter.hasNext()) + { + SnmpRequest req = (SnmpRequest) iter.next(); + if(req.isExpired()) + { +// System.out.println("***************** cleanupExpiredRequests(" + this + ") cleaned -> " +// + req.getRequestID() +// + ", " + req.getPdu() +// + ", " + ((SnmpPduPacket) req.getPdu()).getPeer().getPeer() +// + ", " + ((SnmpPduPacket) req.getPdu()).getPeer().getParameters().getReadCommunity() +// ); + iter.remove(); + } + } + } + } + + /** + * This class is used to periodically cleanup the + * outstanding request that have expired. The cleanup + * interval is nominally once every 5 to 10 seconds. + * It's used like the garbage collector for the m_requests + * list. This is used in hopes of minimizing the contention + * for the request array + * + */ + private class CleanupRequest implements Runnable + { + private CleanupRequest() + { + // Do nothing + } + + /** + * Preforms the actual removal of the expired + * SnmpRequest elements. + * + * @see SnmpRequest + * + */ + public void run() + { + if (m_stopRun) + return; + + try + { + synchronized(m_requestsMap) + { + cleanupExpiredRequests(); + } + } + catch (Throwable te) + { + // ignore + } + + m_timer.schedule(this, EXPIRED_REQUEST_CLEANUP_FREQUENCY); + } + } } // end of SnmpSession class 1.4 +7 -9 joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpTrapSession.java Index: SnmpTrapSession.java ===========================================================... [truncated message content] |
From: Matt B. <br...@us...> - 2004-12-04 16:01:51
|
User: brozow Date: 04/12/04 08:01:45 Modified: src/joesnmp/org/opennms/protocols/snmp SnmpTimeTicks.java Log: Fix error in toString that always printed 0ms incorrectly Revision Changes Path 1.2 +2 -2 joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpTimeTicks.java Index: SnmpTimeTicks.java =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpTimeTicks.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SnmpTimeTicks.java 19 Sep 2004 23:01:11 -0000 1.1 +++ SnmpTimeTicks.java 4 Dec 2004 16:01:44 -0000 1.2 @@ -30,7 +30,7 @@ // // Modifications: // -// $Id: SnmpTimeTicks.java,v 1.1 2004/09/19 23:01:11 andd Exp $ +// $Id: SnmpTimeTicks.java,v 1.2 2004/12/04 16:01:44 brozow Exp $ // package org.opennms.protocols.snmp; @@ -217,7 +217,7 @@ else buf.append("0s "); - buf.append(tmp*10).append("ms"); + buf.append(time*10).append("ms"); return buf.toString(); } |
From: Dimitris A. <an...@us...> - 2004-11-10 23:48:08
|
User: andd Date: 04/11/10 15:48:02 Modified: src/joesnmp/org/opennms/protocols/snmp SnmpAgentHandler.java SnmpAgentSession.java Log: minor changes toward 0.3.3 Revision Changes Path 1.2 +11 -12 joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpAgentHandler.java Index: SnmpAgentHandler.java =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpAgentHandler.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SnmpAgentHandler.java 22 Sep 2004 23:28:04 -0000 1.1 +++ SnmpAgentHandler.java 10 Nov 2004 23:48:01 -0000 1.2 @@ -25,7 +25,10 @@ // // Modifications: // -// $Id: SnmpAgentHandler.java,v 1.1 2004/09/22 23:28:04 andd Exp $ +// $Id: SnmpAgentHandler.java,v 1.2 2004/11/10 23:48:01 andd Exp $ +// +// 2004 Nov 10: Dim...@jb... +// Fixed javadoc comments // // 2000 Sep 08: Bob Snider <bs...@se...> // Adapted from SnmpTrapHandler @@ -53,9 +56,9 @@ * community string of the received PDU</P> * * @param session The SNMP session - * @param agent The remote sender + * @param manager The remote sender * @param port The remote senders port - * @param community The community string + * @param community The community string * @param pdu The SNMP pdu * */ @@ -69,10 +72,11 @@ * <P>This method is defined to handle SNMP Get requests * that are received by the session. The request has already * been validated by the system. This routine will build a - * resonse and pass it back to the caller. - * </P> + * response and pass it back to the caller.</P> * * @param pdu The SNMP pdu + * @param getNext The agent is requesting the lexically NEXT item after each + * item in the pdu. * * @return SnmpPduRequest filled in with the proper response, or null if cannot process * NOTE: this might be changed to throw an exception. @@ -83,12 +87,9 @@ * <P>This method is defined to handle SNMP Set requests * that are received by the session. The request has already * been validated by the system. This routine will build a - * resonse and pass it back to the caller. - * </P> + * response and pass it back to the caller.</P> * * @param pdu The SNMP pdu - * @param getNext The agent is requesting the lexically NEXT item after each - * item in the pdu. * * @return SnmpPduRequest filled in with the proper response, or null if cannot process * NOTE: this might be changed to throw an exception. @@ -113,9 +114,7 @@ * @param session The SNMP Session * @param error The error condition value. * @param ref The PDU reference, or potentially null. - * It may also be an exception. - * - * + * It may also be an exception. */ void SnmpAgentSessionError(SnmpAgentSession session, int error, 1.2 +7 -7 joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpAgentSession.java Index: SnmpAgentSession.java =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpAgentSession.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SnmpAgentSession.java 22 Sep 2004 23:28:04 -0000 1.1 +++ SnmpAgentSession.java 10 Nov 2004 23:48:01 -0000 1.2 @@ -25,7 +25,7 @@ // // Modifications: // -// $Id: SnmpAgentSession.java,v 1.1 2004/09/22 23:28:04 andd Exp $ +// $Id: SnmpAgentSession.java,v 1.2 2004/11/10 23:48:01 andd Exp $ // // 2004 Sep 22: <kri...@ie...> // To support the thread pooling, the constructor of this class @@ -191,9 +191,9 @@ try { int cmd = pdu.getCommand(); - // System.out.println("PDU command......... " + cmd); + //System.out.println("PDU command......... " + cmd); String tst = new String(community.getString()); - System.out.println(" IN processSnmpMessage :: COMMUNITY = " + community.getString()); + //System.out.println(" IN processSnmpMessage :: COMMUNITY = " + community.getString()); String rd = m_peer.getParameters().getReadCommunity(); String wr = m_peer.getParameters().getWriteCommunity(); @@ -203,7 +203,7 @@ // validate request if(tst.equals(rd)) handleResponse(manager, port, pdu, m_handler.snmpReceivedGet(pdu, false)); - System.out.println(" IN processSnmpMessage :: GET " + manager.toString()); + //System.out.println(" IN processSnmpMessage :: GET " + manager.toString()); break; case SnmpPduPacket.GETNEXT: @@ -216,7 +216,7 @@ // validate request if(tst.equals(wr)) handleResponse(manager, port, pdu, m_handler.snmpReceivedSet(pdu)); - System.out.println(" IN processSnmpMessage :: SET " + manager.toString()); + //System.out.println(" IN processSnmpMessage :: SET " + manager.toString()); break; default: @@ -243,10 +243,10 @@ response.setRequestId(pdu.getRequestId()); try { m_forWhom.send(new SnmpPeer(manager, port), response); - // System.out.println("Response Sent"); + //System.out.println("Response Sent"); } catch (Exception e) { - System.out.println("Error sending response "+e); + //System.out.println("Error sending response "+e); } } } |
From: Dimitris A. <an...@us...> - 2004-11-10 23:48:07
|
User: andd Date: 04/11/10 15:48:00 Modified: . CHANGELOG.txt TODO.txt build.properties Log: minor changes toward 0.3.3 Revision Changes Path 1.5 +4 -2 joesnmp/CHANGELOG.txt Index: CHANGELOG.txt =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/CHANGELOG.txt,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- CHANGELOG.txt 16 Oct 2004 02:58:08 -0000 1.4 +++ CHANGELOG.txt 10 Nov 2004 23:47:59 -0000 1.5 @@ -1,6 +1,8 @@ -v0.3.3 +v0.3.3, 2004 Nov 11 --------------------------------------------------------------------- -- fix references a few remaining references to org.joesnmp - brozow +- fix references, a few remaining references to org.joesnmp - brozow +- commented out stupid System.out at SnmpAgentSession +- javadoc corrections at SnmpAgentHandler v0.3.2, 2004 Oct 07 ---------------------------------------------------------------------- 1.4 +2 -0 joesnmp/TODO.txt Index: TODO.txt =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/TODO.txt,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- TODO.txt 16 Oct 2004 02:58:08 -0000 1.3 +++ TODO.txt 10 Nov 2004 23:48:00 -0000 1.4 @@ -11,6 +11,8 @@ or at least mediate calls with a single class, and have the option of using apache-commons for example +- SnmpAgentSession has some stupid commented out System.out calls + - Externalize the thread pool from SnmpPortal using possibly a new derived class, or a handler that does thread management. 1.7 +1 -1 joesnmp/build.properties Index: build.properties =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/build.properties,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- build.properties 7 Oct 2004 14:09:39 -0000 1.6 +++ build.properties 10 Nov 2004 23:48:00 -0000 1.7 @@ -1,3 +1,3 @@ # joesnmp version -joesnmp.version = 0.3.2 +joesnmp.version = 0.3.3 |
From: Matt B. <br...@us...> - 2004-10-16 02:58:24
|
User: brozow Date: 04/10/15 19:58:10 Modified: src/joesnmp/org/opennms/protocols/snmp SnmpPortal.java SnmpTrapSession.java SnmpSession.java SnmpSMI.java SnmpPduEncodingException.java SnmpParameters.java Log: Renamed a few things to org.opennms rather than org.joesnmp so that the code will work with the opennms code base. Matt Brozowski br...@op... Revision Changes Path 1.5 +10 -9 joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpPortal.java Index: SnmpPortal.java =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpPortal.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- SnmpPortal.java 7 Oct 2004 14:09:41 -0000 1.4 +++ SnmpPortal.java 16 Oct 2004 02:58:09 -0000 1.5 @@ -30,7 +30,7 @@ // // Modifications: // -// $Id: SnmpPortal.java,v 1.4 2004/10/07 14:09:41 andd Exp $ +// $Id: SnmpPortal.java,v 1.5 2004/10/16 02:58:09 brozow Exp $ // //2004 Oct 04: kri...@ie... // Changed the default scope of the thread pool variables & Executor class, @@ -150,7 +150,7 @@ * Set to true if it is necessary to set the socket timeout value via the Socket.setSoTimeout() * method in order to keep from blocking indefinitely on a socket I/O call. This value * is configurable at runtime via the system property - * "org.joesnmp.joeSNMP.vmhacks.socketSoTimeoutRequired". + * "org.opennms.joeSNMP.vmhacks.socketSoTimeoutRequired". * If this property is set to 'no', the bSocketSoTimeoutRequired variable will be set to * false and the SNMP trap socket timeout will not be set. * If this property is set to 'yes' or the property does not exist, the bSocketSoTimeoutRequired @@ -163,12 +163,12 @@ * Identifies the system property that may be used to specify whether or not a timeout value is set * on the SNMP trap socket. Valid values are 'yes' and 'no'. */ - private static final String PROP_SOCKET_TIMEOUT_REQUIRED = "org.joesnmp.joeSNMP.vmhacks.socketSoTimeoutRequired"; + private static final String PROP_SOCKET_TIMEOUT_REQUIRED = "org.opennms.joeSNMP.vmhacks.socketSoTimeoutRequired"; /** * Identifies the system property that may be used to specify the number of milliseconds to use for the * socket timeout. */ - private static final String PROP_SOCKET_TIMEOUT_PERIOD = "org.joesnmp.joeSNMP.vmhacks.socketSoTimeoutPeriod"; + private static final String PROP_SOCKET_TIMEOUT_PERIOD = "org.opennms.joeSNMP.vmhacks.socketSoTimeoutPeriod"; /** * Private constructor used to disallow the @@ -505,7 +505,8 @@ boolean handled = true; try { - Class loggerC = Class.forName("org.joesnmp.core.utils.ThreadCategory"); + + Class loggerC = Class.forName("org.opennms.core.utils.ThreadCategory"); Class[] methodParmList = { Class.class }; Method loggerM = loggerC.getMethod("getInstance", methodParmList); @@ -601,7 +602,7 @@ boolean handled = true; try { - Class loggerC = Class.forName("org.joesnmp.core.utils.ThreadCategory"); + Class loggerC = Class.forName("org.opennms.core.utils.ThreadCategory"); Class[] methodParmList = { Class.class }; Method loggerM = loggerC.getMethod("getInstance", methodParmList); @@ -666,7 +667,7 @@ boolean handled = true; try { - Class loggerC = Class.forName("org.joesnmp.core.utils.ThreadCategory"); + Class loggerC = Class.forName("org.opennms.core.utils.ThreadCategory"); Class[] methodParmList = { Class.class }; Method loggerM = loggerC.getMethod("getInstance", methodParmList); @@ -715,7 +716,7 @@ boolean handled = true; try { - Class loggerC = Class.forName("org.joesnmp.core.utils.ThreadCategory"); + Class loggerC = Class.forName("org.opennms.core.utils.ThreadCategory"); Class[] methodParmList = { Class.class }; Method loggerM = loggerC.getMethod("getInstance", methodParmList); @@ -780,7 +781,7 @@ * @see SnmpPduRequest * @see SnmpPduBulk * @see SnmpParameters - * @see org.joesnmp.protocols.snmp.asn1.AsnEncoder + * @see org.opennms.protocols.snmp.asn1.AsnEncoder * */ void handlePkt(DatagramPacket pkt) 1.3 +3 -3 joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpTrapSession.java Index: SnmpTrapSession.java =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpTrapSession.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- SnmpTrapSession.java 23 Sep 2004 11:28:29 -0000 1.2 +++ SnmpTrapSession.java 16 Oct 2004 02:58:09 -0000 1.3 @@ -30,7 +30,7 @@ // // Modifications: // -// $Id: SnmpTrapSession.java,v 1.2 2004/09/23 11:28:29 andd Exp $ +// $Id: SnmpTrapSession.java,v 1.3 2004/10/16 02:58:09 brozow Exp $ // // 2004 Sep 23: Dim...@jb... // Allow RESPONSEs (presumably to INFORM_REQUEST) to go through @@ -431,7 +431,7 @@ * * @exception SnmpPduEncodingException Thrown if an encoding exception * occurs at the session level - * @exception org.joesnmp.protocols.snmp.asn1.AsnEncodingException Thrown + * @exception org.opennms.protocols.snmp.asn1.AsnEncodingException Thrown * if an encoding exception occurs in the AsnEncoder object. * @exception java.io.IOException Thrown if an error occurs sending the * encoded datagram @@ -527,7 +527,7 @@ * * @exception SnmpPduEncodingException Thrown if an encoding exception * occurs at the session level - * @exception org.joesnmp.protocols.snmp.asn1.AsnEncodingException Thrown + * @exception org.opennms.protocols.snmp.asn1.AsnEncodingException Thrown * if an encoding exception occurs in the AsnEncoder object. * @exception java.io.IOException Thrown if an error occurs sending the * encoded datagram 1.3 +5 -5 joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpSession.java Index: SnmpSession.java =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpSession.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- SnmpSession.java 19 Sep 2004 23:44:27 -0000 1.2 +++ SnmpSession.java 16 Oct 2004 02:58:09 -0000 1.3 @@ -30,7 +30,7 @@ // // Modifications: // -// $Id: SnmpSession.java,v 1.2 2004/09/19 23:44:27 andd Exp $ +// $Id: SnmpSession.java,v 1.3 2004/10/16 02:58:09 brozow Exp $ // // 2004 Sep 20: Dim...@jb... // Added local binding address @@ -134,7 +134,7 @@ * timeouts. It is also used to schedule the cleanup * of the m_requests list. * - * @see org.joesnmp.protocols.snmp.SnmpSession.CleanupRequest + * @see org.opennms.protocols.snmp.SnmpSession.CleanupRequest * @see SnmpRequest */ private SnmpTimer m_timer; @@ -394,7 +394,7 @@ * * @exception SnmpPduEncodingException Thrown if an encoding exception * occurs at the session level - * @exception org.joesnmp.protocols.snmp.asn1.AsnEncodingException Thrown + * @exception org.opennms.protocols.snmp.asn1.AsnEncodingException Thrown * if an encoding exception occurs in the AsnEncoder object. */ private ByteArrayInfo encode(SnmpPduPacket pdu) throws SnmpPduEncodingException, AsnEncodingException @@ -471,7 +471,7 @@ * * @exception SnmpPduEncodingException Thrown if an encoding exception * occurs at the session level - * @exception org.joesnmp.protocols.snmp.asn1.AsnEncodingException Thrown + * @exception org.opennms.protocols.snmp.asn1.AsnEncodingException Thrown * if an encoding exception occurs in the AsnEncoder object. */ private ByteArrayInfo encode(SnmpPduTrap pdu) throws SnmpPduEncodingException, AsnEncodingException @@ -624,7 +624,7 @@ * * @exception SnmpPduEncodingException Thrown if an encoding exception * occurs at the session level - * @exception org.joesnmp.protocols.snmp.asn1.AsnEncodingException Thrown + * @exception org.opennms.protocols.snmp.asn1.AsnEncodingException Thrown * if an encoding exception occurs in the AsnEncoder object. * @exception java.io.IOException Thrown if an error occurs sending the * encoded datagram 1.2 +6 -6 joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpSMI.java Index: SnmpSMI.java =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpSMI.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SnmpSMI.java 19 Sep 2004 23:01:11 -0000 1.1 +++ SnmpSMI.java 16 Oct 2004 02:58:09 -0000 1.2 @@ -30,7 +30,7 @@ // // Modifications: // -// $Id: SnmpSMI.java,v 1.1 2004/09/19 23:01:11 andd Exp $ +// $Id: SnmpSMI.java,v 1.2 2004/10/16 02:58:09 brozow Exp $ // package org.opennms.protocols.snmp; @@ -40,7 +40,7 @@ /** * SNMP SMI v1 & v2 constants. * - * @see org.joesnmp.protocols.snmp.asn1.ASN1 + * @see org.opennms.protocols.snmp.asn1.ASN1 * * @version 1.1.1.1 * @author <a href="mailto:we...@oc...">Brian Weaver</a> @@ -52,7 +52,7 @@ * Defines the positive and negative whole numbers, including zero. * The value is represented as a 32-bit signed integer. * - * @see org.joesnmp.protocols.snmp.asn1.ASN1#INTEGER + * @see org.opennms.protocols.snmp.asn1.ASN1#INTEGER */ public static final byte SMI_INTEGER = (ASN1.UNIVERSAL | ASN1.INTEGER); @@ -60,7 +60,7 @@ * A sequence of zero or more octets, where an octet is * an 8-bit quantity. * - * @see org.joesnmp.protocols.snmp.asn1.ASN1#OCTETSTRING + * @see org.opennms.protocols.snmp.asn1.ASN1#OCTETSTRING */ public static final byte SMI_STRING = (ASN1.UNIVERSAL | ASN1.OCTETSTRING); @@ -68,7 +68,7 @@ * A set of values associated with the information objects * defined by the standard. * - * @see org.joesnmp.protocols.snmp.asn1.ASN1#OBJECTID + * @see org.opennms.protocols.snmp.asn1.ASN1#OBJECTID */ public static final byte SMI_OBJECTID = (ASN1.UNIVERSAL | ASN1.OBJECTID); @@ -76,7 +76,7 @@ * A Null value. Commonly used to where there are several * alternatives but none of them apply. * - * @see org.joesnmp.protocols.snmp.asn1.ASN1#NULL + * @see org.opennms.protocols.snmp.asn1.ASN1#NULL */ public static final byte SMI_NULL = (ASN1.UNIVERSAL | ASN1.NULL); 1.2 +2 -2 joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpPduEncodingException.java Index: SnmpPduEncodingException.java =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpPduEncodingException.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SnmpPduEncodingException.java 19 Sep 2004 23:01:11 -0000 1.1 +++ SnmpPduEncodingException.java 16 Oct 2004 02:58:09 -0000 1.2 @@ -30,7 +30,7 @@ // // Modifications: // -// $Id: SnmpPduEncodingException.java,v 1.1 2004/09/19 23:01:11 andd Exp $ +// $Id: SnmpPduEncodingException.java,v 1.2 2004/10/16 02:58:09 brozow Exp $ // package org.opennms.protocols.snmp; @@ -41,7 +41,7 @@ * encoding exception occurs at the SNMP level and not * via the AsnEncoder class. * - * @see org.joesnmp.protocols.snmp.asn1.AsnEncoder + * @see org.opennms.protocols.snmp.asn1.AsnEncoder * @version 1.1.1.1 */ public class SnmpPduEncodingException extends Exception 1.2 +2 -2 joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpParameters.java Index: SnmpParameters.java =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpParameters.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SnmpParameters.java 19 Sep 2004 23:01:11 -0000 1.1 +++ SnmpParameters.java 16 Oct 2004 02:58:09 -0000 1.2 @@ -30,7 +30,7 @@ // // Modifications: // -// $Id: SnmpParameters.java,v 1.1 2004/09/19 23:01:11 andd Exp $ +// $Id: SnmpParameters.java,v 1.2 2004/10/16 02:58:09 brozow Exp $ // package org.opennms.protocols.snmp; @@ -74,7 +74,7 @@ * The AsnEncoder object used by the session to * encode and decode information. * - * @see org.joesnmp.protocols.snmp.asn1.BerEncoder + * @see org.opennms.protocols.snmp.asn1.BerEncoder */ private AsnEncoder m_encoder; |
From: Matt B. <br...@us...> - 2004-10-16 02:58:20
|
User: brozow Date: 04/10/15 19:58:08 Modified: . CHANGELOG.txt TODO.txt Log: Renamed a few things to org.opennms rather than org.joesnmp so that the code will work with the opennms code base. Matt Brozowski br...@op... Revision Changes Path 1.4 +4 -0 joesnmp/CHANGELOG.txt Index: CHANGELOG.txt =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/CHANGELOG.txt,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- CHANGELOG.txt 7 Oct 2004 14:09:39 -0000 1.3 +++ CHANGELOG.txt 16 Oct 2004 02:58:08 -0000 1.4 @@ -1,3 +1,7 @@ +v0.3.3 +--------------------------------------------------------------------- +- fix references a few remaining references to org.joesnmp - brozow + v0.3.2, 2004 Oct 07 ---------------------------------------------------------------------- - first developers version to be released from sourceforge 1.3 +1 -1 joesnmp/TODO.txt Index: TODO.txt =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/TODO.txt,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- TODO.txt 7 Oct 2004 14:09:39 -0000 1.2 +++ TODO.txt 16 Oct 2004 02:58:08 -0000 1.3 @@ -7,7 +7,7 @@ - import samples from opennms -- remove reflective log statements to org.joesnmp.core.utils.ThreadCategory +- remove reflective log statements to org.opennms.core.utils.ThreadCategory or at least mediate calls with a single class, and have the option of using apache-commons for example |
From: Dimitris A. <an...@us...> - 2004-10-07 14:11:08
|
User: andd Date: 04/10/07 07:09:40 Modified: . CHANGELOG.txt TODO.txt build.properties build.xml Added: . README.txt Log: - first developers version to be released from sourceforge - added the logic to terminate the threads of Thread pool in close() - thread pool disabled by default at SnmpPortal (kri...@ie...) - added TODO.txt, README.txt - added classes SnmpAgent, SnmpAgentHandler - added thread pool (5-12 threads) to SnmpPortal (kri...@ie...) - Allow RESPONSEs (presumably to INFORM_REQUEST) in addition to V2TRAPs, from send(SnmpPeer, SnmpPduPacket). Suggested by Cal...@an... Revision Changes Path 1.3 +7 -6 joesnmp/CHANGELOG.txt Index: CHANGELOG.txt =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/CHANGELOG.txt,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- CHANGELOG.txt 3 Oct 2004 22:02:47 -0000 1.2 +++ CHANGELOG.txt 7 Oct 2004 14:09:39 -0000 1.3 @@ -1,21 +1,22 @@ -- thread pool disabled by default at SnmpPortal (kri...@ie...) -- added TODO.txt - -v0.3.2DR, 2004 Sep 23 +v0.3.2, 2004 Oct 07 ---------------------------------------------------------------------- +- first developers version to be released from sourceforge +- added the logic to terminate the threads of Thread pool in close() +- thread pool disabled by default at SnmpPortal (kri...@ie...) +- added TODO.txt, README.txt - added classes SnmpAgent, SnmpAgentHandler - added thread pool (5-12 threads) to SnmpPortal (kri...@ie...) - Allow RESPONSEs (presumably to INFORM_REQUEST) in addition to V2TRAPs, from send(SnmpPeer, SnmpPduPacket). Suggested by Cal...@an... -v0.3.1DR, 2004 Sep 19 +v0.3.1, 2004 Sep 19 ---------------------------------------------------------------------- - SnmpPortal, SnmpSession, added ability to specify bind port/address at CTOR - added src/etc/Manifest.mf with automatic version replacement - added .classpath and .project files for importing project to Eclipse - moved back org.joesnmp to org.opennms to retain backwards compatibility -v0.3.0DR, 2004 +v0.3.0, 2004 ---------------------------------------------------------------------- - builds with Sun SDK 1.4.1 under Win2k shell (build.bat) - builds with Sun SDK 1.4.1 under Win2k plus cygwin (build.sh) 1.2 +2 -0 joesnmp/TODO.txt Index: TODO.txt =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/TODO.txt,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- TODO.txt 3 Oct 2004 22:02:48 -0000 1.1 +++ TODO.txt 7 Oct 2004 14:09:39 -0000 1.2 @@ -5,6 +5,8 @@ - create tests, we badly need them +- import samples from opennms + - remove reflective log statements to org.joesnmp.core.utils.ThreadCategory or at least mediate calls with a single class, and have the option of using apache-commons for example 1.6 +1 -1 joesnmp/build.properties Index: build.properties =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/build.properties,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- build.properties 23 Sep 2004 11:28:27 -0000 1.5 +++ build.properties 7 Oct 2004 14:09:39 -0000 1.6 @@ -1,3 +1,3 @@ # joesnmp version -joesnmp.version = 0.3.2DR +joesnmp.version = 0.3.2 1.5 +9 -3 joesnmp/build.xml Index: build.xml =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/build.xml,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- build.xml 19 Sep 2004 23:01:09 -0000 1.4 +++ build.xml 7 Oct 2004 14:09:39 -0000 1.5 @@ -1,7 +1,7 @@ <?xml version="1.0" ?> <!-- ======================================================================== - $Id: build.xml,v 1.4 2004/09/19 23:01:09 andd Exp $ + $Id: build.xml,v 1.5 2004/10/07 14:09:39 andd Exp $ ======================================================================== --> <project name="joesnmp" default="build" basedir="."> @@ -21,6 +21,7 @@ <!-- output dirs --> <property name="output.lib" value="${output.dir}/lib"/> <property name="output.etc" value="${output.dir}/etc"/> +<property name="output.dist" value="${output.dir}/dist"/> <property name="output.classes" value="${output.dir}/classes"/> <!-- ============================================================ --> @@ -33,8 +34,13 @@ <target name="zip" depends="build-joesnmp" description="-->create a distribution of joesnmp lib"> - <zip zipfile="${output.dir}/joesnmp-${joesnmp.version}.zip" update="false"> - <zipfileset dir="${output.lib}" prefix="joesnmp-${joesnmp.version}"/> + <mkdir dir="${output.dist}"/> + <zip zipfile="${output.dist}/joesnmp-${joesnmp.version}.zip" update="false"> + <zipfileset dir="." prefix="joesnmp-${joesnmp.version}"> + <exclude name="${output.etc}/**"/> + <exclude name="${output.dist}/**"/> + <exclude name="${output.classes}/**"/> + </zipfileset> </zip> </target> 1.1 joesnmp/README.txt Index: README.txt =================================================================== In cooperation with OpenNMS, joeSNMP was forked into a separate sourceforge project in order to retain it's LGPL license. see, http://sourceforge.net/projects/joesnmp Please, send your questions/patches/suggestions to the joeSNMP mailing lists hosted at sourceforge |
From: Dimitris A. <an...@us...> - 2004-10-07 14:11:07
|
User: andd Date: 04/10/07 07:09:41 Modified: src/joesnmp/org/opennms/protocols/snmp SnmpPortal.java Log: - first developers version to be released from sourceforge - added the logic to terminate the threads of Thread pool in close() - thread pool disabled by default at SnmpPortal (kri...@ie...) - added TODO.txt, README.txt - added classes SnmpAgent, SnmpAgentHandler - added thread pool (5-12 threads) to SnmpPortal (kri...@ie...) - Allow RESPONSEs (presumably to INFORM_REQUEST) in addition to V2TRAPs, from send(SnmpPeer, SnmpPduPacket). Suggested by Cal...@an... Revision Changes Path 1.4 +107 -74 joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpPortal.java Index: SnmpPortal.java =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpPortal.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- SnmpPortal.java 3 Oct 2004 22:02:50 -0000 1.3 +++ SnmpPortal.java 7 Oct 2004 14:09:41 -0000 1.4 @@ -30,7 +30,11 @@ // // Modifications: // -// $Id: SnmpPortal.java,v 1.3 2004/10/03 22:02:50 andd Exp $ +// $Id: SnmpPortal.java,v 1.4 2004/10/07 14:09:41 andd Exp $ +// +//2004 Oct 04: kri...@ie... +// Changed the default scope of the thread pool variables & Executor class, +// and added the logic to terminate the threads of Thread pool in close() // // 2004 Sep 24: kri...@ie... // Changed the default thread pool size to 0. This means that thread pool @@ -88,7 +92,7 @@ public class SnmpPortal extends Object { - public static final int DEFAULT_THREADPOOL_SIZE = 0; + public static final int DEFAULT_THREADPOOL_SIZE=0; public static final int MAXIMUM_THREADPOOL_SIZE = 12; /** @@ -118,7 +122,11 @@ */ private int m_numOfExecutorThreads = DEFAULT_THREADPOOL_SIZE; - + /** + * The thread pool that holds the executor threads + */ + Vector m_threadPool; + /** * ASN.1 encoder used to decode the SNMP messages. * If the decoded fails to decode the specific messages @@ -303,6 +311,17 @@ m_numOfExecutorThreads = numOfThreads; } + + m_threadPool = new Vector(m_numOfExecutorThreads); + //Thread Pool will be created only if the m_numOfExecutorThreads is greater than ZERO + //Otherwise the Receiver thread itself will handle the packet. + for(int nThreadID = 0; nThreadID < m_numOfExecutorThreads; nThreadID++) + { + Executor fastExecutor = new Executor("SnmpFastExecutor-" + (nThreadID+1)); + m_threadPool.add(fastExecutor); + fastExecutor.start(); + } + m_recvThread = new Thread(new Receiver(), "SnmpPortal-" + m_comm.getPort()); m_encoder = encoder; @@ -310,6 +329,70 @@ } + + /** + * Defines the inner class, Executor threas, which + * will be part of thread pool that is used for + * handling the packet + * + */ + private class Executor extends Thread + { + + DatagramPacket pkt = null; + boolean suspendFlag = false; + + public Executor(String str) + { + super(str); + } + + public void run() + { + while(false == m_isClosing) + { + try + { + if(null != pkt) + { + invokeHandlePkt(pkt); + pkt = null; + } + mySuspend(); + + synchronized(this) + { + while(suspendFlag) + { + wait(); + } + } + } + catch (InterruptedException e) + { + e.printStackTrace(); + } + } + } + + synchronized void mySuspend() + { + suspendFlag = true; + } + + synchronized boolean isSuspended() + { + return suspendFlag; + } + + synchronized void myResume() + { + suspendFlag = false; + notify(); + } + } + + /** * Defines the inner class that monitors the * datagram socket and receives all the PDU responses. @@ -379,19 +462,6 @@ return; } - Vector threadPool = new Vector(m_numOfExecutorThreads); - - // Thread Pool will be created only if m_numOfExecutorThreads > 0 - // Otherwise the Receiver thread itself will handle the packet. - for(int nThreadID = 0; nThreadID < m_numOfExecutorThreads; nThreadID++) - { - Executor fastExecutor = new Executor("SnmpFastExecutor-" + (nThreadID+1)); - threadPool.add(fastExecutor); - fastExecutor.start(); - //System.out.println(new Date() + "Thread Created count " + (nThreadID+1) ); - } - //System.out.println(new Date() + "Lets Assign to some thread. The size of the vector is :: " + threadPool.size()); - final LinkedList fastReceiverQ = new LinkedList(); final LinkedList usedBuffers = new LinkedList(); Thread fastReceiver = new Thread(new Runnable() @@ -498,7 +568,7 @@ { for(int nThreadIndex = 0; nThreadIndex < m_numOfExecutorThreads; ++nThreadIndex) { - Executor fastExecutor = (Executor)threadPool.elementAt(nThreadIndex); + Executor fastExecutor = (Executor)m_threadPool.elementAt(nThreadIndex); if(true == fastExecutor.isSuspended()){ //System.out.println("Index of thread that is idle and can again start is :: " + nThreadIndex); @@ -573,61 +643,6 @@ } } } // end run() - - private class Executor extends Thread - { - DatagramPacket pkt = null; - boolean suspendFlag = false; - - public Executor(String str) - { - super(str); - } - - public void run() - { - while(true) - { - try - { - if(null != pkt) - { - invokeHandlePkt(pkt); - pkt = null; - } - mySuspend(); - - synchronized(this) - { - while(suspendFlag) - { - wait(); - } - } - } - catch (InterruptedException e) - { - e.printStackTrace(); - } - } - } - - synchronized void mySuspend() - { - suspendFlag = true; - } - - synchronized boolean isSuspended() - { - return suspendFlag; - } - - synchronized void myResume() - { - suspendFlag = false; - notify(); - } - } } /** @@ -1014,7 +1029,26 @@ try { - // + //Now try to close the threads in pool just by invoking resume... + //The threads will die as the m_closing flag is set + if(0 < m_numOfExecutorThreads) + { + for(int nThreadIndex = 0; nThreadIndex < m_numOfExecutorThreads; ++nThreadIndex) + { + Executor fastExecutor = (Executor)m_threadPool.elementAt(nThreadIndex); + if(true == fastExecutor.isSuspended()) + { + fastExecutor.myResume(); // This resume will actually kill the thread as the m_isClosing flag is set + } + else + { + //Since the thread is doing something lets just wait for a moment and then try again + --nThreadIndex; + wait(100); + } + } + } + // make sure that the caller thread // is not the one we are trying to // join! @@ -1030,5 +1064,4 @@ } } } -// vim:tabstop=8:noexpandtab:shiftwidth=8 |
From: Dimitris A. <an...@us...> - 2004-10-07 14:11:06
|
User: andd Date: 04/10/07 07:09:41 Modified: docs FAQ.txt Log: - first developers version to be released from sourceforge - added the logic to terminate the threads of Thread pool in close() - thread pool disabled by default at SnmpPortal (kri...@ie...) - added TODO.txt, README.txt - added classes SnmpAgent, SnmpAgentHandler - added thread pool (5-12 threads) to SnmpPortal (kri...@ie...) - Allow RESPONSEs (presumably to INFORM_REQUEST) in addition to V2TRAPs, from send(SnmpPeer, SnmpPduPacket). Suggested by Cal...@an... Revision Changes Path 1.2 +3 -1 joesnmp/docs/FAQ.txt Index: FAQ.txt =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/docs/FAQ.txt,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- FAQ.txt 17 Dec 2003 17:12:00 -0000 1.1 +++ FAQ.txt 7 Oct 2004 14:09:40 -0000 1.2 @@ -1,6 +1,8 @@ JoeSNMP FAQ -1.1.1.1 +$Id: FAQ.txt,v 1.2 2004/10/07 14:09:40 andd Exp $ + +(Note: needs updating after joeSNMP became a separate sourceforge project) ------------------------------------------------------------------------------ |
From: Dimitris A. <an...@us...> - 2004-10-03 22:04:54
|
User: andd Date: 04/10/03 15:02:48 Modified: . CHANGELOG.txt Added: . TODO.txt Log: threadpool disabled by default Revision Changes Path 1.2 +3 -0 joesnmp/CHANGELOG.txt Index: CHANGELOG.txt =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/CHANGELOG.txt,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- CHANGELOG.txt 23 Sep 2004 14:21:21 -0000 1.1 +++ CHANGELOG.txt 3 Oct 2004 22:02:47 -0000 1.2 @@ -1,3 +1,6 @@ +- thread pool disabled by default at SnmpPortal (kri...@ie...) +- added TODO.txt + v0.3.2DR, 2004 Sep 23 ---------------------------------------------------------------------- - added classes SnmpAgent, SnmpAgentHandler 1.1 joesnmp/TODO.txt Index: TODO.txt =================================================================== List of TODO items, in case you are interested :) ===================================================================== - create tests, we badly need them - remove reflective log statements to org.joesnmp.core.utils.ThreadCategory or at least mediate calls with a single class, and have the option of using apache-commons for example - Externalize the thread pool from SnmpPortal using possibly a new derived class, or a handler that does thread management. - Merge any bug-fixes, test code, joesnmp related stuff from opennms |
From: Dimitris A. <an...@us...> - 2004-10-03 22:04:19
|
User: andd Date: 04/10/03 15:02:50 Modified: src/joesnmp/org/opennms/protocols/snmp SnmpPortal.java Log: threadpool disabled by default Revision Changes Path 1.3 +157 -122 joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpPortal.java Index: SnmpPortal.java =================================================================== RCS file: /cvsroot/joesnmp/joesnmp/src/joesnmp/org/opennms/protocols/snmp/SnmpPortal.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- SnmpPortal.java 22 Sep 2004 23:28:04 -0000 1.2 +++ SnmpPortal.java 3 Oct 2004 22:02:50 -0000 1.3 @@ -30,7 +30,13 @@ // // Modifications: // -// $Id: SnmpPortal.java,v 1.2 2004/09/22 23:28:04 andd Exp $ +// $Id: SnmpPortal.java,v 1.3 2004/10/03 22:02:50 andd Exp $ +// +// 2004 Sep 24: kri...@ie... +// Changed the default thread pool size to 0. This means that thread pool +// is inactive by default, in which case the receiver thread will take care +// of handle packet. Also a wrapper function invokeHandlePkt has been +// introduced to handle exceptions in a central location to reduce code. // // 2004 Sep 22: kri...@ie... // Added the feature of thread pooling. There will be a pool of threads and @@ -72,6 +78,8 @@ * @author <a href="mailto:we...@oc...">Brian Weaver</a> * @author <a href="mailto:so...@op...">Sowmya Nataraj</a> * @author <a href="http://www.opennms.org">OpenNMS</a> + * @author <a href="mailto:dim...@jb...">Dimitris Andreadis</a> + * @author <a href="mailto:kri...@ie..."></a> * * @see SnmpSession * @see SnmpTrapSession @@ -80,8 +88,8 @@ public class SnmpPortal extends Object { - public static final int DEFAULT_THREADS = 5; - public static final int MAXIMUM_THREADS = 12; + public static final int DEFAULT_THREADPOOL_SIZE = 0; + public static final int MAXIMUM_THREADPOOL_SIZE = 12; /** * The packet handler that is used to process @@ -108,7 +116,7 @@ * the number of executor threads in the thread pool * specified during construction of SnmpPortal */ - private int m_numOfExecutorThreads = DEFAULT_THREADS; + private int m_numOfExecutorThreads = DEFAULT_THREADPOOL_SIZE; /** @@ -185,7 +193,7 @@ throws SocketException { // Call the other constructor with default number of threads - this(handler, encoder, port, null, DEFAULT_THREADS); + this(handler, encoder, port, null, DEFAULT_THREADPOOL_SIZE); } /** @@ -208,7 +216,7 @@ throws SocketException { // Call the other constructor with default number of threads - this(handler, encoder, port, laddr, DEFAULT_THREADS); + this(handler, encoder, port, laddr, DEFAULT_THREADPOOL_SIZE); } /** @@ -290,7 +298,7 @@ m_isClosing = false; // Check for the boundary conditions for requested number of threads - if( 0 < numOfThreads && numOfThreads <= MAXIMUM_THREADS ) + if( 0 < numOfThreads && numOfThreads <= MAXIMUM_THREADPOOL_SIZE ) { m_numOfExecutorThreads = numOfThreads; } @@ -373,6 +381,8 @@ Vector threadPool = new Vector(m_numOfExecutorThreads); + // Thread Pool will be created only if m_numOfExecutorThreads > 0 + // Otherwise the Receiver thread itself will handle the packet. for(int nThreadID = 0; nThreadID < m_numOfExecutorThreads; nThreadID++) { Executor fastExecutor = new Executor("SnmpFastExecutor-" + (nThreadID+1)); @@ -484,27 +494,35 @@ //System.out.println(new Date() + "PKT Contents are :: " + pkt.toString()); } - //System.out.println("Lets Assign to some thread. The size of the vector is :: " + threadPool.size()); - for(int nThreadIndex = 0; nThreadIndex < m_numOfExecutorThreads; ++nThreadIndex) + if(m_numOfExecutorThreads > 0) { - Executor fastExecutor = (Executor)threadPool.elementAt(nThreadIndex); - if(true == fastExecutor.isSuspended()){ + for(int nThreadIndex = 0; nThreadIndex < m_numOfExecutorThreads; ++nThreadIndex) + { + Executor fastExecutor = (Executor)threadPool.elementAt(nThreadIndex); + if(true == fastExecutor.isSuspended()){ - //System.out.println("Index of thread that is idle and can again start is :: " + nThreadIndex); + //System.out.println("Index of thread that is idle and can again start is :: " + nThreadIndex); - fastExecutor.pkt = pkt; - fastExecutor.myResume(); - - break; + fastExecutor.pkt = pkt; + fastExecutor.myResume(); + + break; + } + + if(nThreadIndex + 1 >= m_numOfExecutorThreads){ + // about to terminate the loop + // sleep for a while and start over + nThreadIndex = -1; + wait(100); + } } - - if(nThreadIndex + 1 >= m_numOfExecutorThreads){ - // about to terminate the loop - // sleep for a while and start over - nThreadIndex = -1; - wait(100); - } } + else + { + // Thread pool is not used so Receiver thread should handle the packet + invokeHandlePkt(pkt); + } + } catch(Exception e) { @@ -574,7 +592,7 @@ { if(null != pkt) { - handlePkt(pkt); + invokeHandlePkt(pkt); pkt = null; } mySuspend(); @@ -587,104 +605,6 @@ } } } - catch(SnmpPduEncodingException err) - { - boolean handled = true; - try - { - Class loggerC = Class.forName("org.joesnmp.core.utils.ThreadCategory"); - - Class[] methodParmList = { Class.class }; - Method loggerM = loggerC.getMethod("getInstance", methodParmList); - - Object[] parmList = { this.getClass() }; - Object loggerI = loggerM.invoke(null, parmList); - - methodParmList = new Class[] { Object.class, Throwable.class }; - Method infoM = loggerC.getMethod("info", methodParmList); - - parmList = new Object[] { "An error occured decoding the protocol data unit", err }; - infoM.invoke(loggerI, parmList); - - methodParmList = new Class[0]; - Method debugEnabledM = loggerC.getMethod("isDebugEnabled", methodParmList); - - parmList = new Object[0]; - Boolean isEnabled = (Boolean) debugEnabledM.invoke(loggerI, parmList); - - if(isEnabled.booleanValue()) - { - methodParmList = new Class[] { Object.class }; - Method debugM = loggerC.getMethod("debug", methodParmList); - - OutputStream ostream = new ByteArrayOutputStream(); - SnmpUtil.dumpHex(new PrintStream(ostream), pkt.getData(), 0, pkt.getLength()); - - parmList = new Object[] { ostream }; - debugM.invoke(loggerI, parmList); - } - } - catch(Throwable t) - { - handled = false; - } - - if(!handled) - { - System.out.println(new Date() + " - SnmpPortal.Receiver.run: SnmpPduEncodingException: " + err.getMessage()); - SnmpUtil.dumpHex(System.out, pkt.getData(), 0, pkt.getLength()); - } - m_handler.processBadDatagram(pkt); - } - catch(AsnDecodingException err) - { - boolean handled = true; - try - { - Class loggerC = Class.forName("org.joesnmp.core.utils.ThreadCategory"); - - Class[] methodParmList = { Class.class }; - Method loggerM = loggerC.getMethod("getInstance", methodParmList); - - Object[] parmList = { this.getClass() }; - Object loggerI = loggerM.invoke(null, parmList); - - methodParmList = new Class[] { Object.class, Throwable.class }; - Method infoM = loggerC.getMethod("info", methodParmList); - - parmList = new Object[] { "An ASN.1 error occured decoding the packet", err }; - infoM.invoke(loggerI, parmList); - - methodParmList = new Class[0]; - Method debugEnabledM = loggerC.getMethod("isDebugEnabled", methodParmList); - - parmList = new Object[0]; - Boolean isEnabled = (Boolean) debugEnabledM.invoke(loggerI, parmList); - - if(isEnabled.booleanValue()) - { - methodParmList = new Class[] { Object.class }; - Method debugM = loggerC.getMethod("debug", methodParmList); - - OutputStream ostream = new ByteArrayOutputStream(); - SnmpUtil.dumpHex(new PrintStream(ostream), pkt.getData(), 0, pkt.getLength()); - - parmList = new Object[] { ostream }; - debugM.invoke(loggerI, parmList); - } - } - catch(Throwable t) - { - handled = false; - } - - if(!handled) - { - System.out.println(new Date() + " - SnmpPortal.Receiver.run: AsnEncodingException: " + err.getMessage()); - SnmpUtil.dumpHex(System.out, pkt.getData(), 0, pkt.getLength()); - } - m_handler.processBadDatagram(pkt); - } catch (InterruptedException e) { e.printStackTrace(); @@ -710,6 +630,121 @@ } } + /** + * Wrapper for invoking the handlePkt method and handling the necessary exceptions. + * + * @param pkt The datagram packet to be decoded + * + * @exception none + * + * @see handlePkt + * + */ + void invokeHandlePkt(DatagramPacket pkt) + { + try + { + handlePkt(pkt); + } + catch(SnmpPduEncodingException err) + { + boolean handled = true; + try + { + Class loggerC = Class.forName("org.joesnmp.core.utils.ThreadCategory"); + + Class[] methodParmList = { Class.class }; + Method loggerM = loggerC.getMethod("getInstance", methodParmList); + + Object[] parmList = { this.getClass() }; + Object loggerI = loggerM.invoke(null, parmList); + + methodParmList = new Class[] { Object.class, Throwable.class }; + Method infoM = loggerC.getMethod("info", methodParmList); + + parmList = new Object[] { "An error occured decoding the protocol data unit", err }; + infoM.invoke(loggerI, parmList); + + methodParmList = new Class[0]; + Method debugEnabledM = loggerC.getMethod("isDebugEnabled", methodParmList); + + parmList = new Object[0]; + Boolean isEnabled = (Boolean) debugEnabledM.invoke(loggerI, parmList); + + if(isEnabled.booleanValue()) + { + methodParmList = new Class[] { Object.class }; + Method debugM = loggerC.getMethod("debug", methodParmList); + + OutputStream ostream = new ByteArrayOutputStream(); + SnmpUtil.dumpHex(new PrintStream(ostream), pkt.getData(), 0, pkt.getLength()); + + parmList = new Object[] { ostream }; + debugM.invoke(loggerI, parmList); + } + } + catch(Throwable t) + { + handled = false; + } + + if(!handled) + { + System.out.println(new Date() + " - SnmpPortal.Receiver.run: SnmpPduEncodingException: " + err.getMessage()); + SnmpUtil.dumpHex(System.out, pkt.getData(), 0, pkt.getLength()); + } + m_handler.processBadDatagram(pkt); + } + catch(AsnDecodingException err) + { + boolean handled = true; + try + { + Class loggerC = Class.forName("org.joesnmp.core.utils.ThreadCategory"); + + Class[] methodParmList = { Class.class }; + Method loggerM = loggerC.getMethod("getInstance", methodParmList); + + Object[] parmList = { this.getClass() }; + Object loggerI = loggerM.invoke(null, parmList); + + methodParmList = new Class[] { Object.class, Throwable.class }; + Method infoM = loggerC.getMethod("info", methodParmList); + + parmList = new Object[] { "An ASN.1 error occured decoding the packet", err }; + infoM.invoke(loggerI, parmList); + + methodParmList = new Class[0]; + Method debugEnabledM = loggerC.getMethod("isDebugEnabled", methodParmList); + + parmList = new Object[0]; + Boolean isEnabled = (Boolean) debugEnabledM.invoke(loggerI, parmList); + + if(isEnabled.booleanValue()) + { + methodParmList = new Class[] { Object.class }; + Method debugM = loggerC.getMethod("debug", methodParmList); + + OutputStream ostream = new ByteArrayOutputStream(); + SnmpUtil.dumpHex(new PrintStream(ostream), pkt.getData(), 0, pkt.getLength()); + + parmList = new Object[] { ostream }; + debugM.invoke(loggerI, parmList); + } + } + catch(Throwable t) + { + handled = false; + } + + if(!handled) + { + System.out.println(new Date() + " - SnmpPortal.Receiver.run: AsnEncodingException: " + err.getMessage()); + SnmpUtil.dumpHex(System.out, pkt.getData(), 0, pkt.getLength()); + } + m_handler.processBadDatagram(pkt); + } + } /** * Recovers a SnmpPduPacket or SnmpPduTrap from the passed datagram |