Skip to main content

An unofficial Python library to interact with the REST API of the Ryu SDN Controller.

Project description

ryurest

A Python module to interact with the REST API of the Ryu SDN controller.

ABOUT

These are two Python modules that individually provide either a functional or object-orientated approach to using the Ryu REST API.

The modules make use of the Requests framework to interact with the RYU REST API.

MODULES

Both the modules contain identical functions/methods. Which one you should use depends entirely on how comfortable you are with Python (although it is generally seen as better practice in the community to use OO approaches where possible)

ryuswitch

Object-orientated approach.

Provides the RyuSwitch class to instantiate the physical switches connected to the controller as objects.

ryufunc

Functional approach.

Allows you to call the RyuSwitch methods directly (although a switch Datapath ID (DPID) must be passed as an argument in most cases).

REQUIREMENTS

Run the Ryu controller with REST API enabled.:

$ sudo ryu-manager ryu.app.simple_switch_13 ryu.app.ofctl_rest

INSTALLATION

PyPi

$ pip install ryurest

You may wish to use sudo with this command.

From source

Alternatively you can either download or clone this repository, place the required ryufunc.py and/or ryuswitch.py modules into your project directory, and import them as per normal.

$ git clone https://github.com/nathancatania/ryurest
# imports the functional module
import ryufunc

# imports the object-orientated module
from ryuswitch import RySwitch

You may also need to install the requests library if it is not already on your machine:

$ pip install requests

USAGE

ryuswitch.py (Object-Orientated module)

1. Import the ryurest module and the RyuSwitch class into your script

from ryurest import RyuSwitch

2. Create one or more RyuSwitch objects

switch1 = RyuSwitch( DPID )

If you do not know any of the DPIDs of the connected switches, you can initialize with no arguments and call the .get_switches() method to return an array of DPIDs.

Be sure to assign any object created in this way a DPID manually:

# Create a switch
switch0 = RyuSwitch()

# Get an array of Datapath IDs (DPIDs) for all connected switches
DPID_list = switch0.get_switches()

# Assign a DPID manually to the switch created
switch0.DPID = DPID_list[0]

3. [OPTIONAL] Change the REST API URI

  • The default location for the Ryu REST API is: http://localhost:8080

  • If Ryu is running on the same PC as the module (localhost), then there is no need to change anything.

  • If the Ryu controller is running on a different machine and/or port, you MUST set the API path within each RyuSwitch object created.

switch1 = RyuSwitch( DPID_list[0] )
switch1.API = "http://192.168.1.30:8080"

switch2 = RyuSwitch( DPID_list[1] )
switch2.API = "http://192.168.1.30:8080"

Warning! If altering the API path, DO NOT add a trailing ‘/’ at the end or the API call will fail!

4. Execute the class methods as required

# Gets all flows in flowtable
flows = switch1.get_flows()

ryufunc.py (functional module)

1. From the ryurest module, import ryufunc into your script

from ryurest import ryufunc

2. [OPTIONAL] Change the REST API URI

  • The default location for the Ryu REST API is: http://localhost:8080

  • If Ryu is running on the same PC as the module (localhost), then there is no need to change anything.

  • If the Ryu controller is running on a different machine and/or port, you MUST set the API path. This is global for the entire ryufunc namespace.

print ryufunc.API
# prints: http://localhost:8080

# Change the default IP and Port
ryufunc.API = "http://192.168.0.30:8080"

Warning! If altering the API path, DO NOT add a trailing ‘/’ at the end or the API call will fail!

3. [OPTIONAL] Obtain a list of Datapath IDs (DPIDs)

  • If you know the DPID(s) of the switch(es) you wish to interact with, you can skip this step.

  • To return an array containing all of the DPIDs (switches) connected to the Ryu controller, use the get_switches() function:

DPID_list = ryufunc.get_switches()

# Prints a list of all DPIDs
for DPID in DPID_list:
   print DPID

# Access how you would any other array
switch1_dpid = DPID_list[0]
switch2_dpid = DPID_list[1]
# etc...

4. Execute the functions as required

  • Once you know the DPID(s) of the connected switch(es), you can start to execute function calls.

# Gets all flows in flowtable
flows = ryufunc.get_flows( switch1_dpid )     # returns JSON

RETURN FORMATS

  • If API call was successful
    • All the .get_x() methods will return JSON formatted data; EXCEPT .get_switches() which will return an array of DPIDs.

    • All the .set_x(), .delete_x(), .modify_X() methods will return boolean True.

  • If the API call fails
    • ALL methods/functions will return boolean False.

This means that you can use if statements to check for and handle errors accordingly.

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ryurest-0.1.tar.gz (15.6 kB view details)

Uploaded Source

File details

Details for the file ryurest-0.1.tar.gz.

File metadata

  • Download URL: ryurest-0.1.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for ryurest-0.1.tar.gz
Algorithm Hash digest
SHA256 7587d2a734896392470981aa24ccc907caf569004cd3c7e5820fcd70db1e68eb
MD5 f0701a4fe01108000ca71b5e702b6ef2
BLAKE2b-256 3ecf5f7ffad4ed3b595c89226c59d9d35a58390bca5fb9eaf7c93e0123d292c1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page