Search in sources :

Example 61 with SwitchId

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

the class LatencyPathComputationStrategyBaseTest method shouldFindPathOverTriangleByLatency.

@Test
public void shouldFindPathOverTriangleByLatency() throws UnroutableFlowException, RecoverableException {
    /*
         * should choose longer (in hops) but low latency path
         */
    createTriangleTopo(IslStatus.ACTIVE, 10, 10, "00:", 1);
    Switch srcSwitch = getSwitchById("00:01");
    Switch destSwitch = getSwitchById("00:02");
    Flow flow = new TestFlowBuilder().srcSwitch(srcSwitch).destSwitch(destSwitch).bandwidth(100).pathComputationStrategy(PathComputationStrategy.LATENCY).build();
    PathComputer pathComputer = pathComputerFactory.getPathComputer();
    GetPathsResult path = pathComputer.getPath(flow);
    assertNotNull(path);
    assertThat(path.getForward().getSegments(), Matchers.hasSize(2));
    // it should now have C as first hop since A - B segment has high latency
    assertEquals(new SwitchId("00:03"), path.getForward().getSegments().get(0).getDestSwitchId());
}
Also used : PathComputer(org.openkilda.pce.PathComputer) Switch(org.openkilda.model.Switch) SwitchId(org.openkilda.model.SwitchId) Flow(org.openkilda.model.Flow) GetPathsResult(org.openkilda.pce.GetPathsResult) Test(org.junit.Test)

Example 62 with SwitchId

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

the class FermaMirrorGroupRepository method exists.

@Override
public boolean exists(SwitchId switchId, GroupId groupId) {
    String switchIdAsStr = SwitchIdConverter.INSTANCE.toGraphProperty(switchId);
    Long groupIdAsLong = GroupIdConverter.INSTANCE.toGraphProperty(groupId);
    try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V().hasLabel(FlowMeterFrame.FRAME_LABEL).has(MirrorGroupFrame.GROUP_ID_PROPERTY, groupIdAsLong).has(MirrorGroupFrame.SWITCH_ID_PROPERTY, switchIdAsStr)).getRawTraversal()) {
        return traversal.hasNext();
    } catch (Exception e) {
        throw new PersistenceException("Failed to traverse", e);
    }
}
Also used : GroupIdConverter(org.openkilda.persistence.ferma.frames.converters.GroupIdConverter) Collection(java.util.Collection) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) FermaPersistentImplementation(org.openkilda.persistence.ferma.FermaPersistentImplementation) SwitchIdConverter(org.openkilda.persistence.ferma.frames.converters.SwitchIdConverter) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Collectors(java.util.stream.Collectors) MirrorGroupData(org.openkilda.model.MirrorGroup.MirrorGroupData) MirrorGroupRepository(org.openkilda.persistence.repositories.MirrorGroupRepository) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) MirrorGroup(org.openkilda.model.MirrorGroup) MirrorGroupFrame(org.openkilda.persistence.ferma.frames.MirrorGroupFrame) Optional(java.util.Optional) FlowMeterFrame(org.openkilda.persistence.ferma.frames.FlowMeterFrame) KildaBaseVertexFrame(org.openkilda.persistence.ferma.frames.KildaBaseVertexFrame) GroupId(org.openkilda.model.GroupId) PathIdConverter(org.openkilda.persistence.ferma.frames.converters.PathIdConverter) PathId(org.openkilda.model.PathId) P(org.apache.tinkerpop.gremlin.process.traversal.P) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException)

Example 63 with SwitchId

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

the class FlowFrame method getSrcSwitch.

@Override
public Switch getSrcSwitch() {
    if (srcSwitch == null) {
        List<? extends SwitchFrame> switchFrames = traverse(v -> v.out(SOURCE_EDGE).hasLabel(SwitchFrame.FRAME_LABEL)).toListExplicit(SwitchFrame.class);
        if (!switchFrames.isEmpty()) {
            srcSwitch = new Switch((switchFrames.get(0)));
            if (!Objects.equals(getSrcSwitchId(), srcSwitch.getSwitchId())) {
                throw new IllegalStateException(format("The flow %s has inconsistent source switch %s / %s", getId(), getSrcSwitchId(), srcSwitch.getSwitchId()));
            }
        } else {
            String switchId = getProperty(SRC_SWITCH_ID_PROPERTY);
            log.warn("Fallback to find the source switch by a reference instead of an edge. " + "The switch {}, the vertex {}", switchId, this);
            srcSwitch = SwitchFrame.load(getGraph(), switchId).map(Switch::new).orElse(null);
        }
    }
    return srcSwitch;
}
Also used : FlowData(org.openkilda.model.Flow.FlowData) FlowPath(org.openkilda.model.FlowPath) FlowStatus(org.openkilda.model.FlowStatus) FlowEncapsulationTypeConverter(org.openkilda.persistence.ferma.frames.converters.FlowEncapsulationTypeConverter) SwitchIdConverter(org.openkilda.persistence.ferma.frames.converters.SwitchIdConverter) PathComputationStrategyConverter(org.openkilda.persistence.ferma.frames.converters.PathComputationStrategyConverter) Convert(org.openkilda.persistence.ferma.frames.converters.Convert) Map(java.util.Map) YFlow(org.openkilda.model.YFlow) PathId(org.openkilda.model.PathId) DetectConnectedDevices(org.openkilda.model.DetectConnectedDevices) Edge(org.apache.tinkerpop.gremlin.structure.Edge) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) Switch(org.openkilda.model.Switch) PathComputationStrategy(org.openkilda.model.PathComputationStrategy) Collection(java.util.Collection) Set(java.util.Set) FlowStatusConverter(org.openkilda.persistence.ferma.frames.converters.FlowStatusConverter) 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) FramedGraph(com.syncleus.ferma.FramedGraph) Optional(java.util.Optional) VertexFrame(com.syncleus.ferma.VertexFrame) PathIdConverter(org.openkilda.persistence.ferma.frames.converters.PathIdConverter) Collections(java.util.Collections) Switch(org.openkilda.model.Switch)

Example 64 with SwitchId

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

the class IslFrame method getDestSwitch.

@Override
public Switch getDestSwitch() {
    if (destSwitch == null) {
        List<? extends SwitchFrame> switchFrames = traverse(e -> e.inV().hasLabel(SwitchFrame.FRAME_LABEL)).toListExplicit(SwitchFrame.class);
        destSwitch = !switchFrames.isEmpty() ? new Switch((switchFrames.get(0))) : null;
        SwitchId switchId = destSwitch != null ? destSwitch.getSwitchId() : null;
        if (!Objects.equals(getDestSwitchId(), switchId)) {
            throw new IllegalStateException(format("The isl %s has inconsistent dest switch %s / %s", getId(), getDestSwitchId(), switchId));
        }
    }
    return destSwitch;
}
Also used : BfdSessionStatusConverter(org.openkilda.persistence.ferma.frames.converters.BfdSessionStatusConverter) Switch(org.openkilda.model.Switch) IslDownReason(org.openkilda.model.IslDownReason) IslStatus(org.openkilda.model.IslStatus) Instant(java.time.Instant) SwitchIdConverter(org.openkilda.persistence.ferma.frames.converters.SwitchIdConverter) String.format(java.lang.String.format) BfdSessionStatus(org.openkilda.model.BfdSessionStatus) Objects(java.util.Objects) IslDownReasonConverter(org.openkilda.persistence.ferma.frames.converters.IslDownReasonConverter) IslStatusConverter(org.openkilda.persistence.ferma.frames.converters.IslStatusConverter) List(java.util.List) Convert(org.openkilda.persistence.ferma.frames.converters.Convert) IslData(org.openkilda.model.Isl.IslData) SwitchId(org.openkilda.model.SwitchId) InstantStringConverter(org.openkilda.persistence.ferma.frames.converters.InstantStringConverter) Property(com.syncleus.ferma.annotations.Property) DurationConverter(org.openkilda.persistence.ferma.frames.converters.DurationConverter) Duration(java.time.Duration) Switch(org.openkilda.model.Switch) SwitchId(org.openkilda.model.SwitchId)

Example 65 with SwitchId

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

the class IslFrame method getSrcSwitch.

@Override
public Switch getSrcSwitch() {
    if (srcSwitch == null) {
        List<? extends SwitchFrame> switchFrames = traverse(e -> e.outV().hasLabel(SwitchFrame.FRAME_LABEL)).toListExplicit(SwitchFrame.class);
        srcSwitch = !switchFrames.isEmpty() ? new Switch((switchFrames.get(0))) : null;
        SwitchId switchId = srcSwitch != null ? srcSwitch.getSwitchId() : null;
        if (!Objects.equals(getSrcSwitchId(), switchId)) {
            throw new IllegalStateException(format("The isl %s has inconsistent source switch %s / %s", getId(), getSrcSwitchId(), switchId));
        }
    }
    return srcSwitch;
}
Also used : BfdSessionStatusConverter(org.openkilda.persistence.ferma.frames.converters.BfdSessionStatusConverter) Switch(org.openkilda.model.Switch) IslDownReason(org.openkilda.model.IslDownReason) IslStatus(org.openkilda.model.IslStatus) Instant(java.time.Instant) SwitchIdConverter(org.openkilda.persistence.ferma.frames.converters.SwitchIdConverter) String.format(java.lang.String.format) BfdSessionStatus(org.openkilda.model.BfdSessionStatus) Objects(java.util.Objects) IslDownReasonConverter(org.openkilda.persistence.ferma.frames.converters.IslDownReasonConverter) IslStatusConverter(org.openkilda.persistence.ferma.frames.converters.IslStatusConverter) List(java.util.List) Convert(org.openkilda.persistence.ferma.frames.converters.Convert) IslData(org.openkilda.model.Isl.IslData) SwitchId(org.openkilda.model.SwitchId) InstantStringConverter(org.openkilda.persistence.ferma.frames.converters.InstantStringConverter) Property(com.syncleus.ferma.annotations.Property) DurationConverter(org.openkilda.persistence.ferma.frames.converters.DurationConverter) Duration(java.time.Duration) Switch(org.openkilda.model.Switch) SwitchId(org.openkilda.model.SwitchId)

Aggregations

SwitchId (org.openkilda.model.SwitchId)339 Test (org.junit.Test)149 Flow (org.openkilda.model.Flow)73 Switch (org.openkilda.model.Switch)69 List (java.util.List)59 FlowPath (org.openkilda.model.FlowPath)49 ArrayList (java.util.ArrayList)44 Collectors (java.util.stream.Collectors)37 PathId (org.openkilda.model.PathId)36 PathComputer (org.openkilda.pce.PathComputer)35 Set (java.util.Set)34 YFlow (org.openkilda.model.YFlow)33 Map (java.util.Map)30 GetPathsResult (org.openkilda.pce.GetPathsResult)30 InfoMessage (org.openkilda.messaging.info.InfoMessage)29 String.format (java.lang.String.format)28 HashSet (java.util.HashSet)27 Optional (java.util.Optional)27 Collection (java.util.Collection)26 Collections (java.util.Collections)26