Wednesday, May 20, 2009

NS-2 Installation on Ubuntu 9.04

The procedure for installing NS-2 in Ubuntu 9.04 on Dell Vostro 1310.

1. Download
ns-allinone-2.33.tar from here.
2. Place it in somewhere, e.g. /home/programmer, then extract it.
$ cd /home/programmer
$ tar -xvf ns-allinone-2.33.tar
3. Download & install some packages from repository
$ sudo apt-get install build-essential autoconf automake libxmu-dev
4. Install the ns2
$ cd ns-allinone-2.33
$ ./install
5. Edit some paths
$ gedit ~/.bashrc
Put these lines on that file. Off course, you might change /home/programmer for it depends on where you extract ns-allinone-2.33.tar.
# LD_LIBRARY_PATH
OTCL_LIB=/home/programmer/ns-allinone-2.33/otcl-1.13
NS2_LIB=/home/programmer/ns-allinone-2.33/lib
X11_LIB=/usr/X11R6/lib
USR_LOCAL_LIB=/usr/local/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB
:$X11_LIB:$USR_LOCAL_LIB


# TCL_LIBRARY
TCL_LIB=/home/programmer/ns-allinone-2.33/tcl8.4.18/library
USR_LIB=/usr/lib
export TCL_LIBRARY=$TCL_LIB:$USR_LIB

# PATH
XGRAPH=/home/programmer/ns-allinone-2.33/bin:/home/programmer/ns-allinone-2.33/tcl8.4.18/unix:/home/programmer/ns-allinone-2.33/tk8.4.18/unix:/home/programmer/ns-allinone-2.33/xgraph-12.1/
NS=/home/programmer/ns-allinone-2.33/ns-2.33/
NAM=/home/programmer/ns-allinone-2.33/nam-1.13/
export PATH=$PATH:$XGRAPH:$NS:$NAM

6. Validate it (take very long time compare to install process)
$ cd ns-2.33
$ ./validate
7. (Optionally) Create a symlink, so that ns can be called from everywhere
$ sudo ln -s /home/programmer/ns-allinone-2.33/ns-2.33/ns /usr/bin/ns
8. Let it take effect immediately
$ source ~/.bashrc
9. Try to run it (and pray :)
$ ns
10. If the installation success, you will see % at the command prompt. Type following command to exit
% exit

Credit
./anggriawan

Testing ns2 Installation
Use the following ns batch command
set ns [new Simulator]
$ns at 1 “puts \“Hello World!\””
$ns at 1.5 “exit”
$ns run
Then,
1. Copy the commands above and paste in the text editor
2. Save the file as simple.tcl
3. Type command in command prompt
$ ns simple.tcl
4. It will show Hello World in the line below


Troble Shooting
1. Problem : The system cannot find Tcl or it tells that Tcl does not install correctly
Solution 1 : Check your ns tcl nam ... version, check folder name. If it is not correct, edit the .bashrc
Solution 2 : run ./install again
2. Problem : nam does not work
Solution 1 : In fact, you need to change that particular file in your Linux manually.

Here is what you should do.
--- tk8.4.18-orig/generic/tkBind.c 2006-07-21 08:26:54.000000000 +0200
+++ tk8.4.18/generic/tkBind.c 2008-07-05 12:17:10.000000000 +0200

@@ -586,6 +586,9 @@

/* ColormapNotify */ COLORMAP,

/* ClientMessage */ 0,
/* MappingNotify */ 0,

+#ifdef GenericEvent
+ /* GenericEvent */ 0,

+#endif
/* VirtualEvent */ VIRTUAL,

/* Activate */ ACTIVATE,

/* Deactivate */ ACTIVATE,

This @@ -586,6 +586,9 @@ indicates exact location of the line that you start to edit, if you are using gedit or other similar editor in Linux.
The + sign indicates what to add, and the - sign indicates what to delete.
Then run $ ./install to compile and install ns2 again

Credit
Fedora forum

6 comments:

  1. hi!
    ns2 got installed successfully on my ubuntu 9.04.
    I checked $ ns and got %.

    but while running the simple.tcl I am getting following errors:
    yasir@yasir-laptop:~/Desktop$ ns simple.tcl

    (_o5 cmd line 1)
    invoked from within
    "_o5 cmd at 1 “puts “Hello World!””"
    invoked from within
    "catch "$self cmd $args" ret"
    invoked from within
    "if [catch "$self cmd $args" ret] {
    set cls [$self info class]
    global errorInfo
    set savedInfo $errorInfo
    error "error when calling class $cls: $args" $..."
    (procedure "_o5" line 2)
    (SplitObject unknown line 2)
    invoked from within
    "_o5 at 1 “puts “Hello World!””"
    ("eval" body line 1)
    invoked from within
    "eval $scheduler_ at $args"
    (procedure "_o3" line 3)
    (Simulator at line 3)
    invoked from within
    "$ns at 1 “puts \“Hello World!\””"
    (file "simple.tcl" line 2)


    Please help me regarding this. What to do??
    Thanks in advance.

    ReplyDelete
  2. got it working.. :-)
    The problem was with simple.tcl, not with my installation.
    The sample scripts on http://www.cs.wm.edu/~njschm/research/NS2_Examples.html is working fine.

    ReplyDelete
  3. Hello!

    Thanks to the instruction. I got it finally working now! :)

    ReplyDelete
  4. Hi I have the same error while running a tcl script in fedora 9....can you help me please.
    I need your help

    ReplyDelete
  5. It worked for me.
    Thanks for the instructions provided.

    ReplyDelete