Mininet Tutorial
Mininet Tutorial
Mininet Tutorial
James Won-Ki Hong
Department of Computer Science and Engineering
POSTECH, Korea
[email protected]
CSED702Y: Software Defined Networking
POSTECH
1/24
Outline
Introduction
Motivation
Installation
Mininet Tutorial
Command line interface usage
Application programming interface usage
Demo
Demo scenarios
Demo presentation
Experiences on Mininet
2/24
Advantages
Disadvantages
Hardware testbed
Fast
Accurate: ground truth
Expensive
Hard to reconfigure
Hard to change
Hard to download
Simulator
Inexpensive, flexible
Detailed
Easy to download
Virtual time
Emulator
Inexpensive, flexible
Real code
Reasonably accurate
Easy to download
Fast/interactive usage
3/24
h1 (10.0.0.1)
s1
h2 (10.0.0.2)
4/24
h1 (10.0.0.1)
s1
sudo bash
# Create host namespaces
ip netns add h1
ip netns add h2
# Create switch
ovs-vsctl add-br s1
# Create links
ip link add h1-eth0 type veth peer name s1-eth1
ip link add h2-eth0 type veth peer name s1-eth2
ip link show
# Move host ports into namespaces
ip link set h1-eth0 netns h1
ip link set h2-eth0 netns h2
ip netns exec h1 ip link show
ip netns exec h2 ip link show
h2 (10.0.0.2)
# Connect switch ports to OVS
ovs-vsctl add-port s1 s1-eth1
ovs-vsctl add-port s1 s1-eth2
ovs-vsctl show
# Set up OpenFlow controller
ovs-vsctl set-controller s1 tcp:127.0.0.1
ovs-controller ptcp: &
ovs-vsctl show
# Configure network
ip netns exec h1 ifconfig h1-eth0 10.1
ip netns exec h1 ifconfig lo up
ip netns exec h2 ifconfig h2-eth0 10.2
ip netns exec h1 ifconfig lo up
ifconfig s1-eth1 up
ifconfig s1-eth2 up
# Test network
ip netns exec h1 ping -c1 10.2
5/24
h1 (10.0.0.1)
s1
h2 (10.0.0.2)
h1 = net.addHost( 'h1' )
h2 = net.addHost( 'h2' )
s1 = net.addSwitch( 's1' )
c0 = net.addController( 'c0' )
net.addLink( h1, s1 )
net.addLink( h2, s1 )
net.start()
CLI( net )
6/24
Introduction to Mininet
Mininet
A network emulator which creates realistic virtual network
Runs real kernel, switch and application code on a single machine
Abstraction
Host: emulated as an OS level process
Switch: emulated by using software-based switch
E.g., Open vSwitch, SoftSwitch
7/24
8/24
Ubuntu 12.10
Ubuntu 12.04
9/24
Display
nodesnodes
mininet>
mininet>
Display
links net
mininet> dump
10/24
11/24
Link variations
$ sudo mn -link
tc,bw=[bandwidth],delay=[delay_in_millisecond]
Python Interpreter
$ accessible
py locals()
Print
local variables
$ py [mininet_name_space].[method]
Execute
a method through invoking mininet API
12/24
mininet.link.Link
A basic link, which is represented as a pair of nodes
Class
Method
Description
Node
Link
MAC/setMA
C
IP/setIP
cmd
terminate
Link
h1 = Host( 'h1' )
h2 = Host( 'h2' )
s1 = OVSSwitch( 's1', inNamespace=False )
c0 = Controller( 'c0', inNamespace=False )
Link( h1, s1 )
Link( h2, s1 )
h1.setIP( '10.1/8' )
h2.setIP( '10.2/8' )
c0.start()
s1.start( [ c0 ] )
print h1.cmd( 'ping -c1', h2.IP() )
s1.stop()
c0.stop()
13/24
Class
Net
Method
Description
addHost
addSwitch
addLink
addController
getNodeByName
start
stop
ping
net = Mininet()
h1 = net.addHost( 'h1' )
h2 = net.addHost( 'h2' )
s1 = net.addSwitch( 's1' )
c0 = net.addController( 'c0' )
net.addLink( h1, s1 )
net.addLink( h2, s1 )
net.start()
print h1.cmd( 'ping -c1', h2.IP() )
CLI( net )
net.stop()
14/24
Class
Topo
Method
Description
addNode
addPort
switches
Hosts/nodes/switches/links
isSwitch
15/24
LEN_DPID = 16
from mininet.topo import Topo
class MyTopo( Topo ):
def name_dpid( self, index ):
dpid = '%02d' % ( index )
zeros = '0' * ( LEN_DPID - len( dpid ) )
name = 's%02d' % ( index )
return { 'name':name, 'dpid':zeros + dpid }
def build( self, count=1):
hosts = [ self.addHost( 'h%d' % i )
for i in range( 1, count + 1 ) ]
s1 = self.addSwitch( **self.name_dpid(1) )
for h in hosts:
self.addLink( h, s1 )
topos = { 'mytopo': MyTopo }
# mn --custom custom.py --topo mytopo,3
*** Creating network
*** Adding controller
*** Adding hosts:
More examples can be found here:
h1 h2 h3
https://github.com/mininet/mininet/tree/master/examples
16/24
Mininet Applications
MiniEdit
A GUI application which eases the Mininet topology generation
Either save the topology or export as a Mininet python script
17/24
DST
ACT
h1
h2
p1
OpenFlow
Controller
acquire
route
SRC
DST
ACT
h1
h2
p1
insert
flow
host1
switch1 (reactive)
switch2 (proactive)
host2
18/24
DEMO Scenarios
Construct a Customized Topology Using Mininet
A topology with two hosts and five switches
Scenario
Setup the flow in reactive manner
Ping from host1 to host2 in reactive manner
Ping from all hosts to the other hosts
1
0
switch2
switch3
host1
Route #1
1
switch
5
switch4
switch1
1
host
2
Route #2
19/24
Testbed
RESTRESTbased
based
Jython
App
Java App
App
App
Static
Static
Flow
Flow
Pushe
Pushe
rr
Not standardized
yet, use proprietary
APIs
Northbound API
Floodlight Controller
Southbound API
OVS
Switch
Host
Host
OVS
Switch
Host
Host
Host
OVS
Switch
Host
OVS
Switch
OVS
Switch
Host
Host
Host
Implement
OpenFlow
Protocol
Host
mininet
20/24
Floodlight Installation
Native Installation from Source
Recommended OS: any version of Linux distribution
Procedures
Install pre-requisite software packages
$ sudo apt-get install openjdk-7-jdk
$ sudo apt-get install ant
Ubuntu
EPEL
Download
from
github and build the stable version
$ gitsource
clone
git://github.com/floodlight/floodlight.git
$ cd floodlight
$ ant
Run #
the./floodlight.sh
floodlight
21/24
Initiate
a ICMP
request
from host1
mininet>
h1 ping
h2
Initiate
ICMP
requests from all hosts
mininet>
pingall
22/24
At MIT
Design a transport protocol to achieve high throughput and low del
ay on cellular links
Baseline protocol: Sprout (NSDI 2013)
Competition between students, and two student protocols were co
Protocol Design Contests: Anirudh Sivaraman, Keith Winstein, Pauline Varley, Joao
mparable
with Sprout
Batalha, Ameesh Goyal, Somak Das, Joshua Ma, and Hari Balakrishnan, CCR July 2014
23/24
Q&A
24/24