Académique Documents
Professionnel Documents
Culture Documents
a
Hello world Interactive mode
$ns
_04
%ns run
PROGRAM-1.b
Hello world Batch mode
1. Open gedit tool and type the following program and save(file name simple.tcl ).
CODING
$ns run
[info@localhost~]ns simple.tcl
PROGRAM-2
Following program for two nodes(n0,n1) and communication with 1Mb and delay of 10 ms.
CODING
#Create a simulator object
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exit 0
$ns run
PROGRAM-3
Wired network can be created using a simple topology with n number of nodes connected by a wired
link. Any two nodes in the network can be connected using a duplex link and the link characteristics include
bandwidth, delay and queue type. The code segment in test1.tcl creates a wired network and the nodes are
connected with duplex link with the bandwidth 2 Megabit, a delay of 50ms and a DropTail queue. Each node
is assigned with label, color and shape. The wireless network with 3 nodes can be viewed in the Network
Animator (NAM) window after executing the file test1.tcl
CODING
# Filename: test1.tcl
set totalNodes 3
set server 0
set router 1
set client 2
#------------Labelling----------------#
$ns at 0.0 "$node_($server) label Server"
#---------finish procedure--------#
proc finish {} {
global ns nf nt
$ns flush-trace
close $nf
close $nt
exit 0
$ns run
PROGRAM-4
#Create a simulator object
set ns [new Simulator]
# create nodes
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 run
OUTPUT