use of org.openkilda.model.PathSegment in project open-kilda by telstra.
the class StartReroutingYFlowAction method perform.
@Override
protected void perform(State from, State to, Event event, YFlowRerouteContext context, YFlowRerouteFsm stateMachine) {
String yFlowId = stateMachine.getYFlowId();
List<FlowPath> flowPaths = transactionManager.doInTransaction(() -> {
YFlow yFlow = getYFlow(yFlowId);
saveOldResources(stateMachine, yFlow);
stateMachine.setDeleteOldYFlowCommands(buildYFlowDeleteCommands(yFlow, stateMachine.getCommandContext()));
SwitchId sharedSwitchId = yFlow.getSharedEndpoint().getSwitchId();
return yFlow.getSubFlows().stream().map(YSubFlow::getFlow).flatMap(flow -> Stream.of(flow.getForwardPath(), flow.getReversePath())).filter(path -> sharedSwitchId.equals(path.getSrcSwitchId())).collect(Collectors.toList());
});
stateMachine.setOldYFlowPathCookies(flowPaths.stream().map(FlowPath::getCookie).map(FlowSegmentCookie::getValue).collect(Collectors.toList()));
List<PathSegment> sharedPathSegments = IntersectionComputer.calculatePathIntersectionFromSource(flowPaths);
PathInfoData sharedPath = FlowPathMapper.INSTANCE.map(sharedPathSegments);
stateMachine.setOldSharedPath(sharedPath);
List<SubFlowPathDto> subFlowPathDtos = flowPaths.stream().map(flowPath -> new SubFlowPathDto(flowPath.getFlowId(), FlowPathMapper.INSTANCE.map(flowPath))).sorted(Comparator.comparing(SubFlowPathDto::getFlowId)).collect(Collectors.toList());
stateMachine.setOldSubFlowPathDtos(subFlowPathDtos);
}
use of org.openkilda.model.PathSegment in project open-kilda by telstra.
the class AvailableNetwork method processDiversitySegmentsWithPop.
/**
* Adds diversity weights into {@link AvailableNetwork} based on passed path segments and configuration.
*/
public void processDiversitySegmentsWithPop(List<PathSegment> segments) {
if (segments.size() <= 1) {
return;
}
Set<String> allocatedPopSet = new HashSet<>();
for (PathSegment ps : segments) {
allocatedPopSet.add(ps.getSrcSwitch().getPop());
allocatedPopSet.add(ps.getDestSwitch().getPop());
}
String inPop = segments.get(0).getSrcSwitch().getPop();
allocatedPopSet.remove(inPop);
String outPop = segments.get(segments.size() - 1).getDestSwitch().getPop();
allocatedPopSet.remove(outPop);
for (Edge edge : edges) {
String srcPop = edge.getSrcSwitch().getPop();
if (srcPop != null && allocatedPopSet.contains(srcPop)) {
edge.increaseDiversityGroupPerPopUseCounter();
continue;
}
String dstPop = edge.getDestSwitch().getPop();
if (dstPop != null && allocatedPopSet.contains(dstPop)) {
edge.increaseDiversityGroupPerPopUseCounter();
continue;
}
}
}
use of org.openkilda.model.PathSegment in project open-kilda by telstra.
the class AvailableNetwork method processDiversitySegments.
/**
* Adds diversity weights into {@link AvailableNetwork} based on passed path segments and configuration.
*/
public void processDiversitySegments(List<PathSegment> segments, Flow flow) {
Set<SwitchId> terminatingSwitches = newHashSet(flow.getSrcSwitchId(), flow.getDestSwitchId());
for (PathSegment segment : segments) {
Node srcNode = getSwitch(segment.getSrcSwitchId());
Node dstNode = getSwitch(segment.getDestSwitchId());
if (dstNode != null && !terminatingSwitches.contains(dstNode.getSwitchId())) {
dstNode.increaseDiversityGroupUseCounter();
}
if (srcNode != null && segment.getSeqId() == 0 && !terminatingSwitches.contains(srcNode.getSwitchId())) {
srcNode.increaseDiversityGroupUseCounter();
}
if (srcNode == null || dstNode == null) {
log.debug("Diversity segment {} don't present in AvailableNetwork", segment);
continue;
}
Edge segmentEdge = Edge.builder().srcSwitch(srcNode).srcPort(segment.getSrcPort()).destSwitch(dstNode).destPort(segment.getDestPort()).build();
Optional<Edge> edgeOptional = dstNode.getIncomingLinks().stream().filter(segmentEdge::equals).findAny();
if (edgeOptional.isPresent()) {
Edge edge = edgeOptional.get();
edge.increaseDiversityGroupUseCounter();
}
}
}
use of org.openkilda.model.PathSegment in project open-kilda by telstra.
the class AvailableNetwork method processAffinitySegments.
/**
* Adds affinity weights into {@link AvailableNetwork} based on passed path segments and configuration.
*/
public void processAffinitySegments(List<PathSegment> segments) {
Set<Edge> pathEdges = new HashSet<>();
for (PathSegment segment : segments) {
Node srcNode = getSwitch(segment.getSrcSwitchId());
Node dstNode = getSwitch(segment.getDestSwitchId());
if (srcNode == null || dstNode == null) {
log.debug("Affinity segment {} doesn't present in AvailableNetwork", segment);
continue;
}
Edge segmentEdge = Edge.builder().srcSwitch(srcNode).srcPort(segment.getSrcPort()).destSwitch(dstNode).destPort(segment.getDestPort()).build();
pathEdges.add(segmentEdge);
Edge reverseSegmentEdge = segmentEdge.swap();
pathEdges.add(reverseSegmentEdge);
}
edges.stream().filter(edge -> !pathEdges.contains(edge)).forEach(Edge::increaseAffinityGroupUseCounter);
}
use of org.openkilda.model.PathSegment in project open-kilda by telstra.
the class PersistenceDummyEntityFactory method makePathSegments.
private List<PathSegment> makePathSegments(PathId pathId, SwitchId sourceSwitchId, SwitchId destSwitchId, List<IslDirectionalReference> pathHint) {
List<PathSegment> results = new ArrayList<>();
IslDirectionalReference first = null;
IslDirectionalReference last = null;
for (IslDirectionalReference entry : pathHint) {
last = entry;
if (first == null) {
first = entry;
}
IslEndpoint source = entry.getSourceEndpoint();
Switch sourceSwitch = fetchOrCreateSwitch(source.getSwitchId());
IslEndpoint dest = entry.getDestEndpoint();
Switch destSwitch = fetchOrCreateSwitch(dest.getSwitchId());
fetchOrCreateIsl(entry);
results.add(PathSegment.builder().pathId(pathId).srcSwitch(sourceSwitch).srcPort(source.getPortNumber()).destSwitch(destSwitch).destPort(dest.getPortNumber()).build());
}
if (first != null && !sourceSwitchId.equals(first.getSourceEndpoint().getSwitchId())) {
throw new IllegalArgumentException(String.format("Flow's trace do not start on flow endpoint (a-end switch %s, first path's hint entry %s)", sourceSwitchId, first));
}
if (last != null && !destSwitchId.equals(last.getDestEndpoint().getSwitchId())) {
throw new IllegalArgumentException(String.format("Flow's trace do not end on flow endpoint (z-end switch %s, last path's hint entry %s)", destSwitchId, last));
}
return results;
}
Aggregations