Search in sources :

Example 21 with PathInfoData

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

the class PathComputerMock method path.

private PathInfoData path(SwitchInfoData srcSwitch, SwitchInfoData dstSwitch, int bandwidth) {
    System.out.println("Get Path By Switch Instances " + bandwidth + ": " + srcSwitch + " - " + dstSwitch);
    LinkedList<IslInfoData> islInfoDataLinkedList = new LinkedList<>();
    List<PathNode> nodes = new ArrayList<>();
    PathInfoData path = new PathInfoData(0L, nodes);
    if (srcSwitch.equals(dstSwitch)) {
        return path;
    }
    Set<SwitchInfoData> nodesToProcess = new HashSet<>(network.nodes());
    Set<SwitchInfoData> nodesWereProcess = new HashSet<>();
    Map<SwitchInfoData, ImmutablePair<SwitchInfoData, IslInfoData>> predecessors = new HashMap<>();
    Map<SwitchInfoData, Long> distances = network.nodes().stream().collect(Collectors.toMap(k -> k, v -> Long.MAX_VALUE));
    distances.put(srcSwitch, 0L);
    while (!nodesToProcess.isEmpty()) {
        SwitchInfoData source = nodesToProcess.stream().min(Comparator.comparingLong(distances::get)).orElseThrow(() -> new CacheException(ErrorType.NOT_FOUND, "Can not find path", "Error: No nodes to process left"));
        nodesToProcess.remove(source);
        nodesWereProcess.add(source);
        for (SwitchInfoData target : network.successors(source)) {
            if (!nodesWereProcess.contains(target)) {
                IslInfoData edge = network.edgesConnecting(source, target).stream().filter(isl -> isl.getAvailableBandwidth() >= bandwidth).findFirst().orElseThrow(() -> new CacheException(ErrorType.NOT_FOUND, "Can not find path", "Error: No enough bandwidth"));
                Long distance = distances.get(source) + getWeight(edge);
                if (distances.get(target) >= distance) {
                    distances.put(target, distance);
                    nodesToProcess.add(target);
                    predecessors.put(target, new ImmutablePair<>(source, edge));
                }
            }
        }
    }
    ImmutablePair<SwitchInfoData, IslInfoData> nextHop = predecessors.get(dstSwitch);
    if (nextHop == null) {
        return null;
    }
    islInfoDataLinkedList.add(nextHop.getRight());
    while (predecessors.get(nextHop.getLeft()) != null) {
        nextHop = predecessors.get(nextHop.getLeft());
        islInfoDataLinkedList.add(nextHop.getRight());
    }
    Collections.reverse(islInfoDataLinkedList);
    int i = 0;
    for (IslInfoData isl : islInfoDataLinkedList) {
        collect(isl, path, i);
        i += 2;
    }
    updatePathBandwidth(path, bandwidth, islInfoDataLinkedList);
    return path;
}
Also used : Flow(org.openkilda.messaging.model.Flow) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) ImmutablePair(org.openkilda.messaging.model.ImmutablePair) ErrorType(org.openkilda.messaging.error.ErrorType) Set(java.util.Set) CacheException(org.openkilda.messaging.error.CacheException) HashMap(java.util.HashMap) PathNode(org.openkilda.messaging.info.event.PathNode) Collectors(java.util.stream.Collectors) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Map(java.util.Map) MutableNetwork(com.google.common.graph.MutableNetwork) Comparator(java.util.Comparator) LinkedList(java.util.LinkedList) Collections(java.util.Collections) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) HashMap(java.util.HashMap) CacheException(org.openkilda.messaging.error.CacheException) ArrayList(java.util.ArrayList) PathNode(org.openkilda.messaging.info.event.PathNode) LinkedList(java.util.LinkedList) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) ImmutablePair(org.openkilda.messaging.model.ImmutablePair) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) HashSet(java.util.HashSet)

Example 22 with PathInfoData

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

the class FlowCacheTest method getPath.

@Test
public void getPath() throws Exception {
    ImmutablePair<PathInfoData, PathInfoData> path = computer.getPath(makeFlow("generic", NetworkTopologyConstants.sw1, NetworkTopologyConstants.sw3, 0), defaultStrategy);
    System.out.println(path.toString());
    PathNode node;
    List<PathNode> direct = new ArrayList<>();
    node = new PathNode(NetworkTopologyConstants.isl12.getPath().get(0));
    node.setSeqId(0);
    direct.add(node);
    node = new PathNode(NetworkTopologyConstants.isl12.getPath().get(1));
    node.setSeqId(1);
    direct.add(node);
    node = new PathNode(NetworkTopologyConstants.isl25.getPath().get(0));
    node.setSeqId(2);
    direct.add(node);
    node = new PathNode(NetworkTopologyConstants.isl25.getPath().get(1));
    node.setSeqId(3);
    direct.add(node);
    node = new PathNode(NetworkTopologyConstants.isl53.getPath().get(0));
    node.setSeqId(4);
    direct.add(node);
    node = new PathNode(NetworkTopologyConstants.isl53.getPath().get(1));
    node.setSeqId(5);
    direct.add(node);
    PathInfoData expectedDirect = new PathInfoData(NetworkTopologyConstants.isl12.getLatency() + NetworkTopologyConstants.isl25.getLatency() + NetworkTopologyConstants.isl53.getLatency(), direct);
    assertEquals(expectedDirect, path.getLeft());
    List<PathNode> reverse = new ArrayList<>();
    node = new PathNode(NetworkTopologyConstants.isl35.getPath().get(0));
    node.setSeqId(0);
    reverse.add(node);
    node = new PathNode(NetworkTopologyConstants.isl35.getPath().get(1));
    node.setSeqId(1);
    reverse.add(node);
    node = new PathNode(NetworkTopologyConstants.isl52.getPath().get(0));
    node.setSeqId(2);
    reverse.add(node);
    node = new PathNode(NetworkTopologyConstants.isl52.getPath().get(1));
    node.setSeqId(3);
    reverse.add(node);
    node = new PathNode(NetworkTopologyConstants.isl21.getPath().get(0));
    node.setSeqId(4);
    reverse.add(node);
    node = new PathNode(NetworkTopologyConstants.isl21.getPath().get(1));
    node.setSeqId(5);
    reverse.add(node);
    PathInfoData expectedReverse = new PathInfoData(NetworkTopologyConstants.isl12.getLatency() + NetworkTopologyConstants.isl25.getLatency() + NetworkTopologyConstants.isl53.getLatency(), reverse);
    assertEquals(expectedReverse, path.getRight());
}
Also used : PathInfoData(org.openkilda.messaging.info.event.PathInfoData) ArrayList(java.util.ArrayList) PathNode(org.openkilda.messaging.info.event.PathNode) Test(org.junit.Test)

Example 23 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 24 with PathInfoData

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

the class FlowCrudStepsTest method shouldDefineFlowCrossVlan.

@Test
public void shouldDefineFlowCrossVlan() {
    // given
    when(topologyEngineService.getPaths(eq("00:00:00:00:00:01"), eq("00:00:00:00:00:04"))).thenReturn(singletonList(new PathInfoData()));
    // when
    flowCrudSteps.defineFlowsOverAllSwitches();
    // then
    assertEquals(1, flowCrudSteps.flows.size());
    final FlowPayload flowPayload = flowCrudSteps.flows.get(0);
    assertEquals(20, (int) flowPayload.getSource().getPortId());
    assertEquals(1, (int) flowPayload.getSource().getVlanId());
    assertEquals(20, (int) flowPayload.getDestination().getPortId());
    assertEquals(50, (int) flowPayload.getDestination().getVlanId());
}
Also used : PathInfoData(org.openkilda.messaging.info.event.PathInfoData) FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) Test(org.junit.Test)

Example 25 with PathInfoData

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

the class FlowCrudStepsTest method shouldDefineFlowsOver2Switches.

@Test
public void shouldDefineFlowsOver2Switches() {
    // given
    when(topologyEngineService.getPaths(eq("00:00:00:00:00:01"), eq("00:00:00:00:00:02"))).thenReturn(singletonList(new PathInfoData()));
    // when
    flowCrudSteps.defineFlowsOverAllSwitches();
    // then
    assertEquals(1, flowCrudSteps.flows.size());
    final FlowPayload flowPayload = flowCrudSteps.flows.get(0);
    assertEquals(20, (int) flowPayload.getSource().getPortId());
    assertEquals(1, (int) flowPayload.getSource().getVlanId());
    assertEquals(20, (int) flowPayload.getDestination().getPortId());
    assertEquals(1, (int) flowPayload.getDestination().getVlanId());
}
Also used : PathInfoData(org.openkilda.messaging.info.event.PathInfoData) FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) Test(org.junit.Test)

Aggregations

PathInfoData (org.openkilda.messaging.info.event.PathInfoData)27 Flow (org.openkilda.messaging.model.Flow)13 Test (org.junit.Test)12 InfoMessage (org.openkilda.messaging.info.InfoMessage)8 PathNode (org.openkilda.messaging.info.event.PathNode)6 FlowPayload (org.openkilda.messaging.payload.flow.FlowPayload)5 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 UnroutablePathException (org.openkilda.pce.provider.UnroutablePathException)4 AbstractStormTest (org.openkilda.wfm.AbstractStormTest)4 ArrayList (java.util.ArrayList)3 CommandMessage (org.openkilda.messaging.command.CommandMessage)3 FlowPathResponse (org.openkilda.messaging.info.flow.FlowPathResponse)3 HashSet (java.util.HashSet)2 Set (java.util.Set)2 FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)2 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)2 FlowValidationException (org.openkilda.wfm.topology.flow.validation.FlowValidationException)2