Install network simulator on ubuntu


This blog post is regarding installing network simulator on Ubuntu.

Make sure you have the following packages installed:

build-essential autoconf automake libxt-dev libx11-dev libxmu-dev

Download ns-allinone-2.34.tar.gz. Then execute the following using command prompt:

tar -xzf ns-allinone-2.34.tar.gz 
cd ns-allinone-2.34
./install

For Ubuntu 9.10 (karmic), you may encounter this error in the linking of otcl:

otcl.o: In function `OTclDispatch':
  /your/path/ns-allinone-2.34/otcl/otcl.c:495: undefined reference to
`__stack_chk_fail_local'
  otcl.o: In function `Otcl_Init':
  /your/path/ns-allinone-2.34/otcl/otcl.c:2284: undefined reference to
`__stack_chk_fail_local'
  ld: libotcl.so: hidden symbol `__stack_chk_fail_local' isn't defined
  ld: final link failed: Nonrepresentable section on output
  make: *** [libotcl.so] Error 1

This error is because the linker being used is “ld -shared” instead of “gcc -shared”. If you edit one line in otcl-1.13/configure, and rerun install, it should work:

--- configure.orig      2009-11-02 12:14:52.556167945 -0800
 +++ configure   2009-11-02 12:17:28.966706099 -0800
 @@ -6301,7 +6301,7 @@
          ;;
      Linux*)
          SHLIB_CFLAGS="-fpic"
 -        SHLIB_LD="ld -shared"
 +        SHLIB_LD="gcc -shared"
          SHLIB_SUFFIX=".so"
          DL_LIBS="-ldl"
          SHLD_FLAGS=""

After a long wait and a whole lot of text, you should see the installation finish up with text like the following:

Nam has been installed successfully.
Ns-allinone package has been installed successfully.
Here are the installation places:
tcl8.4.11:      /your/path/ns-allinone-2.34/{bin,include,lib}
tk8.4.11:               /your/path/ns-allinone-2.34/{bin,include,lib}
otcl:           /your/path/ns-allinone-2.34/otcl-1.13
tclcl:          /your/path/ns-allinone-2.34/tclcl-1.19
ns:             /your/path/ns-allinone-2.34/ns-2.34/ns
nam:    /your/path/ns-allinone-2.34/nam-1.14/nam
xgraph: /your/path/ns-allinone-2.34/xgraph-12.1
gt-itm:   /your/path/ns-allinone-2.34/itm, edriver, sgb2alt, sgb2ns, sgb2comns, sgb2hierns


Please put /your/path/ns-allinone-2.34/bin:/your/path/ns-allinone-2.34/tcl8.4.19/unix:/your/path/ns-allinone-2.29/tk8.4.18/unix
into your PATH environment; so that you'll be able to run itm/tclsh/wish/xgraph.

IMPORTANT NOTICES:

(1) You MUST put /your/path/ns-allinone-2.34/otcl-1.13, /your/path/ns-allinone-2.34/lib, 
    into your LD_LIBRARY_PATH environment variable.
    If it complains about X libraries, add path to your X libraries 
    into LD_LIBRARY_PATH.
    If you are using csh, you can set it like:
                setenv LD_LIBRARY_PATH 
    If you are using sh, you can set it like:
                export LD_LIBRARY_PATH=

(2) You MUST put /your/path/ns-allinone-2.34/tcl8.4.19/library into your TCL_LIBRARY environmental
    variable. Otherwise ns/nam will complain during startup.

(3) [OPTIONAL] To save disk space, you can now delete directories tcl8.4.18 
    and tk8.4.18. They are now installed under /your/path/ns-allinone-2.34/{bin,include,lib}

After these steps, you can now run the ns validation suite with
cd ns-2.34; ./validate

For trouble shooting, please first read ns problems page 
http://www.isi.edu/nsnam/ns/ns-problems.html. Also search the ns mailing list archive
for related posts.

If your ubuntu version is 9.10, you must change the variable of environment CC if not set

$ export CC=gcc-4.3

Now, You have to set environment variables

$ gedit ~/.bashrc 

Replace /your/path with the path to parent directory of ns-allinone-2.34.

# LD_LIBRARY_PATH
OTCL_LIB=/your/path/ns-allinone-2.34/otcl-1.13
NS2_LIB=/your/path/ns-allinone-2.34/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=/your/path/ns-allinone-2.34/tcl8.4.18/library
USR_LIB=/usr/lib
export TCL_LIBRARY=$TCL_LIB:$USR_LIB

# PATH
XGRAPH=/your/path/ns-allinone-2.34/bin:/your/path/ns-allinone-2.34/tcl8.4.18/unix:/your/path/ns-allinone-2.34/tk8.4.18/unix
NS=/your/path/ns-allinone-2.34/ns-2.34/
NAM=/your/path/ns-allinone-2.34/nam-1.14/
PATH=$PATH:$XGRAPH:$NS:$NAM

Ensure that it immediately takes effect:

$ source ~/.bashrc

Validation of the installation can be tested by:

$ cd ns-2.34
$ ./validate

Now, installation of network simulator is done. Enjoy coding.

Advertisements