[ntp:questions] root_distance function in ntp_proto.c differs from RFC5905 and NTP 4.2.4p6

Dave Hart hart at ntp.org
Mon Dec 12 20:37:06 UTC 2011


On Mon, Dec 12, 2011 at 13:26, blji <ubalaji83 at gmail.com> wrote:
> Also following are the differences with root_distance function:
> RFC 5905:
> return (max(MINDISP, p->rootdelay + p->delay) / 2 +
>            p->rootdisp + p->disp + PHI * (c.t - p->t) + p->jitter);
>
> code in NTP 4.2.4p6:
>  if (peer->stratum >= sys_orphan)
>     dist = 0;
>  else
>     dist = peer->rootdelay;
>
>  dist += max(sys_mindisp, dist + peer->delay) / 2 +
>     peer->rootdispersion + peer->disp + clock_phi *
>     (current_time - peer->update) + peer->jitter;
>  return (dist);

Unless your ntp.conf contains "tos orphan", sys_orphan is always
strictly greater than peer->stratum, which will range from 1 to 16
(with 16 meaning "unspecified" and seen before initial sync).

Here's the code in the latest ntp-dev (4.2.7p239):

	dtemp = (peer->delay + peer->rootdelay) / 2 + peer->disp +
	    peer->rootdisp + clock_phi * (current_time - peer->update) +
	    peer->jitter;
	if (dtemp < sys_mindisp)
		dtemp = sys_mindisp;
	return (dtemp);

As you can see, there are minor differences between the three.
4.2.7's code comes closest to the RFC 5905 pseudocode, but chooses to
floor the entire calculation at MINDISP rather than MINDISP/2.  This
was an conscious decision to diverge from the previous design.  This
matters primarily in the case of a directly-connected reference clock,
which will have 0 delay, rootdelay, and rootdisp and can have very
small disp and jitter.

I believe the code you quoted from 4.2.4 has a bug in factoring in the
full root delay as well as half the sum of delay and rootdelay.
Change += to = and it will match RFC 5905 exactly by my reading,
assuming no "tos orphan".

> Kindly let me know to which RFC does the version NTP 4.2.4p6 refers
> to.

The NTP v4 reference implementation continues to evolve and improve
upon the RFC 5905 design intentionally, as evidenced by the root
distance now always being at least MINDISP.  I suspect the IETF NTP
working group would welcome your participation in preparing an
addendum or update to 5905 to reflect the more recent improvements.

Cheers,
Dave Hart


More information about the questions mailing list