34 #ifndef AVBTS_MESSAGE_HPP
35 #define AVBTS_MESSAGE_HPP
46 #define PTP_CODE_STRING_LENGTH 4
47 #define PTP_SUBDOMAIN_NAME_LENGTH 16
48 #define PTP_FLAGS_LENGTH 2
50 #define GPTP_VERSION 2
51 #define PTP_NETWORK_VERSION 1
54 #define PTP_DEFAULT 255
56 #define PTP_COMMON_HDR_OFFSET 0
57 #define PTP_COMMON_HDR_LENGTH 34
58 #define PTP_COMMON_HDR_TRANSSPEC_MSGTYPE(x) x
59 #define PTP_COMMON_HDR_PTP_VERSION(x) x+1
60 #define PTP_COMMON_HDR_MSG_LENGTH(x) x+2
61 #define PTP_COMMON_HDR_DOMAIN_NUMBER(x) x+4
62 #define PTP_COMMON_HDR_FLAGS(x) x+6
63 #define PTP_COMMON_HDR_CORRECTION(x) x+8
64 #define PTP_COMMON_HDR_SOURCE_CLOCK_ID(x) x+20
65 #define PTP_COMMON_HDR_SOURCE_PORT_ID(x) x+28
66 #define PTP_COMMON_HDR_SEQUENCE_ID(x) x+30
67 #define PTP_COMMON_HDR_CONTROL(x) x+32
68 #define PTP_COMMON_HDR_LOG_MSG_INTRVL(x) x+33
70 #define PTP_ANNOUNCE_OFFSET 34
71 #define PTP_ANNOUNCE_LENGTH 30
72 #define PTP_ANNOUNCE_CURRENT_UTC_OFFSET(x) x+10
73 #define PTP_ANNOUNCE_GRANDMASTER_PRIORITY1(x) x+13
74 #define PTP_ANNOUNCE_GRANDMASTER_CLOCK_QUALITY(x) x+14
75 #define PTP_ANNOUNCE_GRANDMASTER_PRIORITY2(x) x+18
76 #define PTP_ANNOUNCE_GRANDMASTER_IDENTITY(x) x+19
77 #define PTP_ANNOUNCE_STEPS_REMOVED(x) x+27
78 #define PTP_ANNOUNCE_TIME_SOURCE(x) x+29
80 #define PTP_SYNC_OFFSET 34
81 #define PTP_SYNC_LENGTH 10
82 #define PTP_SYNC_SEC_MS(x) x
83 #define PTP_SYNC_SEC_LS(x) x+2
84 #define PTP_SYNC_NSEC(x) x+6
86 #define PTP_FOLLOWUP_OFFSET 34
87 #define PTP_FOLLOWUP_LENGTH 10
88 #define PTP_FOLLOWUP_SEC_MS(x) x
89 #define PTP_FOLLOWUP_SEC_LS(x) x+2
90 #define PTP_FOLLOWUP_NSEC(x) x+6
92 #define PTP_PDELAY_REQ_OFFSET 34
93 #define PTP_PDELAY_REQ_LENGTH 20
94 #define PTP_PDELAY_REQ_SEC_MS(x) x
95 #define PTP_PDELAY_REQ_SEC_LS(x) x+2
96 #define PTP_PDELAY_REQ_NSEC(x) x+6
98 #define PTP_PDELAY_RESP_OFFSET 34
99 #define PTP_PDELAY_RESP_LENGTH 20
100 #define PTP_PDELAY_RESP_SEC_MS(x) x
101 #define PTP_PDELAY_RESP_SEC_LS(x) x+2
102 #define PTP_PDELAY_RESP_NSEC(x) x+6
103 #define PTP_PDELAY_RESP_REQ_CLOCK_ID(x) x+10
104 #define PTP_PDELAY_RESP_REQ_PORT_ID(x) x+18
106 #define PTP_PDELAY_FOLLOWUP_OFFSET 34
107 #define PTP_PDELAY_FOLLOWUP_LENGTH 20
108 #define PTP_PDELAY_FOLLOWUP_SEC_MS(x) x
109 #define PTP_PDELAY_FOLLOWUP_SEC_LS(x) x+2
110 #define PTP_PDELAY_FOLLOWUP_NSEC(x) x+6
111 #define PTP_PDELAY_FOLLOWUP_REQ_CLOCK_ID(x) x+10
112 #define PTP_PDELAY_FOLLOWUP_REQ_PORT_ID(x) x+18
114 #define PTP_LI_61_BYTE 1
115 #define PTP_LI_61_BIT 0
116 #define PTP_LI_59_BYTE 1
117 #define PTP_LI_59_BIT 1
118 #define PTP_ASSIST_BYTE 0
119 #define PTP_ASSIST_BIT 1
120 #define PTP_PTPTIMESCALE_BYTE 1
121 #define PTP_PTPTIMESCALE_BIT 3
123 #define TX_TIMEOUT_BASE 1000
124 #define TX_TIMEOUT_ITER 6
131 DELAY_REQ_MESSAGE = 1,
132 PATH_DELAY_REQ_MESSAGE = 2,
133 PATH_DELAY_RESP_MESSAGE = 3,
134 FOLLOWUP_MESSAGE = 8,
135 DELAY_RESP_MESSAGE = 9,
136 PATH_DELAY_FOLLOWUP_MESSAGE = 0xA,
137 ANNOUNCE_MESSAGE = 0xB,
138 SIGNALLING_MESSAGE = 0xC,
139 MANAGEMENT_MESSAGE = 0xD,
328 #define PATH_TRACE_TLV_TYPE 0x8
343 typedef std::list<ClockIdentity> IdentityList;
344 IdentityList identityList;
358 void parseClockIdentity(uint8_t *buffer) {
360 buffer +=
sizeof(uint16_t);
361 for(; length > 0; --length) {
364 identityList.push_back(add);
375 identityList.push_back(*
id);
383 void toByteString(uint8_t * byte_str) {
384 IdentityList::iterator iter;
385 *((uint16_t *)byte_str) = tlvType;
386 byte_str +=
sizeof(tlvType);
387 *((uint16_t *)byte_str) =
389 byte_str +=
sizeof(uint16_t);
391 (iter = identityList.begin();
392 iter != identityList.end(); ++iter) {
393 iter->getIdentityString(byte_str);
405 (identityList.begin(), identityList.end(), *id) !=
437 uint16_t currentUtcOffset;
438 unsigned char grandmasterPriority1;
439 unsigned char grandmasterPriority2;
441 uint16_t stepsRemoved;
442 unsigned char timeSource;
469 return grandmasterPriority1;
477 return grandmasterPriority2;
485 return grandmasterClockQuality;
511 ret.
set( grandmasterIdentity );
567 return originTimestamp;
608 memcpy(byte_str,
this,
sizeof(*
this));
618 uint16_t lengthField;
619 uint8_t organizationId[3];
620 uint8_t organizationSubType_ms;
621 uint16_t organizationSubType_ls;
622 int32_t cumulativeScaledRateOffset;
623 uint16_t gmTimeBaseIndicator;
625 int32_t scaledLastGmFreqChange;
633 organizationId[0] =
'\x00';
634 organizationId[1] =
'\x80';
635 organizationId[2] =
'\xC2';
636 organizationSubType_ms = 0;
648 memcpy(byte_str,
this,
sizeof(*
this));
656 return cumulativeScaledRateOffset;
698 return preciseOriginTimestamp;
707 preciseOriginTimestamp = timestamp;
756 return originTimestamp;
804 requestReceiptTimestamp = timestamp;
825 return requestReceiptTimestamp;
873 responseOriginTimestamp = timestamp;
887 return responseOriginTimestamp;
894 return requestingPortIdentity;
unsigned char domainNumber
Definition: avbts_message.hpp:182
Definition: avbts_message.hpp:619
void sendPort(IEEE1588Port *port, PortIdentity *destIdentity)
Assembles PTPMessageSync message on the IEEE1588Port payload.
void processMessage(IEEE1588Port *port)
Processes PTP messages.
Definition: avbts_message.hpp:542
void getRequestingPortIdentity(PortIdentity *identity)
Gets requesting port identity.
friend PTPMessageCommon * buildPTPMessage(char *buf, int size, LinkLayerAddress *remote, IEEE1588Port *port)
Builds a PTP message.
Definition: avbts_message.hpp:434
void setRequestingPortIdentity(PortIdentity *identity)
Sets the requesting port identity.
~PTPMessagePathDelayResp()
PortIdentity * getRequestingPortIdentity(void)
Gets the requesting port identity.
Definition: avbts_message.hpp:897
unsigned char * getFlags(void)
Gets a pointer to the flags field within the PTP message.
Definition: avbts_message.hpp:207
MessageType
Definition: avbts_message.hpp:129
virtual ~PTPMessageCommon(void)
MessageType messageType
Definition: avbts_message.hpp:171
friend PTPMessageCommon * buildPTPMessage(char *buf, int size, LinkLayerAddress *remote, IEEE1588Port *port)
Builds a PTP message.
scaledNs()
Definition: avbts_message.hpp:601
Definition: avbts_message.hpp:839
FollowUpTLV()
Definition: avbts_message.hpp:634
uint16_t messageLength
Definition: avbts_message.hpp:179
unsigned _timestamp_counter_value
Definition: avbts_message.hpp:185
long long correctionField
Definition: avbts_message.hpp:181
void buildCommonHeader(uint8_t *buf)
Builds PTP common header.
long long getCorrectionField(void)
Gets the correctionField value in a Little-Endian format.
Definition: avbts_message.hpp:241
LegacyMessageType
Definition: avbts_message.hpp:145
unsigned char versionPTP
Definition: avbts_message.hpp:169
Definition: avbts_port.hpp:76
unsigned char getGrandmasterPriority1(void)
Gets grandmaster's priority1 value.
Definition: avbts_message.hpp:472
Timestamp _timestamp
Definition: avbts_message.hpp:184
LegacyMessageType control
Definition: avbts_message.hpp:176
Definition: ieee1588.hpp:111
unsigned char flags[2]
Definition: avbts_message.hpp:177
void processMessage(IEEE1588Port *port)
Processes PTP message.
uint16_t versionNetwork
Definition: avbts_message.hpp:170
bool _gc
Definition: avbts_message.hpp:186
uint16_t getStepsRemoved(void)
Gets the steps removed value. See IEEE 802.1AS clause 10.3.3.
Definition: avbts_message.hpp:496
#define PTP_CLOCK_IDENTITY_LENGTH
Definition: ieee1588.hpp:54
Timestamp getPreciseOriginTimestamp(void)
Gets the precise origin timestamp value.
Definition: avbts_message.hpp:701
ClockQuality * getGrandmasterClockQuality(void)
Gets grandmaster clock quality.
Definition: avbts_message.hpp:488
Timestamp getTimestamp(void)
Gets the current Timestamp value from the PTP message.
Definition: avbts_message.hpp:272
MulticastType
Definition: avbts_message.hpp:157
void sendPort(IEEE1588Port *port, PortIdentity *destIdentity)
Assembles PTPMessagePathDelayResp message on the IEEE1588Port payload.
Definition: avbts_message.hpp:770
Definition: avbts_message.hpp:344
void getGrandmasterIdentity(char *identity)
Gets grandmaster identity value.
Definition: avbts_message.hpp:505
friend PTPMessageCommon * buildPTPMessage(char *buf, int size, LinkLayerAddress *remote, IEEE1588Port *port)
Builds a PTP message.
void setSequenceId(uint16_t seq)
Sets the sequence ID value to the PTP message.
Definition: avbts_message.hpp:223
MessageType getMessageType(void)
Gets the MessageType field within the PTP message.
Definition: avbts_message.hpp:231
void toByteString(uint8_t *byte_str)
Gets FollowUpTLV information in a byte string format.
Definition: avbts_message.hpp:651
void processMessage(IEEE1588Port *port)
Processes PTP messages.
~PTPMessagePathDelayRespFollowUp()
Definition: avbts_message.hpp:167
void processMessage(IEEE1588Port *port)
Processes PTP messages.
Definition: avbts_clock.hpp:58
Definition: avbts_osnet.hpp:52
Timestamp getRequestReceiptTimestamp(void)
Gets the request receipt timestamp.
Definition: avbts_message.hpp:828
void sendPort(IEEE1588Port *port, PortIdentity *destIdentity)
Assembles PTPMessagePathDelayReq message on the IEEE1588Port payload.
uint32_t getTimestampCounterValue(void)
Gets the timestamp counter value set during the RX timestamp method.
Definition: avbts_message.hpp:279
int32_t getRateOffset()
Gets the cummulative scaledRateOffset.
Definition: avbts_message.hpp:659
friend PTPMessageCommon * buildPTPMessage(char *buf, int size, LinkLayerAddress *remote, IEEE1588Port *port)
Builds a PTP message.
uint16_t getSequenceId(void)
Gets the sequenceId value within a ptp message.
Definition: avbts_message.hpp:215
void setCorrectionField(long long correctionAmount)
Sets the correction field. It expects the host format.
Definition: avbts_message.hpp:251
void toByteString(uint8_t *byte_str)
Gets scaledNs in a byte string format.
Definition: avbts_message.hpp:611
unsigned char getGrandmasterPriority2(void)
Gets grandmaster's priority2 value.
Definition: avbts_message.hpp:480
Definition: avbts_port.hpp:207
bool isBetterThan(PTPMessageAnnounce *msg)
Compare gramdmaster's capabilities comming on the announce messages against the current grandmaster c...
#define PATH_TRACE_TLV_TYPE
Definition: avbts_message.hpp:328
void setResponseOriginTimestamp(Timestamp timestamp)
Sets the response origin timestamp.
Definition: avbts_message.hpp:876
Timestamp getResponseOriginTimestamp(void)
Gets the response origin timestamp.
Definition: avbts_message.hpp:890
void getPortIdentity(PortIdentity *identity)
Gets PortIdentity field.
bool isSenderEqual(PortIdentity portIdentity)
Determine whether the message was sent by given communication technology, uuid, and port id fields...
Timestamp getOriginTimestamp(void)
Gets origin timestamp value.
Definition: avbts_message.hpp:759
PTPMessageCommon(void)
Definition: avbts_message.hpp:191
void processMessage(IEEE1588Port *port)
Processes PTP messages.
void sendPort(IEEE1588Port *port, PortIdentity *destIdentity)
Assembles PTPMessageFollowUp message on the IEEE1588Port payload.
friend PTPMessageCommon * buildPTPMessage(char *buf, int size, LinkLayerAddress *remote, IEEE1588Port *port)
Builds a PTP message.
void sendPort(IEEE1588Port *port, PortIdentity *destIdentity)
Assembles PTPMessageAnnounce message on the IEEE1588Port payload.
bool garbage()
Gets the garbage collection status.
Definition: avbts_message.hpp:295
uint16_t sequenceId
Definition: avbts_message.hpp:175
char logMeanMessageInterval
Definition: avbts_message.hpp:180
void sendPort(IEEE1588Port *port, PortIdentity *destIdentity)
Assembles PTPMessageRespFollowUp message on the IEEE1588Port payload.
PortIdentity * sourcePortIdentity
Definition: avbts_message.hpp:173
ClockIdentity getGrandmasterClockIdentity()
Gets grandmaster's clockIdentity value.
Definition: avbts_message.hpp:513
void setPortIdentity(PortIdentity *identity)
Sets PortIdentity value.
Timestamp getOriginTimestamp(void)
Gets origin timestamp value.
Definition: avbts_message.hpp:570
void setRequestingPortIdentity(PortIdentity *identity)
Sets requesting port identity.
void setPreciseOriginTimestamp(Timestamp ×tamp)
Sets the precis origin timestamp value.
Definition: avbts_message.hpp:710
Definition: avbts_message.hpp:721
Definition: avbts_message.hpp:670
friend PTPMessageCommon * buildPTPMessage(char *buf, int size, LinkLayerAddress *remote, IEEE1588Port *port)
Builds a PTP message.
void setTimestamp(Timestamp ×tamp)
Sets the timestamp value.
Definition: avbts_message.hpp:287
Definition: avbts_message.hpp:593
void setRequestReceiptTimestamp(Timestamp timestamp)
Sets the request receipt timestamp.
Definition: avbts_message.hpp:807
void processMessage(IEEE1588Port *port)
Processes PTP messages.
virtual void processMessage(IEEE1588Port *port)
Generic interface for processing PTP message.
Definition: ieee1588.hpp:222
~PTPMessagePathDelayReq()
Definition: avbts_message.hpp:732
void set(uint8_t *id)
Set the clock id to the object.
Definition: ieee1588.hpp:189
friend PTPMessageCommon * buildPTPMessage(char *buf, int size, LinkLayerAddress *remote, IEEE1588Port *port)
Builds a PTP message.