- Forward


Transmission Control Protocol (TCP)
An Introduction


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

Introduction
Back SMYC Forward
  • Specification:
    • RFC 761, RFC 793, RFC 1122, RFC 1323, RFC 2018, RFC 2581
  • 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
Back SMYC Forward
  • 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
Back SMYC Forward
  • 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
Back SMYC Forward
  • 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
Back SMYC Forward
  • An Observation:
    • Reliability and flow control require that TCP maintain state information for each data stream
  • Process:
    1. Establish a connection (i.e., initialize state information)
    2. Use the connection (i.e., transmit data)
    3. Terminate/close the connection
The Demultiplexing Process
Back SMYC Forward
  • 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
Back SMYC Forward
  • 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
Back SMYC Forward
  • 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
Back SMYC Forward
  • 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
Back SMYC Forward
  • 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
Back SMYC Forward
tcp-format
Sequence Numbers and ACKs
Back SMYC Forward
  • Sequence Numbers:
    • Number of the first octet in the segment
  • ACKs:
    • Sequence number of the next octet expected
Establishing a Connection (Three-Way Handshake)
Back SMYC Forward
  1. Active participant sends SYN (i.e., a special control segment)
    • Specifies the initial client-to-server sequence (number which is clock-based)
  2. Passive participant responds with ACKofSYN (or SYNACK)
    • Allocates buffers
    • Specifies the initial server-to-client sequence number
  3. Active Participant Responds with ACK
Closing a Connection (Four-Way Procedure)
Back SMYC Forward
  1. Peer A sends FIN
  2. Peer Z responds with ACK
  3. Peer Z sends FIN
  4. Peer A responds with ACK
    • And enters a "timed wait" before completely closing
The Lifecycle in Detail (in UML)
Back SMYC Forward
statechart_tcp
A Simplified Reliability Mechanism
Back SMYC Forward
  • "Send" Event:
    • Increase the segment counter
    • Create segment n
    • Send segment n
    • Start timeout timer for segment n
  • "Timeout for Segment n" Event:
    • Send segment n
  • "ACK for Segment n" Event:
    • Stop timeout timer for segment n
There's Always More to Learn
Back -