Thursday, February 11, 2010

How to Install Network Simulator (NS) on Fedora Core/Ubuntu Linux

It’s most easy task. Just applying couple of commands you can complete the installation and work with NS on Linux.

I recommend to use NS on Linux because I think cygwin isn’t a enough software to resolve all linux features on Windows. Obviously there are some wrong workarounds on cygwin.

Now follow these steps to install ns on Linux
  • Download ns-allinone package from nsnam sourceforge project page. Or download directly version 2.34 from here.

  • After downloading extract the packages. To do this open gnome-terminal; press Alt + F2 and type exactly gnome-terminal there and hit enter. Then apply following commands.

    $ tar xzvf ns-allinone-2.34.tar.gz


  • Now change directory and run ns `install` script applying following commands

    $ cd ns-allinone-2.34
    $ ./install
    

    It will display a lot of information on the screen configuring, building and installing packages one after one. It might take around 10 minutes depending on your Computer’s speed. After installation is complete the screen will display information about installation paths of different packages.

    $ ./install
    .....................................................................
    .....................................................................
    
    Ns-allinone package has been installed successfully.
    Here are the installation places:
    tcl8.4.18: /home/Saint/Softs/ns-allinone-2.34/{bin,include,lib}
    tk8.4.18:  /home/Saint/Softs/ns-allinone-2.34/{bin,include,lib}
    otcl:  /home/Saint/Softs/ns-allinone-2.34/otcl-1.13
    tclcl:  /home/Saint/Softs/ns-allinone-2.34/tclcl-1.19
    ns:  /home/Saint/Softs/ns-allinone-2.34/ns-2.34/ns
    nam: /home/Saint/Softs/ns-allinone-2.34/nam-1.14/nam
    gt-itm:   /home/Saint/Softs/ns-allinone-2.34/itm, edriver, sgb2alt, sgb2ns,
    sgb2comns, sgb2hierns
    
    ---------------------------------------------------------------------------
    Please put /home/Saint/Softs/ns-allinone-2.34/bin:/home/Saint/Softs/\
    ns-allinone-2.34/tcl8.4.18/unix:/home/Saint/Softs/ns-allinone-2.34/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 /home/Saint/Softs/ns-allinone-2.34/otcl-1.13, /home/Saint/\
    Softs/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 <paths>
        If you are using sh, you can set it like:
      export LD_LIBRARY_PATH=<paths>
    
    (2) You MUST put /home/Saint/Softs/ns-allinone-2.34/tcl8.4.18/library into your
    TCL_LIBRARY environmental variable. Otherwise ns/nam will complain during
    startup.

    This information is necessary because, you need to include them on your PATH variable.

  • To set your PATH correctly follow this format

    $ PATH=$PATH:PATH_SUGGESTED_BY_INSTALLED_NS

    where PATH_SUGGESTED_BY_INSTALLED_NS has to be replaced with the path displayed at the end of installation of NS.

    For example in my case it is:

    PATH=$PATH:/home/Saint/Softs/ns-allinone-2.34/bin:/home/Saint/Softs/\
    ns-allinone-2.34/tcl8.4.18/unix:/home/Saint/Softs/ns-allinone-2.34/tk8.4.18/\
    unix


  • To make it permanent append following line to .bashrc file (you can open this file using this command: `gedit ~/.bashrc &`)

    export PATH=$PATH:PATH_SUGGESTED_BY_INSTALLED_NS

    In my case it is:

    export PATH=$PATH:/home/Saint/Softs/ns-allinone-2.34/bin:/home/Saint/Softs/ns-allinone-2.34/tcl8.4.18/unix:/home/Saint/Softs/ns-allinone-2.34/tk8.4.18/unix


  • After PATH is set correctly you can now work with NS. Simply type ns on terminal to run the simulator.

    $ ./ns
    % set a 4
    4
    % puts $a
    4
    % exit
    

Some NS Commands

% set a 4
     This command sets value 4 to variable $a

% puts $a
     Prints the value of variable a
     
% puts "[expr $a*$a]"
     prints a*a if variable a is previously defined
     
% exit
     This commands exits the interpreter
     
% # comment
     # is used for commenting

% set fp [open test.txt w]
     opens a file handle to fp
     
% puts $fp "This is a test"
     To print in file handled by fp

% puts -nonewline "test"
     print with no newline

8 comments:

  1. I am facing an installing problem on Fedora Core 12 while installing ns-allinone-2.34. I have explained the problem here http://www.linuxquestions.org/questions/linux-software-2/problem-installing-ns-allinone-2.34-on-fedora-core-12-...-797763/#post3911563

    ReplyDelete
  2. I also tested it on Fedora Core 12. No error. I think you should redownload your ns-allinone archive and try again.

    ReplyDelete
  3. Hello sir,
    I used Fedora 12 for NS-2.34.
    But i cant install Ns-2.34 in Fedora 12.
    I got this type of error.
    Any sloution of this problem.

    Checking for gcc...
    Building static library libz.a version 1.2.3 with cc.
    Checking for unistd.h... No.
    Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()
    Checking for snprintf() in stdio.h... No.
    WARNING: snprintf() not found, falling back to sprintf(). zlib
    can build but will be open to possible buffer-overflow security
    vulnerabilities.
    Checking for return value of sprintf()... No.
    WARNING: apparently sprintf() does not return a value. zlib
    can build but will be open to possible string-format security
    vulnerabilities.
    Checking for errno.h... No.
    Checking for mmap support... No.
    cc -O -DNO_snprintf -DHAS_sprintf_void -DNO_ERRNO_H -c -o example.o example.c
    make: cc: Command not found
    make: *** [example.o] Error 127
    Zlib make failed, but it's optional Continue ...
    ============================================================
    * Build tcl8.4.18
    ============================================================
    ./install: line 431: autoconf: command not found
    loading cache ./config.cache
    checking whether to use symlinks for manpages... no
    checking whether to compress the manpages... no
    checking whether to add a package name suffix for the manpages... no
    checking for gcc... no
    checking for cc... no
    configure: error: no acceptable cc found in $PATH
    tcl8.4.18 configuration failed! Exiting ...
    Tcl is not part of the ns project.

    ReplyDelete
  4. Hey, sorry for late reply. I was busy.

    I tried it in fedora 12. It worked nice. Your output says that you don't have gcc. You may try this command to install gcc and c++, they try to install ns again.

    su
    Password: [Enter your password]
    # yum install gcc-c++

    Hope it will solve your problem. Thanks.

    ReplyDelete
  5. sir after viewing your conversion i tried in the same manner.
    but it did not work


    and the effect is as follow:
    Loaded plugins: presto, refresh-packagekit
    Error: cannot retrieve repository metadata (repond.xml) for repository: fedora.
    Please verify its path and try again

    ReplyDelete
  6. renu@renu-07ccd6ec86 ~/ns-allinone-2.34/ns-2.34
    $ make install
    for d in /usr/local/man/man1; do \
    if [ ! -d $d ]; then \
    mkdir -p $d ;\
    fi;\
    done
    /usr/bin/install -c -m 755 ns /usr/local/bin
    /usr/bin/install: cannot stat `ns': No such file or directory
    make: *** [install-ns] Error 1
    this is the error which i have got while installing the package ns-2.34
    pls give me the gud solution for it.

    ReplyDelete
  7. @Anonymous: Give some more detail. What command did you try? Doesn't seem like a desired output you have got; most likely it's an yum command without internet connection!

    ReplyDelete
  8. @renu: I suggest you to redownload the tar archive and try again.

    Thank you.

    ReplyDelete