Search in sources :

Example 1 with Switch

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

the class ResourceAllocationAction method createFlowMirrorPoints.

private FlowMirrorPoints createFlowMirrorPoints(RequestedFlowMirrorPoint mirrorPoint, FlowPath flowPath) throws ResourceAllocationException {
    Switch mirrorSwitch = switchRepository.findById(mirrorPoint.getMirrorPointSwitchId()).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Switch %s not found", mirrorPoint.getMirrorPointSwitchId())));
    MirrorDirection direction = mirrorPoint.getMirrorPointSwitchId().equals(flowPath.getSrcSwitchId()) ? MirrorDirection.INGRESS : MirrorDirection.EGRESS;
    MirrorGroup mirrorGroup = resourcesManager.getAllocatedMirrorGroup(mirrorPoint.getMirrorPointSwitchId(), mirrorPoint.getFlowId(), flowPath.getPathId(), MirrorGroupType.TRAFFIC_INTEGRITY, direction);
    FlowMirrorPoints flowMirrorPoints = FlowMirrorPoints.builder().mirrorSwitch(mirrorSwitch).mirrorGroup(mirrorGroup).build();
    flowMirrorPointsRepository.add(flowMirrorPoints);
    flowPath.addFlowMirrorPoints(flowMirrorPoints);
    return flowMirrorPoints;
}
Also used : MirrorGroup(org.openkilda.model.MirrorGroup) Switch(org.openkilda.model.Switch) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) MirrorDirection(org.openkilda.model.MirrorDirection)

Example 2 with Switch

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

the class UpdateFlowAction method updateFlow.

private RequestedFlow updateFlow(Flow flow, RequestedFlow targetFlow) {
    if (targetFlow.getDiverseFlowId() != null) {
        if (targetFlow.getDiverseFlowId().isEmpty()) {
            flow.setDiverseGroupId(null);
        } else {
            flow.setDiverseGroupId(getOrCreateDiverseFlowGroupId(targetFlow.getDiverseFlowId()));
        }
    } else if (targetFlow.isAllocateProtectedPath()) {
        if (flow.getDiverseGroupId() == null) {
            flow.setDiverseGroupId(getOrCreateDiverseFlowGroupId(flow.getFlowId()));
        }
    }
    if (targetFlow.getAffinityFlowId() != null) {
        if (targetFlow.getAffinityFlowId().isEmpty()) {
            flow.setAffinityGroupId(null);
        } else {
            flow.setAffinityGroupId(getOrCreateAffinityFlowGroupId(targetFlow.getAffinityFlowId()));
        }
    }
    Switch srcSwitch = switchRepository.findById(targetFlow.getSrcSwitch()).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Switch %s not found", targetFlow.getSrcSwitch())));
    flow.setSrcSwitch(srcSwitch);
    flow.setSrcPort(targetFlow.getSrcPort());
    flow.setSrcVlan(targetFlow.getSrcVlan());
    flow.setSrcInnerVlan(targetFlow.getSrcInnerVlan());
    DetectConnectedDevices.DetectConnectedDevicesBuilder detectConnectedDevices = flow.getDetectConnectedDevices().toBuilder();
    detectConnectedDevices.srcLldp(targetFlow.getDetectConnectedDevices().isSrcLldp());
    detectConnectedDevices.srcArp(targetFlow.getDetectConnectedDevices().isSrcArp());
    Switch destSwitch = switchRepository.findById(targetFlow.getDestSwitch()).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Switch %s not found", targetFlow.getDestSwitch())));
    flow.setDestSwitch(destSwitch);
    flow.setDestPort(targetFlow.getDestPort());
    flow.setDestVlan(targetFlow.getDestVlan());
    flow.setDestInnerVlan(targetFlow.getDestInnerVlan());
    detectConnectedDevices.dstLldp(targetFlow.getDetectConnectedDevices().isDstLldp());
    detectConnectedDevices.dstArp(targetFlow.getDetectConnectedDevices().isDstArp());
    flow.setDetectConnectedDevices(detectConnectedDevices.build());
    if (targetFlow.getPriority() != null) {
        flow.setPriority(targetFlow.getPriority());
    }
    flow.setPinned(targetFlow.isPinned());
    flow.setAllocateProtectedPath(targetFlow.isAllocateProtectedPath());
    if (targetFlow.getDescription() != null) {
        flow.setDescription(targetFlow.getDescription());
    }
    flow.setBandwidth(targetFlow.getBandwidth());
    flow.setIgnoreBandwidth(targetFlow.isIgnoreBandwidth());
    flow.setStrictBandwidth(targetFlow.isStrictBandwidth());
    if (targetFlow.getMaxLatency() != null) {
        flow.setMaxLatency(targetFlow.getMaxLatency());
    }
    if (targetFlow.getMaxLatencyTier2() != null) {
        flow.setMaxLatencyTier2(targetFlow.getMaxLatencyTier2());
    }
    flow.setPeriodicPings(targetFlow.isPeriodicPings());
    if (targetFlow.getFlowEncapsulationType() != null) {
        flow.setEncapsulationType(targetFlow.getFlowEncapsulationType());
    } else {
        targetFlow.setFlowEncapsulationType(flow.getEncapsulationType());
    }
    if (targetFlow.getPathComputationStrategy() != null) {
        flow.setPathComputationStrategy(targetFlow.getPathComputationStrategy());
        flow.setTargetPathComputationStrategy(null);
    } else {
        if (flow.getTargetPathComputationStrategy() != null) {
            targetFlow.setPathComputationStrategy(flow.getTargetPathComputationStrategy());
            flow.setPathComputationStrategy(flow.getTargetPathComputationStrategy());
            flow.setTargetPathComputationStrategy(null);
        } else {
            targetFlow.setPathComputationStrategy(flow.getPathComputationStrategy());
        }
    }
    flow.setLoopSwitchId(targetFlow.getLoopSwitchId());
    return targetFlow;
}
Also used : Switch(org.openkilda.model.Switch) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) DetectConnectedDevices(org.openkilda.model.DetectConnectedDevices)

Example 3 with Switch

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

the class FlowValidator method checkDiverseFlow.

@VisibleForTesting
void checkDiverseFlow(RequestedFlow targetFlow) throws InvalidFlowException {
    if (targetFlow.getSrcSwitch().equals(targetFlow.getDestSwitch())) {
        throw new InvalidFlowException("Couldn't add one-switch flow into diverse group", ErrorType.PARAMETERS_INVALID);
    }
    Flow diverseFlow = flowRepository.findById(targetFlow.getDiverseFlowId()).orElse(null);
    if (diverseFlow == null) {
        YFlow diverseYFlow = yFlowRepository.findById(targetFlow.getDiverseFlowId()).orElseThrow(() -> new InvalidFlowException(format("Failed to find diverse flow id %s", targetFlow.getDiverseFlowId()), ErrorType.PARAMETERS_INVALID));
        diverseFlow = diverseYFlow.getSubFlows().stream().map(YSubFlow::getFlow).filter(flow -> flow.getFlowId().equals(flow.getAffinityGroupId())).findFirst().orElseThrow(() -> new InvalidFlowException(format("Failed to find main affinity flow for diverse y-flow id %s", targetFlow.getDiverseFlowId()), ErrorType.INTERNAL_ERROR));
    }
    if (StringUtils.isNotBlank(diverseFlow.getAffinityGroupId())) {
        String diverseFlowId = diverseFlow.getAffinityGroupId();
        diverseFlow = flowRepository.findById(diverseFlowId).orElseThrow(() -> new InvalidFlowException(format("Failed to find diverse flow id %s", diverseFlowId), ErrorType.PARAMETERS_INVALID));
        Collection<String> affinityFlowIds = flowRepository.findFlowsIdByAffinityGroupId(diverseFlow.getAffinityGroupId()).stream().filter(Objects::nonNull).collect(Collectors.toSet());
        if (affinityFlowIds.contains(targetFlow.getAffinityFlowId())) {
            throw new InvalidFlowException("Couldn't create diverse group with flow in the same affinity group", ErrorType.PARAMETERS_INVALID);
        }
    }
    if (diverseFlow.isOneSwitchFlow()) {
        throw new InvalidFlowException("Couldn't create diverse group with one-switch flow", ErrorType.PARAMETERS_INVALID);
    }
}
Also used : YFlow(org.openkilda.model.YFlow) Getter(lombok.Getter) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AccessLevel(lombok.AccessLevel) Flow(org.openkilda.model.Flow) IslRepository(org.openkilda.persistence.repositories.IslRepository) FlowSourceAdapter(org.openkilda.adapter.FlowSourceAdapter) YFlow(org.openkilda.model.YFlow) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) FlowDestAdapter(org.openkilda.adapter.FlowDestAdapter) PersistenceManager(org.openkilda.persistence.PersistenceManager) SwitchProperties(org.openkilda.model.SwitchProperties) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) FlowEndpoint(org.openkilda.model.FlowEndpoint) Switch(org.openkilda.model.Switch) FlowMirrorPointsRepository(org.openkilda.persistence.repositories.FlowMirrorPointsRepository) YSubFlow(org.openkilda.model.YSubFlow) PhysicalPortRepository(org.openkilda.persistence.repositories.PhysicalPortRepository) RequestedFlowMirrorPoint(org.openkilda.wfm.topology.flowhs.model.RequestedFlowMirrorPoint) ErrorType(org.openkilda.messaging.error.ErrorType) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) Collection(java.util.Collection) Set(java.util.Set) FlowMirrorPathRepository(org.openkilda.persistence.repositories.FlowMirrorPathRepository) RequestedFlowMapper(org.openkilda.wfm.topology.flowhs.mapper.RequestedFlowMapper) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Sets(com.google.common.collect.Sets) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) Objects(java.util.Objects) SwitchPropertiesRepository(org.openkilda.persistence.repositories.SwitchPropertiesRepository) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) Optional(java.util.Optional) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AllArgsConstructor(lombok.AllArgsConstructor) PhysicalPort(org.openkilda.model.PhysicalPort) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) YSubFlow(org.openkilda.model.YSubFlow) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 4 with Switch

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

the class FlowValidator method validateQinQonWB.

@VisibleForTesting
void validateQinQonWB(RequestedFlow requestedFlow) throws UnavailableFlowEndpointException, InvalidFlowException {
    final FlowEndpoint source = RequestedFlowMapper.INSTANCE.mapSource(requestedFlow);
    final FlowEndpoint destination = RequestedFlowMapper.INSTANCE.mapDest(requestedFlow);
    if (source.getInnerVlanId() != 0) {
        Switch srcSwitch = switchRepository.findById(source.getSwitchId()).orElseThrow(() -> new UnavailableFlowEndpointException(format("Endpoint switch not found %s", source.getSwitchId())));
        if (Switch.isNoviflowESwitch(srcSwitch.getOfDescriptionManufacturer(), srcSwitch.getOfDescriptionHardware())) {
            String message = format("QinQ feature is temporary disabled for WB-series switch '%s'", srcSwitch.getSwitchId());
            throw new InvalidFlowException(message, ErrorType.PARAMETERS_INVALID);
        }
    }
    if (destination.getInnerVlanId() != 0) {
        Switch destSwitch = switchRepository.findById(destination.getSwitchId()).orElseThrow(() -> new UnavailableFlowEndpointException(format("Endpoint switch not found %s", destination.getSwitchId())));
        if (Switch.isNoviflowESwitch(destSwitch.getOfDescriptionManufacturer(), destSwitch.getOfDescriptionHardware())) {
            String message = format("QinQ feature is temporary disabled for WB-series switch '%s'", destSwitch.getSwitchId());
            throw new InvalidFlowException(message, ErrorType.PARAMETERS_INVALID);
        }
    }
}
Also used : FlowEndpoint(org.openkilda.model.FlowEndpoint) Switch(org.openkilda.model.Switch) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with Switch

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

the class FlowValidationTestBase method buildFlow.

protected void buildFlow(FlowEncapsulationType flowEncapsulationType, String endpointSwitchManufacturer) {
    Switch switchA = Switch.builder().switchId(TEST_SWITCH_ID_A).description("").build();
    switchRepository.add(switchA);
    switchA.setOfDescriptionManufacturer(endpointSwitchManufacturer);
    Switch switchB = Switch.builder().switchId(TEST_SWITCH_ID_B).description("").build();
    switchRepository.add(switchB);
    Switch switchC = Switch.builder().switchId(TEST_SWITCH_ID_C).description("").build();
    switchRepository.add(switchC);
    Switch switchE = Switch.builder().switchId(TEST_SWITCH_ID_E).description("").build();
    switchRepository.add(switchE);
    Flow flow = Flow.builder().flowId(TEST_FLOW_ID_A).srcSwitch(switchA).srcPort(FLOW_A_SRC_PORT).srcVlan(FLOW_A_SRC_VLAN).destSwitch(switchC).destPort(FLOW_A_DST_PORT).destVlan(FLOW_A_DST_VLAN).allocateProtectedPath(true).encapsulationType(flowEncapsulationType).bandwidth(FLOW_A_BANDWIDTH).status(FlowStatus.UP).build();
    FlowPath forwardFlowPath = FlowPath.builder().pathId(FLOW_A_FORWARD_PATH_ID).cookie(new FlowSegmentCookie(FLOW_A_FORWARD_COOKIE)).meterId(new MeterId(FLOW_A_FORWARD_METER_ID)).srcSwitch(switchA).destSwitch(switchC).bandwidth(FLOW_A_BANDWIDTH).status(FlowPathStatus.ACTIVE).build();
    flow.setForwardPath(forwardFlowPath);
    PathSegment forwardSegmentA = PathSegment.builder().pathId(forwardFlowPath.getPathId()).srcSwitch(switchA).srcPort(FLOW_A_SEGMENT_A_SRC_PORT).destSwitch(switchB).destPort(FLOW_A_SEGMENT_A_DST_PORT).build();
    PathSegment forwardSegmentB = PathSegment.builder().pathId(forwardFlowPath.getPathId()).srcSwitch(switchB).srcPort(FLOW_A_SEGMENT_B_SRC_PORT).destSwitch(switchC).destPort(FLOW_A_SEGMENT_B_DST_PORT).build();
    forwardFlowPath.setSegments(Lists.newArrayList(forwardSegmentA, forwardSegmentB));
    FlowPath forwardProtectedFlowPath = FlowPath.builder().pathId(FLOW_A_FORWARD_PATH_ID_PROTECTED).cookie(new FlowSegmentCookie(FLOW_A_FORWARD_COOKIE_PROTECTED)).meterId(new MeterId(FLOW_A_FORWARD_METER_ID_PROTECTED)).srcSwitch(switchA).destSwitch(switchC).bandwidth(FLOW_A_BANDWIDTH).status(FlowPathStatus.ACTIVE).build();
    flow.setProtectedForwardPath(forwardProtectedFlowPath);
    PathSegment forwardProtectedSegmentA = PathSegment.builder().pathId(forwardProtectedFlowPath.getPathId()).srcSwitch(switchA).srcPort(FLOW_A_SEGMENT_A_SRC_PORT_PROTECTED).destSwitch(switchE).destPort(FLOW_A_SEGMENT_A_DST_PORT_PROTECTED).build();
    PathSegment forwardProtectedSegmentB = PathSegment.builder().pathId(forwardProtectedFlowPath.getPathId()).srcSwitch(switchE).srcPort(FLOW_A_SEGMENT_B_SRC_PORT_PROTECTED).destSwitch(switchC).destPort(FLOW_A_SEGMENT_B_DST_PORT_PROTECTED).build();
    forwardProtectedFlowPath.setSegments(Lists.newArrayList(forwardProtectedSegmentA, forwardProtectedSegmentB));
    FlowPath reverseFlowPath = FlowPath.builder().pathId(FLOW_A_REVERSE_PATH_ID).cookie(new FlowSegmentCookie(FLOW_A_REVERSE_COOKIE)).meterId(new MeterId(FLOW_A_REVERSE_METER_ID)).srcSwitch(switchC).destSwitch(switchA).bandwidth(FLOW_A_BANDWIDTH).status(FlowPathStatus.ACTIVE).build();
    flow.setReversePath(reverseFlowPath);
    PathSegment reverseSegmentA = PathSegment.builder().pathId(reverseFlowPath.getPathId()).srcSwitch(switchC).srcPort(FLOW_A_SEGMENT_B_DST_PORT).destSwitch(switchB).destPort(FLOW_A_SEGMENT_B_SRC_PORT).build();
    PathSegment reverseSegmentB = PathSegment.builder().pathId(reverseFlowPath.getPathId()).srcSwitch(switchB).srcPort(FLOW_A_SEGMENT_A_DST_PORT).destSwitch(switchA).destPort(FLOW_A_SEGMENT_A_SRC_PORT).build();
    reverseFlowPath.setSegments(Lists.newArrayList(reverseSegmentA, reverseSegmentB));
    FlowPath reverseProtectedFlowPath = FlowPath.builder().pathId(FLOW_A_REVERSE_PATH_ID_PROTECTED).cookie(new FlowSegmentCookie(FLOW_A_REVERSE_COOKIE_PROTECTED)).meterId(new MeterId(FLOW_A_REVERSE_METER_ID_PROTECTED)).srcSwitch(switchC).destSwitch(switchA).bandwidth(FLOW_A_BANDWIDTH).status(FlowPathStatus.ACTIVE).build();
    flow.setProtectedReversePath(reverseProtectedFlowPath);
    PathSegment reverseProtectedSegmentA = PathSegment.builder().pathId(reverseProtectedFlowPath.getPathId()).srcSwitch(switchC).srcPort(FLOW_A_SEGMENT_B_DST_PORT_PROTECTED).destSwitch(switchE).destPort(FLOW_A_SEGMENT_B_SRC_PORT_PROTECTED).build();
    PathSegment reverseProtectedSegmentB = PathSegment.builder().pathId(reverseProtectedFlowPath.getPathId()).srcSwitch(switchE).srcPort(FLOW_A_SEGMENT_A_DST_PORT_PROTECTED).destSwitch(switchA).destPort(FLOW_A_SEGMENT_A_SRC_PORT_PROTECTED).build();
    reverseProtectedFlowPath.setSegments(Lists.newArrayList(reverseProtectedSegmentA, reverseProtectedSegmentB));
    flowRepository.add(flow);
}
Also used : FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) Switch(org.openkilda.model.Switch) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow) MeterId(org.openkilda.model.MeterId)

Aggregations

Switch (org.openkilda.model.Switch)230 Test (org.junit.Test)126 Flow (org.openkilda.model.Flow)68 SwitchId (org.openkilda.model.SwitchId)67 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)46 FlowPath (org.openkilda.model.FlowPath)34 PathId (org.openkilda.model.PathId)32 Utils.buildSwitch (org.openkilda.rulemanager.Utils.buildSwitch)32 PathComputer (org.openkilda.pce.PathComputer)28 GetPathsResult (org.openkilda.pce.GetPathsResult)23 List (java.util.List)22 SwitchProperties (org.openkilda.model.SwitchProperties)21 FlowSpeakerData (org.openkilda.rulemanager.FlowSpeakerData)20 SpeakerData (org.openkilda.rulemanager.SpeakerData)19 String.format (java.lang.String.format)17 Set (java.util.Set)17 Isl (org.openkilda.model.Isl)15 HashSet (java.util.HashSet)14 ArrayList (java.util.ArrayList)13 Collections (java.util.Collections)13