Search in sources :

Example 61 with YFlow

use of org.openkilda.model.YFlow in project open-kilda by telstra.

the class RemoveYFlowResourcesAction method perform.

@Override
protected void perform(State from, State to, Event event, YFlowCreateContext context, YFlowCreateFsm stateMachine) {
    log.debug("Abandoning all pending commands: {}", stateMachine.getPendingCommands());
    stateMachine.clearPendingAndRetriedAndFailedCommands();
    String yFlowId = stateMachine.getYFlowId();
    YFlow yFlow = getYFlow(yFlowId);
    Collection<DeleteSpeakerCommandsRequest> commands = buildYFlowDeleteCommands(yFlow, stateMachine.getCommandContext());
    if (commands.isEmpty()) {
        stateMachine.saveActionToHistory("No need to remove y-flow meters");
        stateMachine.fire(Event.ALL_YFLOW_METERS_REMOVED);
    } else {
        // emitting
        commands.forEach(command -> {
            stateMachine.getCarrier().sendSpeakerRequest(command);
            stateMachine.addDeleteSpeakerCommand(command.getCommandId(), command);
            stateMachine.addPendingCommand(command.getCommandId(), command.getSwitchId());
        });
        stateMachine.saveActionToHistory("Commands for removing y-flow rules have been sent");
    }
}
Also used : YFlow(org.openkilda.model.YFlow) DeleteSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest)

Example 62 with YFlow

use of org.openkilda.model.YFlow in project open-kilda by telstra.

the class RemoveYFlowResourcesAction method perform.

@Override
protected void perform(State from, State to, Event event, YFlowDeleteContext context, YFlowDeleteFsm stateMachine) {
    String yFlowId = stateMachine.getYFlowId();
    YFlow yFlow = getYFlow(yFlowId);
    YFlowResources oldResources;
    // This could be a retry.
    if (stateMachine.getOldResources() != null) {
        oldResources = stateMachine.getOldResources();
    } else {
        oldResources = new YFlowResources();
        stateMachine.setOldResources(oldResources);
    }
    if (oldResources.getSharedEndpointResources() == null) {
        oldResources.setSharedEndpointResources(EndpointResources.builder().endpoint(yFlow.getSharedEndpoint().getSwitchId()).meterId(yFlow.getSharedEndpointMeterId()).build());
    }
    if (oldResources.getMainPathYPointResources() == null) {
        oldResources.setMainPathYPointResources(EndpointResources.builder().endpoint(yFlow.getYPoint()).meterId(yFlow.getMeterId()).build());
    }
    if (yFlow.isAllocateProtectedPath() && oldResources.getProtectedPathYPointResources() == null) {
        oldResources.setProtectedPathYPointResources(EndpointResources.builder().endpoint(yFlow.getProtectedPathYPoint()).meterId(yFlow.getProtectedPathMeterId()).build());
    }
    stateMachine.clearPendingAndRetriedAndFailedCommands();
    Collection<DeleteSpeakerCommandsRequest> commands = stateMachine.getDeleteOldYFlowCommands();
    if (commands.isEmpty()) {
        stateMachine.saveActionToHistory("No need to remove y-flow meters");
        stateMachine.fire(Event.ALL_YFLOW_METERS_REMOVED);
    } else {
        // emitting
        commands.forEach(command -> {
            stateMachine.getCarrier().sendSpeakerRequest(command);
            stateMachine.addDeleteSpeakerCommand(command.getCommandId(), command);
            stateMachine.addPendingCommand(command.getCommandId(), command.getSwitchId());
        });
        stateMachine.saveActionToHistory("Commands for removing y-flow rules have been sent");
    }
}
Also used : YFlow(org.openkilda.model.YFlow) YFlowResources(org.openkilda.wfm.topology.flowhs.model.yflow.YFlowResources) DeleteSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest)

Example 63 with YFlow

use of org.openkilda.model.YFlow in project open-kilda by telstra.

the class ValidateYFlowAction method performWithResponse.

@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, YFlowDeleteContext context, YFlowDeleteFsm stateMachine) {
    String yFlowId = stateMachine.getYFlowId();
    dashboardLogger.onYFlowDelete(yFlowId);
    boolean isOperationAllowed = featureTogglesRepository.getOrDefault().getModifyYFlowEnabled();
    if (!isOperationAllowed) {
        throw new FlowProcessingException(ErrorType.NOT_PERMITTED, "Y-flow delete feature is disabled");
    }
    YFlow result = transactionManager.doInTransaction(() -> {
        YFlow yFlow = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Y-flow %s not found", yFlowId)));
        if (yFlow.getStatus() == FlowStatus.IN_PROGRESS) {
            throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Y-flow %s is in progress now", yFlowId));
        }
        // Keep it, just in case we have to revert it.
        stateMachine.setOriginalYFlowStatus(yFlow.getStatus());
        yFlow.setStatus(FlowStatus.IN_PROGRESS);
        return yFlow;
    });
    stateMachine.saveNewEventToHistory("Y-flow was validated successfully", FlowEventData.Event.DELETE);
    return Optional.of(buildResponseMessage(result, stateMachine.getCommandContext()));
}
Also used : YFlow(org.openkilda.model.YFlow) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)

Example 64 with YFlow

use of org.openkilda.model.YFlow in project open-kilda by telstra.

the class RuleManagerImpl method buildRulesForYFlow.

@Override
public List<SpeakerData> buildRulesForYFlow(List<FlowPath> flowPaths, DataAdapter adapter) {
    if (flowPaths == null) {
        return Collections.emptyList();
    }
    FlowPath flowPathForIngress = null;
    FlowPath altFlowPathForIngress = null;
    FlowPath flowPathForTransit = null;
    FlowPath altFlowPathForTransit = null;
    for (FlowPath flowPath : flowPaths) {
        YFlow yFlow = adapter.getYFlow(flowPath.getPathId());
        if (yFlow == null) {
            break;
        }
        SwitchId sharedSwitchId = yFlow.getSharedEndpoint().getSwitchId();
        if (sharedSwitchId.equals(flowPath.getSrcSwitchId())) {
            if (flowPathForIngress == null) {
                flowPathForIngress = flowPath;
            } else if (altFlowPathForIngress == null) {
                altFlowPathForIngress = flowPath;
            }
        } else {
            if (flowPathForTransit == null) {
                flowPathForTransit = flowPath;
            } else if (altFlowPathForTransit == null) {
                altFlowPathForTransit = flowPath;
            }
        }
    }
    if (flowPathForIngress == null || altFlowPathForIngress == null || flowPathForTransit == null || altFlowPathForTransit == null) {
        return Collections.emptyList();
    }
    List<SpeakerData> result = new ArrayList<>(buildIngressYFlowCommands(flowPathForIngress, altFlowPathForIngress, adapter));
    result.addAll(buildTransitYFlowCommands(flowPathForTransit, altFlowPathForTransit, adapter));
    return result;
}
Also used : YFlow(org.openkilda.model.YFlow) ArrayList(java.util.ArrayList) SwitchId(org.openkilda.model.SwitchId) FlowPath(org.openkilda.model.FlowPath)

Example 65 with YFlow

use of org.openkilda.model.YFlow in project open-kilda by telstra.

the class RuleManagerImpl method buildYFlowRulesForSwitch.

private List<SpeakerData> buildYFlowRulesForSwitch(SwitchId switchId, DataAdapter adapter) {
    List<SpeakerData> result = new ArrayList<>();
    Set<YFlow> yFlows = new HashSet<>();
    Map<String, List<FlowPath>> yFlowIdsWithFlowPaths = new HashMap<>();
    for (FlowPath flowPath : adapter.getFlowPaths().values()) {
        YFlow yFlow = adapter.getYFlow(flowPath.getPathId());
        if (yFlow != null) {
            yFlows.add(yFlow);
            yFlowIdsWithFlowPaths.computeIfAbsent(yFlow.getYFlowId(), fp -> new ArrayList<>()).add(flowPath);
        }
    }
    yFlows.stream().filter(yFlow -> switchId.equals(yFlow.getSharedEndpoint().getSwitchId()) || switchId.equals(yFlow.getYPoint()) || switchId.equals(yFlow.getProtectedPathYPoint())).forEach(yFlow -> result.addAll(buildRulesForYFlow(yFlowIdsWithFlowPaths.get(yFlow.getYFlowId()), adapter)));
    return result;
}
Also used : YFlow(org.openkilda.model.YFlow) MULTITABLE_TRANSIT_DROP_COOKIE(org.openkilda.model.cookie.Cookie.MULTITABLE_TRANSIT_DROP_COOKIE) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) HashMap(java.util.HashMap) FlowSideAdapter.makeIngressAdapter(org.openkilda.adapter.FlowSideAdapter.makeIngressAdapter) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MULTITABLE_POST_INGRESS_DROP_COOKIE(org.openkilda.model.cookie.Cookie.MULTITABLE_POST_INGRESS_DROP_COOKIE) Flow(org.openkilda.model.Flow) KildaFeatureToggles(org.openkilda.model.KildaFeatureToggles) MULTITABLE_INGRESS_DROP_COOKIE(org.openkilda.model.cookie.Cookie.MULTITABLE_INGRESS_DROP_COOKIE) Utils(org.openkilda.rulemanager.utils.Utils) Map(java.util.Map) Cookie(org.openkilda.model.cookie.Cookie) YFlow(org.openkilda.model.YFlow) RuleManagerHelper.postProcessCommands(org.openkilda.rulemanager.utils.RuleManagerHelper.postProcessCommands) FlowSideAdapter(org.openkilda.adapter.FlowSideAdapter) PathId(org.openkilda.model.PathId) SwitchProperties(org.openkilda.model.SwitchProperties) FlowRulesGeneratorFactory(org.openkilda.rulemanager.factory.FlowRulesGeneratorFactory) FlowEndpoint(org.openkilda.model.FlowEndpoint) Switch(org.openkilda.model.Switch) DROP_RULE_COOKIE(org.openkilda.model.cookie.Cookie.DROP_RULE_COOKIE) MULTITABLE_PRE_INGRESS_PASS_THROUGH_COOKIE(org.openkilda.model.cookie.Cookie.MULTITABLE_PRE_INGRESS_PASS_THROUGH_COOKIE) ServiceRulesGeneratorFactory(org.openkilda.rulemanager.factory.ServiceRulesGeneratorFactory) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) MeterId(org.openkilda.model.MeterId) MacAddress(org.openkilda.model.MacAddress) Collectors.toList(java.util.stream.Collectors.toList) MULTITABLE_EGRESS_PASS_THROUGH_COOKIE(org.openkilda.model.cookie.Cookie.MULTITABLE_EGRESS_PASS_THROUGH_COOKIE) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) RuleGenerator(org.openkilda.rulemanager.factory.RuleGenerator) Data(lombok.Data) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AllArgsConstructor(lombok.AllArgsConstructor) Collections(java.util.Collections) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) FlowPath(org.openkilda.model.FlowPath) HashSet(java.util.HashSet)

Aggregations

YFlow (org.openkilda.model.YFlow)74 Flow (org.openkilda.model.Flow)30 SwitchId (org.openkilda.model.SwitchId)29 YSubFlow (org.openkilda.model.YSubFlow)26 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)19 Test (org.junit.Test)12 YFlowRequest (org.openkilda.messaging.command.yflow.YFlowRequest)12 ArrayList (java.util.ArrayList)11 FlowStatus (org.openkilda.model.FlowStatus)10 CommandContext (org.openkilda.wfm.CommandContext)10 AbstractYFlowTest (org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)10 FlowPath (org.openkilda.model.FlowPath)9 FlowEndpoint (org.openkilda.model.FlowEndpoint)8 InstallSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.InstallSpeakerCommandsRequest)6 Switch (org.openkilda.model.Switch)6 HashSet (java.util.HashSet)5 DeleteSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest)5 SharedEndpoint (org.openkilda.model.YFlow.SharedEndpoint)5 Collection (java.util.Collection)4 HashMap (java.util.HashMap)4