Computer Networks ns2
Computer Networks ns2
Computer Networks ns2
AIM:
proc finish {} {
global ns nf
$ns flush-trace
#Close the NAM trace file
close $nf
#Execute NAM on the trace file
exec nam o.nam &
exit 0
}
$ns at 1.0 "finish"
$ns run
EXPERIMENT NO :
AIM:
EXPERIMENT NO:
AIM:
#Filename: test2.tcl
#-------Event scheduler object creation--------#
set ns [new Simulator]
#---------finish procedure--------#
proc finish {} {
global ns nf nt
$ns flush-trace
close $nf
close $nt
puts "running nam..."
exec nam test2.nam &
exit 0
}
#Calling finish procedure
$ns at 10.0 "finish"
$ns run
EXPERIMENT NO :
AIM:
EXPERIMENT NO :
AIM: To monitor traffic for Ring topology using NS2
#Create a simulator object
set ns [new Simulator]
#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
#Close the trace file
close $nf
#Executenam on the trace file
exec nam out.nam &
exit0
}
#Create four 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]
#Create links between the nodes
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n2 $n3 1Mb 10ms DropTail
$ns duplex-link $n3 $n4 1Mb 10ms DropTail
$ns duplex-link $n4 $n5 1Mb 10ms DropTail
$ns duplex-link $n5 $n0 1Mb 10ms DropTail
#Create a TCP agent and attach it to node n0
set tcp0 [new Agent/TCP]
$tcp0 set class_ 1
$ns attach-agent $n1 $tcp0
#Create a TCP Sink agent (a traffic sink) for TCP and attach it to node n3
set sink0 [new Agent/TCPSink]
$ns attach-agent $n3 $sink0
#Connect the traffic sources with the traffic sink
$ns connect $tcp0 $sink0
EXPERIMENT NO :
AIM:
To monitor traffic for Star topology using NS2
#Create a simulator object
set ns [new Simulator]
#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
txsize=0
drpSize=0
startTime = 400
stopTime = 0
thru=0
}
{
event = $1
time = $2
node_id = $3
pkt_size = $8
level = $4
# Store start time
if (level == AGT && event == s ) {
if (time < startTime) {
startTime = time
}
# hdr_size = pkt_size % 400
#
pkt_size -= hdr_size
# Store transmitted packets size
txsize++;
}
# Update total received packets size and store packets arrival time
if (level == AGT && event == r ) {
if (time > stopTime) {
stopTime = time
}
# Rip off the header
# hdr_size = pkt_size % 400
# pkt_size -= hdr_size
# Store received packets size
recvdSize++
# thru=(recvdSize/txsize)
# printf( %.2f %.2f \n ,time,thru)>tru2.tr
}
if (level == AGT && event == D ) {
# hdr_size = pkt_size % 400
#
pkt_size -= hdr_size
# Store received packets size
drpSize++
}
}
END {
EXPERIMENT NO :
AIM: To monitor traffic for Mesh topology using NS2
#Create a simulator object
set ns [new Simulator]
#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
#Close the trace file
close $nf
#Executenam on the trace file
exec nam out.nam &
exit 0
}
#Create four nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
#Create links between the nodes
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns duplex-link $n0 $n2 1Mb 10ms DropTail
$ns duplex-link $n0 $n3 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n1 $n3 1Mb 10ms DropTail
$ns duplex-link $n2 $n3 1Mb 10ms DropTail
#Create a TCP agent and attach it to node n0
set tcp0 [new Agent/TCP]
$tcp0 set class_ 1
$ns attach-agent $n1 $tcp0
#Create a TCP Sink agent (a traffic sink) for TCP and attach it to node n3
set sink0 [new Agent/TCPSink]
$ns attach-agent $n3 $sink0
#Connect the traffic sources with the traffic sink
$ns connect $tcp0 $sink0
# Create a CBR traffic source and attach it to tcp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
EXPERIMENT NO :