How do I add, delete, modify a flow using the ODL API or Curl?

  • 0
  • 2
  • Article
  • Updated 3 years ago
A question people frequently ask is "how to add a flow in OpenDaylight?".  This can be a little confusing because the UI for changing flows in DLUX only works with ADSAL in the Helium release and not MDSAL (which is what you will usually be using).  

There are 2 workarounds.  
  • If you want to use DLUX, you can enter flow information using the Yang UI.  
  • If you want to use the API directly or send commands to the API using curl, you can follow the directions/examples below.


You can use the below curl commands to create/retrieve/delete a flow.  For more information on creating  flows and flow matches you can refer the below links.

 

https://wiki.opendaylight.org/view/OpenDaylight_OpenFlow_Plugin:End_to_End_Flows

https://wiki.opendaylight.org/view/Editing_OpenDaylight_OpenFlow_Plugin:End_to_End_Flows:Example_Flows

 

 

Program a  flow in config datastore:

 

Create a file L3Flow and configure flow parameters

 

curl -X PUT -d @L3Flow -H "Content-Type: application/xml" -H "Accept: application/xml" --user admin:abc123 http://10.127.13.240:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:19701787512/table/0/flow/1

 

[openflow@10-127-13-225 ~]$ cat L3Flow

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<flow xmlns="urn:opendaylight:flow:inventory">

    <strict>false</strict>

    <flow-name>flow1</flow-name>

    <id>1</id>

    <cookie_mask>255</cookie_mask>

    <cookie>103</cookie>

    <table_id>0</table_id>

    <priority>20</priority>

    <hard-timeout>1800</hard-timeout>

    <idle-timeout>1800</idle-timeout>

    <installHw>true</installHw>

    <instructions>

        <instruction>

            <order>0</order>

            <apply-actions>

                <action>

                    <order>0</order>

                    <output-action>

                        <output-node-connector>22</output-node-connector>

                        <max-length>60</max-length>

                    </output-action>

                </action>

            </apply-actions>

        </instruction>

    </instructions>

    <match>

        <ethernet-match>

            <ethernet-type>

                <type>2048</type>

            </ethernet-type>

        </ethernet-match>

        <ipv4-destination>2.1.1.10/32</ipv4-destination>

    </match>

</flow>

 

* (Engineering) SW1.133 # show openflow flows

Total number of OpenFlow flows : 1

Total number of default flows  : 2

 

Flow name        Type     Duration (secs)  Prio              Packets

---------------- ---- ------------------- ----- --------------------

of_0             ACL                   12    20                    0

    Match  :  Ethernet Type       : 0x0800 (IPv4)

              IP Dst Address      : 2.1.1.10

    Actions:  output:22

    Timeout (secs/remaining secs) : hard:1800:1787,idle:1800:1787

    Cookie                        : 0x67

 

Retrieve a  flow in config datastore:

 

curl -X GET -H "Content-Type: application/json" -H "Accept: application/json" --user admin:abc123 http://10.127.13.240:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:19701787512/table/0/flow/1

 

Retrieve a  flow in operational datastore:

 

curl -X GET -H "Content-Type: application/json" -H "Accept: application/json" --user admin:abc123 http://10.127.13.240:8181/restconf/operational/opendaylight-inventory:nodes/node/openflow:19701787512/table/0/flow/1

 

Delete a  flow in operational datastore:

 

curl -X DELETE -H "Content-Type: application/json" -H "Accept: application/json" --user admin:abc123 http://10.127.13.240:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:19701787512/table/0/flow/1

 

Photo of Andrew Kinard

Andrew Kinard

  • 170 Points 100 badge 2x thumb
  • happy

Posted 4 years ago

  • 0
  • 2
Photo of Sanjay kumar

Sanjay kumar

  • 60 Points
Hello, can you please elaborate the rest API body if a user needs to change the MAC/IP address of an incoming packet at switch ?
Photo of Stephen Williams

Stephen Williams, Employee

  • 9,034 Points 5k badge 2x thumb
Sanjay,  Sorry you haven't been replied to yet.  You can just add more actions like the ones i have below.  I included IP and MAC change actions.

MAC destination address change:
<action>
    <order>1</order>
    <set-dl-dst-action>
         <address>11:22:33:44:55:66</address>
    </set-dl-dst-action>
</action>

MAC source address change:
<action>
    <order>2</order>
    <set-dl-src-action>
         <address>11:22:33:44:55:66</address>
    </set-dl-src-action>
</action>

IP source change:
<action>
    <order>3</order>
    <set-nw-src-action>
        <address>1.1.1.1</address>
    </set-nw-src-action>
</action>

IP destination change:
<action>
    <order>4</order>
    <set-nw-dst-action>
        <address>1.1.1.1</address>
    </set-nw-dst-action>
</action>
(Edited)
Photo of Emad

Emad

  • 70 Points
Can you please reply to my next comment.
(Edited)
Photo of Emad

Emad

  • 70 Points

Hi,

Based on previous comment, I try to use this xml, to force the flow to go to another destination, so I want to modify the destination address:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="urn:opendaylight:flow:inventory">
    <priority>33000</priority>
    <flow-name>Foo</flow-name>
    <match>
        <ethernet-match>
            <ethernet-type>
                <type>2048</type>
            </ethernet-type>

        </ethernet-match>

        <ipv4-destination>10.0.0.8/32</ipv4-destination>
    </match>
    <id>1</id>
    <table_id>0</table_id>
    <instructions>
        <instruction>
            <order>1</order>
            <apply-actions>
                <action>
                   <order>1</order>
                   <set-nw-dst-action>
                   <ipv4-address>10.0.0.7/32</ipv4-address>
                  </set-nw-dst-action>
               </action>
            </apply-actions>
        </instruction>
    </instructions>
</flow>

however sending REST GET request to 10.0.0.8 is not redirected to 10.0.0.7 <br>

<u>sudo ovs-ofctl -O OpenFlow13 dump-flows br-int</u>: cookie=0x0, duration=63.453s, table=0, n_packets=0, n_bytes=0, priority=33000,ip,nw_dst=10.0.0.8 actions=output:8,set_field:10.0.0.7->ip_dst

Is there any source that I can refer for adding flows, this seems to be incomplete.

(Edited)