Software TSN Switch
A software switch to connect VMs and Containers to a TSN network
Loading...
Searching...
No Matches
NetconfSession.h
Go to the documentation of this file.
1#pragma once
2
3#include <atomic>
4#include <cstdint>
5#include <functional>
6#include <map>
7#include <string>
8#include <thread>
9// Forward declarations
10// Netconf session and RPC structures
11struct nc_session;
12struct lyd_node;
13
14namespace common {
23 private:
24 // Pointer to the underlying NETCONF session
25 struct nc_session* session_ = nullptr;
26
27 std::map<std::string, std::function<void(struct lyd_node*)>> subscriptions_;
28 std::thread listenerThread_;
29 std::atomic<bool> listening_{false};
30
31 public:
32 // Constructor and Destructor
35
44 bool connect(const std::string& ip, int port, const std::string& user, const std::string& password);
45
49 void disconnect();
50
55 [[nodiscard]] [[nodiscard]] bool isConnected() const;
56
62 struct lyd_node* getData(const std::string& xpath = "");
63
69 bool editData(const std::string& configXml);
70
75 bool commit();
76
83 bool subscribe(const std::string& xpath, std::function<void(struct lyd_node*)> callback);
84
89
94};
95} // namespace common
Manages a NETCONF client session and basic datastore operations for a network device.
Definition NetconfSession.h:22
bool isConnected() const
Checks if the NETCONF session is currently connected.
Definition NetconfSession.cpp:98
void stopNotificationListener()
Stops the background notification listener thread and cleans up resources.
Definition NetconfSession.cpp:190
std::atomic< bool > listening_
Definition NetconfSession.h:29
NetconfSession()
Definition NetconfSession.cpp:38
bool editData(const std::string &configXml)
Edits the configuration data on the NETCONF server into the candidate datastore.
Definition NetconfSession.cpp:284
bool commit()
Commits the current configuration from the candidate datastore into the running datastore.
Definition NetconfSession.cpp:344
std::thread listenerThread_
Definition NetconfSession.h:28
void startNotificationListener()
Starts a background thread to listen for incoming notifications and dispatch them to registered callb...
Definition NetconfSession.cpp:151
~NetconfSession()
Definition NetconfSession.cpp:53
struct nc_session * session_
Definition NetconfSession.h:25
std::map< std::string, std::function< void(struct lyd_node *)> > subscriptions_
Definition NetconfSession.h:27
struct lyd_node * getData(const std::string &xpath="")
Retrieves data from the NETCONF server using the specified XPath filter.
Definition NetconfSession.cpp:203
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.
Definition NetconfSession.cpp:59
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.
Definition NetconfSession.cpp:102
void disconnect()
Disconnects the NETCONF session.
Definition NetconfSession.cpp:90
Definition NetconfSession.h:14