How to Write a REST Application
Writing a REST application is one of the quickest and perhaps easiest way for most people to start harnessing the power of an OpenFlow network. Â
To write a REST application in any programming language of your choice, you will typically go through the following steps:
- Determine the "network services/information" your application needs
- Check out the Floodlight REST API pre-v1.0 page to find the REST APIs that provide these services
- If its found, take note of the REST API syntax, input arguments, and available options
- If its not found, the services/information may still be available in Floodlight but has not been exposed through a REST API yet. Â In this case, you should: 1) email the floodlight-dev list to discuss what you need and 2) after consulting with the developer community, you may implement and contribute a REST API to expose the service. Â (The Floodlight team at Big Switch is drafting a proposed syntax and set of REST APIs for Floodlight and will soon be available for community suggestions)
- if its not found and the service simply does not exist in Floodlight at this time, you should 1)Â 1) email the floodlight-dev list to discuss what you need and 2) after consulting with the developer community,based on whether it is more suitable as a controller module or an application module, you may implement and contribute the Java module.
- With all needed REST API calls, design and compose your application.
- Implement tests for it and contribute your application and/or added service modules/APIs back to Floodlight.Â
An example of this can be found from the python Circuit Pusher application released with Floodlight under the floodlight/apps directory.Â
The Circuit Pusher example demonstrates how to create a static single path circuit between two IP hosts A and B in a single OpenFlow cluster. Â Following the design approach above:
- The needed network services/information:
- The "attachment points" for hosts A and B (the data entity used to represent physical location of a host based on the (switch, port) it is connected to;
- The "route" between A and B's attachment points;
- Service to install a circuit for traffic from/to A and B on all switches on the A-B route.Â
- From the Floodlight REST API pre-v1.0s:
- GET with /wm/device/ with GET parameters allows us to find out the attachment point info for any device provided its attribute (such as IP address)
- GET with /wm/topology/route/<switchIdA>/<portA>/<switchIdB>/<portB>/json allows us to find out a route, if one exists, between A and B based on attachment points (switch, port).
- POST with /wm/staticflowentrypusher/json with POST parameters allows us to install one flow entry on one specified switch
- Application design: (source)
- We decided to use python for our application
- We decided to use os.popen to send out curl commands for the REST API calls
- We figure out the /wm/device syntax and parse the attachment point switch port for host A and host B
- We figure out that /wm/topology/route returns switch port pairs (switch X port M to switch X port N) of which each can be use to form a flow entry
- For each switch port pair, we will install four flow entries on switch X using /wm/staticflowentrypusher/json:
- ether-type '0x0800', port M ? N
- ether-type '0x0806', port MÂ ? N
- ether-type '0x0800', port N ? M
- ether-type '0x0806', port N ? M
- If everything works as expected, we are done! (the core feature at least ... do a ping or iperf between A and B to see it work)
- To wrap up the design, we decided two added features would be useful:
- option to remove flows, since these are "static" flows that by definition never times out!
- ability to remember flows already pushed. We decided to use a simple text file to store the flows for this example.
- Complete integration test and submit code to floodlight!
- See How to Write Tests
- See How to Submit a Patch