Network simulation lab: the ns-3 simulator on one private Ubuntu VM

This lab gives each student the network simulator many university courses use, ns-3, in one Ubuntu VM. The student builds a small network inside a C++ program, runs it, reads the packet trace it writes and measures delay, throughput and packet loss. Two programs the student writes are marked by a script that runs them with values the student never sees.

Nothing is installed on the student’s computer and no cables are needed. ns-3 is the real simulator, installed from Ubuntu’s archive, and a program builds in a few seconds. The packet traces are real pcap files, so the same tcpdump command works on them as on a capture from a real network.

What students learn

How a network is described and measured. A first program joins two nodes with a point-to-point link and sends one UDP echo. Its pcap file shows the request and the reply with their times, and changing the delay and the data rate shows which part of the round trip each one moves: the delay is the same for every packet, and the data rate matters more the bigger the packet is. Then several senders share one slower link through a router, and FlowMonitor counts what each flow sent and what arrived, which shows when packets are lost and why.

The five parts

First two nodes and an echo: a given program is built with sim build and run. Second a trace: sim pcap lists the packets that crossed a device. Third the link changed from the command line, with a prediction before each run. Fourth a bottleneck with FlowMonitor: senders, a router and a slower link, with loss and throughput counted per flow. Fifth two programs the student writes, scenario.cc and loss.cc, from a comment that says exactly what each must do. Everything the student edits is in the folder ns3, and README.md in the home folder says what to do and gives none of the answers.

Run it in your browser

VM labs are set as a lab task in a module, and the sample is on the lab’s page. The machine is small: one CPU, 1 GB of memory and 10 GB of disk. A program compiles in two to five seconds.

  1. Add the lab. In a module you teach, add a task and choose the Ubuntu VM lab card. The page shows a short description of the machine instead of a compose file.
  2. Start from the sample. The page offers ready-made labs to start from. Choose Network simulation. Using a sample replaces the text, and Undo brings yours back.
  3. Publish and start your own copy. Publish, then Start. The lab’s own setup script installs ns-3, a C++ compiler and tcpdump from Ubuntu’s archive and writes the sim helper, the programs to work on and the README, the first time the VM starts, in a few minutes.
  4. Open the terminal. Open its terminal and read README.md in the home folder. Nothing opens in the browser: the lab is the terminal.

A basic lesson on this lab

Network Simulation Basics is a small lesson worked in this lab, which is an Ubuntu VM. It has a hook, an I can outcome, key words, a starter, a check after each idea, a common mistake and an exit check, and each step has a Run button that types its command into the machine’s terminal. A student builds and runs the echo, reads its pcap, runs it again with a longer delay and a slower rate, and runs the bottleneck twice to see when packets are lost.

The lesson looks around and leaves the lab’s own task, the two programs, to the student, so it hands out no answers.

How it is marked

The lab has a check. It runs on a copy of the saved machine and compiles scenario.cc and loss.cc. It runs scenario.cc twice with a delay, a data rate and a packet size it draws afresh, and the round trip the program prints must match the arithmetic and the two timestamps in the pcap the program wrote. It runs loss.cc with a number of senders, a rate and a bottleneck it draws afresh, once overloaded and once not, and the loss and throughput the program prints must match the XML FlowMonitor wrote and a run of the given bottleneck program. A program that starts another program, or has no ns-3 in it, is refused. The first line of what the check printed says why.

  1. Hand it out. Assign the lab like any task, with a due date if you want one. Each student gets a VM of their own, kept between sessions.
  2. Run the check. On a student’s row in the class list, press Run the check. It starts a copy of their saved machine that is not saved back, runs the lab’s check script as root and shows whether it passed, what it printed and when. The student is not told the result.
  3. Mark it. Read the first line of what the check printed: it says what is not right, such as a round trip that does not match the pcap the program wrote, or a loss that does not match loss.xml. Send the work back with a reason if it needs more.

The definition on GitHub

The file is the whole lab definition, the same text the platform runs: size, setup script, helper command, the programs to work on, the README and the check. Copy it and change the topology or the numbers to make a longer lab.

Try this lab, and what it costs

A free personal account can work through the basic lessons in this lab, with enough free credit each month to follow most lessons and no card. For a class, a school or college has its first 365 days free for up to 50 students, then pays per student a year, with every lab included and staff free.

Questions people ask

Does the lab need a licence?
No. ns-3 is open source, under the GNU General Public Licence version 2, and is installed from Ubuntu’s archive when the student’s VM starts, so we distribute none of it.
Why C++ and not Python?
Ubuntu 26.04 gives ns-3 3.46 with its libraries and headers but no Python bindings, so the lab uses the language ns-3 is written in and the one its tutorials use. A student edits a short main function, and sim build compiles it against the installed libraries in a few seconds.
Can students harm anything?
Only their own copy. The machine of a visitor without an account reaches Ubuntu’s archive and nothing else, the simulated network is inside a program and touches no real one, and if a student breaks a file, sim reset puts it back as it was given.
Was the lab tested in a real student VM?
The setup, the lesson’s commands and the check, with each way of faking it, were run in a real Ubuntu 26.04 container standing in for the VM, on an arm64 machine. A booted student VM and the amd64 packages of the student machines are worth one try before a class.