    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    public static final int NTP_PORT = 123;
    034
    035    public static final int LI_NO_WARNING = 0;
    036    public static final int LI_LAST_MINUTE_HAS_61_SECONDS = 1;
    037    public static final int LI_LAST_MINUTE_HAS_59_SECONDS = 2;
    038    public static final int LI_ALARM_CONDITION = 3;
    039
    040    /* mode options */
    041    public static final int MODE_RESERVED = 0;
    042    public static final int MODE_SYMMETRIC_ACTIVE = 1;
    043    public static final int MODE_SYMMETRIC_PASSIVE = 2;
    044    public static final int MODE_CLIENT = 3;
    045    public static final int MODE_SERVER = 4;
    046    public static final int MODE_BROADCAST = 5;
    047    public static final int MODE_CONTROL_MESSAGE = 6;
    048    public static final int MODE_PRIVATE = 7;
    049
    050    public static final int NTP_MINPOLL = 4;  // 16 seconds
    051    public static final int NTP_MAXPOLL = 14; // 16284 seconds
    052
    053    public static final int NTP_MINCLOCK = 1;
    054    public static final int NTP_MAXCLOCK = 10;
    055
    056    public static final int VERSION_3 = 3;
    057    public static final 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    public static final String TYPE_NTP = "NTP";         // RFC-1305/2030
    063    public static final String TYPE_ICMP = "ICMP";       // RFC-792
    064    public static final String TYPE_TIME = "TIME";       // RFC-868
    065    public static final String TYPE_DAYTIME = "DAYTIME"; // RFC-867
    066
    067    /**
    068     * @return a datagram packet with the NTP parts already filled in
    069     */
    070    public DatagramPacket getDatagramPacket();
    071
    072    /**
    073     * Set the contents of this object from the datagram packet
    074     * @param dp the 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     * @param mode the mode to set
    102     */
    103    public 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    public 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    public void setPoll(int poll);
    117
    118    /**
    119     * @return precision as defined in RFC-1305
    120     */
    121    public 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    public 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    public double getRootDelayInMillisDouble();
    146
    147    /**
    148     * @return root dispersion as defined in RFC-1305
    149     */
    150    public 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    public long getRootDispersionInMillis();
    163
    164    /**
    165     * @return root dispersion in milliseconds
    166     */
    167    public double getRootDispersionInMillisDouble();
    168
    169    /**
    170     * @return version as defined in RFC-1305
    171     */
    172    public int getVersion();
    173
    174    /**
    175     * Set version as defined in RFC-1305
    176     * @param version the version to set
    177     */
    178    public void setVersion(int version);
    179
    180    /**
    181     * @return stratum as defined in RFC-1305
    182     */
    183    public int getStratum();
    184
    185    /**
    186     * Set stratum as defined in RFC-1305
    187     * @param stratum the stratum to set
    188     */
    189    public void setStratum(int stratum);
    190
    191    /**
    192     * @return the reference id string
    193     */
    194    public String getReferenceIdString();
    195
    196    /**
    197     * @return the reference id (32-bit code) as defined in RFC-1305
    198     */
    199    public int getReferenceId();
    200
    201    /**
    202     * Set reference clock identifier field.
    203     * @param refId the clock id field to set
    204     */
    205    public void setReferenceId(int refId);
    206
    207    /**
    208     * @return the transmit timestamp as defined in RFC-1305
    209     */
    210    public TimeStamp getTransmitTimeStamp();
    211
    212    /**
    213     * @return the reference time as defined in RFC-1305
    214     */
    215    public TimeStamp getReferenceTimeStamp();
    216
    217    /**
    218     * @return the originate time as defined in RFC-1305
    219     */
    220    public TimeStamp getOriginateTimeStamp();
    221
    222    /**
    223     * @return the receive time as defined in RFC-1305
    224     */
    225    public TimeStamp getReceiveTimeStamp();
    226
    227    /**
    228     * Set the transmit timestamp given NTP TimeStamp object.
    229     * @param ts - timestamp
    230     */
    231    public void setTransmitTime(TimeStamp ts);
    232
    233    /**
    234     * Set the reference timestamp given NTP TimeStamp object.
    235     * @param ts - timestamp
    236     */
    237    public void setReferenceTime(TimeStamp ts);
    238
    239    /**
    240     * Set originate timestamp given NTP TimeStamp object.
    241     * @param ts - timestamp
    242     */
    243    public void setOriginateTimeStamp(TimeStamp ts);
    244
    245    /**
    246     * Set receive timestamp given NTP TimeStamp object.
    247     * @param ts - timestamp
    248     */
    249    public 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    public String getType();
    258
    259}