TCP: Transmission Control Protocol
Overview
Provides connection-oriented service implemented on connectionless IP.
Provides transport (end-to-end) service over heterogeneous subnet.
Provides full-duplex (simultaneous two-way) communication.
Provides guaranteed correct and sequenced byte stream transmission.
Messages are packaged in segments, which consist of header and data parts.
Segment Format
Field |
Bits |
Description |
Source Port |
16 |
service access point at source host |
Destination Port |
16 |
service access point at destination host |
Sequence Number |
32 |
byte offset, for sliding window tranmission |
Acknowledgement Number |
32 |
also used in sliding window |
TCP Header Length |
4 |
in 32-bit words |
unused |
6 |
|
Code Bits |
6 |
six 1-bit control fields, explained below |
Window Size |
16 |
used in variable-length sliding window |
Checksum |
16 |
1's comp. sum of segment in 16-bit words |
Urgent Pointer |
16 |
byte offset of special signals (e.g. Ctrl-C) |
Options |
n * 32 |
n = # options specified |
Data |
0-max |
max = what will fit in datagram |
Code bits
are:
- URG : Urgent pointer is used. Pointer is byte offset of interrupt character (such as Ctrl-C)
- ACK : This segment contains an acknowledgement, so use the Ack.Number field.
- PSH : deliver data to destination w/o buffering (short for push)
- RST : reset a scrambled connection
- SYN : used in connection establishment (explained below)
- FIN : used in connection termination "I have nothing more to send" (explained below)
Checksum: partition segment plus "pseudoheader" (IP addresses, TCP protocol number, segment length) into 16=bit pieces, sum the 1's complement of those values, then take the 1's complement of the sum. When receiver calculates checksum of received segment, result should be 0.
Options: examples: request max segment length other endpoint will accept (used in connect setup), negotiate window size > 64K, use of "selective repeat" for more efficient sliding window.
Connections
Uses 3-way handshake protocol to establish and terminate connections.
Segment exchange sequence to establish connection:
Host 1 request: SYN set, sequence # = x (random)
Host 2 confirm: SYN set, sequence # = y (random), ACK set, ack # = x+1
Host 1 confirm ack: SYN set, sequence # = x+1, ACK set, ack # = y+1
(This is duplex: both hosts send and ACK initial sequence numbers; x for host1-to-host2; y for host2-to-host1)
Segment exchange sequence to terminate connection:
Host 1 request: FIN set, sequence = z
Host 2 confirm: FIN set, sequence = w, ACK set, ack = z+1
Host 1 confirm ack: sequence = z+1, ACK set, ack = w+1
(Upon Host 2 confirm, host1-to-host2 direction is shut down)
(Upon Host 1 confirm ack, host2-to-host1 direction is shut down).
Reliable Transmission
duplex transmission (segment can contain piggybacked ACK)
sender retransmits segment if ACK not received within timeout period
receiver rejects duplicate segments
segment checksums generated and validated
receiver buffers out-of-sequence segments
(receiver IP reassembles fragments -- different issue)
Flow Control
Variable-size sliding window.
Sequence numbers initialized to pseudorandom value at connection
(avoid confusing late-arriving segments from interrupted connection with new segments).
Sequence numbers incremented by number of data bytes received in segment.
Window size field:
- Represents bytes of available receiver buffer space
- Updated as each segment received
- Transmitted as part of acknowledgement ("window advertisement").
- When reduced to 0, sender must suspend until advertisement of non-zero size
Congestion Control
Congestion measured from timeouts (delays due to congestion).
Host maintains:
- # bytes that can be send without worsening congestion (congestion window)
- # bytes available in receiver window
- # bytes transmitted is the smaller of A and B.
- Protocol for maintaining A:
- Initialize to max segment size
- Increment by one max segment size for each ack received in time
(doubling window size, since each of n segment acks increases window by one segment size for a total of n).
- Do not increment A beyond value of B.
- Protocol for maintaining B:
- (described above under Flow Control)
Related Home Pages:
notes | CSC 465 | Peter Sanderson | Computer Science | SMSU
Last reviewed: 21 April 1998
Peter Sanderson ( pete@csc.smsu.edu )