View Javadoc
1   package org.apache.commons.net.ntp;
2   /*
3    * Licensed to the Apache Software Foundation (ASF) under one or more
4    * contributor license agreements.  See the NOTICE file distributed with
5    * this work for additional information regarding copyright ownership.
6    * The ASF licenses this file to You under the Apache License, Version 2.0
7    * (the "License"); you may not use this file except in compliance with
8    * the License.  You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  
20  import java.net.DatagramPacket;
21  
22  /**
23   * Interface for a NtpV3Packet with get/set methods corresponding to the fields
24   * in the NTP Data Message Header described in RFC 1305.
25   *
26   * @version $Revision: 1652868 $
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      /* mode options */
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;  // 16 seconds
52      public static final int NTP_MAXPOLL = 14; // 16284 seconds
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      /* possible getType values such that other time-related protocols can
61       * have its information represented as NTP packets
62       */
63      public static final String TYPE_NTP = "NTP";         // RFC-1305/2030
64      public static final String TYPE_ICMP = "ICMP";       // RFC-792
65      public static final String TYPE_TIME = "TIME";       // RFC-868
66      public static final String TYPE_DAYTIME = "DAYTIME"; // RFC-867
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       * @param dp the packet
76       */
77      public void setDatagramPacket(DatagramPacket dp);
78  
79      /**
80       * @return leap indicator as defined in RFC-1305
81       */
82      public int getLeapIndicator();
83  
84      /**
85       * Set leap indicator.
86       * @param li - leap indicator code
87       */
88      public void setLeapIndicator(int li);
89  
90      /**
91       * @return mode as defined in RFC-1305
92       */
93      public int getMode();
94  
95      /**
96       * @return mode as human readable string; e.g. 3=Client
97       */
98      public String getModeName();
99  
100     /**
101      * Set mode as defined in RFC-1305
102      * @param mode the mode to set
103      */
104     public void setMode(int mode);
105 
106     /**
107      * @return poll interval as defined in RFC-1305.
108      * Field range between NTP_MINPOLL and NTP_MAXPOLL.
109      */
110     public int getPoll();
111 
112     /**
113      * Set poll interval as defined in RFC-1305.
114      * Field range between NTP_MINPOLL and NTP_MAXPOLL.
115      * @param poll the interval to set
116      */
117     public void setPoll(int poll);
118 
119     /**
120      * @return precision as defined in RFC-1305
121      */
122     public int getPrecision();
123 
124     /**
125      * Set precision as defined in RFC-1305
126      * @param precision Precision
127      * @since 3.4
128      */
129     void setPrecision(int precision);
130 
131     /**
132      * @return root delay as defined in RFC-1305
133      */
134     public int getRootDelay();
135 
136     /**
137      * Set root delay as defined in RFC-1305
138      * @param delay the delay to set
139      * @since 3.4
140     */
141     void setRootDelay(int delay);
142 
143     /**
144      * @return root delay in milliseconds
145      */
146     public double getRootDelayInMillisDouble();
147 
148     /**
149      * @return root dispersion as defined in RFC-1305
150      */
151     public int getRootDispersion();
152 
153     /**
154      *
155      * @param dispersion the value to set
156      * @since 3.4
157      */
158     void setRootDispersion(int dispersion);
159 
160     /**
161      * @return root dispersion in milliseconds
162      */
163     public long getRootDispersionInMillis();
164 
165     /**
166      * @return root dispersion in milliseconds
167      */
168     public double getRootDispersionInMillisDouble();
169 
170     /**
171      * @return version as defined in RFC-1305
172      */
173     public int getVersion();
174 
175     /**
176      * Set version as defined in RFC-1305
177      * @param version the version to set
178      */
179     public void setVersion(int version);
180 
181     /**
182      * @return stratum as defined in RFC-1305
183      */
184     public int getStratum();
185 
186     /**
187      * Set stratum as defined in RFC-1305
188      * @param stratum the stratum to set
189      */
190     public void setStratum(int stratum);
191 
192     /**
193      * @return the reference id string
194      */
195     public String getReferenceIdString();
196 
197     /**
198      * @return the reference id (32-bit code) as defined in RFC-1305
199      */
200     public int getReferenceId();
201 
202     /**
203      * Set reference clock identifier field.
204      * @param refId the clock id field to set
205      */
206     public void setReferenceId(int refId);
207 
208     /**
209      * @return the transmit timestamp as defined in RFC-1305
210      */
211     public TimeStamp getTransmitTimeStamp();
212 
213     /**
214      * @return the reference time as defined in RFC-1305
215      */
216     public TimeStamp getReferenceTimeStamp();
217 
218     /**
219      * @return the originate time as defined in RFC-1305
220      */
221     public TimeStamp getOriginateTimeStamp();
222 
223     /**
224      * @return the receive time as defined in RFC-1305
225      */
226     public TimeStamp getReceiveTimeStamp();
227 
228     /**
229      * Set the transmit timestamp given NTP TimeStamp object.
230      * @param ts - timestamp
231      */
232     public void setTransmitTime(TimeStamp ts);
233 
234     /**
235      * Set the reference timestamp given NTP TimeStamp object.
236      * @param ts - timestamp
237      */
238     public void setReferenceTime(TimeStamp ts);
239 
240     /**
241      * Set originate timestamp given NTP TimeStamp object.
242      * @param ts - timestamp
243      */
244     public void setOriginateTimeStamp(TimeStamp ts);
245 
246     /**
247      * Set receive timestamp given NTP TimeStamp object.
248      * @param ts - timestamp
249      */
250     public void setReceiveTimeStamp(TimeStamp ts);
251 
252     /**
253      * Return type of time packet. The values (e.g. NTP, TIME, ICMP, ...)
254      * correspond to the protocol used to obtain the timing information.
255      *
256      * @return packet type string identifier
257      */
258     public String getType();
259 
260 }