Search in sources :

Example 1 with MirrorContext

use of org.openkilda.wfm.share.model.MirrorContext in project open-kilda by telstra.

the class RemoveRulesAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowDeleteContext context, FlowDeleteFsm stateMachine) {
    Flow flow = getFlow(stateMachine.getFlowId());
    FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(flow.getEncapsulationType());
    Collection<FlowSegmentRequestFactory> commands = new ArrayList<>();
    Set<PathId> protectedPaths = Stream.of(flow.getProtectedForwardPathId(), flow.getProtectedReversePathId()).filter(Objects::nonNull).collect(Collectors.toSet());
    Set<PathId> processed = new HashSet<>();
    MirrorContext mirrorContext = MirrorContext.builder().removeFlowOperation(true).build();
    for (FlowPath path : flow.getPaths()) {
        PathId pathId = path.getPathId();
        if (processed.add(pathId)) {
            FlowPath oppositePath = flow.getOppositePathId(pathId).filter(oppPathId -> !pathId.equals(oppPathId)).flatMap(flow::getPath).orElse(null);
            if (oppositePath != null) {
                processed.add(oppositePath.getPathId());
            }
            if (oppositePath != null) {
                stateMachine.getFlowResources().add(buildResources(flow, path, oppositePath));
                if (protectedPaths.contains(pathId)) {
                    commands.addAll(commandBuilder.buildAllExceptIngress(stateMachine.getCommandContext(), flow, path, oppositePath, mirrorContext));
                } else {
                    SpeakerRequestBuildContext speakerRequestBuildContext = SpeakerRequestBuildContext.builder().forward(buildPathContext(flow, path)).reverse(buildPathContext(flow, oppositePath)).deleteOperation(true).build();
                    commands.addAll(commandBuilder.buildAll(stateMachine.getCommandContext(), flow, path, oppositePath, speakerRequestBuildContext, mirrorContext));
                }
            } else {
                log.warn("No opposite path found for {}, trying to delete as unpaired path", pathId);
                stateMachine.getFlowResources().add(buildResources(flow, path, path));
                if (protectedPaths.contains(pathId)) {
                    commands.addAll(commandBuilder.buildAllExceptIngress(stateMachine.getCommandContext(), flow, path, null, mirrorContext));
                } else {
                    SpeakerRequestBuildContext speakerRequestBuildContext = SpeakerRequestBuildContext.builder().forward(buildPathContext(flow, path)).reverse(PathContext.builder().build()).deleteOperation(true).build();
                    commands.addAll(commandBuilder.buildAll(stateMachine.getCommandContext(), flow, path, null, speakerRequestBuildContext, mirrorContext));
                }
            }
        }
    }
    stateMachine.clearPendingAndRetriedCommands();
    if (commands.isEmpty()) {
        stateMachine.saveActionToHistory("No need to remove rules");
        stateMachine.fire(Event.RULES_REMOVED);
    } else {
        SpeakerRemoveSegmentEmitter.INSTANCE.emitBatch(stateMachine.getCarrier(), commands, stateMachine.getRemoveCommands());
        stateMachine.getPendingCommands().addAll(stateMachine.getRemoveCommands().keySet());
        stateMachine.saveActionToHistory("Remove commands for rules have been sent");
    }
}
Also used : PathId(org.openkilda.model.PathId) FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) MirrorContext(org.openkilda.wfm.share.model.MirrorContext) ArrayList(java.util.ArrayList) FlowCommandBuilder(org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder) FlowPath(org.openkilda.model.FlowPath) SpeakerRequestBuildContext(org.openkilda.wfm.share.model.SpeakerRequestBuildContext) Flow(org.openkilda.model.Flow) HashSet(java.util.HashSet)

Example 2 with MirrorContext

use of org.openkilda.wfm.share.model.MirrorContext in project open-kilda by telstra.

the class RevertNewRulesAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowRerouteContext context, FlowRerouteFsm stateMachine) {
    Flow flow = getFlow(stateMachine.getFlowId());
    log.debug("Abandoning all pending commands: {}", stateMachine.getPendingCommands());
    stateMachine.clearPendingAndRetriedAndFailedCommands();
    FlowEncapsulationType encapsulationType = stateMachine.getNewEncapsulationType() != null ? stateMachine.getNewEncapsulationType() : flow.getEncapsulationType();
    FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(encapsulationType);
    Collection<FlowSegmentRequestFactory> installCommands = new ArrayList<>();
    // Reinstall old ingress rules that may be overridden by new ingress.
    if (stateMachine.getOldPrimaryForwardPath() != null && stateMachine.getOldPrimaryReversePath() != null) {
        FlowPath oldForward = getFlowPath(flow, stateMachine.getOldPrimaryForwardPath());
        FlowPath oldReverse = getFlowPath(flow, stateMachine.getOldPrimaryReversePath());
        SpeakerRequestBuildContext installContext = buildBaseSpeakerContextForInstall(oldForward.getSrcSwitchId(), oldReverse.getSrcSwitchId());
        installCommands.addAll(commandBuilder.buildIngressOnly(stateMachine.getCommandContext(), flow, oldForward, oldReverse, installContext));
    }
    // need to clean previous requests
    stateMachine.getIngressCommands().clear();
    SpeakerInstallSegmentEmitter.INSTANCE.emitBatch(stateMachine.getCarrier(), installCommands, stateMachine.getIngressCommands());
    stateMachine.getIngressCommands().forEach((key, value) -> stateMachine.addPendingCommand(key, value.getSwitchId()));
    // Remove possible installed flow segments
    MirrorContext mirrorContext = MirrorContext.builder().removeFlowOperation(true).build();
    Collection<FlowSegmentRequestFactory> removeCommands = new ArrayList<>();
    if (stateMachine.getNewPrimaryForwardPath() != null && stateMachine.getNewPrimaryReversePath() != null) {
        FlowPath newForward = getFlowPath(flow, stateMachine.getNewPrimaryForwardPath());
        FlowPath newReverse = getFlowPath(flow, stateMachine.getNewPrimaryReversePath());
        SpeakerRequestBuildContext speakerContext = buildSpeakerContextForRemovalIngressOnly(newForward.getSrcSwitchId(), newReverse.getSrcSwitchId());
        removeCommands.addAll(commandBuilder.buildAll(stateMachine.getCommandContext(), flow, newForward, newReverse, speakerContext, mirrorContext));
    }
    if (stateMachine.getNewProtectedForwardPath() != null && stateMachine.getNewProtectedReversePath() != null) {
        FlowPath newForward = getFlowPath(flow, stateMachine.getNewProtectedForwardPath());
        FlowPath newReverse = getFlowPath(flow, stateMachine.getNewProtectedReversePath());
        removeCommands.addAll(commandBuilder.buildAllExceptIngress(stateMachine.getCommandContext(), flow, newForward, newReverse, mirrorContext));
    }
    stateMachine.getRemoveCommands().clear();
    SpeakerRemoveSegmentEmitter.INSTANCE.emitBatch(stateMachine.getCarrier(), removeCommands, stateMachine.getRemoveCommands());
    stateMachine.getRemoveCommands().forEach((key, value) -> stateMachine.addPendingCommand(key, value.getSwitchId()));
    if (stateMachine.getPendingCommands().isEmpty()) {
        stateMachine.saveActionToHistory("No need to remove new rules or re-install original ingress rule");
        stateMachine.fire(Event.RULES_REMOVED);
    } else {
        stateMachine.saveActionToHistory("Commands for removing new rules and re-installing original ingress rule have been sent");
    }
}
Also used : FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) MirrorContext(org.openkilda.wfm.share.model.MirrorContext) ArrayList(java.util.ArrayList) FlowCommandBuilder(org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) FlowPath(org.openkilda.model.FlowPath) SpeakerRequestBuildContext(org.openkilda.wfm.share.model.SpeakerRequestBuildContext) Flow(org.openkilda.model.Flow)

Example 3 with MirrorContext

use of org.openkilda.wfm.share.model.MirrorContext in project open-kilda by telstra.

the class RemoveOldRulesAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowUpdateContext context, FlowUpdateFsm stateMachine) {
    FlowEncapsulationType oldEncapsulationType = stateMachine.getOriginalFlow().getFlowEncapsulationType();
    FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(oldEncapsulationType);
    Collection<FlowSegmentRequestFactory> factories = new ArrayList<>();
    Flow originalFlow = getOriginalFlowWithPaths(stateMachine, stateMachine.getOriginalFlow());
    MirrorContext mirrorContext = MirrorContext.builder().removeFlowOperation(true).build();
    if (stateMachine.getEndpointUpdate().isPartialUpdate()) {
        SpeakerRequestBuildContext speakerContext = getSpeakerRequestBuildContext(stateMachine, false);
        FlowPath forward = getFlowPath(stateMachine.getOldPrimaryForwardPath());
        FlowPath reverse = getFlowPath(stateMachine.getOldPrimaryReversePath());
        switch(stateMachine.getEndpointUpdate()) {
            case SOURCE:
                factories.addAll(buildCommandsForSourceUpdate(commandBuilder, stateMachine, originalFlow, forward, reverse, speakerContext, mirrorContext.toBuilder().removeGroup(false).build()));
                break;
            case DESTINATION:
                factories.addAll(buildCommandsForDestinationUpdate(commandBuilder, stateMachine, originalFlow, forward, reverse, speakerContext, mirrorContext.toBuilder().removeGroup(false).build()));
                break;
            case BOTH:
            default:
                switch(stateMachine.getFlowLoopOperation()) {
                    case DELETE:
                        factories.addAll(commandBuilder.buildIngressOnly(stateMachine.getCommandContext(), originalFlow, forward, reverse, speakerContext).stream().filter(f -> f instanceof IngressFlowLoopSegmentRequestFactory).collect(Collectors.toList()));
                        break;
                    case CREATE:
                        // No rules removing required
                        break;
                    case NONE:
                    default:
                        factories.addAll(commandBuilder.buildIngressOnly(stateMachine.getCommandContext(), originalFlow, forward, reverse, speakerContext, mirrorContext.toBuilder().removeGroup(false).build()));
                        break;
                }
                break;
        }
    } else {
        SpeakerRequestBuildContext speakerContext = getSpeakerRequestBuildContext(stateMachine, true);
        if (stateMachine.getOldPrimaryForwardPath() != null) {
            FlowPath oldForward = getFlowPath(stateMachine.getOldPrimaryForwardPath());
            if (stateMachine.getOldPrimaryReversePath() != null) {
                FlowPath oldReverse = getFlowPath(stateMachine.getOldPrimaryReversePath());
                factories.addAll(commandBuilder.buildAll(stateMachine.getCommandContext(), originalFlow, oldForward, oldReverse, speakerContext, mirrorContext));
            } else {
                factories.addAll(commandBuilder.buildAll(stateMachine.getCommandContext(), originalFlow, oldForward, speakerContext, mirrorContext));
            }
        } else if (stateMachine.getOldPrimaryReversePath() != null) {
            FlowPath oldReverse = getFlowPath(stateMachine.getOldPrimaryReversePath());
            // swap contexts
            speakerContext.setForward(speakerContext.getReverse());
            speakerContext.setReverse(PathContext.builder().build());
            factories.addAll(commandBuilder.buildAll(stateMachine.getCommandContext(), originalFlow, oldReverse, speakerContext, mirrorContext));
        }
        if (stateMachine.getOldProtectedForwardPath() != null) {
            FlowPath oldForward = getFlowPath(stateMachine.getOldProtectedForwardPath());
            if (stateMachine.getOldProtectedReversePath() != null) {
                FlowPath oldReverse = getFlowPath(stateMachine.getOldProtectedReversePath());
                factories.addAll(commandBuilder.buildAllExceptIngress(stateMachine.getCommandContext(), originalFlow, oldForward, oldReverse, mirrorContext));
            } else {
                factories.addAll(commandBuilder.buildAllExceptIngress(stateMachine.getCommandContext(), originalFlow, oldForward, mirrorContext));
            }
        } else if (stateMachine.getOldProtectedReversePath() != null) {
            FlowPath oldReverse = getFlowPath(stateMachine.getOldProtectedReversePath());
            factories.addAll(commandBuilder.buildAllExceptIngress(stateMachine.getCommandContext(), originalFlow, oldReverse, mirrorContext));
        }
    }
    stateMachine.clearPendingAndRetriedAndFailedCommands();
    if (factories.isEmpty()) {
        stateMachine.saveActionToHistory("No need to remove old rules");
        stateMachine.fire(Event.RULES_REMOVED);
    } else {
        SpeakerRemoveSegmentEmitter.INSTANCE.emitBatch(stateMachine.getCarrier(), factories, stateMachine.getRemoveCommands());
        stateMachine.getRemoveCommands().forEach((key, value) -> stateMachine.addPendingCommand(key, value.getSwitchId()));
        stateMachine.saveActionToHistory("Remove commands for old rules have been sent");
    }
}
Also used : FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) MirrorContext(org.openkilda.wfm.share.model.MirrorContext) IngressFlowLoopSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.IngressFlowLoopSegmentRequestFactory) ArrayList(java.util.ArrayList) FlowCommandBuilder(org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) SpeakerRequestBuildContext(org.openkilda.wfm.share.model.SpeakerRequestBuildContext) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow)

Example 4 with MirrorContext

use of org.openkilda.wfm.share.model.MirrorContext in project open-kilda by telstra.

the class RevertNewRulesAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowUpdateContext context, FlowUpdateFsm stateMachine) {
    String flowId = stateMachine.getFlowId();
    Flow flow = getFlow(flowId);
    log.debug("Abandoning all pending commands: {}", stateMachine.getPendingCommands());
    stateMachine.clearPendingAndRetriedAndFailedCommands();
    FlowEncapsulationType encapsulationType = stateMachine.getTargetFlow().getFlowEncapsulationType();
    FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(encapsulationType);
    Collection<FlowSegmentRequestFactory> installCommands = new ArrayList<>();
    // Reinstall old ingress rules that may be overridden by new ingress.
    if (stateMachine.getOldPrimaryForwardPath() != null && stateMachine.getOldPrimaryReversePath() != null) {
        FlowPath oldForward = getFlowPath(flow, stateMachine.getOldPrimaryForwardPath());
        FlowPath oldReverse = getFlowPath(flow, stateMachine.getOldPrimaryReversePath());
        SpeakerRequestBuildContext speakerContext = buildBaseSpeakerContextForInstall(oldForward.getSrcSwitchId(), oldReverse.getSrcSwitchId());
        installCommands.addAll(commandBuilder.buildIngressOnly(stateMachine.getCommandContext(), flow, oldForward, oldReverse, speakerContext));
    }
    // need to clean previous requests
    stateMachine.getIngressCommands().clear();
    SpeakerInstallSegmentEmitter.INSTANCE.emitBatch(stateMachine.getCarrier(), installCommands, stateMachine.getIngressCommands());
    stateMachine.getIngressCommands().forEach((key, value) -> stateMachine.addPendingCommand(key, value.getSwitchId()));
    CommandContext commandContext = stateMachine.getCommandContext();
    // Remove possible installed segments
    MirrorContext mirrorContext = MirrorContext.builder().removeFlowOperation(true).build();
    Collection<FlowSegmentRequestFactory> revertCommands = new ArrayList<>();
    if (stateMachine.getNewPrimaryForwardPath() != null && stateMachine.getNewPrimaryReversePath() != null) {
        FlowPath newForward = getFlowPath(flow, stateMachine.getNewPrimaryForwardPath());
        FlowPath newReverse = getFlowPath(flow, stateMachine.getNewPrimaryReversePath());
        if (stateMachine.getEndpointUpdate().isPartialUpdate()) {
            SpeakerRequestBuildContext speakerRequestBuildContext = getSpeakerRequestBuildContextForRemoval(stateMachine, false);
            Flow oldFlow = RequestedFlowMapper.INSTANCE.toFlow(stateMachine.getOriginalFlow());
            switch(stateMachine.getEndpointUpdate()) {
                case SOURCE:
                    switch(stateMachine.getFlowLoopOperation()) {
                        case NONE:
                            revertCommands.addAll(commandBuilder.buildIngressOnlyOneDirection(commandContext, flow, newForward, newReverse, speakerRequestBuildContext.getForward(), mirrorContext));
                            revertCommands.addAll(commandBuilder.buildEgressOnlyOneDirection(commandContext, oldFlow, newReverse, newForward, mirrorContext));
                            break;
                        case CREATE:
                            revertCommands.addAll(commandBuilder.buildAll(commandContext, flow, newForward, newReverse, speakerRequestBuildContext).stream().filter(f -> f instanceof IngressFlowLoopSegmentRequestFactory || f instanceof TransitFlowLoopSegmentRequestFactory).collect(Collectors.toList()));
                            break;
                        case DELETE:
                        default:
                            // No need to revert rules
                            break;
                    }
                    break;
                case DESTINATION:
                    switch(stateMachine.getFlowLoopOperation()) {
                        case NONE:
                            revertCommands.addAll(commandBuilder.buildIngressOnlyOneDirection(commandContext, flow, newReverse, newForward, speakerRequestBuildContext.getReverse(), mirrorContext));
                            revertCommands.addAll(commandBuilder.buildEgressOnlyOneDirection(commandContext, oldFlow, newForward, newReverse, mirrorContext));
                            break;
                        case CREATE:
                            revertCommands.addAll(commandBuilder.buildAll(commandContext, flow, newForward, newReverse, speakerRequestBuildContext).stream().filter(f -> f instanceof IngressFlowLoopSegmentRequestFactory || f instanceof TransitFlowLoopSegmentRequestFactory).collect(Collectors.toList()));
                            break;
                        case DELETE:
                        default:
                            // No need to revert rules
                            break;
                    }
                    break;
                default:
                    revertCommands.addAll(commandBuilder.buildIngressOnly(commandContext, flow, newForward, newReverse, speakerRequestBuildContext, mirrorContext));
                    revertCommands.addAll(commandBuilder.buildEgressOnly(commandContext, oldFlow, newForward, newReverse, mirrorContext));
                    break;
            }
        } else {
            revertCommands.addAll(commandBuilder.buildAll(stateMachine.getCommandContext(), flow, newForward, newReverse, getSpeakerRequestBuildContextForRemoval(stateMachine, true), mirrorContext));
        }
    }
    if (stateMachine.getNewProtectedForwardPath() != null && stateMachine.getNewProtectedReversePath() != null) {
        FlowPath newForward = getFlowPath(flow, stateMachine.getNewProtectedForwardPath());
        FlowPath newReverse = getFlowPath(flow, stateMachine.getNewProtectedReversePath());
        Flow oldFlow = RequestedFlowMapper.INSTANCE.toFlow(stateMachine.getOriginalFlow());
        if (stateMachine.getEndpointUpdate().isPartialUpdate()) {
            switch(stateMachine.getEndpointUpdate()) {
                case SOURCE:
                    if (stateMachine.getFlowLoopOperation() == NONE) {
                        revertCommands.addAll(commandBuilder.buildEgressOnlyOneDirection(commandContext, oldFlow, newReverse, newForward, mirrorContext));
                    }
                    break;
                case DESTINATION:
                    if (stateMachine.getFlowLoopOperation() == NONE) {
                        revertCommands.addAll(commandBuilder.buildEgressOnlyOneDirection(commandContext, oldFlow, newForward, newReverse, mirrorContext));
                    }
                    break;
                default:
                    revertCommands.addAll(commandBuilder.buildEgressOnly(commandContext, oldFlow, newForward, newReverse, mirrorContext));
                    break;
            }
        } else {
            revertCommands.addAll(commandBuilder.buildAllExceptIngress(stateMachine.getCommandContext(), flow, newForward, newReverse, mirrorContext));
        }
    }
    stateMachine.getRemoveCommands().clear();
    SpeakerRemoveSegmentEmitter.INSTANCE.emitBatch(stateMachine.getCarrier(), revertCommands, stateMachine.getRemoveCommands());
    stateMachine.getRemoveCommands().forEach((key, value) -> stateMachine.addPendingCommand(key, value.getSwitchId()));
    if (stateMachine.getPendingCommands().isEmpty()) {
        stateMachine.saveActionToHistory("No need to remove new rules or re-install original ingress rule");
        stateMachine.fire(Event.RULES_REMOVED);
    } else {
        stateMachine.saveActionToHistory("Commands for removing new rules and re-installing original ingress rule have been sent");
    }
}
Also used : TransitFlowLoopSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.TransitFlowLoopSegmentRequestFactory) MirrorContext(org.openkilda.wfm.share.model.MirrorContext) CommandContext(org.openkilda.wfm.CommandContext) ArrayList(java.util.ArrayList) FlowCommandBuilder(org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) SpeakerRequestBuildContext(org.openkilda.wfm.share.model.SpeakerRequestBuildContext) Flow(org.openkilda.model.Flow) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow) FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) IngressFlowLoopSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.IngressFlowLoopSegmentRequestFactory) FlowPath(org.openkilda.model.FlowPath)

Example 5 with MirrorContext

use of org.openkilda.wfm.share.model.MirrorContext in project open-kilda by telstra.

the class RemoveOldRulesAction method perform.

@TimedExecution("fsm.remove_old_rules")
@Override
protected void perform(State from, State to, Event event, FlowRerouteContext context, FlowRerouteFsm stateMachine) {
    FlowEncapsulationType encapsulationType = stateMachine.getOriginalEncapsulationType();
    FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(encapsulationType);
    Collection<FlowSegmentRequestFactory> factories = new ArrayList<>();
    Flow originalFlow = getOriginalFlowWithPaths(stateMachine, stateMachine.getOriginalFlow());
    SpeakerRequestBuildContext speakerContext = SpeakerRequestBuildContext.getEmpty();
    MirrorContext mirrorContext = MirrorContext.builder().removeFlowOperation(true).build();
    if (stateMachine.getOldPrimaryForwardPath() != null) {
        FlowPath oldForward = getFlowPath(stateMachine.getOldPrimaryForwardPath());
        speakerContext.setForward(buildPathContextForRemovalIngressOnly(oldForward.getSrcSwitchId()));
        if (stateMachine.getOldPrimaryReversePath() != null) {
            FlowPath oldReverse = getFlowPath(stateMachine.getOldPrimaryReversePath());
            speakerContext.setReverse(buildPathContextForRemovalIngressOnly(oldReverse.getSrcSwitchId()));
            factories.addAll(commandBuilder.buildAll(stateMachine.getCommandContext(), originalFlow, oldForward, oldReverse, speakerContext, mirrorContext));
        } else {
            factories.addAll(commandBuilder.buildAll(stateMachine.getCommandContext(), originalFlow, oldForward, speakerContext, mirrorContext));
        }
    } else if (stateMachine.getOldPrimaryReversePath() != null) {
        FlowPath oldReverse = getFlowPath(stateMachine.getOldPrimaryReversePath());
        speakerContext.setForward(buildPathContextForRemovalIngressOnly(oldReverse.getSrcSwitchId()));
        factories.addAll(commandBuilder.buildAll(stateMachine.getCommandContext(), originalFlow, oldReverse, speakerContext, mirrorContext));
    }
    if (stateMachine.getOldProtectedForwardPath() != null) {
        FlowPath oldForward = getFlowPath(stateMachine.getOldProtectedForwardPath());
        if (stateMachine.getOldProtectedReversePath() != null) {
            FlowPath oldReverse = getFlowPath(stateMachine.getOldProtectedReversePath());
            factories.addAll(commandBuilder.buildAllExceptIngress(stateMachine.getCommandContext(), originalFlow, oldForward, oldReverse, mirrorContext));
        } else {
            factories.addAll(commandBuilder.buildAllExceptIngress(stateMachine.getCommandContext(), originalFlow, oldForward, mirrorContext));
        }
    } else if (stateMachine.getOldProtectedReversePath() != null) {
        FlowPath oldReverse = getFlowPath(stateMachine.getOldProtectedReversePath());
        factories.addAll(commandBuilder.buildAllExceptIngress(stateMachine.getCommandContext(), originalFlow, oldReverse, mirrorContext));
    }
    stateMachine.clearPendingAndRetriedAndFailedCommands();
    if (factories.isEmpty()) {
        stateMachine.saveActionToHistory("No need to remove old rules");
        stateMachine.fire(Event.RULES_REMOVED);
    } else {
        Map<UUID, FlowSegmentRequestFactory> requestsStorage = stateMachine.getRemoveCommands();
        for (FlowSegmentRequestFactory factory : factories) {
            FlowSegmentRequest request = factory.makeRemoveRequest(commandIdGenerator.generate());
            // TODO ensure no conflicts
            requestsStorage.put(request.getCommandId(), factory);
            stateMachine.getCarrier().sendSpeakerRequest(request);
        }
        requestsStorage.forEach((key, value) -> stateMachine.addPendingCommand(key, value.getSwitchId()));
        stateMachine.saveActionToHistory("Remove commands for old rules have been sent");
    }
}
Also used : FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) MirrorContext(org.openkilda.wfm.share.model.MirrorContext) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) ArrayList(java.util.ArrayList) FlowCommandBuilder(org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) SpeakerRequestBuildContext(org.openkilda.wfm.share.model.SpeakerRequestBuildContext) FlowPath(org.openkilda.model.FlowPath) UUID(java.util.UUID) Flow(org.openkilda.model.Flow) TimedExecution(org.openkilda.wfm.share.metrics.TimedExecution)

Aggregations

ArrayList (java.util.ArrayList)5 FlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory)5 Flow (org.openkilda.model.Flow)5 FlowPath (org.openkilda.model.FlowPath)5 MirrorContext (org.openkilda.wfm.share.model.MirrorContext)5 SpeakerRequestBuildContext (org.openkilda.wfm.share.model.SpeakerRequestBuildContext)5 FlowCommandBuilder (org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder)5 FlowEncapsulationType (org.openkilda.model.FlowEncapsulationType)4 IngressFlowLoopSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.IngressFlowLoopSegmentRequestFactory)2 RequestedFlow (org.openkilda.wfm.topology.flowhs.model.RequestedFlow)2 HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 FlowSegmentRequest (org.openkilda.floodlight.api.request.FlowSegmentRequest)1 TransitFlowLoopSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.TransitFlowLoopSegmentRequestFactory)1 PathId (org.openkilda.model.PathId)1 CommandContext (org.openkilda.wfm.CommandContext)1 TimedExecution (org.openkilda.wfm.share.metrics.TimedExecution)1