Teaching Computer
Networking with Mininet
Te-Yuan Huang, Vimalkumar Jeyakumar
Bob Lantz, Brian O'Connor
Nick Feamster
Keith Winstein, Anirudh Sivaraman
Wi-Fi: HHonors, SGC2014
Tutorial Goals
Learn how Mininet (and network emulation in
general) works, and how it can be used in
computer networking courses
Gain hands-on experience using Mininet for a
network lab exercise
Find out what we've learned from using Mininet
in on-campus courses and MOOCs
Tutorial Agenda
1. Introduction to Mininet
presentation, demos, short break
2. Hands-on Lab
presentation, lab, coffee break
3. Teaching with Mininet
presentations, discussion, done!
Teaching Computer
Networking with Mininet
Session 1: Introduction to Mininet
Bob Lantz
Open Networking Laboratory
Introduction to Mininet
Platforms for Network/Systems Teaching
Network Emulator Architecture
Mininet: Basic Usage, CLI, API
Example Demos: Network Security
Conclusion and Questions
Experiential Learning for Networking
"Learning by doing" is memorable and leads
to mastery.
In computer systems courses, this means
building, modifying, using, and experimenting
with working systems.
Networking (and distributed systems) courses
require complicated testbeds including multiple
servers and switches.
Platforms for Network/Systems
Teaching (and Research)
Platform Advantages Disadvantages
Hardware Testbed fast expensive
accurate: "ground truth" shared resource?
hard to reconfigure
hard to change
hard to download
Simulator inexpensive, flexible may require app changes
detailed (or abstract!) might not run OS code
easy to download detail != accuracy
virtual time (can be may not be "believable"
"faster" than reality) may be slow/non-interactive
Emulator inexpensive, flexible slower than hardware
real code experiments may not fit
reasonably accurate possible inaccuracy from
easy to download multiplexing
fast/interactive usage
Introduction to Mininet
Platforms for Network/Systems Teaching
Network Emulator Architecture
Mininet: Basic Usage, CLI, API
Example Demos: Network Security
Conclusion and Questions
To start with,
a Very Simple Network
firefox httpd
Host Switch Host
Very Simple Network using
Full System Virtualization
firefox httpd
cupsd bash cupsd bash
init init
Linux Kernel Linux Kernel
Host VM [Link] eth0 eth0 [Link] Host VM
tap0 tap1 ovs-vswitchd
Linux Kernel openvswitch kernel module
VM Server
Very Simple Network using
Lightweight Virtualization
firefox httpd
[Link] [Link]
Network Namespace 1 eth0 eth0 Network Namespace 2
veth1 veth2 ovs-vswitchd
Linux Kernel openvswitch kernel module
Server (or VM!)
Mechanism: Network Namespaces
and Virtual Ethernet Pairs
firefox httpd
[Link] [Link]
Network Namespace 1 eth0 eth0 Network Namespace 2
virtual Ethernet pairs
veth1 veth2
Software
Root Namespace Switch
Creating it with Linux
sudo bash
# Create host namespaces # Configure network
ip netns add h1 ip netns exec h1 ifconfig h1-eth0 10.1
ip netns add h2 ip netns exec h1 ifconfig lo up
# Create switch ip netns exec h2 ifconfig h2-eth0 10.2
ovs-vsctl add-br s1 ip netns exec h1 ifconfig lo up
# Create links ifconfig s1-eth1 up
ip link add h1-eth0 type veth peer name s1-eth1 ifconfig s1-eth2 up
ip link add h2-eth0 type veth peer name s1-eth2 # Test network
ip link show ip netns exec h1 ping -c1 10.2
# Move host ports into namespaces
ip link set h1-eth0 netns h1
ctrl’er
ip link set h2-eth0 netns h2
ip netns exec h1 ip link show
ip netns exec h2 ip link show
# Connect switch ports to OVS
s1
ovs-vsctl add-port s1 s1-eth1
ovs-vsctl add-port s1 s1-eth2
ovs-vsctl show
# Set up OpenFlow controller h2
h1
ovs-vsctl set-controller s1 tcp:[Link]
[Link] [Link]
ovs-controller ptcp: &
ovs-vsctl show
Wouldn’t it be great if...
We had a simple command-line tool and/or API
that did this for us automatically?
It allowed us to easily create topologies of
varying size, up to hundreds of nodes, and run
tests on them?
It was already included in Ubuntu?
Introduction to Mininet
Platforms for Network/Systems Teaching
Network Emulator Architecture
Mininet: Basic Usage, CLI, API
Example Demos: Network Security
Conclusion and Questions
Mininet command line tool and CLI
demo
# mn
# mn --topo tree,depth=3,fanout=3 --
link=tc,bw=10
mininet> xterm h1 h2
h1# wireshark &
h2# python -m SimpleHTTPServer 80 &
h1# firefox &
# mn --topo linear,100
# mn --custom [Link] --topo mytopo
Mininet's Python API
Core of Mininet!! Everything is built on it.
Python >> JSON/XML/etc.
Easy and (hopefully) fun
Python is used for orchestration, but emulation
is performed by compiled C code (Linux +
switches + apps)
[Link]
[Link]
Introduction to Mininet
Mininet API basics
net = Mininet() # net is a Mininet() object
h1 = [Link]( 'h1' ) # h1 is a Host() object
h2 = [Link]( 'h2' ) # h2 is a Host()
s1 = [Link]( 's1' ) # s1 is a Switch() object
c0 = [Link]( 'c0' ) # c0 is a Controller()
[Link]( h1, s1 ) # creates a Link() object
[Link]( h2, s1 )
[Link]() c0
[Link]( 'python -m SimpleHTTPServer 80 &' )
sleep( 2 )
s1
[Link]( 'curl', [Link]() )
CLI( net )
[Link]('kill %python')
h1 h2
[Link]()
[Link] [Link]
Performance modeling in Mininet
# Use performance-modeling link and host classes
net = Mininet(link=TCLink, host=CPULimitedHost)
# Limit link bandwidth and add delay
[Link](h2, s1, bw=10, delay='50ms') controller
# Limit CPU bandwidth
[Link]('h1', cpu=.2)
s1
10
M
bp
s,
50
m
s
h1 h2
[Link] [Link]
20% of CPU
Low-level API: Nodes and Links
h1 = Host( 'h1' )
h2 = Host( 'h2' )
s1 = OVSSwitch( 's1', inNamespace=False )
c0 = Controller( 'c0', inNamespace=False )
Link( h1, s1 )
Link( h2, s1 )
[Link]( '10.1/8' )
[Link]( '10.2/8' )
[Link]()
[Link]( [ c0 ] )
print [Link]( 'ping -c1', [Link]() )
[Link]()
[Link]()
Mid-level API: Network object
net = Mininet()
h1 = [Link]( 'h1' )
h2 = [Link]( 'h2' )
s1 = [Link]( 's1' )
c0 = [Link]( 'c0' )
[Link]( h1, s1 )
[Link]( h2, s1 )
[Link]()
print [Link]( 'ping -c1', [Link]() )
CLI( net )
[Link]()
High-level API: Topology templates
class SingleSwitchTopo( Topo ):
"Single Switch Topology"
def build( self, count=1):
hosts = [ [Link]( 'h%d' % i )
for i in range( 1, count + 1 ) ]
s1 = [Link]( 's1' )
for h in hosts:
[Link]( h, s1 )
net = Mininet( topo=SingleSwitchTopo( 3 ) )
[Link]()
CLI( net )
[Link]()
more examples and info available at [Link]
Custom Topology Files
# cat [Link]
from [Link] import Topo
class SingleSwitchTopo( Topo ):
"Single Switch Topology"
def build( self, count=1):
hosts = [ [Link]( 'h%d' % i )
for i in range( 1, count + 1 ) ]
s1 = [Link]( 's1' )
for h in hosts:
[Link]( h, s1 )
topos = { 'mytopo': SingleSwitchTopo }
# mn --custom [Link] --topo mytopo,3
*** Creating network
*** Adding controller
*** Adding hosts:
h1 h2 h3
Introduction to Mininet
Platforms for Network/Systems Teaching
Network Emulator Architecture
Mininet: Basic Usage, CLI, API
Example Demos: Network Security
Conclusion and Questions
Security Demo #1: DHCP Attack
internet
dhcp
slow link [Link]
h1
[Link] (good DHCP
Switch (500 ms delay)
(client/ server)
victim)
evil
[Link]
(malicious
DHCP+DNS+
WWW server)
Security Demo #2: BGP
More Demos!
MiniEdit
[Link]
Cluster prototype
Introduction to Mininet
Platforms for Network/Systems Teaching
Network Emulator Architecture
Mininet: Basic Usage, CLI, API
Example Demos: Network Security
Conclusion and Questions
Conclusion and Questions
Network Emulators can facilitate teaching networking via realistic live
demos, interactive labs and course assignments
- inexpensive, interactive, real apps and OS, reasonably accurate
- downloadable, fast setup
Mininet is a lightweight virtualization/container based emulator
- modest hardware requirements, fast startup, hundreds of nodes
- command line tool, CLI, simple Python API
- SDN as well as Ethernet/IP networking as well as SD
- install using VM, Ubuntu package, or source
[Link]: Tutorials, walkthroughs, API documentation and examples
[Link]: Mininet-based course assignments and labs
open source: hosted on github, permissive BSD license
Next up: short break, then hands-on lab!
Tutorial Agenda
1. Introduction to Mininet
presentation, demos, short break
2. Hands-on Lab
presentation, lab, coffee break
3. Teaching with Mininet
presentations, discussion, done!
Backup/Supplementary
Slides
Mininet is a Network Emulator
In this talk, emulation (or running on an
emulator) means running unmodified code
interactively on virtual hardware on a regular
PC, providing convenience and realism at low
cost – with some limitations (e.g. speed, detail.)
This is in contrast to running on a hardware
testbed (fast, accurate, expensive/shared) or a
simulator (cheap, detailed, but perhaps slow
and requiring code modifications.)
Context: Platforms for Network
Experimentation and Development
Container-based emulators: CORE, virtual
Emulab, Trellis, Imunes, even ns-3 (in
emulation mode), Mininet
VM-based emulators: DieCast
UML-based emulators: NetKit
Simulators: ns-3, OPNET
Testbeds: Emulab, GENI, PlanetLab, ORBIT
All of these are fine, but we think Emulators are
particularly useful! Why? Because...
Apps move seamlessly to/from hardware
SDN App
SDN App
Controller Controller
App
App
Switch Switch Host
Host
# mn
> h1 ping h2
Switch
Host
Emulated Network Hardware Network
Appendix: Mininet
Subclassing for Fun and
Profit
Bob Lantz, Brian O'Connor
Classes in Mininet
Example
class Host( Node ):
"A host is simply a Node"
pass
What do you want to customize?
class Node( object ):
def config( self, mac=None, ip=None,
defaultRoute=None, lo='up', **_params ):
# If we were overriding this method, we would call
# the superclass config method here as follows:
# r = [Link]( **_params )
r = {}
[Link]( r, 'setMAC', mac=mac )
[Link]( r, 'setIP', ip=ip )
[Link]( r, 'setDefaultRoute', defaultRoute=defaultRoute )
[Link]( 'ifconfig lo ' + lo )
return r
Customizing Host()
class VLANHost( Host ):
def config( self, vlan=100, **params ):
"""Configure VLANHost according to (optional) parameters:
vlan: VLAN ID for default interface"""
r = super( Host, self ).config( **params )
intf = [Link]()
[Link]( 'ifconfig %s inet 0' % intf ) # remove IP from default, "physical" interface
[Link]( 'vconfig add %s %d' % ( intf, vlan ) ) # create VLAN interface
[Link]( 'ifconfig %s.%d inet %s' % ( intf, vlan, params['ip'] ) ) # assign the host's IP to
the VLAN interface
# to maintain CLI compatibility
newName = '%s.%d' % ( intf, vlan ) # update the intf name and host's intf map
[Link] = newName # update the (Mininet) interface to refer to VLAN interface name
[Link][ newName ] = intf # add VLAN interface to host's name to intf map
return r
hosts = { 'vlan': VLANHost }
Using Custom Hosts
In Python:
def run( vlan ):
# vlan (type: int): VLAN ID to be used by all hosts
host = partial( VLANHost, vlan=vlan )
# Start a basic network using our VLANHost
topo = SingleSwitchTopo( k=2 )
net = Mininet( host=host, topo=topo )
[Link]()
CLI( net )
[Link]()
From the CLI:
sudo mn --custom [Link] --host vlan,vlan=1000
Customizing Switch()
class LinuxBridge( Switch ):
"Linux Bridge"
prio = 0
def __init__( self, name, stp=True, **kwargs ):
[Link] = stp
Switch.__init__( self, name, **kwargs ) # BL doesn’t care about multiple inheritance
def start( self, controllers ):
[Link]( 'ifconfig', self, 'down' )
[Link]( 'brctl delbr', self )
[Link]( 'brctl addbr', self )
if [Link]:
[Link]( 'brctl setbridgeprio', [Link] )
[Link]( 'brctl stp', self, 'on' )
[Link] += 1
for i in [Link]():
if [Link] in [Link]:
[Link]( 'brctl addif', self, i )
[Link]( 'ifconfig', self, 'up' )
def stop( self ):
[Link]( 'ifconfig', self, 'down' )
[Link]( 'brctl delbr', self )
switches = { 'lxbr': LinuxBridge }
Customizing Switch()
demo
openflow@ubuntu13:~$ sudo mn --custom [Link] --switch lxbr --topo torus,3,3
mininet> sh brctl showstp s0x0
…
Customizing Switch()
c0 = Controller( 'c0', port=6633 )
c1 = Controller( 'c1', port=6634 )
c2 = RemoteController( 'c2', ip='[Link]' )
cmap = { 's1': c0, 's2': c1, 's3': c2 }
class MultiSwitch( OVSSwitch ):
"Custom Switch() subclass that connects to different controllers"
def start( self, controllers ):
return [Link]( self, [ cmap[ [Link] ] ] )
topo = TreeTopo( depth=2, fanout=2 )
net = Mininet( topo=topo, switch=MultiSwitch )
for c in [ c0, c1 ]:
[Link](c)
[Link]()
CLI( net )
[Link]()
DEMO: [Link]
Customizing Controller()
from [Link] import Controller
from os import environ
POXDIR = environ[ 'HOME' ] + '/pox'
class POX( Controller ):
def __init__( self, name, cdir=POXDIR,
command='python [Link]',
cargs=( 'openflow.of_01 --port=%s '
'forwarding.l2_learning' ),
**kwargs ):
Controller.__init__( self, name, cdir=cdir, command=command, cargs=cargs, **kwargs )
controllers={ 'pox': POX }
Customizing Controller()
from [Link] import Controller
from os import environ
from functools import partial
POXDIR = environ[ 'HOME' ] + '/pox'
POX = partial( Controller, cdir=POXDIR,
command='python [Link]',
cargs=( 'openflow.of_01 --port=%s '
'forwarding.l2_learning' ) )
controllers = { 'pox': POX }