Search in sources :

Example 1 with FlowDto

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

the class FlowMapperTest method testMirrorPointStatusesMapping.

@Test
public void testMirrorPointStatusesMapping() {
    Flow flow = buildFlow();
    FlowDto flowDto = FlowMapper.INSTANCE.map(flow, new HashSet<>(), new HashSet<>(), buildFlowMirrorPathList());
    assertNotNull(flowDto.getMirrorPointStatuses());
    assertEquals(2, flowDto.getMirrorPointStatuses().size());
    assertEquals(MIRROR_PATH_ID_A.getId(), flowDto.getMirrorPointStatuses().get(0).getMirrorPointId());
    assertEquals(FLOW_PATH_STATUS_A.toString().toLowerCase(), flowDto.getMirrorPointStatuses().get(0).getStatus());
    assertEquals(MIRROR_PATH_ID_B.getId(), flowDto.getMirrorPointStatuses().get(1).getMirrorPointId());
    assertEquals(FLOW_PATH_STATUS_B.toString().toLowerCase(), flowDto.getMirrorPointStatuses().get(1).getStatus());
}
Also used : FlowDto(org.openkilda.messaging.model.FlowDto) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 2 with FlowDto

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

the class FlowMapperTest method testFlowPairToDto.

@Test
public void testFlowPairToDto() {
    PathInfoData pathInfoData = new PathInfoData();
    pathInfoData.setLatency(1L);
    pathInfoData.setPath(asList(new PathNode(SRC_SWITCH_ID, 1, 1, 1L, 1L), new PathNode(DST_SWITCH_ID, 2, 2, 2L, 2L)));
    FlowDto forwardFlow = new FlowDto();
    forwardFlow.setSourceSwitch(SRC_SWITCH_ID);
    forwardFlow.setDestinationSwitch(DST_SWITCH_ID);
    forwardFlow.setFlowId("12");
    forwardFlow.setCookie(11);
    forwardFlow.setSourcePort(113);
    forwardFlow.setSourceVlan(1112);
    forwardFlow.setDestinationPort(113);
    forwardFlow.setDestinationVlan(1112);
    forwardFlow.setBandwidth(23);
    forwardFlow.setDescription("SOME FLOW");
    forwardFlow.setLastUpdated("2011-12-03T10:15:30Z");
    forwardFlow.setTransitEncapsulationId(87);
    forwardFlow.setMeterId(65);
    forwardFlow.setIgnoreBandwidth(true);
    forwardFlow.setPeriodicPings(true);
    forwardFlow.setEncapsulationType(FlowEncapsulationType.TRANSIT_VLAN);
    forwardFlow.setDetectConnectedDevices(new DetectConnectedDevicesDto(false, true, true, false, false, false, true, true));
    PathInfoData reversePathInfoData = new PathInfoData();
    reversePathInfoData.setLatency(1L);
    reversePathInfoData.setPath(asList(new PathNode(DST_SWITCH_ID, 2, 2, 2L, 2L), new PathNode(SRC_SWITCH_ID, 1, 1, 1L, 1L)));
    FlowDto reverseFlow = new FlowDto();
    reverseFlow.setSourceSwitch(forwardFlow.getDestinationSwitch());
    reverseFlow.setDestinationSwitch(SRC_SWITCH_ID);
    reverseFlow.setFlowId("12");
    reverseFlow.setCookie(12);
    reverseFlow.setSourcePort(113);
    reverseFlow.setSourceVlan(1112);
    reverseFlow.setDestinationPort(113);
    reverseFlow.setDestinationVlan(1112);
    reverseFlow.setBandwidth(23);
    reverseFlow.setDescription("SOME FLOW");
    reverseFlow.setLastUpdated("2011-12-03T10:15:30Z");
    reverseFlow.setTransitEncapsulationId(88);
    reverseFlow.setMeterId(66);
    reverseFlow.setIgnoreBandwidth(true);
    reverseFlow.setPeriodicPings(true);
    reverseFlow.setEncapsulationType(FlowEncapsulationType.TRANSIT_VLAN);
    reverseFlow.setDetectConnectedDevices(new DetectConnectedDevicesDto(true, false, false, true, false, false, true, true));
    FlowPairDto<FlowDto, FlowDto> pair = new FlowPairDto<>(forwardFlow, reverseFlow);
    Flow p = FlowMapper.INSTANCE.map(pair, () -> KildaConfiguration.DEFAULTS);
    assertEquals(p.getFlowId(), pair.getLeft().getFlowId());
    assertDetectConnectedDevices(forwardFlow.getDetectConnectedDevices(), p.getDetectConnectedDevices());
}
Also used : PathInfoData(org.openkilda.messaging.info.event.PathInfoData) FlowDto(org.openkilda.messaging.model.FlowDto) DetectConnectedDevicesDto(org.openkilda.messaging.model.DetectConnectedDevicesDto) FlowPairDto(org.openkilda.messaging.model.FlowPairDto) PathNode(org.openkilda.messaging.info.event.PathNode) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 3 with FlowDto

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

the class FlowMapper method map.

/**
 * Convert {@link FlowDto} to {@link Flow}.
 * If encapsulation type and/or path computation strategy is not provided then values from KildaConfiguration
 * will be used.
 */
public Flow map(FlowDto flow, Supplier<KildaConfiguration> kildaConfiguration) {
    Switch srcSwitch = Switch.builder().switchId(flow.getSourceSwitch()).build();
    Switch destSwitch = Switch.builder().switchId(flow.getDestinationSwitch()).build();
    return Flow.builder().flowId(flow.getFlowId()).srcSwitch(srcSwitch).destSwitch(destSwitch).srcPort(flow.getSourcePort()).destPort(flow.getDestinationPort()).srcVlan(flow.getSourceVlan()).destVlan(flow.getDestinationVlan()).status(map(flow.getState())).statusInfo(flow.getStatusInfo()).description(flow.getDescription()).bandwidth(flow.getBandwidth()).ignoreBandwidth(flow.isIgnoreBandwidth()).periodicPings(Boolean.TRUE.equals(flow.getPeriodicPings())).allocateProtectedPath(flow.isAllocateProtectedPath()).encapsulationType(Optional.ofNullable(flow.getEncapsulationType()).map(encapsulationType -> FlowEncapsulationType.valueOf(encapsulationType.name())).orElse(kildaConfiguration.get().getFlowEncapsulationType())).pathComputationStrategy(Optional.ofNullable(flow.getPathComputationStrategy()).map(pathComputationStrategy -> PathComputationStrategy.valueOf(pathComputationStrategy.name())).orElse(kildaConfiguration.get().getPathComputationStrategy())).maxLatency(flow.getMaxLatency()).priority(flow.getPriority()).pinned(flow.isPinned()).detectConnectedDevices(DetectConnectedDevicesMapper.INSTANCE.map(flow.getDetectConnectedDevices())).build();
}
Also used : FlowStatusDetails(org.openkilda.messaging.payload.flow.FlowStatusDetails) FlowStats(org.openkilda.model.FlowStats) Mapping(org.mapstruct.Mapping) FlowPath(org.openkilda.model.FlowPath) FlowStatus(org.openkilda.model.FlowStatus) Supplier(java.util.function.Supplier) FlowPathStatus(org.openkilda.model.FlowPathStatus) Flow(org.openkilda.model.Flow) Mapper(org.mapstruct.Mapper) SwapFlowDto(org.openkilda.messaging.model.SwapFlowDto) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) Mappers(org.mapstruct.factory.Mappers) PathId(org.openkilda.model.PathId) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) Switch(org.openkilda.model.Switch) PathComputationStrategy(org.openkilda.model.PathComputationStrategy) KildaConfiguration(org.openkilda.model.KildaConfiguration) Set(java.util.Set) FlowDto(org.openkilda.messaging.model.FlowDto) UUID(java.util.UUID) Instant(java.time.Instant) MeterId(org.openkilda.model.MeterId) List(java.util.List) FlowPairDto(org.openkilda.messaging.model.FlowPairDto) MirrorPointStatusDto(org.openkilda.messaging.model.MirrorPointStatusDto) SwitchId(org.openkilda.model.SwitchId) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) Optional(java.util.Optional) FlowState(org.openkilda.messaging.payload.flow.FlowState) Switch(org.openkilda.model.Switch)

Example 4 with FlowDto

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

the class FlowMapper method map.

/**
 * Convert {@link Flow} to {@link FlowDto} with diverse flow ids, mirror paths and flow properties.
 */
public FlowDto map(Flow flow, Set<String> diverseWith, Set<String> diverseWithYFlows, List<FlowMirrorPath> flowMirrorPaths, FlowStats flowStats) {
    FlowDto flowDto = map(flow);
    flowDto.setDiverseWith(diverseWith);
    flowDto.setDiverseWithYFlows(diverseWithYFlows);
    flowDto.setMirrorPointStatuses(map(flowMirrorPaths));
    flowDto.setForwardLatency(flowStats.getForwardLatency());
    flowDto.setReverseLatency(flowStats.getReverseLatency());
    flowDto.setLatencyLastModifiedTime(flowStats.getTimeModify());
    return flowDto;
}
Also used : SwapFlowDto(org.openkilda.messaging.model.SwapFlowDto) FlowDto(org.openkilda.messaging.model.FlowDto)

Example 5 with FlowDto

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

the class FlowServiceTest method swapFlowEndpoint.

@Test
public void swapFlowEndpoint() throws Exception {
    String correlationId = "bulk-flow-update";
    RequestCorrelationId.create(correlationId);
    String firstFlowId = "bulk-flow-1";
    String secondFlowId = "bulk-flow-2";
    FlowEndpointV2 firstEndpoint = new FlowEndpointV2(new SwitchId("ff:00"), 1, 1, new DetectConnectedDevicesV2(false, false));
    FlowEndpointV2 secondEndpoint = new FlowEndpointV2(new SwitchId("ff:01"), 2, 2, new DetectConnectedDevicesV2(false, false));
    SwapFlowPayload firstFlowPayload = SwapFlowPayload.builder().flowId(firstFlowId).source(firstEndpoint).destination(firstEndpoint).build();
    SwapFlowPayload secondFlowPayload = SwapFlowPayload.builder().flowId(secondFlowId).source(secondEndpoint).destination(secondEndpoint).build();
    SwapFlowEndpointPayload input = new SwapFlowEndpointPayload(firstFlowPayload, secondFlowPayload);
    FlowDto firstResponse = FlowDto.builder().flowId(firstFlowId).bandwidth(10000).description(firstFlowId).state(FlowState.UP).sourceSwitch(new SwitchId("ff:00")).sourcePort(1).sourceVlan(1).destinationSwitch(new SwitchId("ff:01")).destinationPort(2).destinationVlan(2).build();
    FlowDto secondResponse = FlowDto.builder().flowId(secondFlowId).bandwidth(20000).description(secondFlowId).state(FlowState.UP).sourceSwitch(new SwitchId("ff:01")).sourcePort(2).sourceVlan(2).destinationSwitch(new SwitchId("ff:00")).destinationPort(1).destinationVlan(1).build();
    SwapFlowResponse response = new SwapFlowResponse(new FlowResponse(firstResponse), new FlowResponse(secondResponse));
    messageExchanger.mockResponse(correlationId, response);
    SwapFlowEndpointPayload result = flowService.swapFlowEndpoint(input).get();
    assertEquals(secondEndpoint, result.getFirstFlow().getDestination());
    assertEquals(firstEndpoint, result.getSecondFlow().getDestination());
}
Also used : FlowDto(org.openkilda.messaging.model.FlowDto) SwapFlowEndpointPayload(org.openkilda.northbound.dto.v2.flows.SwapFlowEndpointPayload) FlowEndpointV2(org.openkilda.northbound.dto.v2.flows.FlowEndpointV2) SwapFlowPayload(org.openkilda.northbound.dto.v2.flows.SwapFlowPayload) FlowResponse(org.openkilda.messaging.info.flow.FlowResponse) SwapFlowResponse(org.openkilda.messaging.info.flow.SwapFlowResponse) DetectConnectedDevicesV2(org.openkilda.northbound.dto.v2.flows.DetectConnectedDevicesV2) SwitchId(org.openkilda.model.SwitchId) SwapFlowResponse(org.openkilda.messaging.info.flow.SwapFlowResponse) Test(org.junit.Test)

Aggregations

FlowDto (org.openkilda.messaging.model.FlowDto)9 Test (org.junit.Test)5 Flow (org.openkilda.model.Flow)4 SwitchId (org.openkilda.model.SwitchId)3 List (java.util.List)2 FlowResponse (org.openkilda.messaging.info.flow.FlowResponse)2 SwapFlowResponse (org.openkilda.messaging.info.flow.SwapFlowResponse)2 FlowPairDto (org.openkilda.messaging.model.FlowPairDto)2 SwapFlowDto (org.openkilda.messaging.model.SwapFlowDto)2 Instant (java.time.Instant)1 Optional (java.util.Optional)1 Set (java.util.Set)1 UUID (java.util.UUID)1 Supplier (java.util.function.Supplier)1 Mapper (org.mapstruct.Mapper)1 Mapping (org.mapstruct.Mapping)1 Mappers (org.mapstruct.factory.Mappers)1 ErrorData (org.openkilda.messaging.error.ErrorData)1 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)1 PathInfoData (org.openkilda.messaging.info.event.PathInfoData)1