KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > coach > tracing > service > ntp > NtpInfo


1 /***************************************************************************/
2 /* COACH: Component Based Open Source Architecture for */
3 /* Distributed Telecom Applications */
4 /* See: http://www.objectweb.org/ */
5 /* */
6 /* Copyright (C) 2003 Lucent Technologies Nederland BV */
7 /* Bell Labs Advanced Technologies - EMEA */
8 /* */
9 /* Initial developer(s): Harold Batteram */
10 /* */
11 /* This library is free software; you can redistribute it and/or */
12 /* modify it under the terms of the GNU Lesser General Public */
13 /* License as published by the Free Software Foundation; either */
14 /* version 2.1 of the License, or (at your option) any later version. */
15 /* */
16 /* This library is distributed in the hope that it will be useful, */
17 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
18 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
19 /* Lesser General Public License for more details. */
20 /* */
21 /* You should have received a copy of the GNU Lesser General Public */
22 /* License along with this library; if not, write to the Free Software */
23 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
24 /***************************************************************************/
25 package org.coach.tracing.service.ntp;
26
27 import java.net.*;
28
29 /**
30  * This class represents a datastructure describing the useful
31  * information
32  * that can be extracted from a NtpDatagram returning from the server.
33  * Refer to rfc2030 for more details.
34  */

35 public class NtpInfo {
36     /**
37    * No leap second warning.
38    */

39     public static final byte LI_NO_WARNING = 0;
40     /**
41    * Last minute has 61 seconds.
42    */

43     public static final byte LI_POSITIVE_LEAP_SECOND = 1;
44     /**
45    * Last minute has 59 seconds.
46    */

47     public static final byte LI_NEGATIVE_LEAP_SECOND = 2;
48     /**
49    * Alarm condition (clock not synchrinized)
50    */

51     public static final byte LI_ALARM_CONDITION = 3;
52     /**
53    * Reserved mode.
54    */

55     public static final byte MODE_RESERVED = 0;
56     /**
57    * Symmetric active mode.
58    */

59     public static final byte MODE_SYMMETRIC_ACTIVE = 1;
60     /**
61    * Symmetric passive mode.
62    */

63     public static final byte MODE_RESERVED_PASSIVE = 2;
64     /**
65    * Client mode.
66    */

67     public static final byte MODE_CLIENT = 3;
68     /**
69    * Server mode.
70    */

71     public static final byte MODE_SERVER = 4;
72     /**
73    * Broadcast mode.
74    */

75     public static final byte MODE_BROADCAST = 5;
76     /**
77    * Reserved for NTP control message.
78    */

79     public static final byte MODE_RESERVED_FOR_NTP_CONTROL = 6;
80     /**
81    * Reserved for private use.
82    */

83     public static final byte MODE_RESERVED_FOR_PRIVATE_USE = 7;
84     /**
85    * Unspecified or unavailable stratum.
86    */

87     public static final byte STRATUM_UNSPECIFIED = 0;
88     /**
89    * Primary reference.
90    */

91     public static final byte STRATUM_PRIMARY_REFERENCE = 1;
92     /**
93    * InetAddress of the server.
94    */

95     public InetAddress serverAddress;
96     /**
97    * Leap year indicator.
98    */

99     public int leapYearIndicator;
100     /**
101    * Version number of the packet. In this application we always send
102    * version 3 packet to the server. The servers always seem to reply
103    * with version 3 packets (and not version 4).
104    *
105    */

106     public int versionNumber;
107     /**
108    * Mode of the communication with the server. In our application this
109    * is MODE_CLIENT for the client and MODE_SERVER for the server.
110    */

111     public int mode;
112     /**
113    * The stratum. This number indicates the distance (in hops) from the
114    * server to the primary server (which is stratum 1).
115    */

116     public int stratum;
117     /**
118    * Poll Interval in seconds. See rfc2030
119    */

120     public int pollInterval;
121     /**
122    * Precision of the server clock (in milliseconds).
123    */

124     public double precision;
125     /**
126    * Total roundtrip delay from the server to the primary server
127    * (in milliseconds).
128    */

129     public double rootDelay;
130     /**
131    * Nominal error error relative to the primary reference source
132    * (in milliseconds).
133    */

134     public double rootDispersion;
135     /**
136    * Reference Identifier.
137    * <UL>
138    * <LI> In the case of NTP Version 3 or Version
139    * 4 stratum-0 (unspecified) or stratum-1 (primary) servers,
140    * this is a String identifying the source.
141    * <LI> In NTP Version 3 secondary servers, this is the InetAddress
142    * of the reference source.
143    * <LI> In NTP Version 4 secondary servers this is a 4-byte
144    * array. See rfc2030.
145    * </UL>
146    */

147     public Object JavaDoc referenceIdentifier;
148     /**
149    * Reference timestamp. Indicates when the server clock was last set.
150    */

151     public TimeStamp referenceTimeStamp;
152     /**
153    * Roundtrip delay (in milliseconds). Calculated according to rfc2030.
154    */

155     public long roundTripDelay;
156     /**
157    * Offset of the local clock versus the server clock, taking into
158    * account the roundtrip delay (in milliseconds). Calculated
159    * according to rfc2030.
160 */

161     public long offset;
162     public String JavaDoc toString() {
163         String JavaDoc s = "Server address : " + serverAddress + "\n" + "Leap year indicator : " + leapYearIndicator + "\n" + "Version number : " + versionNumber + "\n" + "Mode : " + mode + "\n" + "Stratum : " + stratum + "\n" + "Poll interval : " + pollInterval + " s\n" + "Precision : " + precision + " ms\n" + "Root delay : " + rootDelay + " ms\n" + "Root dispersion : " + rootDispersion + " ms\n";
164
165         if (referenceIdentifier instanceof InetAddress) {
166             s = s + "Reference address : " + (InetAddress)referenceIdentifier + "\n";
167         } else if (referenceIdentifier instanceof String JavaDoc) {
168             s = s + "Reference code : " + (String JavaDoc)referenceIdentifier + "\n";
169         } else {
170             byte[] temp = (byte[])referenceIdentifier;
171             s = s + "Reference data : " + temp[0] + " " + temp[1] + " " + temp[2] + " " + temp[3] + "\n";
172         }
173         s = s + "Reference timestamp : " + referenceTimeStamp + "\n" + "Round trip delay : " + roundTripDelay + " ms\n" + "Offset : " + offset + " ms";
174         return s;
175     }
176 }
177
Popular Tags