From 55d4a1b251e1b2e36b9036b3d0b033abc38acbec Mon Sep 17 00:00:00 2001 From: Ashlee Young Date: Fri, 13 Nov 2015 17:25:44 -0800 Subject: ONOS commit d9df7bd278935c3d72ac6eeb0ff44efe1edde567 Change-Id: I319f3a3765db55034b894238fb9391eee56c6dd4 Signed-off-by: Ashlee Young --- .../java/org/onlab/graph/SRLGGraphSearchTest.java | 174 --------------------- .../java/org/onlab/graph/SrlgGraphSearchTest.java | 174 +++++++++++++++++++++ .../org/onlab/graph/TarjanGraphSearchTest.java | 16 +- .../test/java/org/onlab/util/HexStringTest.java | 2 +- 4 files changed, 183 insertions(+), 183 deletions(-) delete mode 100644 framework/src/onos/utils/misc/src/test/java/org/onlab/graph/SRLGGraphSearchTest.java create mode 100644 framework/src/onos/utils/misc/src/test/java/org/onlab/graph/SrlgGraphSearchTest.java (limited to 'framework/src/onos/utils/misc/src/test/java/org') diff --git a/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/SRLGGraphSearchTest.java b/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/SRLGGraphSearchTest.java deleted file mode 100644 index 8bfd270c..00000000 --- a/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/SRLGGraphSearchTest.java +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onlab.graph; - -import org.junit.Test; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import static com.google.common.collect.ImmutableSet.of; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.onlab.graph.GraphPathSearch.ALL_PATHS; - -/** - * Test of the Suurballe backup path algorithm. - */ -public class SRLGGraphSearchTest extends BreadthFirstSearchTest { - - @Override - protected AbstractGraphPathSearch graphSearch() { - return new SRLGGraphSearch<>(null); - } - - public void setDefaultWeights() { - weight = null; - } - - @Override - public void defaultGraphTest() { - } - - @Override - public void defaultHopCountWeight() { - } - - @Test - public void onePathPair() { - setDefaultWeights(); - TestEdge aB = new TestEdge(A, B, 1); - TestEdge bC = new TestEdge(B, C, 1); - TestEdge aD = new TestEdge(A, D, 1); - TestEdge dC = new TestEdge(D, C, 1); - Graph graph = new AdjacencyListsGraph<>(of(A, B, C, D), - of(aB, bC, aD, dC)); - Map riskProfile = new HashMap<>(); - riskProfile.put(aB, 0); - riskProfile.put(bC, 0); - riskProfile.put(aD, 1); - riskProfile.put(dC, 1); - SRLGGraphSearch search = new SRLGGraphSearch<>(2, riskProfile); - Set> paths = search.search(graph, A, C, weight, ALL_PATHS).paths(); - System.out.println("\n\n\n" + paths + "\n\n\n"); - assertEquals("one disjoint path pair found", 1, paths.size()); - checkIsDisjoint(paths.iterator().next(), riskProfile); - } - - public void checkIsDisjoint(Path p, Map risks) { - assertTrue("The path is not a DisjointPathPair", (p instanceof DisjointPathPair)); - DisjointPathPair q = (DisjointPathPair) p; - Set p1Risks = new HashSet<>(); - for (TestEdge e : q.edges()) { - p1Risks.add(risks.get(e)); - } - if (!q.hasBackup()) { - return; - } - Path pq = q.secondary(); - for (TestEdge e: pq.edges()) { - assertTrue("The paths are not disjoint", !p1Risks.contains(risks.get(e))); - } - } - - @Test - public void complexGraphTest() { - setDefaultWeights(); - TestEdge aB = new TestEdge(A, B, 1); - TestEdge bC = new TestEdge(B, C, 1); - TestEdge aD = new TestEdge(A, D, 1); - TestEdge dC = new TestEdge(D, C, 1); - TestEdge cE = new TestEdge(C, E, 1); - TestEdge bE = new TestEdge(B, E, 1); - Graph graph = new AdjacencyListsGraph<>(of(A, B, C, D, E), - of(aB, bC, aD, dC, cE, bE)); - Map riskProfile = new HashMap<>(); - riskProfile.put(aB, 0); - riskProfile.put(bC, 0); - riskProfile.put(aD, 1); - riskProfile.put(dC, 1); - riskProfile.put(cE, 2); - riskProfile.put(bE, 3); - SRLGGraphSearch search = new SRLGGraphSearch<>(4, riskProfile); - search.search(graph, A, E, weight, ALL_PATHS).paths(); - } - - @Test - public void multiplePathGraphTest() { - setDefaultWeights(); - TestEdge aB = new TestEdge(A, B, 1); - TestEdge bE = new TestEdge(B, E, 1); - TestEdge aD = new TestEdge(A, D, 1); - TestEdge dE = new TestEdge(D, E, 1); - TestEdge aC = new TestEdge(A, C, 1); - TestEdge cE = new TestEdge(C, E, 1); - Graph graph = new AdjacencyListsGraph<>(of(A, B, C, D, E), - of(aB, bE, aD, dE, aC, cE)); - Map riskProfile = new HashMap<>(); - riskProfile.put(aB, 0); - riskProfile.put(bE, 1); - riskProfile.put(aD, 2); - riskProfile.put(dE, 3); - riskProfile.put(aC, 4); - riskProfile.put(cE, 5); - SRLGGraphSearch search = new SRLGGraphSearch<>(6, riskProfile); - Set> paths = search.search(graph, A, E, weight, ALL_PATHS).paths(); - assertTrue("> one disjoint path pair found", paths.size() >= 1); - checkIsDisjoint(paths.iterator().next(), riskProfile); - } - - @Test - public void onePath() { - setDefaultWeights(); - TestEdge aB = new TestEdge(A, B, 1); - TestEdge bC = new TestEdge(B, C, 1); - TestEdge aD = new TestEdge(A, D, 1); - TestEdge dC = new TestEdge(D, C, 1); - Graph graph = new AdjacencyListsGraph<>(of(A, B, C, D), - of(aB, bC, aD, dC)); - Map riskProfile = new HashMap<>(); - riskProfile.put(aB, 0); - riskProfile.put(bC, 0); - riskProfile.put(aD, 1); - riskProfile.put(dC, 0); - SRLGGraphSearch search = new SRLGGraphSearch<>(2, riskProfile); - Set> paths = search.search(graph, A, C, weight, ALL_PATHS).paths(); - System.out.println(paths); - assertTrue("no disjoint path pairs found", paths.size() == 0); - } - - @Test - public void noPath() { - setDefaultWeights(); - TestEdge aB = new TestEdge(A, B, 1); - TestEdge bC = new TestEdge(B, C, 1); - TestEdge aD = new TestEdge(A, D, 1); - TestEdge dC = new TestEdge(D, C, 1); - Graph graph = new AdjacencyListsGraph<>(of(A, B, C, D, E), - of(aB, bC, aD, dC)); - Map riskProfile = new HashMap<>(); - riskProfile.put(aB, 0); - riskProfile.put(bC, 0); - riskProfile.put(aD, 1); - riskProfile.put(dC, 0); - SRLGGraphSearch search = new SRLGGraphSearch<>(2, riskProfile); - Set> paths = search.search(graph, A, E, weight, ALL_PATHS).paths(); - assertTrue("no disjoint path pairs found", paths.size() == 0); - } -} diff --git a/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/SrlgGraphSearchTest.java b/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/SrlgGraphSearchTest.java new file mode 100644 index 00000000..26d50364 --- /dev/null +++ b/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/SrlgGraphSearchTest.java @@ -0,0 +1,174 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onlab.graph; + +import org.junit.Test; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import static com.google.common.collect.ImmutableSet.of; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.onlab.graph.GraphPathSearch.ALL_PATHS; + +/** + * Test of the Suurballe backup path algorithm. + */ +public class SrlgGraphSearchTest extends BreadthFirstSearchTest { + + @Override + protected AbstractGraphPathSearch graphSearch() { + return new SrlgGraphSearch<>(null); + } + + public void setDefaultWeights() { + weight = null; + } + + @Override + public void defaultGraphTest() { + } + + @Override + public void defaultHopCountWeight() { + } + + @Test + public void onePathPair() { + setDefaultWeights(); + TestEdge aB = new TestEdge(A, B, 1); + TestEdge bC = new TestEdge(B, C, 1); + TestEdge aD = new TestEdge(A, D, 1); + TestEdge dC = new TestEdge(D, C, 1); + Graph graph = new AdjacencyListsGraph<>(of(A, B, C, D), + of(aB, bC, aD, dC)); + Map riskProfile = new HashMap<>(); + riskProfile.put(aB, 0); + riskProfile.put(bC, 0); + riskProfile.put(aD, 1); + riskProfile.put(dC, 1); + SrlgGraphSearch search = new SrlgGraphSearch<>(2, riskProfile); + Set> paths = search.search(graph, A, C, weight, ALL_PATHS).paths(); + System.out.println("\n\n\n" + paths + "\n\n\n"); + assertEquals("one disjoint path pair found", 1, paths.size()); + checkIsDisjoint(paths.iterator().next(), riskProfile); + } + + public void checkIsDisjoint(Path p, Map risks) { + assertTrue("The path is not a DisjointPathPair", (p instanceof DisjointPathPair)); + DisjointPathPair q = (DisjointPathPair) p; + Set p1Risks = new HashSet<>(); + for (TestEdge e : q.edges()) { + p1Risks.add(risks.get(e)); + } + if (!q.hasBackup()) { + return; + } + Path pq = q.secondary(); + for (TestEdge e: pq.edges()) { + assertTrue("The paths are not disjoint", !p1Risks.contains(risks.get(e))); + } + } + + @Test + public void complexGraphTest() { + setDefaultWeights(); + TestEdge aB = new TestEdge(A, B, 1); + TestEdge bC = new TestEdge(B, C, 1); + TestEdge aD = new TestEdge(A, D, 1); + TestEdge dC = new TestEdge(D, C, 1); + TestEdge cE = new TestEdge(C, E, 1); + TestEdge bE = new TestEdge(B, E, 1); + Graph graph = new AdjacencyListsGraph<>(of(A, B, C, D, E), + of(aB, bC, aD, dC, cE, bE)); + Map riskProfile = new HashMap<>(); + riskProfile.put(aB, 0); + riskProfile.put(bC, 0); + riskProfile.put(aD, 1); + riskProfile.put(dC, 1); + riskProfile.put(cE, 2); + riskProfile.put(bE, 3); + SrlgGraphSearch search = new SrlgGraphSearch<>(4, riskProfile); + search.search(graph, A, E, weight, ALL_PATHS).paths(); + } + + @Test + public void multiplePathGraphTest() { + setDefaultWeights(); + TestEdge aB = new TestEdge(A, B, 1); + TestEdge bE = new TestEdge(B, E, 1); + TestEdge aD = new TestEdge(A, D, 1); + TestEdge dE = new TestEdge(D, E, 1); + TestEdge aC = new TestEdge(A, C, 1); + TestEdge cE = new TestEdge(C, E, 1); + Graph graph = new AdjacencyListsGraph<>(of(A, B, C, D, E), + of(aB, bE, aD, dE, aC, cE)); + Map riskProfile = new HashMap<>(); + riskProfile.put(aB, 0); + riskProfile.put(bE, 1); + riskProfile.put(aD, 2); + riskProfile.put(dE, 3); + riskProfile.put(aC, 4); + riskProfile.put(cE, 5); + SrlgGraphSearch search = new SrlgGraphSearch<>(6, riskProfile); + Set> paths = search.search(graph, A, E, weight, ALL_PATHS).paths(); + assertTrue("> one disjoint path pair found", paths.size() >= 1); + checkIsDisjoint(paths.iterator().next(), riskProfile); + } + + @Test + public void onePath() { + setDefaultWeights(); + TestEdge aB = new TestEdge(A, B, 1); + TestEdge bC = new TestEdge(B, C, 1); + TestEdge aD = new TestEdge(A, D, 1); + TestEdge dC = new TestEdge(D, C, 1); + Graph graph = new AdjacencyListsGraph<>(of(A, B, C, D), + of(aB, bC, aD, dC)); + Map riskProfile = new HashMap<>(); + riskProfile.put(aB, 0); + riskProfile.put(bC, 0); + riskProfile.put(aD, 1); + riskProfile.put(dC, 0); + SrlgGraphSearch search = new SrlgGraphSearch<>(2, riskProfile); + Set> paths = search.search(graph, A, C, weight, ALL_PATHS).paths(); + System.out.println(paths); + assertTrue("no disjoint path pairs found", paths.size() == 0); + } + + @Test + public void noPath() { + setDefaultWeights(); + TestEdge aB = new TestEdge(A, B, 1); + TestEdge bC = new TestEdge(B, C, 1); + TestEdge aD = new TestEdge(A, D, 1); + TestEdge dC = new TestEdge(D, C, 1); + Graph graph = new AdjacencyListsGraph<>(of(A, B, C, D, E), + of(aB, bC, aD, dC)); + Map riskProfile = new HashMap<>(); + riskProfile.put(aB, 0); + riskProfile.put(bC, 0); + riskProfile.put(aD, 1); + riskProfile.put(dC, 0); + SrlgGraphSearch search = new SrlgGraphSearch<>(2, riskProfile); + Set> paths = search.search(graph, A, E, weight, ALL_PATHS).paths(); + assertTrue("no disjoint path pairs found", paths.size() == 0); + } +} diff --git a/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/TarjanGraphSearchTest.java b/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/TarjanGraphSearchTest.java index 624c5781..40f90513 100644 --- a/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/TarjanGraphSearchTest.java +++ b/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/TarjanGraphSearchTest.java @@ -19,20 +19,20 @@ import org.junit.Test; import static com.google.common.collect.ImmutableSet.of; import static org.junit.Assert.assertEquals; -import static org.onlab.graph.TarjanGraphSearch.SCCResult; +import static org.onlab.graph.TarjanGraphSearch.SccResult; /** * Tarjan graph search tests. */ public class TarjanGraphSearchTest extends GraphTest { - private void validate(SCCResult result, int cc) { + private void validate(SccResult result, int cc) { System.out.println("Cluster count: " + result.clusterVertexes().size()); System.out.println("Clusters: " + result.clusterVertexes()); assertEquals("incorrect cluster count", cc, result.clusterCount()); } - private void validate(SCCResult result, + private void validate(SccResult result, int i, int vc, int ec) { assertEquals("incorrect cluster count", vc, result.clusterVertexes().get(i).size()); assertEquals("incorrect edge count", ec, result.clusterEdges().get(i).size()); @@ -42,7 +42,7 @@ public class TarjanGraphSearchTest extends GraphTest { public void basic() { graph = new AdjacencyListsGraph<>(vertexes(), edges()); TarjanGraphSearch gs = new TarjanGraphSearch<>(); - SCCResult result = gs.search(graph, null); + SccResult result = gs.search(graph, null); validate(result, 6); } @@ -59,7 +59,7 @@ public class TarjanGraphSearchTest extends GraphTest { new TestEdge(H, A, 1))); TarjanGraphSearch gs = new TarjanGraphSearch<>(); - SCCResult result = gs.search(graph, null); + SccResult result = gs.search(graph, null); validate(result, 1); validate(result, 0, 8, 8); } @@ -76,7 +76,7 @@ public class TarjanGraphSearchTest extends GraphTest { new TestEdge(G, H, 1), new TestEdge(H, E, 1))); TarjanGraphSearch gs = new TarjanGraphSearch<>(); - SCCResult result = gs.search(graph, null); + SccResult result = gs.search(graph, null); validate(result, 2); validate(result, 0, 4, 4); validate(result, 1, 4, 4); @@ -95,7 +95,7 @@ public class TarjanGraphSearchTest extends GraphTest { new TestEdge(H, E, 1), new TestEdge(B, E, 1))); TarjanGraphSearch gs = new TarjanGraphSearch<>(); - SCCResult result = gs.search(graph, null); + SccResult result = gs.search(graph, null); validate(result, 2); validate(result, 0, 4, 4); validate(result, 1, 4, 4); @@ -116,7 +116,7 @@ public class TarjanGraphSearchTest extends GraphTest { new TestEdge(E, B, -1))); TarjanGraphSearch gs = new TarjanGraphSearch<>(); - SCCResult result = gs.search(graph, weight); + SccResult result = gs.search(graph, weight); validate(result, 2); validate(result, 0, 4, 4); validate(result, 1, 4, 4); diff --git a/framework/src/onos/utils/misc/src/test/java/org/onlab/util/HexStringTest.java b/framework/src/onos/utils/misc/src/test/java/org/onlab/util/HexStringTest.java index e04e29a2..f4aadd15 100644 --- a/framework/src/onos/utils/misc/src/test/java/org/onlab/util/HexStringTest.java +++ b/framework/src/onos/utils/misc/src/test/java/org/onlab/util/HexStringTest.java @@ -47,7 +47,7 @@ public class HexStringTest { } @Test - public void testToLongMSB() { + public void testToLongMsb() { String dpidStr = "ca:7c:5e:d1:64:7a:95:9b"; long valid = -3856102927509056101L; long testLong = HexString.toLong(dpidStr); -- cgit 1.2.3-korg