What is TCL File in Ns2

In Ns2, the TCL file is defined as the main configuration file to simulate the projects and the tcl script language is deployed to derive the TCL file main code.

Installation of Ns2 and TCL

To install both the Ns2 and TCL file, we have to open the Ubuntu terminal or the command window and execute the below mentioned commands.

sudo apt-get install ns2

Installation of Ns2

sudo apt-get install tcl

TCL File Code in Ns2 Simulation

In Ns2 simulation, we have to create the main file with the file extension .tcl and store that in project uncle. Here, we have highlighted the code to declare the trace file objects and topology creation in main file.

set tracefd                   [open TCL_Simulation.tr w]

set namtrace                [open TCL_Simulation.nam w]

$ns trace-all $tracefd

$ns namtrace-all-wireless $namtrace $val(x) $val(y)

set topo [new Topography]

$topo load_flatgrid $val(x) $val(y)

Run TCL File in Ns2 Simulation

To run the TCL file in Ns2 simulation, we have to implement the below mentioned commands in terminal window.

cd /home/research/TCL_code_in_NS2

sudo ./ns main.tcl

Running TCL Code in Ns2 Simulation

Finally, we have highlighted the result which is acquired through the execution of TCL code in Ns2 simulation.

Result of Running TCL Code

Eventually, we are hopefully assuming that it is beneficial for you guys to create TCL file in network simulator 2. If any help required just ping us.