use of org.openkilda.pce.Path.Segment in project open-kilda by telstra.
the class FlowPathBuilder method isSamePath.
/**
* Check whether the path and flow path represent the same.
*
* @param path the path to evaluate.
* @param flowPath the flow path to evaluate.
*/
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;
}
use of org.openkilda.pce.Path.Segment in project open-kilda by telstra.
the class FlowPathBuilder method buildPathSegments.
/**
* Build a path segments using provided path.
*
* @param pathId a pathId the segments will be associated with.
* @param pathForSegments path to be used for the segments.
* @param bandwidth bandwidth to be used for the segments.
* @param ignoreBandwidth ignore bandwidth be used for the segments.
* @param sharedBandwidthGroupId a shared bandwidth group to be set for the segments
*/
public List<PathSegment> buildPathSegments(PathId pathId, Path pathForSegments, long bandwidth, boolean ignoreBandwidth, String sharedBandwidthGroupId) {
Map<SwitchId, SwitchProperties> switchProperties = getSwitchProperties(pathId);
List<PathSegment> result = new ArrayList<>();
for (int i = 0; i < pathForSegments.getSegments().size(); i++) {
Path.Segment segment = pathForSegments.getSegments().get(i);
SwitchProperties srcSwitchProperties = switchProperties.get(segment.getSrcSwitchId());
SwitchProperties dstSwitchProperties = switchProperties.get(segment.getDestSwitchId());
result.add(PathSegment.builder().seqId(i).pathId(pathId).srcSwitch(Switch.builder().switchId(segment.getSrcSwitchId()).build()).srcPort(segment.getSrcPort()).srcWithMultiTable(srcSwitchProperties.isMultiTable()).destSwitch(Switch.builder().switchId(segment.getDestSwitchId()).build()).destPort(segment.getDestPort()).destWithMultiTable(dstSwitchProperties.isMultiTable()).latency(segment.getLatency()).bandwidth(bandwidth).ignoreBandwidth(ignoreBandwidth).sharedBandwidthGroupId(sharedBandwidthGroupId).build());
}
return result;
}
use of org.openkilda.pce.Path.Segment in project open-kilda by telstra.
the class PathMapper method map.
/**
* Convert {@link org.openkilda.pce.Path} to {@link org.openkilda.messaging.info.network.Path}.
*/
public org.openkilda.messaging.info.network.Path map(org.openkilda.pce.Path path) {
if (path == null || path.getSegments().isEmpty()) {
return new org.openkilda.messaging.info.network.Path(0L, Duration.ZERO, new ArrayList<>());
}
List<PathNodePayload> nodes = new ArrayList<>();
List<Path.Segment> pathSegments = path.getSegments();
if (!pathSegments.isEmpty()) {
Segment firstSegment = pathSegments.get(0);
nodes.add(new PathNodePayload(firstSegment.getSrcSwitchId(), null, firstSegment.getSrcPort()));
for (int i = 1; i < pathSegments.size(); i++) {
Path.Segment inputNode = pathSegments.get(i - 1);
Path.Segment outputNode = pathSegments.get(i);
nodes.add(new PathNodePayload(inputNode.getDestSwitchId(), inputNode.getDestPort(), outputNode.getSrcPort()));
}
Segment lastSegment = pathSegments.get(pathSegments.size() - 1);
nodes.add(new PathNodePayload(lastSegment.getDestSwitchId(), lastSegment.getDestPort(), null));
}
return new org.openkilda.messaging.info.network.Path(path.getMinAvailableBandwidth(), Duration.ofNanos(path.getLatency()), nodes);
}
use of org.openkilda.pce.Path.Segment in project open-kilda by telstra.
the class InMemoryPathComputerBaseTest method shouldFindAffinityPathOnDiamond.
void shouldFindAffinityPathOnDiamond(PathComputationStrategy pathComputationStrategy) throws Exception {
createDiamondWithAffinity();
Flow flow = Flow.builder().flowId("new-flow").affinityGroupId(TEST_FLOW_ID).bandwidth(10).srcSwitch(getSwitchById("00:0A")).destSwitch(getSwitchById("00:0D")).encapsulationType(FlowEncapsulationType.TRANSIT_VLAN).pathComputationStrategy(pathComputationStrategy).build();
PathComputer pathComputer = pathComputerFactory.getPathComputer();
GetPathsResult affinityPath = pathComputer.getPath(flow);
List<Segment> segments = affinityPath.getForward().getSegments();
assertEquals(new SwitchId("00:0B"), segments.get(1).getSrcSwitchId());
assertEquals(new SwitchId("00:0B"), segments.get(0).getDestSwitchId());
}
use of org.openkilda.pce.Path.Segment in project open-kilda by telstra.
the class InMemoryPathComputerBaseTest method affinityPathShouldSplitAsCloseAsPossibleToDestination.
void affinityPathShouldSplitAsCloseAsPossibleToDestination(PathComputationStrategy pathComputationStrategy) throws Exception {
createTestTopologyForAffinityTesting();
Flow flow = Flow.builder().flowId("new-flow").affinityGroupId(TEST_FLOW_ID).bandwidth(10).srcSwitch(getSwitchById("00:0A")).destSwitch(getSwitchById("00:03")).encapsulationType(FlowEncapsulationType.TRANSIT_VLAN).pathComputationStrategy(pathComputationStrategy).build();
PathComputer pathComputer = pathComputerFactory.getPathComputer();
GetPathsResult affinityPath = pathComputer.getPath(flow);
List<Segment> segments = affinityPath.getForward().getSegments();
assertEquals(3, segments.size());
assertEquals(new SwitchId("00:0A"), segments.get(0).getSrcSwitchId());
assertEquals(new SwitchId("00:0B"), segments.get(1).getSrcSwitchId());
assertEquals(new SwitchId("00:0C"), segments.get(2).getSrcSwitchId());
assertEquals(new SwitchId("00:0B"), segments.get(0).getDestSwitchId());
assertEquals(new SwitchId("00:0C"), segments.get(1).getDestSwitchId());
assertEquals(new SwitchId("00:03"), segments.get(2).getDestSwitchId());
}
Aggregations