Information about NS2 and how to use it

Simulation is a very powerful tool to evaluate network protocols and consequently widely used. The advantages of simulation are that it allows the protocol designer to evaluate their protocol in very controlled conditions, changing (in a repeatable fashion) one variable/factor at a time. In addition, simulation allows us to explore the scalability of protocols way beyond what most reallife testbeds can offer. This course uses NS2 (Network Simulator 2) to explore the behaviour of protocols at the MAC, network, transport and application layer. However, simulation is no magic bullet. The quality of the results depends both on how thorough the researcher sets up experiments and analyzes the results (read this paper for an interesting discussion on the shortfalls of many simulation studies). In addition, the quality of the simulator itself has a bearing on the outcome. In essence, a good simulator should be validated, i.e., its results should correspond to results one would observe in a testbed/real deployment, assuming identical scenarios."Correspond" could either mean quantitative equivalance (for example, the FTP throughput for flow 1 is the same, usually plus/minus a small acceptable margin due to random influences), or qualitative equivalence (for example, packet delivery ratio for a particular multicast routing protocol drops linearly with the size of the multicast group - in that case, the absolute packet delivery ratios for a given scenario could be quite different). As by necessity simulators abstract from reality, this is difficult and cannot be taken for granted, see this paper (among a few others that have recently been published).

How to install NS2 on Windows machines:

  1. Install Cygwin  (from http://www.cygwin.com/). To compile and run NS2, we need a number of packages, as specified in the next step. One important point is that the Cygwin Installation Directory should NOT contain any spaces. In particular, C:\cygwin (the default) is a good installation directory, C:\Program Files\Cygwinis not. If you only want to experiment with the provided software and the tutorial/assignment examples, you need the basic CYGWIN distribution plus an editor (I use VIM, but there are a range of choices), plus whether language tools you need to write your own scripts/programs to analyze NS2 trace files: awk, gcc, python, etc.). And to avoid annoying error messages when running NS2, also install perl. And if you want to use NAM (or any other GUI-based application), make sure to install the X11 packages and startx.
  2. Read the installation information for NS2. The NS2 homepage has a wealth of information about the simulator and the source code can be downloaded from Sourceforge. The developers also maintain a detailed set of instructions to install and run NS2 under Cygwin/Windows. We will work with versions of NS2 later than 2.27, so we don't need to worry about the instructions about old versions. Read carefully through the Cygwin requirements, in terms of installed packages etc.
  3. To install NS-2.31 (the latest version as of June 2007), using the "all in one" distribution. The gzippped tar file can be downloaded from the Sourceforge download site for NS2. Once you downloaded the source, follow the installation instructions on the above website
  4. Alternatively, you can download the pre-compiled version from the course website. This version will unzip under /home/NSHome.
  5. Once you successfully compiled NS2, you can validate it as well, see instructions in the README file. To work with NS2, you need to set certain environment variables. The file source31.sh in /home/NSHome contains the necessary instructions and you can just update the environment variables by executing "source source31.sh". You need to do this every time you open a new shell, but it provides flexibility if you want to work with different versions of NS2. Alternatively, you can add the following lines to  .bash_profile in your home directory (these paths assume that NS-2.31 was compiled and installed in /home/NSHome/ns-allinone-2.31):
PATH=${PATH}:/home/NSHome/ns-allinone-2.31/bin:/home/NSHome/ns-allinone-2.31/tcl8.4.14/unix:/home/NSHome/ns-allinone-2.31/tk8.4.14/unix
LD_LIBRARY_PATH=/home/NSHome/ns-allinone-2.31/otcl-1.13:/home/NSHome/ns-allinone-2.31/lib
TCL_LIBRARY=/home/NSHome/ns-allinone-2.31/tcl8.4.14/library
export PATH LD_LIBRARY_PATH TCL_LIBRARY

Working with NS2

NS2 has a very detailed manual, though it is hard to use as a starting point. A good introductory tutorial is "NS for Beginners" (huge PDF file, but containes an introduction to Tcl/AWK and a range of other useful topics as well). Finally, here is a short and useful tutorial maintained by the VINT group (i.e., the people who develop NS2). The next few simple examples are taken from this tutorial, slightly modified.
As we work on specific simulation tasks, you will find that the WWW has a rich set of resources that we can tap in to, beyond the NS2 documentation.

Patching NS2 with additional source packages

OLSR (UM-OLSR) for NS2, versions 2.27 and 2.28
IEEE 802.11e EDCA and CFB Simulation Models for NS2
Bluetooth Extensions for NS2
An improved 802.11 implementation for NS2

Tutorials for Frequently Used Programming Tools/Languages

Tcl/Tk: the interpreter language to set up simulation scenarios in NS2
C++: the programming language in which most of NS2 is implemented
AWK: a scripting language that comes in handy to write scripts to extract information from NS2 trace files (alternative, somewhat more detailed, tutorial)
PERL: an alternative scripting language to extract information from NS2 trace files

Useful Links

Ke Liu's NS2 page (with code and Q&A)
Bo Wang's NS2 page (with code and notes)
NS2 Learning Guide (in English and Chinese)
NS2 Debugging Page (some experiences)
Data Display Debugger (useful for debugging NS2)
NS2 trace analyzer