snmppdutrap.java

来自「opennms得相关源码 请大家看看」· Java 代码 · 共 600 行 · 第 1/2 页

JAVA
600
字号
//// This file is part of the OpenNMS(R) Application.//// OpenNMS(R) is Copyright (C) 2002-2003 The OpenNMS Group, Inc.  All rights reserved.// OpenNMS(R) is a derivative work, containing both original code, included code and modified// code that was published under the GNU General Public License. Copyrights for modified // and included code are below.//// OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.// // Modifications://// 30 September 2003: Fixed a bad increment in a loop.//// Original code base Copyright (C) 1999-2001 Oculan Corp.  All rights reserved.//// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program 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 General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//// For more information contact://      OpenNMS Licensing       <license@opennms.org>//      http://www.opennms.org///      http://www.opennms.com///// Tab Size = 8//// SnmpPduTrap.java,v 1.1.1.1 2001/11/11 17:27:22 ben Exp//////// RFC 1902: Structure of Management Information for SNMPv2////   PDU ::= //    SEQUENCE {//      request-id   INTEGER32//      error-status INTEGER//      error-index  INTEGER//      Variable Bindings//    }//// BulkPDU ::=//    SEQUENCE {//      request-id      INTEGER32//      non-repeaters   INTEGER//      max-repetitions INTEGER//      Variable Bindings//    }////// RFC 1157: A Simple Network Management Protocol (SNMP)////   PDU ::= //    SEQUENCE {//      request-id   INTEGER//      error-status INTEGER//      error-index  INTEGER//      Variable Bindings//    }////   TrapPDU ::=//    SEQUENCE {//      enterprise    OBJECTID//	agent-address NetworkAddress//      generic-trap  INTEGER//      specific-trap INTEGER//      time-stamp    TIMETICKS//      Variable Bindings//    }//package org.opennms.protocols.snmp;import java.util.ArrayList;import org.opennms.protocols.snmp.asn1.ASN1;import org.opennms.protocols.snmp.asn1.AsnDecodingException;import org.opennms.protocols.snmp.asn1.AsnEncoder;import org.opennms.protocols.snmp.asn1.AsnEncodingException;/** * The SnmpPduTrap object represents the SNMP Protoco Data Unit for an SNMP * Trap. The PDU format for a TRAP is not similar to the PDU format for other V1 * types, and thus the SnmpPduTrap object does not extend the SnmpPduPacket * class. *  * @author <a href="mailto:weave@oculan.com">Brian Weaver </a> * @author <a href="http://www.opennms.org">OpenNMS </a> * @version 1.1.1.1 *  */public class SnmpPduTrap extends Object implements SnmpSyntax, Cloneable {    /**     * The trap's enterprise object identifier     */    private SnmpObjectId m_enterprise;    /**     * The IP Address of the remote agent sending the trap.     */    private SnmpIPAddress m_agentAddr;    /**     * The generic trap number.     */    private int m_generic;    /**     * The specific trap number.     */    private int m_specific;    /**     * The timestamp for when the trap occured. This should be the sysUpTime     * from the remote system.     */    private long m_tstamp;    /**     * The list of variable bindings for the trap.     */    private ArrayList m_variables;    /**     * The ASN.1 type for the SNMPv1 Trap.     */    public final static int TRAP = (int) (ASN1.CONTEXT | ASN1.CONSTRUCTOR | 4) + 256;    /**     * Generic trap type: cold start.     */    public final static int GenericColdStart = 0;    /**     * Generic trap type: warm start.     */    public final static int GenericWarmStart = 1;    /**     * Generic trap type: link down.     */    public final static int GenericLinkDown = 2;    /**     * Generic trap type: link up.     */    public final static int GenericLinkUp = 3;    /**     * Generic trap type: authentication-failure.     */    public final static int GenericAuthenticationFailure = 4;    /**     * Generic trap type: EGP Neighbor Loss.     */    public final static int GenericEgpNeighborLoss = 5;    /**     * Generic trap type: Enterprise Specific.     */    public final static int GenericEnterpriseSpecific = 6;    /**     * Constructs a new SnmpPduTrap with the default values.     *      */    public SnmpPduTrap() {        m_enterprise = new SnmpObjectId();        m_agentAddr = new SnmpIPAddress();        m_generic = 0;        m_specific = 0;        m_tstamp = 0L;        m_variables = new ArrayList();    }    /**     * Constructs a new trap pdu that is identical to the passed pdu.     *      * @param second     *            The object to copy.     *      */    protected SnmpPduTrap(SnmpPduTrap second) {        m_enterprise = second.m_enterprise;        m_agentAddr = second.m_agentAddr;        m_generic = second.m_generic;        m_specific = second.m_specific;        m_tstamp = second.m_tstamp;        m_variables = new ArrayList(second.m_variables.size());        for (int x = 0; x < second.m_variables.size(); x++) {            m_variables.add(((SnmpVarBind) (second.m_variables.get(x))).duplicate());        }    }    /**     * Used to get the enterpise identifier of the trap.     *      */    public SnmpObjectId getEnterprise() {        return m_enterprise;    }    /**     * Sets the enterprise identifier for the trap.     *      * @param id     *            The object identifier.     */    public void setEnterprise(SnmpObjectId id) {        m_enterprise = (SnmpObjectId) id.clone();    }    /**     * Sets the enterprise identifier for the trap. The string must be in the     * format of a dotted decimal object identifier.     *      * @param id     *            The new identifier.     *      */    public void setEnterprise(String id) {        m_enterprise = new SnmpObjectId(id);    }    /**     * Gets the remote agent's IP address.     *      */    public SnmpIPAddress getAgentAddress() {        return m_agentAddr;    }    /**     * Sets the remote agent's IP address.     *      * @param addr     *            The remote agent's ip address.     */    public void setAgentAddress(SnmpIPAddress addr) {        m_agentAddr = addr;    }    /**     * Returns the generic code for the trap.     */    public int getGeneric() {        return m_generic;    }    /**     * Sets the generic code for the trap.     *      * @param generic     *            The new generic code for the trap.     */    public void setGeneric(int generic) {        m_generic = generic;    }    /**     * Returns the specific code for the trap.     *      */    public int getSpecific() {        return m_specific;    }    /**     * Sets the specific type for the trap.     *      * @param spec     *            The new specific identifier.     *      */    public void setSpecific(int spec) {        m_specific = spec;    }    /**     * Returns the timeticks from the trap.     *      */    public long getTimeStamp() {        return m_tstamp;    }    /**

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?