From bd001fdec784fc4aa8f36a773f4e75e634cbc6ba Mon Sep 17 00:00:00 2001 From: Delio Brignoli Date: Fri, 21 Feb 2014 10:40:54 +0100 Subject: [PATCH] port: adjust peer delay calculation using neighborRateRatio Previouly the peer delay was not taking into account the frequency offset between the local clock and the peer's clock. Reset neighborRateRatio to 1.0 in port_nrate_initialize(). Signed-off-by: Delio Brignoli --- port.c | 5 ++++- tmv.h | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/port.c b/port.c index 523970e..7e7b2c1 100644 --- a/port.c +++ b/port.c @@ -855,6 +855,7 @@ static void port_nrate_initialize(struct port *p) p->nrate.ingress1 = tmv_zero(); p->nrate.max_count = (1 << shift); p->nrate.count = 0; + p->nrate.ratio = 1.0; p->nrate.ratio_valid = 0; } @@ -1739,6 +1740,7 @@ static void port_peer_delay(struct port *p) struct ptp_message *req = p->peer_delay_req; struct ptp_message *rsp = p->peer_delay_resp; struct ptp_message *fup = p->peer_delay_fup; + double adj_t41; /* Check for response, validate port and sequence number. */ @@ -1782,7 +1784,8 @@ static void port_peer_delay(struct port *p) t3 = timestamp_to_tmv(fup->ts.pdu); c2 = correction_to_tmv(fup->header.correction); calc: - pd = tmv_sub(tmv_sub(t4, t1), tmv_sub(t3, t2)); + adj_t41 = p->nrate.ratio * tmv_dbl(tmv_sub(t4, t1)); + pd = tmv_sub(dbl_tmv(adj_t41), tmv_sub(t3, t2)); pd = tmv_sub(pd, c1); pd = tmv_sub(pd, c2); pd = tmv_div(pd, 2); diff --git a/tmv.h b/tmv.h index 16a0772..30b41ee 100644 --- a/tmv.h +++ b/tmv.h @@ -81,6 +81,11 @@ static inline double tmv_dbl(tmv_t x) return (double) x; } +static inline tmv_t dbl_tmv(double x) +{ + return (tmv_t) x; +} + static inline int64_t tmv_to_nanoseconds(tmv_t x) { return x;