Transmission Control Protocol (TCP)
An Introduction
|
Prof. David Bernstein
James Madison University
|
|
Computer Science Department
|
bernstdh@jmu.edu
|
Introduction
- Specification:
- Purpose:
- Provide a mechanism for applications to reliably send and receive
streams of bytes
- Assumptions:
- Access to a potentially unreliable datagram service
- Applications are associated with ports
Properties
- Connection/Session-Oriented:
- Handshaking
- State information is maintained
- Reliable:
- Delivery and order is guaranteed
- Stream-Oriented:
- A stream of bytes can be sent/received (in both
directions at the same time)
- Controlled:
- Flow control
- Congestion control
Reliability in TCP
- Requirement:
- "TCP must recover from data that is damaged, lost,
duplicated, or delivered out of order by the internet
communication system"
- Satisfying this Requirement:
- Use sequence numbers
- Aknowledgment (ACK) from the recipient and retransmission
if the ACK is not received in a given amount of time
(i.e., be tenacious)
- Use checksums
Flow Control in TCP
- Requirement:
- TCP must provide
"a means for the receiver to govern the amount of data
sent by the sender"
- Satisfying this Requirement:
- Receiver returns a "window" with every ACK indicating a
range of acceptable sequence numbers beyond the last
segment successfully received
The Need for Connections
- An Observation:
- Reliability and flow control require that TCP
maintain state information for
each data stream
- Process:
- Establish a connection (i.e., initialize state information)
- Use the connection (i.e., transmit data)
- Terminate/close the connection
The Demultiplexing Process
- Recall:
- TCP needs to know what process/application to
deliver segments to
- There may be more than one active connection at the
same time
- The Socket:
- The connection can be characterized by
a four-tuple consisting of the sending
IP address (in the IP frame) and port (in the TCP segment)
and receiving IP address (in the IP frame) and port (in the
TCP segment)
Moving through the Stack/Layers
- Moving Down:
- The TCP segment becomes the payload of the IP datagram
- Moving Up:
- The payload of the TCP datagram is handed off to the
process bound to the destination port
Required Functionality of Service Providers
- Create a "passive/listening" socket that waits/listens for a connection
- Receive connection-establishment requests
- Send and/or receive bytes by writing to and/or
reading from a stream
- Close the connection
Required Functionality of Service Requestors
- Create an "active" socket
- Request a connection (with a "passive" socket)
- Send and/or receive bytes by writing to and/or
reading from a stream
- Close the connection
TCP Segments
- The Send Buffer:
- The octets that are streamed to TCP are placed in a buffer
(associated with the connection)
- TCP periodically removes octets from the buffer and
passes it to the network layer
- TCP Segment:
- The portion of the data and the TCP header that are sent
to the network layer is collectively called a segment
- Segment Size:
- The maximum amount of data in a segment is called
the maximum segment size (MSS)
- The MSS is normally the difference between the the
maximum transmission unit (MTU; i.e., the largest link-layer
frame) and the size of the TCP and IP headers
- For Ethernet, the MTU is typically 1500 so the MSS is
1500 - 20 - 20 = 1460.
TCP Segment Format
Sequence Numbers and ACKs
- Sequence Numbers:
- Number of the first octet in the segment
- ACKs:
- Sequence number of the next octet expected
Establishing a Connection (Three-Way Handshake)
- Active participant sends SYN (i.e., a special control segment)
- Specifies the initial client-to-server sequence (number which is
clock-based)
- Passive participant responds with ACKofSYN (or SYNACK)
- Allocates buffers
- Specifies the initial server-to-client
sequence number
- Active Participant Responds with ACK
Closing a Connection (Four-Way Procedure)
- Peer A sends FIN
- Peer Z responds with ACK
- Peer Z sends FIN
- Peer A responds with ACK
- And enters a "timed wait" before completely closing
The Lifecycle in Detail (in UML)
A Simplified Reliability Mechanism
- "Send" Event:
- Increase the segment counter
- Create segment n
- Send segment n
- Start timeout timer for segment n
- "Timeout for Segment n" Event:
- "ACK for Segment n" Event:
- Stop timeout timer for segment n
There's Always More to Learn