Search in sources :

Example 11 with FlowMirrorPath

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

the class LagPortOperationService method validatePhysicalPort.

private void validatePhysicalPort(SwitchId switchId, Set<SwitchFeature> features, Integer portNumber) throws InvalidDataException {
    if (portNumber == null || portNumber <= 0) {
        throw new InvalidDataException(format("Invalid physical port number %s. It can't be null or negative.", portNumber));
    }
    int bfdPortOffset = config.getBfdPortOffset();
    int bfdPortMaxNumber = config.getBfdPortMaxNumber();
    if (features.contains(BFD) && portNumber >= bfdPortOffset && portNumber <= bfdPortMaxNumber) {
        throw new InvalidDataException(format("Physical port number %d intersects with BFD port range [%d, %d]", portNumber, bfdPortOffset, bfdPortMaxNumber));
    }
    long lagPortOffset = config.getPoolConfig().getIdMinimum();
    if (portNumber >= lagPortOffset) {
        throw new InvalidDataException(format("Physical port number %d can't be greater than LAG port offset %d.", portNumber, lagPortOffset));
    }
    Collection<Isl> isls = islRepository.findByEndpoint(switchId, portNumber);
    if (!isls.isEmpty()) {
        throw new InvalidDataException(format("Physical port number %d intersects with existing ISLs %s.", portNumber, isls));
    }
    Optional<SwitchProperties> properties = switchPropertiesRepository.findBySwitchId(switchId);
    if (properties.isPresent() && Objects.equals(properties.get().getServer42Port(), portNumber)) {
        throw new InvalidDataException(format("Physical port number %d on switch %s is server42 port.", portNumber, switchId));
    }
    Set<String> flowIds = flowRepository.findByEndpoint(switchId, portNumber).stream().map(Flow::getFlowId).collect(Collectors.toSet());
    if (!flowIds.isEmpty()) {
        throw new InvalidDataException(format("Physical port %d already used by following flows: %s. You must " + "remove these flows to be able to use the port in LAG.", portNumber, flowIds));
    }
    Collection<FlowMirrorPath> mirrorPaths = flowMirrorPathRepository.findByEgressSwitchIdAndPort(switchId, portNumber);
    if (!mirrorPaths.isEmpty()) {
        Map<String, List<PathId>> mirrorPathByFLowIdMap = new HashMap<>();
        for (FlowMirrorPath path : mirrorPaths) {
            String flowId = path.getFlowMirrorPoints().getFlowPath().getFlowId();
            mirrorPathByFLowIdMap.computeIfAbsent(flowId, ignore -> new ArrayList<>());
            mirrorPathByFLowIdMap.get(flowId).add(path.getPathId());
        }
        String message = mirrorPathByFLowIdMap.entrySet().stream().map(entry -> format("flow '%s': %s", entry.getKey(), entry.getValue())).collect(Collectors.joining(", "));
        throw new InvalidDataException(format("Physical port %d already used as sink by following mirror points %s", portNumber, message));
    }
}
Also used : TransactionManager(org.openkilda.persistence.tx.TransactionManager) SwitchFeature(org.openkilda.model.SwitchFeature) LRUMap(org.apache.commons.collections4.map.LRUMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SwitchNotFoundException(org.openkilda.wfm.topology.switchmanager.error.SwitchNotFoundException) Flow(org.openkilda.model.Flow) PoolManager(org.openkilda.wfm.share.utils.PoolManager) IslRepository(org.openkilda.persistence.repositories.IslRepository) Map(java.util.Map) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) LagLogicalPort(org.openkilda.model.LagLogicalPort) LagPortNotFoundException(org.openkilda.wfm.topology.switchmanager.error.LagPortNotFoundException) PathId(org.openkilda.model.PathId) SwitchProperties(org.openkilda.model.SwitchProperties) IpSocketAddress(org.openkilda.model.IpSocketAddress) Switch(org.openkilda.model.Switch) PhysicalPortRepository(org.openkilda.persistence.repositories.PhysicalPortRepository) InconsistentDataException(org.openkilda.wfm.topology.switchmanager.error.InconsistentDataException) NonNull(lombok.NonNull) Collection(java.util.Collection) SetView(com.google.common.collect.Sets.SetView) Set(java.util.Set) RetryPolicy(net.jodah.failsafe.RetryPolicy) BFD(org.openkilda.model.SwitchFeature.BFD) FlowMirrorPathRepository(org.openkilda.persistence.repositories.FlowMirrorPathRepository) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) SwitchPropertiesRepository(org.openkilda.persistence.repositories.SwitchPropertiesRepository) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) LagLogicalPortRepository(org.openkilda.persistence.repositories.LagLogicalPortRepository) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) InvalidDataException(org.openkilda.wfm.topology.switchmanager.error.InvalidDataException) Optional(java.util.Optional) ConstraintViolationException(org.openkilda.persistence.exceptions.ConstraintViolationException) Isl(org.openkilda.model.Isl) PhysicalPort(org.openkilda.model.PhysicalPort) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) Isl(org.openkilda.model.Isl) HashMap(java.util.HashMap) InvalidDataException(org.openkilda.wfm.topology.switchmanager.error.InvalidDataException) ArrayList(java.util.ArrayList) List(java.util.List) SwitchProperties(org.openkilda.model.SwitchProperties) FlowMirrorPath(org.openkilda.model.FlowMirrorPath)

Example 12 with FlowMirrorPath

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

the class FermaFlowMirrorPathRepositoryTest method createFlowPath.

private FlowMirrorPath createFlowPath(PathId pathId, long cookie, Switch srcSwitch, Switch dstSwitch, int dstPort, int dstOuterVlan, int dstInnerVlan) {
    FlowMirrorPath flowMirrorPath = FlowMirrorPath.builder().pathId(pathId).cookie(new FlowSegmentCookie(cookie).toBuilder().mirror(true).build()).mirrorSwitch(srcSwitch).egressSwitch(dstSwitch).egressPort(dstPort).egressOuterVlan(dstOuterVlan).egressInnerVlan(dstInnerVlan).status(FlowPathStatus.ACTIVE).build();
    flowMirrorPathRepository.add(flowMirrorPath);
    return flowMirrorPath;
}
Also used : FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) FlowMirrorPath(org.openkilda.model.FlowMirrorPath)

Example 13 with FlowMirrorPath

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

the class FlowMapperTest method buildFlowMirrorPathList.

private List<FlowMirrorPath> buildFlowMirrorPathList() {
    FlowMirrorPath flowMirrorPathA = FlowMirrorPath.builder().pathId(MIRROR_PATH_ID_A).mirrorSwitch(Switch.builder().switchId(SRC_SWITCH_ID).build()).egressSwitch(Switch.builder().switchId(SRC_SWITCH_ID).build()).status(FLOW_PATH_STATUS_A).build();
    FlowMirrorPath flowMirrorPathB = FlowMirrorPath.builder().pathId(MIRROR_PATH_ID_B).mirrorSwitch(Switch.builder().switchId(SRC_SWITCH_ID).build()).egressSwitch(Switch.builder().switchId(SRC_SWITCH_ID).build()).status(FLOW_PATH_STATUS_B).build();
    return Lists.newArrayList(flowMirrorPathA, flowMirrorPathB);
}
Also used : FlowMirrorPath(org.openkilda.model.FlowMirrorPath)

Example 14 with FlowMirrorPath

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

the class SimpleSwitchRuleConverterTest method buildFlow.

private Flow buildFlow(FlowEncapsulationType flowEncapsulationType, boolean checkWithGroup) {
    Switch switchA = Switch.builder().switchId(TEST_SWITCH_ID_A).description("").build();
    Switch switchB = Switch.builder().switchId(TEST_SWITCH_ID_B).description("").build();
    Switch switchC = Switch.builder().switchId(TEST_SWITCH_ID_C).description("").build();
    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_VALUE)).meterId(new MeterId(FLOW_A_FORWARD_METER_ID)).srcSwitch(switchA).destSwitch(switchC).status(FlowPathStatus.ACTIVE).bandwidth(FLOW_A_BANDWIDTH).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));
    if (checkWithGroup) {
        FlowMirrorPoints flowMirrorPoints = FlowMirrorPoints.builder().mirrorSwitch(switchA).mirrorGroup(MirrorGroup.builder().switchId(TEST_SWITCH_ID_A).groupId(new GroupId(FLOW_GROUP_ID_A)).pathId(FLOW_A_FORWARD_PATH_ID).flowId(TEST_FLOW_ID_A).mirrorGroupType(MirrorGroupType.TRAFFIC_INTEGRITY).mirrorDirection(MirrorDirection.INGRESS).build()).build();
        FlowMirrorPath flowMirrorPath = FlowMirrorPath.builder().pathId(new PathId("mirror_path")).mirrorSwitch(switchA).egressSwitch(switchA).egressPort(FLOW_GROUP_ID_A_OUT_PORT).egressOuterVlan(FLOW_GROUP_ID_A_OUT_VLAN).build();
        flowMirrorPoints.addPaths(flowMirrorPath);
        forwardFlowPath.addFlowMirrorPoints(flowMirrorPoints);
    }
    return flow;
}
Also used : PathId(org.openkilda.model.PathId) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) Switch(org.openkilda.model.Switch) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) Flow(org.openkilda.model.Flow) MeterId(org.openkilda.model.MeterId) GroupId(org.openkilda.model.GroupId)

Example 15 with FlowMirrorPath

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

the class SwitchOperationsServiceTest method shouldValidateFlowMirrorPathWhenUpdatingServer42PortSwitchProperties.

@Test(expected = IllegalSwitchPropertiesException.class)
public void shouldValidateFlowMirrorPathWhenUpdatingServer42PortSwitchProperties() {
    Switch firstSwitch = Switch.builder().switchId(TEST_SWITCH_ID).status(SwitchStatus.ACTIVE).build();
    Switch secondSwitch = Switch.builder().switchId(TEST_SWITCH_ID_2).status(SwitchStatus.ACTIVE).build();
    switchRepository.add(firstSwitch);
    switchRepository.add(secondSwitch);
    FlowMirrorPath flowMirrorPath = FlowMirrorPath.builder().pathId(new PathId("test_path_id")).mirrorSwitch(secondSwitch).egressSwitch(firstSwitch).egressPort(TEST_FLOW_SRC_PORT).build();
    flowMirrorPathRepository.add(flowMirrorPath);
    createSwitchProperties(firstSwitch, Collections.singleton(FlowEncapsulationType.TRANSIT_VLAN), true, false, false);
    SwitchPropertiesDto update = new SwitchPropertiesDto();
    update.setSupportedTransitEncapsulation(Collections.singleton(org.openkilda.messaging.payload.flow.FlowEncapsulationType.TRANSIT_VLAN));
    update.setServer42Port(TEST_FLOW_SRC_PORT);
    switchOperationsService.updateSwitchProperties(TEST_SWITCH_ID, update);
}
Also used : PathId(org.openkilda.model.PathId) SwitchPropertiesDto(org.openkilda.messaging.model.SwitchPropertiesDto) Switch(org.openkilda.model.Switch) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Aggregations

FlowMirrorPath (org.openkilda.model.FlowMirrorPath)18 Flow (org.openkilda.model.Flow)6 PathId (org.openkilda.model.PathId)6 Test (org.junit.Test)5 FlowMirrorPoints (org.openkilda.model.FlowMirrorPoints)5 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)5 Switch (org.openkilda.model.Switch)4 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)3 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)3 ArrayList (java.util.ArrayList)2 InfoMessage (org.openkilda.messaging.info.InfoMessage)2 FlowMirrorPointResponse (org.openkilda.messaging.info.flow.FlowMirrorPointResponse)2 FlowPath (org.openkilda.model.FlowPath)2 PhysicalPort (org.openkilda.model.PhysicalPort)2 SwitchProperties (org.openkilda.model.SwitchProperties)2 Sets (com.google.common.collect.Sets)1 SetView (com.google.common.collect.Sets.SetView)1 String.format (java.lang.String.format)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1