64d5324fe8999d5684eabeb11f4f2cdadae1f3b1
[dragonfly.git] / usr.sbin / timed / SMM.doc / timed / timed.ms
1 .\" $FreeBSD: src/usr.sbin/timed/SMM.doc/timed/timed.ms,v 1.1.1.1.14.1 2000/11/23 10:18:38 ru Exp $
2 .\" $DragonFly: src/usr.sbin/timed/SMM.doc/timed/timed.ms,v 1.2 2003/06/17 04:30:03 dillon Exp $
3 .\"
4 .\" Copyright (c) 1986, 1993
5 .\"     The Regents of the University of California.  All rights reserved.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\"    notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\"    notice, this list of conditions and the following disclaimer in the
14 .\"    documentation and/or other materials provided with the distribution.
15 .\" 3. All advertising materials mentioning features or use of this software
16 .\"    must display the following acknowledgement:
17 .\"     This product includes software developed by the University of
18 .\"     California, Berkeley and its contributors.
19 .\" 4. Neither the name of the University nor the names of its contributors
20 .\"    may be used to endorse or promote products derived from this software
21 .\"    without specific prior written permission.
22 .\"
23 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .\" SUCH DAMAGE.
34 .\"
35 .\"     @(#)timed.ms    8.1 (Berkeley) 6/8/93
36 .\"
37 .TL
38 The Berkeley
39 .UX
40 .br
41 Time Synchronization Protocol
42 .AU
43 Riccardo Gusella, Stefano Zatti, and James M. Bloom
44 .AI
45 Computer Systems Research Group
46 Computer Science Division
47 Department of Electrical Engineering and Computer Science
48 University of California, Berkeley
49 Berkeley, CA 94720
50 .FS
51 This work was sponsored by the Defense Advanced Research Projects Agency
52 (DoD), monitored by the Naval Electronics Systems
53 Command under contract No. N00039-84-C-0089, and by the Italian CSELT 
54 Corporation.
55 The views and conclusions contained in this document are those of the
56 authors and should not be interpreted as representing official policies,
57 either expressed or implied, of the Defense Research Projects Agency,
58 of the US Government, or of CSELT.
59 .FE
60 .LP
61 .OH 'The Berkeley UNIX Time Synchronization Protocol''SMM:12-%'
62 .EH 'SMM:12-%''The Berkeley UNIX Time Synchronization Protocol'
63 .SH 
64 Introduction
65 .PP
66 The Time Synchronization Protocol (TSP) 
67 has been designed for specific use by the program \fItimed\fP,
68 a local area network clock synchronizer for 
69 the UNIX 4.3BSD operating
70 system.
71 Timed is built on the DARPA UDP protocol [4] and
72 is based on a master slave scheme.
73 .PP
74 TSP serves a dual purpose.
75 First, it supports messages for the synchronization of the clocks 
76 of the various hosts in a local area network.
77 Second, it supports messages for the election that occurs
78 among slave time daemons when, for any reason, the master disappears.
79 The synchronization mechanism and the election procedure 
80 employed by the program timed are described 
81 in other documents [1,2,3].
82 .PP
83 Briefly, the synchronization software, which works in a 
84 local area network, consists of a collection of \fItime daemons\fP
85 (one per machine) and is based on a master-slave
86 structure.
87 The present implementation keeps processor clocks synchronized 
88 within 20 milliseconds.
89 A \fImaster time daemon\fP measures the time
90 difference between the clock of the machine on which it 
91 is running and those of all other machines.  The current implementation
92 uses ICMP \fITime Stamp Requests\fP [5] to measure the clock difference
93 between machines.
94 The master computes the \fInetwork time\fP as the average of the 
95 times provided by nonfaulty clocks.\**
96 .FS
97 A clock is considered to be faulty when its value 
98 is more than a small specified
99 interval apart from the majority of the clocks 
100 of the machines on the same network.
101 See [1,2] for more details.
102 .FE
103 It then sends to each \fIslave time daemon\fP the
104 correction that should be performed on the clock of its machine.
105 This process is repeated periodically.
106 Since the correction is expressed as a time difference rather than an 
107 absolute time, transmission delays do not interfere with synchronization.
108 When a machine comes up and joins the network,
109 it starts a slave time daemon, which
110 will ask the master for the correct time and will reset the machine's clock
111 before any user activity can begin.
112 The time daemons therefore maintain a single network time in spite of 
113 the drift of clocks away from each other. 
114 .PP
115 Additionally, a time daemon on gateway machines may run as 
116 a \fIsubmaster\fP.
117 A submaster time daemon functions as a slave on one network that
118 already has a master and as master on other networks.
119 In addition, a submaster is responsible for propagating broadcast
120 packets from one network to the other.
121 .PP
122 To ensure that service provided is continuous and reliable,
123 it is necessary to implement an election algorithm that will elect a
124 new master should the machine running the current master crash, the master
125 terminate (for example, because of a run-time error), or the network be
126 partitioned.
127 Under our algorithm, slaves are able to realize when the master has
128 stopped functioning and to elect a new master from among themselves.
129 It is important to note that since the failure of the master results
130 only in a gradual divergence of clock values, the election
131 need not occur immediately.
132 .PP
133 All the communication occurring among time daemons uses the TSP
134 protocol.
135 While some messages need not be sent in a reliable way,
136 most communication in TSP requires reliability not provided by the underlying
137 protocol.
138 Reliability is achieved by the use of acknowledgements, sequence numbers, and
139 retransmission when message losses occur.
140 When a message that requires acknowledgment is not acknowledged after
141 multiple attempts,
142 the time daemon that has sent the message will assume that the
143 addressee is down.
144 This document will not describe the details of how reliability is
145 implemented, but will only point out when
146 a message type requires a reliable transport mechanism.
147 .PP
148 The message format in TSP is the same for all message types;
149 however, in some instances, one or more fields are not used. 
150 The next section describes the message format.
151 The following sections describe
152 in detail the different message types, their use and the contents
153 of each field.  NOTE:  The message format is likely to change in
154 future versions of timed.
155 .sp 2
156 .SH
157 Message Format
158 .PP
159 All fields are based upon 8-bit bytes.  Fields should be sent in
160 network byte order if they are more than one byte long.
161 The structure of a TSP message is the following:
162 .IP 1)
163 A one byte message type.
164 .IP 2)
165 A one byte version number, specifying the protocol version which the
166 message uses.
167 .IP 3)
168 A two byte sequence number to be used for recognizing duplicate messages
169 that occur when messages are retransmitted.
170 .IP 4)
171 Eight bytes of packet specific data.  This field contains two 4 byte time
172 values, a one byte hop count, or may be unused depending on the type
173 of the packet.
174 .IP 5)
175 A zero-terminated string of up to 256 \s-2ASCII\s+2 characters with the name of 
176 the machine sending the message.
177 .PP
178 The following charts describe the message types,
179 show their fields, and explain their usages.
180 For the purpose of the following discussion, a time daemon can 
181 be considered to be in
182 one of three states: slave, master, or candidate for election to master.
183 Also, the term \fIbroadcast\fP refers to
184 the sending of a message to all active time daemons.
185 .sp 1
186 .SH
187 Adjtime Message
188 .so time
189 .LP
190 Type: TSP_ADJTIME (1)
191 .sp 1
192 .PP
193 The master sends this message to a slave to communicate 
194 the difference between 
195 the clock of the slave and
196 the network time the master has just computed. 
197 The slave will accordingly
198 adjust the time of its machine.
199 This message requires an acknowledgment.
200 .sp 1
201 .SH
202 Acknowledgment Message
203 .so unused
204 .LP
205 Type: TSP_ACK (2)
206 .sp 1
207 .PP
208 Both the master and the slaves use this message for
209 acknowledgment only.
210 It is used in several different contexts, for example
211 in reply to an Adjtime message.
212 .sp 1
213 .SH
214 Master Request Message
215 .so unused
216 .LP
217 Type: TSP_MASTERREQ (3)
218 .sp 1
219 .PP
220 A newly-started time daemon broadcasts this message to
221 locate a master.  No other action is implied by this packet.
222 It requires a Master Acknowledgment.
223 .sp 1
224 .SH
225 Master Acknowledgement
226 .so unused
227 .LP
228 Type: TSP_MASTERACK (4)
229 .sp 1
230 .PP
231 The master sends this message to acknowledge the Master Request message
232 and the Conflict Resolution Message.
233 .sp 1
234 .SH
235 Set Network Time Message
236 .so date
237 .LP
238 Type: TSP_SETTIME (5)
239 .sp 1
240 .PP
241 The master sends this message to slave time daemons to set their time.
242 This packet is sent to newly started time daemons and when the network
243 date is changed.
244 It contains the master's time as an approximation of the network time.
245 It requires an acknowledgment.
246 The next
247 synchronization round will eliminate the small time difference
248 caused by the random delay in the communication channel.
249 .sp 1
250 .SH
251 Master Active Message
252 .so unused
253 .LP
254 Type: TSP_MASTERUP (6)
255 .sp 1
256 .PP
257 The master broadcasts this message to 
258 solicit the names of the active slaves.
259 Slaves will reply with a Slave Active message.
260 .sp 1
261 .SH
262 Slave Active Message
263 .so unused
264 .LP
265 Type: TSP_SLAVEUP (7)
266 .sp 1
267 .PP
268 A slave sends this message to the master in answer to a Master Active message.
269 This message is also sent when a new slave starts up to inform the master that
270 it wants to be synchronized.
271 .sp 1
272 .SH
273 Master Candidature Message
274 .so unused
275 .LP
276 Type: TSP_ELECTION (8)
277 .sp 1
278 .PP
279 A slave eligible to become a master broadcasts this message when its election
280 timer expires.
281 The message declares that the slave wishes to become the new master.
282 .sp 1
283 .SH
284 Candidature Acceptance Message
285 .so unused
286 .LP
287 Type: TSP_ACCEPT (9)
288 .sp 1
289 .PP
290 A slave sends this message to accept the candidature of the time daemon
291 that has broadcast an Election message.
292 The candidate will add the slave's name to the list of machines that it
293 will control should it become the master.
294 .sp 1
295 .SH
296 Candidature Rejection Message
297 .so unused
298 .LP
299 Type: TSP_REFUSE (10)
300 .sp 1
301 .PP
302 After a slave accepts the candidature of a time daemon, it will reply
303 to any election messages from other slaves
304 with this message.
305 This rejects any candidature other than the first received.
306 .sp 1
307 .SH
308 Multiple Master Notification Message
309 .so unused
310 .LP
311 Type: TSP_CONFLICT (11)
312 .sp 1
313 .PP
314 When two or more masters reply to a Master Request message, the slave
315 uses this message to inform one of them that more than one master exists.
316 .sp 1
317 .SH
318 Conflict Resolution Message 
319 .so unused
320 .LP
321 Type: TSP_RESOLVE (12)
322 .sp 1
323 .PP
324 A master which has been informed of the existence of other masters
325 broadcasts this message to determine who the other masters are.
326 .sp 1
327 .SH
328 Quit Message
329 .so unused
330 .LP
331 Type: TSP_QUIT (13)
332 .sp 1
333 .PP
334 This message is sent by the master in three different contexts:
335 1) to a candidate that broadcasts an Master Candidature message,
336 2) to another master when notified of its existence,
337 3) to another master if a loop is detected.
338 In all cases, the recipient time daemon will become a slave.
339 This message requires an acknowledgement.
340 .sp 1
341 .SH
342 Set Date Message
343 .so date
344 .LP
345 Type: TSP_SETDATE (22)
346 .sp 1
347 .PP
348 The program \fIdate\fP\|(1) sends this message to the local time daemon
349 when a super-user wants to set the network date.
350 If the local time daemon is the master, it will set the date;
351 if it is a slave, it will communicate the desired date to the master.
352 .sp 1
353 .SH
354 Set Date Request Message
355 .so date
356 .LP
357 Type: TSP_SETDATEREQ (23)
358 .sp 1
359 .PP
360 A slave that has received a Set Date message will communicate the
361 desired date to the master using this message.
362 .sp 1
363 .SH
364 Set Date Acknowledgment Message
365 .so unused
366 .LP
367 Type: TSP_DATEACK (16)
368 .sp 1
369 .PP
370 The master sends this message to a slave in acknowledgment of a
371 Set Date Request Message.
372 The same message is sent by the local time daemon to the program
373 \fIdate(1)\fP to confirm that the network date has been set by the
374 master.
375 .sp 1
376 .SH
377 Start Tracing Message
378 .so unused
379 .LP
380 Type: TSP_TRACEON (17)
381 .sp 1
382 .PP
383 The controlling program \fItimedc\fP sends this message to the local
384 time daemon to start the recording in a system file of
385 all messages received.
386 .sp 1
387 .SH
388 Stop Tracing Message
389 .so unused
390 .LP
391 Type: TSP_TRACEOFF (18)
392 .sp 1
393 .PP
394 \fITimedc\fP sends this message to the local
395 time daemon to stop the recording of
396 messages received.
397 .sp 1
398 .SH
399 Master Site Message
400 .so unused
401 .LP
402 Type: TSP_MSITE (19)
403 .sp 1
404 .PP
405 \fITimedc\fP sends this message to the local time daemon to find out
406 where the master is running.
407 .sp 1
408 .SH
409 Remote Master Site Message
410 .so unused
411 .LP
412 Type: TSP_MSITEREQ (20)
413 .sp 1
414 .PP
415 A local time daemon broadcasts this message to find the location
416 of the master.
417 It then uses the Acknowledgement message to 
418 communicate this location to \fItimedc\fP.
419 .sp 1
420 .SH
421 Test Message
422 .so unused
423 .LP
424 Type: TSP_TEST (21)
425 .sp 1
426 .PP
427 For testing purposes, \fItimedc\fP sends this message to a slave
428 to cause its election timer to expire.  NOTE: \fItimed\fP
429 is not normally compiled to support this.
430 .sp 1
431 .SH
432 .SH
433 Loop Detection Message
434 .so loop
435 .LP
436 Type: TSP_LOOP (24)
437 .sp 1
438 .PP
439 This packet is initiated by all masters occasionally to attempt to detect loops.
440 All submasters forward this packet onto the networks over which they are master.
441 If a master receives a packet it sent out initially,
442 it knows that a loop exists and tries to correct the problem.
443 .SH
444 References
445 .IP 1.
446 R. Gusella and S. Zatti, 
447 \fITEMPO: A Network Time Controller for Distributed Berkeley UNIX System\fP,
448 USENIX Summer Conference Proceedings, Salt Lake City, June 1984.
449 .IP 2.
450 R. Gusella and S. Zatti, \fIClock Synchronization in a Local Area Network\fP,
451 University of California, Berkeley, Technical Report, \fIto appear\fP.
452 .IP 3.
453 R. Gusella and S. Zatti, 
454 \fIAn Election Algorithm for a Distributed Clock Synchronization Program\fP,
455 University of California, Berkeley, CS Technical Report #275, Dec. 1985.
456 .IP 4.
457 Postel, J., \fIUser Datagram Protocol\fP, RFC 768.
458 Network Information Center, SRI International, Menlo Park, California,
459 August 1980.
460 .IP 5.
461 Postel, J., \fIInternet Control Message Protocol\fP, RFC 792.
462 Network Information Center, SRI International, Menlo Park, California,
463 September 1981.