Skip to content

Commit

Permalink
multicast, udn: Add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Enrique Llorente <ellorent@redhat.com>
  • Loading branch information
qinqon committed Jul 26, 2024
1 parent 4dca23b commit aada474
Show file tree
Hide file tree
Showing 6 changed files with 502 additions and 19 deletions.
6 changes: 3 additions & 3 deletions go-controller/pkg/ovn/egressfirewall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ var _ = ginkgo.Describe("OVN EgressFirewall Operations", func() {
config.Gateway.Mode = gwMode
app.Action = func(ctx *cli.Context) error {
// owned by non-existing namespace
fakeController := getFakeController(DefaultNetworkControllerName)
fakeController := getFakeController()
purgeIDs := fakeController.getEgressFirewallACLDbIDs("none", 0)
purgeACL := libovsdbops.BuildACL(
"purgeACL1",
Expand Down Expand Up @@ -489,7 +489,7 @@ var _ = ginkgo.Describe("OVN EgressFirewall Operations", func() {
config.Gateway.Mode = gwMode
app.Action = func(ctx *cli.Context) error {

fakeController := getFakeController(DefaultNetworkControllerName)
fakeController := getFakeController()
fakeOVN.controller = fakeController

namespace1 := *newNamespace("namespace1")
Expand Down Expand Up @@ -522,7 +522,7 @@ var _ = ginkgo.Describe("OVN EgressFirewall Operations", func() {
namespace1 := *newNamespace("namespace1")
dnsName := util.LowerCaseFQDN("www.example.com")

fakeController := getFakeController(DefaultNetworkControllerName)
fakeController := getFakeController()
fakeOVN.controller = fakeController

// add dns address set along with the acl and pg to the initial db.
Expand Down
12 changes: 10 additions & 2 deletions go-controller/pkg/ovn/master_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1833,15 +1833,23 @@ func newClusterJoinSwitch() *nbdb.LogicalSwitch {
}

func newClusterPortGroup() *nbdb.PortGroup {
fakeController := getFakeController(DefaultNetworkControllerName)
return newClusterPortGroupForNetwork(&util.DefaultNetInfo{})
}

func newClusterPortGroupForNetwork(netInfo util.NetInfo) *nbdb.PortGroup {
fakeController := getFakeControllerForNetwork(netInfo)
pgIDs := fakeController.getClusterPortGroupDbIDs(types.ClusterPortGroupNameBase)
pg := libovsdbutil.BuildPortGroup(pgIDs, nil, nil)
pg.UUID = pgIDs.String()
return pg
}

func newRouterPortGroup() *nbdb.PortGroup {
fakeController := getFakeController(DefaultNetworkControllerName)
return newRouterPortGroupForNetwork(&util.DefaultNetInfo{})
}

func newRouterPortGroupForNetwork(netInfo util.NetInfo) *nbdb.PortGroup {
fakeController := getFakeControllerForNetwork(netInfo)
pgIDs := fakeController.getClusterPortGroupDbIDs(types.ClusterRtrPortGroupNameBase)
pg := libovsdbutil.BuildPortGroup(pgIDs, nil, nil)
pg.UUID = pgIDs.String()
Expand Down
27 changes: 19 additions & 8 deletions go-controller/pkg/ovn/multicast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ func setIpMode(m ipMode) {
}

func getMulticastDefaultExpectedData(clusterPortGroup, clusterRtrPortGroup *nbdb.PortGroup) []libovsdb.TestData {
return getMulticastDefaultExpectedDataForNetwork(&util.DefaultNetInfo{}, clusterPortGroup, clusterRtrPortGroup)
}
func getMulticastDefaultExpectedDataForNetwork(netInfo util.NetInfo, clusterPortGroup, clusterRtrPortGroup *nbdb.PortGroup) []libovsdb.TestData {
controllerName := getNetworkControllerName(netInfo.GetNetworkName())
match := getMulticastACLMatch()
aclIDs := getDefaultMcastACLDbIDs(mcastDefaultDenyID, libovsdbutil.ACLEgress, DefaultNetworkControllerName)
aclIDs := getDefaultMcastACLDbIDs(mcastDefaultDenyID, libovsdbutil.ACLEgress, controllerName)
aclName := libovsdbutil.GetACLName(aclIDs)
defaultDenyEgressACL := libovsdbops.BuildACL(
aclName,
Expand All @@ -74,7 +78,7 @@ func getMulticastDefaultExpectedData(clusterPortGroup, clusterRtrPortGroup *nbdb
)
defaultDenyEgressACL.UUID = "defaultDenyEgressACL_UUID"

aclIDs = getDefaultMcastACLDbIDs(mcastDefaultDenyID, libovsdbutil.ACLIngress, DefaultNetworkControllerName)
aclIDs = getDefaultMcastACLDbIDs(mcastDefaultDenyID, libovsdbutil.ACLIngress, controllerName)
aclName = libovsdbutil.GetACLName(aclIDs)
defaultDenyIngressACL := libovsdbops.BuildACL(
aclName,
Expand All @@ -92,7 +96,7 @@ func getMulticastDefaultExpectedData(clusterPortGroup, clusterRtrPortGroup *nbdb
defaultDenyIngressACL.UUID = "defaultDenyIngressACL_UUID"
clusterPortGroup.ACLs = []string{defaultDenyEgressACL.UUID, defaultDenyIngressACL.UUID}

aclIDs = getDefaultMcastACLDbIDs(mcastAllowInterNodeID, libovsdbutil.ACLEgress, DefaultNetworkControllerName)
aclIDs = getDefaultMcastACLDbIDs(mcastAllowInterNodeID, libovsdbutil.ACLEgress, controllerName)
aclName = libovsdbutil.GetACLName(aclIDs)
egressMatch := libovsdbutil.GetACLMatch(clusterRtrPortGroup.Name, match, libovsdbutil.ACLEgress)
defaultAllowEgressACL := libovsdbops.BuildACL(
Expand All @@ -112,7 +116,7 @@ func getMulticastDefaultExpectedData(clusterPortGroup, clusterRtrPortGroup *nbdb
)
defaultAllowEgressACL.UUID = "defaultAllowEgressACL_UUID"

aclIDs = getDefaultMcastACLDbIDs(mcastAllowInterNodeID, libovsdbutil.ACLIngress, DefaultNetworkControllerName)
aclIDs = getDefaultMcastACLDbIDs(mcastAllowInterNodeID, libovsdbutil.ACLIngress, controllerName)
aclName = libovsdbutil.GetACLName(aclIDs)
ingressMatch := libovsdbutil.GetACLMatch(clusterRtrPortGroup.Name, match, libovsdbutil.ACLIngress)
defaultAllowIngressACL := libovsdbops.BuildACL(
Expand Down Expand Up @@ -141,7 +145,11 @@ func getMulticastDefaultExpectedData(clusterPortGroup, clusterRtrPortGroup *nbdb
}

func getMulticastDefaultStaleData(clusterPortGroup, clusterRtrPortGroup *nbdb.PortGroup) []libovsdb.TestData {
testData := getMulticastDefaultExpectedData(clusterPortGroup, clusterRtrPortGroup)
return getMulticastDefaultStaleDataForNetwork(&util.DefaultNetInfo{}, clusterPortGroup, clusterRtrPortGroup)
}

func getMulticastDefaultStaleDataForNetwork(netInfo util.NetInfo, clusterPortGroup, clusterRtrPortGroup *nbdb.PortGroup) []libovsdb.TestData {
testData := getMulticastDefaultExpectedDataForNetwork(netInfo, clusterPortGroup, clusterRtrPortGroup)
defaultDenyIngressACL := testData[0].(*nbdb.ACL)
newName := libovsdbutil.JoinACLName(types.ClusterPortGroupNameBase, "DefaultDenyMulticastIngress")
defaultDenyIngressACL.Name = &newName
Expand Down Expand Up @@ -179,15 +187,18 @@ func getDefaultPortGroups() (clusterPortGroup, clusterRtrPortGroup *nbdb.PortGro
}

func getMulticastPolicyExpectedData(ns string, ports []string) []libovsdb.TestData {
fakeController := getFakeController(DefaultNetworkControllerName)
return getMulticastPolicyExpectedDataForNetwork(&util.DefaultNetInfo{}, ns, ports)
}
func getMulticastPolicyExpectedDataForNetwork(netInfo util.NetInfo, ns string, ports []string) []libovsdb.TestData {
fakeController := getFakeControllerForNetwork(netInfo)
pg_hash := fakeController.getNamespacePortGroupName(ns)
egressMatch := libovsdbutil.GetACLMatch(pg_hash, fakeController.getMulticastACLEgrMatch(), libovsdbutil.ACLEgress)

ip4AddressSet, ip6AddressSet := getNsAddrSetHashNames(ns)
mcastMatch := getACLMatchAF(getMulticastACLIgrMatchV4(ip4AddressSet), getMulticastACLIgrMatchV6(ip6AddressSet), config.IPv4Mode, config.IPv6Mode)
ingressMatch := libovsdbutil.GetACLMatch(pg_hash, mcastMatch, libovsdbutil.ACLIngress)

aclIDs := getNamespaceMcastACLDbIDs(ns, libovsdbutil.ACLEgress, DefaultNetworkControllerName)
aclIDs := getNamespaceMcastACLDbIDs(ns, libovsdbutil.ACLEgress, getNetworkControllerName(netInfo.GetNetworkName()))
aclName := libovsdbutil.GetACLName(aclIDs)
egressACL := libovsdbops.BuildACL(
aclName,
Expand All @@ -206,7 +217,7 @@ func getMulticastPolicyExpectedData(ns string, ports []string) []libovsdb.TestDa
)
egressACL.UUID = ns + "mc-egress-UUID"

aclIDs = getNamespaceMcastACLDbIDs(ns, libovsdbutil.ACLIngress, DefaultNetworkControllerName)
aclIDs = getNamespaceMcastACLDbIDs(ns, libovsdbutil.ACLIngress, getNetworkControllerName(netInfo.GetNetworkName()))
aclName = libovsdbutil.GetACLName(aclIDs)
ingressACL := libovsdbops.BuildACL(
aclName,
Expand Down
Loading

0 comments on commit aada474

Please sign in to comment.