CS 457 - Lecture 20 Transport Layer: UDP and TCP: Fall 2011
CS 457 - Lecture 20 Transport Layer: UDP and TCP: Fall 2011
CS 457 - Lecture 20 Transport Layer: UDP and TCP: Fall 2011
available to applications
– Internet: TCP and UDP
Internet Transport Protocols
• Datagram messaging service (UDP)
– No-frills extension of “best-effort” IP
– Just send the data – each send is a message
• Reliable, streaming, in-order delivery (TCP)
– Connection set-up
– Discarding of corrupted packets
– Retransmission of lost packets
– Flow control
– Congestion control (next lecture)
• Services not available
– Delay guarantees
– Bandwidth guarantees
Multiplexing and Demultiplexing
• Host receives IP datagrams
32 bits
– Each datagram has source
source port # dest port #
and destination IP address,
– Each datagram carries one
other header fields
transport-layer segment
– Each segment has source
and destination port application
number data
• Host uses IP addresses and (message)
port numbers to direct the
segment to appropriate socket
TCP/UDP segment format
User Datagram Protocol (UDP)
checksum length
DATA
Why Would Anyone Use UDP?
• Finer control over what data is sent and when
– As soon as an application process writes into the socket
– … UDP will package the data and send the packet
• Low delay
– UDP just blasts away without any formal preliminaries
– … which avoids introducing delays such as setup
• No connection state
– No allocation of buffers, parameters, sequence #s, etc.
– … making it easier to handle many active clients
• Small packet header overhead
– UDP header is only eight-bytes long
Popular Applications That Use UDP
• Multimedia streaming
– Retransmitting lost/corrupted packets is not worthwhile
– By the time the packet is retransmitted, it’s too late
– E.g., telephone calls, video conferencing, gaming
• Simple query protocols like Domain Name System
– Overhead of connection establishment is overkill
– Easier to have application retransmit if needed
“12.3.4.15”
Transmission Control Protocol (TCP)
• Connection oriented
– Explicit set-up and tear-down of TCP session
• Stream-of-bytes service
– Sends and receives a stream of bytes, not messages
– Similar to file I/O
• Reliable, in-order delivery
– Checksums to detect corrupted data
– Acknowledgments & retransmissions for reliable
delivery
– Sequence numbers to detect losses and reorder data
• Flow control
– Prevent overflow of the receiver’s buffer space
• Congestion control
– Adapt to network congestion for the greater good
Human Analogy: Talking on a
Cell Phone
• Alice and Bob talk on their cell phones
• What if Bob couldn’t understand Alice?
– ..or there was a brief dropout?
– Bob asks Alice to repeat what she said
• What if Bob hasn’t heard Alice for a while?
– Is Alice just being quiet?
– Or, have Bob and Alice lost connection?
– Maybe Alice should periodically say “uh huh”
– … or Bob should ask “Can you hear me now?”
– How long should Bob just keep on talking?
Highlights from Previous
Example
• Acknowledgments from receiver
– Positive: “okay” or “ACK”
– Negative: “please repeat that” or “NACK”
• Timeout by the sender (“stop and wait”)
– Don’t wait indefinitely without receiving some
response
– … whether a positive or a negative
acknowledgment
• Retransmission by the sender
– After receiving a “NACK” from the receiver
– After receiving no feedback from the receiver
TCP Support for Reliable
Delivery
• Checksum
– Used to detect corrupted data at the receiver
– …leading the receiver to drop the packet
• Sequence numbers
– Used to detect missing data
– ... and for putting the data back in order
• Retransmission
– Sender retransmits lost or corrupted data
– Timeout based on estimates of round-trip time
– Fast retransmit algorithm for rapid retransmission
TCP Segments
TCP “Stream of Bytes”
Service
Byte 80
Byte 3
Byte 2
Byte 1
Byte 0
Byte 80
Byte 3
Byte 2
Byte 1
Byte 0
Host A
Host B
…Emulated Using TCP
Host A
“Segments”
Byte 0
Byte 1
Byte 2
Byte 3
Byte 80
TCP Data
Host B
Byte 0
Byte 1
Byte 2
Byte 3
Byte 80
TCP Segment
IP Data
TCP Data (segment) TCP Hdr IP Hdr
• IP packet
– No bigger than Maximum Transmission Unit
(MTU)
– E.g., up to 1500 bytes on an Ethernet
• TCP packet
– IP packet with a TCP header and data inside
– TCP header is typically 20 bytes long
• TCP segment
– No more than Maximum Segment Size (MSS)
bytes
– E.g., up to 1460 consecutive bytes from the
stream
Host A
Sequence Numbers
ISN (initial sequence number)
Sequence TCP
TCP Data
number = 1st HDR
Sequence number
Flags: SYN
Acknowledgment
FIN
RST HdrLen 0 Flags Advertised window
PSH
URG Checksum Urgent pointer
ACK Options (variable)
Data
Step 1: A’s Initial SYN Packet
A’s port B’s port
Sequence number
Flags: SYN
B’s ISN plus 1
FIN
RST 20 0 Flags Advertised window
PSH
URG Checksum Urgent pointer
ACK Options (variable)