Key Technologies

ns-3 is a C++ library which provides a set of network simulation models implemented as C++ objects and wrapped through python. Users normally interact with this library by writing a C++ or a python application which instantiates a set of simulation models to set up the simulation scenario of interest, enters the simulation mainloop, and exits when the simulation is completed.

The ns-3 library

Python bindings

The ns-3 library is wrapped to python thanks to the pybindgen library which delegates the parsing of the ns-3 C++ headers to gccxml and pygccxml to generate automatically the corresponding C++ binding glue. These automatically-generated C++ files are finally compiled into the ns-3 python module to allow users to interact with the C++ ns-3 models and core through python scripts.

Details on how to set up properly your development environment to re-scan the ns-3 C++ headers and generate new bindings can be found here.

High Level Design

In comparison with other discrete-event network simulators, ns-3 is distinguished by the following high level design goals.

C++ and Python emphasis

Many simulators use a domain-specific modeling language to describe models and program flow.  ns-3 uses C++ or Python, allowing users to take advantage of the full support of each language.

Callback-driven events and connections

Simulation events in ns-3 are simply function calls that are scheduled to execute at a prescribed simulation time.  Any function can be made into an event and scheduled, by use of a callback function.  This is in contrast to specialized “handler” functions that centralize the processing of events in each simulation object.   Callbacks are also heavily used in the simulator to reduce compile-time dependencies between simulation objects.

Flexible core with helper layer

ns-3 features a powerful low-level API that allows power users the flexibility to configure things in different ways.  Layered on top of this is a set of “helper” layer APIs that provide easier-to-use functions with reasonable default behavior.  ns-3 users can mix and match between the simpler APIs at the helper layer and the full APIs underneath.

Emphasis on emulation

The simulation design is oriented towards use cases that allow the simulator to interact with the real world.  ns-3 packet objects are stored internally as packet byte buffers (similar to packets in real operating systems) ready to be serialized and sent on a real network interface.  Several different simulation-in-the-loop and virtual machine integration frameworks have been developed, and ns-3 experiments have been carried out on wireless testbeds.

Emphasis on software reuse

A Direct Code Execution environment has been developed alongside of ns-3 that allows users to run many POSIX-compliant userspace applications within the simulation, without requiring changes to the application code.

Alignment with real-world interfaces

ns-3 nodes are patterned after the Linux networking architecture, and key interfaces and objects (sockets, net devices) are aligned with those in a Linux computer.  This better facilitates code reuse and improves realism of the models, and makes the simulator control flow easier to compare with real systems.

Configuration management

The ns-3 simulator features an integrated attribute-based system to manage default and per-instance values for simulation parameters.  All of the configurable default values for parameters are managed by this system, integrated with command-line argument processing, Doxygen documentation, and an XML-based and optional GTK-based configuration subsystem.

Lack of an IDE

The project does not maintain an Integrated Development Environment (IDE) to configure, debug, execute, and visualize simulations in a single application window, such as found in other simulators.  Instead, the typical workflow is to work at the command line and integrate configuration and visualization tools as needed.  Some developers have used Eclipse as a development IDE.