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   * @author Naz Irizarry, MITRE Corp
27   * @author Jason Mathews, MITRE Corp
28   * @version $Revision: 1299238 $
29   */
30  public interface NtpV3Packet
31  {
32  
33      /**
34       * Standard NTP UDP port
35       */
36      public static final int NTP_PORT = 123;
37  
38      public static final int LI_NO_WARNING = 0;
39      public static final int LI_LAST_MINUTE_HAS_61_SECONDS = 1;
40      public static final int LI_LAST_MINUTE_HAS_59_SECONDS = 2;
41      public static final int LI_ALARM_CONDITION = 3;
42  
43      /* mode options */
44      public static final int MODE_RESERVED = 0;
45      public static final int MODE_SYMMETRIC_ACTIVE = 1;
46      public static final int MODE_SYMMETRIC_PASSIVE = 2;
47      public static final int MODE_CLIENT = 3;
48      public static final int MODE_SERVER = 4;
49      public static final int MODE_BROADCAST = 5;
50      public static final int MODE_CONTROL_MESSAGE = 6;
51      public static final int MODE_PRIVATE = 7;
52  
53      public static final int NTP_MINPOLL = 4;  // 16 seconds
54      public static final int NTP_MAXPOLL = 14; // 16284 seconds
55  
56      public static final int NTP_MINCLOCK = 1;
57      public static final int NTP_MAXCLOCK = 10;
58  
59      public static final int VERSION_3 = 3;
60      public static final int VERSION_4 = 4;
61  
62      /* possible getType values such that other time-related protocols can
63       * have its information represented as NTP packets
64       */
65      public static final String TYPE_NTP = "NTP";         // RFC-1305/2030
66      public static final String TYPE_ICMP = "ICMP";       // RFC-792
67      public static final String TYPE_TIME = "TIME";       // RFC-868
68      public static final String TYPE_DAYTIME = "DAYTIME"; // RFC-867
69  
70      /**
71       * @return a datagram packet with the NTP parts already filled in
72       */
73      public DatagramPacket getDatagramPacket();
74  
75      /**
76       * Set the contents of this object from the datagram packet
77       */
78      public void setDatagramPacket(DatagramPacket dp);
79  
80      /**
81       * @return leap indicator as defined in RFC-1305
82       */
83      public int getLeapIndicator();
84  
85      /**
86       * Set leap indicator.
87       * @param li - leap indicator code
88       */
89      public void setLeapIndicator(int li);
90  
91      /**
92       * @return mode as defined in RFC-1305
93       */
94      public int getMode();
95  
96      /**
97       * @return mode as human readable string; e.g. 3=Client
98       */
99      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 }