Software TSN Switch
A software switch to connect VMs and Containers to a TSN network
Loading...
Searching...
No Matches
NetworkManager.h
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <condition_variable>
5#include <functional>
6#include <future>
7#include <map>
8#include <memory>
9#include <mutex>
10#include <queue>
11#include <string>
12#include <thread>
13#include <vector>
14
15#include "CncTypes.h"
16#include "Inventory.h"
17#include "NetconfSession.h"
18#include "Topology.h"
19
20namespace cnc {
21
25struct NodeWorker {
26 std::shared_ptr<common::NetconfSession> opsSession;
27 std::shared_ptr<common::NetconfSession> notifSession;
28
29 std::thread workerThread;
30 std::queue<std::function<void()>> jobQueue;
31 std::mutex queueMutex;
32 std::condition_variable cv;
33 bool stop = false;
34
35 const size_t MAX_QUEUE_SIZE = 10; // Load shredder: Max 10 pending jobs per node
36};
37
46 public:
51 NetworkManager(Topology& topology);
52
57
63 bool connectAllNodes(const InventoryMap& inventory);
64
69 void fetchLldpData();
70
75 void fetchOperationGcl();
76
81 void fetchInterfaces();
82
87 void fetchPtpData();
88
92 void discoverNetwork();
93
99 bool fetchLldpDataForNode(const std::string& nodeName);
100
106 bool fetchOperationGclForNode(const std::string& nodeName);
107
113 bool fetchPtpDataForNode(const std::string& nodeName);
114
123 bool deployConfigToNode(const std::string& nodeName);
124
134 bool deployInterfaceConfig(const std::string& nodeName, const std::string& ifaceName);
135
139 void deployConfigToAll();
140
146 std::shared_ptr<common::NetconfSession> getSession(const std::string& nodeName);
147
148 private:
149 Topology& topology_; // Reference to the topology managing network nodes.
150
151 // Active NodeWorkers keyed by node hostname.
152 // Use shared_ptr to manage session lifetimes automatically. (no dangling pointers)
153 // std::map<std::string, std::shared_ptr<common::NetconfSession>> sessions_;
154 std::map<std::string, std::shared_ptr<NodeWorker>> nodeWorkers_;
155
156 bool executeOnNodeWorker(const std::string& nodeName,
157 std::function<void(std::shared_ptr<common::NetconfSession>)> task);
158
164 static std::string buildGclXml(const CncNode_t& node);
165
166 std::string buildInterfaceGclXml(const ietfInterface_t& iface);
167};
168} // namespace cnc
Stores and provides lookup access to the controller's in-memory network topology.
Definition Topology.h:18
Coordinates NETCONF-based communication and TSN configuration workflows across topology nodes.
Definition NetworkManager.h:45
std::string buildInterfaceGclXml(const ietfInterface_t &iface)
void fetchOperationGcl()
Fetches operational GCL data from all connected nodes and updates their configurations....
Definition NetworkManager.cpp:255
Topology & topology_
Definition NetworkManager.h:149
void fetchInterfaces()
Fetches interface data from all connected nodes and updates the topology. Reads interface data via /i...
Definition NetworkManager.cpp:275
void discoverNetwork()
Discovers the network topology and populating the Topology structure.
Definition NetworkManager.cpp:300
std::shared_ptr< common::NetconfSession > getSession(const std::string &nodeName)
Retrieves the Netconf session for a given node by its hostname.
Definition NetworkManager.cpp:174
void fetchPtpData()
Fetches PTP data from all connected nodes and updates the topology. Reads PTP data via /ieee1588-ptp:...
Definition NetworkManager.cpp:265
static std::string buildGclXml(const CncNode_t &node)
Builds the XML configuration for GCL based on the node's TSN parameters.
Definition NetworkManager.cpp:419
bool executeOnNodeWorker(const std::string &nodeName, std::function< void(std::shared_ptr< common::NetconfSession >)> task)
Definition NetworkManager.cpp:38
void fetchLldpData()
Fetches LLDP data from all connected nodes and updates the topology. Reads LLDP data via /ietf-lldp:l...
Definition NetworkManager.cpp:245
bool connectAllNodes(const InventoryMap &inventory)
Connects to all nodes in the topology using the provided credentials.
Definition NetworkManager.cpp:85
void deployConfigToAll()
Configures all nodes in the topology with their respective TSN parameters.
Definition NetworkManager.cpp:400
bool fetchPtpDataForNode(const std::string &nodeName)
Fetches PTP data for a specific node and updates the topology.
Definition NetworkManager.cpp:202
bool deployInterfaceConfig(const std::string &nodeName, const std::string &ifaceName)
Configures a specific interface on a node with its TSN parameters.
Definition NetworkManager.cpp:313
bool deployConfigToNode(const std::string &nodeName)
Configures specific nodes with TSN parameters.
Definition NetworkManager.cpp:340
bool fetchOperationGclForNode(const std::string &nodeName)
Fetches operational GCL data for a specific node and updates the topology.
Definition NetworkManager.cpp:221
~NetworkManager()
Destructor for NetworkManager. Disconnects all active sessions.
Definition NetworkManager.cpp:24
std::map< std::string, std::shared_ptr< NodeWorker > > nodeWorkers_
Definition NetworkManager.h:154
bool fetchLldpDataForNode(const std::string &nodeName)
Fetches LLDP data for a specific node and updates the topology.
Definition NetworkManager.cpp:183
Definition GclParser.h:10
std::map< std::string, DeviceCredentials_t > InventoryMap
Definition Inventory.h:17
This struct is used on the CNC side to represent one host with all its interfaces as well as its PTP ...
Definition CncTypes.h:512
Worker structure for managing NETCONF sessions and job queues for individual nodes.
Definition NetworkManager.h:25
std::queue< std::function< void()> > jobQueue
Definition NetworkManager.h:30
std::condition_variable cv
Definition NetworkManager.h:32
std::mutex queueMutex
Definition NetworkManager.h:31
const size_t MAX_QUEUE_SIZE
Definition NetworkManager.h:35
std::shared_ptr< common::NetconfSession > opsSession
Definition NetworkManager.h:26
std::shared_ptr< common::NetconfSession > notifSession
Definition NetworkManager.h:27
std::thread workerThread
Definition NetworkManager.h:29
bool stop
Definition NetworkManager.h:33
Struct to hold information about an interface, inspired by the ietf-interfaces yang model.
Definition CncTypes.h:256