Skip to content

Commit bd6a0f0

Browse files
committed
Gptp: fixed gmRateRatio calculation (fix for omnet discussion 1128)
old gmrateRatio calculation measured the arrival time difference of last two arrived FollowUp packets instead of arrival time difference of last two Sync packets.
1 parent 964820a commit bd6a0f0

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/inet/linklayer/ieee8021as/Gptp.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,10 @@ void Gptp::processFollowUp(Packet *packet, const GptpFollowUp* gptp)
376376
void Gptp::synchronize()
377377
{
378378
simtime_t now = simTime();
379-
clocktime_t origNow = clock->getClockTime();
380-
clocktime_t residenceTime = origNow - syncIngressTimestamp;
379+
clocktime_t oldLocalTimeAtTimeSync = clock->getClockTime();
380+
clocktime_t residenceTime = oldLocalTimeAtTimeSync - syncIngressTimestamp;
381381

382-
emit(timeDifferenceSignal, CLOCKTIME_AS_SIMTIME(origNow) - now);
382+
emit(timeDifferenceSignal, CLOCKTIME_AS_SIMTIME(oldLocalTimeAtTimeSync) - now);
383383

384384
/************** Time synchronization *****************************************
385385
* Local time is adjusted using peer delay, correction field, residence time *
@@ -393,19 +393,20 @@ void Gptp::synchronize()
393393
if (oldPeerSentTimeSync == -1)
394394
gmRateRatio = 1;
395395
else
396-
gmRateRatio = (peerSentTimeSync - oldPeerSentTimeSync) / (origNow - newLocalTimeAtTimeSync) ;
396+
gmRateRatio = (peerSentTimeSync - oldPeerSentTimeSync) / (syncIngressTimestamp - receivedTimeSync);
397397

398398
auto settableClock = check_and_cast<SettableClock *>(clock.get());
399399
ppm newOscillatorCompensation = unit(gmRateRatio * (1 + unit(settableClock->getOscillatorCompensation()).get()) - 1);
400400
settableClock->setClockTime(newTime, newOscillatorCompensation, true);
401401

402-
oldLocalTimeAtTimeSync = origNow;
403402
newLocalTimeAtTimeSync = clock->getClockTime();
403+
timeDiffAtTimeSync = newLocalTimeAtTimeSync - oldLocalTimeAtTimeSync;
404404
receivedTimeSync = syncIngressTimestamp;
405405

406406
// adjust local timestamps, too
407-
pdelayRespEventIngressTimestamp += newLocalTimeAtTimeSync - oldLocalTimeAtTimeSync;
408-
pdelayReqEventEgressTimestamp += newLocalTimeAtTimeSync - oldLocalTimeAtTimeSync;
407+
adjustLocalTimestamp(pdelayRespEventIngressTimestamp);
408+
adjustLocalTimestamp(pdelayReqEventEgressTimestamp);
409+
adjustLocalTimestamp(receivedTimeSync);
409410

410411
/************** Rate ratio calculation *************************************
411412
* It is calculated based on interval between two successive Sync messages *

src/inet/linklayer/ieee8021as/Gptp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ class INET_API Gptp : public ClockUserModuleBase, public cListener
5656
clocktime_t sentTimeSyncSync;
5757

5858
/* Slave port - Variables is used for Rate Ratio. All times are drifted based on constant drift */
59-
// clocktime_t sentTimeSync;
6059
clocktime_t newLocalTimeAtTimeSync;
61-
clocktime_t oldLocalTimeAtTimeSync;
60+
clocktime_t timeDiffAtTimeSync; // new local time - old local time
6261
clocktime_t peerSentTimeSync; // sending time of last received GptpSync
6362
clocktime_t oldPeerSentTimeSync = -1; // sending time of previous received GptpSync
6463
clocktime_t syncIngressTimestamp; // receiving time of last incoming GptpSync
@@ -107,6 +106,7 @@ class INET_API Gptp : public ClockUserModuleBase, public cListener
107106

108107
clocktime_t getCalculatedDrift(IClock *clock, clocktime_t value) { return CLOCKTIME_ZERO; }
109108
void synchronize();
109+
inline void adjustLocalTimestamp(clocktime_t& time) { time += timeDiffAtTimeSync; }
110110

111111
virtual void receiveSignal(cComponent *source, simsignal_t signal, cObject *obj, cObject *details) override;
112112
};

0 commit comments

Comments
 (0)