SDNLAB君 发表于 2017-7-27 17:37:34

如何使用ODL的bulk-o-matic下发多条流表?

之前分享过《如何用postman控制ODL查看和下发流表》。但是在实际应用中,经常会遇到需要下发大量流表的情况。ODL的bulk-o-matic组件可以帮助我们实现这个需求。准备工作
[*]Ubuntu 14.04.4 LTS
[*]java version “1.8.0_91”
[*]distribution-karaf-0.5.2-Boron-SR2
[*]Curl & Postman
安装
[*]解压distribution-karaf-0.5.2-Boron-SR2.zip后启动ODL,安装下列组件                                                                               
                                                opendaylight-user@root>feature:install odl-restconfopendaylight-user@root>feature:install odl-l2switch-switchopendaylight-user@root>feature:install odl-mdsal-apidocsopendaylight-user@root>feature:install odl-mdsal-allopendaylight-user@root>feature:install odl-openflowplugin-app-bulk-o-maticopendaylight-user@root>feature:install odl-dlux-allopendaylight-user@root>
                                                       
                                                                                                                1
2
3
4
5
6
7

                                                                                opendaylight-user@root>feature:install odl-restconf
opendaylight-user@root>feature:install odl-l2switch-switch
opendaylight-user@root>feature:install odl-mdsal-apidocs
opendaylight-user@root>feature:install odl-mdsal-all
opendaylight-user@root>feature:install odl-openflowplugin-app-bulk-o-matic
opendaylight-user@root>feature:install odl-dlux-all
opendaylight-user@root>

                                       
                                                       
               

[*]确认组件安装成功:                                                                               
                                                opendaylight-user@root>feature:list | grep "bulk-o-matic"odl-openflowplugin-app-bulk-o-matic            | 0.3.2-Boron-SR2| x         | openflowplugin-0.3.2-Boron-SR2            | OpenDaylight :: Openflow Plugin :: Application -odl-openflowplugin-app-bulk-o-matic-he         | 0.3.2-Boron-SR2|         | openflowplugin-he-0.3.2-Boron-SR2         | OpenDaylight :: Openflow Plugin :: app bulk flow oopendaylight-user@root>
                                                       
                                                                                                                1
2
3
4

                                                                                opendaylight-user@root>feature:list | grep "bulk-o-matic"
odl-openflowplugin-app-bulk-o-matic            | 0.3.2-Boron-SR2| x         | openflowplugin-0.3.2-Boron-SR2            | OpenDaylight :: Openflow Plugin :: Application -
odl-openflowplugin-app-bulk-o-matic-he         | 0.3.2-Boron-SR2|         | openflowplugin-he-0.3.2-Boron-SR2         | OpenDaylight :: Openflow Plugin :: app bulk flow o
opendaylight-user@root>

                                       
                                                       
               

[*]连接OpenFlow换机,查看交换机上的流表:                                                                               
                                                DUT1# ovs-ofctldump-flows br0 -O openflow13OFPST_FLOW reply (OF1.3) (xid=0x2): cookie=0x2b00000000000000, duration=1551.307s, table=0, n_packets=0, n_bytes=0, priority=100,dl_type=0x88cc actions=CONTROLLER:65535 cookie=0x2b00000000000000, duration=1551.309s, table=0, n_packets=0, n_bytes=0, priority=0 actions=dropDUT1#
                                                       
                                                                                                                1
2
3
4
5

                                                                                DUT1# ovs-ofctldump-flows br0 -O openflow13
OFPST_FLOW reply (OF1.3) (xid=0x2):
cookie=0x2b00000000000000, duration=1551.307s, table=0, n_packets=0, n_bytes=0, priority=100,dl_type=0x88cc actions=CONTROLLER:65535
cookie=0x2b00000000000000, duration=1551.309s, table=0, n_packets=0, n_bytes=0, priority=0 actions=drop
DUT1#

                                       
                                                       
               

[*]在ODL的WebUI上可以看到连上的交换机,并获取OVS的dpid=openflow:128983239877。
准备xml文件
[*]创建一个文件test.xml,写入下面内容:                                                                               

                                                <?xml version="1.0" encoding="UTF-8" standalone="no"?><input xmlns="urn:opendaylight:bulk-flow:service"><bulk-flow-ds-item>    <flow-name>test_1</flow-name>    <flow-id>31#-0</flow-id>    <node xmlns:inv="urn:opendaylight:inventory">/inv:nodes/inv:node</node>    <barrier>false</barrier>    <strict>false</strict>    <hard-timeout>0</hard-timeout>    <idle-timeout>0</idle-timeout>    <priority>980</priority>    <table_id>0</table_id>    <cookie>16</cookie>    <cookie_mask>255</cookie_mask>    <match>       <ethernet-match>               <ethernet-type>               <type>2048</type>             </ethernet-type>       </ethernet-match>       <ip-match>      <ip-protocol>6</ip-protocol>                </ip-match>      <tcp-destination-port>80</tcp-destination-port>         <in-port>openflow:128983239877:1</in-port></match>    <instructions>      <instruction>            <order>0</order>            <apply-actions>                        <action>                  <order>0</order>                  <output-action>                        <output-node-connector>openflow:128983239877:2</output-node-connector>                  </output-action>                  </action>            </apply-actions>      </instruction>    </instructions></bulk-flow-ds-item><bulk-flow-ds-item>    <flow-name>test_2</flow-name>    <flow-id>32#-0</flow-id>    <node xmlns:inv="urn:opendaylight:inventory">/inv:nodes/inv:node</node>    <barrier>false</barrier>    <strict>false</strict>    <hard-timeout>0</hard-timeout>    <idle-timeout>0</idle-timeout>    <priority>980</priority>    <table_id>0</table_id>    <cookie>16</cookie>    <cookie_mask>255</cookie_mask>    <match>       <ethernet-match>               <ethernet-type>               <type>2048</type>             </ethernet-type>       </ethernet-match>       <ip-match>      <ip-protocol>6</ip-protocol>                </ip-match>      <tcp-destination-port>443</tcp-destination-port>         <in-port>openflow:128983239877:1</in-port></match>    <instructions>      <instruction>            <order>0</order>            <apply-actions>                        <action>                  <order>0</order>                  <output-action>                        <output-node-connector>openflow:128983239877:2</output-node-connector>                  </output-action>                  </action>            </apply-actions>      </instruction>    </instructions></bulk-flow-ds-item></input>
                                                       
                                                                                                                1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

                                                                                <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<input xmlns="urn:opendaylight:bulk-flow:service">
<bulk-flow-ds-item>
    <flow-name>test_1</flow-name>
    <flow-id>31#-0</flow-id>
    <node xmlns:inv="urn:opendaylight:inventory">/inv:nodes/inv:node</node>
    <barrier>false</barrier>
    <strict>false</strict>
    <hard-timeout>0</hard-timeout>
    <idle-timeout>0</idle-timeout>
    <priority>980</priority>
    <table_id>0</table_id>
    <cookie>16</cookie>
    <cookie_mask>255</cookie_mask>
    <match>
       <ethernet-match>
               <ethernet-type>
               <type>2048</type>
             </ethernet-type>
       </ethernet-match>
       <ip-match>
      <ip-protocol>6</ip-protocol>      
      </ip-match>
      <tcp-destination-port>80</tcp-destination-port>
         <in-port>openflow:128983239877:1</in-port>
</match>
    <instructions>
      <instruction>
            <order>0</order>
            <apply-actions>
                        <action>
                  <order>0</order>
                  <output-action>
                        <output-node-connector>openflow:128983239877:2</output-node-connector>
                  </output-action>
                  </action>
            </apply-actions>
      </instruction>
    </instructions>
</bulk-flow-ds-item>
<bulk-flow-ds-item>
    <flow-name>test_2</flow-name>
    <flow-id>32#-0</flow-id>
    <node xmlns:inv="urn:opendaylight:inventory">/inv:nodes/inv:node</node>
    <barrier>false</barrier>
    <strict>false</strict>
    <hard-timeout>0</hard-timeout>
    <idle-timeout>0</idle-timeout>
    <priority>980</priority>
    <table_id>0</table_id>
    <cookie>16</cookie>
    <cookie_mask>255</cookie_mask>
    <match>
       <ethernet-match>
               <ethernet-type>
               <type>2048</type>
             </ethernet-type>
       </ethernet-match>
       <ip-match>
      <ip-protocol>6</ip-protocol>      
      </ip-match>
      <tcp-destination-port>443</tcp-destination-port>
         <in-port>openflow:128983239877:1</in-port>
</match>
    <instructions>
      <instruction>
            <order>0</order>
            <apply-actions>
                        <action>
                  <order>0</order>
                  <output-action>
                        <output-node-connector>openflow:128983239877:2</output-node-connector>
                  </output-action>
                  </action>
            </apply-actions>
      </instruction>
    </instructions>
</bulk-flow-ds-item>
</input>

                                       
                                                       
               

下发流表
[*]可以使用curl进行下发流表:
                                                                               
                                                centec@ubuntu-onos-80:~/Applications$ curl -v -H "Expect:" -H "Content-Type: application/xml; charset=UTF-8" -X POST -d @test.xml http://admin:admin@10.10.11.80:8181/restconf/operations/sal-bulk-flow:add-flows-ds* Hostname was NOT found in DNS cache*   Trying 10.10.11.80...* Connected to 10.10.11.80 (10.10.11.80) port 8181 (#0)* Server auth using Basic with user 'admin'> POST /restconf/operations/sal-bulk-flow:add-flows-ds HTTP/1.1> Authorization: Basic YWRtaW46YWRtaW4=> User-Agent: curl/7.35.0> Host: 10.10.11.80:8181> Accept: */*> Content-Type: application/xml; charset=UTF-8> Content-Length: 2533> * upload completely sent off: 2533 out of 2533 bytes< HTTP/1.1 200 OK< Set-Cookie: JSESSIONID=1l76a46cmwjooy3b6r9bc2g7u;Path=/restconf< Expires: Thu, 01 Jan 1970 00:00:00 GMT< Set-Cookie: rememberMe=deleteMe; Path=/restconf; Max-Age=0; Expires=Tue, 23-May-2017 00:45:23 GMT< Content-Type: application/yang.operation+json< Content-Length: 0* Server Jetty(8.1.19.v20160209) is not blacklisted< Server: Jetty(8.1.19.v20160209)< * Connection #0 to host 10.10.11.80 left intactcentec@ubuntu-onos-80:~/Applications$
                                                       
                                                                                                                1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

                                                                                centec@ubuntu-onos-80:~/Applications$ curl -v -H "Expect:" -H "Content-Type: application/xml; charset=UTF-8" -X POST -d @test.xml http://admin:admin@10.10.11.80:8181/restconf/operations/sal-bulk-flow:add-flows-ds
* Hostname was NOT found in DNS cache
*   Trying 10.10.11.80...
* Connected to 10.10.11.80 (10.10.11.80) port 8181 (#0)
* Server auth using Basic with user 'admin'
> POST /restconf/operations/sal-bulk-flow:add-flows-ds HTTP/1.1
> Authorization: Basic YWRtaW46YWRtaW4=
> User-Agent: curl/7.35.0
> Host: 10.10.11.80:8181
> Accept: */*
> Content-Type: application/xml; charset=UTF-8
> Content-Length: 2533
>
* upload completely sent off: 2533 out of 2533 bytes
< HTTP/1.1 200 OK
< Set-Cookie: JSESSIONID=1l76a46cmwjooy3b6r9bc2g7u;Path=/restconf
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
< Set-Cookie: rememberMe=deleteMe; Path=/restconf; Max-Age=0; Expires=Tue, 23-May-2017 00:45:23 GMT
< Content-Type: application/yang.operation+json
< Content-Length: 0
* Server Jetty(8.1.19.v20160209) is not blacklisted
< Server: Jetty(8.1.19.v20160209)
<
* Connection #0 to host 10.10.11.80 left intact
centec@ubuntu-onos-80:~/Applications$

                                       
                                                       
               

[*]或者 使用postman下发,将test.xml的内容,复制粘贴到postman的body,send POST。
http://img1.sdnlab.com/wp-content/uploads/2017/06/ODL-bulk-o-matic-fig-1.png
[*]效果相同,都会添加xml描述的两条流表:                                                                               
                                                DUT1# ovs-ofctldump-flows br0 -O openflow13OFPST_FLOW reply (OF1.3) (xid=0x2): cookie=0x10, duration=1.6s, table=0, n_packets=0, n_bytes=0, priority=980,tcp,in_port=1,tp_dst=80 actions=output:2 cookie=0x10, duration=1.598s, table=0, n_packets=0, n_bytes=0, priority=980,tcp,in_port=1,tp_dst=443 actions=output:2 cookie=0x2b00000000000000, duration=1562.955s, table=0, n_packets=0, n_bytes=0, priority=100,dl_type=0x88cc actions=CONTROLLER:65535 cookie=0x2b00000000000000, duration=1562.957s, table=0, n_packets=0, n_bytes=0, priority=0 actions=dropDUT1#
                                                       
                                                                                                                1
2
3
4
5
6
7

                                                                                DUT1# ovs-ofctldump-flows br0 -O openflow13
OFPST_FLOW reply (OF1.3) (xid=0x2):
cookie=0x10, duration=1.6s, table=0, n_packets=0, n_bytes=0, priority=980,tcp,in_port=1,tp_dst=80 actions=output:2
cookie=0x10, duration=1.598s, table=0, n_packets=0, n_bytes=0, priority=980,tcp,in_port=1,tp_dst=443 actions=output:2
cookie=0x2b00000000000000, duration=1562.955s, table=0, n_packets=0, n_bytes=0, priority=100,dl_type=0x88cc actions=CONTROLLER:65535
cookie=0x2b00000000000000, duration=1562.957s, table=0, n_packets=0, n_bytes=0, priority=0 actions=drop
DUT1#

                                       
                                                       
               

删除流表
[*]依然使用curl或是postman来send DELETE:                                                                               
                                                http://10.10.11.80:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:128983239877/flow-node-inventory:table/0
                                                       
                                                                                                                1

                                                                                http://10.10.11.80:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:128983239877/flow-node-inventory:table/0

                                       
                                                       
               
*查看交换机,上步添加的指定流表被删除了。                                                                               
                                                DUT1# ovs-ofctldump-flows br0 -O openflow13OFPST_FLOW reply (OF1.3) (xid=0x2): cookie=0x2b00000000000000, duration=1551.307s, table=0, n_packets=0, n_bytes=0, priority=100,dl_type=0x88cc actions=CONTROLLER:65535 cookie=0x2b00000000000000, duration=1551.309s, table=0, n_packets=0, n_bytes=0, priority=0 actions=dropDUT1#
                                                       
                                                                                                                1
2
3
4
5

                                                                                DUT1# ovs-ofctldump-flows br0 -O openflow13
OFPST_FLOW reply (OF1.3) (xid=0x2):
cookie=0x2b00000000000000, duration=1551.307s, table=0, n_packets=0, n_bytes=0, priority=100,dl_type=0x88cc actions=CONTROLLER:65535
cookie=0x2b00000000000000, duration=1551.309s, table=0, n_packets=0, n_bytes=0, priority=0 actions=drop
DUT1#

                                       
                                                       
               

扩展
[*]上面举例的xml中包含两条流表,很容易扩展到添加更多的流表,每条流表放在和之间即可。
[*]添加流表的问题,就转换成写xml文件的问题,这个大家就可以各显神通了。
补充说明
[*]我也曾经尝试使用更习惯的JSON来写test.json,可是发现和用yangui一样,都会报错;
http://img1.sdnlab.com/wp-content/uploads/2017/06/ODL-bulk-o-matic.png
[*]用谷歌也没有搜出有用的信息,怀疑是ODL的bug;
[*]如果哪位知道如何解决,还望不吝赐教。
[*]《SDN实战特训营第七期》课程详情 http://edu.sdnlab.com/training/480.html 转发文章至朋友圈,咨询报名即可享受9.5折优惠
                                                                       
                       

页: [1]
查看完整版本: 如何使用ODL的bulk-o-matic下发多条流表?