Ryu's Restapi profile--I'm mainly used to distribute and view streaming tables

Source: Internet
Author: User

I. Introduction to Rest APIs

Rest, the representational state transfer (representational-Transfer), is a design and development approach to network applications that reduces the complexity of development and increases the scalability of the system.

Representational state transfer is a set of framework constraints and principles that satisfy these constraints and principles that an application or design is Restful,rest is a design style rather than a standard, which is often based on existing widely prevalent protocols and standards using Http,uri,xml and HTML.

Rest defines a set of architectural principles that can be used to design a system-resource-centric Web service based on these principles, including how clients written in different languages can process and transmit resource state over HTTP.

Two. Introduction to rest API in Ryu

Ryu has provided some definitions of RESTAPI, and the following related files can be found in the Ryu/app directory:

ofctl_rest.py rest_topology.py rest_firewall.py rest_qos.py rest_router.py

Open these files under the simple browsing can be found that they provide and OpenFlow protocol, topology and other related information query and configuration, the results of the query returned to the browser in JSON format, and the configuration will call related functions of the relevant modules, you can simply see the code to get the switch in the SDN network. The command to get switches is: http://ip:port/stats/switches, which first resolves the HTTP request (GET), and the required content (switches), and then calls the corresponding function (get_dpids). In the function, get the corresponding content, and then return in JSON form

Path ='/stats'URI= Path +'/switches'Mapper.connect ('Stats', URI, controller=statscontroller, action='Get_dpids', Conditions=dict (method=['GET']))defGet_dpids (self, req, * *_kwargs): DPS=list (Self.dpset.dps.keys ()) Body=json.dumps (DPS)returnResponse (content_type='Application/json', Body=body)

Understand the code is to better use it, or can easily modify, to get their own desired results, a shallow, not to repeat the building of the car

Before using the corresponding RESTAPI, you need to use the Ryu-manager *.rest*. PY loads the corresponding module

Three. Ryu Common Restapi profile

The most commonly used RESTAPI is the RESTAPI provided by ofctl_rest.py, which provides openflow-related interfaces, such as viewing switches, which are most useful for viewing, adding, modifying flow tables, and so on. In the previous comment section of the oftcl_rest.py file, we can get the method of using the interface, listed as follows:

#Retrieve the switch stats##get the list of all switches#get/stats/switches##get the desc stats of the switch#get/stats/desc/<dpid>##get flows stats of the switch#get/stats/flow/<dpid>##get flows stats of the switch filtered by the#post/stats/flow/<dpid>##get aggregate flows stats of the switch#get/stats/aggregateflow/<dpid>##get aggregate flows stats of the switch filtered by the fields#post/stats/aggregateflow/<dpid>##Get table stats of the switch#get/stats/table/<dpid>

For example, in order to get all the switches in the SDN network, you need to use get/stats/switches, if you want to view with a browser, send a GET request using http://ip:port/stats/switches

Four. Three ways to use Restapi in Ryu

    1. Enter a similar http://ip:port/stats/switches command in the browser to send a GET request, get the information, the IP for the controller's Ip,ryu provides a port of 8080
    2. Replace the browser with curl (curl is an open source file Transfer tool that works with URL syntax on the command line), and enter Curl Http://ip:port/stats/switches in the terminal to transfer the content
    3. Using the plugin postman provided by Chrome and other browsers, this method is highly recommended for the following reasons:
      1. Pretty and raw two results display methods are provided, Raw is the same as the return format of the previous two methods, but the pretty format is much better than the visibility and readability of raw
      2. provides two formats for presentation of JSON and XML results
      3. The release of the flow table is also simple, visual better, just in the body in accordance with the Python dictionary format to write the flow table, and then issued to
      4. can display the response of the request, such as the success of the status will display the OK

The flexibility of the flow table is one of the advantages of the SDN network, which uses the above method to check the flow table, verify the network function, and develop the app with a very important role.

Ryu's Restapi profile--I'm mainly used to distribute and view streaming tables

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.