Difference between revisions of "Time and NTP"

Jump to: navigation , search
(NTP on Sawyer)
 
(22 intermediate revisions by the same user not shown)
Line 1: Line 1:
= Robot Time and NTP =
+
<div class="title-block">
 
+
<span style="font-size:120%;">'''Robot Time and NTP : The Network Time Protocol ([http://networktimefoundation.org/projects/ntp-project/ NTP]) is run on the robot to keep the robot's system time accurate and synchronized.'''</span>
The Network Time Protocol ([http://networktimefoundation.org/projects/ntp-project/ NTP]) is run on the robot to keep the robot's system time accurate.
+
</div>
  
 +
{{TOClimit|limit=2}}
  
 +
<div class="content-block">
 
== Introduction ==
 
== Introduction ==
 
By default, your robot will automatically use NTP to synchronize its system clock when connected to the internet.  Large offsets are corrected at boot, while small inaccuracies are handled gradually during run-time.
 
By default, your robot will automatically use NTP to synchronize its system clock when connected to the internet.  Large offsets are corrected at boot, while small inaccuracies are handled gradually during run-time.
Line 17: Line 19:
 
This will tell you the difference between your computer's time (the time on the left) and the robot's system clock.
 
This will tell you the difference between your computer's time (the time on the left) and the robot's system clock.
  
If you cannot connect your Sawyer to the internet or need to set a custom configuration, see the [[Time and NTP#configuration|Configuration]] Section.
+
If you cannot connect your Sawyer to the internet or need to set a custom configuration, see the [[Time and NTP#Configuration|Configuration]] Section.
 
+
</div>
 +
<div class="content-block">
 
== Overview ==
 
== Overview ==
Sawyer's on-board time is kept accurate using the standard [http://networktimefoundation.org/projects/ntp-project/ NTP] time service.  The default configuration will set the robot's time once during startup each time the robot boots, and then will maintain a running NTP server that will gradually slew the time to keep the robot's system time in sync.  The default time servers are received from pool.ntp.org, but these can be configured by either providing the <code>ntp-servers</code> option from your DHCP host, or using the [http://www.eecis.udel.edu/~mills/ntp/html/ntpdc.html ntpdc] tool to configure the running NTP server.
+
Sawyer's on-board time is kept accurate using the standard [http://networktimefoundation.org/projects/ntp-project/ NTP] time service.  The default configuration will set the robot's time once during startup each time the robot boots, and then will maintain a running NTP server that will gradually slew the time to keep the robot's system time in sync.  The default time servers are received from pool.ntp.org, but these can be configured by either providing the <code>NTP Servers</code> field of the [[Field_Service_Menu_(FSM)#Menu_Functions|Configuration Menu in the FSM]] from your DHCP host.
 
 
''Note: NTP was first enabled in version 0.6.2 of the RSDK. Make sure you are running rsdk-0.6.2 or above to use these services.''
 
  
 
=== NTP on Sawyer ===
 
=== NTP on Sawyer ===
Line 32: Line 33:
 
The final important piece is the <code>ntp.conf</code> configuration used for both these services.  This determines which reference time servers the robot should use to synchronize against.
 
The final important piece is the <code>ntp.conf</code> configuration used for both these services.  This determines which reference time servers the robot should use to synchronize against.
  
Default settings should work for most people to keep Baxter's time accurate.  Users can query the status of the robot's NTP timeserver using various NTP tools including: ntpdate, ntpq, and ntpdc.
+
Default settings should work for most people to keep Sawyer's time accurate.  Users can query the status of the robot's NTP timeserver using various NTP tools including: ntpdate, and ntpq.
  
For the advanced users, the above NTP services can be [[Time and NTP#configuration|configured]] using DHCP or the run-time ntpdc client.
+
For the advanced users, the above NTP services can be [[Time and NTP#Configuration|configured]] using DHCP.
  
 
=== Timezone ===
 
=== Timezone ===
 
NTP will sync your robot's time to "real-world" time, but you still need to set the robot's timezone.  The robot's timezone can be set using the [[Field Service Menu (FSM)|Field-Service-Menu]].  This does not affect the time kept by NTP as that will be based on UTC, however it will affect the offset used for the displayed system time.
 
NTP will sync your robot's time to "real-world" time, but you still need to set the robot's timezone.  The robot's timezone can be set using the [[Field Service Menu (FSM)|Field-Service-Menu]].  This does not affect the time kept by NTP as that will be based on UTC, however it will affect the offset used for the displayed system time.
 
+
</div>
 +
<div class="content-block">
 
== How to Use NTP ==
 
== How to Use NTP ==
 
 
=== How to Check Robot Time ===
 
=== How to Check Robot Time ===
You can use the [http://www.eecis.udel.edu/~mills/ntp/html/ntpdate.html ntpdate] tool for a simple reference check against the robot, or use the [[ntpq.html ntpq]]) tool to check the status of the NTP timeserver and Baxter's synchronization, among other details.
+
You can use the [http://www.eecis.udel.edu/~mills/ntp/html/ntpdate.html ntpdate] tool for a simple reference check against the robot, or use the ntpq tool to check the status of the NTP timeserver and Sawyer's synchronization, among other details.
 
 
 
Make sure you have installed the ntp tools:
 
Make sure you have installed the ntp tools:
 
<source lang="bash">
 
<source lang="bash">
Line 61: Line 61:
 
This lists the known synchronization references (and their "refid" references) of the robot’s ntp server.  These are the servers and peer timeservers that the robot’s NTP daemon/server is trying to sync against.
 
This lists the known synchronization references (and their "refid" references) of the robot’s ntp server.  These are the servers and peer timeservers that the robot’s NTP daemon/server is trying to sync against.
 
The first character in a row indicates the current Selection status (‘*’ means active). See ‘Select Field’: http://www.eecis.udel.edu/~mills/ntp/html/decode.html#peer
 
The first character in a row indicates the current Selection status (‘*’ means active). See ‘Select Field’: http://www.eecis.udel.edu/~mills/ntp/html/decode.html#peer
 
 
===== Compare Reference Time =====
 
===== Compare Reference Time =====
 
You can compare the robot's time to your system's time using the <code>-q</code> ntpdate command:
 
You can compare the robot's time to your system's time using the <code>-q</code> ntpdate command:
Line 67: Line 66:
 
     $ ntpdate -q <robot_ip>   
 
     $ ntpdate -q <robot_ip>   
 
</source>
 
</source>
 
 
=== How to Fix Robot Time ===
 
=== How to Fix Robot Time ===
 
Robot time is fixed by connecting the robot to timeservers.  This must happen at boot for large offsets.  Smaller inaccuracies (~17min) are handled regularly during run-time.
 
Robot time is fixed by connecting the robot to timeservers.  This must happen at boot for large offsets.  Smaller inaccuracies (~17min) are handled regularly during run-time.
 
 
==== Default Operation ====
 
==== Default Operation ====
By default the NTP services are configured to get four servers from the [http://www.pool.ntp.org/ NTP Pool Project] at pool.ntp.org.  On boot, if the robot can reach these servers -- i.e. if the robot can connect to the internet -- the <code>ntp-client</code> corrects the robot's time, setting it to the reference time from the servers in one big jump.  After this the robot's <code>ntpd</code> timeserver will continue to synchronize against these four servers.
+
By default the NTP services are configured to get four servers from the [http://www.pool.ntp.org/ NTP Pool Project] at pool.ntp.org.  On boot, if the robot can reach these servers -- i.e. if the robot can connect to the internet -- the <code>ntp-client</code> corrects the robot's time, setting it to the reference time from the servers in one big jump.  After this the robot's <code>ntpd</code> timeserver will continue to synchronize against these servers.
 
 
 
==== Setting the Time on Boot ====
 
==== Setting the Time on Boot ====
In order to set large offsets, the boot-time <code>ntp-client</code> need to be able to connect to the configured NTP servers.  If using the default settings, this just means the robot can reach the internet.  If your robot cannot connect to the internet, or you wish to use different servers during boot time, you can provide those servers using the <code>ntp-servers</code> option in your DHCP servers configuration.
+
In order to set large offsets, the boot-time <code>ntp-client</code> need to be able to connect to the configured NTP servers.  If using the default settings, this just means the robot can reach the internet.  If your robot cannot connect to the internet, or you wish to use different servers during boot time, you can provide those servers using the <code>NTP Servers</code> field of the [[Field_Service_Menu_(FSM)#Menu_Functions|Configuration Menu in the FSM]].
 
 
 
Once the robot has accurate time, it will save that time to the hardware clock on shutdown.
 
Once the robot has accurate time, it will save that time to the hardware clock on shutdown.
 +
</div>
 +
<div class="content-block">
  
 
== Configuration ==
 
== Configuration ==
Line 92: Line 89:
 
   of preference.<br />
 
   of preference.<br />
 
</blockquote>
 
</blockquote>
 
 
-- http://www.ietf.org/rfc/rfc2132.txt
 
-- http://www.ietf.org/rfc/rfc2132.txt
 
  
 
==== Running Locally with DHCP ====
 
==== Running Locally with DHCP ====
If you need to correct the time locally (without being on a network), you can setup your own DHCP server on a local machine with a tool such as <code>isc-dhcp-server</code>.  Make sure to run an NTP server on your own machine and provide the address of your machine as the address in the <code>ntp-servers</code> option.   
+
If you need to correct the time locally (without being on a network), you can setup your own DHCP server on a local machine with a tool such as <code>isc-dhcp-server</code>.  Make sure to run an NTP server on your own machine and provide the address of your machine as the address in the <code>NTP Servers</code> [[Field_Service_Menu_(FSM)#Menu_Functions|field in the Configuration Menu of the FSM]].   
  
 
If your dev machine is not connected to other authentic time servers, you will need to <code>fudge</code> your own local time as a valid source of authentication.  By default, NTP does not sync against stratum 16 servers (which is what a disconnected server is). "Stratum" indicates the number of hops you are away from a 'true' time source (stratum 1), such as a GPS based device.
 
If your dev machine is not connected to other authentic time servers, you will need to <code>fudge</code> your own local time as a valid source of authentication.  By default, NTP does not sync against stratum 16 servers (which is what a disconnected server is). "Stratum" indicates the number of hops you are away from a 'true' time source (stratum 1), such as a GPS based device.
 
<source lang="bash">
 
<source lang="bash">
= Add backup fake local server =
+
# editing your workstation's /etc/ntp.conf
server 127.127.1.1            # local clock
+
# remove or comment out your workstation's references to other NTP servers or NTP pools
fudge  127.127.1.1 stratum 12  # increase stratum
 
</source>
 
 
 
=== ntpdc Tool ===
 
The <code>ntpdc</code> tool is a program that can be run on the dev machine to query and configure the robot's NTP timeserver.  Configuration changes made at run-time using this tool are only currently saved for that boot.
 
 
 
==== Configuring the NTP Server at Run-Time ====
 
Use the <code>ntpdc</code> tool to configure the NTP server at run-time. The easiest method is to use the interactive mode.
 
 
 
# Get the NTP Authentication Key information from the Rethink FTP - RSDK Resources folder.  Your POC (Point-of-Contact) should have access to this service.
 
# In a terminal on your computer, drop into interactive mode:
 
#: <source lang="bash">
 
    $ ntpdc -i <robot_address> 
 
</source>
 
# Authenticate your ntpdc session. Using the authentication file above:
 
#: <source lang="bash">
 
    = Use the keyid number found at the start of the line =
 
    ntpdc> keyid #<number>
 
    = Use the MD5 password found in the middle of the line =
 
    ntpdc> passwd
 
    MD5 Password: #<Copy-&-Paste middle value of key in keys file here>
 
</source>
 
#: Now add a reference to your prefered time server.
 
 
 
# Add a server using the <code>addserver</code> command; use the <code>prefer</code> option to prioritize it:
 
#: <source lang="bash">
 
    ntpdc> addserver ntp0.rethink.cxm prefer 
 
</source>
 
 
 
===== List Status with ntpdc =====
 
You can also use the <code>ntpdc</code> tool to list the current status of the robot's NTP synchronization.
 
  
# From inside an interactive session, use the <code>peers</code> command:
+
# add backup fake local server
#: <source lang="bash">
+
server 127.127.1.0 iburst      # use local clock of sdk workstation as the server, burst synchronize
    ntpdc> peers
+
fudge 127.127.1.0  stratum 10 # "fake" sdk workstation as a stratum 10 NTP server (rather than the default and invalid stratum 16)
        remote          local     st poll reach  delay  offset    disp
 
    =======================================================================
 
  *kona.skafari.co 192.168.52.242  2 1024  373 0.00854  0.000148 0.15186
 
    =server2.shellva 192.168.52.242  2 1024  372 0.01021 0.001264 0.15143
 
    =sisdb01.muskego 192.168.52.242  3 1024 377 0.03574 -0.003096 0.13756
 
    =173.44.32.10    192.168.52.242  2 1024  77 0.05266 -0.003718 0.27809
 
</source>
 
#: This is the same as using the <code>ntpq -p <robot></code> command.
 
  
===== Unconfigure Servers =====
+
# set permissions to use your computer as an NTP server
If you want to remove the default servers from the current configuration, you can remove the peers by reference.
+
restrict -4 default kod notrap nomodify nopeer limited  # remove the default "noquery" options to allow others on the LAN to see the NTP server
 +
restrict -6 default kod notrap nomodify nopeer limited  # ditto
  
# Drop into interactive mode as shown above.
+
# optionally broadcast your IP address to the network
# Authenticate as shown above.
+
broadcast <your>.<ip>.<address>.<here>
# List peers (for finding their reference names):
 
#: <source lang="bash">
 
    ntpdc> listpeers
 
    client    kona.skafari.com
 
    client    blah.servers.net
 
    client    server2.shellvatore.us
 
    client    173.44.32.10
 
</source>
 
# Unconfigure each peer/server by address (right side of above):
 
#: <source lang="bash">
 
    ntpdc> unconfig <peer_address>
 
 
</source>
 
</source>
 +
</div>
 +
<div class="content-block">
  
 
== Resources ==
 
== Resources ==
 
* ntpq - standard NTP query program:  
 
* ntpq - standard NTP query program:  
 
   http://www.eecis.udel.edu/~mills/ntp/html/ntpq.html
 
   http://www.eecis.udel.edu/~mills/ntp/html/ntpq.html
* ntpdc - special NTP query program (for configuration commands):
 
  http://www.eecis.udel.edu/~mills/ntp/html/ntpdc.html
 
 
* ntpd - Network Time Protocol (NTP) daemon:  
 
* ntpd - Network Time Protocol (NTP) daemon:  
 
   http://www.eecis.udel.edu/~mills/ntp/html/ntpd.html
 
   http://www.eecis.udel.edu/~mills/ntp/html/ntpd.html
Line 175: Line 121:
 
   http://www.eecis.udel.edu/~mills/ntp/html/comdex.html
 
   http://www.eecis.udel.edu/~mills/ntp/html/comdex.html
  
== Troubleshooting ==
+
</div>

Latest revision as of 17:44, 28 February 2018

Robot Time and NTP : The Network Time Protocol (NTP) is run on the robot to keep the robot's system time accurate and synchronized.

Introduction

By default, your robot will automatically use NTP to synchronize its system clock when connected to the internet. Large offsets are corrected at boot, while small inaccuracies are handled gradually during run-time.

To correct your robot's time, reboot your robot while having it connected to the internet.

You can check the time on the robot with the ntpdate tool:

    $ ntpdate -q <robot_address>
    server 192.168.0.1, stratum 2, offset -0.000680, delay 0.03934
    5 Oct 18:32:31 ntpdate[7238]: adjust time server 192.168.52.242 offset -0.000680 sec

This will tell you the difference between your computer's time (the time on the left) and the robot's system clock.

If you cannot connect your Sawyer to the internet or need to set a custom configuration, see the Configuration Section.

Overview

Sawyer's on-board time is kept accurate using the standard NTP time service. The default configuration will set the robot's time once during startup each time the robot boots, and then will maintain a running NTP server that will gradually slew the time to keep the robot's system time in sync. The default time servers are received from pool.ntp.org, but these can be configured by either providing the NTP Servers field of the Configuration Menu in the FSM from your DHCP host.

NTP on Sawyer

NTP runs automatically on Sawyer in two parts:

  1. The ntp-client script runs on boot to correct large time offsets.
  2. The ntpd service then runs an NTP timeserver to gradually keep the time accurate for small time differences.

The final important piece is the ntp.conf configuration used for both these services. This determines which reference time servers the robot should use to synchronize against.

Default settings should work for most people to keep Sawyer's time accurate. Users can query the status of the robot's NTP timeserver using various NTP tools including: ntpdate, and ntpq.

For the advanced users, the above NTP services can be configured using DHCP.

Timezone

NTP will sync your robot's time to "real-world" time, but you still need to set the robot's timezone. The robot's timezone can be set using the Field-Service-Menu. This does not affect the time kept by NTP as that will be based on UTC, however it will affect the offset used for the displayed system time.

How to Use NTP

How to Check Robot Time

You can use the ntpdate tool for a simple reference check against the robot, or use the ntpq tool to check the status of the NTP timeserver and Sawyer's synchronization, among other details. Make sure you have installed the ntp tools:

    $ sudo apt-get install ntp

Query the status of the NTP server on the robot:

    $ ntpq -p <robot_address>  
         remote           refid      st t when poll reach   delay   offset  jitter
    ==============================================================================
*server2.shellva 128.59.39.48     2 u 1712 1024  376   10.225    1.013   3.852
*173.44.32.10    96.237.191.14    2 u   42 1024  217   52.744   -7.044  10.286
     kona.skafari.co 209.51.161.238   2 u 1694 1024  376    8.558   -1.378  16.680
*sisdb01.muskego 50.18.44.198     3 u  358 1024  377   35.632   -3.661   7.991

This lists the known synchronization references (and their "refid" references) of the robot’s ntp server. These are the servers and peer timeservers that the robot’s NTP daemon/server is trying to sync against. The first character in a row indicates the current Selection status (‘*’ means active). See ‘Select Field’: http://www.eecis.udel.edu/~mills/ntp/html/decode.html#peer

Compare Reference Time

You can compare the robot's time to your system's time using the -q ntpdate command:

    $ ntpdate -q <robot_ip>

How to Fix Robot Time

Robot time is fixed by connecting the robot to timeservers. This must happen at boot for large offsets. Smaller inaccuracies (~17min) are handled regularly during run-time.

Default Operation

By default the NTP services are configured to get four servers from the NTP Pool Project at pool.ntp.org. On boot, if the robot can reach these servers -- i.e. if the robot can connect to the internet -- the ntp-client corrects the robot's time, setting it to the reference time from the servers in one big jump. After this the robot's ntpd timeserver will continue to synchronize against these servers.

Setting the Time on Boot

In order to set large offsets, the boot-time ntp-client need to be able to connect to the configured NTP servers. If using the default settings, this just means the robot can reach the internet. If your robot cannot connect to the internet, or you wish to use different servers during boot time, you can provide those servers using the NTP Servers field of the Configuration Menu in the FSM. Once the robot has accurate time, it will save that time to the hardware clock on shutdown.

Configuration

DHCP

Using DHCP to provide the ntp-servers option is the standard way to provide NTP configuration information on a network. Your local network may already be configured to provide this information.

From DHCP Options and BOOTP Vendor Extensions:

8.3. Network Time Protocol Servers Option

This option specifies a list of IP addresses indicating NTP [18]
servers available to the client. Servers SHOULD be listed in order
of preference.

-- http://www.ietf.org/rfc/rfc2132.txt

Running Locally with DHCP

If you need to correct the time locally (without being on a network), you can setup your own DHCP server on a local machine with a tool such as isc-dhcp-server. Make sure to run an NTP server on your own machine and provide the address of your machine as the address in the NTP Servers field in the Configuration Menu of the FSM.

If your dev machine is not connected to other authentic time servers, you will need to fudge your own local time as a valid source of authentication. By default, NTP does not sync against stratum 16 servers (which is what a disconnected server is). "Stratum" indicates the number of hops you are away from a 'true' time source (stratum 1), such as a GPS based device.

# editing your workstation's /etc/ntp.conf
# remove or comment out your workstation's references to other NTP servers or NTP pools

# add backup fake local server 
server 127.127.1.0 iburst      # use local clock of sdk workstation as the server, burst synchronize
fudge 127.127.1.0  stratum 10  # "fake" sdk workstation as a stratum 10 NTP server (rather than the default and invalid stratum 16)

# set permissions to use your computer as an NTP server
restrict -4 default kod notrap nomodify nopeer limited  # remove the default "noquery" options to allow others on the LAN to see the NTP server
restrict -6 default kod notrap nomodify nopeer limited  # ditto

# optionally broadcast your IP address to the network
broadcast <your>.<ip>.<address>.<here>

Resources

  • ntpq - standard NTP query program:
 http://www.eecis.udel.edu/~mills/ntp/html/ntpq.html
  • ntpd - Network Time Protocol (NTP) daemon:
 http://www.eecis.udel.edu/~mills/ntp/html/ntpd.html
  • Command Index - (all the commands available in the ntp.conf configuration file and the ntpdc(/future ntpq versions) tools:
 http://www.eecis.udel.edu/~mills/ntp/html/comdex.html