Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

M19CA3090 Computer Networking Lab using NS2

PART-B

PROGRAM 1:

1 Problem Statement
Set up a simple network topology which consists of two nodes (n0-n1). Link existence (duplex in nature)
between the nodes is as follows: n0-n1 . The link no-n1 has 10 Mb of bandwidth and 10 ms of delay. Each
node uses Drop Tail queue of which the maximum size is 10.
2 Student Learning Outcomes

After successful completion of this lab, the students will be able to


Familiarize the need and advantages of Simulation
Learn to simulate a point-to-point network with duplex link
Interpret the effect of varying Queue size and Bandwidth
Analyze the packet drop

3 Design of the Program


3.1
3.2
#simulator initialization
set ns [new Simulator]

#output files

#network animator output file


set namf [open twonode.nam w]
$ns namtrace-all $namf

#creation of nodes
#$set n0 [new Node]
set n0 [$ns node]
set n1 [$ns node]

#connecting through links


$ns duplex-link $n0 $n1 10Mb 10ms DropTail

#run

$ns run
3.3 Expected Results

School of CSA, REVA University Page 15


M19CA3090 Computer Networking Lab using NS2

School of CSA, REVA University Page 16


M19CA3090 Computer Networking Lab using NS2

Program 2 :

1 Problem Statement
Set up a network topology using NS2 with nodes n0 , node n1 which are connected to n2 . Also n2 is
connected to n3. Create all links as duplex link and set the link bandwidth, propagation delay and
queue type of the n0,n2 as 10Mb, 10ms and drop tail queue. The link characteristics of n1,n2 is to be
set as 10Mb, 10ms and drop tail queue . Finally set the link characteristics of n2,n3 as 10Kb, 10oms
and drop tail queue.

#simulator initialization
set ns [new Simulator]

#output files
#packet trace output file
set trf [open wirednetwork.tr w]
$ns trace-all $trf

#network animator output file


set namf [open wirednetwork.nam w]
$ns namtrace-all $namf

#creation of nodes
#$set n0 [new Node]
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
#connecting through links
$ns duplex-link $n0 $n2 10Mb 10ms DropTail
$ns duplex-link $n1 $n2 10Kb 100ms DropTail
$ns duplex-link $n2 $n3 10Kb 100ms DropTail
#agents[TCP] creation
set t [new Agent/TCP]
$ns attach-agent $n0 $t

School of CSA, REVA University Page 17


M19CA3090 Computer Networking Lab using NS2

set s [new Agent/TCPSink]


$ns attach-agent $n3 $s
$ns connect $t $s
#create application
set f [new Application/FTP]
$f attach-agent $t
#agents[UDP] creation
set u [new Agent/UDP]
$ns attach-agent $n1 $u

set n [new Agent/Null]


$ns attach-agent $n3 $n
$ns connect $u $n
#create application
set c [new Application/Traffic/CBR]
$c attach-agent $u
#packet size and time interval
$f set packetSize_ 200
$f set packetSize_ 100
$f set interval_ 0.01
$c set interval_ 0.001
#finish procedure
proc finish {} {
global ns trf namf
$ns flush-trace
exec nam wirednetwork.nam &
close $namf
close $trf
exit 0
}
#allotment
$ns at 0.1 "$c start"
$ns at 0.5 "$f start"
$ns at 7.0 "$f stop"
$ns at 9.0 "$c stop"
$ns at 10.0 "finish"
$ns run

School of CSA, REVA University Page 18


M19CA3090 Computer Networking Lab using NS2

Program 3:

1 Problem Statement
Set up star network using NS2 with central source node n0 which connected to n1 ,n2 n3,n4 and n5.
Create link as duplex link and set bandwidth as 1Mb, propagation delay as 10ms and queue type as drop
tail queue. Create a FTP application with TCP as transport layer (attach TCP agent and application agent).
Write a Tcl script to observe the packet flow for the given network in network animator (NAM).

School of CSA, REVA University Page 19


M19CA3090 Computer Networking Lab using NS2

set ns [new Simulator]


set starf [open "namstar.tr" w]
$ns trace-all $starf
set namstarf [ open "namstar.nam" w]
$ns namtrace-all $namstarf
proc finish { } {
global ns starf namstarf
$ns flush-trace
close $starf
close $namstarf
exec nam namstar.nam &
exit
}
set n0 [$ns node]

set n1 [$ns node]


set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
$ns duplex-link $n1 $n0 2Mb 5ms DropTail
$ns duplex-link $n2 $n0 2Mb 5ms DropTail
$ns duplex-link $n3 $n0 2Mb 5ms DropTail
$ns duplex-link $n4 $n0 2Mb 5ms DropTail
$ns duplex-link $n5 $n0 2Mb 5ms DropTail

set tcp0 [new Agent/TCP]


$ns attach-agent $n1 $tcp0
set ftp [new Application/FTP]
$ftp attach-agent $tcp0

set sink [new Agent/TCPSink]


$ns attach-agent $n3 $sink

$ns connect $tcp0 $sink

$ns at 0.1 "$ftp start"


$ns at 2 "$ftp stop"
$ns at 2.1 "finish"
$ns run

School of CSA, REVA University Page 20


M19CA3090 Computer Networking Lab using NS2

School of CSA, REVA University Page 21


M19CA3090 Computer Networking Lab using NS2

Program 4:

1 Problem Statement

Set up star network using NS2 with central source node n0 which connected to n1 ,n2 n3,n4 and n5.
Create link as duplex link and set bandwidth as 1Mb, propagation delay as 10ms and queue type as drop
tail queue. Create an CBR application with UDP as transport layer (attach TCP and application agent).
Write a Tcl script to observe the packet flow for the given network in network animator (NAM).

set ns [new Simulator]


set trf [open "starnetwork.tr" w]
$ns trace-all $trf
set namf [open "starnetwork.nam" w]
$ns namtrace-all $namf

set n0 [$ns node]


set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]

School of CSA, REVA University Page 22


M19CA3090 Computer Networking Lab using NS2

#change the shape of the central node

$n0 shape square

#Connecting throuhg links

$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 $n0 $n4 1Mb 10ms DropTail
$ns duplex-link $n0 $n5 1Mb 10ms DropTail

set t [new Agent/TCP]


$ns attach-agent $n0 $t
set s [new Agent/TCPSink]
$ns attach-agent $n3 $s
$ns connect $t $s

set cbr [new Application/Traffic/CBR]


$cbr set packetSize_ 500
$cbr set interval_ 0.01
$cbr attach-agent $t

proc finish { } {
global ns trf namf
$ns flush-trace
exec nam starnetwork.nam &
close $namf
close $trf
exit 0
}

$ns at 0.5 "$cbr start"


$ns at 4.5 "$cbr stop"
$ns at 5.0 "finish"
$ns run

School of CSA, REVA University Page 23


M19CA3090 Computer Networking Lab using NS2

School of CSA, REVA University Page 24


M19CA3090 Computer Networking Lab using NS2

PROGRAM 5:

1 Problem Statement
Set up a network using NS2 with source source node n0 ,n1 which connected
to n2 with duplex link characteristics as follows. (set set bandwidth as 1Mb,
propagation delay as 10ms and queue type as drop tail queue) . Create a link
between n2 and n3 with a duplex link and set bandwidth as 0.3Mb,
propagation delay as 100ms and queue type as drop tail queue. Create link
from n3 to n4 with link characteristics (set set bandwidth as 0.5Mb,
propagation delay as 40ms and queue type as drop tail queue) . Also Create
link from n3 to n5 with link characteristics (set set bandwidth as 0.5Mb,
propagation delay as 30ms and queue type as drop tail queue). Create two
transport layer agents with TCP and UDP. Create application traffic with
FTP
(Over TCP) , CBR (over UDP). Analyze the packet loss in the network using
NAM animator.

School of CSA, REVA University Page 25


M19CA3090 Computer Networking Lab using NS2

#simulator initialization

set ns [new Simulator]

#output files

#packet trace output file

set trf [open starnetwork1.tr w]

$ns trace-all $trf

#network animator output file

set namf [open starnetwork1.nam w]

$ns namtrace-all $namf

#creation of 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 $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

School of CSA, REVA University Page 26


M19CA3090 Computer Networking Lab using NS2

$ns duplex-link $n3 $n4 0.5Mb 40ms DropTail

$ns duplex-link $n3 $n5 0.5Mb 30ms DropTail

#Set Queue Size of link (n2-n3) to 1011

$ns queue-limit $n2 $n3 20

#Setup a TCP connection

set tcp [new Agent/TCP/Newreno]

$ns attach-agent $n0 $tcp

set 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 connection

set ftp [new Application/FTP]

$ftp attach-agent $tcp

$ftp set type_ FTP

#Setup a UDP connection

set udp [new Agent/UDP]

$ns attach-agent $n1 $udp

set null [new Agent/Null]

School of CSA, REVA University Page 27


M19CA3090 Computer Networking Lab using NS2

$ns attach-agent $n5 $null

$ns connect $udp $null

$udp set fid_ 2

#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_ 0.01mb

$cbr set random_ false

$ns at 0.1 "$cbr start"

$ns at 1.0 "$ftp start"

$ns at 10.0 "$ftp stop"

$ns at 10.5 "$cbr stop"

$ns run

3.3 Expected Results

School of CSA, REVA University Page 28


M19CA3090 Computer Networking Lab using NS2

School of CSA, REVA University Page 29

You might also like