Ryu

raw JSON →
4.34 verified Fri May 01 auth: no python

Ryu is a component-based software-defined networking (SDN) framework that provides a set of APIs for network applications to manage and control network devices. The current version is 4.34. It has a stable release cadence with occasional updates.

pip install ryu
error AttributeError: module 'ryu' has no attribute 'base'
cause Typo or wrong import path; 'base' is a subpackage, not an attribute of the top-level ryu module.
fix
Use 'from ryu.base import app_manager' instead of 'import ryu.base as base'.
error ImportError: No module named 'ryu.lib'
cause Ryu's 'lib' package was removed or restructured in newer versions.
fix
Check the actual location of the desired module; most functionality is now in 'ryu.ofproto' or 'ryu.controller'.
breaking Ryu removed support for Python 2.7 as of version 4.31. Attempting to use Python 2 will result in syntax errors.
fix Use Python 3.6 or higher.
deprecated The 'ryu-manager --observe-links' flag is deprecated in favor of using the REST API or topology discovery module directly.
fix Use Ryu's REST API or import 'ryu.app.rest_topology' explicitly.
gotcha Ryu applications must declare the OFP_VERSIONS class variable. Omitting it causes silent failures or versions mismatches.
fix Add 'OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION]' (or appropriate version) in your RyuApp subclass.

A minimal Ryu application that responds to switch connection events.

from ryu.base import app_manager
from ryu.controller import ofp_event
from ryu.controller.handler import MAIN_DISPATCHER, set_ev_cls
from ryu.ofproto import ofproto_v1_3

class MyController(app_manager.RyuApp):
    OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION]

    @set_ev_cls(ofp_event.EventOFPSwitchFeatures, MAIN_DISPATCHER)
    def switch_features_handler(self, ev):
        datapath = ev.msg.datapath
        ofproto = datapath.ofproto
        parser = datapath.ofproto_parser
        print(f"Switch connected: {datapath.id}")