Module org.snmp4j
Package org.snmp4j

Class PDUv1

  • All Implemented Interfaces:
    java.io.Serializable, BERSerializable

    public class PDUv1
    extends PDU
    The PDUv1 represents SNMPv1 PDUs. The behavior of this class is identical to its superclass PDU for the PDU type PDU.GET, PDU.GETNEXT, and PDU.SET. The other SNMPv2 PDU types implemented by PDU are not supported. In contrast to its super class, PDUv1 implements the PDU.V1TRAP type. To support this type, access methods are provided to get and set the enterprise OID, generic, specific, and timestamp of a SNMPv1 trap PDU. The constants defined for generic SNMPv1 traps are included in this class. The descriptions are taken from the SNMPv2-MIB (RFC 3418). The corresponding OIDs are defined in SnmpConstants.
    Version:
    1.7.3
    Author:
    Frank Fock
    See Also:
    Serialized Form
    • Field Detail

      • COLDSTART

        public static final int COLDSTART
        A coldStart(0) trap signifies that the SNMP entity, supporting a notification originator application, is reinitializing itself and that its configuration may have been altered.
        See Also:
        Constant Field Values
      • WARMSTART

        public static final int WARMSTART
        A warmStart(1) trap signifies that the SNMP entity, supporting a notification originator application, is reinitializing itself such that its configuration is unaltered.
        See Also:
        Constant Field Values
      • LINKDOWN

        public static final int LINKDOWN
        A linkDown(2) trap signifies that the SNMP entity, acting in an agent role, has detected that the ifOperStatus object for one of its communication links is about to enter the down state from some other state (but not from the notPresent state). This other state is indicated by the included value of ifOperStatus.
        See Also:
        Constant Field Values
      • LINKUP

        public static final int LINKUP
        A linkUp(3) trap signifies that the SNMP entity, acting in an agent role, has detected that the ifOperStatus object for one of its communication links left the down state and transitioned into some other state (but not into the notPresent state). This other state is indicated by the included value of ifOperStatus.
        See Also:
        Constant Field Values
      • AUTHENTICATIONFAILURE

        public static final int AUTHENTICATIONFAILURE
        An authenticationFailure(4) trap signifies that the SNMP entity has received a protocol message that is not properly authenticated. While all implementations of SNMP entities MAY be capable of generating this trap, the snmpEnableAuthenTraps object indicates whether this trap will be generated.
        See Also:
        Constant Field Values
      • ENTERPRISE_SPECIFIC

        public static final int ENTERPRISE_SPECIFIC
        If the generic trap identifier is ENTERPRISE_SPECIFIC(6), then the enterprise specific trap ID is given by the specificTrap member field.
        See Also:
        Constant Field Values
    • Constructor Detail

      • PDUv1

        public PDUv1()
      • PDUv1

        public PDUv1​(PDUv1 other)
        Copy constructor.
        Parameters:
        other - the PDUv1 to copy from.
        Since:
        1.9.1c
    • Method Detail

      • clone

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

        public void decodeBER​(BERInputStream inputStream)
                       throws java.io.IOException
        Decodes a Variable from an BERInputStream.
        Specified by:
        decodeBER in interface BERSerializable
        Overrides:
        decodeBER in class PDU
        Parameters:
        inputStream - an InputStream containing a BER encoded byte stream.
        Throws:
        java.io.IOException - if there is an encoding error in the BER stream.
      • encodeBER

        public void encodeBER​(java.io.OutputStream outputStream)
                       throws java.io.IOException
        Encodes a Variable to an OutputStream.
        Specified by:
        encodeBER in interface BERSerializable
        Overrides:
        encodeBER in class PDU
        Parameters:
        outputStream - an OutputStream.
        Throws:
        java.io.IOException - if an error occurs while writing to the stream.
      • isVariableV1

        protected boolean isVariableV1​(Variable v)
        Check if the given variable can be encoded into a SNMPv1 PDU.
        Parameters:
        v - a variable value (must not be null).
        Returns:
        true if the variable is SNMPv1 compatible (or SNMP4JSettings.isAllowSNMPv2InV1() is true), false otherwise, i.e. if v is an instance of Counter64.
        Since:
        1.9.1c
      • getMaxRepetitions

        public int getMaxRepetitions()
        This method is not supported for SNMPv1 PDUs and will throw a UnsupportedOperationException
        Overrides:
        getMaxRepetitions in class PDU
        Returns:
        nothing
        Throws:
        java.lang.UnsupportedOperationException - is always thrown.
      • setMaxRepetitions

        public void setMaxRepetitions​(int maxRepetitions)
        This method is not supported for SNMPv1 PDUs and will throw a UnsupportedOperationException
        Overrides:
        setMaxRepetitions in class PDU
        Parameters:
        maxRepetitions - the number of repetitions for SNMPv2c or later SNMP version. Ignored by this PDUv1.
        Throws:
        java.lang.UnsupportedOperationException - is always thrown.
      • setMaxSizeScopedPDU

        public void setMaxSizeScopedPDU​(int maxSizeScopedPDU)
        This method is not supported for SNMPv1 PDUs and will throw a UnsupportedOperationException
        Parameters:
        maxSizeScopedPDU - int
        Throws:
        java.lang.UnsupportedOperationException - is always thrown.
      • setNonRepeaters

        public void setNonRepeaters​(int nonRepeaters)
        This method is not supported for SNMPv1 PDUs and will throw a UnsupportedOperationException
        Overrides:
        setNonRepeaters in class PDU
        Parameters:
        nonRepeaters - int
        Throws:
        java.lang.UnsupportedOperationException - is always thrown.
      • getEnterprise

        public OID getEnterprise()
        Gets the "enterprise" OID of the SNMPv1 trap. The enterprise OID could be any OID although the name could lead to the assumption that the enterprise OID has to be an OID under the iso(1).org(3).dod(6).internet(1).private(4).enterprises(1) node, but that's not true.
        Returns:
        an OID instance.
        Throws:
        java.lang.UnsupportedOperationException - if the type of this PDU is not PDU.V1TRAP.
      • setEnterprise

        public void setEnterprise​(OID enterprise)
        Sets the "enterprise" OID of the SNMPv1 trap. The enterprise OID could be any OID although the name could lead to the assumption that the enterprise OID has to be an OID under the iso(1).org(3).dod(6).internet(1).private(4).enterprises(1) node, but that's not true.
        Parameters:
        enterprise - an OID instance.
        Throws:
        java.lang.UnsupportedOperationException - if the type of this PDU is not PDU.V1TRAP.
      • getAgentAddress

        public IpAddress getAgentAddress()
        Gets the IP address of the originator system of this SNMPv1 trap. If this value is 0.0.0.0 (the recommended default), then the address of the peer SNMP entity should be extracted from the Target object associated with this PDU.
        Returns:
        an IpAddress instance.
        Throws:
        java.lang.UnsupportedOperationException - if the type of this PDU is not PDU.V1TRAP.
      • setAgentAddress

        public void setAgentAddress​(IpAddress agentAddress)
        Sets the IP address of the originator system of this SNMPv1 trap. The default value is 0.0.0.0, which should be only overriden in special cases, for example when forwarding SNMPv1 traps through a SNMP proxy.
        Parameters:
        agentAddress - a IpAddress instance.
        Throws:
        java.lang.UnsupportedOperationException - if the type of this PDU is not PDU.V1TRAP.
      • getGenericTrap

        public int getGenericTrap()
        Gets the generic trap ID. If this value is ENTERPRISE_SPECIFIC(6), then getSpecificTrap() will return the trap ID of the enterprise specific trap.
        Returns:
        an Integer32 instance with a value between 0 and 6.
        Throws:
        java.lang.UnsupportedOperationException - if the type of this PDU is not PDU.V1TRAP.
      • setGenericTrap

        public void setGenericTrap​(int genericTrap)
        Sets the generic trap ID. If this value is ENTERPRISE_SPECIFIC(6), then setSpecificTrap(int) must be used to set the trap ID of the enterprise specific trap.
        Parameters:
        genericTrap - an integer value >= 0 and <= 6.
        Throws:
        java.lang.UnsupportedOperationException - if the type of this PDU is not PDU.V1TRAP.
      • getSpecificTrap

        public int getSpecificTrap()
        Gets the specific trap ID. If this value is set, getGenericTrap() must return ENTERPRISE_SPECIFIC(6).
        Returns:
        an integer value > 0.
        Throws:
        java.lang.UnsupportedOperationException - if the type of this PDU is not PDU.V1TRAP.
      • setSpecificTrap

        public void setSpecificTrap​(int specificTrap)
        Sets the specific trap ID. If this value is set, setGenericTrap(int genericTrap) must be called with value ENTERPRISE_SPECIFIC.
        Parameters:
        specificTrap - an integer value > 0.
        Throws:
        java.lang.UnsupportedOperationException - if the type of this PDU is not PDU.V1TRAP.
      • getTimestamp

        public long getTimestamp()
        Gets the TimeTicks value of the trap sender's notion of its sysUpTime value when this trap has been generated.
        Returns:
        a long value.
        Throws:
        java.lang.UnsupportedOperationException - if the type of this PDU is not PDU.V1TRAP.
      • setTimestamp

        public void setTimestamp​(long timeStamp)
        Sets the TimeTicks value of the trap sender's notion of its sysUpTime value when this trap has been generated.
        Parameters:
        timeStamp - a long value.
      • checkNull

        protected void checkNull​(Variable parameter)
        Checks for null parameters.
        Parameters:
        parameter - an Object instance.
        Throws:
        java.lang.NullPointerException - if parameter is null.
      • toString

        public java.lang.String toString()
        Description copied from class: PDU
        Returns a string representation of the object.
        Overrides:
        toString in class PDU
        Returns:
        a string representation of the object.
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class PDU