go-openvswitch icon indicating copy to clipboard operation
go-openvswitch copied to clipboard

ofctlFlags not applied to all ovs-ofctl executions

Open brentahughes opened this issue 6 years ago • 1 comments

I've run into an issue when trying to dump flows or delete flows using Openflow14.

If I create a new client and specify the protocols it is not used on all open flow executions

client := ovs.New(
    ovs.Debug("true"),
    ovs.Debug(ovs.Protocols([]string{ovs.ProtocolOpenFlow14}),
)

client.OpenFlow.DelFlows(
    "br1",
    &ovs.MatchFlow{
        Cookie:    cookie, // cookie and mask are predefined outside this example
        CookieMask: mask,
    },
)

This results in

2019/01/03 20:51:32 ovs: exec: ovs-ofctl [del-flows br1 cookie=0x0000006000000000/0x00000fffff000000,table=0]
2019/01/03 20:51:32 ovs: exec: "2019-01-03T20:51:32Z|00001|vconn|WARN|unix:/var/run/openvswitch/br1.mgmt: version negotiation failed (we support version 0x01, peer supports version 0x05)\novs-ofctl: br1: failed to connect to socket (Broken pipe)"

If I use the patch

diff --git a/vendor/github.com/digitalocean/go-openvswitch/ovs/openflow.go b/vendor/github.com/digitalocean/go-openvswitch/ovs/openflow.go
index 7591482..8bd339a 100644
--- a/vendor/github.com/digitalocean/go-openvswitch/ovs/openflow.go
+++ b/vendor/github.com/digitalocean/go-openvswitch/ovs/openflow.go
@@ -453,6 +453,7 @@ func parseEach(in []byte, prefix []byte, fn func(b []byte) error) error {

 // exec executes an ExecFunc using 'ovs-ofctl'.
 func (o *OpenFlowService) exec(args ...string) ([]byte, error) {
+       args = append(o.c.ofctlFlags, args...)
        return o.c.exec("ovs-ofctl", args...)
 }

it adds the flag and works as expected.

2019/01/03 21:00:59 ovs: exec: ovs-ofctl [--protocols=OpenFlow14 del-flows br1 cookie=0x0000006000000000/0x00000fffff000000,table=0]
2019/01/03 21:00:59 ovs: exec: ""

My question is. Should this flag be added to every execution like it is in this patch or should it only be added for specific commands?

So far it is not added for dump-flows or del-flows which cause the above error for me. If it is safe to add to every ovs-ofctl command I can get the PR created to add it and remove the specific ones for commands. Or if there is a list of commands it should be used on I can open a PR for just those.

brentahughes avatar Jan 03 '19 21:01 brentahughes

I have the same issue with you, it seems like the ofctlFlags was not applied when the openflow command excuted.

zhangzju avatar Nov 07 '19 10:11 zhangzju