use of org.openkilda.model.PathSegment in project open-kilda by telstra.
the class AvailableNetworkTest method buildPathWithSegment.
private PathSegment buildPathWithSegment(SwitchId srcDpid, SwitchId dstDpid, int srcPort, int dstPort, String srcPop, String dstPop, int seqId) {
Switch srcSwitch = Switch.builder().switchId(srcDpid).pop(srcPop).build();
Switch dstSwitch = Switch.builder().switchId(dstDpid).pop(dstPop).build();
PathId pathId = new PathId(UUID.randomUUID().toString());
FlowPath flowPath = FlowPath.builder().pathId(pathId).srcSwitch(srcSwitch).destSwitch(dstSwitch).segments(IntStream.rangeClosed(0, seqId).mapToObj(i -> PathSegment.builder().pathId(pathId).srcSwitch(srcSwitch).destSwitch(dstSwitch).srcPort(srcPort).destPort(dstPort).build()).collect(toList())).build();
return flowPath.getSegments().get(seqId);
}
use of org.openkilda.model.PathSegment in project open-kilda by telstra.
the class InMemoryPathComputerBaseTest method buildFlowPath.
private FlowPath buildFlowPath(String pathIdAsString, int... ids) {
PathId pathId = new PathId(pathIdAsString);
List<PathSegment> segments = new ArrayList<>();
for (int i = 1; i < ids.length; i++) {
segments.add(PathSegment.builder().pathId(pathId).srcSwitch(Switch.builder().switchId(new SwitchId(ids[i - 1])).build()).destSwitch(Switch.builder().switchId(new SwitchId(ids[i])).build()).build());
}
return FlowPath.builder().pathId(pathId).srcSwitch(Switch.builder().switchId(new SwitchId(ids[0])).build()).destSwitch(Switch.builder().switchId(new SwitchId(ids[ids.length - 1])).build()).segments(segments).build();
}
use of org.openkilda.model.PathSegment in project open-kilda by telstra.
the class FermaPathSegmentRepository method updateFailedStatus.
@Override
@TransactionRequired
public void updateFailedStatus(FlowPath path, PathSegment segment, boolean failed) {
PathSegment segmentToUpdate;
if (segment.getData() instanceof PathSegmentFrame) {
segmentToUpdate = segment;
} else {
segmentToUpdate = path.getSegments().stream().filter(pathSegment -> pathSegment.getSrcSwitchId().equals(segment.getSrcSwitchId()) && pathSegment.getSrcPort() == segment.getSrcPort() && pathSegment.getDestSwitchId().equals(segment.getDestSwitchId()) && pathSegment.getDestPort() == segment.getDestPort()).findAny().orElse(null);
}
if (segmentToUpdate == null) {
throw new PersistenceException(format("PathSegment not found to be updated: %s_%d - %s_%d. Path id: %s.", segment.getSrcSwitchId(), segment.getSrcPort(), segment.getDestSwitchId(), segment.getDestPort(), path.getPathId()));
}
segmentToUpdate.setFailed(failed);
}
use of org.openkilda.model.PathSegment in project open-kilda by telstra.
the class FlowMirrorPathFrame method setSegments.
@Override
public void setSegments(List<PathSegment> segments) {
getElement().edges(Direction.OUT, OWNS_SEGMENTS_EDGE).forEachRemaining(edge -> {
edge.inVertex().remove();
edge.remove();
});
PathId pathId = getPathId();
for (int idx = 0; idx < segments.size(); idx++) {
PathSegment segment = segments.get(idx);
PathSegment.PathSegmentData data = segment.getData();
data.setPathId(pathId);
data.setSeqId(idx);
PathSegmentFrame frame;
if (data instanceof PathSegmentFrame) {
frame = (PathSegmentFrame) data;
// Unlink the path from the previous owner.
frame.getElement().edges(Direction.IN, OWNS_SEGMENTS_EDGE).forEachRemaining(Edge::remove);
} else {
frame = PathSegmentFrame.create(getGraph(), data);
}
linkOut(frame, OWNS_SEGMENTS_EDGE);
}
// force to reload
this.segments = null;
}
use of org.openkilda.model.PathSegment in project open-kilda by telstra.
the class FlowPathFrame method setSegments.
@Override
public void setSegments(List<PathSegment> segments) {
getElement().edges(Direction.OUT, OWNS_SEGMENTS_EDGE).forEachRemaining(edge -> {
edge.inVertex().remove();
edge.remove();
});
PathId pathId = getPathId();
for (int idx = 0; idx < segments.size(); idx++) {
PathSegment segment = segments.get(idx);
PathSegment.PathSegmentData data = segment.getData();
data.setPathId(pathId);
data.setSeqId(idx);
PathSegmentFrame frame;
if (data instanceof PathSegmentFrame) {
frame = (PathSegmentFrame) data;
// Unlink the path from the previous owner.
frame.getElement().edges(Direction.IN, OWNS_SEGMENTS_EDGE).forEachRemaining(Edge::remove);
} else {
frame = PathSegmentFrame.create(getGraph(), data);
}
linkOut(frame, OWNS_SEGMENTS_EDGE);
}
// force to reload
this.segments = null;
}
Aggregations