Search in sources :

Example 11 with FlowPatch

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

the class FlowOperationsServiceTest method shouldPrepareFlowUpdateResultWithChangedStrategy.

@Test
public void shouldPrepareFlowUpdateResultWithChangedStrategy() {
    // given: FlowPatch with COST strategy and Flow with MAX_LATENCY strategy
    String flowId = "test_flow_id";
    FlowPatch flowDto = FlowPatch.builder().flowId(flowId).maxLatency(100L).pathComputationStrategy(PathComputationStrategy.COST).build();
    Flow flow = Flow.builder().flowId(flowId).srcSwitch(Switch.builder().switchId(new SwitchId(1)).build()).destSwitch(Switch.builder().switchId(new SwitchId(2)).build()).pathComputationStrategy(PathComputationStrategy.MAX_LATENCY).build();
    // when: compare this flows
    UpdateFlowResult result = flowOperationsService.prepareFlowUpdateResult(flowDto, flow).build();
    // then: needUpdateFlow flag set to true
    assertTrue(result.isNeedUpdateFlow());
}
Also used : FlowPatch(org.openkilda.messaging.model.FlowPatch) UpdateFlowResult(org.openkilda.wfm.topology.nbworker.services.FlowOperationsService.UpdateFlowResult) SwitchId(org.openkilda.model.SwitchId) Flow(org.openkilda.model.Flow) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 12 with FlowPatch

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

the class FlowOperationsServiceTest method shouldPrepareFlowUpdateResultWithChangedMaxLatencySecondCase.

@Test
public void shouldPrepareFlowUpdateResultWithChangedMaxLatencySecondCase() {
    // given: FlowPatch with max latency and MAX_LATENCY strategy
    // and Flow with MAX_LATENCY strategy and no max latency
    String flowId = "test_flow_id";
    FlowPatch flowDto = FlowPatch.builder().flowId(flowId).maxLatency(100L).pathComputationStrategy(PathComputationStrategy.MAX_LATENCY).build();
    Flow flow = Flow.builder().flowId(flowId).srcSwitch(Switch.builder().switchId(new SwitchId(1)).build()).destSwitch(Switch.builder().switchId(new SwitchId(2)).build()).pathComputationStrategy(PathComputationStrategy.MAX_LATENCY).build();
    // when: compare this flows
    UpdateFlowResult result = flowOperationsService.prepareFlowUpdateResult(flowDto, flow).build();
    // then: needRerouteFlow flag set to true
    assertTrue(result.isNeedUpdateFlow());
}
Also used : FlowPatch(org.openkilda.messaging.model.FlowPatch) UpdateFlowResult(org.openkilda.wfm.topology.nbworker.services.FlowOperationsService.UpdateFlowResult) SwitchId(org.openkilda.model.SwitchId) Flow(org.openkilda.model.Flow) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 13 with FlowPatch

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

the class FlowMapperTest method testFlowPatchV2ToFlowDto.

@Test
public void testFlowPatchV2ToFlowDto() {
    FlowPatchV2 flowPatchDto = new FlowPatchV2(new FlowPatchEndpoint(SRC_SWITCH_ID, SRC_PORT, SRC_VLAN, SRC_INNER_VLAN, SRC_DETECT_CONNECTED_DEVICES), new FlowPatchEndpoint(DST_SWITCH_ID, DST_PORT, DST_VLAN, DST_INNER_VLAN, DST_DETECT_CONNECTED_DEVICES), (long) BANDWIDTH, IGNORE_BANDWIDTH, STRICT_BANDWIDTH, PERIODIC_PINGS, DESCRIPTION, LATENCY, LATENCY_TIER2, PRIORITY, DIVERSE_FLOW_ID, AFFINITY_FLOW_ID, PINNED, ALLOCATE_PROTECTED_PATH, ENCAPSULATION_TYPE, PATH_COMPUTATION_STRATEGY, TARGET_PATH_COMPUTATION_STRATEGY);
    FlowPatch flowPatch = flowMapper.toFlowPatch(flowPatchDto);
    assertEquals(flowPatchDto.getSource().getSwitchId(), flowPatch.getSource().getSwitchId());
    assertEquals(flowPatchDto.getSource().getPortNumber(), flowPatch.getSource().getPortNumber());
    assertEquals(flowPatchDto.getSource().getVlanId(), flowPatch.getSource().getVlanId());
    assertEquals(flowPatchDto.getSource().getInnerVlanId(), flowPatch.getSource().getInnerVlanId());
    assertEquals(flowPatchDto.getSource().getDetectConnectedDevices().isLldp(), flowPatch.getSource().getTrackLldpConnectedDevices());
    assertEquals(flowPatchDto.getSource().getDetectConnectedDevices().isArp(), flowPatch.getSource().getTrackArpConnectedDevices());
    assertEquals(flowPatchDto.getDestination().getSwitchId(), flowPatch.getDestination().getSwitchId());
    assertEquals(flowPatchDto.getDestination().getPortNumber(), flowPatch.getDestination().getPortNumber());
    assertEquals(flowPatchDto.getDestination().getVlanId(), flowPatch.getDestination().getVlanId());
    assertEquals(flowPatchDto.getDestination().getInnerVlanId(), flowPatch.getDestination().getInnerVlanId());
    assertEquals(flowPatchDto.getDestination().getDetectConnectedDevices().isLldp(), flowPatch.getDestination().getTrackLldpConnectedDevices());
    assertEquals(flowPatchDto.getDestination().getDetectConnectedDevices().isArp(), flowPatch.getDestination().getTrackArpConnectedDevices());
    assertEquals(flowPatchDto.getMaxLatency() * MS_TO_NS_MULTIPLIER, (long) flowPatch.getMaxLatency());
    assertEquals(flowPatchDto.getMaxLatencyTier2() * MS_TO_NS_MULTIPLIER, (long) flowPatch.getMaxLatencyTier2());
    assertEquals(flowPatchDto.getPriority(), flowPatch.getPriority());
    assertEquals(flowPatchDto.getPeriodicPings(), flowPatch.getPeriodicPings());
    assertEquals(flowPatchDto.getTargetPathComputationStrategy(), flowPatch.getTargetPathComputationStrategy().name().toLowerCase());
    assertEquals(flowPatchDto.getDiverseFlowId(), flowPatch.getDiverseFlowId());
    assertEquals(flowPatchDto.getAffinityFlowId(), flowPatch.getAffinityFlowId());
    assertEquals(flowPatchDto.getMaximumBandwidth(), flowPatch.getBandwidth());
    assertEquals(flowPatchDto.getAllocateProtectedPath(), flowPatch.getAllocateProtectedPath());
    assertEquals(flowPatchDto.getPinned(), flowPatch.getPinned());
    assertEquals(flowPatchDto.getIgnoreBandwidth(), flowPatch.getIgnoreBandwidth());
    assertEquals(flowPatchDto.getStrictBandwidth(), flowPatch.getStrictBandwidth());
    assertEquals(flowPatchDto.getDescription(), flowPatch.getDescription());
    assertEquals(flowPatchDto.getEncapsulationType(), flowPatch.getEncapsulationType().name().toLowerCase());
    assertEquals(flowPatchDto.getPathComputationStrategy(), flowPatch.getPathComputationStrategy().name().toLowerCase());
}
Also used : FlowPatchV2(org.openkilda.northbound.dto.v2.flows.FlowPatchV2) FlowPatch(org.openkilda.messaging.model.FlowPatch) FlowPatchEndpoint(org.openkilda.northbound.dto.v2.flows.FlowPatchEndpoint) Test(org.junit.Test)

Example 14 with FlowPatch

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

the class FlowMapperTest method testFlowPatchDtoToFlowDto.

@Test
public void testFlowPatchDtoToFlowDto() {
    FlowPatchDto flowPatchDto = new FlowPatchDto(LATENCY, PRIORITY, PERIODIC_PINGS, TARGET_PATH_COMPUTATION_STRATEGY);
    FlowPatch flowPatch = flowMapper.toFlowPatch(flowPatchDto);
    assertEquals(flowPatchDto.getMaxLatency() * MS_TO_NS_MULTIPLIER, (long) flowPatch.getMaxLatency());
    assertEquals(flowPatchDto.getPriority(), flowPatch.getPriority());
    assertEquals(flowPatchDto.getPeriodicPings(), flowPatch.getPeriodicPings());
    assertEquals(flowPatchDto.getTargetPathComputationStrategy(), flowPatch.getTargetPathComputationStrategy().name().toLowerCase());
}
Also used : FlowPatchDto(org.openkilda.northbound.dto.v1.flows.FlowPatchDto) FlowPatch(org.openkilda.messaging.model.FlowPatch) Test(org.junit.Test)

Example 15 with FlowPatch

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

the class FlowServiceImpl method patchFlow.

@Override
public CompletableFuture<FlowResponsePayload> patchFlow(String flowId, FlowPatchDto flowPatchDto) {
    logger.info("Patch flow request for flow {}", flowId);
    String correlationId = RequestCorrelationId.getId();
    FlowPatch flowPatch;
    try {
        flowPatch = flowMapper.toFlowPatch(flowPatchDto);
    } catch (IllegalArgumentException e) {
        logger.error("Can not parse arguments: {}", e.getMessage(), e);
        throw new MessageException(correlationId, System.currentTimeMillis(), ErrorType.DATA_INVALID, e.getMessage(), "Can not parse arguments of the flow patch request");
    }
    flowPatch.setFlowId(flowId);
    CommandMessage request = new CommandMessage(new FlowPatchRequest(flowPatch), System.currentTimeMillis(), correlationId);
    return messagingChannel.sendAndGet(nbworkerTopic, request).thenApply(FlowResponse.class::cast).thenApply(FlowResponse::getPayload).thenApply(flowMapper::toFlowResponseOutput);
}
Also used : FlowPatch(org.openkilda.messaging.model.FlowPatch) FlowPatchRequest(org.openkilda.messaging.nbtopology.request.FlowPatchRequest) MessageException(org.openkilda.messaging.error.MessageException) FlowResponse(org.openkilda.messaging.info.flow.FlowResponse) SwapFlowResponse(org.openkilda.messaging.info.flow.SwapFlowResponse) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Aggregations

FlowPatch (org.openkilda.messaging.model.FlowPatch)15 Test (org.junit.Test)12 Flow (org.openkilda.model.Flow)11 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)10 SwitchId (org.openkilda.model.SwitchId)7 UpdateFlowResult (org.openkilda.wfm.topology.nbworker.services.FlowOperationsService.UpdateFlowResult)6 TestFlowBuilder (org.openkilda.wfm.share.flow.TestFlowBuilder)4 MessageException (org.openkilda.messaging.error.MessageException)3 FlowResponse (org.openkilda.messaging.info.flow.FlowResponse)3 CommandMessage (org.openkilda.messaging.command.CommandMessage)2 SwapFlowResponse (org.openkilda.messaging.info.flow.SwapFlowResponse)2 PathComputationStrategy (org.openkilda.model.PathComputationStrategy)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 String.format (java.lang.String.format)1 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1