View
217
Download
2
Category
Tags:
Preview:
Citation preview
Transport LayerTCP and UDP
IS250Spring 2010
chuang@ischool.berkeley.edu
John Chuang 2
Network Layers
Application (layer 7): specific to application need
Transport (layer 4): end-to-end delivery, congestion and flow control
Network (layer 3): addressing, routing
Data Link (layer 2): framing, error detection
Physical (layer 1): bits (0/1), voltages, frequencies, wires, pins, …
IP
TCP, UDP
HTTP, FTP, NNTP, SMTP,
telnet, ...
coax, twisted pair, fiber,
wireless, ...
Ethernet
FDDI, SONET
Wi-Fi
John Chuang 3
TCP/IP ModelAppl
Transport
Network
Link
Network
Link
Network
Link
Appl
Transport
Network
Link
Host A Host BRouter 1 Router 2
end-to-end
point-to-point
point-to-point
end-to-end
John Chuang 4
Transport Layer
Functions1.Addressing (ports)2.Data integrity (error detection)3.Reliable data transport4.Flow control5.Congestion control
Protocols- Transmission Control Protocol (TCP)
- Reliable data transport (1, 2, 3, 4, and 5)
- User Datagram Protocol (UDP)- Unreliable data transport (1 and 2 only)
John Chuang 5
TCP Segment FormatBit 0 Bit 31
Data (variable length)
Data
Header
Source Port # (16) Destination Port # (16)
Sequence Number (32 bits)
Acknowledgement Number (32 bits)
Hdr Len(4) Flags (6) Window Size (16)
Options (if any) PAD
Reserved (6)
TCP Checksum (16) Urgent Pointer (16)
Like the IPv4 header, TCP header is also 20 bytes long without options
John Chuang 6
UDP Datagram Format0 3116
Data
UDP Header
Source Port Number (16) Destination Port Number (16)
UDP Checksum (16)Message Length (16)
UDP is considered light-weight :- low overhead; no connection setup- used for real-time applications (don’t need retransmission)
John Chuang 7
TCP Maximum Segment Size
Note that TCP segment header does not include segment size field
Instead, Sequence Number field is used to identify location of segment in the TCP byte stream (more on SEQ later)
Sender constructs segments so that they do not need to be fragmented at the network layer
MSS = MTU - IP header length - TCP header length
Maximum Segment Size
Maximum Transmission Unit
20 bytes without Options 20 bytes without Options
John Chuang 8
Transport Layer Functions
1. Addressing (ports)2. Data integrity (error
detection)3. Reliable data transport4. Flow control5. Congestion control
John Chuang 9
L4 Addressing
TCP/UDP ports identify processes on a host
Source Port # (16) Destination Port # (16)
Sequence Number (32 bits)
Acknowledgement Number (32 bits)Hdr Len
(4) Flags (6) Window Size (16)
Options (if any) PAD
Bit 0 Bit 31
Reserved (6)
TCP Checksum (16) Urgent Pointer (16)TCP Header
0 3116
UDP Header
Source Port Number (16) Destination Port Number (16)
UDP Checksum (16)Message Length (16)
John Chuang 10
Ports
Multiple processes can run on a single host - all processes share a single IP address- each process talks/listens via a different port
128.32.226.87; port 21128.2.14.60; port 50001
128.32.226.87; port 80128.2.14.60; port 50002
ftp client
http client
ftp server
http server
Note: IP cannot distinguish ftp packets from http packets (they have the same source and destination IP addresses)
John Chuang 11
Ports
The port numbers are divided into three ranges: - Well known ports (0-1023)- Registered ports (1024-49151)- Dynamic and/or private ports (49152 – 65535)
Some “well known ports”- ftp (21); ssh (22); telnet (23); smtp (25); finger (79); http (80)
- Assigned by Internet Assigned Numbers Authority (http://www.iana.org/numbers.html)
John Chuang 12
Transport Layer Functions
1. Addressing (ports)2. Data integrity (error
detection)3. Reliable data transport4. Flow control5. Congestion control
John Chuang 13
Data Integrity
TCP/UDP checksums cover entire segment/datagram
Source Port # (16) Destination Port # (16)
Sequence Number (32 bits)
Acknowledgement Number (32 bits)Hdr Len
(4) Flags (6) Window Size (16)
Options (if any) PAD
Bit 0 Bit 31
Reserved (6)
TCP Checksum (16) Urgent Pointer (16)TCP Header
0 3116
UDP Header
Source Port Number (16) Destination Port Number (16)
UDP Checksum (16)Message Length (16)
John Chuang 14
Transport Layer Functions
1. Addressing (ports)2. Data integrity (error
detection)3. Reliable data transport4. Flow control5. Congestion control
John Chuang 15
Reliable Data Transport
Connection (or Session) Management- Agreement on start and end of connection/session
Error Control- Data delivered without deletions, insertions, duplications, reordering
John Chuang 16
Connection Management
TCP establishes a session with ordered and bi-directional reliable delivery of bytes- Establishment:
- Informs receiving port of connection- Initializes packet sequence number (to a random number)
- Sets congestion and flow control state
- Teardown:- By either peer- Frees state and resources
John Chuang 17
A TCP SessionProcess A Process B
SYN
3-Way handshake to establish TCP session
time
SYN + ACK
Conversation
ACK
Teardown
Data + ACK
FIN
FIN + ACK
ACK
Data + ACK
Data + ACK
DataCan be merged into one
John Chuang 18
TCP Header Flags
Flags: URG, ACK, PSH, RST, SYN, FIN
Source Port # (16) Destination Port # (16)
Sequence Number (32 bits)
Acknowledgement Number (32 bits)
Hdr Len(4) Flags (6) Window Size (16)
Options (if any) PAD
Bit 0 Bit 31
Reserved (6)
TCP Checksum (16) Urgent Pointer (16)
John Chuang 19
Error Control
Original data stream: “I am here”
Can data be deleted? “I here” Can data be reordered? “here I am” Can data be duplicated? “I am am here”
Can non-data be inserted? “I am not here”
John Chuang 20
Reliable Delivery
Positive Acknowledgment with retransmission Sequence and acknowledgement numbers
Options (if any)
0 3116
Padding
Data
TCP Header
Source Port Number (16) Destination Port Number (16)
Sequence Number (32)
Acknowledgement Number (32)
Hdr Len(4)
Flags (6) Window Size (16)Reserved (6)
TCP Checksum (16) Urgent Pointer (16)
John Chuang 21
Reliable Delivery
Each packet has a sequence number (SEQ)- SEQ represents byte offset with respect to initial SEQ
- Duplicate packets can be detected and discarded- Out of order packets can be re-ordered
Each packet carries acknowledgment of received packet- ACK = sequence number of next byte expected by the receiver
Lost packet can be detected by missing ACK Lost packet can be retransmitted after a timeout period
John Chuang 22
A TCP SessionProcess A Process B
SYN (Seq=x)
3-Way handshake to establish TCP session
time
SYN (Seq=y; Ack=x+1)
Conversation
Data (Seq=x+1; Ack=y+1)
Teardown
Data (Seq=y+1; Ack=x+2)
FIN (Seq=x+3; Ack=y+3)
FIN (Seq=y+3; Ack=x+4)
ACK (Ack=y+4)
Data (Seq=y+2; Ack=x+3)
Data (Seq=x+2; Ack=y+2)
Notes: •Processes pick random initial values for x and y•SEQ incremented by one for illustrative purposes only (in practice, SEQ incremented by MSS)
John Chuang 23
ACK and Packet Retransmission
Process A Process B
time
Data (Seq=x+1)
Data (Seq=y+1; Ack=x+2)
ACK (Ack=x+3)
Data (Seq=x+2; Ack=y+2)T
imeo
ut
Data (Seq=x+2; Ack=y+2)
IP loses packet
TCP resends packet
John Chuang 24
ACK and Packet Retransmission
Process A Process B
time
Data (Seq=x+1)
Data (Ack=x+2)
ACK (Ack=x+3)
Data (Seq=x+2)T
imeo
ut
Data (Seq=x+2)
IP loses ACK
TCP resends packet
TCP resends ACK;drops duplicate
Data (Ack=x+3)
John Chuang 25
Adaptive Retransmission (Timeout)
Round trip time (RTT): elapsed time between sending of a TCP segment and the receipt of the corresponding ACK
EstRTT = (*EstRTT) + ((1- )*SampleRTT)Timeout = * EstRTT
In the original spec, suggested values for and are 0.9 and 2. In Jacobson/Karels algorithm, timeout is set adaptively to avoid spurious retransmissions
Recommended