تخطَّ إلى المحتوى

Mininet Cheat Sheet

Overview

Mininet is a network emulation platform that creates a realistic virtual network running real kernel, switch, and application code on a single Linux machine. It uses lightweight OS virtualization (Linux network namespaces) to create hosts, Open vSwitch for software switches, and virtual ethernet pairs for links, enabling networks of hundreds of nodes to run on a laptop. Mininet networks run real code including standard Unix network applications, making it ideal for developing, testing, and teaching Software-Defined Networking (SDN).

Mininet is the de facto standard for SDN research and education, providing a Python API for programmatic network creation alongside a command-line interface for interactive experimentation. Networks created in Mininet can be seamlessly migrated to real hardware since they use the same OpenFlow-compatible switches and standard protocols. It supports custom topologies, bandwidth limitations, link delays, and loss simulation, making it suitable for performance testing and protocol validation before deployment.

Installation

Ubuntu/Debian (Native)

# From package manager
sudo apt update
sudo apt install mininet

# Verify installation
sudo mn --test pingall

From Source (Latest)

git clone https://github.com/mininet/mininet.git
cd mininet
git checkout -b mininet-2.3.1 2.3.1

# Full install (Mininet + Open vSwitch + OpenFlow tools)
sudo util/install.sh -a

# Minimal install (Mininet + Open vSwitch only)
sudo util/install.sh -nfv

# Install with specific components
sudo util/install.sh -n   # Mininet core
sudo util/install.sh -f   # OpenFlow reference
sudo util/install.sh -v   # Open vSwitch
sudo util/install.sh -w   # Wireshark with OpenFlow dissector

VM Image

# Download pre-built VM from mininet.org
# Import into VirtualBox/VMware
# Default credentials: mininet/mininet

Basic Usage

Command-Line Quick Start

# Start minimal topology (1 switch, 2 hosts)
sudo mn

# Start with specific topology
sudo mn --topo single,4          # 1 switch, 4 hosts
sudo mn --topo linear,3          # 3 switches in a line
sudo mn --topo tree,depth=2,fanout=3  # Tree topology

# Specify controller
sudo mn --controller=remote,ip=127.0.0.1,port=6653
sudo mn --controller=ovsc        # OVS controller
sudo mn --controller=none        # No controller

# Specify switch type
sudo mn --switch ovsk             # Open vSwitch kernel mode
sudo mn --switch ovs              # Open vSwitch user mode
sudo mn --switch ovsbr            # OVS bridge mode

# Run built-in tests
sudo mn --test pingall
sudo mn --test iperf
sudo mn --test pingpair

Mininet CLI Commands

CommandDescription
helpList available commands
nodesList all nodes
netShow network topology
linksShow all links
dumpShow node details (IPs, interfaces)
pingallTest connectivity between all hosts
pingpairPing between first two hosts
h1 ping h2Ping from h1 to h2
h1 ifconfigRun ifconfig on host h1
iperf h1 h2TCP bandwidth test
iperfudp 10M h1 h2UDP bandwidth test at 10 Mbps
xterm h1Open terminal for host h1
link s1 h1 downBring down link between s1 and h1
link s1 h1 upBring up link
dpctl dump-flowsShow OpenFlow flow table
sh <command>Run shell command on root namespace
exit / quitExit Mininet

Running Commands on Hosts

# Execute command on specific host
mininet> h1 ping -c 3 10.0.0.2
mininet> h1 python3 -m http.server 80 &
mininet> h2 curl h1
mininet> h1 arp -a
mininet> h1 route -n
mininet> h1 iptables -L

Python API

Basic Topology Script

#!/usr/bin/env python3
from mininet.net import Mininet
from mininet.topo import Topo
from mininet.cli import CLI
from mininet.log import setLogLevel

class SimpleTopo(Topo):
    def build(self):
        # Add hosts
        h1 = self.addHost('h1', ip='10.0.1.1/24')
        h2 = self.addHost('h2', ip='10.0.1.2/24')
        h3 = self.addHost('h3', ip='10.0.2.1/24')

        # Add switches
        s1 = self.addSwitch('s1')
        s2 = self.addSwitch('s2')

        # Add links
        self.addLink(h1, s1)
        self.addLink(h2, s1)
        self.addLink(h3, s2)
        self.addLink(s1, s2)

if __name__ == '__main__':
    setLogLevel('info')
    topo = SimpleTopo()
    net = Mininet(topo=topo)
    net.start()
    CLI(net)
    net.stop()
from mininet.link import TCLink

# Add link with bandwidth, delay, loss
self.addLink(h1, s1, cls=TCLink,
             bw=10,          # 10 Mbps bandwidth
             delay='5ms',    # 5ms delay
             loss=1,         # 1% packet loss
             max_queue_size=1000)

# Asymmetric link parameters
self.addLink(h1, s1, cls=TCLink,
             bw=100, delay='2ms',
             params2={'bw': 50, 'delay': '10ms'})

Remote Controller

from mininet.node import RemoteController

net = Mininet(topo=topo,
              controller=lambda name: RemoteController(
                  name, ip='127.0.0.1', port=6653))
net.start()

Custom Topology with Multiple Subnets

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

class DataCenterTopo(Topo):
    def build(self, k=4):
        # Fat-tree topology with k pods
        core_switches = []
        agg_switches = []
        edge_switches = []

        # Core switches
        for i in range((k // 2) ** 2):
            core = self.addSwitch(f'cs{i+1}')
            core_switches.append(core)

        # Pod switches and hosts
        for pod in range(k):
            agg = []
            for i in range(k // 2):
                a = self.addSwitch(f'as{pod}_{i}')
                agg.append(a)
                agg_switches.append(a)

            for i in range(k // 2):
                e = self.addSwitch(f'es{pod}_{i}')
                edge_switches.append(e)
                for j in range(k // 2):
                    host = self.addHost(f'h{pod}_{i}_{j}',
                        ip=f'10.{pod}.{i}.{j+1}/24')
                    self.addLink(host, e)
                for a in agg:
                    self.addLink(e, a)

        # Connect aggregation to core
        for i, a in enumerate(agg_switches):
            pod_idx = i // (k // 2)
            for c in core_switches[pod_idx::k]:
                self.addLink(a, c)

if __name__ == '__main__':
    setLogLevel('info')
    topo = DataCenterTopo(k=4)
    net = Mininet(topo=topo, switch=OVSSwitch)
    net.start()
    CLI(net)
    net.stop()

Open vSwitch Integration

# In Mininet CLI
mininet> dpctl dump-flows
mininet> sh ovs-vsctl show
mininet> sh ovs-ofctl dump-flows s1
mininet> sh ovs-ofctl dump-ports s1

# Add manual flow rules
mininet> sh ovs-ofctl add-flow s1 "in_port=1,actions=output:2"
mininet> sh ovs-ofctl add-flow s1 "dl_type=0x0800,nw_dst=10.0.0.2,actions=output:2"

# Delete flows
mininet> sh ovs-ofctl del-flows s1

Advanced Usage

Performance Testing

# Automated performance test
from mininet.net import Mininet
from mininet.topo import SingleSwitchTopo
from mininet.link import TCLink

topo = SingleSwitchTopo(n=2)
net = Mininet(topo=topo, link=TCLink)
net.start()

h1, h2 = net.get('h1', 'h2')

# Start iperf server
h2.cmd('iperf -s &')

# Run iperf client
result = h1.cmd('iperf -c %s -t 10' % h2.IP())
print(result)

net.stop()

Network Monitoring

# Capture traffic on a link
mininet> h1 tcpdump -i h1-eth0 -w /tmp/h1_capture.pcap &

# Monitor bandwidth usage
mininet> sh bwm-ng -o plain -I s1-eth1

# Watch OpenFlow messages
mininet> sh ovs-ofctl snoop s1

Cluster Mode (Multiple Machines)

from mininet.examples.cluster import MininetCluster

# Distribute nodes across servers
servers = ['server1', 'server2']
net = MininetCluster(topo=topo, servers=servers)
net.start()

Configuration

Mininet Custom Configuration File

# mn_custom.py - custom topology for --custom flag
from mininet.topo import Topo

class MyTopo(Topo):
    def build(self):
        s1 = self.addSwitch('s1')
        for i in range(1, 5):
            h = self.addHost(f'h{i}')
            self.addLink(h, s1, bw=100, delay='1ms')

topos = {'mytopo': MyTopo}
# Use custom topology
sudo mn --custom mn_custom.py --topo mytopo

Logging Configuration

from mininet.log import setLogLevel, info, debug, warning, error

setLogLevel('debug')    # debug, info, warning, error, critical, output
info('Network starting\n')
debug('Detailed information\n')

Troubleshooting

IssueSolution
”Error creating interface pair”Run sudo mn -c to clean up
Hosts can’t ping each otherCheck controller is running, verify flows
Open vSwitch not startingsudo service openvswitch-switch restart
Mininet crash leaves state behindsudo mn -c cleans up all state
Cannot start xtermInstall xterm, set DISPLAY, use X forwarding
Remote controller unreachableVerify IP/port, check firewall rules
Bandwidth limiting not workingUse --link tc or cls=TCLink in Python
Permission deniedMininet requires root: use sudo

Cleanup

# Clean up Mininet state (run after crashes)
sudo mn -c

# Manual cleanup
sudo killall -9 ovs-controller controller
sudo ovs-vsctl --if-exists del-br s1
sudo ip link del s1-eth1 2>/dev/null

Useful Diagnostic Commands

# Check OVS status
sudo ovs-vsctl show
sudo ovs-vsctl list-br

# Verify OpenFlow version
sudo ovs-ofctl -O OpenFlow13 dump-flows s1

# Check network namespaces
sudo ip netns list
sudo ip netns exec h1 ip addr