Date post: | 03-Jan-2016 |
Category: |
Documents |
Upload: | benjamin-malone |
View: | 219 times |
Download: | 0 times |
TNK092: Network Simulation - Nätverkssimulering
Lecture 3: TCP
Vangelis Angelakis
The Transport Control Protocol (TCP)
2
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
Regulate TCP transmission rate ensuring that packets can be transmitted
only when others have left the network Render the connection reliable by
transmitting to the source information it
need so as to retransmit packets that
have not reached destination TCP packet is considered lost if
Three ACKs for the same packets
arrive at the source Or time’s out…
with a = 7/8 typically
Acknowledgements
3
Host A
Seq=92, 8 bytes data
ACK=100
loss
timeo
ut
A lost ACK scenario
Host B
X
Seq=92, 8 bytes data
ACK=100
time
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
.
Flow vs. Congestion Control
4
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 as long as segments are not lost (dropped at routers) due to
congestion. A TCP connection starts with a small value of w
"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.
Congestion Control
5
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:
1) the congestion window is below the threshold and
2) the acknowledgements arrive before their corresponding timeouts.
Notice each step effectively doubles the congestion window
Congestion Control
6
Host A
RT
T
Host B
time
one segment
two segments
four segments
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.
Congestion Control
7
Host A
RT
T
Host B
time
one segment
two segments
four segments
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
Congestion Control
8
Tahoe
A loss is detected then the window reduces to the value of 1 and slow start phase begins
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.
Congestion Control: Summary
9
Example 1
10
set ns [new Simulator]
#Define different colors for #data flows (for NAM)$ns color 1 Blue$ns color 2 Red
#Open the Trace filesset file1 [open out.tr w]set winfile [open WinFile w]$ns trace-all $file1
#Open the NAM trace fileset file2 [open out.nam w]$ns namtrace-all $file2
#Define a 'finish' procedureproc finish {} {global ns file1 file2$ns flush-traceclose $file1close $file2exec nam out.nam &exit 0}
#Create six nodesset n0 [$ns node]set n1 [$ns node]set n2 [$ns node]set n3 [$ns node]set n4 [$ns node]set n5 [$ns 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
Example 1
11
#Setup a TCP connectionset tcp [new Agent/TCP/Newreno]$ns attach-agent $n0 $tcpset 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 connectionset ftp [new Application/FTP]$ftp attach-agent $tcp$ftp set type_ FTP
#Setup a UDP connectionset udp [new Agent/UDP]$ns attach-agent $n1 $udpset null [new Agent/Null]$ns attach-agent $n5 $null$ns connect $udp $null$udp set fid_ 2
#Setup a CBR over UDP connectionset 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 nsset time 0.1set 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
Tracing and analysis
12
Throughput of TCP connection „ Window size of TCP connection
TCP over Noisy links
13
Assume that packets are dropped on the forward link independently with some fixed constant probability
#set error model on link n2 to n3set 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
Queue monitoring
14
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 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 columns1. time
2. input queue node
3. output queue node
4. queue size in bytes
5. queue size in packets
6. number of packets that have arrived
7. number of packets that have departure the link
8. number of packets dropped at the queue
9. number of bytes that have arrived
10. number of bytes that have departure the link
11. number of bytes dropped
Queue monitoring
15
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 0Time From To qsizeB qsizeP arrivedP departedP droppedP arrivedB departedB droppedB
Connections with random features
16
ex3.tcl
„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
Connections with random features (ex3.tcl)
17
…
set NumbSrc 5set Duration 10
#Source nodesfor {set j 1} {$j<=$NumbSrc} {incr j }{ set S($j) [$ns node]}
# Create a random generator# for starting ftp and# for bottleneck link delaysset rng [new RNG]$rng seed 0
# paratmers for random variables# for delaysset RVdly [new RandomVariable/Uniform]$RVdly set min_ 1$RVdly set max_ 5$RVdly use-rng $rng
# parameters for random variables for # beginning of ftp connectionsset RVstart [new RandomVariable/Uniform]$RVstart set min_ 0$RVstart set max_ 7$RVstart use-rng $rng
# Define 2 random params for each connectionfor {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"}
#Links between source and bottleneckfor {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}
Connections with random features (ex3.tcl)
18
# 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 Sourcesfor {set j 1} {$j<=$NumbSrc} { incr j }
{set tcp_src($j) [new Agent/TCP/Reno]}
# TCP Destinationsfor {set j 1} {$j<=$NumbSrc} { incr j } { set tcp_snk($j) [new Agent/TCPSink]}
# Connectionsfor {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)}
# FTP sourcesfor {set j 1} {$j<=$NumbSrc} { incr j } { set ftp($j) [$tcp_src($j) attach-source FTP]}
# Parametrisation of TCP sourcesfor {set j 1} {$j<=$NumbSrc} { incr j } { $tcp_src($j) set packetSize_ 552}
# 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"}
Short rt TCP connections
19
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
Short TCP connections
20
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 queueset qflie [$ns monitor-queue $N $D [open queue.tr w] 0.05][$ns link $N $D] queue-sample-timeout;
Short TCP connections
21
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