diff --git a/pkg/ovs/ovsctl/appctl.go b/pkg/ovs/ovsctl/appctl.go index c6d2310a336..1a81eb3ab7f 100644 --- a/pkg/ovs/ovsctl/appctl.go +++ b/pkg/ovs/ovsctl/appctl.go @@ -15,14 +15,11 @@ package ovsctl import ( + "bytes" "fmt" - "os/exec" "strings" ) -// File path of the ovs-vswitchd control UNIX domain socket. -const ovsVSwitchdUDS = "/var/run/openvswitch/ovs-vswitchd.*.ctl" - // Shell exits with 127 if the command to execute is not found. const exitCodeCommandNotFound = 127 @@ -128,6 +125,8 @@ func (c *ovsCtlClient) runTracing(flow string) (string, error) { if execErr != nil { return "", execErr } + // Remove "\r" to avoid format issue on Windows. + out = bytes.ReplaceAll(out, []byte("\r"), []byte("")) return string(out), nil } @@ -137,7 +136,7 @@ func (c *ovsCtlClient) runAppctlCmd(cmd string, args ...string) ([]byte, *ExecEr // to reach ovs-vswitchd using the PID. cmdStr := fmt.Sprintf("ovs-appctl -t %s %s %s", ovsVSwitchdUDS, cmd, c.bridge) cmdStr = cmdStr + " " + strings.Join(args, " ") - out, err := exec.Command("/bin/sh", "-c", cmdStr).CombinedOutput() + out, err := getOVSCommand(cmdStr).CombinedOutput() if err != nil { return nil, newExecError(err, string(out)) } diff --git a/pkg/ovs/ovsctl/ofctl.go b/pkg/ovs/ovsctl/ofctl.go index f77bc9d1ca2..33a660ba607 100644 --- a/pkg/ovs/ovsctl/ofctl.go +++ b/pkg/ovs/ovsctl/ofctl.go @@ -17,7 +17,6 @@ package ovsctl import ( "bufio" "fmt" - "os/exec" "strings" ) @@ -91,7 +90,7 @@ func (c *ovsCtlClient) DumpGroups(args ...string) ([][]string, error) { func (c *ovsCtlClient) RunOfctlCmd(cmd string, args ...string) ([]byte, error) { cmdStr := fmt.Sprintf("ovs-ofctl -O Openflow13 %s %s", cmd, c.bridge) cmdStr = cmdStr + " " + strings.Join(args, " ") - out, err := exec.Command("/bin/sh", "-c", cmdStr).Output() + out, err := getOVSCommand(cmdStr).Output() if err != nil { return nil, err } diff --git a/pkg/ovs/ovsctl/ovsctl_others.go b/pkg/ovs/ovsctl/ovsctl_others.go new file mode 100644 index 00000000000..8a1662db60a --- /dev/null +++ b/pkg/ovs/ovsctl/ovsctl_others.go @@ -0,0 +1,26 @@ +// +build linux darwin + +// Copyright 2020 Antrea Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package ovsctl + +import "os/exec" + +// File path of the ovs-vswitchd control UNIX domain socket. +const ovsVSwitchdUDS = "/var/run/openvswitch/ovs-vswitchd.*.ctl" + +func getOVSCommand(cmdStr string) *exec.Cmd { + return exec.Command("/bin/sh", "-c", cmdStr) +} diff --git a/pkg/ovs/ovsctl/ovsctl_windows.go b/pkg/ovs/ovsctl/ovsctl_windows.go new file mode 100644 index 00000000000..f8ef82bbe62 --- /dev/null +++ b/pkg/ovs/ovsctl/ovsctl_windows.go @@ -0,0 +1,26 @@ +// +build windows + +// Copyright 2020 Antrea Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package ovsctl + +import "os/exec" + +// File path of the ovs-vswitchd control named pipe. +const ovsVSwitchdUDS = "c:/openvswitch/var/run/openvswitch/ovs-vswitchd.ctl" + +func getOVSCommand(cmdStr string) *exec.Cmd { + return exec.Command("cmd.exe", "/c", cmdStr) +}