001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.apache.commons.net.ntp; 019 020import java.net.DatagramPacket; 021 022/** 023 * Interface for a NtpV3Packet with get/set methods corresponding to the fields in the NTP Data Message Header described in RFC 1305. 024 * 025 */ 026public interface NtpV3Packet { 027 028 /** 029 * Standard NTP UDP port 030 */ 031 int NTP_PORT = 123; 032 033 int LI_NO_WARNING = 0; 034 int LI_LAST_MINUTE_HAS_61_SECONDS = 1; 035 int LI_LAST_MINUTE_HAS_59_SECONDS = 2; 036 int LI_ALARM_CONDITION = 3; 037 038 /* mode options */ 039 int MODE_RESERVED = 0; 040 int MODE_SYMMETRIC_ACTIVE = 1; 041 int MODE_SYMMETRIC_PASSIVE = 2; 042 int MODE_CLIENT = 3; 043 int MODE_SERVER = 4; 044 int MODE_BROADCAST = 5; 045 int MODE_CONTROL_MESSAGE = 6; 046 int MODE_PRIVATE = 7; 047 048 int NTP_MINPOLL = 4; // 16 seconds 049 int NTP_MAXPOLL = 14; // 16284 seconds 050 051 int NTP_MINCLOCK = 1; 052 int NTP_MAXCLOCK = 10; 053 054 int VERSION_3 = 3; 055 int VERSION_4 = 4; 056 057 /* 058 * possible getType values such that other time-related protocols can have its information represented as NTP packets 059 */ 060 String TYPE_NTP = "NTP"; // RFC-1305/2030 061 String TYPE_ICMP = "ICMP"; // RFC-792 062 String TYPE_TIME = "TIME"; // RFC-868 063 String TYPE_DAYTIME = "DAYTIME"; // RFC-867 064 065 /** 066 * @return a datagram packet with the NTP parts already filled in 067 */ 068 DatagramPacket getDatagramPacket(); 069 070 /** 071 * @return leap indicator as defined in RFC-1305 072 */ 073 int getLeapIndicator(); 074 075 /** 076 * @return mode as defined in RFC-1305 077 */ 078 int getMode(); 079 080 /** 081 * @return mode as human readable string; e.g. 3=Client 082 */ 083 String getModeName(); 084 085 /** 086 * @return the originate time as defined in RFC-1305 087 */ 088 TimeStamp getOriginateTimeStamp(); 089 090 /** 091 * @return poll interval as defined in RFC-1305. Field range between NTP_MINPOLL and NTP_MAXPOLL. 092 */ 093 int getPoll(); 094 095 /** 096 * @return precision as defined in RFC-1305 097 */ 098 int getPrecision(); 099 100 /** 101 * @return the receive time as defined in RFC-1305 102 */ 103 TimeStamp getReceiveTimeStamp(); 104 105 /** 106 * @return the reference id (32-bit code) as defined in RFC-1305 107 */ 108 int getReferenceId(); 109 110 /** 111 * @return the reference id string 112 */ 113 String getReferenceIdString(); 114 115 /** 116 * @return the reference time as defined in RFC-1305 117 */ 118 TimeStamp getReferenceTimeStamp(); 119 120 /** 121 * @return root delay as defined in RFC-1305 122 */ 123 int getRootDelay(); 124 125 /** 126 * @return root delay in milliseconds 127 */ 128 double getRootDelayInMillisDouble(); 129 130 /** 131 * @return root dispersion as defined in RFC-1305 132 */ 133 int getRootDispersion(); 134 135 /** 136 * @return root dispersion in milliseconds 137 */ 138 long getRootDispersionInMillis(); 139 140 /** 141 * @return root dispersion in milliseconds 142 */ 143 double getRootDispersionInMillisDouble(); 144 145 /** 146 * @return stratum as defined in RFC-1305 147 */ 148 int getStratum(); 149 150 /** 151 * @return the transmit timestamp as defined in RFC-1305 152 */ 153 TimeStamp getTransmitTimeStamp(); 154 155 /** 156 * Return type of time packet. The values (e.g. NTP, TIME, ICMP, ...) correspond to the protocol used to obtain the timing information. 157 * 158 * @return packet type string identifier 159 */ 160 String getType(); 161 162 /** 163 * @return version as defined in RFC-1305 164 */ 165 int getVersion(); 166 167 /** 168 * Set the contents of this object from the datagram packet 169 * 170 * @param dp the packet 171 */ 172 void setDatagramPacket(DatagramPacket dp); 173 174 /** 175 * Set leap indicator. 176 * 177 * @param li - leap indicator code 178 */ 179 void setLeapIndicator(int li); 180 181 /** 182 * Set mode as defined in RFC-1305 183 * 184 * @param mode the mode to set 185 */ 186 void setMode(int mode); 187 188 /** 189 * Set originate timestamp given NTP TimeStamp object. 190 * 191 * @param ts - timestamp 192 */ 193 void setOriginateTimeStamp(TimeStamp ts); 194 195 /** 196 * Set poll interval as defined in RFC-1305. Field range between NTP_MINPOLL and NTP_MAXPOLL. 197 * 198 * @param poll the interval to set 199 */ 200 void setPoll(int poll); 201 202 /** 203 * Set precision as defined in RFC-1305 204 * 205 * @param precision Precision 206 * @since 3.4 207 */ 208 void setPrecision(int precision); 209 210 /** 211 * Set receive timestamp given NTP TimeStamp object. 212 * 213 * @param ts - timestamp 214 */ 215 void setReceiveTimeStamp(TimeStamp ts); 216 217 /** 218 * Set reference clock identifier field. 219 * 220 * @param refId the clock id field to set 221 */ 222 void setReferenceId(int refId); 223 224 /** 225 * Set the reference timestamp given NTP TimeStamp object. 226 * 227 * @param ts - timestamp 228 */ 229 void setReferenceTime(TimeStamp ts); 230 231 /** 232 * Set root delay as defined in RFC-1305 233 * 234 * @param delay the delay to set 235 * @since 3.4 236 */ 237 void setRootDelay(int delay); 238 239 /** 240 * 241 * @param dispersion the value to set 242 * @since 3.4 243 */ 244 void setRootDispersion(int dispersion); 245 246 /** 247 * Set stratum as defined in RFC-1305 248 * 249 * @param stratum the stratum to set 250 */ 251 void setStratum(int stratum); 252 253 /** 254 * Set the transmit timestamp given NTP TimeStamp object. 255 * 256 * @param ts - timestamp 257 */ 258 void setTransmitTime(TimeStamp ts); 259 260 /** 261 * Set version as defined in RFC-1305 262 * 263 * @param version the version to set 264 */ 265 void setVersion(int version); 266 267}