congestion control

advertisement
TNK092:
Network Simulation - Nätverkssimulering
Lecture 3: TCP
Vangelis Angelakis
The Transport Control Protocol (TCP)

Objectives of TCP and flow control



Adapt the transmission rate of packets to the available bandwidth
Avoid congestion at the network
Create a reliable connection by retransmitting lost packets
2
Acknowledgements
Regulate TCP transmission rate



Host B
ensuring that packets can be transmitted
only when others have left the network
Render the connection reliable by

Host A
transmitting to the source information it
need so as to retransmit packets that
have not reached destination
timeout

X
loss
TCP packet is considered lost if


Three ACKs for the same packets
arrive at the source
Or time’s out…
time
A lost ACK scenario
with a = 7/8 typically
3
Flow vs. Congestion Control

flow control







eliminates the possibility of the sender overflowing the receiver's
buffer.
matching the rate at which the sender is sending to the rate at
which the receiving application is reading
a TCP sender can also be throttled due to congestion within
the IP network; this form of sender control is referred to
as congestion control
Actions taken by flow and congestion control are similar (the
throttling of the sender), they are obviously taken for very
different reasons.
Caution as many use the term interchangeably (dead wrong)
TCP provides flow control by having the sender maintain a
variable called the receive window RcvWindow
.
4
Congestion Control



A TCP connection controls its transmission rate by limiting its
number of transmitted-but-yet-to-be-acknowledged segments.
TCP window size w, number of segments that can be sent
Ideally, TCP connections should be allowed to transmit as fast as
possible


A TCP connection starts with a small value of w


as long as segments are not lost (dropped at routers) due to
congestion.
"probes" for the existence of additional unused link bandwidth at the
links on its end-to-end path by increasing w.
The TCP connection continues to increase w until a segment loss
occurs (as detected by a timeout or duplicate acknowledgements).

When such a loss occurs, the TCP connection reduces w to a "safe
level" and then begins probing again for unused bandwidth by slowly
increasing w.
5
Congestion Control





1)
2)

Slow start phase: exponential growth
of the window
Initially, the congestion window is equal to one MSS.
TCP sends the first segment into the network and
waits for an acknowledgement.
If this segment is acknowledged before its timer times
out, the sender increases the congestion window by
one MSS and sends out two maximum-size segments.
If these segments are acknowledged before their
timeouts, the sender increases the congestion window
by one MSS for each of the acknowledged segments,
giving a congestion window of four MSS, and sends
out four maximum-sized segments.
& so on as long as:
the congestion window is below the threshold and
the acknowledgements arrive before their
corresponding timeouts.
Notice each step effectively doubles the congestion
window
Host A
Host B
RTT

time
6
Congestion Control
Congestion Avoidance: Linear increase

Slow Start ends when the window size exceed the value
of threshold.
Once the congestion window is larger than the current
value of threshold, if w is the current value of the
congestion window, w > threshold, then
after w acknowledgements have arrived, TCP
replaces w with w + 1.


The congestion avoidance phase continues as long
as the acknowledgements arrive before their
corresponding timeouts. But the window size, and hence
the rate at which the TCP sender can send, can not
increase forever. Eventually, the TCP rate will be such
that one of the links along the path becomes saturated,
and which point loss (and a resulting timeout at the
sender) will occur. When a timeout occurs, the value
of threshold is set to half the value of the current
congestion window, and the congestion window is reset to
one MSS. The sender then again grows the congestion
window exponentially fast using the slow start procedure
until the congestion window hits the threshold.
Host A
Host B
RTT

time
7
Congestion Control



Losses and a dynamic
threshold Wth
Wth is fixed in TCP to half
the value of W when there
has been a packet loss
Reno or New-Reno
The window drops to 1 only
if the loss is detected
through a time-out
A loss is detected through
repeated ACKs then the
congestion window drops by
half
 Remain in the “congestion
avoidance” phase


Tahoe
A loss is detected then
the window reduces to
the value of 1 and slow
start phase begins
8
Congestion Control: Summary

When CongWin is below Threshold, sender in slow-start
phase, window grows exponentially.

When CongWin is above Threshold, sender is in
congestion-avoidance phase, window grows linearly.

When a triple duplicate ACK occurs, Threshold set to
CongWin/2 and CongWin set to Threshold.

When timeout occurs, Threshold set to CongWin/2 and
CongWin is set to 1 MSS.
9
Example 1
set ns [new Simulator]
#Define different colors for
#data flows (for NAM)
$ns color 1 Blue
$ns color 2 Red
#Open the Trace files
set file1 [open out.tr w]
set winfile [open WinFile w]
$ns trace-all $file1
#Open the NAM trace file
set file2 [open out.nam w]
$ns namtrace-all $file2
#Define a 'finish' procedure
proc finish {} {
global ns file1 file2
$ns flush-trace
close $file1
close $file2
exec nam out.nam &
exit 0
}
#Create six
set n0 [$ns
set n1 [$ns
set n2 [$ns
set n3 [$ns
set n4 [$ns
set n5 [$ns
nodes
node]
node]
node]
node]
node]
node]
#Create links between the nodes
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns simplex-link $n2 $n3 0.3Mb 100ms DropTail
$ns simplex-link $n3 $n2 0.3Mb 100ms DropTail
$ns duplex-link $n3 $n4 0.5Mb 40ms DropTail
$ns duplex-link $n3 $n5 0.5Mb 30ms DropTail
#Give node position (for NAM)
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns simplex-link-op $n2 $n3 orient right
$ns simplex-link-op $n3 $n2 orient left
$ns duplex-link-op $n3 $n4 orient right-up
$ns duplex-link-op $n3 $n5 orient right-down
#Set Queue Size of link (n2-n3) to 10
$ns queue-limit $n2 $n3 10
10
Example 1
#Setup a TCP connection
set tcp [new Agent/TCP/Newreno]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink/DelAck]
$ns attach-agent $n4 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
$tcp set window_ 8000
$tcp set packetSize_ 552
#Setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
#Setup a UDP connection
set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n5 $null
$ns connect $udp $null
$udp set fid_ 2
#Setup a CBR over UDP connection
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 0.01mb
$cbr set random_ false
$ns at 0.1 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 124.0 "$ftp stop"
$ns at 124.5 "$cbr stop"
# next procedure gets two arguments: the name of the
# tcp source node, will be called here "tcp",
# and the name of output file.
proc plotWindow {tcpSource file} {
global ns
set time 0.1
set now [$ns now]
set cwnd [$tcpSource set cwnd_]
set wnd [$tcpSource set window_]
puts $file "$now $cwnd"
$ns at [expr $now+$time] "plotWindow $tcpSource $file" }
$ns at 0.1 "plotWindow $tcp $winfile"
$ns at 125.0 "finish"
$ns run
11
Tracing and analysis
Throughput of TCP connection
„
Window size of TCP connection
12
TCP over Noisy links

Assume that packets are dropped on the forward link
independently with some fixed constant probability
#set error model on link n2 to n3
set loss_module [new ErrorModel]
# a loss rate of 20% of the packets
$loss_module set rate_ 0.2
# uses a generator of a uniformly distributed random variable
$loss_module ranvar [new RandomVariable/Uniform]
$loss_module drop-target [new Agent/Null]
$ns lossmodel $loss_module $n2 $n3
http://www-sop.inria.fr/members/Eitan.Altman/COURS-NS/TCL+PERL/TCP-rand-dr/rdrop.tcl
13
Queue monitoring

ns allows to collect much useful information on queue length,
arrivals, departures and losses
set qmon [$ns monitor-queue $n2 $n3 [open qm.out w] 0.1];
[$ns link $n2 $n3] queue-sample-timeout; # [$ns link $n2 $n3] start-tracing

The “monitor-queue” object has 4 arguments




1.
2.
3.
4.
5.
The first two defines the link where the queue is located
The third is the output trace file
The last says how frequently we wish to monitor the queue
Output file contains the following 11 columns
time
input queue node
output queue node
queue size in bytes
queue size in packets
6.
7.
8.
9.
10.
11.
number of packets that have arrived
number of packets that have departure the link
number of packets dropped at the queue
number of bytes that have arrived
number of bytes that have departure the link
number of bytes dropped
14
Queue monitoring




To monitor a queue between two nodes use monitor-queue:
$ns monitor-queue
Sets up a monitor that keeps track of average queue length of
the queue on the link between nodes
The default value of sample interval is 0.1.
Eg:
set monitor [$ns monitor-queue $S $D [open qm.out w] 0.1]

Trace format :
0.69996 0 1 0.0 0.0 12 12 0 5178 5178 0
Time From To qsizeB qsizeP arrivedP departedP droppedP arrivedB departedB droppedB
15
Connections with random features

„5 FTP connections that start at random
Starting time is uniformly distributed between 0 and 7 sec

The whole simulation duration is 10 sec

Links with delay that is chosen at random, uniformly distributed
between 1ms and 5ms

ex3.tcl
16
Connections with random features (ex3.tcl)
…
set NumbSrc 5
set Duration 10
#Source nodes
for {set j 1} {$j<=$NumbSrc} {incr j }
{
set S($j) [$ns node]
}
# parameters for random variables for
# beginning of ftp connections
set RVstart [new RandomVariable/Uniform]
$RVstart set min_ 0
$RVstart set max_ 7
$RVstart use-rng $rng
# Create a random generator
# for starting ftp and
# for bottleneck link delays
set rng [new RNG]
$rng seed 0
# Define 2 random params for each connection
for {set i 1} {$i<=$NumbSrc} { incr i } {
set startT($i) [expr [$RVstart value]]
set dly($i) [expr [$RVdly value]]
puts $param "dly($i) $dly($i) ms"
puts $param "startT($i) $startT($i) sec"
}
# paratmers for random variables
# for delays
set RVdly [new RandomVariable/Uniform]
$RVdly set min_ 1
$RVdly set max_ 5
$RVdly use-rng $rng
#Links between source and bottleneck
for {set j 1} {$j<=$NumbSrc} { incr j } {
$ns duplex-link $S($j) $n2 10Mb $dly($j)ms
DropTail
$ns queue-limit $S($j) $n2 100
}
17
Connections with random features (ex3.tcl)
# Monitor queue for link (n2-n3) --NAM
$ns duplex-link-op $n2 $n3 queuePos 0.5
# Set Queue Size of link (n2-n3) to 10
$ns queue-limit $n2 $n3 10
# TCP Sources
for {set j 1} {$j<=$NumbSrc} { incr j }
{
set tcp_src($j) [new Agent/TCP/Reno]
}
# FTP sources
for {set j 1} {$j<=$NumbSrc} { incr j }
{
set ftp($j) [$tcp_src($j) attach-source FTP]
}
# TCP Destinations
for {set j 1} {$j<=$NumbSrc} { incr j }
{
set tcp_snk($j) [new Agent/TCPSink]
}
# Parametrisation of TCP sources
for {set j 1} {$j<=$NumbSrc} { incr j }
{
$tcp_src($j) set packetSize_ 552
}
# Connections
for {set j 1} {$j<=$NumbSrc} { incr j }
{
$ns attach-agent $S($j) $tcp_src($j)
$ns attach-agent $n3 $tcp_snk($j)
$ns connect $tcp_src($j) $tcp_snk($j)
}
# Schedule events for the FTP agents:
for {set i 1} {$i<=$NumbSrc} { incr i }
{
$ns at $startT($i) "$ftp($i) start"
$ns at $Duration "$ftp($i) stop"
}
18
Short rt TCP connections

Ways to simulate short sessions.


To measure the distribution of the transmission duration, of the
number of ongoing connections and the throughput
Topology








New TCP connections arrive according to a Poisson process
Bottleneck link : 2Mbps, 1ms, queue size 3000
Other input links : 100Mbps, 1ms
New Reno with a maximum window size of 2000
The average time between the arrivals of new TCP sessions at
each node is in example 45msec
22.22 new sessions arrive at each node: 133.33 session/sec
Generate sessions with random size with mean 10Kbytes with a
Pareto distribution with shape 1.5
The global rate of generation of bits 133.33×10 4×8 = 10.67Mbps
19
Short TCP connections


Monitoring the number of sessions
Recursive procedure, called “ test”, that checks for each
session whether it has ended

To check whether a session has ended, use:
if {[$tcpsrc($i, $j) set ack_]==[$tcpsrc($i, $j) set maxseq_]}

an output file contains:
- The connection identifiers i and j (where (i,j) stands for the jth
connection from node i)
- The start and end time of that connection
- The throughput of that connection
- The size of that transfer in bytes
- Another recursive procedure called “countFlows” is used to
update the
number of active connections from each node

Monitoring the queue
set qflie [$ns monitor-queue $N $D [open queue.tr w] 0.05]
[$ns link $N $D] queue-sample-timeout;
20
Short TCP connections

The number of packets at the queue is larger than the number
of Kbytes queued



A very large number of sessions are very small (3packets or less)
The number of over head packets of size 40 bytes is considerable
„All packets at the queue are TCP data packets and there no
packets of 40 bytes corresponding to beginning of session
21
Download