16 package org.openkilda.topo;
18 import static java.lang.String.format;
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.fail;
27 import com.google.common.base.Charsets;
28 import com.google.common.io.Resources;
29 import com.google.common.util.concurrent.Uninterruptibles;
31 import java.io.IOException;
34 import java.util.TreeSet;
35 import java.util.concurrent.TimeUnit;
44 System.out.println(
"TOPOLOGY DISCOVERY: The number of SWITCHES don't match");
45 System.out.println(
"expected.getSwitches().keySet() = " + expected.
getSwitches().keySet());
46 System.out.println(
"actual.getSwitches().keySet() = " + actual.
getSwitches().keySet());
51 assertEquals(
"TOPOLOGY DISCOVERY: The number of LINKS don't match" 52 , expected.
getLinks().keySet().size()
53 , actual.
getLinks().keySet().size());
54 assertEquals(
"TOPOLOGY DISCOVERY: The IDs of SWITCHES don't match" 56 simpleLinkComparison(expected.
getLinks().keySet(), actual.
getLinks().keySet());
60 private static Set<String> toUpper(Set<String> ss) {
61 Set<String>
result =
new TreeSet<>();
63 result.add(s.toUpperCase());
68 private static Set<String> toUpperSubstring(Set<String> ss,
int start,
int end) {
69 Set<String>
result =
new TreeSet<>();
72 String[] trunc = s.toUpperCase().split(TopoSlug.EP_DELIM);
73 trunc[0] = trunc[0].substring(start, end);
74 trunc[1] = trunc[1].substring(start, end);
75 result.add(trunc[0] + TopoSlug.EP_DELIM + trunc[1]);
82 private static void simpleLinkComparison(Set<String> expected, Set<String> actual) {
84 String[]
s1 = toUpperSubstring(expected, 0, 23).toArray(
new String[expected.size()]);
85 String[]
s2 = toUpperSubstring(actual, 0, 23).toArray(
new String[actual.size()]);
86 for (
int i = 0;
i <
s1.length;
i++) {
94 doc = Resources.toString(
url, Charsets.UTF_8);
95 }
catch (IOException ex) {
98 doc = doc.replaceAll(
"\"dpid\": \"SW",
"\"dpid\": \"");
99 doc = doc.replaceAll(
"([0-9A-Fa-f]{2}):",
"$1");
107 private static ITopology translateTestTopo(String doc) {
117 long expectedSwitches = expected.
getSwitches().keySet().size();
118 long expectedLinks = expected.getLinks().keySet().size();
133 InterruptedException {
138 long priorSwitches = 0, priorLinks = 0;
139 for (
int i = 0;
i < 4;
i++) {
141 TimeUnit.SECONDS.sleep(10);
146 long numSwitches = tTE.
getSwitches().keySet().size();
147 long numLinks = tTE.
getLinks().keySet().size();
149 System.out.print(
"(" + numSwitches +
"," + numLinks +
") ");
150 System.out.print(
"of (" + expectedSwitches +
"," + expectedLinks +
") .. ");
153 if (numSwitches != expectedSwitches) {
154 if (numSwitches > priorSwitches) {
155 priorSwitches = numSwitches;
161 if (numLinks != expectedLinks) {
162 if (numLinks > priorLinks) {
163 priorLinks = numLinks;
170 System.out.println(
"");
185 public static void clearEverything(String endpoint)
throws InterruptedException, IOException {
186 String expected =
"{\"nodes\": []}";
189 TimeUnit.MILLISECONDS.sleep(3000);
194 for (
int i = 0;
i < 2;
i++) {
195 if (!expected.equals(entity)) {
196 TimeUnit.MILLISECONDS.sleep(2000);
198 assertEquals(
"Default, initial, response from TopologyEngine", expected, entity);
209 Uninterruptibles.sleepUninterruptibly(3, TimeUnit.SECONDS);
219 ITopology expected = translateTestTopo(doc);
222 }
catch (Exception e) {
223 fail(
"Unexpected Exception:" + e.getMessage());
229 System.out.println(
"t1 = " + t);
232 System.out.println(
"t2 = " + t.printSwitchConnections());
234 System.out.println(
"t2.size = " + t.
getSwitches().keySet().size());
static void main(String[] args)
static void testTheTopo(URL url)
static ITopology checkAndGetTopo(long expectedSwitches, long expectedLinks)
static String GetTopology()
static String createMininetTopoFromFile(URL url)
Map< String, Switch > getSwitches()
static String ClearTopology()
Map< String, Link > getLinks()
static void validateTopos(ITopology expected, ITopology actual)
static final Topology buildLinearTopo(int numSwitches)
static void clearEverything(String endpoint)
static final Topology buildTopoFromTestJson(String jsonDoc)
static boolean CreateMininetTopology(String json)
CtrlResponse clearTopologyComponentState(String topology, String componentId)
static ITopology translateTopoEngTopo(ITopology expected)
static boolean DeleteMininetTopology()
static void clearEverything()
static Topology parseTopologyEngineJson(String json)
static final Topology buildTreeTopo(int depth, int fanout)