AgentXcpp  Version:0.3
Internals Documentation
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Pages
agentxcpp::Oid Class Reference

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

#include <Oid.hpp>

Inheritance diagram for agentxcpp::Oid:
Collaboration diagram for agentxcpp::Oid:

Public Member Functions

 Oid (std::string id="")
 Initialize an Oid object with an OID in string format. More...
 
 Oid (const Oid &o, std::string id)
 Initialize an Oid object with another Oid plus a subid. More...
 
 Oid (const Oid &o, quint32 id)
 Initialize an Oid object with another Oid plus a subid. More...
 
Oidoperator= (const Oid &o)
 Assignment operator. More...
 
bool operator< (const Oid &o) const
 The less-than operator. More...
 
bool operator<= (const Oid &o) const
 The less-than-or-equal operator. More...
 
bool operator== (const Oid &o) const
 The equal-operator. More...
 
bool operator!= (const Oid &o) const
 The not-equal-operator for OIDs. More...
 
bool operator> (const Oid &o) const
 The greater-than operator. More...
 
bool operator>= (const Oid &o) const
 The greater-than-or-equal operator. More...
 
Oid operator+ (quint32 subid) const
 Concatenation. More...
 
Oid operator+ (const Oid &o) const
 Concatenation. More...
 
Oidoperator+= (const Oid &o)
 Concatenation. More...
 
bool contains (const Oid &id) const
 Checks whether the given Oid is in the subtree of this Oid. More...
 
bool is_null () const
 
bool include () const
 Get the current include value. More...
 
void setInclude (bool i)
 set the include value More...
 

Public Attributes

const Oid iso_oid ("1")
 The 'iso' OID according to RFC 1155. More...
 
const Oid ccitt_oid ("0")
 The 'ccitt' OID according to RFC 1155. More...
 
const Oid joint_iso_ccitt_oid ("2")
 The 'joint.iso.ccitt' OID according to RFC 1155. More...
 
const Oid org_oid (iso_oid,"3")
 The 'iso.org' OID according to RFC 1155. More...
 
const Oid dod_oid (org_oid,"6")
 The 'iso.org.dod' OID according to RFC 1155. More...
 
const Oid internet_oid (dod_oid,"1")
 The 'iso.org.dod.internet' OID according to RFC 1155. More...
 
const Oid directory_oid (internet_oid,"1")
 The 'iso.org.dod.internet.directory' OID according to RFC 1155. More...
 
const Oid mgmt_oid (internet_oid,"2")
 The 'iso.org.dod.internet.mgmt' OID according to RFC 1155. More...
 
const Oid experimental_oid (internet_oid,"3")
 The 'iso.org.dod.internet.experimental' OID according to RFC 1155. More...
 
const Oid private_oid (internet_oid,"4")
 The 'iso.org.dod.internet.private' OID according to RFC 1155. More...
 
const Oid enterprises_oid (private_oid,"1")
 The 'iso.org.dod.internet.private.enterprises' OID according to RFC 1155. More...
 
const Oid snmpMIBObjects_oid (internet_oid,"6.3.1.1")
 The 'snmpMIBObjects' OID according to RFC 1907. More...
 
const Oid snmpTrapOID_oid (snmpMIBObjects_oid,"4.1")
 The 'snmpTrapOID' OID according to RFC 1907. More...
 
const Oid sysUpTime_oid (mgmt_oid,"1.1.3")
 The sysUpTime_oid OID according to RFC 1907. More...
 

Private Member Functions

void parseString (std::string s)
 Parse an OID from a string and append it. More...
 

Private Attributes

bool mInclude
 the 'include' field. More...
 

Friends

std::ostream & operator<< (std::ostream &out, const Oid &o)
 The output operator for the Oid class. More...
 

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:

Oid myCompany("1.3.6.1.4.1.355");

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

Oid myObject(myCompany, "1.1.3.0");

In addition, some common Oid's are provided as constants, e.g. 'enterprises_oid', so the following will also work:

Oid yourCompany(enterprises_oid, 42); // 42 is an integer
Oid yourCompanyMib(enterprises_oid, "42.1.1"); // "42.1.1" 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 QVector<quint32>, which means that an Oid object can be manipulated the same way as a QVector<> can be manipulated:

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

Definition at line 91 of file Oid.hpp.

Constructor & Destructor Documentation

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.

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

Definition at line 67 of file Oid.cpp.

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

Initialize an Oid object with another Oid plus a subid.

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.

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

Definition at line 74 of file Oid.cpp.

Oid::Oid ( const Oid o,
quint32  id 
)

Initialize an Oid object with another Oid plus a subid.

All subid's are copied from 'o'. Then, the subid 'id' is appended.

Parameters
oThe starting OID.
idThe subid to append.
Exceptions
None.

Definition at line 84 of file Oid.cpp.

Member Function Documentation

bool Oid::contains ( const Oid id) const

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:

Oid id("1.3.6.1.4.1.42.3");
id.contains( Oid("1.3.6.1.4.1.42.3") ); // true
id.contains( Oid("1.3.6.1.4.1.42") ); // false
id.contains( Oid("1.3.6.1.4.1.43.3") ); // false
id.contains( Oid("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 213 of file Oid.cpp.

bool agentxcpp::Oid::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 400 of file Oid.hpp.

References mInclude.

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

bool Oid::is_null ( ) const
bool agentxcpp::Oid::operator!= ( const Oid o) const
inline

The not-equal-operator for OIDs.

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

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

Definition at line 246 of file Oid.hpp.

Oid agentxcpp::Oid::operator+ ( quint32  subid) const
inline

Concatenation.

This operator returns a temporary Oid object which is this OID plus 'subid' appended. Example:

Oid a("1.2.3");
Oid b = a + 4; // b will be 1.2.3.4
Parameters
subidThe subid to append.
Returns
The temporary object.

Definition at line 299 of file Oid.hpp.

Oid agentxcpp::Oid::operator+ ( const Oid o) const
inline

Concatenation.

This operator returns a temporary Oid object which is this OID plus 'o' appended. Example:

Oid a("1.2.3");
Oid b("4.5.6");
Oid c = a + b; // c will be 1.2.3.4.5.6
Parameters
oThe OID to append.
Returns
The temporary object.

Definition at line 322 of file Oid.hpp.

Oid& agentxcpp::Oid::operator+= ( const Oid o)
inline

Concatenation.

This operator appends 'o' to this OID. Example:

Oid a("1.2.3");
Oid b("4.5.6");
a += b;
// a is now 1.2.3.4.5.6
Parameters
oThe OID to append.
Returns
A reference to this OID.

Definition at line 345 of file Oid.hpp.

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).

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

Definition at line 124 of file Oid.cpp.

bool agentxcpp::Oid::operator<= ( const Oid o) const
inline

The less-than-or-equal operator.

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

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

Definition at line 212 of file Oid.hpp.

Oid & Oid::operator= ( const Oid 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 201 of file Oid.cpp.

References mInclude.

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

The equal-operator.

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

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

Definition at line 167 of file Oid.cpp.

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

The greater-than operator.

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

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

Definition at line 261 of file Oid.hpp.

bool agentxcpp::Oid::operator>= ( const Oid o) const
inline

The greater-than-or-equal operator.

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

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

Definition at line 278 of file Oid.hpp.

void Oid::parseString ( 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 29 of file Oid.cpp.

void agentxcpp::Oid::setInclude ( 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 416 of file Oid.hpp.

Friends And Related Function Documentation

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

The output operator for the Oid class.

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

Oid 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 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 dod_oid(org_oid,"6")

The 'iso.org.dod' 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.

const Oid internet_oid(dod_oid,"1")

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

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.

bool agentxcpp::Oid::mInclude
private

the 'include' field.

Definition at line 98 of file Oid.hpp.

Referenced by include(), and operator=().

const Oid org_oid(iso_oid,"3")

The 'iso.org' 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 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 Oid 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 Oid 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.1OidValue

Conclusion: sysUpTime = mgmt.1.1.3


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