EXTRA_OBJS = @EXTRA_OBJS@
-OBJS = array.o cmdparse.o conf.o local.o logging.o main.o memory.o \
+OBJS = array.o cmdparse.o conf.o local.o logging.o main.o memory.o quantiles.o \
reference.o regress.o rtc.o samplefilt.o sched.o socket.o sources.o sourcestats.o \
stubs.o smooth.o sys.o sys_null.o tempcomp.o util.o $(EXTRA_OBJS)
uint32_t flags;
int32_t filter_length;
uint32_t cert_set;
- uint32_t reserved[2];
+ Float max_delay_quant;
+ uint32_t reserved[1];
int32_t EOR;
} REQ_NTP_Source;
(data.params.sel_options & SRC_SELECT_REQUIRE ? REQ_ADDSRC_REQUIRE : 0));
msg->data.ntp_source.filter_length = htonl(data.params.filter_length);
msg->data.ntp_source.cert_set = htonl(data.params.cert_set);
+ msg->data.ntp_source.max_delay_quant =
+ UTI_FloatHostToNetwork(data.params.max_delay_quant);
memset(msg->data.ntp_source.reserved, 0, sizeof (msg->data.ntp_source.reserved));
result = 1;
UTI_FloatNetworkToHost(rx_message->data.ntp_source.max_delay_ratio);
params.max_delay_dev_ratio =
UTI_FloatNetworkToHost(rx_message->data.ntp_source.max_delay_dev_ratio);
+ params.max_delay_quant =
+ UTI_FloatNetworkToHost(rx_message->data.ntp_source.max_delay_quant);
params.min_delay = UTI_FloatNetworkToHost(rx_message->data.ntp_source.min_delay);
params.asymmetry = UTI_FloatNetworkToHost(rx_message->data.ntp_source.asymmetry);
params.offset = UTI_FloatNetworkToHost(rx_message->data.ntp_source.offset);
src->params.max_delay = SRC_DEFAULT_MAXDELAY;
src->params.max_delay_ratio = SRC_DEFAULT_MAXDELAYRATIO;
src->params.max_delay_dev_ratio = SRC_DEFAULT_MAXDELAYDEVRATIO;
+ src->params.max_delay_quant = 0.0;
src->params.min_delay = 0.0;
src->params.asymmetry = SRC_DEFAULT_ASYMMETRY;
src->params.offset = 0.0;
} else if (!strcasecmp(cmd, "maxdelaydevratio")) {
if (sscanf(line, "%lf%n", &src->params.max_delay_dev_ratio, &n) != 1)
return 0;
+ } else if (!strcasecmp(cmd, "maxdelayquant")) {
+ if (sscanf(line, "%lf%n", &src->params.max_delay_quant, &n) != 1)
+ return 0;
} else if (!strcasecmp(cmd, "maxpoll")) {
if (sscanf(line, "%d%n", &src->params.maxpoll, &n) != 1)
return 0;
&val, sizeof (val));'
then
add_def HAVE_LINUX_TIMESTAMPING
- EXTRA_OBJECTS="$EXTRA_OBJECTS hwclock.o ntp_io_linux.o quantiles.o"
+ EXTRA_OBJECTS="$EXTRA_OBJECTS hwclock.o ntp_io_linux.o"
if test_code 'other timestamping options' \
'sys/types.h sys/socket.h linux/net_tstamp.h' '' '' '
'ioctl(1, PTP_CLOCK_GETCAPS + PTP_SYS_OFFSET, 0);'
then
grep 'HAVE_LINUX_TIMESTAMPING' config.h > /dev/null ||
- EXTRA_OBJECTS="$EXTRA_OBJECTS hwclock.o quantiles.o"
+ EXTRA_OBJECTS="$EXTRA_OBJECTS hwclock.o"
add_def FEAT_PHC
fi
minimum delay amongst the previous measurements to the standard deviation of
the previous measurements that is greater than the specified ratio, it will be
rejected. The default is 10.0.
+*maxdelayquant* _p_:::
+This option disables the *maxdelaydevratio* test and specifies the maximum
+acceptable delay as a quantile of the round-trip delay instead of a function of
+the minimum delay amongst the buffered measurements. If a measurement has a
+round-trip delay that is greater than a long-term estimate of the _p_-quantile,
+it will be rejected.
++
+The specified _p_ value should be between 0.05 and 0.95. For example,
+*maxdelayquant 0.2* would indicate that only measurements with the lowest 20
+percent of round-trip delays should be accepted. Note that it can take many
+measurements for the estimated quantile to reach the expected value. This
+option is intended for synchronisation in mostly static local networks with
+very short polling intervals and possibly combined with the *filter* option.
+By default, this test is disabled in favour of the *maxdelaydevratio* test.
*mindelay* _delay_:::
This option specifies a fixed minimum round-trip delay to be used instead of
the minimum amongst the previous measurements. This can be useful in networks
. Stratum of remote computer. [2]
. RFC 5905 tests 1 through 3 (1=pass, 0=fail) [111]
. RFC 5905 tests 5 through 7 (1=pass, 0=fail) [111]
-. Tests for maximum delay, maximum delay ratio and maximum delay dev ratio,
- against defined parameters, and a test for synchronisation loop (1=pass,
+. Results of the *maxdelay*, *maxdelayratio*, and *maxdelaydevratio* (or
+ *maxdelayquant*) tests, and a test for synchronisation loop (1=pass,
0=fail). The first test from these four also checks the server precision,
response time, and whether an interleaved response is acceptable for
synchronisation. [1111]
from the source back.
*NTP tests*:::
Results of RFC 5905 tests 1 through 3, 5 through 7, and tests for maximum
-delay, delay ratio, delay dev ratio, and synchronisation loop.
+delay, delay ratio, delay dev ratio (or delay quantile), and synchronisation
+loop.
*Interleaved*:::
This shows if the response was in the interleaved mode.
*Authenticated*:::
#include "ntp_ext.h"
#include "ntp_io.h"
#include "memory.h"
+#include "quantiles.h"
#include "sched.h"
#include "reference.h"
#include "local.h"
SRC_Instance source;
+ /* Optional long-term quantile estimate of peer delay */
+ QNT_Instance delay_quant;
+
/* Optional median filter for NTP measurements */
SPF_Instance filter;
int filter_count;
#define MAX_MAXDELAYRATIO 1.0e6
#define MAX_MAXDELAYDEVRATIO 1.0e6
+/* Parameters for the peer delay quantile */
+#define DELAY_QUANT_Q 100
+#define DELAY_QUANT_REPEAT 7
+
/* Minimum and maximum allowed poll interval */
#define MIN_POLL -7
#define MAX_POLL 24
params->min_samples, params->max_samples,
params->min_delay, params->asymmetry);
+ if (params->max_delay_quant > 0.0) {
+ int k = round(CLAMP(0.05, params->max_delay_quant, 0.95) * DELAY_QUANT_Q);
+ result->delay_quant = QNT_CreateInstance(k, k, DELAY_QUANT_Q, DELAY_QUANT_REPEAT,
+ LCL_GetSysPrecisionAsQuantum() / 2.0);
+ } else {
+ result->delay_quant = NULL;
+ }
+
if (params->filter_length >= 1)
result->filter = SPF_CreateInstance(1, params->filter_length, NTP_MAX_DISPERSION, 0.0);
else
if (instance->mode == MODE_ACTIVE)
NIO_CloseServerSocket(instance->local_addr.sock_fd);
+ if (instance->delay_quant)
+ QNT_DestroyInstance(instance->delay_quant);
if (instance->filter)
SPF_DestroyInstance(instance->filter);
UTI_ZeroNtp64(&instance->init_remote_ntp_tx);
zero_local_timestamp(&instance->init_local_rx);
+ if (instance->delay_quant)
+ QNT_Reset(instance->delay_quant);
if (instance->filter)
SPF_DropSamples(instance->filter);
instance->filter_count = 0;
/* ================================================== */
+static int
+check_delay_quant(NCR_Instance inst, double delay)
+{
+ double quant;
+
+ quant = QNT_GetQuantile(inst->delay_quant, QNT_GetMinK(inst->delay_quant));
+
+ if (delay <= quant)
+ return 1;
+
+ DEBUG_LOG("maxdelayquant: delay=%e quant=%e", delay, quant);
+ return 0;
+}
+
+/* ================================================== */
+
static int
check_delay_dev_ratio(NCR_Instance inst, SST_Stats stats,
struct timespec *sample_time, double offset, double delay)
administrator-defined value */
testB = check_delay_ratio(inst, stats, &sample.time, sample.peer_delay);
- /* Test C requires that the ratio of the increase in delay from the minimum
+ /* Test C either requires that the delay is less than an estimate of an
+ administrator-defined quantile, or (if the quantile is not specified)
+ it 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
in the register is less than an administrator-defined value or the
difference between measured offset and predicted offset is larger than
the increase in delay */
- testC = check_delay_dev_ratio(inst, stats, &sample.time, sample.offset, sample.peer_delay);
+ if (inst->delay_quant)
+ testC = check_delay_quant(inst, sample.peer_delay);
+ else
+ testC = check_delay_dev_ratio(inst, stats, &sample.time, sample.offset,
+ sample.peer_delay);
/* Test D requires that the source is not synchronised to us and is not us
to prevent a synchronisation loop */
}
SRC_UpdateStatus(inst->source, MAX(inst->remote_stratum, inst->min_stratum), pkt_leap);
+
+ if (inst->delay_quant)
+ QNT_Accumulate(inst->delay_quant, sample.peer_delay);
}
if (good_packet) {
double max_delay;
double max_delay_ratio;
double max_delay_dev_ratio;
+ double max_delay_quant;
double min_delay;
double asymmetry;
double offset;
for chronyc_conf in \
"accheck 1.2.3.4" \
"add peer 10.0.0.0 minpoll 2 maxpoll 6" \
- "add server 10.0.0.0 minpoll 6 maxpoll 10 iburst burst key 1 certset 2 maxdelay 1e-3 maxdelayratio 10.0 maxdelaydevratio 10.0 mindelay 1e-4 asymmetry 0.5 offset 1e-5 minsamples 6 maxsamples 6 filter 3 offline auto_offline prefer noselect trust require xleave polltarget 20 port 123 presend 7 minstratum 3 version 4 nts ntsport 4460 copy extfield F323" \
+ "add server 10.0.0.0 minpoll 6 maxpoll 10 iburst burst key 1 certset 2 maxdelay 1e-3 maxdelayratio 10.0 maxdelaydevratio 10.0 maxdelayquant 0.5 mindelay 1e-4 asymmetry 0.5 offset 1e-5 minsamples 6 maxsamples 6 filter 3 offline auto_offline prefer noselect trust require xleave polltarget 20 port 123 presend 7 minstratum 3 version 4 nts ntsport 4460 copy extfield F323" \
"add server node1.net1.clk" \
"allow 1.2.3.4" \
"allow 1.2" \
check_sync && test_fail
done
+min_sync_time=10
+client_conf="
+logdir tmp
+log rawmeasurements"
+client_server_options="minpoll 2 maxpoll 2 maxdelayquant 0.1"
+
+run_test || test_fail
+check_chronyd_exit || test_fail
+check_packet_interval || test_fail
+check_sync || test_fail
+
+check_file_messages "20.*123\.1.* 111 111 1111" 200 500 measurements.log || test_fail
+check_file_messages "20.*123\.1.* 111 111 1101" 2000 2300 measurements.log || test_fail
+
test_pass