001: package org.apache.commons.net.ntp;
002:
003: /*
004: * Copyright 2001-2005 The Apache Software Foundation
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * 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: import java.net.DatagramPacket;
020:
021: /**
022: * Interface for a NtpV3Packet with get/set methods corresponding to the fields
023: * in the NTP Data Message Header described in RFC 1305.
024: *
025: * @author Naz Irizarry, MITRE Corp
026: * @author Jason Mathews, MITRE Corp
027: * @version $Revision: 165675 $ $Date: 2005-05-02 15:09:55 -0500 (Mon, 02 May 2005) $
028: */
029: public interface NtpV3Packet {
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: */
076: public void setDatagramPacket(DatagramPacket dp);
077:
078: /**
079: * @return leap indicator as defined in RFC-1305
080: */
081: public int getLeapIndicator();
082:
083: /**
084: * Set leap indicator.
085: * @param li - leap indicator code
086: */
087: public void setLeapIndicator(int li);
088:
089: /**
090: * @return mode as defined in RFC-1305
091: */
092: public int getMode();
093:
094: /**
095: * @return mode as human readable string; e.g. 3=Client
096: */
097: public String getModeName();
098:
099: /**
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: }
|