Search in sources :

Example 31 with PathInfoData

use of org.openkilda.messaging.info.event.PathInfoData in project open-kilda by telstra.

the class FlowCacheTest method getPathIntersection.

@Test
public void getPathIntersection() throws Exception {
    networkCache.createIsl(NetworkTopologyConstants.isl14);
    networkCache.createIsl(NetworkTopologyConstants.isl41);
    PathNode node;
    ImmutablePair<PathInfoData, PathInfoData> path43 = computer.getPath(makeFlow("collide-flow-one", NetworkTopologyConstants.sw4, NetworkTopologyConstants.sw3, 5), defaultStrategy);
    System.out.println(path43);
    List<PathNode> nodesForward43 = new ArrayList<>();
    node = new PathNode(NetworkTopologyConstants.isl45.getPath().get(0));
    node.setSeqId(0);
    nodesForward43.add(node);
    node = new PathNode(NetworkTopologyConstants.isl45.getPath().get(1));
    node.setSeqId(1);
    nodesForward43.add(node);
    node = new PathNode(NetworkTopologyConstants.isl53.getPath().get(0));
    node.setSeqId(2);
    nodesForward43.add(node);
    node = new PathNode(NetworkTopologyConstants.isl53.getPath().get(1));
    node.setSeqId(3);
    nodesForward43.add(node);
    PathInfoData islForwardPath43 = new PathInfoData(NetworkTopologyConstants.isl45.getLatency() + NetworkTopologyConstants.isl53.getLatency(), nodesForward43);
    List<PathNode> nodesReverse43 = new ArrayList<>();
    node = new PathNode(NetworkTopologyConstants.isl35.getPath().get(0));
    node.setSeqId(0);
    nodesReverse43.add(node);
    node = new PathNode(NetworkTopologyConstants.isl35.getPath().get(1));
    node.setSeqId(1);
    nodesReverse43.add(node);
    node = new PathNode(NetworkTopologyConstants.isl54.getPath().get(0));
    node.setSeqId(2);
    nodesReverse43.add(node);
    node = new PathNode(NetworkTopologyConstants.isl54.getPath().get(1));
    node.setSeqId(3);
    nodesReverse43.add(node);
    PathInfoData islReversePath43 = new PathInfoData(NetworkTopologyConstants.isl35.getLatency() + NetworkTopologyConstants.isl54.getLatency(), nodesReverse43);
    assertEquals(islForwardPath43, path43.left);
    assertEquals(islReversePath43, path43.right);
    ImmutablePair<PathInfoData, PathInfoData> path23 = computer.getPath(makeFlow("collide-flow-two", NetworkTopologyConstants.sw2, NetworkTopologyConstants.sw3, 5), defaultStrategy);
    System.out.println(path23);
    List<PathNode> nodesForward23 = new ArrayList<>();
    node = new PathNode(NetworkTopologyConstants.isl25.getPath().get(0));
    node.setSeqId(0);
    nodesForward23.add(node);
    node = new PathNode(NetworkTopologyConstants.isl25.getPath().get(1));
    node.setSeqId(1);
    nodesForward23.add(node);
    PathNode node1 = new PathNode(NetworkTopologyConstants.isl53.getPath().get(0));
    node1.setSeqId(2);
    nodesForward23.add(node1);
    PathNode node2 = new PathNode(NetworkTopologyConstants.isl53.getPath().get(1));
    node2.setSeqId(3);
    nodesForward23.add(node2);
    PathInfoData islForwardPath23 = new PathInfoData(NetworkTopologyConstants.isl25.getLatency() + NetworkTopologyConstants.isl53.getLatency(), nodesForward23);
    List<PathNode> nodesReverse23 = new ArrayList<>();
    PathNode node3 = new PathNode(NetworkTopologyConstants.isl35.getPath().get(0));
    node3.setSeqId(0);
    nodesReverse23.add(node3);
    PathNode node4 = new PathNode(NetworkTopologyConstants.isl35.getPath().get(1));
    node4.setSeqId(1);
    nodesReverse23.add(node4);
    node = new PathNode(NetworkTopologyConstants.isl52.getPath().get(0));
    node.setSeqId(2);
    nodesReverse23.add(node);
    node = new PathNode(NetworkTopologyConstants.isl52.getPath().get(1));
    node.setSeqId(3);
    nodesReverse23.add(node);
    PathInfoData islReversePath23 = new PathInfoData(NetworkTopologyConstants.isl35.getLatency() + NetworkTopologyConstants.isl52.getLatency(), nodesReverse23);
    assertEquals(islForwardPath23, path23.left);
    assertEquals(islReversePath23, path23.right);
    ImmutablePair<Set<PathNode>, Set<PathNode>> expected = new ImmutablePair<>(new HashSet<>(Arrays.asList(node1, node2)), new HashSet<>(Arrays.asList(node3, node4)));
    assertEquals(expected, flowCache.getPathIntersection(path43, path23));
    assertEquals(expected, flowCache.getPathIntersection(path23, path43));
}
Also used : PathInfoData(org.openkilda.messaging.info.event.PathInfoData) Set(java.util.Set) HashSet(java.util.HashSet) ImmutablePair(org.openkilda.messaging.model.ImmutablePair) ArrayList(java.util.ArrayList) PathNode(org.openkilda.messaging.info.event.PathNode) Test(org.junit.Test)

Example 32 with PathInfoData

use of org.openkilda.messaging.info.event.PathInfoData 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 33 with PathInfoData

use of org.openkilda.messaging.info.event.PathInfoData in project open-kilda by telstra.

the class DatabaseSupportImpl method getPaths.

/**
 * Get all possible paths between source and destination switches.
 *
 * @param src source switch ID
 * @param dst destination switch ID
 * @return list of PathInfoData objects
 */
@Override
@SuppressWarnings("unchecked")
public List<PathInfoData> getPaths(SwitchId src, SwitchId dst) {
    return transactionManager.doInTransaction(() -> {
        FramedGraph framedGraph = getGraph();
        GraphTraversal<?, ?> rawTraversal = framedGraph.traverse(input -> input.V().hasLabel(SwitchFrame.FRAME_LABEL).has(SwitchFrame.SWITCH_ID_PROPERTY, src.toString()).repeat(__.outE(IslFrame.FRAME_LABEL).has(IslFrame.STATUS_PROPERTY, "active").inV().hasLabel(SwitchFrame.FRAME_LABEL).simplePath()).until(__.has(SwitchFrame.SWITCH_ID_PROPERTY, dst.toString()).or().loops().is(DEFAULT_DEPTH)).has(SwitchFrame.SWITCH_ID_PROPERTY, dst.toString()).path()).getRawTraversal();
        List<PathInfoData> deserializedResults = new ArrayList<>();
        while (rawTraversal.hasNext()) {
            ImmutablePath tpPath = (ImmutablePath) rawTraversal.next();
            List<PathNode> resultPath = new ArrayList<>();
            int seqId = 0;
            for (Object hop : tpPath) {
                if (hop instanceof Edge) {
                    Edge edge = (Edge) hop;
                    Vertex srcVertex = edge.outVertex();
                    resultPath.add(new PathNode(new SwitchId((String) srcVertex.property(SwitchFrame.SWITCH_ID_PROPERTY).value()), (Integer) edge.property(IslFrame.SRC_PORT_PROPERTY).value(), seqId++, (Long) edge.property(IslFrame.LATENCY_PROPERTY).value()));
                    Vertex dstVertex = edge.inVertex();
                    resultPath.add(new PathNode(new SwitchId((String) dstVertex.property(SwitchFrame.SWITCH_ID_PROPERTY).value()), (Integer) edge.property(IslFrame.DST_PORT_PROPERTY).value(), seqId++, (Long) edge.property(IslFrame.LATENCY_PROPERTY).value()));
                }
            }
            deserializedResults.add(new PathInfoData(0, resultPath));
        }
        return deserializedResults;
    });
}
Also used : FlowEvent(org.openkilda.model.history.FlowEvent) TransitVlanRepository(org.openkilda.persistence.repositories.TransitVlanRepository) FlowPath(org.openkilda.model.FlowPath) Isl(org.openkilda.testing.model.topology.TopologyDefinition.Isl) FlowEventRepository(org.openkilda.persistence.repositories.history.FlowEventRepository) Flow(org.openkilda.model.Flow) PersistenceContextManager(org.openkilda.persistence.context.PersistenceContextManager) FlowMeterRepository(org.openkilda.persistence.repositories.FlowMeterRepository) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) SwitchFrame(org.openkilda.persistence.ferma.frames.SwitchFrame) SwitchConnectedDeviceRepository(org.openkilda.persistence.repositories.SwitchConnectedDeviceRepository) IslFrame(org.openkilda.persistence.ferma.frames.IslFrame) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) Collection(java.util.Collection) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Instant(java.time.Instant) String.format(java.lang.String.format) List(java.util.List) Stream(java.util.stream.Stream) FramedGraph(com.syncleus.ferma.FramedGraph) Optional(java.util.Optional) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) DetachedFactory(org.apache.tinkerpop.gremlin.structure.util.detached.DetachedFactory) TransactionManager(org.openkilda.persistence.tx.TransactionManager) FlowMeter(org.openkilda.model.FlowMeter) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) ArrayList(java.util.ArrayList) DEFAULT_COST(org.openkilda.testing.Constants.DEFAULT_COST) OrientDbPersistenceImplementation(org.openkilda.persistence.orientdb.OrientDbPersistenceImplementation) IslRepository(org.openkilda.persistence.repositories.IslRepository) TransitVlan(org.openkilda.model.TransitVlan) PersistenceManager(org.openkilda.persistence.PersistenceManager) PathId(org.openkilda.model.PathId) OrientDbContextExtension(org.openkilda.persistence.orientdb.OrientDbContextExtension) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Switch(org.openkilda.model.Switch) FlowMirrorPointsRepository(org.openkilda.persistence.repositories.FlowMirrorPointsRepository) PersistenceContext(org.openkilda.persistence.context.PersistenceContext) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) ImmutablePath(org.apache.tinkerpop.gremlin.process.traversal.step.util.ImmutablePath) PathNode(org.openkilda.messaging.info.event.PathNode) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) MeterId(org.openkilda.model.MeterId) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) Collectors.toList(java.util.stream.Collectors.toList) Component(org.springframework.stereotype.Component) SwitchId(org.openkilda.model.SwitchId) SwitchStatus(org.openkilda.model.SwitchStatus) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) ArrayList(java.util.ArrayList) SwitchId(org.openkilda.model.SwitchId) PathNode(org.openkilda.messaging.info.event.PathNode) ImmutablePath(org.apache.tinkerpop.gremlin.process.traversal.step.util.ImmutablePath) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) FramedGraph(com.syncleus.ferma.FramedGraph) Edge(org.apache.tinkerpop.gremlin.structure.Edge)

Example 34 with PathInfoData

use of org.openkilda.messaging.info.event.PathInfoData 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 35 with PathInfoData

use of org.openkilda.messaging.info.event.PathInfoData in project open-kilda by telstra.

the class PostResourceAllocationAction method buildRerouteResponseMessage.

private Message buildRerouteResponseMessage(FlowPath currentForward, FlowPath newForward, CommandContext commandContext) {
    PathInfoData currentPath = FlowPathMapper.INSTANCE.map(currentForward);
    PathInfoData resultPath = Optional.ofNullable(newForward).map(FlowPathMapper.INSTANCE::map).orElse(currentPath);
    FlowRerouteResponse response = new FlowRerouteResponse(resultPath, !resultPath.equals(currentPath));
    return new InfoMessage(response, commandContext.getCreateTime(), commandContext.getCorrelationId());
}
Also used : PathInfoData(org.openkilda.messaging.info.event.PathInfoData) FlowPathMapper(org.openkilda.wfm.share.mappers.FlowPathMapper) FlowRerouteResponse(org.openkilda.messaging.info.flow.FlowRerouteResponse) InfoMessage(org.openkilda.messaging.info.InfoMessage)

Aggregations

PathInfoData (org.openkilda.messaging.info.event.PathInfoData)39 Test (org.junit.Test)15 Flow (org.openkilda.messaging.model.Flow)13 InfoMessage (org.openkilda.messaging.info.InfoMessage)10 PathNode (org.openkilda.messaging.info.event.PathNode)10 ArrayList (java.util.ArrayList)9 FlowPayload (org.openkilda.messaging.payload.flow.FlowPayload)9 List (java.util.List)6 PathSegment (org.openkilda.model.PathSegment)5 SwitchId (org.openkilda.model.SwitchId)5 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 Values (org.apache.storm.tuple.Values)4 Driver (org.neo4j.driver.v1.Driver)4 MessageException (org.openkilda.messaging.error.MessageException)4 ImmutablePair (org.openkilda.messaging.model.ImmutablePair)4 FlowPath (org.openkilda.model.FlowPath)4 UnroutablePathException (org.openkilda.pce.provider.UnroutablePathException)4 HashMap (java.util.HashMap)3 CommandMessage (org.openkilda.messaging.command.CommandMessage)3