Search in sources :

Example 36 with SwitchId

use of org.openkilda.model.SwitchId in project open-kilda by telstra.

the class InMemoryPathComputer method convertFlowPathsToSwitchLists.

@VisibleForTesting
List<LinkedList<SwitchId>> convertFlowPathsToSwitchLists(SwitchId sharedSwitchId, FlowPath... flowPaths) {
    List<LinkedList<SwitchId>> paths = new ArrayList<>();
    for (FlowPath flowPath : flowPaths) {
        List<PathSegment> pathSegments = flowPath.getSegments();
        if (pathSegments == null || pathSegments.isEmpty()) {
            throw new IllegalArgumentException(format("The path '%s' has no path segments", flowPath.getPathId()));
        }
        LinkedList<SwitchId> path = new LinkedList<>();
        path.add(pathSegments.get(0).getSrcSwitchId());
        for (PathSegment pathSegment : pathSegments) {
            path.add(pathSegment.getDestSwitchId());
        }
        if (sharedSwitchId.equals(path.getLast())) {
            Collections.reverse(path);
        } else if (!sharedSwitchId.equals(path.getFirst())) {
            throw new IllegalArgumentException(format("Shared switch '%s' is not an endpoint switch for path '%s'", sharedSwitchId, flowPath.getPathId()));
        }
        paths.add(path);
    }
    return paths;
}
Also used : ArrayList(java.util.ArrayList) SwitchId(org.openkilda.model.SwitchId) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) LinkedList(java.util.LinkedList) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 37 with SwitchId

use of org.openkilda.model.SwitchId in project open-kilda by telstra.

the class InMemoryPathComputer method getNPaths.

@Override
public List<Path> getNPaths(SwitchId srcSwitchId, SwitchId dstSwitchId, int count, FlowEncapsulationType flowEncapsulationType, PathComputationStrategy pathComputationStrategy, Duration maxLatency, Duration maxLatencyTier2) throws RecoverableException, UnroutableFlowException {
    final long maxLatencyNs = maxLatency != null ? maxLatency.toNanos() : 0;
    final long maxLatencyTier2Ns = maxLatencyTier2 != null ? maxLatencyTier2.toNanos() : 0;
    Flow flow = Flow.builder().flowId(// just any id, as not used.
    "").srcSwitch(Switch.builder().switchId(srcSwitchId).build()).destSwitch(Switch.builder().switchId(dstSwitchId).build()).ignoreBandwidth(false).encapsulationType(flowEncapsulationType).bandwidth(// to get ISLs with non zero available bandwidth
    1).maxLatency(maxLatencyNs).maxLatencyTier2(maxLatencyTier2Ns).build();
    AvailableNetwork availableNetwork = availableNetworkFactory.getAvailableNetwork(flow, Collections.emptyList());
    if (MAX_LATENCY.equals(pathComputationStrategy) && (flow.getMaxLatency() == null || flow.getMaxLatency() == 0)) {
        pathComputationStrategy = LATENCY;
    }
    List<List<Edge>> paths;
    switch(pathComputationStrategy) {
        case COST:
        case LATENCY:
        case COST_AND_AVAILABLE_BANDWIDTH:
            paths = pathFinder.findNPathsBetweenSwitches(availableNetwork, srcSwitchId, dstSwitchId, count, getWeightFunctionByStrategy(pathComputationStrategy));
            break;
        case MAX_LATENCY:
            paths = pathFinder.findNPathsBetweenSwitches(availableNetwork, srcSwitchId, dstSwitchId, count, getWeightFunctionByStrategy(pathComputationStrategy), maxLatencyNs, maxLatencyTier2Ns);
            break;
        default:
            throw new UnsupportedOperationException(String.format("Unsupported strategy type %s", pathComputationStrategy));
    }
    Comparator<Path> comparator;
    if (pathComputationStrategy == LATENCY || pathComputationStrategy == MAX_LATENCY) {
        comparator = Comparator.comparing(Path::getLatency).thenComparing(Comparator.comparing(Path::getMinAvailableBandwidth).reversed());
    } else {
        comparator = Comparator.comparing(Path::getMinAvailableBandwidth).reversed().thenComparing(Path::getLatency);
    }
    return paths.stream().map(edges -> convertToPath(srcSwitchId, dstSwitchId, edges)).sorted(comparator).limit(count).collect(Collectors.toList());
}
Also used : FlowPath(org.openkilda.model.FlowPath) Path(org.openkilda.pce.Path) MAX_LATENCY(org.openkilda.model.PathComputationStrategy.MAX_LATENCY) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) RecoverableException(org.openkilda.pce.exception.RecoverableException) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) Edge(org.openkilda.pce.model.Edge) Flow(org.openkilda.model.Flow) AvailableNetworkFactory(org.openkilda.pce.AvailableNetworkFactory) Duration(java.time.Duration) PathComputerConfig(org.openkilda.pce.PathComputerConfig) LinkedList(java.util.LinkedList) PathId(org.openkilda.model.PathId) Path(org.openkilda.pce.Path) PathFinder(org.openkilda.pce.finder.PathFinder) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) PathWeight(org.openkilda.pce.model.PathWeight) Switch(org.openkilda.model.Switch) PathComputationStrategy(org.openkilda.model.PathComputationStrategy) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Set(java.util.Set) LATENCY(org.openkilda.model.PathComputationStrategy.LATENCY) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) WeightFunction(org.openkilda.pce.model.WeightFunction) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) FindPathResult(org.openkilda.pce.model.FindPathResult) PathComputer(org.openkilda.pce.PathComputer) Optional(java.util.Optional) GetPathsResult(org.openkilda.pce.GetPathsResult) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) Collections(java.util.Collections) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Flow(org.openkilda.model.Flow)

Example 38 with SwitchId

use of org.openkilda.model.SwitchId in project open-kilda by telstra.

the class BestWeightAndShortestPathFinderTest method failToFindASwitch.

@Test(expected = UnroutableFlowException.class)
public void failToFindASwitch() throws UnroutableFlowException {
    AvailableNetwork network = buildTestNetwork();
    SwitchId srcDpid = new SwitchId("00:00:00:00:00:00:00:ff");
    BestWeightAndShortestPathFinder pathFinder = new BestWeightAndShortestPathFinder(ALLOWED_DEPTH);
    pathFinder.findPathWithMinWeight(network, srcDpid, SWITCH_ID_F, WEIGHT_FUNCTION);
}
Also used : SwitchId(org.openkilda.model.SwitchId) AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork) Test(org.junit.Test)

Example 39 with SwitchId

use of org.openkilda.model.SwitchId in project open-kilda by telstra.

the class BestWeightAndShortestPathFinderTest method testForwardAndBackwardPathsEquality.

@Test
public void testForwardAndBackwardPathsEquality() throws UnroutableFlowException {
    AvailableNetwork network = buildEqualCostsNetwork();
    BestWeightAndShortestPathFinder pathFinder = new BestWeightAndShortestPathFinder(ALLOWED_DEPTH);
    Pair<List<Edge>, List<Edge>> paths = pathFinder.findPathWithMinWeight(network, SWITCH_ID_1, SWITCH_ID_5, WEIGHT_FUNCTION).getFoundPath();
    List<SwitchId> forwardSwitchPath = getSwitchIdsFlowPath(paths.getLeft());
    List<SwitchId> backwardSwitchPath = Lists.reverse(getSwitchIdsFlowPath(paths.getRight()));
    assertEquals(forwardSwitchPath, backwardSwitchPath);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork) Test(org.junit.Test)

Example 40 with SwitchId

use of org.openkilda.model.SwitchId in project open-kilda by telstra.

the class CostAndBandwidthPathComputationStrategyTest method shouldFindPathOverDiamondWithOneActiveRouteByCostAndBandwidth.

@Test
public void shouldFindPathOverDiamondWithOneActiveRouteByCostAndBandwidth() throws UnroutableFlowException, RecoverableException {
    createDiamond(IslStatus.INACTIVE, IslStatus.ACTIVE, 10, 20, "01:", 1);
    Switch srcSwitch = getSwitchById("01:01");
    Switch destSwitch = getSwitchById("01:04");
    Flow f = getTestFlowBuilder(srcSwitch, destSwitch).build();
    PathComputer pathComputer = pathComputerFactory.getPathComputer();
    GetPathsResult path = pathComputer.getPath(f);
    assertNotNull(path);
    assertThat(path.getForward().getSegments(), Matchers.hasSize(2));
    // ====> only difference is it should now have C as first hop .. since B is inactive
    // chooses path C
    assertEquals(new SwitchId("01:03"), path.getForward().getSegments().get(0).getDestSwitchId());
}
Also used : PathComputer(org.openkilda.pce.PathComputer) Switch(org.openkilda.model.Switch) SwitchId(org.openkilda.model.SwitchId) Flow(org.openkilda.model.Flow) GetPathsResult(org.openkilda.pce.GetPathsResult) Test(org.junit.Test)

Aggregations

SwitchId (org.openkilda.model.SwitchId)339 Test (org.junit.Test)149 Flow (org.openkilda.model.Flow)73 Switch (org.openkilda.model.Switch)69 List (java.util.List)59 FlowPath (org.openkilda.model.FlowPath)49 ArrayList (java.util.ArrayList)44 Collectors (java.util.stream.Collectors)37 PathId (org.openkilda.model.PathId)36 PathComputer (org.openkilda.pce.PathComputer)35 Set (java.util.Set)34 YFlow (org.openkilda.model.YFlow)33 Map (java.util.Map)30 GetPathsResult (org.openkilda.pce.GetPathsResult)30 InfoMessage (org.openkilda.messaging.info.InfoMessage)29 String.format (java.lang.String.format)28 HashSet (java.util.HashSet)27 Optional (java.util.Optional)27 Collection (java.util.Collection)26 Collections (java.util.Collections)26