Search in sources :

Example 16 with SwitchId

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

the class PostFlowMirrorPathDeallocationAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowMirrorPointDeleteContext context, FlowMirrorPointDeleteFsm stateMachine) {
    PathId flowPathId = stateMachine.getFlowPathId();
    SwitchId mirrorSwitchId = stateMachine.getMirrorSwitchId();
    boolean mirrorPointsWereDeallocated = transactionManager.doInTransaction(() -> {
        FlowMirrorPoints flowMirrorPoints = flowMirrorPointsRepository.findByPathIdAndSwitchId(flowPathId, mirrorSwitchId).orElse(null);
        if (flowMirrorPoints != null && flowMirrorPoints.getMirrorPaths().isEmpty()) {
            flowMirrorPointsRepository.remove(flowMirrorPoints);
            resourcesManager.deallocateMirrorGroup(flowPathId, mirrorSwitchId);
            return true;
        }
        return false;
    });
    if (mirrorPointsWereDeallocated) {
        stateMachine.saveActionToHistory("Flow mirror group was deallocated", format("The flow mirror group for flow path %s and switch id %s was deallocated", flowPathId, mirrorSwitchId));
    }
}
Also used : PathId(org.openkilda.model.PathId) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) SwitchId(org.openkilda.model.SwitchId)

Example 17 with SwitchId

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

the class FlowValidationFsm method receiveData.

protected void receiveData(State from, State to, Event event, Object context) {
    Flow flow;
    try {
        flow = service.checkFlowStatusAndGetFlow(flowId);
    } catch (FlowNotFoundException e) {
        log.error("Flow {} not found when sending commands to SpeakerWorkerBolt", flowId, e);
        sendException(e.getMessage(), "Receiving rules operation in FlowValidationFsm", ErrorType.NOT_FOUND);
        return;
    } catch (IllegalFlowStateException e) {
        log.error("Could not validate flow: Flow {} is in DOWN state", flowId, e);
        sendException("Could not validate flow", format("Could not validate flow: Flow %s is in DOWN state", flowId), ErrorType.UNPROCESSABLE_REQUEST);
        return;
    }
    List<SwitchId> switchIds = service.getSwitchIdListByFlowId(flowId);
    awaitingRules = switchIds.size();
    log.debug("Send commands to get rules on the switches");
    switchIds.forEach(switchId -> getCarrier().sendSpeakerRequest(flowId, new DumpRulesForFlowHsRequest(switchId)));
    log.debug("Send commands to get meters on the termination switches");
    awaitingMeters = TERMINATION_SWITCHES_COUNT;
    getCarrier().sendSpeakerRequest(flowId, new DumpMetersForFlowHsRequest(flow.getSrcSwitchId()));
    getCarrier().sendSpeakerRequest(flowId, new DumpMetersForFlowHsRequest(flow.getDestSwitchId()));
    log.debug("Send commands to get groups on the termination switches");
    awaitingGroups = TERMINATION_SWITCHES_COUNT;
    getCarrier().sendSpeakerRequest(flowId, new DumpGroupsForFlowHsRequest(flow.getSrcSwitchId()));
    getCarrier().sendSpeakerRequest(flowId, new DumpGroupsForFlowHsRequest(flow.getDestSwitchId()));
}
Also used : FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) DumpGroupsForFlowHsRequest(org.openkilda.messaging.command.switches.DumpGroupsForFlowHsRequest) DumpMetersForFlowHsRequest(org.openkilda.messaging.command.switches.DumpMetersForFlowHsRequest) IllegalFlowStateException(org.openkilda.wfm.error.IllegalFlowStateException) DumpRulesForFlowHsRequest(org.openkilda.messaging.command.switches.DumpRulesForFlowHsRequest) SwitchId(org.openkilda.model.SwitchId) Flow(org.openkilda.model.Flow)

Example 18 with SwitchId

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

the class FlowValidationService method validateFlow.

/**
 * Validate flow.
 */
public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries, List<SwitchGroupEntries> switchGroupEntries) throws FlowNotFoundException, SwitchNotFoundException {
    Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>();
    int rulesCount = 0;
    int metersCount = 0;
    for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) {
        SwitchMeterEntries switchMeters = switchMeterEntries.stream().filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())).findFirst().orElse(null);
        SwitchGroupEntries switchGroup = switchGroupEntries.stream().filter(groupEntries -> switchRulesEntries.getSwitchId().equals(groupEntries.getSwitchId())).findFirst().orElse(null);
        List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter.convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters, switchGroup);
        switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules);
        rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()).map(List::size).orElse(0);
        metersCount += Optional.ofNullable(switchMeters).map(SwitchMeterEntries::getMeterEntries).map(List::size).orElse(0);
    }
    Optional<Flow> foundFlow = flowRepository.findById(flowId);
    if (!foundFlow.isPresent()) {
        throw new FlowNotFoundException(flowId);
    }
    Flow flow = foundFlow.get();
    if (flow.getForwardPath() == null) {
        throw new InvalidPathException(flowId, "Forward path was not returned.");
    }
    if (flow.getReversePath() == null) {
        throw new InvalidPathException(flowId, "Reverse path was not returned.");
    }
    List<FlowValidationResponse> flowValidationResponse = new ArrayList<>();
    List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath());
    flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount));
    List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath());
    flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount));
    if (flow.getProtectedForwardPath() != null) {
        List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath());
        flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount));
    }
    if (flow.getProtectedReversePath() != null) {
        List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath());
        flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount));
    }
    return flowValidationResponse;
}
Also used : FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) SwitchFlowEntries(org.openkilda.messaging.info.rule.SwitchFlowEntries) HashMap(java.util.HashMap) SwitchMeterEntries(org.openkilda.messaging.info.meter.SwitchMeterEntries) ArrayList(java.util.ArrayList) SwitchId(org.openkilda.model.SwitchId) FlowValidationResponse(org.openkilda.messaging.info.flow.FlowValidationResponse) InvalidPathException(java.nio.file.InvalidPathException) Flow(org.openkilda.model.Flow) SimpleSwitchRule(org.openkilda.wfm.share.utils.rule.validation.SimpleSwitchRule) SwitchGroupEntries(org.openkilda.messaging.info.rule.SwitchGroupEntries) ArrayList(java.util.ArrayList) List(java.util.List)

Example 19 with SwitchId

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

the class RevertYFlowRulesAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowPathSwapContext context, FlowPathSwapFsm stateMachine) {
    String flowId = stateMachine.getFlowId();
    Flow flow = getFlow(flowId);
    String yFlowId = flow.getYFlowId();
    if (yFlowId == null) {
        stateMachine.saveActionToHistory("No need to revert y-flow rules - it's not a sub-flow");
        stateMachine.fire(Event.SKIP_YFLOW_RULES_REVERT);
        return;
    }
    YFlow yFlow = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.INTERNAL_ERROR, format("Y-flow %s not found in persistent storage", yFlowId)));
    stateMachine.clearPendingAndRetriedAndFailedCommands();
    SwitchId sharedEndpoint = yFlow.getSharedEndpoint().getSwitchId();
    InstallSpeakerCommandsRequest installRequest = buildYFlowInstallRequest(sharedEndpoint, stateMachine.getOldPrimaryForwardPath(), stateMachine.getCommandContext());
    stateMachine.addInstallSpeakerCommand(installRequest.getCommandId(), installRequest);
    DeleteSpeakerCommandsRequest deleteRequest = buildYFlowDeleteRequest(sharedEndpoint, stateMachine.getNewPrimaryForwardPath(), stateMachine.getCommandContext());
    stateMachine.addDeleteSpeakerCommand(deleteRequest.getCommandId(), deleteRequest);
    // emitting
    Stream.of(installRequest, deleteRequest).forEach(command -> {
        stateMachine.getCarrier().sendSpeakerRequest(command);
        stateMachine.addPendingCommand(command.getCommandId(), command.getSwitchId());
    });
    stateMachine.saveActionToHistory("Commands for reverting y-flow rules have been sent");
}
Also used : YFlow(org.openkilda.model.YFlow) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) InstallSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.InstallSpeakerCommandsRequest) SwitchId(org.openkilda.model.SwitchId) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) DeleteSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest)

Example 20 with SwitchId

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

the class SetValidateRuleErrorAction method execute.

@Override
public void execute(State from, State to, Event event, FlowRerouteContext context, FlowRerouteFsm stateMachine) {
    Set<SwitchId> switches = Stream.concat(stateMachine.getPendingCommands().values().stream(), stateMachine.getFailedValidationResponses().values().stream().map(SpeakerResponse::getSwitchId)).collect(Collectors.toSet());
    stateMachine.setRerouteError(new SpeakerRequestError("Failed to validate rules", switches));
    log.debug("Abandoning all pending commands: {}", stateMachine.getPendingCommands());
    stateMachine.clearPendingCommands();
}
Also used : SpeakerResponse(org.openkilda.floodlight.api.response.SpeakerResponse) SwitchId(org.openkilda.model.SwitchId) SpeakerRequestError(org.openkilda.messaging.info.reroute.error.SpeakerRequestError)

Aggregations

SwitchId (org.openkilda.model.SwitchId)339 Test (org.junit.Test)149 Flow (org.openkilda.model.Flow)73 Switch (org.openkilda.model.Switch)69 List (java.util.List)59 FlowPath (org.openkilda.model.FlowPath)49 ArrayList (java.util.ArrayList)44 Collectors (java.util.stream.Collectors)37 PathId (org.openkilda.model.PathId)36 PathComputer (org.openkilda.pce.PathComputer)35 Set (java.util.Set)34 YFlow (org.openkilda.model.YFlow)33 Map (java.util.Map)30 GetPathsResult (org.openkilda.pce.GetPathsResult)30 InfoMessage (org.openkilda.messaging.info.InfoMessage)29 String.format (java.lang.String.format)28 HashSet (java.util.HashSet)27 Optional (java.util.Optional)27 Collection (java.util.Collection)26 Collections (java.util.Collections)26