之前分享過(guò)《如何用postman控制ODL查看和下發(fā)流表》。但是在實(shí)際應(yīng)用中瞧筛,經(jīng)常會(huì)遇到需要下發(fā)大量流表的情況厉熟。ODL的bulk-o-matic組件可以幫助我們實(shí)現(xiàn)這個(gè)需求。
準(zhǔn)備工作
- 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后啟動(dòng)ODL较幌,安裝下列組件
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>
- 確認(rèn)組件安裝成功
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換機(jī)揍瑟,查看交換機(jī)上的流表
DUT1# ovs-ofctl dump-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上可以看到連上的交換機(jī),并獲取OVS的dpid=openflow:128983239877
準(zhǔn)備xml文件
- 創(chuàng)建一個(gè)文件test.xml乍炉,寫(xiě)入下面內(nèi)容
<?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[inv:id="openflow:128983239877"]</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[inv:id="openflow:128983239877"]</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>
下發(fā)流表
- 可以使用curl下發(fā)
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下發(fā)绢片,將test.xml的內(nèi)容滤馍,復(fù)制粘貼到postman的body,send POST
- 效果相同底循,都會(huì)添加xml描述的兩條流表
DUT1# ovs-ofctl dump-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來(lái)send DELETE
http://10.10.11.80:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:128983239877/flow-node-inventory:table/0
*查看交換機(jī),上步添加的指定流表被刪除了
DUT1# ovs-ofctl dump-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#
擴(kuò)展
- 上面舉例的xml中包含兩條流表巢株,很容易擴(kuò)展到添加更多的流表,每條流表放在<bulk-flow-ds-item>和</bulk-flow-ds-item>之間即可
- 添加流表的問(wèn)題熙涤,就轉(zhuǎn)換成寫(xiě)xml文件的問(wèn)題阁苞,這個(gè)大家就可以各顯神通了
補(bǔ)充說(shuō)明
-
我也曾經(jīng)嘗試使用更習(xí)慣的JSON來(lái)寫(xiě)test.json,可是發(fā)現(xiàn)和用yangui一樣祠挫,都會(huì)報(bào)錯(cuò)
- 用谷歌也沒(méi)有搜出有用的信息那槽,懷疑是ODL的bug
- 如果哪位知道如何解決,還望不吝賜教
本文首發(fā)于http://www.sdnlab.com/19345.html