diff --git a/ntp_core.c b/ntp_core.c index 9d9c2b4..2ee3958 100644 --- a/ntp_core.c +++ b/ntp_core.c @@ -703,7 +703,7 @@ get_poll_adj(NCR_Instance inst, double error_in_estimate, double peer_distance) poll_adj = -shift - inst->poll_score + 0.5; } else { - int samples = SRC_Samples(inst->source); + int samples = SST_Samples(SRC_GetSourcestats(inst->source)); /* Adjust polling interval so that the number of sourcestats samples remains close to the target value */ @@ -1227,6 +1227,8 @@ static int receive_packet(NCR_Instance inst, NTP_Local_Address *local_addr, NTP_Local_Timestamp *rx_ts, NTP_Packet *message, int length) { + SST_Stats stats; + int pkt_leap; uint32_t pkt_refid, pkt_key_id; double pkt_root_delay; @@ -1280,6 +1282,8 @@ receive_packet(NCR_Instance inst, NTP_Local_Address *local_addr, /* ==================== */ + stats = SRC_GetSourcestats(inst->source); + pkt_leap = NTP_LVM_TO_LEAP(message->lvm); pkt_refid = ntohl(message->reference_id); pkt_root_delay = UTI_Ntp32ToDouble(message->root_delay); @@ -1347,7 +1351,7 @@ receive_packet(NCR_Instance inst, NTP_Local_Address *local_addr, precision = LCL_GetSysPrecisionAsQuantum() + UTI_Log2ToDouble(message->precision); - SRC_GetFrequencyRange(inst->source, &source_freq_lo, &source_freq_hi); + SST_GetFrequencyRange(stats, &source_freq_lo, &source_freq_hi); UTI_Ntp64ToTimespec(&message->receive_ts, &remote_receive); UTI_Ntp64ToTimespec(&message->transmit_ts, &remote_transmit); @@ -1416,16 +1420,15 @@ 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 / SRC_MinRoundTripDelay(inst->source) <= inst->max_delay_ratio; + delay / 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 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 = SRC_IsGoodSample(inst->source, -offset, delay, - inst->max_delay_dev_ratio, LCL_GetMaxClockError(), - &sample_time); + testC = SST_IsGoodSample(stats, -offset, delay, inst->max_delay_dev_ratio, + LCL_GetMaxClockError(), &sample_time); /* Test D requires that the remote peer is not synchronised to us to prevent a synchronisation loop */ @@ -1514,7 +1517,7 @@ receive_packet(NCR_Instance inst, NTP_Local_Address *local_addr, if (good_packet) { /* Do this before we accumulate a new sample into the stats registers, obviously */ - estimated_offset = SRC_PredictOffset(inst->source, &sample_time); + estimated_offset = SST_PredictOffset(stats, &sample_time); SRC_AccumulateSample(inst->source, &sample_time, diff --git a/sources.c b/sources.c index 0eaf8ee..0af9db4 100644 --- a/sources.c +++ b/sources.c @@ -309,22 +309,12 @@ SRC_SetRefid(SRC_Instance instance, uint32_t ref_id, IPAddr *addr) } /* ================================================== */ -/* Function to get the range of frequencies, relative to the given - source, that we believe the local clock lies within. The return - values are in terms of the number of seconds fast (+ve) or slow - (-ve) relative to the source that the local clock becomes after a - given amount of local time has elapsed. - Suppose the initial offset relative to the source is U (fast +ve, - slow -ve) and a time interval T elapses measured in terms of the - local clock. Then the error relative to the source at the end of - the interval should lie in the interval [U+T*lo, U+T*hi]. */ - -void SRC_GetFrequencyRange(SRC_Instance instance, double *lo, double *hi) +SST_Stats +SRC_GetSourcestats(SRC_Instance instance) { assert(initialised); - - SST_GetFrequencyRange(instance->stats, lo, hi); + return instance->stats; } /* ================================================== */ @@ -405,7 +395,7 @@ special_mode_end(void) /* Check if the source could still have enough samples to be selectable */ if (SOURCE_REACH_BITS - 1 - sources[i]->reachability_size + - SRC_Samples(sources[i]) >= MIN_SAMPLES_FOR_REGRESS) + SST_Samples(sources[i]->stats) >= MIN_SAMPLES_FOR_REGRESS) return 0; } @@ -1103,32 +1093,6 @@ SRC_SetReselectDistance(double distance) } } -/* ================================================== */ - -double -SRC_PredictOffset(SRC_Instance inst, struct timespec *when) -{ - return SST_PredictOffset(inst->stats, when); -} - -/* ================================================== */ - -double -SRC_MinRoundTripDelay(SRC_Instance inst) -{ - return SST_MinRoundTripDelay(inst->stats); -} - -/* ================================================== */ - -int -SRC_IsGoodSample(SRC_Instance inst, double offset, double delay, - double max_delay_dev_ratio, double clock_error, struct timespec *when) -{ - return SST_IsGoodSample(inst->stats, offset, delay, max_delay_dev_ratio, - clock_error, when); -} - /* ================================================== */ /* This routine is registered as a callback with the local clock module, to be called whenever the local clock changes frequency or @@ -1413,11 +1377,3 @@ SRC_GetType(int index) } /* ================================================== */ - -int -SRC_Samples(SRC_Instance inst) -{ - return SST_Samples(inst->stats); -} - -/* ================================================== */ diff --git a/sources.h b/sources.h index f62db7b..9acf98b 100644 --- a/sources.h +++ b/sources.h @@ -34,6 +34,7 @@ #include "ntp.h" #include "reports.h" +#include "sourcestats.h" /* Size of the source reachability register */ #define SOURCE_REACH_BITS 8 @@ -73,18 +74,8 @@ extern void SRC_ResetInstance(SRC_Instance instance); /* Function to change the sources's reference ID and IP address */ extern void SRC_SetRefid(SRC_Instance instance, uint32_t ref_id, IPAddr *addr); -/* Function to get the range of frequencies, relative to the given - source, that we believe the local clock lies within. The return - values are in terms of the number of seconds fast (+ve) or slow - (-ve) relative to the source that the local clock becomes after a - given amount of local time has elapsed. - - Suppose the initial offset relative to the source is U (fast +ve, - slow -ve) and a time interval T elapses measured in terms of the - local clock. Then the error relative to the source at the end of - the interval should lie in the interval [U+T*lo, U+T*hi]. */ - -extern void SRC_GetFrequencyRange(SRC_Instance instance, double *lo, double *hi); +/* Function to get access to the sourcestats instance */ +extern SST_Stats SRC_GetSourcestats(SRC_Instance instance); /* This function is called by one of the source drivers when it has a new sample that is to be accumulated. @@ -143,19 +134,6 @@ extern void SRC_ReselectSource(void); /* Set reselect distance */ extern void SRC_SetReselectDistance(double distance); -/* Predict the offset of the local clock relative to a given source at - a given local cooked time. Positive indicates local clock is FAST - relative to reference. */ -extern double SRC_PredictOffset(SRC_Instance inst, struct timespec *when); - -/* Return the minimum peer delay amongst the previous samples - currently held in the register */ -extern double SRC_MinRoundTripDelay(SRC_Instance inst); - -/* This routine determines if a new sample is good enough that it should be - accumulated */ -extern int SRC_IsGoodSample(SRC_Instance inst, double offset, double delay, double max_delay_dev_ratio, double clock_error, struct timespec *when); - extern void SRC_DumpSources(void); extern void SRC_ReloadSources(void); extern void SRC_RemoveDumpFiles(void); @@ -170,7 +148,4 @@ extern int SRC_ReportSourcestats(int index, RPT_SourcestatsReport *report, struc extern SRC_Type SRC_GetType(int index); -extern int SRC_Samples(SRC_Instance inst); - #endif /* GOT_SOURCES_H */ -