use of com.syncleus.ferma.FramedGraph 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;
}
use of com.syncleus.ferma.FramedGraph in project open-kilda by telstra.
the class FermaIslRepository method updateAvailableBandwidthOnIslsOccupiedByPath.
@Override
public Map<IslEndpoints, Long> updateAvailableBandwidthOnIslsOccupiedByPath(PathId pathId) {
FramedGraph framedGraph = framedGraph();
Set<IslEndpoints> segmentEndpoints = new HashSet<>();
framedGraph.traverse(g -> g.V().hasLabel(PathSegmentFrame.FRAME_LABEL).has(PathSegmentFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))).frameExplicit(PathSegmentFrame.class).forEachRemaining(frame -> {
String srcSwitch = frame.getProperty(PathSegmentFrame.SRC_SWITCH_ID_PROPERTY);
String dstSwitch = frame.getProperty(PathSegmentFrame.DST_SWITCH_ID_PROPERTY);
segmentEndpoints.add(new IslEndpoints(srcSwitch, frame.getSrcPort(), dstSwitch, frame.getDestPort()));
});
Map<IslEndpoints, Long> updatedEndpoints = new HashMap<>();
segmentEndpoints.forEach(endpoint -> {
long usedBandwidth = flowPathRepository.getUsedBandwidthBetweenEndpoints(framedGraph, endpoint.getSrcSwitch(), endpoint.getSrcPort(), endpoint.getDestSwitch(), endpoint.getDestPort());
long updatedAvailableBandwidth = updateAvailableBandwidth(framedGraph, endpoint.getSrcSwitch(), endpoint.getSrcPort(), endpoint.getDestSwitch(), endpoint.getDestPort(), usedBandwidth);
updatedEndpoints.put(endpoint, updatedAvailableBandwidth);
});
return updatedEndpoints;
}
use of com.syncleus.ferma.FramedGraph in project open-kilda by telstra.
the class FermaIslRepository method updateAvailableBandwidth.
@Override
public long updateAvailableBandwidth(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort) {
FramedGraph framedGraph = framedGraph();
String srcSwitchIdAsStr = SwitchIdConverter.INSTANCE.toGraphProperty(srcSwitchId);
String dstSwitchIdAsStr = SwitchIdConverter.INSTANCE.toGraphProperty(dstSwitchId);
long usedBandwidth = flowPathRepository.getUsedBandwidthBetweenEndpoints(framedGraph, srcSwitchIdAsStr, srcPort, dstSwitchIdAsStr, dstPort);
return updateAvailableBandwidth(framedGraph, srcSwitchIdAsStr, srcPort, dstSwitchIdAsStr, dstPort, usedBandwidth);
}
use of com.syncleus.ferma.FramedGraph in project open-kilda by telstra.
the class DatabaseSupportImpl method getPaths.
/**
* Get all possible paths between source and destination switches.
*
* @param src source switch ID
* @param dst destination switch ID
* @return list of PathInfoData objects
*/
@Override
@SuppressWarnings("unchecked")
public List<PathInfoData> getPaths(SwitchId src, SwitchId dst) {
return transactionManager.doInTransaction(() -> {
FramedGraph framedGraph = getGraph();
GraphTraversal<?, ?> rawTraversal = framedGraph.traverse(input -> input.V().hasLabel(SwitchFrame.FRAME_LABEL).has(SwitchFrame.SWITCH_ID_PROPERTY, src.toString()).repeat(__.outE(IslFrame.FRAME_LABEL).has(IslFrame.STATUS_PROPERTY, "active").inV().hasLabel(SwitchFrame.FRAME_LABEL).simplePath()).until(__.has(SwitchFrame.SWITCH_ID_PROPERTY, dst.toString()).or().loops().is(DEFAULT_DEPTH)).has(SwitchFrame.SWITCH_ID_PROPERTY, dst.toString()).path()).getRawTraversal();
List<PathInfoData> deserializedResults = new ArrayList<>();
while (rawTraversal.hasNext()) {
ImmutablePath tpPath = (ImmutablePath) rawTraversal.next();
List<PathNode> resultPath = new ArrayList<>();
int seqId = 0;
for (Object hop : tpPath) {
if (hop instanceof Edge) {
Edge edge = (Edge) hop;
Vertex srcVertex = edge.outVertex();
resultPath.add(new PathNode(new SwitchId((String) srcVertex.property(SwitchFrame.SWITCH_ID_PROPERTY).value()), (Integer) edge.property(IslFrame.SRC_PORT_PROPERTY).value(), seqId++, (Long) edge.property(IslFrame.LATENCY_PROPERTY).value()));
Vertex dstVertex = edge.inVertex();
resultPath.add(new PathNode(new SwitchId((String) dstVertex.property(SwitchFrame.SWITCH_ID_PROPERTY).value()), (Integer) edge.property(IslFrame.DST_PORT_PROPERTY).value(), seqId++, (Long) edge.property(IslFrame.LATENCY_PROPERTY).value()));
}
}
deserializedResults.add(new PathInfoData(0, resultPath));
}
return deserializedResults;
});
}
Aggregations