Friday 11 November 2016

Network Simulator

Network Simulator (ns) is a name for a series of discrete event network simulators. Various Versions of ns are ns1, ns2 and ns3. These are discrete event computer network simulators which are used in research and teaching. It is an open source software and is publically available under the GNU GPL v2 license for research, development and use. The aim of ns project is to create an open simulation environment for computer networking research.

Tool Command Language(TCL) scripting : 

We can write TCL scripts in any text editor like notepad++,VI Editor etc

WORKING WITH TCL SCRIPTS:

1 To begin with, we first need to create an object of simulator class.
Syntax is as:
set ns [new Simulator]
2 Next step is to open a file for writing nam trace data.
Its syntax is as:
a   set nf [open out.nam w]
b   $ns namtrace-all $nf
Line (a) opens the file out.nam and gives it a file handle  ‘nf’
Line (b) tells the simulator object ‘ns’ to write all simulation data to the nam file ‘out.nam’ which is refrenced by ‘nf’
3 The next step in TCL scripting is to add a ‘finish’ procedure that is used to close the trace file and start the nam file.
Syntax is as:
1                      proc finish { }     
2                      global ns nf
3                     $ns flush-trace
4                      close $nf
5                     exec nam out.nam &
6                  exit(0)
}
finish{} is the name of a procedure having code as shown above.
Line(2) specifies that objects ‘ns’ and ‘nf’ can be used inside the finish{} procedure using keyword global.
Line (3) writes all the data to the trace file through object ‘ns’
Line(4) closes the object ‘ns’ and all the links opened by it.
Line (5) finally executes the nam file using keyword ‘exec’ having name out.nam
Line(6) exits the procedure.

4 Next line in the TCL script is as:
$ns at 5.0 “finish”
This line tells the simulator object ‘ ns ’to execute the finish procedure after 5.0 seconds of simulation time.
5 Finally the last line which actually starts the simulation is written as:
$ns run
After writing the script we have to save the file with filename.tcl extension .

No comments:

Post a Comment