Search in sources :

Example 1 with RerouteQueue

use of org.openkilda.wfm.topology.reroute.model.RerouteQueue in project open-kilda by telstra.

the class RerouteQueueService method flushThrottling.

/**
 * Move reroute requests form throttling to pending/in-progress.
 */
public void flushThrottling() {
    Map<String, FlowThrottlingData> requestsToSend = new HashMap<>();
    reroutes.forEach((flowId, rerouteQueue) -> rerouteQueue.flushThrottling().ifPresent(flowThrottlingData -> requestsToSend.put(flowId, flowThrottlingData)));
    log.info("Send reroute requests for flows {}", requestsToSend.keySet());
    Comparator<FlowThrottlingData> comparator = ((Comparator<FlowThrottlingData>) this::comparePriority).thenComparing(this::compareAvailableBandwidth).thenComparing(this::compareTimeCreate);
    requestsToSend.entrySet().stream().sorted(Map.Entry.comparingByValue(comparator)).forEach(es -> {
        String flowId = es.getKey();
        FlowThrottlingData flowThrottlingData = es.getValue();
        sendRerouteRequest(flowId, flowThrottlingData);
    });
}
Also used : RerouteResultInfoData(org.openkilda.messaging.info.reroute.RerouteResultInfoData) FlowThrottlingData(org.openkilda.wfm.topology.reroute.model.FlowThrottlingData) HashMap(java.util.HashMap) COST_AND_AVAILABLE_BANDWIDTH(org.openkilda.model.PathComputationStrategy.COST_AND_AVAILABLE_BANDWIDTH) NoPathFoundError(org.openkilda.messaging.info.reroute.error.NoPathFoundError) Flow(org.openkilda.model.Flow) Map(java.util.Map) SpeakerRequestError(org.openkilda.messaging.info.reroute.error.SpeakerRequestError) YFlow(org.openkilda.model.YFlow) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) PersistenceManager(org.openkilda.persistence.PersistenceManager) RerouteInProgressError(org.openkilda.messaging.info.reroute.error.RerouteInProgressError) PathComputationStrategy(org.openkilda.model.PathComputationStrategy) YSubFlow(org.openkilda.model.YSubFlow) ErrorType(org.openkilda.messaging.error.ErrorType) RerouteError(org.openkilda.messaging.info.reroute.error.RerouteError) Set(java.util.Set) CommandContext(org.openkilda.wfm.CommandContext) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) Objects(java.util.Objects) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) RerouteQueue(org.openkilda.wfm.topology.reroute.model.RerouteQueue) YFlowRerouteRequest(org.openkilda.messaging.command.yflow.YFlowRerouteRequest) Entry(java.util.Map.Entry) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) ErrorData(org.openkilda.messaging.error.ErrorData) HashMap(java.util.HashMap) FlowThrottlingData(org.openkilda.wfm.topology.reroute.model.FlowThrottlingData) Comparator(java.util.Comparator)

Example 2 with RerouteQueue

use of org.openkilda.wfm.topology.reroute.model.RerouteQueue in project open-kilda by telstra.

the class RerouteQueueService method processAutomaticRequest.

/**
 * Put reroute request to throttling.
 *
 * @param flowId flow id
 * @param throttlingData reroute request params
 */
public void processAutomaticRequest(String flowId, FlowThrottlingData throttlingData) {
    if (throttlingData.isYFlow()) {
        Optional<YFlow> flow = yFlowRepository.findById(flowId);
        if (!flow.isPresent()) {
            log.warn(format("Y-flow %s not found. Skip the reroute operation of this flow.", flowId));
            return;
        } else if (flow.get().isPinned()) {
            log.info(format("Y-flow %s is pinned. Skip the reroute operation of this flow.", flowId));
            return;
        }
    } else {
        Optional<Flow> flow = flowRepository.findById(flowId);
        if (!flow.isPresent()) {
            log.warn(format("Flow %s not found. Skip the reroute operation of this flow.", flowId));
            return;
        } else if (flow.get().isPinned()) {
            log.info(format("Flow %s is pinned. Skip the reroute operation of this flow.", flowId));
            return;
        }
    }
    log.info("Puts reroute request for flow {} with correlationId {}.", flowId, throttlingData.getCorrelationId());
    RerouteQueue rerouteQueue = getRerouteQueue(flowId);
    rerouteQueue.putToThrottling(throttlingData);
    carrier.sendExtendTimeWindowEvent();
}
Also used : YFlow(org.openkilda.model.YFlow) RerouteQueue(org.openkilda.wfm.topology.reroute.model.RerouteQueue) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow)

Example 3 with RerouteQueue

use of org.openkilda.wfm.topology.reroute.model.RerouteQueue in project open-kilda by telstra.

the class RerouteQueueService method processRerouteResult.

/**
 * Process reroute result. Check fail reason, decide if retry is needed and schedule it if yes.
 *
 * @param rerouteResultInfoData reroute result
 * @param correlationId correlation id
 */
public void processRerouteResult(RerouteResultInfoData rerouteResultInfoData, String correlationId) {
    String flowId = rerouteResultInfoData.getFlowId();
    RerouteQueue rerouteQueue = getRerouteQueue(flowId);
    FlowThrottlingData inProgress = rerouteQueue.getInProgress();
    if (inProgress == null || !Objects.equals(inProgress.getCorrelationId(), correlationId)) {
        log.error("Skipped unexpected reroute result for flow {} with correlation id {}.", flowId, correlationId);
        return;
    }
    carrier.cancelTimeout(correlationId);
    if (rerouteResultInfoData.isSuccess()) {
        FlowThrottlingData toSend = rerouteQueue.processPending();
        sendRerouteRequest(flowId, toSend);
    } else {
        RerouteError rerouteError = rerouteResultInfoData.getRerouteError();
        if (isRetryRequired(flowId, rerouteError, rerouteResultInfoData.isYFlow())) {
            injectRetry(flowId, rerouteQueue, rerouteError instanceof NoPathFoundError);
        } else {
            FlowThrottlingData toSend = rerouteQueue.processPending();
            sendRerouteRequest(flowId, toSend);
        }
    }
}
Also used : NoPathFoundError(org.openkilda.messaging.info.reroute.error.NoPathFoundError) FlowThrottlingData(org.openkilda.wfm.topology.reroute.model.FlowThrottlingData) RerouteQueue(org.openkilda.wfm.topology.reroute.model.RerouteQueue) RerouteError(org.openkilda.messaging.info.reroute.error.RerouteError)

Example 4 with RerouteQueue

use of org.openkilda.wfm.topology.reroute.model.RerouteQueue in project open-kilda by telstra.

the class RerouteQueueServiceTest method shouldSendManualRerouteRequestWithoutThrottling.

@Test
public void shouldSendManualRerouteRequestWithoutThrottling() {
    FlowThrottlingData throttling = getFlowThrottlingData(flow, "another one").build();
    RerouteQueue rerouteQueue = RerouteQueue.builder().throttling(throttling).build();
    rerouteQueueService.getReroutes().put(FLOW_ID, rerouteQueue);
    FlowThrottlingData actual = getFlowThrottlingData(flow, CORRELATION_ID).build();
    rerouteQueueService.processManualRequest(FLOW_ID, actual);
    assertEquals(1, rerouteQueueService.getReroutes().size());
    assertEquals(actual, rerouteQueue.getInProgress());
    assertNull(rerouteQueue.getPending());
    assertEquals(throttling, rerouteQueue.getThrottling());
    FlowRerouteRequest expected = getFlowRerouteRequest(FLOW_ID, actual);
    verify(carrier).sendRerouteRequest(eq(CORRELATION_ID), eq(expected));
}
Also used : FlowThrottlingData(org.openkilda.wfm.topology.reroute.model.FlowThrottlingData) RerouteQueue(org.openkilda.wfm.topology.reroute.model.RerouteQueue) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) YFlowRerouteRequest(org.openkilda.messaging.command.yflow.YFlowRerouteRequest) Test(org.junit.Test)

Example 5 with RerouteQueue

use of org.openkilda.wfm.topology.reroute.model.RerouteQueue in project open-kilda by telstra.

the class RerouteQueueServiceTest method shouldSendExtendTimeWindowEventForRerouteRequestInThrottling.

@Test
public void shouldSendExtendTimeWindowEventForRerouteRequestInThrottling() {
    FlowThrottlingData actual = getFlowThrottlingData(flow, CORRELATION_ID).build();
    rerouteQueueService.processAutomaticRequest(FLOW_ID, actual);
    assertEquals(1, rerouteQueueService.getReroutes().size());
    assertNotNull(rerouteQueueService.getReroutes().get(FLOW_ID));
    RerouteQueue rerouteQueue = rerouteQueueService.getReroutes().get(FLOW_ID);
    assertNull(rerouteQueue.getInProgress());
    assertNull(rerouteQueue.getPending());
    assertEquals(actual, rerouteQueue.getThrottling());
    verify(carrier).sendExtendTimeWindowEvent();
}
Also used : FlowThrottlingData(org.openkilda.wfm.topology.reroute.model.FlowThrottlingData) RerouteQueue(org.openkilda.wfm.topology.reroute.model.RerouteQueue) Test(org.junit.Test)

Aggregations

RerouteQueue (org.openkilda.wfm.topology.reroute.model.RerouteQueue)19 FlowThrottlingData (org.openkilda.wfm.topology.reroute.model.FlowThrottlingData)17 Test (org.junit.Test)15 YFlowRerouteRequest (org.openkilda.messaging.command.yflow.YFlowRerouteRequest)7 RerouteResultInfoData (org.openkilda.messaging.info.reroute.RerouteResultInfoData)6 FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)5 SpeakerRequestError (org.openkilda.messaging.info.reroute.error.SpeakerRequestError)4 IslEndpoint (org.openkilda.model.IslEndpoint)4 Flow (org.openkilda.model.Flow)3 YFlow (org.openkilda.model.YFlow)3 YSubFlow (org.openkilda.model.YSubFlow)3 ErrorData (org.openkilda.messaging.error.ErrorData)2 NoPathFoundError (org.openkilda.messaging.info.reroute.error.NoPathFoundError)2 RerouteError (org.openkilda.messaging.info.reroute.error.RerouteError)2 RerouteInProgressError (org.openkilda.messaging.info.reroute.error.RerouteInProgressError)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 String.format (java.lang.String.format)1 Instant (java.time.Instant)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1