Mininet SDN Lab Environment with Custom Python Topologies
I built reproducible SDN test environments with the Mininet Python API, defining custom multi-switch topologies that spin up on demand against a remote controller. Codifying topologies made OpenFlow and controller experiments repeatable and disposable.
Objective & Context
Mininet emulates real networks with lightweight namespaces and Open vSwitch, so an entire fabric runs on one host. This lab uses the Python API to script topologies, providing the reproducible substrate for the SDN concepts, OpenFlow, and controller labs.
Environment & Prerequisites
- Mininet with Open vSwitch; Python 3.
- A remote controller (Ryu/ONOS) for non-trivial topologies.
- Root privileges (Mininet manipulates namespaces).
flowchart TB
C[Remote Controller] --> S1[s1]
C --> S2[s2]
S1 --- S2
S1 --- H1[h1]
S2 --- H2[h2]
Step-by-Step Execution
1. Define a topology with the Python API
from mininet.topo import Topo
class TwoSwitch(Topo):
def build(self):
s1, s2 = self.addSwitch('s1'), self.addSwitch('s2')
self.addLink(s1, s2)
self.addLink(self.addHost('h1'), s1)
self.addLink(self.addHost('h2'), s2)
topos = {'two': (lambda: TwoSwitch())}
2. Launch against a remote controller [PRIVILEGED]
mn --custom topo.py --topo two --controller remote,ip=127.0.0.13. Validate full reachability
mininet> pingall*** Results: 0% dropped (2/2 received)
Validation & Testing
Run pingall and iperf within the emulated topology to confirm connectivity and link behaviour. Pass criteria: 0% drop with the controller present and a clean teardown via mn -c.
Advanced: Troubleshooting
- Stale state errors: always
mn -cbetween runs to clear namespaces and OVS bridges. - No connectivity: a remote controller must be running or hosts have no flows.
- Link params ignored: use TCLink to apply bandwidth/delay.
Key Results
- Scripted reproducible multi-switch topologies that deploy in seconds.
- Provided the disposable substrate for 3 dependent SDN labs.
- Achieved 0% packet drop in controller-managed reachability tests.
- Standardized clean teardown to prevent cross-run contamination.