1 package org.apache.commons.net.ntp;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 import java.net.DatagramPacket;
19
20 /**
21 * Interface for a NtpV3Packet with get/set methods corresponding to the fields
22 * in the NTP Data Message Header described in RFC 1305.
23 *
24 * @author Naz Irizarry, MITRE Corp
25 * @author Jason Mathews, MITRE Corp
26 * @version $Revision: 165675 $ $Date: 2005-05-02 15:09:55 -0500 (Mon, 02 May 2005) $
27 */
28 public interface NtpV3Packet
29 {
30
31 /**
32 * Standard NTP UDP port
33 */
34 public static final int NTP_PORT = 123;
35
36 public static final int LI_NO_WARNING = 0;
37 public static final int LI_LAST_MINUTE_HAS_61_SECONDS = 1;
38 public static final int LI_LAST_MINUTE_HAS_59_SECONDS = 2;
39 public static final int LI_ALARM_CONDITION = 3;
40
41
42 public static final int MODE_RESERVED = 0;
43 public static final int MODE_SYMMETRIC_ACTIVE = 1;
44 public static final int MODE_SYMMETRIC_PASSIVE = 2;
45 public static final int MODE_CLIENT = 3;
46 public static final int MODE_SERVER = 4;
47 public static final int MODE_BROADCAST = 5;
48 public static final int MODE_CONTROL_MESSAGE = 6;
49 public static final int MODE_PRIVATE = 7;
50
51 public static final int NTP_MINPOLL = 4;
52 public static final int NTP_MAXPOLL = 14;
53
54 public static final int NTP_MINCLOCK = 1;
55 public static final int NTP_MAXCLOCK = 10;
56
57 public static final int VERSION_3 = 3;
58 public static final int VERSION_4 = 4;
59
60
61
62
63 public static final String TYPE_NTP = "NTP";
64 public static final String TYPE_ICMP = "ICMP";
65 public static final String TYPE_TIME = "TIME";
66 public static final String TYPE_DAYTIME = "DAYTIME";
67
68 /**
69 * @return a datagram packet with the NTP parts already filled in
70 */
71 public DatagramPacket getDatagramPacket();
72
73 /**
74 * Set the contents of this object from the datagram packet
75 */
76 public void setDatagramPacket(DatagramPacket dp);
77
78 /**
79 * @return leap indicator as defined in RFC-1305
80 */
81 public int getLeapIndicator();
82
83 /**
84 * Set leap indicator.
85 * @param li - leap indicator code
86 */
87 public void setLeapIndicator(int li);
88
89 /**
90 * @return mode as defined in RFC-1305
91 */
92 public int getMode();
93
94 /**
95 * @return mode as human readable string; e.g. 3=Client
96 */
97 public String getModeName();
98
99 /**
100 * Set mode as defined in RFC-1305
101 */
102 public void setMode(int mode);
103
104 /**
105 * @return poll interval as defined in RFC-1305.
106 * Field range between NTP_MINPOLL and NTP_MAXPOLL.
107 */
108 public int getPoll();
109
110 /**
111 * Set poll interval as defined in RFC-1305.
112 * Field range between NTP_MINPOLL and NTP_MAXPOLL.
113 */
114 public void setPoll(int poll);
115
116 /**
117 * @return precision as defined in RFC-1305
118 */
119 public int getPrecision();
120
121 /**
122 * @return root delay as defined in RFC-1305
123 */
124 public int getRootDelay();
125
126 /**
127 * @return root delay in milliseconds
128 */
129 public double getRootDelayInMillisDouble();
130
131 /**
132 * @return root dispersion as defined in RFC-1305
133 */
134 public int getRootDispersion();
135
136 /**
137 * @return root dispersion in milliseconds
138 */
139 public long getRootDispersionInMillis();
140
141 /**
142 * @return root dispersion in milliseconds
143 */
144 public double getRootDispersionInMillisDouble();
145
146 /**
147 * @return version as defined in RFC-1305
148 */
149 public int getVersion();
150
151 /**
152 * Set version as defined in RFC-1305
153 */
154 public void setVersion(int mode);
155
156 /**
157 * @return stratum as defined in RFC-1305
158 */
159 public int getStratum();
160
161 /**
162 * Set stratum as defined in RFC-1305
163 */
164 public void setStratum(int stratum);
165
166 /**
167 * @return the reference id string
168 */
169 public String getReferenceIdString();
170
171 /**
172 * @return the reference id (32-bit code) as defined in RFC-1305
173 */
174 public int getReferenceId();
175
176 /**
177 * Set reference clock identifier field.
178 * @param refId
179 */
180 public void setReferenceId(int refId);
181
182 /**
183 * @return the transmit timestamp as defined in RFC-1305
184 */
185 public TimeStamp getTransmitTimeStamp();
186
187 /**
188 * @return the reference time as defined in RFC-1305
189 */
190 public TimeStamp getReferenceTimeStamp();
191
192 /**
193 * @return the originate time as defined in RFC-1305
194 */
195 public TimeStamp getOriginateTimeStamp();
196
197 /**
198 * @return the receive time as defined in RFC-1305
199 */
200 public TimeStamp getReceiveTimeStamp();
201
202 /**
203 * Set the transmit timestamp given NTP TimeStamp object.
204 * @param ts - timestamp
205 */
206 public void setTransmitTime(TimeStamp ts);
207
208 /**
209 * Set the reference timestamp given NTP TimeStamp object.
210 * @param ts - timestamp
211 */
212 public void setReferenceTime(TimeStamp ts);
213
214 /**
215 * Set originate timestamp given NTP TimeStamp object.
216 * @param ts - timestamp
217 */
218 public void setOriginateTimeStamp(TimeStamp ts);
219
220 /**
221 * Set receive timestamp given NTP TimeStamp object.
222 * @param ts - timestamp
223 */
224 public void setReceiveTimeStamp(TimeStamp ts);
225
226 /**
227 * Return type of time packet. The values (e.g. NTP, TIME, ICMP, ...)
228 * correspond to the protocol used to obtain the timing information.
229 *
230 * @return packet type string identifier
231 */
232 public String getType();
233
234 }