Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@lantz
lantz / order.py
Last active July 1, 2019 23:40
Simple sanity test for Mininet host ordering
#!/usr/bin/env python3
"""
Mininet host order sanity test
We make sure that net.topo.hosts(sorted=False)
returns hosts in the order they were added.
We also make sure that net.hosts is in canonical
order, which should also be different from repr()
@lantz
lantz / ovs-stp.py
Last active December 30, 2023 14:26
(Evil) Spanning Tree Protocol (STP) using Open vSwitch
#!/usr/bin/python
"""
OVS Bridge with Spanning Tree Protocol
Note: STP bridges don't start forwarding until
after STP has converged, which can take a while!
See below for a command to wait until STP is up.
Example:
@lantz
lantz / prefix.py
Last active December 27, 2015 07:09
In Mininet (up to 2.1.0 at least) you cannot have multiple Mininet instances running without running into namespace conflicts for the nodes and port conflicts for local controllers. This example demonstrates an easy way to specify a unique prefix for the nodes and a unique port for the controller, thus allowing multiple Mininet instances to coex…
#!/usr/bin/python
"""
Example of adding a node prefix to avoid namespace conflicts
(and changing the controller port to avoid port conflicts.)
If we use UserSwitch, then we can run in a Mininet host (!)
"""
from mininet.net import Mininet
@lantz
lantz / addhost.py
Created September 12, 2013 20:38
Simple example of adding a host to a Mininet network after calling `net.start()`; should work in Mininet 2.1.0.
#!/usr/bin/python
from mininet.net import Mininet
from mininet.topo import SingleSwitchTopo
net = Mininet( topo=SingleSwitchTopo( 2 ) )
net.start()
net.pingAll()
print "*** Attaching new host h3 to s1"
h3 = net.addHost( 'h3' )
s1 = net[ 's1' ]
link = net.addLink( h3, s1 )
@lantz
lantz / gist:5640610
Last active August 12, 2019 14:04
Script to set up NAT with Mininet
#!/usr/bin/python
"""
Example to create a Mininet topology and connect it to the internet via NAT
through eth0 on the host.
Glen Gibb, February 2011
(slight modifications by BL, 5/13)
"""