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

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