0% found this document useful (0 votes)
17 views3 pages

Experiment - 4: Pranshu Awasthi 18102276

This document describes a network simulation experiment using the NS2 simulator. It defines 9 nodes connected in a ring topology with additional links forming a LAN between nodes 5, 6, 7 and 8. UDP and TCP agents are created and attached to node 0 along with a CBR and FTP application. The CBR application sends traffic to a null agent from 0.5 to 4.5 seconds while the FTP application sends to a sink agent over TCP during the same period. Traces are recorded and the simulation ends at 5 seconds.

Uploaded by

Pranshu Awasthi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

Experiment - 4: Pranshu Awasthi 18102276

This document describes a network simulation experiment using the NS2 simulator. It defines 9 nodes connected in a ring topology with additional links forming a LAN between nodes 5, 6, 7 and 8. UDP and TCP agents are created and attached to node 0 along with a CBR and FTP application. The CBR application sends traffic to a null agent from 0.5 to 4.5 seconds while the FTP application sends to a sink agent over TCP during the same period. Traces are recorded and the simulation ends at 5 seconds.

Uploaded by

Pranshu Awasthi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

EXPERIMENT - 4

Pranshu Awasthi
18102276
CODE :
set ns [new Simulator]
# defining trace files
set tracefile1 [open out.tr w]
$ns trace-all $tracefile1
set namfile [open out.nam w]
$ns namtrace-all $namfile
#define finish procedure
proc finish {} {
global ns tracefile1 namfile
$ns flush-trace
close $tracefile1
close $namfile
exec nam out.nam &
exit 0
}
#define 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]
set n6 [$ns node]
set n7 [$ns node]
set n8 [$ns node]
$n1 color Red
$n2 shape box

Pranshu Awasthi
18102276
#link
$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 $n6 1Mb 10ms DropTail
$ns duplex-link $n6 $n7 1Mb 10ms DropTail
$ns duplex-link $n7 $n8 1Mb 10ms DropTail
$ns duplex-link $n8 $n0 1Mb 10ms DropTail
set lan [$ns newLan "$n5 $n6 $n7 $n8" 0.5Mb 40ms LL Queue/DropTail MAC/Csma/Cd
Channel]

#create udp agent


set udp0 [new Agent/UDP]
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $udp0
$ns attach-agent $n0 $tcp0
#create a null agent [sink]
set null0 [new Agent/Null]
$ns attach-agent $n0 $null0
set sink0 [new Agent/TCPSink]
$ns attach-agent $n5 $sink0
#create CBR
set cbr0 [new Application/Traffic/CBR]
set ftp0 [new Application/FTP]
$cbr0 set packetSize_ 500
$tcp0 set packetSize_ 500
$cbr0 set rate_ 0.05ms
$cbr0 attach-agent $udp0
$ftp0 attach-agent $tcp0
#connect agents
$ns connect $udp0 $null0
$ns connect $tcp0 $sink0

$ns at 0.5 "$cbr0 start"


$ns at 4.5 "$cbr0 stop"
$ns at 0.5 "$ftp0 start"
$ns at 4.5 "$ftp0 stop"
$ns at 5.0 "finish"

Pranshu Awasthi
18102276

You might also like