Search in sources :

Example 61 with PathSegment

use of org.openkilda.model.PathSegment in project open-kilda by telstra.

the class RerouteServiceTest method testRerouteInactivePinnedFlowsTwoFailedSegments.

@Test
public void testRerouteInactivePinnedFlowsTwoFailedSegments() {
    pinnedFlow.setStatus(FlowStatus.DOWN);
    for (FlowPath flowPath : pinnedFlow.getPaths()) {
        flowPath.setStatus(FlowPathStatus.INACTIVE);
        for (PathSegment pathSegment : flowPath.getSegments()) {
            pathSegment.setFailed(true);
        }
    }
    RepositoryFactory repositoryFactory = mock(RepositoryFactory.class);
    FlowRepository flowRepository = mock(FlowRepository.class);
    when(flowRepository.findInactiveFlows()).thenReturn(Collections.singletonList(pinnedFlow));
    when(repositoryFactory.createFlowRepository()).thenReturn(flowRepository);
    FlowPathRepository pathRepository = mock(FlowPathRepository.class);
    when(repositoryFactory.createFlowPathRepository()).thenReturn(pathRepository);
    PathSegmentRepository pathSegmentRepository = mock(PathSegmentRepository.class);
    when(repositoryFactory.createPathSegmentRepository()).thenReturn(pathSegmentRepository);
    MessageSender messageSender = mock(MessageSender.class);
    PersistenceManager persistenceManager = mock(PersistenceManager.class);
    when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
    when(persistenceManager.getTransactionManager()).thenReturn(transactionManager);
    RerouteService rerouteService = new RerouteService(persistenceManager);
    rerouteService.rerouteInactiveFlows(messageSender, CORRELATION_ID, REROUTE_INACTIVE_FLOWS_COMMAND);
    verify(pathRepository, times(0)).updateStatus(any(), any());
    assertTrue(FlowStatus.DOWN.equals(pinnedFlow.getStatus()));
    for (FlowPath fp : pinnedFlow.getPaths()) {
        assertTrue(FlowPathStatus.INACTIVE.equals(fp.getStatus()));
        for (PathSegment ps : fp.getSegments()) {
            if (ps.containsNode(SWITCH_ID_A, PORT)) {
                assertFalse(ps.isFailed());
            } else {
                assertTrue(ps.isFailed());
            }
        }
    }
}
Also used : FlowRepository(org.openkilda.persistence.repositories.FlowRepository) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) PathSegmentRepository(org.openkilda.persistence.repositories.PathSegmentRepository) PersistenceManager(org.openkilda.persistence.PersistenceManager) MessageSender(org.openkilda.wfm.topology.reroute.bolts.MessageSender) PathSegment(org.openkilda.model.PathSegment) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) FlowPath(org.openkilda.model.FlowPath) Test(org.junit.Test)

Example 62 with PathSegment

use of org.openkilda.model.PathSegment in project open-kilda by telstra.

the class FlowPathMapper method mapToPathNodes.

/**
 * Convert {@link FlowPath} to {@link PathNodePayload}.
 */
public List<PathNodePayload> mapToPathNodes(FlowPath flowPath) {
    List<PathNodePayload> resultList = new ArrayList<>();
    Flow flow = flowPath.getFlow();
    FlowEndpoint ingress = FlowSideAdapter.makeIngressAdapter(flow, flowPath).getEndpoint();
    FlowEndpoint egress = FlowSideAdapter.makeEgressAdapter(flow, flowPath).getEndpoint();
    List<PathSegment> pathSegments = flowPath.getSegments();
    Iterator<PathSegment> leftIter = pathSegments.iterator();
    Iterator<PathSegment> rightIter = pathSegments.iterator();
    if (!rightIter.hasNext()) {
        resultList.add(new PathNodePayload(flowPath.getSrcSwitchId(), ingress.getPortNumber(), egress.getPortNumber()));
    } else {
        PathSegment left;
        PathSegment right = rightIter.next();
        resultList.add(new PathNodePayload(ingress.getSwitchId(), ingress.getPortNumber(), right.getSrcPort()));
        while (rightIter.hasNext()) {
            left = leftIter.next();
            right = rightIter.next();
            resultList.add(new PathNodePayload(left.getDestSwitchId(), left.getDestPort(), right.getSrcPort()));
        }
        resultList.add(new PathNodePayload(egress.getSwitchId(), right.getDestPort(), egress.getPortNumber()));
    }
    return resultList;
}
Also used : FlowEndpoint(org.openkilda.model.FlowEndpoint) PathNodePayload(org.openkilda.messaging.payload.flow.PathNodePayload) ArrayList(java.util.ArrayList) PathSegment(org.openkilda.model.PathSegment) Flow(org.openkilda.model.Flow)

Example 63 with PathSegment

use of org.openkilda.model.PathSegment in project open-kilda by telstra.

the class FlowPathMapper method map.

/**
 * Convert {@link FlowPath} to {@link PathInfoData}.
 */
public PathInfoData map(FlowPath path) {
    PathInfoData result = new PathInfoData();
    if (path != null) {
        result.setLatency(path.getLatency());
        int seqId = 0;
        List<PathNode> nodes = new ArrayList<>();
        for (PathSegment pathSegment : path.getSegments()) {
            nodes.add(new PathNode(pathSegment.getSrcSwitchId(), pathSegment.getSrcPort(), seqId++, pathSegment.getLatency()));
            nodes.add(new PathNode(pathSegment.getDestSwitchId(), pathSegment.getDestPort(), seqId++));
        }
        result.setPath(nodes);
    }
    return result;
}
Also used : PathInfoData(org.openkilda.messaging.info.event.PathInfoData) ArrayList(java.util.ArrayList) PathSegment(org.openkilda.model.PathSegment) PathNode(org.openkilda.messaging.info.event.PathNode) FlowEndpoint(org.openkilda.model.FlowEndpoint)

Example 64 with PathSegment

use of org.openkilda.model.PathSegment in project open-kilda by telstra.

the class SpeakerFlowSegmentRequestBuilder method makePathRequests.

@SuppressWarnings("squid:S00107")
private List<FlowSegmentRequestFactory> makePathRequests(@NonNull Flow flow, @NonNull FlowPath path, CommandContext context, FlowTransitEncapsulation encapsulation, boolean doIngress, boolean doTransit, boolean doEgress, RulesContext rulesContext, MirrorContext mirrorContext) {
    final FlowSideAdapter ingressSide = FlowSideAdapter.makeIngressAdapter(flow, path);
    final FlowSideAdapter egressSide = FlowSideAdapter.makeEgressAdapter(flow, path);
    final List<FlowSegmentRequestFactory> requests = new ArrayList<>();
    PathSegment lastSegment = null;
    for (PathSegment segment : path.getSegments()) {
        if (lastSegment == null) {
            if (doIngress) {
                requests.addAll(makeIngressSegmentRequests(context, path, encapsulation, ingressSide, segment, egressSide, rulesContext, mirrorContext));
                if (ingressLoopRuleRequired(flow, ingressSide)) {
                    requests.addAll(makeLoopRequests(context, path, encapsulation, ingressSide, egressSide, segment));
                }
            }
        } else {
            if (doTransit) {
                requests.add(makeTransitSegmentRequest(context, path, encapsulation, lastSegment, segment));
            }
        }
        lastSegment = segment;
    }
    if (lastSegment != null) {
        if (doEgress) {
            requests.addAll(makeEgressSegmentRequests(context, path, encapsulation, lastSegment, egressSide, ingressSide, mirrorContext));
        }
    } else if (flow.isOneSwitchFlow()) {
        // one switch flow (path without path segments)
        requests.addAll(makeOneSwitchRequest(context, path, ingressSide, egressSide, rulesContext, mirrorContext));
        if (singleSwitchLoopRuleRequired(flow)) {
            requests.add(makeSingleSwitchIngressLoopRequest(context, path, ingressSide));
        }
    }
    return requests;
}
Also used : IngressMirrorFlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.IngressMirrorFlowSegmentRequestFactory) IngressFlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.IngressFlowSegmentRequestFactory) EgressMirrorFlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.EgressMirrorFlowSegmentRequestFactory) EgressFlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.EgressFlowSegmentRequestFactory) TransitFlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.TransitFlowSegmentRequestFactory) FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) ArrayList(java.util.ArrayList) FlowSideAdapter(org.openkilda.adapter.FlowSideAdapter) PathSegment(org.openkilda.model.PathSegment)

Example 65 with PathSegment

use of org.openkilda.model.PathSegment in project open-kilda by telstra.

the class IntersectionComputer method calculatePathIntersectionFromSource.

/**
 * Calculates intersection (shared part) among the paths starting from the source endpoint.
 *
 * @param paths the paths to examine.
 * @return the overlapping path segments.
 */
public static List<PathSegment> calculatePathIntersectionFromSource(Collection<FlowPath> paths) {
    if (paths.size() < 2) {
        throw new IllegalArgumentException("At least 2 paths must be provided");
    }
    SwitchId source = null;
    for (FlowPath path : paths) {
        List<PathSegment> segments = path.getSegments();
        if (segments.isEmpty()) {
            throw new IllegalArgumentException("All paths mustn't be empty");
        }
        // Check that all paths have the same source.
        if (source == null) {
            source = segments.get(0).getSrcSwitchId();
        } else if (!segments.get(0).getSrcSwitchId().equals(source)) {
            throw new IllegalArgumentException("All paths must have the same source endpoint");
        }
    }
    // Gather iterators of all paths' segments.
    List<Iterator<PathSegment>> pathSegmentIterators = paths.stream().map(FlowPath::getSegments).map(List::iterator).collect(Collectors.toList());
    return getLongestIntersectionOfSegments(pathSegmentIterators);
}
Also used : Iterator(java.util.Iterator) SwitchId(org.openkilda.model.SwitchId) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath)

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