refclock: add stratum option

This commit is contained in:
Andreas Steinmetz 2017-10-09 10:39:20 +02:00 committed by Miroslav Lichvar
parent 6f54210db2
commit 154b39cf7a
4 changed files with 14 additions and 2 deletions

8
conf.c
View file

@ -681,7 +681,7 @@ static void
parse_refclock(char *line) parse_refclock(char *line)
{ {
int n, poll, dpoll, filter_length, pps_rate, min_samples, max_samples, sel_options; int n, poll, dpoll, filter_length, pps_rate, min_samples, max_samples, sel_options;
int max_lock_age, pps_forced; int max_lock_age, pps_forced, stratum;
uint32_t ref_id, lock_ref_id; uint32_t ref_id, lock_ref_id;
double offset, delay, precision, max_dispersion, pulse_width; double offset, delay, precision, max_dispersion, pulse_width;
char *p, *cmd, *name, *param; char *p, *cmd, *name, *param;
@ -704,6 +704,7 @@ parse_refclock(char *line)
ref_id = 0; ref_id = 0;
max_lock_age = 2; max_lock_age = 2;
lock_ref_id = 0; lock_ref_id = 0;
stratum = 0;
if (!*line) { if (!*line) {
command_parse_error(); command_parse_error();
@ -774,6 +775,10 @@ parse_refclock(char *line)
} else if (!strcasecmp(cmd, "maxdispersion")) { } else if (!strcasecmp(cmd, "maxdispersion")) {
if (sscanf(line, "%lf%n", &max_dispersion, &n) != 1) if (sscanf(line, "%lf%n", &max_dispersion, &n) != 1)
break; break;
} else if (!strcasecmp(cmd, "stratum")) {
if (sscanf(line, "%d%n", &stratum, &n) != 1 ||
stratum >= NTP_MAX_STRATUM || stratum < 0)
break;
} else if (!strcasecmp(cmd, "width")) { } else if (!strcasecmp(cmd, "width")) {
if (sscanf(line, "%lf%n", &pulse_width, &n) != 1) if (sscanf(line, "%lf%n", &pulse_width, &n) != 1)
break; break;
@ -811,6 +816,7 @@ parse_refclock(char *line)
refclock->min_samples = min_samples; refclock->min_samples = min_samples;
refclock->max_samples = max_samples; refclock->max_samples = max_samples;
refclock->sel_options = sel_options; refclock->sel_options = sel_options;
refclock->stratum = stratum;
refclock->offset = offset; refclock->offset = offset;
refclock->delay = delay; refclock->delay = delay;
refclock->precision = precision; refclock->precision = precision;

View file

@ -516,6 +516,9 @@ is included in the maximum assumed error which is used in the source selection
algorithm. Increasing the delay is useful to avoid having no majority in the algorithm. Increasing the delay is useful to avoid having no majority in the
source selection or to make it prefer other sources. The default is 1e-9 (1 source selection or to make it prefer other sources. The default is 1e-9 (1
nanosecond). nanosecond).
*stratum* _stratum_:::
This option sets the NTP stratum of the refclock. This can be useful when the
refclock provides time with a stratum other than 0. The default is 0.
*precision* _precision_::: *precision* _precision_:::
This option sets the precision of the reference clock (in seconds). The default This option sets the precision of the reference clock (in seconds). The default
value is the estimated precision of the system clock. value is the estimated precision of the system clock.

View file

@ -79,6 +79,7 @@ struct RCL_Instance_Record {
int pps_rate; int pps_rate;
int pps_active; int pps_active;
int max_lock_age; int max_lock_age;
int stratum;
struct MedianFilter filter; struct MedianFilter filter;
uint32_t ref_id; uint32_t ref_id;
uint32_t lock_ref; uint32_t lock_ref;
@ -200,6 +201,7 @@ RCL_AddRefclock(RefclockParameters *params)
inst->pps_rate = params->pps_rate; inst->pps_rate = params->pps_rate;
inst->pps_active = 0; inst->pps_active = 0;
inst->max_lock_age = params->max_lock_age; inst->max_lock_age = params->max_lock_age;
inst->stratum = params->stratum;
inst->lock_ref = params->lock_ref_id; inst->lock_ref = params->lock_ref_id;
inst->offset = params->offset; inst->offset = params->offset;
inst->delay = params->delay; inst->delay = params->delay;
@ -635,7 +637,7 @@ poll_timeout(void *arg)
/* Handle special case when PPS is used with local stratum */ /* Handle special case when PPS is used with local stratum */
stratum = pps_stratum(inst, &sample_time); stratum = pps_stratum(inst, &sample_time);
else else
stratum = 0; stratum = inst->stratum;
SRC_UpdateReachability(inst->source, 1); SRC_UpdateReachability(inst->source, 1);
SRC_AccumulateSample(inst->source, &sample_time, offset, SRC_AccumulateSample(inst->source, &sample_time, offset,

View file

@ -43,6 +43,7 @@ typedef struct {
int max_samples; int max_samples;
int sel_options; int sel_options;
int max_lock_age; int max_lock_age;
int stratum;
uint32_t ref_id; uint32_t ref_id;
uint32_t lock_ref_id; uint32_t lock_ref_id;
double offset; double offset;