31
TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides of Prof. J. Kurose (U Mass), Prof. K. Fall (UC- Bekeley)

TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

Embed Size (px)

Citation preview

Page 1: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

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)

Page 2: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

Internet Layer

Internet

Net interface/Physical

Transport

Application

IP

LAN Packetradio

TCP UDP

Telnet FTP DNS

Transport Layer:• UDP• TCP

Page 3: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

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

Page 4: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

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)

Page 5: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

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

Page 6: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

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

Page 7: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

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

Page 8: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

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

Page 9: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

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

Page 10: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

Stop and Wait -Diagram

Page 11: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

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 =

Page 12: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

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

Page 13: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

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

Page 14: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

Go Back N - Diagram

Page 15: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

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!

Page 16: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

Example Sliding Window

Page 17: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

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

Page 18: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

Selective repeat: sender, receiver windows

Page 19: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

Selective repeat in action

Page 20: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

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?

Page 21: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

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

Page 22: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

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

Page 23: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

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

Page 24: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

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)

Page 25: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

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

Page 26: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

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

Page 27: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

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?

Page 28: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

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

Page 29: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

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.

Page 30: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

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.

Page 31: TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides

Chapter 13

• Read Section 13.1 – 13.15, 13.20, 13.23 – 13.25,13.33