ntpのクライアントモード利用

(2001.08.19更新)
(2001.08.15作成)


ntpは、GPSなどを用いてtimeserverを構築するだけでなく、クライアント機能にも使えます。
単に時刻同期をさせるだけなら、他のページでも紹介しているように簡単な設定で利用できます。

このページでは、クライアントが享受できる時刻の精度がどの程度なのか考察できないかと思い実験したことを記してあります。
ただ、ntpのしくみをあまりよく理解していないので、アホなことを書いているかもしれません。。。Precisionの意味を正確に理解したいと考えているのですが至っていません・・・。


<実験環境>

TimeServer用PC(pc03またはserver01と表示)
Linux kernel version 2.0.32+PPSkit(4年前の1997年に構築したマシンです。最新カーネルを導入したいなとは思っています。。。)
GPSはジュピター(第2バージョン)利用
xntp v3.5.93導入済
クライアント機 No.1(pc02)
Linux kernel version 1.2.23+IPマスカレイド用patch(VLバスのあるマシンです。5年前の1996年に構築したマシンです。いまだ家庭内LANのgwマシンとして活躍中)
xntp v3.5.93導入済
クライアント機 No.2(pc05)
windowsNT 4.0+SP6a+IE4.02
PII350MHz Dual CPUマシン(3年前の1998年に構築)
ntp v4.0.99mRC2導入済、その他桜時計なども導入済
public ntpサーバー(インターネット経由でアクセス可能なもの):
gpsntp.miz.nao.ac.jp が国立天文台の論文ページで紹介されていたのですが一応アクセス可能でした。
ひょっとしたらpublicでないかもしれないので、恒常的にアクセスする場合はちゃんと調べてからアクセスした方が無難でしょう。
stratum2のものは以下で紹介する通信総合研究所の実験で公開されています。


<関連情報の所在源>---他のページとの重複あり

NTP:http://www.ntp.org
ntp FAQは必読と思われます。また、ntp以外のクライアント用各種ソフトの一覧もあります。

国立天文台のページ:
http://www.miz.nao.ac.jp/staffs/hisa/00fall_1.html
http://www.miz.nao.ac.jp/staffs/hisa/00TEsympo.html#top
http://www.miz.nao.ac.jp/staffs/hisa/trials2.html#top
ntpサーバー同士の時刻比較などもあります。
しかし、web pageには詳しい記述がないので、ちょっと物足りないですね。。。

通信総合研究所:
http://www2.crl.go.jp/pub/whatsnew/press/010410/010410.html
関連して NTPサーバ(stratum2)の精度情報を計測するサーバに関する情報http://www.jst.mfeed.ad.jp/

RFCドキュメント一般:
http://rfc-jp.nic.ad.jp/
http://www.rfc-editor.org/など
ntpのアーカイブの中のマニュアルから判断するに、まず、rfc1305を読むのがよさそうに感じます。残念ながら日本語化はされていないようです。rfc1305は図表が多様されているのでpdf版をゲットしておいた方がいいでしょう。

サーバーモードやクライアントモードで(x)ntpdを動作させて、(x)ntpdcコマンドを利用して各種情報を表示させてみた結果です。
経験上、十分時間が経過してから(できれば1日ぐらい経過してから)の表示を見ないといけないように感じます。
(x)ntpdcの表示内容の一部の意味はrfc1305に書いてあります。

Stratum1のTimeserver(pc03)上でのxntpdcの表示

server01:~# ntpq -p
remote refid st t when poll reach delay offset disp
==============================================================================
LOCAL(0) LOCAL(0) 3 l 42 64 377 0.00 0.000 10.01
oGPS_JUPITER(2) .JUPI. 0 l 9 16 377 0.00 -1.408 0.53

server01:~# xntpdc
xntpdc> kerninfo
pll offset: -1629 us
pll frequency: 39.526 ppm
maximum error: 2248 us
estimated error: 2048 us---kernelが古いのでこの程度です。
status: 0107
pll time constant: 0
precision: 1 us
frequency tolerance: 200 ppm
pps frequency: 41.976 ppm
pps stability: 0.006 ppm
pps jitter: 46 us
calibration interval: 256 s
calibration cycles: 380
jitter exceeded: 0
stability exceeded: 5
calibration errors: 5

xntpdc> sysinfo
system peer: GPS_JUPITER(2)
system peer mode: client
leap indicator: 00
stratum: 1
precision: -17---2のべき乗を意味しています。rfc1305参照。us対応のkernelではこの程度でしょう。これまで-18になったのを見たことがあるのですが、通常は-17になっています。
root distance: 0.00000 s---さすがに0となりますね。
root dispersion: 0.00195 s
reference ID: [JUPI]
reference time: bf24bceb.011fc4c1 Wed, Aug 15 2001 18:18:35.004
system flags: auth monitor pll pps stats kernel_sync pps_sync
frequency: 0.000 ppm
stability: 25.250 ppm
broadcastdelay: 0.003906 s
authdelay: 0.000122 s
xntpdc>

Linuxマシン(pc02)上でのxntpdcの表示

pc02:~# ntpq -p
remote refid st t when poll reach delay offset disp
==============================================================================
LOCAL(0) LOCAL(0) 3 l 15 64 377 0.00 0.000 10.01
*pc03.sato_local .JUPI. 1 u 76 128 377 1.40 -1.823 2.35

pc02:~# xntpdc
xntpdc> sysinfo
system peer: pc03.sato_local.nakano.tokyo.jp
system peer mode: sym_active
leap indicator: 00
stratum: 2
precision: -16
root distance: 0.00140 s
root dispersion: 0.01193 s
reference ID: [192.168.1.103]
reference time: bf24bc74.05c1e000 Wed, Aug 15 2001 18:16:36.022
system flags: auth monitor pll stats
frequency: -32.000 ppm
stability: 35.981 ppm
broadcastdelay: 0.003906 s
authdelay: 0.000122 s
xntpdc>

windowsNTマシン上でのntpdcの表示
なお、windows2000にはsntpクライアント機能が標準で含まれているそうです。
その1---直接stratum1のTimeServer(pc03)にアクセスした場合

同じstratum1のTimeServerであるpc03にアクセスしているにもかかわらずLinuxマシンではprecision-16であったものが、こちらではprecision-17となっています。
とはいえ、windowsNTの内部時計の解像度からしてprecision-17(=0.000007...)の精度で時刻あわせできるのかは不明です。
ntpのドキュメントdriver29.htmをみると、windowNT版は1msオーダーでしか時刻同期できないようです。

その2---stratum2のサーバー(上記で紹介したpc02)へアクセスした場合

さすがにprecisionは-13(=0.00012...)に低下していますね。

このとき桜時計を用いてインターネット上で公開されているntpサーバーにアクセスしてみると、以下のようになりました。
precisionが-18となっていますね。。。

桜時計の表示内容はrfc1305のAppendixAなどをみると意味が分かると思います。
LI=0 Leap Indicator :0=no warning
VN=4 :version number
MODE=4 :4=server
Stratum=2
Poll=4 :Poll interval
Precision=-18

<(x)ntpdcなどのコマンド及び出力例について>

(x)ntpdcのコマンドについては、(x)ntpのアーカイブファイルの中のhtmlファイルに詳しい記述があります。ここではxntpdcの具体的出力を記しておきます。
なお、コマンドによっては省略形が可能です。
例:
xntpdc > peersとxntpdc> pe


stratum1となっているマシンの例
server01:~# ntpq -p
     remote           refid      st t when poll reach   delay   offset    disp
==============================================================================
 LOCAL(0)        LOCAL(0)         3 l    5   64  377     0.00    0.000   10.01
oGPS_JUPITER(2)  .JUPI.           0 l    3   16  377     0.00   -2.214    1.17
PPS同期していると「o」がつきます。

server01:~# xntpdc
xntpdc> pe
     remote           local      st poll reach  delay   offset    disp
=======================================================================
=LOCAL(0)        127.0.0.1        3   64  377 0.00000  0.000000 0.01001
*GPS_JUPITER(2)  127.0.0.1        0   16  377 0.00000 -0.002214 0.00117
時刻同期していてもこのコマンドの表示では「o」がつかないので注意が必要です。


stratum2となっているマシンの例
pc02:~# ntpq -p
     remote           refid      st t when poll reach   delay   offset    disp
==============================================================================
 LOCAL(0)        LOCAL(0)         3 l   19   64  377     0.00    0.000   10.01
*pc03.sato_local .JUPI.           1 u  674 1024  377     1.51   -0.916    2.12

pc02:~# xntpdc
xntpdc> pe---ntpq -pと同様の結果が得られますが、桁の取り方がs単位になっています。
     remote           local      st poll reach  delay   offset    disp
=======================================================================
=LOCAL(0)        127.0.0.1        3   64  377 0.00000  0.000000 0.01001
*pc03.sato_local 192.168.1.2      1 1024  377 0.00151 -0.000916 0.00212

xntpdc> sysinfo---rfc1305 AppendixAなどを見ると更に詳しく内容が分かるようです。
system peer:          pc03.sato_local.nakano.tokyo.jp
system peer mode:     sym_active
leap indicator:       00
stratum:              2
precision:            -16---2のべき乗 2^-16=0.0000152587890625
root distance:        0.00151 s---peで表示されるdelayと同様の値
root dispersion:      0.01114 s---結構変動します。
reference ID:         [192.168.1.103]---TimeServer(pc03)のIPアドレス
reference time:       bf2a57ac.6d1bb000  Mon, Aug 20 2001  0:20:12.426
system flags:         auth monitor pll stats---ntp.confの設定に依存します。
frequency:            -16.000 ppm
stability:            10.129 ppm
broadcastdelay:       0.003906 s
authdelay:            0.000122 s

xntpdc> listpeers
client    LOCAL(0)
sym_active pc03.sato_local.nakano.tokyo.jp---sysinfoと同様の情報

xntpdc> showpeer pc03_sato---時刻ソースとなっているサーバー名を指定します。
remote 192.168.1.103, local 192.168.1.2
hmode sym_active, pmode mode#255, stratum 1, precision -17---サーバーのprecision等を示しています。
leap 00, refid [JUPI], rootdistance 0.00000, rootdispersion 0.00415
ppoll 10, hpoll 10, keyid 0, version 3, association 15709
valid 8, reach 377, unreach 0, flash 000, boffset 0.00391, ttl/mode 0
timer 780s, flags system_peer, config, bclient
reference time:      bf2a5fab.0171f362  Mon, Aug 20 2001  0:54:19.005
originate timestamp: bf2a5fac.7ee3a000  Mon, Aug 20 2001  0:54:20.495
receive timestamp:   bf2a5fac.7e6bd000  Mon, Aug 20 2001  0:54:20.493
transmit timestamp:  bf2a5fac.7dff6000  Mon, Aug 20 2001  0:54:20.492
filter delay:  0.00153  0.00150  0.00151  0.00151
               0.00151  0.00151  0.00150  0.00151
filter offset: 0.002594 -0.00089 -0.00091 0.001190
               0.002013 -0.00220 -0.00012 0.002192
filter order:  0        1        2        3
               4        5        6        7
offset 0.002594, delay 0.00153, dispersion 0.00302, selectdisp 0.00000


xntpdc> pstats pc03_sato---時刻ソースとなっているサーバー名を指定します。
remote host:          pc03.sato_local.nakano.tokyo.jp
local interface:      192.168.1.2
time last received:   284s
time until next send: 740s
reachability change:  372332s
packets sent:         1122
packets received:     1122
bad authentication:   0
bogus origin:         0
duplicate:            0
bad dispersion:       8
bad reference time:   0
candidate order:      1

xntpdc> loopinfo
offset:               0.000531 s
frequency:            12.113 ppm
poll adjust:          30
watchdog timer:       348 s

xntpdc> sysstats
system uptime:          372537
time since reset:       372537
bad stratum in packet:  0
old version packets:    1
new version packets:    1665
unknown version number: 0
bad packet length:      0
packets processed:      1613
bad authentication:     0
limitation rejects:     0

xntpdc> memstats
time since reset:     372563
total peer memory:    15
free peer memory:     13
calls to findpeer:    1614
new peer allocations: 0
peer demobilizations: 491
hash table counts:      0   1   0   0   0   0   1   0
                        0   0   0   0   0   0   0   0
                        0   0   0   0   0   0   0   0
                        0   0   0   0   0   0   0   0


xntpdc> iostats
time since reset:      372496
receive buffers:      10
free receive buffers: 9
used receive buffers: 0
low water refills:    0
dropped packets:      0
ignored packets:      0
received packets:     1665
packets sent:         1678
packets not sent:     0
interrupts handled:   1665
received by int:      1665

xntpdc> timerstats
time since reset:  372597
alarms handled:    0
alarm overruns:    0
calls to transmit: 6944