Search in sources :

Example 11 with FlowCommandBuilder

use of org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder 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)

Example 12 with FlowCommandBuilder

use of org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder in project open-kilda by telstra.

the class InstallIngressRulesAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowUpdateContext context, FlowUpdateFsm stateMachine) {
    String flowId = stateMachine.getFlowId();
    RequestedFlow requestedFlow = stateMachine.getTargetFlow();
    Flow flow = getFlow(flowId);
    FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(requestedFlow.getFlowEncapsulationType());
    FlowPath newPrimaryForward = getFlowPath(flow, stateMachine.getNewPrimaryForwardPath());
    FlowPath newPrimaryReverse = getFlowPath(flow, stateMachine.getNewPrimaryReversePath());
    SpeakerRequestBuildContext speakerContext = buildBaseSpeakerContextForInstall(newPrimaryForward.getSrcSwitchId(), newPrimaryReverse.getSrcSwitchId());
    Collection<FlowSegmentRequestFactory> commands = new ArrayList<>();
    switch(stateMachine.getEndpointUpdate()) {
        case SOURCE:
            speakerContext.getForward().setUpdateMeter(false);
            commands.addAll(getCommandsForSourceUpdate(commandBuilder, stateMachine, flow, newPrimaryForward, newPrimaryReverse, speakerContext));
            break;
        case DESTINATION:
            speakerContext.getReverse().setUpdateMeter(false);
            commands.addAll(getCommandsForDestinationUpdate(commandBuilder, stateMachine, flow, newPrimaryForward, newPrimaryReverse, speakerContext));
            break;
        case BOTH:
            speakerContext.getForward().setUpdateMeter(false);
            speakerContext.getReverse().setUpdateMeter(false);
            if (stateMachine.getFlowLoopOperation() == FlowLoopOperation.NONE) {
                commands.addAll(commandBuilder.buildIngressOnly(stateMachine.getCommandContext(), flow, newPrimaryForward, newPrimaryReverse, speakerContext));
            } else {
                commands.addAll(commandBuilder.buildIngressOnly(stateMachine.getCommandContext(), flow, newPrimaryForward, newPrimaryReverse, speakerContext).stream().filter(f -> f instanceof IngressFlowLoopSegmentRequestFactory).collect(Collectors.toList()));
            }
            break;
        default:
            commands.addAll(commandBuilder.buildIngressOnly(stateMachine.getCommandContext(), flow, newPrimaryForward, newPrimaryReverse, speakerContext));
            break;
    }
    // Installation of ingress rules for protected paths is skipped. These paths are activated on swap.
    stateMachine.clearPendingAndRetriedAndFailedCommands();
    if (commands.isEmpty()) {
        stateMachine.saveActionToHistory("No need to install ingress rules");
        stateMachine.fire(Event.INGRESS_IS_SKIPPED);
    } else {
        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 : FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) IngressFlowLoopSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.IngressFlowLoopSegmentRequestFactory) ArrayList(java.util.ArrayList) FlowCommandBuilder(org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow) FlowPath(org.openkilda.model.FlowPath) SpeakerRequestBuildContext(org.openkilda.wfm.share.model.SpeakerRequestBuildContext) Flow(org.openkilda.model.Flow) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow)

Example 13 with FlowCommandBuilder

use of org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder in project open-kilda by telstra.

the class InstallNonIngressRulesAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowUpdateContext context, FlowUpdateFsm stateMachine) {
    String flowId = stateMachine.getFlowId();
    RequestedFlow requestedFlow = stateMachine.getTargetFlow();
    Flow flow = getFlow(flowId);
    FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(requestedFlow.getFlowEncapsulationType());
    // primary path
    FlowPath newPrimaryForward = getFlowPath(flow, stateMachine.getNewPrimaryForwardPath());
    FlowPath newPrimaryReverse = getFlowPath(flow, stateMachine.getNewPrimaryReversePath());
    Collection<FlowSegmentRequestFactory> commands = buildCommands(commandBuilder, stateMachine, flow, newPrimaryForward, newPrimaryReverse);
    // protected path
    if (stateMachine.getNewProtectedForwardPath() != null && stateMachine.getNewProtectedReversePath() != null) {
        FlowPath newProtectedForward = getFlowPath(flow, stateMachine.getNewProtectedForwardPath());
        FlowPath newProtectedReverse = getFlowPath(flow, stateMachine.getNewProtectedReversePath());
        commands.addAll(buildCommands(commandBuilder, stateMachine, flow, newProtectedForward, newProtectedReverse));
    }
    stateMachine.clearPendingAndRetriedAndFailedCommands();
    if (commands.isEmpty()) {
        stateMachine.saveActionToHistory("No need to install non ingress rules");
        stateMachine.fire(Event.RULES_INSTALLED);
    } else {
        // emitting
        SpeakerInstallSegmentEmitter.INSTANCE.emitBatch(stateMachine.getCarrier(), commands, stateMachine.getNonIngressCommands());
        stateMachine.getNonIngressCommands().forEach((key, value) -> stateMachine.addPendingCommand(key, value.getSwitchId()));
        stateMachine.saveActionToHistory("Commands for installing non ingress rules have been sent");
    }
}
Also used : FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) FlowCommandBuilder(org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow)

Example 14 with FlowCommandBuilder

use of org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder 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)

Example 15 with FlowCommandBuilder

use of org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder in project open-kilda by telstra.

the class EmitCommandRequestsAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowMirrorPointDeleteContext context, FlowMirrorPointDeleteFsm stateMachine) {
    String flowId = stateMachine.getFlowId();
    Flow flow = getFlow(flowId);
    PathId flowPathId = stateMachine.getFlowPathId();
    SwitchId mirrorSwitchId = stateMachine.getMirrorSwitchId();
    FlowMirrorPoints mirrorPoints = flowMirrorPointsRepository.findByPathIdAndSwitchId(flowPathId, mirrorSwitchId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Flow mirror points for flow path %s and mirror switch id %s not found", flowPathId, mirrorSwitchId)));
    FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(flow.getEncapsulationType());
    Collection<FlowSegmentRequestFactory> commands = buildCommands(commandBuilder, stateMachine, flow, mirrorPoints);
    // emitting
    SpeakerRequestEmitter requestEmitter;
    if (mirrorPoints.getMirrorPaths().isEmpty()) {
        requestEmitter = SpeakerRemoveSegmentEmitter.INSTANCE;
    } else {
        requestEmitter = SpeakerInstallSegmentEmitter.INSTANCE;
    }
    requestEmitter.emitBatch(stateMachine.getCarrier(), commands, stateMachine.getCommands());
    stateMachine.getCommands().forEach((key, value) -> stateMachine.getPendingCommands().put(key, value.getSwitchId()));
    if (commands.isEmpty()) {
        stateMachine.saveActionToHistory("No need to remove group");
    } else {
        stateMachine.saveActionToHistory("Commands for removing group have been sent");
    }
}
Also used : PathId(org.openkilda.model.PathId) SpeakerRequestEmitter(org.openkilda.wfm.topology.flowhs.utils.SpeakerRequestEmitter) FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) FlowCommandBuilder(org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder) SwitchId(org.openkilda.model.SwitchId) Flow(org.openkilda.model.Flow)

Aggregations

FlowCommandBuilder (org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder)15 FlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory)14 Flow (org.openkilda.model.Flow)13 ArrayList (java.util.ArrayList)12 FlowPath (org.openkilda.model.FlowPath)12 SpeakerRequestBuildContext (org.openkilda.wfm.share.model.SpeakerRequestBuildContext)12 MirrorContext (org.openkilda.wfm.share.model.MirrorContext)5 FlowEncapsulationType (org.openkilda.model.FlowEncapsulationType)4 RequestedFlow (org.openkilda.wfm.topology.flowhs.model.RequestedFlow)4 UUID (java.util.UUID)3 FlowSegmentRequest (org.openkilda.floodlight.api.request.FlowSegmentRequest)3 IngressFlowLoopSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.IngressFlowLoopSegmentRequestFactory)3 PathId (org.openkilda.model.PathId)3 CommandContext (org.openkilda.wfm.CommandContext)3 TransitFlowLoopSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.TransitFlowLoopSegmentRequestFactory)2 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)2 HashSet (java.util.HashSet)1 EgressMirrorFlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.EgressMirrorFlowSegmentRequestFactory)1 FlowMirrorPoints (org.openkilda.model.FlowMirrorPoints)1 SwitchId (org.openkilda.model.SwitchId)1