Search in sources :

Example 26 with PathId

use of org.openkilda.model.PathId 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;
}
Also used : PathId(org.openkilda.model.PathId) PathSegment(org.openkilda.model.PathSegment) Edge(org.apache.tinkerpop.gremlin.structure.Edge)

Example 27 with PathId

use of org.openkilda.model.PathId 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;
}
Also used : PathId(org.openkilda.model.PathId) PathSegment(org.openkilda.model.PathSegment) Edge(org.apache.tinkerpop.gremlin.structure.Edge)

Example 28 with PathId

use of org.openkilda.model.PathId in project open-kilda by telstra.

the class FlowMirrorPointsFrame method getMirrorGroup.

@Override
public MirrorGroup getMirrorGroup() {
    if (mirrorGroup == null) {
        List<? extends MirrorGroupFrame> mirrorGroupFrames = traverse(v -> v.out(HAS_MIRROR_GROUP_EDGE).hasLabel(MirrorGroupFrame.FRAME_LABEL)).toListExplicit(MirrorGroupFrame.class);
        if (!mirrorGroupFrames.isEmpty()) {
            mirrorGroup = new MirrorGroup((mirrorGroupFrames.get(0)));
            if (!Objects.equals(getMirrorGroupId(), mirrorGroup.getGroupId())) {
                throw new IllegalStateException(format("The flow mirror points %s has inconsistent mirror group %s / %s", getId(), getMirrorGroupId(), mirrorGroup.getGroupId()));
            }
        } else {
            String switchId = getProperty(MIRROR_SWITCH_ID_PROPERTY);
            String pathId = getProperty(FLOW_PATH_ID_PROPERTY);
            log.warn("Fallback to find the mirror group by a reference instead of an edge. " + "The switch {}, the vertex {}", switchId, this);
            mirrorGroup = MirrorGroupFrame.load(getGraph(), switchId, pathId).map(MirrorGroup::new).orElse(null);
        }
    }
    return mirrorGroup;
}
Also used : GroupIdConverter(org.openkilda.persistence.ferma.frames.converters.GroupIdConverter) FlowPath(org.openkilda.model.FlowPath) FlowMirrorPointsData(org.openkilda.model.FlowMirrorPoints.FlowMirrorPointsData) SwitchIdConverter(org.openkilda.persistence.ferma.frames.converters.SwitchIdConverter) Convert(org.openkilda.persistence.ferma.frames.converters.Convert) MirrorGroup(org.openkilda.model.MirrorGroup) Map(java.util.Map) PathId(org.openkilda.model.PathId) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Switch(org.openkilda.model.Switch) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) Direction(org.apache.tinkerpop.gremlin.structure.Direction) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) Property(com.syncleus.ferma.annotations.Property) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) Optional(java.util.Optional) VertexFrame(com.syncleus.ferma.VertexFrame) GroupId(org.openkilda.model.GroupId) PathIdConverter(org.openkilda.persistence.ferma.frames.converters.PathIdConverter) Collections(java.util.Collections) MirrorGroup(org.openkilda.model.MirrorGroup)

Example 29 with PathId

use of org.openkilda.model.PathId in project open-kilda by telstra.

the class FlowMirrorPointsFrame method getFlowPath.

@Override
public FlowPath getFlowPath() {
    if (flowPath == null) {
        List<? extends FlowPathFrame> flowFrames = traverse(v -> v.in(FlowPathFrame.HAS_SEGMENTS_EDGE).hasLabel(FlowPathFrame.FRAME_LABEL)).toListExplicit(FlowPathFrame.class);
        flowPath = !flowFrames.isEmpty() ? new FlowPath(flowFrames.get(0)) : null;
        PathId pathId = flowPath != null ? flowPath.getPathId() : null;
        if (!Objects.equals(getFlowPathId(), pathId)) {
            throw new IllegalStateException(format("The flow mirror points %s has inconsistent flow_path_id %s / %s", getId(), getFlowPathId(), pathId));
        }
    }
    return flowPath;
}
Also used : GroupIdConverter(org.openkilda.persistence.ferma.frames.converters.GroupIdConverter) FlowPath(org.openkilda.model.FlowPath) FlowMirrorPointsData(org.openkilda.model.FlowMirrorPoints.FlowMirrorPointsData) SwitchIdConverter(org.openkilda.persistence.ferma.frames.converters.SwitchIdConverter) Convert(org.openkilda.persistence.ferma.frames.converters.Convert) MirrorGroup(org.openkilda.model.MirrorGroup) Map(java.util.Map) PathId(org.openkilda.model.PathId) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Switch(org.openkilda.model.Switch) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) Direction(org.apache.tinkerpop.gremlin.structure.Direction) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) Property(com.syncleus.ferma.annotations.Property) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) Optional(java.util.Optional) VertexFrame(com.syncleus.ferma.VertexFrame) GroupId(org.openkilda.model.GroupId) PathIdConverter(org.openkilda.persistence.ferma.frames.converters.PathIdConverter) Collections(java.util.Collections) PathId(org.openkilda.model.PathId) FlowPath(org.openkilda.model.FlowPath)

Example 30 with PathId

use of org.openkilda.model.PathId in project open-kilda by telstra.

the class FermaFlowPathRepositoryTest method buildTestProtectedFlow.

private Flow buildTestProtectedFlow(String flowId, Switch srcSwitch, int srcPort, int srcVlan, Switch destSwitch, int destPort, int destVlan) {
    Flow flow = buildTestFlow(flowId, srcSwitch, srcPort, srcVlan, destSwitch, destPort, destVlan);
    FlowPath forwardProtectedFlowPath = FlowPath.builder().pathId(new PathId(flowId + "_forward_protected_path")).cookie(new FlowSegmentCookie(FlowPathDirection.FORWARD, 2L)).srcSwitch(srcSwitch).destSwitch(destSwitch).status(FlowPathStatus.ACTIVE).build();
    flow.setProtectedForwardPath(forwardProtectedFlowPath);
    PathSegment forwardSegment = PathSegment.builder().pathId(forwardProtectedFlowPath.getPathId()).srcSwitch(srcSwitch).srcPort(srcPort).destSwitch(destSwitch).destPort(destPort).build();
    forwardProtectedFlowPath.setSegments(Collections.singletonList(forwardSegment));
    FlowPath reverseProtectedFlowPath = FlowPath.builder().pathId(new PathId(flowId + "_reverse_protected_path")).cookie(new FlowSegmentCookie(FlowPathDirection.REVERSE, 2L)).srcSwitch(destSwitch).destSwitch(srcSwitch).status(FlowPathStatus.ACTIVE).build();
    flow.setProtectedReversePath(reverseProtectedFlowPath);
    PathSegment reverseSegment = PathSegment.builder().pathId(reverseProtectedFlowPath.getPathId()).srcSwitch(destSwitch).srcPort(destPort).destSwitch(srcSwitch).destPort(srcPort).build();
    reverseProtectedFlowPath.setSegments(Collections.singletonList(reverseSegment));
    return flow;
}
Also used : PathId(org.openkilda.model.PathId) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow)

Aggregations

PathId (org.openkilda.model.PathId)124 Flow (org.openkilda.model.Flow)65 FlowPath (org.openkilda.model.FlowPath)65 Test (org.junit.Test)44 Switch (org.openkilda.model.Switch)29 SwitchId (org.openkilda.model.SwitchId)28 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)27 PathSegment (org.openkilda.model.PathSegment)26 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)21 MeterId (org.openkilda.model.MeterId)19 ArrayList (java.util.ArrayList)18 List (java.util.List)13 Slf4j (lombok.extern.slf4j.Slf4j)11 GetPathsResult (org.openkilda.pce.GetPathsResult)11 FlowMirrorPoints (org.openkilda.model.FlowMirrorPoints)10 Path (org.openkilda.pce.Path)10 Collection (java.util.Collection)9 RecoverableException (org.openkilda.pce.exception.RecoverableException)9 String.format (java.lang.String.format)8 HashMap (java.util.HashMap)8