use of org.openkilda.model.Isl in project open-kilda by telstra.
the class PersistenceDummyEntityFactory method makeIsl.
/**
* Create {@link Isl} object.
*/
public Isl makeIsl(IslEndpoint source, IslEndpoint dest) {
Switch destSwitch = fetchOrCreateSwitch(source.getSwitchId());
Switch sourceSwitch = fetchOrCreateSwitch(dest.getSwitchId());
Isl isl = islDefaults.fill(Isl.builder()).srcSwitch(destSwitch).srcPort(source.getPortNumber()).destSwitch(sourceSwitch).destPort(dest.getPortNumber()).build();
islRepository.add(isl);
return isl;
}
use of org.openkilda.model.Isl in project open-kilda by telstra.
the class IslFsm method flush.
private void flush(Anchor source, Anchor dest, Instant timeNow) {
Optional<Isl> storedIsl = loadIsl(source.getEndpoint(), dest.getEndpoint());
Isl link = storedIsl.orElseGet(() -> createIsl(source, dest, timeNow));
link.setTimeModify(timeNow);
long maxBandwidth = link.getMaxBandwidth();
for (DiscoveryMonitor<?> entry : monitorsByPriority) {
entry.flush(source.getEndpoint(), link);
}
applyIslMaxBandwidth(link, source.getEndpoint(), dest.getEndpoint());
if (!storedIsl.isPresent() || maxBandwidth != link.getMaxBandwidth()) {
applyIslAvailableBandwidth(link, source.getEndpoint(), dest.getEndpoint());
}
link.setStatus(statusAggregator.getEffectiveStatus());
if (statusAggregator.getEffectiveStatus() == IslStatus.INACTIVE) {
link.setDownReason(statusAggregator.getDownReason());
} else {
link.setDownReason(null);
}
log.debug("Write ISL object: {}", link);
}
use of org.openkilda.model.Isl in project open-kilda by telstra.
the class IslFsm method loadPersistentData.
// -- private/service methods --
private void loadPersistentData(Endpoint start, Endpoint end) {
Optional<Isl> potentialIsl = islRepository.findByEndpoints(start.getDatapath(), start.getPortNumber(), end.getDatapath(), end.getPortNumber());
if (potentialIsl.isPresent()) {
Isl isl = potentialIsl.get();
for (DiscoveryMonitor<?> entry : monitorsByPriority) {
entry.load(start, isl);
}
fixUpPersistentData(isl);
} else {
log.debug("There is no persistent ISL data {} ==> {} (do not load monitors state)", start, end);
}
}
use of org.openkilda.model.Isl 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.Isl in project open-kilda by telstra.
the class FermaIslRepository method findByPathIds.
@Override
public Collection<Isl> findByPathIds(List<PathId> pathIds) {
List<String> pathIdAsStr = pathIds.stream().map(PathIdConverter.INSTANCE::toGraphProperty).collect(Collectors.toList());
List<? extends PathSegmentFrame> segmentFrames = framedGraph().traverse(g -> g.V().hasLabel(PathSegmentFrame.FRAME_LABEL).has(PathSegmentFrame.PATH_ID_PROPERTY, P.within(pathIdAsStr))).toListExplicit(PathSegmentFrame.class);
if (segmentFrames.isEmpty()) {
return emptyList();
}
List<Isl> result = new ArrayList<>();
segmentFrames.forEach(segmentFrame -> {
framedGraph().traverse(g -> g.E().hasLabel(IslFrame.FRAME_LABEL).has(IslFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(segmentFrame.getSrcSwitchId())).has(IslFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(segmentFrame.getDestSwitchId())).has(IslFrame.SRC_PORT_PROPERTY, segmentFrame.getSrcPort()).has(IslFrame.DST_PORT_PROPERTY, segmentFrame.getDestPort())).frameExplicit(IslFrame.class).forEachRemaining(frame -> result.add(addIslConfigToIsl(new Isl(frame))));
});
return result;
}
Aggregations