Objective

Deploy a Ryu SDN controller, implement a learning switch application, and interact with the REST API to query topology and flows.

Tools & Technologies

  • Ryu
  • POX
  • ONOS
  • REST API
  • northbound

Key Commands

ryu-manager simple_switch_13.py
curl http://localhost:8080/v1.0/topology/switches
mn --controller remote,ip=127.0.0.1
ryu-manager --observe-links ryu.app.ofctl_rest ryu.app.rest_topology

Architecture Overview

graph LR subgraph Northbound REST[REST API\n:8080] --> APP[Ryu App\nPython] APP --> OF[OpenFlow\nEngine] end subgraph Southbound OF -->|OpenFlow 1.3| SW1[OVS Switch 1] OF -->|OpenFlow 1.3| SW2[OVS Switch 2] end subgraph Mininet SW1 <--> H1[h1] SW2 <--> H2[h2] SW1 <--> SW2 end style APP fill:#1a1a2e,stroke:#00d4ff,color:#e0e0e0 style REST fill:#1a1a2e,stroke:#00ff88,color:#e0e0e0

Step-by-Step Process

01
Install Ryu

Install the Ryu SDN controller and its dependencies.

sudo apt install python3-pip
pip3 install ryu

# Verify
ryu-manager --version

# List built-in apps
ls $(python3 -c 'import ryu; print(ryu.__path__[0])')/app/
02
Run a Learning Switch

The simple_switch_13.py app implements a Layer 2 learning switch.

# Terminal 1: Start controller
ryu-manager ryu.app.simple_switch_13

# Terminal 2: Start Mininet connected to controller
sudo mn --controller remote,ip=127.0.0.1 --switch ovsk,protocols=OpenFlow13

# Test in Mininet
mininet> pingall
mininet> h1 ping -c5 h2
03
REST API

Ryu provides a REST API for querying topology and managing flows.

# Start with REST + topology apps
ryu-manager \
  ryu.app.ofctl_rest \
  ryu.app.rest_topology \
  ryu.app.simple_switch_13 \
  --observe-links

# Query topology
curl http://localhost:8080/v1.0/topology/switches | python3 -m json.tool
curl http://localhost:8080/v1.0/topology/links

# Query flows
curl http://localhost:8080/stats/flow/1  # switch dpid=1

Challenges & Solutions

  • Ryu REST API only available when ofctl_rest app is loaded
  • Mininet must use --protocols=OpenFlow13 to match controller version

Key Takeaways

  • Ryu apps are simple Python classes that handle OpenFlow events
  • REST topology API requires --observe-links flag for LLDP discovery