Search in sources :

Example 1 with PathId

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

the class YFlowRuleManagerProcessingAction method buildYFlowSpeakerData.

private Map<SwitchId, List<SpeakerData>> buildYFlowSpeakerData(YFlow yFlow) {
    List<FlowPath> flowPaths = yFlow.getSubFlows().stream().map(YSubFlow::getFlow).map(Flow::getPaths).flatMap(Collection::stream).collect(toList());
    Set<SwitchId> switchIds = Sets.newHashSet(yFlow.getSharedEndpoint().getSwitchId(), yFlow.getYPoint(), yFlow.getProtectedPathYPoint());
    Set<PathId> pathIds = flowPaths.stream().map(FlowPath::getPathId).collect(Collectors.toSet());
    DataAdapter dataAdapter = PersistenceDataAdapter.builder().persistenceManager(persistenceManager).switchIds(switchIds).pathIds(pathIds).build();
    return ruleManager.buildRulesForYFlow(flowPaths, dataAdapter).stream().collect(Collectors.groupingBy(SpeakerData::getSwitchId, Collectors.mapping(Function.identity(), toList())));
}
Also used : PathId(org.openkilda.model.PathId) DataAdapter(org.openkilda.rulemanager.DataAdapter) PersistenceDataAdapter(org.openkilda.rulemanager.adapter.PersistenceDataAdapter) SwitchId(org.openkilda.model.SwitchId) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow)

Example 2 with PathId

use of org.openkilda.model.PathId 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 3 with PathId

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

the class EmitUpdateRulesRequestsAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowMirrorPointCreateContext context, FlowMirrorPointCreateFsm stateMachine) {
    stateMachine.getCommands().clear();
    stateMachine.getPendingCommands().clear();
    String flowId = stateMachine.getFlowId();
    Flow flow = getFlow(flowId);
    Collection<FlowSegmentRequestFactory> commands = buildCommands(stateMachine, flow);
    // emitting
    PathId flowPathId = stateMachine.getFlowPathId();
    SwitchId mirrorSwitchId = stateMachine.getMirrorSwitchId();
    FlowMirrorPoints mirrorPoints = flowMirrorPointsRepository.findByPathIdAndSwitchId(flowPathId, mirrorSwitchId).orElse(null);
    SpeakerRequestEmitter requestEmitter;
    if (mirrorPoints != null && 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 update rules");
    } else {
        stateMachine.saveActionToHistory("Commands for updating rules have been sent");
        stateMachine.setRulesInstalled(true);
    }
}
Also used : PathId(org.openkilda.model.PathId) SpeakerRequestEmitter(org.openkilda.wfm.topology.flowhs.utils.SpeakerRequestEmitter) FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) SwitchId(org.openkilda.model.SwitchId) Flow(org.openkilda.model.Flow)

Example 4 with PathId

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

the class EmitUpdateRulesRequestsAction method buildCommands.

private Collection<FlowSegmentRequestFactory> buildCommands(FlowMirrorPointCreateFsm stateMachine, Flow flow) {
    final FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(flow.getEncapsulationType());
    PathId flowPathId = stateMachine.getFlowPathId();
    FlowPath path = flow.getPath(flowPathId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Flow path %s not found", flowPathId)));
    PathId oppositePathId = flow.getOppositePathId(flowPathId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Opposite flow path id for path %s not found", flowPathId)));
    FlowPath oppositePath = flow.getPath(oppositePathId).orElse(null);
    RequestedFlowMirrorPoint mirrorPoint = stateMachine.getRequestedFlowMirrorPoint();
    CommandContext context = stateMachine.getCommandContext();
    SpeakerRequestBuildContext speakerContext = buildBaseSpeakerContextForInstall(path.getSrcSwitchId(), path.getDestSwitchId());
    if (mirrorPoint.getMirrorPointSwitchId().equals(path.getSrcSwitchId())) {
        return new ArrayList<>(commandBuilder.buildIngressOnlyOneDirection(context, flow, path, oppositePath, speakerContext.getForward(), MirrorContext.builder().buildMirrorFactoryOnly(true).addNewGroup(stateMachine.isAddNewGroup()).build()));
    } else if (mirrorPoint.getMirrorPointSwitchId().equals(path.getDestSwitchId())) {
        return new ArrayList<>(commandBuilder.buildEgressOnlyOneDirection(context, flow, path, oppositePath, MirrorContext.builder().buildMirrorFactoryOnly(true).addNewGroup(stateMachine.isAddNewGroup()).build()));
    }
    return Collections.emptyList();
}
Also used : PathId(org.openkilda.model.PathId) RequestedFlowMirrorPoint(org.openkilda.wfm.topology.flowhs.model.RequestedFlowMirrorPoint) CommandContext(org.openkilda.wfm.CommandContext) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) ArrayList(java.util.ArrayList) FlowCommandBuilder(org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder) FlowPath(org.openkilda.model.FlowPath) SpeakerRequestBuildContext(org.openkilda.wfm.share.model.SpeakerRequestBuildContext)

Example 5 with PathId

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

the class PostFlowMirrorPathInstallationAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowMirrorPointCreateContext context, FlowMirrorPointCreateFsm stateMachine) {
    PathId mirrorPath = stateMachine.getMirrorPathId();
    log.debug("Completing installation of the flow mirror path {}", mirrorPath);
    flowMirrorPathRepository.updateStatus(mirrorPath, FlowPathStatus.ACTIVE);
    stateMachine.saveActionToHistory("Flow mirror path was installed", format("The flow path %s was installed", mirrorPath));
}
Also used : PathId(org.openkilda.model.PathId)

Aggregations

PathId (org.openkilda.model.PathId)124 Flow (org.openkilda.model.Flow)65 FlowPath (org.openkilda.model.FlowPath)65 Test (org.junit.Test)44 Switch (org.openkilda.model.Switch)29 SwitchId (org.openkilda.model.SwitchId)28 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)27 PathSegment (org.openkilda.model.PathSegment)26 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)21 MeterId (org.openkilda.model.MeterId)19 ArrayList (java.util.ArrayList)18 List (java.util.List)13 Slf4j (lombok.extern.slf4j.Slf4j)11 GetPathsResult (org.openkilda.pce.GetPathsResult)11 FlowMirrorPoints (org.openkilda.model.FlowMirrorPoints)10 Path (org.openkilda.pce.Path)10 Collection (java.util.Collection)9 RecoverableException (org.openkilda.pce.exception.RecoverableException)9 String.format (java.lang.String.format)8 HashMap (java.util.HashMap)8