home *** CD-ROM | disk | FTP | other *** search
/ ftp.cse.unsw.edu.au / 2014.06.ftp.cse.unsw.edu.au.tar / ftp.cse.unsw.edu.au / pub / doc / standards / file_xfer / uucp next >
Encoding:
Internet Message Format  |  1992-10-18  |  15.6 KB

  1. From std-unix@longway.TIC.COM Sat May  7 18:49:12 1988
  2. Relay-Version: version B UNSW 1.1 19 Sep 1984; site elecvax.eecs.unsw.oz
  3. Path: elecvax!usage!basser!munnari!uunet!longway!std-unix
  4. From: std-unix@longway.TIC.COM (Moderator, John S. Quarterman)
  5. Newsgroups: comp.std.unix
  6. Subject: Re: UUCP protocol definition
  7. Message-ID: <186@longway.TIC.COM>
  8. Date: 3 May 88 23:49:00 GMT
  9. Date-Received: Sat, 7 May 88 07:44:02 AEST
  10. Approved: jsq@longway.tic.com (Moderator, John S. Quarterman)
  11. Reply-To: uunet!uts.amdahl.com!gam (Gordon Moffett)
  12. Lines: 635
  13.  
  14. From: uunet!uts.amdahl.com!gam (Gordon Moffett)
  15.  
  16. [ This is Greg Chesson's packet driver protocol (UUCP g protocol) paper
  17. that I posted a year ago.  It originally came from John Gilmore, who has
  18. since appended some useful code, thus this updated reposting.  -mod ]
  19.  
  20. .\" @(#) packet.driver.ms    Version hoptoad-1.4    88/03/24
  21. .\"
  22. .\" format this with [nt]roff -ms.
  23. .\"
  24. .\" From: greg@sgi.uucp (Greg Chesson)
  25. .\" Newsgroups: mod.std.unix
  26. .\" Volume-Number: Volume 9, Number 55
  27. .\" Subject: Packet Driver Protocol
  28. .\" Message-ID: <7136@ut-sally.UUCP>
  29. .\" Date: 11 Feb 87 23:44:09 GMT
  30. .\"
  31. .\" This message contains a copy of ``Packet Driver Protocol,''
  32. .\" written by G. L. Chesson while he was at Bell Laboratories.
  33. .\" He remarks that it was approved for public distribution, and that
  34. .\" 
  35. .\"     The version of the note that you probably have omits the
  36. .\"     detail that the transmitted checksum is really 0125252
  37. .\"     - the block checksum function.
  38. .\" 
  39. .\" [Note that 0125252 is 0xAAAA, which is easier to remember.
  40. .\" I have folded this update into the document. -- hoptoad!gnu]
  41. .\"
  42. .\" [I have also updated the checksum routine to include one that
  43. .\" works regardless of the size of a "short" or an "int". -- hoptoad!gnu]
  44. .ce
  45. .B
  46. Packet Driver Protocol
  47. .R
  48. .sp 1
  49. .ce
  50. G. L. Chesson
  51. .br
  52. .ce
  53. Bell Laboratories
  54. .SH
  55. Abstract
  56. .in +.5i
  57. .PP
  58. These notes describe the packet driver link
  59. protocol that was supplied
  60. with the
  61. Seventh Edition of
  62. .UX
  63. and is used by the UUCP program.
  64. .in -.5i
  65. .SH
  66. General
  67. .PP
  68. Information flow between a pair of machines
  69. may be regulated by
  70. first
  71. representing the data 
  72. as sequence-numbered 
  73. .I
  74. packets
  75. .R
  76. of data 
  77. and then establishing conventions that
  78. govern the use of sequence numbers.
  79. The
  80. .I
  81. PK,
  82. .R
  83. or
  84. .I
  85. packet driver,
  86. .R
  87. protocol
  88. is a particular instance of this type of
  89. flow-control discipline.
  90. The technique depends on the notion of a transmission
  91. .I
  92. window
  93. .R
  94. to determine upper and lower bounds for valid
  95. sequence numbers.
  96. The transmitter is allowed to retransmit packets
  97. having sequence numbers
  98. within the window until the receiver indicates that
  99. packets have been correctly received.
  100. Positive acknowledgement from the receiver moves the
  101. window;
  102. negative acknowledgement or no acknowledgement
  103. causes retransmission.
  104. The receiver must ignore duplicate transmission, detect
  105. the various errors that may occur,
  106. and inform the transmitter when packets are 
  107. correctly or incorrectly received.
  108. .PP
  109. The following paragraphs describe the packet formats,
  110. message exchanges,
  111. and framing
  112. used by the protocol as coded
  113. in the UUCP program and the
  114. .UX
  115. kernel.
  116. Although no attempt will be made here to present
  117. internal details of the algorithms that were used,
  118. the checksum routine is supplied
  119. for the benefit of other implementors.
  120. .SH
  121. Packet Formats
  122. .PP
  123. The protocol is defined in terms of message
  124. transmissions of 8-bit bytes.
  125. Each message includes one
  126. .I
  127. control
  128. .R
  129. byte plus a
  130. .I
  131. data segment
  132. .R
  133. of zero or more information bytes.
  134. The allowed data segment sizes range
  135. between 32 and 4096 as determined by the formula
  136. 32(2\uk\d) where
  137. k is a 3-bit number.
  138. The packet sequence numbers are likewise constrained
  139. to 3-bits; i.e. counting proceeds modulo-8.
  140. .PP
  141. The control byte is partitioned into three fields as
  142. depicted below.
  143. .bp
  144. .nf
  145. .sp 
  146. .in 1i
  147. .ls 1
  148. bit    7    6    5    4    3    2    1    0
  149.     t    t    x    x    x    y    y    y
  150. .ls 1
  151. .in -1i
  152. .fi
  153. .sp
  154. The
  155. .I
  156. t
  157. .R
  158. bits indicate a packet type and
  159. determine the interpretation to be placed on
  160. the
  161. .I
  162. xxx
  163. .R
  164. and
  165. .I
  166. yyy
  167. .R
  168. fields.
  169. The various interpretations are as follows:
  170. .in +1i
  171. .sp
  172. .nf
  173. .ls 1
  174. .I
  175. tt    interpretation
  176. .sp
  177. .R
  178. 00    control packet
  179. 10    data packet
  180. 11    `short' data packet
  181. 01    alternate channel
  182. .ls 1
  183. .fi
  184. .sp
  185. .in -1i
  186. A data segment accompanies all non-control packets.
  187. Each transmitter is constrained to observe the maximum
  188. data segment size
  189. established during initial synchronization by the
  190. receiver that it sends to.
  191. Type 10 packets have maximal size data segments.
  192. Type 11, or `short', packets have zero or more data
  193. bytes but less than the maximum.
  194. The first one or two bytes of the data segment of a
  195. short packet are `count' bytes that
  196. indicate the difference between the
  197. maximum size and the number of bytes in the short
  198. segment.
  199. If the difference is less than 127, one count
  200. byte is used.
  201. If the difference exceeds 127,
  202. then the low-order seven bits of the difference
  203. are put in the first data byte and the high-order
  204. bit is set as an indicator that the remaining
  205. bits of the difference are in the second byte.
  206. Type 01 packets are never used by UUCP
  207. and need not be discussed in detail here.
  208. .PP
  209. The sequence number of a non-control packet is
  210. given by the
  211. .I
  212. xxx
  213. .R
  214. field.
  215. Control packets are not sequenced.
  216. The newest sequence number,
  217. excluding duplicate transmissions,
  218. accepted by a receiver is placed in the
  219. .I
  220. yyy
  221. .R
  222. field of non-control packets sent to the
  223. `other' receiver.
  224. .PP
  225. There are no data bytes associated with a control packet,
  226. the
  227. .I
  228. xxx
  229. .R
  230. field is interpreted as a control message,
  231. and the
  232. .I
  233. yyy
  234. .R
  235. field is a value accompanying the control message.
  236. The control messages are listed below in decreasing priority.
  237. That is, if several control messages are to be sent,
  238. the lower-numbered ones are sent first.
  239. .in +1i
  240. .nf
  241. .ls 1
  242. .sp
  243. .I
  244. xxx    name        yyy
  245. .R
  246.  
  247. 1    CLOSE    n/a
  248. 2    RJ        last correctly received sequence number
  249. 3    SRJ        sequence number to retransmit
  250. 4    RR        last correctly received sequence number
  251. 5    INITC    window size
  252. 6    INITB    data segment size
  253. 7    INITA    window size
  254. .in -i
  255. .ls 1
  256. .fi
  257. .sp
  258. .PP
  259. The CLOSE message indicates that the communications channel
  260. is to be shut down.
  261. The RJ, or
  262. .I
  263. reject,
  264. .R
  265. message indicates that the receiver has detected an error
  266. and the sender should retransmit after using the 
  267. .I
  268. yyy
  269. .R
  270. field to update the window.
  271. This mode of retransmission is usually
  272. referred to as a
  273. `go-back-N' procedure.
  274. The SRJ, or
  275. .I
  276. selective reject,
  277. .R
  278. message carries with it the sequence number of
  279. a particular packet to be retransmitted.
  280. The RR, or
  281. .I
  282. receiver ready,
  283. .R
  284. message indicates that the receiver has detected
  285. no errors; the
  286. .I
  287. yyy
  288. .R
  289. field updates the sender's window.
  290. The INITA/B/C messages are used
  291. to set window and data segment sizes.
  292. Segment sizes are calculated by the formula
  293. 32(2\uyyy\d)
  294. as mentioned above,
  295. and window sizes may range between 1 and 7.
  296. .PP
  297. Measurements of the protocol running on communication
  298. links at rates up to 9600 baud showed that
  299. a window size of 2 is optimal
  300. given a packet size greater than 32 bytes.
  301. This means that the link bandwidth can be fully utilized
  302. by the software.
  303. For this reason the SRJ message is not as important as it
  304. might otherwise be.
  305. Therefore the
  306. .UX
  307. implementations no longer generate or respond to SRJ
  308. messages.
  309. It is mentioned here for historical accuracy only,
  310. and one may assume that SRJ is no longer part of the protocol.
  311. .SH
  312. Message Exchanges
  313. .SH
  314.     Initialization
  315. .PP
  316. Messages are exchanged between four cooperating
  317. entities: two senders and two receivers.
  318. This means that the communication channel is thought of
  319. as two independent half-duplex data paths.
  320. For example the window and segment sizes need not
  321. be the same in each direction.
  322. .PP
  323. Initial synchronization is accomplished
  324. with two 3-way handshakes: two each of
  325. INITA/INITB/INITC.
  326. Each sender transmits INITA messages repeatedly.
  327. When an INITA message is received, INITB is
  328. sent in return.
  329. When an INITB message is received
  330. .I
  331. and
  332. .R
  333. an INITB message has been sent,
  334. an INITC message is sent.
  335. The INITA and INITB messages carry 
  336. with them the packet and window size that
  337. each receiver wants to use,
  338. and the senders are supposed to comply.
  339. When a receiver has seen all three
  340. INIT messages, the channel is 
  341. considered to be open.
  342. .PP
  343. It is possible to design a protocol that starts up using
  344. fewer messages than the interlocked handshakes described above.
  345. The advantage of the more complicated design lies in its use as
  346. a research vehicle:
  347. the initial handshake sequence is completely symmetric,
  348. a handshake
  349. can be initiated by one side of the link while the
  350. connection is in use, and the software to do this can
  351. utilize code that would ordinarily be used only once
  352. at connection setup time.
  353. These properties were used in experiments with dynamically
  354. adjusted parameters.
  355. That is attempts were made to adapt the window and segment
  356. sizes to changes observed in traffic while a link was in use.
  357. Other experiments used the initial
  358. handshake  in a different way
  359. for restarting the protocol without data loss
  360. after machine crashes.
  361. These experiments never worked well in the packet driver and
  362. basically provided the impetus for other protocol designs.
  363. The result 
  364. as far as UUCP is concerned is that initial synchronization
  365. uses the two 3-way handshakes, and the INIT
  366. messages are ignored elsewhere.
  367. .SH
  368.     Data Transport
  369. .PP
  370. After initial synchronization each receiver
  371. sets a modulo-8 incrementing counter R to 0;
  372. each sender sets a similar counter S to 1.
  373. The value of R is always the number of the most recent
  374. correctly received packet.
  375. The value of S is always the first sequence number in
  376. the output window.
  377. Let W denote window size.
  378. Note that the value of W may be different for each sender.
  379. .PP
  380. A sender may transmit packets with sequence numbers
  381. in the range S to (S+W-1)\ mod-8.
  382. At any particular time a receiver expects
  383. arriving packets to have numbers in the range
  384. (R+1)\ mod-8 to (R+W)\ mod-8.
  385. Packets must arrive in sequence number order
  386. are are only acknowledged in order.
  387. That is,
  388. the `next' packet a receiver
  389. will acknowledge must have
  390. sequence number (R+1)\ mod-8.
  391. .PP
  392. A receiver acknowledges receipt of data packets
  393. by arranging for the value of its R counter to be
  394. sent across the channel
  395. where it will be used to update an S counter.
  396. This is done in two ways.
  397. If data is flowing in both directions across a
  398. channel then each receiver's current R value is
  399. carried in the
  400. .I
  401. yyy
  402. .R
  403. field of non-control packets.
  404. Otherwise when there is no bidirectional
  405. data flow,
  406. each receiver's R value is transmitted across the link
  407. as the
  408. .I
  409. yyy
  410. .R
  411. field of an RR control packet.
  412. .PP
  413. Error handling is up to the discretion
  414. of the receiver.
  415. It can ignore all errors in which case
  416. transmitter timeouts must provide for
  417. retransmission.
  418. The receiver may also generate RJ 
  419. error control packets.
  420. The
  421. .I
  422. yyy
  423. .R
  424. field of an incoming RJ message replaces
  425. the S value of the local sender and
  426. constitutes a request for retransmission to start
  427. at that sequence number.
  428. The
  429. .I
  430. yyy
  431. .R
  432. field of an incoming SRJ message selects a particular
  433. packet for retransmission.
  434. .PP
  435. The resemblance between the flow control procedure in the
  436. packet driver and that defined for X.25 is no accident.
  437. The packet driver protocol began life as an attempt at
  438. cleaning up X.25.
  439. That is why, for example,
  440. control information is uniform in length (one byte),
  441. there is no RNR message (not needed),
  442. and there is but one timeout defined
  443. in the sender.
  444. .SH
  445.     Termination
  446. .PP
  447. The CLOSE message is used to terminate communications.
  448. Software on either or both ends of the communication
  449. channel may initiate termination.
  450. In any case when one end wants to terminate it sends
  451. CLOSE messages until one is received from the other end
  452. or until a programmable limit on the number of CLOSE
  453. messages is reached.
  454. Receipt of a CLOSE message causes a CLOSE message to be sent.
  455. In the 
  456. .UX
  457. environment
  458. it also causes the SIGPIPE or
  459. `broken pipe' signal to be sent to
  460. the local process using the communication channel.
  461. .SH
  462.     Framing
  463. .PP
  464. The term
  465. .I
  466. framing
  467. .R
  468. is used to denote the technique by which the
  469. beginning and end of a message is detected
  470. in a byte stream;
  471. .I
  472. error control
  473. .R
  474. denotes the method by which transmission
  475. errors are detected.
  476. Strategies for framing and error control depend
  477. upon
  478. additional information being transmitted along
  479. with the control byte and data segment,
  480. and the choice of a particular strategy usually
  481. depends on characteristics of input/output
  482. devices and transmission media.
  483. .PP
  484. Several framing techniques are in used in support
  485. of PK protocol implementations,
  486. not all of which can be described in detail here.
  487. The technique used on asynchronous serial lines
  488. will be described.
  489. .PP
  490. A six byte
  491. framing
  492. .I
  493. envelope
  494. .R
  495. is constructed using the control byte
  496. C of a packet and five other bytes as
  497. depicted below.
  498. .in +1i
  499. <DLE><k><c0><c1><C><x>
  500. .in -1i
  501. The <DLE> symbol denotes the ASCII ctrl/P character.
  502. If the envelope is to be followed by a data segment,
  503. <k> has the value
  504. log\d2\u(size)-4;
  505. i.e. 1 \(<= k \(<= 8.
  506. If k is 9, then the envelope represents a control packet.
  507. The <c0> and <c1> bytes are the low-order and high-order
  508. bytes respectively of 0xAAAA minus a 16-bit checksum.
  509. For control packets, this 16-bit checksum is the same
  510. as the control byte C.
  511. For data packets, the checksum is calculated by the 
  512. program below.
  513. The <x> byte is the exclusive-or of <k><c0><c1><C>.
  514. Error control is accomplished by checking 
  515. a received framing envelope for compliance with the definition,
  516. and comparing a checksum function of the data segment
  517. with <c0><c1>.
  518. .PP
  519. This particular framing strategy assumes data segments
  520. are constant-sized:
  521. the `unused' bytes in a short packet are actually
  522. transmitted.
  523. This creates a certain amount of overhead which
  524. can be eliminated by a more complicated framing technique.
  525. The advantage of this strategy is that i/o
  526. devices can be programmed to take advantage of the
  527. constant-sized framing envelopes and data segments.
  528. .bp
  529. .PP
  530. The checksum calculation is displayed below as a C function.
  531. Note that the code is not truly portable because
  532. the definitions of
  533. .I short
  534. and
  535. .I char
  536. are not necessarily uniform across all machines
  537. that might support this language.
  538. This code assumes that
  539. .I short
  540. and
  541. .I char
  542. are 16 and 8-bits respectively.
  543. .PP
  544. .in +.5i
  545. .nf
  546. .ft CW
  547. .ls 1
  548. /* [Original document's version corrected to actual version] */
  549. chksum(s,n)
  550. register char *s;
  551. register n;
  552. {
  553.     register short sum;
  554.     register unsigned short t;
  555.     register short x;
  556.  
  557.     sum = -1;
  558.     x = 0;
  559.  
  560.     do {
  561.         if (sum<0) {
  562.             sum <<= 1;
  563.             sum++;
  564.         } else
  565.             sum <<= 1;
  566.         t = sum;
  567.         sum += (unsigned)*s++ & 0377;
  568.         x += sum^n;
  569.         if ((unsigned short)sum <= t) {
  570.             sum ^= x;
  571.         }
  572.     } while (--n > 0);
  573.  
  574.     return(sum);
  575. }
  576.  
  577. .fi
  578. .in -.5i
  579. .ft
  580. The checksum routine used in gnuucp has been updated to avoid depending
  581. on the particular sizes of 
  582. .I char
  583. and
  584. .I short
  585. variables.  As long as a
  586. .I char
  587. holds 8 bits or more, and a
  588. .I short
  589. holds 16 bits or more, the code will work.
  590. To test it, uncomment the ``#define short long'' below.
  591. A good compiler produces the same code from this function as from
  592. the less portable version.
  593. .PP
  594. .in +.5i
  595. .nf
  596. .ft CW
  597. .ls 1
  598. #define    HIGHBIT16    0x8000
  599. #define    JUST16BITS    0xFFFF
  600. #define    JUST8BITS    0x00FF
  601. #define    MAGIC        0125252        /* checksum is subtracted from this */
  602.  
  603. int
  604. pktchksum(msg, bytes)
  605.     unsigned char *msg;
  606.     int bytes;
  607. {
  608.     return (JUST16BITS &
  609.         (MAGIC - (chksum(&msg[6], bytes) ^ (JUST8BITS & msg[4]))));
  610.     
  611. }
  612.  
  613.  
  614. int
  615. chksum(s,n)
  616. register unsigned char *s;
  617. register n;
  618. {
  619. /* #define short long    /* To make sure it works with shorts > 16 bits */
  620.     register short sum;
  621.     register unsigned short t;
  622.     register short x;
  623.  
  624.     sum = (-1) & JUST16BITS;
  625.     x = 0;
  626.     do {
  627.         /* Rotate "sum" left by 1 bit, in a 16-bit barrel */
  628.         if (sum & HIGHBIT16)
  629.         {
  630.             sum = (1 + (sum << 1)) & JUST16BITS;
  631.         }
  632.         else
  633.             sum <<= 1;
  634.         t = sum;
  635.         sum = (sum + (*s++ & JUST8BITS)) & JUST16BITS;
  636.         x += sum ^ n;
  637.         if ((unsigned short)sum <= t)
  638.             sum = (sum ^ x) & JUST16BITS;
  639.     } while (--n > 0);
  640.  
  641.     return(sum);
  642. #undef short        /* End of debugging check */
  643. }
  644. .fi
  645. .in -.5i
  646. .ft
  647.  
  648. Volume-Number: Volume 14, Number 13
  649.