Class AgentXPDU

java.lang.Object
org.snmp4j.agent.agentx.AgentXPDU
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
AgentXCleanupSetPDU, AgentXClosePDU, AgentXCommitSetPDU, AgentXContextPDU, AgentXOpenPDU, AgentXResponsePDU, AgentXUndoSetPDU

public abstract class AgentXPDU extends Object implements Serializable
The AgentXPDU implements the common characteristics of all AgentX PDUs (see RFC 2741).
Author:
Frank Fock
See Also:
  • Field Details

    • RESERVED

      public static final byte RESERVED
      The reserved byte position.
      See Also:
    • AGENTX_OPEN_PDU

      public static final byte AGENTX_OPEN_PDU
      The agentx-Open-PDU ID.
      See Also:
    • AGENTX_CLOSE_PDU

      public static final byte AGENTX_CLOSE_PDU
      The agentx-Close-PDU ID.
      See Also:
    • AGENTX_REGISTER_PDU

      public static final byte AGENTX_REGISTER_PDU
      The agentx-Register-PDU ID.
      See Also:
    • AGENTX_UNREGISTER_PDU

      public static final byte AGENTX_UNREGISTER_PDU
      The agentx-Unregister-PDU ID.
      See Also:
    • AGENTX_GET_PDU

      public static final byte AGENTX_GET_PDU
      The agentx-Get-PDU ID.
      See Also:
    • AGENTX_GETNEXT_PDU

      public static final byte AGENTX_GETNEXT_PDU
      The agentx-GetNext-PDU ID.
      See Also:
    • AGENTX_GETBULK_PDU

      public static final byte AGENTX_GETBULK_PDU
      The agentx-GetBulk-PDU ID.
      See Also:
    • AGENTX_TESTSET_PDU

      public static final byte AGENTX_TESTSET_PDU
      The agentx-TestSet-PDU ID.
      See Also:
    • AGENTX_COMMITSET_PDU

      public static final byte AGENTX_COMMITSET_PDU
      The agentx-CommitSet-PDU ID.
      See Also:
    • AGENTX_UNDOSET_PDU

      public static final byte AGENTX_UNDOSET_PDU
      The agentx-UndoSet-PDU ID.
      See Also:
    • AGENTX_CLEANUPSET_PDU

      public static final byte AGENTX_CLEANUPSET_PDU
      The agentx-CleanupSet-PDU ID.
      See Also:
    • AGENTX_NOTIFY_PDU

      public static final byte AGENTX_NOTIFY_PDU
      The agentx-Notify-PDU ID.
      See Also:
    • AGENTX_PING_PDU

      public static final byte AGENTX_PING_PDU
      The agentx-Ping-PDU ID.
      See Also:
    • AGENTX_INDEXALLOCATE_PDU

      public static final byte AGENTX_INDEXALLOCATE_PDU
      The agentx-IndexAllocate-PDU ID.
      See Also:
    • AGENTX_INDEXDEALLOCATE_PDU

      public static final byte AGENTX_INDEXDEALLOCATE_PDU
      The agentx-IndexDeallocate-PDU ID.
      See Also:
    • AGENTX_ADDAGENTCAPS_PDU

      public static final byte AGENTX_ADDAGENTCAPS_PDU
      The agentx-AddAgentCaps-PDU ID.
      See Also:
    • AGENTX_REMOVEAGENTCAPS_PDU

      public static final byte AGENTX_REMOVEAGENTCAPS_PDU
      The agentx-RemoveAgentCaps-PDU ID.
      See Also:
    • AGENTX_RESPONSE_PDU

      public static final byte AGENTX_RESPONSE_PDU
      The agentx-Response-PDU ID.
      See Also:
    • type

      protected byte type
      AgentX PDU type.
    • version

      protected byte version
      AgentX protocol version
    • sessionID

      protected int sessionID
      Session ID
    • transactionID

      protected int transactionID
      Transaction ID.
    • packetID

      protected int packetID
      Packet ID
    • flags

      protected byte flags
      Flags (bitwise OR), see AgentXProtocol.FLAG_INSTANCE_REGISTRATION for example.
    • byteOrder

      protected ByteOrder byteOrder
      The byte order.
  • Constructor Details

  • Method Details

    • addFlag

      public final void addFlag(byte flag)
      Adds a flag to the existing flags (bit-wise OR).
      Parameters:
      flag - a AgentX flag, see AgentXProtocol.FLAG_NETWORK_BYTE_ORDER
    • isFlagSet

      public final boolean isFlagSet(int flag)
      Check if the specified flag is set, see AgentXProtocol.FLAG_INSTANCE_REGISTRATION for example.
      Parameters:
      flag - the flag to test.
      Returns:
      true if it is set.
    • getFlags

      public final byte getFlags()
      Gets all flags.
      Returns:
      a bit-wise OR flag set.
    • getPacketID

      public final int getPacketID()
      Gets the packet ID.
      Returns:
      the packet ID.
    • getSessionID

      public final int getSessionID()
      Gets the session ID.
      Returns:
      the session ID.
    • getType

      public final byte getType()
      Get the PDU type.
      Returns:
      the type like AGENTX_OPEN_PDU.
    • getVersion

      public final byte getVersion()
      Gets the protcol version.
      Returns:
      the version info.
    • getByteOrder

      public final ByteOrder getByteOrder()
      Gets the byte order.
      Returns:
      the byte order.
    • getTransactionID

      public final int getTransactionID()
      Gets the transaction ID.
      Returns:
      the transaction ID.
    • setFlags

      public void setFlags(byte flags)
      Sets all flags at once.
      Parameters:
      flags - a bit-wise OR combinaed set of flags.
    • setPacketID

      public void setPacketID(int packetID)
      Sets the packet ID.
      Parameters:
      packetID - the packet ID.
    • setSessionID

      public void setSessionID(int sessionID)
      Sets the session ID.
      Parameters:
      sessionID - the session ID.
    • setType

      public void setType(byte type)
      Sets the PDU type.
      Parameters:
      type - the type.
    • setVersion

      public void setVersion(byte version)
      Sets the version.
      Parameters:
      version - the version.
    • setByteOrder

      public void setByteOrder(ByteOrder byteOrder)
      Sets the byte order.
      Parameters:
      byteOrder - the byte order.
    • setTransactionID

      public void setTransactionID(int transactionID)
      Sets the transaction ID
      Parameters:
      transactionID - the transaction ID.
    • setSessionAttributes

      public void setSessionAttributes(AgentXSession<?> session)
      Sets the AgentXSession specific attributes: session ID and byte order.
      Parameters:
      session - an AgentXSession.
    • encodePayload

      protected abstract void encodePayload(ByteBuffer buf)
      Encode the payload to the given byte buffer.
      Parameters:
      buf - the buffer.
    • getPayloadLength

      public abstract int getPayloadLength()
      Gets the payload length.
      Returns:
      the payload length.
    • encode

      public final void encode(ByteBuffer buf)
      Encode this PDU into the given byte buffer.
      Parameters:
      buf - the ByteBuffer to hold the BER encoded PDU.
    • beforeEncode

      protected abstract void beforeEncode()
      Initialize flags and other things before a PDU is encoded.
    • decodePayload

      public abstract void decodePayload(ByteBuffer buf, int length) throws IOException
      Decode this PDU's payload.
      Parameters:
      buf - the buffer positioned at the end of the encoded context.
      length - the length of the PDU to be decoded.
      Throws:
      IOException - if the buffer contains less data than expected.
    • decode

      public static AgentXPDU decode(ByteBuffer buf) throws IOException
      Decode AgentXPDU from a byte buffer.
      Parameters:
      buf - the ByteBuffer that contains the BER encoded PDU.
      Returns:
      the decoded AgentXPDU.
      Throws:
      IOException - if the buffer contains less than encoded data or if the is a parse error.
    • isConfirmedPDU

      public final boolean isConfirmedPDU()
      Check if this PDU is a confirmed PDU (i.e. requires a response).
      Returns:
      true if a repsone is required.
    • toStringExtMembers

      protected String toStringExtMembers()
      Returns a string representation of the PDU members. An empty string is returned by this base class.
      Returns:
      a string representation of the PDU members.
    • toString

      public String toString()
      Overrides:
      toString in class Object