Search in sources :

Example 11 with ImmutablePair

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

the class AbstractSerializerTest method dumpNetworkResponseTest.

@Test
public void dumpNetworkResponseTest() throws IOException, ClassNotFoundException {
    NetworkInfoData data = new NetworkInfoData(requester, new HashSet<>(Arrays.asList(sw1, sw2)), new HashSet<>(), Collections.singleton(isl), Collections.singleton(new ImmutablePair<>(flowModel, flowModel)));
    System.out.println(data);
    InfoMessage info = new InfoMessage(data, System.currentTimeMillis(), CORRELATION_ID, DESTINATION);
    info.setData(data);
    serialize(info);
    Message message = (Message) deserialize();
    assertTrue(message instanceof InfoMessage);
    InfoMessage resultInfo = (InfoMessage) message;
    assertTrue(resultInfo.getData() != null);
    NetworkInfoData resultData = (NetworkInfoData) resultInfo.getData();
    System.out.println(resultData);
    assertEquals(data, resultData);
    assertEquals(data.hashCode(), resultData.hashCode());
}
Also used : NetworkInfoData(org.openkilda.messaging.info.discovery.NetworkInfoData) ImmutablePair(org.openkilda.messaging.model.ImmutablePair) InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) InfoMessage(org.openkilda.messaging.info.InfoMessage) Test(org.junit.Test)

Example 12 with ImmutablePair

use of org.openkilda.messaging.model.ImmutablePair 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)

Aggregations

ImmutablePair (org.openkilda.messaging.model.ImmutablePair)12 Flow (org.openkilda.messaging.model.Flow)7 PathInfoData (org.openkilda.messaging.info.event.PathInfoData)5 And (cucumber.api.java.en.And)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 Test (org.junit.Test)2 CacheException (org.openkilda.messaging.error.CacheException)2 PathNode (org.openkilda.messaging.info.event.PathNode)2 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ContiguousSet (com.google.common.collect.ContiguousSet)1 DiscreteDomain (com.google.common.collect.DiscreteDomain)1 Range (com.google.common.collect.Range)1 RangeSet (com.google.common.collect.RangeSet)1 TreeRangeSet (com.google.common.collect.TreeRangeSet)1 MutableNetwork (com.google.common.graph.MutableNetwork)1