001package org.apache.commons.net.ntp;
002/*
003 * Licensed to the Apache Software Foundation (ASF) under one or more
004 * contributor license agreements.  See the NOTICE file distributed with
005 * this work for additional information regarding copyright ownership.
006 * The ASF licenses this file to You under the Apache License, Version 2.0
007 * (the "License"); you may not use this file except in compliance with
008 * the License.  You may obtain a copy of the License at
009 *
010 *      http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019
020import java.net.DatagramPacket;
021
022/**
023 * Interface for a NtpV3Packet with get/set methods corresponding to the fields
024 * in the NTP Data Message Header described in RFC 1305.
025 *
026 * @version $Revision: 1652868 $
027 */
028public interface NtpV3Packet
029{
030
031    /**
032     * Standard NTP UDP port
033     */
034    public static final int NTP_PORT = 123;
035
036    public static final int LI_NO_WARNING = 0;
037    public static final int LI_LAST_MINUTE_HAS_61_SECONDS = 1;
038    public static final int LI_LAST_MINUTE_HAS_59_SECONDS = 2;
039    public static final int LI_ALARM_CONDITION = 3;
040
041    /* mode options */
042    public static final int MODE_RESERVED = 0;
043    public static final int MODE_SYMMETRIC_ACTIVE = 1;
044    public static final int MODE_SYMMETRIC_PASSIVE = 2;
045    public static final int MODE_CLIENT = 3;
046    public static final int MODE_SERVER = 4;
047    public static final int MODE_BROADCAST = 5;
048    public static final int MODE_CONTROL_MESSAGE = 6;
049    public static final int MODE_PRIVATE = 7;
050
051    public static final int NTP_MINPOLL = 4;  // 16 seconds
052    public static final int NTP_MAXPOLL = 14; // 16284 seconds
053
054    public static final int NTP_MINCLOCK = 1;
055    public static final int NTP_MAXCLOCK = 10;
056
057    public static final int VERSION_3 = 3;
058    public static final int VERSION_4 = 4;
059
060    /* possible getType values such that other time-related protocols can
061     * have its information represented as NTP packets
062     */
063    public static final String TYPE_NTP = "NTP";         // RFC-1305/2030
064    public static final String TYPE_ICMP = "ICMP";       // RFC-792
065    public static final String TYPE_TIME = "TIME";       // RFC-868
066    public static final String TYPE_DAYTIME = "DAYTIME"; // RFC-867
067
068    /**
069     * @return a datagram packet with the NTP parts already filled in
070     */
071    public DatagramPacket getDatagramPacket();
072
073    /**
074     * Set the contents of this object from the datagram packet
075     * @param dp the packet
076     */
077    public void setDatagramPacket(DatagramPacket dp);
078
079    /**
080     * @return leap indicator as defined in RFC-1305
081     */
082    public int getLeapIndicator();
083
084    /**
085     * Set leap indicator.
086     * @param li - leap indicator code
087     */
088    public void setLeapIndicator(int li);
089
090    /**
091     * @return mode as defined in RFC-1305
092     */
093    public int getMode();
094
095    /**
096     * @return mode as human readable string; e.g. 3=Client
097     */
098    public String getModeName();
099
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}