3.9. Event Processing (Part 1)
The activity of the TCP can be characterized as responding to events. The events that occur can be cast into three categories: user calls, arriving segments, and timeouts. This section describes the processing the TCP does in response to each of the events. In many cases the processing required depends on the state of the connection.
Events that occur:
User Calls
OPEN
SEND
RECEIVE
CLOSE
ABORT
STATUS
Arriving Segments
SEGMENT ARRIVES
Timeouts
USER TIMEOUT
RETRANSMISSION TIMEOUT
The model of the TCP/user interface is that user commands receive an immediate return and possibly a delayed response via an event or pseudo interrupt. In the following descriptions, the term "signal" means cause a delayed response.
Error responses are given as character strings. For example, user commands referencing connections that do not exist receive "error: connection not open".
Please note in the following that all arithmetic on sequence numbers, acknowledgment numbers, windows, et cetera, is modulo 2**32 the size of the sequence number space. Also note that "=<" means less than or equal to.
A natural way to think about processing incoming segments is to imagine that they are first tested for proper sequence number (i.e., that their contents lie in the range of the expected "receive window" in the sequence number space) and then that they are generally queued and processed in sequence number order.
When a segment overlaps other already received segments we reconstruct the segment to contain just the new data, and adjust the header fields to be consistent.
OPEN Call
CLOSED STATE (i.e., TCB does not exist)
Create a new transmission control block (TCB) to hold connection state information. Fill in local socket identifier, foreign socket, precedence, security/compartment, and user timeout information. Verify the security and precedence requested are allowed for this user, if not return "error: precedence not allowed" or "error: security/compartment not allowed." If active and the foreign socket is unspecified, return "error: foreign socket unspecified"; if active and the foreign socket is specified, issue a SYN segment. An initial send sequence number (ISS) is selected and the TCP receive buffer size is selected (if applicable). A SYN segment of the form <SEQ=ISS><CTL=SYN> is sent (this may include the buffer size option if applicable). Set SND.UNA to ISS, SND.NXT to ISS+1, SND.LBB to ISS+1, enter SYN-SENT state, and return.
If the caller does not have access to the local socket specified, return "error: connection illegal for this process". If there is no room to create a new connection, return "error: insufficient resources".
LISTEN STATE
SYN-SENT STATE
SYN-RECEIVED STATE
ESTABLISHED STATE
FIN-WAIT-1 STATE
FIN-WAIT-2 STATE
TIME-WAIT STATE
CLOSE-WAIT STATE
CLOSING STATE
Return "error: connection already exists".
SEND Call
CLOSED STATE (i.e., TCB does not exist)
If the user should no have access to such a connection, then return "error: connection illegal for this process".
Otherwise, return "error: connection does not exist".
LISTEN STATE
If the foreign socket is specified, then change the connection from passive to active, select an ISS, and select the receive buffer size. Send a SYN segment, set SND.UNA to ISS, SND.NXT to ISS+1 and SND.LBB to ISS+1. Enter SYN-SENT state. Data associated with SEND may be sent with SYN segment or queued for transmission after entering ESTABLISHED state. The urgent bit if requested in the command should be sent with the first data segment sent as a result of this command. If there is no room to queue the request, respond with "error: insufficient resources". If Foreign socket was not specified, then return "error: foreign socket unspecified".
SYN-SENT STATE
Queue for processing after the connection is ESTABLISHED. Typically, nothing can be sent yet, anyway, because the send window has not yet been set by the other side. If no space, return "error: insufficient resources".
SYN-RECEIVED STATE
Queue for later processing after entering ESTABLISHED state. If no space to queue, respond with "error: insufficient resources".
ESTABLISHED STATE
Segmentize the buffer, send or queue it for output, with a piggybacked acknowledgment (acknowledgment value = RCV.NXT) with the data. If there is insufficient space to remember this buffer, simply return "error: insufficient resources".
If remote buffer size is not one octet, and, if this is the end of a letter, do the following end-of-letter/buffer-size adjustment processing:
if EOL = 0 then
SND.NXT <- SEG.SEQ + SEG.LEN
if EOL = 1 then
While SND.LBB < SEG.SEQ + SEG.LEN
Do SND.LBB <- SND.LBB + SND.BS End
SND.NXT <- SND.LBB
If the urgent flag is set, then SND.UP <- SND.NXT-1 and set the urgent pointer in the outgoing segment.
FIN-WAIT-1 STATE
FIN-WAIT-2 STATE
TIME-WAIT STATE
Return "error: connection closing" and do not service request.
CLOSE-WAIT STATE
Segmentize any text to be sent and queue for output. If there is insufficient space to remember the SEND, return "error: insufficient resources"
CLOSING STATE
Respond with "error: connection closing"
RECEIVE Call
CLOSED STATE (i.e., TCB does not exist)
If the user should no have access to such a connection, return "error: connection illegal for this process".
Otherwise return "error: connection does not exist".
LISTEN STATE
SYN-SENT STATE
SYN-RECEIVED STATE
Queue for processing after entering ESTABLISHED state. If there is no room to queue this request, respond with "error: insufficient resources".
ESTABLISHED STATE
If insufficient incoming segments are queued to satisfy the request, queue the request. If there is no queue space to remember the RECEIVE, respond with "error: insufficient resources".
Reassemble queued incoming segments into receive buffer and return to user. Mark "end of letter" (EOL) if this is the case.
If RCV.UP is in advance of the data currently being passed to the user notify the user of the presence of urgent data.
When the TCP takes responsibility for delivering data to the user that fact must be communicated to the sender via an acknowledgment. The formation of such an acknowledgment is described below in the discussion of processing an incoming segment.
FIN-WAIT-1 STATE
FIN-WAIT-2 STATE
Reassemble and return a letter, or as much as will fit, in the user buffer. Queue the request if it cannot be serviced immediately.
TIME-WAIT STATE
CLOSE-WAIT STATE
Since the remote side has already sent FIN, RECEIVEs must be satisfied by text already reassembled, but not yet delivered to the user. If no reassembled segment text is awaiting delivery, the RECEIVE should get a "error: connection closing" response. Otherwise, any remaining text can be used to satisfy the RECEIVE.
CLOSING STATE
Return "error: connection closing"