
An Introduction to NS3
If you're getting into network research — wireless protocols, routing algorithms, IoT deployments, anything that involves simulating how packets move through a network before you build the real thing — NS-3 is very likely the tool you'll end up using. Here's what it is, why it exists, and how to get your first simulation running.
What NS-3 is
NS-3 is a discrete-event network simulator, built primarily for research and education. It's free, open-source, licensed under the GNU GPLv2, and maintained by a large worldwide community rather than a single company or lab — the project ships a new stable release roughly every three months.
"Discrete-event" is the key architectural idea: instead of stepping forward through time in fixed small increments, the simulator jumps directly from one event to the next (a packet is transmitted, a timer expires, a channel becomes free). That's what makes it possible to simulate hours of network activity in a fraction of the time it would take to actually happen.
NS-3 is written in C++ at its core, with Python bindings available for writing simulation scripts. Simulations themselves are usually written as short C++ or Python programs that construct a network topology, attach applications and traffic generators, and then hand control over to the simulator to run.
NS-3 is the successor to NS-2, an older simulator that was widely used through the 2000s but was built around a Tcl scripting interface and had become difficult to extend. Rather than patch NS-2, the community made a deliberate decision to break backward compatibility entirely and rewrite the simulator from scratch in C++, starting in 2006. NS-1 and NS-2 are no longer developed; NS-3 is the actively maintained line, now on major releases in the high-40s (ns-3.48 as of mid-2026).
The core concepts you need before writing a simulation
- Node The basic abstraction for a device on the network — a computer, a router, a sensor. A node starts out as an empty container; you add network interfaces, protocol stacks, and applications to it.
- NetDevice Represents a network interface card and its driver — the thing that actually sends and receives packets on behalf of a node. Different NetDevice types model different link layers (Wi-Fi, point-to-point, CSMA/Ethernet, LTE, and so on).
- Channel The medium that connects NetDevices together and models how a transmission from one device is (or isn't) received by others — propagation delay, loss, interference.
- Application The traffic source or sink running on a node — something that generates packets to send, or consumes packets on arrival. NS-3 ships with common ones (UDP echo, bulk send, on/off traffic) so you don't have to write your own for a basic test.
- Helper classes Most of the objects above have a matching "helper" (NodeContainer, WifiHelper, InternetStackHelper, and so on) whose job is to hide the tedious wiring and let you set up a topology in a handful of lines instead of dozens.
-
Simulator
The engine that owns the event queue and the notion of simulated
time. Your script builds the whole topology first, schedules
whatever needs to happen, and then calls
Simulator::Run()to actually execute it.
What it's actually used for
NS-3's simulation core supports both IP and non-IP networks, but the large majority of real-world use is wireless and IP-focused: Wi-Fi, LTE, and a variety of static and dynamic routing protocols like OLSR and AODV. It also supports a real-time scheduler, which lets a simulation interact with actual systems — sending and receiving NS-3-generated packets on real network devices, or acting as an interconnect between virtual machines.
In practice, that makes it the default tool for testing a new routing protocol before proposing it to a standards body, checking whether a sensor network layout will actually cover the area it needs to before installing hardware, or comparing MAC-layer designs under identical, repeatable conditions that would be nearly impossible to reproduce on real radios.
Installing it
NS-3 runs natively on Linux, FreeBSD, and macOS, and on Windows via a Linux virtual machine or WSL. The simplest path on a fresh Linux machine is the "allinone" bundle, which pulls in commonly used contributed modules alongside the mainline release:
\# install build prerequisites (Ubuntu/Debian example)
sudo apt install g++ python3 cmake ninja-build git
\# download and unpack the allinone bundle
wget https://www.nsnam.org/releases/ns-allinone-3.48.tar.bz2
tar xjf ns-allinone-3.48.tar.bz2
cd ns-allinone-3.48
\# build everything
./build.py --enable-examples --enable-tests
That last step compiles the simulator core along with the example programs and test suite, which is worth keeping enabled the first time through — running the test suite afterward is a quick way to confirm your build is healthy before you write anything of your own.
Your first simulation, conceptually
Every NS-3 script follows roughly the same shape, regardless of how complex the topology gets:
- Create the nodes. Decide how many devices are in the topology and instantiate them with a NodeContainer.
- Install the network devices and channel. Pick a link type (point-to-point, Wi-Fi, CSMA) and use its helper to connect the nodes.
- Install an internet stack. Add IP addressing and routing to each node so they can actually talk to each other above the link layer.
- Attach applications. Put a traffic source on one node and a sink on another, and set when each should start and stop during the simulation.
-
Run it and collect results.
Call
Simulator::Run(), thenSimulator::Destroy(), and pull your metrics out of whatever tracing or logging you enabled along the way — NS-3's FlowMonitor module is the standard way to get per-flow statistics like delay, throughput, and packet delivery ratio without writing that bookkeeping yourself.
The official tutorial walks through exactly this shape with a working point-to-point example in the first chapter, and it's the fastest way to get from "installed" to "ran something and saw output" — worth doing before reaching for a more complex scenario like Wi-Fi or LTE.
NS-3 gets you a long way on installed helpers and example code alone. But the moment your work depends on the numbers being right — a paper, a design decision, a deployment plan — it's worth pairing this introduction with the follow-up post on methodology: how to validate a scenario before trusting it, why parameter sweeps beat single runs, and what to do when a result looks impossible instead of just surprising.
You may also like
Edge AI for Personal Safety
