@Test public void shouldBuildFlowPathFor3SwitchPath() { SwitchId switchId1 = new SwitchId(1); SwitchId switchId2 = new SwitchId(2); SwitchId switchId3 = new SwitchId(3); Path path = Path.builder() .srcSwitchId(switchId1) .destSwitchId(switchId2) .segments(asList(Segment.builder() .srcSwitchId(switchId1) .srcPort(1) .destSwitchId(switchId3) .destPort(2) .build(), Segment.builder() .srcSwitchId(switchId3) .srcPort(1) .destSwitchId(switchId2) .destPort(2) .build())) .build(); Flow flow = Flow.builder() .flowId("test_flow") .srcSwitch(Switch.builder().switchId(switchId1).build()) .destSwitch(Switch.builder().switchId(switchId2).build()) .build(); PathId pathId = new PathId("test_path_id"); MeterId meterId = new MeterId(MeterId.MIN_FLOW_METER_ID); PathResources pathResources = PathResources.builder() .pathId(pathId) .meterId(meterId) .build(); FlowSegmentCookie cookie = new FlowSegmentCookie(FlowPathDirection.FORWARD, 1); FlowPath flowPath = builder.buildFlowPath(flow, pathResources, path, cookie, false); assertEquals(switchId1, flowPath.getSrcSwitchId()); assertEquals(switchId2, flowPath.getDestSwitchId()); assertEquals(pathId, flowPath.getPathId()); assertEquals(meterId, flowPath.getMeterId()); assertEquals(cookie, flowPath.getCookie()); assertThat(flowPath.getSegments(), hasSize(2)); }
public FlowPath buildFlowPath(Flow flow, PathResources pathResources, Path path, FlowSegmentCookie cookie, boolean forceToIgnoreBandwidth) { Map<SwitchId, Switch> switches = new HashMap<>(); Map<SwitchId, SwitchProperties> switchProperties = new HashMap<>(); switches.put(flow.getSrcSwitchId(), flow.getSrcSwitch()); switches.put(flow.getDestSwitchId(), flow.getDestSwitch()); Switch srcSwitch = switches.get(path.getSrcSwitchId()); if (srcSwitch == null) { throw new IllegalArgumentException(format("Path %s has different end-point %s than flow %s", pathResources.getPathId(), path.getSrcSwitchId(), flow.getFlowId())); } Switch destSwitch = switches.get(path.getDestSwitchId()); if (destSwitch == null) { throw new IllegalArgumentException(format("Path %s has different end-point %s than flow %s", pathResources.getPathId(), path.getDestSwitchId(), flow.getFlowId())); } Optional<SwitchProperties> srcSwitchProperties = switchPropertiesRepository.findBySwitchId( flow.getSrcSwitchId()); DetectConnectedDevices.DetectConnectedDevicesBuilder detectConnectedDevices = flow.getDetectConnectedDevices().toBuilder(); if (srcSwitchProperties.isPresent()) { switchProperties.put(flow.getSrcSwitchId(), srcSwitchProperties.get()); flow.setSrcWithMultiTable(srcSwitchProperties.get().isMultiTable()); detectConnectedDevices.srcSwitchLldp(srcSwitchProperties.get().isSwitchLldp()); detectConnectedDevices.srcSwitchArp(srcSwitchProperties.get().isSwitchArp()); } Optional<SwitchProperties> dstSwitchProperties = switchPropertiesRepository.findBySwitchId( flow.getDestSwitchId()); if (dstSwitchProperties.isPresent()) { switchProperties.put(flow.getDestSwitchId(), dstSwitchProperties.get()); flow.setDestWithMultiTable(dstSwitchProperties.get().isMultiTable()); detectConnectedDevices.dstSwitchLldp(dstSwitchProperties.get().isSwitchLldp()); detectConnectedDevices.dstSwitchArp(dstSwitchProperties.get().isSwitchArp()); } flow.setDetectConnectedDevices(detectConnectedDevices.build()); FlowPath flowPath = FlowPath.builder() .pathId(pathResources.getPathId()) .srcSwitch(srcSwitch) .destSwitch(destSwitch) .meterId(pathResources.getMeterId()) .cookie(cookie) .bandwidth(flow.getBandwidth()) .ignoreBandwidth(flow.isIgnoreBandwidth() || forceToIgnoreBandwidth) .latency(path.getLatency()) .build(); List<PathSegment> segments = path.getSegments().stream() .map(segment -> { Switch segmentSrcSwitch = switches.get(segment.getSrcSwitchId()); if (segmentSrcSwitch == null) { segmentSrcSwitch = switchRepository.findById(segment.getSrcSwitchId()) .orElseThrow(() -> new IllegalArgumentException( format("Path %s has unknown end-point %s", pathResources.getPathId(), segment.getSrcSwitchId()))); switches.put(segment.getSrcSwitchId(), segmentSrcSwitch); } SwitchProperties segmentSrcSwitchProperties = switchProperties.get(segment.getSrcSwitchId()); if (segmentSrcSwitchProperties == null) { segmentSrcSwitchProperties = switchPropertiesRepository.findBySwitchId(segment.getSrcSwitchId()) .orElseThrow(() -> new IllegalArgumentException( format("Path %s has end-point %s without switch properties", pathResources.getPathId(), segment.getSrcSwitchId()))); switchProperties.put(segment.getSrcSwitchId(), segmentSrcSwitchProperties); } Switch segmentDestSwitch = switches.get(segment.getDestSwitchId()); if (segmentDestSwitch == null) { segmentDestSwitch = switchRepository.findById(segment.getDestSwitchId()) .orElseThrow(() -> new IllegalArgumentException( format("Path %s has unknown end-point %s", pathResources.getPathId(), segment.getDestSwitchId()))); switches.put(segment.getDestSwitchId(), segmentDestSwitch); } SwitchProperties segmentDstSwitchProperties = switchProperties.get(segment.getDestSwitchId()); if (segmentDstSwitchProperties == null) { segmentDstSwitchProperties = switchPropertiesRepository .findBySwitchId(segment.getDestSwitchId()) .orElseThrow(() -> new IllegalArgumentException( format("Path %s has end-point %s without switch properties", pathResources.getPathId(), segment.getDestSwitchId()))); switchProperties.put(segment.getDestSwitchId(), segmentDstSwitchProperties); } return PathSegment.builder() .srcSwitch(segmentSrcSwitch) .srcWithMultiTable(segmentSrcSwitchProperties.isMultiTable()) .srcPort(segment.getSrcPort()) .destSwitch(segmentDestSwitch) .destWithMultiTable(segmentDstSwitchProperties.isMultiTable()) .destPort(segment.getDestPort()) .latency(segment.getLatency()) .build(); }) .collect(Collectors.toList()); flowPath.setSegments(segments); return flowPath; }
FlowPathBuilder { public FlowPath buildFlowPath(Flow flow, PathResources pathResources, Path path, FlowSegmentCookie cookie, boolean forceToIgnoreBandwidth) { Map<SwitchId, Switch> switches = new HashMap<>(); Map<SwitchId, SwitchProperties> switchProperties = new HashMap<>(); switches.put(flow.getSrcSwitchId(), flow.getSrcSwitch()); switches.put(flow.getDestSwitchId(), flow.getDestSwitch()); Switch srcSwitch = switches.get(path.getSrcSwitchId()); if (srcSwitch == null) { throw new IllegalArgumentException(format("Path %s has different end-point %s than flow %s", pathResources.getPathId(), path.getSrcSwitchId(), flow.getFlowId())); } Switch destSwitch = switches.get(path.getDestSwitchId()); if (destSwitch == null) { throw new IllegalArgumentException(format("Path %s has different end-point %s than flow %s", pathResources.getPathId(), path.getDestSwitchId(), flow.getFlowId())); } Optional<SwitchProperties> srcSwitchProperties = switchPropertiesRepository.findBySwitchId( flow.getSrcSwitchId()); DetectConnectedDevices.DetectConnectedDevicesBuilder detectConnectedDevices = flow.getDetectConnectedDevices().toBuilder(); if (srcSwitchProperties.isPresent()) { switchProperties.put(flow.getSrcSwitchId(), srcSwitchProperties.get()); flow.setSrcWithMultiTable(srcSwitchProperties.get().isMultiTable()); detectConnectedDevices.srcSwitchLldp(srcSwitchProperties.get().isSwitchLldp()); detectConnectedDevices.srcSwitchArp(srcSwitchProperties.get().isSwitchArp()); } Optional<SwitchProperties> dstSwitchProperties = switchPropertiesRepository.findBySwitchId( flow.getDestSwitchId()); if (dstSwitchProperties.isPresent()) { switchProperties.put(flow.getDestSwitchId(), dstSwitchProperties.get()); flow.setDestWithMultiTable(dstSwitchProperties.get().isMultiTable()); detectConnectedDevices.dstSwitchLldp(dstSwitchProperties.get().isSwitchLldp()); detectConnectedDevices.dstSwitchArp(dstSwitchProperties.get().isSwitchArp()); } flow.setDetectConnectedDevices(detectConnectedDevices.build()); FlowPath flowPath = FlowPath.builder() .pathId(pathResources.getPathId()) .srcSwitch(srcSwitch) .destSwitch(destSwitch) .meterId(pathResources.getMeterId()) .cookie(cookie) .bandwidth(flow.getBandwidth()) .ignoreBandwidth(flow.isIgnoreBandwidth() || forceToIgnoreBandwidth) .latency(path.getLatency()) .build(); List<PathSegment> segments = path.getSegments().stream() .map(segment -> { Switch segmentSrcSwitch = switches.get(segment.getSrcSwitchId()); if (segmentSrcSwitch == null) { segmentSrcSwitch = switchRepository.findById(segment.getSrcSwitchId()) .orElseThrow(() -> new IllegalArgumentException( format("Path %s has unknown end-point %s", pathResources.getPathId(), segment.getSrcSwitchId()))); switches.put(segment.getSrcSwitchId(), segmentSrcSwitch); } SwitchProperties segmentSrcSwitchProperties = switchProperties.get(segment.getSrcSwitchId()); if (segmentSrcSwitchProperties == null) { segmentSrcSwitchProperties = switchPropertiesRepository.findBySwitchId(segment.getSrcSwitchId()) .orElseThrow(() -> new IllegalArgumentException( format("Path %s has end-point %s without switch properties", pathResources.getPathId(), segment.getSrcSwitchId()))); switchProperties.put(segment.getSrcSwitchId(), segmentSrcSwitchProperties); } Switch segmentDestSwitch = switches.get(segment.getDestSwitchId()); if (segmentDestSwitch == null) { segmentDestSwitch = switchRepository.findById(segment.getDestSwitchId()) .orElseThrow(() -> new IllegalArgumentException( format("Path %s has unknown end-point %s", pathResources.getPathId(), segment.getDestSwitchId()))); switches.put(segment.getDestSwitchId(), segmentDestSwitch); } SwitchProperties segmentDstSwitchProperties = switchProperties.get(segment.getDestSwitchId()); if (segmentDstSwitchProperties == null) { segmentDstSwitchProperties = switchPropertiesRepository .findBySwitchId(segment.getDestSwitchId()) .orElseThrow(() -> new IllegalArgumentException( format("Path %s has end-point %s without switch properties", pathResources.getPathId(), segment.getDestSwitchId()))); switchProperties.put(segment.getDestSwitchId(), segmentDstSwitchProperties); } return PathSegment.builder() .srcSwitch(segmentSrcSwitch) .srcWithMultiTable(segmentSrcSwitchProperties.isMultiTable()) .srcPort(segment.getSrcPort()) .destSwitch(segmentDestSwitch) .destWithMultiTable(segmentDstSwitchProperties.isMultiTable()) .destPort(segment.getDestPort()) .latency(segment.getLatency()) .build(); }) .collect(Collectors.toList()); flowPath.setSegments(segments); return flowPath; } }
FlowPathBuilder { public FlowPath buildFlowPath(Flow flow, PathResources pathResources, Path path, FlowSegmentCookie cookie, boolean forceToIgnoreBandwidth) { Map<SwitchId, Switch> switches = new HashMap<>(); Map<SwitchId, SwitchProperties> switchProperties = new HashMap<>(); switches.put(flow.getSrcSwitchId(), flow.getSrcSwitch()); switches.put(flow.getDestSwitchId(), flow.getDestSwitch()); Switch srcSwitch = switches.get(path.getSrcSwitchId()); if (srcSwitch == null) { throw new IllegalArgumentException(format("Path %s has different end-point %s than flow %s", pathResources.getPathId(), path.getSrcSwitchId(), flow.getFlowId())); } Switch destSwitch = switches.get(path.getDestSwitchId()); if (destSwitch == null) { throw new IllegalArgumentException(format("Path %s has different end-point %s than flow %s", pathResources.getPathId(), path.getDestSwitchId(), flow.getFlowId())); } Optional<SwitchProperties> srcSwitchProperties = switchPropertiesRepository.findBySwitchId( flow.getSrcSwitchId()); DetectConnectedDevices.DetectConnectedDevicesBuilder detectConnectedDevices = flow.getDetectConnectedDevices().toBuilder(); if (srcSwitchProperties.isPresent()) { switchProperties.put(flow.getSrcSwitchId(), srcSwitchProperties.get()); flow.setSrcWithMultiTable(srcSwitchProperties.get().isMultiTable()); detectConnectedDevices.srcSwitchLldp(srcSwitchProperties.get().isSwitchLldp()); detectConnectedDevices.srcSwitchArp(srcSwitchProperties.get().isSwitchArp()); } Optional<SwitchProperties> dstSwitchProperties = switchPropertiesRepository.findBySwitchId( flow.getDestSwitchId()); if (dstSwitchProperties.isPresent()) { switchProperties.put(flow.getDestSwitchId(), dstSwitchProperties.get()); flow.setDestWithMultiTable(dstSwitchProperties.get().isMultiTable()); detectConnectedDevices.dstSwitchLldp(dstSwitchProperties.get().isSwitchLldp()); detectConnectedDevices.dstSwitchArp(dstSwitchProperties.get().isSwitchArp()); } flow.setDetectConnectedDevices(detectConnectedDevices.build()); FlowPath flowPath = FlowPath.builder() .pathId(pathResources.getPathId()) .srcSwitch(srcSwitch) .destSwitch(destSwitch) .meterId(pathResources.getMeterId()) .cookie(cookie) .bandwidth(flow.getBandwidth()) .ignoreBandwidth(flow.isIgnoreBandwidth() || forceToIgnoreBandwidth) .latency(path.getLatency()) .build(); List<PathSegment> segments = path.getSegments().stream() .map(segment -> { Switch segmentSrcSwitch = switches.get(segment.getSrcSwitchId()); if (segmentSrcSwitch == null) { segmentSrcSwitch = switchRepository.findById(segment.getSrcSwitchId()) .orElseThrow(() -> new IllegalArgumentException( format("Path %s has unknown end-point %s", pathResources.getPathId(), segment.getSrcSwitchId()))); switches.put(segment.getSrcSwitchId(), segmentSrcSwitch); } SwitchProperties segmentSrcSwitchProperties = switchProperties.get(segment.getSrcSwitchId()); if (segmentSrcSwitchProperties == null) { segmentSrcSwitchProperties = switchPropertiesRepository.findBySwitchId(segment.getSrcSwitchId()) .orElseThrow(() -> new IllegalArgumentException( format("Path %s has end-point %s without switch properties", pathResources.getPathId(), segment.getSrcSwitchId()))); switchProperties.put(segment.getSrcSwitchId(), segmentSrcSwitchProperties); } Switch segmentDestSwitch = switches.get(segment.getDestSwitchId()); if (segmentDestSwitch == null) { segmentDestSwitch = switchRepository.findById(segment.getDestSwitchId()) .orElseThrow(() -> new IllegalArgumentException( format("Path %s has unknown end-point %s", pathResources.getPathId(), segment.getDestSwitchId()))); switches.put(segment.getDestSwitchId(), segmentDestSwitch); } SwitchProperties segmentDstSwitchProperties = switchProperties.get(segment.getDestSwitchId()); if (segmentDstSwitchProperties == null) { segmentDstSwitchProperties = switchPropertiesRepository .findBySwitchId(segment.getDestSwitchId()) .orElseThrow(() -> new IllegalArgumentException( format("Path %s has end-point %s without switch properties", pathResources.getPathId(), segment.getDestSwitchId()))); switchProperties.put(segment.getDestSwitchId(), segmentDstSwitchProperties); } return PathSegment.builder() .srcSwitch(segmentSrcSwitch) .srcWithMultiTable(segmentSrcSwitchProperties.isMultiTable()) .srcPort(segment.getSrcPort()) .destSwitch(segmentDestSwitch) .destWithMultiTable(segmentDstSwitchProperties.isMultiTable()) .destPort(segment.getDestPort()) .latency(segment.getLatency()) .build(); }) .collect(Collectors.toList()); flowPath.setSegments(segments); return flowPath; }  }
FlowPathBuilder { public FlowPath buildFlowPath(Flow flow, PathResources pathResources, Path path, FlowSegmentCookie cookie, boolean forceToIgnoreBandwidth) { Map<SwitchId, Switch> switches = new HashMap<>(); Map<SwitchId, SwitchProperties> switchProperties = new HashMap<>(); switches.put(flow.getSrcSwitchId(), flow.getSrcSwitch()); switches.put(flow.getDestSwitchId(), flow.getDestSwitch()); Switch srcSwitch = switches.get(path.getSrcSwitchId()); if (srcSwitch == null) { throw new IllegalArgumentException(format("Path %s has different end-point %s than flow %s", pathResources.getPathId(), path.getSrcSwitchId(), flow.getFlowId())); } Switch destSwitch = switches.get(path.getDestSwitchId()); if (destSwitch == null) { throw new IllegalArgumentException(format("Path %s has different end-point %s than flow %s", pathResources.getPathId(), path.getDestSwitchId(), flow.getFlowId())); } Optional<SwitchProperties> srcSwitchProperties = switchPropertiesRepository.findBySwitchId( flow.getSrcSwitchId()); DetectConnectedDevices.DetectConnectedDevicesBuilder detectConnectedDevices = flow.getDetectConnectedDevices().toBuilder(); if (srcSwitchProperties.isPresent()) { switchProperties.put(flow.getSrcSwitchId(), srcSwitchProperties.get()); flow.setSrcWithMultiTable(srcSwitchProperties.get().isMultiTable()); detectConnectedDevices.srcSwitchLldp(srcSwitchProperties.get().isSwitchLldp()); detectConnectedDevices.srcSwitchArp(srcSwitchProperties.get().isSwitchArp()); } Optional<SwitchProperties> dstSwitchProperties = switchPropertiesRepository.findBySwitchId( flow.getDestSwitchId()); if (dstSwitchProperties.isPresent()) { switchProperties.put(flow.getDestSwitchId(), dstSwitchProperties.get()); flow.setDestWithMultiTable(dstSwitchProperties.get().isMultiTable()); detectConnectedDevices.dstSwitchLldp(dstSwitchProperties.get().isSwitchLldp()); detectConnectedDevices.dstSwitchArp(dstSwitchProperties.get().isSwitchArp()); } flow.setDetectConnectedDevices(detectConnectedDevices.build()); FlowPath flowPath = FlowPath.builder() .pathId(pathResources.getPathId()) .srcSwitch(srcSwitch) .destSwitch(destSwitch) .meterId(pathResources.getMeterId()) .cookie(cookie) .bandwidth(flow.getBandwidth()) .ignoreBandwidth(flow.isIgnoreBandwidth() || forceToIgnoreBandwidth) .latency(path.getLatency()) .build(); List<PathSegment> segments = path.getSegments().stream() .map(segment -> { Switch segmentSrcSwitch = switches.get(segment.getSrcSwitchId()); if (segmentSrcSwitch == null) { segmentSrcSwitch = switchRepository.findById(segment.getSrcSwitchId()) .orElseThrow(() -> new IllegalArgumentException( format("Path %s has unknown end-point %s", pathResources.getPathId(), segment.getSrcSwitchId()))); switches.put(segment.getSrcSwitchId(), segmentSrcSwitch); } SwitchProperties segmentSrcSwitchProperties = switchProperties.get(segment.getSrcSwitchId()); if (segmentSrcSwitchProperties == null) { segmentSrcSwitchProperties = switchPropertiesRepository.findBySwitchId(segment.getSrcSwitchId()) .orElseThrow(() -> new IllegalArgumentException( format("Path %s has end-point %s without switch properties", pathResources.getPathId(), segment.getSrcSwitchId()))); switchProperties.put(segment.getSrcSwitchId(), segmentSrcSwitchProperties); } Switch segmentDestSwitch = switches.get(segment.getDestSwitchId()); if (segmentDestSwitch == null) { segmentDestSwitch = switchRepository.findById(segment.getDestSwitchId()) .orElseThrow(() -> new IllegalArgumentException( format("Path %s has unknown end-point %s", pathResources.getPathId(), segment.getDestSwitchId()))); switches.put(segment.getDestSwitchId(), segmentDestSwitch); } SwitchProperties segmentDstSwitchProperties = switchProperties.get(segment.getDestSwitchId()); if (segmentDstSwitchProperties == null) { segmentDstSwitchProperties = switchPropertiesRepository .findBySwitchId(segment.getDestSwitchId()) .orElseThrow(() -> new IllegalArgumentException( format("Path %s has end-point %s without switch properties", pathResources.getPathId(), segment.getDestSwitchId()))); switchProperties.put(segment.getDestSwitchId(), segmentDstSwitchProperties); } return PathSegment.builder() .srcSwitch(segmentSrcSwitch) .srcWithMultiTable(segmentSrcSwitchProperties.isMultiTable()) .srcPort(segment.getSrcPort()) .destSwitch(segmentDestSwitch) .destWithMultiTable(segmentDstSwitchProperties.isMultiTable()) .destPort(segment.getDestPort()) .latency(segment.getLatency()) .build(); }) .collect(Collectors.toList()); flowPath.setSegments(segments); return flowPath; }  boolean isSamePath(Path path, FlowPath flowPath); boolean arePathsOverlapped(Path path, FlowPath flowPath); FlowPath buildFlowPath(Flow flow, PathResources pathResources, Path path, FlowSegmentCookie cookie,
                                  boolean forceToIgnoreBandwidth); }
FlowPathBuilder { public FlowPath buildFlowPath(Flow flow, PathResources pathResources, Path path, FlowSegmentCookie cookie, boolean forceToIgnoreBandwidth) { Map<SwitchId, Switch> switches = new HashMap<>(); Map<SwitchId, SwitchProperties> switchProperties = new HashMap<>(); switches.put(flow.getSrcSwitchId(), flow.getSrcSwitch()); switches.put(flow.getDestSwitchId(), flow.getDestSwitch()); Switch srcSwitch = switches.get(path.getSrcSwitchId()); if (srcSwitch == null) { throw new IllegalArgumentException(format("Path %s has different end-point %s than flow %s", pathResources.getPathId(), path.getSrcSwitchId(), flow.getFlowId())); } Switch destSwitch = switches.get(path.getDestSwitchId()); if (destSwitch == null) { throw new IllegalArgumentException(format("Path %s has different end-point %s than flow %s", pathResources.getPathId(), path.getDestSwitchId(), flow.getFlowId())); } Optional<SwitchProperties> srcSwitchProperties = switchPropertiesRepository.findBySwitchId( flow.getSrcSwitchId()); DetectConnectedDevices.DetectConnectedDevicesBuilder detectConnectedDevices = flow.getDetectConnectedDevices().toBuilder(); if (srcSwitchProperties.isPresent()) { switchProperties.put(flow.getSrcSwitchId(), srcSwitchProperties.get()); flow.setSrcWithMultiTable(srcSwitchProperties.get().isMultiTable()); detectConnectedDevices.srcSwitchLldp(srcSwitchProperties.get().isSwitchLldp()); detectConnectedDevices.srcSwitchArp(srcSwitchProperties.get().isSwitchArp()); } Optional<SwitchProperties> dstSwitchProperties = switchPropertiesRepository.findBySwitchId( flow.getDestSwitchId()); if (dstSwitchProperties.isPresent()) { switchProperties.put(flow.getDestSwitchId(), dstSwitchProperties.get()); flow.setDestWithMultiTable(dstSwitchProperties.get().isMultiTable()); detectConnectedDevices.dstSwitchLldp(dstSwitchProperties.get().isSwitchLldp()); detectConnectedDevices.dstSwitchArp(dstSwitchProperties.get().isSwitchArp()); } flow.setDetectConnectedDevices(detectConnectedDevices.build()); FlowPath flowPath = FlowPath.builder() .pathId(pathResources.getPathId()) .srcSwitch(srcSwitch) .destSwitch(destSwitch) .meterId(pathResources.getMeterId()) .cookie(cookie) .bandwidth(flow.getBandwidth()) .ignoreBandwidth(flow.isIgnoreBandwidth() || forceToIgnoreBandwidth) .latency(path.getLatency()) .build(); List<PathSegment> segments = path.getSegments().stream() .map(segment -> { Switch segmentSrcSwitch = switches.get(segment.getSrcSwitchId()); if (segmentSrcSwitch == null) { segmentSrcSwitch = switchRepository.findById(segment.getSrcSwitchId()) .orElseThrow(() -> new IllegalArgumentException( format("Path %s has unknown end-point %s", pathResources.getPathId(), segment.getSrcSwitchId()))); switches.put(segment.getSrcSwitchId(), segmentSrcSwitch); } SwitchProperties segmentSrcSwitchProperties = switchProperties.get(segment.getSrcSwitchId()); if (segmentSrcSwitchProperties == null) { segmentSrcSwitchProperties = switchPropertiesRepository.findBySwitchId(segment.getSrcSwitchId()) .orElseThrow(() -> new IllegalArgumentException( format("Path %s has end-point %s without switch properties", pathResources.getPathId(), segment.getSrcSwitchId()))); switchProperties.put(segment.getSrcSwitchId(), segmentSrcSwitchProperties); } Switch segmentDestSwitch = switches.get(segment.getDestSwitchId()); if (segmentDestSwitch == null) { segmentDestSwitch = switchRepository.findById(segment.getDestSwitchId()) .orElseThrow(() -> new IllegalArgumentException( format("Path %s has unknown end-point %s", pathResources.getPathId(), segment.getDestSwitchId()))); switches.put(segment.getDestSwitchId(), segmentDestSwitch); } SwitchProperties segmentDstSwitchProperties = switchProperties.get(segment.getDestSwitchId()); if (segmentDstSwitchProperties == null) { segmentDstSwitchProperties = switchPropertiesRepository .findBySwitchId(segment.getDestSwitchId()) .orElseThrow(() -> new IllegalArgumentException( format("Path %s has end-point %s without switch properties", pathResources.getPathId(), segment.getDestSwitchId()))); switchProperties.put(segment.getDestSwitchId(), segmentDstSwitchProperties); } return PathSegment.builder() .srcSwitch(segmentSrcSwitch) .srcWithMultiTable(segmentSrcSwitchProperties.isMultiTable()) .srcPort(segment.getSrcPort()) .destSwitch(segmentDestSwitch) .destWithMultiTable(segmentDstSwitchProperties.isMultiTable()) .destPort(segment.getDestPort()) .latency(segment.getLatency()) .build(); }) .collect(Collectors.toList()); flowPath.setSegments(segments); return flowPath; }  boolean isSamePath(Path path, FlowPath flowPath); boolean arePathsOverlapped(Path path, FlowPath flowPath); FlowPath buildFlowPath(Flow flow, PathResources pathResources, Path path, FlowSegmentCookie cookie,
                                  boolean forceToIgnoreBandwidth);  }