-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathmind.h
465 lines (425 loc) · 13.9 KB
/
mind.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
/*
* Excelfore gptp - Implementation of gPTP(IEEE 802.1AS)
* Copyright (C) 2019 Excelfore Corporation (https://excelfore.com)
*
* This file is part of Excelfore-gptp.
*
* Excelfore-gptp is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Excelfore-gptp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Excelfore-gptp. If not, see
* <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>.
*/
#ifndef __MIND_H_
#define __MIND_H_
#include "gptpbasetypes.h"
#define NUMBER_OF_PORTS 2
typedef struct PTPMsgAnnounce PTPMsgAnnounce;
typedef struct PTPMsgIntervalRequestTLV PTPMsgIntervalRequestTLV;
typedef struct PTPMsgGPTPCapableTLV PTPMsgGPTPCapableTLV;
typedef struct PerPortGlobal PerPortGlobal;
// 10.2 Time-synchronization state machines
// 10.2.2.1 MDSyncSend
typedef struct MDSyncSend {
uint8_t domainNumber;
ScaledNs followUpCorrectionField;
PortIdentity sourcePortIdentity;
int8_t logMessageInterval;
Timestamp preciseOriginTimestamp;
UScaledNs upstreamTxTime;
double rateRatio;
uint16_t gmTimeBaseIndicator;
ScaledNs lastGmPhaseChange;
double lastGmFreqChange;
} MDSyncSend;
// 10.2.2.2 MDSyncReceive
typedef struct MDSyncReceive {
uint8_t domainNumber;
ScaledNs followUpCorrectionField;
PortIdentity sourcePortIdentity;
int8_t logMessageInterval;
Timestamp preciseOriginTimestamp;
UScaledNs upstreamTxTime;
double rateRatio;
uint16_t gmTimeBaseIndicator;
ScaledNs lastGmPhaseChange;
double lastGmFreqChange;
uint16_t seqid;
} MDSyncReceive;
// 10.2.2.3 PortSyncSync
typedef struct PortSyncSync {
uint8_t domainNumber;
int16_t localPortNumber;
UScaledNs syncReceiptTimeoutTime;
ScaledNs followUpCorrectionField;
PortIdentity sourcePortIdentity;
int8_t logMessageInterval;
Timestamp preciseOriginTimestamp;
UScaledNs upstreamTxTime;
double rateRatio;
uint16_t gmTimeBaseIndicator;
ScaledNs lastGmPhaseChange;
double lastGmFreqChange;
// As portNumber is not the same as portIndex, we keep portIndex separately
int16_t localPortIndex;
// Next send time relative to current time
UScaledNs syncNextSendTimeoutTime;
uint16_t lastSyncSeqID;
PerPortGlobal *local_ppg; // per-port-global for the localPort
} PortSyncSync;
// 10.2.3 Per-time-aware-system global variables
typedef struct PerTimeAwareSystemGlobal {
bool BEGIN;
UScaledNs clockMasterSyncInterval;
ExtendedTimestamp clockSlaveTime;
ExtendedTimestamp syncReceiptTime;
UScaledNs syncReceiptLocalTime;
double clockSourceFreqOffset;
ScaledNs clockSourcePhaseOffset;
uint16_t clockSourceTimeBaseIndicator;
uint16_t clockSourceTimeBaseIndicatorOld;
ScaledNs clockSourceLastGmPhaseChange;
double clockSourceLastGmFreqChange;
//UScaledNs currentTime; //we use gptpclock of (clockIndex,domainNumber)
bool gmPresent;
double gmRateRatio;
uint16_t gmTimeBaseIndicator;
ScaledNs lastGmPhaseChange;
double lastGmFreqChange;
TimeInterval localClockTickInterval;
//UScaledNs localTime; //we use gptpclock of (clockIndex,domainNumber)
Enumeration2 selectedState[MAX_PORT_NUMBER_LIMIT];
//ExtendedTimestamp masterTime; //we use gptpclock of (clockIndex=0,domainNumber)
ClockIdentity thisClock;
int8_t parentLogSyncInterval;
bool instanceEnable;
uint8_t domainNumber; // domainNumber is not defined in the standard, but we need here
int thisClockIndex; // index of the gptpclock entity of 'thisClock'
int8_t clockMasterLogSyncInterval;
bool gm_stable_initdone;
bool asCapableOrAll;
uint16_t lastSyncSeqID;
ClockIdentity gmIdentity;
// Flag to determine if AVNU is followed over 802.1AS
bool conformToAvnu;
} PerTimeAwareSystemGlobal;
// 10.2.4 Per-port global variables
typedef struct PerPortGlobalForAllDomain {
bool asymmetryMeasurementMode;
double neighborRateRatio;
UScaledNs neighborPropDelay;
UScaledNs delayAsymmetry;
bool computeNeighborRateRatio;
bool computeNeighborPropDelay;
bool portOper;
bool useMgtSettableLogAnnounceInterval;
int8_t mgtSettableLogAnnounceInterval;
//14.8.25 useMgtSettableLogPdelayReqInterval
bool useMgtSettableLogPdelayReqInterval;
int8_t mgtSettableLogPdelayReqInterval;
//when PdelayReq comes in CMLDS mode(SdoId=0x200), set this
int8_t receivedNonCMLDSPdelayReq;
}PerPortGlobalForAllDomain;
struct PerPortGlobal {
bool asCapable; // for domain!=0, somebody needs to set this
uint32_t portEventFlags;
UScaledNs syncReceiptTimeoutTimeInterval;
int8_t currentLogSyncInterval;
int8_t initialLogSyncInterval;
UScaledNs syncInterval;
bool ptpPortEnabled;
uint16_t thisPort;
// As portNumber is not the same as portIndex, we keep portIndex separately
uint16_t thisPortIndex;
bool syncLocked;
bool neighborGptpCapable;
bool syncSlowdown;
UScaledNs oldAnnounceInterval;
PerPortGlobalForAllDomain *forAllDomain;
// 10.7.3.1 syncReceiptTimeout
int8_t syncReceiptTimeout;
// 10.4.1 gPtpCapableTransmit state machine needs this value
int8_t logGptpCapableMessageInterval;
// 10.7.3.3 gPtpCapableReceiptTimeout
int8_t gPtpCapableReceiptTimeout;
// 14.8.19 useMgtSettableLogSyncInterval
bool useMgtSettableLogSyncInterval;
// 14.8.20 mgtSettableLogSyncInterval
int8_t mgtSettableLogSyncInterval;
// 14.8.38 initialOneStepTxOper
bool initialOneStepTxOper;
// 14.8.39 currentOneStepTxOper
bool currentOneStepTxOper;
// 14.8.40 useMgtSettableOneStepTxOper
bool useMgtSettableOneStepTxOper;
// 14.8.41 mgtSettableOneStepTxOper
bool mgtSettableOneStepTxOper;
};
// 10.2.6 SiteSyncSync state machine
typedef struct SiteSyncSyncSM {
bool rcvdPSSync;
PortSyncSync *rcvdPSSyncPtr;
// 802.1AS-2020 10.2.7.1.3 txPSSyncPtrSSS
PortSyncSync *txPSSyncPtrSSS;
} SiteSyncSyncSM;
// 10.2.7 PortSyncSyncReceive state machine
typedef struct PortSyncSyncReceiveSM {
bool rcvdMDSync;
MDSyncReceive *rcvdMDSyncPtr;
PortSyncSync *txPSSyncPtr;
double rateRatio;
} PortSyncSyncReceiveSM;
// 10.2.8 ClockMasterSyncSend state machine
typedef struct ClockMasterSyncSendSM {
UScaledNs syncSendTime;
PortSyncSync *txPSSyncPtr;
} ClockMasterSyncSendSM;
// 10.2.9 ClockMasterSyncOffset state machine
typedef struct ClockMasterSyncOffsetSM {
bool rcvdSyncReceiptTime;
} ClockMasterSyncOffsetSM;
// 10.2.10 ClockMasterSyncReceive state machine
typedef struct ClockMasterSyncReceiveSM {
bool rcvdClockSourceReq;
// a pointer to the received ClockSourceTime.invoke function parameters.
void *rcvdClockSourceReqPtr;
bool rcvdLocalClockTick;
} ClockMasterSyncReceiveSM;
// 10.2.11 PortSyncSyncSend state machine
typedef struct PortSyncSyncSendSM {
bool rcvdPSSync;
PortSyncSync *rcvdPSSyncPtr;
Timestamp lastPreciseOriginTimestamp;
ScaledNs lastFollowUpCorrectionField;
double lastRateRatio;
UScaledNs lastUpstreamTxTime;
UScaledNs lastSyncSentTime;
uint16_t lastRcvdPortNum;
uint16_t lastGmTimeBaseIndicator;
ScaledNs lastGmPhaseChange;
double lastGmFreqChange;
MDSyncSend *txMDSyncSendPtr;
UScaledNs syncReceiptTimeoutTime;
uint8_t numberSyncTransmissions;
UScaledNs interval1;
} PortSyncSyncSendSM;
// 10.2.12 ClockSlaveSync state machine
typedef struct ClockSlaveSyncSM {
bool rcvdPSSync;
bool rcvdLocalClockTick;
PortSyncSync *rcvdPSSyncPtr;
} ClockSlaveSyncSM;
// 10.3 Best master clock selection
// 10.3.8 Per-time-aware-system global variables
typedef struct BmcsPerTimeAwareSystemGlobal {
bool reselect[MAX_PORT_NUMBER_LIMIT];
bool selected[MAX_PORT_NUMBER_LIMIT];
uint16_t masterStepsRemoved;
bool leap61;
bool leap59;
bool currentUtcOffsetValid;
bool ptpTimescale;
bool timeTraceable;
bool frequencyTraceable;
int16_t currentUtcOffset;
Enumeration8 timeSource;
bool sysLeap61;
bool sysLeap59;
bool sysCurrentUTCOffsetValid;
bool sysPtpTimescale;
bool sysTimeTraceable;
bool sysFrequencyTraceable;
int16_t sysCurrentUtcOffset;
Enumeration8 sysTimeSource;
UInteger224 systemPriority;
UInteger224 gmPriority;
UInteger224 lastGmPriority;
// Addition of pathTrace length
uint8_t pathTraceCount;
ClockIdentity pathTrace[MAX_PATH_TRACE_N];
Enumeration8 externalPortConfiguration;
uint32_t lastAnnouncePort;
int bmcsQuickUpdate;
} BmcsPerTimeAwareSystemGlobal;
// 10.3.9 Per-port global variables
typedef struct BmcsPerPortGlobal {
UScaledNs announceReceiptTimeoutTimeInterval;
bool announceSlowdown;
UScaledNs oldAnnounceInterval;
Enumeration2 infoIs;
UInteger224 masterPriority;
int8_t currentLogAnnounceInterval;
int8_t initialLogAnnounceInterval;
UScaledNs announceInterval;
uint16_t messageStepsRemoved;
bool newInfo;
UInteger224 portPriority;
uint16_t portStepsRemoved;
PTPMsgAnnounce *rcvdAnnouncePtr;
bool rcvdMsg;
bool updtInfo;
bool annLeap61;
bool annLeap59;
bool annCurrentUtcOffsetValid;
bool annPtpTimescale;
bool annTimeTraceable;
bool annFrequencyTraceable;
int16_t annCurrentUtcOffset;
Enumeration8 annTimeSource;
// ??? global pathTrace is updated only when portState is known
// to be SlavePort, in the case when system is grandmaster (no SlavePort)
// and the Announce received may convey transition of portState to SlavePort
// a copy of the announce pathSequence should be used for global pathTrace
uint8_t annPathSequenceCount;
ClockIdentity annPathSequence[MAX_PATH_TRACE_N];
// Additional from 10.7.3 Timeouts
int8_t announceReceiptTimeout;
} BmcsPerPortGlobal;
// 10.3.9.4 infoIs
typedef enum {
Received,
Mine,
Aged,
Disabled
} BmcsInfoIs;
// 10.3.11.2.1 rcvInfo
typedef enum {
RepeatedMasterInfo,
SuperiorMasterInfo,
InferiorMasterInfo,
OtherInfo
} BmcsRcvdInfo;
// 10.3.10 PortAnnounceReceive state machine
typedef struct PortAnnounceReceiveSM {
bool rcvdAnnounce;
} PortAnnounceReceiveSM;
// 10.3.11 PortAnnounceInformation state machine
typedef struct PortAnnounceInformationSM {
UScaledNs announceReceiptTimeoutTime;
UInteger224 messagePriority;
Enumeration2 rcvdInfo;
} PortAnnounceInformationSM;
// 10.3.12 PortStateSelection state machine
typedef struct PortStateSelectionSMforAllDomain {
bool asymmetryMeasurementModeChange;
} PortStateSelectionSMforAllDomain;
typedef struct PortStateSelectionSM {
bool systemIdentityChange;
PortStateSelectionSMforAllDomain *forAllDomain;
} PortStateSelectionSM;
// 10.3.13 PortAnnounceInformationExt state machine
typedef struct PortAnnounceInformationExtSM {
bool rcvdAnnounce;
UInteger224 messagePriority;
} PortAnnounceInformationExtSM;
// 10.3.14 PortStateSettingExt state machine
typedef struct PortStateSettingExtSMforAllDomain {
bool asymmetryMeasurementModeChangeThisPort;
} PortStateSettingExtSMforAllDomain;
typedef struct PortStateSettingExtSM {
bool disabledExt;
bool rcvdPortStateInd;
Enumeration2 portStateInd;
PortStateSettingExtSMforAllDomain *forAllDomain;
} PortStateSettingExtSM;
// 10.3.15 PortAnnounceTransmit state machine
typedef struct PortAnnounceTransmitSM {
UScaledNs announceSendTime;
uint8_t numberAnnounceTransmissions;
UScaledNs interval2;
} PortAnnounceTransmitSM;
// 10.3.16 AnnounceIntervalSetting state machine
typedef struct AnnounceIntervalSettingSM {
bool rcvdSignalingMsg2;
PTPMsgIntervalRequestTLV *rcvdSignalingPtr;
} AnnounceIntervalSettingSM;
// 10.4 State machines related to signaling gPTP protocol capability
// 10.4.1 gPtpCapableTransmit state machine
typedef struct gPtpCapableTransmitSM {
UScaledNs signalingMsgTimeInterval;
UScaledNs intervalTimer;
PTPMsgGPTPCapableTLV *txSignalingMsgPtr;
} gPtpCapableTransmitSM;
// 10.4.2 gPtpCapableReceive state machine
typedef struct gPtpCapableReceiveSM {
bool rcvdGptpCapableTlv;
PTPMsgGPTPCapableTLV *rcvdSignalingMsgPtr;
UScaledNs gPtpCapableReceiptTimeoutInterval;
UScaledNs timeoutTime;
} gPtpCapableReceiveSM;
// 10.6.2 Message formats - Header
typedef struct PTPMsgHeader {
Nibble majorSdoId;
Enumeration4 messageType;
UInteger4 minorVersionPTP;
UInteger4 versionPTP;
uint16_t messageLength;
uint8_t domainNumber;
uint8_t minorSdoId;
Octet2 flags;
int64_t correctionField;
Octet4 messageTypeSpecific;
PortIdentity sourcePortIdentity;
uint16_t sequenceId;
uint8_t control;
int8_t logMessageInterval;
} PTPMsgHeader;
// 10.6.3 Announce message
struct PTPMsgAnnounce {
PTPMsgHeader header;
int16_t currentUtcOffset;
uint8_t grandmasterPriority1;
ClockQuality grandmasterClockQuality;
uint8_t grandmasterPriority2;
ClockIdentity grandmasterIdentity;
uint16_t stepsRemoved;
Enumeration8 timeSource;
Enumeration16 tlvType;
uint16_t tlvLength;
ClockIdentity pathSequence[MAX_PATH_TRACE_N];
};
// 10.6.4.3 Message interval request TLV definition
struct PTPMsgIntervalRequestTLV {
Enumeration16 tlvType;
uint16_t lengthField;
Octet3 organizationId;
Enumeration24 organizationSubType;
int8_t linkDelayInterval;
int8_t timeSyncInterval;
int8_t announceInterval;
Octet flags;
};
// 10.6.4.4 gPTP capable TLV
struct PTPMsgGPTPCapableTLV {
Enumeration16 tlvType;
uint16_t lengthField;
Octet3 organizationId;
Enumeration24 organizationSubType;
int8_t logGptpCapableMessageInterval;
Octet flags;
};
// 10.6.4.3.9 flags (Octet)
#define COMPUTE_NEIGHBOR_RATE_RATIO_BIT 0
#define COMPUTE_NEIGHBOR_PROP_DELAY_BIT 1
#define ONE_STEP_RECEIVE_CAPABLE_BIT 2
void ptas_glb_init(PerTimeAwareSystemGlobal **tasglb, uint8_t domainNumber);
void ptas_glb_close(PerTimeAwareSystemGlobal **tasglb);
void pp_glb_init(PerPortGlobal **ppglb, PerPortGlobalForAllDomain *forAllDomain,
uint16_t portIndex);
void pp_glb_close(PerPortGlobal **ppglb, int domainNumber);
void bmcs_ptas_glb_init(BmcsPerTimeAwareSystemGlobal **btasglb,
PerTimeAwareSystemGlobal *ptasglb);
void bmcs_ptas_glb_update(BmcsPerTimeAwareSystemGlobal **btasglb,
PerTimeAwareSystemGlobal *ptasglb, bool primary);
void bmcs_ptas_glb_close(BmcsPerTimeAwareSystemGlobal **btasglb);
void bmcs_pp_glb_init(BmcsPerPortGlobal **bppglb);
void bmcs_pp_glb_close(BmcsPerPortGlobal **bppglb);
#endif