Search in sources :

Example 26 with FlowRequest

use of org.openkilda.messaging.command.flow.FlowRequest in project open-kilda by telstra.

the class FlowCreateServiceTest method shouldRollbackIfIngressRuleNotInstalled.

@Test
public void shouldRollbackIfIngressRuleNotInstalled() throws Exception {
    when(pathComputer.getPath(any(Flow.class))).thenReturn(make3SwitchesPathPair());
    String key = "failed_flow_create";
    FlowRequest flowRequest = makeRequest().flowId("failed_flow_id").build();
    FlowCreateService service = makeService();
    service.handleRequest(key, new CommandContext(), flowRequest);
    Flow inProgress = verifyFlowStatus(flowRequest.getFlowId(), FlowStatus.IN_PROGRESS);
    verifyFlowPathStatus(inProgress.getForwardPath(), FlowPathStatus.IN_PROGRESS, "forward");
    verifyFlowPathStatus(inProgress.getReversePath(), FlowPathStatus.IN_PROGRESS, "reverse");
    verifyNorthboundSuccessResponse(carrier);
    FlowSegmentRequest request;
    int installCommands = 0;
    int deleteCommands = 0;
    while ((request = requests.poll()) != null) {
        try {
            if (request.isVerifyRequest()) {
                service.handleAsyncResponse(key, buildResponseOnVerifyRequest(request));
            } else if (request.isInstallRequest()) {
                installCommands++;
                if (requests.size() > 1 || request instanceof EgressFlowSegmentInstallRequest) {
                    handleResponse(service, key, request);
                } else {
                    handleErrorResponse(service, key, request, ErrorCode.UNKNOWN);
                }
            } else if (request.isRemoveRequest()) {
                deleteCommands++;
                handleResponse(service, key, request);
            }
        } catch (UnknownKeyException ex) {
        // skip
        }
    }
    assertEquals("All installed rules should be deleted", installCommands, deleteCommands);
    Flow result = verifyFlowStatus(flowRequest.getFlowId(), FlowStatus.DOWN);
    Assert.assertNull(result.getForwardPath());
    Assert.assertNull(result.getReversePath());
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) EgressFlowSegmentInstallRequest(org.openkilda.floodlight.api.request.EgressFlowSegmentInstallRequest) FlowEndpoint(org.openkilda.model.FlowEndpoint) Flow(org.openkilda.model.Flow) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException) Test(org.junit.Test)

Example 27 with FlowRequest

use of org.openkilda.messaging.command.flow.FlowRequest in project open-kilda by telstra.

the class FlowCreateServiceTest method shouldNotRetryForever.

@Test
public void shouldNotRetryForever() throws Exception {
    String key = "retries_non_ingress_installation";
    FlowRequest flowRequest = makeRequest().flowId("dummy_flow_id").build();
    int retriesLimit = 10;
    FlowCreateService service = makeService(retriesLimit);
    preparePathComputation(flowRequest.getFlowId(), make2SwitchesPathPair());
    service.handleRequest(key, new CommandContext(), flowRequest);
    Flow inProgress = verifyFlowStatus(flowRequest.getFlowId(), FlowStatus.IN_PROGRESS);
    verifyFlowPathStatus(inProgress.getForwardPath(), FlowPathStatus.IN_PROGRESS, "forward");
    verifyFlowPathStatus(inProgress.getReversePath(), FlowPathStatus.IN_PROGRESS, "reverse");
    verifyNorthboundSuccessResponse(carrier);
    FlowSegmentRequest request;
    Map<UUID, Integer> remainingRetries = new HashMap<>();
    while ((request = requests.poll()) != null) {
        UUID commandId = request.getCommandId();
        Integer remaining = remainingRetries.getOrDefault(commandId, retriesLimit + 1);
        Assert.assertTrue(0 < remaining);
        try {
            if (request instanceof EgressFlowSegmentInstallRequest) {
                remainingRetries.put(commandId, remaining - 1);
                handleErrorResponse(service, key, request, ErrorCode.SWITCH_UNAVAILABLE);
            } else if (request.isVerifyRequest()) {
                service.handleAsyncResponse(key, buildResponseOnVerifyRequest(request));
            } else {
                handleResponse(service, key, request);
            }
        } catch (UnknownKeyException ex) {
        // skip
        }
    }
    verifyFlowStatus(flowRequest.getFlowId(), FlowStatus.DOWN);
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) HashMap(java.util.HashMap) EgressFlowSegmentInstallRequest(org.openkilda.floodlight.api.request.EgressFlowSegmentInstallRequest) FlowEndpoint(org.openkilda.model.FlowEndpoint) Flow(org.openkilda.model.Flow) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException) UUID(java.util.UUID) Test(org.junit.Test)

Example 28 with FlowRequest

use of org.openkilda.messaging.command.flow.FlowRequest in project open-kilda by telstra.

the class FlowUpdateService method handleDeleteFlowLoopRequest.

/**
 * Handles delete flow loop request.
 *
 * @param request request to handle.
 */
public void handleDeleteFlowLoopRequest(@NonNull String key, @NonNull CommandContext commandContext, @NonNull DeleteFlowLoopRequest request) throws DuplicateKeyException {
    if (yFlowRepository.isSubFlow(request.getFlowId())) {
        sendForbiddenSubFlowOperationToNorthbound(request.getFlowId(), commandContext);
        return;
    }
    Optional<Flow> flow = flowRepository.findById(request.getFlowId());
    if (flow.isPresent()) {
        FlowRequest flowRequest = RequestedFlowMapper.INSTANCE.toFlowRequest(flow.get());
        flowRequest.setLoopSwitchId(null);
        handleUpdateRequest(key, commandContext, flowRequest);
    } else {
        carrier.sendNorthboundResponse(buildFlowNotFoundErrorMessage(request.getFlowId(), commandContext));
    }
}
Also used : FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) Flow(org.openkilda.model.Flow) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow)

Example 29 with FlowRequest

use of org.openkilda.messaging.command.flow.FlowRequest in project open-kilda by telstra.

the class FlowUpdateService method handleCreateFlowLoopRequest.

/**
 * Handles create flow loop request.
 *
 * @param request request to handle.
 */
public void handleCreateFlowLoopRequest(@NonNull String key, @NonNull CommandContext commandContext, @NonNull CreateFlowLoopRequest request) throws DuplicateKeyException {
    if (yFlowRepository.isSubFlow(request.getFlowId())) {
        sendForbiddenSubFlowOperationToNorthbound(request.getFlowId(), commandContext);
        return;
    }
    Optional<Flow> flow = flowRepository.findById(request.getFlowId());
    if (flow.isPresent()) {
        FlowRequest flowRequest = RequestedFlowMapper.INSTANCE.toFlowRequest(flow.get());
        if (flowRequest.getLoopSwitchId() == null || flowRequest.getLoopSwitchId().equals(request.getSwitchId())) {
            flowRequest.setLoopSwitchId(request.getSwitchId());
            handleUpdateRequest(key, commandContext, flowRequest);
        } else {
            carrier.sendNorthboundResponse(buildFlowAlreadyLoopedErrorMessage(flowRequest, commandContext));
        }
    } else {
        carrier.sendNorthboundResponse(buildFlowNotFoundErrorMessage(request.getFlowId(), commandContext));
    }
}
Also used : FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) Flow(org.openkilda.model.Flow) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow)

Example 30 with FlowRequest

use of org.openkilda.messaging.command.flow.FlowRequest in project open-kilda by telstra.

the class RequestedFlowMapperTest method mapFlowToFlowRequestTest.

@Test
public void mapFlowToFlowRequestTest() {
    FlowRequest flowRequest = RequestedFlowMapper.INSTANCE.toFlowRequest(flow);
    assertEquals(FLOW_ID, flowRequest.getFlowId());
    assertEquals(SRC_SWITCH_ID, flowRequest.getSource().getSwitchId());
    assertEquals(SRC_PORT, (int) flowRequest.getSource().getPortNumber());
    assertEquals(SRC_VLAN, flowRequest.getSource().getOuterVlanId());
    assertEquals(DST_SWITCH_ID, flowRequest.getDestination().getSwitchId());
    assertEquals(DST_PORT, (int) flowRequest.getDestination().getPortNumber());
    assertEquals(DST_VLAN, flowRequest.getDestination().getOuterVlanId());
    assertEquals(PRIORITY, flowRequest.getPriority());
    assertEquals(DESCRIPTION, flowRequest.getDescription());
    assertEquals(BANDWIDTH, flowRequest.getBandwidth());
    assertEquals(MAX_LATENCY, flowRequest.getMaxLatency());
    assertEquals(org.openkilda.messaging.payload.flow.FlowEncapsulationType.TRANSIT_VLAN, flowRequest.getEncapsulationType());
    assertEquals(PATH_COMPUTATION_STRATEGY.toString().toLowerCase(), flowRequest.getPathComputationStrategy());
    assertTrue(flowRequest.isPinned());
    assertTrue(flowRequest.isAllocateProtectedPath());
    assertTrue(flowRequest.isIgnoreBandwidth());
    assertTrue(flowRequest.isPeriodicPings());
    assertEquals(new DetectConnectedDevicesDto(true, true, true, true, true, true, true, true), flowRequest.getDetectConnectedDevices());
}
Also used : FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) DetectConnectedDevicesDto(org.openkilda.messaging.model.DetectConnectedDevicesDto) Test(org.junit.Test)

Aggregations

FlowRequest (org.openkilda.messaging.command.flow.FlowRequest)45 Test (org.junit.Test)28 Flow (org.openkilda.model.Flow)25 FlowSegmentRequest (org.openkilda.floodlight.api.request.FlowSegmentRequest)12 FlowEndpoint (org.openkilda.model.FlowEndpoint)6 CommandMessage (org.openkilda.messaging.command.CommandMessage)5 MessageException (org.openkilda.messaging.error.MessageException)5 FlowResponse (org.openkilda.messaging.info.flow.FlowResponse)5 SwapFlowResponse (org.openkilda.messaging.info.flow.SwapFlowResponse)4 FlowPathRepository (org.openkilda.persistence.repositories.FlowPathRepository)4 CommandContext (org.openkilda.wfm.CommandContext)4 UnknownKeyException (org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)4 DetectConnectedDevicesDto (org.openkilda.messaging.model.DetectConnectedDevicesDto)3 Sets (com.google.common.collect.Sets)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 UUID (java.util.UUID)2 Collectors (java.util.stream.Collectors)2 Ignore (org.junit.Ignore)2