home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / std_unix / proto.ms < prev    next >
Internet Message Format  |  1988-05-05  |  16KB

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