34 #ifndef AVBTS_PORT_HPP
35 #define AVBTS_PORT_HPP
54 #define GPTP_MULTICAST 0x0180C200000EULL
55 #define PDELAY_MULTICAST GPTP_MULTICAST
56 #define OTHER_MULTICAST GPTP_MULTICAST
58 #define PDELAY_RESP_RECEIPT_TIMEOUT_MULTIPLIER 3
59 #define SYNC_RECEIPT_TIMEOUT_MULTIPLIER 3
60 #define ANNOUNCE_RECEIPT_TIMEOUT_MULTIPLIER 3
92 this->portNumber = *portNumber;
93 this->portNumber =
PLAT_ntohs(this->portNumber);
94 this->clock_id.set(clock_id);
104 !(this->clock_id == cmp.clock_id) ||
105 this->portNumber != cmp.portNumber ?
true :
false;
115 this->clock_id == cmp.clock_id &&
116 this->portNumber == cmp.portNumber ?
true :
false;
126 this->clock_id < cmp.clock_id ?
127 true : this->clock_id == cmp.clock_id &&
128 this->portNumber < cmp.portNumber ?
true :
false;
138 this->clock_id > cmp.clock_id ?
139 true : this->clock_id == cmp.clock_id &&
140 this->portNumber > cmp.portNumber ?
true :
false;
158 this->clock_id = clock_id;
166 return this->clock_id;
175 uint16_t portNumberNO =
PLAT_htons(portNumber);
221 unsigned pdelay_count;
224 unsigned char delay_mechanism;
226 char log_mean_unicast_sync_interval;
227 char log_mean_sync_interval;
228 char log_mean_announce_interval;
229 char log_min_mean_delay_req_interval;
230 char log_min_mean_pdelay_req_interval;
232 int _accelerated_sync_count;
235 int64_t one_way_delay;
243 int32_t *rate_offset_array;
244 uint32_t rate_offset_array_size;
245 uint32_t rate_offset_count;
246 uint32_t rate_offset_index;
251 bool _peer_offset_init;
253 int32_t _initial_clock_offset;
254 int32_t _current_clock_offset;
258 uint16_t announce_sequence_id;
259 uint16_t sync_sequence_id;
261 uint16_t pdelay_sequence_id;
360 if( !pdelay_started ) {
370 return timer_factory;
379 if (ascap != asCapable) {
380 fprintf(stderr,
"AsCapable: %s\n",
381 ascap ==
true ?
"Enabled" :
"Disabled");
384 _peer_offset_init =
false;
516 if( qualified_announce != NULL )
delete qualified_announce;
517 qualified_announce = msg;
525 return log_mean_sync_interval;
533 return log_mean_announce_interval;
541 return log_min_mean_pdelay_req_interval;
567 identity = this->port_identity;
575 return burst_enabled;
583 return announce_sequence_id++;
591 return sync_sequence_id++;
599 return pdelay_sequence_id++;
645 return pdelay_rx_lock->
lock() == oslock_ok ?
true :
false;
653 return pdelay_rx_lock->
trylock() == oslock_ok ?
true :
false;
661 return pdelay_rx_lock->
unlock() == oslock_ok ?
true :
false;
669 return port_tx_lock->
lock() == oslock_ok ?
true :
false;
677 return port_tx_lock->
unlock() == oslock_ok ?
true :
false;
694 last_pdelay_req = msg;
702 return last_pdelay_req;
711 last_pdelay_resp = msg;
719 return last_pdelay_resp;
728 last_pdelay_resp_fwup = msg;
736 return last_pdelay_resp_fwup;
744 return _peer_rate_offset;
753 _peer_rate_offset = offset;
763 _peer_offset_ts_mine = mine;
764 _peer_offset_ts_theirs = theirs;
765 _peer_offset_init =
true;
775 mine = _peer_offset_ts_mine;
776 theirs = _peer_offset_ts_theirs;
777 return _peer_offset_init;
786 if( _hw_timestamper ) {
807 if (_hw_timestamper) {
824 (
PortIdentity * sourcePortIdentity, uint16_t sequenceId,
825 Timestamp & timestamp,
unsigned &counter_value,
bool last);
837 (
PortIdentity * sourcePortIdentity, uint16_t sequenceId,
838 Timestamp & timestamp,
unsigned &counter_value,
bool last);
879 uint32_t & nominal_clock_rate);
886 return one_way_delay > 0LL ? one_way_delay : 0LL;
897 one_way_delay = delay;
void addSockAddrMap(PortIdentity *destIdentity, LinkLayerAddress *remote)
Adds New sock addr map.
void mapSocketAddr(PortIdentity *destIdentity, LinkLayerAddress *remote)
Maps socket addr to the remote link layer address.
void setLastPDelayRespFollowUp(PTPMessagePathDelayRespFollowUp *msg)
Sets the last PTPMessagePathDelayRespFollowUp message.
Definition: avbts_port.hpp:727
Definition: avbts_message.hpp:542
Definition: ieee1588.hpp:101
void sendGeneralPort(uint8_t *buf, int len, MulticastType mcast_type, PortIdentity *destIdentity)
Sends a general message to a port. No timestamps.
Definition: ieee1588.hpp:445
Definition: avbts_message.hpp:434
uint16_t getNextPDelaySequenceId(void)
Increments PDelay sequence ID and returns.
Definition: avbts_port.hpp:598
bool putPDelayRxLock()
Unlocks PDelay RX.
Definition: avbts_port.hpp:660
PortIdentity(uint8_t *clock_id, uint16_t *portNumber)
Constructs PortIdentity interface.
Definition: avbts_port.hpp:91
void setLastPDelayReq(PTPMessagePathDelayReq *msg)
Sets the last_pdelay_req message.
Definition: avbts_port.hpp:693
Definition: avbts_ostimer.hpp:62
void setPeerRateOffset(FrequencyRatio offset)
Sets the peer rate offset. Used to calculate neighbor rate ratio.
Definition: avbts_port.hpp:752
bool _adjustClockRate(FrequencyRatio freq_offset)
Adjusts the clock frequency.
Definition: avbts_port.hpp:785
unsigned getPayloadOffset()
Get the payload offset inside a packet.
bool operator>(const PortIdentity &cmp) const
Implements the operator '>' overloading method. Compares clock_id and portNumber.
Definition: avbts_port.hpp:136
unsigned getSyncCount()
Gets current sync count value. It is set to zero when master and incremented at each sync received fo...
Definition: avbts_port.hpp:956
void removeForeignMasterAll(void)
Remove all foreign masters.
void getPortNumber(uint16_t *id)
Gets the port number in the host byte order, which can be either Big-Endian or Little-Endian, depending on the processor where it is running.
Definition: avbts_port.hpp:185
Definition: avbts_message.hpp:839
bool operator!=(const PortIdentity &cmp) const
Implements the operator '!=' overloading method. Compares clock_id and portNumber.
Definition: avbts_port.hpp:102
PTPMessageAnnounce * calculateERBest(void)
Gets the "best" announce.
int getVersion()
Gets the HWTimestamper version.
Definition: ieee1588.hpp:572
void * openPort(void)
Receives messages from the network interface.
void incSyncCount()
Increments sync count.
Definition: avbts_port.hpp:947
bool restoreSerializedState(void *buf, long *count)
Restores the serialized state from the buffer. Copies the information from buffer to the variables (i...
PTPMessagePathDelayReq * getLastPDelayReq(void)
Gets the last PTPMessagePathDelayReq message.
Definition: avbts_port.hpp:701
void setParentLastSyncSequenceNumber(uint16_t num)
Sets last sync sequence number from parent.
virtual void HWTimestamper_get_extderror(char *msg)
Gets a string with the error from the hardware timestamp block.
Definition: ieee1588.hpp:552
Definition: avbts_port.hpp:76
void getDeviceTime(Timestamp &system_time, Timestamp &device_time, uint32_t &local_clock, uint32_t &nominal_clock_rate)
Get the cross timestamping information. The gPTP subsystem uses these samples to calculate ratios whi...
PortIdentity()
Definition: avbts_port.hpp:84
void recoverPort(void)
Currently doesnt do anything. Just returns.
bool putTxLock()
Unlocks the port TX.
Definition: avbts_port.hpp:676
void getClockIdentityString(uint8_t *id)
Gets the ClockIdentity string.
Definition: avbts_port.hpp:148
void setPortNumber(uint16_t *id)
Sets the Port number.
Definition: avbts_port.hpp:194
Definition: avbts_clock.hpp:77
Definition: avbts_oscondition.hpp:106
void setPortState(PortState state)
Sets the PortState.
Definition: avbts_port.hpp:557
IEEE1588Port(IEEE1588Clock *clock, uint16_t index, bool forceSlave, int accelerated_sync_count, HWTimestamper *timestamper, int32_t offset, InterfaceLabel *net_label, OSConditionFactory *condition_factory, OSThreadFactory *thread_factory, OSTimerFactory *timer_factory, OSLockFactory *lock_factory)
Creates the IEEE1588Port interface.
uint16_t getNextAnnounceSequenceId(void)
Increments announce sequence id and returns.
Definition: avbts_port.hpp:582
Definition: ieee1588.hpp:111
void setLastPDelayResp(PTPMessagePathDelayResp *msg)
Sets the last PTPMessagePathDelayResp message.
Definition: avbts_port.hpp:710
void syncDone()
Starts pDelay event timer if not yet started.
Definition: avbts_port.hpp:359
Event
Definition: ieee1588.hpp:74
void becomeMaster(bool annc)
Switches port to a gPTP master.
virtual bool HWTimestamper_adjclockrate(float frequency_offset)
Adjusts the hardware clock frequency.
Definition: ieee1588.hpp:471
uint16_t getNextSyncSequenceId(void)
Increments sync sequence ID and returns.
Definition: avbts_port.hpp:590
bool operator==(const PortIdentity &cmp) const
Implements the operator '==' overloading method. Compares clock_id and portNumber.
Definition: avbts_port.hpp:113
void setAsCapable(bool ascap)
Sets asCapable flag.
Definition: avbts_port.hpp:378
IEEE1588Clock * getClock(void)
Gets a pointer to IEEE1588Clock.
MulticastType
Definition: avbts_message.hpp:157
Definition: avbts_message.hpp:770
unsigned getPdelayCount()
Gets current pdelay count value. It is set to zero when asCapable is false.
Definition: avbts_port.hpp:939
void processEvent(Event e)
Process all events for a IEEE1588Port.
PortState
Definition: ptptypes.hpp:48
PTPMessageSync * getLastSync(void)
Gets last sync message.
Definition: avbts_port.hpp:636
Definition: avbts_message.hpp:167
PTPMessagePathDelayRespFollowUp * getLastPDelayRespFollowUp(void)
Gets the last PTPMessagePathDelayRespFollowUp message.
Definition: avbts_port.hpp:735
PortState getPortState(void)
Gets the portState information.
Definition: avbts_port.hpp:548
bool operator<(const PortIdentity &cmp) const
Implements the operator '<' overloading method. Compares clock_id and portNumber.
Definition: avbts_port.hpp:124
char getSyncInterval(void)
Gets the sync interval value.
Definition: avbts_port.hpp:524
void getPortIdentity(PortIdentity &identity)
Gets port identity.
Definition: avbts_port.hpp:566
Definition: avbts_osnet.hpp:52
void addQualifiedAnnounce(PTPMessageAnnounce *msg)
Adds a new qualified announce the port. IEEE 802.1AS Clause 10.3.10.2.
Definition: avbts_port.hpp:515
bool getPDelayRxLock()
Locks PDelay RX.
Definition: avbts_port.hpp:644
PortType
Definition: avbts_port.hpp:66
void incPdelayCount()
Increments Pdelay count.
Definition: avbts_port.hpp:930
bool forceSlave
Forces port to be slave. Added for testing.
Definition: avbts_port.hpp:297
bool getTxLock()
Locks the TX port.
Definition: avbts_port.hpp:668
void removeForeignMaster(PTPMessageAnnounce *msg)
Remove a foreign master.
void addForeignMaster(PTPMessageAnnounce *msg)
Adds a foreign master.
Definition: avbts_oscondition.hpp:42
std::string getIdentityString()
Gets the identity string from the ClockIdentity object.
void startPDelay()
Starts pDelay event timer.
bool getAsCapable()
Gets the asCapable flag.
Definition: avbts_port.hpp:393
virtual OSLockResult trylock()=0
Tries locking a critical section.
int getTimestampVersion()
Gets the hardware timestamper version.
Definition: avbts_port.hpp:684
Definition: avbts_osnet.hpp:277
virtual OSLockResult unlock()=0
Unlocks a critical section.
bool burstEnabled(void)
Gets the burst_enabled flag.
Definition: avbts_port.hpp:574
Definition: avbts_port.hpp:207
bool init_port()
Initializes the port. Creates network interface, initializes hardware timestamper and create OS locks...
void getPortNumberNO(uint16_t *id)
Gets the port number following the network byte order, i.e. Big-Endian.
Definition: avbts_port.hpp:174
bool adjustClockRate(FrequencyRatio freq_offset)
Adjusts the clock frequency.
Definition: avbts_port.hpp:797
void startAnnounce()
Starts announce event timer.
FrequencyRatio getPeerRateOffset(void)
Gets the Peer rate offset. Used to calculate neighbor rate ratio.
Definition: avbts_port.hpp:743
bool getPeerOffset(Timestamp &mine, Timestamp &theirs)
Gets peer offset timestamps.
Definition: avbts_port.hpp:774
char getAnnounceInterval(void)
Gets the announce interval.
Definition: avbts_port.hpp:532
uint16_t getParentLastSyncSequenceNumber(void)
Gets last sync sequence number from parent.
std::map< PortIdentity, LinkLayerAddress > IdentityMap_t
Definition: avbts_port.hpp:202
void setClockIdentity(ClockIdentity clock_id)
Sets the ClockIdentity.
Definition: avbts_port.hpp:157
void setPeerOffset(Timestamp mine, Timestamp theirs)
Sets peer offset timestamps.
Definition: avbts_port.hpp:762
uint64_t getLinkDelay(void)
Gets the link delay information.
Definition: avbts_port.hpp:885
Definition: avbts_oslock.hpp:98
char getPDelayInterval(void)
Gets the pDelay minimum interval.
Definition: avbts_port.hpp:540
Definition: avbts_osthread.hpp:54
net_result
Definition: avbts_osnet.hpp:272
ClockIdentity getClockIdentity(void)
Gets the clockIdentity value.
Definition: avbts_port.hpp:165
OSTimerFactory * getTimerFactory()
Gets a pointer to timer_factory object.
Definition: avbts_port.hpp:369
Definition: avbts_oslock.hpp:57
bool serializeState(void *buf, long *count)
Serializes (i.e. copy over buf pointer) the information from the variables (in that order): ...
void recommendState(PortState state, bool changed_external_master)
Changes the port state.
Definition: avbts_message.hpp:721
long double FrequencyRatio
Definition: ptptypes.hpp:39
void becomeSlave(bool restart_syntonization)
Switches port to a gPTP slave.
int getTxTimestamp(PortIdentity *sourcePortIdentity, uint16_t sequenceId, Timestamp ×tamp, unsigned &counter_value, bool last)
Gets TX timestamp based on port identity.
void setLinkDelay(int64_t delay)
Sets link delay information. Signed value allows this to be negative result because of inaccurate tim...
Definition: avbts_port.hpp:896
bool tryPDelayRxLock()
Do a trylock on the PDelay RX.
Definition: avbts_port.hpp:652
virtual OSLockResult lock()=0
Locks a critical section.
void sendEventPort(uint8_t *buf, int len, MulticastType mcast_type, PortIdentity *destIdentity)
Sends and event to a IEEE1588 port. It includes timestamp.
Definition: avbts_osthread.hpp:78
void getExtendedError(char *msg)
Gets extended error message from hardware timestamper.
Definition: avbts_port.hpp:806
Definition: ieee1588.hpp:222
int getRxTimestamp(PortIdentity *sourcePortIdentity, uint16_t sequenceId, Timestamp ×tamp, unsigned &counter_value, bool last)
Gets RX timestamp based on port identity.
void setLastSync(PTPMessageSync *msg)
Sets last sync ptp message.
Definition: avbts_port.hpp:628
PTPMessagePathDelayResp * getLastPDelayResp(void)
Gets the last PTPMessagePathDelayResp message.
Definition: avbts_port.hpp:718