Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Study and use of openflow.webservice Construction in pox

2025-03-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

A simple JSON-RPC-ish web service interactive interface for Openflow, derived from of_service Information Services, that relies on webcore components. You can use HTTP POST to send JSON for access.

Currently supported methods are:

Method introduces the parameter get_flow_stats to get the entry dpid of the flow table-a dpid in the form of a string, for example:'00-00-00-00-00-01'

Flows-list of all flow tables

Get_switch_desc gets the details of the specified switch dpid-as above get_switches gets the switch list and basic information

Dpid-Ibid.

Match-match entries for the flow table (match all by default)

Table_id-id of the flow table (default is all)

Out_port-filter by out port (defaults to all)

Set_table sets the flow table of the specified switch None.

In the process of using pox, basically you can only add a build to run together after. / pox.py, and webservice build provides an interface that can access the switch and flow table through web. As shown above, only four functions are supported. I will demonstrate in the next process ~ I basically look at the data in pox wiki and then verify the results, but there is a bit of bug in wiki, which I have also corrected. You can also refer to the content of pox wiki ~ I use curl to implement the above method. I will skip the specific introduction of this thing here. I will directly talk about my running process.

First of all, two basic things, mininet and pox, are used here. Since we can read the estimate of this article, we will not explain it. This article points to some things that are difficult to find on domestic websites. Don't talk much nonsense.

First of all, run pox and mininet (I basically run su root with root permissions, compare personal use, without considering any security issues), we use the default topology of mininet, the comparison is just a functional demonstration.

Go to the directory of pox to launch pox and the corresponding build. In order to verify the information obtained by the test, we have enabled the l3_learning build, which will send the flow table during the ping operation:

Cd pox. / pox.py openflow.of_01 web.webcore openflow.webservice forwarding.l3_learning

Enable mininet:

Mn-controller=remote

Generally speaking, the default is to connect ~ and output the following information in pox:

INFO:openflow.of_01: [00-00-00-00-01 2] connected

Let's do the ping operation in mininet and ask the controller to send the flow table ~

Mininet > H2 ping h3

If you can ping, there will already be a flow table issued by the controller in the switch.

Now we can access the web interface through curl and get the information.

Let's get the flow table of the switch first.

Curl-I-X POST-d'{"method": "get_flow_stats", "params": {"dpid": "00-00-00-00-01"}, "id": 1} 'http://127.0.0.1:8000/OF/

This operation is divided into three parts, the front is the curl command, not to mention here, the middle pair of curly braces, is the data we want to request, we are in the form of post, request data, and finally is the URL we want to request data, the URL written in pox wiki is http://127.0.0.1:8000, but according to my own test site should be the above. Let's talk about the contents in the middle pair of curly braces.

Generally speaking, we send a form in the form of one-to-one data. This form is called a dictionary in python, and in other places it may be called hash table, mapping, and so on. Now let's talk about specific parameters. In this method, there are three parameters, method, corresponding to four options, which have been listed at the beginning. Params corresponds to another dictionary, which includes some parameters of the corresponding method, such as the method in the example, method. He must specify which switch the flow table we want to obtain comes from, and the switch is usually identified by dpid, so the parameter we enter is dpid, because getting the information of the switch is a simple operation, so there is only one parameter. Execute the above command in the liux terminal to get the information about the switch to which the controller is connected. The output in this example is as follows:

{"result": {"flowstats": [{"packet_count": 2, "hard_timeout": 0, "byte_count": 196, "duration_sec": 3, "actions": [{"dl_addr": "be:48:cb:78:60:92", "type": "OFPAT_SET_DL_DST"}, {"max_len": 0, "type": "OFPAT_OUTPUT", "port": 2}] "duration_nsec": 194000000, "priority": 65535, "idle_timeout": 10, "cookie": 0, "table_id": 0, "match": {"dl_type": "IP", "nw_dst": "10.0.0.2 IP 32", "dl_src": "52:9d:f5:2b:88:d4", "nw_proto": 1, "nw_tos": 0, "tp_dst": 0 "tp_src": 8, "dl_dst": "be:48:cb:78:60:92", "dl_vlan": 65535, "nw_src": "10.0.0.1", "in_port": 1}}, {"packet_count": 2, "hard_timeout": 0, "byte_count": 196, "duration_sec": 3 "actions": [{"dl_addr": "52:9d:f5:2b:88:d4", "type": "OFPAT_SET_DL_DST"}, {"max_len": 0, "type": "OFPAT_OUTPUT", "port": 1}], "duration_nsec": 193000000, "priority": 65535, "idle_timeout": 10, "cookie": 0, "table_id": 0 "match": {"dl_type": "IP", "nw_dst": "10.0.0.1 be:48:cb:78:60:92", "dl_src": "be:48:cb:78:60:92", "nw_proto": 1, "nw_tos": 0, "tp_dst": 0, "tp_src": 0, "dl_dst": "52:9d:f5:2b:88:d4", "dl_vlan": 65535 "nw_src": "10.0.0.2", "in_port": 2}}], "dpid": "00-00-00-00-01"}, "id": 1}

If you haven't sent out the flow meter yourself, it may seem a little difficult, but if you have sent it yourself, you can basically read it.

Get information about the specified switch (specify a different switch with dpid):

Curl-I-X POST-d'{"method": "get_switch_desc", "params": {"dpid": "00-00-00-00-01"}, "id": 1} 'http://127.0.0.1:8000/OF/

Results:

{"result": {"switchdesc": {"dp_desc": "None", "sw_desc": "2.3.2", "hw_desc": "Open vSwitch", "serial_num": "None", "mfr_desc": "Nicira, Inc."}, "dpid": "00-00-00-00-01"}, "id": 1}

In fact, there is no content at all. Ahem.

Get a list of switches and basic information:

Curl-I-X POST-d'{"method": "get_switches", "id": 1}'

Results:

{"result": [{"n_tables": 254, "ports": [{"hw_addr": "9e:0f:91:2d:a0:8e", "name": "s1-eth2", "port_no": 1}, {"hw_addr": "de:d6:d4:55:9e:e0", "name": "s1-eth3", "port_no": 2} {"hw_addr": "7a:2a:44:cf:ff:4f", "port_down": true, "link_down": true, "name": "S1", "port_no": 65534}], "dpid": "00-00-00-00-01"}], "id": 1}

Because there is only one switch, a set of information is obtained.

Finally, the sending table is issued.

Curl-I-X POST-d'{"method": "set_table", "params": {"dpid": "00-00-00-00-01", "flows": [{"actions": [{"type": "OFPAT_OUTPUT", "port": 2}], "match": {"dl_type": "IP", "in_port": 1}]}} 'http://127.0.0.1:8000/OF/

In addition to specifying dpid, there is also an extra flow in params. In python, what is in parentheses is the form of list, that is, several flow tables can be issued at the same time. Similarly, actions corresponds to the form of list, corresponding to multiple actions. There is a flow table in flows. We specify the matching information of the flow table. First, it must be an ip packet, and then it must be a packet coming in from port 1. We also specify that the action after a successful match is forwarded from port 2.

Let's demonstrate how to send multiple flow tables at the same time:

Curl-I-X POST-d'{"method": "set_table", "params": {"dpid": "00-00-00-00-01", "flows": [{"actions": [{"type": "OFPAT_OUTPUT", "port": 2}], "match": {"dl_type": "IP", "in_port": 1}, {"actions": [{"type": "OFPAT_OUTPUT" "port": "OFPP_ALL"}]}} 'http://127.0.0.1:8000/OF/

We added another item to the flows list.

Then we look at the flow table in mininet and execute the following code:

Mininet > dpctl dump-flows

We can get the following information:

* * S1-NXST_FLOW reply (xid=0x4): cookie=0x0, duration=203.063s, table=0, n_packets=0, n_bytes=0, idle_age=203, actions=ALL cookie=0x0, duration=203.102s, table=0, n_packets=0, n_bytes=0, idle_age=203, ip In_port=1 actions=output:2

At this point, all the content is over. It may not be clear enough, or it may be too wordy and do not understand the place. Everyone can leave a message or email me. Of course, if I leave a message, I don't know that I will have a blog for centuries. So it's best to send an email.

Finally, there is a problem. There is always a problem when I match the source ip address.

Curl-I-X POST-d'{"method": "set_table", "params": {"dpid": "00-00-00-00-01", "flows": [{"actions": [{"type": "OFPAT_OUTPUT", "port": 2}], "match": {"dl_type": "IP" "nw_dst": "192.168.42.0 http://127.0.0.1:8000/OF/ 255.255.255.0"}]}

If I send it like this, there will be a problem, there is no solution at present. Others say he runs without errors in the version of ovs2.5 and POX eel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 209

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report