Host A (source) communicates with Host B (destination) using TCP.
TCP data is transmitted with a TCP header.
ISN (Initial Sequence Number): The initial sequence number for the connection.
Sequence number: Sequence number of the first byte.
ACK sequence number: The next expected byte.
TCP Byte Service
Application processes communicate using TCP.
TCP uses send and receive buffers.
Write: Bytes are written to the send buffer.
Read: Bytes are read from the receive buffer.
Data is transmitted in segments.
TCP is a full-duplex protocol, meaning data and acknowledgements flow in both directions.
TCP Segment
TCP segment encapsulated within an IP packet.
The size of the IP packet must not be bigger than the Maximum Transmission Unit (MTU).
Example: Up to 1500 bytes on an Ethernet network.
The TCP header is typically 20 bytes long.
TCP Segment Header Format
The TCP segment header includes the following fields:
SrcPort: Source port.
DstPort: Destination port.
SequenceNum: Sequence number.
Acknowledgment: Acknowledgment number.
HdrLen: Header length.
Flags: Control flags.
AdvertisedWindow: Advertised window size.
Checksum: Checksum for error detection.
UrgPtr: Urgent pointer.
Options: Variable options.
Data: The actual data.
Header Fields in a Segment
<SrcPort, SrcIPAddr, DestPort, DestIPAddr>: Defines a TCP connection.
SequenceNum: Denotes the location of the first byte in the segment.
Flags: A 6-bit field containing control flags:
SYN: Synchronize, used to establish a connection.
FIN: Finish, used to terminate a connection.
ACK: Acknowledgment, signifies an acknowledgement.
URG: Urgent data, indicates urgent data.
UrgPtr: Points to where the urgent data ends.
PUSH: Notifies the application to deliver data immediately.
RESET: Indicates an error occurred and the connection needs to be aborted.
Simplified TCP Flow
Data flows toward the receiver (full duplex, with flow in the opposite direction).
Acknowledgements (Acks) and window size flow in the opposite direction.
Connection Establishment: Three-Way Handshake
Involves the exchange of three messages.
Active participant (client) initiates the connection.
Passive participant (server) listens for connection requests.
Client sends SYN, Sequence Num = x.
Server responds with SYN + ACK, Sequence Num = y, Acknowledgment = x + 1.
Client sends ACK, Acknowledgment = y + 1.
Client's SYN Packet
Contains the following fields:
Client's Port
Server's Port
Client's ISN (Initial Sequence Number)
Acknowledgment
SYN flag is set.
Other header fields: AdvertisedWindow, Checksum, UrgPtr, Options, Data.
Server's Reply Packet
Contains the following fields:
Server's Port
Client's Port
Server's ISN
Acknowledgment = Client's ISN + 1
SYN and ACK flags are set.
Other header fields: AdvertisedWindow, Checksum, UrgPtr, Options, Data.
Client's ACK Packet
Contains the following fields:
Client's Port
Server's Port
Sequence Num
Acknowledgment = Server's ISN + 1
ACK flag is set.
Other header fields: AdvertisedWindow, Checksum, UrgPtr, Options, Data.
Initial Sequence Number (ISN)
Sequence number for the very first byte of the session.
Why not a default ISN of 0?
Practical issue: IP addresses and port numbers uniquely identify a connection. The same port numbers may get used again, and an old packet might still be in flight, potentially associated with the new connection.
Security reasons: To prevent TCP hijacking.
TCP requires changing the ISN over time.
Tearing Down the Connection
Closing the connection:
FIN (Finish) is sent to close and receive remaining bytes.
The other host sends a FIN ACK to acknowledge.
RST (Reset) is sent to close and not receive remaining bytes.
Flow Control: Sliding Window in TCP
Goals of sliding window:
Guarantee end-to-end reliable data delivery and in-order delivery.
Flow control between sender and receiver to avoid receiver buffer overflow.