ntp: add offset option
Add offset option to the server/pool/peer directive. It specifies a correction which will be applied to offsets measured with the NTP source. It's particularly useful to compensate for a known asymmetry in network delay or timestamping errors.
This commit is contained in:
parent
632cd1a177
commit
6cd558398a
5 changed files with 22 additions and 1 deletions
2
client.c
2
client.c
|
@ -1083,6 +1083,8 @@ process_cmd_add_server_or_peer(CMD_Request *msg, char *line)
|
||||||
opt_name = "maxsources";
|
opt_name = "maxsources";
|
||||||
else if (data.params.min_stratum != SRC_DEFAULT_MINSTRATUM)
|
else if (data.params.min_stratum != SRC_DEFAULT_MINSTRATUM)
|
||||||
opt_name = "minstratum";
|
opt_name = "minstratum";
|
||||||
|
else if (data.params.offset != 0.0)
|
||||||
|
opt_name = "offset";
|
||||||
else if (data.params.poll_target != SRC_DEFAULT_POLLTARGET)
|
else if (data.params.poll_target != SRC_DEFAULT_POLLTARGET)
|
||||||
opt_name = "polltarget";
|
opt_name = "polltarget";
|
||||||
else if (data.params.version != NTP_VERSION)
|
else if (data.params.version != NTP_VERSION)
|
||||||
|
|
|
@ -63,6 +63,7 @@ CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src)
|
||||||
src->params.max_delay = SRC_DEFAULT_MAXDELAY;
|
src->params.max_delay = SRC_DEFAULT_MAXDELAY;
|
||||||
src->params.max_delay_ratio = SRC_DEFAULT_MAXDELAYRATIO;
|
src->params.max_delay_ratio = SRC_DEFAULT_MAXDELAYRATIO;
|
||||||
src->params.max_delay_dev_ratio = SRC_DEFAULT_MAXDELAYDEVRATIO;
|
src->params.max_delay_dev_ratio = SRC_DEFAULT_MAXDELAYDEVRATIO;
|
||||||
|
src->params.offset = 0.0;
|
||||||
|
|
||||||
hostname = line;
|
hostname = line;
|
||||||
line = CPS_SplitWord(line);
|
line = CPS_SplitWord(line);
|
||||||
|
@ -123,6 +124,9 @@ CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src)
|
||||||
} else if (!strcasecmp(cmd, "minstratum")) {
|
} else if (!strcasecmp(cmd, "minstratum")) {
|
||||||
if (sscanf(line, "%d%n", &src->params.min_stratum, &n) != 1)
|
if (sscanf(line, "%d%n", &src->params.min_stratum, &n) != 1)
|
||||||
return 0;
|
return 0;
|
||||||
|
} else if (!strcasecmp(cmd, "offset")) {
|
||||||
|
if (sscanf(line, "%lf%n", &src->params.offset, &n) != 1)
|
||||||
|
return 0;
|
||||||
} else if (!strcasecmp(cmd, "port")) {
|
} else if (!strcasecmp(cmd, "port")) {
|
||||||
if (sscanf(line, "%hu%n", &src->port, &n) != 1)
|
if (sscanf(line, "%hu%n", &src->port, &n) != 1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -116,6 +116,13 @@ If a measurement has a ratio of the increase in the round-trip delay from the
|
||||||
minimum delay amongst the previous measurements to the standard deviation of
|
minimum delay amongst the previous measurements to the standard deviation of
|
||||||
the previous measurements that is greater than the specified ratio, it will be
|
the previous measurements that is greater than the specified ratio, it will be
|
||||||
rejected. The default is 10.0.
|
rejected. The default is 10.0.
|
||||||
|
*offset* _offset_:::
|
||||||
|
This option specifies a correction (in seconds) which will be applied to
|
||||||
|
offsets measured with this source. It's particularly useful to compensate for a
|
||||||
|
known asymmetry in network delay or timestamping errors. For example, if
|
||||||
|
packets sent to the source were on average delayed by 100 microseconds more
|
||||||
|
than packets sent from the source back, the correction would be -0.00005 (-50
|
||||||
|
microseconds). The default is 0.0.
|
||||||
*minsamples* _samples_:::
|
*minsamples* _samples_:::
|
||||||
Set the minimum number of samples kept for this source. This overrides the
|
Set the minimum number of samples kept for this source. This overrides the
|
||||||
<<minsamples,*minsamples*>> directive.
|
<<minsamples,*minsamples*>> directive.
|
||||||
|
|
|
@ -119,6 +119,9 @@ struct NCR_Instance_Record {
|
||||||
|
|
||||||
double max_delay_dev_ratio; /* Maximum ratio of increase in delay / stddev */
|
double max_delay_dev_ratio; /* Maximum ratio of increase in delay / stddev */
|
||||||
|
|
||||||
|
double offset_correction; /* Correction applied to measured offset
|
||||||
|
(e.g. for asymmetry in network delay) */
|
||||||
|
|
||||||
int do_auth; /* Flag indicating whether we
|
int do_auth; /* Flag indicating whether we
|
||||||
authenticate packets we send to
|
authenticate packets we send to
|
||||||
this machine (if it's serving us or
|
this machine (if it's serving us or
|
||||||
|
@ -481,6 +484,7 @@ NCR_GetInstance(NTP_Remote_Address *remote_addr, NTP_Source_Type type, SourcePar
|
||||||
result->max_delay = params->max_delay;
|
result->max_delay = params->max_delay;
|
||||||
result->max_delay_ratio = params->max_delay_ratio;
|
result->max_delay_ratio = params->max_delay_ratio;
|
||||||
result->max_delay_dev_ratio = params->max_delay_dev_ratio;
|
result->max_delay_dev_ratio = params->max_delay_dev_ratio;
|
||||||
|
result->offset_correction = params->offset;
|
||||||
result->auto_offline = params->auto_offline;
|
result->auto_offline = params->auto_offline;
|
||||||
result->poll_target = params->poll_target;
|
result->poll_target = params->poll_target;
|
||||||
|
|
||||||
|
@ -1311,6 +1315,9 @@ receive_packet(NTP_Packet *message, struct timeval *now, double now_err, NCR_Ins
|
||||||
if we are fast of the remote source. */
|
if we are fast of the remote source. */
|
||||||
UTI_DiffTimevalsToDouble(&offset, &remote_average, &local_average);
|
UTI_DiffTimevalsToDouble(&offset, &remote_average, &local_average);
|
||||||
|
|
||||||
|
/* Apply configured correction */
|
||||||
|
offset += inst->offset_correction;
|
||||||
|
|
||||||
/* We treat the time of the sample as being midway through the local
|
/* We treat the time of the sample as being midway through the local
|
||||||
measurement period. An analysis assuming constant relative
|
measurement period. An analysis assuming constant relative
|
||||||
frequency and zero network delay shows this is the only possible
|
frequency and zero network delay shows this is the only possible
|
||||||
|
|
|
@ -47,6 +47,7 @@ typedef struct {
|
||||||
double max_delay;
|
double max_delay;
|
||||||
double max_delay_ratio;
|
double max_delay_ratio;
|
||||||
double max_delay_dev_ratio;
|
double max_delay_dev_ratio;
|
||||||
|
double offset;
|
||||||
} SourceParameters;
|
} SourceParameters;
|
||||||
|
|
||||||
#define SRC_DEFAULT_PORT 123
|
#define SRC_DEFAULT_PORT 123
|
||||||
|
|
Loading…
Reference in a new issue