diff --git a/pom.xml b/pom.xml
index c509f00..1f2a099 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,8 +6,7 @@
0.0.1-SNAPSHOT
- 17
- 17
+ 17
diff --git a/src/main/java/eu/m724/netsim/PathVisualizer.java b/src/main/java/eu/m724/netsim/PathVisualizer.java
new file mode 100644
index 0000000..e63e49f
--- /dev/null
+++ b/src/main/java/eu/m724/netsim/PathVisualizer.java
@@ -0,0 +1,22 @@
+package eu.m724.netsim;
+
+public class PathVisualizer {
+ public static String path(Machine from, Machine to, int limit) {
+ String out = from.id;
+
+ Machine current = from;
+ int i = 0;
+ while (!current.equals(to)) {
+ RoutingInfo route = current.getRouteTo(to);
+ current = route.from();
+ out += " - " + current.id;
+
+ if (++i >= limit) {
+ out += " - x";
+ break;
+ }
+ }
+
+ return out;
+ }
+}
diff --git a/src/test/java/netsim/PeeringDirectTest.java b/src/test/java/netsim/PeeringDirectTest.java
new file mode 100644
index 0000000..7818d1f
--- /dev/null
+++ b/src/test/java/netsim/PeeringDirectTest.java
@@ -0,0 +1,33 @@
+package netsim;
+
+import org.junit.Test;
+
+import eu.m724.netsim.Machine;
+import eu.m724.netsim.PathVisualizer;
+
+public class PeeringDirectTest {
+ @Test
+ public void testComplexPeering() {
+ // machine1 - machine2 - machine3 - machine4
+ // \------------/
+ // so machine1 should skip machine2
+
+ Machine machine1 = new Machine("machine1");
+ Machine machine2 = new Machine("machine2");
+ Machine machine3 = new Machine("machine3");
+ Machine machine4 = new Machine("machine4");
+
+ machine1.peerWith(machine2);
+ machine2.peerWith(machine3);
+ machine3.peerWith(machine4);
+ machine1.peerWith(machine3); // that's the bottom arrow
+
+ System.out.println("\nMachine 1:");
+ System.out.println(machine1.getRouteTo(machine2).toString());
+ System.out.println(machine1.getRouteTo(machine3).toString());
+ System.out.println(machine1.getRouteTo(machine4).toString());
+ System.out.println(PathVisualizer.path(machine1, machine4, 10));
+ System.out.println("\nMachine 2:");
+ System.out.println(machine2.getRouteTo(machine4).toString());
+ }
+}
diff --git a/src/test/java/netsim/PeeringTest.java b/src/test/java/netsim/PeeringTest.java
index 14139ea..76ac41c 100644
--- a/src/test/java/netsim/PeeringTest.java
+++ b/src/test/java/netsim/PeeringTest.java
@@ -3,6 +3,7 @@ package netsim;
import org.junit.Test;
import eu.m724.netsim.Machine;
+import eu.m724.netsim.PathVisualizer;
public class PeeringTest {
@Test
@@ -21,5 +22,7 @@ public class PeeringTest {
System.out.println(machine1.getRouteTo(machine2).toString());
System.out.println(machine2.getRouteTo(machine3).toString());
System.out.println(machine1.getRouteTo(machine3).toString());
+
+ System.out.print(PathVisualizer.path(machine1, machine3, 10));
}
}
diff --git a/src/test/java/netsim/PeeringTreeTest.java b/src/test/java/netsim/PeeringTreeTest.java
new file mode 100644
index 0000000..201dddf
--- /dev/null
+++ b/src/test/java/netsim/PeeringTreeTest.java
@@ -0,0 +1,35 @@
+package netsim;
+
+import org.junit.Test;
+
+import eu.m724.netsim.Machine;
+import eu.m724.netsim.PathVisualizer;
+
+public class PeeringTreeTest {
+ @Test
+ public void testTreePeering() {
+ // / machine4
+ // / machine2 - machine5
+ // machine1
+ // \ machine3 - machine6
+ // \ machine7
+ // so machine1 should skip machine2
+
+ Machine machine1 = new Machine("machine1");
+ Machine machine2 = new Machine("machine2");
+ Machine machine3 = new Machine("machine3");
+ Machine machine4 = new Machine("machine4");
+ Machine machine5 = new Machine("machine5");
+ Machine machine6 = new Machine("machine6");
+ Machine machine7 = new Machine("machine7");
+
+ machine1.peerWith(machine2);
+ machine1.peerWith(machine3);
+ machine2.peerWith(machine4);
+ machine2.peerWith(machine5);
+ machine3.peerWith(machine6);
+ machine3.peerWith(machine7);
+
+ System.out.println(PathVisualizer.path(machine4, machine7, 10));
+ }
+}