Software TSN Switch
A software switch to connect VMs and Containers to a TSN network
Loading...
Searching...
No Matches
CncServiceImpl.h
Go to the documentation of this file.
1#pragma once
2
3#include <grpcpp/grpcpp.h>
4
5#include <atomic>
6#include <condition_variable>
7#include <memory>
8#include <shared_mutex>
9#include <string>
10#include <thread>
11
12#include "NetworkManager.h"
13#include "Topology.h"
14#include "cnc.grpc.pb.h"
15
16class CncServiceImpl final : public cnc::rpc::CncService::Service {
17 private:
19 std::unique_ptr<cnc::NetworkManager> networkManager;
20
21 // mutex to protect access to data structure for timer based ptp fetching
22 std::shared_mutex topologyMutex;
23 std::thread ptpTimerThread;
24 std::atomic<bool> stopTimer{false};
25 std::condition_variable timerCV;
26 std::mutex timerMutex;
27
28 // helper function to find a node by hostname in the topology
29 CncNode_t* FindNode(const std::string& hostName);
30
31 // helper function to map internal CncNode_t to cnc::rpc::Node protobuf message
37 void MapInterface(const ietfInterface_t& internalIface, cnc::rpc::IetfInterface* protoIface);
38
44 void MapPtpNode(const PtpNode_t& internalPtp, cnc::rpc::PtpNode* protoPtp);
45
51 void MapLldpNode(const LldpNode_t& internalLldp, cnc::rpc::LldpNode* protoLldp);
52
58 void MapPtpPort(const PtpPort_t& internalPort, cnc::rpc::PtpPort* protoPort);
59
65 void MapLldpPort(const LldpPort_t& internalPort, cnc::rpc::LldpPort* protoPort);
66
73 void ptpBackgroundTask();
74
75 public:
76 CncServiceImpl(const std::string& inventoryFilePath);
77
79
89 grpc::Status GetNetworkState(grpc::ServerContext* context, const cnc::rpc::EmptyRequest* request,
90 cnc::rpc::Topology* response) override;
91
99 grpc::Status GetAllPtpData(grpc::ServerContext* context, const cnc::rpc::EmptyRequest* request,
100 cnc::rpc::AllPtpDataResponse* response) override;
101
110 grpc::Status GetAllLldpData(grpc::ServerContext* context, const cnc::rpc::EmptyRequest* request,
111 cnc::rpc::AllLldpDataResponse* response) override;
112
122 grpc::Status GetNodePtpData(grpc::ServerContext* context, const cnc::rpc::NodeRequest* request,
123 cnc::rpc::PtpNode* response) override;
124
135 grpc::Status GetNodeLldpData(grpc::ServerContext* context, const cnc::rpc::NodeRequest* request,
136 cnc::rpc::LldpNode* response) override;
137
148 grpc::Status GetInterfacePtpData(grpc::ServerContext* context, const cnc::rpc::InterfaceRequest* request,
149 cnc::rpc::PtpPort* response) override;
150
161 grpc::Status GetInterfaceLldpData(grpc::ServerContext* context, const cnc::rpc::InterfaceRequest* request,
162 cnc::rpc::LldpPort* response) override;
163
174 grpc::Status GetInterfaceGcl(grpc::ServerContext* context, const cnc::rpc::InterfaceRequest* request,
175 cnc::rpc::GclConfig* response) override;
176
187 grpc::Status GetInterfaceAdminGcl(grpc::ServerContext* context, const cnc::rpc::InterfaceRequest* request,
188 cnc::rpc::AdminGclResponse* response) override;
189
200 grpc::Status GetInterfaceOperGcl(grpc::ServerContext* context, const cnc::rpc::InterfaceRequest* request,
201 cnc::rpc::OperGclResponse* response) override;
202
213 grpc::Status SetNodeSchedule(grpc::ServerContext* context, const cnc::rpc::SetNodeScheduleRequest* request,
214 cnc::rpc::SetNodeScheduleResponse* response);
215
226 grpc::Status SetInterfaceSchedule(grpc::ServerContext* context,
227 const cnc::rpc::SetInterfaceScheduleRequest* request,
228 cnc::rpc::IetfInterface* response);
229
239 grpc::Status GetTopologyGraph(grpc::ServerContext* context, const cnc::rpc::EmptyRequest* request,
240 cnc::rpc::TopologyGraph* response);
241};
Definition CncServiceImpl.h:16
grpc::Status GetInterfaceLldpData(grpc::ServerContext *context, const cnc::rpc::InterfaceRequest *request, cnc::rpc::LldpPort *response) override
gRPC method implementation to retrieve interface-specific LLDP data for a given interface identified ...
Definition CncServiceImpl.cpp:345
void MapLldpPort(const LldpPort_t &internalPort, cnc::rpc::LldpPort *protoPort)
Maps an internal LldpPort_t structure to a cnc::rpc::LldpPort protobuf message.
Definition CncServiceImpl.cpp:90
grpc::Status GetTopologyGraph(grpc::ServerContext *context, const cnc::rpc::EmptyRequest *request, cnc::rpc::TopologyGraph *response)
gRPC method implementation to retrieve the topology graph of the network, which includes the nodes an...
Definition CncServiceImpl.cpp:663
grpc::Status GetAllPtpData(grpc::ServerContext *context, const cnc::rpc::EmptyRequest *request, cnc::rpc::AllPtpDataResponse *response) override
gRPC method implementation to retrieve all PTP data across all nodes and interfaces in the network.
Definition CncServiceImpl.cpp:274
std::thread ptpTimerThread
Definition CncServiceImpl.h:23
grpc::Status GetInterfaceAdminGcl(grpc::ServerContext *context, const cnc::rpc::InterfaceRequest *request, cnc::rpc::AdminGclResponse *response) override
gRPC method implementation to retrieve administrative GCL (Gate Control List) data for a specific int...
Definition CncServiceImpl.cpp:405
grpc::Status GetInterfaceOperGcl(grpc::ServerContext *context, const cnc::rpc::InterfaceRequest *request, cnc::rpc::OperGclResponse *response) override
gRPC method implementation to retrieve operational GCL (Gate Control List) data for a specific interf...
Definition CncServiceImpl.cpp:443
std::atomic< bool > stopTimer
Definition CncServiceImpl.h:24
std::condition_variable timerCV
Definition CncServiceImpl.h:25
grpc::Status GetInterfacePtpData(grpc::ServerContext *context, const cnc::rpc::InterfaceRequest *request, cnc::rpc::PtpPort *response) override
gRPC method implementation to retrieve interface-specific PTP data for a given interface identified b...
Definition CncServiceImpl.cpp:328
void MapPtpNode(const PtpNode_t &internalPtp, cnc::rpc::PtpNode *protoPtp)
Maps an internal PtpNode_t structure to a cnc::rpc::PtpNode protobuf message.
Definition CncServiceImpl.cpp:207
CncNode_t * FindNode(const std::string &hostName)
Definition CncServiceImpl.cpp:76
grpc::Status SetInterfaceSchedule(grpc::ServerContext *context, const cnc::rpc::SetInterfaceScheduleRequest *request, cnc::rpc::IetfInterface *response)
gRPC method implementation to set the schedule for a specific interface identified by node hostname a...
Definition CncServiceImpl.cpp:593
~CncServiceImpl()
Definition CncServiceImpl.cpp:44
void ptpBackgroundTask()
Background task that periodically fetches PTP data for all nodes. This function runs in a separate th...
Definition CncServiceImpl.cpp:57
grpc::Status GetAllLldpData(grpc::ServerContext *context, const cnc::rpc::EmptyRequest *request, cnc::rpc::AllLldpDataResponse *response) override
gRPC method implementation to retrieve all LLDP data across all nodes and interfaces in the network.
Definition CncServiceImpl.cpp:288
grpc::Status GetNodeLldpData(grpc::ServerContext *context, const cnc::rpc::NodeRequest *request, cnc::rpc::LldpNode *response) override
gRPC method implementation to retrieve node-specific LLDP data for a given node identified by its hos...
Definition CncServiceImpl.cpp:315
grpc::Status GetNodePtpData(grpc::ServerContext *context, const cnc::rpc::NodeRequest *request, cnc::rpc::PtpNode *response) override
gRPC method implementation to retrieve node-specific PTP data for a given node identified by its host...
Definition CncServiceImpl.cpp:303
std::shared_mutex topologyMutex
Definition CncServiceImpl.h:22
std::unique_ptr< cnc::NetworkManager > networkManager
Definition CncServiceImpl.h:19
std::mutex timerMutex
Definition CncServiceImpl.h:26
void MapInterface(const ietfInterface_t &internalIface, cnc::rpc::IetfInterface *protoIface)
Maps an internal CncNode_t structure to a cnc::rpc::Node protobuf message.
Definition CncServiceImpl.cpp:104
void MapLldpNode(const LldpNode_t &internalLldp, cnc::rpc::LldpNode *protoLldp)
Maps an internal LldpNode_t structure to a cnc::rpc::LldpNode protobuf message.
Definition CncServiceImpl.cpp:230
grpc::Status SetNodeSchedule(grpc::ServerContext *context, const cnc::rpc::SetNodeScheduleRequest *request, cnc::rpc::SetNodeScheduleResponse *response)
gRPC method implementation to set schedules for all interfaces on a specific node identified by its h...
Definition CncServiceImpl.cpp:480
grpc::Status GetInterfaceGcl(grpc::ServerContext *context, const cnc::rpc::InterfaceRequest *request, cnc::rpc::GclConfig *response) override
gRPC method implementation to retrieve GCL (Gate Control List) data for a specific interface identifi...
Definition CncServiceImpl.cpp:364
grpc::Status GetNetworkState(grpc::ServerContext *context, const cnc::rpc::EmptyRequest *request, cnc::rpc::Topology *response) override
gRPC method implementation to retrieve the entire network topology, including nodes,...
Definition CncServiceImpl.cpp:245
Topology topology
Definition CncServiceImpl.h:18
void MapPtpPort(const PtpPort_t &internalPort, cnc::rpc::PtpPort *protoPort)
Maps an internal PtpPort_t structure to a cnc::rpc::PtpPort protobuf message.
Definition CncServiceImpl.cpp:82
Stores and provides lookup access to the controller's in-memory network topology.
Definition Topology.h:18
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
Represents all LLDP information of a host. Includes the local configuration and system-data and a lis...
Definition CncTypes.h:500
Struct that represents one "LLDP-port", aka one interface participating in LLDP. Contains a list of L...
Definition CncTypes.h:489
Struct that represents all the PTP information on one host we use, corresponds to one /ptp/instances/...
Definition CncTypes.h:464
Struct that represents the fields we use from the port element of the ieee1588-ptp-tt YANG model.
Definition CncTypes.h:452
Struct to hold information about an interface, inspired by the ietf-interfaces yang model.
Definition CncTypes.h:256