use of org.openkilda.model.PathSegment 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.PathSegment in project open-kilda by telstra.
the class BaseResourceAllocationAction method createPathSegments.
@VisibleForTesting
void createPathSegments(List<PathSegment> segments, Supplier<Map<IslEndpoints, Long>> reuseBandwidth) throws ResourceAllocationException {
for (PathSegment segment : segments) {
log.debug("Persisting the segment {}", segment);
long updatedAvailableBandwidth = pathSegmentRepository.addSegmentAndUpdateIslAvailableBandwidth(segment).orElse(0L);
if (!segment.isIgnoreBandwidth() && updatedAvailableBandwidth < 0) {
IslEndpoints isl = new IslEndpoints(segment.getSrcSwitchId().toString(), segment.getSrcPort(), segment.getDestSwitchId().toString(), segment.getDestPort());
log.debug("ISL {} is being over-provisioned, check if it's allowed", isl);
long allowedOverprovisionedBandwidth = reuseBandwidth.get().getOrDefault(isl, 0L);
if ((updatedAvailableBandwidth + allowedOverprovisionedBandwidth) < 0) {
throw new ResourceAllocationException(format("ISL %s_%d-%s_%d was overprovisioned", isl.getSrcSwitch(), isl.getSrcPort(), isl.getDestSwitch(), isl.getDestPort()));
}
}
}
}
use of org.openkilda.model.PathSegment in project open-kilda by telstra.
the class ResourcesDeallocationAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowCreateContext context, FlowCreateFsm stateMachine) {
try {
transactionManager.doInTransaction(() -> {
Flow flow = getFlow(stateMachine.getFlowId());
flow.resetPaths();
});
} catch (FlowProcessingException e) {
stateMachine.saveActionToHistory("Skip resources deallocation", format("Skip resources deallocation. Flow %s has already been deleted: %s", stateMachine.getFlowId(), e.getMessage()));
return;
}
Collection<FlowResources> flowResources = stateMachine.getFlowResources();
for (FlowResources resources : flowResources) {
List<PathSegment> removedSegments = new ArrayList<>();
Stream.of(resources.getForward().getPathId(), resources.getReverse().getPathId()).forEach(pathId -> flowPathRepository.remove(pathId).ifPresent(path -> removedSegments.addAll(path.getSegments())));
updateIslsForSegments(removedSegments);
transactionManager.doInTransaction(() -> resourcesManager.deallocatePathResources(resources));
}
if (!stateMachine.isPathsBeenAllocated()) {
flowRepository.remove(stateMachine.getFlowId());
}
stateMachine.saveActionToHistory("The resources have been deallocated");
}
use of org.openkilda.model.PathSegment in project open-kilda by telstra.
the class OnSubFlowAllocatedAction method buildRerouteResponseMessage.
private Message buildRerouteResponseMessage(YFlowRerouteFsm stateMachine) {
String yFlowId = stateMachine.getYFlowId();
List<Long> oldFlowPathCookies = stateMachine.getOldYFlowPathCookies();
List<FlowPath> flowPaths = transactionManager.doInTransaction(() -> {
YFlow yflow = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Y-flow %s not found", yFlowId)));
SwitchId sharedSwitchId = yflow.getSharedEndpoint().getSwitchId();
List<FlowPath> paths = new ArrayList<>();
for (YSubFlow subFlow : yflow.getSubFlows()) {
Flow flow = subFlow.getFlow();
FlowPath flowPath = flow.getPaths().stream().filter(path -> sharedSwitchId.equals(path.getSrcSwitchId()) && !path.isProtected() && !oldFlowPathCookies.contains(path.getCookie().getValue())).findFirst().orElse(sharedSwitchId.equals(flow.getForwardPath().getSrcSwitchId()) ? flow.getForwardPath() : flow.getReversePath());
paths.add(flowPath);
}
return paths;
});
List<PathSegment> sharedPathSegments = IntersectionComputer.calculatePathIntersectionFromSource(flowPaths);
PathInfoData sharedPath = FlowPathMapper.INSTANCE.map(sharedPathSegments);
List<SubFlowPathDto> subFlowPathDtos = flowPaths.stream().map(flowPath -> new SubFlowPathDto(flowPath.getFlowId(), FlowPathMapper.INSTANCE.map(flowPath))).sorted(Comparator.comparing(SubFlowPathDto::getFlowId)).collect(Collectors.toList());
PathInfoData oldSharedPath = stateMachine.getOldSharedPath();
List<SubFlowPathDto> oldSubFlowPathDtos = stateMachine.getOldSubFlowPathDtos();
YFlowRerouteResponse response = new YFlowRerouteResponse(sharedPath, subFlowPathDtos, !(sharedPath.equals(oldSharedPath) && subFlowPathDtos.equals(oldSubFlowPathDtos)));
CommandContext commandContext = stateMachine.getCommandContext();
return new InfoMessage(response, commandContext.getCreateTime(), commandContext.getCorrelationId());
}
use of org.openkilda.model.PathSegment in project open-kilda by telstra.
the class YFlowReadService method getYFlowPaths.
/**
* Gets y-flow paths.
*/
public YFlowPathsResponse getYFlowPaths(@NonNull String yFlowId) throws FlowNotFoundException {
return transactionManager.doInTransaction(getReadOperationRetryPolicy(), () -> {
Set<YSubFlow> subFlows = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowNotFoundException(yFlowId)).getSubFlows();
Set<FlowPath> mainPaths = new HashSet<>();
Set<FlowPath> protectedPaths = new HashSet<>();
for (YSubFlow subFlow : subFlows) {
Flow flow = subFlow.getFlow();
mainPaths.add(flow.getForwardPath());
if (flow.isAllocateProtectedPath() && flow.getProtectedForwardPath() != null) {
protectedPaths.add(flow.getProtectedForwardPath());
}
}
List<PathSegment> sharedPathSegments = IntersectionComputer.calculatePathIntersectionFromSource(mainPaths);
PathInfoData sharedPath = FlowPathMapper.INSTANCE.map(sharedPathSegments);
PathInfoData sharedProtectedPath;
// At least 2 paths required to calculate Y-point.
if (protectedPaths.size() < 2) {
sharedProtectedPath = new PathInfoData();
} else {
List<PathSegment> pathSegments = IntersectionComputer.calculatePathIntersectionFromSource(protectedPaths);
sharedProtectedPath = FlowPathMapper.INSTANCE.map(pathSegments);
}
List<SubFlowPathDto> subFlowPathDtos = mainPaths.stream().map(flowPath -> new SubFlowPathDto(flowPath.getFlowId(), FlowPathMapper.INSTANCE.map(flowPath))).collect(Collectors.toList());
List<SubFlowPathDto> subFlowProtectedPathDtos = protectedPaths.stream().map(flowPath -> new SubFlowPathDto(flowPath.getFlowId(), FlowPathMapper.INSTANCE.map(flowPath))).collect(Collectors.toList());
return new YFlowPathsResponse(sharedPath, subFlowPathDtos, sharedProtectedPath, subFlowProtectedPathDtos);
});
}
Aggregations