File: sources.h

package info (click to toggle)
chrony 1.23-6%2Blenny1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,012 kB
  • ctags: 2,431
  • sloc: ansic: 14,926; yacc: 858; sh: 622; perl: 426; makefile: 147
file content (155 lines) | stat: -rw-r--r-- 6,216 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
  $Header: /cvs/src/chrony/sources.h,v 1.15 2002/02/28 23:27:14 richard Exp $

  =======================================================================

  chronyd/chronyc - Programs for keeping computer clocks accurate.

 **********************************************************************
 * Copyright (C) Richard P. Curnow  1997-2002
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 * 
 **********************************************************************

  =======================================================================

  This is the header for the module that manages the collection of all
  sources that we are making measurements from.  This include all NTP
  servers & peers, locally connected reference sources, eye/wristwatch
  drivers etc */

#ifndef GOT_SOURCES_H
#define GOT_SOURCES_H

#include "sysincl.h"

#include "ntp.h"
#include "reports.h"

/* This datatype is used to hold information about sources.  The
   instance must be passed when calling many of the interface
   functions */

typedef struct SRC_Instance_Record *SRC_Instance;

/* Initialisation function */
extern void SRC_Initialise(void);

/* Finalisation function */
extern void SRC_Finalise(void);

/* Function to create a new instance.  This would be called by one of
   the individual source-type instance creation routines. */

extern SRC_Instance SRC_CreateNewInstance(unsigned long ref_id);

/* Function to get rid of a source when it is being unconfigured.
   This may cause the current reference source to be reselected, if this
   was the reference source or contributed significantly to a
   falseticker decision. */

extern void SRC_DestroyInstance(SRC_Instance instance);


/* 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);

/* This function is called by one of the source drivers when it has
   a new sample that is to be accumulated.

   This function causes the frequency estimation to be re-run for the
   designated source, and the clock selection procedure to be re-run
   afterwards.

   sample_time is the local time at which the sample is to be
   considered to have been made, in terms of doing a regression fit of
   offset against local time.

   offset is the offset at the time, in seconds.  Positive indicates
   that the local clock is SLOW relative to the source, negative
   indicates that the local clock is FAST relative to it.

   root_delay and root_dispersion are in seconds, and are as per
   RFC1305.  root_dispersion only includes the peer's root dispersion
   + local sampling precision + skew dispersion accrued during the
   measurement.  It is the job of the source statistics algorithms +
   track.c to add on the extra dispersion due to the residual standard
   deviation of the offsets from this source after regression, to form
   the root_dispersion field in the packets transmitted to clients or
   peers.

   stratum is the stratum of the source that supplied the sample.

   */

extern void SRC_AccumulateSample(SRC_Instance instance, struct timeval *sample_time, double offset, double peer_delay, double peer_dispersion, double root_delay, double root_dispersion, int stratum, NTP_Leap leap_status);

/* This routine indicates that packets with valid headers are being
   received from the designated source */
extern void SRC_SetReachable(SRC_Instance instance);

/* This routine indicates that we are no longer receiving packets with
   valid headers from the designated source */
extern void SRC_UnsetReachable(SRC_Instance instance);

/* This routine is used to select the best source from amongst those
   we currently have valid data on, and use it as the tracking base
   for the local time.  If match_addr is zero it means we must start
   tracking the (newly) selected reference unconditionally, otherwise
   it is equal to the address we should track if it turns out to be
   the best reference.  (This avoids updating the frequency tracking
   for every sample from other sources - only the ones from the
   selected reference make a difference) */
extern void SRC_SelectSource(unsigned long match_addr);

/* 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 timeval *when);

/* Return the minimum peer delay amongst the previous samples
   currently held in the register */
extern double SRC_MinRoundTripDelay(SRC_Instance inst);

extern void SRC_DumpSources(void);

extern void SRC_ReloadSources(void);

extern int SRC_IsSyncPeer(SRC_Instance inst);
extern int SRC_ReadNumberOfSources(void);
extern int SRC_ReportSource(int index, RPT_SourceReport *report, struct timeval *now);

extern int SRC_ReportSourcestats(int index, RPT_SourcestatsReport *report);

typedef enum {
  SRC_Skew_Decrease,
  SRC_Skew_Nochange,
  SRC_Skew_Increase
} SRC_Skew_Direction;

extern SRC_Skew_Direction SRC_LastSkewChange(SRC_Instance inst);

#endif /* GOT_SOURCES_H */