Search in sources :

Example 1 with TransitFlowLoopSegmentRequestFactory

use of org.openkilda.floodlight.api.request.factory.TransitFlowLoopSegmentRequestFactory 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 2 with TransitFlowLoopSegmentRequestFactory

use of org.openkilda.floodlight.api.request.factory.TransitFlowLoopSegmentRequestFactory in project open-kilda by telstra.

the class InstallIngressRulesAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowPathSwapContext context, FlowPathSwapFsm stateMachine) {
    String flowId = stateMachine.getFlowId();
    Flow flow = getFlow(flowId);
    FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(flow.getEncapsulationType());
    FlowPath newPrimaryForward = flow.getForwardPath();
    FlowPath newPrimaryReverse = flow.getReversePath();
    SpeakerRequestBuildContext speakerContext = buildBaseSpeakerContextForInstall(flow.getSrcSwitchId(), flow.getDestSwitchId());
    Collection<FlowSegmentRequestFactory> commands = new ArrayList<>(commandBuilder.buildIngressOnly(stateMachine.getCommandContext(), flow, newPrimaryForward, newPrimaryReverse, speakerContext));
    commands.addAll(commandBuilder.buildEgressOnly(stateMachine.getCommandContext(), flow, newPrimaryForward, newPrimaryReverse).stream().filter(f -> f instanceof TransitFlowLoopSegmentRequestFactory || f instanceof EgressMirrorFlowSegmentRequestFactory).collect(Collectors.toList()));
    // Installation of ingress rules for protected paths is skipped. These paths are activated on swap.
    stateMachine.clearPendingAndRetriedAndFailedCommands();
    SpeakerInstallSegmentEmitter.INSTANCE.emitBatch(stateMachine.getCarrier(), commands, stateMachine.getIngressCommands());
    stateMachine.getIngressCommands().forEach((key, value) -> stateMachine.addPendingCommand(key, value.getSwitchId()));
    stateMachine.saveActionToHistory("Commands for installing ingress rules have been sent");
}
Also used : EgressMirrorFlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.EgressMirrorFlowSegmentRequestFactory) FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) TransitFlowLoopSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.TransitFlowLoopSegmentRequestFactory) EgressMirrorFlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.EgressMirrorFlowSegmentRequestFactory) 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)

Aggregations

ArrayList (java.util.ArrayList)2 FlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory)2 TransitFlowLoopSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.TransitFlowLoopSegmentRequestFactory)2 Flow (org.openkilda.model.Flow)2 FlowPath (org.openkilda.model.FlowPath)2 SpeakerRequestBuildContext (org.openkilda.wfm.share.model.SpeakerRequestBuildContext)2 FlowCommandBuilder (org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder)2 EgressMirrorFlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.EgressMirrorFlowSegmentRequestFactory)1 IngressFlowLoopSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.IngressFlowLoopSegmentRequestFactory)1 FlowEncapsulationType (org.openkilda.model.FlowEncapsulationType)1 CommandContext (org.openkilda.wfm.CommandContext)1 MirrorContext (org.openkilda.wfm.share.model.MirrorContext)1 RequestedFlow (org.openkilda.wfm.topology.flowhs.model.RequestedFlow)1