Search in sources :

Example 16 with UnroutableFlowException

use of org.openkilda.pce.exception.UnroutableFlowException in project open-kilda by telstra.

the class YFlowUpdateServiceTest method shouldFailIfNoPathAvailableForFirstSubFlow.

@Test
public void shouldFailIfNoPathAvailableForFirstSubFlow() throws UnroutableFlowException, RecoverableException, DuplicateKeyException {
    // given
    YFlowRequest request = createYFlow();
    request.setMaximumBandwidth(2000L);
    request.getSubFlows().get(0).setEndpoint(newFirstEndpoint);
    request.getSubFlows().get(1).setEndpoint(newSecondEndpoint);
    when(pathComputer.getPath(buildFlowIdArgumentMatch("test_flow_1"), any())).thenThrow(new UnroutableFlowException(injectedErrorMessage));
    preparePathComputationForUpdate("test_flow_2", buildNewSecondSubFlowPathPair(), buildSecondSubFlowPathPair());
    prepareYPointComputation(SWITCH_SHARED, SWITCH_NEW_FIRST_EP, SWITCH_NEW_SECOND_EP, SWITCH_TRANSIT);
    // when
    processUpdateRequestAndSpeakerCommands(request);
    verifyNorthboundErrorResponse(yFlowUpdateHubCarrier, ErrorType.NOT_FOUND);
    verifyYFlowStatus(request.getYFlowId(), FlowStatus.UP);
    YFlow flow = getYFlow(request.getYFlowId());
    assertEquals(1000L, flow.getMaximumBandwidth());
    Set<SwitchId> expectedEndpointSwitchIds = Stream.of(SWITCH_FIRST_EP, SWITCH_SECOND_EP).collect(Collectors.toSet());
    Set<SwitchId> actualEndpointSwitchIds = flow.getSubFlows().stream().map(YSubFlow::getEndpointSwitchId).collect(Collectors.toSet());
    assertEquals(expectedEndpointSwitchIds, actualEndpointSwitchIds);
}
Also used : YFlow(org.openkilda.model.YFlow) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) SwitchId(org.openkilda.model.SwitchId) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest) Test(org.junit.Test) AbstractYFlowTest(org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)

Example 17 with UnroutableFlowException

use of org.openkilda.pce.exception.UnroutableFlowException in project open-kilda by telstra.

the class FlowUpdateServiceTest method shouldFailUpdateFlowIfNoPathAvailable.

@Test
public void shouldFailUpdateFlowIfNoPathAvailable() throws RecoverableException, UnroutableFlowException, DuplicateKeyException {
    Flow origin = makeFlow();
    when(pathComputer.getPath(makeFlowArgumentMatch(origin.getFlowId()), anyCollection())).thenThrow(new UnroutableFlowException(injectedErrorMessage));
    FlowRequest request = makeRequest().flowId(origin.getFlowId()).bandwidth(origin.getBandwidth() + 1).build();
    Flow result = testExpectedFailure(request, origin, ErrorType.NOT_FOUND);
    Assert.assertEquals(origin.getBandwidth(), result.getBandwidth());
    verify(pathComputer, times(11)).getPath(makeFlowArgumentMatch(origin.getFlowId()), any());
}
Also used : FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 18 with UnroutableFlowException

use of org.openkilda.pce.exception.UnroutableFlowException in project open-kilda by telstra.

the class FlowRerouteServiceTest method shouldFailRerouteFlowIfNoPathAvailable.

@Test
public void shouldFailRerouteFlowIfNoPathAvailable() throws RecoverableException, UnroutableFlowException {
    Flow origin = makeFlow();
    preparePathComputation(origin.getFlowId(), new UnroutableFlowException(injectedErrorMessage));
    FlowRerouteRequest request = new FlowRerouteRequest(origin.getFlowId(), false, false, false, Collections.emptySet(), null, false);
    testExpectedFailure(dummyRequestKey, request, commandContext, origin, FlowStatus.DOWN, ErrorType.NOT_FOUND);
    verify(pathComputer, times(11)).getPath(makeFlowArgumentMatch(origin.getFlowId()), any());
}
Also used : UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 19 with UnroutableFlowException

use of org.openkilda.pce.exception.UnroutableFlowException in project open-kilda by telstra.

the class InMemoryPathComputer method getPath.

private GetPathsResult getPath(AvailableNetwork network, Flow flow, PathComputationStrategy strategy) throws UnroutableFlowException {
    if (flow.isOneSwitchFlow()) {
        log.info("No path computation for one-switch flow");
        SwitchId singleSwitchId = flow.getSrcSwitchId();
        return GetPathsResult.builder().forward(convertToPath(singleSwitchId, singleSwitchId, emptyList())).reverse(convertToPath(singleSwitchId, singleSwitchId, emptyList())).backUpPathComputationWayUsed(false).build();
    }
    WeightFunction weightFunction = getWeightFunctionByStrategy(strategy);
    FindPathResult findPathResult;
    try {
        findPathResult = findPathInNetwork(flow, network, weightFunction, strategy);
    } catch (UnroutableFlowException e) {
        String message = format("Failed to find path with requested bandwidth=%s: %s", flow.isIgnoreBandwidth() ? " ignored" : flow.getBandwidth(), e.getMessage());
        throw new UnroutableFlowException(message, e, flow.getFlowId(), flow.isIgnoreBandwidth());
    }
    return convertToGetPathsResult(flow.getSrcSwitchId(), flow.getDestSwitchId(), findPathResult, strategy, flow.getPathComputationStrategy());
}
Also used : WeightFunction(org.openkilda.pce.model.WeightFunction) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) FindPathResult(org.openkilda.pce.model.FindPathResult) SwitchId(org.openkilda.model.SwitchId)

Example 20 with UnroutableFlowException

use of org.openkilda.pce.exception.UnroutableFlowException in project open-kilda by telstra.

the class BestWeightAndShortestPathFinder method findPath.

private FindPathResult findPath(AvailableNetwork network, SwitchId startSwitchId, SwitchId endSwitchId, Supplier<FindOneDirectionPathResult> getPath) throws UnroutableFlowException {
    Node start = network.getSwitch(startSwitchId);
    Node end = network.getSwitch(endSwitchId);
    if (start == null || end == null) {
        throw new UnroutableFlowException(format("Switch %s doesn't have links with enough bandwidth", start == null ? startSwitchId : endSwitchId));
    }
    FindOneDirectionPathResult pathFindResult = getPath.get();
    List<Edge> forwardPath = pathFindResult.getFoundPath();
    if (forwardPath.isEmpty()) {
        throw new UnroutableFlowException(format("Can't find a path from %s to %s", start, end));
    }
    List<Edge> reversePath = getReversePath(end, start, forwardPath);
    if (reversePath.isEmpty()) {
        throw new UnroutableFlowException(format("Can't find a reverse path from %s to %s. Forward path : %s", end, start, StringUtils.join(forwardPath, ", ")));
    }
    return FindPathResult.builder().foundPath(Pair.of(forwardPath, reversePath)).backUpPathComputationWayUsed(pathFindResult.isBackUpPathComputationWayUsed()).build();
}
Also used : Node(org.openkilda.pce.model.Node) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) FindOneDirectionPathResult(org.openkilda.pce.model.FindOneDirectionPathResult) Edge(org.openkilda.pce.model.Edge)

Aggregations

UnroutableFlowException (org.openkilda.pce.exception.UnroutableFlowException)22 Test (org.junit.Test)12 Flow (org.openkilda.model.Flow)10 RecoverableException (org.openkilda.pce.exception.RecoverableException)9 List (java.util.List)8 FlowPath (org.openkilda.model.FlowPath)8 GetPathsResult (org.openkilda.pce.GetPathsResult)8 YFlowRequest (org.openkilda.messaging.command.yflow.YFlowRequest)7 ResourceAllocationException (org.openkilda.wfm.share.flow.resources.ResourceAllocationException)7 AbstractYFlowTest (org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)7 ErrorType (org.openkilda.messaging.error.ErrorType)6 PathId (org.openkilda.model.PathId)6 SwitchId (org.openkilda.model.SwitchId)6 ArrayList (java.util.ArrayList)5 Slf4j (lombok.extern.slf4j.Slf4j)5 Objects (java.util.Objects)4 Set (java.util.Set)4 Collection (java.util.Collection)3 Collectors (java.util.stream.Collectors)3 Assert.assertEquals (org.junit.Assert.assertEquals)3