For SDNDS-TW Sharing 
Developing SDN apps in Ryu 林哲緯, John-Lin 
http://linton.tw/
whoami 
❖ 林哲緯 ( John-Lin ) 
❖ 清華⼤大學 通訊⼯工程所 HSNL LAB 
❖ 背景是通訊⼯工程 
• 原是寫 Python 當興趣,玩網路程式時接觸 
SDN/OpenFlow 
❖ ⽬目前研究使⽤用 Ryu 未來應該也會繼續⽤用 Ryu Controller 
❖ Network Security in SDN 
• Contribute Snort-Integrate patch in Ryu 
• See more: http://linton.tw/2014/09/03/Ryu-with-Snort-Integration/
Outline 
❖ OpenFlow Overview 
❖ Introduction to Ryu application development 
❖ The OpenFlow API in Ryu 
❖ Demo
Outline 
❖ OpenFlow Overview 
❖ Introduction to Ryu application development 
❖ The OpenFlow API in Ryu 
❖ Demo
What is OpenFlow? 
Controller Plane 
OpenFlow Controller 
OpenFlow Protocol (SSL/TCP) 
Flow Table 
Packet Packet 
OpenFlow Switch 
Data Plane 
Forwarding 
Drop 
Forward to Controller
About Flow Entry 
Rule Action Statistics 
in_port 
VLAN 
ID 
VLAN 
pcp 
1. Forward packet to ports 
2. Forward to controller 
3. Drop packet 
4. Modify Field (set-field) 
MAC 
src 
MAC 
dst 
Eth 
type 
1. Packet counter 
2. Byte counter 
IP src IP dst IP ToS sport dport 
More match field: http://ryu.readthedocs.org/en/latest/ofproto_v1_3_ref.html?highlight=match#ryu.ofproto.ofproto_v1_3_parser.OFPMatch
Flow Table 
Table id 0 
Rule Action Statistics 
Rule Action Statistics 
Rule Action Statistics 
Rule Action Statistics 
Rule Action Statistics 
Rule Action Statistics
Multiple Flow Tables 
Table id 0 
Table id 1 
Table id 2 
Rule Action Statistics 
Rule Action Statistics 
Rule Action Statistics 
Rule Action Statistics 
Rule Action Statistics 
Rule Action Statistics 
Rule Action Statistics 
Rule Action Statistics 
Rule Action Statistics 
Rule Action Statistics 
Rule Action Statistics 
Rule Action Statistics 
Rule Action Statistics 
Rule Action Statistics 
Rule Action Statistics 
Rule Action Statistics 
Rule Action Statistics 
Rule Action Statistics 
SDN Controller 
OpenFlow-enabled Network Device 
OpenFlow Protocol
OpenFlow Controller and switch workflow 
HANDSHAKE_DISPATCHER 
CONFIG_DISPATCHER 
MAIN_DISPATCHER 
DEAD_DISPATCHER 
如果發⽣生連線中斷 
Ryu Controller 的4種狀態
The messages between Controller and switch 
❖ Controller-to-Switch Messages (Controller->Switch) 
❖ Features 
❖ Modify-State 
❖ Packet-out 
❖ Configuration, Read-State, Barrier, Role-Request, Asynchronous-Configuration 
❖ Asynchronous Messages (Switch->Controller) 
❖ Packet-In 
❖ Flow Removed 
❖ Port Status 
❖ Error 
❖ Symmetric Messages (Switch<->Controller) 
❖ Hello 
❖ Echo Request / Reply 
❖ Experimenter 
OpenFlow Controller 
OpenFlow Protocol 
Flow Table 
OpenFlow Switch
Outline 
❖ OpenFlow Overview 
❖ Introduction to Ryu application development 
❖ The OpenFlow API in Ryu 
❖ Demo
What is Ryu 
❖ Ryu is a component-based software defined networking 
framework. 
❖ Fully written in Python 
❖ Ryu supports various protocols for managing network 
devices 
• OpenFlow 1.0, 1.2, 1.3, 1.4, Netconf, OF-config 
❖ License: Apache 2.0
Ryu Resources 
❖ Official site: 
• http://osrg.github.io/ryu/ 
❖ Mailing list: 
• https://lists.sourceforge.net/lists/listinfo/ryu-devel 
❖ API Documentation: 
• http://ryu.readthedocs.org/en/latest/ 
❖ RyuBook Tutorial (Chinese): 
• http://osrg.github.io/ryu-book/zh_tw/html/
Installation
Installation 
❖ On Official site… 
❖ Notice: Before you Install, check the dependencies first.
Automatic Installation Script 
❖ On Ubuntu 12.04+, two-line command can install Ryu 
3.14 
❖ This helper script which should get all dependencies 
and download, build, and install Ryu. 
Fork me on: https://github.com/John-Lin/ryuInstallHelper
To install dependencies in Ubuntu
How to use 
❖ Run your application 
❖ Run your application with debug output
Application programming model 
1. ⼀一個 OpenFlow message 
可以視為⼀一個 event 
2. 利⽤用 decorators 來接 event 
3. 定義事件處理器(Event 
Handler) 
Custom library 
事件 
Come from OpenFlow switches: 
• Asynchronous messages 
• Switch reply messages
Outline 
❖ OpenFlow Overview 
❖ Introduction to Ryu application development 
❖ The OpenFlow API in Ryu 
❖ Demo
OpenFlow protocol API 
Type Message Name Ryu OpenFlow API 
Controller to 
Switch 
Messages 
Features OFPFeaturesRequest / OFPSwitchFeatures 
Configuration OFPSetConfig 
Modify-State OFPFlowMod 
Read-State 
OFPFlowStatsRequest / OFPFlowStatsReply 
OFPPortStatsRequest / OFPPortStatsReply 
Packet-out OFPPacketOut 
Barrier OFPBarrierRequest / OFPBarrierReply 
Role-Request OFPRoleRequest / OFPRoleReply 
Asynchronous-Configuration OFPSetAsync / OFPGetAsyncReply 
Asynchronous 
Messages 
Packet-In OFPPacketIn 
Flow Removed OFPFlowRemoved 
Port Status OFPPortStatus 
Error OFPErrorMsg 
Symmetric 
Messages 
Hello OFPHello 
Echo Request / Reply OFPEchoRequest / OFPEchoReply 
Experimenter OFPExperimenter
OpenFlow Controller and switch workflow
Code Template in Ryu 
❖ Usually in the 
Class 
❖ Inheritance 
❖ Decorators: @ 
❖ 接取 OpenFlow 
message event 
❖ Event Handler 
❖ 接到event 後要 
做的事定義在 
method裡 
Initial method 
Utility 
Methods 
Snort 
Library Plugin 
Controller to 
Switch Messages 
Asynchronous 
Messages
Outline 
❖ OpenFlow Overview 
❖ Introduction to Ryu application development 
❖ The OpenFlow API in Ryu 
❖ Demo
DEMO 
SDN 
Controller 
❖ Hub application 
Flow table 
1 2 3 4 priority=10, match=icmp, action=ALL 
priority=0, actions=CONTROLLER:65535 
Host A Host B 
❖ 利⽤用 Flow Table match ICMP 封包將其 Flood,其他協定 
封包導到Controller 做處理 
❖ https://github.com/John-Lin/SDNDS-TW
Developing SDN apps in Ryu

Developing SDN apps in Ryu

  • 1.
    For SDNDS-TW Sharing Developing SDN apps in Ryu 林哲緯, John-Lin http://linton.tw/
  • 2.
    whoami ❖ 林哲緯( John-Lin ) ❖ 清華⼤大學 通訊⼯工程所 HSNL LAB ❖ 背景是通訊⼯工程 • 原是寫 Python 當興趣,玩網路程式時接觸 SDN/OpenFlow ❖ ⽬目前研究使⽤用 Ryu 未來應該也會繼續⽤用 Ryu Controller ❖ Network Security in SDN • Contribute Snort-Integrate patch in Ryu • See more: http://linton.tw/2014/09/03/Ryu-with-Snort-Integration/
  • 3.
    Outline ❖ OpenFlowOverview ❖ Introduction to Ryu application development ❖ The OpenFlow API in Ryu ❖ Demo
  • 4.
    Outline ❖ OpenFlowOverview ❖ Introduction to Ryu application development ❖ The OpenFlow API in Ryu ❖ Demo
  • 5.
    What is OpenFlow? Controller Plane OpenFlow Controller OpenFlow Protocol (SSL/TCP) Flow Table Packet Packet OpenFlow Switch Data Plane Forwarding Drop Forward to Controller
  • 6.
    About Flow Entry Rule Action Statistics in_port VLAN ID VLAN pcp 1. Forward packet to ports 2. Forward to controller 3. Drop packet 4. Modify Field (set-field) MAC src MAC dst Eth type 1. Packet counter 2. Byte counter IP src IP dst IP ToS sport dport More match field: http://ryu.readthedocs.org/en/latest/ofproto_v1_3_ref.html?highlight=match#ryu.ofproto.ofproto_v1_3_parser.OFPMatch
  • 7.
    Flow Table Tableid 0 Rule Action Statistics Rule Action Statistics Rule Action Statistics Rule Action Statistics Rule Action Statistics Rule Action Statistics
  • 8.
    Multiple Flow Tables Table id 0 Table id 1 Table id 2 Rule Action Statistics Rule Action Statistics Rule Action Statistics Rule Action Statistics Rule Action Statistics Rule Action Statistics Rule Action Statistics Rule Action Statistics Rule Action Statistics Rule Action Statistics Rule Action Statistics Rule Action Statistics Rule Action Statistics Rule Action Statistics Rule Action Statistics Rule Action Statistics Rule Action Statistics Rule Action Statistics SDN Controller OpenFlow-enabled Network Device OpenFlow Protocol
  • 9.
    OpenFlow Controller andswitch workflow HANDSHAKE_DISPATCHER CONFIG_DISPATCHER MAIN_DISPATCHER DEAD_DISPATCHER 如果發⽣生連線中斷 Ryu Controller 的4種狀態
  • 10.
    The messages betweenController and switch ❖ Controller-to-Switch Messages (Controller->Switch) ❖ Features ❖ Modify-State ❖ Packet-out ❖ Configuration, Read-State, Barrier, Role-Request, Asynchronous-Configuration ❖ Asynchronous Messages (Switch->Controller) ❖ Packet-In ❖ Flow Removed ❖ Port Status ❖ Error ❖ Symmetric Messages (Switch<->Controller) ❖ Hello ❖ Echo Request / Reply ❖ Experimenter OpenFlow Controller OpenFlow Protocol Flow Table OpenFlow Switch
  • 11.
    Outline ❖ OpenFlowOverview ❖ Introduction to Ryu application development ❖ The OpenFlow API in Ryu ❖ Demo
  • 12.
    What is Ryu ❖ Ryu is a component-based software defined networking framework. ❖ Fully written in Python ❖ Ryu supports various protocols for managing network devices • OpenFlow 1.0, 1.2, 1.3, 1.4, Netconf, OF-config ❖ License: Apache 2.0
  • 13.
    Ryu Resources ❖Official site: • http://osrg.github.io/ryu/ ❖ Mailing list: • https://lists.sourceforge.net/lists/listinfo/ryu-devel ❖ API Documentation: • http://ryu.readthedocs.org/en/latest/ ❖ RyuBook Tutorial (Chinese): • http://osrg.github.io/ryu-book/zh_tw/html/
  • 14.
  • 15.
    Installation ❖ OnOfficial site… ❖ Notice: Before you Install, check the dependencies first.
  • 16.
    Automatic Installation Script ❖ On Ubuntu 12.04+, two-line command can install Ryu 3.14 ❖ This helper script which should get all dependencies and download, build, and install Ryu. Fork me on: https://github.com/John-Lin/ryuInstallHelper
  • 17.
  • 18.
    How to use ❖ Run your application ❖ Run your application with debug output
  • 19.
    Application programming model 1. ⼀一個 OpenFlow message 可以視為⼀一個 event 2. 利⽤用 decorators 來接 event 3. 定義事件處理器(Event Handler) Custom library 事件 Come from OpenFlow switches: • Asynchronous messages • Switch reply messages
  • 20.
    Outline ❖ OpenFlowOverview ❖ Introduction to Ryu application development ❖ The OpenFlow API in Ryu ❖ Demo
  • 21.
    OpenFlow protocol API Type Message Name Ryu OpenFlow API Controller to Switch Messages Features OFPFeaturesRequest / OFPSwitchFeatures Configuration OFPSetConfig Modify-State OFPFlowMod Read-State OFPFlowStatsRequest / OFPFlowStatsReply OFPPortStatsRequest / OFPPortStatsReply Packet-out OFPPacketOut Barrier OFPBarrierRequest / OFPBarrierReply Role-Request OFPRoleRequest / OFPRoleReply Asynchronous-Configuration OFPSetAsync / OFPGetAsyncReply Asynchronous Messages Packet-In OFPPacketIn Flow Removed OFPFlowRemoved Port Status OFPPortStatus Error OFPErrorMsg Symmetric Messages Hello OFPHello Echo Request / Reply OFPEchoRequest / OFPEchoReply Experimenter OFPExperimenter
  • 22.
    OpenFlow Controller andswitch workflow
  • 23.
    Code Template inRyu ❖ Usually in the Class ❖ Inheritance ❖ Decorators: @ ❖ 接取 OpenFlow message event ❖ Event Handler ❖ 接到event 後要 做的事定義在 method裡 Initial method Utility Methods Snort Library Plugin Controller to Switch Messages Asynchronous Messages
  • 24.
    Outline ❖ OpenFlowOverview ❖ Introduction to Ryu application development ❖ The OpenFlow API in Ryu ❖ Demo
  • 25.
    DEMO SDN Controller ❖ Hub application Flow table 1 2 3 4 priority=10, match=icmp, action=ALL priority=0, actions=CONTROLLER:65535 Host A Host B ❖ 利⽤用 Flow Table match ICMP 封包將其 Flood,其他協定 封包導到Controller 做處理 ❖ https://github.com/John-Lin/SDNDS-TW