Transport Layer Protocols-1
Transport Layer Protocols-1
on different hosts
transport protocols run in end
systems
send side: breaks app
messages into segments,
passes to network layer
rcv side: reassembles
segments into messages, application
transport
passes to app layer network
data link
application
3-8
Unreliable UDP vs. Reliable TCP
UDP TCP
9
Chapter 3 outline
3.5 connection-oriented
3.1 transport-layer services transport: TCP
3.2 multiplexing and segment structure
demultiplexing reliable data transfer
3.3 connectionless transport: UDP flow control
connection management
3.4 principles of reliable data
transfer 3.6 principles of congestion
control
3.7 TCP congestion control
RIP
SNMP
(Simple Network
Management
Protocol)
length checksum
why is there a UDP?
no connection establishment
application (which can add delay)
data
simple: no connection state
(payload)
at sender, receiver
small header size
no congestion control: UDP
UDP segment format can blast away as fast as
desired
wraparound 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1
sum 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0
checksum 1 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 1
socket
application
writes data
application
reads data
socket
• Full-duplex data
door
TCP
send buffer
TCP
receive buffer
door
• bi-directional data flow over
segment same connection
• point-to-point • Connection-oriented
• one sender, one receiver – handshaking (exchange of
control msgs) initializes sender
and receiver states before data
• reliable byte stream exchange
– no “message boundaries”
• Flow controlled
– sender will not overwhelm
• pipelined receiver
– TCP congestion and flow
• Congestion controlled
control set window size
– sender will not overwhelm
receiver
Transport Layer
What is a TCP connection?
Comm.
Networks +
protocols TCP conn.
Receiver
Sender Receiver Sender
abstraction process process
process process
A connection is identified by (Src Port + Src IP, Dst Port + Dst IP).
A connection has well-defined start and finish events.
Communication parameters are exchanged to establish a
connection: ISN (Initial Sequence Number), RWND (Receive
Window Size), MSS (Maximum Segment Size)
Client Server
Read/Write Read/Write
Port/socket Port/socket
Connection
TCP TCP
Internet
IP/Link/PHY IP/Link/PHY
Ports
- Reserved for well-known services
- Telnet/23, SMTP/25, FTP/20,21, HTTP/80,
BGP/179, lp/515
- Free ports 19
Example: A file is viewed as a stream of bytes.
In fact, data produced by any source is considered as a stream of bytes.
Bytes have individual IDs. Bytes are individually numbered.
ACK
Client
Server
Data
ACK
Data
Client
Server
Data
21
TCP Segment Header
0 4 10 16 24 31 (bit number)
Source Port Destination Port
Sequence Number H
Acknowledgment Number
e
Header A R F
a
Length
Reserved
U P S Window size d
Checksum Urgent Pointer e
Options
MSS, Window ( Time stamp,…
Scale, r
) Padding
Data
U: URG (Urgent)
A: ACK S=1 Seq. num. field carries ISN to be used
P: PSH (Push) S=0 Seq. num. = Seq. # of the first data byte in seg.
R: RST (Reset) MSS: Maximum Segment Size
S: SYN (Sync.)
F: FIN (Finish) 22
TCP: Header
• Source/destination Ports
• Port: A 16 bit local unique number on the host
• Port + Host IP => Unique end point of an application
• (Src Port + IP, Dst Port + IP): Unique connection ID
• Source and destination IP: NOT part of a TCP segment
• 32-bit seq. number
• SYN = 0 (DATA segment)
• Position of the first data byte of this segment in the sender’s data
stream
• SYN = 1
• ISN to be used in the sender’s byte stream. (in fact, ISN+1)
• Different each time a host requests a connection
23
TCP seq. numbers, ACKs
outgoing segment from sender
sequence numbers: source port # dest port #
sequence number
• byte stream “number” of acknowledgement number
rwnd
first byte in segment’s checksum urg pointer
data window size
N
acknowledgements:
• seq # of next byte
expected from other side sender sequence number space
25
TCP: Header
• URG: ‘1’ => Urgent Pointer is valid
• ACK: ‘1’ => ACK Seq# is valid
• PSH:
• ‘1’: The receiving TCP module passes the data to the application
immediately
• ‘0’: The receiving TCP module may delay the data
• RST: ‘1’ => Tells the receiver to abort the conn.
• SYN: This bit requests a connection
• FIN
• ‘1’: Sender has no more data to send, but is ready to receive.
26
TCP: Header
• Window Size
• The number of bytes the sender is willing to receive.
• Used in flow control and congestion control
27
TCP: Header
• Options
• MSS
• The Max Segment Size accepted by the sender
• Specified during connection set up
• Window Scale
• Allows the use of a larger advertised Window Size
• Time Stamp
• Used in Round-Trip Time (RTT) calculation
• Intended to be used on high-speed connection
• Sequence number may wrap around during a connection.
• New segments are distinguished from old segments by means of
time stamps
28
TCP Conn.: Established in two ways
29
TCP Connection: 3-way handshake
• Use these fields to understand the opening of a
conn.
• Connection request (SYN)
• Sequence number (ISN)
• Acknowledgement (ACK)
• Receive window size (RWND)
30
TCP Connection: 3-way handshake
Client Server
Passive open
Active open Seg(Seq# = 8000,SYN) Listen()
Connect()
31
TCP Connection: 3-way handshake
• SYN segment from client to server
• SYN = 1
• A random initial Seq# (ISN)
• RWND is undefined (defined later …)
• Options
• SYN+ACK segment from server to client
• SYN = 1
• A random initial Seq# (ISN)
• ACK = 1 (server acks the received SYN segment)
• Ack Seq.#: The sequence # of first data byte to be received
• RWND: Receive window size
• ACK from client to server
• ACKs the second SYN segment
• RWND
32
TCP: closing a connection
LAST_ACK
FINbit=1, seq=y
TIMED_WAIT can no longer
send data
ACKbit=1; ACKnum=y+1
timed wait
for 2*max CLOSED
segment lifetime
CLOSED
Client Server
Timeout/RST Timeout/RST
Data Tx./ACK
35
Client TCP Operation Server
LISTEN Closed
Closed
Active open Passive open
SYN
SENT
SYN
SYN+ACK
RCVD
SYN
ACK
Read/Write
Established
Read/Write
Established
Active close
FIN
WAIT-1
FIN
ACK
CLOSE
WAIT
Passive close
WAIT-2
FIN
LAST
ACK
2MSL timer FIN
WAIT
TIME
ACK
Closed
Closed
37
TCP: Flow Control (FC)
• FC: Regulates the amount of data a source can send before receiving
an ACK.
38
TCP: Silly Window Syndrome
• SWS occurs if
– the sender and/or the receiver is very slow.
39
TCP: Silly Window Syndrome (Sender produces small data blocks)
Server
Client
Read Write
Port Port
TCP TCP
IP/Link/PHY
Internet IP/LinkPHY
Nagle’s solution
Sender sends the first segment even if it is a small one.
Next, wait until an ACK is received OR a maximum-size segment is accumulated
before sending the next segment
…… and repeat “Next” ...
40
TCP: Silly Window Syndrome (Slow Receiver)
Client is emptying the buffer slowly RWND is small
Client Server
Read Write
Port Port
TCP TCP
IP/Link/PHY
Internet IP/Link/PHY
Receive buffer
Clarke’s solution
Send an ACK and close the window until another segment
can be received or buffer is ½ empty.
41
TCP: Congestion Control
Host
Network input
Network output
42
Causes of congestion
• Slow routers
Queues build up if computing tasks take too
much time.
Buffer mngmt., updating RT, running routing p’cols,
looking up RT
43
General Principles of Congestion Control
Introduction 1-44
General Principles of Congestion Control
Monitor: A variety of metrics can be monitored.
Fraction of all packets discarded due to lack of buffer
Average queue length
Number of retransmitted packets
Average packet delay
- Network layer
Next …
46
TCP: Congestion Control (CC)
• CC is achieved by controlling the transmission rate at the
sender after “detecting” congestion.
• Tx rate is controlled by controlling the window
size.
• Main idea in controlling CW (congestion window)
Slow start (CW = 1 MSS)
but quickly speed up to congestion threshold (CT): 1,2,4, 8, …CT
Congestion avoidance
beyond threshold, increase linearly: CW++, CW++, …, RWND
v Congestion detection
Go back to slow start ….
47
TCP: Congestion Control
• Slow start • Congestion Avoidance: Additive Inc.
Initially, CW = 1: Tx 1 Seg. (MSS) Each time the whole window of
segs. is ACKed
If ACK received before TO CW = CW + 1
CW = 2 (= CW x 2): Tx 2 Segs. (CWmax = RWND)
If ACKs received before TO
CW = 4 (= CW x 2): Tx 4 Segs.
If ACKs received before TO Congestion Detection
CW = 8 (= CW x 2): Tx 8 Segs.
RTO timer goes off
:
Continue until you hit a threshold:
CT = CW/2 and CW = 1
Congestion Threshold (CT)
• Variable CT
• Congestion Threshold is also known as ssthresh
Transport Layer 3-49
TCP: Timers
Four kinds of timers
Persistence Timer
Keep-Alive Timer
50
Example RTT estimation:
RTT: gaia.cs.umass.edu to fantasia.eurecom.fr
350
300
250
RTT (milliseconds)
200
150
100
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
52
TCP: Persistence Timer
• A receiver can close the window and reopen it with an ACK
Problem: If the ACK is lost, there is deadlock.
Solution:
When a sending TCP receives a segment with RWND = 0, start a persistence
timer.
53
TCP: Timers (Keepalive and TIME-WAIT)
• Keepalive Timer
To sustain mostly idle connections (as between BGP routers)
Each time the server hears from a client
Reset the timer: 2 hours.
If the server does not hear from the client for 2 hours
Send a probe segment.
If there is no response after 10 probes (75 sec apart)
Assume that the client is down.
W/2
TCP connection 1
bottleneck
router
capacity R
TCP connection 2
Connection 1 throughput R
Transport Layer 3-57
Fairness (more)
Fairness and UDP Fairness, parallel TCP
• multimedia apps often connections
do not use TCP • application can open
• do not want rate multiple parallel
throttled by congestion connections between two
control hosts
• instead use UDP: • web browsers do this
• send audio/video at
constant rate, tolerate • e.g., link of rate R with 9
packet loss existing connections:
• new app asks for 1 TCP, gets rate
R/10
• new app asks for 11 TCPs, gets R/2