diff options
author | andrew-elder <aelder@audioscience.com> | 2017-05-19 08:10:04 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-19 08:10:04 -0400 |
commit | 10d0afc8ea251d8da4320abac1cc5bdb226b2680 (patch) | |
tree | a7854f5b34a56a061022bed6fbcd1a789b90d833 /daemons | |
parent | 9fea86620c00350b9873aeb5cb8186a109c55832 (diff) | |
parent | 1bc38706e7edfccfa0b7ddcbf0082ac29b22a130 (diff) | |
download | Open-AVB-10d0afc8ea251d8da4320abac1cc5bdb226b2680.tar.gz |
Merge pull request #595 from PawelModrzejewski/open-avb-next
gPTP: add negative time jumps detection
Diffstat (limited to 'daemons')
-rw-r--r-- | daemons/gptp/common/avbts_clock.hpp | 3 | ||||
-rw-r--r-- | daemons/gptp/common/ieee1588clock.cpp | 15 | ||||
-rw-r--r-- | daemons/gptp/common/ptp_message.cpp | 18 |
3 files changed, 29 insertions, 7 deletions
diff --git a/daemons/gptp/common/avbts_clock.hpp b/daemons/gptp/common/avbts_clock.hpp index 9010279e..750433da 100644 --- a/daemons/gptp/common/avbts_clock.hpp +++ b/daemons/gptp/common/avbts_clock.hpp @@ -61,6 +61,9 @@ adjustment is performed */ #define PHASE_ERROR_MAX_COUNT (6) +/* Value returned by calcMasterLocalClockRateDifference() to indicate + detection of negative time jump in follow_up message */ +#define NEGATIVE_TIME_JUMP 0.0 /** * @brief Provides the clock quality abstraction. diff --git a/daemons/gptp/common/ieee1588clock.cpp b/daemons/gptp/common/ieee1588clock.cpp index c002bd24..dbae6e16 100644 --- a/daemons/gptp/common/ieee1588clock.cpp +++ b/daemons/gptp/common/ieee1588clock.cpp @@ -322,8 +322,11 @@ FrequencyRatio IEEE1588Clock::calcMasterLocalClockRateDifference( Timestamp mast inter_sync_time = TIMESTAMP_TO_NS(sync_time) - TIMESTAMP_TO_NS(_prev_sync_time); - inter_master_time = - TIMESTAMP_TO_NS(master_time) - TIMESTAMP_TO_NS(_prev_master_time); + + uint64_t master_time_ns = TIMESTAMP_TO_NS(master_time); + uint64_t prev_master_time_ns = TIMESTAMP_TO_NS(_prev_master_time); + + inter_master_time = master_time_ns - prev_master_time_ns; if( inter_sync_time != 0 ) { ppt_offset = ((FrequencyRatio)inter_master_time)/inter_sync_time; @@ -331,6 +334,14 @@ FrequencyRatio IEEE1588Clock::calcMasterLocalClockRateDifference( Timestamp mast ppt_offset = 1.0; } + if( master_time_ns < prev_master_time_ns ) { + GPTP_LOG_ERROR("Negative time jump detected - inter_master_time: %lld, inter_sync_time: %lld, icorrect ppt_offset: %Lf", + inter_master_time, inter_sync_time, ppt_offset); + _master_local_freq_offset_init = false; + + return NEGATIVE_TIME_JUMP; + } + _prev_sync_time = sync_time; _prev_master_time = master_time; diff --git a/daemons/gptp/common/ptp_message.cpp b/daemons/gptp/common/ptp_message.cpp index b51f0bf7..0e3914fc 100644 --- a/daemons/gptp/common/ptp_message.cpp +++ b/daemons/gptp/common/ptp_message.cpp @@ -1013,6 +1013,18 @@ void PTPMessageFollowUp::processMessage( EtherPort *port ) if( correction > 0 ) TIMESTAMP_ADD_NS( preciseOriginTimestamp, correction ); else TIMESTAMP_SUB_NS( preciseOriginTimestamp, -correction ); + + local_clock_adjustment = + port->getClock()-> + calcMasterLocalClockRateDifference + ( preciseOriginTimestamp, sync_arrival ); + + if( local_clock_adjustment == NEGATIVE_TIME_JUMP ) + { + GPTP_LOG_VERBOSE("Received Follow Up but preciseOrigintimestamp indicates negative time jump"); + goto done; + } + scalar_offset = TIMESTAMP_TO_NS( sync_arrival ); scalar_offset -= TIMESTAMP_TO_NS( preciseOriginTimestamp ); @@ -1022,6 +1034,7 @@ void PTPMessageFollowUp::processMessage( EtherPort *port ) GPTP_LOG_VERBOSE ("FollowUp Scalar = %lld", scalar_offset); + /* Otherwise synchronize clock with approximate time from Sync message */ uint32_t local_clock, nominal_clock_rate; uint32_t device_sync_time_offset; @@ -1042,11 +1055,6 @@ void PTPMessageFollowUp::processMessage( EtherPort *port ) system_time.seconds_ls, system_time.nanoseconds, device_time.seconds_ls, device_time.nanoseconds); - local_clock_adjustment = - port->getClock()-> - calcMasterLocalClockRateDifference - ( preciseOriginTimestamp, sync_arrival ); - /*Update information on local status structure.*/ scaledLastGmFreqChange = (int32_t)((1.0/local_clock_adjustment -1.0) * (1ULL << 41)); scaledLastGmPhaseChange.setLSB( tlv.getRateOffset() ); |