Basics of Network Simulation

Steps for conducting the experiment

General Instructions

Follow are the steps to be followed in general to perform the experiments in Advanced Network Technologies Virtual Lab.

  1. Read the theory about the experiment
  2. View the simulation provided for a chosen, related problem
  3. Take the self evaluation to judge your understanding (optional, but recommended)
  4. Go to the exercises section, choose a problem, and carefully read the problem description
  5. Write a script (or make necessary changes) to simulate the desired scenario in the code editor just below the problem statement
  6. Click on the 'Run' button to execute the simulation script
  7. Simulation with ns2: If the simulation was successful, and was instructed to create a trace file, contents of the trace file would be displayed in the area below the 'Run' button
  8. Simulation with ns3: If the simulation was successful, output of the program would be displayed in the area below the 'Run' button
  9. A trace file generated as a result of simulation with ns2 could be used for certain kind of analysis, which would be discussed in a later section

Experiment Specific Instructions

In the theory part we have learned how to work with NS2. In this section we now learn how to make your system ready so that you can work with Network Simulator 2.NS2 is a open source software. It can be downloaded from Internet and installed.

Basic Requirements:

  • A computer which is having access to the Internet
  • Minimum 512Mb RAM
  • Operating system: Linux(Ubuntu 10.04)
  • ns-2.34 package
  • gcc-4.4.3
  • make tools

The following instructions for downloading and installing ns2 are for a system with:

  • Operating System: Linux (Ubuntu 10.04)
  • ns2: 2.34
  • gcc: 4.4.3

Some of the known problems that have been faced during installation as well as their solutions have been discussed in one of the sections below.

The steps for installation should ideally be applicable for other version and/or configuration of Linux also. Any other problem that might arise would require further troubleshooting.

Downloading ns-2.34

To download ns2 go to The Network Simulator: Building Ns. Here you can download the ns all-in-one package or you can download the packages separately. The instructions provided here are largely based on what have been mentioned in The Network Simulator: Building Ns.

Now let's learn how to download the packages separately.

  1. First go to The Network Simulator: Building Ns
  2. Then download Tcl and Tk from http://www.tcl.tk/software/tcltk/downloadnow84.tml [Note: the versions of Tcl and Tk must be same.]
  3. Download OTcl from: http://sourceforge.net/projects/otcl-tclcl/files/OTcl/1.13/
  4. Download Tclcl from: http://sourceforge.net/projects/otcl-tclcl/files/TclCL/1.19/
  5. Download ns-2 from: http://sourceforge.net/projects/nsnam/files/ns-2/2.34/
  6. Download nam from: http://sourceforge.net/projects/nsnam/files/nam-1/1.14/ [Note: download only nam-1.14.tar.gz not ns-allinone package.]
  7. Download xgraph from: http://sourceforge.net/projects/nsnam/files/xgraph/xgraph-12.1/
  8. Note: There are some other few things to be downloaded but that depends upon your requirement. For example, if some error occurs for absence of any package, then you need to detect the error and download the required package. A good amount of troubleshooting guidance will be provided in the subsequent sections.

    Installation

    Following steps illustrate how to install the packages separately

    1. All the files will be zip format -- you need to unzip all the files at first. The command to unzip the files:

    tar -xzvf  <file_name>
    

    for e.g if we want to unzip the Tcl package the type: tar -xzvf tcl8.4.19

    To unzip all the files together use the following command:

    for ifile in ` ls *.tar.gz`
    do
    tar -xzvf $ifile
    done
    

    2. Now let's begin with installing Tcl. The steps required are:

    cd tcl8.4.19    # Move inside the directory containing (unzipped) source code of Tcl
    ls
    cd unix
    ./configure
    make
    sudo make install
    

    3. Install Tk:

    cd tk8.4.19
    ls
    cd unix
    ./configure
    make
    sudo make install
    

    4. Install OTcl:

    cd otcl-1.13
    ./configure --with-tcl=../tcl8.4.19  # Note: while configuring we need to specify the path of tcl
    make
    sudo make install
    

    5. Install Tclcl-1.19:

    cd tclcl-1.19
    ./configure --with-tcl=../tcl8.4.19  # Note: while configuring we need to specify the path of tcl
    make
    sudo make install
    

    6. Install ns-2.34:

    cd ns-2.34
    ./configure --with-tcl=../tcl8.4.19
    make 
    sudo make install
    
    If the above steps complete successfully, open a terminal, and type in ns. If you see a % prompt, then, congrats, your installation was successful!

    7. Install NAM:

    cd nam-1.14
    ./configure --with-tcl=../tcl8.4.19
    make
    sudo make install
    

    8. Install xgraph:

    cd xgraph-12.1
    ./configure
    make
    sudo make install
    

    Probable problems that could appear while installing the packages and their solution

    1. While installing Tk, 'make' fails. It generates some error message like:

      gcc -c -O2  -pipe  -Wall -Wno-implicit-int -fno-strict-aliasing -fPIC -I/home/tamoghna/Downloads/tk8.4.19/unix -I/home/tamoghna/Downloads/tk8.4.19/unix/../generic -I/home/tamoghna/Downloads/tk8.4.19/unix/../bitmaps -I/home/tamoghna/Downloads/tcl8.4.19/generic  -DHAVE_LIMITS_H=1 -DHAVE_UNISTD_H=1 -DPEEK_XCLOSEIM=1 -D_LARGEFILE64_SOURCE=1 -DTCL_WIDE_INT_TYPE=long\ long -DHAVE_STRUCT_STAT64=1 -DHAVE_OPEN64=1 -DHAVE_LSEEK64=1 -DHAVE_TYPE_OFF64_T=1 -DHAVE_SYS_TIME_H=1 -DTIME_WITH_SYS_TIME=1 -DSTDC_HEADERS=1 -DHAVE_PW_GECOS=1      -DTCL_NO_DEPRECATED  -DUSE_TCL_STUBS  /home/tamoghna/Downloads/tk8.4.19/unix/../generic/tk3d.c
      In file included from /home/tamoghna/Downloads/tk8.4.19/unix/../generic/tkInt.h:21,
                       from /home/tamoghna/Downloads/tk8.4.19/unix/../generic/tk3d.h:18,
                       from /home/tamoghna/Downloads/tk8.4.19/unix/../generic/tk3d.c:16:
      /home/tamoghna/Downloads/tk8.4.19/unix/../generic/tk.h:81:23: error: X11/Xlib.h: No such file or directory
      In file included from /home/tamoghna/Downloads/tk8.4.19/unix/../generic/tkInt.h:21,
                       from /home/tamoghna/Downloads/tk8.4.19/unix/../generic/tk3d.h:18,
                       from /home/tamoghna/Downloads/tk8.4.19/unix/../generic/tk3d.c:16:
      /home/tamoghna/Downloads/tk8.4.19/unix/../generic/tk.h:557: error: expected declaration specifiers or ‘...’ before ‘Window’
      /home/tamoghna/Downloads/tk8.4.19/unix/../generic/tk.h:557: error: ‘Window’ declared as function returning a function
      /home/tamoghna/Downloads/tk8.4.19/unix/../generic/tk.h:557: warning: parameter names (without types) in function declaration
      /home/tamoghna/Downloads/tk8.4.19/unix/../generic/tk.h:560: error: expected declaration specifiers or ‘...’ before ‘XEvent’
      /home/tamoghna/Downloads/tk8.4.19/unix/../generic/tk.h:569: error: expected specifier-qualifier-list before ‘Tk_ClassCreateProc’
      /home/tamoghna/Downloads/tk8.4.19/unix/../generic/tk.h:663: error: expected specifier-qualifier-list before ‘Bool’
      /home/tamoghna/Downloads/tk8.4.19/unix/../generic/tk.h:679: error: expected specifier-qualifier-list before ‘Bool’
      /home/tamoghna/Downloads/tk8.4.19/unix/../generic/tk.h:756: error: expected specifier-qualifier-list before ‘Display’
      ...
      ...
      ...
      make: *** [tk3d.o] Error 1
      

      Solution:

      Install the libx11-dev package. Open a terminal, and type in

      sudo apt-get install libx11-dev
      

    2. Tk was installed properly but it failed to run somehow.

      How to identify this:

      After installing tk8.4.19 try to run the script tk8.4.19/unix/wish from the terminal. A small window will open, close it. If no error messages appears in the terminal then Tk installation is successful and Tk is working properly. This can also be verified after installing nam and then trying to run nam. The error message would be something like:

      nam:
      [code omitted because of length]
      : no event type or button # or keysym
          while executing
      "bind Listbox <MouseWheel> {
      %W yview scroll [expr {- (%D / 120) * 4}] units
      }"
          invoked from within
      "if {[tk windowingsystem] eq "classic" || [tk windowingsystem] eq "aqua"} {
      bind Listbox <MouseWheel> {
      %W yview scroll [expr {- (%D)}] units
      }
      bind Li..."
      

      Solution:

      If you get error messages then download the patch files tk-8.4.18-tkBind.patch and tk-8.4-lastevent.patch from http://bugs.gentoo.org/show_bug.cgi?id=225999.

      then copy those files into Tk directory.Now apply the patches by using the following command:

       patch -p1 < tk-8.4.18-tkBind.patch
       patch -p0 < tk-8.4-lastevent.patch
      

      If fail to apply the patches then open the patch, check the name of the file to be patched, and make the relevant modifications to that file accordingly.

      Note: the contents of the original file are shown with a minus(-) sign at the beginning.The modified contents do begin with a plus(+) sign. The contents of the two patch files are shown below for easy reference:

      --- 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,
      
      and
      --- generic/tk.h.orig	2008-02-06 16:31:40.000000000 +0100
      +++ generic/tk.h	2008-07-24 08:21:46.000000000 +0200
      @@ -635,17 +635,15 @@
        *
        *---------------------------------------------------------------------------
        */
      -#define VirtualEvent	    (LASTEvent)
      -#define ActivateNotify	    (LASTEvent + 1)
      -#define DeactivateNotify    (LASTEvent + 2)
      -#define MouseWheelEvent     (LASTEvent + 3)
      -#define TK_LASTEVENT	    (LASTEvent + 4)
      +#define VirtualEvent	    (MappingNotify + 1)
      +#define ActivateNotify	    (MappingNotify + 2)
      +#define DeactivateNotify    (MappingNotify + 3)
      +#define MouseWheelEvent     (MappingNotify + 4)
      +#define TK_LASTEVENT	    (MappingNotify + 5)
       
       #define MouseWheelMask	    (1L << 28)
      -
       #define ActivateMask	    (1L < 29)
       #define VirtualEventMask    (1L < 30)
      -#define TK_LASTEVENT	    (LASTEvent + 4)
       
       
       /*
      

      After this install Tk from beginning again and also verify whether 'wish' runs properly (as indicated above).

    3. Problem while running 'make' for OTcl

      otcl.o: In function `OTclDispatch':
      /home/tanay/Desktop/ns2/otcl-1.13/otcl.c:495: undefined reference to `__stack_chk_fail_local'
      otcl.o: In function `Otcl_Init':
      /home/tanay/Desktop/ns2/otcl-1.13/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
      

      Solution:

      1.goto the 'configure' file

      2.In line no. 5516

      SHLIB_LD="ld -shared"

      change the above to

      SHLIB_LD="gcc -shared"

      Now reapeat the installation process starting from './configure'. For further information you can go to http://nsnam.isi.edu/nsnam/index.php/User_Information

    4. Problem wile running ' sudo make install' for ns-2.34

      ns: error while loading shared libraries: libotcl.so: cannot open shared object file: No such file or directory
      

      Solution:

      We need to set the following environment variables, and store them in the ~/.bashrc file.

      OTCL_LIB=/your/path/ns2_packages/otcl-1.13
      NS2_LIB=/your/path/ns2_packages/ns-2.34/lib
      export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB
      
      Now open a new terminal, and type ns. This should now work without any error.

    5. Problem while running 'make' for nam

      rm -f tkcompat.o; gcc -o tkcompat.o -c -Wall -Wno-write-strings -DTCL_TK -DNO_VOID  -DNDEBUG -DUSE_SHM
      -DHAVE_LIBTCLCL -DHAVE_TCLCL_H -DHAVE_LIBOTCL1_13 -DHAVE_OTCL_H -DHAVE_LIBTK8_4 -DHAVE_TK_H -DHAVE_LIBTCL8_4 -DHAVE_TCLINT_H -DHAVE_TCL_H  -I. -I/home/bibudhendu/Desktop/ns2/tclcl-1.19 -I/home/bibudhendu/Desktop/ns2/otcl-1.13 -I/usr/local/include -I/home/bibudhendu/Desktop/ns2/tcl8.4.19/generic -I/home/bibudhendu/Desktop/ns2/tcl8.4.19/generic  tkcompat.c
      
      rm -f tkUnixInit.o; gcc -o tkUnixInit.o -c -Wall -Wno-write-strings -DTCL_TK -DNO_VOID  -DNDEBUG -DUSE_SHM -DHAVE_LIBTCLCL -DHAVE_TCLCL_H -DHAVE_LIBOTCL1_13 -DHAVE_OTCL_H -DHAVE_LIBTK8_4 -DHAVE_TK_H -DHAVE_LIBTCL8_4 -DHAVE_TCLINT_H -DHAVE_TCL_H  -I. -I/home/bibudhendu/Desktop/ns2/tclcl-1.19 -I/home/bibudhendu/Desktop/ns2/otcl-1.13 -I/usr/local/include -I/home/bibudhendu/Desktop/ns2/tcl8.4.19/generic -I/home/bibudhendu/Desktop/ns2/tcl8.4.19/generic  tkUnixInit.c
      
      rm -f xwd.o; gcc -o xwd.o -c -Wall -Wno-write-strings -DTCL_TK -DNO_VOID  -DNDEBUG -DUSE_SHM -DHAVE_LIBTCLCL -DHAVE_TCLCL_H -DHAVE_LIBOTCL1_13 -DHAVE_OTCL_H -DHAVE_LIBTK8_4 -DHAVE_TK_H -DHAVE_LIBTCL8_4 -DHAVE_TCLINT_H -DHAVE_TCL_H  -I. -I/home/bibudhendu/Desktop/ns2/tclcl-1.19 -I/home/bibudhendu/Desktop/ns2/otcl-1.13 -I/usr/local/include -I/home/bibudhendu/Desktop/ns2/tcl8.4.19/generic -I/home/bibudhendu/Desktop/ns2/tcl8.4.19/generic  xwd.c
      
      xwd.c:87:29: error: X11/Xmu/WinUtil.h: No such file or directory
      make: *** [xwd.o] Error 1
      

      Solution:

      Install the package libxmu-dev. Then run

      ./configure
      make clean
      make
      sudo make install
      

    6. Problem while running 'make' for xgraph

      /usr/include/stdio.h:651: note: expected ‘size_t * __restrict__’ but argument is of type ‘char *’
      dialog.c:780: error: too few arguments to function ‘getline’
      dialog.c: In function ‘getline’:
      dialog.c:899: error: argument ‘lptr’ doesn’t match prototype
      /usr/include/stdio.h:651: error: prototype declaration
      dialog.c:899: error: number of arguments doesn’t match prototype
      /usr/include/stdio.h:651: error: prototype declaration
      make: *** [dialog.o] Error 1
      

      Solution:

      Download the patch below-

      http://archive.ubuntu.com/ubuntu/pool/universe/x/xgraph/xgraph_12.1-12.diff.gz

      Note: copy and unzip the above patch file into xgraph-12.1

      patch < xgraph_12.1-12.diff
      
      After applying the patch if you see in get any problem with the configure.in file like
      configure.in:3: version mismatch.  This is Automake 1.11,
      configure.in:3: but the definition used by this AM_INIT_AUTOMAKE
      configure.in:3: comes from Automake 1.11.1.  You should recreate
      configure.in:3: aclocal.m4 with aclocal and run automake again.
      
      then goto configure.in file and add 'AC_LOCAL' in the first line.

    The above is an attempt to list frequent problems faced while trying to install ns2. This list is by no means exhaustive. In the worst case, you might require to do a bit of troubleshooting by yourself, which, in most cases, would be installing certain missing packages.

    You can also look at the following places for further help:

    Trace File Analysis

    A simple tool has been provided as part of this lab to analyze the trace files generated after simulation with ns2. A summary of the available options, and usage guide is given below.

    Features List

    Following is a list of functionalities provided by the Trace Analysis tool:

    • Trace file formats: Following trace file formats are being supported:
      • Wired
      • Wireless (new format)
      • Satellite -- currently redirects to wired mode
      • Mixed -- when both wired and wireless connections are present in the simulation
    • General Statistics: To provide some common statistics about the simulation being run. Currently displays only the simulation duration.
      • Inputs: None
      • Output: Text
    • Average Throughput: Computes total # of bytes received by a node over the entire simulation duration
      • Inputs: Node #
      • Output: Number
    • Bytes Received: Plots cumulative count of bytes received by a node over the entire simulation duration
      • Inputs: Node #; for wireless scenario, trace levels (AGT, MAC, RTR)
      • Output: Graph
    • End-to-end Delay: Plots the end-to-end delay delay encountered by packets while moving from a source node to the destination node
      • Inputs: Source node #, destination node #, scaling factor [optional] -- scaling factor helps to amplify the y-axis values
      • Output: Graph
    • Packet Retransmissions: Plots # of retransmission(s) of a given packet occurs between the source and destination nodes
      • Inputs: Source node #, destination node #
      • Output: Graph
    • Hop Count: Plots the # of hops traveled by a packet to reach the destination node from the source node. It counts the destination node as well.
      • Inputs: Source node #, source port #, destination node #, destination port #
      • Output: Graph

    Limitations

    1. For analyzing the problems in the "Satellite Networks" experiment, please use the Wired mode of analysis
    2. Analysis of trace files for mixed mode of simulations (wired & wireless) is not supported currently
    3. Outputs produced do not necessarily have accuracy for scientific publications. In particular, the plot of hop counts may vary a bit from the original count (in wireless mode) in cases when a packet has been forwarded to more than one node.
    4. The tool currently allows only a single instance of a given type of plot. For example, this doesn't let you plot end-to-end delays between multiple (source, destination) node pairs
Decrease font size Increase font size List of experiments
Top