gPTP Documentation
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
IEEE1588Port Class Reference

#include <avbts_port.hpp>

Collaboration diagram for IEEE1588Port:
Collaboration graph

Public Member Functions

bool serializeState (void *buf, long *count)
 Serializes (i.e. copy over buf pointer) the information from the variables (in that order): More...
 
bool restoreSerializedState (void *buf, long *count)
 Restores the serialized state from the buffer. Copies the information from buffer to the variables (in that order): More...
 
void becomeMaster (bool annc)
 Switches port to a gPTP master. More...
 
void becomeSlave (bool restart_syntonization)
 Switches port to a gPTP slave. More...
 
void startPDelay ()
 Starts pDelay event timer. More...
 
void startAnnounce ()
 Starts announce event timer. More...
 
void syncDone ()
 Starts pDelay event timer if not yet started. More...
 
OSTimerFactorygetTimerFactory ()
 Gets a pointer to timer_factory object. More...
 
void setAsCapable (bool ascap)
 Sets asCapable flag. More...
 
bool getAsCapable ()
 Gets the asCapable flag. More...
 
 ~IEEE1588Port ()
 
 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. More...
 
bool init_port ()
 Initializes the port. Creates network interface, initializes hardware timestamper and create OS locks conditions. More...
 
void recoverPort (void)
 Currently doesnt do anything. Just returns. More...
 
void * openPort (void)
 Receives messages from the network interface. More...
 
unsigned getPayloadOffset ()
 Get the payload offset inside a packet. More...
 
void sendEventPort (uint8_t *buf, int len, MulticastType mcast_type, PortIdentity *destIdentity)
 Sends and event to a IEEE1588 port. It includes timestamp. More...
 
void sendGeneralPort (uint8_t *buf, int len, MulticastType mcast_type, PortIdentity *destIdentity)
 Sends a general message to a port. No timestamps. More...
 
void processEvent (Event e)
 Process all events for a IEEE1588Port. More...
 
PTPMessageAnnouncecalculateERBest (void)
 Gets the "best" announce. More...
 
void addForeignMaster (PTPMessageAnnounce *msg)
 Adds a foreign master. More...
 
void removeForeignMaster (PTPMessageAnnounce *msg)
 Remove a foreign master. More...
 
void removeForeignMasterAll (void)
 Remove all foreign masters. More...
 
void addQualifiedAnnounce (PTPMessageAnnounce *msg)
 Adds a new qualified announce the port. IEEE 802.1AS Clause 10.3.10.2. More...
 
char getSyncInterval (void)
 Gets the sync interval value. More...
 
char getAnnounceInterval (void)
 Gets the announce interval. More...
 
char getPDelayInterval (void)
 Gets the pDelay minimum interval. More...
 
PortState getPortState (void)
 Gets the portState information. More...
 
void setPortState (PortState state)
 Sets the PortState. More...
 
void getPortIdentity (PortIdentity &identity)
 Gets port identity. More...
 
bool burstEnabled (void)
 Gets the burst_enabled flag. More...
 
uint16_t getNextAnnounceSequenceId (void)
 Increments announce sequence id and returns. More...
 
uint16_t getNextSyncSequenceId (void)
 Increments sync sequence ID and returns. More...
 
uint16_t getNextPDelaySequenceId (void)
 Increments PDelay sequence ID and returns. More...
 
uint16_t getParentLastSyncSequenceNumber (void)
 Gets last sync sequence number from parent. More...
 
void setParentLastSyncSequenceNumber (uint16_t num)
 Sets last sync sequence number from parent. More...
 
IEEE1588ClockgetClock (void)
 Gets a pointer to IEEE1588Clock. More...
 
void setLastSync (PTPMessageSync *msg)
 Sets last sync ptp message. More...
 
PTPMessageSyncgetLastSync (void)
 Gets last sync message. More...
 
bool getPDelayRxLock ()
 Locks PDelay RX. More...
 
bool tryPDelayRxLock ()
 Do a trylock on the PDelay RX. More...
 
bool putPDelayRxLock ()
 Unlocks PDelay RX. More...
 
bool getTxLock ()
 Locks the TX port. More...
 
bool putTxLock ()
 Unlocks the port TX. More...
 
int getTimestampVersion ()
 Gets the hardware timestamper version. More...
 
void setLastPDelayReq (PTPMessagePathDelayReq *msg)
 Sets the last_pdelay_req message. More...
 
PTPMessagePathDelayReqgetLastPDelayReq (void)
 Gets the last PTPMessagePathDelayReq message. More...
 
void setLastPDelayResp (PTPMessagePathDelayResp *msg)
 Sets the last PTPMessagePathDelayResp message. More...
 
PTPMessagePathDelayRespgetLastPDelayResp (void)
 Gets the last PTPMessagePathDelayResp message. More...
 
void setLastPDelayRespFollowUp (PTPMessagePathDelayRespFollowUp *msg)
 Sets the last PTPMessagePathDelayRespFollowUp message. More...
 
PTPMessagePathDelayRespFollowUpgetLastPDelayRespFollowUp (void)
 Gets the last PTPMessagePathDelayRespFollowUp message. More...
 
FrequencyRatio getPeerRateOffset (void)
 Gets the Peer rate offset. Used to calculate neighbor rate ratio. More...
 
void setPeerRateOffset (FrequencyRatio offset)
 Sets the peer rate offset. Used to calculate neighbor rate ratio. More...
 
void setPeerOffset (Timestamp mine, Timestamp theirs)
 Sets peer offset timestamps. More...
 
bool getPeerOffset (Timestamp &mine, Timestamp &theirs)
 Gets peer offset timestamps. More...
 
bool _adjustClockRate (FrequencyRatio freq_offset)
 Adjusts the clock frequency. More...
 
bool adjustClockRate (FrequencyRatio freq_offset)
 Adjusts the clock frequency. More...
 
void getExtendedError (char *msg)
 Gets extended error message from hardware timestamper. More...
 
int getRxTimestamp (PortIdentity *sourcePortIdentity, uint16_t sequenceId, Timestamp &timestamp, unsigned &counter_value, bool last)
 Gets RX timestamp based on port identity. More...
 
int getTxTimestamp (PortIdentity *sourcePortIdentity, uint16_t sequenceId, Timestamp &timestamp, unsigned &counter_value, bool last)
 Gets TX timestamp based on port identity. More...
 
int getTxTimestamp (PTPMessageCommon *msg, Timestamp &timestamp, unsigned &counter_value, bool last)
 Gets TX timestamp based on PTP message. More...
 
int getRxTimestamp (PTPMessageCommon *msg, Timestamp &timestamp, unsigned &counter_value, bool last)
 Gets RX timestamp based on PTP message. More...
 
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 which can be used to translate or extrapolate one clock into another clock reference. The gPTP service uses these supplied cross timestamps to perform internal rate estimation and conversion functions. More...
 
uint64_t getLinkDelay (void)
 Gets the link delay information. More...
 
void setLinkDelay (int64_t delay)
 Sets link delay information. Signed value allows this to be negative result because of inaccurate timestamps. More...
 
void recommendState (PortState state, bool changed_external_master)
 Changes the port state. More...
 
void mapSocketAddr (PortIdentity *destIdentity, LinkLayerAddress *remote)
 Maps socket addr to the remote link layer address. More...
 
void addSockAddrMap (PortIdentity *destIdentity, LinkLayerAddress *remote)
 Adds New sock addr map. More...
 
void incPdelayCount ()
 Increments Pdelay count. More...
 
unsigned getPdelayCount ()
 Gets current pdelay count value. It is set to zero when asCapable is false. More...
 
void incSyncCount ()
 Increments sync count. More...
 
unsigned getSyncCount ()
 Gets current sync count value. It is set to zero when master and incremented at each sync received for slave. More...
 

Public Attributes

bool forceSlave
 Forces port to be slave. Added for testing.
 

Detailed Description

Provides the IEEE 1588 port interface

Constructor & Destructor Documentation

IEEE1588Port::~IEEE1588Port ( )

Destroys a IEEE1588Port

IEEE1588Port::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.

Parameters
clockIEEE1588Clock instance
indexInterface index
forceSlaveForces port to be slave
accelerated_sync_countIf non-zero, then start 16ms sync timer
timestamperHardware timestamper instance
offsetInitial clock offset
net_labelNetwork label
condition_factoryOSConditionFactory instance
thread_factoryOSThreadFactory instance
timer_factoryOSTimerFactory instance
lock_factoryOSLockFactory instance

Member Function Documentation

bool IEEE1588Port::_adjustClockRate ( FrequencyRatio  freq_offset)
inline

Adjusts the clock frequency.

Parameters
freq_offsetFrequency offset
Returns
TRUE if adjusted. FALSE otherwise.
void IEEE1588Port::addForeignMaster ( PTPMessageAnnounce msg)

Adds a foreign master.

Parameters
msg[in] PTP announce message
Returns
void
Todo:
Currently not implemented
void IEEE1588Port::addQualifiedAnnounce ( PTPMessageAnnounce msg)
inline

Adds a new qualified announce the port. IEEE 802.1AS Clause 10.3.10.2.

Parameters
msgPTP announce message
Returns
void
void IEEE1588Port::addSockAddrMap ( PortIdentity destIdentity,
LinkLayerAddress remote 
)

Adds New sock addr map.

Parameters
destIdentity[in] PortIdentity remote
remote[in] remote link layer address
Returns
void
bool IEEE1588Port::adjustClockRate ( FrequencyRatio  freq_offset)
inline

Adjusts the clock frequency.

Parameters
freq_offsetFrequency offset
Returns
TRUE if adjusted. FALSE otherwise.
void IEEE1588Port::becomeMaster ( bool  annc)

Switches port to a gPTP master.

Parameters
anncIf TRUE, starts announce event timer.
Returns
void
void IEEE1588Port::becomeSlave ( bool  restart_syntonization)

Switches port to a gPTP slave.

Parameters
restart_syntonizationif TRUE, restarts the syntonization
Returns
void
bool IEEE1588Port::burstEnabled ( void  )
inline

Gets the burst_enabled flag.

Returns
burst_enabled
PTPMessageAnnounce* IEEE1588Port::calculateERBest ( void  )

Gets the "best" announce.

Returns
Pointer to PTPMessageAnnounce
char IEEE1588Port::getAnnounceInterval ( void  )
inline

Gets the announce interval.

Returns
Announce interval
bool IEEE1588Port::getAsCapable ( )
inline

Gets the asCapable flag.

Returns
asCapable flag
IEEE1588Clock* IEEE1588Port::getClock ( void  )

Gets a pointer to IEEE1588Clock.

Returns
Pointer to clock
void IEEE1588Port::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 which can be used to translate or extrapolate one clock into another clock reference. The gPTP service uses these supplied cross timestamps to perform internal rate estimation and conversion functions.

Parameters
system_time[out] System time
device_time[out] Device time
local_clock[out] Local clock
nominal_clock_rate[out] Nominal clock rate
Returns
True in case of success. FALSE in case of error
void IEEE1588Port::getExtendedError ( char *  msg)
inline

Gets extended error message from hardware timestamper.

Parameters
msg[out] Extended error message
Returns
void
PTPMessagePathDelayReq* IEEE1588Port::getLastPDelayReq ( void  )
inline

Gets the last PTPMessagePathDelayReq message.

Returns
Last pdelay request
PTPMessagePathDelayResp* IEEE1588Port::getLastPDelayResp ( void  )
inline

Gets the last PTPMessagePathDelayResp message.

Returns
Last pdelay response
PTPMessagePathDelayRespFollowUp* IEEE1588Port::getLastPDelayRespFollowUp ( void  )
inline

Gets the last PTPMessagePathDelayRespFollowUp message.

Returns
last pdelay response follow up
PTPMessageSync* IEEE1588Port::getLastSync ( void  )
inline

Gets last sync message.

Returns
PTPMessageSync last sync
uint64_t IEEE1588Port::getLinkDelay ( void  )
inline

Gets the link delay information.

Returns
one way delay if delay > 0, or zero otherwise.
uint16_t IEEE1588Port::getNextAnnounceSequenceId ( void  )
inline

Increments announce sequence id and returns.

Returns
Next announce sequence id.
uint16_t IEEE1588Port::getNextPDelaySequenceId ( void  )
inline

Increments PDelay sequence ID and returns.

Returns
Next PDelay sequence id.
uint16_t IEEE1588Port::getNextSyncSequenceId ( void  )
inline

Increments sync sequence ID and returns.

Returns
Next synce sequence id.
uint16_t IEEE1588Port::getParentLastSyncSequenceNumber ( void  )

Gets last sync sequence number from parent.

Returns
Parent last sync sequence number
Todo:
Not currently implemented.
unsigned IEEE1588Port::getPayloadOffset ( )

Get the payload offset inside a packet.

Returns
0
unsigned IEEE1588Port::getPdelayCount ( )
inline

Gets current pdelay count value. It is set to zero when asCapable is false.

Returns
pdelay count
char IEEE1588Port::getPDelayInterval ( void  )
inline

Gets the pDelay minimum interval.

Returns
PDelay interval
bool IEEE1588Port::getPDelayRxLock ( )
inline

Locks PDelay RX.

Returns
TRUE if acquired the lock. FALSE otherwise
bool IEEE1588Port::getPeerOffset ( Timestamp mine,
Timestamp theirs 
)
inline

Gets peer offset timestamps.

Parameters
mine[out] Reference to local timestamps
theirs[out] Reference to remote timestamps
Returns
TRUE if peer offset has already been initialized. FALSE otherwise.
FrequencyRatio IEEE1588Port::getPeerRateOffset ( void  )
inline

Gets the Peer rate offset. Used to calculate neighbor rate ratio.

Returns
FrequencyRatio peer rate offset
void IEEE1588Port::getPortIdentity ( PortIdentity identity)
inline

Gets port identity.

Parameters
identity[out] Reference to PortIdentity
Returns
void
PortState IEEE1588Port::getPortState ( void  )
inline

Gets the portState information.

Returns
PortState
int IEEE1588Port::getRxTimestamp ( PortIdentity sourcePortIdentity,
uint16_t  sequenceId,
Timestamp timestamp,
unsigned &  counter_value,
bool  last 
)

Gets RX timestamp based on port identity.

Parameters
sourcePortIdentity[in] Source port identity
sequenceIdSequence ID
timestamp[out] RX timestamp
counter_value[out] timestamp count value
lastIf true, removes the rx lock.
Returns
-1 error, -72 to try again. 0 Success.
int IEEE1588Port::getRxTimestamp ( PTPMessageCommon msg,
Timestamp timestamp,
unsigned &  counter_value,
bool  last 
)

Gets RX timestamp based on PTP message.

Parameters
msgPTPMessageCommon message
timestamp[out] RX timestamp
counter_value[out] timestamp count value
lastIf true, removes the RX lock
Returns
-1 error, -72 to try again. 0 Success.
unsigned IEEE1588Port::getSyncCount ( )
inline

Gets current sync count value. It is set to zero when master and incremented at each sync received for slave.

Returns
sync count
char IEEE1588Port::getSyncInterval ( void  )
inline

Gets the sync interval value.

Returns
Sync Interval
OSTimerFactory* IEEE1588Port::getTimerFactory ( )
inline

Gets a pointer to timer_factory object.

Returns
timer_factory pointer
int IEEE1588Port::getTimestampVersion ( )
inline

Gets the hardware timestamper version.

Returns
HW timestamper version
bool IEEE1588Port::getTxLock ( )
inline

Locks the TX port.

Returns
TRUE if success. FALSE otherwise.
int IEEE1588Port::getTxTimestamp ( PortIdentity sourcePortIdentity,
uint16_t  sequenceId,
Timestamp timestamp,
unsigned &  counter_value,
bool  last 
)

Gets TX timestamp based on port identity.

Parameters
sourcePortIdentity[in] Source port identity
sequenceIdSequence ID
timestamp[out] TX timestamp
counter_value[out] timestamp count value
lastIf true, removes the TX lock
Returns
-1 error, -72 to try again. 0 Success.
int IEEE1588Port::getTxTimestamp ( PTPMessageCommon msg,
Timestamp timestamp,
unsigned &  counter_value,
bool  last 
)

Gets TX timestamp based on PTP message.

Parameters
msgPTPMessageCommon message
timestamp[out] TX timestamp
counter_value[out] timestamp count value
lastIf true, removes the TX lock
Returns
-1 error, -72 to try again. 0 Success.
void IEEE1588Port::incPdelayCount ( )
inline

Increments Pdelay count.

Returns
void
void IEEE1588Port::incSyncCount ( )
inline

Increments sync count.

Returns
void
bool IEEE1588Port::init_port ( )

Initializes the port. Creates network interface, initializes hardware timestamper and create OS locks conditions.

Returns
FALSE if error during building the interface. TRUE if success
void IEEE1588Port::mapSocketAddr ( PortIdentity destIdentity,
LinkLayerAddress remote 
)

Maps socket addr to the remote link layer address.

Parameters
destIdentity[in] PortIdentity remote
remote[in] remote link layer address
Returns
void
void* IEEE1588Port::openPort ( void  )

Receives messages from the network interface.

Returns
Its an infinite loop. Returns NULL in case of error.
void IEEE1588Port::processEvent ( Event  e)

Process all events for a IEEE1588Port.

Parameters
eEvent to be processed
Returns
void
bool IEEE1588Port::putPDelayRxLock ( )
inline

Unlocks PDelay RX.

Returns
TRUE if success. FALSE otherwise
bool IEEE1588Port::putTxLock ( )
inline

Unlocks the port TX.

Returns
TRUE if success. FALSE otherwise.
void IEEE1588Port::recommendState ( PortState  state,
bool  changed_external_master 
)

Changes the port state.

Parameters
stateCurrent state
changed_external_masterTRUE if external master has changed, FALSE otherwise
Returns
void
void IEEE1588Port::recoverPort ( void  )

Currently doesnt do anything. Just returns.

Returns
void
void IEEE1588Port::removeForeignMaster ( PTPMessageAnnounce msg)

Remove a foreign master.

Parameters
msg[in] PTP announce message
Returns
void
Todo:
Currently not implemented
void IEEE1588Port::removeForeignMasterAll ( void  )

Remove all foreign masters.

Returns
void
Todo:
Currently not implemented
bool IEEE1588Port::restoreSerializedState ( void *  buf,
long *  count 
)

Restores the serialized state from the buffer. Copies the information from buffer to the variables (in that order):

  • asCapable;
  • Port State;
  • Link Delay;
  • Neighbor Rate Ratio
    Parameters
    bufBuffer containing the serialized state.
    countBuffer lenght. It is decremented by the same size of the variables that are being copied.
    Returns
    TRUE if everything was copied successfully, FALSE otherwise.
void IEEE1588Port::sendEventPort ( uint8_t *  buf,
int  len,
MulticastType  mcast_type,
PortIdentity destIdentity 
)

Sends and event to a IEEE1588 port. It includes timestamp.

Parameters
buf[in] Pointer to the data buffer
lenSize of the message
mcast_typeEnumeration MulticastType (pdlay, none or other). Depracated.
destIdentityDestination port identity
Returns
void
void IEEE1588Port::sendGeneralPort ( uint8_t *  buf,
int  len,
MulticastType  mcast_type,
PortIdentity destIdentity 
)

Sends a general message to a port. No timestamps.

Parameters
buf[in] Pointer to the data buffer
lenSize of the message
mcast_typeEnumeration MulticastType (pdelay, none or other). Depracated.
destIdentityDestination port identity
Returns
void
bool IEEE1588Port::serializeState ( void *  buf,
long *  count 
)

Serializes (i.e. copy over buf pointer) the information from the variables (in that order):

  • asCapable;
  • Port Sate;
  • Link Delay;
  • Neighbor Rate Ratio
    Parameters
    buf[out] Buffer where to put the results.
    count[inout] Length of buffer. It contains maximum length to be written when the function is called, and the value is decremented by the same amount the buf size increases.
    Returns
    TRUE if it has successfully written to buf all the values or if buf is NULL. FALSE if count should be updated with the right size.
void IEEE1588Port::setAsCapable ( bool  ascap)
inline

Sets asCapable flag.

Parameters
ascapflag to be set. If FALSE, marks peer_offset_init as false.
Returns
void
void IEEE1588Port::setLastPDelayReq ( PTPMessagePathDelayReq msg)
inline

Sets the last_pdelay_req message.

Parameters
msg[in] PTPMessagePathDelayReq message to set
Returns
void
void IEEE1588Port::setLastPDelayResp ( PTPMessagePathDelayResp msg)
inline

Sets the last PTPMessagePathDelayResp message.

Parameters
msg[in] Last pdelay response
Returns
void
void IEEE1588Port::setLastPDelayRespFollowUp ( PTPMessagePathDelayRespFollowUp msg)
inline

Sets the last PTPMessagePathDelayRespFollowUp message.

Parameters
msg[in] last pdelay response follow up
Returns
void
void IEEE1588Port::setLastSync ( PTPMessageSync msg)
inline

Sets last sync ptp message.

Parameters
msg[in] PTP sync message
Returns
void
void IEEE1588Port::setLinkDelay ( int64_t  delay)
inline

Sets link delay information. Signed value allows this to be negative result because of inaccurate timestamps.

Parameters
delayLink delay
Returns
void
void IEEE1588Port::setParentLastSyncSequenceNumber ( uint16_t  num)

Sets last sync sequence number from parent.

Parameters
numSequence number
Returns
void
Todo:
Currently not implemented.
void IEEE1588Port::setPeerOffset ( Timestamp  mine,
Timestamp  theirs 
)
inline

Sets peer offset timestamps.

Parameters
mineLocal timestamps
theirsRemote timestamps
Returns
void
void IEEE1588Port::setPeerRateOffset ( FrequencyRatio  offset)
inline

Sets the peer rate offset. Used to calculate neighbor rate ratio.

Parameters
offsetOffset to be set
Returns
void
void IEEE1588Port::setPortState ( PortState  state)
inline

Sets the PortState.

Parameters
statevalue to be set
Returns
void
void IEEE1588Port::startAnnounce ( )

Starts announce event timer.

Returns
void
void IEEE1588Port::startPDelay ( )

Starts pDelay event timer.

Returns
void
void IEEE1588Port::syncDone ( )
inline

Starts pDelay event timer if not yet started.

Returns
void
bool IEEE1588Port::tryPDelayRxLock ( )
inline

Do a trylock on the PDelay RX.

Returns
TRUE if acquired the lock. FALSE otherwise.

The documentation for this class was generated from the following file: