public class PDU extends Object implements BERSerializable, Serializable
PDU
class represents a SNMP protocol data unit. The PDU
version supported by the BER decoding and encoding methods of this class
is v2.
The default PDU type is GET.
PDUv1
,
ScopedPDU
,
Serialized FormModifier and Type | Field and Description |
---|---|
static int |
authorizationError
Unauthorized access, see error index.
|
static int |
badValue
Bad value in variable binding, see error index.
|
static int |
commitFailed
Unable to commit a value, see error index.
|
protected Integer32 |
errorIndex |
protected Integer32 |
errorStatus |
static int |
genErr
An unspecific error caused by a variable binding, see error index.
|
static int |
GET
Denotes a get PDU.
|
static int |
GETBULK
Denotes a SNMPv2c/v3 getbulk PDU.
|
static int |
GETNEXT
Denotes a getnext (search) PDU.
|
static int |
inconsistentName
The specified object does not exists and presently it cannot be created,
see error index.
|
static int |
inconsistentValue
The variable binding's value is presently inconsistent with the current
state of the target object, see error index.
|
static int |
INFORM
Denotes a SNMPv2c/v3 inform PDU (unprecisely also known as a confirmed
notification).
|
static int |
noAccess
The variable binding is not accessible by the current MIB view, see error
index.
|
static int |
noCreation
The specified object does not exists and cannot be created,
see error index.
|
static int |
noError
Operation success (no error).
|
static int |
noSuchName
No such variable binding name, see error index.
|
static int |
NOTIFICATION
Denotes a SNMPv2c/v3 notification PDU (undistinguishable from
NOTIFICATION ). |
static int |
notWritable
The variable's value cannot be modified, see error index.
|
static int |
readOnly
The variable binding is read-only, see error index.
|
static int |
REPORT
Denotes a SNMPv3 report PDU.
|
protected Integer32 |
requestID |
static int |
resourceUnavailable
The resource needed to assign a variable binding's value is presently
unavailable, see error index.
|
static int |
RESPONSE
Denotes a response PDU.
|
static int |
SET
Denotes a set PDU.
|
static int |
tooBig
PDU encoding is too big for the transport used.
|
static int |
TRAP
Denotes a SNMPv2c/v3 notification PDU (undistinguishable from
TRAP ). |
protected int |
type |
static int |
undoFailed
Unable to undo a committed value, see error index.
|
static int |
V1TRAP
Denotes a SNMPv1 trap PDU.
|
protected Vector<VariableBinding> |
variableBindings |
static int |
wrongEncoding
The variable binding's value has the wrong encoding, see error index.
|
static int |
wrongLength
The variable binding's value has the wrong length, see error index.
|
static int |
wrongType
The variable binding's value has the wrong type, see error index.
|
static int |
wrongValue
The variable binding's value has a value that could under no circumstances
be assigned, see error index.
|
Constructor and Description |
---|
PDU()
Default constructor.
|
PDU(int pduType,
List<? extends VariableBinding> vbs)
Constructs a new PDU from a type and a list of
VariableBinding instances. |
PDU(PDU other)
Copy constructor which creates a deep copy (clone) of the
other PDU.
|
Modifier and Type | Method and Description |
---|---|
void |
add(VariableBinding vb)
Adds a variable binding to this PDU.
|
void |
addAll(List<? extends VariableBinding> vbs)
Adds a list of variable bindings to this PDU (see
add(VariableBinding vb) ). |
void |
addAll(VariableBinding[] vbs)
Adds an array of variable bindings to this PDU (see
add(VariableBinding vb) ). |
void |
addAllOIDs(VariableBinding[] vbs)
Adds new
VariableBindings each with the OID of the
corresponding variable binding of the supplied array to this PDU (see
addOID(VariableBinding vb) ). |
void |
addOID(VariableBinding vb)
Adds a new variable binding to this PDU by using the OID of the supplied
VariableBinding . |
void |
clear()
Removes all variable bindings from the PDU and sets the request ID to zero.
|
Object |
clone() |
void |
decodeBER(BERInputStream inputStream)
Decodes a
Variable from an InputStream . |
void |
encodeBER(OutputStream outputStream)
Encodes a
Variable to an OutputStream . |
boolean |
equals(Object obj) |
VariableBinding |
get(int index)
Gets the variable binding at the specified position.
|
int |
getBERLength()
Returns the length of this
BERSerializable object
in bytes when encoded according to the Basic Encoding Rules (BER). |
static int |
getBERLength(List<? extends VariableBinding> variableBindings)
Computes the length in bytes of the BER encoded variable bindings without
including the length of BER sequence length.
|
int |
getBERPayloadLength()
Returns the length of the payload of this
BERSerializable object
in bytes when encoded according to the Basic Encoding Rules (BER). |
protected int |
getBERPayloadLengthPDU() |
List<VariableBinding> |
getBindingList(OID prefix)
Gets a list of
VariableBinding s whose OID prefix
matches the supplied prefix. |
int |
getErrorIndex()
Gets the error index.
|
int |
getErrorStatus()
Gets the error status of the PDU.
|
String |
getErrorStatusText()
Gets a textual description of the error status.
|
int |
getMaxRepetitions()
Gets the maximum repetitions of repeatable variable bindings in GETBULK
requests.
|
int |
getNonRepeaters()
Gets the number of non repeater variable bindings in a GETBULK PDU.
|
Integer32 |
getRequestID()
Gets the request ID associated with this PDU.
|
int |
getType()
Gets the PDU type.
|
static int |
getTypeFromString(String type)
Gets the PDU type identifier for a string representation of the type.
|
static String |
getTypeString(int type)
Gets a string representation of the supplied PDU type.
|
Variable |
getVariable(OID prefix)
Gets the first variable whose OID starts with the specified OID.
|
Vector<? extends VariableBinding> |
getVariableBindings()
Gets the variable binding vector.
|
int |
hashCode() |
boolean |
isConfirmedPdu()
Checks whether this PDU is a confirmed class PDU.
|
boolean |
isResponsePdu()
Checks whether this PDU is a
RESPONSE or [@link PDU#REPORT}. |
void |
remove(int index)
Removes the variable binding at the supplied position.
|
VariableBinding |
set(int index,
VariableBinding vb)
Sets the variable binding at the specified position.
|
void |
setErrorIndex(int errorIndex)
Sets the error index.
|
void |
setErrorStatus(int errorStatus)
Sets the error status of the PDU.
|
void |
setMaxRepetitions(int maxRepetitions)
Sets the maximum repetitions of repeatable variable bindings in GETBULK
requests.
|
void |
setNonRepeaters(int nonRepeaters)
Sets the number of non repeater variable bindings in a GETBULK PDU.
|
void |
setRequestID(Integer32 requestID)
Sets the request ID for this PDU.
|
void |
setType(int type)
Sets the PDU type.
|
void |
setVariableBindings(List<? extends VariableBinding> vbs)
Sets the
VariableBinding s for this PDU. |
int |
size()
Gets the number of variable bindings in the PDU.
|
VariableBinding[] |
toArray()
Returns an array with the variable bindings of this PDU.
|
static String |
toErrorStatusText(int errorStatus)
Returns textual description for the supplied error status value.
|
String |
toString()
Returns a string representation of the object.
|
void |
trim()
Remove the last variable binding from the PDU, if such an element exists.
|
public static final int GET
public static final int GETNEXT
public static final int RESPONSE
public static final int SET
public static final int V1TRAP
PDUv1
class.public static final int GETBULK
public static final int INFORM
public static final int TRAP
TRAP
).public static final int NOTIFICATION
NOTIFICATION
).public static final int REPORT
public static final int noError
public static final int tooBig
public static final int noSuchName
public static final int badValue
public static final int readOnly
public static final int genErr
public static final int noAccess
public static final int wrongType
public static final int wrongLength
public static final int wrongValue
public static final int wrongEncoding
public static final int noCreation
public static final int inconsistentValue
public static final int resourceUnavailable
public static final int commitFailed
public static final int undoFailed
public static final int authorizationError
public static final int notWritable
public static final int inconsistentName
protected Vector<VariableBinding> variableBindings
protected Integer32 errorStatus
protected Integer32 errorIndex
protected Integer32 requestID
protected int type
public PDU()
public PDU(PDU other)
other
- the PDU
to copy from.public PDU(int pduType, List<? extends VariableBinding> vbs)
VariableBinding
instances.
The list will not be referenced, instead a deep copy of the variable bindings
is executed (each variable binding will be cloned).pduType
- the PDU type.vbs
- the variable bindings.public void add(VariableBinding vb)
NullPointerException
is thrown if VariableBinding
or its Variable
is
null
.vb
- a VariableBinding
instance.public void addOID(VariableBinding vb)
VariableBinding
. The value portion is thus set to
null
.
This method should be used for GET type requests. For SET, TRAP and INFORM
requests, the add(org.snmp4j.smi.VariableBinding)
method should be used instead.
vb
- a VariableBinding
instance.public void addAll(VariableBinding[] vbs)
add(VariableBinding vb)
).vbs
- an array of VariableBinding
instances. The instances in the
array will be appended to the current list of variable bindings in the
PDU.public void addAll(List<? extends VariableBinding> vbs)
add(VariableBinding vb)
).vbs
- a list of VariableBinding
instances. The instances in the
list will be appended to the current list of variable bindings in the
PDU.public void addAllOIDs(VariableBinding[] vbs)
VariableBindings
each with the OID of the
corresponding variable binding of the supplied array to this PDU (see
addOID(VariableBinding vb)
).vbs
- an array of VariableBinding
instances. For each instance
in the supplied array, a new VariableBinding created by
new VariableBinding(OID)
will be appended to the current
list of variable bindings in the PDU.public VariableBinding get(int index)
index
- a zero based positive integer (0 <= index < size()
)index
is out of bounds
an exception is thrown.public Variable getVariable(OID prefix)
prefix
- the search OID
.Variable
of the first VariableBinding
whose prefix matches oid
. If no such element
could be found, null
is returned.public List<VariableBinding> getBindingList(OID prefix)
VariableBinding
s whose OID prefix
matches the supplied prefix.prefix
- the search OID
.VariableBinding
s
whose prefix matches oid
. If no such element
could be found, an empty List is returned.public VariableBinding set(int index, VariableBinding vb)
index
- a zero based positive integer (0 <= index < size()
)
If index
is out of bounds
an exception is thrown.vb
- a VariableBinding instance (null
is not allowed).public void remove(int index)
index
- a position >= 0 and < size()
.public int size()
public Vector<? extends VariableBinding> getVariableBindings()
Vector
containing the PDU's variable bindings.public void setVariableBindings(List<? extends VariableBinding> vbs)
VariableBinding
s for this PDU.vbs
- a list of VariableBinding
instances which must
not be null.public void trim()
public void setErrorStatus(int errorStatus)
errorStatus
- a SNMP error status.SnmpConstants
public int getErrorStatus()
SnmpConstants
public String getErrorStatusText()
SnmpConstants.SNMP_ERROR_MESSAGES
array for a valid error status.
"Unknown error: public static String toErrorStatusText(int errorStatus)
errorStatus
- an error status.SnmpConstants.SNMP_ERROR_MESSAGES
array for a valid error status.
"Unknown error: public void setErrorIndex(int errorIndex)
errorIndex
- an integer value >= 0 where 1 denotes the first variable binding.public int getErrorIndex()
public boolean isConfirmedPdu()
public boolean isResponsePdu()
RESPONSE
or [@link PDU#REPORT}.public int getBERLength()
BERSerializable
BERSerializable
object
in bytes when encoded according to the Basic Encoding Rules (BER).getBERLength
in interface BERSerializable
public int getBERPayloadLength()
BERSerializable
BERSerializable
object
in bytes when encoded according to the Basic Encoding Rules (BER).getBERPayloadLength
in interface BERSerializable
public void decodeBER(BERInputStream inputStream) throws IOException
BERSerializable
Variable
from an InputStream
.decodeBER
in interface BERSerializable
inputStream
- an InputStream
containing a BER encoded byte stream.IOException
- if the stream could not be decoded by using BER rules.public static int getBERLength(List<? extends VariableBinding> variableBindings)
variableBindings
- a list of variable bindings.protected int getBERPayloadLengthPDU()
public void encodeBER(OutputStream outputStream) throws IOException
BERSerializable
Variable
to an OutputStream
.encodeBER
in interface BERSerializable
outputStream
- an OutputStream
.IOException
- if an error occurs while writing to the stream.public void clear()
public void setType(int type)
type
- the type of the PDU (e.g. GETNEXT, SET, etc.)public int getType()
GETNEXT
.public Integer32 getRequestID()
Integer32
instance.public void setRequestID(Integer32 requestID)
PDU
when sent.requestID
- a unique request ID.public static String getTypeString(int type)
type
- a PDU type.type
, for example "GET".public static int getTypeFromString(String type)
type
- the string representation of a PDU type: GET, GETNEXT, GETBULK,
SET, INFORM, RESPONSE, REPORT, TRAP, V1TRAP)
.Integer.MIN_VALUE
of the supplied type is unknown.public String toString()
public int getMaxRepetitions()
public void setMaxRepetitions(int maxRepetitions)
maxRepetitions
- an integer value >= 0.public int getNonRepeaters()
size()
public void setNonRepeaters(int nonRepeaters)
nonRepeaters
- an integer value >= 0 and <= size()
public VariableBinding[] toArray()
VariableBinding
instances of this PDU in the
same order as in the PDU.Copyright © 2016 SNMP4J.org. All rights reserved.