Search in sources :

Example 41 with PathSegment

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);
}
Also used : YFlow(org.openkilda.model.YFlow) EndpointResources(org.openkilda.wfm.topology.flowhs.model.yflow.YFlowResources.EndpointResources) PathSegment(org.openkilda.model.PathSegment) YSubFlow(org.openkilda.model.YSubFlow) FlowPath(org.openkilda.model.FlowPath) State(org.openkilda.wfm.topology.flowhs.fsm.yflow.reroute.YFlowRerouteFsm.State) YFlowResources(org.openkilda.wfm.topology.flowhs.model.yflow.YFlowResources) FlowPathMapper(org.openkilda.wfm.share.mappers.FlowPathMapper) YFlowRuleManagerProcessingAction(org.openkilda.wfm.topology.flowhs.fsm.common.actions.YFlowRuleManagerProcessingAction) Collectors(java.util.stream.Collectors) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) RuleManager(org.openkilda.rulemanager.RuleManager) YFlowRerouteContext(org.openkilda.wfm.topology.flowhs.fsm.yflow.reroute.YFlowRerouteContext) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Stream(java.util.stream.Stream) SwitchId(org.openkilda.model.SwitchId) IntersectionComputer(org.openkilda.wfm.share.service.IntersectionComputer) SubFlowPathDto(org.openkilda.messaging.command.yflow.SubFlowPathDto) YFlow(org.openkilda.model.YFlow) Event(org.openkilda.wfm.topology.flowhs.fsm.yflow.reroute.YFlowRerouteFsm.Event) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) PersistenceManager(org.openkilda.persistence.PersistenceManager) Comparator(java.util.Comparator) YFlowRerouteFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.reroute.YFlowRerouteFsm) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) SwitchId(org.openkilda.model.SwitchId) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) SubFlowPathDto(org.openkilda.messaging.command.yflow.SubFlowPathDto)

Example 42 with PathSegment

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;
        }
    }
}
Also used : ToString(lombok.ToString) PathSegment(org.openkilda.model.PathSegment) Edge(org.openkilda.pce.model.Edge) HashSet(java.util.HashSet) Sets.newHashSet(com.google.common.collect.Sets.newHashSet)

Example 43 with PathSegment

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();
        }
    }
}
Also used : Node(org.openkilda.pce.model.Node) SwitchId(org.openkilda.model.SwitchId) PathSegment(org.openkilda.model.PathSegment) Edge(org.openkilda.pce.model.Edge)

Example 44 with PathSegment

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);
}
Also used : PathSegment(org.openkilda.model.PathSegment) Set(java.util.Set) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Edge(org.openkilda.pce.model.Edge) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Flow(org.openkilda.model.Flow) SwitchId(org.openkilda.model.SwitchId) Node(org.openkilda.pce.model.Node) Map(java.util.Map) ToString(lombok.ToString) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Node(org.openkilda.pce.model.Node) PathSegment(org.openkilda.model.PathSegment) Edge(org.openkilda.pce.model.Edge) HashSet(java.util.HashSet) Sets.newHashSet(com.google.common.collect.Sets.newHashSet)

Example 45 with PathSegment

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;
}
Also used : IslEndpoint(org.openkilda.model.IslEndpoint) Switch(org.openkilda.model.Switch) ArrayList(java.util.ArrayList) PathSegment(org.openkilda.model.PathSegment)

Aggregations

PathSegment (org.openkilda.model.PathSegment)73 FlowPath (org.openkilda.model.FlowPath)40 ArrayList (java.util.ArrayList)28 Flow (org.openkilda.model.Flow)26 PathId (org.openkilda.model.PathId)24 SwitchId (org.openkilda.model.SwitchId)18 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)17 FlowEndpoint (org.openkilda.model.FlowEndpoint)12 Test (org.junit.Test)11 List (java.util.List)9 MeterId (org.openkilda.model.MeterId)9 Switch (org.openkilda.model.Switch)9 YFlow (org.openkilda.model.YFlow)8 PersistenceManager (org.openkilda.persistence.PersistenceManager)7 Optional (java.util.Optional)6 Slf4j (lombok.extern.slf4j.Slf4j)6 VisibleForTesting (com.google.common.annotations.VisibleForTesting)5 Set (java.util.Set)5 Collectors (java.util.stream.Collectors)5 PathInfoData (org.openkilda.messaging.info.event.PathInfoData)5