use of org.openkilda.model.PathId in project open-kilda by telstra.
the class FlowPathFrame method addFlowMirrorPoints.
@Override
public void addFlowMirrorPoints(FlowMirrorPoints flowMirrorPoints) {
FlowMirrorPoints.FlowMirrorPointsData data = flowMirrorPoints.getData();
FlowMirrorPointsFrame frame;
if (data instanceof FlowMirrorPointsFrame) {
frame = (FlowMirrorPointsFrame) data;
// Unlink the mirror points from the previous owner.
frame.getElement().edges(Direction.IN, FlowPathFrame.HAS_SEGMENTS_EDGE).forEachRemaining(Edge::remove);
} else {
// A path must be added via corresponding repository first.
throw new IllegalArgumentException("Unable to link to transient flow mirror points " + flowMirrorPoints);
}
PathId flowPathId = getPathId();
frame.setProperty(FlowMirrorPointsFrame.FLOW_PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(flowPathId));
linkOut(frame, HAS_SEGMENTS_EDGE);
flowMirrorPoints.getMirrorGroup().setPathId(flowPathId);
if (this.flowMirrorPointsSet != null) {
this.flowMirrorPointsSet.add(flowMirrorPoints);
}
}
use of org.openkilda.model.PathId in project open-kilda by telstra.
the class FlowResourcesManager method allocateFlowResources.
/**
* Try to allocate resources for the flow paths. The method doesn't initialize a transaction.
* So it requires external transaction to cover allocation failures.
* <p/>
* Provided two flows are considered as paired (forward and reverse),
* so some resources can be shared among them.
*/
public FlowResources allocateFlowResources(Flow flow) throws ResourceAllocationException {
PathId forwardPathId = generatePathId(flow.getFlowId());
PathId reversePathId = generatePathId(flow.getFlowId());
return allocateFlowResources(flow, forwardPathId, reversePathId);
}
use of org.openkilda.model.PathId in project open-kilda by telstra.
the class BaseResourceAllocationAction method allocateFlowResources.
@SneakyThrows
protected FlowResources allocateFlowResources(Flow flow, PathId forwardPathId, PathId reversePathId) throws ResourceAllocationException {
RetryPolicy<FlowResources> resourceAllocationRetryPolicy = transactionManager.<FlowResources>getDefaultRetryPolicy().handle(ResourceAllocationException.class).handle(ConstraintViolationException.class).onRetry(e -> log.warn("Failure in resource allocation. Retrying #{}...", e.getAttemptCount(), e.getLastFailure())).onRetriesExceeded(e -> log.warn("Failure in resource allocation. No more retries", e.getFailure())).withMaxRetries(resourceAllocationRetriesLimit);
FlowResources flowResources = transactionManager.doInTransaction(resourceAllocationRetryPolicy, () -> resourcesManager.allocateFlowResources(flow, forwardPathId, reversePathId));
log.debug("Resources have been allocated: {}", flowResources);
return flowResources;
}
use of org.openkilda.model.PathId in project open-kilda by telstra.
the class BaseResourceAllocationAction method allocatePathPair.
@SneakyThrows
protected GetPathsResult allocatePathPair(Flow flow, PathId newForwardPathId, PathId newReversePathId, boolean forceToIgnoreBandwidth, List<PathId> pathsToReuseBandwidth, FlowPathPair oldPaths, boolean allowOldPaths, String sharedBandwidthGroupId, Predicate<GetPathsResult> whetherCreatePathSegments) throws RecoverableException, UnroutableFlowException, ResourceAllocationException {
// Lazy initialisable map with reused bandwidth...
Supplier<Map<IslEndpoints, Long>> reuseBandwidthPerIsl = Suppliers.memoize(() -> {
Map<IslEndpoints, Long> result = new HashMap<>();
if (pathsToReuseBandwidth != null && !pathsToReuseBandwidth.isEmpty()) {
pathsToReuseBandwidth.stream().map(pathId -> flow.getPath(pathId).orElse(flowPathRepository.findById(pathId).orElse(null))).filter(Objects::nonNull).flatMap(path -> path.getSegments().stream()).forEach(segment -> {
IslEndpoints isl = new IslEndpoints(segment.getSrcSwitchId().toString(), segment.getSrcPort(), segment.getDestSwitchId().toString(), segment.getDestPort());
result.put(isl, result.getOrDefault(isl, 0L) + segment.getBandwidth());
});
}
return result;
});
RetryPolicy<GetPathsResult> pathAllocationRetryPolicy = new RetryPolicy<GetPathsResult>().handle(RecoverableException.class).handle(ResourceAllocationException.class).handle(UnroutableFlowException.class).handle(PersistenceException.class).onRetry(e -> log.warn("Failure in path allocation. Retrying #{}...", e.getAttemptCount(), e.getLastFailure())).onRetriesExceeded(e -> log.warn("Failure in path allocation. No more retries", e.getFailure())).withMaxRetries(pathAllocationRetriesLimit);
if (pathAllocationRetryDelay > 0) {
pathAllocationRetryPolicy.withDelay(Duration.ofMillis(pathAllocationRetryDelay));
}
try {
return Failsafe.with(pathAllocationRetryPolicy).get(() -> {
GetPathsResult potentialPath;
if (forceToIgnoreBandwidth) {
boolean originalIgnoreBandwidth = flow.isIgnoreBandwidth();
flow.setIgnoreBandwidth(true);
potentialPath = pathComputer.getPath(flow);
flow.setIgnoreBandwidth(originalIgnoreBandwidth);
} else {
potentialPath = pathComputer.getPath(flow, pathsToReuseBandwidth);
}
boolean newPathFound = isNotSamePath(potentialPath, oldPaths);
if (allowOldPaths || newPathFound) {
if (!newPathFound) {
log.debug("Found the same path for flow {}. Proceed with recreating it", flow.getFlowId());
}
if (whetherCreatePathSegments.test(potentialPath)) {
boolean ignoreBandwidth = forceToIgnoreBandwidth || flow.isIgnoreBandwidth();
List<PathSegment> forwardSegments = flowPathBuilder.buildPathSegments(newForwardPathId, potentialPath.getForward(), flow.getBandwidth(), ignoreBandwidth, sharedBandwidthGroupId);
List<PathSegment> reverseSegments = flowPathBuilder.buildPathSegments(newReversePathId, potentialPath.getReverse(), flow.getBandwidth(), ignoreBandwidth, sharedBandwidthGroupId);
transactionManager.doInTransaction(() -> {
createPathSegments(forwardSegments, reuseBandwidthPerIsl);
createPathSegments(reverseSegments, reuseBandwidthPerIsl);
});
}
return potentialPath;
}
return null;
});
} catch (FailsafeException ex) {
throw ex.getCause();
}
}
use of org.openkilda.model.PathId in project open-kilda by telstra.
the class FlowValidationTestBase method buildOneSwitchPortFlow.
protected void buildOneSwitchPortFlow() {
Switch switchD = Switch.builder().switchId(TEST_SWITCH_ID_D).description("").build();
switchRepository.add(switchD);
Flow flow = Flow.builder().flowId(TEST_FLOW_ID_B).srcSwitch(switchD).srcPort(FLOW_B_SRC_PORT).srcVlan(FLOW_B_SRC_VLAN).destSwitch(switchD).destPort(FLOW_B_SRC_PORT).destVlan(FLOW_B_DST_VLAN).bandwidth(FLOW_B_BANDWIDTH).encapsulationType(FlowEncapsulationType.TRANSIT_VLAN).status(FlowStatus.UP).build();
FlowPath forwardFlowPath = FlowPath.builder().pathId(new PathId(TEST_FLOW_ID_B + "_forward_path")).cookie(new FlowSegmentCookie(FLOW_B_FORWARD_COOKIE)).meterId(new MeterId(FLOW_B_FORWARD_METER_ID)).srcSwitch(switchD).destSwitch(switchD).bandwidth(FLOW_B_BANDWIDTH).status(FlowPathStatus.ACTIVE).build();
flow.setForwardPath(forwardFlowPath);
FlowPath reverseFlowPath = FlowPath.builder().pathId(new PathId(TEST_FLOW_ID_B + "_reverse_path")).cookie(new FlowSegmentCookie(FLOW_B_REVERSE_COOKIE)).meterId(new MeterId(FLOW_B_REVERSE_METER_ID)).srcSwitch(switchD).destSwitch(switchD).bandwidth(FLOW_B_BANDWIDTH).status(FlowPathStatus.ACTIVE).build();
flow.setReversePath(reverseFlowPath);
flowRepository.add(flow);
}
Aggregations