Software TSN Switch
A software switch to connect VMs and Containers to a TSN network
Loading...
Searching...
No Matches
CncTypes.h
Go to the documentation of this file.
1#pragma once
2#ifndef CNC_TYPES_H
3#define CNC_TYPES_H
4#include <array>
5#include <cstdint>
6#include <limits>
7#include <optional>
8#include <string>
9#include <vector>
10
15enum class OperStatus : uint8_t {
16 UP = 1,
17 DOWN = 2,
18 TESTING = 3,
19 UNKNOWN = 4,
20 DORMANT = 5,
21 NOT_PRESENT = 6,
23};
24
31inline const std::optional<std::string>& operStatusToYangString(OperStatus status) {
32 static const std::optional<std::string> s_up = "up";
33 static const std::optional<std::string> s_down = "down";
34 static const std::optional<std::string> s_testing = "testing";
35 static const std::optional<std::string> s_unknown = "unknown";
36 static const std::optional<std::string> s_dormant = "dormant";
37 static const std::optional<std::string> s_notPresent = "not-present";
38 static const std::optional<std::string> s_lowerDown = "lower-layer-down";
39 static const std::optional<std::string> s_none = std::nullopt;
40
41 switch (status) {
42 case OperStatus::UP:
43 return s_up;
45 return s_down;
47 return s_testing;
49 return s_unknown;
51 return s_dormant;
53 return s_notPresent;
55 return s_lowerDown;
56 default:
57 return s_none;
58 }
59}
60
65enum class IfType : uint8_t {
66 ETHERNET, // iana-if-type:ethernetCsmacd (Default)
67 BRIDGE, // iana-if-type:bridge
68 LAG, // iana-if-type:ieee8023adLag
69 LOOPBACK // iana-if-type:softwareLoopback
70};
71
79inline const std::optional<std::string>& ifTypeToIanaString(IfType type) {
80 // These are initialized once the first time the function is called
81 static const std::optional<std::string> s_ethernet = "iana-if-type:ethernetCsmacd";
82 static const std::optional<std::string> s_bridge = "iana-if-type:bridge";
83 static const std::optional<std::string> s_lag = "iana-if-type:ieee8023adLag";
84 static const std::optional<std::string> s_loopback = "iana-if-type:softwareLoopback";
85 static const std::optional<std::string> s_none = std::nullopt;
86
87 switch (type) {
89 return s_ethernet;
90 case IfType::BRIDGE:
91 return s_bridge;
92 case IfType::LAG:
93 return s_lag;
95 return s_loopback;
96 default:
97 return s_none;
98 }
99}
100
104inline constexpr uint64_t kInterfaceSpeedUnknown = std::numeric_limits<uint64_t>::max();
105
109inline constexpr uint64_t kMbpsToBps = 1000000ULL;
110
117 bool mapDataSet = false;
118 uint8_t numTrafficClasses = 1;
119
120 // IEEE 802.1Q defines priorities 0-7.
121 // Kernel supports 16, but YANG usually exposes 8.
122 std::array<uint8_t, 8> priorityMap = {0};
123};
124
130 uint32_t index;
131 uint8_t gateStatesValue; // Bitmask: 0=Closed, 1=Open (Bit 0 = TC0)
132 uint32_t timeIntervalValue; // Duration in nanoseconds
133 std::string operationName = "sched:set-gate-states"; // Default operation (maybe unnötig)
134};
135
140 uint32_t numerator;
141 uint32_t denominator; // Usually 1,000,000,000 for seconds
142};
143
147struct PtpTime_t {
148 uint64_t seconds;
149 uint32_t nanoseconds;
150};
151
157 uint32_t queueMaxSdu;
158 uint64_t transmissionOverrun; // RO
159};
160
169 // Metadata variable to be set by netlink parser, determines if it makes sense to read data relating to the
170 // operational dataset.
171 bool operDataSet = false;
172 // Metadata variable to be set by netlink parser, determines if it makes sense to read data relating to the
173 // administrative dataset.
174 bool adminDataSet = false;
175
176 std::vector<queueMaxSduEntry_t> queueMaxSduTable;
177
178 // 802.1Qbv Admin Parameters
179 bool gateEnabled = false; // Master switch for TSN
180 uint8_t adminGateStates = 255; // Initial state (255 = all open)
181
182 RationalTime_t adminCycleTime = {.numerator = 1, .denominator = 1}; // Cycle duration
183 uint32_t adminCycleTimeExtensionNs = 0; // Max extension for updates (prevent packet loss)
184
185 PtpTime_t adminBaseTime; // Start time for the schedule (ConfigChangeTime)
186
187 std::vector<GclEntry_t> adminControlList; // The actual schedule list
188
189 uint8_t operGateStates = 255; // Initial state (255 = all open)
190
191 RationalTime_t operCycleTime; // Cycle duration
192 uint32_t operCycleTimeExtensionNs = 0; // Max extension for updates (prevent packet loss)
193
194 PtpTime_t operBaseTime; // Start time for the schedule (ConfigChangeTime)
195
196 std::vector<GclEntry_t> operControlList; // The actual schedule list
197
198 bool configChange; // RW: Set true to trigger apply
199
202
203 bool configPending; // RO
204 uint64_t configChangeError; // RO: Counter
205
206 uint32_t tickGranularity = 10'000; // RO: Resolution of shaper in tenths of nanoseconds, using 1us for simplicity
207
210 int32_t clockId;
211
212 uint32_t supportedListMax = 31;
213 uint32_t supportedIntervalMax = 1e9;
214
217};
218
224 bool hasNeighbor = false;
225 std::string chassisId;
226 std::string portId;
227 std::string systemName;
228 uint32_t ttl;
229 std::string managementIp;
231 std::string systemDescription;
234 std::string addressSubtype;
235 std::string address;
236};
237
248
258 std::string name;
259
262
263 // --- IETF Interfaces Data ---
264 IfType type = IfType::ETHERNET; // Will be mapped to "iana-if-type:ethernetCsmacd", "iana-if-type:bridge", etc.
265 bool adminEnabled = false; // Derived from IFF_UP
266 OperStatus operStatus = OperStatus::UNKNOWN; // Derived from IFLA_OPERSTATE
267
268 bool hasPhysAddr = false;
269 std::array<uint8_t, 6> physAddress = {0}; // Derived from IFLA_ADDRESS
270
271 uint32_t mtu = 0; // Derived from IFLA_MTU
272
273 // --- Capabilities / Logic ---
274 uint32_t numTxQueues = 1; // Derived from IFLA_NUM_TX_QUEUES, contains the maximum supported number of queues
275 uint32_t numActiveTxQueues = 1; // Derived via ethtools, contains the number of active queues
276 uint64_t speed = kInterfaceSpeedUnknown; // ietf-interfaces speed in bits/second, unknown => leaf omitted
277
279};
280
291
298inline const std::optional<std::string>& ptpInstanceTypeToEnum(PtpInstanceType_t type) {
299 // These are initialized once the first time the function is called
300 static const std::optional<std::string> s_oc = "oc";
301 static const std::optional<std::string> s_bc = "bc";
302 static const std::optional<std::string> s_p2p_tc = "p2p-tc";
303 static const std::optional<std::string> s_e2e_tc = "e2e-tc";
304 static const std::optional<std::string> s_none = std::nullopt;
305
306 switch (type) {
308 return s_oc;
310 return s_bc;
312 return s_p2p_tc;
314 return s_e2e_tc;
315 default:
316 return s_none;
317 }
318}
319
323enum class PtpPortState_t : uint8_t {
324 INITIALIZING = 1,
325 FAULTY,
326 DISABLED,
327 LISTENING,
330 PASSIVE,
333};
334
340inline const std::optional<std::string>& portStateToString(PtpPortState_t state) {
341 // Initialized once on first call
342 static const std::optional<std::string> s_initializing = "initializing";
343 static const std::optional<std::string> s_faulty = "faulty";
344 static const std::optional<std::string> s_disabled = "disabled";
345 static const std::optional<std::string> s_listening = "listening";
346 static const std::optional<std::string> s_pre_time_transmitter = "pre-time-transmitter";
347 static const std::optional<std::string> s_time_transmitter = "time-transmitter";
348 static const std::optional<std::string> s_passive = "passive";
349 static const std::optional<std::string> s_uncalibrated = "uncalibrated";
350 static const std::optional<std::string> s_time_receiver = "time-receiver";
351 static const std::optional<std::string> s_none = std::nullopt;
352
353 switch (state) {
355 return s_initializing;
357 return s_faulty;
359 return s_disabled;
361 return s_listening;
363 return s_pre_time_transmitter;
365 return s_time_transmitter;
367 return s_passive;
369 return s_uncalibrated;
371 return s_time_receiver;
372 default:
373 return s_none;
374 }
375}
376
381 int64_t avg;
382 int64_t min;
383 int64_t max;
384 int64_t stddev;
385};
386
400
409
420
429
438
448
452struct PtpPort_t {
453 uint16_t portIndex;
456 std::vector<PtpPortPerformanceRecord_t> portPerformanceRecords15m;
457 std::vector<PtpPortPerformanceRecord_t> portPerformanceRecords24h;
458};
459
464struct PtpNode_t {
468 std::vector<PtpPerformanceRecord_t> performanceRecords15m;
469 std::vector<PtpPerformanceRecord_t> performanceRecords24h;
470 std::vector<PtpPort_t> ports;
471};
472
484
490 std::string name;
491 std::string destMacAddress;
492 std::string adminStatus;
493 std::vector<LldpNeighbor_t> neighbors; // TODO: Needs to be implemented
494};
495
507
512struct CncNode_t {
513 uint32_t id;
514 std::string hostName;
515 std::vector<ietfInterface_t> interfaces;
516 std::string ipAddress;
519};
520#endif
constexpr uint64_t kMbpsToBps
Conversion factor from megabits per second to bits per second.
Definition CncTypes.h:109
const std::optional< std::string > & operStatusToYangString(OperStatus status)
Helper method that maps internal OperStatus to YANG enumeration labels.
Definition CncTypes.h:31
const std::optional< std::string > & ptpInstanceTypeToEnum(PtpInstanceType_t type)
Helper method to convert an PtpInstanceType_t to a string that is valid in the YANG model.
Definition CncTypes.h:298
const std::optional< std::string > & ifTypeToIanaString(IfType type)
Helper method to convert an IfType to a string accepted by a field of type iana-interface-type in a Y...
Definition CncTypes.h:79
OperStatus
Enum that represents the operational status of an interface, as given by the IFLA_OPERSTATE netlink a...
Definition CncTypes.h:15
constexpr uint64_t kInterfaceSpeedUnknown
Constant that represents an unknown interface speed, used as a sentinel value.
Definition CncTypes.h:104
PtpPortState_t
Enum that defines which state a port is in. For gPTP only some of them are used.
Definition CncTypes.h:323
const std::optional< std::string > & portStateToString(PtpPortState_t state)
Helper method to convert an PtpPortState_t to a string that is valid in the YANG model.
Definition CncTypes.h:340
PtpInstanceType_t
Enum that represents the type of a PTP instance, for gPTP either Ordinary Clock or Boundary Clock.
Definition CncTypes.h:284
IfType
Enum that represents the iana-if-type of an interface, interpreted from the IFLA_INFO_KIND netlink at...
Definition CncTypes.h:65
Struct to hold information about and interfaces bridge-port, as defined by the ieee802-dot1q-bridge y...
Definition CncTypes.h:242
GclConfig_t gateParameterTable
Definition CncTypes.h:246
std::string bridgeName
Definition CncTypes.h:243
TrafficClassData_t trafficClassData
Definition CncTypes.h:245
int masterIndex
Definition CncTypes.h:244
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
std::string hostName
Definition CncTypes.h:514
uint32_t id
Definition CncTypes.h:513
PtpNode_t ptpAllData
Definition CncTypes.h:517
std::vector< ietfInterface_t > interfaces
Definition CncTypes.h:515
LldpNode_t lldpAllData
Definition CncTypes.h:518
std::string ipAddress
Definition CncTypes.h:516
Struct that represents the fields we use from the "Current data set" of the ieee1588-ptp-tt YANG mode...
Definition CncTypes.h:424
uint16_t stepsRemoved
Definition CncTypes.h:425
int64_t offsetFromTimeTransmitter
Definition CncTypes.h:426
int64_t meanDelay
Definition CncTypes.h:427
Struct that represents the fields we use from the "Default data set" of the ieee1588-ptp-tt YANG mode...
Definition CncTypes.h:413
PtpInstanceType_t instanceType
Definition CncTypes.h:418
uint16_t numPorts
Definition CncTypes.h:414
uint8_t priority1
Definition CncTypes.h:415
std::string clockIdentity
Definition CncTypes.h:416
PtpTime_t currentTime
Definition CncTypes.h:417
Struct to hold information about the gate-parameter-table of an interface, according to the ieee802-d...
Definition CncTypes.h:168
uint32_t supportedCycleMaxNumerator
Definition CncTypes.h:215
uint64_t configChangeError
Definition CncTypes.h:204
RationalTime_t operCycleTime
Definition CncTypes.h:191
bool gateEnabled
Definition CncTypes.h:179
std::vector< queueMaxSduEntry_t > queueMaxSduTable
Definition CncTypes.h:176
uint64_t currentTimeSeconds
Definition CncTypes.h:208
std::vector< GclEntry_t > adminControlList
Definition CncTypes.h:187
uint32_t tickGranularity
Definition CncTypes.h:206
bool configChange
Definition CncTypes.h:198
uint64_t configChangeTimeSeconds
Definition CncTypes.h:200
uint32_t supportedListMax
Definition CncTypes.h:212
uint32_t currentTimeNanoseconds
Definition CncTypes.h:209
PtpTime_t adminBaseTime
Definition CncTypes.h:185
uint32_t configChangeTimeNanoseconds
Definition CncTypes.h:201
uint32_t supportedIntervalMax
Definition CncTypes.h:213
uint8_t adminGateStates
Definition CncTypes.h:180
bool operDataSet
Definition CncTypes.h:171
uint8_t operGateStates
Definition CncTypes.h:189
uint32_t operCycleTimeExtensionNs
Definition CncTypes.h:192
PtpTime_t operBaseTime
Definition CncTypes.h:194
bool configPending
Definition CncTypes.h:203
uint32_t supportedCycleMaxDenominator
Definition CncTypes.h:216
uint32_t adminCycleTimeExtensionNs
Definition CncTypes.h:183
std::vector< GclEntry_t > operControlList
Definition CncTypes.h:196
bool adminDataSet
Definition CncTypes.h:174
RationalTime_t adminCycleTime
Definition CncTypes.h:182
int32_t clockId
Definition CncTypes.h:210
Struct to represent a single gate-control-entry in a base-gate-control-entries grouping (aka the admi...
Definition CncTypes.h:129
uint32_t timeIntervalValue
Definition CncTypes.h:132
uint8_t gateStatesValue
Definition CncTypes.h:131
std::string operationName
Definition CncTypes.h:133
uint32_t index
Definition CncTypes.h:130
Struct that represents the information about the local system, as available to the LLDP agent.
Definition CncTypes.h:476
std::string systemName
Definition CncTypes.h:479
std::string systemCapabilitiesSupported
Definition CncTypes.h:481
std::string chassisIdSubtype
Definition CncTypes.h:477
std::string systemCapabilitiesEnabled
Definition CncTypes.h:482
std::string chassisId
Definition CncTypes.h:478
std::string systemDescription
Definition CncTypes.h:480
Struct that represents the basic information about a system connected to an LLDP-port on a host....
Definition CncTypes.h:223
bool hasNeighbor
Definition CncTypes.h:224
std::string portId
Definition CncTypes.h:226
std::string chassisId
Definition CncTypes.h:225
std::string systemDescription
Definition CncTypes.h:231
std::string address
Definition CncTypes.h:235
uint32_t ttl
Definition CncTypes.h:228
std::string systemCapabilitiesSupported
Definition CncTypes.h:232
std::string systemName
Definition CncTypes.h:227
std::string chassisIdIdSubtype
Definition CncTypes.h:230
std::string addressSubtype
Definition CncTypes.h:234
std::string systemCapabilitiesEnabled
Definition CncTypes.h:233
std::string managementIp
Definition CncTypes.h:229
Represents all LLDP information of a host. Includes the local configuration and system-data and a lis...
Definition CncTypes.h:500
uint32_t messageTxHoldMultiplier
Definition CncTypes.h:502
uint32_t messageTxInterval
Definition CncTypes.h:501
LldpLocalSystemData_t localSystemData
Definition CncTypes.h:504
uint32_t messageFastTx
Definition CncTypes.h:503
std::vector< LldpPort_t > ports
Definition CncTypes.h:505
Struct that represents one "LLDP-port", aka one interface participating in LLDP. Contains a list of L...
Definition CncTypes.h:489
std::string adminStatus
Definition CncTypes.h:492
std::string name
Definition CncTypes.h:490
std::vector< LldpNeighbor_t > neighbors
Definition CncTypes.h:493
std::string destMacAddress
Definition CncTypes.h:491
Struct that represents the fields we use from the "Parent data set" of the ieee1588-ptp-tt YANG model...
Definition CncTypes.h:433
uint16_t parentPortNumber
Definition CncTypes.h:435
std::string parentClockIdentity
Definition CncTypes.h:434
std::string grandParentClockIdentity
Definition CncTypes.h:436
Struct that represents the fields we use from the "Port data set" of the ieee1588-ptp-tt YANG model.
Definition CncTypes.h:442
PtpPortState_t portState
Definition CncTypes.h:445
int64_t meanLinkDelay
Definition CncTypes.h:446
std::string portClockIdentity
Definition CncTypes.h:443
uint16_t portPortNumber
Definition CncTypes.h:444
Struct that represents all the PTP information on one host we use, corresponds to one /ptp/instances/...
Definition CncTypes.h:464
std::vector< PtpPort_t > ports
Definition CncTypes.h:470
ParentDs_t parentDs
Definition CncTypes.h:467
std::vector< PtpPerformanceRecord_t > performanceRecords24h
Definition CncTypes.h:469
DefaultDs_t defaultDs
Definition CncTypes.h:465
CurrentDs_t currentDs
Definition CncTypes.h:466
std::vector< PtpPerformanceRecord_t > performanceRecords15m
Definition CncTypes.h:468
Struct that represents the 4 values for a statistic: Mean, Max, Min, and StdDev.
Definition CncTypes.h:380
int64_t avg
Definition CncTypes.h:381
int64_t stddev
Definition CncTypes.h:384
int64_t max
Definition CncTypes.h:383
int64_t min
Definition CncTypes.h:382
Struct that represents the statistics of the PTP performance metrics (specifically the offset from th...
Definition CncTypes.h:393
PtpPerformanceParameters_t meanPathDelay
Definition CncTypes.h:398
bool periodComplete
Definition CncTypes.h:394
PtpPerformanceParameters_t offsetFromTimeTransmitter
Definition CncTypes.h:397
uint32_t pmTime
Definition CncTypes.h:395
bool measurementValid
Definition CncTypes.h:396
Struct that represents the statistics of the PTP performance metrics of a single port,...
Definition CncTypes.h:405
uint32_t pmTime
Definition CncTypes.h:406
PtpPerformanceParameters_t meanLinkDelay
Definition CncTypes.h:407
Struct that represents the fields we use from the port element of the ieee1588-ptp-tt YANG model.
Definition CncTypes.h:452
PortDs_t portDs
Definition CncTypes.h:455
std::string underlyingInterface
Definition CncTypes.h:454
std::vector< PtpPortPerformanceRecord_t > portPerformanceRecords24h
Definition CncTypes.h:457
std::vector< PtpPortPerformanceRecord_t > portPerformanceRecords15m
Definition CncTypes.h:456
uint16_t portIndex
Definition CncTypes.h:453
Struct to represent an ieee802:ptp-time-grouping.
Definition CncTypes.h:147
uint32_t nanoseconds
Definition CncTypes.h:149
uint64_t seconds
Definition CncTypes.h:148
Struct to represent an ieee802:rational-grouping.
Definition CncTypes.h:139
uint32_t numerator
Definition CncTypes.h:140
uint32_t denominator
Definition CncTypes.h:141
Struct to represent the traffic-class/traffic-class-table container of the ieee802-dot1q-bridge model...
Definition CncTypes.h:116
std::array< uint8_t, 8 > priorityMap
Definition CncTypes.h:122
uint8_t numTrafficClasses
Definition CncTypes.h:118
bool mapDataSet
Definition CncTypes.h:117
Struct to hold information about an interface, inspired by the ietf-interfaces yang model.
Definition CncTypes.h:256
std::array< uint8_t, 6 > physAddress
Definition CncTypes.h:269
uint32_t numActiveTxQueues
Definition CncTypes.h:275
std::string name
Definition CncTypes.h:258
uint32_t numTxQueues
Definition CncTypes.h:274
bool hasPhysAddr
Definition CncTypes.h:268
uint32_t mtu
Definition CncTypes.h:271
bool adminEnabled
Definition CncTypes.h:265
OperStatus operStatus
Definition CncTypes.h:266
IfType type
Definition CncTypes.h:264
uint32_t lastQdiscUpdateId
Definition CncTypes.h:261
uint32_t lastLinkUpdateId
Definition CncTypes.h:260
BridgePort_t bridgePort
Definition CncTypes.h:278
uint64_t speed
Definition CncTypes.h:276
int ifindex
Definition CncTypes.h:257
Struct to represent a single entry of the queue-max-sdu-table list of the ieee802-dot1q-sched model.
Definition CncTypes.h:155
uint32_t queueMaxSdu
Definition CncTypes.h:157
uint8_t trafficClass
Definition CncTypes.h:156
uint64_t transmissionOverrun
Definition CncTypes.h:158