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