Tuesday, April 23, 2013

NS2 simulation

NS2 Installation

How to run NSG2 in Ubuntu 12.04

After installing the NS2 on your PC, you are ready to simulate for the first time...

For your convenience, you can make a new folder to store all NS2 simulation files.

Go to  .../ns-allinone-2.35/ns-2.35/tcl/ex

ex is the folder that contains the example tcl files. From this folder, copy simple.tcl and paste it to your own folder.

Then, open the terminal (Ctrl+Alt+t).


Go to the folder that contains simple.tcl

To run simple.tcl, give the command ns simple.tcl

The script will run and an output trace file (out.tr) will be generated

Contents of out.tr file


+ 1 0 2 cbr 210 ------- 0 0.0 3.1 0 0
- 1 0 2 cbr 210 ------- 0 0.0 3.1 0 0
r 1.002336 0 2 cbr 210 ------- 0 0.0 3.1 0 0
+ 1.002336 2 3 cbr 210 ------- 0 0.0 3.1 0 0
- 1.002336 2 3 cbr 210 ------- 0 0.0 3.1 0 0
+ 1.00375 0 2 cbr 210 ------- 0 0.0 3.1 1 1
- 1.00375 0 2 cbr 210 ------- 0 0.0 3.1 1 1
r 1.006086 0 2 cbr 210 ------- 0 0.0 3.1 1 1
+ 1.006086 2 3 cbr 210 ------- 0 0.0 3.1 1 1
- 1.006086 2 3 cbr 210 ------- 0 0.0 3.1 1 1
+ 1.0075 0 2 cbr 210 ------- 0 0.0 3.1 2 2
- 1.0075 0 2 cbr 210 ------- 0 0.0 3.1 2 2
...................................

This file contains event based data for the entire simulation.


From the out.tr file, you will have to extract the data according to your requirement.

For that, you will have to write awk script

A sample awk script is available here

Save the file in the same folder. Then go to terminal window (Ctrl+Alt+t). Give the test.sh (awk script) executable permission by giving the following command

chmod +x test.sh

Command to run test.sh  :  ./test.sh

For Wireless network

Install awk:       sudo apt-get install gawk

To run awk script:   gawk -f e2edelay.awk simple.tr



No comments:

Post a Comment