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

  • 20 February 2015
  • 4 replies
  • 1509 views

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.
[/code]

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





false

flow1

[i]1

255

103

0

20

1800

[i]1800

[i]true

[i]

[i]

0





0



22

60

















2048





[i]2.1.1.10/32







* (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

4 replies

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 ?
Userlevel 6
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:

1

11:22:33:44:55:66




MAC source address change:

2

11:22:33:44:55:66




IP source change:

3

1.1.1.1




IP destination change:

4

1.1.1.1


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:

1

11:22:33:44:55:66




MAC source address change:

2

11:22:33:44:55:66




IP source change:

3

1.1.1.1




IP destination change:

4

1.1.1.1



Can you please reply to my next comment.
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:

code:
      33000     Foo                                            2048                                 [i]10.0.0.8/32          [i]1     0     [i]         [i]             1                                                  1                                        [i]10.0.0.7/32                                                               
[/code] however sending REST GET request to 10.0.0.8 is not redirected to 10.0.0.7
code:



code:
[u]sudo ovs-ofctl -O OpenFlow13 dump-flows br-int[/u]
:
code:
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.

Reply