forked from xl4-shiro/excelfore-gptp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmdeth.h
334 lines (298 loc) · 9.82 KB
/
mdeth.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
/*
* 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 __MDETH_H_
#define __MDETH_H_
#include "mind.h"
#include "gptpnet.h"
/************************************************
data types directly point to network data
*************************************************/
typedef struct MDPortIdentity {
ClockIdentity clockIdentity;
uint16_t portNumber_ns;
} __attribute__((packed)) MDPortIdentity;
typedef struct MDClockQuality {
uint8_t clockClass;
Enumeration8 clockAccuracy;
uint16_t offsetScaledLogVariance_ns;
} __attribute__((packed)) MDClockQuality;
typedef struct MDScaledNs {
int16_t nsec_msb;
int64_t nsec_nll;
uint16_t subns_ns;
} __attribute__((packed)) MDScaledNs;
typedef struct MDUScaledNs {
uint16_t nsec_msb;
uint64_t nsec_nll;
uint16_t subns_ns;
} __attribute__((packed)) MDUScaledNs;
typedef struct MDTimestamp {
uint16_t seconds_msb_ns;
uint32_t seconds_lsb_nl;
uint32_t nanoseconds_nl;
} __attribute__((packed)) MDTimestamp;
// 11.4.2 Header
typedef struct MDPTPMsgHeader {
uint8_t majorSdoId_messageType;
uint8_t minorVersionPTP_versionPTP;
uint16_t messageLength_ns;
uint8_t domainNumber;
uint8_t minorSdoId;
uint8_t flags[2];
int64_t correctionField_nll;
uint8_t messageTypeSpecific[4];
MDPortIdentity sourcePortIdentity;
uint16_t sequenceId_ns;
uint8_t control;
int8_t logMessageInterval;
} __attribute__((packed)) MDPTPMsgHeader;
// 11.4.4.3 Follow_Up information TLV
typedef struct MDFollowUpInformationTLV {
uint16_t tlvType_ns;
uint16_t lengthField_ns;
uint8_t organizationId[3];
uint8_t organizationSubType_nb[3];
int32_t cumulativeScaledRateOffset_nl;
uint16_t gmTimeBaseIndicator_ns;
MDScaledNs lastGmPhaseChange;
int32_t scaledLastGmFreqChange_nl;
} __attribute__((packed)) MDFollowUpInformationTLV;
// 11.4.3.1 General Sync message specifications
typedef struct MDPTPMsgSync {
MDPTPMsgHeader head;
uint8_t reserved[10];
} __attribute__((packed)) MDPTPMsgSync;
typedef struct MDPTPMsgSyncOneStep {
MDPTPMsgHeader head;
MDTimestamp originTimestamp;
MDFollowUpInformationTLV FUpInfoTLV;
} __attribute__((packed)) MDPTPMsgSyncOneStep;
// 11.4.4 Follow_Up
// 11.4.4.1 General Follow_Up message specifications
typedef struct MDPTPMsgFollowUp {
MDPTPMsgHeader head;
MDTimestamp preciseOriginTimestamp;
MDFollowUpInformationTLV FUpInfoTLV;
} __attribute__((packed)) MDPTPMsgFollowUp;
// 11.4.5 Pdelay_Req message
typedef struct MDPTPMsgPdelayReq {
MDPTPMsgHeader head;
uint8_t reserved0[10];
uint8_t reserved1[10];
} __attribute__((packed)) MDPTPMsgPdelayReq;
// 11.4.6 Pdelay_Resp message
typedef struct MDPTPMsgPdelayResp {
MDPTPMsgHeader head;
MDTimestamp requestReceiptTimestamp;
MDPortIdentity requestingPortIdentity;
} __attribute__((packed)) MDPTPMsgPdelayResp;
// 11.4.7 Pdelay_Resp_Follow_Up message
typedef struct MDPTPMsgPdelayRespFollowUp {
MDPTPMsgHeader head;
MDTimestamp requestOriginTimestamp;
MDPortIdentity requestingPortIdentity;
} __attribute__((packed)) MDPTPMsgPdelayRespFollowUp;
// 10.6.3 Announce message, reformat to MD
typedef struct MDPTPMsgAnnounce {
MDPTPMsgHeader head;
uint8_t reserved0[10];
int16_t currentUtcOffset_ns;
uint8_t reserved1[1];
uint8_t grandmasterPriority1;
MDClockQuality grandmasterClockQuality;
uint8_t grandmasterPriority2;
ClockIdentity grandmasterIdentity;
uint16_t stepsRemoved_ns;
uint8_t timeSource;
uint16_t tlvType_ns;
uint16_t tlvLength_ns;
ClockIdentity pathSequence[MAX_PATH_TRACE_N];
} __attribute__((packed)) MDPTPMsgAnnounce;
// 10.6.4.3 Message interval request TLV definition, reformat to MD
typedef struct MDPTPMsgIntervalRequestTLV {
MDPTPMsgHeader head;
MDPortIdentity targetPortIdentity;
uint16_t tlvType_ns;
uint16_t lengthField_ns;
uint8_t organizationId[3];
uint8_t organizationSubType_nb[3];
int8_t linkDelayInterval;
int8_t timeSyncInterval;
int8_t announceInterval;
uint8_t flags;
uint8_t reserved[2];
} __attribute__((packed)) MDPTPMsgIntervalRequestTLV;
// 10.6.4.4 gPTP capable TLV, reformat to MD
typedef struct MDPTPMsgGPTPCapableTLV {
MDPTPMsgHeader head;
MDPortIdentity targetPortIdentity;
uint16_t tlvType_ns;
uint16_t lengthField_ns;
uint8_t organizationId[3];
uint8_t organizationSubType_nb[3];
uint8_t logGptpCapableMessageInterval;
uint8_t flags;
uint8_t reserved[4];
} __attribute__((packed)) MDPTPMsgGPTPCapableTLV;
/************************************************
data types from the 802.1AS-Rev
*************************************************/
// 11.2 State machines for MD entity specific to full-duplex, point-to-point links
// 11.2.9
typedef struct MDTimestampReceive {
UScaledNs timestamp;
} MDTimestampReceive;
// 11.2.12 MD entity global variables
// the instance is per port but only one for domains
typedef struct MDEntityGlobalForAllDomain{
int8_t currentLogPdelayReqInterval;
int8_t initialLogPdelayReqInterval;
UScaledNs pdelayReqInterval;
uint16_t allowedLostResponses;
uint16_t allowedFaults;
bool isMeasuringDelay;
UScaledNs neighborPropDelayThresh;
UScaledNs neighborPropDelayMinLimit;
bool asCapableAcrossDomains;
}MDEntityGlobalForAllDomain;
typedef struct MDEntityGlobal{
uint16_t syncSequenceId;
bool oneStepReceive;
bool oneStepTransmit;
bool oneStepTxOper;
MDEntityGlobalForAllDomain *forAllDomain;
} MDEntityGlobal;
// 11.2.13 MDSyncReceiveSM state machine
typedef struct MDSyncReceiveSM {
UScaledNs followUpReceiptTimeoutTime;
bool rcvdSync;
bool rcvdFollowUp;
MDPTPMsgSync *rcvdSyncPtr;
MDPTPMsgFollowUp *rcvdFollowUpPtr;
MDSyncReceive *txMDSyncReceivePtr;
UScaledNs upstreamSyncInterval;
} MDSyncReceiveSM;
// 11.2.14 MDSyncSendSM state machine
typedef struct MDSyncSendSM {
bool rcvdMDSync;
MDPTPMsgSync *txSyncPtr;
bool rcvdMDTimestampReceive;
MDTimestampReceive *rcvdMDTimestampReceivePtr;
MDPTPMsgFollowUp *txFollowUpPtr;
} MDSyncSendSM;
// 11.2.15 Common Mean Link Delay Service
// 11.2.16 Common Mean Link Delay Service global variables
typedef struct CMLinkDelayServiceGlobal {
bool cmldsLinkPortEnabled;
} CMLinkDelayServiceGlobal;
// 11.2.17 MDPdelayReq state machine
typedef struct MDPdelayReqSM {
UScaledNs pdelayIntervalTimer;
bool rcvdPdelayResp;
MDPTPMsgPdelayResp *rcvdPdelayRespPtr;
bool rcvdPdelayRespFollowUp;
MDPTPMsgPdelayRespFollowUp *rcvdPdelayRespFollowUpPtr;
MDPTPMsgPdelayReq *txPdelayReqPtr;
bool rcvdMDTimestampReceive;
uint16_t pdelayReqSequenceId;
bool initPdelayRespReceived;
uint16_t lostResponses;
bool neighborRateRatioValid;
uint16_t detectedFaults;
bool portEnabled0;
// AVnu requirement to cease transmit on consecutive multi-responses
uint16_t multiResponses;
} MDPdelayReqSM;
// 11.2.18 MDPdelayResp state machine
typedef struct MDPdelayRespSM {
bool rcvdPdelayReq;
bool rcvdMDTimestampReceive;
MDPTPMsgPdelayResp *txPdelayRespPtr;
MDPTPMsgPdelayRespFollowUp *txPdelayRespFollowUpPtr;
bool portEnabled1;
MDPTPMsgPdelayReq *rcvdPdelayReqPtr; // not in the standard
} MDPdelayRespSM;
// 11.2.19 SyncIntervalSetting state machine
typedef struct SyncIntervalSettingSM {
bool rcvdSignalingMsg1;
PTPMsgIntervalRequestTLV *rcvdSignalingPtr;
} SyncIntervalSettingSM;
// 11.2.20 LinkDelayIntervalSetting state machine
typedef struct LinkDelayIntervalSettingSM {
bool rcvdSignalingMsg1;
PTPMsgIntervalRequestTLV *rcvdSignalingPtr;
bool portEnabled3;
} LinkDelayIntervalSettingSM;
// 11.2.21 OneStepTxOperSetting state machine
typedef struct OneStepTxOperSettingSM {
bool rcvdSignalingMsg4;
PTPMsgIntervalRequestTLV *rcvdSignalingPtr;
} OneStepTxOperSettingSM;
// for announce state machines
typedef struct MDAnnounceSendSM {
bool rcvdTxAnnounce;
PTPMsgAnnounce *txAnnouncePtr;
} MDAnnounceSendSM;
typedef struct MDAnnounceReceiveSM {
bool rcvdRxAnnounce;
void *rxAnnouncePtr;
} MDAnnounceReceiveSM;
// 11.4 Message formats
typedef enum {
SYNC = 0,
DELAY_REQ,
PDELAY_REQ = 2,
PDELAY_RESP = 3,
RESERVED_04,
RESERVED_05,
RESERVED_06,
RESERVED_07,
FOLLOW_UP = 8,
DELAY_RESP,
PDELAY_RESP_FOLLOW_UP = 10,
ANNOUNCE,
SIGNALING,
MANAGEMENT,
RESERVED_14,
RESERVED_15,
} PTPMsgType;
/************************************************
macros
*************************************************/
#define GET_TWO_STEP_FLAG(x) ((x).flags[0] & 0x2)
#define SET_TWO_STEP_FLAG(x) ((x).flags[0] |= 0x2)
#define RESET_TWO_STEP_FLAG(x) ((x).flags[0] &= ~0x2)
/************************************************
functions
*************************************************/
void md_compose_head(PTPMsgHeader *head, MDPTPMsgHeader *phead);
void *md_header_compose(gptpnet_data_t *gptpnet, int portIndex, PTPMsgType msgtype,
uint16_t ssize, ClockIdentity thisClock, uint16_t thisPort,
uint16_t seqid, int8_t logMessageInterval);
void md_decompose_head(MDPTPMsgHeader *phead, PTPMsgHeader *head);
void md_header_template(PTPMsgHeader *head, PTPMsgType msgtype, uint16_t len,
PortIdentity *portId, uint16_t seqid, int8_t logMessageInterval);
void md_entity_glb_init(MDEntityGlobal **mdeglb, MDEntityGlobalForAllDomain *forAllDomain);
void md_entity_glb_close(MDEntityGlobal **mdeglb, int domainIndex);
void md_followup_information_tlv_compose(MDFollowUpInformationTLV *tlv,
double rateRatio, uint16_t gmTimeBaseIndicator,
ScaledNs lastGmPhaseChange, double lastGmFreqChange);
#endif