Mininet Tutorial Leonardo Richter Bays Gustavo Mio7o Marcelo Caggiani Luizelli Luciano Paschoal Gaspary
Outline Introduc?on Installing Mininet SeAng Up First Steps in Mininet Ini?aliza?on Main commands Handling Flow Rules Advanced Usage Python API Addi?onal Informa?on An End-to-End Example
Introduc?on Mininet is a network emulator testbed Emulates collec?ons of end-hosts, switches, routers, and links on a single Linux kernel Uses lightweight virtualiza?on Supports OpenFlow na?vely It allows the Crea?on of arbitrary custom topologies Development and evalua?on of network algorithms (e.g., rou?ng) and architectures (e.g., CCN Content Centric Networks) Usage of any available switch (e.g., OpenVSwitch) Customiza?on of packet forwarding
Installing Mininet First, you have to download Mininet. You can either: Download it directly on a Linux distro Tutorial available at: h7p://mininet.org/download/ Download a VM Image (easiest way) Requirements: A virtualiza?on system (Virtualbox, Vmware, etc) SSH X11 (If you are not running Mininet on a Linux distro) We recommend using an OF1.3-enabled Mininet image. We provide an image at: h7p://inf.ufrgs.br/~lrbays/mininet-2.2.1.zip
SeAng Up Before impor?ng the downloaded image on VirtualBox, you have to add a Host-Only Adapter Virtualbox -> Preferences -> Networks -> Host-Only Networks and add an adapter
SeAng Up A`er impor?ng the image, you must add the recently created network adapter to it SeAngs -> Network -> Adapter 2 -> Enable Network Adapter -> Host-only Adapter and select the adapter
SeAng Up Boot up the Mininet-VM Log in using user and password mininet Set up the newly added network adapter $> sudo dhclient eth1 Get the VM IP address (usually the one that starts with 192.168 ) $> ifconfig
SeAng Up Op?onal Add the IP address in your host machine /etc/hosts so that you can ssh with the machine name, instead of using the IP $> echo '192.168.x.y mininet-vm' sudo tee -a /etc/hosts
SeAng Up On your host PC, run: $> ssh X mininet@mininet-vm Password: mininet Op?onal: You can set up SSH auto-login so that you can log in without password More info available at: h7p://mininet.org/vm-setup-notes/, on the Op?onal VM Customiza?on sec?on
First Steps Ini?aliza?on Default topology: $> sudo mn Single topology (one switch, N hosts) $> sudo mn --topo single,n --mac --controller remote[,ip]
First Steps Ini?aliza?on Linear topology (N switches connected in line; only one host a7ached to each switch): $> sudo mn --topo linear,n --mac --controller remote[,ip] Tree topology (depth M, width N): $> sudo mn --topo tree,depth=m,fanout=n --mac --controller remote[,ip] You can also customize the link parameters. For example, to set bandwidth to 10Mb/s, you can use: $> sudo mn --link=tc,bw=10
First Steps Main Commands nodes list the nodes dump show nodes informa?on net list the links between the nodes xterm open a terminal for one or more nodes help list all available commands exit shutdown mininet
First Steps Handling Flow Rules Syntax (Mininet CLI): mininet> [switch] dpctl add-flow [protocol:ip:port] [flow] Examples: mininet> s1 dpctl add-flow tcp:127.0.0.1:6634 dl_src=00:00:00:00:00:02,idle_?meout=0,ac?ons= mod_dl_src:00:00:00:00:00:09,all mininet> s1 dpctl add-flow tcp:127.0.0.1:6634 dl_src=00:00:00:00:00:01,dl_dst=00:00:00:00:00:02,idle_?meout=0, ac?ons=output:6
First Steps Handling Flow Rules Match Fields: in_port=[port number] dl_vlan=[vlan] dl_src=[source mac] dl_dst=[des?na?on mac] dl_type=[ethernet protocol type (0-65535)] nw_src=[source ip[/net_mask]] nw_dst=[des?na?on ip[/net_mask]]
First Steps Handling Flow Rules Match Fields: nw_proto=[ip protocol type (0-255)] nw_tos=[tos/dscp (0-255)] tp_src=[source port TCP/UDP] tp_dst=[des?na?on port TCP/UDP] icmp_type=[icmp message type (0-255)] Icmp_code=[code present in message] priority=[priority (0-65535)]
First Steps Handling Flow Rules ac?ons=[ac?on1[,ac?on2, ]] output:[port] enqueue:[port]:[queue id] normal flood all controller:[maximum size] local
First Steps Handling Flow Rules ac?ons=[ac?on1[,ac?on2, ]] mod_vlan_vid:[vlan id] mod_vlan_pcp:[vlan priority (0-7)] mod_dl_dst:[des?na?on mac] mod_dl_src:[source mac] mod_nw_tos:[tos/dscp] strip_vlan
Advanced Usage Python API Mininet provides a straighuorward and extensible Python API Core of Mininet Used to create custom topologies Examples can be found at: ~/mininet/examples A tutorial can be found at: h7ps://github.com/mininet/mininet/wiki/introduc?on-to-mininet Python is used for orchestra?on, but emula?on is performed by compiled C code
Advanced Usage Python API Mininet script 1 from mininet.net import Mininet 2 from mininet.cli import CLI 3 net = Mininet() # net is a Mininet() object 4 h1 = net.addhost( 'h1' ) # h1 is a Host() object 5 h2 = net.addhost( 'h2' ) # h2 is a Host() 6 s1 = net.addswitch( 's1' ) # s1 is a Switch() object 7 c0 = net.addcontroller( 'c0' ) # c0 is a Controller() 8 net.addlink( h1, s1 ) # creates a Link() object 9 net.addlink( h2, s1 ) 10 net.start() 11 print h1.cmd( 'ping -c1', h2.ip() ) 12 CLI( net ) 13 net.stop() Save it as a python script Run with: $> sudo python script_name.py
Advanced Usage Python API Custom topology 1 from mininet.topo import Topo 2 3 class SingleSwitchTopo( Topo ): 4 5 "Single Switch Topology" 6 7 def build( self, count=1): 8 hosts = [ self.addhost( 'h%d' % i ) 9 for i in range( 1, count + 1 ) ] 10 s1 = self.addswitch( 's1' ) 11 for h in hosts: 12 self.addlink( h, s1 ) 13 14 topos = { 'mytopo': SingleSwitchTopo } Save it as a python script: custom.py Run with: $> sudo mn --custom custom.py --topo mytopo
Addi?onal Informa?on External Controller It is possible (and desirable) to run an external controller Op?on 1: POX (Python) h7p://www.noxrepo.org/pox/about-pox/ Already installed on Mininet-VM Only supports OpenFlow 1.0 Op?on 2: RYU (Python) h7p://osrg.github.io/ryu/ Not installed, but it is possible to install at Host or VM machine (tutorial available at website) Fully supports OpenFlow 1.0, 1.2, 1.3 and 1.4 Op?on 3 (not covered here): Floodlight (Java) h7p://www.projeculoodlight.org/floodlight/ Not installed, but it is possible to install at Host or VM machine (tutorial available at website) Fully supports OpenFlow 1.0 and 1.3
Addi?onal Informa?on External Controller Op?on 1 -> POX Boo?ng up the controller with L2 forwarding $> cd ~/pox $>./pox.py forwarding.l2_learning Ini?ate Mininet with the following command: $> sudo mn --topo single,3 --mac --switch ovsk --controller remote
Addi?onal Informa?on External Controller Op?on 2 -> RYU with OpenFlow 1.3 installed at host machine Boo?ng up the controller with L2 forwarding $> ryu-manager ryu.app.simple_switch_13 Ini?ate Mininet with the following command: $> sudo mn --topo single,3 --mac --switch ovsk,protocols=openflow13 -- controller remote,192.168.56.1 #host machine ip Easy to write complex applica?ons There are a lot of examples at ${installa?on_folder}/ryu/ryu/app/
Addi?onal Informa?on -- Wireshark VM includes Wireshark with the OpenFlow dissector installed Useful for general debugging To start Wireshark, run: $> sudo wireshark & To set up a filter for Openflow For OpenFlow 1.0 of For OpenFlow 1.3 of13
An End-to-End Example Problem: Mul?path forwarding between two nodes Link failures are detected and the paths are rearranged Used tools: Controller: Ryu Switch: OFSo`switch13 Available at: h7ps://github.com/cpqd/ofso`switch13 Emula?on Plauorm: Mininet
An End-to-End Example
References Team, M. Mininet: An Instant Virtual Network on your Laptop (or other PC) - Mininet. Available at: <h7p://mininet.org/>. Accessed in: Apr. 1st, 2015. Team, M. Mininet: An Instant Virtual Network on your Laptop (or other PC) - Mininet. Available at:<h7ps://github.com/mininet/ mininet/wiki/introduc?on-to-mininet>. Accessed in: Apr. 1st, 2015 HUANG, TE-YUAN, JEYAKUMAR, VIMALKUMARLANTZ, BOB ET AL. Teaching Computer Networking with Mininet. 1. ed. [s.l.: s.n.], 2015. Available at: <h7p://conferences.sigcomm.org/sigcomm/ 2014/doc/slides/mininet-intro.pdf>. Accessed in: Apr. 1st, 2015. OpenFlow Switch Specifica?on. The Open Networking Founda?on, 2015. Available at: <h7ps://www.opennetworking.org/images/ stories/downloads/sdn-resources/onf-specifica?ons/openflow/ openflow-spec-v1.3.0.pdf>. Accessed in: Apr. 1st, 2015.