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