CN Lab Simulation Programs-BCS502
Dept of ISE, SJCIT, Chickballapur
1. Implement Three nodes point – to – point network with duplex links
between them for different topologies. 1Set the queue size, vary the
bandwidth, and find the number of packets dropped for various
iterations.
p1.tcl
set ns [ new Simulator ]
set tf [ openp1.tr w ]
$ns trace-all $tf
set nf [ open p1.nam w ]
$ns namtrace-all $nf
# The below code is used to create the nodes.
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
#This is used to give color to the packets.
$ns color 1 "red"
$ns color 2 "blue"
$n0 label "Source/udp0"
$n1 label "Source/udp1"
$n2 label "Router"
$n3 label "Destination/Null"
#Vary the below Bandwidth and see the number of packets dropped.
$ns duplex-link $n0 $n2 10Mb 300ms DropTail
$ns duplex-link $n1 $n2 10Mb 300ms DropTail
$ns duplex-link $n2 $n3 1Mb 300ms DropTail
#The below code is used to set the queue size b/w the nodes
$ns set queue-limit $n0 $n2 10
$ns set queue-limit $n1 $n2 10
$ns set queue-limit $n2 $n3 5
#The below code is used to attach an UDP agent to n0,
#UDP agent to n1 and null agent to n3.
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
set null [new Agent/Null]
$ns attach-agent $n3 $null
set udp1 [new Agent/UDP]
$ns attach-agent $n1 $udp1
set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp1
#The below code sets the udp0 packets to red and udp1 packets to blue color
$udp0 set class_ 1
$udp1 set class_ 2
#The below code is used to connect the agents.
$ns connect $udp0 $null
$ns connect $udp1 $null
#The below code is used to set the packet size to 500
$cbr1 set packetSize_ 500Mb
#The below code is used to set the interval of the packets, i.e., Data rate of the packets.
#if the data rate is high then packets drops are high.
$cbr1 set interval_ 0.005
proc finish { } {
global ns nf tf
$ns flush-trace
exec nam p1.nam &
close $tf
close $nf
exit 0
}
$ns at 0.1 "$cbr0 start"
$ns at 0.1 "$cbr1 start"
$ns at 10.0 "finish"
$ns run
Execution
#Run the program using command: ns p1.tcl
p1.awk
BEGIN{
#include<stdio.h>
count=0;
}
{
if($1=="d")
#d stands for the packets drops.
count++
} END{
printf("The Total no of Packets Dropped due to Congestion :%d\n\n", count)
}
#Run awk program usinng commad: awk -f p1.awk p1.tr
2. Implement transmission of ping messages/trace route over a network topology
consisting of 6 nodes and find the number of packets dropped due to congestion
in the network.
p2.tcl
set ns [new Simulator]
set nf [open p2.nam w]
$ns namtrace-all $nf
set nd [open p2.tr w]
$ns trace-all $nd
proc finish {} {
global ns nf nd
$ns flush-trace
close $nf
close $nd
exec nam p2.nam &
exit 0
}
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
set n6 [$ns node]
$ns duplex-link $n1 $n0 1Mb 10ms DropTail
$ns duplex-link $n2 $n0 1Mb 10ms DropTail
$ns duplex-link $n3 $n0 1Mb 10ms DropTail
$ns duplex-link $n4 $n0 1Mb 10ms DropTail
$ns duplex-link $n5 $n0 1Mb 10ms DropTail
$ns duplex-link $n6 $n0 1Mb 10ms DropTail
Agent/Ping instproc recv {from rtt} {
$self instvar node_
puts "node [$node_ id] recieved ping answer from \$from with round-trip-time $rtt
ms."
}
set p1 [new Agent/Ping]
set p2 [new Agent/Ping]
set p3 [new Agent/Ping]
set p4 [new Agent/Ping]
set p5 [new Agent/Ping]
set p6 [new Agent/Ping]
$ns attach-agent $n1 $p1
$ns attach-agent $n2 $p2
$ns attach-agent $n3 $p3
$ns attach-agent $n4 $p4
$ns attach-agent $n5 $p5
$ns attach-agent $n6 $p6
$ns queue-limit $n0 $n4 1
$ns queue-limit $n0 $n5 1
$ns queue-limit $n0 $n6 1
$ns connect $p1 $p4
$ns connect $p2 $p5
$ns connect $p3 $p6
$ns at 0.1 "$p1 send"
$ns at 0.1 "$p2 send"
$ns at 0.1 "$p3 send"
$ns at 0.2 "$p4 send"
$ns at 0.2 "$p5 send"
$ns at 0.2 "$p6 send"
$ns at 0.1 "$p1 send"
$ns at 0.1 "$p2 send"
$ns at 0.1 "$p3 send"
$ns at 0.2 "$p4 send"
$ns at 0.2 "$p5 send"
$ns at 0.2 "$p6 send"
$ns at 2.0 "finish"
$ns run
Execution:
#Run the program using command: ns p2.tcl
p2.awk
BEGIN {
count=0;
}
{
event=$1;
if(event=="d")
{
count++;
}
}
END {
printf("No of packets dropped : %d\n",count);
}
Execution
#Run the program using command: awk -f p2.awk p2.tr
3. Implement an Ethernet LAN using n nodes and set multiple traffic nodes and
plot congestion window for different source / destination.
p3.tcl
set ns [new Simulator]
set nf [open m4p1.nam w]
$ns namtrace-all $nf
set nd [open m4p1.tr w]
$ns trace-all $nd
$ns color 1 Blue
$ns color 2 Red
proc finish { } {
global ns nf nd
$ns flush-trace
close $nf
close $nd
exec nam m4p1.nam &
exit 0
}
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
set n6 [$ns node]
set n7 [$ns node]
set n8 [$ns node]
$n7 shape box
$n7 color Blue
$n8 shape hexagon
$n8 color Red
$ns duplex-link $n1 $n0 2Mb 10ms DropTail
$ns duplex-link $n2 $n0 2Mb 10ms DropTail
$ns duplex-link $n0 $n3 1Mb 20ms DropTail
$ns make-lan "$n3 $n4 $n5 $n6 $n7 $n8" 512Kb 40ms LL Queue/DropTail Mac/802_3
$ns duplex-link-op $n1 $n0 orient right-down
$ns duplex-link-op $n2 $n0 orient right-up
$ns duplex-link-op $n0 $n3 orient right
$ns queue-limit $n0 $n3 20
set tcp1 [new Agent/TCP/Vegas]
$ns attach-agent $n1 $tcp1
set tcp2 [new Agent/TCP/Vegas]
$ns attach-agent $n2 $tcp2
set sink1 [new Agent/TCPSink]
$ns attach-agent $n7 $sink1
$ns connect $tcp1 $sink1
set sink2 [new Agent/TCPSink]
$ns attach-agent $n8 $sink2
$ns connect $tcp2 $sink2
$tcp1 set class_ 1
$tcp1 set packetSize_ 55
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
set ftp2 [new Application/FTP]
$ftp2 attach-agent $tcp2
set f1 [open file1.tr w]
$tcp1 attach $f1
$tcp1 trace cwnd_
set f2 [open file2.tr w]
$tcp2 attach $f2
$tcp2 trace cwnd_
$ns at 0.5 "$ftp1 start"
$ns at 1.0 "$ftp2 start"
$ns at 5.0 "$ftp2 stop"
$ns at 5.0 "$ftp1 stop"
$ns at 5.5 "finish"
$ns run
Execution:
#Run the program using command: ns p3.tcl
p3.awk
BEGIN {
}
{
if($6=="cwnd_")
{
printf("%f\t%f\n",$1,$7);
}
}
END {
}
Execution:
#Run the program using following commands:
awk -f p3.awk file1.tr > tcp1
awk -f p3.awk file2.tr > tcp2
xgraph tcp1 tcp2 (This will plot congestion window)