TCP Implementation (Part 2)
4.2.2 TRANSMISSION CONTROL BLOCK
It is highly likely that any implementation will include shared data structures among parts of the TCP and some asynchronous means of signaling users when letters have been delivered.
One typical data structure is the Transmission Control Block (TCB) which is created and maintained during the lifetime of a given connection. The TCB contains the following information (field sizes are notional only and may vary from one implementation to another):
16 bits: Local connection name
48 bits: Local socket
48 bits: Foreign socket
16 bits: Receive window size in octets
32 bits: Receive left window edge (next sequence number expected)
16 bits: Receive packet buffer size of TCB (may be less than
window)
16 bits: Send window size in octets
32 bits: Send left window edge (earliest unacknowledged octet)
32 bits: Next packet sequence number
16 bits: Send packet buffer size of TCB (may be less than window)
8 bits: Connection state
E/C - 1 if TCP has been synchronized at least once (i.e. has
been established, else O, meaning it is closed; this bit is
reset after FINS are exchanged and the user has done a CLOSE).
The bit is not reset if the connection is only desynchronized
on send or receive or both directions.
SS - SYNCed on send side (if set) else desynchronized
SR - SYNCed on receive side (if set, else desynchronized)
16 bits: Special flags
S1 - SYN sent if set
S2 - SYN verified if set
R - SYN received if set
Y - FIN sent if set
C - CLOSE from local user received if set
U - Foreign socket unspecified if set
SDS - Send side DSN sent if set
SDV - Send side DSN verified if set
RDR - Receive side DSN received if set
Initially, all bits are off [no pun intended] (i.e. SS, SR, E/C, S1, S2, R, F, C, SDS, SDV, RDR =0). When R is set, so is SR. When S1 and S2 are both set, so is SS. SR is reset when RDR is set. SS is reset when both SDS and SDV are set. These bits are used to keep track of connection state and to aid in arriving packet processing (e.g. Can sequence number be validated? Only if SR is set.).
16 bits: Retransmission timeout (in eighths of a second#]
16 bits: Head of Send buffer queue [buffers SENT from user to TCP,
but not packetized]
16 bits: Tail of Send buffer queue
16 bits: Pointer to last octet packetized in partially packetized
buffer (refers to the buffer at the head of the queue)
16 bits: Head of Send packet queue
16 bits: Tail of Send packet queue
16 bits: Head of Packetized buffer Queue
16 bits: Tail of Packetized buffer queue
16 bits: Head of Retransmit packet queue
16 bits: Tail of Retransmit packet queue
16 bits: Head of Receive buffer queue [queue of buffers given by user
to RECEIVE letters, but unfilled]
16 bits: Tail of Receive buffer queue
16 bits: Head of Receive packet queue
16 bits: Tail of receive packet queue
16 bits: Pointer to last contiguous receive packet
16 bits: Pointer to last octet filled in partly filled buffer
16 bits: Pointer to next octet to read from partly emptied packet
[Note: The above two pointers refer to the head of the receive
buffer and receive packet queues respectively]
16 bits: Forward TCB pointer
16 bits: Backward TCB pointer
4.3 CONNECTION MANAGEMENT
4.3.1 INITIAL SEQUENCE NUMBER SELECTION
The protocol places no restriction on a particular connection being used over and over again. New instances of a connection will be referred to as incarnations of the connection. The problem that arises owing to this is, "how does the TCP identify duplicate packets from previous incarnations of the connection?". This problem becomes harmfully apparent if the connection is being opened and closed in quick succession, or if the connection breaks with loss of memory and is then reestablished.
The essence of the solution [TOML74] is that the initial sequence number [ISN] must be chosen so that a particular sequence number can never refer to an "o1d" octet, Once the connection is established the sequencing mechanism provided by the TCP filters out duplicates.
For an association to be established or initialized, the two TCP's must synchronize on each other's initial sequence numbers. Hence the solution requires a suitable mechanism for picking an initial sequence number [ISN], and a slightly involved handshake to exchange the ISN's. A "three way handshake" is necessary because sequence numbers are not tied to a global clock in the network, and TCP's may have different mechanisms for picking the ISN's. The receiver of the first SYN has no way of knowing whether the packet was an old delayed one or not, unless it remembers the last sequence number used on the connection which is not always possible, and so it must ask the sender to verify this SYN.
The "three way handshake" and the advantages of a "clock-driven" scheme are discussed in [TOML74]. More on the subject, and algorithms for implementing the clock-driven scheme can be found in [DALA74].