use of org.openkilda.model.PathId 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.PathId 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));
}
}
use of org.openkilda.model.PathId 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.PathId in project open-kilda by telstra.
the class PersistenceDataAdapterTest method shouldProvideCorrectFlowPaths.
@Test
public void shouldProvideCorrectFlowPaths() {
PathId pathId = new PathId("path1");
Set<PathId> pathIds = Sets.newHashSet(pathId);
FlowPath flowPath = FlowPath.builder().pathId(pathId).srcSwitch(buildSwitch(SWITCH_ID_1, Collections.emptySet())).destSwitch(buildSwitch(SWITCH_ID_2, Collections.emptySet())).build();
Map<PathId, FlowPath> flowPaths = new HashMap<>();
flowPaths.put(pathId, flowPath);
when(flowPathRepository.findByIds(pathIds)).thenReturn(flowPaths);
adapter = PersistenceDataAdapter.builder().pathIds(pathIds).persistenceManager(persistenceManager).build();
Map<PathId, FlowPath> actual = adapter.getFlowPaths();
assertEquals(1, actual.size());
assertEquals(flowPath, actual.get(pathId));
adapter.getFlowPaths();
verify(flowPathRepository).findByIds(pathIds);
verifyNoMoreInteractions(flowPathRepository);
}
use of org.openkilda.model.PathId in project open-kilda by telstra.
the class RuleManagerImpl method buildRulesForFlowPath.
@Override
public List<SpeakerData> buildRulesForFlowPath(FlowPath flowPath, boolean filterOutUsedSharedRules, DataAdapter adapter) {
List<SpeakerData> result = new ArrayList<>();
Flow flow = adapter.getFlow(flowPath.getPathId());
PathId oppositePathId = flow.getOppositePathId(flowPath.getPathId()).orElse(null);
FlowTransitEncapsulation encapsulation = adapter.getTransitEncapsulation(flowPath.getPathId(), oppositePathId);
if (!flow.isProtectedPath(flowPath.getPathId())) {
Set<FlowSideAdapter> overlappingAdapters = new HashSet<>();
if (filterOutUsedSharedRules) {
overlappingAdapters = getOverlappingMultiTableIngressAdapters(flowPath, adapter);
}
buildIngressCommands(adapter.getSwitch(flowPath.getSrcSwitchId()), flowPath, flow, encapsulation, overlappingAdapters, adapter.getSwitchProperties(flowPath.getSrcSwitchId()), adapter.getFeatureToggles());
}
if (flowPath.isOneSwitchFlow()) {
return result;
}
result.addAll(buildEgressCommands(adapter.getSwitch(flowPath.getDestSwitchId()), flowPath, flow, encapsulation));
for (int i = 1; i < flowPath.getSegments().size(); i++) {
PathSegment firstSegment = flowPath.getSegments().get(i - 1);
PathSegment secondSegment = flowPath.getSegments().get(i);
result.addAll(buildTransitCommands(adapter.getSwitch(firstSegment.getDestSwitchId()), flowPath, encapsulation, firstSegment, secondSegment));
}
if (flow.isLooped()) {
Switch loopedSwitch = adapter.getSwitch(flow.getLoopSwitchId());
result.addAll(buildTransitLoopCommands(loopedSwitch, flowPath, flow, encapsulation));
}
return postProcessCommands(result);
}
Aggregations