the transmission control protocol (tcp)

32
The Transmission Control Protocol (TCP) Application Services (Telnet, FTP, e- mail, WWW) Reliable Stream Transport (TCP) Connectionless Packet Delivery Service (IP) Unreliable Transport Service (UDP)

Upload: yair

Post on 31-Jan-2016

65 views

Category:

Documents


0 download

DESCRIPTION

Application Services (Telnet, FTP, e-mail, WWW). Reliable Stream Transport (TCP). Unreliable Transport Service (UDP). Connectionless Packet Delivery Service (IP). The Transmission Control Protocol (TCP). The Transmission Control Protocol (TCP). TCP is a protocol that specifies: - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: The Transmission Control Protocol (TCP)

The Transmission Control Protocol (TCP)

Application Services

(Telnet, FTP, e-mail, WWW)

Reliable Stream

Transport (TCP)

Connectionless Packet Delivery Service

(IP)

Unreliable Transport

Service (UDP)

Page 2: The Transmission Control Protocol (TCP)

The Transmission Control Protocol (TCP)

• TCP is a protocol that specifies:

– How to distinguish among multiple destinations on a given machine

– How to initiate and terminate a stream transfer

– Format of the data and acknowledgments that two computers exchange to achieve a reliable transfer

– Procedures the computers use to ensure that the data arrives correctly

Page 3: The Transmission Control Protocol (TCP)

TCP Segment Format

• TCP divides the data stream into segments for transmission:

0 4 10 16 24 31

...

CHECKSUM URGENT POINTER

OPTIONS (IF ANY) PADDING

DATA

HLEN RESERVED CODE BITS WINDOW

ACKNOWLEDGMENT NUMBER

SOURCE PORT DESTINATION PORT

SEQUENCE NUMBER

Page 4: The Transmission Control Protocol (TCP)

TCP Segment Header Fields

• Code bits - identify the contents of the segment:

• Window - how much data the sender is willing to accept (flow control)

• Urgent pointer - specifies the position in the segment where urgent data ends

Bit (left to right) Meaning if bit is set to 1URG Urgent pointer field is validACK Acknowledgment field is validPSH This segment requests a pushRST Reset the connectionSYN Synchronize sequence numbersFIN Sender has reached end of its

byte stream

Page 5: The Transmission Control Protocol (TCP)

Out of Band Data

• TCP provides a mechanism to handle urgent data

• Urgent data is received before octets already in the stream

• Sender:– Sets urgent bit in segment header

– Puts urgent data at the beginning of the data field

– Sets urgent pointer to the end of the urgent data

• Receiver:– Notified of the urgent data as soon as it arrives

– Enters “urgent mode” until all urgent data has been consumed

– Returns to “normal mode”

Page 6: The Transmission Control Protocol (TCP)

TCP Segment Header Fields (cont)

• Checksum - used to verify the integrity of the segment– Computed over:

• Segment header

• Segment data

• Pseudo header

– 1’s complement addition algorithm

• Options - signal various options– Maximum segment size

Page 7: The Transmission Control Protocol (TCP)

TCP - Acknowledgments and Retransmission

• Uses cumulative acknowledgment scheme:– ACK 7 = “all octets up to but not including number 7

have been received correctly”

• Advantages– ACKs are easy to generate and unambiguous

– Lost acknowledgments do not force retransmission

• Disadvantages– Sender does not receive information about all

successful transmissions

Page 8: The Transmission Control Protocol (TCP)

TCP - Timeout and Retransmission

• For each segment sent:– Start timer and wait for acknowledgment

– Retransmit if timer expires

• TCP uses an adaptive retransmission algorithm because internet delays are so variable

• Round trip time of each connection is recomputed every time an acknowledgment arrives

• Timeout value is adjusted accordingly

Page 9: The Transmission Control Protocol (TCP)

TCP - Timeout and Retransmission (cont)

• How should the most recent round trip sample (RTS) effect the round trip time (RTT)?New RTT = (a * RTT) + ((1-a) * RTS)– a = 0– a = 1

• How should RTT be used to compute timeout?Timeout = b * RTT– b = 1– b > 1

Page 10: The Transmission Control Protocol (TCP)

Accurate Measurement ofRound Trip Samples

• Simple answer:– Difference in time segment sent and time ACK

received

• But what about retransmissions?– Does ACK correspond to first or second copy of

segment sent?• Assuming ACK is for the earliest transmission causes

problems

• Assuming ACK is for the latest transmission causes problems

– TCP acknowledgments are ambiguous

Page 11: The Transmission Control Protocol (TCP)

Accurate Measurement ofRound Trip Samples

• To avoid problems with ambiguous ACKs:– TCP should not update the RTT for retransmitted

segments

– Problem: if timeout value is too small all segments will cause retransmissions and RTT will never be updated

– Timer back-off: if the timer expires and causes a retransmission TCP increases the timeout

• New timeout = c * timeout

Page 12: The Transmission Control Protocol (TCP)

Karn’s Algorithm

“When computing the round trip estimate, ignore samples that correspond to retransmitted segments, but use a backoff strategy, and retain the timeout value from a retransmitted packet for subsequent packets until a valid sample is obtained.”

Page 13: The Transmission Control Protocol (TCP)

Responding to HighVariance in Delay

• Often a good estimate of the round trip time is not very useful because internet delays tend to have a high variance

• Most TCP implementations estimate:– Average round trip time

– Variance

• Using the varianceTimeout = b * RTT

Page 14: The Transmission Control Protocol (TCP)

Responding to Congestion

• Endpoints cannot know the details of where in the internet congestion has occurred or why

• Congestion will usually lengthen delays• TCP’s response to lengthened delays

(retransmission) can cause congestion collapse• Instead, TCP must reduce transmission rates when

congestion occurs

Page 15: The Transmission Control Protocol (TCP)

Responding to Congestion (cont)

• Augment the TCP transmission window with a congestion window:

Window=min(receiver advertisement,congestion window)

• Multiplicative Decrease Congestion Avoidance:– Upon loss of a segment reduce the congestion window

by half (down to a minimum of one segment)

– Backoff the retransmission timer exponentially

Page 16: The Transmission Control Protocol (TCP)

Responding to Congestion (cont)

• Slow-start (additive) recovery:– When starting traffic on a new connection or increasing

traffic after a period of congestion– Start the congestion window at the size of a single

segment and increase the congestion window by one segment each time an ACK arrives

• Congestion avoidance phase (during recovery):– Once the congestion window reaches half of its original

size before congestion occurred– Increase the size of the congestion window by 1 only if

all segments in the window have been acknowledged

Page 17: The Transmission Control Protocol (TCP)

TCP Timeout and Retransmission - Summary

• What do we get for all this stuff:– Slow-start increase– Multiplicitive decrease– Congestion avoidance– Measurement of RTT and variance– Exponential timer backoff

• Dramatic improvement of TCP performance without adding significant computational overhead

Page 18: The Transmission Control Protocol (TCP)

Establishing a TCP Connection

• The 3-way handshake– Guarantee that both sides are ready for connection– Allows both sides to agree on initial sequence numbers

Receive SYN

Site 1 Network Site 2Send SYN seq=x

Send SYN seq=y, ACK x+1

Send ACK y+1

Receive SYN&ACK

Receive ACK

Page 19: The Transmission Control Protocol (TCP)

Closing a TCP Connection

• Applications should close a connection when they have no more data to transmit

• Connection can be closed in either one or both directions– Site 1 finishes transmitting data and waits for ACK from site 2– Site 1 transmits a segment with the FIN bit set– Site 2 acknowledges the FIN segment– Site 2 notifies the application that no more data is coming– Data can still be transmitted from site 2 to site 1– Site 1 will still receive and acknowledge data from site 2– Eventually, site 2 will finish transmitting and close its connection– Both endpoints delete record of the connection

Page 20: The Transmission Control Protocol (TCP)

Closing a TCP Connection (cont)

Site 1 Network Site 2

Send FIN seq=x

Receive FIN Send ACK x+1

Receive FIN&ACK

Receive ACK

Send FIN seq=y, ACK x+1

Send ACK y+1

Receive ACK

(app closes connection)

(inform application)

(app closes connection)

Page 21: The Transmission Control Protocol (TCP)

TCP Connection Reset

• Applications normally close connections• Sometimes abnormal conditions arise that break a

connection• Broken connections can be reset:

– Site 1 sends a segment with the RST bit set– Site 2 receives segment and aborts the connection– Transfers in both directions cease immediately– Resources for the connection are released– Applications programs are informed

Page 22: The Transmission Control Protocol (TCP)

Forcing Data Delivery

• TCP divides the stream of octets into segments for transmission

• This improves efficiency since octets can be buffered until a good-sized segment can be sent

• TCP provides a push operation for applications that want to force delivery of octets– Set PSH bit

– Send segment

Page 23: The Transmission Control Protocol (TCP)

Reserved TCP Port Numbers

• Like UDP:– Static port bindings for commonly used services

• Ports 0-1024 are reserved

– Dynamic port bindings• Port numbers over 1024

• Port numbers for services accessible by both UDP and TCP usually match– ECHO (7)

– TIME (37)

Page 24: The Transmission Control Protocol (TCP)

Reserved TCP Port Numbers

Port number: Service:

0 Reserved

7 Echo

17 Quote of the day

21 FTP

23 TELNET

25 SMTP

37 Time

79 Finger

80 HTTP

119 NNTP

Page 25: The Transmission Control Protocol (TCP)

TCP Performance

• Silly Window Syndrome– Sender generates data quickly

– Receiver reads incoming data one octet at a time

Sender Receiver

Page 26: The Transmission Control Protocol (TCP)

TCP Performance (cont)

• Silly Window Syndrome– Each ACK advertises a small amount of space

– Each segment carries a small amount of data

• Problems:– Poor use of network bandwidth

– Unnecessary computational overhead

Page 27: The Transmission Control Protocol (TCP)

TCP Performance (cont)

• Avoiding Silly Window Syndrome– Use heuristics at sender to avoid transmitting a small

amount of data in each segment– Use heuristics at receiver to avoid sending small

window advisements

• Receive-side silly window avoidance– Monitor receive window size– Delay advertising an increase until a “significant”

increase is possible• “Significant” = min(half the window, maximum segment size)

Page 28: The Transmission Control Protocol (TCP)

Receive-Side Silly Window Avoidance Example

Receive 6 octets, send ACK 7 with window advisement of 0

Application reads one octet

Application reads one octet

Application reads one octet

Send window advisement of 3, receive 3 octets

Page 29: The Transmission Control Protocol (TCP)

Receive-Side SillyWindow Avoidance

• Two approaches:– Receiver can ACK received octets but does not

advertise an increase in its window until the increase is significant

– Receiver can not send ACKs when the window is not large enough to advertise

• Advantages/disadvantages?

Page 30: The Transmission Control Protocol (TCP)

Send-Side SillyWindow Avoidance

• Goal: avoid sending small segments• Application can generate data in small blocks• TCP must collect data sent by application into a

single large segment (clump) for transmission• TCP must delay sending a segment until it

contains a reasonable amount of data• How long should TCP wait before transmitting

data?

Page 31: The Transmission Control Protocol (TCP)

Send-Side Silly Window Avoidance (cont)

• The Nagle Algorithm:– Application generates data to be sent over a connection

that has already transmitted some data• If all previous transmissions have been acknowledged send the

data immediately

• If any ACKs are still pending do not transmit until:– Maximum segment size is reached, or

– An ACK arrives

• Self-clocking - does not compute delays• Applies even if the application requests a push

Page 32: The Transmission Control Protocol (TCP)

TCP Summary

• Provides reliable stream delivery service– Full duplex– Out-of-band for urgent data

• Makes efficient use of the network– Piggybacking– Sliding windows

• Efficiency• End-to-end flow control

– Acknowledgment and retransmission– Congestion recovery/avoidance