Router with API

We have been manually entering the flow in the last example; in particular, the flows were inserted upon the completion of switch feature negotiation. It would be great if we could dynamically insert and remove flows. Luckily, Ryu already ships with many reference applications with the REST API under the ryu/app directory, such as rest_router.py. The REST API portion of the code is also separated into its own example filename, ofctl_rest.py:

ubuntu@sdnhubvm:~/ryu_latest[15:40] (master)$ ls ryu/app/rest*
ryu/app/rest_conf_switch.py ryu/app/rest_qos.py ryu/app/rest_topology.py
ryu/app/rest_firewall.py ryu/app/rest_router.py ryu/app/rest_vtep.py
...
ubuntu@sdnhubvm:~/ryu_latest[12:34] (master)$ ls ryu/app/ofctl_rest.py
ryu/app/ofctl_rest.py

The rest_router.py application usage is covered in detail in the Ryu book, https://osrg.github.io/ryu-book/en/html/rest_router.html, with a three-switch, three-host linear topology. The example mainly consists of API usage for dealing with flow and VLAN, which would be a great reference to see what is possible with the Ryu framework. However, if you dive directly into the code, it is a bit too complex for starting out.
In this section, we will focus on adding a few API for our router controller from the previous section. We will do this by leveraging the methods and classes already created in ofctl_rest.py. By limiting the scope as well as leveraging our existing example, we are able to focus on adding just the API. In the following example, we will use HTTPie, which we have seen before for HTTP GET:

$ sudo apt-get install httpie

I find the HTTPie color-highlighting and output pretty-print easier for viewing, but using HTTPie is of course optional. I personally find the HTTP POST operation with a complex body a bit easier with curl. In this section, I will use curl for HTTP POST operations that include complex JSON bodies, and HTTPie for HTTP GET operations.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.89.18