Search in sources :

Example 11 with SpeakerRequestBuildContext

use of org.openkilda.wfm.share.model.SpeakerRequestBuildContext 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 SpeakerRequestBuildContext

use of org.openkilda.wfm.share.model.SpeakerRequestBuildContext 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 SpeakerRequestBuildContext

use of org.openkilda.wfm.share.model.SpeakerRequestBuildContext 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

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