Upload
rosamund-baker
View
219
Download
0
Embed Size (px)
Citation preview
TCOM 509 – Internet Protocols (TCP/IP)
Lecture 04_b
Transport Protocols - TCP
Instructor: Dr. Li-Chuan ChenDate: 09/22/2003
Based in part upon slides of Prof. J. Kurose (U Mass), Prof. K. Fall (UC-Bekeley)
Internet Layer
Internet
Net interface/Physical
Transport
Application
IP
LAN Packetradio
TCP UDP
Telnet FTP DNS
Transport Layer:• UDP• TCP
TCP
• Provides the following reliable services to applications such as FTP, SMTP, TELNET.– Logical connection Establishment– Maintenance termination– Reliable data transfer
• In-order byte stream• point-to-point:
– one sender, one receiver
• connection-oriented: – Establish a connection before data exchange
• flow control– sender will not overwhelm receiver
TCP - Reliability
• Sequence numbers are used for re-ordering at the destination
• Use sequence numbers and acknowledgements (ack)– sender sends a packet, starts a timer, and waits for ack
before next send• Retransmit if data is lost (timer expires before receiving
ack)
TCP – Flow Control
• Use sliding window mechanism
• TCP sliding window operates at octet (byte) level not segment or packet level.
• Receiver sends a window that specifies receiver current buffer size
• Multiple segments can be sent before an ACK is received by the sender
TCP segment structure
source port # dest port #
32 bits
applicationdata
(variable length)
sequence number
acknowledgement numberReceive window
Urg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG: urgent data (generally not used)
ACK: ACK #valid
PSH: push data now(generally not used)
RST, SYN, FIN:connection estab(setup, teardown
commands)
# bytes Receiver willing toaccept
countingby bytes of data(not segments!)
Internetchecksum
(as in UDP)
TCP minimum header size = 20 bytes
TCP Connection ManagementOpening a connection
Three way handshake:
Step 1: client host sends TCP SYN segment to server– specifies initial seq #– no data
Step 2: server host receives SYN, replies with SYNACK segment– server allocates buffers– specifies server initial seq. #
Step 3: client receives SYNACK, replies with ACK segment, which may contain data
Host A
SYN, Seq=100
TCP Connection scenario
Host B
ACK, Seq=101, Ack=1001
time
SYNACK, Seq=1000, Ack=101
TCP Connection Management (cont.)
Closing a connection:
Step 1: client end system sends TCP FIN control segment to server
Step 2: server receives FIN, replies with ACK. Closes connection, sends FIN.
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
TCP Connection Management (cont.)
Step 3: client receives FIN, replies with ACK.
– Enters “timed wait” - will respond with ACK to received FINs
Step 4: server, receives ACK. Connection closed.
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Stop and Wait -Diagram
stop-and-wait operation
first packet bit transmitted, t = 0
sender receiver
RTT
last packet bit transmitted, t = L / R
first packet bit arriveslast packet bit arrives, send ACK
ACK arrives, send next packet, t = RTT + L / R
U sender
= .008
30.008 = 0.00027
microseconds
L / R
RTT + L / R =
TCP: Transmission scenariosHost A
ACK=109
tim
eout
Host B
Seq=109, 16 bytes data
ACK=125
time
Seq, Seq=101, Ack=10018 bytes data
Pipelined protocolsPipelining: sender allows multiple packets send
before receiving acknowledged– range of sequence numbers must be increased– buffering at sender and/or receiver
• Two generic forms of pipelined protocols: go-Back-N, selective repeat
Go Back N - Diagram
Pipelining: increased utilization
first packet bit transmitted, t = 0
sender receiver
RTT
last bit transmitted, t = L / R
first packet bit arriveslast packet bit arrives, send ACK
ACK arrives, send next packet, t = RTT + L / R
last bit of 2nd packet arrives, send ACKlast bit of 3rd packet arrives, send ACK
U sender
= .024
30.008 = 0.0008
microseconds
3 * L / R
RTT + L / R =
Increase utilizationby a factor of 3!
Example Sliding Window
Selective Repeat
• receiver individually acknowledges all correctly received packets– buffers packets, as needed, for eventual in-order
delivery to upper layer
• sender only resends packets for which ACK not received– sender timer for each unACKed pkt
• sender window– N consecutive seq #’s– again limits seq #s of sent, unACKed pkts
Selective repeat: sender, receiver windows
Selective repeat in action
Selective repeat:dilemmaExample: • seq #’s: 0, 1, 2, 3• window size=3
• receiver sees no difference in two scenarios!
• incorrectly passes duplicate data as new in (a)
Q: what relationship between seq # size and window size?
TCP: retransmission scenariosHost A
Seq=109, 16 bytes data
ACK=109
timepremature timeout
Host B
Seq=101, 8 bytes data
ACK=125
Seq=101, 8 bytes data
Seq=
92
tim
eout
ACK=125
Seq=
92
tim
eout
Host A
Seq=101, 8 bytes data
ACK=109
loss
tim
eout
lost ACK scenario
Host B
X
Seq=101, 8 bytes data
ACK=109
time
SendBase= 109
SendBase= 125
SendBase= 125
Sendbase= 101
TCP retransmission scenarios (more)
Host A
Seq=101, 8 bytes data
ACK=109
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=109, 16 bytes data
ACK=125
time
SendBase= 125
Cumulative ACK:• Pros:
– acks are unambiguous and easy to generate.
– Lost acks may not need to retransmit
• Cons:– Sender does not receive
all acks for the successful transmission
TCP Flow Control
• receive side of TCP connection has a receive buffer:
• speed-matching service: matching the send rate to the receiving app’s drain rate• app process may be
slow at reading from buffer
sender won’t overflow
receiver’s buffer bytransmitting too
much, too fast
flow control
Principles of Congestion Control
Congestion:• informally: “too many sources sending too much
data too fast for network to handle”• different from flow control!• manifestations:
– lost packets (buffer overflow at routers)– long delays (queueing in router buffers)
TCP Congestion Control• end-end control
(no network assistance)• sender limits transmission: LastByteSent-LastByteAcked CongWin
• Roughly,
• CongWin is dynamic, function of perceived network congestion
How does sender perceive congestion?
• loss event = timeout or 3 duplicate acks
• TCP sender reduces rate (CongWin) after loss event
three mechanisms:– AIMD– slow start– conservative after
timeout events
rate = CongWin
RTT Bytes/sec
TCP AIMD
• multiplicative decrease: cut CongWin in half after loss event
• additive increase: increase CongWin by 1 maximum segment size (MSS) every RTT in the absence of loss events: probing
Response to TCP Congestion
• Slow-start:– Let i = ith iteration of round trip
c = congestion window size– Init i = 0, c=1: TCP sends 1 segment– i = 1, c = 2: TCP sends 2 segments– i = 2, c = 4: TCP sends 4 segments– i = 3, c = 8: TCP sends 8 segments– …– i = n, what is the number of segments that
TCP can send?
TCP Slow Start (more)• When connection
begins, increase rate exponentially until first loss event:– double CongWin every
RTT– done by incrementing CongWin for every ACK received
• Summary: initial rate is slow but ramps up exponentially fast
Host A
one segment
RTT
Host B
time
two segments
four segments
Response to TCP Congestion• Congestion collapse: retransmission can cause
network unusable.• To avoid congestion collapse, must reduce transmission
rate– Slow-start– Multiplicative decrease
• Multiplicative decrease congestion avoidance (exponential backoff timer): – upon loss of a segment, reduce the congestion window size by
half (traffic is reduced exponentially overtime).
• Slow-start recovery: – for a new connection or after a period of congestion, increase
the congestion windows size by one segment each time when ACK arrives.
Response to TCP Congestion
• To avoid increasing the window size too quickly and causing more congestions, TCP uses congestion avoidance phase.
• Congestion avoidance phase– Once the congestion windows reaches half
of its original size, slows down the rate by increases the congestion window size by only 1 if all segments in the window have been acknowledged.
Chapter 13
• Read Section 13.1 – 13.15, 13.20, 13.23 – 13.25,13.33