July 18, 2006

ns-2 network simulator: Free, yes; friendly, no

Author: Nauman Afzal

The open source network simulation tool ns-2 is an invaluable tool for researchers working on wired or wireless networks. I came across ns-2 while working on my thesis. I needed a network simulator, and since my college lacked the brand-name heavyweights, I had to look for an alternative that was free but could do the job. While ns-2 is free, it's also pretty unfriendly.

ns-2 is a variant of the REAL network simulator. Over the past few years it has been evolving, and it is still far from complete. Several organizations have been involved in its development, including DARPA, Xerox, UCB, and Sun Microsystems. The objective has been to make a network simulation tool to study and analyze new ideas in detail before implementation.

The software has been designed to work on Linux, but it can be made to run on Windows XP by using the Cygwin tool. For the current version ns-2.29, Fedora Core 2 is recommended, although ns-2 may work on Red Hat 9 or even FC4. Though there are no stringent hardware requirements, using a fast PC will result in less wasted time when you're running large simulations.

Installing ns-2 shouldn't be difficult for anyone familiar with unzipping source code, which can be downloaded for free from the ns-2 Web site. ns-2 runs from the command line; there is little GUI or drag-and-drop functionality.

The simulator structure uses two languages: OTcl scripting on the front end, and C++ on the back end. You use OTcl scripting to make a simulation scenario, which may include network components like nodes, routers, and link bandwidth. When using Windows-based simulators like Opnet and OMNeT, making a simulation scenario is as easy as dragging and dropping the required network components onto a workspace. In order to make a simulation scenario with ns-2, however, one has to learn OTcl in some detail, and that means the learning curve to use ns-2 can be quite steep.

Then, on the back end, there is C++. If, for instance, you are making a Mobile IP-based simulation, you have to enable the relevant Mobile IP C++ files in the OTcl code. The OTcl code links to the C++ files, so when the OTcl code runs, it calls the relevant C++ code to execute a particular task.

Results of the simulations are shown in a tabular form in what ns-2 calls trace files. One line in a trace file is produced for each data packet that travels from the initiating node to the terminating node. Since the trace files record every parameter of a data packet, including its size, start time, type, time to live, starting node, and ending node, ns-2 generates huge trace files. For example, in a Mobile IP simulation run of 120 seconds involving two nodes, the relevant trace file generated takes up a hefty 100MB. Run on a Pentium III client, the simulation could take more than 45 minutes to finish.

Filtering out required data from the trace files presents another issue. The data in trace files is in tabular form, with each column separated by a white space. You need to employ a programming language to filter out the required data. I have found that Perl or awk can handle the white space issue well.

ns-2 comes bundled with Xgraph to plot the data on a graph for analysis. You can also use a spreadsheet to make relevant plots and curves.

Though ns-2 provides limited ability to view the animations after the simulation, its sister program Network Animator (NAM) makes it possible. NAM also can record the animation in the form of graphics as the simulation progresses. These graphics can then be converted to GIF or AVI format for later viewing. NAM also provides options for adjusting the step size of the animation in milliseconds, zooming in and out, and pausing the animation.

In addition to being a research tool, ns-2 is also an excellent educational tool. The built-in tutorials provide an in-depth understanding of networks, their different protocols, and layer functions. For research, you will have to tinker with the C++ files that work in the background, and that can be mind-boggling at times. However, user support via mailing lists is excellent. Posted questions are usually answered in 24 hours, and that is one of the reasons why I chose ns-2 instead of OMNeT.

I advise anyone planning to try ns-2 to have patience and be ready for a lot of experimentation and tinkering.

Click Here!