Search in sources :

Example 61 with FlowEndpoint

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

the class BaseFlowRuleRemovalAction method buildSpeakerContextForRemovalIngressAndShared.

protected SpeakerRequestBuildContext buildSpeakerContextForRemovalIngressAndShared(RequestedFlow oldFlow, RequestedFlow newFlow, boolean removeMeters) {
    SwitchProperties srcSwitchProperties = getSwitchProperties(oldFlow.getSrcSwitch());
    boolean server42FlowRttToggle = isServer42FlowRttFeatureToggle();
    boolean srcServer42FlowRtt = srcSwitchProperties.isServer42FlowRtt() && server42FlowRttToggle;
    FlowEndpoint oldIngress = new FlowEndpoint(oldFlow.getSrcSwitch(), oldFlow.getSrcPort(), oldFlow.getSrcVlan(), oldFlow.getSrcInnerVlan());
    FlowEndpoint oldEgress = new FlowEndpoint(oldFlow.getDestSwitch(), oldFlow.getDestPort(), oldFlow.getDestVlan(), oldFlow.getDestInnerVlan());
    FlowEndpoint newIngress = new FlowEndpoint(newFlow.getSrcSwitch(), newFlow.getSrcPort(), newFlow.getSrcVlan(), newFlow.getSrcInnerVlan());
    FlowEndpoint newEgress = new FlowEndpoint(newFlow.getDestSwitch(), newFlow.getDestPort(), newFlow.getDestVlan(), newFlow.getDestInnerVlan());
    PathContext forwardPathContext = PathContext.builder().removeCustomerPortRule(removeForwardCustomerPortSharedCatchRule(oldFlow, newFlow)).removeCustomerPortLldpRule(removeForwardSharedLldpRule(oldFlow, newFlow)).removeCustomerPortArpRule(removeForwardSharedArpRule(oldFlow, newFlow)).removeOuterVlanMatchSharedRule(removeOuterVlanMatchSharedRule(oldFlow.getFlowId(), oldIngress, newIngress)).removeServer42InputRule(removeForwardSharedServer42InputRule(oldFlow, newFlow, srcServer42FlowRtt)).removeServer42IngressRule(srcServer42FlowRtt).updateMeter(removeMeters).removeServer42OuterVlanMatchSharedRule(srcServer42FlowRtt && removeServer42OuterVlanMatchSharedRule(oldFlow, oldIngress, newIngress)).server42Port(srcSwitchProperties.getServer42Port()).server42MacAddress(srcSwitchProperties.getServer42MacAddress()).build();
    SwitchProperties dstSwitchProperties = getSwitchProperties(oldFlow.getDestSwitch());
    boolean dstServer42FlowRtt = dstSwitchProperties.isServer42FlowRtt() && server42FlowRttToggle;
    PathContext reversePathContext = PathContext.builder().removeCustomerPortRule(removeReverseCustomerPortSharedCatchRule(oldFlow, newFlow)).removeCustomerPortLldpRule(removeReverseSharedLldpRule(oldFlow, newFlow)).removeCustomerPortArpRule(removeReverseSharedArpRule(oldFlow, newFlow)).removeOuterVlanMatchSharedRule(removeOuterVlanMatchSharedRule(oldFlow.getFlowId(), oldEgress, newEgress)).removeServer42InputRule(removeReverseSharedServer42InputRule(oldFlow, newFlow, dstServer42FlowRtt)).removeServer42IngressRule(dstServer42FlowRtt).updateMeter(removeMeters).removeServer42OuterVlanMatchSharedRule(dstServer42FlowRtt && removeServer42OuterVlanMatchSharedRule(oldFlow, oldEgress, newEgress)).server42Port(dstSwitchProperties.getServer42Port()).server42MacAddress(dstSwitchProperties.getServer42MacAddress()).build();
    return SpeakerRequestBuildContext.builder().forward(forwardPathContext).reverse(reversePathContext).build();
}
Also used : PathContext(org.openkilda.wfm.share.model.SpeakerRequestBuildContext.PathContext) FlowEndpoint(org.openkilda.model.FlowEndpoint) SwitchProperties(org.openkilda.model.SwitchProperties)

Example 62 with FlowEndpoint

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

the class YFlowUpdateService method handlePartialUpdateRequest.

/**
 * Handles request for y-flow patch updating.
 *
 * @param key command identifier.
 * @param request request data.
 */
public void handlePartialUpdateRequest(@NonNull String key, @NonNull CommandContext commandContext, @NonNull YFlowPartialUpdateRequest request) throws DuplicateKeyException {
    YFlowRequest target;
    if (request.getYFlowId() != null) {
        YFlow yFlow = yFlowRepository.findById(request.getYFlowId()).orElse(null);
        target = YFlowRequestMapper.INSTANCE.toYFlowRequest(yFlow);
    } else {
        throw new FlowProcessingException(ErrorType.REQUEST_INVALID, "Need to specify the y-flow id");
    }
    if (target == null) {
        throw new FlowProcessingException(ErrorType.NOT_FOUND, format("Y-flow was not found by the specified y-flow id: %s", request.getYFlowId()));
    }
    if (request.getSharedEndpoint() != null) {
        if (target.getSharedEndpoint() == null) {
            target.setSharedEndpoint(new FlowEndpoint(request.getSharedEndpoint().getSwitchId(), request.getSharedEndpoint().getPortNumber()));
        } else {
            SwitchId switchId = Optional.ofNullable(request.getSharedEndpoint().getSwitchId()).orElse(target.getSharedEndpoint().getSwitchId());
            int portNumber = Optional.ofNullable(request.getSharedEndpoint().getPortNumber()).orElse(target.getSharedEndpoint().getPortNumber());
            target.setSharedEndpoint(new FlowEndpoint(switchId, portNumber));
        }
    }
    Optional.ofNullable(request.getMaximumBandwidth()).ifPresent(target::setMaximumBandwidth);
    Optional.ofNullable(request.getPathComputationStrategy()).ifPresent(target::setPathComputationStrategy);
    Optional.ofNullable(request.getEncapsulationType()).ifPresent(target::setEncapsulationType);
    Optional.ofNullable(request.getMaxLatency()).ifPresent(target::setMaxLatency);
    Optional.ofNullable(request.getMaxLatencyTier2()).ifPresent(target::setMaxLatencyTier2);
    Optional.ofNullable(request.getIgnoreBandwidth()).ifPresent(target::setIgnoreBandwidth);
    Optional.ofNullable(request.getPeriodicPings()).ifPresent(target::setPeriodicPings);
    Optional.ofNullable(request.getPinned()).ifPresent(target::setPinned);
    Optional.ofNullable(request.getPriority()).ifPresent(target::setPriority);
    Optional.ofNullable(request.getStrictBandwidth()).ifPresent(target::setStrictBandwidth);
    Optional.ofNullable(request.getDescription()).ifPresent(target::setDescription);
    Optional.ofNullable(request.getAllocateProtectedPath()).ifPresent(target::setAllocateProtectedPath);
    Optional.ofNullable(request.getDiverseFlowId()).ifPresent(target::setDiverseFlowId);
    if (request.getSubFlows() != null && !request.getSubFlows().isEmpty()) {
        Map<String, SubFlowDto> stringSubFlowDtoMap;
        if (target.getSubFlows() != null) {
            stringSubFlowDtoMap = target.getSubFlows().stream().collect(Collectors.toMap(SubFlowDto::getFlowId, Function.identity()));
        } else {
            throw new FlowProcessingException(ErrorType.INTERNAL_ERROR, format("Sub-flows for y-flow %s not found", target.getYFlowId()));
        }
        List<SubFlowDto> subFlows = new ArrayList<>();
        for (SubFlowPartialUpdateDto subFlowPartialUpdate : request.getSubFlows()) {
            SubFlowDto subFlow = stringSubFlowDtoMap.get(subFlowPartialUpdate.getFlowId());
            if (subFlow != null) {
                if (subFlowPartialUpdate.getEndpoint() != null) {
                    if (subFlow.getEndpoint() == null) {
                        subFlow.setEndpoint(new FlowEndpoint(subFlowPartialUpdate.getEndpoint().getSwitchId(), subFlowPartialUpdate.getEndpoint().getPortNumber(), subFlowPartialUpdate.getEndpoint().getVlanId(), subFlowPartialUpdate.getEndpoint().getInnerVlanId()));
                    } else {
                        SwitchId switchId = Optional.ofNullable(subFlowPartialUpdate.getEndpoint().getSwitchId()).orElse(subFlow.getEndpoint().getSwitchId());
                        int portNumber = Optional.ofNullable(subFlowPartialUpdate.getEndpoint().getPortNumber()).orElse(subFlow.getEndpoint().getPortNumber());
                        int vlanId = Optional.ofNullable(subFlowPartialUpdate.getEndpoint().getVlanId()).orElse(subFlow.getEndpoint().getOuterVlanId());
                        int innerVlanId = Optional.ofNullable(subFlowPartialUpdate.getEndpoint().getInnerVlanId()).orElse(subFlow.getEndpoint().getInnerVlanId());
                        subFlow.setEndpoint(new FlowEndpoint(switchId, portNumber, vlanId, innerVlanId));
                    }
                }
                if (subFlowPartialUpdate.getSharedEndpoint() != null) {
                    if (subFlow.getSharedEndpoint() == null) {
                        subFlow.setSharedEndpoint(new SubFlowSharedEndpointEncapsulation(subFlowPartialUpdate.getSharedEndpoint().getVlanId(), subFlowPartialUpdate.getSharedEndpoint().getInnerVlanId()));
                    } else {
                        int vlanId = Optional.ofNullable(subFlowPartialUpdate.getSharedEndpoint().getVlanId()).orElse(subFlow.getSharedEndpoint().getVlanId());
                        int innerVlanId = Optional.ofNullable(subFlowPartialUpdate.getSharedEndpoint().getInnerVlanId()).orElse(subFlow.getSharedEndpoint().getInnerVlanId());
                        subFlow.setSharedEndpoint(new SubFlowSharedEndpointEncapsulation(vlanId, innerVlanId));
                    }
                }
                Optional.ofNullable(subFlowPartialUpdate.getDescription()).ifPresent(subFlow::setDescription);
                subFlows.add(subFlow);
            } else {
                throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("There is no sub-flows with sub-flow id: %s", subFlowPartialUpdate.getFlowId()));
            }
        }
        target.setSubFlows(subFlows);
    }
    target.setType(Type.UPDATE);
    handleRequest(key, commandContext, target);
}
Also used : YFlow(org.openkilda.model.YFlow) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) ArrayList(java.util.ArrayList) SwitchId(org.openkilda.model.SwitchId) SubFlowSharedEndpointEncapsulation(org.openkilda.messaging.command.yflow.SubFlowSharedEndpointEncapsulation) SubFlowDto(org.openkilda.messaging.command.yflow.SubFlowDto) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest) FlowEndpoint(org.openkilda.model.FlowEndpoint) FlowEndpoint(org.openkilda.model.FlowEndpoint) SubFlowPartialUpdateDto(org.openkilda.messaging.command.yflow.SubFlowPartialUpdateDto)

Example 63 with FlowEndpoint

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

the class FlowValidator method checkForConnectedDevisesConflict.

private void checkForConnectedDevisesConflict(String flowId, SwitchId switchId) throws InvalidFlowException {
    SwitchProperties properties = switchPropertiesRepository.findBySwitchId(switchId).orElseThrow(() -> new InvalidFlowException(format("Couldn't get switch properties for switch %s.", switchId), ErrorType.DATA_INVALID));
    if (properties.isSwitchLldp() || properties.isSwitchArp()) {
        String errorMessage = format("Connected devices feature is active on the switch %s, " + "flow mirror point cannot be created on this switch.", switchId);
        throw new InvalidFlowException(errorMessage, ErrorType.PARAMETERS_INVALID);
    }
    Optional<Flow> foundFlow = flowRepository.findById(flowId);
    if (foundFlow.isPresent()) {
        Flow flow = foundFlow.get();
        FlowEndpoint source = new FlowSourceAdapter(flow).getEndpoint();
        FlowEndpoint destination = new FlowDestAdapter(flow).getEndpoint();
        if (switchId.equals(source.getSwitchId())) {
            if (source.isTrackLldpConnectedDevices() || source.isTrackArpConnectedDevices()) {
                String errorMessage = format("Connected devices feature is active on the flow %s for endpoint %s, " + "flow mirror point cannot be created this flow", flow.getFlowId(), source);
                throw new InvalidFlowException(errorMessage, ErrorType.PARAMETERS_INVALID);
            }
        } else {
            if (destination.isTrackLldpConnectedDevices() || destination.isTrackArpConnectedDevices()) {
                String errorMessage = format("Connected devices feature is active on the flow %s for endpoint %s, " + "flow mirror point cannot be created this flow", flow.getFlowId(), destination);
                throw new InvalidFlowException(errorMessage, ErrorType.PARAMETERS_INVALID);
            }
        }
    }
}
Also used : FlowSourceAdapter(org.openkilda.adapter.FlowSourceAdapter) FlowEndpoint(org.openkilda.model.FlowEndpoint) FlowDestAdapter(org.openkilda.adapter.FlowDestAdapter) SwitchProperties(org.openkilda.model.SwitchProperties) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow)

Example 64 with FlowEndpoint

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

the class FlowValidator method checkForEqualsEndpoints.

/**
 * Check for equals endpoints.
 *
 * @param firstFlow a first flow.
 * @param secondFlow a second flow.
 */
@VisibleForTesting
void checkForEqualsEndpoints(RequestedFlow firstFlow, RequestedFlow secondFlow) throws InvalidFlowException {
    String message = "New requested endpoint for '%s' conflicts with existing endpoint for '%s'";
    Set<FlowEndpoint> firstFlowEndpoints = validateFlowEqualsEndpoints(firstFlow, message);
    Set<FlowEndpoint> secondFlowEndpoints = validateFlowEqualsEndpoints(secondFlow, message);
    for (FlowEndpoint endpoint : secondFlowEndpoints) {
        if (firstFlowEndpoints.contains(endpoint)) {
            message = String.format(message, secondFlow.getFlowId(), firstFlow.getFlowId());
            throw new InvalidFlowException(message, ErrorType.DATA_INVALID);
        }
    }
}
Also used : FlowEndpoint(org.openkilda.model.FlowEndpoint) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 65 with FlowEndpoint

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

the class FlowValidator method checkFlowForMirrorEndpointConflicts.

private void checkFlowForMirrorEndpointConflicts(String flowId, EndpointDescriptor descriptor) throws InvalidFlowException {
    FlowEndpoint endpoint = descriptor.getEndpoint();
    Optional<Flow> foundFlow = flowRepository.findById(flowId);
    if (foundFlow.isPresent()) {
        Flow flow = foundFlow.get();
        Optional<FlowMirrorPoints> flowMirrorPointsForward = flowMirrorPointsRepository.findByPathIdAndSwitchId(flow.getForwardPathId(), endpoint.getSwitchId());
        Optional<FlowMirrorPoints> flowMirrorPointsReverse = flowMirrorPointsRepository.findByPathIdAndSwitchId(flow.getReversePathId(), endpoint.getSwitchId());
        if ((flowMirrorPointsForward.isPresent() || flowMirrorPointsReverse.isPresent()) && (endpoint.isTrackLldpConnectedDevices() || endpoint.isTrackArpConnectedDevices())) {
            String errorMessage = format("Flow mirror point is created for the flow %s, " + "lldp or arp can not be set to true.", flowId);
            throw new InvalidFlowException(errorMessage, ErrorType.PARAMETERS_INVALID);
        }
    }
}
Also used : FlowEndpoint(org.openkilda.model.FlowEndpoint) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow)

Aggregations

FlowEndpoint (org.openkilda.model.FlowEndpoint)105 Test (org.junit.Test)26 Flow (org.openkilda.model.Flow)22 ArrayList (java.util.ArrayList)15 RoutingMetadata (org.openkilda.floodlight.utils.metadata.RoutingMetadata)12 YFlow (org.openkilda.model.YFlow)11 FlowPath (org.openkilda.model.FlowPath)10 FlowSpeakerData (org.openkilda.rulemanager.FlowSpeakerData)9 SpeakerData (org.openkilda.rulemanager.SpeakerData)9 SwitchId (org.openkilda.model.SwitchId)8 YSubFlow (org.openkilda.model.YSubFlow)8 HashSet (java.util.HashSet)7 FlowSideAdapter (org.openkilda.adapter.FlowSideAdapter)7 FlowSourceAdapter (org.openkilda.adapter.FlowSourceAdapter)7 IngressFlowSegmentInstallCommand (org.openkilda.floodlight.command.flow.ingress.IngressFlowSegmentInstallCommand)7 EffectiveIds (org.openkilda.floodlight.model.EffectiveIds)7 FlowSegmentWrapperCommand (org.openkilda.floodlight.command.flow.FlowSegmentWrapperCommand)6 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)6 OFFlowAdd (org.projectfloodlight.openflow.protocol.OFFlowAdd)6 MessageContext (org.openkilda.messaging.MessageContext)5