如何用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-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 o
opendaylight-user@root>
  • 连接OpenFlow换机,查看交换机上的流表
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上可以看到连上的交换机,并获取OVS的dpid=openflow:128983239877

准备xml文件

  • 创建一个文件test.xml,写入下面内容



    test_1
    31#-0
    /inv:nodes/inv:node[inv:id="openflow:128983239877"]
    false
    false
    0
    0
    980
    0
    16
    255
    
       
               
               2048
             
       
       
        6        
        
        80
           openflow:128983239877:1

    
        
            0
            
                        
                    0
                    
                        openflow:128983239877:2
                    
                    
            
        
    


    test_2
    32#-0
    /inv:nodes/inv:node[inv:id="openflow:128983239877"]
    false
    false
    0
    0
    980
    0
    16
    255
    
       
               
               2048
             
       
       
        6        
        
        443
           openflow:128983239877:1

    
        
            0
            
                        
                    0
                    
                        openflow:128983239877:2
                    
                    
            
        
    


下发流表

  • 可以使用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:[email protected]: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
如何用ODL的bulk-o-matic下发多条流表_第1张图片
Paste_Image.png
  • 效果相同,都会添加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来send DELETE
http://10.10.11.80:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:128983239877/flow-node-inventory:table/0

*查看交换机,上步添加的指定流表被删除了

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# 

扩展

  • 上面举例的xml中包含两条流表,很容易扩展到添加更多的流表,每条流表放在之间即可
  • 添加流表的问题,就转换成写xml文件的问题,这个大家就可以各显神通了

补充说明

  • 我也曾经尝试使用更习惯的JSON来写test.json,可是发现和用yangui一样,都会报错


    如何用ODL的bulk-o-matic下发多条流表_第2张图片
    Paste_Image.png
  • 用谷歌也没有搜出有用的信息,怀疑是ODL的bug
  • 如果哪位知道如何解决,还望不吝赐教

本文首发于http://www.sdnlab.com/19345.html

你可能感兴趣的:(如何用ODL的bulk-o-matic下发多条流表)