use of org.openkilda.model.FlowPath in project open-kilda by telstra.
the class BaseResourceAllocationAction method createFlowPathPair.
protected FlowPathPair createFlowPathPair(String flowId, FlowResources flowResources, GetPathsResult pathPair, boolean forceToIgnoreBandwidth, String sharedBandwidthGroupId) {
FlowSegmentCookieBuilder cookieBuilder = FlowSegmentCookie.builder().flowEffectiveId(flowResources.getUnmaskedCookie());
return transactionManager.doInTransaction(() -> {
Flow flow = getFlow(flowId);
updateSwitchRelatedFlowProperties(flow);
Path forward = pathPair.getForward();
List<PathSegment> forwardSegments = pathSegmentRepository.findByPathId(flowResources.getForward().getPathId());
FlowPath newForwardPath = flowPathBuilder.buildFlowPath(flow, flowResources.getForward(), forward.getLatency(), forward.getSrcSwitchId(), forward.getDestSwitchId(), forwardSegments, cookieBuilder.direction(FlowPathDirection.FORWARD).build(), forceToIgnoreBandwidth, sharedBandwidthGroupId);
newForwardPath.setStatus(FlowPathStatus.IN_PROGRESS);
Path reverse = pathPair.getReverse();
List<PathSegment> reverseSegments = pathSegmentRepository.findByPathId(flowResources.getReverse().getPathId());
FlowPath newReversePath = flowPathBuilder.buildFlowPath(flow, flowResources.getReverse(), reverse.getLatency(), reverse.getSrcSwitchId(), reverse.getDestSwitchId(), reverseSegments, cookieBuilder.direction(FlowPathDirection.REVERSE).build(), forceToIgnoreBandwidth, sharedBandwidthGroupId);
newReversePath.setStatus(FlowPathStatus.IN_PROGRESS);
log.debug("Persisting the paths {}/{}", newForwardPath, newReversePath);
flowPathRepository.add(newForwardPath);
flowPathRepository.add(newReversePath);
flow.addPaths(newForwardPath, newReversePath);
return FlowPathPair.builder().forward(newForwardPath).reverse(newReversePath).build();
});
}
use of org.openkilda.model.FlowPath in project open-kilda by telstra.
the class YFlowRuleManagerProcessingAction method buildYFlowSpeakerData.
private Map<SwitchId, List<SpeakerData>> buildYFlowSpeakerData(YFlow yFlow) {
List<FlowPath> flowPaths = yFlow.getSubFlows().stream().map(YSubFlow::getFlow).map(Flow::getPaths).flatMap(Collection::stream).collect(toList());
Set<SwitchId> switchIds = Sets.newHashSet(yFlow.getSharedEndpoint().getSwitchId(), yFlow.getYPoint(), yFlow.getProtectedPathYPoint());
Set<PathId> pathIds = flowPaths.stream().map(FlowPath::getPathId).collect(Collectors.toSet());
DataAdapter dataAdapter = PersistenceDataAdapter.builder().persistenceManager(persistenceManager).switchIds(switchIds).pathIds(pathIds).build();
return ruleManager.buildRulesForYFlow(flowPaths, dataAdapter).stream().collect(Collectors.groupingBy(SpeakerData::getSwitchId, Collectors.mapping(Function.identity(), toList())));
}
use of org.openkilda.model.FlowPath in project open-kilda by telstra.
the class CompleteFlowPathRemovalAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowDeleteContext context, FlowDeleteFsm stateMachine) {
Flow flow = transactionManager.doInTransaction(() -> {
Flow foundFlow = getFlow(stateMachine.getFlowId());
Stream.of(foundFlow.getForwardPath(), foundFlow.getReversePath()).map(FlowPath::getFlowMirrorPointsSet).flatMap(Collection::stream).forEach(mirrorPoints -> {
Set<Long> cookies = new HashSet<>();
mirrorPoints.getMirrorPaths().forEach(mirrorPath -> {
cookies.add(mirrorPath.getCookie().getFlowEffectiveId());
flowMirrorPathRepository.remove(mirrorPath);
});
stateMachine.getFlowMirrorPathResources().add(FlowMirrorPathResources.builder().flowPathId(mirrorPoints.getFlowPathId()).mirrorSwitchId(mirrorPoints.getMirrorSwitchId()).unmaskedCookies(cookies).build());
flowMirrorPointsRepository.remove(mirrorPoints);
});
return foundFlow;
});
// Iterate to remove each path in a dedicated transaction.
flow.getPathIds().forEach(pathId -> {
Optional<FlowPath> deletedPath = flowPathRepository.remove(pathId);
deletedPath.ifPresent(path -> {
updateIslsForFlowPath(path);
saveRemovalActionWithDumpToHistory(stateMachine, flow, new FlowPathPair(path, path));
});
});
}
use of org.openkilda.model.FlowPath in project open-kilda by telstra.
the class HandleNotRemovedPathsAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowDeleteContext context, FlowDeleteFsm stateMachine) {
Flow flow = getFlow(stateMachine.getFlowId());
FlowPath[] paths = flow.getPaths().stream().filter(Objects::nonNull).toArray(FlowPath[]::new);
stateMachine.saveErrorToHistory("Failed to remove paths", format("Failed to remove paths: \"%s\"", Arrays.stream(paths).map(FlowPath::getPathId).map(PathId::toString).collect(Collectors.joining("\", \""))));
}
use of org.openkilda.model.FlowPath in project open-kilda by telstra.
the class ResourcesAllocationAction method allocateProtectedPath.
private void allocateProtectedPath(FlowCreateFsm stateMachine) throws UnroutableFlowException, RecoverableException, ResourceAllocationException, FlowNotFoundException {
String flowId = stateMachine.getFlowId();
Flow tmpFlow = getFlow(flowId);
if (!tmpFlow.isAllocateProtectedPath()) {
return;
}
tmpFlow.setDiverseGroupId(getFlowDiverseGroupFromContext(flowId).orElseThrow(() -> new FlowNotFoundException(flowId)));
GetPathsResult protectedPath = pathComputer.getPath(tmpFlow);
stateMachine.setBackUpProtectedPathComputationWayUsed(protectedPath.isBackUpPathComputationWayUsed());
boolean overlappingProtectedPathFound = flowPathBuilder.arePathsOverlapped(protectedPath.getForward(), tmpFlow.getForwardPath()) || flowPathBuilder.arePathsOverlapped(protectedPath.getReverse(), tmpFlow.getReversePath());
if (overlappingProtectedPathFound) {
log.info("Couldn't find non overlapping protected path. Result flow state: {}", tmpFlow);
throw new UnroutableFlowException("Couldn't find non overlapping protected path", tmpFlow.getFlowId());
}
log.debug("Creating the protected path {} for flow {}", protectedPath, tmpFlow);
transactionManager.doInTransaction(() -> {
Flow flow = getFlow(flowId);
FlowResources flowResources = resourcesManager.allocateFlowResources(flow);
final FlowSegmentCookieBuilder cookieBuilder = FlowSegmentCookie.builder().flowEffectiveId(flowResources.getUnmaskedCookie());
FlowPath forward = flowPathBuilder.buildFlowPath(flow, flowResources.getForward(), protectedPath.getForward(), cookieBuilder.direction(FlowPathDirection.FORWARD).build(), false, stateMachine.getSharedBandwidthGroupId());
forward.setStatus(FlowPathStatus.IN_PROGRESS);
flowPathRepository.add(forward);
flow.setProtectedForwardPath(forward);
FlowPath reverse = flowPathBuilder.buildFlowPath(flow, flowResources.getReverse(), protectedPath.getReverse(), cookieBuilder.direction(FlowPathDirection.REVERSE).build(), false, stateMachine.getSharedBandwidthGroupId());
reverse.setStatus(FlowPathStatus.IN_PROGRESS);
flowPathRepository.add(reverse);
flow.setProtectedReversePath(reverse);
updateIslsForFlowPath(forward.getPathId());
updateIslsForFlowPath(reverse.getPathId());
stateMachine.setProtectedForwardPathId(forward.getPathId());
stateMachine.setProtectedReversePathId(reverse.getPathId());
log.debug("Allocated resources for the flow {}: {}", flow.getFlowId(), flowResources);
stateMachine.getFlowResources().add(flowResources);
});
}
Aggregations