Search in sources :

Example 16 with GroupId

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

the class SwitchSyncFsm method sendGroupsCommands.

protected void sendGroupsCommands(SwitchSyncState from, SwitchSyncState to, SwitchSyncEvent event, Object context) {
    if (missingGroups.isEmpty() && misconfiguredGroups.isEmpty() && excessGroups.isEmpty()) {
        log.info("Nothing to do with groups (switch={}, key={})", switchId, key);
        fire(NEXT);
        return;
    }
    if (!missingGroups.isEmpty()) {
        log.info("Request to install switch groups has been sent (switch={}, key={})", switchId, key);
        missingGroupsPendingResponsesCount = missingGroups.size();
        for (GroupInstallContext groupContext : missingGroups) {
            carrier.sendCommandToSpeaker(key, new InstallGroupRequest(switchId, groupContext.getMirrorConfig(), groupContext.getEncapsulation(), groupContext.getEgressSwitchId()));
        }
    }
    if (!misconfiguredGroups.isEmpty()) {
        log.info("Request to modify switch groups has been sent (switch={}, key={})", switchId, key);
        misconfiguredGroupsPendingResponsesCount = misconfiguredGroups.size();
        for (GroupInstallContext groupContext : misconfiguredGroups) {
            carrier.sendCommandToSpeaker(key, new ModifyGroupRequest(switchId, groupContext.getMirrorConfig(), groupContext.getEncapsulation(), groupContext.getEgressSwitchId()));
        }
    }
    if (!excessGroups.isEmpty()) {
        log.info("Request to remove switch groups has been sent (switch={}, key={})", switchId, key);
        excessGroupsPendingResponsesCount = excessGroups.size();
        for (Integer groupId : excessGroups) {
            carrier.sendCommandToSpeaker(key, new DeleteGroupRequest(switchId, new GroupId(groupId)));
        }
    }
    continueIfGroupsSynchronized();
}
Also used : GroupInstallContext(org.openkilda.wfm.topology.switchmanager.model.GroupInstallContext) InstallGroupRequest(org.openkilda.messaging.command.switches.InstallGroupRequest) DeleteGroupRequest(org.openkilda.messaging.command.switches.DeleteGroupRequest) ModifyGroupRequest(org.openkilda.messaging.command.switches.ModifyGroupRequest) GroupId(org.openkilda.model.GroupId)

Example 17 with GroupId

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

the class OfGroupConverterTest method testConvertInstallGroupCommand.

@Test
public void testConvertInstallGroupCommand() {
    List<Bucket> buckets = new ArrayList<>();
    buckets.add(Bucket.builder().watchPort(WatchPort.ANY).watchGroup(WatchGroup.ALL).writeActions(Sets.newHashSet(new PortOutAction(new PortNumber(2, null)))).build());
    buckets.add(Bucket.builder().watchPort(WatchPort.ANY).watchGroup(WatchGroup.ALL).writeActions(Sets.newHashSet(new PortOutAction(new PortNumber(1, null)))).build());
    GroupSpeakerData groupSpeakerData = GroupSpeakerData.builder().groupId(new GroupId(GROUP_ID)).type(GroupType.ALL).buckets(buckets).build();
    OFFactoryVer13 factory = new OFFactoryVer13();
    OFGroupAdd ofGroupAdd = OfGroupConverter.INSTANCE.convertInstallGroupCommand(groupSpeakerData, factory);
    assertEquals(OFGroup.of(GROUP_ID), ofGroupAdd.getGroup());
    assertEquals(OFGroupType.ALL, ofGroupAdd.getGroupType());
    assertEquals(2, ofGroupAdd.getBuckets().size());
    List<OFBucket> expectedBuckets = new ArrayList<>();
    expectedBuckets.add(factory.buildBucket().setWatchPort(OFPort.ANY).setWatchGroup(OFGroup.ALL).setActions(getActions(factory, 2)).build());
    expectedBuckets.add(factory.buildBucket().setWatchPort(OFPort.ANY).setWatchGroup(OFGroup.ALL).setActions(getActions(factory, 1)).build());
    assertEquals(expectedBuckets, ofGroupAdd.getBuckets());
}
Also used : OFGroupAdd(org.projectfloodlight.openflow.protocol.OFGroupAdd) OFBucket(org.projectfloodlight.openflow.protocol.OFBucket) OFBucket(org.projectfloodlight.openflow.protocol.OFBucket) Bucket(org.openkilda.rulemanager.group.Bucket) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) OFFactoryVer13(org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13) ArrayList(java.util.ArrayList) GroupSpeakerData(org.openkilda.rulemanager.GroupSpeakerData) PortNumber(org.openkilda.rulemanager.ProtoConstants.PortNumber) GroupId(org.openkilda.model.GroupId) Test(org.junit.Test)

Example 18 with GroupId

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

the class OfGroupConverterTest method testConvertToGroupSpeakerData.

@Test
public void testConvertToGroupSpeakerData() {
    OFFactoryVer13 factory = new OFFactoryVer13();
    Builder builder = factory.buildGroupDescStatsReply();
    List<OFGroupDescStatsEntry> entries = new ArrayList<>();
    entries.add(getOfGroupEntry(factory));
    builder.setEntries(entries);
    List<GroupSpeakerData> groupSpeakerDataList = OfGroupConverter.INSTANCE.convertToGroupSpeakerData(builder.build());
    assertEquals(1, groupSpeakerDataList.size());
    GroupSpeakerData groupSpeakerData = groupSpeakerDataList.get(0);
    assertEquals(new GroupId(GROUP_ID), groupSpeakerData.getGroupId());
    assertEquals(GroupType.ALL, groupSpeakerData.getType());
    List<Bucket> buckets = groupSpeakerData.getBuckets();
    Set<Bucket> expectedBuckets = new HashSet<>();
    expectedBuckets.add(Bucket.builder().watchPort(WatchPort.ANY).watchGroup(WatchGroup.ALL).writeActions(Sets.newHashSet(new PortOutAction(new PortNumber(2, null)))).build());
    expectedBuckets.add(Bucket.builder().watchPort(WatchPort.ANY).watchGroup(WatchGroup.ALL).writeActions(Sets.newHashSet(new PortOutAction(new PortNumber(1, null)))).build());
    assertEquals(expectedBuckets, new HashSet<>(buckets));
}
Also used : OFFactoryVer13(org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) OFGroupDescStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry) Builder(org.projectfloodlight.openflow.protocol.OFGroupDescStatsReply.Builder) ArrayList(java.util.ArrayList) GroupSpeakerData(org.openkilda.rulemanager.GroupSpeakerData) GroupId(org.openkilda.model.GroupId) OFBucket(org.projectfloodlight.openflow.protocol.OFBucket) Bucket(org.openkilda.rulemanager.group.Bucket) PortNumber(org.openkilda.rulemanager.ProtoConstants.PortNumber) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 19 with GroupId

use of org.openkilda.model.GroupId 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 20 with GroupId

use of org.openkilda.model.GroupId 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

GroupId (org.openkilda.model.GroupId)20 MirrorGroup (org.openkilda.model.MirrorGroup)9 ArrayList (java.util.ArrayList)8 PathId (org.openkilda.model.PathId)8 SwitchId (org.openkilda.model.SwitchId)6 List (java.util.List)5 Test (org.junit.Test)5 FlowMirrorPoints (org.openkilda.model.FlowMirrorPoints)5 Switch (org.openkilda.model.Switch)5 PortNumber (org.openkilda.rulemanager.ProtoConstants.PortNumber)5 PortOutAction (org.openkilda.rulemanager.action.PortOutAction)5 OFBucket (org.projectfloodlight.openflow.protocol.OFBucket)5 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 MirrorGroupRepository (org.openkilda.persistence.repositories.MirrorGroupRepository)4 Bucket (org.openkilda.rulemanager.group.Bucket)4 Set (java.util.Set)3 Generators (com.fasterxml.uuid.Generators)2 NoArgGenerator (com.fasterxml.uuid.NoArgGenerator)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2