Search in sources :

Example 16 with FlowRequest

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

the class FlowCreateServiceTest method shouldCreateOneSwitchFlow.

@Test
public void shouldCreateOneSwitchFlow() throws Exception {
    FlowRequest request = makeRequest().flowId("one_switch_flow").destination(new FlowEndpoint(SWITCH_SOURCE, 2, 2)).build();
    preparePathComputation(request.getFlowId(), makeOneSwitchPathPair());
    testHappyPath(request, "successful_flow_create");
}
Also used : FlowEndpoint(org.openkilda.model.FlowEndpoint) FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) Test(org.junit.Test)

Example 17 with FlowRequest

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

the class FlowMapper method toFlowCreateRequest.

/**
 * Map FlowCreatePayload.
 *
 * @param source {@link FlowCreatePayload} instance.
 * @return {@link FlowRequest} instance.
 */
public FlowRequest toFlowCreateRequest(FlowCreatePayload source) {
    FlowRequest target = toFlowRequest(source).toBuilder().diverseFlowId(source.getDiverseFlowId()).type(Type.CREATE).build();
    if (source.getSource().getDetectConnectedDevices() != null) {
        DetectConnectedDevicesPayload srcDevs = source.getSource().getDetectConnectedDevices();
        target.getDetectConnectedDevices().setSrcArp(srcDevs.isArp());
        target.getDetectConnectedDevices().setSrcLldp(srcDevs.isLldp());
    }
    if (source.getDestination().getDetectConnectedDevices() != null) {
        DetectConnectedDevicesPayload dstDevs = source.getDestination().getDetectConnectedDevices();
        target.getDetectConnectedDevices().setDstArp(dstDevs.isArp());
        target.getDetectConnectedDevices().setDstLldp(dstDevs.isLldp());
    }
    return target;
}
Also used : FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) DetectConnectedDevicesPayload(org.openkilda.messaging.payload.flow.DetectConnectedDevicesPayload)

Example 18 with FlowRequest

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

the class FlowServiceImpl method createFlow.

/**
 * {@inheritDoc}
 */
@Override
public CompletableFuture<FlowResponsePayload> createFlow(FlowCreatePayload request) {
    logger.info("Create flow: {}", request);
    final String correlationId = RequestCorrelationId.getId();
    FlowRequest flowRequest;
    try {
        flowRequest = flowMapper.toFlowCreateRequest(request);
    } 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 create flow request");
    }
    CommandMessage command = new CommandMessage(flowRequest, System.currentTimeMillis(), correlationId, Destination.WFM);
    return messagingChannel.sendAndGet(flowHsTopic, command).thenApply(FlowResponse.class::cast).thenApply(FlowResponse::getPayload).thenApply(flowMapper::toFlowResponseOutput);
}
Also used : FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) 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 19 with FlowRequest

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

the class FlowMapperTest method testFlowRequestV2Mapping.

@Test
public void testFlowRequestV2Mapping() {
    FlowRequestV2 flowRequestV2 = FlowRequestV2.builder().flowId(FLOW_ID).encapsulationType(ENCAPSULATION_TYPE).source(new FlowEndpointV2(SRC_SWITCH_ID, SRC_PORT, SRC_VLAN, SRC_DETECT_CONNECTED_DEVICES)).destination(new FlowEndpointV2(DST_SWITCH_ID, DST_PORT, DST_VLAN, DST_DETECT_CONNECTED_DEVICES)).description(DESCRIPTION).maximumBandwidth(BANDWIDTH).maxLatency(LATENCY).maxLatencyTier2(LATENCY_TIER2).priority(PRIORITY).diverseFlowId(DIVERSE_FLOW_ID).build();
    FlowRequest flowRequest = flowMapper.toFlowRequest(flowRequestV2);
    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(FlowEncapsulationType.TRANSIT_VLAN, flowRequest.getEncapsulationType());
    assertEquals(DESCRIPTION, flowRequest.getDescription());
    assertEquals(BANDWIDTH, flowRequest.getBandwidth());
    // ms to ns
    assertEquals(LATENCY * MS_TO_NS_MULTIPLIER, (long) flowRequest.getMaxLatency());
    assertEquals(LATENCY_TIER2 * MS_TO_NS_MULTIPLIER, (long) flowRequest.getMaxLatencyTier2());
    assertEquals(PRIORITY, flowRequest.getPriority());
    assertEquals(DIVERSE_FLOW_ID, flowRequest.getDiverseFlowId());
    assertEquals(SRC_DETECT_CONNECTED_DEVICES.isLldp(), flowRequest.getDetectConnectedDevices().isSrcLldp());
    assertEquals(SRC_DETECT_CONNECTED_DEVICES.isArp(), flowRequest.getDetectConnectedDevices().isSrcArp());
    assertEquals(DST_DETECT_CONNECTED_DEVICES.isLldp(), flowRequest.getDetectConnectedDevices().isDstLldp());
    assertEquals(DST_DETECT_CONNECTED_DEVICES.isArp(), flowRequest.getDetectConnectedDevices().isDstArp());
}
Also used : FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) FlowEndpointV2(org.openkilda.northbound.dto.v2.flows.FlowEndpointV2) FlowRequestV2(org.openkilda.northbound.dto.v2.flows.FlowRequestV2) Test(org.junit.Test)

Example 20 with FlowRequest

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

the class FlowServiceImpl method updateFlow.

/**
 * {@inheritDoc}
 */
@Override
public CompletableFuture<FlowResponsePayload> updateFlow(final FlowUpdatePayload request) {
    logger.info("Update flow request for flow {}", request.getId());
    final String correlationId = RequestCorrelationId.getId();
    FlowRequest updateRequest;
    try {
        updateRequest = flowMapper.toFlowUpdateRequest(request);
    } 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 update flow request");
    }
    CommandMessage command = new CommandMessage(updateRequest, System.currentTimeMillis(), correlationId, Destination.WFM);
    return messagingChannel.sendAndGet(flowHsTopic, command).thenApply(FlowResponse.class::cast).thenApply(FlowResponse::getPayload).thenApply(flowMapper::toFlowResponseOutput);
}
Also used : FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) 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

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