SDN Network Emulation with Mininet: Building a 100-node Topology on Your Laptop

Network tutorial - IT technology blog
Network tutorial - IT technology blog

The Struggle of SDN Labs: When Your Wallet Can’t Match Your Passion

When I first started tinkering with Software-Defined Networking (SDN), I dreamed of having a rack of high-end OpenFlow switches to test routing algorithms. But reality was quite harsh: a tight budget, and old equipment that was both power-hungry and as noisy as a tractor.

The biggest issue arises when you want to experiment with Fat-Tree or Spine-Leaf architectures involving 50-100 nodes. When configuring ECMP routing on Linux to manage traffic across these paths, buying physical hardware is out of the question for individuals. Even using traditional Virtual Machines (VMs), each one consumes at least 1-2GB of RAM. Just launching 10 nodes would cause your Core i7 machine to freeze instantly.

Why GNS3 or Cisco Modeling Labs Can Be ‘Overkill’ Sometimes

Tools like GNS3 or CML are excellent for studying for Cisco certifications because they run the full device operating systems (IOS, NX-OS). However, the price is extremely high resource consumption.

In the SDN world, we need to separate the Control Plane and Data Plane. Traditional tools often bundle these two components together, making control programming cumbersome. Furthermore, drag-and-drop topologies in a GUI are hard to reproduce and nearly impossible to fully automate with code.

Mininet – The Gold Standard for Lightweight Network Emulation

Mininet solves this problem with a smarter approach. Instead of running heavy VMs, it leverages Linux Network Namespaces. Much like configuring VRF on Linux to isolate routing tables, this is a lightweight technology within the Linux kernel that allows for the creation of hundreds of hosts and switches in just seconds.

The best part? A host in Mininet consumes only about 15-20MB of RAM instead of gigabytes like a VM. You can build a massive network right on your office laptop, similar to configuring VXLAN on Linux for virtualized environments, and interact seamlessly with controllers like Ryu, ONOS, or OpenDaylight via OpenFlow.

Installing Mininet in 30 Seconds

I always prioritize Ubuntu Server for its stability. You only need a single command to get started:

sudo apt update && sudo apt install mininet -y

To check if the system is ready, try running this command:

sudo mn --test pingall

The system will automatically spin up 2 hosts, 1 switch, perform a ping test, and clean up the environment. Everything happens in the blink of an eye.

Using Python to ‘Code’ Your Entire Network

Using the CLI is just for getting started. To build a real Data Center network, you should write Python scripts. This allows you to manage the topology via Git and scale the network simply by changing a variable.

Here is the script I often use to create a custom Tree Topology:

from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import RemoteController
from mininet.cli import CLI
from mininet.log import setLogLevel

class CustomTreeTopo(Topo):
    def build(self, depth=2, fanout=2):
        # depth: depth level, fanout: number of child branches per node
        self.addTree(depth, fanout)

def run_network():
    topo = CustomTreeTopo(depth=2, fanout=4) # Create a network with 16 hosts
    
    # Connect to an external Controller (e.g., Ryu running on port 6633)
    net = Mininet(topo=topo, controller=RemoteController)
    
    # Pro tip: When designing large networks, IP calculation is prone to errors.
    # You can use toolcraft.app/en/tools/developer/ip-subnet-calculator 
    # to quickly divide subnets and avoid IP overlaps when assigning hundreds of nodes.

    net.start()
    print("*** Network is ready. Type 'nodes' to see the device list.")
    CLI(net)
    net.stop()

if __name__ == '__main__':
    setLogLevel('info')
    run_network()

Performance Testing: Don’t Just Look, Measure!

Once built, you need to know how fast or slow the network is performing. Beyond basic Linux bandwidth monitoring, in the Mininet CLI, take advantage of these “power” commands:

  • iperf h1 h2: Measure actual bandwidth. You’ll see speeds up to 10-20 Gbps depending on your CPU.
  • ovs-ofctl dump-flows s1: View the flow table of switch s1. This is the best way to debug OpenFlow logic.
  • wireshark &: Open Wireshark to capture OpenFlow packets on the loopback (lo) interface.

Real-World Advice: Separating the ‘Body’ and the ‘Soul’

A common mistake for beginners is trying to configure everything within Mininet. Remember: Mininet is just the “body” (Data Plane). To master SDN, you need a “soul” (Control Plane), which is a real Controller.

The standard workflow I apply for projects is: Write the topology in Python -> Run the Ryu Controller in a separate terminal -> Use RemoteController to connect. This approach helps you isolate whether a bug is in the network structure or the programming logic, making debugging much less of a headache than using manual tools or Scapy for packet-level analysis.

Share: