Manages a NETCONF client session and basic datastore operations for a network device.
More...
#include <NetconfSession.h>
|
| | NetconfSession () |
| |
| | ~NetconfSession () |
| |
| bool | connect (const std::string &ip, int port, const std::string &user, const std::string &password) |
| | Establishes a NETCONF session with the specified device via SSH.
|
| |
| void | disconnect () |
| | Disconnects the NETCONF session.
|
| |
| bool | isConnected () const |
| | Checks if the NETCONF session is currently connected.
|
| |
| struct lyd_node * | getData (const std::string &xpath="") |
| | Retrieves data from the NETCONF server using the specified XPath filter.
|
| |
| bool | editData (const std::string &configXml) |
| | Edits the configuration data on the NETCONF server into the candidate datastore.
|
| |
| bool | commit () |
| | Commits the current configuration from the candidate datastore into the running datastore.
|
| |
| bool | subscribe (const std::string &xpath, std::function< void(struct lyd_node *)> callback) |
| | Subscribes to notifications matching the specified XPath filter and registers a callback.
|
| |
| void | startNotificationListener () |
| | Starts a background thread to listen for incoming notifications and dispatch them to registered callbacks.
|
| |
| void | stopNotificationListener () |
| | Stops the background notification listener thread and cleans up resources.
|
| |
Manages a NETCONF client session and basic datastore operations for a network device.
This class wraps the underlying NETCONF session lifecycle, including SSH-based connection setup, session teardown, and connectivity checks. It also provides helper methods for reading operational data and applying configuration changes via candidate datastore edit/commit workflows.
◆ NetconfSession()
| common::NetconfSession::NetconfSession |
( |
| ) |
|
◆ ~NetconfSession()
| common::NetconfSession::~NetconfSession |
( |
| ) |
|
◆ commit()
| bool common::NetconfSession::commit |
( |
| ) |
|
Commits the current configuration from the candidate datastore into the running datastore.
- Returns
- true if the commit operation is successful, false otherwise.
◆ connect()
| bool common::NetconfSession::connect |
( |
const std::string & |
ip, |
|
|
int |
port, |
|
|
const std::string & |
user, |
|
|
const std::string & |
password |
|
) |
| |
Establishes a NETCONF session with the specified device via SSH.
- Parameters
-
| ip | The IP address of the device e.g., "192.168.1.1". |
| port | The Netconf port of the device (standard is 830). |
| user | The username for authentication. |
| password | The password for authentication. |
- Returns
- true if the connection is successful, false otherwise.
◆ disconnect()
| void common::NetconfSession::disconnect |
( |
| ) |
|
Disconnects the NETCONF session.
◆ editData()
| bool common::NetconfSession::editData |
( |
const std::string & |
configXml | ) |
|
Edits the configuration data on the NETCONF server into the candidate datastore.
- Parameters
-
| configXml | The configuration data in XML format. |
- Returns
- true if the edit operation is successful, false otherwise.
◆ getData()
| struct lyd_node * common::NetconfSession::getData |
( |
const std::string & |
xpath = "" | ) |
|
Retrieves data from the NETCONF server using the specified XPath filter.
- Parameters
-
| xpath | The XPath filter to apply (default is empty, which retrieves all data). |
- Returns
- The retrieved data as a lyd_node pointer.
◆ isConnected()
| bool common::NetconfSession::isConnected |
( |
| ) |
const |
Checks if the NETCONF session is currently connected.
- Returns
- true if connected, false otherwise.
◆ startNotificationListener()
| void common::NetconfSession::startNotificationListener |
( |
| ) |
|
Starts a background thread to listen for incoming notifications and dispatch them to registered callbacks.
◆ stopNotificationListener()
| void common::NetconfSession::stopNotificationListener |
( |
| ) |
|
Stops the background notification listener thread and cleans up resources.
◆ subscribe()
| bool common::NetconfSession::subscribe |
( |
const std::string & |
xpath, |
|
|
std::function< void(struct lyd_node *)> |
callback |
|
) |
| |
Subscribes to notifications matching the specified XPath filter and registers a callback.
- Parameters
-
| xpath | The XPath filter for notifications to subscribe to. |
| callback | The callback function to invoke when a matching notification is received. |
- Returns
- true if the subscription is successful, false otherwise.
◆ listenerThread_
| std::thread common::NetconfSession::listenerThread_ |
|
private |
◆ listening_
| std::atomic<bool> common::NetconfSession::listening_ {false} |
|
private |
◆ session_
| struct nc_session* common::NetconfSession::session_ = nullptr |
|
private |
◆ subscriptions_
| std::map<std::string, std::function<void(struct lyd_node*)> > common::NetconfSession::subscriptions_ |
|
private |
The documentation for this class was generated from the following files: