Search in sources :

Example 1 with FlowValidationResponse

use of org.openkilda.messaging.info.flow.FlowValidationResponse 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 2 with FlowValidationResponse

use of org.openkilda.messaging.info.flow.FlowValidationResponse in project open-kilda by telstra.

the class CompleteYFlowValidationAction method performWithResponse.

@Override
public Optional<Message> performWithResponse(State from, State to, Event event, YFlowValidationContext context, YFlowValidationFsm stateMachine) throws FlowNotFoundException, SwitchNotFoundException {
    YFlowDiscrepancyDto resourcesValidationResult = validationService.validateYFlowResources(stateMachine.getYFlowId(), stateMachine.getReceivedRules(), stateMachine.getReceivedMeters());
    YFlowValidationResponse result = new YFlowValidationResponse();
    result.setYFlowValidationResult(resourcesValidationResult);
    result.setSubFlowValidationResults(stateMachine.getSubFlowValidationResults());
    boolean notAsExpected = !resourcesValidationResult.isAsExpected() || stateMachine.getSubFlowValidationResults().stream().map(FlowValidationResponse::getAsExpected).anyMatch(n -> !n);
    result.setAsExpected(!notAsExpected);
    CommandContext commandContext = stateMachine.getCommandContext();
    InfoMessage message = new InfoMessage(result, commandContext.getCreateTime(), commandContext.getCorrelationId());
    return Optional.of(message);
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) FlowValidationResponse(org.openkilda.messaging.info.flow.FlowValidationResponse) YFlowValidationFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationFsm) CommandContext(org.openkilda.wfm.CommandContext) YFlowValidationContext(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationContext) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) Slf4j(lombok.extern.slf4j.Slf4j) NbTrackableAction(org.openkilda.wfm.topology.flowhs.fsm.common.actions.NbTrackableAction) YFlowDiscrepancyDto(org.openkilda.messaging.command.yflow.YFlowDiscrepancyDto) Event(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationFsm.Event) Optional(java.util.Optional) YFlowValidationResponse(org.openkilda.messaging.command.yflow.YFlowValidationResponse) YFlowValidationService(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationService) State(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationFsm.State) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) YFlowValidationResponse(org.openkilda.messaging.command.yflow.YFlowValidationResponse) CommandContext(org.openkilda.wfm.CommandContext) InfoMessage(org.openkilda.messaging.info.InfoMessage) YFlowDiscrepancyDto(org.openkilda.messaging.command.yflow.YFlowDiscrepancyDto) FlowValidationResponse(org.openkilda.messaging.info.flow.FlowValidationResponse) YFlowValidationResponse(org.openkilda.messaging.command.yflow.YFlowValidationResponse)

Aggregations

FlowValidationResponse (org.openkilda.messaging.info.flow.FlowValidationResponse)2 FlowNotFoundException (org.openkilda.wfm.error.FlowNotFoundException)2 InvalidPathException (java.nio.file.InvalidPathException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Optional (java.util.Optional)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Message (org.openkilda.messaging.Message)1 YFlowDiscrepancyDto (org.openkilda.messaging.command.yflow.YFlowDiscrepancyDto)1 YFlowValidationResponse (org.openkilda.messaging.command.yflow.YFlowValidationResponse)1 InfoMessage (org.openkilda.messaging.info.InfoMessage)1 SwitchMeterEntries (org.openkilda.messaging.info.meter.SwitchMeterEntries)1 SwitchFlowEntries (org.openkilda.messaging.info.rule.SwitchFlowEntries)1 SwitchGroupEntries (org.openkilda.messaging.info.rule.SwitchGroupEntries)1 Flow (org.openkilda.model.Flow)1 SwitchId (org.openkilda.model.SwitchId)1 CommandContext (org.openkilda.wfm.CommandContext)1 SwitchNotFoundException (org.openkilda.wfm.error.SwitchNotFoundException)1 SimpleSwitchRule (org.openkilda.wfm.share.utils.rule.validation.SimpleSwitchRule)1