[ovs-discuss] Adding/Removing Flows Programmatically in C Application

Ben Warren ben at skyportsystems.com
Mon Oct 16 22:24:44 UTC 2017

Hi Tommy,

Here’s how I do it.  It’s essentially the same as what the ‘ovs-ofctl add-flow’ command does under the hood.

1. Build a string formatted as the “ovs-ofctl” command would do, for example “table=1,cookie=0xdeadbeef,in_port=1,actions=resubmit(,2)”
2. Pass this to parser_ofp_flow_mod_str().  The parser will magically parse the string in to a rich struct.
3. Pass the struct to ofputil_encode_flow_mod().  This returns a struct with a serialized OpenFlow message buffer.
4. Send this buffer on the wire either via a socket you manage yourself or let OpenVswitch do it for you.


> On Oct 16, 2017, at 2:05 PM, Tommy Romano <tomrom95 at fb.com> wrote:
> My project was previously calling system commands like ‘ovs-ofctl add-flow’ directly from C, but we would like to do this programmatically now, by calling into the openvswitch library. After looking at this for a bit and what methods I would have to call, I’ve realized this is non trivial, and I can’t find any easily exposed methods to add and delete flows. Does anyone have an example anywhere of calling into openvswitch methods directly to add/remove flows? So far the best way I can find is calling into ovn/controller/ofctrl.h:ofctrl_add_flow(…), but this will require quite a bit of legwork.
> Best,
> Tommy Romano
> _______________________________________________
> discuss mailing list
> discuss at openvswitch.org <mailto:discuss at openvswitch.org>
> https://mail.openvswitch.org/mailman/listinfo/ovs-discuss <https://mail.openvswitch.org/mailman/listinfo/ovs-discuss>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openvswitch.org/pipermail/ovs-discuss/attachments/20171016/8deb4b3e/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3866 bytes
Desc: not available
URL: <http://mail.openvswitch.org/pipermail/ovs-discuss/attachments/20171016/8deb4b3e/attachment-0001.p7s>

More information about the discuss mailing list