Skip to content

Commit

Permalink
Merge pull request #5752 from telstra/test/improvement-ypoint-selection
Browse files Browse the repository at this point in the history
[TEST]: Improvement: SwT: Y-Point selection
  • Loading branch information
IvanChupin authored Dec 3, 2024
2 parents 4ca84a0 + 5d1939d commit a148a07
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,6 @@ class TopologyHelper {
}
}

@Memoized
List<SwitchId> 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<PathNode> potentialPath2 ->
def switches = path1WithPath2.path1.switchId
.intersect(potentialPath2.switchId)
switches ? switches[-1] : null
}
}.findAll().unique()
}

List<List<PathNode>> getDbPathsNodes(SwitchId src, SwitchId dst) {
database.getPaths(src, dst)*.path
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,7 +22,7 @@ class SwitchTriplet {
List<List<PathNode>> pathsEp2

@JsonIgnore
TopologyDefinition topologyDefinition
TopologyDefinition topology

@JsonIgnore
SwitchTriplet getReversed() {
Expand Down Expand Up @@ -75,14 +77,34 @@ class SwitchTriplet {
areEp1Ep2AndEp1OrEp2AndShEpNeighbour
}

@Memoized
List<SwitchId> 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<PathNode> potentialPath2 ->
def switches = path1WithPath2.path1.switchId
.intersect(potentialPath2.switchId)
switches ? switches[-1] : null
}
}.findAll().unique()
}

List<Path> retrieveAvailablePathsEp1(){
convertToPathNodePayload(pathsEp1).collect{
new Path(it, topologyDefinition)
new Path(it, topology)
}
}
List<Path> retrieveAvailablePathsEp2(){
convertToPathNodePayload(pathsEp2).collect{
new Path(it, topologyDefinition)
new Path(it, topology)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,8 +28,6 @@ import org.springframework.stereotype.Component
class SwitchTriplets {
List<SwitchTriplet> switchTriplets
@Autowired
TopologyHelper topologyHelper
@Autowired
TopologyDefinition topology

SwitchTriplets(List<SwitchTriplet> switchTriplets) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -227,7 +224,7 @@ class SwitchTriplets {
ep2: ep2,
pathsEp1: retrievePairPathNode(shared.dpId, ep1.dpId),
pathsEp2: retrievePairPathNode(shared.dpId, ep2.dpId),
topologyDefinition: topology)
topology: topology)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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
Expand All @@ -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
}]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit a148a07

Please sign in to comment.