Class AgentXProtocol

java.lang.Object
org.snmp4j.agent.agentx.AgentXProtocol
All Implemented Interfaces:
org.snmp4j.transport.MessageLengthDecoder

public class AgentXProtocol extends Object implements org.snmp4j.transport.MessageLengthDecoder
The AgentXProtocol class defines constants and operations specific to the AgentX protocol as defined by RFC 2741.
Author:
Frank Fock
  • Field Details

    • VERSION_1_0

      public static final byte VERSION_1_0
      AgentX protocol version.
      See Also:
    • REASON_OTHER

      public static final byte REASON_OTHER
      Close reason: None of the following reasons.
      See Also:
    • REASON_PARSE_ERROR

      public static final byte REASON_PARSE_ERROR
      Close reason: Too many AgentX parse errors from peer.
      See Also:
    • REASON_PROTOCOL_ERROR

      public static final byte REASON_PROTOCOL_ERROR
      Close reason: Too many AgentX protocol errors from peer.
      See Also:
    • REASON_TIMEOUTS

      public static final byte REASON_TIMEOUTS
      Close reason: Too many timeouts waiting for peer.
      See Also:
    • REASON_SHUTDOWN

      public static final byte REASON_SHUTDOWN
      Close reason: Sending entity is shutting down.
      See Also:
    • REASON_BY_MANAGER

      public static final byte REASON_BY_MANAGER
      Close reason: Due to Set operation; this reason code can be used only by the master agent, in response to an SNMP management request.
      See Also:
    • AGENTX_OPEN_FAILED

      public static final int AGENTX_OPEN_FAILED
      AgentX error: open failed.
      See Also:
    • AGENTX_NOT_OPEN

      public static final int AGENTX_NOT_OPEN
      AgentX error: not open.
      See Also:
    • AGENTX_INDEX_WRONG_TYPE

      public static final int AGENTX_INDEX_WRONG_TYPE
      AgentX error: index has wrong type.
      See Also:
    • AGENTX_INDEX_ALREADY_ALLOCATED

      public static final int AGENTX_INDEX_ALREADY_ALLOCATED
      AgentX error: index already allocated.
      See Also:
    • AGENTX_INDEX_NONE_AVAILABLE

      public static final int AGENTX_INDEX_NONE_AVAILABLE
      AgentX error: no index available.
      See Also:
    • AGENTX_INDEX_NOT_ALLOCATED

      public static final int AGENTX_INDEX_NOT_ALLOCATED
      AgentX error: index not allocated.
      See Also:
    • AGENTX_UNSUPPORTED_CONTEXT

      public static final int AGENTX_UNSUPPORTED_CONTEXT
      AgentX error: unsupported context.
      See Also:
    • AGENTX_DUPLICATE_REGISTRATION

      public static final int AGENTX_DUPLICATE_REGISTRATION
      AgentX error: duplicate registration.
      See Also:
    • AGENTX_UNKNOWN_REGISTRATION

      public static final int AGENTX_UNKNOWN_REGISTRATION
      AgentX error: unknown registration.
      See Also:
    • AGENTX_UNKNOWN_AGENTCAPS

      public static final int AGENTX_UNKNOWN_AGENTCAPS
      AgentX error: unknown agent capabilities.
      See Also:
    • AGENTX_PARSE_ERROR

      public static final int AGENTX_PARSE_ERROR
      AgentX error: parse error.
      See Also:
    • AGENTX_REQUEST_DENIED

      public static final int AGENTX_REQUEST_DENIED
      AgentX error: request denied.
      See Also:
    • AGENTX_PROCESSING_ERROR

      public static final int AGENTX_PROCESSING_ERROR
      AgentX error: processing error.
      See Also:
    • AGENTX_MAX_OID_LENGTH

      public static final int AGENTX_MAX_OID_LENGTH
      The maximum OID length for AgentX transported OIDs according to RFC2741 §5.1.
      See Also:
    • AGENTX_SUCCESS

      public static final int AGENTX_SUCCESS
      No error (success).
      See Also:
    • AGENTX_ERROR

      public static final int AGENTX_ERROR
      General error.
      See Also:
    • AGENTX_DISCONNECT

      public static final int AGENTX_DISCONNECT
      AentX disconnected.
      See Also:
    • AGENTX_BADVER

      public static final int AGENTX_BADVER
      Bad AgentX version.
      See Also:
    • AGENTX_TIMEOUT

      public static final int AGENTX_TIMEOUT
      AgentX timeout.
      See Also:
    • AGENTX_NOREG

      public static final int AGENTX_NOREG
      No registration error.
      See Also:
    • AGENTX_DUPMAP

      public static final int AGENTX_DUPMAP
      Deprecated.
      Will be removed in 3.0
      Duplicate mapping (not used)
      See Also:
    • FLAG_ALLOCATE_INDEX

      public static final int FLAG_ALLOCATE_INDEX
      AgentX flag: ALLOCATE_INDEX.
      See Also:
    • FLAG_INSTANCE_REGISTRATION

      public static final byte FLAG_INSTANCE_REGISTRATION
      AgentX flag: INSTANCE_REGISTRATION.
      See Also:
    • FLAG_NEW_INDEX

      public static final byte FLAG_NEW_INDEX
      AgentX flag: NEW_INDEX.
      See Also:
    • FLAG_ANY_INDEX

      public static final byte FLAG_ANY_INDEX
      AgentX flag: ANY_INDEX.
      See Also:
    • FLAG_NON_DEFAULT_CONTEXT

      public static final byte FLAG_NON_DEFAULT_CONTEXT
      AgentX flag: NON_DEFAULT_CONTEXT.
      See Also:
    • FLAG_NETWORK_BYTE_ORDER

      public static final byte FLAG_NETWORK_BYTE_ORDER
      AgentX flag: NETWORK_BYTE_ORDER.
      See Also:
    • AGENTX_INT_SIZE

      protected static final int AGENTX_INT_SIZE
      Number of bytes for an AgentX INTEGER.
      See Also:
    • HEADER_LENGTH

      public static final int HEADER_LENGTH
      AgentX header length = 5 * AGENTX_INT_SIZE.
      See Also:
    • DEFAULT_TIMEOUT_SECONDS

      public static final int DEFAULT_TIMEOUT_SECONDS
      Default AgentX timeout in seconds.
      See Also:
    • DEFAULT_MAX_CONSECUTIVE_TIMEOUTS

      public static final int DEFAULT_MAX_CONSECUTIVE_TIMEOUTS
      Default maximum of consecutive timeouts before connection closing.
      See Also:
    • DEFAULT_MAX_PARSE_ERRORS

      public static final int DEFAULT_MAX_PARSE_ERRORS
      Default maximum number of parse errors before connection closing.
      See Also:
    • MAX_TIMEOUT_SECONDS

      public static final int MAX_TIMEOUT_SECONDS
      Maximum timeout seconds.
      See Also:
    • DEFAULT_PRIORITY

      public static final byte DEFAULT_PRIORITY
      The default priority for registrations.
      See Also:
  • Constructor Details

    • AgentXProtocol

      public AgentXProtocol()
  • Method Details

    • encodeOID

      public static void encodeOID(ByteBuffer buf, org.snmp4j.smi.OID oid, boolean include)
      AgentX encode an OID
      Parameters:
      buf - the target byte buffer.
      oid - the OID to encode
      include - true to add include flag and false to set it to 0.
    • getOIDLength

      public static int getOIDLength(org.snmp4j.smi.OID oid)
      Get the encoded length of an OID.
      Parameters:
      oid - the OID.
      Returns:
      the encoding length.
    • getOIDLength

      public static int getOIDLength(int[] oid)
      Get the encoded length of an OID.
      Parameters:
      oid - the OID.
      Returns:
      the encoding length.
    • decodeOID

      public static boolean decodeOID(ByteBuffer buf, org.snmp4j.smi.OID oid)
      Decode an OID from an AgentX encoded message (byte buffer)
      Parameters:
      buf - the byte buffer containing the encoded OID.
      oid - the OID to return (data will be written into this object).
      Returns:
      true if the include flag is set, false otherwise.
    • encodeVariableData

      public static void encodeVariableData(ByteBuffer buf, org.snmp4j.smi.Variable v)
      Encode a Variable.
      Parameters:
      buf - the target byte buffer.
      v - the variable to encode.
    • getVariableDataLength

      public static int getVariableDataLength(org.snmp4j.smi.Variable v)
      Gets the encoded variable data length for a given Variable.
      Parameters:
      v - the Variable.
      Returns:
      the encoded length of the given variable.
    • decodeVariableData

      public static org.snmp4j.smi.Variable decodeVariableData(ByteBuffer buf, int syntax)
      Decode a Variable from an AgentX message provided as byte buffer.
      Parameters:
      buf - the AgentX message (portion) to decode.
      syntax - the syntax ID specifying the variable type.
      Returns:
      the decoded Variable.
    • decodeVariableBindings

      public static org.snmp4j.smi.VariableBinding[] decodeVariableBindings(ByteBuffer buf)
      Decode an array of VariableBinding.
      Parameters:
      buf - the AgentX message (portion) to decode.
      Returns:
      the decoded array of VariableBinding instances.
    • encodeVaribleBindings

      public static void encodeVaribleBindings(ByteBuffer buf, org.snmp4j.smi.VariableBinding[] vbs)
      Encode an array of VariableBinding to an AgentX message buffer.
      Parameters:
      buf - the AgentX message (portion) to encode.
      vbs - an array of VariableBinding instances.
    • encodeRanges

      public static void encodeRanges(ByteBuffer buf, org.snmp4j.agent.MOScope[] searchRanges)
      Encode search ranges.
      Parameters:
      buf - the AgentX message (portion) to encode.
      searchRanges - an array of search ranges.
    • getOctetStringLength

      public static int getOctetStringLength(int length)
      Gets the encoded length of an encoded OctetString.
      Parameters:
      length - the length in bytes of the OctetString.
      Returns:
      the encoded length in bytes.
    • encodeOctetString

      public static void encodeOctetString(ByteBuffer buf, org.snmp4j.smi.OctetString os)
      Encode an OctetString.
      Parameters:
      buf - the AgentX message (portion) to encode.
      os - an OctetString to encode.
    • decodeOctetString

      public static org.snmp4j.smi.OctetString decodeOctetString(ByteBuffer buf)
      Decode an OctetString.
      Parameters:
      buf - the AgentX message (portion) to decode.
      Returns:
      os the decoded OctetString.
    • decodeRanges

      public static org.snmp4j.agent.MOScope[] decodeRanges(ByteBuffer buf)
      Decode search ranges.
      Parameters:
      buf - the AgentX message (portion) to decode.
      Returns:
      the decoded array of MOScope instances representing the search ranges.
    • decodeRanges

      public static org.snmp4j.agent.MOScope[] decodeRanges(ByteBuffer buf, boolean lowerAlwaysIncluded)
      Decode search ranges.
      Parameters:
      buf - the AgentX message (portion) to decode.
      lowerAlwaysIncluded - true to interpret lower bounds as always included, false to include lower bound if encoded as included.
      Returns:
      the decoded array of MOScope instances representing the search ranges.
    • getRangesLength

      public static int getRangesLength(org.snmp4j.agent.MOScope[] ranges)
      Gets the encoded length of the given ranges.
      Parameters:
      ranges - an array of MOScope instances representing search ranges.
      Returns:
      the encoded length in bytes.
    • getVariableBindingsLength

      public static int getVariableBindingsLength(org.snmp4j.smi.VariableBinding[] vbs)
      Gets the encoded length of the given VariableBindings.
      Parameters:
      vbs - the VariableBindings.
      Returns:
      the encoded length in bytes.
    • getMinHeaderLength

      public int getMinHeaderLength()
      Gets the minimum header length.
      Specified by:
      getMinHeaderLength in interface org.snmp4j.transport.MessageLengthDecoder
      Returns:
      HEADER_LENGTH.
    • getMessageLength

      public org.snmp4j.transport.MessageLength getMessageLength(ByteBuffer buf) throws IOException
      Gets the encoded message length.
      Specified by:
      getMessageLength in interface org.snmp4j.transport.MessageLengthDecoder
      Parameters:
      buf - the AgentX message buffer containing the AgentX message to decode.
      Returns:
      the length of the message.
      Throws:
      IOException - if the header could not be decoded.
    • decodeHeader

      public static AgentXMessageHeader decodeHeader(ByteBuffer buf) throws IOException
      Decodes the header of an AgentX message.
      Parameters:
      buf - the AgentX message buffer containing the AgentX message to decode.
      Returns:
      the decoded AgentXMessageHeader.
      Throws:
      IOException - if the header could not be decoded.
    • setNonDefaultContextsEnabled

      public static void setNonDefaultContextsEnabled(boolean enabled)
      Activate/deactivate non-default context support.
      Parameters:
      enabled - false to disable non-default context support for this AgentXProtocol, enabled is the default.
    • isNonDefaultContextsEnabled

      public static boolean isNonDefaultContextsEnabled()
      Checks if non-default context support is enabled or not.
      Returns:
      true if non-default context support is enabled (default).