TCP: Overview - PowerPoint PPT Presentation

1 / 72
About This Presentation
Title:

TCP: Overview

Description:

Cumulative ACK. If received segment 1, waits for segment 2 ... SampleRTT: measured time from segment transmission until ACK receipt ... – PowerPoint PPT presentation

Number of Views:391
Avg rating:3.0/5.0
Slides: 73
Provided by: mass6
Category:
Tags: tcp | ack | overview

less

Transcript and Presenter's Notes

Title: TCP: Overview


1
TCP Overview
Error detection, retransmission, cumulative ACKs,
timers, header fields for sequence and ACK numbers
  • full duplex data
  • bi-directional app. data flow in same connection
  • MSS maximum segment size
  • connection-oriented
  • handshaking (exchange of control msgs) init's
    sender, receiver state before data exchange
  • flow controlled
  • sender will not ''flood'' receiver with data
  • point-to-point
  • one sender, one receiver
  • reliable, in-order byte stream
  • no message boundaries
  • pipelined
  • TCP congestion and flow control set window size
  • send receive buffers

application
application
writes data
reads data
socket
socket
door
door
TCP
TCP
send buffer
receive buffer
segment
2
TCP segment structure
Header
sequence number
acknowledgement number
In practice, PSH, URG, and the Urgent Data
Pointer are not used.
3
Example
Suppose that a process in Host A wants to send a
stream of data to a process in Host B over a TCP
connection.
Assume Data stream file consisting of 500,000
bytes MSS 1,000 bytes First byte of data stream
numbered as 0
TCP constructs 500 segments out of the data
stream.
500,000 bytes/1,000 bytes 500 segments
4
TCP sequence 's and ACKs
...
Segment 1
Segment 2
0 1 2 3 4 5 ..... 1000 1001 1002 ....
  • Sequence. Numbers ('s)
  • byte stream 'number' of first byte in segment's
    data
  • Do not necessarily start from 0, use random
    initial number R
  • Segment 1 0 R
  • Segment 2 1000 R etc...
  • ACKs (acknowledgment)
  • Seq of next byte expected from other side (last
    byte 1)
  • Cumulative ACK
  • If received segment 1, waits for segment 2
  • E.g. Ack1000 R (received up to 999th byte)

5
TCP sequence 's and ACKs
  • Q how receiver handles out-of-order segments
  • A TCP specs. does not say, - decide when
    implementing

Im sending data starting at seq. num42
Assuming that the starting sequence numbers for
Host A and Host B are 42 and 79 respectively
Send me the bytes from 43 onward ACK is being
piggy-backed with server-to-client data
6
Yet another example
Host A seq42 ack79 seq47 ack84
Host B seq79 ack47 seq84 ack50
Seq84, ACK50, data 200
7
TCP Round Trip Time and Timeout
  • Q how to estimate RTT?
  • SampleRTT measured time from segment
    transmission until ACK receipt
  • ignore retransmissions, cumulatively ACKed
    segments
  • SampleRTT will vary, we would want estimated RTT
    to be ''smoother''
  • use several recent measurements, not just current
    SampleRTT
  • Q how to set TCP timeout value?
  • longer than RTT
  • note RTT will vary
  • too short premature timeout
  • unnecessary retransmissions
  • too long slow reaction to segment loss
  • RTT round trip time

8
TCP Round Trip Time and Timeout
  • Setting the timeout
  • EstimatedRTT plus ''safety margin''
  • large variation in EstimatedRTT -gt larger safety
    margin

Deviation (1-x)Deviation
xSampleRTT-EstimatedRTT
9
TCP Round Trip Time and Timeout
Estimated RTT
300 250 200 150 100
Sample RTT
time
10
TCP Reliable Data Transfer
simplified sender, assuming
- one way data transfer - no flow, congestion
control
11
SIMPLIFIED TCP
SENDER
  • Assumptions
  • sender is not constrained by TCP flow or
    congestion control
  • that data from above is less than MSS in size
  • that data transfer is in one direction only

Associated with the oldest unACKed segment
12
TCP with MODIFICATIONS
SENDER
Why wait for the timeout to expire, when
consecutive ACKs can be used to indicate a lost
segment
With Fast Retransmit
13
TCP ACK generation RFC 1122, RFC 2581
Receiver does not discard out-of-order segments
1
2
3
4
14
TCP Interesting Scenarios
ACK120
Timer is restarted here for Seq92
ACK120
Segment with Seq100 not retransmitted
Retransmission due to lost ACK
15
TCP Retransmission Scenarios
X loss
ACK120
Cumulative ACK avoids retransmission of the first
segment.
16
TCP Modifications Doubling the Timeout Interval
Provides a limited form of congestion control
Congestion may get worse if sources continue to
retransmit packets persistently.
Timer expiration is more likely caused by
congestion in the network
TimeoutInterval 2 TimeoutIntervalPrevious
After ACK is received, TimeoutInterval is
derived from most recent EstimatedRTT and DevRTT
TCP acts more politely by increasing the
TimeoutInterval, causing the sender to retransmit
after longer and longer intervals.
Others check RFC 2018 selective ACK
17
TCP Flow Control
  • receiver explicitly informs sender of
    (dynamically changing) amount of free buffer
    space
  • RcvWindow field in TCP segment
  • sender keeps the amount of transmitted, unACKed
    data less than most recently received RcvWindow

sender won't overrun receiver's buffers
by transmitting too much, too fast
18
FLOW CONTROL Receiver
EXAMPLE HOST A sends a large file to HOST B
RECEIVER HOST B uses RcvWindow, LastByteRcvd,
LastByteRead
Application Process
Data from IP
HOST B tells HOST A how much spare room it has in
the connection buffer by placing its current
value of RcvWindow in the receive window field of
every segment it sends to HOST A.
Initially, RcvWindow RcvBuffer
Application reads from the buffer
RcvWindowRcvBuffer-LastByteRcvd-LastByteRead
19
FLOW CONTROL Sender
EXAMPLE HOST A sends a large file to HOST B
SENDER HOST A uses RcvWindow of HostB,
LastByteSent, LastByteACKed
SENDER HOST A
ACKs from Host B
Data
To ensure that HOST B does not overflow, HOST A
maintains throughout the connections life that
LastByteSent-LastByteACKed lt RcvWindow
20
FLOW CONTROL
Some issue to consider
RcvWindow used by the connection to provide the
flow control service
What happens when the receive buffer of HOST B is
full ? (that is, when RcvWindow0)
TCP requires that HOST A continue to send
segments with one data byte when HOST Bs receive
window is 0. Such segments will be ACKed by HOST
B. Eventually, the buffer will have some space
and the ACKs will contain RcvWindow gt 0
TCP sends a segment only when there is data or
ACK to send. Therefore, the sender must maintain
the connection alive.
21
TCP Connection Management
  • Recall TCP sender, receiver establish
    connection before exchanging data segments
  • Initialize TCP variables
  • sequence numbers
  • buffers, flow control info (e.g. RcvWindow)
  • Client is the connection initiator
  • In Java, Socket clientSocket new
    Socket("hostname","port number") connect
  • Server is contacted by client
  • In Java,Socket accept()

if (connect(s, (struct sockaddr )sin,
sizeof(sin)) ! 0) printf("connect
failed\n") WSACleanup() exit(1)
ns accept(s,(struct sockaddr )(remoteaddr),ad
drlen)
22
TCP Connection Management
Establishing a connection
  • Three way handshake
  • Step 1 client end system sends TCP SYN control
    segment to server (executed by TCP itself)
  • specifies initial seq number (isn)
  • Step 2 server end system receives SYN, replies
    with SYNACK control segment
  • ACKs received SYN
  • allocates buffers
  • specifies servers initial seq. number
  • Step 3 client ACKs the connection with
  • ACKserver_isn 1
  • allocates buffers
  • sends SYN0
  • Connection established!

This is what happens when we create a socket for
connection to a server
After establishing the connection, the client can
receive segments with app-generated data! (SYN0)
23
TCP Connection Management (cont.)
How TCP connection is established and torn down
  • Closing a connection
  • client closes socket
  • closesocket(s)
  • Java clientSocket.close()
  • Step 1 client end system sends TCP FIN control
    segment to server
  • Step 2 server receives FIN, replies with ACK.
    Closes connection, sends FIN.

24
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.
  • Note with small modification, can handle
    simultaneous FINs.

ACK
FIN
25
TCP Connection Management (cont)
Used in case ACK gets lost. It is
implementation-dependent (e.g. 30 seconds, 1
minute, 2 minutes
TCP server lifecycle
TCP client lifecycle
Connection formally closes all resources (e.g.
port numbers) are released
Lets see a demonstration using FTP client,
server, netstat
26
End of Flow Control and Error Control
27
Flow Control vs. Congestion Control
Similar actions are taken, but for very different
reasons
  • Flow Control
  • point-to-point traffic between sender and
    receiver
  • speed matching service, matching the rate at
    which the sender is sending against the rate at
    which the receiving application is reading
  • prevents Receiver Buffers from overflowing

Congestion happens when there are too many
sources attempting to send data at too high a
rate for the routers along the path
  • Congestion Control
  • service that makes sure that the routers
    between End Systems are able to carry the
    offered traffic
  • prevents routers from overflowing

Same course of action Throttling of the sender
28
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 (queuing in router buffers)
  • a top-10 problem!

29
Approaches towards congestion control
Two broad approaches towards congestion control
  • Network-assisted congestion control
  • routers provide feedback to End Systems in the
    form of
  • single bit indicating link congestion (SNA,
    DECbit, TCP/IP ECN, ATM ABR)
  • explicit transmission rate the sender should send
    at

1
2
  • End-to-end congestion control
  • no explicit feedback from network
  • congestion inferred by end-systems from observed
    packet loss delay
  • approach taken by TCP

30
TCP Congestion Control
How TCP sender limits the rate at which it sends
traffic into its connection?
New variable! Congestion Window
SENDER
(Amount of unACKed data)SENDER lt min(CongWin,
RcvWindow)
By adjusting CongWin, sender can therefore adjust
the rate at which it sends data into its
connection
Assumptions
  • TCP receive buffer is very large no RcvWindow
    constraint
  • ? Amt. of unACKed data at sender is solely
    limited by CongWin
  • Packet loss delay packet transmission delay
    are negligible

CongWin
Sending rate
RTT
31
TCP Congestion Control
TCP uses ACKs to trigger (clock) its increase
in congestion window size self-clocking
Arrival of ACKs
  • Slow Rate
  • Congestion window will be increased at a
    relatively slow rate
  • High rate
  • Congestion window will be increased more quickly

32
TCP Congestion Control
How TCP perceives that there is congestion on the
path?
Loss Event when there is excessive
congestion, router buffers along the path
overflows, causing datagrams to be dropped, which
in turn, results in a loss event at the sender
  • Timeout
  • no ACK is received after segment loss
  • Receipt of three duplicate ACKs
  • segment loss is followed by three ACKs received
    at the sender

33
TCP Congestion Control Algorithm
3 Major Components
  • Additive-increase, Multiplicative Decrease
  • mechanism for reducing sending rate when loss
    event occurs,
  • and increasing sending rate when there is no
    perceived congestion.
  • Slow Start
  • sender begins transmitting at a slow rate, but
    increases its
  • sending rate exponentially fast
  • Reaction to timeout events
  • enters slow-start phase, letting CongWin to grow
    exponentially
  • until it reaches ½ of the value it had before the
    timeout event.
  • At that point, CongWin grows linearly

34
TCP Congestion Control Algorithm
3 Major Components
  • Additive-increase, Multiplicative Decrease
  • mechanism for reducing sending rate when loss
    event occurs,
  • and increasing sending rate when there is no
    perceived congestion.
  • when loss event occurs,
  • CongWin 0.5 CongWin

The value of CongWin may continue to drop, but
not below 1 MSS
  • Otherwise, when there is no loss event (there is
    available unused
  • Bandwidth), For every RTT (each time an ACK is
    received),
  • CongWin CongWin MSS

Congestion avoidance linear increase phase
35
TCP Congestion Control Algorithm
3 Major Components
  • Slow Start
  • sender begins transmitting at a slow rate, but
    increases its
  • sending rate exponentially fast
  • Initially, CongWin 1 MSS
  • when loss event occurs,
  • CongWin 0.5 CongWin

CongWin size is allowed to grow linearly
afterwards
  • Otherwise, when there is no loss event during
    the initial phase
  • (there is available unused Bandwidth), For every
    RTT (each time
  • an ACK is received),
  • CongWin CongWin 2

36
TCP Congestion Control Algorithm
3 Major Components
  • Reaction to Timeout Events
  • Receipt of three duplicate ACKs (Fast Recovery)
  • CongWin cut in half and then increases linearly
  • Timeout

When a timeout event occurs,
  • TCP enters a slow-start phase, CongWin1, and
    then grows
  • exponentially until CongWin0.5 CongWinPREV

At that point, CongWin grows linearly (same as
receiving triple duplicate ACKs)
37
TCP Congestion Control Algorithm
Summary
CongWin lt Threshold
  • sender is in slow-start phase, CongWin grows
    exponentially fast

CongWin gt Threshold
  • sender is in congestion-avoidance phase, CongWin
    grows linearly

When triple duplicate ACK loss event occurs
1
  • Threshold0.5CongWin
  • CongWinThreshold

1
When a Timeout loss event occurs
2
  • Threshold0.5CongWin

2
  • CongWin1 MSS

38
TCP Congestion Control
  • End-to-End control (no network assistance)
  • transmission rate limited by congestion window
    size (CongWin)over segments

39
TCP Congestion Control
Denote W be the value of w when a loss event
occurs, and assuming Further that W and RTT
remains approximately constant (W 0.5W)/2
0.75
40
TCP congestion control
  • Two ''phases''
  • slow start
  • congestion avoidance
  • important variables
  • Congwin
  • threshold defines threshold between two slow
    start phase, congestion control phase
  • ''probing'' for usable bandwidth
  • ideally transmit as fast as possible (Congwin as
    large as possible) without loss
  • increase Congwin until loss (congestion)
  • loss decrease Congwin, then begin probing
    (increasing) again

41
TCP Slowstart
Initialization Congwin 1 Do (each transmission
completed) CongwinCongwin2 Loop Until
(loss event OR CongWin gt threshold)
  • exponential increase (per RTT) in window size
    (not so slow!)
  • loss event timeout and/or or three duplicate ACKs

42
TCP Congestion Avoidance
Congestion avoidance
/ slowstart is over / / CongWin gt
threshold / Until (loss event) every w
segments ACKed CongWin threshold
CongWin/2 CongWin 1 perform slowstart
In practice, initially, Threshold is set to
65Kbytes
43
12 11 10 9 8 7 6 5 4 3 2 1
  • TCP congestion avoidance
  • AIMD additive increase, multiplicative decrease
  • increase window by 1 per RTT
  • decrease window by factor of 2 on loss event

Average
0 5 10 15 20
transmissions
44
TCPs Congestion Control Service
Problem Gridlock sets-in when there is packet
loss due to router congestion
The sending systems packet is lost due to
congestion, and is alerted when it stops
receiving ACKs of packets sent
CLIENT
SERVER
  • Congestion control

forces the End Systems to decrease the rate at
which packets are sent during periods of
congestion
45
TCP Fairness
  • Fairness goal if N TCP sessions share same
    bottleneck link, each should get 1/N of link
    capacity

Go to Summary of TCP Congestion Control
46
Analysis of 2 connections sharing a link
Assumptions
Link with transmission rate of R
Each connection have the same MSS, RTT
No other TCP connections or UDP datagrams
traverse the shared link
Ignore slow start phase of TCP
Operating in congestion-avoidance mode (linear
increase phase)
Goal adjust sending rate of the two connections
to allow for equal bandwidth sharing
47
Why is TCP fair?
  • Two competing sessions
  • Additive increase gives slope of 1, as throughout
    increases
  • multiplicative decrease decreases throughput
    proportionally

R
equal bandwidth share
We can view a simulation on this
A point on the graph depicts the amount of link
bandwidth jointly consumed by the connections
Connection 2 throughput
congestion avoidance additive increase
R
Connection 1 throughput
Full bandwidth utilisation line
View Simulation
48
TCP Latency Modeling
Multiple End Systems sharing a link
1 TCP connection
1 TCP connection
3 TCP connections
Multithreading implementation
1 TCP connection
R bps links transmission rate
Loop holes in TCP
In practice, client/server applications with
smaller RTT gets the available bandwidth more
quickly as it becomes free. Therefore, they have
higher throughputs
Multiple parallel TCP connection allows one
application to get a bigger share of the bandwidth
49
TCP latency modeling
the time from when the client initiates a TCP
connection until when the client receives the
requested object in its entirety
Q How long does it take to receive an object
from a Web server after sending a request?
  • TCP connection establishment time
  • data transfer delay
  • Actual data transmission time
  • Two cases to consider
  • WS/R gt RTT S/R
  • An ACK for the first segment in window returns
    to the Sender before a windows worth of data is
    sent
  • WS/R lt RTT S/R
  • Sender has to wait for an ACK after a windows
    worth of data sent

No data transfer delay
Theres data transfer delay
50
TCP Latency Modeling
SERVER
CLIENT
R bps links transmission rate
FILE
O - Size of object in bits
Assumptions
S number of bits of MSS (max. segment size)
Network is uncongested, with one link between end
systems of rate R
CongWin (fixed) determines the amount of data
that can be sent
No packet loss, no packet corruption, no
retransmissions required
Header overheads are negligible
File to send integer number of segments of size
MSS
Connection establishment, request messages, ACKs,
TCP connection-establishment segments have
negligible transmission times
Initial Threshold of TCP congestion mechanism is
very big
51
TCP latency Modeling
Case Analysis STATIC CONGESTION WINDOW
Case 1 WS/R gt RTT S/R An ACK for the first
segment in window returns to the Sender before a
windows worth of data is sent
Number of segments Rounded up to the nearest
integer
e.g. O256bits, S32bits, W4
Assume W4 segments
52
TCP latency Modeling
Case Analysis STATIC CONGESTION WINDOW
Case 2 WS/R lt RTT S/R Sender has to wait
for an ACK after a windows worth of data sent
If there are k windows, sender will be stalled
(k-1) times
STALLED PERIOD
Case 2 latency 2RTT O/R (K-1)S/R RTT -
WS/R
53
Case Analysis DYNAMIC CONGESTION WINDOW
STALLED PERIOD
O/S15
4 windows
54
Case Analysis DYNAMIC CONGESTION WINDOW
  • We can express K (the number of windows that
    cover the object) in terms of the number of
    segments in the object as follows

55
Case Analysis DYNAMIC CONGESTION WINDOW
  • From the time the server begins to transmit the
    kth window until the time the server receives an
    ACK for the first segment in the window
  • Transmission of kth window
  • Stall Time
  • Latency

56
Exercises
1
TRUE or FALSE
Consider an HTTP Web server using persistent
connections. Suppose the server spawns a separate
process for each client that connects to the
server. Then each of these spawned processes will
have different server port numbers.
True
False
57
Exercises
2
TRUE or FALSE
Host A is sending host B a large file over a TCP
connection. Assume host B has no data to send A.
Host B will not send acknowledgements to host A
because host B cannot piggyback the
acknowledgements on data.
True
False
58
Exercises
3
TRUE or FALSE
The size of the TCP RcvWindow never changes
throughout the duration of the connection.
True
False
Details
59
Exercises
4
TRUE or FALSE
Suppose host A is sending a large file to host B
over a TCP connection. If the sequence number for
a segment of this connection is m, then the
sequence number for the subsequent segment will
necessarily be m1.
True
False
Details
60
Exercises
5
TRUE or FALSE
The TCP segment has a field in its header for
RcvWindow.
True
False
Details
61
Exercises
6
TRUE or FALSE
Suppose that the last SampleRTT in a TCP
connection is equal to 1 sec. Then Timeout for
the connection will necessarily be set to a value
gt 1 sec.
True
False
Details
62
Exercises
7
TRUE or FALSE
Suppose host A sends host B one segment with
sequence number 38 and 4 bytes of data. Then in
this same segment the acknowledgement number is
necessarily 42.
True
False
Details
63
Exercises
8
TRUE or FALSE
Suppose that host A wants to send data over TCP
to host B, and host B wants to send data to host
A over TCP. Two separate TCP connections - one
for each direction - are needed.
True
False
64
Exercises
9
TRUE or FALSE
The MSS is the maximum size of a TCP segment
including headers.
True
False
65
Exercises
10
TRUE or FALSE
In TCP, the acknowledgement number that a host
puts in a segment is the sequence number of the
next byte the host is expecting from the sender.
True
False
66
Exercises
1
MULTIPLE CHOICE
When a TCP segment arrives to a host, the socket
to which the segment is directed depends on
the destination port number
the source IP address of the datagram that
encapsulated the segment
the source port number
all of the above
67
Exercises
2
MULTIPLE CHOICE
UDP has which of the following characteristics
three-way hand shake for connection establishment
regulated send rate
connection state at the server
none of the above
68
Exercises
3
MULTIPLE CHOICE
When a UDP segment arrives to a host, in order
to direct the segment to the appropriate socket,
the OS uses
the destination port number
the source port number
the source IP number
all of the above
69
Exercises
4
See Slide 31 of TCP Presentation-Part 1
MULTIPLE CHOICE
The stop-and-wait protocol is highly inefficient
when
when there is a short distance between source and
destination and the transmission rate is large
when there is a large distance between source and
destination and the transmission rate is low
when there is a large distance between source and
destination and the transmission rate is high
Details
when there is a short distance between source and
destination and the transmission rate is low
70
Exercises
5
MULTIPLE CHOICE
Pipelining requires which of the following?
sender-side buffering of unacknowledged packets
transmitting many packets before receiving
acknowledgements
unique sequence numbers for each in-transit packet
all of the above
71
Exercises
6
MULTIPLE CHOICE
TCP applies fast retransmit to a segment when
the segment's timer expires
when it receives three ACKs for an earlier segment
it estimates unusually large RTTs
none of the above
72
Exercises
7
MULTIPLE CHOICE
In a TCP connection, suppose that loss occurs
whenever the window size of a connection hits W.
Also suppose that the RTT is constant. Then, the
approximate average transmission rate is
WMSS/2 RTT
MSS/RTT
.75 WSS/RTT
WMSS/RTT
73
Exercises
8
MULTIPLE CHOICE
Consider the latency model for static congestion
windows. If the server receives an
acknowledgement for the first data segment in the
first window before the server completes the
transmission of the first window, then the
latency for an object of size O is
Latency 2 RTT O/R - S/R - RTT WS/R
Latency 2 RTT O/R (K-1) S/R RTT - WS/R
Latency 2 RTT
Details
Latency 2 RTT O/R
74
Exercises
9
MULTIPLE CHOICE
Consider the latency model for dynamic
congestion windows. Which of the following
components contribute to latency
the transmission time of the object, O/R
round trip time, RTT
the sum of all the stalled times
all of the above
75
Exercises
10
MULTIPLE CHOICE
Consider the latency model for dynamic
congestion windows. The value P is equal to
the number of times the server stalls
RTT/O
the number of windows that cover the object
none of the above
76
End of Session
Happy Easter!
Write a Comment
User Comments (0)
About PowerShow.com