Search in sources :

Example 6 with FlowThrottlingData

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

the class RerouteQueueServiceTest method shouldSendThrottledRequestOnFlushWindowEvent.

@Test
public void shouldSendThrottledRequestOnFlushWindowEvent() {
    FlowThrottlingData throttling = getFlowThrottlingData(flow, CORRELATION_ID).build();
    RerouteQueue rerouteQueue = RerouteQueue.builder().throttling(throttling).build();
    rerouteQueueService.getReroutes().put(FLOW_ID, rerouteQueue);
    rerouteQueueService.flushThrottling();
    assertEquals(throttling, rerouteQueue.getInProgress());
    assertNull(rerouteQueue.getPending());
    assertNull(rerouteQueue.getThrottling());
    FlowRerouteRequest expectedRequest = getFlowRerouteRequest(FLOW_ID, throttling);
    verify(carrier).sendRerouteRequest(any(String.class), eq(expectedRequest));
}
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 7 with FlowThrottlingData

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

the class RerouteQueueServiceTest method shouldNotInjectRetryWhenRetryCountIsExceeded.

@Test
public void shouldNotInjectRetryWhenRetryCountIsExceeded() {
    FlowThrottlingData inProgress = getFlowThrottlingData(flow, CORRELATION_ID).build();
    inProgress.setRetryCounter(4);
    RerouteQueue rerouteQueue = RerouteQueue.builder().inProgress(inProgress).build();
    rerouteQueueService.getReroutes().put(FLOW_ID, rerouteQueue);
    rerouteQueueService.handleTimeout(CORRELATION_ID);
    assertNull(rerouteQueue.getInProgress());
    assertNull(rerouteQueue.getPending());
    assertNull(rerouteQueue.getThrottling());
}
Also used : FlowThrottlingData(org.openkilda.wfm.topology.reroute.model.FlowThrottlingData) RerouteQueue(org.openkilda.wfm.topology.reroute.model.RerouteQueue) Test(org.junit.Test)

Example 8 with FlowThrottlingData

use of org.openkilda.wfm.topology.reroute.model.FlowThrottlingData 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 9 with FlowThrottlingData

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

the class RerouteQueueService method injectRetry.

private void injectRetry(String flowId, RerouteQueue rerouteQueue, boolean ignoreBandwidth) {
    log.info("Injecting retry for flow {} wuth ignore b/w flag {}", flowId, ignoreBandwidth);
    FlowThrottlingData retryRequest = rerouteQueue.getInProgress();
    if (retryRequest == null) {
        throw new IllegalStateException(format("Can not retry 'null' reroute request for flow %s.", flowId));
    }
    retryRequest.setIgnoreBandwidth(computeIgnoreBandwidth(retryRequest, ignoreBandwidth));
    if (retryRequest.getRetryCounter() < maxRetry) {
        retryRequest.increaseRetryCounter();
        String retryCorrelationId = new CommandContext(retryRequest.getCorrelationId()).fork(format("retry #%d ignore_bw %b", retryRequest.getRetryCounter(), retryRequest.isIgnoreBandwidth())).getCorrelationId();
        retryRequest.setCorrelationId(retryCorrelationId);
        FlowThrottlingData toSend = rerouteQueue.processRetryRequest(retryRequest, carrier);
        sendRerouteRequest(flowId, toSend);
    } else {
        log.error("No more retries available for reroute request {}.", retryRequest);
        FlowThrottlingData toSend = rerouteQueue.processPending();
        if (toSend != null) {
            toSend.setIgnoreBandwidth(computeIgnoreBandwidth(toSend, ignoreBandwidth));
        }
        sendRerouteRequest(flowId, toSend);
    }
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) FlowThrottlingData(org.openkilda.wfm.topology.reroute.model.FlowThrottlingData)

Example 10 with FlowThrottlingData

use of org.openkilda.wfm.topology.reroute.model.FlowThrottlingData 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)

Aggregations

FlowThrottlingData (org.openkilda.wfm.topology.reroute.model.FlowThrottlingData)34 Test (org.junit.Test)26 RerouteQueue (org.openkilda.wfm.topology.reroute.model.RerouteQueue)17 YFlowRerouteRequest (org.openkilda.messaging.command.yflow.YFlowRerouteRequest)9 IslEndpoint (org.openkilda.model.IslEndpoint)8 PersistenceManager (org.openkilda.persistence.PersistenceManager)7 FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)6 RerouteResultInfoData (org.openkilda.messaging.info.reroute.RerouteResultInfoData)6 RepositoryFactory (org.openkilda.persistence.repositories.RepositoryFactory)6 YFlowRepository (org.openkilda.persistence.repositories.YFlowRepository)6 YFlow (org.openkilda.model.YFlow)5 PathNode (org.openkilda.messaging.info.event.PathNode)4 SpeakerRequestError (org.openkilda.messaging.info.reroute.error.SpeakerRequestError)4 Flow (org.openkilda.model.Flow)4 FlowPathRepository (org.openkilda.persistence.repositories.FlowPathRepository)4 FlowRepository (org.openkilda.persistence.repositories.FlowRepository)4 SwitchId (org.openkilda.model.SwitchId)3 HashMap (java.util.HashMap)2 Set (java.util.Set)2 RerouteAffectedFlows (org.openkilda.messaging.command.reroute.RerouteAffectedFlows)2