@Test public void shouldDetectSame3SwitchPaths() { SwitchId switchId1 = new SwitchId(1); Switch switch1 = Switch.builder().switchId(switchId1).build(); SwitchId switchId2 = new SwitchId(2); Switch switch2 = Switch.builder().switchId(switchId2).build(); SwitchId switchId3 = new SwitchId(3); Switch switch3 = Switch.builder().switchId(switchId3).build(); 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(); FlowPath flowPath = FlowPath.builder() .srcSwitch(switch1) .destSwitch(switch2) .pathId(new PathId("test_path_id")) .segments(asList( PathSegment.builder().srcSwitch(switch1).srcPort(1).destSwitch(switch3).destPort(2).build(), PathSegment.builder().srcSwitch(switch3).srcPort(1).destSwitch(switch2).destPort(2).build())) .build(); assertTrue(builder.isSamePath(path, flowPath)); }
public boolean isSamePath(Path path, FlowPath flowPath) { if (!path.getSrcSwitchId().equals(flowPath.getSrcSwitchId()) || !path.getDestSwitchId().equals(flowPath.getDestSwitchId()) || path.getSegments().size() != flowPath.getSegments().size()) { return false; } Iterator<Segment> pathIt = path.getSegments().iterator(); Iterator<PathSegment> flowPathIt = flowPath.getSegments().iterator(); while (pathIt.hasNext() && flowPathIt.hasNext()) { Path.Segment pathSegment = pathIt.next(); PathSegment flowSegment = flowPathIt.next(); if (!pathSegment.getSrcSwitchId().equals(flowSegment.getSrcSwitchId()) || !pathSegment.getDestSwitchId().equals(flowSegment.getDestSwitchId()) || pathSegment.getSrcPort() != flowSegment.getSrcPort() || pathSegment.getDestPort() != flowSegment.getDestPort()) { return false; } } return true; }
FlowPathBuilder { public boolean isSamePath(Path path, FlowPath flowPath) { if (!path.getSrcSwitchId().equals(flowPath.getSrcSwitchId()) || !path.getDestSwitchId().equals(flowPath.getDestSwitchId()) || path.getSegments().size() != flowPath.getSegments().size()) { return false; } Iterator<Segment> pathIt = path.getSegments().iterator(); Iterator<PathSegment> flowPathIt = flowPath.getSegments().iterator(); while (pathIt.hasNext() && flowPathIt.hasNext()) { Path.Segment pathSegment = pathIt.next(); PathSegment flowSegment = flowPathIt.next(); if (!pathSegment.getSrcSwitchId().equals(flowSegment.getSrcSwitchId()) || !pathSegment.getDestSwitchId().equals(flowSegment.getDestSwitchId()) || pathSegment.getSrcPort() != flowSegment.getSrcPort() || pathSegment.getDestPort() != flowSegment.getDestPort()) { return false; } } return true; } }
FlowPathBuilder { public boolean isSamePath(Path path, FlowPath flowPath) { if (!path.getSrcSwitchId().equals(flowPath.getSrcSwitchId()) || !path.getDestSwitchId().equals(flowPath.getDestSwitchId()) || path.getSegments().size() != flowPath.getSegments().size()) { return false; } Iterator<Segment> pathIt = path.getSegments().iterator(); Iterator<PathSegment> flowPathIt = flowPath.getSegments().iterator(); while (pathIt.hasNext() && flowPathIt.hasNext()) { Path.Segment pathSegment = pathIt.next(); PathSegment flowSegment = flowPathIt.next(); if (!pathSegment.getSrcSwitchId().equals(flowSegment.getSrcSwitchId()) || !pathSegment.getDestSwitchId().equals(flowSegment.getDestSwitchId()) || pathSegment.getSrcPort() != flowSegment.getSrcPort() || pathSegment.getDestPort() != flowSegment.getDestPort()) { return false; } } return true; }  }
FlowPathBuilder { public boolean isSamePath(Path path, FlowPath flowPath) { if (!path.getSrcSwitchId().equals(flowPath.getSrcSwitchId()) || !path.getDestSwitchId().equals(flowPath.getDestSwitchId()) || path.getSegments().size() != flowPath.getSegments().size()) { return false; } Iterator<Segment> pathIt = path.getSegments().iterator(); Iterator<PathSegment> flowPathIt = flowPath.getSegments().iterator(); while (pathIt.hasNext() && flowPathIt.hasNext()) { Path.Segment pathSegment = pathIt.next(); PathSegment flowSegment = flowPathIt.next(); if (!pathSegment.getSrcSwitchId().equals(flowSegment.getSrcSwitchId()) || !pathSegment.getDestSwitchId().equals(flowSegment.getDestSwitchId()) || pathSegment.getSrcPort() != flowSegment.getSrcPort() || pathSegment.getDestPort() != flowSegment.getDestPort()) { return false; } } return true; }  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 boolean isSamePath(Path path, FlowPath flowPath) { if (!path.getSrcSwitchId().equals(flowPath.getSrcSwitchId()) || !path.getDestSwitchId().equals(flowPath.getDestSwitchId()) || path.getSegments().size() != flowPath.getSegments().size()) { return false; } Iterator<Segment> pathIt = path.getSegments().iterator(); Iterator<PathSegment> flowPathIt = flowPath.getSegments().iterator(); while (pathIt.hasNext() && flowPathIt.hasNext()) { Path.Segment pathSegment = pathIt.next(); PathSegment flowSegment = flowPathIt.next(); if (!pathSegment.getSrcSwitchId().equals(flowSegment.getSrcSwitchId()) || !pathSegment.getDestSwitchId().equals(flowSegment.getDestSwitchId()) || pathSegment.getSrcPort() != flowSegment.getSrcPort() || pathSegment.getDestPort() != flowSegment.getDestPort()) { return false; } } return true; }  boolean isSamePath(Path path, FlowPath flowPath); boolean arePathsOverlapped(Path path, FlowPath flowPath); FlowPath buildFlowPath(Flow flow, PathResources pathResources, Path path, FlowSegmentCookie cookie,
                                  boolean forceToIgnoreBandwidth);  }