Install ns2 (Network Simulator 2) in ubuntu (ns-2.35)

Install ns2 (Network Simulator 2) in ubuntu (ns-2.35)

Ns is a discrete event simulator targeted at networking research. Ns provides substantial support for simulation of TCP, routing, and multicast protocols over wired and wireless (local and satellite) networks. Here instructions are given for installing Ns version 2.35 in ubuntu.

  • Download NS2 from terminal using command
    or directly using
  • Unpack ns-allinone-2.35.tar.gz to your home directory.
    tar -zxvf ns-allinone-2.35.tar.gz -C /home/yourusername
  • Next you need to edit a file. Go to /home/yourusername/ns-allinone-2.35/ns-2.35/linkstate/ directory and open ls.h file in a text editor. Line 137 will be
    void eraseAll() { erase(baseMap::begin(), baseMap::end()); }
    Change it to
    void eraseAll() { this->erase(baseMap::begin(), baseMap::end()); }
  • Now install dependencies.
    sudo apt-get install tcl8.5-dev tk8.5-dev
    sudo apt-get install build-essential autoconf automake
    sudo apt-get install perl xgraph libxt-dev libx11-dev libxmu-dev g++ xorg-dev
    sudo apt-get install libperl4-corelibs-perl
  • Change your directory
    cd /home/yourusername/ns-allinone-2.35/
  • Run the “install script” by ./install command. [This may take few minutes]
  • After installation modify .bashrc file located in your home directory.
    gedit /home/yourusername/.bashrc
    Add the following lines to the end of the file.
    export PATH=$PATH:/home/yourusername/ns-allinone-2.35/bin:/home/yourusername/ns-allinone-2.35/tcl8.5.10/unix:/home/yourusername/ns-allinone-2.35/tk8.5.10/unix
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/yourusername/ns-allinone-2.35/otcl-1.14:/home/yourusername/ns-allinone-2.35/lib
    export TCL_LIBRARY=$TCL_LIBRARY:/home/yourusername/ns-allinone-2.35/tcl8.5.10/library
    Close gedit.
  • To enable the path setting immediately, use.
    source ~/.bashrc
  • Go to directory /home/yourusername/ns-allinone-2.35/ns-2.35
    cd /home/yourusername/ns-allinone-2.35/ns-2.35
    and type: ./validate
    Validations tests are performed. This may also take few minutes.
  • Now check ns2 working by entering the command ns. We should get a “%” prompt.
  • For testing create a sample.tcl file in your home directory.
    gedit sample.tcl
    and type the following sample code

    set ns [new Simulator]
    set nf [open out.nam w]
    $ns namtrace-all $nf
    proc finish {} {
    global ns nf
    $ns flush-trace
    close $nf
    exec nam out.nam &
    exit 0
    set n0 [$ns node]
    set n1 [$ns node]
    $ns duplex-link $n0 $n1 1Mb 10ms DropTail
    $ns at 3.0 “finish”
    $ns run
  • Save and close sample.tcl and run using
    ns sample.tcl
    It will display a graph with two nodes and a link between them in the NAM
    GUI window.

( Lack of dependencies can cause error messages like
validate overall report: some tests failed:
./test-all-newreno ./test-all-tcpOptions ./test-all-tcpVariants ./test-all-aimd
./test-all-frto ./test-all-quickstart ./test-all-manual-routing ./test-all-links
to re-run a specific test, cd tcl/test; ./test-all-TEST-NAME on running ./validate )

This Post Has One Comment

Leave a Reply