diff --git a/pkg/networkservice/l2ovsconnect/local.go b/pkg/networkservice/l2ovsconnect/local.go index af8116c..10ecbe9 100644 --- a/pkg/networkservice/l2ovsconnect/local.go +++ b/pkg/networkservice/l2ovsconnect/local.go @@ -1,6 +1,6 @@ -// Copyright (c) 2021 Nordix Foundation. +// Copyright (c) 2021-2024 Nordix Foundation. // -// Copyright (c) 2023 Cisco and/or its affiliates. +// Copyright (c) 2023-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -22,10 +22,10 @@ import ( "fmt" "github.com/networkservicemesh/sdk/pkg/tools/log" - "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/util" "github.com/pkg/errors" "github.com/networkservicemesh/sdk-ovs/pkg/tools/ifnames" + "github.com/networkservicemesh/sdk-ovs/pkg/tools/utils" ) func createLocalCrossConnect(logger log.Logger, bridgeName string, endpointOvsPortInfo, @@ -44,7 +44,8 @@ func createLocalCrossConnect(logger log.Logger, bridgeName string, endpointOvsPo ofRuleToEndpoint = fmt.Sprintf("priority=100,in_port=%d,"+ "actions=output:%d", clientOvsPortInfo.PortNo, endpointOvsPortInfo.PortNo) } - stdout, stderr, err := util.RunOVSOfctl("add-flow", "-OOpenflow13", bridgeName, ofRuleToClient) + w := &utils.OVSRunWrapper{Logger: logger} + stdout, stderr, err := w.RunOVSOfctl("add-flow", "-OOpenflow13", bridgeName, ofRuleToClient) if err != nil { logger.Infof("Failed to add flow on %s for port %s stdout: %s"+ " stderr: %s, error: %v", bridgeName, endpointOvsPortInfo.PortName, stdout, stderr, err) @@ -55,7 +56,7 @@ func createLocalCrossConnect(logger log.Logger, bridgeName string, endpointOvsPo " stderr: %s", bridgeName, endpointOvsPortInfo.PortName, stdout, stderr) } - stdout, stderr, err = util.RunOVSOfctl("add-flow", "-OOpenflow13", bridgeName, ofRuleToEndpoint) + stdout, stderr, err = w.RunOVSOfctl("add-flow", "-OOpenflow13", bridgeName, ofRuleToEndpoint) if err != nil { logger.Errorf("Failed to add flow on %s for port %s stdout: %s"+ " stderr: %s, error: %v", bridgeName, clientOvsPortInfo.PortName, stdout, stderr, err) @@ -81,14 +82,15 @@ func deleteLocalCrossConnect(logger log.Logger, bridgeName string, endpointOvsPo } else { matchForEndpoint = fmt.Sprintf("in_port=%d", endpointOvsPortInfo.PortNo) } - stdout, stderr, err := util.RunOVSOfctl("del-flows", "-OOpenflow13", bridgeName, matchForEndpoint) + w := &utils.OVSRunWrapper{Logger: logger} + stdout, stderr, err := w.RunOVSOfctl("del-flows", "-OOpenflow13", bridgeName, matchForEndpoint) if err != nil { logger.Errorf("Failed to delete flow on %s for port "+ "%s, stdout: %q, stderr: %q, error: %v", bridgeName, endpointOvsPortInfo.PortName, stdout, stderr, err) return errors.Wrapf(err, "failed to delete flow on %s for port %s, stdout: %q, stderr: %q", bridgeName, endpointOvsPortInfo.PortName, stdout, stderr) } - stdout, stderr, err = util.RunOVSOfctl("del-flows", "-OOpenflow13", bridgeName, fmt.Sprintf("in_port=%d", clientOvsPortInfo.PortNo)) + stdout, stderr, err = w.RunOVSOfctl("del-flows", "-OOpenflow13", bridgeName, fmt.Sprintf("in_port=%d", clientOvsPortInfo.PortNo)) if err != nil { logger.Errorf("Failed to delete flow on %s for port "+ "%s, stdout: %q, stderr: %q, error: %v", bridgeName, clientOvsPortInfo.PortName, stdout, stderr, err) diff --git a/pkg/networkservice/l2ovsconnect/remote.go b/pkg/networkservice/l2ovsconnect/remote.go index d934169..ebe57e3 100644 --- a/pkg/networkservice/l2ovsconnect/remote.go +++ b/pkg/networkservice/l2ovsconnect/remote.go @@ -1,6 +1,6 @@ -// Copyright (c) 2021 Nordix Foundation. +// Copyright (c) 2021-2024 Nordix Foundation. // -// Copyright (c) 2023 Cisco and/or its affiliates. +// Copyright (c) 2023-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -22,10 +22,10 @@ import ( "fmt" "github.com/networkservicemesh/sdk/pkg/tools/log" - "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/util" "github.com/pkg/errors" "github.com/networkservicemesh/sdk-ovs/pkg/tools/ifnames" + "github.com/networkservicemesh/sdk-ovs/pkg/tools/utils" ) func createRemoteCrossConnect(logger log.Logger, bridgeName string, endpointOvsPortInfo, clientOvsPortInfo *ifnames.OvsPortInfo) error { @@ -60,7 +60,8 @@ func createRemoteCrossConnect(logger log.Logger, bridgeName string, endpointOvsP ovsLocalPortNum, vni, ovsTunnelPortNum) ofRuleTo = fmt.Sprintf("priority=100,in_port=%d,tun_id=%d,actions=output:%d", ovsTunnelPortNum, vni, ovsLocalPortNum) } - stdout, stderr, err := util.RunOVSOfctl("add-flow", "-OOpenflow13", bridgeName, ofRuleFrom) + w := &utils.OVSRunWrapper{Logger: logger} + stdout, stderr, err := w.RunOVSOfctl("add-flow", "-OOpenflow13", bridgeName, ofRuleFrom) if err != nil { logger.Errorf("Failed to add flow on %s for port %s stdout: %s"+ " stderr: %s, error: %v", bridgeName, ovsLocalPort, stdout, stderr, err) @@ -70,14 +71,12 @@ func createRemoteCrossConnect(logger log.Logger, bridgeName string, endpointOvsP logger.Errorf("Failed to add flow on %s for port %s stdout: %s"+ " stderr: %s", bridgeName, ovsLocalPort, stdout, stderr) } - - stdout, stderr, err = util.RunOVSOfctl("add-flow", "-OOpenflow13", bridgeName, ofRuleTo) + stdout, stderr, err = w.RunOVSOfctl("add-flow", "-OOpenflow13", bridgeName, ofRuleTo) if err != nil { logger.Errorf("Failed to add tunnel flow on %s for port %s stdout: %s"+ " stderr: %s, error: %v", bridgeName, ovsTunnelPort, stdout, stderr, err) return errors.Wrapf(err, "failed to add tunnel flow on %s for port %s stdout: %s, stderr: %s", bridgeName, ovsTunnelPort, stdout, stderr) } - if stderr != "" { logger.Errorf("Failed to add tunnel flow on %s for port %s stdout: %s"+ " stderr: %s", bridgeName, ovsTunnelPort, stdout, stderr) @@ -110,19 +109,19 @@ func deleteRemoteCrossConnect(logger log.Logger, bridgeName string, endpointOvsP vni = clientOvsPortInfo.VNI } var ofMatch string + w := &utils.OVSRunWrapper{Logger: logger} if vlanID > 0 { ofMatch = fmt.Sprintf("in_port=%d,dl_vlan=%d", ovsLocalPortNum, vlanID) } else { ofMatch = fmt.Sprintf("in_port=%d", ovsLocalPortNum) } - stdout, stderr, err := util.RunOVSOfctl("del-flows", "-OOpenflow13", bridgeName, ofMatch) + stdout, stderr, err := w.RunOVSOfctl("del-flows", "-OOpenflow13", bridgeName, ofMatch) if err != nil { logger.Errorf("Failed to delete flow on %s for port "+ "%s, stdout: %q, stderr: %q, error: %v", bridgeName, ovsLocalPort, stdout, stderr, err) return errors.Wrapf(err, "Failed to delete flow on %s for port %s, stdout: %q, stderr: %q", bridgeName, ovsLocalPort, stdout, stderr) } - - stdout, stderr, err = util.RunOVSOfctl("del-flows", "-OOpenflow13", bridgeName, fmt.Sprintf("in_port=%d,tun_id=%d", ovsTunnelPortNum, vni)) + stdout, stderr, err = w.RunOVSOfctl("del-flows", "-OOpenflow13", bridgeName, fmt.Sprintf("in_port=%d,tun_id=%d", ovsTunnelPortNum, vni)) if err != nil { logger.Errorf("Failed to delete flow on %s for port "+ "%s on VNI %d, stdout: %q, stderr: %q, error: %v", bridgeName, ovsTunnelPort, vni, stdout, stderr, err) diff --git a/pkg/networkservice/mechanisms/kernel/common.go b/pkg/networkservice/mechanisms/kernel/common.go index 93a5241..0382522 100644 --- a/pkg/networkservice/mechanisms/kernel/common.go +++ b/pkg/networkservice/mechanisms/kernel/common.go @@ -1,6 +1,6 @@ -// Copyright (c) 2021-2022 Nordix Foundation. +// Copyright (c) 2021-2024 Nordix Foundation. // -// Copyright (c) 2023 Cisco and/or its affiliates. +// Copyright (c) 2023-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -30,7 +30,6 @@ import ( "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/kernel" "github.com/networkservicemesh/sdk-kernel/pkg/kernel/networkservice/vfconfig" "github.com/networkservicemesh/sdk/pkg/tools/log" - "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/util" "github.com/pkg/errors" "github.com/vishvananda/netlink" @@ -87,7 +86,8 @@ func setupVeth(ctx context.Context, logger log.Logger, conn *networkservice.Conn } if _, exists := parentIfRefCountMap[hostIfName]; !exists { - stdout, stderr, err := util.RunOVSVsctl("--", "--may-exist", "add-port", bridgeName, hostIfName) + w := &ovsutil.OVSRunWrapper{Logger: logger} + stdout, stderr, err := w.RunOVSVsctl("--", "--may-exist", "add-port", bridgeName, hostIfName) if err != nil { logger.Errorf("Failed to add port %s to %s, stdout: %q, stderr: %q,"+ " error: %v", hostIfName, bridgeName, stdout, stderr, err) @@ -145,8 +145,9 @@ func resetVeth(ctx context.Context, logger log.Logger, conn *networkservice.Conn if refCount == 0 { if !isL2Connect { + w := &ovsutil.OVSRunWrapper{Logger: logger} /* delete the port from ovs bridge and this op is valid only for p2p OF ports */ - stdout, stderr, err := util.RunOVSVsctl("del-port", bridgeName, ifaceName) + stdout, stderr, err := w.RunOVSVsctl("del-port", bridgeName, ifaceName) if err != nil { logger.Errorf("Failed to delete port %s from %s, stdout: %q, stderr: %q,"+ " error: %v", ifaceName, bridgeName, stdout, stderr, err) diff --git a/pkg/networkservice/mechanisms/kernel/sriov.go b/pkg/networkservice/mechanisms/kernel/sriov.go index 2380ddd..589ec08 100644 --- a/pkg/networkservice/mechanisms/kernel/sriov.go +++ b/pkg/networkservice/mechanisms/kernel/sriov.go @@ -1,6 +1,6 @@ -// Copyright (c) 2021-2022 Nordix Foundation. +// Copyright (c) 2021-2024 Nordix Foundation. // -// Copyright (c) 2023 Cisco and/or its affiliates. +// Copyright (c) 2023-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -29,7 +29,6 @@ import ( "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/kernel" "github.com/networkservicemesh/sdk-kernel/pkg/kernel/networkservice/vfconfig" "github.com/networkservicemesh/sdk/pkg/tools/log" - "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/util" "github.com/pkg/errors" "github.com/networkservicemesh/sdk-ovs/pkg/tools/ifnames" @@ -59,7 +58,8 @@ func setupVF(ctx context.Context, logger log.Logger, conn *networkservice.Connec return errors.Wrapf(err, "failed to find VF representor for uplink %s", vfConfig.PFInterfaceName) } if _, exists := parentIfRefCount[vfRepresentor]; !exists { - stdout, stderr, err1 := util.RunOVSVsctl("--", "--may-exist", "add-port", bridgeName, vfRepresentor) + w := &ovsutil.OVSRunWrapper{Logger: logger} + stdout, stderr, err1 := w.RunOVSVsctl("--", "--may-exist", "add-port", bridgeName, vfRepresentor) if err1 != nil { logger.Errorf("Failed to add representor port %s to %s, stdout: %q, stderr: %q,"+ " error: %v", vfRepresentor, bridgeName, stdout, stderr, err1) @@ -91,8 +91,9 @@ func resetVF(logger log.Logger, portInfo *ifnames.OvsPortInfo, parentIfRefCountM } if refCount == 0 { if !isL2Connect { + w := &ovsutil.OVSRunWrapper{Logger: logger} // this op is valid only for p2p connection - stdout, stderr, err := util.RunOVSVsctl("del-port", bridgeName, portInfo.PortName) + stdout, stderr, err := w.RunOVSVsctl("del-port", bridgeName, portInfo.PortName) if err != nil { logger.Errorf("Failed to delete port %s from %s, stdout: %q, stderr: %q,"+ " error: %v", portInfo.PortName, bridgeName, stdout, stderr, err) diff --git a/pkg/networkservice/mechanisms/vlan/client.go b/pkg/networkservice/mechanisms/vlan/client.go index c3a2566..9a573f2 100644 --- a/pkg/networkservice/mechanisms/vlan/client.go +++ b/pkg/networkservice/mechanisms/vlan/client.go @@ -1,6 +1,6 @@ -// Copyright (c) 2021-2022 Nordix Foundation. +// Copyright (c) 2021-2024 Nordix Foundation. // -// Copyright (c) 2023 Cisco and/or its affiliates. +// Copyright (c) 2023-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -26,8 +26,6 @@ import ( "context" "fmt" - "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/util" - "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/networkservice" "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/cls" @@ -119,15 +117,16 @@ func (c *vlanClient) addDelVlan(ctx context.Context, logger log.Logger, conn *ne if !ok { return nil } + w := &ovsutil.OVSRunWrapper{Logger: logger} if isAdd { // delete the ns client port from br-nsm bridge and add it into l2 connect bridge with vlan tag. - stdout, stderr, err := util.RunOVSVsctl("del-port", c.bridgeName, nsClientOvsPortInfo.PortName) + stdout, stderr, err := w.RunOVSVsctl("del-port", c.bridgeName, nsClientOvsPortInfo.PortName) if err != nil { logger.Errorf("Failed to delete port %s from %s, stdout: %q, stderr: %q,"+ " error: %v", nsClientOvsPortInfo.PortName, c.bridgeName, stdout, stderr, err) return errors.Wrapf(err, "Failed to delete port %s from %s, stdout: %q, stderr: %q", nsClientOvsPortInfo.PortName, c.bridgeName, stdout, stderr) } - stdout, stderr, err = util.RunOVSVsctl("--", "--may-exist", "add-port", l2Point.Bridge, + stdout, stderr, err = w.RunOVSVsctl("--", "--may-exist", "add-port", l2Point.Bridge, nsClientOvsPortInfo.PortName, fmt.Sprintf("tag=%d", mechanism.GetVlanID())) if err != nil { logger.Errorf("Failed to add port %s to %s, stdout: %q, stderr: %q,"+ @@ -137,7 +136,7 @@ func (c *vlanClient) addDelVlan(ctx context.Context, logger log.Logger, conn *ne nsClientOvsPortInfo.IsL2Connect = true nsClientOvsPortInfo.IsCrossConnected = true } else { - stdout, stderr, err := util.RunOVSVsctl("del-port", l2Point.Bridge, nsClientOvsPortInfo.PortName) + stdout, stderr, err := w.RunOVSVsctl("del-port", l2Point.Bridge, nsClientOvsPortInfo.PortName) if err != nil { logger.Errorf("Failed to delete port %s from %s, stdout: %q, stderr: %q,"+ " error: %v", nsClientOvsPortInfo.PortName, l2Point.Bridge, stdout, stderr, err) diff --git a/pkg/networkservice/mechanisms/vxlan/client.go b/pkg/networkservice/mechanisms/vxlan/client.go index c7e5751..e639b4d 100644 --- a/pkg/networkservice/mechanisms/vxlan/client.go +++ b/pkg/networkservice/mechanisms/vxlan/client.go @@ -94,7 +94,7 @@ func (c *vxlanClient) Request(ctx context.Context, request *networkservice.Netwo func (c *vxlanClient) Close(ctx context.Context, conn *networkservice.Connection, opts ...grpc.CallOption) (*empty.Empty, error) { _, err := next.Client(ctx).Close(ctx, conn, opts...) - vxlanClientErr := remove(conn, c.bridgeName, c.vxlanInterfacesMutex, c.vxlanInterfacesMap, true) + vxlanClientErr := remove(conn, c.bridgeName, c.vxlanInterfacesMutex, c.vxlanInterfacesMap, true, log.FromContext(ctx).WithField("vxlanClient", "Close")) if err != nil && vxlanClientErr != nil { return nil, errors.Wrap(err, vxlanClientErr.Error()) diff --git a/pkg/networkservice/mechanisms/vxlan/common.go b/pkg/networkservice/mechanisms/vxlan/common.go index adb498c..1a59aca 100644 --- a/pkg/networkservice/mechanisms/vxlan/common.go +++ b/pkg/networkservice/mechanisms/vxlan/common.go @@ -1,6 +1,6 @@ -// Copyright (c) 2021-2024 Nordix Foundation. +// Copyright (c) 2021-2022 Nordix Foundation. // -// Copyright (c) 2023-2024 Cisco and/or its affiliates. +// Copyright (c) 2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -31,7 +31,6 @@ import ( "github.com/networkservicemesh/api/pkg/api/networkservice" "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/vxlan" "github.com/networkservicemesh/sdk/pkg/tools/log" - "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/util" "github.com/pkg/errors" "github.com/networkservicemesh/sdk-ovs/pkg/tools/ifnames" @@ -69,7 +68,7 @@ func add(ctx context.Context, logger log.Logger, conn *networkservice.Connection vxlanInterfacesMutex.Lock() defer vxlanInterfacesMutex.Unlock() if _, exists := vxlanRefCountMap[ovsTunnelName]; !exists { - if err := newVXLAN(bridgeName, ovsTunnelName, egressIP, remoteIP, port); err != nil { + if err := newVXLAN(bridgeName, ovsTunnelName, egressIP, remoteIP, port, logger); err != nil { return err } vxlanRefCountMap[ovsTunnelName] = 0 @@ -90,7 +89,7 @@ func getTunnelPortName(remoteIP string) string { } func remove(conn *networkservice.Connection, bridgeName string, vxlanInterfacesMutex sync.Locker, - vxlanRefCountMap map[string]int, isClient bool) error { + vxlanRefCountMap map[string]int, isClient bool, logger log.Logger) error { if mechanism := vxlan.ToMechanism(conn.GetMechanism()); mechanism != nil { var remoteIP net.IP if !isClient { @@ -102,7 +101,7 @@ func remove(conn *networkservice.Connection, bridgeName string, vxlanInterfacesM vxlanInterfacesMutex.Lock() defer vxlanInterfacesMutex.Unlock() if count := vxlanRefCountMap[ovsTunnelName]; count == 1 { - if err := deleteVXLAN(bridgeName, ovsTunnelName); err != nil { + if err := deleteVXLAN(bridgeName, ovsTunnelName, logger); err != nil { return err } delete(vxlanRefCountMap, ovsTunnelName) @@ -114,12 +113,14 @@ func remove(conn *networkservice.Connection, bridgeName string, vxlanInterfacesM } // newVXLAN creates a VXLAN interface instance in OVS -func newVXLAN(bridgeName, ovsTunnelName string, egressIP, remoteIP net.IP, dstPort uint16) error { +func newVXLAN(bridgeName, ovsTunnelName string, egressIP, remoteIP net.IP, dstPort uint16, logger log.Logger) error { /* Populate the VXLAN interface configuration */ localOptions := "options:local_ip=" + egressIP.String() remoteOptions := "options:remote_ip=" + remoteIP.String() portOption := "options:dst_port=" + strconv.FormatUint(uint64(dstPort), 10) - stdout, stderr, err := util.RunOVSVsctl("--", "--may-exist", "add-port", bridgeName, ovsTunnelName, + + w := ovsutil.OVSRunWrapper{Logger: logger} + stdout, stderr, err := w.RunOVSVsctl("--", "--may-exist", "add-port", bridgeName, ovsTunnelName, "--", "set", "interface", ovsTunnelName, "type=vxlan", localOptions, remoteOptions, portOption, "options:key=flow") if err != nil { @@ -129,9 +130,10 @@ func newVXLAN(bridgeName, ovsTunnelName string, egressIP, remoteIP net.IP, dstPo return nil } -func deleteVXLAN(bridgeName, ovsTunnelPort string) error { +func deleteVXLAN(bridgeName, ovsTunnelPort string, logger log.Logger) error { + w := ovsutil.OVSRunWrapper{Logger: logger} /* Populate the VXLAN interface configuration */ - stdout, stderr, err := util.RunOVSVsctl("del-port", bridgeName, ovsTunnelPort) + stdout, stderr, err := w.RunOVSVsctl("del-port", bridgeName, ovsTunnelPort) if err != nil { return errors.Errorf("Failed to delete port %s to %s, stdout: %q, stderr: %q,"+ " error: %v", ovsTunnelPort, bridgeName, stdout, stderr, err) diff --git a/pkg/networkservice/mechanisms/vxlan/server.go b/pkg/networkservice/mechanisms/vxlan/server.go index e47ce40..5bb56eb 100644 --- a/pkg/networkservice/mechanisms/vxlan/server.go +++ b/pkg/networkservice/mechanisms/vxlan/server.go @@ -81,7 +81,7 @@ func (v *vxlanServer) Request(ctx context.Context, request *networkservice.Netwo closeCtx, cancelClose := postponeCtxFunc() defer cancelClose() if _, exists := ifnames.LoadAndDelete(closeCtx, metadata.IsClient(v)); exists { - if vxlanServerErr := remove(request.GetConnection(), v.bridgeName, v.vxlanInterfacesMutex, v.vxlanInterfacesMap, metadata.IsClient(v)); vxlanServerErr != nil { + if vxlanServerErr := remove(request.GetConnection(), v.bridgeName, v.vxlanInterfacesMutex, v.vxlanInterfacesMap, metadata.IsClient(v), logger); vxlanServerErr != nil { err = errors.Wrapf(err, "connection closed with error: %s", vxlanServerErr.Error()) } } @@ -94,7 +94,7 @@ func (v *vxlanServer) Request(ctx context.Context, request *networkservice.Netwo func (v *vxlanServer) Close(ctx context.Context, conn *networkservice.Connection) (*empty.Empty, error) { _, err := next.Server(ctx).Close(ctx, conn) if mechanism := vxlan.ToMechanism(conn.GetMechanism()); mechanism != nil { - vxlanServerErr := remove(conn, v.bridgeName, v.vxlanInterfacesMutex, v.vxlanInterfacesMap, metadata.IsClient(v)) + vxlanServerErr := remove(conn, v.bridgeName, v.vxlanInterfacesMutex, v.vxlanInterfacesMap, metadata.IsClient(v), log.FromContext(ctx).WithField("vxlanServer", "Close")) ifnames.Delete(ctx, metadata.IsClient(v)) if err != nil && vxlanServerErr != nil { diff --git a/pkg/tools/utils/log.go b/pkg/tools/utils/log.go new file mode 100644 index 0000000..66b7ca9 --- /dev/null +++ b/pkg/tools/utils/log.go @@ -0,0 +1,54 @@ +// Copyright (c) 2024 Nordix Foundation. +// +// SPDX-License-Identifier: Apache-2.0 +// +// 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 utils provides helper methods related to ovs and ip parsing +package utils + +import ( + "github.com/networkservicemesh/sdk/pkg/tools/log" + "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/util" +) + +// OVSRunWrapper - +type OVSRunWrapper struct { + Logger log.Logger +} + +// RunOVSVsctl - wrapper function for github.com/ovn-org/ovn-kubernetes/go-controller/pkg/util.RunOVSVsctl +func (w *OVSRunWrapper) RunOVSVsctl(args ...string) (stdout, stderr string, err error) { + stdout, stderr, err = util.RunOVSVsctl(args...) + defer func() { + cmdStr := []string{"ovs-vsctl"} + cmdStr = append(cmdStr, args...) + w.Logger.WithField("RunOVSVsctl", cmdStr). + WithField("stdout", stdout). + Debug("completed") + }() + return stdout, stderr, err +} + +// RunOVSOfctl - wrapper function for github.com/ovn-org/ovn-kubernetes/go-controller/pkg/util.RunOVSOfctl +func (w *OVSRunWrapper) RunOVSOfctl(args ...string) (stdout, stderr string, err error) { + stdout, stderr, err = util.RunOVSOfctl(args...) + defer func() { + cmdStr := []string{"ovs-ofctl"} + cmdStr = append(cmdStr, args...) + w.Logger.WithField("RunOVSOfctl", cmdStr). + WithField("stdout", stdout). + Debug("completed") + }() + return stdout, stderr, err +} diff --git a/pkg/tools/utils/ovs.go b/pkg/tools/utils/ovs.go index 9deb73f..2f5e612 100644 --- a/pkg/tools/utils/ovs.go +++ b/pkg/tools/utils/ovs.go @@ -1,6 +1,6 @@ -// Copyright (c) 2021-2022 Nordix Foundation. +// Copyright (c) 2021-2024 Nordix Foundation. // -// Copyright (c) 2023 Cisco and/or its affiliates. +// Copyright (c) 2023-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -45,7 +45,8 @@ func GetInterfaceOfPort(logger log.Logger, interfaceName string) (int, error) { var portNo, count int count = 5 for count > 0 { - ofPort, stdErr, err := util.RunOVSVsctl("--if-exists", "get", "interface", interfaceName, "ofport") + w := &OVSRunWrapper{Logger: logger} + ofPort, stdErr, err := w.RunOVSVsctl("--if-exists", "get", "interface", interfaceName, "ofport") if err != nil { return -1, errors.Wrap(err, "failed to run command via ovs-vsctl") } @@ -75,10 +76,12 @@ func ConfigureOvS(ctx context.Context, l2Connections map[string]*L2ConnectionPoi log.FromContext(ctx).Warnf("failed to initialize ovs exec helper: %v", err) } + logger := log.FromContext(ctx).WithField("utils", "ConfigureOvS") + w := &OVSRunWrapper{Logger: logger} for _, cp := range l2Connections { if cp.Bridge != "" { // Create ovs bridge for l2 egress point - stdout, stderr, err := util.RunOVSVsctl("--", "--may-exist", "add-br", cp.Bridge) + stdout, stderr, err := w.RunOVSVsctl("--", "--may-exist", "add-br", cp.Bridge) if err != nil { log.FromContext(ctx).Warnf("Failed to add bridge %s, stdout: %q, stderr: %q, error: %v", bridgeName, stdout, stderr, err) } @@ -93,13 +96,13 @@ func ConfigureOvS(ctx context.Context, l2Connections map[string]*L2ConnectionPoi } // Create ovs bridge for client and endpoint connections - stdout, stderr, err := util.RunOVSVsctl("--", "--may-exist", "add-br", bridgeName) + stdout, stderr, err := w.RunOVSVsctl("--", "--may-exist", "add-br", bridgeName) if err != nil { log.FromContext(ctx).Warnf("Failed to add bridge %s, stdout: %q, stderr: %q, error: %v", bridgeName, stdout, stderr, err) } // Clean the flows from the above created ovs bridge - stdout, stderr, err = util.RunOVSOfctl("del-flows", bridgeName) + stdout, stderr, err = w.RunOVSOfctl("del-flows", bridgeName) if err != nil { log.FromContext(ctx).Warnf("Failed to cleanup flows on %s "+ "stdout: %q, stderr: %q, error: %v", bridgeName, stdout, stderr, err) @@ -134,12 +137,15 @@ func configureL2Interface(ctx context.Context, cp *L2ConnectionPoint) error { return errors.Wrapf(err, "failed to delete IP address from link device") } } - stdout, stderr, err := util.RunOVSVsctl("--", "--may-exist", "add-port", cp.Bridge, cp.Interface) + logger := log.FromContext(ctx).WithField("utils", "configureL2Interface") + w := &OVSRunWrapper{Logger: logger} + stdout, stderr, err := w.RunOVSVsctl("--", "--may-exist", "add-port", cp.Bridge, cp.Interface) if err != nil { log.FromContext(ctx).Errorf("Failed to add l2 egress port %s to %s, stdout: %q, stderr: %q,"+ " error: %v", cp.Interface, cp.Bridge, stdout, stderr, err) return errors.Wrap(err, "failed to run command via ovs-vsctl") } + link, err = netlink.LinkByName(cp.Bridge) if err != nil { return errors.Wrapf(err, "failed to find link %s", cp.Bridge)