SNMP 2.0.0
|
#include <src/SNMPMessage.h>
Classes | |
class | OID |
Helper class to defines some useful SNMP OIDs. More... | |
Public Member Functions | |
Message (const uint8_t version=Version::V1, const char *community=nullptr, const uint8_t type=Type::GetRequest) | |
Creates a Message. | |
virtual | ~Message () |
Message destructor. | |
virtual const unsigned int | getSize (const bool refresh=false) |
Gets the size of the message. | |
VarBind * | add (const char *oid, BER *value=nullptr) |
Adds a VarBind. | |
const uint8_t | getVersion () const |
Gets the version. | |
const char * | getCommunity () const |
Gets the community. | |
const uint8_t | getType () const |
Gets the type. | |
const int32_t | getRequestID () const |
Gets the request identifier. | |
void | setRequestID (const int32_t requestId) |
Sets the request identifier. | |
const uint8_t | getErrorStatus () const |
Gets the error status. | |
const uint8_t | getErrorIndex () const |
Gets the error index. | |
void | setError (const uint8_t status, const uint8_t index) |
Sets error status and error index. | |
const uint8_t | getNonRepeaters () const |
Gets the non repeaters. | |
void | setNonRepeaters (const uint8_t nonRepeaters) |
Sets the non repeaters. | |
const uint8_t | getMaxRepetition () const |
Gets the maximum repetition. | |
void | setMaxRepetitions (const uint8_t maxRepetitions) |
Sets the maximum repetition. | |
void | setEnterprise (const char *enterprise) |
Sets the enterprise. | |
void | setAgentAddress (IPAddress agentAddr) |
Sets the agent address. | |
void | setTrap (const uint8_t generic, const uint8_t specific=0) |
Sets the generic and specific traps. | |
void | setSNMPTrapOID (const char *name) |
Sets the SNMPTRAPOID variable binding. | |
VarBindList * | getVarBindList () const |
Gets the variable bindings list. | |
Public Member Functions inherited from SNMP::SequenceBER | |
SequenceBER (const uint8_t type=Type::Sequence) | |
Creates a SequenceBER. | |
Public Member Functions inherited from SNMP::ArrayBER< SNMP_CAPACITY > | |
ArrayBER (const uint8_t type) | |
Creates an ArrayBER. | |
~ArrayBER () | |
ArrayBER destructor. | |
virtual void | encode (Stream &stream) |
Encodes ArrayBER to stream. | |
virtual uint8_t * | encode (uint8_t *buffer) |
Encodes ArrayBER to memory buffer. | |
virtual void | decode (Stream &stream, const uint8_t flag=Flag::None) |
Decodes ArrayBER from stream. | |
virtual uint8_t * | decode (uint8_t *buffer) |
Decodes ArrayBER from memory buffer. | |
BER * | operator[] (const unsigned int index) |
Array subscript operator. | |
const uint8_t | count () const |
Gets the count of BERs in the array. | |
Public Member Functions inherited from SNMP::BER | |
BER (const unsigned int type) | |
Creates a BER object. | |
virtual | ~BER () |
BER destructor. | |
template<typename T > | |
void | encodeNumeric (T value, Stream &stream) |
Encodes BER numeric value to stream. | |
template<typename T > | |
void | decodeNumeric (T *value, Stream &stream, const uint8_t flag=Flag::None) |
Decodes BER numeric value from stream. | |
template<typename T > | |
uint8_t * | encodeNumeric (T value, uint8_t *buffer) |
Encodes BER numeric value to memory buffer. | |
template<typename T > | |
uint8_t * | decodeNumeric (T *value, uint8_t *buffer, const uint8_t flag=Flag::None) |
Decodes BER numeric value from memory buffer. | |
template<typename T > | |
void | setNegative (T value) |
Computes BER length of a negative integer. | |
template<typename T > | |
void | setPositive (T value) |
Computes BER length of a positive integer. | |
const unsigned int | getType () const |
Gets the BER type. | |
const unsigned int | getLength () const |
Gets the BER length. | |
Public Member Functions inherited from SNMP::Base | |
void | encode7bits (uint32_t value, uint8_t *buffer, const uint8_t size) |
Encodes integer value to memory buffer. | |
Private Member Functions | |
void | build () |
Builds the message. | |
void | parse () |
Parses the message. | |
void | build (Stream &stream) |
Builds the message to stream. | |
void | parse (Stream &stream) |
Parses the message from stream. | |
void | build (uint8_t *buffer) |
Builds the message to buffer. | |
void | parse (uint8_t *buffer) |
Parses the message from buffer. | |
const uint8_t | mapErrorStatus (const uint8_t status) const |
Maps error status. | |
Private Member Functions inherited from SNMP::PDU | |
PDU () | |
Creates a PDU object. | |
~PDU () | |
PDU destructor. | |
Private Attributes | ||
uint8_t | _version | |
const char * | _community | |
uint8_t | _type | |
VarBindList * | _varBindList | |
Private Attributes inherited from SNMP::PDU | ||
union { | ||
Generic _generic | ||
Trap _trap | ||
}; | ||
Friends | |
class | SNMP |
Additional Inherited Members | |
Static Public Member Functions inherited from SNMP::Base | |
static void | encode7bits (uint32_t value, Stream &stream, const uint8_t size) |
Encodes integer value to stream. | |
Protected Member Functions inherited from SNMP::ArrayBER< SNMP_CAPACITY > | |
BER * | add (BER *ber) |
Adds a BER to the array. | |
void | remove () |
Removes the last BER in the array. | |
Protected Member Functions inherited from SNMP::BER | |
BER * | create (const Type &type) |
Creates a BER of given type. | |
Protected Attributes inherited from SNMP::BER | |
Length | _length |
Type | _type |
Protected Attributes inherited from SNMP::Base | |
unsigned int | _size = 0 |
SNMP message object.
Example
Definition at line 110 of file SNMPMessage.h.
|
inline |
Creates a Message.
Definition at line 139 of file SNMPMessage.h.
References _community, _type, _varBindList, _version, and SNMP::ArrayBER< SNMP_CAPACITY >::VarBindList.
|
inlinevirtual |
Message destructor.
Releases variable bindings.
Definition at line 153 of file SNMPMessage.h.
References _varBindList.
Adds a VarBind.
Creates and adds a VarBind to the message variable bindings list.
Definition at line 180 of file SNMPMessage.h.
References _varBindList, SNMP::ArrayBER< U >::add(), and SNMP::ArrayBER< SNMP_CAPACITY >::VarBind.
Referenced by setSNMPTrapOID().
|
inlineprivate |
Builds the message.
If required, updates value of sysUpTime.0 variable binding.
Definition at line 379 of file SNMPMessage.h.
References SNMP::Trap::_agentAddr, SNMP::PDU::Generic::_bulk, _community, SNMP::Trap::_enterprise, SNMP::PDU::Generic::_error, SNMP::PDU::_generic, SNMP::Trap::_genericTrap, SNMP::Error::_index, SNMP::PDU::Generic::Bulk::_maxRepetitions, SNMP::PDU::Generic::Bulk::_nonRepeaters, SNMP::PDU::Generic::_requestID, SNMP::Trap::_specificTrap, SNMP::Error::_status, SNMP::PDU::_trap, _type, _varBindList, _version, SNMP::ArrayBER< U >::add(), SNMP::Type::GetBulkRequest, SNMP::SequenceBER::SequenceBER(), and SNMP::Type::Trap.
Referenced by build(), getSize(), and SNMP::SNMP::send().
|
inlineprivate |
Builds the message to stream.
stream | Stream to write to. |
Definition at line 455 of file SNMPMessage.h.
References build(), and SNMP::ArrayBER< SNMP_CAPACITY >::encode().
|
inlineprivate |
Builds the message to buffer.
buffer | Pointer to the buffer. |
Definition at line 483 of file SNMPMessage.h.
References SNMP::ArrayBER< SNMP_CAPACITY >::encode().
|
inline |
Gets the community.
Definition at line 198 of file SNMPMessage.h.
References _community.
|
inline |
Gets the error index.
Definition at line 251 of file SNMPMessage.h.
References SNMP::PDU::Generic::_error, SNMP::PDU::_generic, and SNMP::Error::_index.
|
inline |
Gets the error status.
Definition at line 240 of file SNMPMessage.h.
References SNMP::PDU::Generic::_error, SNMP::PDU::_generic, and SNMP::Error::_status.
|
inline |
Gets the maximum repetition.
Definition at line 297 of file SNMPMessage.h.
References SNMP::PDU::Generic::_bulk, SNMP::PDU::_generic, and SNMP::PDU::Generic::Bulk::_maxRepetitions.
|
inline |
Gets the non repeaters.
Definition at line 275 of file SNMPMessage.h.
References SNMP::PDU::Generic::_bulk, SNMP::PDU::_generic, and SNMP::PDU::Generic::Bulk::_nonRepeaters.
|
inline |
Gets the request identifier.
Definition at line 218 of file SNMPMessage.h.
References SNMP::PDU::_generic, and SNMP::PDU::Generic::_requestID.
|
inlinevirtual |
Gets the size of the message.
Builds the message and call inherited ArrayBER::getSize() to ensure the size is valid.
refresh | Refresh parameter for inherited ArrayBER::getSize(). |
Reimplemented from SNMP::ArrayBER< SNMP_CAPACITY >.
Definition at line 166 of file SNMPMessage.h.
References build(), and SNMP::ArrayBER< U >::getSize().
Referenced by SNMP::SNMP::send().
|
inline |
|
inline |
Gets the variable bindings list.
Definition at line 369 of file SNMPMessage.h.
References _varBindList.
|
inline |
Gets the version.
Definition at line 189 of file SNMPMessage.h.
References _version.
|
inlineprivate |
Maps error status.
Converts an error status from SNMP version 2 to SNMP version 1.
status | SNMP version 2 error status. |
Definition at line 511 of file SNMPMessage.h.
References _version, SNMP::Error::AuthorizationError, SNMP::Error::BadValue, SNMP::Error::CommitFailed, SNMP::Error::GenErr, SNMP::Error::InconsistentName, SNMP::Error::InconsistentValue, SNMP::Error::NoAccess, SNMP::Error::NoCreation, SNMP::Error::NoSuchName, SNMP::Error::NotWritable, SNMP::Error::ResourceUnavailable, SNMP::Error::UndoFailed, SNMP::Version::V1, SNMP::Error::WrongEncoding, SNMP::Error::WrongLength, SNMP::Error::WrongType, and SNMP::Error::WrongValue.
Referenced by setError().
|
inlineprivate |
Parses the message.
Definition at line 417 of file SNMPMessage.h.
References SNMP::Trap::_agentAddr, SNMP::PDU::Generic::_bulk, _community, SNMP::Trap::_enterprise, SNMP::PDU::Generic::_error, SNMP::PDU::_generic, SNMP::Trap::_genericTrap, SNMP::Error::_index, SNMP::PDU::Generic::Bulk::_maxRepetitions, SNMP::PDU::Generic::Bulk::_nonRepeaters, SNMP::PDU::Generic::_requestID, SNMP::Trap::_specificTrap, SNMP::Error::_status, SNMP::Trap::_timeStamp, SNMP::PDU::_trap, _type, _varBindList, _version, SNMP::Type::GetBulkRequest, SNMP::BER::getType(), SNMP::ArrayBER< SNMP_CAPACITY >::operator[](), SNMP::ArrayBER< U >::remove(), and SNMP::Type::Trap.
Referenced by SNMP::SNMP::loop(), parse(), and parse().
|
inlineprivate |
Parses the message from stream.
stream | Stream to read from. |
Definition at line 468 of file SNMPMessage.h.
References SNMP::ArrayBER< SNMP_CAPACITY >::decode(), and parse().
|
inlineprivate |
Parses the message from buffer.
buffer | Pointer to the buffer. |
Definition at line 495 of file SNMPMessage.h.
References SNMP::ArrayBER< SNMP_CAPACITY >::decode(), and parse().
|
inline |
Sets the agent address.
agentAddr | Network address of the agent. |
Definition at line 330 of file SNMPMessage.h.
References SNMP::Trap::_agentAddr, and SNMP::PDU::_trap.
|
inline |
Sets the enterprise.
enterprise | Enterprise OID. |
Definition at line 319 of file SNMPMessage.h.
References SNMP::Trap::_enterprise, and SNMP::PDU::_trap.
|
inline |
Sets error status and error index.
Definition at line 263 of file SNMPMessage.h.
References SNMP::PDU::Generic::_error, SNMP::PDU::_generic, SNMP::Error::_index, SNMP::Error::_status, and mapErrorStatus().
|
inline |
Sets the maximum repetition.
maxRepetitions | Number of get next operations for each additional OIDs. |
Definition at line 308 of file SNMPMessage.h.
References SNMP::PDU::Generic::_bulk, SNMP::PDU::_generic, and SNMP::PDU::Generic::Bulk::_maxRepetitions.
|
inline |
Sets the non repeaters.
nonRepeaters | Number of OIDs treated as getRequest. |
Definition at line 286 of file SNMPMessage.h.
References SNMP::PDU::Generic::_bulk, SNMP::PDU::_generic, and SNMP::PDU::Generic::Bulk::_nonRepeaters.
|
inline |
Sets the request identifier.
requestId | Request identifier. |
Definition at line 229 of file SNMPMessage.h.
References SNMP::PDU::_generic, and SNMP::PDU::Generic::_requestID.
|
inline |
Sets the SNMPTRAPOID variable binding.
Adds variable binding snmpTrapOID.0 with value name.
name | snmpTrapOID.0 value. |
Definition at line 358 of file SNMPMessage.h.
References add(), SNMP::Message::OID::SNMPTRAPOID, and SNMP::Message::OID::SYSUPTIME.
|
inline |
Sets the generic and specific traps.
generic | Generic trap code. |
specific | Specific trap code. |
Definition at line 342 of file SNMPMessage.h.
References SNMP::Trap::_genericTrap, SNMP::Trap::_specificTrap, and SNMP::PDU::_trap.
|
friend |
Definition at line 545 of file SNMPMessage.h.
|
private |
SNMP community.
Definition at line 539 of file SNMPMessage.h.
Referenced by build(), getCommunity(), Message(), and parse().
|
private |
|
private |
Variable bindings list.
Definition at line 543 of file SNMPMessage.h.
Referenced by add(), build(), getVarBindList(), Message(), parse(), and ~Message().
|
private |
SNMP version.
Definition at line 537 of file SNMPMessage.h.
Referenced by build(), getVersion(), mapErrorStatus(), Message(), and parse().