Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.commons.net.ntp
Class NtpV3Impl  view NtpV3Impl download NtpV3Impl.java

java.lang.Object
  extended byorg.apache.commons.net.ntp.NtpV3Impl
All Implemented Interfaces:
NtpV3Packet

public class NtpV3Impl
extends java.lang.Object
implements NtpV3Packet

Implementation of NtpV3Packet with methods converting Java objects to/from the Network Time Protocol (NTP) data message header format described in RFC-1305.

Version:
$Revision: 165675 $ $Date: 2005-05-02 15:09:55 -0500 (Mon, 02 May 2005) $

Field Summary
private  byte[] buf
           
private  java.net.DatagramPacket dp
           
private static int KEY_IDENTIFIER_INDEX
           
private static int LI_INDEX
           
private static int LI_SHIFT
           
private static int MESSAGE_DIGEST
           
private static int MODE_INDEX
           
private static int MODE_SHIFT
           
private static int ORIGINATE_TIMESTAMP_INDEX
           
private static int POLL_INDEX
           
private static int PRECISION_INDEX
           
private static int RECEIVE_TIMESTAMP_INDEX
           
private static int REFERENCE_ID_INDEX
           
private static int REFERENCE_TIMESTAMP_INDEX
           
private static int ROOT_DELAY_INDEX
           
private static int ROOT_DISPERSION_INDEX
           
private static int STRATUM_INDEX
           
private static int TRANSMIT_TIMESTAMP_INDEX
           
private static int VERSION_INDEX
           
private static int VERSION_SHIFT
           
 
Fields inherited from interface org.apache.commons.net.ntp.NtpV3Packet
LI_ALARM_CONDITION, LI_LAST_MINUTE_HAS_59_SECONDS, LI_LAST_MINUTE_HAS_61_SECONDS, LI_NO_WARNING, MODE_BROADCAST, MODE_CLIENT, MODE_CONTROL_MESSAGE, MODE_PRIVATE, MODE_RESERVED, MODE_SERVER, MODE_SYMMETRIC_ACTIVE, MODE_SYMMETRIC_PASSIVE, NTP_MAXCLOCK, NTP_MAXPOLL, NTP_MINCLOCK, NTP_MINPOLL, NTP_PORT, TYPE_DAYTIME, TYPE_ICMP, TYPE_NTP, TYPE_TIME, VERSION_3, VERSION_4
 
Constructor Summary
NtpV3Impl()
          Creates a new instance of NtpV3Impl
 
Method Summary
 java.net.DatagramPacket getDatagramPacket()
          Returns the datagram packet with the NTP details already filled in.
private  int getInt(int index)
           
 int getLeapIndicator()
          Returns leap indicator as defined in RFC-1305 which is a two-bit code: 0=no warning 1=last minute has 61 seconds 2=last minute has 59 seconds 3=alarm condition (clock not synchronized)
private  long getLong(int index)
          Get Long value represented by bits starting at specified index.
 int getMode()
          Returns mode as defined in RFC-1305 which is a 3-bit integer whose value is indicated by the MODE_xxx parameters.
 java.lang.String getModeName()
          Return human-readable name of message mode type as described in RFC 1305.
 TimeStamp getOriginateTimeStamp()
          Returns the originate time as defined in RFC-1305.
 int getPoll()
          Returns poll interval as defined in RFC-1305, which is an eight-bit signed integer indicating the maximum interval between successive messages, in seconds to the nearest power of two (e.g.
 int getPrecision()
          Returns precision as defined in RFC-1305 encoded as an 8-bit signed integer (seconds to nearest power of two).
 TimeStamp getReceiveTimeStamp()
          Returns receive timestamp as defined in RFC-1305.
 int getReferenceId()
          Returns the reference id as defined in RFC-1305, which is a 32-bit integer whose value is dependent on several criteria.
 java.lang.String getReferenceIdString()
          Returns the reference id string.
 TimeStamp getReferenceTimeStamp()
          Returns the reference time as defined in RFC-1305.
 int getRootDelay()
          Return root delay as defined in RFC-1305, which is the total roundtrip delay to the primary reference source, in seconds.
 double getRootDelayInMillisDouble()
          Return root delay as defined in RFC-1305 in milliseconds, which is the total roundtrip delay to the primary reference source, in seconds.
 int getRootDispersion()
          Returns root dispersion as defined in RFC-1305.
 long getRootDispersionInMillis()
          Returns root dispersion (as defined in RFC-1305) in milliseconds.
 double getRootDispersionInMillisDouble()
          Returns root dispersion (as defined in RFC-1305) in milliseconds as double precision value.
 int getStratum()
          Returns Stratum as defined in RFC-1305, which indicates the stratum level of the local clock, with values defined as follows: 0=unspecified, 1=primary ref clock, and all others a secondary reference (via NTP).
private  TimeStamp getTimestamp(int index)
          Get NTP Timestamp at specified starting index.
 TimeStamp getTransmitTimeStamp()
          Returns the transmit timestamp as defined in RFC-1305.
 java.lang.String getType()
          Return type of time packet.
 int getVersion()
          Returns NTP version number as defined in RFC-1305.
private  java.lang.String idAsHex()
           
private  java.lang.String idAsIPAddress()
          Returns Reference id as dotted IP address.
private  java.lang.String idAsString()
           
 void setDatagramPacket(java.net.DatagramPacket srcDp)
          Set the contents of this object from source datagram packet.
 void setLeapIndicator(int li)
          Set leap indicator as defined in RFC-1305.
 void setMode(int mode)
          Set mode as defined in RFC-1305.
 void setOriginateTimeStamp(TimeStamp ts)
          Set originate timestamp given NTP TimeStamp object.
 void setPoll(int poll)
          Set poll interval as defined in RFC-1305.
 void setPrecision(int precision)
          Set precision as defined in RFC-1305.
 void setReceiveTimeStamp(TimeStamp ts)
          Set receive timestamp given NTP TimeStamp object.
 void setReferenceId(int refId)
          Set reference clock identifier field with 32-bit unsigned integer value.
 void setReferenceTime(TimeStamp ts)
          Set Reference time with NTP timestamp.
 void setStratum(int stratum)
          Set stratum level as defined in RFC-1305.
private  void setTimestamp(int index, TimeStamp t)
          Sets the NTP timestamp at the given array index.
 void setTransmitTime(TimeStamp ts)
          Set transmit time with NTP timestamp.
 void setVersion(int version)
          Set NTP version as defined in RFC-1305.
 java.lang.String toString()
          Returns details of NTP packet as a string.
protected static int ui(byte b)
          Convert byte to unsigned integer.
protected static long ul(byte b)
          Convert byte to unsigned long.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MODE_INDEX

private static final int MODE_INDEX
See Also:
Constant Field Values

MODE_SHIFT

private static final int MODE_SHIFT
See Also:
Constant Field Values

VERSION_INDEX

private static final int VERSION_INDEX
See Also:
Constant Field Values

VERSION_SHIFT

private static final int VERSION_SHIFT
See Also:
Constant Field Values

LI_INDEX

private static final int LI_INDEX
See Also:
Constant Field Values

LI_SHIFT

private static final int LI_SHIFT
See Also:
Constant Field Values

STRATUM_INDEX

private static final int STRATUM_INDEX
See Also:
Constant Field Values

POLL_INDEX

private static final int POLL_INDEX
See Also:
Constant Field Values

PRECISION_INDEX

private static final int PRECISION_INDEX
See Also:
Constant Field Values

ROOT_DELAY_INDEX

private static final int ROOT_DELAY_INDEX
See Also:
Constant Field Values

ROOT_DISPERSION_INDEX

private static final int ROOT_DISPERSION_INDEX
See Also:
Constant Field Values

REFERENCE_ID_INDEX

private static final int REFERENCE_ID_INDEX
See Also:
Constant Field Values

REFERENCE_TIMESTAMP_INDEX

private static final int REFERENCE_TIMESTAMP_INDEX
See Also:
Constant Field Values

ORIGINATE_TIMESTAMP_INDEX

private static final int ORIGINATE_TIMESTAMP_INDEX
See Also:
Constant Field Values

RECEIVE_TIMESTAMP_INDEX

private static final int RECEIVE_TIMESTAMP_INDEX
See Also:
Constant Field Values

TRANSMIT_TIMESTAMP_INDEX

private static final int TRANSMIT_TIMESTAMP_INDEX
See Also:
Constant Field Values

KEY_IDENTIFIER_INDEX

private static final int KEY_IDENTIFIER_INDEX
See Also:
Constant Field Values

MESSAGE_DIGEST

private static final int MESSAGE_DIGEST
See Also:
Constant Field Values

buf

private byte[] buf

dp

private java.net.DatagramPacket dp
Constructor Detail

NtpV3Impl

public NtpV3Impl()
Creates a new instance of NtpV3Impl

Method Detail

getMode

public int getMode()
Returns mode as defined in RFC-1305 which is a 3-bit integer whose value is indicated by the MODE_xxx parameters.

Specified by:
getMode in interface NtpV3Packet

getModeName

public java.lang.String getModeName()
Return human-readable name of message mode type as described in RFC 1305.

Specified by:
getModeName in interface NtpV3Packet

setMode

public void setMode(int mode)
Set mode as defined in RFC-1305.

Specified by:
setMode in interface NtpV3Packet

getLeapIndicator

public int getLeapIndicator()
Returns leap indicator as defined in RFC-1305 which is a two-bit code: 0=no warning 1=last minute has 61 seconds 2=last minute has 59 seconds 3=alarm condition (clock not synchronized)

Specified by:
getLeapIndicator in interface NtpV3Packet

setLeapIndicator

public void setLeapIndicator(int li)
Set leap indicator as defined in RFC-1305.

Specified by:
setLeapIndicator in interface NtpV3Packet

getPoll

public int getPoll()
Returns poll interval as defined in RFC-1305, which is an eight-bit signed integer indicating the maximum interval between successive messages, in seconds to the nearest power of two (e.g. value of six indicates an interval of 64 seconds. The values that can appear in this field range from NTP_MINPOLL to NTP_MAXPOLL inclusive.

Specified by:
getPoll in interface NtpV3Packet

setPoll

public void setPoll(int poll)
Set poll interval as defined in RFC-1305.

Specified by:
setPoll in interface NtpV3Packet

getPrecision

public int getPrecision()
Returns precision as defined in RFC-1305 encoded as an 8-bit signed integer (seconds to nearest power of two). Values normally range from -6 to -20.

Specified by:
getPrecision in interface NtpV3Packet

setPrecision

public void setPrecision(int precision)
Set precision as defined in RFC-1305.


getVersion

public int getVersion()
Returns NTP version number as defined in RFC-1305.

Specified by:
getVersion in interface NtpV3Packet

setVersion

public void setVersion(int version)
Set NTP version as defined in RFC-1305.

Specified by:
setVersion in interface NtpV3Packet

getStratum

public int getStratum()
Returns Stratum as defined in RFC-1305, which indicates the stratum level of the local clock, with values defined as follows: 0=unspecified, 1=primary ref clock, and all others a secondary reference (via NTP).

Specified by:
getStratum in interface NtpV3Packet

setStratum

public void setStratum(int stratum)
Set stratum level as defined in RFC-1305.

Specified by:
setStratum in interface NtpV3Packet

getRootDelay

public int getRootDelay()
Return root delay as defined in RFC-1305, which is the total roundtrip delay to the primary reference source, in seconds. Values can take positive and negative values, depending on clock precision and skew.

Specified by:
getRootDelay in interface NtpV3Packet

getRootDelayInMillisDouble

public double getRootDelayInMillisDouble()
Return root delay as defined in RFC-1305 in milliseconds, which is the total roundtrip delay to the primary reference source, in seconds. Values can take positive and negative values, depending on clock precision and skew.

Specified by:
getRootDelayInMillisDouble in interface NtpV3Packet

getRootDispersion

public int getRootDispersion()
Returns root dispersion as defined in RFC-1305.

Specified by:
getRootDispersion in interface NtpV3Packet

getRootDispersionInMillis

public long getRootDispersionInMillis()
Returns root dispersion (as defined in RFC-1305) in milliseconds.

Specified by:
getRootDispersionInMillis in interface NtpV3Packet

getRootDispersionInMillisDouble

public double getRootDispersionInMillisDouble()
Returns root dispersion (as defined in RFC-1305) in milliseconds as double precision value.

Specified by:
getRootDispersionInMillisDouble in interface NtpV3Packet

setReferenceId

public void setReferenceId(int refId)
Set reference clock identifier field with 32-bit unsigned integer value. See RFC-1305 for description.

Specified by:
setReferenceId in interface NtpV3Packet

getReferenceId

public int getReferenceId()
Returns the reference id as defined in RFC-1305, which is a 32-bit integer whose value is dependent on several criteria.

Specified by:
getReferenceId in interface NtpV3Packet

getReferenceIdString

public java.lang.String getReferenceIdString()
Returns the reference id string. String cannot be null but value is dependent on the version of the NTP spec supported and stratum level. Value can be an empty string, clock type string, IP address, or a hex string.

Specified by:
getReferenceIdString in interface NtpV3Packet

idAsIPAddress

private java.lang.String idAsIPAddress()
Returns Reference id as dotted IP address.


idAsString

private java.lang.String idAsString()

idAsHex

private java.lang.String idAsHex()

getTransmitTimeStamp

public TimeStamp getTransmitTimeStamp()
Returns the transmit timestamp as defined in RFC-1305.

Specified by:
getTransmitTimeStamp in interface NtpV3Packet

setTransmitTime

public void setTransmitTime(TimeStamp ts)
Set transmit time with NTP timestamp. If ts is null then zero time is used.

Specified by:
setTransmitTime in interface NtpV3Packet

setOriginateTimeStamp

public void setOriginateTimeStamp(TimeStamp ts)
Set originate timestamp given NTP TimeStamp object. If ts is null then zero time is used.

Specified by:
setOriginateTimeStamp in interface NtpV3Packet

getOriginateTimeStamp

public TimeStamp getOriginateTimeStamp()
Returns the originate time as defined in RFC-1305.

Specified by:
getOriginateTimeStamp in interface NtpV3Packet

getReferenceTimeStamp

public TimeStamp getReferenceTimeStamp()
Returns the reference time as defined in RFC-1305.

Specified by:
getReferenceTimeStamp in interface NtpV3Packet

setReferenceTime

public void setReferenceTime(TimeStamp ts)
Set Reference time with NTP timestamp. If ts is null then zero time is used.

Specified by:
setReferenceTime in interface NtpV3Packet

getReceiveTimeStamp

public TimeStamp getReceiveTimeStamp()
Returns receive timestamp as defined in RFC-1305.

Specified by:
getReceiveTimeStamp in interface NtpV3Packet

setReceiveTimeStamp

public void setReceiveTimeStamp(TimeStamp ts)
Set receive timestamp given NTP TimeStamp object. If ts is null then zero time is used.

Specified by:
setReceiveTimeStamp in interface NtpV3Packet

getType

public java.lang.String getType()
Return type of time packet. The values (e.g. NTP, TIME, ICMP, ...) correspond to the protocol used to obtain the timing information.

Specified by:
getType in interface NtpV3Packet

getInt

private int getInt(int index)

getTimestamp

private TimeStamp getTimestamp(int index)
Get NTP Timestamp at specified starting index.


getLong

private long getLong(int index)
Get Long value represented by bits starting at specified index.


setTimestamp

private void setTimestamp(int index,
                          TimeStamp t)
Sets the NTP timestamp at the given array index.


getDatagramPacket

public java.net.DatagramPacket getDatagramPacket()
Returns the datagram packet with the NTP details already filled in.

Specified by:
getDatagramPacket in interface NtpV3Packet

setDatagramPacket

public void setDatagramPacket(java.net.DatagramPacket srcDp)
Set the contents of this object from source datagram packet.

Specified by:
setDatagramPacket in interface NtpV3Packet

ui

protected static final int ui(byte b)
Convert byte to unsigned integer. Java only has signed types so we have to do more work to get unsigned ops.


ul

protected static final long ul(byte b)
Convert byte to unsigned long. Java only has signed types so we have to do more work to get unsigned ops


toString

public java.lang.String toString()
Returns details of NTP packet as a string.