001    package 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    
020    import 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     * @author Naz Irizarry, MITRE Corp
027     * @author Jason Mathews, MITRE Corp
028     * @version $Revision: 1299238 $
029     */
030    public interface NtpV3Packet
031    {
032    
033        /**
034         * Standard NTP UDP port
035         */
036        public static final int NTP_PORT = 123;
037    
038        public static final int LI_NO_WARNING = 0;
039        public static final int LI_LAST_MINUTE_HAS_61_SECONDS = 1;
040        public static final int LI_LAST_MINUTE_HAS_59_SECONDS = 2;
041        public static final int LI_ALARM_CONDITION = 3;
042    
043        /* mode options */
044        public static final int MODE_RESERVED = 0;
045        public static final int MODE_SYMMETRIC_ACTIVE = 1;
046        public static final int MODE_SYMMETRIC_PASSIVE = 2;
047        public static final int MODE_CLIENT = 3;
048        public static final int MODE_SERVER = 4;
049        public static final int MODE_BROADCAST = 5;
050        public static final int MODE_CONTROL_MESSAGE = 6;
051        public static final int MODE_PRIVATE = 7;
052    
053        public static final int NTP_MINPOLL = 4;  // 16 seconds
054        public static final int NTP_MAXPOLL = 14; // 16284 seconds
055    
056        public static final int NTP_MINCLOCK = 1;
057        public static final int NTP_MAXCLOCK = 10;
058    
059        public static final int VERSION_3 = 3;
060        public static final int VERSION_4 = 4;
061    
062        /* possible getType values such that other time-related protocols can
063         * have its information represented as NTP packets
064         */
065        public static final String TYPE_NTP = "NTP";         // RFC-1305/2030
066        public static final String TYPE_ICMP = "ICMP";       // RFC-792
067        public static final String TYPE_TIME = "TIME";       // RFC-868
068        public static final String TYPE_DAYTIME = "DAYTIME"; // RFC-867
069    
070        /**
071         * @return a datagram packet with the NTP parts already filled in
072         */
073        public DatagramPacket getDatagramPacket();
074    
075        /**
076         * Set the contents of this object from the datagram packet
077         */
078        public void setDatagramPacket(DatagramPacket dp);
079    
080        /**
081         * @return leap indicator as defined in RFC-1305
082         */
083        public int getLeapIndicator();
084    
085        /**
086         * Set leap indicator.
087         * @param li - leap indicator code
088         */
089        public void setLeapIndicator(int li);
090    
091        /**
092         * @return mode as defined in RFC-1305
093         */
094        public int getMode();
095    
096        /**
097         * @return mode as human readable string; e.g. 3=Client
098         */
099        public String getModeName();
100    
101        /**
102         * Set mode as defined in RFC-1305
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         */
116        public void setPoll(int poll);
117    
118        /**
119         * @return precision as defined in RFC-1305
120         */
121        public int getPrecision();
122    
123        /**
124         * @return root delay as defined in RFC-1305
125         */
126        public int getRootDelay();
127    
128        /**
129         * @return root delay in milliseconds
130         */
131        public double getRootDelayInMillisDouble();
132    
133        /**
134         * @return root dispersion as defined in RFC-1305
135         */
136        public int getRootDispersion();
137    
138        /**
139         * @return root dispersion in milliseconds
140         */
141        public long getRootDispersionInMillis();
142    
143        /**
144         * @return root dispersion in milliseconds
145         */
146        public double getRootDispersionInMillisDouble();
147    
148        /**
149         * @return version as defined in RFC-1305
150         */
151        public int getVersion();
152    
153        /**
154         * Set version as defined in RFC-1305
155         */
156        public void setVersion(int mode);
157    
158        /**
159         * @return stratum as defined in RFC-1305
160         */
161        public int getStratum();
162    
163        /**
164         * Set stratum as defined in RFC-1305
165         */
166        public void setStratum(int stratum);
167    
168        /**
169         * @return the reference id string
170         */
171        public String getReferenceIdString();
172    
173        /**
174         * @return the reference id (32-bit code) as defined in RFC-1305
175         */
176        public int getReferenceId();
177    
178        /**
179         * Set reference clock identifier field.
180         * @param refId
181         */
182        public void setReferenceId(int refId);
183    
184        /**
185         * @return the transmit timestamp as defined in RFC-1305
186         */
187        public TimeStamp getTransmitTimeStamp();
188    
189        /**
190         * @return the reference time as defined in RFC-1305
191         */
192        public TimeStamp getReferenceTimeStamp();
193    
194        /**
195         * @return the originate time as defined in RFC-1305
196         */
197        public TimeStamp getOriginateTimeStamp();
198    
199        /**
200         * @return the receive time as defined in RFC-1305
201         */
202        public TimeStamp getReceiveTimeStamp();
203    
204        /**
205         * Set the transmit timestamp given NTP TimeStamp object.
206         * @param ts - timestamp
207         */
208        public void setTransmitTime(TimeStamp ts);
209    
210        /**
211         * Set the reference timestamp given NTP TimeStamp object.
212         * @param ts - timestamp
213         */
214        public void setReferenceTime(TimeStamp ts);
215    
216        /**
217         * Set originate timestamp given NTP TimeStamp object.
218         * @param ts - timestamp
219         */
220        public void setOriginateTimeStamp(TimeStamp ts);
221    
222        /**
223         * Set receive timestamp given NTP TimeStamp object.
224         * @param ts - timestamp
225         */
226        public void setReceiveTimeStamp(TimeStamp ts);
227    
228        /**
229         * Return type of time packet. The values (e.g. NTP, TIME, ICMP, ...)
230         * correspond to the protocol used to obtain the timing information.
231         *
232         * @return packet type string identifier
233         */
234        public String getType();
235    
236    }