SessionBase C++ Module

Analysis of Snmpwalk Options and SessionBase Constructor Mapping

This document analyzes how the command-line options of the snmpwalk tool correspond to the parameters of the SessionBase C++ constructor. It identifies direct matches, options without direct counterparts, and implicit or default behaviors. Note this behavior is identical/very similar for the other supported methods like snmpget, snmpbulkwalk, etc.

Direct Mappings

Several snmpwalk, snmpget, etc.. options have direct equivalents in the SessionBase constructor:

  • -v 1|2c|3 -> version

  • -c COMMUNITY -> community

  • -a PROTOCOL -> auth_protocol

  • -A PASSPHRASE -> auth_passphrase

  • -e ENGINE-ID -> security_engine_id

  • -E ENGINE-ID -> context_engine_id

  • -l LEVEL -> security_level

  • -n CONTEXT -> context

  • -u USER-NAME -> security_username

  • -x PROTOCOL -> privacy_protocol

  • -X PASSPHRASE -> privacy_passphrase

  • -Z BOOTS,TIME -> boots_time

  • -r RETRIES -> retries

  • -t TIMEOUT -> timeout

  • AGENT (hostname) -> hostname

The [OID] argument given to snmpwalk specifies the target OID for the walk. While not a parameter of the SessionBase constructor, it represents the action to be performed. SessionBase sets up a session, and contains a walk method that then uses the OID as its input parameter.

No Direct Mapping (or Implicit/Default)

The following snmpwalk options do not correspond to SessionBase constructor parameters:

  • -h, --help, -H, -V, --version, -d, -D[TOKEN[,...]], -m MIB[:...], -M DIR[:...], -P MIBOPTS, -O OUTOPTS, -I INOPTS, -L LOGOPTS, -C APPOPTS

These options influence snmpwalk’s operation (help, version display, debugging, MIB loading, output format, etc.). They are handled by the lower level NetsnmpBase functions. The SessionBase constructor is designed for core SNMP session setup, not the specifics of the snmpwalk tool or other SNMP operations.

The port_number parameter in the SessionBase constructor has no direct equivalent in snmpwalk. snmpwalk defaults to the standard SNMP port (161). The constructor parameter allows overriding this, but this cannot be set through snmpwalk’s options.

Summary Table

snmpwalk Option

SessionBase Parameter

Direct Map?

Notes

-v 1|2c|3

version

Yes

-v followed by the version (1, 2c, or 3)

-c COMMUNITY

community

Yes

-a PROTOCOL

auth_protocol

Yes

-A PASSPHRASE

auth_passphrase

Yes

-e ENGINE-ID

security_engine_id

Yes

-E ENGINE-ID

context_engine_id

Yes

-l LEVEL

security_level

Yes

-n CONTEXT

context

Yes

-u USER-NAME

security_username

Yes

-x PROTOCOL

privacy_protocol

Yes

-X PASSPHRASE

privacy_passphrase

Yes

-Z BOOTS,TIME

boots_time

Yes

-r RETRIES

retries

Yes

-t TIMEOUT

timeout

Yes

AGENT (hostname)

hostname

Yes

[OID]

(N/A - Action)

No

OID is the target of methods like walk, bulk_walk, get, etc., and is not a constructor parameter.

port_number

port_number

No (Implicit)

snmpwalk and methods alike use the default port 161. Parameter allows overriding.

All other options

(N/A - Tool Options)

No

These control snmpwalk’s and methods alike behavior, not the core SessionBase. If one wants more control, use the NetSnmpBase functions.

class SessionBase

Base class for managing SNMP sessions.

This class provides a base for managing SNMP sessions, including connection parameters, authentication, and basic operations like GET, SET, and WALK.

Public Functions

SessionBase(std::string const &hostname = "localhost", std::string const &port_number = "", std::string const &version = "3", std::string const &community = "public", std::string const &auth_protocol = "", std::string const &auth_passphrase = "", std::string const &security_engine_id = "", std::string const &context_engine_id = "", std::string const &security_level = "", std::string const &context = "", std::string const &security_username = "", std::string const &privacy_protocol = "", std::string const &privacy_passphrase = "", std::string const &boots_time = "", std::string const &retries = "3", std::string const &timeout = "1", std::string const &load_mibs = "", std::string const &mib_directories = "", bool print_enums_numerically = false, bool print_full_oids = false, bool print_oids_numerically = false, bool print_timeticks_numerically = false)

Constructor for SessionBase.

Initializes a new SessionBase object with the provided parameters.

Parameters:
  • hostname – Hostname or IP address of the SNMP agent (default: “localhost”).

  • port_number – Port number for the SNMP agent (default: “”).

  • version – SNMP version (“1”, “2c”, or “3”) (default: “3”).

  • community – Community string for SNMP v1/v2c (default: “public”).

  • auth_protocol – Authentication protocol for SNMP v3 (default: “”).

  • auth_passphrase – Authentication passphrase for SNMP v3 (default: “”).

  • security_engine_id – Security engine ID for SNMP v3 (default: “”).

  • context_engine_id – Context engine ID for SNMP v3 (default: “”).

  • security_level – Security level for SNMP v3 (default: “”).

  • context – Context name for SNMP v3 (default: “”).

  • security_username – Security username for SNMP v3 (default: “”).

  • privacy_protocol – Privacy protocol for SNMP v3 (default: “”).

  • privacy_passphrase – Privacy passphrase for SNMP v3 (default: “”).

  • boots_time – System boots time for SNMP v3 (default: “”).

  • retries – Number of retries for SNMP requests (default: “3”).

  • timeout – Timeout for SNMP requests (default: “1”).

  • load_mibs – Load given list of MIBs (default: “”).

  • mib_directories – Directories to search for MIBs (default: “”).

  • print_enums_numerically – Print enums numerically (default: false).

  • print_full_oids – Print full OIDs on output (default: false).

  • print_oids_numerically – Print OIDs numerically (default: false).

  • print_timeticks_numerically – Print timeticks as numeric integers (default: false).

~SessionBase()

Destructor for SessionBase.

std::vector<Result> walk(std::string const &mib = "")

Performs an SNMP WALK operation.

Retrieves a subtree of management information using SNMP WALK.

Parameters:

mib – The OID (Object Identifier) to start the walk from (default: “”).

Returns:

A vector of Result objects containing the retrieved data.

std::vector<Result> bulk_walk(std::string const &mib)

Performs an SNMP BULK WALK operation.

Retrieves a subtree of management information using SNMP BULK WALK.

Parameters:

mib – The OID to start the walk from.

Returns:

A vector of Result objects containing the retrieved data.

std::vector<Result> bulk_walk(std::vector<std::string> const &mibs)

Performs an SNMP BULK WALK operation on multiple OIDs.

Retrieves subtrees of management information using SNMP BULK WALK for multiple OIDs.

Parameters:

mibs – A vector of OIDs to start the walks from.

Returns:

A vector of Result objects containing the retrieved data.

std::vector<Result> get(std::string const &mib = "")

Performs an SNMP GET operation.

Retrieves the value of a specific management information object.

Parameters:

mib – The OID of the object to retrieve (default: “”).

Returns:

A vector of Result objects containing the retrieved data.

std::vector<Result> get(std::vector<std::string> const &mibs)

Performs an SNMP GET operation on multiple OIDs.

Retrieves the values of multiple management information objects.

Parameters:

mibs – A vector of OIDs to retrieve.

Returns:

A vector of Result objects containing the retrieved data.

std::vector<Result> get_next(std::vector<std::string> const &mibs)

Performs an SNMP GET NEXT operation on multiple OIDs.

Retrieves the values of the next lexicographically greater OIDs.

Parameters:

mibs – A vector of OIDs to retrieve the next values for.

Returns:

A vector of Result objects containing the retrieved data.

std::vector<Result> bulk_get(std::vector<std::string> const &mibs)

Performs an SNMP BULK GET operation on multiple OIDs.

Retrieves the values of multiple management information objects using BULK GET.

Parameters:

mibs – A vector of OIDs to retrieve.

Returns:

A vector of Result objects containing the retrieved data.

std::vector<Result> set(std::vector<std::string> const &mibs)

Performs an SNMP SET operation on multiple OIDs.

Sets the values of multiple management information objects.

Parameters:

mibs – A vector of OIDs and their corresponding values to set.

Returns:

A vector of Result objects containing the results of the SET operation.

std::vector<std::string> const &_get_args() const

Returns the SNMP command arguments.

Returns:

A constant reference to the vector of SNMP command arguments.

std::string const &_get_hostname() const

Returns the hostname of the SNMP agent.

Returns:

A constant reference to the hostname.

std::string const &_get_port_number() const

Returns the port number for the SNMP agent.

Returns:

A constant reference to the port number.

std::string const &_get_version() const

Returns the SNMP version.

Returns:

A constant reference to the SNMP version.

std::string const &_get_community() const

Returns the community string.

Returns:

A constant reference to the community string.

std::string const &_get_auth_protocol() const

Returns the authentication protocol.

Returns:

A constant reference to the authentication protocol.

std::string const &_get_auth_passphrase() const

Returns the authentication passphrase.

Returns:

A constant reference to the authentication passphrase.

std::string const &_get_security_engine_id() const

Returns the security engine ID.

Returns:

A constant reference to the security engine ID.

std::string const &_get_context_engine_id() const

Returns the context engine ID.

Returns:

A constant reference to the context engine ID.

std::string const &_get_security_level() const

Returns the security level.

Returns:

A constant reference to the security level.

std::string const &_get_context() const

Returns the context name.

Returns:

A constant reference to the context name.

std::string const &_get_security_username() const

Returns the security username.

Returns:

A constant reference to the security username.

std::string const &_get_privacy_protocol() const

Returns the privacy protocol.

Returns:

A constant reference to the privacy protocol.

std::string const &_get_privacy_passphrase() const

Returns the privacy passphrase.

Returns:

A constant reference to the privacy passphrase.

std::string const &_get_boots_time() const

Returns the system boots time.

Returns:

A constant reference to the system boots time.

std::string const &_get_retries() const

Returns the number of retries.

Returns:

A constant reference to the number of retries.

std::string const &_get_timeout() const

Returns the timeout value.

Returns:

A constant reference to the timeout value.

void _set_hostname(std::string const &hostname)

Sets the hostname of the SNMP agent.

Parameters:

hostname – The new hostname to set.

void _set_port_number(std::string const &port_number)

Sets the port number for the SNMP agent.

Parameters:

port_number – The new port number to set.

void _set_version(std::string const &version)

Sets the SNMP version.

Parameters:

version – The new SNMP version to set.

void _set_community(std::string const &community)

Sets the community string.

Parameters:

community – The new community string to set.

void _set_auth_protocol(std::string const &auth_protocol)

Sets the authentication protocol.

Parameters:

auth_protocol – The new authentication protocol to set.

void _set_auth_passphrase(std::string const &auth_passphrase)

Sets the authentication passphrase.

Parameters:

auth_passphrase – The new authentication passphrase to set.

void _set_security_engine_id(std::string const &security_engine_id)

Sets the security engine ID.

Parameters:

security_engine_id – The new security engine ID to set.

void _set_context_engine_id(std::string const &context_engine_id)

Sets the context engine ID.

Parameters:

context_engine_id – The new context engine ID to set.

void _set_security_level(std::string const &security_level)

Sets the security level.

Parameters:

security_level – The new security level to set.

void _set_context(std::string const &context)

Sets the context name.

Parameters:

context – The new context name to set.

void _set_security_username(std::string const &security_username)

Sets the security username.

Parameters:

security_username – The new security username to set.

void _set_privacy_protocol(std::string const &privacy_protocol)

Sets the privacy protocol.

Parameters:

privacy_protocol – The new privacy protocol to set.

void _set_privacy_passphrase(std::string const &privacy_passphrase)

Sets the privacy passphrase.

Parameters:

privacy_passphrase – The new privacy passphrase to set.

void _set_boots_time(std::string const &boots_time)

Sets the system boots time.

Parameters:

boots_time – The new system boots time to set.

void _set_retries(std::string const &retries)

Sets the number of retries.

Parameters:

retries – The new number of retries to set.

void _set_timeout(std::string const &timeout)

Sets the timeout value.

Parameters:

timeout – The new timeout value to set.

Private Functions

void populate_args()

Populates the m_args vector with SNMP command arguments.

This private method constructs the command-line arguments for the SNMP command based on the session parameters.

void check_and_clear_v3_user()

Checks and clears SNMP v3 user parameters if not applicable.

This private method ensures that SNMP v3 user-related parameters are cleared if the SNMP version is not 3.

Private Members

std::vector<std::string> m_args

Vector to store SNMP command arguments.

std::string m_hostname = ""

Hostname or IP address of the SNMP agent [AGENT].

std::string m_port_number = ""

Port number for the SNMP agent.

std::string m_version = ""

SNMP version (1|2c|3).

std::string m_community = ""

Community string (COMMUNITY).

std::string m_auth_protocol = ""

Authentication protocol (MD5|SHA|SHA-224|SHA-256|SHA-384|SHA-512).

std::string m_auth_passphrase = ""

Authentication protocol pass phrase (PASSPHRASE).

std::string m_security_engine_id = ""

Security engine ID (ENGINE-ID e.g. 800000020109840301).

std::string m_context_engine_id = ""

Context engine ID (ENGINE-ID e.g. 800000020109840301).

std::string m_security_level = ""

Security level (noAuthNoPriv|authNoPriv|authPriv).

std::string m_context = ""

Context name (CONTEXT e.g. bridge1).

std::string m_security_username = ""

Security name (USER-NAME e.g. bert).

std::string m_privacy_protocol = ""

Privacy protocol (DES|AES|AES-192|AES-256).

std::string m_privacy_passphrase = ""

Privacy protocol pass phrase (PASSPHRASE).

std::string m_boots_time = ""

Destination engine boots/time (BOOTS,TIME).

std::string m_retries = ""

Number of retries (RETRIES).

std::string m_timeout = ""

Request timeout in seconds (TIMEOUT).

std::string m_load_mibs = ""

Load given list of MIBs (MIB[:…]).

std::string m_mib_directories = ""

Directories to search for MIBs (DIR[:…]).

bool m_print_enums_numerically = false

Print enums numerically (-O e).

bool m_print_full_oids = false

Print full OIDs on output (-O f).

bool m_print_oids_numerically = false

Print OIDs numerically (-O n).

bool m_print_timeticks_numerically = false

Print timeticks unparsed as numeric integers (-O t).