Professional Documents
Culture Documents
Chapter 6
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Milestones
• Progression in scale of networks
• Point-to-point link (2 nodes)
• Small local area networks (tens of nodes)
• Extended local area networks (thousands of nodes)
• Heterogeneous inter-networks (millions of nodes)
• Can now handle host-to-host delivery
• Network layer (determines which next hop) uses
services of link layer (delivers to next hop) which in
turn uses services of physical layer (converts bits to
signals) to deliver packets
• Next: process to process communication -> role of the
transport layer
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Transport Layer Services (1)
• Hosts run many application
processes
application
transport
• Provide logical communication network
data link network
between application physical
network
data link
physical
data link
processes running on different physical
network
hosts data link
physical network
Segment
Application Layer Expectations
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Network Layer Limitations
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Challenge
• Enhance network layer services to meet application
expectations
• Cannot provide services that inherently cannot be
supported by network layer (e.g., delay guarantees,
bandwidth guarantees)
• Different transport protocols offer different tradeoffs
• TCP (transmission control protocol): reliable, in-order
delivery
− congestion control
− flow control
− connection setup
• UDP (user datagram protocol): unreliable, unordered
delivery
− no-frills extension of “best-effort” IP
Multiplexing & Demultiplexing
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Multiplexing & Demultiplexing
multiplexing at sender:
handle data from multiple demultiplexing at receiver:
sockets, add transport header use header info to deliver
(later used for demultiplexing) received segments to correct
socket
application
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
How Demultiplexing Work
• host receives IP datagrams
• each datagram has source IP
32 bits
address, destination IP
address source port # dest port #
• each datagram carries one
transport-layer segment other header fields
• each segment has source,
destination port number
application
• host uses IP addresses & data
port numbers to direct (payload)
segment to appropriate
socket
TCP/UDP segment format
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Socket (1)
• An interface between an application process and the
transport layer
• The application process sends/receives messages
to/from another application process (local or remote)
via a socket
• Also referred to as the Application Programming
Interface (API) between the application and the network
application application
socket controlled by
process process app developer
transport transport
network network controlled
link by OS
link Internet
physical physical
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Socket (2)
• Application developer can
• Specify type of transport protocol
• Configure a few parameters related to the transport
layer
• To help multiplex/demultiplex a segment
• Sockets have unique identifiers (port & IP address)
• Segments carry fields that help identify the right
socket
− Fields of relevance: source and destination port
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Connectionless Multiplexing &
Demultiplexing
• Used with UDP sockets
• Socket identified by two-tuple:
• Destination IP address, Destination port number
• Transport layer checks port information in segment and
directs to the right socket
• IP datagrams with different source IP addresses and/or
source port numbers, but the same destination IP
address and destination port number, are directed to the
same socket
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Connectionless Multiplexing &
Demultiplexing: Example
application
application application
P1
P3 P4
transport
transport transport
network
network link network
link physical link
physical physical
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Connection-oriented Multiplexing &
Demultiplexing
• Used with TCP sockets
• Socket identified by 4-tuple:
• Source IP address
• Source port number
• Destination IP address
• Destination port number
• All four values are used to direct segment to the right
socket
• A server host may support many simultaneous TCP
sockets, with each socket attached to a process, and
with each socket identified by its 4-tuple
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Connection-oriented Multiplexing &
Demultiplexing: Example
application
application P4 P5 P6 application
P3 P2 P3
transport
transport transport
network
network link network
link physical link
physical server: IP physical
address B
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Review - 1
• The role of transport layer is to provide logical
communication between processes
• All transport protocols provide multiplexing and
demultiplexing capability
• Others try to enhance network services to meet
application specific requirements
• Different types of multiplexing and demultiplexing
• Role of sockets
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Internet Protocols – UDP
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
User Datagram Protocol
• Provides multiplexing and demultiplexing capability
over best-effort network layer service
• ‘bare bones’ transport protocol
− UDP segments can be lost, duplicated, delivered out of order
• Connectionless:
− No handshaking between UDP sender and receiver
− Each UDP segment is handled independently of others
• Reliable transfer over UDP:
− add reliability at application layer
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Why Would Anyone Use UDP?
• Fine 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
• No delay for connection establishment
• UDP just blasts away without any formal preliminaries
• … which avoids introducing any unnecessary delays
• No connection state
• No allocation of buffers, parameters, sequence #s, etc.
• … making it easier to handle many active clients at once
• Small packet header overhead
• UDP header is only eight-bytes long
23
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 (DNS)
• Overhead of connection establishment is overkill
• Easier to have the application retransmit if needed
“Address for www.cnn.com?”
“12.3.4.15”
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
UDP Segment Format
length, in bytes of
32 bits UDP segment,
source port # dest port # including header
length checksum
• Source/Destination port:
identifies sending/receiving
process
application • Client: random port
data • Server: well-known port
(payload)
• Checksum: covers UDP segment
and IP pseudoheader
• Detect “errors” in transmitted
UDP segment format segment
• Provides end-to-end delivery
check
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Review - 2
• UDP is a simple transport protocol
• Provides multiplexing/demultiplexing and simple error
detection capability
• Finds good use in many applications in spite of its
simplicity
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Internet Protocols – TCP
• TCP Overview
• TCP Segment Header
• TCP Connection Management
• TCP Flow Control
• TCP Timer Management
• TCP Congestion Control
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
TCP Overview
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
TCP Overview
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
The TCP Service Model
TCP provides applications with a reliable byte stream
between processes
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Recap: Sliding Window Protocol
Sender Receiver
TX Time
Frame0
Frame1 ACK0
Frame2 ACK1
RTT Frame3 ACK2
ACK3
Frame4
Frame5
Frame6
Frame7
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Link vs Transport: Connection Management
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Link vs Transport: RTT
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Link vs Transport: Reordering
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Link vs Transport: Flow Control
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Link vs Transport: Congestion Control
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
TCP Segment Header
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
TCP Segment Header
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Sequence Number & Acknowledgement
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Sequence Number & Acknowledgement:
Example
A B
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
TCP Segment Header
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Flags
• CWR & ECE: used to signal congestion when ECN (Explicit
Congestion Notification) is used.
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
TCP Segment Header
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Options
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Review - 3
• TCP: provides quite a few features at the transport layer
• Multiplexing & demultiplexing
• Reliable point-to-point data transfer
• Full-duplex
• Flow control
• Congestion control
• Heart of TCP is the sliding window protocol
• Examined TCP header
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
TCP Connection Management
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Background
• TCP is a connection-oriented protocol
• Processes can run on any type of machine in the
Internet
• Connection establishment helps
• Exchange and initiate state variables
− MSS, initial sequence number, ACK type
• Allocate resources (e.g., send and receive buffers)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Connection Setup
2-way handshake:
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
2-Way Handshake Failure Scenario 1
ESTAB
Time out, retransmit
ESTAB
connection
client completes
terminates
Duplicate
ESTAB
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
2-Way Handshake Failure Scenario 2
ESTAB
Time out, retransmit
ESTAB
ESTAB
Duplicate
What the hell is this?
Transfer $1M to account x
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
TCP 3-Way Handshake
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Solution for Failure Scenario 1
ESTAB
Time out, retransmit
ESTAB
connection
client completes
terminates
Duplicate
ESTAB
Abort connection
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Solution for Failure Scenario 2
ESTAB
Time out, retransmit
ESTAB
Time out, retransmit
connection
client completes
terminates
Duplicate
ESTAB
Duplicate
What the hell is this? Huh? I sent Seq=z.
Why acks y? Stop
Abort connection
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Initial Sequence Number (ISN)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Connection Termination
• Asymmetric release (just hang-up) leads to loss of
data
• Symmetric release
• Treat connection as two separate unidirectional
connections
• Each side should be released separately
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Two Army Problem
• The attack will succeed if and only if both armies attack the
enemy at the same time.
can no longer
send but can
receive data FINbit=1, seq=x
ACKbit=1; ACKnum=x+1
can still
wait for server send data
close
• Follows simple 2-
way handshake FINbit=1, seq=y
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Review - 4
• TCP is a connection-oriented protocol
• Connection management complicated by the fact
that packets can get retransmitted, delayed,
delivered out of order, etc.
• Connection establishment governed by 3-way
handshake
• Connection termination is based on symmetric
release and managed by 2-way handshake
B
A
time
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
TCP Flow Control
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
TCP Sliding Window
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
TCP Buffers
Application Application
Process Process
Write bytes Read bytes
LastByteRead
LastByteWritten
LastByteAcked <= LastByteSent <= LastByteWritten LastByteRead < NextByteExpected <= LastByteRcvd+1
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Flow Control (1)
LastByteWritten LastByteRead
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Flow Control (2)
LastByteWritten LastByteRead
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Retransmission Timeout
How long should the retransmission timeout be?
• Should be longer than RTT
• Too short: unnecessary retransmissions
• Too long: slow reaction to segment loss
How to estimate RTT?
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Estimate RTT (2)
EstimatedRTT = (1- )*EstimatedRTT + *SampleRTT
350
300
250
RTT (milliseconds)
200
sampleRTT
150
EstimatedRTT
100
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
time (seconds)
SampleRTT Estimated RTT
Timeout Interval
timeout interval: EstimatedRTT plus “safety margin”
• large variation in EstimatedRTT -> larger safety
margin
estimate SampleRTT deviation from EstimatedRTT:
(typically, = 0.25)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Review - 5
• Looked at how TCP implements flow control in the
context of the sliding window protocol
• Receiver advertises the free space available at the
receive buffer
• Sender determines the amount of data that can be
sent based on the advertised window size, as well
as cwnd
• Looked at how to determine the retransmission timeout
interval
• Function of the RTT
• Dynamic approach
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
TCP Congestion Control
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
The Problem of Congestion
What is congestion?
• Load is higher than capacity
What do IP routers do?
• Drop the excess packets
Why is this bad?
• Wasted bandwidth for retransmissions
“congestion
Goodput collapse” Increase in load that
results in a decrease in
useful work done.
72
Load
Important Questions
• How does the sender know there is congestion?
• IP layer provides no explicit feedback regarding
network congestion
• Must infer based on network performance
• What should the sender do?
• Limit the rate at which it sends traffic into its
connection as a function of perceived network
congestion
• How does a sender limit the rate at which it sends
traffic into its connection?
• What algorithm should the sender use to change
its send rate as a function of perceived network
congestion?
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Inferring From Implicit Feedback
75
How does Sender Limits Send Rate?
Sender Receiver
TX Time
Segment0 Send rate ≈ MaxWindow/RTT
Segment1 ACK0
Segment2 ACK1
RTT Segment3 ACK2 LastByteWritten
ACK3
Segment4
Segment5
Segment6 LastByteAcked LastByteSent
Segment7
LastByteSent – LastByteAcked <= WIN
LastByteSent – LastByteAcked <= cwnd
MaxWindow = min(cwnd, WIN)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
TCP Congestion Avoidance: Additive
Increase Multiplicative Decrease (AIMD)
• How much to increase and decrease?
• Increase linearly, decrease multiplicatively
• A necessary condition for stability of TCP
• Consequences of over-sized window are much
worse than having an under-sized window
− Over-sized window: packets dropped and retransmitted
− Under-sized window: somewhat lower throughput
• Multiplicative decrease
• On loss of packet, cut cwnd in half
• Additive increase
• On success for last window of data, increase cwnd
by 1 MSS every RTT until loss (linearly)
77
TCP Additive increase
Implemented by
• Increase cwnd by
1/cwnd on every ACK
of new data
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
TCP Slow Start
• When connection begins, increase rate exponentially until first
loss event:
• initially cwnd = 1 MSS; double cwnd every RTT
• Implementation: increase cwnd by 1 on every ACK of new
data
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
TCP Tahoe (2)
Slow start followed by additive increase
Threshold is half of previous loss cwnd
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
TCP Reno (1)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
TCP Reno (2) - Fast Recovery
• On 3rd duplicate ACK,
1. Set ssthresh = cwnd/2
2. Retransmit the missing segment
3. Set cwnd = ssthresh + 3
4. Each time the same duplicate ACK arrives, set cwnd
= cwnd + 1. Transmit a new packet, if allowed by
cwnd
5. If a non-duplicated ACK arrives, set cwnd =
ssthresh, and continue with a linear increase of
cwnd (additive increase)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
TCP Reno (3)
With fast recovery, we get the classic sawtooth
• Retransmit lost packet after 3 duplicate ACKs
• New packet for each dup. ACK until loss is repaired
3 duplicate ACKs
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Tahoe vs Reno (1)
• loss indicated by timeout:
− cwnd set to 1 MSS;
− window then grows exponentially (as in slow start)
to threshold, then grows linearly
3 duplicate ACKs
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Review - 6
• Congestion control is a complex problem
• TCP relies on a variety of techniques to achieve this
• Slow start, additive increase multiplicative decrease
(AIMD)
• TCP Tahoe: slow start with AIMD
• Loss recovery slow;
• TCP Reno: improves upon Tahoe
• Better loss recovery via duplicate ACKs (fast
retransmit)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011