Search in sources :

Example 16 with RequestedFlow

use of org.openkilda.wfm.topology.flowhs.model.RequestedFlow in project open-kilda by telstra.

the class FlowValidator method checkAffinityFlow.

@VisibleForTesting
void checkAffinityFlow(RequestedFlow targetFlow) throws InvalidFlowException {
    if (targetFlow.getSrcSwitch().equals(targetFlow.getDestSwitch())) {
        throw new InvalidFlowException("Couldn't add one-switch flow into affinity group", ErrorType.PARAMETERS_INVALID);
    }
    Flow affinityFlow = flowRepository.findById(targetFlow.getAffinityFlowId()).orElseThrow(() -> new InvalidFlowException(format("Failed to find affinity flow id %s", targetFlow.getAffinityFlowId()), ErrorType.PARAMETERS_INVALID));
    if (affinityFlow.isOneSwitchFlow()) {
        throw new InvalidFlowException("Couldn't create affinity group with one-switch flow", ErrorType.PARAMETERS_INVALID);
    }
    if (StringUtils.isNotBlank(affinityFlow.getAffinityGroupId())) {
        String mainAffinityFlowId = affinityFlow.getAffinityGroupId();
        Flow mainAffinityFlow = flowRepository.findById(mainAffinityFlowId).orElseThrow(() -> new InvalidFlowException(format("Failed to find main affinity flow id %s", mainAffinityFlowId), ErrorType.PARAMETERS_INVALID));
        if (StringUtils.isNotBlank(mainAffinityFlow.getDiverseGroupId())) {
            Collection<String> diverseFlowIds = flowRepository.findFlowsIdByAffinityGroupId(mainAffinityFlow.getDiverseGroupId()).stream().filter(Objects::nonNull).collect(Collectors.toSet());
            if (!diverseFlowIds.contains(targetFlow.getDiverseFlowId())) {
                throw new InvalidFlowException("Couldn't create a diverse group with flow " + "in a different diverse group than main affinity flow", ErrorType.PARAMETERS_INVALID);
            }
        }
    }
}
Also used : Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 17 with RequestedFlow

use of org.openkilda.wfm.topology.flowhs.model.RequestedFlow in project open-kilda by telstra.

the class FlowValidator method checkDiverseFlow.

@VisibleForTesting
void checkDiverseFlow(RequestedFlow targetFlow) throws InvalidFlowException {
    if (targetFlow.getSrcSwitch().equals(targetFlow.getDestSwitch())) {
        throw new InvalidFlowException("Couldn't add one-switch flow into diverse group", ErrorType.PARAMETERS_INVALID);
    }
    Flow diverseFlow = flowRepository.findById(targetFlow.getDiverseFlowId()).orElse(null);
    if (diverseFlow == null) {
        YFlow diverseYFlow = yFlowRepository.findById(targetFlow.getDiverseFlowId()).orElseThrow(() -> new InvalidFlowException(format("Failed to find diverse flow id %s", targetFlow.getDiverseFlowId()), ErrorType.PARAMETERS_INVALID));
        diverseFlow = diverseYFlow.getSubFlows().stream().map(YSubFlow::getFlow).filter(flow -> flow.getFlowId().equals(flow.getAffinityGroupId())).findFirst().orElseThrow(() -> new InvalidFlowException(format("Failed to find main affinity flow for diverse y-flow id %s", targetFlow.getDiverseFlowId()), ErrorType.INTERNAL_ERROR));
    }
    if (StringUtils.isNotBlank(diverseFlow.getAffinityGroupId())) {
        String diverseFlowId = diverseFlow.getAffinityGroupId();
        diverseFlow = flowRepository.findById(diverseFlowId).orElseThrow(() -> new InvalidFlowException(format("Failed to find diverse flow id %s", diverseFlowId), ErrorType.PARAMETERS_INVALID));
        Collection<String> affinityFlowIds = flowRepository.findFlowsIdByAffinityGroupId(diverseFlow.getAffinityGroupId()).stream().filter(Objects::nonNull).collect(Collectors.toSet());
        if (affinityFlowIds.contains(targetFlow.getAffinityFlowId())) {
            throw new InvalidFlowException("Couldn't create diverse group with flow in the same affinity group", ErrorType.PARAMETERS_INVALID);
        }
    }
    if (diverseFlow.isOneSwitchFlow()) {
        throw new InvalidFlowException("Couldn't create diverse group with one-switch flow", ErrorType.PARAMETERS_INVALID);
    }
}
Also used : YFlow(org.openkilda.model.YFlow) Getter(lombok.Getter) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AccessLevel(lombok.AccessLevel) Flow(org.openkilda.model.Flow) IslRepository(org.openkilda.persistence.repositories.IslRepository) FlowSourceAdapter(org.openkilda.adapter.FlowSourceAdapter) YFlow(org.openkilda.model.YFlow) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) FlowDestAdapter(org.openkilda.adapter.FlowDestAdapter) PersistenceManager(org.openkilda.persistence.PersistenceManager) SwitchProperties(org.openkilda.model.SwitchProperties) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) FlowEndpoint(org.openkilda.model.FlowEndpoint) Switch(org.openkilda.model.Switch) FlowMirrorPointsRepository(org.openkilda.persistence.repositories.FlowMirrorPointsRepository) YSubFlow(org.openkilda.model.YSubFlow) PhysicalPortRepository(org.openkilda.persistence.repositories.PhysicalPortRepository) RequestedFlowMirrorPoint(org.openkilda.wfm.topology.flowhs.model.RequestedFlowMirrorPoint) ErrorType(org.openkilda.messaging.error.ErrorType) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) Collection(java.util.Collection) Set(java.util.Set) FlowMirrorPathRepository(org.openkilda.persistence.repositories.FlowMirrorPathRepository) RequestedFlowMapper(org.openkilda.wfm.topology.flowhs.mapper.RequestedFlowMapper) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Sets(com.google.common.collect.Sets) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) Objects(java.util.Objects) SwitchPropertiesRepository(org.openkilda.persistence.repositories.SwitchPropertiesRepository) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) Optional(java.util.Optional) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AllArgsConstructor(lombok.AllArgsConstructor) PhysicalPort(org.openkilda.model.PhysicalPort) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) YSubFlow(org.openkilda.model.YSubFlow) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 18 with RequestedFlow

use of org.openkilda.wfm.topology.flowhs.model.RequestedFlow in project open-kilda by telstra.

the class FlowValidatorTest method shouldFailOnSwapWhenEqualsEndpointsOnSecondFlow.

@Test(expected = InvalidFlowException.class)
public void shouldFailOnSwapWhenEqualsEndpointsOnSecondFlow() throws InvalidFlowException {
    RequestedFlow firstFlow = RequestedFlow.builder().flowId("firstFlow").srcSwitch(SWITCH_ID_2).srcPort(10).srcVlan(11).destSwitch(SWITCH_ID_2).destPort(12).detectConnectedDevices(new DetectConnectedDevices()).build();
    RequestedFlow secondFlow = RequestedFlow.builder().flowId("secondFlow").srcSwitch(SWITCH_ID_1).srcPort(10).srcVlan(11).destSwitch(SWITCH_ID_1).destPort(10).destVlan(11).detectConnectedDevices(new DetectConnectedDevices()).build();
    flowValidator.checkForEqualsEndpoints(firstFlow, secondFlow);
}
Also used : DetectConnectedDevices(org.openkilda.wfm.topology.flowhs.model.DetectConnectedDevices) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow) Test(org.junit.Test)

Example 19 with RequestedFlow

use of org.openkilda.wfm.topology.flowhs.model.RequestedFlow in project open-kilda by telstra.

the class FlowValidatorTest method shouldFailOnSwapWhenEqualsEndpointsOnFirstFlow.

@Test(expected = InvalidFlowException.class)
public void shouldFailOnSwapWhenEqualsEndpointsOnFirstFlow() throws InvalidFlowException {
    RequestedFlow firstFlow = RequestedFlow.builder().flowId("firstFlow").srcSwitch(SWITCH_ID_1).srcPort(10).srcVlan(11).destSwitch(SWITCH_ID_2).destPort(10).destVlan(11).detectConnectedDevices(new DetectConnectedDevices()).build();
    RequestedFlow secondFlow = RequestedFlow.builder().flowId("secondFlow").srcSwitch(SWITCH_ID_2).destSwitch(SWITCH_ID_2).detectConnectedDevices(new DetectConnectedDevices()).build();
    flowValidator.checkForEqualsEndpoints(firstFlow, secondFlow);
}
Also used : DetectConnectedDevices(org.openkilda.wfm.topology.flowhs.model.DetectConnectedDevices) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow) Test(org.junit.Test)

Example 20 with RequestedFlow

use of org.openkilda.wfm.topology.flowhs.model.RequestedFlow in project open-kilda by telstra.

the class RevertSubFlowsAction method perform.

@Override
public void perform(State from, State to, Event event, YFlowUpdateContext context, YFlowUpdateFsm stateMachine) {
    stateMachine.clearUpdatingSubFlows();
    stateMachine.clearAllocatedSubFlows();
    stateMachine.clearFailedSubFlows();
    String yFlowId = stateMachine.getYFlowId();
    Collection<RequestedFlow> originalFlows = YFlowRequestMapper.INSTANCE.toRequestedFlows(stateMachine.getOriginalFlow());
    stateMachine.setRequestedFlows(originalFlows);
    log.debug("Start reverting {} sub-flows for y-flow {}", originalFlows.size(), stateMachine.getYFlowId());
    originalFlows.stream().filter(originalFlow -> originalFlow.getFlowId().equals(stateMachine.getMainAffinityFlowId())).forEach(originalFlow -> {
        String subFlowId = originalFlow.getFlowId();
        CommandContext flowContext = stateMachine.getCommandContext().fork(subFlowId);
        stateMachine.addUpdatingSubFlow(subFlowId);
        stateMachine.notifyEventListeners(listener -> listener.onSubFlowProcessingStart(yFlowId, subFlowId));
        flowUpdateService.startFlowUpdating(flowContext, originalFlow, yFlowId);
    });
}
Also used : YFlowRequestMapper(org.openkilda.wfm.topology.flowhs.mapper.YFlowRequestMapper) Slf4j(lombok.extern.slf4j.Slf4j) HistoryRecordingAction(org.openkilda.wfm.topology.flowhs.fsm.common.actions.HistoryRecordingAction) Collection(java.util.Collection) YFlowUpdateFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.update.YFlowUpdateFsm) Event(org.openkilda.wfm.topology.flowhs.fsm.yflow.update.YFlowUpdateFsm.Event) CommandContext(org.openkilda.wfm.CommandContext) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow) State(org.openkilda.wfm.topology.flowhs.fsm.yflow.update.YFlowUpdateFsm.State) YFlowUpdateContext(org.openkilda.wfm.topology.flowhs.fsm.yflow.update.YFlowUpdateContext) FlowUpdateService(org.openkilda.wfm.topology.flowhs.service.FlowUpdateService) CommandContext(org.openkilda.wfm.CommandContext) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow)

Aggregations

RequestedFlow (org.openkilda.wfm.topology.flowhs.model.RequestedFlow)34 Flow (org.openkilda.model.Flow)12 Test (org.junit.Test)10 DetectConnectedDevices (org.openkilda.wfm.topology.flowhs.model.DetectConnectedDevices)8 YFlow (org.openkilda.model.YFlow)4 YSubFlow (org.openkilda.model.YSubFlow)4 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)4 FlowPath (org.openkilda.model.FlowPath)3 InvalidFlowException (org.openkilda.wfm.topology.flowhs.validation.InvalidFlowException)3 UnavailableFlowEndpointException (org.openkilda.wfm.topology.flowhs.validation.UnavailableFlowEndpointException)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 FlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory)2 Switch (org.openkilda.model.Switch)2 CommandContext (org.openkilda.wfm.CommandContext)2 FlowCommandBuilder (org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder)2 Sets (com.google.common.collect.Sets)1 String.format (java.lang.String.format)1 HashSet (java.util.HashSet)1