Represents an SNMP object identifier (OID). More...
#include <oid.hpp>
Public Member Functions | |
| oid () | |
| Default Constructor. | |
| oid (std::string id) | |
| Initialize an oid object with an OID in string format. | |
| oid (const oid &o, std::string id) | |
| Initialize an oid object with another oid plus an OID in string format. | |
| oid & | operator= (const oid &o) |
| Assignment operator. | |
| bool | get_include () |
| Get the current include value. | |
| void | set_include (bool i) |
| set the include value | |
| binary | serialize () const |
| Encode an OID object as described in RFC 2741, section 5.1. | |
| oid (binary::const_iterator &pos, const binary::const_iterator &end, bool big_endian=true) | |
| Construct the object from input stream. | |
| bool | operator< (const oid &o) const |
| The less-than operator. | |
| bool | operator== (const oid &o) const |
| The equal-operator. | |
| bool | operator!= (const oid &o) const |
| The not-equal-operator for oids. | |
| bool | operator> (const oid &o) const |
| The greater-than operator. | |
| bool | contains (const oid &id) |
| Checks whether the given oid is in the subtree of this oid. | |
| bool | is_null () const |
| Whether it is the null Object Identifier. | |
| virtual void | update () |
| Update the internal state of the object. | |
| virtual oid | get () |
| Obtain the current value for the object. | |
Public Member Functions inherited from agentxcpp::variable | |
| virtual | ~variable () |
| Destructor. | |
Public Attributes | |
| const oid | iso_oid ("1") |
| The 'iso' OID according to RFC 1155. | |
| const oid | ccitt_oid ("0") |
| The 'ccitt' OID according to RFC 1155. | |
| const oid | joint_iso_ccitt_oid ("2") |
| The 'joint.iso.ccitt' OID according to RFC 1155. | |
| const oid | org_oid (iso_oid,"3") |
| The 'iso.org' OID according to RFC 1155. | |
| const oid | dod_oid (org_oid,"6") |
| The 'iso.org.dod' OID according to RFC 1155. | |
| const oid | internet_oid (dod_oid,"1") |
| The 'iso.org.dod.internet' OID according to RFC 1155. | |
| const oid | directory_oid (internet_oid,"1") |
| The 'iso.org.dod.internet.directory' OID according to RFC 1155. | |
| const oid | mgmt_oid (internet_oid,"2") |
| The 'iso.org.dod.internet.mgmt' OID according to RFC 1155. | |
| const oid | experimental_oid (internet_oid,"3") |
| The 'iso.org.dod.internet.experimental' OID according to RFC 1155. | |
| const oid | private_oid (internet_oid,"4") |
| The 'iso.org.dod.internet.private' OID according to RFC 1155. | |
| const oid | enterprises_oid (private_oid,"1") |
| The 'iso.org.dod.internet.private.enterprises' OID according to RFC 1155. | |
Public Attributes inherited from std::vector< T > | |
| T | elements |
| STL member. | |
Private Member Functions | |
| void | parse_string (std::string s) |
| Parse an OID from a string and append it. | |
Private Attributes | |
| bool | include |
| the 'include' field. | |
Friends | |
| std::ostream & | operator<< (std::ostream &out, const agentxcpp::oid &o) |
| The output operator for the oid class. | |
Represents an SNMP object identifier (OID).
This class represents an OID. OID's are sequences of sub-identifiers, which are integers.
This class provides constructors taking a string which contains an OID. For example, this works:
Also a constructor is provided which takes an oid and a string and concatenates them, so this works also:
In addition, some common oid's are provided as constants, e.g. 'enterprises_oid', so the following will also work (note that the second argument is a string, not an integer!):
The string given to the constructors must have a valid syntax. If a malformed string is provided, inval_param is thrown and the object is not constructed. For example, the following strings are malformed:
However, the following strings are accepted:
This class inherits from std:vector<uint32_t>, which means that an oid object can be manipulated the same way as a std::vector<> can be manipulated:
|
inline |
| oid::oid | ( | std::string | id | ) |
Initialize an oid object with an OID in string format.
This constructor takes a string and initializes the oid object with the OID contained within this string. The format of the string is described above.
The 'include' field is initialized to 'false'.
\param id The initial object identifier.
\exception inval_param If the string is malformed.
| oid::oid | ( | const oid & | o, |
| std::string | id | ||
| ) |
Initialize an oid object with another oid plus an OID in string format.
All subid's are copied from 'o'. Then, the OID contained within the string 'id' is appended. The format of the string is described in the documentation of this class.
The 'include' field is copied from 'o'.
\param o The starting OID.
\param id The OID to append.
\exception inval_param If the string is malformed.
| oid::oid | ( | binary::const_iterator & | pos, |
| const binary::const_iterator & | end, | ||
| bool | big_endian = true |
||
| ) |
Construct the object from input stream.
This constructor parses the serialized form of the object. It takes an iterator, starts parsing at the position of the iterator and advances the iterator to the position right behind the object.
The constructor expects valid data from the stream; if parsing fails, parse_error is thrown. In this case, the iterator is left at an undefined position.
| pos | Iterator pointing to the current stream position. The iterator is advanced while reading the header. |
| end | Iterator pointing one element past the end of the current stream. This is needed to mark the end of the buffer. |
| big_endian | Whether the input stream is in big endian format |
| parse_error | If parsing fails. In this case, the iterator is left at an undefined position. |
| bool oid::contains | ( | const oid & | id | ) |
Checks whether the given oid is in the subtree of this oid.
This method checks whether the given OID is included in the subtree which has this oid as root.
Examples:
| id | The OID to check. |
|
inlinevirtual |
Obtain the current value for the object.
This member function is derived by classes representing SNMP variables and shall return the current value of the object.
The default implementation throws generic_error.
| generic_error | If obtaining the current value fails. No other exception shall be thrown. |
|
inline |
Get the current include value.
The include value is present in the serialized form of an OID. If an OID object is created by parsing a AgentX message, the 'include' member is set accordingly.
See RFC 2741, sections 5.1 and 5.2 for details.
Definition at line 192 of file oid.hpp.
References include.
Referenced by agentxcpp::GetPDU::GetPDU().
| bool oid::is_null | ( | ) | const |
Whether it is the null Object Identifier.
According to RFC 2741, 5.1 "Object Identifier", a null object identifier has serial representation of for 4 bytes which are all set to 0. An OID with no subid's and the index field set to 0 results in that representation and is thus considered to be the null OID.
|
inline |
The not-equal-operator for oids.
See operator<() for a more detailed description about comparing OIDs.
| o | The OID tocompare to. |
| bool oid::operator< | ( | const oid & | o | ) | const |
The less-than operator.
An OID is less than another OID if either the first not-identical part is lesser or if all parts are identical and it has lesser parts.
Example:
1.3.6.1.4.1.42.3.3.1
is less than
1.3.6.1.4.1.42.3.4.1
Note the next to last number.
Also,
1.3.6.1.4.1.42.3.3.1
is less than
1.3.6.1.4.1.42.3.3.1.1
because it is shorter.
However,
1.3.6.1.4.1.42.3.3.1
is greater than
1.3.6.1.4.1.42.3.2.1.1
because the 9th number is greater (although the first OID has less numbers than the second).
| o | The OID tocompare to. |
| bool oid::operator== | ( | const oid & | o | ) | const |
The equal-operator.
See operator<() for a more detailed description about comparing OIDs.
| o | The OID tocompare to. |
|
inline |
The greater-than operator.
See operator<() for a more detailed description about comparing OIDs.
| o | The OID tocompare to. |
|
private |
Parse an OID from a string and append it.
The OID contained within the string 's' is parsed and appended this object. The format of the string is described above
| s | The OID to be parsed. |
| inval_param | If the string is malformed. |
|
virtual |
Encode an OID object as described in RFC 2741, section 5.1.
Implements agentxcpp::variable.
Definition at line 118 of file oid.cpp.
Referenced by agentxcpp::UnregisterPDU::serialize(), agentxcpp::varbind::serialize(), and agentxcpp::RegisterPDU::serialize().
|
inline |
|
inlinevirtual |
Update the internal state of the object.
This function calls get() to obtain a new value and stores that value within this object.
| generic_error | If obtaining the new value failed. |
Implements agentxcpp::variable.
|
friend |
The output operator for the oid class.
Object identifiers (oid objects) can be output as follows:
The last line will output "LED state OID: .1.3.6.1.4.1.3.3.1".
| out | The stream to which to write the output. |
| o | The OID to output. |
| const oid ccitt_oid("0") |
The 'ccitt' OID according to RFC 1155.
| const oid directory_oid(internet_oid,"1") |
The 'iso.org.dod.internet.directory' OID according to RFC 1155.
| const oid enterprises_oid(private_oid,"1") |
The 'iso.org.dod.internet.private.enterprises' OID according to RFC 1155.
| const oid experimental_oid(internet_oid,"3") |
The 'iso.org.dod.internet.experimental' OID according to RFC 1155.
|
private |
the 'include' field.
Definition at line 100 of file oid.hpp.
Referenced by get_include(), oid(), operator=(), and set_include().
| const oid iso_oid("1") |
The 'iso' OID according to RFC 1155.
| const oid joint_iso_ccitt_oid("2") |
The 'joint.iso.ccitt' OID according to RFC 1155.
| const oid mgmt_oid(internet_oid,"2") |
The 'iso.org.dod.internet.mgmt' OID according to RFC 1155.
| const oid private_oid(internet_oid,"4") |
The 'iso.org.dod.internet.private' OID according to RFC 1155.