An Intro To Mininet: TELE4642: Week5

Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

An intro to Mininet

TELE4642: Week5
Types of Network Testbeds
n Platforms for Network/Systems Teaching

Platform Advantages Disadvantages


Hardware § Fast § Expensive
testbed § Accurate § Hard to reconfigure
§ Hard to change
§ Hard to download
Simulator § Inexpensive, flexible § May require app changes
§ Detailed § Might not run OS code
§ Easy to download § May not be “believable”
§ Virtual time § May be slow/non-interactive
Emulator § Inexpensive, flexible § Slower than hardware
§ Real code § Possible inaccuracy from
§ Reasonably accurate multiplexing
§ Easy to download
§ Fast/interactive usage

Network Performance 5-2


Hardware based Network Testbed (1/2)
n Very Simple Network using Full System Virtualization

h1 (10.0.0.1) s1 h2 (10.0.0.2)

Network Performance 5-3


Hardware based Network Testbed (2/2)
n Problems
q Too much work even for creating such a simple network topology
q Not programmable / Not scalable

h1 (10.0.0.1) s1 h2 (10.0.0.2)
sudo bash # Connect switch ports to OVS
# Create host namespaces ovs-vsctl add-port s1 s1-eth1
ip netns add h1 ovs-vsctl add-port s1 s1-eth2
ip netns add h2 ovs-vsctl show
# Create switch # Set up OpenFlow controller
ovs-vsctl add-br s1 ovs-vsctl set-controller s1 tcp:127.0.0.1
# Create links ovs-controller ptcp: &
ip link add h1-eth0 type veth peer name s1-eth1 ovs-vsctl show
ip link add h2-eth0 type veth peer name s1-eth2 # Configure network
ip link show ip netns exec h1 ifconfig h1-eth0 10.1
# Move host ports into namespaces ip netns exec h1 ifconfig lo up
ip link set h1-eth0 netns h1 ip netns exec h2 ifconfig h2-eth0 10.2
ip link set h2-eth0 netns h2 ip netns exec h1 ifconfig lo up
ip netns exec h1 ip link show ifconfig s1-eth1 up
ip netns exec h2 ip link show ifconfig s1-eth2 up
# Test network
ip netns exec h1 ping -c1 10.2

Network Performance 5-4


Emulator based Network Testbed
n What We Want is
q A simple command-line tool / API which can ease the work
q The solution should allow us to easily create topologies for
varying size, up to hundreds and thousand of nodes

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 )

Topology Generation using Mininet API

Network Performance 5-5


Introduction to Mininet
n Mininet
q A network emulator which creates realistic virtual network
q Runs real kernel, switch and application code on a single machine

q Provides both Command Line Interface (CLI) and Application


Programming Interface (API)
n CLI: interactive commanding
n API: automation

q Many OpenFlow features are built-in


q

q Abstraction
n Host: emulated as an OS level process
n Switch: emulated by using software-based switch
q E.g., Open vSwitch, SoftSwitch

Network Performance 5-6


Mininet Installation (1/2)
n Mininet VM Installation
q The easiest and most fool-proof way of installing Mininet
q Procedures
n Download the Mininet pre-installed VM image
n Download and install one of the hypervisors (e.g., VirtualBox, Qemu,
VMware Workstation, VMware Fusion, or KVM)
n Import VM image into selected hypervisor
n Native Installation from Source
q Recommended OS: Ubuntu 11.10 and later
q Procedures
n Download source from github
$ git clone git://github.com/mininet/mininet
n Full installation: Mininet + Open vSwtich + wireshark + etc.
$ mininet/util/install.sh -a
n Minimum installation: + Mininet + Open vSwitch
$ mininet/util/install.sh -fnv

Network Performance 5-7


Mininet Installation (2/2)
n Native Installation from Package
q Recommended OS: Ubuntu 12.04 and later
q Procedures
n Remove all previously installed Mininet and Open vSwitch
$ sudo rm -rf /usr/local/bin/mn /usr/local/bin/mnexec \
/usr/local/lib/python*/*/*mininet* \
/usr/local/bin/ovs-* /usr/local/sbin/ovs-*
n Install Mininet package according to your Ubuntu version (choose one of them!)
$ sudo apt-get install mininet Ubuntu 13.04
$ sudo apt-get install mininet/quantal-backports Ubuntu 12.10
$ sudo apt-get install mininet/precise-backports Ubuntu 12.04
n Deactive OpenvSwitch controller if it is running
$ sudo service openvswitch-controller stop
$ sudo update-rc.d openvswitch-controller disable

n You can also install additional software from mininet source

$ git clone git://github.com/mininet/mininet


$ mininet/util/install.sh -fw

Network Performance 5-8


Mininet Tutorial (1/7)
n Mininet Command Line Interface Usage
q Interact with hosts and switches
n Start a minimal topology
$ sudo mn

n Start a minimal topology using a remote controller

$ sudo mn --controller=remote,ip=[IP_ADDDR],port=[listening port]


n Start a custom topology
$ sudo mn --custom [topo_script_path] --topo=[topo_name]
n Display nodes
mininet> nodes

n Display links
mininet> net

n Dump information about all nodes


mininet> dump

Network Performance 5-9


Mininet Tutorial (2/7)

n Mininet Command Line Interface Usage


q Interact with hosts and switches
n Check the IP address of a certain node
mininet> h1 ifconfig -a
n Print the process list from a host process
mininet> h1 ps -a

q Test connectivity between hosts


n Verify the connectivity by pinging from host1 to host2
mininet> h1 ping -c 1 h2

n Verify the connectivity between all hosts


mininet> pingall

Network Performance 5-10


Mininet Tutorial (3/7)
n Mininet Command Line Interface Usage
q Run a regression test
n Traffic receive preparation

mininet> iperf -s -u -p [port_num] &


n Traffic generation from client

mininet> iperf -c [IP] -u -t [duration] -b [bandwidth] -p [port_num] &

q Link variations
$ sudo mn -link tc,bw=[bandwidth],delay=[delay_in_millisecond]

q Python Interpreter
n Print accessible local variables

$ py locals()
n Execute a method through invoking mininet API
$ py [mininet_name_space].[method]

Network Performance 5-11


Mininet Tutorial (4/7)
n Mininet Application Programming Interface Usage
q Low-level API: nodes and links
n mininet.node.Node
q A virtual network node, which is a simply in a network namespace
n mininet.link.Link
q A basic link, which is represented as a pair of nodes

Class Method Description


MAC/setMAC Return/Assign MAC address of a node or specific interface
IP/setIP Return/Assign IP address of a node or specific interface
Node
cmd Send a command, wait for output, and return it
terminate Send kill signal to Node and clean up after it
Link Link Create a link to another node, make two new interfaces

h1 = Host( 'h1' ) c0.start()


h2 = Host( 'h2' ) s1.start( [ c0 ] )
s1 = OVSSwitch( 's1', inNamespace=False ) print h1.cmd( 'ping -c1', h2.IP() )
c0 = Controller( 'c0', inNamespace=False ) s1.stop()
Link( h1, s1 ) c0.stop()
Link( h2, s1 )
h1.setIP( '10.1/8' )
h2.setIP( '10.2/8' )

Network Performance 5-12


Mininet Tutorial (5/7)
n Mininet Application Programming Interface Usage
q Middle-level API: network object
n mininet.net.Mininet
q Network emulation with hosts spawned in network namespaces

Class Method Description


addHost Add a host to network
addSwitch Add a switch to network
addLink Link two nodes into together
addController Add a controller to network
Net
getNodeByName Return node(s) with given name(s)
main class to
create and start Start controller and switches
manage a
stop Stop the controller, switches and hosts
network
ping Ping between all specified hosts and return all data

net = Mininet() net.start()


h1 = net.addHost( 'h1' ) print h1.cmd( 'ping -c1', h2.IP() )
h2 = net.addHost( 'h2' ) net.stop()
s1 = net.addSwitch( 's1' )
c0 = net.addController( 'c0' )
net.addLink( h1, s1 )
net.addLink( h2, s1 )

Network Performance 5-13


Mininet Tutorial (6/7)
n Mininet Application Programming Interface Usage
q High-level API: topology templates
n mininet.topo.Topo
q Data center network representation for structured multi-trees
Class Method Description
Methods similar to net E.g., addHost, addSwitch, addLink,
addNode Add node to graph
addPort Generate port mapping for new edge
Topo
switches Return all switches
Hosts/nodes/switches/links Return all hosts
isSwitch Return true if node is a switch, return false otherwise

class SingleSwitchTopo( Topo ): net = Mininet( topo=SingleSwitchTopo( 3 ) )


"Single Switch Topology" net.start()
def build( self, count=1): CLI( net )
hosts = [ self.addHost( 'h%d' % i ) net.stop()
for i in range( 1, count + 1 ) ]
s1 = self.addSwitch( 's1' )
for h in hosts:
self.addLink( h, s1 )

Network Performance 5-14


Mininet Tutorial (7/7)

n Parametrised custom topologies


q With a few lines of Python code
q Can create a flexible topology which can be
configured based on the parameters you pass
into it, and reused for multiple experiments.

Network Performance 5-15


example
the base class for Mininet topologies

setLogLevel( 'info' | 'debug' |


'output' ):

set Mininet's default output level; 'info' is


recommended as it provides useful information.

Network Performance 5-16


Performance parameters?

n In addition to basic behavioral networking,


Mininet provides performance limiting and
isolation features, through the
CPULimitedHost and TCLink classes.

Network Performance 5-17


Network Performance 5-18
Mininet Applications

n MiniEdit
q A GUI application which
eases the Mininet
topology generation
q Either save the
topology or export as a
Mininet python script
n Visual Network
Description (VND)
q A GUI tool which allows
automate creation of
Mininet and OpenFlow
controller scripts

Network Performance 5-19


Two Flow Insertion Methods
n Reactive Flow Insertion
q A non-matched packet reaches an OpenFlow switch, it is sent
to the controller, based on the packet an appropriate flow is
inserted
n Proactive Flow Insertion
q Flow can be inserted proactively by the controller in switches
before packet arrive
SRC DST ACT … OpenFlow SRC DST ACT …

h1 h2 p1 acquire Controller h1 h2 p1

route
insert
flow

host1 switch1 (reactive) switch2 (proactive) host2

Network Performance 5-20


Sample Scenarios
n Construct a Customized Topology Using Mininet
q A topology with two hosts and five switches
n Scenario
q Setup the flow in reactive manner
q Ping from host1 to host2 in reactive manner
q Ping from all hosts to the other hosts

1 2 1 2
Route #1
0 1 2 1 3 0
switch2 switch3
3 2

switch1 switch host


host1
1 2 5 2

Route #2
switch4

Network Performance 5-21


Setup
REST- Static
based Flow
App Pusher
Not standardized yet,
use proprietary APIs

Northbound API

Ryu Controller Implement


Southbound API OpenFlow
OVS Host
Protocol
Host Switch OVS
Switch
OVS
OVS Host Switch
Host Switch Host Host
Host
OVS Host
Host Switch Host
mininet

Network Performance 5-22


Ryu installation
n Using pip command is the easiest option:
$ pip install ryu

n If you prefer to install from the source code:


$ git clone git://github.com/osrg/ryu.git
$ cd ryu; python ./setup.py install

n ryu.app.ofctl_rest
q http://ryu.readthedocs.io/en/latest/app/ofctl_rest.html

http://osrg.github.io/ryu-book/en/html/

Network Performance 5-23


Execution Procedures

n Procedures
q Start Ryu controller with Simple Switch 1.3 application
n http://sdnhub.org/tutorials/openflow-1-3/

q Initialize Mininet by specifying custom topology

$ sudo mn --custom ./topo.py --topo mytopo --controller=remote,


ip=127.0.0.1,port=6633

q Initiate a ICMP request from host1


mininet> h1 ping h2

q Initiate ICMP requests from all hosts


mininet> pingall

Network Performance
5-24
Lab2: Fat-Tree Topology Generation

It is not static tree, it grows with K (e.g. K=4)

Network Performance
5-25
Useful resources

n http://sdnhub.org/resources/

n http://mininet.org/walkthrough/

Network Performance
5-26

You might also like