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");
}
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;
}
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);
}
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());
}
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);
}
Aggregations