Introduction

Mininet is an instant virtual network. It creates a realistic virtual network, running real kernel, switch and application code, on a single machine (VM, cloud or native), in seconds, with a single command. Ryu is a component-based software defined networking (SDN) framework. Ryu supports various protocols for managing network devices, such as OpenFlow. We can develop network application with Ryu controller and simulate inside Mininet. Let's start by installing Mininet and Ryu.

Install Mininet

There are four options to get started with Mininet:
  1. Option 1: Mininet VM Installation
  2. Option 2: Native Installation from Source
  3. Option 3: Installation from Packages
  4. Option 4: Upgrading an existing Miniet Installation
Option 1 is the easiest and most foolproof way of installing Mininet. However, the following section will follow option 2 and 3.
First, to confirm which OS version you are running, run the command.
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 16.04.5 LTS
Release:	16.04
Codename:	xenial
If you are one of the following OS, you can install from packages
Mininet 2.1.0 on Ubuntu 14.10: sudo apt-get install mininet
Mininet 2.1.0 on Ubuntu 14.04: sudo apt-get install mininet
Mininet 2.0.0 on Ubuntu 12.04: sudo apt-get install mininet/precise-backports
In my case, I'm using Ubuntu 16.04 so I have to install from source. To install natively from source, first you need to get the source code.
$ git clone git://github.com/mininet/mininet
Note that the git command will check out the lastest version. If you want to run other release of Mininet you can checkout that version with the following command.
$ cd mininet
$ git tag  # list available versions
$ git checkout -b 2.2.2 2.2.2
Make a directory to place source/build trees.
$ mkdir build
The first option specifies the directory and the second option installs everything that is included in the Mininet VM, including dependencies like Open vSwitch as well as the additions like the OpenFlow wireshark dissector and POX. This command should take a while.
$ ./util/install.sh -s ./build/ -a
After successful installation, you can test with creating a network with tree topology of depth 2 and fanout 8 (i.e. 64 hosts connected to 9 switches), using Open vSwitch switches under the control of OpenFlow/Stanford reference controller, and runs the test to check connectivity between every pair of nodes with pingall.
$ sudo mn --switch ovs --controller ref --topo tree,depth=2,fanout=8 --test pingall

Install Ryu Controller

Using pip3 command to install Ryu Controller is the easiest option. If you have pip3 already, you can skip the first command
$ sudo apt install python-pip3
$ sudo pip3 install ryu

Test Ryu Controller with Simple Switch

First, open a terminal and run Mininet with the following command. This starts a network emulation environment with 1 switch and 3 hosts.
$ sudo mn --topo single,3 --mac --controller remote --switch ovsk
Second, open another new terminal and run a simple switch controller. This controller will flood a packet to all ports if the switching table has no record of the destination mac address and add a record which specifies the source mac address at in port.
$ ryu-manager ryu.app.simple_switch
loading app ryu.app.simple_switch
loading app ryu.controller.ofp_handler
instantiating app ryu.app.simple_switch of SimpleSwitch
instantiating app ryu.controller.ofp_handler of OFPHandler
After opening the Ryu controller, you can test the reachability between these three hosts.
mininet> pingall
*** Ping: testing ping reachability
h1 -> h2 h3 
h2 -> h1 h3 
h3 -> h1 h2 
*** Results: 0% dropped (6/6 received)
In the terminal of the Ryu controller, you can see these packet in messages.
packet in 1 00:00:00:00:00:02 00:00:00:00:00:01 2
packet in 1 00:00:00:00:00:01 00:00:00:00:00:02 1
packet in 1 00:00:00:00:00:01 ff:ff:ff:ff:ff:ff 1
packet in 1 00:00:00:00:00:03 00:00:00:00:00:01 3
packet in 1 00:00:00:00:00:01 00:00:00:00:00:03 1
packet in 1 00:00:00:00:00:02 ff:ff:ff:ff:ff:ff 2
packet in 1 00:00:00:00:00:03 00:00:00:00:00:02 3
packet in 1 00:00:00:00:00:02 00:00:00:00:00:03 2

Conclusion

After installing Mininet and Ryu controller, you can go ahead and build your own Ryu applications. You can start from writing your Ryu application with Python.

History

Reference

  1. Mininet
  2. Ryu
  3. RYU Controller Tutorial