Skip to content
yamahata edited this page Mar 18, 2013 · 13 revisions

OpenFlow Tutorial

This page is Ryu version of OpenFlow Tutorial

Set up Virtual Machine

Basically, please refer to http://www.openflow.org/wk/index.php/OpenFlow_Tutorial except VM image.

The VM in ovf format can be found here. OVF format, 64-bit ubuntu, mininet-2.0. This can be imported into virtualbox, VMWare or other hypervisors.

import Virtual Machine Image

Virtual Machine Image(OVF format, 64-bit, Mininet 2.0) This VM image is setup for Ryu

Finish VM Setup

If your virtual box is new,

  • Add host-only network (If your virtual box is not so-new, the host-only network is already created by default. In that case, skip to the next step) file menu/Preferences/Network and "Add host-only network" button with default settings.
  • select your VM and go to the Setting Tab. Go to Network->Adapter 2. Select the "Enable Adapter" box and attach it to "host-only network" which was created at the step 1.

Prerequisites

You will need the following installed in your environment that runs Ryu

  • python-gevent>=0.13
  • python-routes
  • python-webob
  • python-paramiko

Make sure that you have internet access:

ping -c www.standford.edu

If not, ensure that each ethX interface on your VM has an IP assigned via DHCP:

ifconfig -a

Run for each interface without an IP assigned, replacing ethX as necessary:

sudo dhclient ethX

update apt soruces:

sudo apt-get update

install prereqs:

time sudo apt-get install python-gevent python-routes python-webob python-paramiko

Getting Started

running mininet

If you had run the reference controller, please make sure it doesn't run:

$ sudo killall controller

And run mininet as follows:

mininet> exit
$ sudo mn -c
$ sudo mn --topo single,3 --mac --switch ovsk --controller remote

Without optional argument to --controller remote, it defaults to localhost:6633

Download and build

Ryu can be downloaded from Github.

git clone git://github.com/osrg/ryu.git
cd ryu

If you're using the VM image for Ryu, the repository is already cloned for you. So update the repository:

cd ryu
git pull

running Ryu

Then run the ryu as follows.

PYTHONPATH=. ./bin/ryu-manager ryu/app/simple_switch.py

This example runs simple_siwtch ryu application. If you have your own ryu application, replace ryu/app/simple_switch.py with yours. By adding --verbose option, you can observe more logs from Ryu. NOTE: The output is an example. As Ryu develops, the details of output might be slightly different from yours.:

PYTHONPATH=. ./bin/ryu-manager --verbose ryu/app/simple_switch.py
loading app ryu/app/simple_switch.py
loading app ryu.controller.ofp_handler
instantiating app ryu.controller.ofp_handler
instantiating app ryu/app/simple_switch.py
BRICK SimpleSwitch
  CONSUMES EventOFPPortStatus
  CONSUMES EventOFPPacketIn
BRICK ofp_event
  PROVIDES EventOFPPortStatus TO {'SimpleSwitch': ['main']}
  PROVIDES EventOFPPacketIn TO {'SimpleSwitch': ['main']}
  CONSUMES EventOFPErrorMsg
  CONSUMES EventOFPHello
  CONSUMES EventOFPEchoRequest
  CONSUMES EventOFPSwitchFeatures
connected socket:<socket fileno=4 sock=127.0.0.1:6633 peer=127.0.0.1:48488> address:('127.0.0.1', 48488)
hello ev <ryu.controller.ofp_event.EventOFPHello object at 0x23fdd90>
move onto config mode
switch features ev version: 0x1 msg_type 0x6 xid 0xef6eb3c4 port OFPPhyPort(port_no=1, hw_addr='\xaa\xbf-X\xad\xee', name='s1-eth1\x00\x00\x00\x00\x00\x00\x00\x00\x00', config=0, state=0, curr=192, advertised=0, supported=0, peer=0) OFPPhyPort(port_no=2, hw_addr='> l\xd96\xe3', name='s1-eth2\x00\x00\x00\x00\x00\x00\x00\x00\x00', config=0, state=0, curr=192, advertised=0, supported=0, peer=0) OFPPhyPort(port_no=3, hw_addr='\xf6\xb8\xde\x00\xe3\x82', name='s1-eth3\x00\x00\x00\x00\x00\x00\x00\x00\x00', config=0, state=0, curr=192, advertised=0, supported=0, peer=0) OFPPhyPort(port_no=65534, hw_addr='\xfa\xe3>\xc9\xb4M', name='s1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', config=1, state=1, curr=0, advertised=0, supported=0, peer=0)
move onto main mode

Verify Hub Behavior with tcpdump

Now we verify that hosts can ping each other, and that all hosts see the exact same traffic - the behavior of a hub. To do this, we'll create xterms for each host, and view the traffic in each. In the Mininet console, start up three xterms:

mininet> xterm h2 h3 h4

Arrange each xterm so that they're all on the screen at once. This may require reducing the height of to fit a cramped laptop screen.

In the xterms for h3 and h4, run tcpdump, a utility to print the packets seen by a host:

# tcpdump -XX -n -i h3-eth0

and respectively:

# tcpdump -XX -n -i h4-eth0

In the xterm for h2, send a ping:

# ping -c1 10.0.0.3

The ping packets are now going up to the controller, which then floods them out all interfaces except the sending one. You should see identical ARP and ICMP packets corresponding to the ping in both xterms running tcpdump.

Now, see what happens when a non-existent host doesn't reply. From h2 xterm:

# ping -c1 10.0.0.5

You should see three unanswered ARP requests in the tcpdump xterms. If your code is off later, three unanswered ARP requests is a signal that you might be accidentally dropping packets.

You can close the xterms now.

Benchmark Hub Controller w/iperf

Here, you'll benchmark the provided hub code, part of the Tutorial bundle.

First, verify reachability. Mininet should be running, along with your Beacon tutorial controller. In the Mininet console, run:

mininet> pingall

This is just a sanity check for connectivity. Now, in the Mininet console, run:

mininet> iperf

Now, compare your number with the reference controller you saw before. How does that compare?

Developing your own Ryu application

Ryu is written fully in python script. So just open related files with your favorite editor and edit them. And restart ryu. ryu/app/simple_switch.py is a good starting point.

The first step tutorial is here. The First Application.

packets with ryu packet library

Ryu also includes packet parser library. Packet library.

Python

Python basics

If you are not familiar with python, there are many good tutorials.

pydoc command is also useful:

$ pydoc dict

will show the documentation dict class. or builtin functions, exceptions and other objects see the documentation f builtin by typing:

$ pydoc __builtin__

Python decorators

Ryu heavily utilizes decorator. You might not familiar with it. The decorator is syntax sugar to twist functions/methods. It is used to twist functions/methods. For example.

Example:

def log_on_entry(method):
    def _method(self):
        print 'on-entry'
        return method(self)
    return _method

class aClass(object)

    @log_on_entry
    def a_method(self):
        print self, 'a_method is called'

a = aClass()
a.a_method()

@log_on_entry is same to:

class aClass(object)

    def a_method(self):
        print 'a_method is called'

    a_method = log_on_entry(a_method)

The output will be:

on-entry <main.aClass object at 0x7fc75eaf4d10> a_method is called.

For details, the following links would be useful.