Consolidate license copies
[its.git] / sysdoc / chaord.57
1 Copyright (c) 1999 Massachusetts Institute of Technology
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 3 of the License, or (at
6 your option) any later version.
7
8 This program is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 ------------------------------
17
18 ;skip 1
19 ;list
20 ;lftmar 350
21 ;kset 20fg
22 \f
23                                 CHAOS   ORDER
24
25                                **** DRAFT ****
26 NOTES:
27 Work more on dynamic flow control, see end of that section.
28 Data grams seem to have a bug that the two parties can never
29  agree on whether they both agree that it really happened.  Am I losing?
30 Flush cruft at end?
31 Add QES, which is the same as RFC but implies you expect ANS?  Any point to it?
32 For ITS, a flavor of listening which queues RFCs coming in while index is busy,
33  or otherwise avoids that timing problem.
34 -------
35 This table of contents has not been kept up to date *******
36
37         Goals
38         Non-goals
39         Hardware Assumptions and Constraints
40
41 User appearance
42
43         Connections
44         Contact Names
45         ITS implementation
46         Lisp Machine implementation
47
48 Network Control Program
49
50         Packets
51         Hosts attached to more than one subnet
52         Subnet and Host numbers
53         Packet numbers
54         Indices
55         Routing
56         Operations
57         Table of packet field use vs opcode
58         Flow and Error Control
59         Dynamic Window-size Adjustment
60         Uniquization
61         Media Handlers
62         Buffers
63         ITS System Calls
64
65 Comparison with LCSNET
66         Principle differences
67         High priority data packets, interrupts, and flushing
68         Data grams
69         Multiple messages per packet
70         Checksums in the packet
71         Host-independent user-level protocols
72         Very Small Hosts
73
74 Transmission Media
75
76         Ethernet
77         TEN11 Interface
78         DL10 & DTE20
79         Asynchronous line
80
81 Higher-Level Protocols
82
83         Telnet
84         File Access
85         Mail
86         Locate-named-service
87 \f
88 >Goals
89
90 High speed communication between processes running in various local machines.
91 By "high speed", I mean much faster than the Arpanet.
92 At least comparable to TU20 magtape (30000 characters/second),
93 about 10 times the speed of the Arpanet.
94 (30-50 kcps seems to be the measured preformance, with ITS, 10/2/78)
95
96 No undetected errors in data transmission.
97
98 Not to depend on a particular medium.  (However, we are compromising
99 by picking a fixed packet size.  The simplicity and efficiency are worth it.)
100
101 Simple enough to put in small pdp11's.  Also, simple to the user.
102
103 As much power as the Arpanet but, hopefully, a lot less hair.
104
105 Work well for both "telnet" and "file transfer."
106
107 The initial implementation in ITS should have the "in-system" part as
108 small and simple as possible.  This includes no per-host tables
109 in the NCP, which allows large nets and easy reconfiguration.
110 There is, of course, a host-name to address translation table
111 used by "user" programs.  The NCP has to have a per-subnet table
112 which remembers where the bridge(s) to that subnet from
113 the local subnet are.
114
115 The acknowledgement protocol must be designed not to limit
116 performance.
117
118 Statistical flow control ((see below.))
119
120 Avoid bottlenecks such as the Arpanet "control link".  Be immune
121 to transmission medium failures which cause deleted, duplicated,
122 or out-of-order packets.
123
124
125 >Non-goals
126
127 Byte sizes other than 8 bits.  (pdp10 binary transmission should
128 be part of a user-level file-transfer/ML-device protocol.)
129
130 Compatibility with the Arpanet.
131
132 Substituting for TEN11 interface functions such as running
133 the AI TV11 and XGP.
134
135 Automatic routing will be deferred.  Initially the routing
136 tables will be assembled into the programs.  A host needs
137 one routing table for each subnet it is connected to
138 (or one for each network interface it possesses.)
139
140
141 >Hardware Assumptions and Constraints
142
143 Transmission is physically in "packets" which have headers, rather
144 than in, e.g., continuous streams.
145
146 The chaos net (ether) interface limits the physical length
147 of a packet to 4097 bits including overhead bits.  The net result
148 is the maximum number of data bytes (excluding the header
149 defined by this protocol) in any packet is 488.  This limitation
150 will be extended to the whole network (to keep things simple).
151 However some provision will be made for a possible network-wide
152 packet-size expansion, which has already been done once.
153
154 All transmission media will be assumed to be highly-reliable
155 but not perfect; "perfect" reliability will be assured by having
156 the two ends of a connection use an acknowledgement protocol
157 which detects lost messages.  Transmission media are required
158 to lose any messages that they don't deliver intact.  (I.e. there
159 must be hardware checksums.)
160 \f
161 >User appearance
162
163 The network allows user processes in various machines to
164 communicate with each other in various ways, for instance,
165 in imitation of a terminal, or in imitation of a disk file
166 system.  These facilities are built on top of the basic
167 capability to send "packets" (a header plus some data in the
168 form of 8-bit bytes) through the network.  The network undertakes
169 never to lose or garble any packets, except when the connection
170 is cut off entirely.
171
172 This document defines the low-level, "in-system" part of the
173 protocol.  On top of this, special programs (running in user-mode)
174 will implement the higher-level protocol that the general user
175 program sees.  These protocols and programs won't be discussed
176 further in this document, but remember that the strange packet
177 formats and so forth are not seen by most user programs.
178
179 >>Connections
180
181 When two processes wish to communicate, they establish a
182 connection between them.  This connection allows two streams
183 of packets to flow, one in each direction.  [Explain why
184 connections should be bi-directional rather than uni-directional.
185 Basically that's what you always want, and it makes things simpler.]
186
187 Connections are essentially the only facility provided by the network.
188 However, when first establishing the connection it is necessary
189 for the two processes to contact each other, and make each
190 other known to their respective operating systems.  In addition,
191 it is often the case (in the usual user-server situation) that
192 one of the processes does not exist beforehand, but is to be created
193 and made to run a specified program.
194
195 >>Contact Names
196
197 The way we choose to implement contacting is to say that one process
198 is always a "user" and one process is always a "server".  The server
199 has some "contact name" to which it "listens".  The user requests its
200 operating system to connect it to a specified contact name at a
201 specified host.  If a process at that host is listening to that
202 contact name, the two are connected.  If no one is listening to that
203 contact name, the operating system must create a server process
204 which will load itself with the appropriate program and connect up.
205
206 Discovering which host to connect to to obtain a given service
207 is an issue for higher-level protocols.  It will not be dealt
208 with at all initially (that is, there will be a table of host
209 names and numbers and the user will have to enter the name.)
210
211 Once the connection has been established, there is no more need for
212 the contact name, and it is discarded.  Indeed, often the contact name
213 is simply the name of a network protocol (such as "telnet") and several
214 users may want to have connections to that service at the same time,
215 so contact names must be "reusable."  (In the other common case, the
216 contact name will be a "gensym".)
217
218 As far as the operating systems involved are concerned, contact names
219 are simply arbitrary ascii strings defined by user programs.  It is
220 expected that the various higher-level protocols will define standard
221 contact names; for instance, to get the telnet protocol one would
222 connect to "telnet"; to get the file transfer protocol one would
223 connect to "file-transfer".  If a machine receives a request to connect
224 to a contact name which no one is currently listening to, a server
225 process must be created and made to execute a program which decides,
226 from the contact name, what server program to load and execute, or else
227 to refuse the request for connection. 
228
229 Contact names have no relation to file names; they are simply
230 a device for introducing two processes to each other.  If one was
231 using the network to transfer a file, one would first contact
232 the file transfer server at the appropriate host, then send a
233 packet containing the name of the file to be accessed.
234
235
236 >>ITS system calls
237
238 Ordinary user programs will not access the network directly; they will
239 go indirectly through a job-device or sty-type program which will
240 use a higher-level protocol to make the network look like what the
241 user wants, the traditional things being a terminal and a disk
242 file system.
243
244 Since these intermediate user-mode programs for using the network will
245 exist, there is no reason for the interface to the low level network
246 provided by the system to look at all like a standard device. Instead,
247 it will be designed solely for simplicity and ease of implementation,
248 and for a certain degree of efficiency.  This interface will be
249 described after the interface between Network Control Programs in
250 different machines (the low-level protocol) is described.
251
252 At some future time the intermediate programs might get moved into the
253 system for reasons of efficiency, but that should not be allowed to
254 complicate the initial implementation.
255
256 As of October 1978, the opening and closing of connections is completely
257 device-dependent, as are "status"-type operations, however byte-string
258 I/O is supported in a fashion which is device-independent except when
259 errors occur, which is handy in several programs.  Packet-level,
260 device-dependent I/O is also supported.
261
262 The .INSRT-able file of routines NETWRK, will be augmented to handle
263 both the Chaos net and the Arpa net.
264
265
266 >>Lisp Machine implementation
267
268 In the case of the Lisp Machine, the only distinction between user
269 programs and system programs is who maintains and documents them,
270 and how carefully.
271
272 (More?)
273 \f
274 >Network Control Program
275
276 This is the part of the operating system(s) that implements the network
277 (obviously).
278
279 >>Packets
280
281 The NCP's operate by exchanging packets.  A packet consists of a
282 header containing control information, and zero or more 8-bit bytes of
283 data. Hardware restrictions of the Chaos net interface
284 restrict the maximum length of a packet to 253 16-bit words.  In fact,
285 we will limit it to 252 words (to make packet buffers in pdp10's be 128
286 words including two overhead words).  Again for the convenience of
287 pdp10's, the header should be an even number of 16-bit words.
288
289 In this section the packets will be described as they look to a pdp11. 
290 They look the same inside a Lisp Machine, since the byte structure is the
291 same.  Inside a pdp10, packets are stored with two 16-bit words
292 left-adjusted in each pdp10 word. Additionally, the bytes in the data
293 portion of the packet are swapped so as to put them in pdp10 standard
294 order.  pdp11's that act as network interfaces for pdp10's will be required
295 to do this byte swapping since they're likely to have more time available
296 than the 10 to do it in, and can also do it faster, having a special
297 instruction for it.  pdp10's that communicate directly to the network will
298 have hardware assistance for byte reshuffling in their interfaces.  See the
299 transmission media section for how packets are encapsulated during
300 transmission through the various media. 
301
302 The header is 8 16-bit words and contains the following fields:
303
304         -----------------------
305         |opcode(8) | unused(8)|
306         -----------------------
307         |fc(4) |  nbytes(12)  |
308         -----------------------
309         |  destination host # |
310         -----------------------
311         |  destination index  |
312         -----------------------
313         |    source host #    |
314         -----------------------
315         |    source index     |
316         -----------------------
317         |      packet #       |
318         -----------------------
319         |    ack packet #     |
320         -----------------------
321
322         opcode - tells the receiver of the packet how to interpret
323                 it.  See the Operations section below.
324                 This is 8 bits long.  The 128 opcodes with high
325                 order bit =0 are for NCP use.  The 128 with high
326                 order bit =1 are for user-program use.
327
328         unused  8 bits reserved for future use.
329
330         fc - forwarding count. 4 bits which count the number of times this 
331                 packet has been forwarded by bridges.  Initially this field
332                 is always generated as zero.  Each bridge increments it;
333                 if it overflows, there is assumed to be a loop
334                 and the packet is discarded.
335
336         nbytes - the number of 8-bit bytes of data in the data part.
337                 The maximum value of nbytes is 488.  The minimum is 0.
338                 This is 12 bits long to allow for 4K-bit packets.
339                 (Actually 12 bits is enough for up to 32K-bit packets.)
340
341         destination host #
342                 This is divided into two 8-bit fields.  The high
343                 byte specifies which subnet.  The low byte specifies
344                 which host on that subnet, and (on ethernet subnets)
345                 is identical to the hardware host number.  Neither
346                 field may be zero in a valid host number.
347
348         destination index - index for this connection assigned by the
349                 destination host's NCP.
350
351         source host # - see destination host #.
352
353         source index - index for this connection assigned by the
354                 source host's NCP.
355
356         packet # - an ascending reference number used in error and
357                 flow control (see below).
358
359         ack packet # - used in error and flow control (see below.)
360 \f
361 >>Hosts attached to more than one subnet
362
363 (This also applies to hosts with more than one interface to
364 the same subnet, if there ever are any.)
365
366 Such hosts ought to act as bridges.  That is, if a packet
367 is received which is not addressed to this host, it should
368 be sent back out, using this host's routing tables.  The
369 forwarding count should be used to prevent infinite loops
370 in the event of inconsistent forwarding tables in two bridges.
371
372 It is undesirable for a host to have more than one number.
373 So a host connected to multiple subnets should choose one
374 subnet as its "home", which is the address which is advertised
375 as that host.  The host's other network connections are
376 un-named bridges.  In some causes it may be preferable
377 not to pick a "home" subnet; instead, one invents a new
378 private subnet which only has that one host on it,
379 and all the host's network connections act as bridges
380 to that subnet (also to each other).
381
382 The routing should be set up so that packets destined for such
383 a host from a subnet on which it has an interface choose that
384 interface as the bridge to that host, so that in fact data flows
385 the same way as if the host had more than one number and the
386 host-name to host-number lookup magically chose the right number.
387
388
389 >>Subnet and host numbers.
390
391 Subnet numbers are arbitrary.  Host numbers are assigned according to
392 position on the cable, as explained (elsewhere).
393
394 These numbers may be found in the file SYSENG;HOSTS >
395
396 The physical cable address of a host should include both its subnet number
397 and its host number (prior to October 1978 the subnet field of a physical
398 address was always 0).  This allows the physical address to be used as
399 a unique machine identifier and makes it possible for a host to discover
400 its full 16-bit host address without prior knowledge.
401 \f
402 >>Packet numbers
403
404 Each time the sending user puts another packet into the network, this
405 number is increased by one.  (These numbers are independent for the
406 two directions of a connection.)  The receiver uses these numbers to
407 get the packets into order and ensure that there are no duplications
408 nor omissions.  The packet numbers are 16 bits and wrap around to zero
409 when they overflow.  When the connection is first opened, an initial
410 value for the packet# is established.  If it was 0, then the packet#
411 of the first data packet would be 1.
412
413 Packet #'s should be compared modulo 2**16.  On pdp11's, use
414
415         CMP A,B
416         BMI <A is less>         (BMI rather than BLT or BLO)
417
418 On pdp10's, use
419
420         SUB A,B
421         TRNE A,100000           (rather than CAMGE A,B)
422          JRST <A is less>
423
424 On Lisp machines, use
425
426         (AND (BITTEST 100000 (- A B))
427              <A is less>)       [rather than (AND (< A B) ...)]
428 \f
429 >>Indices
430
431 Each connection has two indices assigned to it, one at each end.  Each
432 index is an arbitrary 16-bit number assigned by the NCP at its end; usually
433 it is an index into that NCP's tables.  Indices are required to be
434 non-zero.  For maximum simplicity, all packets include both indices.  The
435 receiver of a packet uses the destination index to find out who to give the
436 packet to.  Generally the source index is used only for error checking, but
437 when a connection is first opened the source index has to be saved and used
438 as the destination index in future packets in the reverse direction.
439
440 To prevent packets somehow left over from old connections from
441 interfering with new connections, we require that a certain time
442 elapse between successive connections between the same pair of hosts
443 with the same index numbers at each end, this time to be longer than
444 the maximum time a packet is reasonably expected to sit around in
445 the network somewhere (the maximum transit time through all bridges, etc.)
446 This requirement is implemented by making part of the index number be
447 a "uniquizer"; when a host reuses a slot in its tables, it increments
448 the uniquizer, so that the index number for that slot is not the same
449 as it was previously.  Then if the uniquizer field is sufficiently wide,
450 and the rate of creation of connections (actually the rate of allocation
451 of indices) is sufficiently low, the requirement will be satisfied.
452 For the kind of network we're talking about, the time is a few tens of
453 seconds, and the uniquizer need only be a few bits wide.  It is up
454 to each host how wide it makes the uniquizer, depending on how big
455 it wants its tables to be.  It is best if table slots are also
456 allocated circularly, so that slots are reused at the minimum possible rate.
457
458 The uniquizer also serves to "more or less" uniquely identify connections
459 so that duplicate copies of a Request For Connection (RFC) packet
460 can be identified and discarded.
461
462 A user process's "capability" or "channel" to a connection, used by it
463 to ask the NCP to operate on that connection, simply contains the
464 appropriate index.
465
466 Associated with each index the NCP has a "state", the host # and index
467 # of the other end of the connection, some read buffers and associated
468 variables, including a current packet #, and some write buffers and
469 associated variables, again including a current packet #.
470
471 The "state" can be Closed (no connection or other activity currently
472 associated with this index), Open (this index has a connection to
473 another index at another machine), RFC-sent (requested another machine
474 for a connection, but no answer yet), Listen (listening for a request
475 for connection to a certain contact name), Broken (connection closed
476 abnormally by network or machine lossage), and RFC-received (waiting
477 for a server process to get going and pick up a request for connection
478 that came in).
479
480
481 >>Routing
482
483 This section is a place-holder.  Initially routing will be kludged with
484 a fixed table.  Once the network is set up automatic routing will
485 be put in.
486
487 The routing decision consists of looking at the destination subnet
488 field of a packet and deciding which interface (on a multi-interface
489 host) to transmit it on, i.e. what is the best route to that subnet.
490 In addition, if the destination is not on a subnet to which there
491 is a direct interface, one must determine what is the host number of
492 the bridge it should be sent to.
493
494 It also involves recognizing packets which are destined to the
495 current host and receiving them.
496
497
498 The following is not yet implemented.  It is an initial plan for routing.
499
500 Gaetways will broadcast RUT packets periodically, perhaps once a minute.
501 The destination field is zero and the source field is the address of the
502 gateway on the net on which the packet is being broadcasted.  The data field
503 contains a bunch of 16-bit words, divided into fields in the same way as
504 a host address.  The subnet field of each word contains the number of a
505 subnet which this gateway is able to reach.  The host field of each word
506 contains the hop count, which is 0 if the gateway is physically connected
507 to the specified (non-ether) subnet, 1 if the gateway is connected to
508 the specified (ether) subnet, or 1+ the hop count of the closer gateway
509 if this gateway indirects through another.  The hop counts allow the gateways
510 to avoid loops when there are multiple paths; they may not need to be
511 looked at by non-gateway hosts.
512
513 Each host maintains a routing table, with entries keyed by subnet number.
514 For subnets to which the host is physically connected, the entry points
515 to the host's physical interface.  For subnets which the host knows how to
516 get to because it has been informed of a gateway via a RUT packet, the entry
517 contains the gateway's host address, the hop count, and the time that this
518 route was last confirmed by a RUT packet.  If the NCP remembers only one
519 route to a given subnet, it wants to remember the one with the smallest
520 hop count unless that one is more than (say) 5 minutes old.  If the NCP
521 remembers all the routes, it should stop using ones which are more than
522 (say) 5 minutes old.  It is not clear that it should ever use one with
523 a hop count larger than the minimum.  The reason for the time-out is to
524 avoid forever losing packets by sending to a gateway which has gone down.
525 If there are no gateways up and known about by the NCP which reach a given
526 host, it will look like that host is down.
527 \f
528 >>Operations
529
530 This section tells what the values of the opcode field in a packet are, and
531 how an NCP responds to each one.
532
533 1    RFC - Request for Connection
534
535 This message is sent from user to server in order to open a
536 connection.  The data contains the contact name.  Actually, if
537 the data contains a space, the characters before the space are
538 the contact name and the characters after the space are "arguments".
539 This is done so that simple transactions can work (see below).
540
541 The destination index is zero, because it is not known yet.  The
542 responses are:
543
544         OPN, if a server process is found or created that wishes
545         to accept the request and open up a connection.
546
547         CLS, if the connection cannot be opened.  The data field
548         contains an ascii explanation of why not.
549
550         ANS, if a simple transaction is occuring.  The data contains
551         the answer, and no connection is ever created.
552
553         FWD, if there is no server process at this host, but there
554         might be a suitable one some place else.
555
556 There may also be no response, if the RFC was lost in the network, or
557 the destination host is down, or the reply was lost in the network. 
558
559 To increase the reliability of establishment of connections, RFC's and
560 OPN's are retransmitted, just as data packets are, until a response is
561 elicited.  CLS, ANS, and FWD cannot be retransmitted because we take
562 the position that retransmission is implemented by something associated
563 with a connection, and these packets are not sent by connections (and are
564 not acknowledged).  OPN is sent by a connection, and RFC is sent by
565 a sort of embryonic connection which continues to exist while it awaits
566 an OPN or other reply.
567
568 Since RFC is retransmitted, it is the responsibility of the NCP to detect
569 and discard duplicates.  When an RFC is received, all existing connections
570 in the OPN or RFC-RECEIVED state, and all "pending" RFC's which are awaiting
571 servers to connect to them (if the NCP has such), should be checked to see
572 if they have the same source host and index number as the received RFC.
573 If so, the RFC is a duplicate and should be ignored.  Note that connections
574 in the LOST, CLOSED, or BROKEN states should not be checked, since these
575 are not really connections as far as the foreign host is concerned, but simply
576 ghosts of connections left around to remember error status for their controlling
577 user programn.
578
579 Since the response to RFC is not guaranteed, processes issueing RFC's
580 must have timeouts.  In most implementations the normal host-down timeout
581 will suffice.
582
583 [We should discuss why the special kludgery for control packets, rather
584 than using the regular connection mechanism to assure reliable transmission
585 of control packets, as the Arpanet does.  Also a discussion of which control
586 operations inherently need reliability and which inherently don't, and
587 why that should be so.]
588
589 The packet # field contains the first packet # that will be assigned
590 to data transmitted from the user process, minus one modulo 2**16.  In
591 the simplest case, this can be zero, and the first packet sent will be
592 packet # 1.  One might also imagine uniquizing the packet numbers
593 as an extra error check, but this should not be necessary, because
594 the indices are uniquized, and connections must be explicitly agreed
595 to by each end before data can flow.
596
597
598 2    OPN - Connection Open
599
600 This is the positive acknowledgement to RFC.  The source index field
601 conveys the acknowledger's connection index to the requester.  The packet #
602 field contains the first packet # that will be assigned to data transmitted
603 from the server process, minus one modulo 2**16.  The data portion of this
604 packet is the same as a STS packet (see below), and mainly serves to convey
605 the server's window-size to the user.  The ack packet # field must contain
606 the usual value, i.e. the number that was sent in the packet # field of the RFC.
607 The receipt and ack in the OPN serve primarily to terminate retransmission of the RFC.
608
609 When an OPN is received, a STS is sent in response, telling the server
610 the user's window-size.  The exchange of an OPN and a STS also serves
611 as acknowledgement to each side that the other believes the connection
612 is open.  No data packets may be committed to the network until after
613 this has occurred.  If this rule was not followed, and packets happened
614 to get out of order, a data packet could arrive before the connection
615 was open and cause a LOS.
616
617 To improve the reliability of establishment of connections, OPN's are
618 retransmitted, just as data packets are, until receipted (and
619 acknowledged) by STS.  Because of this retransmission, the NCP must
620 detect and discard duplicate OPN's.  If an OPN is received for a connection
621 which exists and is not in the RFC-SENT state, the OPN should be ignored
622 and no LOS should be sent.
623
624 OPN's contain 16-bit data and are not byte-swapped.  See below under opcode 300.
625
626 3    CLS - Connection Closed
627
628 CLS is the negative response to RFC.  It indicates that no server was
629 listening to the contact name, and one couldn't be created, or for
630 some reason the server didn't feel like accepting this request for a
631 connection, or the destination NCP was unable to complete the
632 connection (e.g. connection table full.)  The destination index will
633 be the source index of the RFC.  The source index will be zero because
634 the NCP did not put this connection into its tables.  The data bytes,
635 if there are any, contain an ascii explanation.
636
637 CLS is also used to close a connection after it has been open for a while.
638 In the Arpanet, the NCP undertakes not to close the connection when the
639 user requests it, but waits until all data transfer has completed.  This is
640 a source of extra complexity, since data transfer may be hung up, there
641 have to be timeouts, there have to be connections waiting to be closed
642 which aren't owned by any user, etc.  It seems simpler to make CLS take
643 effect immediately, and let the user processes assure that data transfer
644 has been completed.  Note that telnet-like applications don't need it, and
645 ftp-like applications have to have it separately from closing anyway.
646
647 Since there is no error recovery or retransmission mechanism for CLS,
648 the use of CLS is necessarily optional.  However, it is desirable to
649 send a CLS when possible to decrease user confusion.
650
651 4    FWD - forward a request for connection
652
653 This is a response to RFC which indicates that the desired service
654 is not available at the process contacted, but may be available at
655 a possibly-different contact name at a possibly-different host.  The
656 data field contains the new contact name and the ack packet # field
657 contains the new host number.  The issuer of the RFC should issue
658 another RFC to that address.
659
660 5    ANS - answer to a simple transaction
661
662 Simple transactions are transactions which consist of a single question
663 (request) and a single answer (response).  They have no side effects,
664 so it is not necessary for either party to know whether the other party
665 thinks the transaction was completed or not.  Simple transactions need
666 no flow control and no error control, other than a timeout by the user
667 side to detect lost messages.  They are a simple, efficient way for
668 doing simple-minded things such as extracting information (such as the
669 time or a host name table) from a central server. 
670
671 A simple transaction is initiated by sending an RFC to a server which
672 happens to use simple transactions rather than full connections.  The
673 data field of the RFC consists of the contact name of the server,
674 optionally followed by a space and arguments to the request.  The
675 server responds by sending an ANS packet, whose data field is the
676 answer.  The destination address of the ANS comes from the source
677 address of the RFC.  The source address, packet #, and ack packet #
678 fields of the ANS are not used and should be zero. 
679
680 The difference between simple transactions (2 packets) and
681 full datagrams (4 packets) is that in the simple transaction the two
682 parties don't have to agree about whether or not the transaction
683 in fact took place, while in the full datagram they do, making
684 acknowledgement necessary.
685
686 The server of a simple transaction should be prepared to process
687 the transaction multiple times without error.  Simple transactions
688 should not have side effects which would be dangerous if repeated.
689
690 200-377 DATA - Transmits Data
691
692 The data portion of the packet is data being sent through the
693 connection.  The packet # is a number that increments by one for each
694 data packet sent in this direction on this connection.  This is used to
695 detect lost packets (which includes packets garbled in transmission and
696 packets lost in the statistical flow control scheme) and duplicated
697 packets (caused by lost or delayed acknowledges.  The NCP undertakes to
698 deliver the packets to the destination process in the same order that
699 they came from the source process, with no duplications and no
700 omissions.  Note that any opcode with the sign bit on is a data packet
701 as far as the NCP is concerned; if they wish, higher-level protocols
702 may use the opcode field to define various different kinds of data
703 packets.  Thus, what is herein called a data packet may be a "control"
704 packet to a higher-level protocol.  Normally, opcodes 200 and 300
705 should be used.  Opcodes 201-277 and 301-377 are to be used for special
706 purposes, as defined by higher-level protocols.
707
708 Opcodes 300-377 are defined to be "16-bit data".  Note that this does not
709 affect the byte count in the packet header; it is still a count of 8-bit
710 bytes.  The sole effect of 16-bit data is to prevent byte-swapping when
711 communicating with pdp10's; pdp10's store the 2 8-bit bytes in a 16-bit
712 "word" in the reverse of the network standard order (defined by pdp11's
713 and Lisp machines).  ((For purposes of 16-bit data, Interdata machines
714 are considered pdp10's.))
715
716 6    SNS - sense status
717
718 This packet is a request for a STS packet to be returned.  It is used for
719 "probing", see the section on flow and error control.
720
721 Note that, to avoid a timing error, a SNS received by a connection in the
722 RFC-sent state should be ignored.  This can happen if an OPN is transmitted
723 followed by a SNS and the packets get out of order.
724
725 SNS should not be transmitted on a connection that is not in the Open state.
726
727
728 7    STS - report status
729
730 STS is used for a variety of purposes.  It is the vehicle to carry an
731 acknowledgement, when no data packet is being sent on which the
732 acknowledge could be piggy-backed.  STS is used to set or change the
733 window size, to acknowledge opening of a connection, and to carry
734 receipts (see the flow control section.)  In the future STS will (may)
735 be used to carry information used in automatic window-size adjustment.
736 Like most packets, the ack packet# field of STS carries an
737 acknowledgement, the number of the last packet given to the user
738 process.  The first two bytes of the data field (low-order byte first)
739 carry a receipt, the number of the last packet guaranteed to be given
740 to the user process eventually.  The next 2 data bytes carry the window
741 size (low-order byte first).  Additional data bytes will be defined in
742 the future.
743
744 STS's contain 16-bit data and are not byte-swapped.  See above under opcode 300.
745
746 10   RUT - routing information
747
748 This packet type is reserved for the future, when automatic routing exists.
749
750 RUT's contain 16-bit data and are not byte-swapped.  See above under opcode 300.
751
752 11   LOS - you are losing
753
754 If a host receives a packet for a connection that does not exist (other
755 than RFC which isn't associated with a particular connection, LOS, and
756 CLS which is safe to ignore), it should return a LOS packet to the
757 source of the offending packet.  The source of the LOS should be the
758 destination of the offending packet, and the packet# and ack packet#
759 fields should be copied.  The data portion of a LOS contains an ascii
760 explanation of the problem.  A host receiving a LOS should break the
761 connection specified by the destination index and inform the associated
762 process that something has gone wrong.  It should make the LOS packet
763 available to that process so the explanation of the problem can be
764 read.
765
766 The LOS packet isn't actually necessary, since if the supposed other
767 end of a connection refuses to cooperate (i.e. never sends any
768 packets), after a while the NCP will give up, close the connection, and
769 inform the user that the foreign host appears to be dead.
770
771 For debugging, an echo feature is implemented as follows.  If you send
772 a packet with a data opcode and source and destination indices of 0,
773 it will be sent back as a LOS packet.  The data field will be destroyed
774 by the error explanation, but the packet # and ack packet # fields can
775 be used to remember any sequencing or checking information.
776
777 12   LSN - listen (never transmitted through the net, see below)
778
779 13   MNT - maintenance
780
781 Normal NCPs will discard MNT packets, without generating a LOS.  This packet
782 type is reserved for use by maintenance programs.  
783 \f
784 >>Table of packet field use vs opcode
785
786 The unused field is never used and must be zero, the forwarding count
787 field is always used in the same way, and the nbytes field is always
788 the length of the data.  Fields marked "0" below are don't care
789 rather than must be zero, but zero is certainly recommended.  The packet#
790 field of CLS, SNS, and STS would best be set the same as the packet# of
791 the next data packet to be sent (just as in RFC and OPN).
792
793          Destination       Source
794 Opcode  Host    Index   Host    Index    Packet#     Ack pk#    Data
795 ------  ----    -----   ----    -----    -------     -------    ----
796  RFC    usual     0     usual   usual   first - 1       0       contact name
797
798  OPN    usual   usual   usual   usual   first - 1     usual     0, window size
799
800  CLS    usual   usual   usual     0         0           0       reason
801
802  ANS    usual   usual   usual     0         0           0       answer
803
804  FWD    usual   usual   usual     0         0        new host   contact name
805
806  SNS    usual   usual   usual   usual       0         usual        0
807
808  STS    usual   usual   usual   usual       0         usual  receipt#, window size
809
810  LOS    src h   src i   dst h   dst i      pk#      ack pk #    reason
811
812  LSN      0       0       0       0         0           0       contact name
813
814 Data    usual   usual   usual   usual     usual       usual     data
815
816  MNT    completely nonstandard
817
818  RUT    completely nonstandard
819 \f
820 >>Flow and Error Control
821
822 The NCPs conspire to ensure that data packets are sent from user to
823 user with no duplications, omissions, or changes of order.
824 Secondarily, the NCPs attempt to achieve a maximum rate of flow of
825 data, and a minimum of overhead and retransmission.
826
827 The transmission medium is required to lose all damaged packets.  Therefore
828 error control reduces to retransmission of lost packets, plus immunity to
829 duplicated and out-of-sequence packets.
830
831 The following concepts must be explained:  the window, acknowledgement,
832 receipt, retransmission, and probing.
833
834 The window is the set of data packets "in the network" between the
835 sending process and the receiving process.  Conceptually the window
836 slides along as transmission proceeds.  When a packet is acknowledged,
837 that means that the window is to the right of that packet, since the
838 receiving process has gobbled that packet.  The window has a fixed size
839 to limit the amount of buffer space that is used up if the sender sends
840 faster than the receiver receives.  If the sending user process tries
841 to transmit more packets than the window size allows, it should be made
842 to wait until some packets have been acknowledged.  The window is made
843 sufficiently large to regulate how often acknowledgements must be
844 returned.  Note that the window includes only data packets, not
845 control packets.  Control packets are to be processed immediately
846 when they are received, and do not take up buffer space.  Separate
847 mechanisms are provided to deal with control packets being lost in
848 the network.
849
850 No sender is actually required to pay any attention to the window size.
851 No receiver is actually required to set the window size to something
852 reasonable.  However, those hosts that want to maximize performance
853 should do something about the window size.  The size is initially set
854 during the RFC/OPN/STS dialogue, presumably according to the type of
855 protocol being used.  An NCP may, if it chooses, dynamically adjust the
856 window size according to observed network behavior.  (See dynamic
857 window-size adjustment section below.)
858
859 An acknowledgement is a signal from a receiver to a sender that all
860 packets through packet number "n" have been given to the receiving
861 process, therefore the window should go from n+1 through n+window_size.
862 Note that acknowledgements can get out of order, so one should use
863 the maximum (mod 2^16) of all the acknowledgements ever received
864 as the start of the window.  Since acknowledgements are so common,
865 there is a field (ack packet #) in the data packet which allows
866 an acknowledgement to be "piggy-backed" on another packet.
867
868 A receipt is a signal from a receiver to a sender that all packets
869 through packet number "n" have been received successfully by the NCP
870 and are guaranteed to be delivered to the user process, therefore they
871 need not be retransmitted.  Note that acknowledgement implies receipt.
872 The separate receipt mechanism is supplied so that useless
873 retransmissions can be limited, when the data have been received but
874 cannot be acknowledged because the receiving process is being slow
875 about reading them.  The STS packet is used to send a
876 receipt.  Receipts are optional.
877
878 Retransmission is the process of sending all unreceipted data packets
879 in the sender's queue through the network to the receiver, except those
880 that were last sent very recently (within 1/30'th of a second in ITS.)
881 Retransmission occurs every 1/2 second, and when a STS packet is
882 received.  The idea of retransmission is to keep sending a packet until
883 it has been proven to have successfully reached its destination (by
884 receipt or acknowledgement.)  The reason retransmission occurs in
885 response to STS is so that a receiver may cause a faster retranmission
886 rate than twice a second, if it so desires.  Since STS carries a
887 receipt, and very-recently-transmitted packets are not retransmitted,
888 this should never cause useless retransmission.
889
890 A probe is the sending of a SNS packet, in the hope of eliciting
891 either a STS or a LOS, depending on whether the other side believes
892 in the connection.  Probing is used periodically as a way of testing
893 that the connection is still open, and also serves as a way to get STS
894 packets retransmitted as a hedge against the loss of an acknowledgement,
895 which could otherwise stymie the connection.
896
897 We probe every five seconds, on connections which have unacknowledged
898 packets outstanding (a non-empty window), and on connections which have
899 not received any packets for one minute.  If a connection receives no
900 packets for 1 1/2 minutes, this means that at least 5 probes have been
901 ignored, and the connection is declared to be broken.
902
903 The receiver generates STS packets under the following circumstances:
904 When a SNS is received (thus a response to a probe).  When a duplicate
905 packet is received, so that further useless retransmission will be
906 prevented by the receipt.  When the number of received but not
907 acknowledged packets is more than 1/3 the window size; evidently the
908 normal piggy-backed acknowledge mechanism is not working, so we
909 generate a STS to carry the acknowledge that will empty the window back
910 out, hopefully in time before transmission becomes clogged.  When the
911 window size changes (to tell the other end of the change).
912
913 When it is time to send a STS, we attempt to send one immediately.
914 If this fails (for instance, there might be no buffers available),
915 we keep trying to send one every half-second.
916
917 The receiver can also generate "spontaneous" STS's, to stimulate
918 retransmission or to carry an acknowledge, to keep things moving on
919 fast devices with insufficient buffering, such as the Gould printer.
920 This provides a way for the receiver to speed up the retransmission
921 timeout in the sender, and to make sure that acknowledges are happening
922 often enough.  For example, one might use a timer to generate a STS
923 every 1/10th of a second.
924
925 Note that spontaneous STS's should not be generated until the connection
926 is fully open.  This means that the server should not send STS until it
927 has gotten a STS back from its OPN.  STS's other than spontaneous ones
928 have no such problem.
929 \f
930 >>Host Status
931
932 All physical Chaosnet hosts, even gateways, are required to answer an
933 RFC with contact name STATUS and byte count 5 (no "arguments" allowed
934 in the data field of the packet) by returning an ANS packet whose data
935 field contains:  the name of the host in ascii, an octal 200 (any byte
936 with the sign bit on terminates the name), and additional status and
937 metering information to be defined later, perhaps in a site-dependent
938 way.  This makes it possible to write a program which determines the
939 status of all nodes in the network; the program could either be driven
940 by a host table or could try all possible host addresses; the NCP should
941 respond promptly to the STATUS RFC rather than starting up a program
942 to handle it, if starting up a program would take more than a second
943 or two.
944 \f
945 >>>Here is some narrative description of the NCP.
946
947 Each receiver (each end of each connection is a receiver, and also a
948 sender; think of receivers and senders as little actors inside the NCP)
949 has a list of buffers containing packets which have been successfully
950 received and are waiting to be read by the user process, and two
951 packet# variables.  One is the number of the last packet read by the
952 user process.  The other is the number of the last packet which has
953 been acknowledged.  If these two are not equal, the receiver needs to
954 send an acknowledgement "soon."
955
956 The received-packet list needs to be kept sorted by packet number, and
957 the NCP has to make sure that the user process does not see duplicates
958 or omissions.  If packets arrive out of order, the NCP has to sort them. 
959 This means that the user process may not be able to read a packet even
960 though the receive list is non-empty, because the first packet in the
961 receive list is not the successor of the last packet read by the user
962 process. 
963
964 A good way to do this is to have two lists of received packets, each
965 of which is sorted.  The first list contains those packets which
966 the user process may read; the first in the list is the successor
967 to the last packet read, and there are no gaps in the list.
968 The second list is the remaining packets, which the user may not
969 read until some other packet arrives to fill in the gap.  Each
970 list needs a pointer to head and tail, and the packet number of
971 the next packet to be appended to the tail.
972
973 It is not actually a requirement that an NCP support out-of-order
974 packets, rather than simply discarding them and hoping that they
975 will be retransmitted in order, but if it's not very hard to do
976 one might as well do it.
977
978 Acknowledgements are sent by putting the last-received variable into
979 the "ack packet #" field of an outgoing packet on the opposite
980 direction of the appropriate connection, and copying the last-received
981 variable into the last-acknowledged variable.  Where does the outgoing
982 packet come from?  First of all, all outgoing data, SNS, and STS
983 packets automatically carry acknowledgement for the reverse direction
984 of their connection.  So if an outgoing packet happens to be sent at a
985 time when an acknowledgement is necssary, that takes care of it. 
986
987 Secondly, if the number of outstanding unacknowledged packets is more
988 than 1/3 the window size, a STS should be generated and sent immediately
989 to acknowledge those packets before the sender fills up the window.
990
991 Thirdly, the "soon" of four paragraphs back is implemented by a timeout
992 in the NCP.  If an acknowledgement remains required for a certain amount
993 of time, a STS should be generated and sent to carry it.  The appropriate
994 time interval is 1 second, I would guess.  This timeout does not have
995 to be too exact, however.  One could also not bother with this and let
996 the other end's probe timeout trigger the STS via a SNS.  However, it
997 is desirable to send a receipt fairly soon after receiving a packet
998 to avoid useless retransmission.  This could be done either by a timeout
999 or by sending a receipt when the packet is received for the second time.
1000 [No known NCP has such a timeout.  10/2/78]
1001
1002 The reason for having a timeout here, rather than just sending an
1003 acknowledgement right away, is two-fold.  It allows "batching" of
1004 acknowledgements, where a single packet can be used to acknowledge
1005 many packets, which halves the network traffic caused by bulk
1006 data transfer.  It also allows "piggy-backing" of acknowledgements
1007 on data packets, which (for instance) decreases the network traffic
1008 caused by remote-echoing telnet connections.
1009
1010 When a receiver receives a data packet, it compares the packet # of
1011 that packet with the last-received variable.  If it is less or equal
1012 (modulo 2^16), it is a duplicate of a packet already given to the user,
1013 and should be discarded (or it is at least 30000 packets ahead of the
1014 user, which is unlikely.)
1015
1016 If it is greater, it is sorted into the received-packet list at the
1017 appropriate position (if it has the same packet# as a packet already in
1018 that list, it is a duplicate and is discarded.)  It is NOT acknowledged
1019 at this time; no packet is ever acknowledged until it has been given to
1020 the user process ("end to end acknowledgement").  Since a packet on the
1021 received packet list has not yet been acknowledged, it may be safely
1022 discarded at any time if the operating system runs out of buffer space,
1023 PROVIDED that it has not yet been receipted.
1024 Also, if the receiving user process is not listening to the net, the
1025 NCP cannot be swamped with arbitrary numbers of packets, since the
1026 sending user process is not supposed to send more than window-size
1027 packets past the last one the receiving user process read. 
1028 However, if receipts are being used, once a receipt has been sent for
1029 a packet that packet may not be discarded.  It is up to the individual
1030 NCP which strategy it prefers to use.
1031
1032 Note that the most likely cause of packet duplication is that an
1033 acknowledge or a receipt was lost, so whenever a duplicate packet is
1034 discarded, a STS packet should be sent back containing the current
1035 receipt and acknowledge packet numbers.
1036
1037 The sender has a list of packets which have been entrusted to it by the
1038 user for transmission and one packet # variable, the number of the last
1039 packet sent by the user.  When the user next sends a packet, the sender
1040 will increment this variable and set the packet# of the sent packet to
1041 the result.  The sender also sets the source and destination host
1042 numbers and indices of the packet, sets the "ack packet #" to the
1043 last-received variable of its corresponding receiver, sets the
1044 receiver's last-acknowledged variable to that (clearing the receiver's
1045 need-an-acknowledge flag), chooses a transmission medium by checking
1046 the routing tables, and gives the packet to the transmission medium for
1047 "immediate" transmission (perhaps it has to wait its turn in a queue.)
1048 It also saves the packet on a list, in case retransmission is required.
1049
1050 With each buffered packet the sender holds in trust, it remembers the time
1051 that packet was last transmitted.  From time to time "retransmission"
1052 occurs.  The sender gives one or more packets from its list to the
1053 transmission medium.  It always starts with the oldest, so as to keep
1054 things in order, and sends the rest in order until it gets to one that was
1055 transmitted too recently to do again.  Retransmission is used to recover
1056 from lost or damaged packets, lost or damaged acknowledgements, and packets
1057 discarded by the receiver due to lack of buffering capacity.
1058
1059 Each time a receiver receives a packet, it gives the "ack packet #"
1060 from that packet to its corresponding sender.  The sender discards any
1061 packets with numbers less than or equal to that, since their successful
1062 receipt has just been acknowledged, and advances the window.  If a STS
1063 packet is received, its receipt field is processed by discarding
1064 packets, but the window is not advanced.
1065 \f
1066 >>Dynamic Window-size Adjustment
1067
1068 This section has not been updated for receipts.  Also, it is a bunch
1069 of junk.  Probably we can do without this stuff.
1070
1071 Permit me to stress that this stuff is optional for small NCPs.
1072
1073 The goals of flow control are:
1074         1. Error recovery.
1075         2. If the receiver is faster than the sender, avoid unnecessary
1076            delays in transmission due to having to wait for an
1077            acknowledge or having to wait for the sender process to wake up.
1078         3. If the sender is faster than the receiver, minimize
1079            retransmissions due to receive buffer overflow.
1080         4. Minimize the number of otherwise-useless packets generated
1081            to carry an acknowledgement or a window-size negotiation,
1082            and minimize useless retransmissions.
1083
1084 Consequences of the goals:
1085         1. All packets will be retransmitted until acknowledged.
1086         2. The sending NCP must buffer several packets, and packets
1087            must be acknowledged in groups, not one-by-one.
1088         3. If the receiver is slow, something must force the sender
1089            not to send packets too fast.
1090         4. The interval between retransmissions should not be too small.
1091            It may be desirable for it to increase if the receiving
1092            process is not listening for some reason.
1093
1094 The window size is the maximum number of packets which may be in the
1095 network at one time (for one direction of one connection).  "In the
1096 network" means output by the sending process and not yet input by
1097 the receiving process.  (These processes are the entities which
1098 determine the rate, unless they are so fast that the network slows
1099 them down.)
1100
1101 The window size is not the number of packets acknowledged at a time;
1102 for best operation the latter must be 1/2 to 1/3 of the former.
1103 See below.
1104
1105 If the sending process is slow (and determines the rate), things
1106 are relatively simple.  We just have to have a big enough window
1107 size and frequent enough acknowledgement to cover for sending
1108 process wakeup delays.
1109
1110 If things are not limited by the sender, then
1111                       Window size
1112         Flow rate = ---------------
1113                     Round trip time
1114
1115         Round trip time = time to wake up sender process (multiplied
1116                                 by the fraction of the time this
1117                                 is necessary)
1118                         + time packet is sitting in sender buffers
1119                                 before it is transmitted
1120                         + transit time through the net
1121                         + time packet is sitting in receiver buffers
1122                                 before it is read; this is the maximum
1123                                 of time to process previous packets
1124                                 and time to wakeup sender process
1125                         + time until acknowledge is generated and sent
1126                         + transit time through the net
1127
1128 The round trip time is the time between when packet N is output by the
1129 sending process and when it is acknowledged, permitting the sending
1130 process to output packet N+WS. 
1131
1132 The main variable components of the round trip time are the delay
1133 before acknowledgement and the delay waiting in the receiver buffer for
1134 packets to be processed.  If these were zero, the round trip time would
1135 consist of two process wakeups and two network transit times
1136 (determined by the delay waiting for the cable and waiting for previous
1137 packets from this host to be transmitted, the time needed to load and
1138 unload the interface in the buffer, and the actual transmission time,
1139 multiplied by the number of bridges in the path.)
1140
1141 This ideal round trip time is probably on the order of 2 seconds.
1142 The timeout for retransmission should be 2 to 3 times the round trip
1143 time.  The timeout for acknowledgement should be 1/3 to 1/2 the
1144 round trip time.  One could either measure the actual round trip time,
1145 or use an estimate of say 3 seconds, a little higher than the ideal.
1146 It would be a good idea to measure the round trip time in any case,
1147 which is done by getting the elapsed time since transmission when
1148 a packet is discarded due to its being acknowledged, and averaging
1149 that.
1150
1151 The receiver process should initially set the window size to the
1152 maximum flow rate it wants to handle times the desirable round trip
1153 time. 
1154
1155 Symptoms of improper window size:
1156
1157 If the window-size is too large, the round trip time becomes
1158 long due to packet processing delay in the receiver buffer.
1159 (There will be many packets in the receiver buffer, and the
1160 receiver will be processing them slowly.)  The long round-trip
1161 time will cause unnecessary retransmissions.  Retransmissions
1162 could also be caused by the NCP's discarding received packets
1163 due to insufficient core to buffer them.
1164
1165 If the window-size is too small, excessive process blocking
1166 and waking up occurs.  The receiver process often empties its
1167 buffer and has to block until more packets arrive.  The sender
1168 process often fills up its buffer and has to block until
1169 some of the buffered packets are acknowledged.  A small window
1170 size also causes acknowledgements to have to be sent more
1171 frequently than necessary.  Note that from the receiver's
1172 point of view it is impossible to distinguish between the
1173 window size being too small and the sending process being
1174 too slow.
1175
1176 Here is a scheme for dynamic adjustment of the window size:
1177
1178 Note that window-size adjustments cannot take effect
1179 (in the sense of fixing the symptoms) immediately, so it
1180 is necessary to limit the rate at which the window size
1181 is adjusted.
1182
1183 When the receiver receives (and discards) a duplicate of a
1184 packet it already has in its buffer, this indicates either
1185 that an acknowledgement was lost or that the window size
1186 is too large.  Since packets are assumed not be lost very
1187 often, we may as well assume the window size is too large
1188 and send a WIN packet to decrease it.  Another possibility
1189 would be to have the sender detect the long round-trip
1190 time and complain to the receiver, who could adjust the
1191 window size.  The receiver must not decrease the window
1192 size again until all packets currently buffered have
1193 been read and acknowledged, indicating that the sender
1194 has had a chance to decrease the number of packets
1195 buffered at its end.  A reasonable amount to decrease
1196 the window size by is 1/3 of its current value.
1197
1198 When the sending process wants to output a packet, but the number of
1199 packets already buffered is greater than or equal to the window size,
1200 it should send a WTS, indicating that the problem is too small a window
1201 size or too slow a receiver rather than too slow a sender.  When the
1202 receiving process wants to input a packet, but the buffer is empty, and
1203 a flag is set indicating that a WTS has been received, it should send a
1204 WIN packet adjusting the window size upward by 1/2 of its current value
1205 (and clear the WTS-received flag).  This is rate-limited by preventing
1206 the sender from sending a second WTS until all the packets buffered at
1207 the time the first WTS was sent have been acknowledged, indicating that
1208 the receiver has had time to act on the first WTS. 
1209
1210 The variables required.  For both the sending and receiving sides, a
1211 packet number which has to be acknowledged before WTS or WIN can be
1212 sent again, and a flag saying whether this number is operative.  Also,
1213 a WTS-received flag in the receiver. 
1214
1215 It is important to meter the performance of this mechanism and find out
1216 whether it does anything and whether what it does is right. 
1217
1218 Consider the possibilities of changing this into a more symmetric and
1219 negotiation-based scheme, where the sender always initiates window size
1220 changing and the receiver either agrees or ignores the request. 
1221 Consider using elapsed time as an additional rate-limiter (have to use
1222 the other thing, too, so idle connections don't keep changing window
1223 size; this may be deleteable if it is always sender-initiated.)
1224
1225 More notes on the subject of window-size too small.
1226 This is identical to receiver too slow.  The net flow rate
1227 out of the sender is trying to be higher than that into
1228 the receiver, so packets pile up in buffers at each end.
1229 The round-trip becomes arbitrarily high to preserve the
1230 equation and divide window size down enough to get the
1231 flow rate.
1232
1233 The situation where the window-size is too small and we want to do
1234 something about it has to be distinguished from two other situations. 
1235 One, the receiver is accepting packets slowly but the sender is also
1236 sending them slowly.  We don't want to change the window-size, because
1237 it doesn't matter since packets aren't piling up, and at any time they
1238 might both decide to go fast.  Two, the receiver's net flow rate is
1239 high, but its response time is long (it's taking packets in bursts). 
1240 Here the round-trip time is still long, but making the window size
1241 smaller would make things worse. 
1242
1243 The symptoms that distinguish the case where we want to make the
1244 window-size smaller are:  the round-trip time is long, the sender
1245 buffer is full, and the number of packets acknowledged at a time is
1246 small compared to the window size.  Actually, the last two are sufficient,
1247 since if the acknowledgement batch size is small, and we know it's
1248 not the sender's fault, may as well decrease the window size
1249 to save buffer space and decrease the round-trip time.
1250 \f
1251 >>Uniquization
1252
1253 To avoid problems with packets left over from old connections
1254 causing problems with new connections, we do two things.  First of
1255 all, packets are not accepted as input unless the source and
1256 destination hosts and indices correspond to a known, existent
1257 connection.  By itself, this should be adequate, provided that
1258 retransmission is only done by the originating host, not by intervening
1259 gateways and bridges in the network.  This is because we can safely
1260 assume that when a host agrees to open a connection with a certain
1261 index number at its end, it will give up on any previous connection
1262 with the same index, therefore it won't retransmit any old packets
1263 with that index once it has sent out a new RFC or OPN.  The indications
1264 are that our network will be "local" enough that indeed retransmission
1265 will only be done by the original host.
1266
1267 Problems could still occur if packets get out of order, so that an OPN
1268 establishing a new connection gets ahead of a data packet for an old
1269 connection with the same index.  To protect against this, it is
1270 necessary to assure that at least a few seconds elapse before an index
1271 number is reused.  This could be done either by remembering when an
1272 index is last used, or by reserving part of the 16-bit index number as
1273 a uniquization field, which is incremented each time an
1274 otherwise-the-same index is reused.  This field needs to big enough to
1275 cover for the maximum delay of an old data packet with the same index,
1276 and depends on the rate of creation of connections.  Which method is
1277 chosen is at the discretion of each local NCP.  Another necessary
1278 assumption is that when a system crashes and is reloaded (thus
1279 forgetting any remembered information about which indices were in use
1280 when and so forth) that the time to reload it is more than a few
1281 seconds. 
1282
1283 Problems could occur not only with left over data packets, but also
1284 with left over control packets.  This isn't too much of a problem since
1285 control packets are not retransmitted, but it could still happen that a
1286 host gets faked out into thinking that it has a connection to another
1287 host that the other host doesn't know about.  In this case, it should
1288 just look like the connection was opened and then either the other host
1289 went down or the connection was broken by a LOS packet, since the other
1290 host won't generate any data packets and won't accept any. 
1291 \f
1292 >>Media handlers
1293
1294 A host may be connected to more than one transmission medium.  It has
1295 service programs for each.
1296
1297 When a packet is received that is not addressed to this host, the
1298 forwarding count should be incremented.  If it doesn't overflow, the
1299 packet should be sent back out according to the routing tables,
1300 otherwise it should be discarded.  Normally it would not be useful to
1301 send a packet back out on the same subnet it came in on, but we may as
1302 well let the forwarding count catch this along with other loops. 
1303
1304 When a packet is received, if the opcode is RFC, it is handled
1305 specially.  The contact name is compared against those of all the
1306 indices which are in the Listening state.  If a match is found, that
1307 index is put into the RFC-received state, its LSN packet is discarded,
1308 and the RFC packet is put into its input list so that the server
1309 process can see it.  If no server is listening to that contact name,
1310 the RFC packet is placed on the  pending-RFC list, and (in the case of
1311 ITS) a server process is created which will load itself with a suitable
1312 program to open an index in "server" mode, gobble an RFC packet, look
1313 at the contact name, and either reload itself with the  appropriate
1314 server program or send a CLS reply. 
1315
1316 When a non-RFC packet is received, the system must look for a receiver
1317 index to handle it.  If none is found, or the state is wrong, or the
1318 source host and index don't match, a LOS should be sent unless the
1319 received packet was a LOS.  Otherwise, if the received packet is WIN,
1320 WTS, or NOP, it is processed and discarded.  Other packets are given to
1321 the user; OPN, CLS, and LOS cause a state change but are also given to
1322 the user as input. 
1323
1324 The transmitting side of a transmission medium handler has a queue of
1325 packets to be transmitted.  It should send them out, in order, as fast
1326 as possible, except that if a receiving host has no buffer space (which
1327 can be detected because its chaosnet interface will cause
1328 "interference" on the ether), it should look down the list for another
1329 host to send to.  [No known NCP bothers to look for another
1330 host to send to.  10/2/78]  As long as packets to the same host are sent in the
1331 order they are queued, everything will be all right.  (Actually, this
1332 normally shouldn't matter much.) In addition, when the packets are put
1333 into the transmit queue, the destination host number has to be looked
1334 up in a table to determine which transmission medium to use to get to
1335 it and (in the case of ether) which physical host number to put in the
1336 packet trailer for the hardware. 
1337 \f
1338 >>Buffers
1339
1340 In ITS, the buffering scheme will be as follows.  There will be a pool of
1341 128-word packet buffers available.  When it runs out, more can be made.  When
1342 there are many free some can be flushed.  128-word buffers are made out of
1343 1024-word pages (adding a new page type), rather than using the existing
1344 128-word buffer mechanism, because there is a limited number of 128-word
1345 buffers, and that mechanism is a little painful to use.  There are likely
1346 to be several hundred (?) packet buffers (say 12K of core) in use when
1347 high-speed (e.g. mag-tape speed) file transfer is going on.
1348
1349 Each packet buffer has a two-word header, and 126 words which can hold a
1350 packet.  Packet buffers can be on one (or sometimes two) of six lists:
1351 The free list.  The receive list, of which there are two for each
1352 index, one for packets which the user may safely read and one for
1353 out-of-order packets which are awaiting the arrival of an earlier
1354 packet before the user may read them.  The send list, of which there is
1355 one for each index.  The transmission list.  The pending-RFC list.  The
1356 pending-LSN list. 
1357
1358 The free list contains packet buffers which are free.  They are threaded
1359 together through addresses in the first word.  Zero ends the list.
1360
1361 The transmission list contains packets which are to be transmitted out
1362 on the network "immediately".  At interrupt level packets are pulled
1363 off of this list and sent.  (There might be more than one transmission
1364 list if a machine is connected to more than one physical medium.)
1365 The transmission list is threaded through addresses in the left half
1366 of the first word.  Zero ends the list.  After transmission -1 is stored
1367 to indicate that the packet is not on the transmission list any more.
1368 If the right half of the first word is -1, indicating that the packet
1369 is not also on a send list, it is returned to free.
1370
1371 Each send list contains packets for a particular connection which have
1372 been entrusted to the system by the user to be sent, but have not yet
1373 been acknowledged.  They are threaded together through the right half
1374 of the first word.  The second word contains the time that the packet
1375 was last transmitted (actually, the time that it was last put on the
1376 transmission list.)
1377
1378 Each receive list contains packets which have been received on a particular
1379 connection and not yet read by the user.  They are threaded together
1380 by addresses in the first word, and the list ends with zero.  The receive
1381 lists must be kept sorted by packet number.
1382
1383 The pending-RFC list contains request-for-connection packets which have
1384 not yet been either accepted or rejected.  They are threaded together
1385 through the first word.  When a server process finishes getting created
1386 and loaded, it will take an RFC off the pending-RFC list and put it
1387 on its own receive list.  The second word of these packets contains
1388 the time received so that the system can know when something has gone
1389 wrong and they should be thrown away.
1390
1391 The pending-LSN list contains LSN packets for all the listening users.
1392 These packets are just used as a handy place to save the contact name
1393 being listened to.  They are threaded together through the first word.
1394 The source-index field in the packet header can, of course, be used
1395 to find which user this packet belongs to.
1396 \f
1397 >>ITS System Calls
1398
1399 (Other systems would have similar calls, with appropriate
1400 changes for their own ways of doing things.)
1401
1402 OPEN
1403
1404         Not allowed.  (I said this wasn't a "standard" device!)
1405         Instead use:
1406
1407 CHAOSO
1408
1409         arg 1 - receive channel number
1410         arg 2 - transmit channel number
1411         arg 3 - receive window size
1412
1413         First, the two specified channels are closed.  Then an index
1414         is assigned to the user and the two channels are set up to
1415         point to it.  Two channels are used since in general ITS
1416         channels are unidirectional, and to allow to the user to
1417         handle receive and transmit interrupts differently.
1418
1419         The created index is placed in the Closed state.  To set up
1420         a connection, IOT an RFC or LSN packet down the transmit
1421         channel.
1422
1423
1424 PKTIOT
1425         arg 1 - channel number
1426         arg 2 - address of a 126.-word block.
1427
1428         Always transfers exactly one packet.
1429         The format of the 126.-word block is:
1430                          16               16          4
1431                 -----------------------------------------
1432                 | opcode | unused | fc |   nbytes   | 0 |
1433                 -----------------------------------------
1434                 |destination host |destination index| 0 |
1435                 -----------------------------------------
1436                 |   source host   |   source index  | 0 |
1437                 -----------------------------------------
1438                 |    packet #     |  ack packet #   | 0 |
1439                 -----------------------------------------
1440                 | data1  |  data2  ...
1441         
1442                                             ... data487 |
1443                 -----------------------------------------
1444
1445         In the descriptions below, if an error is said to
1446         occur that means IOC error 10. (channel in illegal mode) [3?]
1447         is signalled.  (Probably change this to an error return?) *******
1448
1449         In the case of an output PKTIOT, the user sets only
1450         the opcode, nbytes, and data-n fields.  When the
1451         NCP copies the packet into a buffer in the system
1452         it sets the other fields of the header to the
1453         appropriate values.
1454
1455         This is not completely true.  When outputting an RFC,
1456         the user sets the destination host field, and sets the
1457         ack packet # to the receive window size desired.  The user
1458         also sets the window size when outputting an OPN.
1459
1460         The NCP checks for the following special values
1461         in the opcode field of a packet output by the user:
1462
1463         RFC - error if the index is not in the Closed state.
1464               The packet is transmitted (but not queued for
1465               possible retransmission) and the index enters
1466               the RFC-sent state.  The user should do an input
1467               PKTIOT which will wait for the OPN, CLS, FWD, or ANS reply
1468               packet to arrive.  The NCP also copies and saves
1469               the user-specified host number and window size.
1470
1471         LSN - error if the index is not in the Closed state.
1472               It is put into the Listen state.  The packet
1473               is not transmitted, but it is saved so that
1474               when an RFC comes in the system can compare
1475               the contact names.  (Note- LSN is a special
1476               opcode which is never actually transmitted
1477               through the net.)  The pending-RFC list is searched
1478               to see if an RFC with the same contact name has
1479               been received.  If so, it is given to this index
1480               as if it was received just after the LSN was
1481               sent out.
1482
1483         OPN - error if the connection is not in the RFC-received
1484               state.  It is put into the Open state.  The
1485               packet is transmitted (but not queued for
1486               retransmission, since until it is received
1487               the other end does not know what index to
1488               send acknowledgements to.)  The system also
1489               copies and remembers the window size.
1490
1491         CLS - error if the connection is not in the Open
1492               or the RFC-received state.  It is put into
1493               the Closed state and the packet is transmitted
1494               (but not queued for retransmission).  This packet
1495               may optionally contain data bytes which are
1496               an ascii excuse for the close.
1497
1498         FWD - error if the connection is not in the RFC-received
1499               state.  The packet is transmitted, but not queued
1500               for retransmission, and the connection is put into
1501               the Closed state.
1502
1503         ANS - error if the connection is not in the RFC-received
1504               state.  The packet is transmitted, but not queued
1505               for retransmission, and the connection is put into
1506               the Closed state.
1507
1508         200 or higher - This is a data packet.  Error if the
1509               connection is not in the Open state.  A packet#
1510               is assigned, the destination and source fields
1511               are filled in, and the packet is transmitted and
1512               queued for retransmission.
1513
1514         Any other opcode causes an error.
1515
1516         In the case of an input PKTIOT, the user will get an error
1517         if the connection is in the Closed or Broken state,
1518         except if it is in the Closed state and there are data
1519         packets queued.  This is so that the user can read the
1520         CLS packet.  Otherwise, it will hang until a packet
1521         arrives, then return the packet into the user's
1522         126.-word block.
1523
1524         The user should check the sign bit of the first word,
1525         which will be set if this is a data packet.  The 
1526         non-data packets which can get given to the user are
1527         RFC, OPN, FWD, ANS, LOS, and CLS.  (You shouldn't be
1528         surprised if you get something else, though!)
1529
1530
1531 IOT, SIOT
1532         These can be used to do unit-mode 8-bit-byte transfers.
1533         Control bit 1.4 means don't-hang, and applies to both input
1534         and output.  Only data packets with opcode 200 will be
1535         transferred.  Anything else on input causes the transfer
1536         to stop, like an end-of-file.  Use PKTIOT to find out what
1537         the story is.  (The correct way is to verify that there are
1538         some packets in the input buffer, then do a SIOT, and if it
1539         transfers 0 bytes then the first packet in the input buffer
1540         must not be a data packet, so PKTIOT it in.)
1541
1542         There can be input available to SIOT even when the state is
1543         not %CSOPN (e.g. if the input buffer contains data and
1544         a CLS packet.)  In this case, you should first SIOT (if you
1545         care to pick up the data) then PKTIOT.
1546
1547 CLOSE
1548
1549         Immediately closes the connection.  All buffers and other
1550         information associated with the index are discarded.  Normally
1551         the user should first IOT a CLS
1552         packet containing an ascii explanation for why it is
1553         closing.  Note that any data previously written on the
1554         connection but not yet received by the other end will be
1555         lost.  User programs should exchange "bye" commands of some
1556         sort before closing if they care about losing data.  It is
1557         done this way to keep the NCP simple.
1558
1559
1560 RESET
1561
1562         Does nothing.
1563
1564
1565 FORCE
1566
1567         If there is a partially-filled output packet (created by IOT
1568         or SIOT), it is transmitted.
1569
1570 FLUSH
1571
1572         On an output channel, does FORCE and then waits until
1573         there are no queued output buffers.  I.e., waits for
1574         all output to be received and acknowledged by the foreign
1575         host.  This in fact waits for acknowledge, not just receipt.
1576
1577
1578 RCHST
1579
1580         val 1   SIXBIT/CHAOS/
1581         val 2   0
1582         val 3   0
1583         val 4   0
1584         val 5   -1
1585
1586
1587 RFNAME
1588
1589         val 1   SIXBIT/CHAOS/
1590         val 2   0
1591         val 3   0
1592         val 4   0
1593         val 5   0 or 1  (i.e. .UAI or .UAO)
1594
1595
1596 WHYINT
1597
1598         val 1 - %WYCHA
1599         val 2 - state
1600         val 3 - number of packets queued (receive,,transmit)
1601         val 4 - window size (receive,,transmit)
1602         val 5 - input channel#,,output channel# (-1 if not open or I/O-pushed)
1603
1604         LH(val 3) is the number of packets available to input IOT.
1605                   This is different from the number of received packets
1606                   if some are out of order.  This is increased by 1 if
1607                   there is a partially-read buffer available to SIOT;
1608                   this packet is not available to PKTIOT.  This is zero
1609                   if the connection is direct-connected to a STY.
1610
1611         RH(val 3) is the number of packets which have been transmitted
1612                   by output IOT but which have not yet been received and
1613                   acknowledged by the foreign host.
1614
1615         The state codes are:
1616
1617                 %CSCLS  Closed
1618                 %CSLSN  Listen
1619                 %CSRFC  RFC-received
1620                 %CSRFS  RFC-sent
1621                 %CSOPN  Open
1622                 %CSLOS  Broken by receipt of "LOS" packet.
1623                 %CSINC  Broken by incomplete transmission (no acknowledge
1624                         for a long time)
1625
1626
1627 NETBLK
1628
1629         Similar to Arpanet NETBLK.
1630
1631
1632 STYNET
1633
1634         arg 1 - STY channel
1635         arg 2 - Chaos channel to connect to, or
1636                 -1 to disconnect
1637         arg 3 - Other Chaos channel (not actually used)
1638         arg 4 - Output-reset character sequence, up to 3 8-bit
1639                 characters left-justified.
1640
1641         This works the same as on the Arpanet.  The specified STY
1642         is connected to or disconnected from a Chaos net channel.
1643         Data is transferred in and out by the system without the
1644         need for intervention by the user program.  If an unusual
1645         condition occurs, the STY is disconnected from the Chaos
1646         channel and the user is interrupted.  It is illegal to do
1647         I/O on any of the involved channels while they are connected.
1648
1649         This call is provided for the benefit of the "Telnet" server.
1650
1651
1652 CHAOSQ
1653
1654         arg 1 - address of a 126.-word block (packet buffer)
1655
1656         This is a special system call for use by the ATSIGN CHAOS
1657         program, which is a daemon program that gets run when
1658         an RFC is received that does not match up against an
1659         existing LSN.  
1660
1661         The first packet on the pending-RFC queue is copied
1662         into the packet buffer, then moved to the end of the
1663         queue (so that the right thing happens when several
1664         RFC's are pending at the same time.)
1665
1666         The call fails if the pending-RFC queue is empty.
1667
1668         The program should use the contact name in this
1669         packet to choose a server program to execute.  This
1670         server program will then LSN to (presumably) the same
1671         contact name, thus picking up the RFC.
1672
1673 Interrupts
1674
1675         IOC error interrupts occur if an attempt is made to IOT
1676         when the connection is in an improper state, or to IOT
1677         a packet with an illegal opcode.
1678
1679         An I/O channel interrupt is signalled on the input channel
1680         when the number of queued buffers changes from zero to
1681         non-zero.
1682
1683         An I/O channel interrupt is signalled on the output channel
1684         when the number of queued buffers changes from greater or
1685         equal to the window size, to less than the window size.
1686
1687         An I/O channel interrupt is signalled on the input channel
1688         when the connection state changes.
1689
1690         Interrupts can be used for
1691
1692                 (1) detecting when input arrives.
1693                 (2) detecting when the system is willing to accept
1694                     output.
1695                 (3) detecting when the other end does a CLOSE.
1696                 (4) detecting when a requested connection
1697                     is accepted or rejected.
1698                 (5) detecting when a request for connection
1699                     comes into a listening server.
1700 \f
1701 >ITS packages
1702
1703 Here document CHSDEF and NNETWK someday.  Also the host table.
1704 \f
1705 >An NCP in English
1706
1707 This section contains the salient routines and variables of the ITS
1708 Chaos Network Control Program, in English.
1709
1710 The following variables exist per-connection:
1711
1712 CHSUSR  the user who owns the connection, and his channel number for
1713         it.  This is used for reporting interrupts, and to keep track
1714         of who owns what.
1715
1716 CHSSTA  the state.  The following states exist:
1717         Closed - this is the initial state
1718         Listening - awaiting an RFC that matches the user's LSN.
1719         RFC-received - entered from the Listening state when a matching 
1720                 RFC arrives.
1721         RFC-sent - entered from the closed state when an RFC is transmitted.
1722         Open - entered from RFC-sent when an OPN is received, from RFC-received
1723                 when an OPN is sent.  This is the "active" state.
1724         Lost - entered when a LOS is received
1725         Incomplete transmission - entered when probing produces no response.
1726
1727         Some flags also exist:
1728         Send STS as soon as possible
1729         Connection is direct-connected to a STY.
1730
1731 CHSIBF  List of received packets, in order, which the user may read.
1732
1733 CHSPBF  List of out-of-order received packets.  The user may not read these.
1734         When the missing packets arrive, these are transferred to CHSIBF.
1735
1736 CHSOBF  List of transmitted packets which have not yet been receipted.  This
1737         list retains the packets for retransmission.  Control packets do
1738         not go on this list, only data packets.  RFC's and OPN's DO go on this list.
1739
1740 CHSNOS  Number of output slots.  This is the number of packets which the user
1741         may output before the window fills and the user must wait.  It is equal
1742         to the window size minus the number of unacknowledged packets.
1743
1744 CHSPKN  The number of the last packet given to the user, and the number of
1745         the last packet sent by the user.  Used in assigning packet numbers,
1746         checking order, and sending acknowledgements.
1747
1748 CHSACK  The numbers of the last packets acknowledged in each direction
1749         of the connection.
1750
1751 CHSNBF  The number of packets in CHSIBF and the number of packets in CHSPBF.
1752         Redundant information which is handy now and then.
1753
1754 CHSITM  The time (in 30ths of a second) that a packet was last received
1755         from the network for this connection.  Used in probing/incomplete-transmission.
1756
1757 CHSWIN  The two window sizes for the two directions of the connection.
1758
1759 CHSLCL  The local host and index numbers.
1760
1761 CHSFRN  The foreign host and index numbers.
1762
1763 ---
1764 When the user reads a packet, this algorithm is executed:
1765 If the CHSIBF list is empty, then if the connection state is
1766 not Open, give an error, otherwise await the arrival of a packet
1767 into CHSIBF.  Remove the first packet in CHSIBF and give it to
1768 the user.  If it is a data packet (opcode >= 200), "virtually
1769 acknowledge" it as follows.  Put its packet number into CHSPKN
1770 as the last packet given to the user.  Get the last packet number
1771 acknowledged from CHSACK.  If the difference of these is more than
1772 1/3 the window size, send a STS.
1773
1774 When the user outputs a packet, this algorithm is executed:
1775 (what algorithm?)
1776 \f
1777 ---------- Material after this point may be inoperative ----------
1778
1779 >Comparison with LCSnet
1780                 , and other blathering.
1781
1782 >>Principle differences
1783
1784 The LCSnet proposed protocol is called DSP.  The Chaosnet protocol will
1785 just be called chaos in this section.
1786
1787 (1) DSP specifies things in terms of bytes where Chaosnet specifies
1788 them in terms of packets.  We choose packets to increase the simplicity
1789 and efficiency of the scheme.  DSP has to work in terms of bytes because
1790 it allows packets to be reformatted en route, hence
1791
1792 (2) DSP assumes that gateways can exist between networks with the same
1793 protocols but different packet sizes.  Therefore, the protocol has to
1794 allow for the fact that packets may be reformatted en route.  I happen
1795 to believe that this situation is extremely unlikely to exist, and in
1796 fact gateways between "different" networks will have to do much more
1797 than just change the packet size.  Therefore, it makes sense to make
1798 the gateway worry about gateway issues, rather than have them permeate
1799 the whole protocol.  I believe that gateways will look more like
1800 regular network ports than like transmission media; to get from a host
1801 on the local net to a host on the arpa net, one will connect to the
1802 arpa net gateway and ask it to open a connection from itself to the
1803 host on the arpa net, then tie those connections together.  A gateway
1804 will perform not only packet reformatting, but protocol translation,
1805 flow control on both sides, and maybe even character set translation.
1806 There can also be entities called "bridges", which connect two networks
1807 (or two separate segments of one network) with the same protocol.  A bridge
1808 simply forwards any packets it receives, but never alters the packets,
1809 and never looks inside them except to find out where to forward them to.
1810
1811 (3) A related difference is that DSP includes the arpa net, and TCP,
1812 and by extension all the networks in the universe, in its port number
1813 address space.  Chaosnet would have you connect to a gateway, then
1814 send the gateway the port number to connect to in the foreign
1815 address space separately.  Chaosnet does have to include all networks
1816 reachable by bridges in its address space.
1817
1818 (4) Chaosnet has an "opcode" field in the packet header, where DSP
1819 does not.  DSP acheives the same effect with various bits here and
1820 there.  It makes little difference unless user-level programs decide
1821 to exploit the opcode field.
1822
1823 (5) DSP and Chaosnet have quite different mechanisms for creating
1824 connections.  In DSP, one never creates a connection, exactly;
1825 one simply starts sending to a port address.  Local network note
1826 #3 mumbles about how one discovers which port address to send to,
1827 but I have not seen any specifics.  In Chaosnet, the mechanism
1828 for finding out where to send to and the mechanism for creating
1829 a connection are intertwined; the excuse is that often the process
1830 being connected to is created at the same time as the connection.
1831
1832 (6) DSP uses unique, never-reused port IDs.  Chaosnet does not.
1833 The problem with unique, never-reused IDs is that I know of no
1834 system that can implement them.  Multics comes close, with the
1835 aid of a special hardware clock.  The clock is set from the
1836 operator's watch when the system is powered on, and the mechanism
1837 depends on the fact that the error in the operator's watch is
1838 less then the time required to bring up the system after a power
1839 failure.  Small systems that cannot afford special hardware just
1840 for this, and don't have permanent disk storage, would find it
1841 very hard to generate unique IDs.
1842
1843 Chaosnet prefers to rely on a scheme that doesn't require special
1844 hardware, but nearly always works.  By requiring a connection
1845 to be opened before data packets can be sent through it, and by
1846 some assumptions about the structure of the network, the problem
1847 is eliminated.  See the Flow and Error Control section for
1848 further discussion.
1849
1850 (7) DSP closes the two directions of a connection separately.  Why?
1851
1852 >>High priority data packets, interrupts, and flushing.
1853
1854 The basic idea is to note that if you want to send a high priority
1855 message, this means you want it out of order with respect to previously-
1856 sent data on some connection.  Therefore, high priority data should
1857 be sent over an auxiliary connection.  The per-connection overhead
1858 is not prohibitively high, and this eliminates vast quantities of
1859 hair from the innermost portion of the system.
1860
1861 One advantage that DSP gains by having "high priority messages"
1862 built into the system is that it also incorporates a standardized
1863 way to "mark" a particular point in a data stream.  However, this
1864 is comparatively unimportant, particularly since I think high-priority
1865 messages will probably never get used.  The only place I've heard
1866 them proposed to be used is with Telnet, but ordinary terminals
1867 get along quite well without "out of band" signals when used with
1868 reasonable operating system software.
1869
1870 Interrupts and flushing of input are random crocks associated
1871 with high priority messages.  I don't propose to implement them either.
1872
1873 >>Datagrams.  (connections only used to pass a single packet.)
1874
1875 These are easy.  The guy who wishes to send a datagram does
1876 OPEN, IOTs an RFC to the service to which the gram is to be
1877 sent, and NETBLKs waiting for the connection to open up.  He
1878 then IOTs the data packet, FLUSHes waiting for it to get there,
1879 then CLOSEs.
1880
1881 The server OPENs and IOTs an OPN in response to the RFC.  She
1882 then IOTs in the datagram packet, CLOSEs, and goes off processing
1883 the message.
1884
1885 Four packets are transmitted, two in each direction.  (An RFC, an OPN,
1886 a DATA, and an ACKing NOP.)  No need to send any CLS messages, since
1887 each user process knows to do a CLOSE system call after one data
1888 packet has been transmitted.  It has been claimed that this is
1889 the theoretical minimum if acknowledgement is required.  The reason
1890 is that the data packet must contain some unique id generated by
1891 the RECEIVER to avoid duplicates, and it must be acknowledged,
1892 so that's two packets in each direction, with no combining possible.
1893
1894 Note that as [someone at] PARC has pointed out, for the important
1895 case of side-effect-free transactions, a timeout can substitute
1896 for acknowledgement, and only two packets are necessary.  See ANS.
1897
1898
1899 >>Why not multiple messages per packet?
1900
1901 [1] Not needed for data.  The division of the data stream into
1902 packets is invisble to the real user, anyway.  It's only used by
1903 the "user-ring" portion of the network system software.
1904
1905 [2] Extra complexity.  Consider the hair involved with packed
1906 control messages in the Arpanet.  Because of the control link being
1907 shared between multiple connections between the same pair of hosts,
1908 this could save a little.  I don't know of any NCP that does this;
1909 furthermore, having that shared facility is a bad idea.  The only
1910 case in the Arpanet where packing two control messages into one
1911 packet is useful is when opening a connection the receiver wants
1912 to send STR and ALL both.  In this protocol we just put the window
1913 size in as part of the RFC and OPN messages.
1914
1915 [3] There is an argument that having message boundaries separate
1916 from packet boundaries is useful because gateways between different
1917 networks may need to split up packets because the two networks
1918 may have different maximum packet sizes.  My feeling about this
1919 is that the gateway is likely to have to do a good deal more than
1920 that.  It seems like too much to wish for that the two networks
1921 should use exactly the same packet format, protocols, or even character
1922 set; so the gateway rather than being a packet-reformatting device
1923 is much more likely to look like a user program with two connections,
1924 one on one network and one on the other, which passes data between
1925 the connections with appropriate conversion.  In particular, flow
1926 control is likely to be host1 to gateway and host2 to gateway,
1927 rather than host1 to host2.
1928
1929
1930 >>Why not have a checksum in the packet?
1931
1932 This network is likely to have a very diverse collection of machines
1933 on it, which means it will be impossible to define a checksum which
1934 can be computed efficiently in software on all machines.  Now all
1935 hardware links in the system ought to have whatever amount of
1936 hardware checking is appropriate to them, but due to the efficiency
1937 costs of a user-level end to end checksum, this should not be
1938 a built-in requirement of the basic low-level protocol.  Instead,
1939 checksumming should be an optional feature which some higher-level
1940 protocols (those that need it because the data being passed through
1941 them is so vitally important that every possible effort must be made
1942 to ensure its correctness) may implement.  Checksumming should
1943 be implemented at the user level in exactly the same way and for exactly
1944 the same reasons as encryption should be implemented at the user level.
1945
1946
1947 >>How about host-independent user-level protocols, where one just
1948 connects to a service and doesn't have to know what host it's at today?
1949
1950 Yeah, how about it?  As far as I know, this protocol provides an
1951 adequate base for constructing such a thing.  Also I haven't
1952 seen anything published on the subject.
1953
1954
1955 >>Very small hosts.
1956
1957 E.g. we'd like to put the Chess machine on the net.  It has very little
1958 memory, but not totally impotent microcode.  A small host need only
1959 support one connection, may ignore WIN, LOS, and CLS, may only have one packet
1960 in transmission at a time, and may process receive packets one at a time
1961 (ignoring any that come in until the first one has been fully processed).
1962 It IS necessary to check that received DATA packets come in in the right order.
1963
1964 RFC may be handled by remembering the other guy's host number and index,
1965 and sending back a completely canned OPN.  The contact name is ignored.
1966 If a second user tries to connect while a first user is connected,
1967 the first user gets bumped.  Let them fight it out on some larger
1968 machine (or the floor) for who will get to use the small machine.
1969 Never originate any packet type other than DATA and that one OPN.
1970
1971 Attaching ordinary terminals "directly" to the network is obviously
1972 undesirable.  
1973 \f
1974 >Transmission Media
1975
1976 This section describes how packets are encapsulated for transmission
1977 through various media, and what auxiliary hair is needed by each
1978 medium.
1979
1980
1981 >>Ethernet
1982
1983 The messages transmitted through the ether (or CAIOS) net consist of
1984 a packet followed by a three-word trailer:
1985
1986         +----------------+
1987         |     header     |  8 words
1988         +----------------+
1989         |      data      |  0-52 words
1990         +----------------+
1991         | immediate dest |  1 word
1992         +----------------+
1993         | immediate src  |  1 word
1994         +----------------+
1995         | CRC check word |  1 word
1996         +----------------+
1997
1998 The three trailer words are looked at by the hardware; the last two
1999 of them are supplied by the hardware.  The reason this stuff is in
2000 a trailer rather than a leader is that the caiosnet hardware actually
2001 transmits the packet backwards.  However, this is transparent to
2002 the software.
2003
2004 Bytes are sent two per word.  The low-order byte is first (pdp11 standard).
2005
2006
2007 >>TEN11 Interface
2008
2009 [The following total hair has not been checked recently.]
2010
2011 Since interrupts can't be sent through the TEN11 interface, the pdp10 can
2012 only service the network at relatively-infrequent intervals, for instance
2013 every 1/60'th of a second.  Therefore it is necessary to have queues of
2014 packet buffers in each direction.  This provides high speed by allowing
2015 several packets to be processed at a time.
2016
2017 The speed and reliability of the TEN11 interface eliminates any need for
2018 error checking.  (ha ha) [ho ho] <he he>   To decrease the load on the AI
2019 pdp10, it is assumed that the pdp11's will be responsible for swapping the
2020 bytes in the data portions of packets so that they will be in pdp10
2021 standard order. 
2022
2023 Even though the contents of packets will not be error-checked, the
2024 pdp10 must check addresses to avoid being screwed by a losing pdp11.
2025
2026 The form of a packet encapsulated for the TEN11 interface will then be
2027
2028         |-----------------|-----------------|----|
2029         |  queue thread   | 0=empty, 1=full |  0 |
2030         |-----------------|-----------------|----|
2031         | #bytes | opcode |     unused      |  0 |
2032         |-----------------|-----------------|----|
2033         |destination host |destination index|  0 |
2034         |-----------------|-----------------|----|
2035         |   source host   |   source index  |  0 |
2036         |-----------------|-----------------|----|
2037         |    packet #     |   ack packet #  |  0 |
2038         |-----------------|-----------------|----|
2039         | data 0 | data 1 | data 2  . . .   |  0 |
2040         |                                   |  0 |
2041         |-----------------|-----------------|----|
2042
2043 for a total of 31 36-bit words, or 62 pdp11 words.
2044
2045 The queue thread is the pdp11 address of the next packet-buffer in
2046 a queue, or zero if this is the last.  The empty/full indicator
2047 says whether this buffer currently contains a packet, or not.
2048
2049 The following is an attempt to express the algorithms of the
2050 pdp10 and pdp11 in concise form.  Hopefully they are self-
2051 explanatory.
2052
2053 Several queues of buffers need to exist in the pdp11.  Only
2054 two of these are known to the pdp10.
2055
2056 TO10QF - first buffer queued for transmission to the 10.
2057
2058 TO10QL - last buffer queued for transmission to the 10.
2059          Exists so that buffers can be appended to the
2060          list more quickly.
2061
2062 TO10AC - first buffer in list of buffers actively being
2063          gobbled by the 10.  Set by 11, cleared by 10.
2064
2065 TO10FR - copy of TO10AC.  Used to free the buffers after
2066          the 10 gobbles them.
2067
2068 (come-from pdp11-packet-receivers
2069       when (eq (destination-host ?packet) pdp10)
2070        ;re-arrange 8-bit bytes for 10
2071         (swap-bytes (data-part packet))
2072        ;Add to to-10 queue
2073         (set (thread packet) nil)       ;nil=0
2074         (cond ((null TO10QF)
2075                (setq TO10QF packet TO10QL packet))
2076               (t (set (thread TO10QL) packet)
2077                  (setq TO10QL packet)))
2078        ;Try to activate to-10 queue
2079         (cond ((null TO10FR)
2080                (setq TO10FR TO10QF
2081                      TO10AC TO10QF
2082                      TO10QF nil
2083                      TO10QL nil)))
2084 )
2085
2086 (come-from pdp11-polling-loop
2087       when (and (not (null TO10FR))  ;buffers were sent to 10
2088                 (null TO10AC))       ;and 10 has finished gobbling
2089         (mapcar 'make-buffer-free TO10FR)       ;mapcar follows queue words
2090         (setq TO10FR nil)            ;OK to activate more buffers now
2091         (cond ((not (null TO10QF))   ; more stuff waiting, activate it now
2092                (setq TO10FR TO10QF
2093                      TO10AC TO10QF
2094                      TO10QF nil
2095                      TO10QL nil)))
2096 )
2097
2098 (come-from pdp10-clock-level
2099       when (and (not (null TO10AC))  ;11 is sending buffers
2100                 (not web-buffers-locked))
2101        ;copy to user, process control message, or reject if buffers full
2102         (mapcar 'process-input
2103                 TO10AC)
2104        ;signal pdp11 that all packets have been gobbled
2105         (setq TO10AC nil))
2106
2107
2108 FRBFLS - list of free buffers.  cons-buffer gets from here,
2109          make-buffer-free puts here.
2110
2111 FM10AC - list of buffers into which pdp10 may place packets
2112          set by 11 / cleared by 10.
2113
2114 FM10GB - copy of FM10AC, used by 11 to process buffers after
2115         10 has placed packets into them.
2116
2117 (come-from pdp11-polling-loop
2118       when (and (null FM10GB)        ;10 needs some buffers &
2119                 (not (null FRBFLS))) ; free buffers available
2120        ;give the 10 a list of a suitable number of empty buffers
2121         (repeat max-at-a-whack times
2122           (and (null FRBFLS) (exitloop))
2123           (setq buffer (cons-buffer)) ;pull off free list
2124           (set (full-indicator buffer) nil) ;contains no packet
2125           (set (thread buffer) FM10GB) ;cons onto list
2126           (setq FM10GB buffer))
2127         (setq FM10AC FM10GB)         ;give buffer list to 10
2128 )
2129
2130 (come-from pdp11-polling-loop
2131       when (and (not (null FM10GB))  ;gave 10 some buffers
2132                 (null FM10AC))       ;which it has used
2133        ;process packets sent from 10.
2134         (mapcar
2135          '(lambda (buffer)
2136             (cond ((null (full-indicator buffer))
2137                    (make-buffer-free buffer)) ;didn't get used
2138                   (t (swap-bytes buffer)
2139                      (send-to-destination buffer))))
2140          FM10GB)
2141         (setq FM10GB nil))           ;no buffers active in 10 now
2142
2143 (come-from pdp10-clock-level
2144       when (and (not (null FM10AC))  ;buffer space avail
2145                 (not web-buffers-locked)) ;no M.P. interference
2146        ;send as many packets as possible
2147         (mapcar
2148          '(lambda (buffer)
2149             (cond ((needs-to-be-sent ?packet)   ;find a sendable packet somewhere
2150                    (copy-into buffer packet)
2151                    (set (full-indicator buffer) t))))
2152          FM10AC)
2153        ;signal pdp11 to gobble the packets
2154         (setq FM10AC nil))
2155
2156
2157 To avoid the need for a gross number of exec pages in the pdp10,
2158 the FM10AC and TO10AC words, and all the packet buffers, should
2159 lie in a single 4K page.  The best location for this page varies
2160 from machine to machine.  On dedicated 11's such as the AI TV11,
2161 the MC console 11, etc. it should probably just be the first 4K
2162 of memory.  On the logo machine, it would probably be best to put
2163 this page up in high memory where RUG won't mess with it.  In the
2164 case of the mini-robot system, I'm not sure.
2165
2166 It would be best not to try to use this protocol with "general
2167 purpose" machines, because of problems with finding the list
2168 headers and packet buffers, problems with telling whether the
2169 machine is running the right program, etc.  It should be used
2170 just as a way for the AI machine to get a path to the net.
2171 \f
2172 >>DL10 & DTE20
2173
2174 [Outline only]
2175
2176 [Just use the pdp11 as a substitute for a direct chaosnet interface.]
2177
2178 [Basically, the 11 says ready to transfer (in either direction), the 10
2179 sets up the pointers and says to transfer, and the 11 transfers the cruft.
2180 To eliminate an extra level of buffering, on input transfers the 11 makes a
2181 copy of the first 4 16-bit words of the header available to the 10 when it first
2182 says "ready to transfer."  The 10 uses these to decide where to copy the
2183 packet into.  It helps if you don't try to use a DL10 on a machine with a
2184 cache.]
2185 \f
2186 >>Asynchronous line
2187
2188 Packets are encapsulated by preceding them with start of text (202),
2189 and following them with a 1-byte additive checksum and an end of text (203).
2190 The 16-bit words are transmitted low order byte first.  If the checksum
2191 is wrong the receiver ignores the packet.  The start and end characters are
2192 just there to help in ignoring random noise on the line.  If they don't
2193 appear, the packet is ignored.  The full 60-word packet is not transmitted;
2194 the #bytes count is used to determine how many of the data bytes to
2195 transmit; the receiver fills the remainder with zero (or garbage, at its
2196 convenience.)
2197
2198 This protocol is intended mainly for communication between the plasma
2199 physics pdp11 in bldg. 38 and a pdp11 in 545, until the caiosnet
2200 gets extended that far (or a longer-distance, lower-speed caiosnet
2201 is extended to various machines off in that direction.)