Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Build a test network with Mininet

After this lesson: I can build a small test network and check that every host can reach every other.

50 min lesson5 commandsSoftware-defined networking lab: Open vSwitch, Mininet and an OpenFlow controller on one VM

A whole network in one command

Mininet is a tool that builds a whole test network, with hosts, switches and links, on one computer in a few seconds. You can try a network design, break it and build it again without buying a single cable.

Software-defined networking research and teaching both rely on it, because the network is only software.

By the end of this lesson

Note

I can build a small test network and check that every host can reach every other.

Key words

WordWhat it means
Hosta computer on the network
Linka cable between two devices
Topologythe shape of a network: what is joined to what
Minineta tool that builds a test network from software
Ping testevery host pings every other host

The cells students fill in are left blank in this preview.

A topology says what is joined to what

You describe a network to Mininet by naming its topology. single,4 means one switch with four hosts on it. linear,3 means three switches in a row, each with one host. tree,depth=2,fanout=2 means a tree of switches with two branches at each level.

Mininet names the hosts h1, h2 and so on, and the switches s1, s2 and so on.

Worked example: four topologies, counted

TopologyHostsSwitchesLinks
single,3313
single,4414
linear,3335
tree,depth=2,fanout=2436

The cells students fill in are left blank in this preview.

A ping test tries every pair

Mininet can run a ping test for you with --test pingall. Every host pings every other host, and Mininet prints how many pings got no answer.

The word is pingall because it tests all of them. Each host pings each other host, so a pair is tried in both directions.

Worked example: how many pings a test sends

HostsEach host pingsPings in all
21 other host2 x 1 = 2
32 other hosts3 x 2 = 6
43 other hosts4 x 3 = 12
54 other hosts5 x 4 = 20

The cells students fill in are left blank in this preview.

A common mistake

Warning

Many people think a ping test tries each pair of hosts once, so 4 hosts would send 6 pings. Each host pings every other host, so each pair is tried in both directions. The count is hosts times one fewer than hosts: 4 hosts send 12 pings.

Run a test network in your lab

Mininet and the lab's controller both want port 6653. If the controller is still running, Mininet stops with the message Please shut down the controller which is running on port 6653.

So the first command stops the lab and frees the port. The next three each build a network, test it and take it down again. Mininet removes every Open vSwitch switch when it stops, br0 too, so the last command builds your lab again.

Stop the lab and free port 6653

Command
sudo sdnlab down

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

The smallest test network

Command
sudo mn --mac --test pingall

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Reading what Mininet printed

Mininet prints a line for each step. It adds a controller, then hosts h1 and h2, then a switch s1, then the links (h1, s1) (h2, s1).

It pings, and the results line says 0% dropped (2/2 received). A first line about resource limits may appear. You can ignore it.

One switch with four hosts

Command
sudo mn --mac --topo single,4 --test pingall

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Three switches in a row

Command
sudo mn --mac --topo linear,3 --test pingall

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Build the lab again

Command
sudo sdnlab flows

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

What the three tests showed

The four host test ended with 0% dropped (12/12 received), and the three switch test with (6/6 received). Both match the counts in the table.

You can also open Mininet's own prompt with sudo mn --mac --topo single,3. It waits for you to type, so try it in the terminal rather than here, and type exit to leave.

About this lab and its source: Software-defined networking lab: Open vSwitch, Mininet and an OpenFlow controller on one VM

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.