diff --git a/src-java/testing/functional-tests/src/main/groovy/org/openkilda/functionaltests/helpers/TopologyHelper.groovy b/src-java/testing/functional-tests/src/main/groovy/org/openkilda/functionaltests/helpers/TopologyHelper.groovy index 78dfabd139..d628727f24 100644 --- a/src-java/testing/functional-tests/src/main/groovy/org/openkilda/functionaltests/helpers/TopologyHelper.groovy +++ b/src-java/testing/functional-tests/src/main/groovy/org/openkilda/functionaltests/helpers/TopologyHelper.groovy @@ -84,26 +84,6 @@ class TopologyHelper { } } - @Memoized - List findPotentialYPoints(SwitchTriplet swT) { - def sortedEp1Paths = swT.pathsEp1.sort { it.size() } - def potentialEp1Paths = sortedEp1Paths.takeWhile { it.size() == sortedEp1Paths[0].size() } - def potentialEp2Paths = potentialEp1Paths.collect { potentialEp1Path -> - def sortedEp2Paths = swT.pathsEp2.sort { - it.size() - it.intersect(potentialEp1Path).size() - } - [path1: potentialEp1Path, - potentialPaths2: sortedEp2Paths.takeWhile {it.size() == sortedEp2Paths[0].size() }] - } - return potentialEp2Paths.collectMany {path1WithPath2 -> - path1WithPath2.potentialPaths2.collect { List potentialPath2 -> - def switches = path1WithPath2.path1.switchId - .intersect(potentialPath2.switchId) - switches ? switches[-1] : null - } - }.findAll().unique() - } - List> getDbPathsNodes(SwitchId src, SwitchId dst) { database.getPaths(src, dst)*.path } diff --git a/src-java/testing/functional-tests/src/main/groovy/org/openkilda/functionaltests/helpers/model/SwitchTriplet.groovy b/src-java/testing/functional-tests/src/main/groovy/org/openkilda/functionaltests/helpers/model/SwitchTriplet.groovy index 3e6bce2790..d86387ff7f 100644 --- a/src-java/testing/functional-tests/src/main/groovy/org/openkilda/functionaltests/helpers/model/SwitchTriplet.groovy +++ b/src-java/testing/functional-tests/src/main/groovy/org/openkilda/functionaltests/helpers/model/SwitchTriplet.groovy @@ -3,11 +3,13 @@ package org.openkilda.functionaltests.helpers.model import static org.openkilda.functionaltests.helpers.TopologyHelper.convertToPathNodePayload import org.openkilda.messaging.info.event.PathNode +import org.openkilda.model.SwitchId import org.openkilda.testing.model.topology.TopologyDefinition import org.openkilda.testing.model.topology.TopologyDefinition.Switch import com.fasterxml.jackson.annotation.JsonIgnore import groovy.transform.EqualsAndHashCode +import groovy.transform.Memoized import groovy.transform.TupleConstructor @TupleConstructor @@ -20,7 +22,7 @@ class SwitchTriplet { List> pathsEp2 @JsonIgnore - TopologyDefinition topologyDefinition + TopologyDefinition topology @JsonIgnore SwitchTriplet getReversed() { @@ -75,14 +77,34 @@ class SwitchTriplet { areEp1Ep2AndEp1OrEp2AndShEpNeighbour } + @Memoized + List findPotentialYPoints() { + def sortedEp1Paths = pathsEp1.sort { it.size() } + def potentialEp1Paths = sortedEp1Paths.takeWhile { it.size() == sortedEp1Paths[0].size() } + def potentialEp2Paths = potentialEp1Paths.collect { potentialEp1Path -> + def sortedEp2Paths = pathsEp2.sort { + it.size() - it.intersect(potentialEp1Path).size() + } + [path1: potentialEp1Path, + potentialPaths2: sortedEp2Paths.takeWhile {it.size() == sortedEp2Paths[0].size() }] + } + return potentialEp2Paths.collectMany {path1WithPath2 -> + path1WithPath2.potentialPaths2.collect { List potentialPath2 -> + def switches = path1WithPath2.path1.switchId + .intersect(potentialPath2.switchId) + switches ? switches[-1] : null + } + }.findAll().unique() + } + List retrieveAvailablePathsEp1(){ convertToPathNodePayload(pathsEp1).collect{ - new Path(it, topologyDefinition) + new Path(it, topology) } } List retrieveAvailablePathsEp2(){ convertToPathNodePayload(pathsEp2).collect{ - new Path(it, topologyDefinition) + new Path(it, topology) } } } diff --git a/src-java/testing/functional-tests/src/main/groovy/org/openkilda/functionaltests/helpers/model/SwitchTriplets.groovy b/src-java/testing/functional-tests/src/main/groovy/org/openkilda/functionaltests/helpers/model/SwitchTriplets.groovy index 0a79d305ea..0317e0e4c3 100644 --- a/src-java/testing/functional-tests/src/main/groovy/org/openkilda/functionaltests/helpers/model/SwitchTriplets.groovy +++ b/src-java/testing/functional-tests/src/main/groovy/org/openkilda/functionaltests/helpers/model/SwitchTriplets.groovy @@ -2,7 +2,6 @@ package org.openkilda.functionaltests.helpers.model import static org.springframework.beans.factory.config.ConfigurableBeanFactory.SCOPE_PROTOTYPE -import org.openkilda.functionaltests.helpers.TopologyHelper import org.openkilda.messaging.info.event.PathNode import org.openkilda.model.SwitchId import org.openkilda.testing.model.topology.TopologyDefinition @@ -29,8 +28,6 @@ import org.springframework.stereotype.Component class SwitchTriplets { List switchTriplets @Autowired - TopologyHelper topologyHelper - @Autowired TopologyDefinition topology SwitchTriplets(List switchTriplets) { @@ -147,7 +144,7 @@ class SwitchTriplets { .unique(false) { a, b -> a.intersect(b) == [] ? 1 : 0 } def ep2paths = it.pathsEp2.findAll { path -> !path.any { node -> node.switchId == it.ep1.dpId } } .unique(false) { a, b -> a.intersect(b) == [] ? 1 : 0 } - def yPoints = topologyHelper.findPotentialYPoints(it) + def yPoints = it.findPotentialYPoints() yPoints.size() == 1 && (isYPointOnSharedEp ? yPoints[0] == it.shared.dpId : yPoints[0] != it.shared.dpId) && yPoints[0] != it.ep1.dpId && yPoints[0] != it.ep2.dpId && ep1paths.size() >= 2 && ep2paths.size() >= 2 @@ -184,7 +181,7 @@ class SwitchTriplets { SwitchTriplet findSwitchTripletWithYPointOnSharedEp() { return switchTriplets.find { - topologyHelper.findPotentialYPoints(it).size() == 1 && it.getShared().getDpId() == topologyHelper.findPotentialYPoints(it).get(0) + it.findPotentialYPoints().size() == 1 && it.shared.dpId == it.findPotentialYPoints().get(0) } } @@ -227,7 +224,7 @@ class SwitchTriplets { ep2: ep2, pathsEp1: retrievePairPathNode(shared.dpId, ep1.dpId), pathsEp2: retrievePairPathNode(shared.dpId, ep2.dpId), - topologyDefinition: topology) + topology: topology) } } diff --git a/src-java/testing/functional-tests/src/test/groovy/org/openkilda/functionaltests/spec/flows/haflows/HaFlowCreateSpec.groovy b/src-java/testing/functional-tests/src/test/groovy/org/openkilda/functionaltests/spec/flows/haflows/HaFlowCreateSpec.groovy index 02b4051aef..b5c5ebf943 100644 --- a/src-java/testing/functional-tests/src/test/groovy/org/openkilda/functionaltests/spec/flows/haflows/HaFlowCreateSpec.groovy +++ b/src-java/testing/functional-tests/src/test/groovy/org/openkilda/functionaltests/spec/flows/haflows/HaFlowCreateSpec.groovy @@ -164,12 +164,12 @@ and ${haFlowInvalidRequest.subFlows[1].endpointInnerVlan}./).matches(exc) //se = shared endpoint, ep = subflow endpoint, yp = y-point [name : "se is wb and se!=yp", condition: { SwitchTriplet swT -> - def yPoints = topologyHelper.findPotentialYPoints(swT) + def yPoints = swT.findPotentialYPoints() swT.shared.wb5164 && yPoints.size() == 1 && yPoints[0] != swT.shared.dpId }], [name : "se is non-wb and se!=yp", condition: { SwitchTriplet swT -> - def yPoints = topologyHelper.findPotentialYPoints(swT) + def yPoints = swT.findPotentialYPoints() !swT.shared.wb5164 && yPoints.size() == 1 && yPoints[0] != swT.shared.dpId }], [name : "ep on wb and different eps", //ep1 is not the same sw as ep2 @@ -178,37 +178,37 @@ and ${haFlowInvalidRequest.subFlows[1].endpointInnerVlan}./).matches(exc) condition: { SwitchTriplet swT -> !swT.ep1.wb5164 && swT.ep1 != swT.ep2 }], [name : "se+yp on wb", condition: { SwitchTriplet swT -> - def yPoints = topologyHelper.findPotentialYPoints(swT) + def yPoints = swT.findPotentialYPoints() swT.shared.wb5164 && yPoints.size() == 1 && yPoints[0] == swT.shared.dpId }], [name : "se+yp on non-wb", condition: { SwitchTriplet swT -> - def yPoints = topologyHelper.findPotentialYPoints(swT) + def yPoints = swT.findPotentialYPoints() !swT.shared.wb5164 && yPoints.size() == 1 && yPoints[0] == swT.shared.dpId }], [name : "yp on wb and yp!=se!=ep", condition: { SwitchTriplet swT -> - def yPoints = topologyHelper.findPotentialYPoints(swT) + def yPoints = swT.findPotentialYPoints() swT.shared.wb5164 && yPoints.size() == 1 && yPoints[0] != swT.shared.dpId && yPoints[0] != swT.ep1.dpId && yPoints[0] != swT.ep2.dpId }], [name : "yp on non-wb and yp!=se!=ep", condition: { SwitchTriplet swT -> - def yPoints = topologyHelper.findPotentialYPoints(swT) + def yPoints = swT.findPotentialYPoints() !swT.shared.wb5164 && yPoints.size() == 1 && yPoints[0] != swT.shared.dpId && yPoints[0] != swT.ep1.dpId && yPoints[0] != swT.ep2.dpId }], [name : "ep+yp on wb", condition: { SwitchTriplet swT -> - def yPoints = topologyHelper.findPotentialYPoints(swT) + def yPoints = swT.findPotentialYPoints() swT.shared.wb5164 && yPoints.size() == 1 && (yPoints[0] == swT.ep1.dpId || yPoints[0] == swT.ep2.dpId) }], [name : "ep+yp on non-wb", condition: { SwitchTriplet swT -> - def yPoints = topologyHelper.findPotentialYPoints(swT) + def yPoints = swT.findPotentialYPoints() !swT.shared.wb5164 && yPoints.size() == 1 && (yPoints[0] == swT.ep1.dpId || yPoints[0] == swT.ep2.dpId) }], [name : "yp==se", condition: { SwitchTriplet swT -> - def yPoints = topologyHelper.findPotentialYPoints(swT) + def yPoints = swT.findPotentialYPoints() yPoints.size() == 1 && yPoints[0] == swT.shared.dpId && swT.shared != swT.ep1 && swT.shared != swT.ep2 }] ] diff --git a/src-java/testing/functional-tests/src/test/groovy/org/openkilda/functionaltests/spec/flows/haflows/HaFlowRerouteSpec.groovy b/src-java/testing/functional-tests/src/test/groovy/org/openkilda/functionaltests/spec/flows/haflows/HaFlowRerouteSpec.groovy index 028dd3ccfe..24c299887f 100644 --- a/src-java/testing/functional-tests/src/test/groovy/org/openkilda/functionaltests/spec/flows/haflows/HaFlowRerouteSpec.groovy +++ b/src-java/testing/functional-tests/src/test/groovy/org/openkilda/functionaltests/spec/flows/haflows/HaFlowRerouteSpec.groovy @@ -167,7 +167,7 @@ class HaFlowRerouteSpec extends HealthCheckSpecification { def "HA-flow goes to 'Down' status when ISl of the HA-flow fails and there is no alt path to reroute"() { given: "An HA-flow without alternative paths" def swT = switchTriplets.all().withAllDifferentEndpoints().switchTriplets.find { - def yPoints = topologyHelper.findPotentialYPoints(it) + def yPoints = it.findPotentialYPoints() yPoints.size() == 1 && yPoints[0] != it.shared.dpId } assumeTrue(swT != null, "These cases cannot be covered on given topology:") diff --git a/src-java/testing/functional-tests/src/test/groovy/org/openkilda/functionaltests/spec/flows/yflows/YFlowCreateSpec.groovy b/src-java/testing/functional-tests/src/test/groovy/org/openkilda/functionaltests/spec/flows/yflows/YFlowCreateSpec.groovy index 90ec61f562..b73732082c 100644 --- a/src-java/testing/functional-tests/src/test/groovy/org/openkilda/functionaltests/spec/flows/yflows/YFlowCreateSpec.groovy +++ b/src-java/testing/functional-tests/src/test/groovy/org/openkilda/functionaltests/spec/flows/yflows/YFlowCreateSpec.groovy @@ -384,8 +384,8 @@ source: switchId="${flowParams.yFlow.sharedEndpoint.switchId}" port=${flowParams def slowestLinkSwitchIds = [slowestLinkOnTheWest.getSrcSwitchId(), slowestLinkOnTheWest.getDestSwitchId()] def switchTriplet = switchTriplets.all(true, false).getSwitchTriplets() .find { - def yPoints = topologyHelper.findPotentialYPoints(it) - slowestLinkSwitchIds.contains(it.shared.getDpId()) && + def yPoints = it.findPotentialYPoints() + slowestLinkSwitchIds.contains(it.shared.dpId) && !slowestLinkSwitchIds.intersect(yPoints).isEmpty() } assumeTrue(switchTriplet != null, "No suiting switches found.") @@ -456,12 +456,12 @@ source: switchId="${flowParams.yFlow.sharedEndpoint.switchId}" port=${flowParams //se = shared endpoint, ep = subflow endpoint, yp = y-point [name : "se is wb and se!=yp", condition: { SwitchTriplet swT -> - def yPoints = topologyHelper.findPotentialYPoints(swT) + def yPoints = swT.findPotentialYPoints() swT.shared.wb5164 && yPoints.size() == 1 && yPoints[0] != swT.shared.dpId }], [name : "se is non-wb and se!=yp", condition: { SwitchTriplet swT -> - def yPoints = topologyHelper.findPotentialYPoints(swT) + def yPoints = swT.findPotentialYPoints() !swT.shared.wb5164 && yPoints.size() == 1 && yPoints[0] != swT.shared.dpId }], [name : "ep on wb and different eps", //ep1 is not the same sw as ep2 @@ -470,37 +470,37 @@ source: switchId="${flowParams.yFlow.sharedEndpoint.switchId}" port=${flowParams condition: { SwitchTriplet swT -> !swT.ep1.wb5164 && swT.ep1 != swT.ep2 }], [name : "se+yp on wb", condition: { SwitchTriplet swT -> - def yPoints = topologyHelper.findPotentialYPoints(swT) + def yPoints = swT.findPotentialYPoints() swT.shared.wb5164 && yPoints.size() == 1 && yPoints[0] == swT.shared.dpId }], [name : "se+yp on non-wb", condition: { SwitchTriplet swT -> - def yPoints = topologyHelper.findPotentialYPoints(swT) + def yPoints = swT.findPotentialYPoints() !swT.shared.wb5164 && yPoints.size() == 1 && yPoints[0] == swT.shared.dpId }], [name : "yp on wb and yp!=se!=ep", condition: { SwitchTriplet swT -> - def yPoints = topologyHelper.findPotentialYPoints(swT) + def yPoints = swT.findPotentialYPoints() swT.shared.wb5164 && yPoints.size() == 1 && yPoints[0] != swT.shared.dpId && yPoints[0] != swT.ep1.dpId && yPoints[0] != swT.ep2.dpId }], [name : "yp on non-wb and yp!=se!=ep", condition: { SwitchTriplet swT -> - def yPoints = topologyHelper.findPotentialYPoints(swT) + def yPoints = swT.findPotentialYPoints() !swT.shared.wb5164 && yPoints.size() == 1 && yPoints[0] != swT.shared.dpId && yPoints[0] != swT.ep1.dpId && yPoints[0] != swT.ep2.dpId }], [name : "ep+yp on wb", condition: { SwitchTriplet swT -> - def yPoints = topologyHelper.findPotentialYPoints(swT) + def yPoints = swT.findPotentialYPoints() swT.shared.wb5164 && yPoints.size() == 1 && (yPoints[0] == swT.ep1.dpId || yPoints[0] == swT.ep2.dpId) }], [name : "ep+yp on non-wb", condition: { SwitchTriplet swT -> - def yPoints = topologyHelper.findPotentialYPoints(swT) + def yPoints = swT.findPotentialYPoints() !swT.shared.wb5164 && yPoints.size() == 1 && (yPoints[0] == swT.ep1.dpId || yPoints[0] == swT.ep2.dpId) }], [name : "yp==se", condition: { SwitchTriplet swT -> - def yPoints = topologyHelper.findPotentialYPoints(swT) + def yPoints = swT.findPotentialYPoints() yPoints.size() == 1 && yPoints[0] == swT.shared.dpId && swT.shared != swT.ep1 && swT.shared != swT.ep2 }] ] diff --git a/src-java/testing/functional-tests/src/test/groovy/org/openkilda/functionaltests/spec/flows/yflows/YFlowRerouteSpec.groovy b/src-java/testing/functional-tests/src/test/groovy/org/openkilda/functionaltests/spec/flows/yflows/YFlowRerouteSpec.groovy index 950561da1f..955ac2b561 100644 --- a/src-java/testing/functional-tests/src/test/groovy/org/openkilda/functionaltests/spec/flows/yflows/YFlowRerouteSpec.groovy +++ b/src-java/testing/functional-tests/src/test/groovy/org/openkilda/functionaltests/spec/flows/yflows/YFlowRerouteSpec.groovy @@ -50,7 +50,7 @@ class YFlowRerouteSpec extends HealthCheckSpecification { def "Valid y-flow can be rerouted"() { given: "A qinq y-flow" def swT = switchTriplets.all().withAllDifferentEndpoints().withoutWBSwitch().getSwitchTriplets().find { - def yPoints = topologyHelper.findPotentialYPoints(it) + def yPoints = it.findPotentialYPoints() yPoints.size() == 1 && yPoints[0] != it.shared.dpId } assumeTrue(swT != null, "These cases cannot be covered on given topology:") diff --git a/src-java/testing/functional-tests/src/test/groovy/org/openkilda/functionaltests/spec/switches/SwitchesFlowsV2Spec.groovy b/src-java/testing/functional-tests/src/test/groovy/org/openkilda/functionaltests/spec/switches/SwitchesFlowsV2Spec.groovy index 5ce60a8dbd..97b129f0fb 100644 --- a/src-java/testing/functional-tests/src/test/groovy/org/openkilda/functionaltests/spec/switches/SwitchesFlowsV2Spec.groovy +++ b/src-java/testing/functional-tests/src/test/groovy/org/openkilda/functionaltests/spec/switches/SwitchesFlowsV2Spec.groovy @@ -60,8 +60,8 @@ class SwitchesFlowsV2Spec extends HealthCheckSpecification { usual flow protected path subflow 2 ends on the switch that is not used by other flows */ switchTriplet = switchTriplets.all(true, false).nonNeighbouring().getSwitchTriplets().find { - def yPoints = topologyHelper.findPotentialYPoints(it) - yPoints[0] != it.shared + def yPoints = it.findPotentialYPoints() + yPoints[0] != it.shared.dpId } assumeTrue(switchTriplet != null, "Couldn't find appropriate switch triplet")