Search in sources :

Example 6 with MeterId

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

the class FlowValidationTestBase method buildFlow.

protected void buildFlow(FlowEncapsulationType flowEncapsulationType, String endpointSwitchManufacturer) {
    Switch switchA = Switch.builder().switchId(TEST_SWITCH_ID_A).description("").build();
    switchRepository.add(switchA);
    switchA.setOfDescriptionManufacturer(endpointSwitchManufacturer);
    Switch switchB = Switch.builder().switchId(TEST_SWITCH_ID_B).description("").build();
    switchRepository.add(switchB);
    Switch switchC = Switch.builder().switchId(TEST_SWITCH_ID_C).description("").build();
    switchRepository.add(switchC);
    Switch switchE = Switch.builder().switchId(TEST_SWITCH_ID_E).description("").build();
    switchRepository.add(switchE);
    Flow flow = Flow.builder().flowId(TEST_FLOW_ID_A).srcSwitch(switchA).srcPort(FLOW_A_SRC_PORT).srcVlan(FLOW_A_SRC_VLAN).destSwitch(switchC).destPort(FLOW_A_DST_PORT).destVlan(FLOW_A_DST_VLAN).allocateProtectedPath(true).encapsulationType(flowEncapsulationType).bandwidth(FLOW_A_BANDWIDTH).status(FlowStatus.UP).build();
    FlowPath forwardFlowPath = FlowPath.builder().pathId(FLOW_A_FORWARD_PATH_ID).cookie(new FlowSegmentCookie(FLOW_A_FORWARD_COOKIE)).meterId(new MeterId(FLOW_A_FORWARD_METER_ID)).srcSwitch(switchA).destSwitch(switchC).bandwidth(FLOW_A_BANDWIDTH).status(FlowPathStatus.ACTIVE).build();
    flow.setForwardPath(forwardFlowPath);
    PathSegment forwardSegmentA = PathSegment.builder().pathId(forwardFlowPath.getPathId()).srcSwitch(switchA).srcPort(FLOW_A_SEGMENT_A_SRC_PORT).destSwitch(switchB).destPort(FLOW_A_SEGMENT_A_DST_PORT).build();
    PathSegment forwardSegmentB = PathSegment.builder().pathId(forwardFlowPath.getPathId()).srcSwitch(switchB).srcPort(FLOW_A_SEGMENT_B_SRC_PORT).destSwitch(switchC).destPort(FLOW_A_SEGMENT_B_DST_PORT).build();
    forwardFlowPath.setSegments(Lists.newArrayList(forwardSegmentA, forwardSegmentB));
    FlowPath forwardProtectedFlowPath = FlowPath.builder().pathId(FLOW_A_FORWARD_PATH_ID_PROTECTED).cookie(new FlowSegmentCookie(FLOW_A_FORWARD_COOKIE_PROTECTED)).meterId(new MeterId(FLOW_A_FORWARD_METER_ID_PROTECTED)).srcSwitch(switchA).destSwitch(switchC).bandwidth(FLOW_A_BANDWIDTH).status(FlowPathStatus.ACTIVE).build();
    flow.setProtectedForwardPath(forwardProtectedFlowPath);
    PathSegment forwardProtectedSegmentA = PathSegment.builder().pathId(forwardProtectedFlowPath.getPathId()).srcSwitch(switchA).srcPort(FLOW_A_SEGMENT_A_SRC_PORT_PROTECTED).destSwitch(switchE).destPort(FLOW_A_SEGMENT_A_DST_PORT_PROTECTED).build();
    PathSegment forwardProtectedSegmentB = PathSegment.builder().pathId(forwardProtectedFlowPath.getPathId()).srcSwitch(switchE).srcPort(FLOW_A_SEGMENT_B_SRC_PORT_PROTECTED).destSwitch(switchC).destPort(FLOW_A_SEGMENT_B_DST_PORT_PROTECTED).build();
    forwardProtectedFlowPath.setSegments(Lists.newArrayList(forwardProtectedSegmentA, forwardProtectedSegmentB));
    FlowPath reverseFlowPath = FlowPath.builder().pathId(FLOW_A_REVERSE_PATH_ID).cookie(new FlowSegmentCookie(FLOW_A_REVERSE_COOKIE)).meterId(new MeterId(FLOW_A_REVERSE_METER_ID)).srcSwitch(switchC).destSwitch(switchA).bandwidth(FLOW_A_BANDWIDTH).status(FlowPathStatus.ACTIVE).build();
    flow.setReversePath(reverseFlowPath);
    PathSegment reverseSegmentA = PathSegment.builder().pathId(reverseFlowPath.getPathId()).srcSwitch(switchC).srcPort(FLOW_A_SEGMENT_B_DST_PORT).destSwitch(switchB).destPort(FLOW_A_SEGMENT_B_SRC_PORT).build();
    PathSegment reverseSegmentB = PathSegment.builder().pathId(reverseFlowPath.getPathId()).srcSwitch(switchB).srcPort(FLOW_A_SEGMENT_A_DST_PORT).destSwitch(switchA).destPort(FLOW_A_SEGMENT_A_SRC_PORT).build();
    reverseFlowPath.setSegments(Lists.newArrayList(reverseSegmentA, reverseSegmentB));
    FlowPath reverseProtectedFlowPath = FlowPath.builder().pathId(FLOW_A_REVERSE_PATH_ID_PROTECTED).cookie(new FlowSegmentCookie(FLOW_A_REVERSE_COOKIE_PROTECTED)).meterId(new MeterId(FLOW_A_REVERSE_METER_ID_PROTECTED)).srcSwitch(switchC).destSwitch(switchA).bandwidth(FLOW_A_BANDWIDTH).status(FlowPathStatus.ACTIVE).build();
    flow.setProtectedReversePath(reverseProtectedFlowPath);
    PathSegment reverseProtectedSegmentA = PathSegment.builder().pathId(reverseProtectedFlowPath.getPathId()).srcSwitch(switchC).srcPort(FLOW_A_SEGMENT_B_DST_PORT_PROTECTED).destSwitch(switchE).destPort(FLOW_A_SEGMENT_B_SRC_PORT_PROTECTED).build();
    PathSegment reverseProtectedSegmentB = PathSegment.builder().pathId(reverseProtectedFlowPath.getPathId()).srcSwitch(switchE).srcPort(FLOW_A_SEGMENT_A_DST_PORT_PROTECTED).destSwitch(switchA).destPort(FLOW_A_SEGMENT_A_SRC_PORT_PROTECTED).build();
    reverseProtectedFlowPath.setSegments(Lists.newArrayList(reverseProtectedSegmentA, reverseProtectedSegmentB));
    flowRepository.add(flow);
}
Also used : FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) Switch(org.openkilda.model.Switch) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow) MeterId(org.openkilda.model.MeterId)

Example 7 with MeterId

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

the class FermaFlowMeterRepository method findFirstUnassignedMeter.

@Override
public Optional<MeterId> findFirstUnassignedMeter(SwitchId switchId, MeterId lowestMeterId, MeterId highestMeterId) {
    String switchIdAsStr = SwitchIdConverter.INSTANCE.toGraphProperty(switchId);
    Long lowestMeterIdAsLong = MeterIdConverter.INSTANCE.toGraphProperty(lowestMeterId);
    Long highestMeterIdAsLong = MeterIdConverter.INSTANCE.toGraphProperty(highestMeterId);
    try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V().hasLabel(FlowMeterFrame.FRAME_LABEL).has(FlowMeterFrame.METER_ID_PROPERTY, P.gte(lowestMeterIdAsLong)).has(FlowMeterFrame.METER_ID_PROPERTY, P.lt(highestMeterIdAsLong)).has(FlowMeterFrame.SWITCH_PROPERTY, switchIdAsStr).values(FlowMeterFrame.METER_ID_PROPERTY).order().math("_ + 1").as("a").where(__.not(__.V().hasLabel(FlowMeterFrame.FRAME_LABEL).has(FlowMeterFrame.SWITCH_PROPERTY, switchIdAsStr).values(FlowMeterFrame.METER_ID_PROPERTY).where(P.eq("a")))).select("a").limit(1)).getRawTraversal()) {
        if (traversal.hasNext()) {
            return traversal.tryNext().map(l -> ((Double) l).longValue()).map(MeterIdConverter.INSTANCE::toEntityAttribute);
        }
    } catch (Exception e) {
        throw new PersistenceException("Failed to traverse", e);
    }
    try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V().hasLabel(FlowMeterFrame.FRAME_LABEL).has(FlowMeterFrame.METER_ID_PROPERTY, lowestMeterIdAsLong).has(FlowMeterFrame.SWITCH_PROPERTY, switchIdAsStr)).getRawTraversal()) {
        if (!traversal.hasNext()) {
            return Optional.of(lowestMeterId);
        }
    } catch (Exception e) {
        throw new PersistenceException("Failed to traverse", e);
    }
    return Optional.empty();
}
Also used : FlowMeter(org.openkilda.model.FlowMeter) Collection(java.util.Collection) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) FlowMeterData(org.openkilda.model.FlowMeter.FlowMeterData) 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) MeterIdConverter(org.openkilda.persistence.ferma.frames.converters.MeterIdConverter) MeterId(org.openkilda.model.MeterId) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) FlowMeterRepository(org.openkilda.persistence.repositories.FlowMeterRepository) Optional(java.util.Optional) FlowMeterFrame(org.openkilda.persistence.ferma.frames.FlowMeterFrame) KildaBaseVertexFrame(org.openkilda.persistence.ferma.frames.KildaBaseVertexFrame) 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 8 with MeterId

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

the class FermaFlowMeterRepository method exists.

@Override
public boolean exists(SwitchId switchId, MeterId meterId) {
    String switchIdAsStr = SwitchIdConverter.INSTANCE.toGraphProperty(switchId);
    Long meterIdAsLong = MeterIdConverter.INSTANCE.toGraphProperty(meterId);
    try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V().hasLabel(FlowMeterFrame.FRAME_LABEL).has(FlowMeterFrame.METER_ID_PROPERTY, meterIdAsLong).has(FlowMeterFrame.SWITCH_PROPERTY, switchIdAsStr)).getRawTraversal()) {
        return traversal.hasNext();
    } catch (Exception e) {
        throw new PersistenceException("Failed to traverse", e);
    }
}
Also used : FlowMeter(org.openkilda.model.FlowMeter) Collection(java.util.Collection) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) FlowMeterData(org.openkilda.model.FlowMeter.FlowMeterData) 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) MeterIdConverter(org.openkilda.persistence.ferma.frames.converters.MeterIdConverter) MeterId(org.openkilda.model.MeterId) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) FlowMeterRepository(org.openkilda.persistence.repositories.FlowMeterRepository) Optional(java.util.Optional) FlowMeterFrame(org.openkilda.persistence.ferma.frames.FlowMeterFrame) KildaBaseVertexFrame(org.openkilda.persistence.ferma.frames.KildaBaseVertexFrame) 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 9 with MeterId

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

the class FermaFlowPathRepositoryTest method buildTestFlow.

private Flow buildTestFlow(String flowId, Switch srcSwitch, int srcPort, int srcVlan, Switch destSwitch, int destPort, int destVlan) {
    Flow flow = Flow.builder().flowId(flowId).srcSwitch(srcSwitch).srcPort(srcPort).srcVlan(srcVlan).destSwitch(destSwitch).destPort(destPort).destVlan(destVlan).encapsulationType(FlowEncapsulationType.TRANSIT_VLAN).status(FlowStatus.UP).build();
    FlowPath forwardFlowPath = FlowPath.builder().pathId(new PathId(flowId + "_forward_path")).cookie(new FlowSegmentCookie(FlowPathDirection.FORWARD, 1L)).meterId(new MeterId(1)).srcSwitch(srcSwitch).destSwitch(destSwitch).status(FlowPathStatus.ACTIVE).build();
    flow.setForwardPath(forwardFlowPath);
    PathSegment forwardSegment = PathSegment.builder().pathId(forwardFlowPath.getPathId()).srcSwitch(srcSwitch).srcPort(srcPort).destSwitch(destSwitch).destPort(destPort).build();
    forwardFlowPath.setSegments(Collections.singletonList(forwardSegment));
    FlowPath reverseFlowPath = FlowPath.builder().pathId(new PathId(flowId + "_reverse_path")).cookie(new FlowSegmentCookie(FlowPathDirection.REVERSE, 1L)).meterId(new MeterId(2)).srcSwitch(destSwitch).destSwitch(srcSwitch).status(FlowPathStatus.ACTIVE).build();
    flow.setReversePath(reverseFlowPath);
    PathSegment reverseSegment = PathSegment.builder().pathId(reverseFlowPath.getPathId()).srcSwitch(destSwitch).srcPort(destPort).destSwitch(srcSwitch).destPort(srcPort).build();
    reverseFlowPath.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) MeterId(org.openkilda.model.MeterId)

Example 10 with MeterId

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

the class MeterIdConverterTest method shouldConvertIdToString.

@Test
public void shouldConvertIdToString() {
    // given
    MeterId meterId = new MeterId(0x123);
    // when
    Long graphObject = MeterIdConverter.INSTANCE.toGraphProperty(meterId);
    // then
    assertEquals(meterId.getValue(), (long) graphObject);
}
Also used : MeterId(org.openkilda.model.MeterId) Test(org.junit.Test)

Aggregations

MeterId (org.openkilda.model.MeterId)62 PathId (org.openkilda.model.PathId)20 Flow (org.openkilda.model.Flow)19 FlowPath (org.openkilda.model.FlowPath)18 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)18 Test (org.junit.Test)17 SwitchId (org.openkilda.model.SwitchId)16 Switch (org.openkilda.model.Switch)11 ArrayList (java.util.ArrayList)10 PathSegment (org.openkilda.model.PathSegment)9 MeterSpeakerData (org.openkilda.rulemanager.MeterSpeakerData)7 List (java.util.List)6 ValidateMetersResult (org.openkilda.wfm.topology.switchmanager.model.ValidateMetersResult)6 FlowMeter (org.openkilda.model.FlowMeter)5 MeterConfig (org.openkilda.model.MeterConfig)5 YFlow (org.openkilda.model.YFlow)5 Instructions (org.openkilda.rulemanager.Instructions)5 PortOutAction (org.openkilda.rulemanager.action.PortOutAction)5 ValidationService (org.openkilda.wfm.topology.switchmanager.service.ValidationService)5 MessageContext (org.openkilda.messaging.MessageContext)4