Class SnmpPduTrap

  • All Implemented Interfaces:
    java.lang.Cloneable, SnmpSyntax

    public class SnmpPduTrap
    extends java.lang.Object
    implements SnmpSyntax, java.lang.Cloneable
    The SnmpPduTrap object represents the SNMP Protocol 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.
    Version:
    1.1.1.1
    Author:
    Brian Weaver , OpenNMS
    • Field Detail

      • GenericColdStart

        public static final int GenericColdStart
        Generic trap type: cold start.
        See Also:
        Constant Field Values
      • GenericWarmStart

        public static final int GenericWarmStart
        Generic trap type: warm start.
        See Also:
        Constant Field Values
      • GenericLinkDown

        public static final int GenericLinkDown
        Generic trap type: link down.
        See Also:
        Constant Field Values
      • GenericLinkUp

        public static final int GenericLinkUp
        Generic trap type: link up.
        See Also:
        Constant Field Values
      • GenericAuthenticationFailure

        public static final int GenericAuthenticationFailure
        Generic trap type: authentication-failure.
        See Also:
        Constant Field Values
      • GenericEgpNeighborLoss

        public static final int GenericEgpNeighborLoss
        Generic trap type: EGP Neighbor Loss.
        See Also:
        Constant Field Values
      • GenericEnterpriseSpecific

        public static final int GenericEnterpriseSpecific
        Generic trap type: Enterprise Specific.
        See Also:
        Constant Field Values
    • Constructor Detail

      • SnmpPduTrap

        public SnmpPduTrap()
        Constructs a new SnmpPduTrap with the default values.
      • SnmpPduTrap

        protected SnmpPduTrap​(SnmpPduTrap second)
        Constructs a new trap pdu that is identical to the passed pdu.
        Parameters:
        second - The object to copy.
    • Method Detail

      • getEnterprise

        public SnmpObjectId getEnterprise()
        Used to get the enterpise identifier of the trap.
      • setEnterprise

        public void setEnterprise​(SnmpObjectId id)
        Sets the enterprise identifier for the trap.
        Parameters:
        id - The object identifier.
      • setEnterprise

        public void setEnterprise​(java.lang.String id)
        Sets the enterprise identifier for the trap. The string must be in the format of a dotted decimal object identifier.
        Parameters:
        id - The new identifier.
      • getAgentAddress

        public SnmpIPAddress getAgentAddress()
        Gets the remote agent's IP address.
      • setAgentAddress

        public void setAgentAddress​(SnmpIPAddress addr)
        Sets the remote agent's IP address.
        Parameters:
        addr - The remote agent's ip address.
      • getGeneric

        public int getGeneric()
        Returns the generic code for the trap.
      • setGeneric

        public void setGeneric​(int generic)
        Sets the generic code for the trap.
        Parameters:
        generic - The new generic code for the trap.
      • getSpecific

        public int getSpecific()
        Returns the specific code for the trap.
      • setSpecific

        public void setSpecific​(int spec)
        Sets the specific type for the trap.
        Parameters:
        spec - The new specific identifier.
      • getTimeStamp

        public long getTimeStamp()
        Returns the timeticks from the trap.
      • setTimeStamp

        public void setTimeStamp​(long ts)
        Set's the timeticks in the trap.
        Parameters:
        ts - The timeticks for the trap.
      • getLength

        public int getLength()
        Returns the number of variables contained in the PDU.
      • addVarBind

        public void addVarBind​(SnmpVarBind vb)
        Adds a new variable to the protocol data unit. The variable is added at the end of the list
        Parameters:
        vb - The new variable to add
      • addVarBindAt

        public void addVarBindAt​(int ndx,
                                 SnmpVarBind vb)
        Adds a variable at a specific index.
        Parameters:
        ndx - The index of the variable
        vb - The new variable.
      • getVarBindAt

        public SnmpVarBind getVarBindAt​(int ndx)
        Retrieves the variable at the specific index.
        Parameters:
        ndx - The index of the variable
        Returns:
        The variable at the specified index
      • setVarBindAt

        public void setVarBindAt​(int ndx,
                                 SnmpVarBind vb)
        Sets the specific variable at the requested location.
        Parameters:
        ndx - The location to set
        vb - The new variable
      • removeVarBindAt

        public SnmpVarBind removeVarBindAt​(int ndx)
        Removes the variable as defined by the index
        Parameters:
        ndx - The index of the variable to remove
        Returns:
        The removed variable
      • toVarBindArray

        public SnmpVarBind[] toVarBindArray()
        Returns a list of all the variables managed by this protocol data unit.
        Returns:
        An array of the internal variable.
      • typeId

        public byte typeId()
        Returns the PDU commmand in an 8-bit format
        Specified by:
        typeId in interface SnmpSyntax
        Returns:
        The pdu command
      • encodeASN

        public int encodeASN​(byte[] buf,
                             int offset,
                             AsnEncoder encoder)
                      throws AsnEncodingException
        Encodes the protocol data unit using the passed encoder and stores the results in the passed buffer. An exception is thrown if an error occurs with the encoding of the information.
        Specified by:
        encodeASN in interface SnmpSyntax
        Parameters:
        buf - The buffer to write the encoded information.
        offset - The offset to start writing information
        encoder - The encoder object.
        Returns:
        The offset of the byte immediantly after the last encoded byte.
        Throws:
        AsnEncodingException - Thrown if the encoder finds an error in the buffer.
      • decodeASN

        public int decodeASN​(byte[] buf,
                             int offset,
                             AsnEncoder encoder)
                      throws AsnDecodingException
        Decodes the protocol data unit from the passed buffer. If an error occurs during the decoding sequence then an AsnDecodingException is thrown by the method. The value is decoded using the AsnEncoder passed to the object.
        Specified by:
        decodeASN in interface SnmpSyntax
        Parameters:
        buf - The encode buffer
        offset - The offset byte to begin decoding
        encoder - The decoder object.
        Returns:
        The index of the byte immediantly after the last decoded byte of information.
        Throws:
        AsnDecodingException - Thrown by the encoder if an error occurs trying to decode the data buffer.
      • duplicate

        public SnmpSyntax duplicate()
        Description copied from interface: SnmpSyntax
        Creates a duplicate (in memory) object of the caller. Similar to the clone() method.
        Specified by:
        duplicate in interface SnmpSyntax
      • clone

        public java.lang.Object clone()
        Overrides:
        clone in class java.lang.Object