AgentXcpp  Revision:0.2
Internals Documentation
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Pages
agentxcpp::OidValue Class Reference

Represents an SNMP object identifier (OID). More...

#include <OidValue.hpp>

Inheritance diagram for agentxcpp::OidValue:
Collaboration diagram for agentxcpp::OidValue:

Public Member Functions

 OidValue ()
 Default Constructor.
 OidValue (std::string id)
 Initialize an OidValue object with an OID in string format.
 OidValue (const OidValue &o, std::string id)
 Initialize an OidValue object with another OidValue plus an OID in string format.
OidValueoperator= (const OidValue &o)
 Assignment operator.
bool get_include () const
 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.
 OidValue (binary::const_iterator &pos, const binary::const_iterator &end, bool big_endian=true)
 Parse Constructor.
bool operator< (const OidValue &o) const
 The less-than operator.
bool operator== (const OidValue &o) const
 The equal-operator.
bool operator!= (const OidValue &o) const
 The not-equal-operator for OidValues.
bool operator> (const OidValue &o) const
 The greater-than operator.
bool contains (const OidValue &id)
 Checks whether the given OidValue is in the subtree of this OidValue.
bool is_null () const
 Whether it is the null Object Identifier.
- Public Member Functions inherited from agentxcpp::AbstractValue
virtual ~AbstractValue ()
 Destructor.

Public Attributes

const OidValue iso_oid ("1")
 The 'iso' OID according to RFC 1155.
const OidValue ccitt_oid ("0")
 The 'ccitt' OID according to RFC 1155.
const OidValue joint_iso_ccitt_oid ("2")
 The 'joint.iso.ccitt' OID according to RFC 1155.
const OidValue org_oid (iso_oid,"3")
 The 'iso.org' OID according to RFC 1155.
const OidValue dod_oid (org_oid,"6")
 The 'iso.org.dod' OID according to RFC 1155.
const OidValue internet_oid (dod_oid,"1")
 The 'iso.org.dod.internet' OID according to RFC 1155.
const OidValue directory_oid (internet_oid,"1")
 The 'iso.org.dod.internet.directory' OID according to RFC 1155.
const OidValue mgmt_oid (internet_oid,"2")
 The 'iso.org.dod.internet.mgmt' OID according to RFC 1155.
const OidValue experimental_oid (internet_oid,"3")
 The 'iso.org.dod.internet.experimental' OID according to RFC 1155.
const OidValue private_oid (internet_oid,"4")
 The 'iso.org.dod.internet.private' OID according to RFC 1155.
const OidValue enterprises_oid (private_oid,"1")
 The 'iso.org.dod.internet.private.enterprises' OID according to RFC 1155.
const OidValue snmpMIBObjects_oid (internet_oid,"6.3.1.1")
 The 'snmpMIBObjects' OID according to RFC 1907.
const OidValue snmpTrapOID_oid (snmpMIBObjects_oid,"4.1")
 The 'snmpTrapOID' OID according to RFC 1907.
const OidValue sysUpTime_oid (mgmt_oid,"1.1.3")
 The sysUpTime_oid OID according to RFC 1907.
- Public Attributes inherited from std::vector< 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::OidValue &o)
 The output operator for the OidValue class.

Detailed Description

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:

OidValue myCompany = OidValue("1.3.6.1.4.1.355");

Also a constructor is provided which takes an OidValue and a string and concatenates them, so this works also:

OidValue myObject = OidValue(myCompany, "1.1.3.0");

In addition, some common OidValue'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!):

OidValue yourCompany = OidValue(enterprises_oid, "42"); // second param is a string!

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:

"1,3,6" // wrong separator (must be a period)
"1.3.6." // trailing character at the end
"1.3.6.1.4.1.123456789123" // last subid is too big (must fit in a 32 bit unsigned integer)

However, the following strings are accepted:

"1.3.6"
"1" // a single subid is ok
"1.3.6.1.4.1.42.1.0" // 0 as subid is ok
"" // empty string is ok

This class inherits from std:vector<uint32_t>, which means that an OidValue object can be manipulated the same way as a std::vector<> can be manipulated:

OidValue theirCompany = enterprises_oid;
theirCompany.push_back(23); // Don't use a string here!

Definition at line 93 of file OidValue.hpp.

Constructor & Destructor Documentation

agentxcpp::OidValue::OidValue ( )
inline

Default Constructor.

This constructs an empty OidValue (the null OidValue).

The 'include' field is initialized to 'false'.

Exceptions
None.

Definition at line 127 of file OidValue.hpp.

References include.

OidValue::OidValue ( std::string  id)

Initialize an OidValue object with an OID in string format.

This constructor takes a string and initializes the OidValue object with the OID contained within this string. The format of the string is described above.

The 'include' field is initialized to 'false'.

Parameters
idThe initial object identifier.
Exceptions
inval_paramIf the string is malformed.

Definition at line 68 of file OidValue.cpp.

OidValue::OidValue ( const OidValue o,
std::string  id 
)

Initialize an OidValue object with another OidValue 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'.

Parameters
oThe starting OID.
idThe OID to append.
Exceptions
inval_paramIf the string is malformed.

Definition at line 77 of file OidValue.cpp.

OidValue::OidValue ( binary::const_iterator &  pos,
const binary::const_iterator &  end,
bool  big_endian = true 
)

Parse Constructor.

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.

Parameters
posIterator pointing to the current stream position. The iterator is advanced while reading the header.
endIterator pointing one element past the end of the current stream. This is needed to mark the end of the buffer.
big_endianWhether the input stream is in big endian format
Exceptions
parse_errorIf parsing fails. In this case, the iterator is left at an undefined position.

Definition at line 189 of file OidValue.cpp.

Member Function Documentation

bool OidValue::contains ( const OidValue id)

Checks whether the given OidValue is in the subtree of this OidValue.

This method checks whether the given OID is included in the subtree which has this OidValue as root.

Examples:

OidValue id("1.3.6.1.4.1.42.3");
id.contains( OidValue(1.3.6.1.4.1.42.3) ); // true
id.contains( OidValue(1.3.6.1.4.1.42) ); // false
id.contains( OidValue(1.3.6.1.4.1.43.3) ); // false
id.contains( OidValue(1.3.6.1.4.1.42.3.3.1) ); // true
Parameters
idThe OID to check.
Returns
True if id is contained in the subtree, false otherwise.

Definition at line 349 of file OidValue.cpp.

bool agentxcpp::OidValue::get_include ( ) const
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 OidValue.hpp.

References include.

Referenced by agentxcpp::GetPDU::GetPDU(), and agentxcpp::MasterProxy::handle_getnextpdu().

bool OidValue::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 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.

Returns
True if the object is the null OID, false otherwise.

Definition at line 375 of file OidValue.cpp.

Referenced by agentxcpp::MasterProxy::handle_getnextpdu().

bool agentxcpp::OidValue::operator!= ( const OidValue o) const
inline

The not-equal-operator for OidValues.

See operator<() for a more detailed description about comparing OIDs.

Parameters
oThe OID tocompare to.
Returns
False if the OIDs are equal, true otherwise.

Definition at line 307 of file OidValue.hpp.

bool OidValue::operator< ( const OidValue 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).

Parameters
oThe OID tocompare to.
Returns
True if the OID is less than 'o', false otherwise.

Definition at line 258 of file OidValue.cpp.

OidValue & OidValue::operator= ( const OidValue o)

Assignment operator.

Copies all data from 'o' into this OID.

Parameters
oThe OID to copy from.
Returns
A reference to this OID.

Definition at line 335 of file OidValue.cpp.

References include.

bool OidValue::operator== ( const OidValue o) const

The equal-operator.

See operator<() for a more detailed description about comparing OIDs.

Parameters
oThe OID tocompare to.
Returns
True if the OIDs are equal, false otherwise.

Definition at line 301 of file OidValue.cpp.

bool agentxcpp::OidValue::operator> ( const OidValue o) const
inline

The greater-than operator.

See operator<() for a more detailed description about comparing OIDs.

Parameters
oThe OID tocompare to.
Returns
True if the OID is greater than 'o', false otherwise.

Definition at line 322 of file OidValue.hpp.

void OidValue::parse_string ( std::string  s)
private

Parse an OID from a string and append it.

The OID contained within the string 's' is parsed and appended to this object. The format of the string is described above.

Parameters
sThe OID to be parsed.
Exceptions
inval_paramIf the string is malformed.

Definition at line 30 of file OidValue.cpp.

binary OidValue::serialize ( ) const
virtual

Encode an OID object as described in RFC 2741, section 5.1.

Implements agentxcpp::AbstractValue.

Definition at line 118 of file OidValue.cpp.

Referenced by agentxcpp::UnregisterPDU::serialize(), agentxcpp::RegisterPDU::serialize(), and agentxcpp::varbind::serialize().

void agentxcpp::OidValue::set_include ( bool  i)
inline

set the include value

The include value is present in the serialized form of an OID. If an OID object is serialized, the include field is encoded into the stream.

See RFC 2741, sections 5.1 and 5.2 for details.

Definition at line 208 of file OidValue.hpp.

References include.

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  out,
const agentxcpp::OidValue o 
)
friend

The output operator for the OidValue class.

Object identifiers (OidValue objects) can be output as follows:

OidValue led_state(enterprises_oid, "1.3.3.1");
cout << "LED state OID: " << led_state << endl;

The last line will output "LED state OID: .1.3.6.1.4.1.3.3.1".

Parameters
outThe stream to which to write the output.
oThe OID to output.
Returns
The 'out' parameter.

Member Data Documentation

const OidValue ccitt_oid("0")

The 'ccitt' OID according to RFC 1155.

const OidValue directory_oid(internet_oid,"1")

The 'iso.org.dod.internet.directory' OID according to RFC 1155.

const OidValue dod_oid(org_oid,"6")

The 'iso.org.dod' OID according to RFC 1155.

const OidValue enterprises_oid(private_oid,"1")

The 'iso.org.dod.internet.private.enterprises' OID according to RFC 1155.

const OidValue experimental_oid(internet_oid,"3")

The 'iso.org.dod.internet.experimental' OID according to RFC 1155.

bool agentxcpp::OidValue::include
private

the 'include' field.

Definition at line 100 of file OidValue.hpp.

Referenced by get_include(), OidValue(), operator=(), and set_include().

const OidValue internet_oid(dod_oid,"1")

The 'iso.org.dod.internet' OID according to RFC 1155.

const OidValue iso_oid("1")

The 'iso' OID according to RFC 1155.

const OidValue joint_iso_ccitt_oid("2")

The 'joint.iso.ccitt' OID according to RFC 1155.

const OidValue mgmt_oid(internet_oid,"2")

The 'iso.org.dod.internet.mgmt' OID according to RFC 1155.

const OidValue org_oid(iso_oid,"3")

The 'iso.org' OID according to RFC 1155.

const OidValue private_oid(internet_oid,"4")

The 'iso.org.dod.internet.private' OID according to RFC 1155.

const OidValue snmpMIBObjects_oid(internet_oid,"6.3.1.1")

The 'snmpMIBObjects' OID according to RFC 1907.

This OID is used in the context of notifications.

According to RFC 1907:
snmpTrapOID ::= snmpTrap.1
snmpTrap ::= snmpMIBObjects.4
snmpMIBObjects ::= snmpMIB.1
snmpMIB ::= snmpModules.1

According to RFC 2578 (SNMPv2-SMI):
snmpModules ::= snmpV2.3
snmpV2 ::= internet.6

Conclusion:
snmpMIBObjects ::= internet.6.3.1.1

const OidValue snmpTrapOID_oid(snmpMIBObjects_oid,"4.1")

The 'snmpTrapOID' OID according to RFC 1907.

This OID is used in the context of notifications.

According to RFC 1907:
snmpTrapOID ::= snmpTrap.1
snmpTrap ::= snmpMIBObjects.4

Conclusion:
snmpTrapOID ::= snmpMIBObjects.4.1

const OidValue sysUpTime_oid(mgmt_oid,"1.1.3")

The sysUpTime_oid OID according to RFC 1907.

This OID is used in the context of notifications.

According to RFC 1907:
sysUpTime = system.3
system = mib-2.1

According to RFC 1902:
mib-2 = mgmt.1

Conclusion: sysUpTime = mgmt.1.1.3


The documentation for this class was generated from the following files: