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