In my last blog , I gave a brief idea about TCP and TCP states, Lets check how its work in real network by simulating the TCP connection using NS2 simulator.
You can easly install NS2 in Ubunutu using "Ubunutu Software Center", as usual make use of your terminal and install. sudo apt-get install ns2 nam xgraph.
Below NS2 Script contain TCP - TCP compare.
Below NS2 Script contain TCP-UDP compare
you can run these codes using ns.tcl
Above NS2 scripts help you to simulate how TCP's functionality in the real network.
Lets see what has happened!
As shown in Figure 1, the network model was configured with two TCP (TransmissionControl Protocol) flows for two milliseconds and recorded observation in trace files.
Trace files were plotted using “xgraph” utility and it has been shown in figure 2
According to the results given by the experiment, TCP flows fairly shared the network bandwidth.
As shown in Figure 3, additional another experiment was conducted in respect to model the TCP flow and UDP (User Datagram Protocol) flow in shared network environment, which experiment was inspected for two milliseconds. Furthermore, observations were recorded in the trace file as previous experiment.
Second experiment’s trace files were plotted using “xgraph” utility and it has been shown in Figure 4.
According to Figure 5, in first experiment; first TCP flow was shared the bandwidth with second TCP flow. In second experiment; TCP flow was trampled by UDP flow.Hence, as a conclusion of those two experiments, TCP Shares the network resource fairly.Nevertheless, UPD does not share the network resource.
Even though this is irrelevant to this topic, this help us to understand the behavior of the TCP connections.
So what is NS2?
NS2 is a discrete event network simulator. It is aimed at network research, and supports simulation of various facets of networking, including TCP, multicast, and routing protocols.You can easly install NS2 in Ubunutu using "Ubunutu Software Center", as usual make use of your terminal and install. sudo apt-get install ns2 nam xgraph.
Below NS2 Script contain TCP - TCP compare.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Experimention :- TCP flow vs TCP flow | |
# Experimenter :- Sivajothy Vanjikumaran | |
#Create a simulator object | |
set ns [new Simulator] | |
#Colors Define | |
$ns color 1 brown | |
$ns color 2 green | |
#Save throughput for the First tcp flow | |
set f1 [open tcp-tcp-one.tr w] | |
#Save throughput for the Second tcp flow | |
set f2 [open tcp-tcp-two.tr w] | |
#Open the nam trace file | |
set nf [open tcp-out.nam w] | |
$ns namtrace-all $nf | |
#Create nodes | |
set n0 [$ns node] | |
set n1 [$ns node] | |
set n2 [$ns node] | |
set n3 [$ns node] | |
set n4 [$ns node] | |
set n5 [$ns node] | |
#Links between the nodes | |
$ns duplex-link $n0 $n2 1Mb 10ms DropTail | |
$ns duplex-link $n1 $n2 1Mb 10ms DropTail | |
$ns duplex-link $n3 $n4 1Mb 10ms DropTail | |
$ns duplex-link $n3 $n5 1Mb 10ms DropTail | |
# Making a bottle neck connection | |
$ns duplex-link $n2 $n3 1Mb 10ms DropTail | |
# | |
#(0)- -(4) | |
# \ / | |
# (2)-----(3) | |
# / \ | |
#(1)- -(5) | |
# | |
#layout of the data transferring path | |
$ns duplex-link-op $n0 $n2 orient right-down | |
$ns duplex-link-op $n1 $n2 orient right-up | |
$ns duplex-link-op $n2 $n3 orient right | |
$ns duplex-link-op $n3 $n4 orient right-up | |
$ns duplex-link-op $n3 $n5 orient right-down | |
#Queue limit between node n2 & n3 (Bottle neck) | |
$ns queue-limit $n2 $n3 10 | |
#Creation of TCP 1 agent and attach it to node n0 | |
set tcp1 [new Agent/TCP/Vegas] | |
$ns attach-agent $n0 $tcp1 | |
# Max bound on window size | |
$tcp1 set window_ 20 | |
# Set flow ID field | |
$tcp1 set fid_ 1 | |
#Creation of a TCP 2 agent and attach it to node n1 | |
set tcp2 [new Agent/TCP/Vegas] | |
$ns attach-agent $n1 $tcp2 | |
# max bound on window size | |
$tcp2 set window_ 20 | |
# set flow ID field | |
$tcp2 set fid_ 2 | |
#Creation of TCP sinks agents | |
set sink1 [new Agent/TCPSink] | |
set sink2 [new Agent/TCPSink] | |
#Attach Sinks to nodes | |
$ns attach-agent $n4 $sink1 | |
$ns attach-agent $n5 $sink2 | |
$ns connect $tcp1 $sink1 | |
$ns connect $tcp2 $sink2 | |
#Creation of FTP applications + attach to agents | |
set ftp1 [new Application/FTP] | |
$ftp1 attach-agent $tcp1 | |
set ftp2 [new Application/FTP] | |
$ftp2 attach-agent $tcp2 | |
#Define a 'finish' procedure | |
proc finish {} { | |
global ns | |
$ns flush-trace | |
puts "running nam..." | |
exec nam -a tcp-out.nam & | |
exec xgraph tcp-tcp-one.tr tcp-tcp-two.tr -geometry 800x400+10+10 -x "Time -ms" -y "Throughtput -Kbps" -t "Vanjikumaran's TCP-TCP Experiment" & | |
exit 0 | |
} | |
proc record {} { | |
global sink1 sink2 ns f1 f2 | |
#Set the time the procedure should be called again | |
set time 0.1 | |
set bw0 [$sink1 set bytes_] | |
set bw1 [$sink2 set bytes_] | |
#Get the current time | |
set now [$ns now] | |
# throughtput in Kbps | |
puts $f1 "$now [expr ($bw0 * 8) / ($time * 1024)]" | |
puts $f2 "$now [expr ($bw1 * 8) / ($time * 1024)]" | |
$sink1 set bytes_ 0 | |
$sink2 set bytes_ 0 | |
#Call procedure again | |
$ns at [expr $now + $time] "record" | |
} | |
$ns at 0.0 "record" | |
$ns at 0.2 "$ftp1 start" | |
$ns at 0.4 "$ftp2 start" | |
$ns at 2.0 "$ftp1 stop" | |
$ns at 2.0 "$ftp2 stop" | |
$ns at 2.2 "finish" | |
$ns run |
Below NS2 Script contain TCP-UDP compare
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Experimention :- TCP flow vs UDP flow | |
# Experimenter :- Sivajothy Vanjikumaran | | |
#Create a simulator object | |
set ns [new Simulator] | |
#Colors Define | |
$ns color 1 brown | |
$ns color 2 green | |
#Save throughput for the First tcp flow | |
set f1 [open tcp-tcp_Exp1.tr w] | |
#Save throughput for the Second tcp flow | |
set f2 [open tcp-udp_Exp2.tr w] | |
#Open the nam trace file | |
set nf [open tcp_udp_nam.nam w] | |
$ns namtrace-all $nf | |
#Create nodes | |
set n0 [$ns node] | |
set n1 [$ns node] | |
set n2 [$ns node] | |
set n3 [$ns node] | |
set n4 [$ns node] | |
set n5 [$ns node] | |
#Links between the nodes | |
$ns duplex-link $n0 $n2 1Mb 10ms DropTail | |
$ns duplex-link $n1 $n2 1Mb 10ms DropTail | |
$ns duplex-link $n3 $n4 1Mb 10ms DropTail | |
$ns duplex-link $n3 $n5 1Mb 10ms DropTail | |
# Making a bottle neck connection | |
$ns duplex-link $n2 $n3 1Mb 10ms DropTail | |
# | |
#(0)- -(4) | |
# \ / | |
# (2)-----(3) | |
# / \ | |
#(1)- -(5) | |
# | |
#layout of the data transferring path | |
$ns duplex-link-op $n0 $n2 orient right-down | |
$ns duplex-link-op $n1 $n2 orient right-up | |
$ns duplex-link-op $n2 $n3 orient right | |
$ns duplex-link-op $n3 $n4 orient right-up | |
$ns duplex-link-op $n3 $n5 orient right-down | |
#Queue limit between node n2 & n3 (Bottle neck) | |
$ns queue-limit $n2 $n3 25 | |
#Creation of TCP agent and attach it to node n0 | |
set tcp [new Agent/TCP] | |
$ns attach-agent $n0 $tcp | |
# Max bound on window size | |
$tcp set window_ 10 | |
# Set flow ID field | |
$tcp set fid_ 1 | |
#Creation of a UDP agent and attach it to node n1 | |
set udp [new Agent/UDP] | |
$ns attach-agent $n1 $udp | |
# max bound on window size | |
$udp set window_ 10 | |
# set flow ID field | |
$udp set fid_ 2 | |
#Creation of TCP sinks agents | |
set sink1 [new Agent/TCPSink] | |
#Creation of UDP Reciver Agent | |
set sink2 [new Agent/LossMonitor] | |
#Attach Sinks to nodes | |
$ns attach-agent $n4 $sink1 | |
$ns attach-agent $n5 $sink2 | |
$ns connect $tcp $sink1 | |
$ns connect $udp $sink2 | |
#Creation of FTP applications + attach to agents | |
set ftp [new Application/FTP] | |
$ftp attach-agent $tcp | |
#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_ 1mb | |
$cbr set random_ false | |
#Define a 'finish' procedure | |
proc finish {} { | |
global ns | |
$ns flush-trace | |
puts "running nam..." | |
exec nam -a tcp_udp_nam.nam & | |
exec xgraph tcp-tcp_Exp1.tr tcp-udp_Exp2.tr -geometry 800x400+10+10 -x "Time -ms" -y "Throughtput -Kbps" -t "Vanjikumaran's TCP-UDP Experiment" & | |
exit 0 | |
} | |
proc record {} { | |
global sink1 sink2 ns f1 f2 | |
#Set the time the procedure should be called again | |
set time 0.1 | |
set bw0 [$sink1 set bytes_] | |
set bw1 [$sink2 set bytes_] | |
#Get the current time | |
set now [$ns now] | |
# throughtput in Kbps | |
puts $f1 "$now [expr ($bw0 * 8) / ($time * 1024)]" | |
puts $f2 "$now [expr ($bw1 * 8) / ($time * 1024)]" | |
$sink1 set bytes_ 0 | |
$sink2 set bytes_ 0 | |
#Call procedure again | |
$ns at [expr $now + $time] "record" | |
} | |
$ns at 0.0 "record" | |
$ns at 0.2 "$ftp start" | |
$ns at 0.4 "$cbr start" | |
$ns at 2.0 "$ftp stop" | |
$ns at 2.0 "$cbr stop" | |
$ns at 2.2 "finish" | |
$ns run |
you can run these codes using ns
Above NS2 scripts help you to simulate how TCP's functionality in the real network.
Lets see what has happened!
As shown in Figure 1, the network model was configured with two TCP (TransmissionControl Protocol) flows for two milliseconds and recorded observation in trace files.
![]() |
Figure 1 |
![]() |
Figure 2 |
As shown in Figure 3, additional another experiment was conducted in respect to model the TCP flow and UDP (User Datagram Protocol) flow in shared network environment, which experiment was inspected for two milliseconds. Furthermore, observations were recorded in the trace file as previous experiment.
![]() |
Figure 3 |
In accordance with the second experimental result given in the Figure 4, UPD flow was taken over the shared network resource from TCP flow and it did not moderately shared the band with it .
![]() |
Figure 4 |
According to Figure 5, in first experiment; first TCP flow was shared the bandwidth with second TCP flow. In second experiment; TCP flow was trampled by UDP flow.Hence, as a conclusion of those two experiments, TCP Shares the network resource fairly.Nevertheless, UPD does not share the network resource.
Even though this is irrelevant to this topic, this help us to understand the behavior of the TCP connections.
No comments:
Post a Comment