Search in sources :

Example 1 with FlowPathDto

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

the class ActionServiceTest method shouldUpdateFlowInfo.

@Test
public void shouldUpdateFlowInfo() {
    service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.FORWARD, NANOSECOND);
    service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.REVERSE, NANOSECOND);
    FlowPathDto path = FlowPathDto.builder().forwardPath(Arrays.asList(new PathNodePayload(SRC_SWITCH, 1, 2), new PathNodePayload(DST_SWITCH, 3, 4))).reversePath(Arrays.asList(new PathNodePayload(DST_SWITCH, 4, 3), new PathNodePayload(SRC_SWITCH, 2, 1))).build();
    long maxLatency = flow.getMaxLatency() / 2;
    long maxLatencyTier2 = flow.getMaxLatencyTier2() / 2;
    UpdateFlowCommand info = new UpdateFlowCommand(flow.getFlowId(), path, maxLatency, maxLatencyTier2);
    service.updateFlowInfo(info);
    assertEquals(2, service.fsms.values().size());
    FlowLatencyMonitoringFsm fsm = service.fsms.values().stream().findAny().orElseThrow(() -> new IllegalStateException("Fsm not found"));
    assertEquals(maxLatency, fsm.getMaxLatency());
    assertEquals(maxLatencyTier2, fsm.getMaxLatencyTier2());
    verifyNoMoreInteractions(carrier);
}
Also used : UpdateFlowCommand(org.openkilda.messaging.info.flow.UpdateFlowCommand) FlowPathDto(org.openkilda.messaging.model.FlowPathDto) PathNodePayload(org.openkilda.messaging.payload.flow.PathNodePayload) FlowLatencyMonitoringFsm(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 2 with FlowPathDto

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

the class NotifyFlowMonitorAction method getFlowInfo.

private CommandData getFlowInfo(String flowId) {
    Optional<Flow> flow = flowRepository.findById(flowId);
    if (!flow.isPresent() || flow.get().isOneSwitchFlow()) {
        return new RemoveFlowCommand(flowId);
    }
    FlowPathDto flowPathDto = toFlowPathDtoBuilder(flow.get()).build();
    return new UpdateFlowCommand(flowId, flowPathDto, flow.get().getMaxLatency(), flow.get().getMaxLatencyTier2());
}
Also used : UpdateFlowCommand(org.openkilda.messaging.info.flow.UpdateFlowCommand) FlowPathDto(org.openkilda.messaging.model.FlowPathDto) RemoveFlowCommand(org.openkilda.messaging.info.flow.RemoveFlowCommand) Flow(org.openkilda.model.Flow)

Example 3 with FlowPathDto

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

the class FlowServiceImpl method buildFlowPathPayload.

private FlowPathPayload buildFlowPathPayload(List<FlowPathDto> paths, String flowId) {
    FlowPathDto askedPathDto = paths.stream().filter(e -> e.getId().equals(flowId)).findAny().orElseThrow(() -> new IllegalStateException(format("Path for flow %s is not found.", flowId)));
    // fill primary flow path
    FlowPathPayload payload = new FlowPathPayload();
    payload.setId(askedPathDto.getId());
    payload.setForwardPath(askedPathDto.getForwardPath());
    payload.setReversePath(askedPathDto.getReversePath());
    if (askedPathDto.getProtectedPath() != null) {
        FlowProtectedPathDto protectedPath = askedPathDto.getProtectedPath();
        payload.setProtectedPath(FlowProtectedPath.builder().forwardPath(protectedPath.getForwardPath()).reversePath(protectedPath.getReversePath()).build());
    }
    // fill group paths
    if (paths.size() > 1) {
        payload.setDiverseGroupPayload(DiverseGroupPayload.builder().overlappingSegments(askedPathDto.getSegmentsStats()).otherFlows(mapGroupPaths(paths, flowId, FlowPathDto::isPrimaryPathCorrespondStat)).build());
        if (askedPathDto.getProtectedPath() != null) {
            payload.setDiverseGroupProtectedPayload(DiverseGroupPayload.builder().overlappingSegments(askedPathDto.getProtectedPath().getSegmentsStats()).otherFlows(mapGroupPaths(paths, flowId, e -> !e.isPrimaryPathCorrespondStat())).build());
        }
    }
    return payload;
}
Also used : FlowReadRequest(org.openkilda.messaging.nbtopology.request.FlowReadRequest) GetFlowStatusTimestampsRequest(org.openkilda.messaging.nbtopology.request.GetFlowStatusTimestampsRequest) FlowHistoryEntry(org.openkilda.messaging.payload.history.FlowHistoryEntry) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) MessageException(org.openkilda.messaging.error.MessageException) CommandMessage(org.openkilda.messaging.command.CommandMessage) FlowResponseV2(org.openkilda.northbound.dto.v2.flows.FlowResponseV2) DiverseGroupPayload(org.openkilda.messaging.payload.flow.DiverseGroupPayload) FlowMirrorPointsDumpResponse(org.openkilda.messaging.nbtopology.response.FlowMirrorPointsDumpResponse) FlowPathPayload(org.openkilda.messaging.payload.flow.FlowPathPayload) FlowPatchRequest(org.openkilda.messaging.nbtopology.request.FlowPatchRequest) GroupFlowPathPayload(org.openkilda.messaging.payload.flow.GroupFlowPathPayload) PingInput(org.openkilda.northbound.dto.v1.flows.PingInput) FlowDeleteRequest(org.openkilda.messaging.command.flow.FlowDeleteRequest) FlowResponsePayload(org.openkilda.messaging.payload.flow.FlowResponsePayload) SwapFlowEndpointRequest(org.openkilda.messaging.command.flow.SwapFlowEndpointRequest) FlowValidationResponse(org.openkilda.messaging.info.flow.FlowValidationResponse) FlowProtectedPath(org.openkilda.messaging.payload.flow.FlowPathPayload.FlowProtectedPath) FlowPatchDto(org.openkilda.northbound.dto.v1.flows.FlowPatchDto) FlowPatchV2(org.openkilda.northbound.dto.v2.flows.FlowPatchV2) FlowMirrorPointsDumpRequest(org.openkilda.messaging.nbtopology.request.FlowMirrorPointsDumpRequest) Predicate(java.util.function.Predicate) GetFlowPathRequest(org.openkilda.messaging.nbtopology.request.GetFlowPathRequest) FlowDto(org.openkilda.messaging.model.FlowDto) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) FlowMirrorPointPayload(org.openkilda.northbound.dto.v2.flows.FlowMirrorPointPayload) FlowResponse(org.openkilda.messaging.info.flow.FlowResponse) FlowService(org.openkilda.northbound.service.FlowService) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) FLOW_ID(org.openkilda.messaging.Utils.FLOW_ID) List(java.util.List) FlowMirrorPointCreateRequest(org.openkilda.messaging.command.flow.FlowMirrorPointCreateRequest) BatchResults(org.openkilda.northbound.dto.BatchResults) FlowConnectedDevicesResponse(org.openkilda.northbound.dto.v1.flows.FlowConnectedDevicesResponse) FlowValidationRequest(org.openkilda.messaging.command.flow.FlowValidationRequest) FlowPatch(org.openkilda.messaging.model.FlowPatch) FlowsDumpRequest(org.openkilda.messaging.nbtopology.request.FlowsDumpRequest) Optional(java.util.Optional) FlowValidationDto(org.openkilda.northbound.dto.v1.flows.FlowValidationDto) GetFlowLoopsRequest(org.openkilda.messaging.nbtopology.request.GetFlowLoopsRequest) CreateFlowLoopRequest(org.openkilda.messaging.command.flow.CreateFlowLoopRequest) CompletableFuture(java.util.concurrent.CompletableFuture) SwapFlowEndpointPayload(org.openkilda.northbound.dto.v2.flows.SwapFlowEndpointPayload) Function(java.util.function.Function) FlowMirrorPointResponseV2(org.openkilda.northbound.dto.v2.flows.FlowMirrorPointResponseV2) PathMapper(org.openkilda.northbound.converter.PathMapper) FlowLoopResponse(org.openkilda.northbound.dto.v2.flows.FlowLoopResponse) ArrayList(java.util.ArrayList) PingOutput(org.openkilda.northbound.dto.v1.flows.PingOutput) Value(org.springframework.beans.factory.annotation.Value) FlowPingRequest(org.openkilda.messaging.command.flow.FlowPingRequest) Type(org.openkilda.messaging.command.flow.FlowRequest.Type) FlowIdStatusPayload(org.openkilda.messaging.payload.flow.FlowIdStatusPayload) MeterModifyRequest(org.openkilda.messaging.nbtopology.request.MeterModifyRequest) GetFlowPathResponse(org.openkilda.messaging.nbtopology.response.GetFlowPathResponse) FlowRequestV2(org.openkilda.northbound.dto.v2.flows.FlowRequestV2) Service(org.springframework.stereotype.Service) MessagingChannel(org.openkilda.northbound.messaging.MessagingChannel) FlowRerouteRequest.createManualFlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest.createManualFlowRerouteRequest) FlowPathSwapRequest(org.openkilda.messaging.command.flow.FlowPathSwapRequest) FlowPathDto(org.openkilda.messaging.model.FlowPathDto) FlowLoopsResponse(org.openkilda.messaging.nbtopology.response.FlowLoopsResponse) FlowProtectedPathDto(org.openkilda.messaging.model.FlowPathDto.FlowProtectedPathDto) FlowMapper(org.openkilda.northbound.converter.FlowMapper) FlowRerouteResponse(org.openkilda.messaging.info.flow.FlowRerouteResponse) FlowMirrorPointDeleteRequest(org.openkilda.messaging.command.flow.FlowMirrorPointDeleteRequest) CorrelationIdFactory(org.openkilda.northbound.utils.CorrelationIdFactory) AsyncUtils.collectResponses(org.openkilda.northbound.utils.async.AsyncUtils.collectResponses) FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) Logger(org.slf4j.Logger) DeleteFlowLoopRequest(org.openkilda.messaging.command.flow.DeleteFlowLoopRequest) ErrorType(org.openkilda.messaging.error.ErrorType) FlowMeterEntries(org.openkilda.messaging.info.meter.FlowMeterEntries) FlowStatusTimestampsEntry(org.openkilda.messaging.payload.history.FlowStatusTimestampsEntry) RequestCorrelationId(org.openkilda.northbound.utils.RequestCorrelationId) FlowPingResponse(org.openkilda.messaging.info.flow.FlowPingResponse) FlowRerouteResponseV2(org.openkilda.northbound.dto.v2.flows.FlowRerouteResponseV2) FlowUpdatePayload(org.openkilda.messaging.payload.flow.FlowUpdatePayload) FlowConnectedDeviceRequest(org.openkilda.messaging.nbtopology.request.FlowConnectedDeviceRequest) SwitchId(org.openkilda.model.SwitchId) FlowReroutePayload(org.openkilda.messaging.payload.flow.FlowReroutePayload) ConnectedDeviceMapper(org.openkilda.northbound.converter.ConnectedDeviceMapper) Destination(org.openkilda.messaging.Destination) GetFlowHistoryRequest(org.openkilda.messaging.nbtopology.request.GetFlowHistoryRequest) FlowMirrorPointsResponseV2(org.openkilda.northbound.dto.v2.flows.FlowMirrorPointsResponseV2) Collections(java.util.Collections) FlowMirrorPointResponse(org.openkilda.messaging.info.flow.FlowMirrorPointResponse) FlowHistoryStatusesResponse(org.openkilda.northbound.dto.v2.flows.FlowHistoryStatusesResponse) SwapFlowResponse(org.openkilda.messaging.info.flow.SwapFlowResponse) FlowCreatePayload(org.openkilda.messaging.payload.flow.FlowCreatePayload) FlowPathDto(org.openkilda.messaging.model.FlowPathDto) FlowProtectedPathDto(org.openkilda.messaging.model.FlowPathDto.FlowProtectedPathDto) FlowPathPayload(org.openkilda.messaging.payload.flow.FlowPathPayload) GroupFlowPathPayload(org.openkilda.messaging.payload.flow.GroupFlowPathPayload)

Example 4 with FlowPathDto

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

the class FlowOperationsService method getFlowPath.

/**
 * Returns flow path. If flow has group, returns also path for each flow in group.
 *
 * @param flowId the flow to get a path.
 */
public List<FlowPathDto> getFlowPath(String flowId) throws FlowNotFoundException {
    flowDashboardLogger.onFlowPathsRead(flowId);
    Flow flow = flowRepository.findById(flowId).orElseThrow(() -> new FlowNotFoundException(flowId));
    String groupId = flow.getDiverseGroupId();
    if (groupId == null) {
        return Collections.singletonList(toFlowPathDtoBuilder(flow).build());
    } else {
        Collection<Flow> flowsInGroup = flowRepository.findByDiverseGroupId(groupId);
        Collection<FlowPath> flowPathsInGroup = flowPathRepository.findByFlowGroupId(groupId);
        IntersectionComputer primaryIntersectionComputer = new IntersectionComputer(flow.getFlowId(), flow.getForwardPathId(), flow.getReversePathId(), flowPathsInGroup);
        // target flow primary path
        FlowPathDtoBuilder targetFlowDtoBuilder = this.toFlowPathDtoBuilder(flow).segmentsStats(primaryIntersectionComputer.getOverlappingStats());
        // other flows in the the group
        List<FlowPathDto> payloads = flowsInGroup.stream().filter(e -> !e.getFlowId().equals(flowId)).map(e -> this.mapGroupPathFlowDto(e, true, primaryIntersectionComputer)).collect(Collectors.toList());
        if (flow.isAllocateProtectedPath()) {
            IntersectionComputer protectedIntersectionComputer = new IntersectionComputer(flow.getFlowId(), flow.getProtectedForwardPathId(), flow.getProtectedReversePathId(), flowPathsInGroup);
            // target flow protected path
            targetFlowDtoBuilder.protectedPath(FlowProtectedPathDto.builder().forwardPath(buildPathFromFlow(flow, flow.getProtectedForwardPath())).reversePath(buildPathFromFlow(flow, flow.getProtectedReversePath())).segmentsStats(protectedIntersectionComputer.getOverlappingStats()).build());
            // other flows in the the group
            List<FlowPathDto> protectedPathPayloads = flowsInGroup.stream().filter(e -> !e.getFlowId().equals(flowId)).map(e -> this.mapGroupPathFlowDto(e, false, protectedIntersectionComputer)).collect(Collectors.toList());
            payloads = union(payloads, protectedPathPayloads);
        }
        payloads.add(targetFlowDtoBuilder.build());
        return payloads;
    }
}
Also used : MAX_LATENCY(org.openkilda.model.PathComputationStrategy.MAX_LATENCY) FlowStats(org.openkilda.model.FlowStats) IslNotFoundException(org.openkilda.wfm.error.IslNotFoundException) FlowPath(org.openkilda.model.FlowPath) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) MessageException(org.openkilda.messaging.error.MessageException) FlowMirrorPoint(org.openkilda.messaging.nbtopology.response.FlowMirrorPointsDumpResponse.FlowMirrorPoint) Flow(org.openkilda.model.Flow) IntersectionComputer(org.openkilda.wfm.share.service.IntersectionComputer) Duration(java.time.Duration) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) SwitchConnectedDeviceRepository(org.openkilda.persistence.repositories.SwitchConnectedDeviceRepository) IslEndpoint(org.openkilda.model.IslEndpoint) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) PathComputationStrategy(org.openkilda.model.PathComputationStrategy) YSubFlow(org.openkilda.model.YSubFlow) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) Collection(java.util.Collection) Set(java.util.Set) RetryPolicy(net.jodah.failsafe.RetryPolicy) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Sets(com.google.common.collect.Sets) FlowResponse(org.openkilda.messaging.info.flow.FlowResponse) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) Objects(java.util.Objects) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Stream(java.util.stream.Stream) FlowPatch(org.openkilda.messaging.model.FlowPatch) Builder(lombok.Builder) FlowsDumpRequest(org.openkilda.messaging.nbtopology.request.FlowsDumpRequest) DetectConnectedDevicesDto(org.openkilda.messaging.model.DetectConnectedDevicesDto) Optional(java.util.Optional) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) ListUtils.union(org.apache.commons.collections4.ListUtils.union) TransactionManager(org.openkilda.persistence.tx.TransactionManager) FlowStatsRepository(org.openkilda.persistence.repositories.FlowStatsRepository) FlowPathMapper(org.openkilda.wfm.share.mappers.FlowPathMapper) PathNodePayload(org.openkilda.messaging.payload.flow.PathNodePayload) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) PatchEndpoint(org.openkilda.messaging.model.PatchEndpoint) FlowPathDtoBuilder(org.openkilda.messaging.model.FlowPathDto.FlowPathDtoBuilder) IslRepository(org.openkilda.persistence.repositories.IslRepository) FlowPathDto(org.openkilda.messaging.model.FlowPathDto) YFlow(org.openkilda.model.YFlow) FlowProtectedPathDto(org.openkilda.messaging.model.FlowPathDto.FlowProtectedPathDto) FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) FlowEndpoint(org.openkilda.model.FlowEndpoint) RequestedFlowMapper(org.openkilda.wfm.share.mappers.RequestedFlowMapper) FlowOperationsDashboardLogger(org.openkilda.wfm.share.logger.FlowOperationsDashboardLogger) ErrorType(org.openkilda.messaging.error.ErrorType) LATENCY(org.openkilda.model.PathComputationStrategy.LATENCY) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) FlowMapper(org.openkilda.wfm.share.mappers.FlowMapper) FlowFilter(org.openkilda.model.FlowFilter) SwitchId(org.openkilda.model.SwitchId) FlowOperationsCarrier(org.openkilda.wfm.topology.nbworker.bolts.FlowOperationsCarrier) Data(lombok.Data) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) SwitchConnectedDevice(org.openkilda.model.SwitchConnectedDevice) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) FlowPathDto(org.openkilda.messaging.model.FlowPathDto) FlowPathDtoBuilder(org.openkilda.messaging.model.FlowPathDto.FlowPathDtoBuilder) IntersectionComputer(org.openkilda.wfm.share.service.IntersectionComputer) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow) YSubFlow(org.openkilda.model.YSubFlow) YFlow(org.openkilda.model.YFlow)

Aggregations

FlowPathDto (org.openkilda.messaging.model.FlowPathDto)4 String.format (java.lang.String.format)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Optional (java.util.Optional)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 FlowRequest (org.openkilda.messaging.command.flow.FlowRequest)2 FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)2 ErrorType (org.openkilda.messaging.error.ErrorType)2 MessageException (org.openkilda.messaging.error.MessageException)2 FlowResponse (org.openkilda.messaging.info.flow.FlowResponse)2 UpdateFlowCommand (org.openkilda.messaging.info.flow.UpdateFlowCommand)2 FlowPatch (org.openkilda.messaging.model.FlowPatch)2 FlowProtectedPathDto (org.openkilda.messaging.model.FlowPathDto.FlowProtectedPathDto)2 FlowsDumpRequest (org.openkilda.messaging.nbtopology.request.FlowsDumpRequest)2 SwitchId (org.openkilda.model.SwitchId)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Lists (com.google.common.collect.Lists)1