Search in sources :

Example 6 with MirrorGroup

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

the class SwitchOperationsServiceTest method shouldValidateFlowMirrorPointsWhenUpdatingSwitchLldpProperties.

@Test(expected = IllegalSwitchPropertiesException.class)
public void shouldValidateFlowMirrorPointsWhenUpdatingSwitchLldpProperties() {
    Switch mirrorSwitch = Switch.builder().switchId(TEST_SWITCH_ID).status(SwitchStatus.ACTIVE).build();
    switchRepository.add(mirrorSwitch);
    MirrorGroup mirrorGroup = MirrorGroup.builder().switchId(TEST_SWITCH_ID).groupId(new GroupId(12L)).pathId(new PathId("test_path_id")).flowId(TEST_FLOW_ID_1).mirrorGroupType(MirrorGroupType.TRAFFIC_INTEGRITY).mirrorDirection(MirrorDirection.INGRESS).build();
    mirrorGroupRepository.add(mirrorGroup);
    FlowMirrorPoints flowMirrorPoints = FlowMirrorPoints.builder().mirrorGroup(mirrorGroup).mirrorSwitch(mirrorSwitch).build();
    flowMirrorPointsRepository.add(flowMirrorPoints);
    createSwitchProperties(mirrorSwitch, 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.setMultiTable(true);
    update.setSwitchLldp(true);
    switchOperationsService.updateSwitchProperties(TEST_SWITCH_ID, update);
}
Also used : PathId(org.openkilda.model.PathId) SwitchPropertiesDto(org.openkilda.messaging.model.SwitchPropertiesDto) MirrorGroup(org.openkilda.model.MirrorGroup) Switch(org.openkilda.model.Switch) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) GroupId(org.openkilda.model.GroupId) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 7 with MirrorGroup

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

the class CommandBuilderImpl method buildGroupInstallContexts.

@Override
public List<GroupInstallContext> buildGroupInstallContexts(SwitchId switchId, List<Integer> groupIds) {
    List<GroupInstallContext> groupInstallContexts = new ArrayList<>();
    Map<PathId, MirrorGroup> mirrorGroups = new HashMap<>();
    groupIds.stream().map(GroupId::new).map(mirrorGroupRepository::findByGroupId).flatMap(o -> o.map(Stream::of).orElseGet(Stream::empty)).forEach(mirrorGroup -> mirrorGroups.put(mirrorGroup.getPathId(), mirrorGroup));
    flowPathRepository.findBySegmentDestSwitch(switchId).forEach(flowPath -> {
        if (mirrorGroups.containsKey(flowPath.getPathId())) {
            PathSegment segment = flowPath.getSegments().stream().filter(pathSegment -> pathSegment.getDestSwitchId().equals(switchId)).findAny().orElseThrow(() -> new IllegalStateException(format("PathSegment not found, path %s, switch %s", flowPath, switchId)));
            Flow flow = flowPath.getFlow();
            if (segment.getDestSwitchId().equals(flowPath.getDestSwitchId())) {
                MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, flow.getDestSwitchId(), flow.getDestPort());
                groupInstallContexts.add(GroupInstallContext.builder().mirrorConfig(mirrorConfig).build());
                log.info("Group {} is to be (re)installed on switch {}", mirrorConfig.getGroupId(), switchId);
            }
        }
    });
    flowPathRepository.findByEndpointSwitch(switchId).forEach(flowPath -> {
        if (mirrorGroups.containsKey(flowPath.getPathId())) {
            Flow flow = getFlow(flowPath);
            if (flowPath.isOneSwitchFlow()) {
                SwitchId swId = flowPath.isForward() ? flow.getDestSwitchId() : flow.getSrcSwitchId();
                int port = flowPath.isForward() ? flow.getDestPort() : flow.getSrcPort();
                MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, swId, port);
                groupInstallContexts.add(GroupInstallContext.builder().mirrorConfig(mirrorConfig).build());
                log.info("Group {} is to be (re)installed on switch {}", mirrorConfig.getGroupId(), switchId);
            } else if (flowPath.getSrcSwitchId().equals(switchId)) {
                if (flowPath.getSegments().isEmpty()) {
                    log.warn("Output port was not found for mirror config");
                } else {
                    PathSegment foundIngressSegment = flowPath.getSegments().get(0);
                    MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, foundIngressSegment.getSrcSwitchId(), foundIngressSegment.getSrcPort());
                    EncapsulationResources encapsulation = getEncapsulationResources(flowPath, flow);
                    groupInstallContexts.add(GroupInstallContext.builder().mirrorConfig(mirrorConfig).encapsulation(new FlowTransitEncapsulation(encapsulation.getTransitEncapsulationId(), encapsulation.getEncapsulationType())).egressSwitchId(flowPath.getDestSwitchId()).build());
                    log.info("Group {} is to be (re)installed on switch {}", mirrorConfig.getGroupId(), switchId);
                }
            }
        }
    });
    return groupInstallContexts;
}
Also used : ModifyDefaultMeterForSwitchManagerRequest(org.openkilda.messaging.command.flow.ModifyDefaultMeterForSwitchManagerRequest) MirrorConfig(org.openkilda.model.MirrorConfig) NoArgGenerator(com.fasterxml.uuid.NoArgGenerator) EncapsulationResources(org.openkilda.wfm.share.flow.resources.EncapsulationResources) InstallServer42Flow(org.openkilda.messaging.command.flow.InstallServer42Flow) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria) FlowPath(org.openkilda.model.FlowPath) BaseFlow(org.openkilda.messaging.command.flow.BaseFlow) FlowResourcesConfig(org.openkilda.wfm.share.flow.resources.FlowResourcesConfig) SERVER_42_FLOW_RTT_OUTPUT_VXLAN_COOKIE(org.openkilda.model.cookie.Cookie.SERVER_42_FLOW_RTT_OUTPUT_VXLAN_COOKIE) NumberUtils(org.apache.commons.lang.math.NumberUtils) LogicalPortInfoEntry(org.openkilda.messaging.info.switches.LogicalPortInfoEntry) ReinstallDefaultFlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.ReinstallDefaultFlowForSwitchManagerRequest) Flow(org.openkilda.model.Flow) MirrorGroup(org.openkilda.model.MirrorGroup) Map(java.util.Map) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) ModifyFlowMeterForSwitchManagerRequest(org.openkilda.messaging.command.flow.ModifyFlowMeterForSwitchManagerRequest) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) DeleteLogicalPortRequest(org.openkilda.messaging.command.grpc.DeleteLogicalPortRequest) SwitchProperties(org.openkilda.model.SwitchProperties) IpSocketAddress(org.openkilda.model.IpSocketAddress) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) NonNull(lombok.NonNull) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) Set(java.util.Set) CookieType(org.openkilda.model.cookie.CookieBase.CookieType) InstallServer42FlowBuilder(org.openkilda.messaging.command.flow.InstallServer42Flow.InstallServer42FlowBuilder) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) ReinstallServer42FlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.ReinstallServer42FlowForSwitchManagerRequest) MeterInfoEntry(org.openkilda.messaging.info.switches.MeterInfoEntry) SwitchPropertiesRepository(org.openkilda.persistence.repositories.SwitchPropertiesRepository) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Stream(java.util.stream.Stream) FlowInstructions(org.openkilda.messaging.info.rule.FlowInstructions) Optional(java.util.Optional) FlowCommandFactory(org.openkilda.wfm.share.flow.service.FlowCommandFactory) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) PathSegment(org.openkilda.model.PathSegment) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SwitchNotFoundException(org.openkilda.wfm.topology.switchmanager.error.SwitchNotFoundException) BaseInstallFlow(org.openkilda.messaging.command.flow.BaseInstallFlow) CreateLogicalPortRequest(org.openkilda.messaging.command.grpc.CreateLogicalPortRequest) Cookie(org.openkilda.model.cookie.Cookie) LogicalPortMapper(org.openkilda.wfm.topology.switchmanager.mappers.LogicalPortMapper) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) PersistenceManager(org.openkilda.persistence.PersistenceManager) CommandBuilder(org.openkilda.wfm.topology.switchmanager.service.CommandBuilder) PathId(org.openkilda.model.PathId) SERVER_42_FLOW_RTT_OUTPUT_VLAN_COOKIE(org.openkilda.model.cookie.Cookie.SERVER_42_FLOW_RTT_OUTPUT_VLAN_COOKIE) SharedSegmentType(org.openkilda.model.cookie.FlowSharedSegmentCookie.SharedSegmentType) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) Switch(org.openkilda.model.Switch) GroupInstallContext(org.openkilda.wfm.topology.switchmanager.model.GroupInstallContext) SERVER_42_ISL_RTT_OUTPUT_COOKIE(org.openkilda.model.cookie.Cookie.SERVER_42_ISL_RTT_OUTPUT_COOKIE) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) PortColourCookie(org.openkilda.model.cookie.PortColourCookie) FlowSharedSegmentCookie(org.openkilda.model.cookie.FlowSharedSegmentCookie) FlowApplyActions(org.openkilda.messaging.info.rule.FlowApplyActions) MirrorGroupRepository(org.openkilda.persistence.repositories.MirrorGroupRepository) InstallSharedFlow(org.openkilda.messaging.command.flow.InstallSharedFlow) SwitchId(org.openkilda.model.SwitchId) MirrorConfigData(org.openkilda.model.MirrorConfig.MirrorConfigData) FlowResourcesManager(org.openkilda.wfm.share.flow.resources.FlowResourcesManager) Generators(com.fasterxml.uuid.Generators) VisibleForTesting(com.google.common.annotations.VisibleForTesting) FlowMatchField(org.openkilda.messaging.info.rule.FlowMatchField) GroupId(org.openkilda.model.GroupId) Collections(java.util.Collections) MirrorGroup(org.openkilda.model.MirrorGroup) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) SwitchId(org.openkilda.model.SwitchId) PathSegment(org.openkilda.model.PathSegment) InstallServer42Flow(org.openkilda.messaging.command.flow.InstallServer42Flow) BaseFlow(org.openkilda.messaging.command.flow.BaseFlow) Flow(org.openkilda.model.Flow) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) BaseInstallFlow(org.openkilda.messaging.command.flow.BaseInstallFlow) InstallSharedFlow(org.openkilda.messaging.command.flow.InstallSharedFlow) PathId(org.openkilda.model.PathId) GroupInstallContext(org.openkilda.wfm.topology.switchmanager.model.GroupInstallContext) EncapsulationResources(org.openkilda.wfm.share.flow.resources.EncapsulationResources) MirrorConfig(org.openkilda.model.MirrorConfig) Stream(java.util.stream.Stream)

Example 8 with MirrorGroup

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

the class MirrorGroupIdPool method addMirrorGroup.

private MirrorGroup addMirrorGroup(String flowId, PathId pathId, SwitchId switchId, GroupId groupId, MirrorGroupType type, MirrorDirection direction) {
    MirrorGroup mirrorGroup = MirrorGroup.builder().groupId(groupId).switchId(switchId).flowId(flowId).pathId(pathId).mirrorGroupType(type).mirrorDirection(direction).build();
    mirrorGroupRepository.add(mirrorGroup);
    return mirrorGroup;
}
Also used : MirrorGroup(org.openkilda.model.MirrorGroup)

Example 9 with MirrorGroup

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

the class MirrorGroupIdPool method allocate.

/**
 * Allocates a group id for the flow path.
 */
@TransactionRequired
public MirrorGroup allocate(SwitchId switchId, String flowId, PathId pathId, MirrorGroupType type, MirrorDirection direction) {
    GroupId nextGroupId = nextGroupIds.get(switchId);
    if (nextGroupId != null && nextGroupId.getValue() > 0) {
        if (nextGroupId.compareTo(maxGroupId) <= 0 && !mirrorGroupRepository.exists(switchId, nextGroupId)) {
            MirrorGroup mirrorGroup = addMirrorGroup(flowId, pathId, switchId, nextGroupId, type, direction);
            nextGroupIds.put(switchId, new GroupId(nextGroupId.getValue() + 1));
            return mirrorGroup;
        } else {
            nextGroupIds.remove(switchId);
        }
    }
    // The pool requires (re-)initialization.
    if (!nextGroupIds.containsKey(switchId)) {
        long numOfPools = (maxGroupId.getValue() - minGroupId.getValue()) / poolSize;
        if (numOfPools > 1) {
            long poolToTake = Math.abs(new Random().nextInt()) % numOfPools;
            Optional<GroupId> availableGroupId = mirrorGroupRepository.findFirstUnassignedGroupId(switchId, new GroupId(minGroupId.getValue() + poolToTake * poolSize), new GroupId(minGroupId.getValue() + (poolToTake + 1) * poolSize - 1));
            if (availableGroupId.isPresent()) {
                nextGroupId = availableGroupId.get();
                MirrorGroup mirrorGroup = addMirrorGroup(flowId, pathId, switchId, nextGroupId, type, direction);
                nextGroupIds.put(switchId, new GroupId(nextGroupId.getValue() + 1));
                return mirrorGroup;
            }
        }
        // The pool requires full scan.
        nextGroupId = new GroupId(-1);
        nextGroupIds.put(switchId, nextGroupId);
    }
    if (nextGroupId != null && nextGroupId.getValue() == -1) {
        Optional<GroupId> availableMeter = mirrorGroupRepository.findFirstUnassignedGroupId(switchId, minGroupId, maxGroupId);
        if (availableMeter.isPresent()) {
            nextGroupId = availableMeter.get();
            MirrorGroup mirrorGroup = addMirrorGroup(flowId, pathId, switchId, nextGroupId, type, direction);
            nextGroupIds.put(switchId, new GroupId(nextGroupId.getValue() + 1));
            return mirrorGroup;
        }
    }
    throw new ResourceNotAvailableException(format("No group id available for switch %s", switchId));
}
Also used : MirrorGroup(org.openkilda.model.MirrorGroup) Random(java.util.Random) GroupId(org.openkilda.model.GroupId) TransactionRequired(org.openkilda.persistence.tx.TransactionRequired)

Example 10 with MirrorGroup

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

the class SwitchOperationsServiceTest method shouldValidateFlowMirrorPointsWhenUpdatingSwitchArpProperties.

@Test(expected = IllegalSwitchPropertiesException.class)
public void shouldValidateFlowMirrorPointsWhenUpdatingSwitchArpProperties() {
    Switch mirrorSwitch = Switch.builder().switchId(TEST_SWITCH_ID).status(SwitchStatus.ACTIVE).build();
    switchRepository.add(mirrorSwitch);
    MirrorGroup mirrorGroup = MirrorGroup.builder().switchId(TEST_SWITCH_ID).groupId(new GroupId(12L)).pathId(new PathId("test_path_id")).flowId(TEST_FLOW_ID_1).mirrorGroupType(MirrorGroupType.TRAFFIC_INTEGRITY).mirrorDirection(MirrorDirection.INGRESS).build();
    mirrorGroupRepository.add(mirrorGroup);
    FlowMirrorPoints flowMirrorPoints = FlowMirrorPoints.builder().mirrorGroup(mirrorGroup).mirrorSwitch(mirrorSwitch).build();
    flowMirrorPointsRepository.add(flowMirrorPoints);
    createSwitchProperties(mirrorSwitch, 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.setMultiTable(true);
    update.setSwitchArp(true);
    switchOperationsService.updateSwitchProperties(TEST_SWITCH_ID, update);
}
Also used : PathId(org.openkilda.model.PathId) SwitchPropertiesDto(org.openkilda.messaging.model.SwitchPropertiesDto) MirrorGroup(org.openkilda.model.MirrorGroup) Switch(org.openkilda.model.Switch) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) GroupId(org.openkilda.model.GroupId) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Aggregations

MirrorGroup (org.openkilda.model.MirrorGroup)13 GroupId (org.openkilda.model.GroupId)7 Test (org.junit.Test)6 PathId (org.openkilda.model.PathId)6 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)6 Switch (org.openkilda.model.Switch)5 FlowMirrorPoints (org.openkilda.model.FlowMirrorPoints)4 String.format (java.lang.String.format)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Slf4j (lombok.extern.slf4j.Slf4j)2 FlowPath (org.openkilda.model.FlowPath)2 SwitchId (org.openkilda.model.SwitchId)2 Generators (com.fasterxml.uuid.Generators)1 NoArgGenerator (com.fasterxml.uuid.NoArgGenerator)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1