Search in sources :

Example 1 with FlowPatch

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

the class FlowServiceImpl method patchFlow.

@Override
public CompletableFuture<FlowResponseV2> patchFlow(String flowId, FlowPatchV2 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::toFlowResponseV2);
}
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)

Example 2 with FlowPatch

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

the class FlowOperationsServiceTest method shouldPrepareFlowUpdateResultWithNeedUpdateFlag.

@Test
public void shouldPrepareFlowUpdateResultWithNeedUpdateFlag() {
    String flowId = "test_flow_id";
    Flow flow = Flow.builder().flowId(flowId).srcSwitch(Switch.builder().switchId(new SwitchId(1)).build()).srcPort(2).srcVlan(3).destSwitch(Switch.builder().switchId(new SwitchId(2)).build()).destPort(4).destVlan(5).bandwidth(1000).allocateProtectedPath(true).encapsulationType(FlowEncapsulationType.TRANSIT_VLAN).pathComputationStrategy(PathComputationStrategy.COST).build();
    // new src switch
    FlowPatch flowPatch = FlowPatch.builder().source(PatchEndpoint.builder().switchId(new SwitchId(3)).build()).build();
    UpdateFlowResult result = flowOperationsService.prepareFlowUpdateResult(flowPatch, flow).build();
    assertTrue(result.isNeedUpdateFlow());
    // new src port
    flowPatch = FlowPatch.builder().source(PatchEndpoint.builder().portNumber(9).build()).build();
    result = flowOperationsService.prepareFlowUpdateResult(flowPatch, flow).build();
    assertTrue(result.isNeedUpdateFlow());
    // new src vlan
    flowPatch = FlowPatch.builder().source(PatchEndpoint.builder().vlanId(9).build()).build();
    result = flowOperationsService.prepareFlowUpdateResult(flowPatch, flow).build();
    assertTrue(result.isNeedUpdateFlow());
    // new src inner vlan
    flowPatch = FlowPatch.builder().source(PatchEndpoint.builder().innerVlanId(9).build()).build();
    result = flowOperationsService.prepareFlowUpdateResult(flowPatch, flow).build();
    assertTrue(result.isNeedUpdateFlow());
    // new src LLDP flag
    flowPatch = FlowPatch.builder().source(PatchEndpoint.builder().trackLldpConnectedDevices(true).build()).build();
    result = flowOperationsService.prepareFlowUpdateResult(flowPatch, flow).build();
    assertTrue(result.isNeedUpdateFlow());
    // new src ARP flag
    flowPatch = FlowPatch.builder().source(PatchEndpoint.builder().trackArpConnectedDevices(true).build()).build();
    result = flowOperationsService.prepareFlowUpdateResult(flowPatch, flow).build();
    assertTrue(result.isNeedUpdateFlow());
    // new dst switch
    flowPatch = FlowPatch.builder().destination(PatchEndpoint.builder().switchId(new SwitchId(3)).build()).build();
    result = flowOperationsService.prepareFlowUpdateResult(flowPatch, flow).build();
    assertTrue(result.isNeedUpdateFlow());
    // new dst port
    flowPatch = FlowPatch.builder().destination(PatchEndpoint.builder().portNumber(9).build()).build();
    result = flowOperationsService.prepareFlowUpdateResult(flowPatch, flow).build();
    assertTrue(result.isNeedUpdateFlow());
    // new dst vlan
    flowPatch = FlowPatch.builder().destination(PatchEndpoint.builder().vlanId(9).build()).build();
    result = flowOperationsService.prepareFlowUpdateResult(flowPatch, flow).build();
    assertTrue(result.isNeedUpdateFlow());
    // new dst inner vlan
    flowPatch = FlowPatch.builder().destination(PatchEndpoint.builder().innerVlanId(9).build()).build();
    result = flowOperationsService.prepareFlowUpdateResult(flowPatch, flow).build();
    assertTrue(result.isNeedUpdateFlow());
    // new dst LLDP flag
    flowPatch = FlowPatch.builder().destination(PatchEndpoint.builder().trackLldpConnectedDevices(true).build()).build();
    result = flowOperationsService.prepareFlowUpdateResult(flowPatch, flow).build();
    assertTrue(result.isNeedUpdateFlow());
    // new dst ARP flag
    flowPatch = FlowPatch.builder().destination(PatchEndpoint.builder().trackArpConnectedDevices(true).build()).build();
    result = flowOperationsService.prepareFlowUpdateResult(flowPatch, flow).build();
    assertTrue(result.isNeedUpdateFlow());
    // new maximum bandwidth
    flowPatch = FlowPatch.builder().bandwidth(9000L).build();
    result = flowOperationsService.prepareFlowUpdateResult(flowPatch, flow).build();
    assertTrue(result.isNeedUpdateFlow());
    // new flag allocate protected path
    flowPatch = FlowPatch.builder().allocateProtectedPath(false).build();
    result = flowOperationsService.prepareFlowUpdateResult(flowPatch, flow).build();
    assertTrue(result.isNeedUpdateFlow());
    // add diverse flow id
    flowPatch = FlowPatch.builder().diverseFlowId("diverse_flow_id").build();
    result = flowOperationsService.prepareFlowUpdateResult(flowPatch, flow).build();
    assertTrue(result.isNeedUpdateFlow());
    // new ignore bandwidth flag
    flowPatch = FlowPatch.builder().ignoreBandwidth(true).build();
    result = flowOperationsService.prepareFlowUpdateResult(flowPatch, flow).build();
    assertTrue(result.isNeedUpdateFlow());
    // new encapsulation type
    flowPatch = FlowPatch.builder().encapsulationType(FlowEncapsulationType.VXLAN).build();
    result = flowOperationsService.prepareFlowUpdateResult(flowPatch, flow).build();
    assertTrue(result.isNeedUpdateFlow());
    // new path computation strategy
    flowPatch = FlowPatch.builder().pathComputationStrategy(PathComputationStrategy.LATENCY).build();
    result = flowOperationsService.prepareFlowUpdateResult(flowPatch, flow).build();
    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 3 with FlowPatch

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

the class FlowOperationsServiceTest method shouldPrepareFlowUpdateResultShouldNotUpdateFirstCase.

@Test
public void shouldPrepareFlowUpdateResultShouldNotUpdateFirstCase() {
    // given: FlowPatch with max latency and MAX_LATENCY strategy
    // and Flow with MAX_LATENCY strategy and same 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()).maxLatency(100L).pathComputationStrategy(PathComputationStrategy.MAX_LATENCY).build();
    // when: compare this flows
    UpdateFlowResult result = flowOperationsService.prepareFlowUpdateResult(flowDto, flow).build();
    // then: needRerouteFlow flag set to false
    assertFalse(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 4 with FlowPatch

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

the class FlowOperationsServiceTest method testStrictBandwidthAndIgnoreBandwidthPatchConflict.

@Test(expected = IllegalArgumentException.class)
public void testStrictBandwidthAndIgnoreBandwidthPatchConflict() throws FlowNotFoundException {
    String testFlowId = "flow_id";
    Flow flow = new TestFlowBuilder().flowId(testFlowId).srcSwitch(createSwitch(SWITCH_ID_1)).destSwitch(createSwitch(SWITCH_ID_2)).build();
    flowRepository.add(flow);
    FlowPatch receivedFlow = FlowPatch.builder().flowId(testFlowId).strictBandwidth(true).ignoreBandwidth(true).build();
    flowOperationsService.updateFlow(new FlowCarrierImpl(), receivedFlow);
}
Also used : FlowPatch(org.openkilda.messaging.model.FlowPatch) TestFlowBuilder(org.openkilda.wfm.share.flow.TestFlowBuilder) Flow(org.openkilda.model.Flow) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 5 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