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();
}
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());
}
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));
}
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));
}
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);
}
Aggregations