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:
- 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\Cygwin
is
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.
- 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.
- 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.
- Alternatively, you can download the pre-compiled version from the course website. This version will unzip under /home/NSHome.
- 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.
- Trace file formats: there are a number if different traces file formats, they are described here.
- MAC:
- TCL Script to test throughput and awk script to extract information
- Paper describing analytical models for 802.11 MAC, can be used to validate simulation results
- Setting up simulations for ZigBee: set of pages with a tutorial on ZigBee, scripts, etc.
- The IEEE 802.11 implementation in NS2 is not perfect. In
addition, the PHY model is extremely simplistic. While this is good
enough for many purposes, better/more detaled implementations of the
PHY/MAC layers for 802.11 exist, a link to one such independently
developed version is provided below.
- Mobility:
- NS2 comes with its own scenario generator, which is based on the Randome Waypoint mobility model.
- BonnMotion
is a tool to generate a range of mobility scenarios and to analyze
their properties. Some mobility models are individual mobility models
(i.e., the movement of each node is determined independently), others
are so-called group mobility models, where node movements are
correlated. This allows to model, for example, platoons of soldiers
marching together, or emergency workers searching through a confined
space in a systematic and coordinated fashion.
- The NS2 mobility model suffers from instability: initially, the
nodes are randomly but uniformly distributed in the simulated space,
after a while the node distribution changes to a non-uniform pattern
(more nodes tend to be in the centre of the simulated area. This site
has information (ns2 code, descriptions, etc.) on an improved random
trip model that does not suffer the same initial transient phase that
NS2's Random Waypoint Mobility model exhibits.
- Routing:
- TCL Script to run a
MANET routing protocol simulation. Expects that subdirectories
<PROTO>_traces exist to store trace files, where <PROTO> is
the name of the routing protocol passed as one of the command-line
parameters.
- Directory with a number
of (mobile) scenario files for the above script (individual files
should be stored in subdirectory "scenarios" for TCL script to work)
- AWK script to analyze the result of a single run
- Batch file to run a set of ten experiments, analyzes the output for each run
- C program to read in the ten summaries and calculate averages and standard deviation for PDR and packet latency
- Mixed Wired/Wireless Scenario with two long-lived FTP/TCP flows
- Scenario file
- To run the scripts with bandwidth values that correspond to
the bandwidth of 802.11b, use the following two lines before creating
the simulator object:
- Mac/802_11 set basicRate_ 2Mb
- Mac/802_11 set dataRate_ 11Mb
- TCL Script to run NS simulations
- AWK script to analyzes the results of a single run
- Sample output results (should be stored in subdirectory "2FlowTraces")
- Batch file to analyze all four possible runs in the sample output directory
- Paper describing the unfairness and possible solution (to appear at IEEE WiMob 2007)
- Traffic generators:
- Many studies use CBR (constant bit rate)
traffic flows. But sometimes we want to model more interesting traffic
(bulk FTP downloads, HTTP traffic, VoIP traffic, video streams, etc.).
NS2 provides for a range of (mostly data stream) traffic generators, see Section 6 of the NS Manual
(Applications).
- In addition, a range of tools/references on the
WWW provide information about generating other traffic streams: BonnTraffic, VoIP streams, MPEG video, IP Telephony including SIP, etc.
- Topologies: another important part of any simulation study is the
network topology. For MANETs and WSN, mobility models generate
(indirectly) the topology. Yet fixed networks also have specific
structures, and a range of topology generators have been developed.
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