Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions tests/cnf/core/network/sriov/internal/sriovenv/bond.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package sriovenv

import (
"fmt"

"github.com/rh-ecosystem-edge/eco-goinfra/pkg/nad"
. "github.com/rh-ecosystem-edge/eco-gotests/tests/cnf/core/network/internal/netinittools"
"github.com/rh-ecosystem-edge/eco-gotests/tests/cnf/core/network/sriov/internal/tsparams"
)

// CreateBondNAD creates a Bond CNI NAD in the SR-IOV test namespace.
// This follows the same pattern used by sriov/tests/qinq.go.
func CreateBondNAD(
nadName string,
mode string,
mtu int,
slaveCount int,
ipamType string,
vlanInContainer *uint16,
) (*nad.Builder, error) {
if slaveCount < 2 {
return nil, fmt.Errorf("slaveCount must be >= 2, got %d", slaveCount)
}

var links []nad.Link
for i := 1; i <= slaveCount; i++ {
links = append(links, nad.Link{Name: fmt.Sprintf("net%d", i)})
}

plugin := nad.NewMasterBondPlugin(nadName, mode).
WithFailOverMac(1).
WithLinksInContainer(true).
WithMiimon(100).
WithLinks(links).
WithCapabilities(&nad.Capability{IPs: true}).
WithIPAM(&nad.IPAM{Type: ipamType})

if vlanInContainer != nil {
plugin = plugin.WithVLANInContainer(*vlanInContainer)
}

masterPlugin, err := plugin.GetMasterPluginConfig()
if err != nil {
return nil, err
}

if mtu > 0 {
masterPlugin.Mtu = mtu
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

createdNAD, err := nad.NewBuilder(APIClient, nadName, tsparams.TestNamespaceName).
WithMasterPlugin(masterPlugin).
Create()
if err != nil {
return nil, err
}

return createdNAD, nil
}

// CreateBondNADStaticIPAM creates a two-slave bond NAD with static IPAM, no in-container VLAN,
// and unset bond MTU (0). This matches the common default used by tests such as allmulti.
func CreateBondNADStaticIPAM(nadName, mode string) (*nad.Builder, error) {
return CreateBondNAD(nadName, mode, 0, 2, "static", nil)
}
24 changes: 24 additions & 0 deletions tests/cnf/core/network/sriov/internal/tsparams/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,30 @@ const (
// Net1Interface is the name of the first secondary network interface attached to pods.
Net1Interface = "net1"

// MTU500 is used by SR-IOV IPv4 custom MTU tests.
MTU500 = 500
// MTU1280 is the minimum MTU for IPv6.
MTU1280 = 1280
// MTU9000 is used by jumbo MTU tests.
MTU9000 = 9000

// BondResourceV4PF1Custom is the SR-IOV policy resourceName for IPv4 bond PF1 (custom MTU tier).
BondResourceV4PF1Custom = "sriovbondpf1mtu500"
// BondResourceV4PF1Jumbo is the SR-IOV policy resourceName for IPv4 bond PF1 (jumbo MTU).
BondResourceV4PF1Jumbo = "sriovbondpf1mtu9000"
// BondResourceV4PF2Custom is the SR-IOV policy resourceName for IPv4 bond PF2 (custom MTU tier).
BondResourceV4PF2Custom = "sriovbondpf2mtu500"
// BondResourceV4PF2Jumbo is the SR-IOV policy resourceName for IPv4 bond PF2 (jumbo MTU).
BondResourceV4PF2Jumbo = "sriovbondpf2mtu9000"
// BondResourceV6PF1Custom is the SR-IOV policy resourceName for IPv6 bond PF1 (custom MTU tier).
BondResourceV6PF1Custom = "sriovbondpf1mtu1280v6"
// BondResourceV6PF1Jumbo is the SR-IOV policy resourceName for IPv6 bond PF1 (jumbo MTU).
BondResourceV6PF1Jumbo = "sriovbondpf1mtu9000v6"
// BondResourceV6PF2Custom is the SR-IOV policy resourceName for IPv6 bond PF2 (custom MTU tier).
BondResourceV6PF2Custom = "sriovbondpf2mtu1280v6"
// BondResourceV6PF2Jumbo is the SR-IOV policy resourceName for IPv6 bond PF2 (jumbo MTU).
BondResourceV6PF2Jumbo = "sriovbondpf2mtu9000v6"

// ClientPodMTU500 is the name of the client pod for MTU 500 tests.
ClientPodMTU500 = "client-mtu500"
// ServerPodMTU500 is the name of the server pod for MTU 500 tests.
Expand Down
28 changes: 4 additions & 24 deletions tests/cnf/core/network/sriov/tests/allmulti.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/rh-ecosystem-edge/eco-goinfra/pkg/nad"
"github.com/rh-ecosystem-edge/eco-goinfra/pkg/namespace"
"github.com/rh-ecosystem-edge/eco-goinfra/pkg/nodes"
"github.com/rh-ecosystem-edge/eco-goinfra/pkg/pod"
Expand Down Expand Up @@ -148,18 +147,13 @@ var _ = Describe(

By("Define and create Bonded network attachment for allmulti client")

nadBondAllmultiConfig := defineBondNAD(bondNadNameAllMulti, "active-backup")

_, err = nadBondAllmultiConfig.Create()
Expect(err).ToNot(HaveOccurred(), "Failed to create Bond Nad %s",
nadBondAllmultiConfig.Definition.Name)
_, err = sriovenv.CreateBondNADStaticIPAM(bondNadNameAllMulti, "active-backup")
Expect(err).ToNot(HaveOccurred(), "Failed to create Bond NAD %s", bondNadNameAllMulti)

By("Define and create Bonded network attachment for default client")

nadBondDefaultConfig := defineBondNAD(bondNadNameDefault, "active-backup")
_, err = nadBondDefaultConfig.Create()
Expect(err).ToNot(HaveOccurred(), "Failed to create Bond Nad %s",
nadBondDefaultConfig.Definition.Name)
_, err = sriovenv.CreateBondNADStaticIPAM(bondNadNameDefault, "active-backup")
Expect(err).ToNot(HaveOccurred(), "Failed to create Bond NAD %s", bondNadNameDefault)

By("Waiting until cluster MCP and SR-IOV are stable")

Expand Down Expand Up @@ -475,20 +469,6 @@ func runAllMultiTestCases(
assertMulticastTrafficIsReceived(defaultClientPod, tcpDumpCMD, multicastGroupIP)
}

// defineBondNAD returns network attachment definition for a Bond interface.
func defineBondNAD(nadname, mode string) *nad.Builder {
bondNad, err := nad.NewMasterBondPlugin(nadname, mode).WithFailOverMac(1).
WithLinksInContainer(true).WithMiimon(100).
WithLinks([]nad.Link{{Name: "net1"}, {Name: "net2"}}).WithCapabilities(&nad.Capability{IPs: true}).
WithIPAM(&nad.IPAM{Type: "static"}).GetMasterPluginConfig()
Expect(err).ToNot(HaveOccurred(), "Failed to define Bond NAD for %s", nadname)

createdNad, err := nad.NewBuilder(APIClient, nadname, tsparams.TestNamespaceName).WithMasterPlugin(bondNad).Create()
Expect(err).ToNot(HaveOccurred(), "Failed to create Bond NAD for %s", nadname)

return createdNad
}

// defineAndCreateSrIovNetworkWithOutIPAM is used to create sriovnetworks with IPAM for a bonded interface.
func defineAndCreateSrIovNetworkWithOutIPAM(srIovNetwork string, allMulti bool) {
srIovNetworkObject := sriov.NewNetworkBuilder(
Expand Down
19 changes: 5 additions & 14 deletions tests/cnf/core/network/sriov/tests/qinq.go
Original file line number Diff line number Diff line change
Expand Up @@ -1075,17 +1075,11 @@ func runQinQDpdkTestCases(nodeName, serverName, clientName, sriovNetworkName, na
readAndValidateTCPDump(clientDpdk, []string{"bash", "-c", "tail -20 /tmp/tcpdump"}, outPutSubString)
}

// defineBondNAD returns network attachment definition for a Bond interface.
func defineQinQBondNAD(nadname, mode string) *nad.Builder {
bondNad, err := nad.NewMasterBondPlugin(nadname, mode).WithFailOverMac(1).
WithLinksInContainer(true).WithVLANInContainer(uint16(100)).WithMiimon(100).
WithLinks([]nad.Link{{Name: "net1"}, {Name: "net2"}}).WithIPAM(&nad.IPAM{Type: ""}).GetMasterPluginConfig()
Expect(err).ToNot(HaveOccurred(), "Failed to define Bond NAD for %s", nadname)

createdNad, err := nad.NewBuilder(APIClient, nadname, tsparams.TestNamespaceName).WithMasterPlugin(bondNad).Create()
// defineQinQBondNAD creates the Bond CNI NetworkAttachmentDefinition (CreateBondNAD already persists it).
func defineQinQBondNAD(nadname, mode string) {
vlan := uint16(100)
_, err := sriovenv.CreateBondNAD(nadname, mode, 0, 2, "", &vlan)
Expect(err).ToNot(HaveOccurred(), "Failed to create Bond NAD for %s", nadname)

return createdNad
}

func defineCreateSriovNetPolices(vfioPCIName, vfioPCIResName, sriovInterface,
Expand Down Expand Up @@ -1162,10 +1156,7 @@ func defineAndCreateNADs(nadCVLAN100, nadCVLAN101, nadMasterBond0, intNet1 strin

By("Define and create a Bonded network attachment definition with a C-VLAN 100")

bondMasterNad := defineQinQBondNAD(nadMasterBond0, "active-backup")
_, err = bondMasterNad.Create()
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("Fail to create a Bond Network-Attachment-Definition %s",
nadCVLAN100))
defineQinQBondNAD(nadMasterBond0, "active-backup")
}

func setVFPromiscMode(nodeName, srIovInterfacesUnderTest, sriovVendor, onOff string) {
Expand Down
Loading