Objective

Build custom network topologies programmatically with Mininet's Python API, test traffic, and implement flow rules.

Tools & Technologies

  • Mininet
  • Python API
  • custom topology
  • flow rules

Key Commands

sudo mn --custom topo.py --topo mytopo
sudo mn --test iperf
mn.pingFull()
net.addController('c0')

Architecture Overview

graph LR subgraph Custom Topology CTRL[Controller c0] --> S1[Switch s1] CTRL --> S2[Switch s2] CTRL --> S3[Switch s3] S1 --- S2 S2 --- S3 S1 --- H1[Host h1\n10.0.0.1] S1 --- H2[Host h2\n10.0.0.2] S2 --- H3[Host h3\n10.0.0.3] S3 --- H4[Host h4\n10.0.0.4] end style CTRL fill:#1a1a2e,stroke:#00d4ff,color:#e0e0e0

Step-by-Step Process

01
Python API Topology

Define a custom topology in Python for repeatable lab setup.

# topo.py
from mininet.topo import Topo

class MyTopo(Topo):
    def build(self):
        s1 = self.addSwitch('s1')
        s2 = self.addSwitch('s2')
        h1 = self.addHost('h1', ip='10.0.0.1/24')
        h2 = self.addHost('h2', ip='10.0.0.2/24')
        h3 = self.addHost('h3', ip='10.0.0.3/24')
        self.addLink(h1, s1)
        self.addLink(h2, s1)
        self.addLink(h3, s2)
        self.addLink(s1, s2, bw=10)  # 10 Mbps link

topos = {'mytopo': MyTopo}
# Run: sudo mn --custom topo.py --topo mytopo
02
Test Bandwidth and Latency

Use iperf and ping inside Mininet to characterize network performance.

mininet> iperf                    # test h1-h2 bandwidth
mininet> iperf h1 h3               # specific pair
mininet> h1 ping -c5 -i0.1 h3     # latency test
mininet> pingFull                  # all-pairs with RTT
03
Programmatic Network Control

Control the network from Python — add flows, change routes at runtime.

from mininet.net import Mininet
from mininet.topo import SingleSwitchTopo

net = Mininet(topo=SingleSwitchTopo(4))
net.start()

# Run commands on hosts
result = net['h1'].cmd('ping -c1 10.0.0.2')
print(result)

# Test connectivity
net.pingAll()
net.stop()

Challenges & Solutions

  • Always run sudo mn -c before starting a new Mininet session — clears stale state
  • Link parameters only take effect with --link tc flag

Key Takeaways

  • bw parameter requires the tc tool installed: apt install iproute2
  • Mininet nodes are Linux processes with separate network namespaces