From 23a4e8b38d873ce1246c4ef43a05d92c442a9f26 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Mon, 5 Dec 2016 13:26:58 +0100 Subject: [PATCH] ntp: rework calculation and testing of peer delay Instead of a worst-case delay use a mean value and relate it to the source's time. This makes it more stable in the interleaved and symmetric modes, which should improve the weighting and asymmetry correction. Modify the test A and B to work with a minimum estimated delay (delay - dispersion). --- ntp_core.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ntp_core.c b/ntp_core.c index 4fb6677..a1da2c8 100644 --- a/ntp_core.c +++ b/ntp_core.c @@ -1408,10 +1408,9 @@ receive_packet(NCR_Instance inst, NTP_Local_Address *local_addr, sample_rx_tss = rx_ts->source; } - /* In our case, we work out 'delay' as the worst case delay, - assuming worst case frequency error between us and the other - source */ - delay = local_interval - remote_interval * (1.0 + source_freq_lo); + /* Work out 'delay' relative to the source's time */ + delay = (1.0 - (source_freq_lo + source_freq_hi) / 2.0) * + local_interval - remote_interval; /* Clamp delay to avoid misleading results later */ delay = fabs(delay); @@ -1440,11 +1439,12 @@ receive_packet(NCR_Instance inst, NTP_Local_Address *local_addr, /* Additional tests required to pass before accumulating the sample */ - /* Test A requires that the peer delay is not larger than the configured - maximum, in client mode that the server processing time is sane, and in - interleaved symmetric mode that the delay is not longer than half of the - remote polling interval to detect missed packets */ - testA = delay <= inst->max_delay && + /* Test A requires that the minimum estimate of the peer delay is not + larger than the configured maximum, in client mode that the server + processing time is sane, and in the interleaved symmetric mode that + the delay is not longer than half of the remote polling interval to + detect missed packets */ + testA = delay - dispersion <= inst->max_delay && !(inst->mode == MODE_CLIENT && server_interval > MAX_SERVER_INTERVAL) && !(inst->mode == MODE_ACTIVE && interleaved_packet && delay > UTI_Log2ToDouble(message->poll - 1)); @@ -1453,7 +1453,7 @@ receive_packet(NCR_Instance inst, NTP_Local_Address *local_addr, minimum one currently in the stats data register is less than an administrator-defined value */ testB = inst->max_delay_ratio <= 1.0 || - delay / SST_MinRoundTripDelay(stats) <= inst->max_delay_ratio; + (delay - dispersion) / SST_MinRoundTripDelay(stats) <= inst->max_delay_ratio; /* Test C requires that the ratio of the increase in delay from the minimum one in the stats data register to the standard deviation of the offsets