Search in sources :

Example 11 with PathSegment

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);
}
Also used : PathId(org.openkilda.model.PathId) IntStream(java.util.stream.IntStream) PathWeight(org.openkilda.pce.model.PathWeight) Switch(org.openkilda.model.Switch) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) Matchers(org.hamcrest.Matchers) Set(java.util.Set) Test(org.junit.Test) UUID(java.util.UUID) Collections.singletonList(java.util.Collections.singletonList) WeightFunction(org.openkilda.pce.model.WeightFunction) Assert.assertThat(org.junit.Assert.assertThat) Collectors.toList(java.util.stream.Collectors.toList) Edge(org.openkilda.pce.model.Edge) Flow(org.openkilda.model.Flow) SwitchId(org.openkilda.model.SwitchId) Arrays.asList(java.util.Arrays.asList) Node(org.openkilda.pce.model.Node) Assert.assertEquals(org.junit.Assert.assertEquals) PathId(org.openkilda.model.PathId) Switch(org.openkilda.model.Switch) FlowPath(org.openkilda.model.FlowPath)

Example 12 with PathSegment

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();
}
Also used : PathId(org.openkilda.model.PathId) ArrayList(java.util.ArrayList) SwitchId(org.openkilda.model.SwitchId) PathSegment(org.openkilda.model.PathSegment)

Example 13 with PathSegment

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);
}
Also used : PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) TransactionRequired(org.openkilda.persistence.tx.TransactionRequired) PathSegmentData(org.openkilda.model.PathSegment.PathSegmentData) PathSegmentFrame(org.openkilda.persistence.ferma.frames.PathSegmentFrame) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) FermaPersistentImplementation(org.openkilda.persistence.ferma.FermaPersistentImplementation) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) List(java.util.List) PathSegmentRepository(org.openkilda.persistence.repositories.PathSegmentRepository) IslRepository(org.openkilda.persistence.repositories.IslRepository) Optional(java.util.Optional) Comparator(java.util.Comparator) PathIdConverter(org.openkilda.persistence.ferma.frames.converters.PathIdConverter) PathId(org.openkilda.model.PathId) PathSegmentFrame(org.openkilda.persistence.ferma.frames.PathSegmentFrame) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) PathSegment(org.openkilda.model.PathSegment) TransactionRequired(org.openkilda.persistence.tx.TransactionRequired)

Example 14 with PathSegment

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

Example 15 with PathSegment

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

Aggregations

PathSegment (org.openkilda.model.PathSegment)73 FlowPath (org.openkilda.model.FlowPath)40 ArrayList (java.util.ArrayList)28 Flow (org.openkilda.model.Flow)26 PathId (org.openkilda.model.PathId)24 SwitchId (org.openkilda.model.SwitchId)18 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)17 FlowEndpoint (org.openkilda.model.FlowEndpoint)12 Test (org.junit.Test)11 List (java.util.List)9 MeterId (org.openkilda.model.MeterId)9 Switch (org.openkilda.model.Switch)9 YFlow (org.openkilda.model.YFlow)8 PersistenceManager (org.openkilda.persistence.PersistenceManager)7 Optional (java.util.Optional)6 Slf4j (lombok.extern.slf4j.Slf4j)6 VisibleForTesting (com.google.common.annotations.VisibleForTesting)5 Set (java.util.Set)5 Collectors (java.util.stream.Collectors)5 PathInfoData (org.openkilda.messaging.info.event.PathInfoData)5