Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next
Conflicts:
providers/of/link/src/main/java/org/onlab/onos/provider/of/link/impl/OpenFlowLinkProvider.java
diff --git a/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleDeviceManager.java b/core/trivial/src/main/java/org/onlab/onos/net/trivial/device/impl/SimpleDeviceManager.java
similarity index 99%
rename from core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleDeviceManager.java
rename to core/trivial/src/main/java/org/onlab/onos/net/trivial/device/impl/SimpleDeviceManager.java
index 135edd9..221a249 100644
--- a/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleDeviceManager.java
+++ b/core/trivial/src/main/java/org/onlab/onos/net/trivial/device/impl/SimpleDeviceManager.java
@@ -1,4 +1,4 @@
-package org.onlab.onos.net.trivial.impl;
+package org.onlab.onos.net.trivial.device.impl;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
diff --git a/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleDeviceStore.java b/core/trivial/src/main/java/org/onlab/onos/net/trivial/device/impl/SimpleDeviceStore.java
similarity index 99%
rename from core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleDeviceStore.java
rename to core/trivial/src/main/java/org/onlab/onos/net/trivial/device/impl/SimpleDeviceStore.java
index 1c1502e..6317b14 100644
--- a/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleDeviceStore.java
+++ b/core/trivial/src/main/java/org/onlab/onos/net/trivial/device/impl/SimpleDeviceStore.java
@@ -1,4 +1,4 @@
-package org.onlab.onos.net.trivial.impl;
+package org.onlab.onos.net.trivial.device.impl;
import com.google.common.collect.ImmutableList;
import org.onlab.onos.net.DefaultDevice;
diff --git a/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/DefaultTopologyDescription.java b/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/DefaultTopologyDescription.java
deleted file mode 100644
index c438146..0000000
--- a/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/DefaultTopologyDescription.java
+++ /dev/null
@@ -1,250 +0,0 @@
-package org.onlab.onos.net.trivial.impl;
-
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-import org.onlab.graph.AdjacencyListsGraph;
-import org.onlab.graph.DijkstraGraphSearch;
-import org.onlab.graph.Graph;
-import org.onlab.graph.GraphPathSearch;
-import org.onlab.onos.net.ConnectPoint;
-import org.onlab.onos.net.Device;
-import org.onlab.onos.net.DeviceId;
-import org.onlab.onos.net.Link;
-import org.onlab.onos.net.topology.ClusterId;
-import org.onlab.onos.net.topology.LinkWeight;
-import org.onlab.onos.net.topology.TopoEdge;
-import org.onlab.onos.net.topology.TopoVertex;
-import org.onlab.onos.net.topology.TopologyCluster;
-import org.onlab.onos.net.topology.TopologyDescription;
-
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-
-import static com.google.common.base.MoreObjects.toStringHelper;
-import static org.onlab.graph.GraphPathSearch.Result;
-import static org.onlab.onos.net.Link.Type.INDIRECT;
-
-/**
- * Default implementation of an immutable topology data carrier.
- */
-class DefaultTopologyDescription implements TopologyDescription {
-
- private static final GraphPathSearch<TopoVertex, TopoEdge> DIJKSTRA =
- new DijkstraGraphSearch<>();
-
- private final long nanos;
- private final Map<DeviceId, TopoVertex> vertexesById = Maps.newHashMap();
- private final Graph<TopoVertex, TopoEdge> graph;
- private final Map<DeviceId, Result<TopoVertex, TopoEdge>> results;
- private final Map<ClusterId, TopologyCluster> clusters;
-// private final Multimap<ClusterId, DeviceId> clusterDevices;
-// private final Multimap<ClusterId, Link> clusterLinks;
-// private final Map<DeviceId, TopologyCluster> deviceClusters;
-
-
- DefaultTopologyDescription(long nanos, Iterable<Device> devices, Iterable<Link> links) {
- this.nanos = nanos;
- this.graph = buildGraph(devices, links);
- this.results = computeDefaultPaths();
- this.clusters = computeClusters();
-// this.clusterDevices = clusterDevices;
-// this.clusterLinks = clusterLinks;
-// this.deviceClusters = deviceClusters;
- }
-
- // Constructs the topology graph using the supplied devices and links.
- private Graph<TopoVertex, TopoEdge> buildGraph(Iterable<Device> devices,
- Iterable<Link> links) {
- Graph<TopoVertex, TopoEdge> graph =
- new AdjacencyListsGraph<>(buildVertexes(devices),
- buildEdges(links));
- return graph;
- }
-
- // Builds a set of topology vertexes from the specified list of devices
- private Set<TopoVertex> buildVertexes(Iterable<Device> devices) {
- Set<TopoVertex> vertexes = Sets.newHashSet();
- for (Device device : devices) {
- TopoVertex vertex = new TVertex(device.id());
- vertexesById.put(vertex.deviceId(), vertex);
- vertexes.add(vertex);
- }
- return vertexes;
- }
-
- // Builds a set of topology vertexes from the specified list of links
- private Set<TopoEdge> buildEdges(Iterable<Link> links) {
- Set<TopoEdge> edges = Sets.newHashSet();
- for (Link link : links) {
- edges.add(new TEdge(vertexOf(link.src()), vertexOf(link.dst()), link));
- }
- return edges;
- }
-
- // Computes the default shortest paths for all source/dest pairs using
- // the multi-path Dijkstra and hop-count as path cost.
- private Map<DeviceId, Result<TopoVertex, TopoEdge>> computeDefaultPaths() {
- LinkWeight weight = new HopCountLinkWeight(graph.getVertexes().size());
- Map<DeviceId, Result<TopoVertex, TopoEdge>> results = Maps.newHashMap();
-
- // Search graph paths for each source to all destinations.
- for (TopoVertex src : vertexesById.values()) {
- results.put(src.deviceId(), DIJKSTRA.search(graph, src, null, weight));
- }
- return results;
- }
-
- // Computes topology SCC clusters using Tarjan algorithm.
- private Map<ClusterId, TopologyCluster> computeClusters() {
- Map<ClusterId, TopologyCluster> clusters = Maps.newHashMap();
- return clusters;
- }
-
- // Fetches a vertex corresponding to the given connection point device.
- private TopoVertex vertexOf(ConnectPoint connectPoint) {
- DeviceId id = connectPoint.deviceId();
- TopoVertex vertex = vertexesById.get(id);
- if (vertex == null) {
- // If vertex does not exist, create one and register it.
- vertex = new TVertex(id);
- vertexesById.put(id, vertex);
- }
- return vertex;
- }
-
- @Override
- public long timestamp() {
- return nanos;
- }
-
- @Override
- public Graph<TopoVertex, TopoEdge> graph() {
- return graph;
- }
-
- @Override
- public Result<TopoVertex, TopoEdge> pathResults(DeviceId srcDeviceId) {
- return results.get(srcDeviceId);
- }
-
- @Override
- public Set<TopologyCluster> clusters() {
- return ImmutableSet.copyOf(clusters.values());
- }
-
- @Override
- public Set<DeviceId> clusterDevices(TopologyCluster cluster) {
- return null; // clusterDevices.get(cluster.id());
- }
-
- @Override
- public Set<Link> clusterLinks(TopologyCluster cluster) {
- return null; // clusterLinks.get(cluster.id());
- }
-
- @Override
- public TopologyCluster clusterFor(DeviceId deviceId) {
- return null; // deviceClusters.get(deviceId);
- }
-
- // Implementation of the topology vertex backed by a device id
- private static class TVertex implements TopoVertex {
-
- private final DeviceId deviceId;
-
- public TVertex(DeviceId deviceId) {
- this.deviceId = deviceId;
- }
-
- @Override
- public DeviceId deviceId() {
- return deviceId;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(deviceId);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof TVertex) {
- final TVertex other = (TVertex) obj;
- return Objects.equals(this.deviceId, other.deviceId);
- }
- return false;
- }
-
- @Override
- public String toString() {
- return deviceId.toString();
- }
- }
-
- // Implementation of the topology edge backed by a link
- private class TEdge implements TopoEdge {
- private final Link link;
- private final TopoVertex src;
- private final TopoVertex dst;
-
- public TEdge(TopoVertex src, TopoVertex dst, Link link) {
- this.src = src;
- this.dst = dst;
- this.link = link;
- }
-
- @Override
- public Link link() {
- return link;
- }
-
- @Override
- public TopoVertex src() {
- return src;
- }
-
- @Override
- public TopoVertex dst() {
- return dst;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(link);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof TEdge) {
- final TEdge other = (TEdge) obj;
- return Objects.equals(this.link, other.link);
- }
- return false;
- }
-
- @Override
- public String toString() {
- return toStringHelper(this).add("src", src).add("dst", dst).toString();
- }
- }
-
- // Link weight for measuring link cost as hop count with indirect links
- // being as expensive as traversing the entire graph to assume the worst.
- private class HopCountLinkWeight implements LinkWeight {
- private final int indirectLinkCost;
-
- public HopCountLinkWeight(int indirectLinkCost) {
- this.indirectLinkCost = indirectLinkCost;
- }
-
- @Override
- public double weight(TopoEdge edge) {
- // To force preference to use direct paths first, make indirect
- // links as expensive as the linear vertex traversal.
- return edge.link().type() == INDIRECT ? indirectLinkCost : 1;
- }
- }
-
-}
diff --git a/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleLinkManager.java b/core/trivial/src/main/java/org/onlab/onos/net/trivial/link/impl/SimpleLinkManager.java
similarity index 99%
rename from core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleLinkManager.java
rename to core/trivial/src/main/java/org/onlab/onos/net/trivial/link/impl/SimpleLinkManager.java
index 1930ea1..a817bb6 100644
--- a/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleLinkManager.java
+++ b/core/trivial/src/main/java/org/onlab/onos/net/trivial/link/impl/SimpleLinkManager.java
@@ -1,4 +1,4 @@
-package org.onlab.onos.net.trivial.impl;
+package org.onlab.onos.net.trivial.link.impl;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
diff --git a/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleLinkStore.java b/core/trivial/src/main/java/org/onlab/onos/net/trivial/link/impl/SimpleLinkStore.java
similarity index 99%
rename from core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleLinkStore.java
rename to core/trivial/src/main/java/org/onlab/onos/net/trivial/link/impl/SimpleLinkStore.java
index 9de3d5b..2ba7a30 100644
--- a/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleLinkStore.java
+++ b/core/trivial/src/main/java/org/onlab/onos/net/trivial/link/impl/SimpleLinkStore.java
@@ -1,4 +1,4 @@
-package org.onlab.onos.net.trivial.impl;
+package org.onlab.onos.net.trivial.link.impl;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableSet;
diff --git a/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/DefaultTopology.java b/core/trivial/src/main/java/org/onlab/onos/net/trivial/topology/impl/DefaultTopology.java
similarity index 96%
rename from core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/DefaultTopology.java
rename to core/trivial/src/main/java/org/onlab/onos/net/trivial/topology/impl/DefaultTopology.java
index cb55819..c20acd8 100644
--- a/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/DefaultTopology.java
+++ b/core/trivial/src/main/java/org/onlab/onos/net/trivial/topology/impl/DefaultTopology.java
@@ -1,4 +1,4 @@
-package org.onlab.onos.net.trivial.impl;
+package org.onlab.onos.net.trivial.topology.impl;
import org.onlab.onos.net.AbstractModel;
import org.onlab.onos.net.provider.ProviderId;
diff --git a/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleTopologyManager.java b/core/trivial/src/main/java/org/onlab/onos/net/trivial/topology/impl/SimpleTopologyManager.java
similarity index 98%
rename from core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleTopologyManager.java
rename to core/trivial/src/main/java/org/onlab/onos/net/trivial/topology/impl/SimpleTopologyManager.java
index 33b2a18..70f001c 100644
--- a/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleTopologyManager.java
+++ b/core/trivial/src/main/java/org/onlab/onos/net/trivial/topology/impl/SimpleTopologyManager.java
@@ -1,4 +1,4 @@
-package org.onlab.onos.net.trivial.impl;
+package org.onlab.onos.net.trivial.topology.impl;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
diff --git a/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleTopologyStore.java b/core/trivial/src/main/java/org/onlab/onos/net/trivial/topology/impl/SimpleTopologyStore.java
similarity index 98%
rename from core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleTopologyStore.java
rename to core/trivial/src/main/java/org/onlab/onos/net/trivial/topology/impl/SimpleTopologyStore.java
index 7944a53..1b9766d 100644
--- a/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleTopologyStore.java
+++ b/core/trivial/src/main/java/org/onlab/onos/net/trivial/topology/impl/SimpleTopologyStore.java
@@ -1,4 +1,4 @@
-package org.onlab.onos.net.trivial.impl;
+package org.onlab.onos.net.trivial.topology.impl;
import org.onlab.graph.Graph;
import org.onlab.onos.event.Event;
diff --git a/core/trivial/src/main/java/org/onlab/onos/net/trivial/topology/provider/impl/DefaultTopoEdge.java b/core/trivial/src/main/java/org/onlab/onos/net/trivial/topology/provider/impl/DefaultTopoEdge.java
new file mode 100644
index 0000000..d940754
--- /dev/null
+++ b/core/trivial/src/main/java/org/onlab/onos/net/trivial/topology/provider/impl/DefaultTopoEdge.java
@@ -0,0 +1,68 @@
+package org.onlab.onos.net.trivial.topology.provider.impl;
+
+import org.onlab.onos.net.Link;
+import org.onlab.onos.net.topology.TopoEdge;
+import org.onlab.onos.net.topology.TopoVertex;
+
+import java.util.Objects;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+/**
+ * Implementation of the topology edge backed by a link.
+ */
+class DefaultTopoEdge implements TopoEdge {
+
+ private final Link link;
+ private final TopoVertex src;
+ private final TopoVertex dst;
+
+ /**
+ * Creates a new topology edge.
+ *
+ * @param src source vertex
+ * @param dst destination vertex
+ * @param link infrastructure link
+ */
+ DefaultTopoEdge(TopoVertex src, TopoVertex dst, Link link) {
+ this.src = src;
+ this.dst = dst;
+ this.link = link;
+ }
+
+ @Override
+ public Link link() {
+ return link;
+ }
+
+ @Override
+ public TopoVertex src() {
+ return src;
+ }
+
+ @Override
+ public TopoVertex dst() {
+ return dst;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(link);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof DefaultTopoEdge) {
+ final DefaultTopoEdge other = (DefaultTopoEdge) obj;
+ return Objects.equals(this.link, other.link);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this).add("src", src).add("dst", dst).toString();
+ }
+
+}
+
diff --git a/core/trivial/src/main/java/org/onlab/onos/net/trivial/topology/provider/impl/DefaultTopoVertex.java b/core/trivial/src/main/java/org/onlab/onos/net/trivial/topology/provider/impl/DefaultTopoVertex.java
new file mode 100644
index 0000000..afcaca6
--- /dev/null
+++ b/core/trivial/src/main/java/org/onlab/onos/net/trivial/topology/provider/impl/DefaultTopoVertex.java
@@ -0,0 +1,49 @@
+package org.onlab.onos.net.trivial.topology.provider.impl;
+
+import org.onlab.onos.net.DeviceId;
+import org.onlab.onos.net.topology.TopoVertex;
+
+import java.util.Objects;
+
+/**
+ * Implementation of the topology vertex backed by a device id.
+ */
+class DefaultTopoVertex implements TopoVertex {
+
+ private final DeviceId deviceId;
+
+ /**
+ * Creates a new topology vertex.
+ *
+ * @param deviceId backing infrastructure device identifier
+ */
+ DefaultTopoVertex(DeviceId deviceId) {
+ this.deviceId = deviceId;
+ }
+
+ @Override
+ public DeviceId deviceId() {
+ return deviceId;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(deviceId);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof DefaultTopoVertex) {
+ final DefaultTopoVertex other = (DefaultTopoVertex) obj;
+ return Objects.equals(this.deviceId, other.deviceId);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return deviceId.toString();
+ }
+
+}
+
diff --git a/core/trivial/src/main/java/org/onlab/onos/net/trivial/topology/provider/impl/DefaultTopologyDescription.java b/core/trivial/src/main/java/org/onlab/onos/net/trivial/topology/provider/impl/DefaultTopologyDescription.java
new file mode 100644
index 0000000..408e6af
--- /dev/null
+++ b/core/trivial/src/main/java/org/onlab/onos/net/trivial/topology/provider/impl/DefaultTopologyDescription.java
@@ -0,0 +1,247 @@
+package org.onlab.onos.net.trivial.topology.provider.impl;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSetMultimap;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import org.onlab.graph.AdjacencyListsGraph;
+import org.onlab.graph.DijkstraGraphSearch;
+import org.onlab.graph.Graph;
+import org.onlab.graph.GraphPathSearch;
+import org.onlab.graph.TarjanGraphSearch;
+import org.onlab.onos.net.ConnectPoint;
+import org.onlab.onos.net.Device;
+import org.onlab.onos.net.DeviceId;
+import org.onlab.onos.net.Link;
+import org.onlab.onos.net.topology.ClusterId;
+import org.onlab.onos.net.topology.DefaultTopologyCluster;
+import org.onlab.onos.net.topology.LinkWeight;
+import org.onlab.onos.net.topology.TopoEdge;
+import org.onlab.onos.net.topology.TopoVertex;
+import org.onlab.onos.net.topology.TopologyCluster;
+import org.onlab.onos.net.topology.TopologyDescription;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static com.google.common.collect.ImmutableSetMultimap.Builder;
+import static org.onlab.graph.GraphPathSearch.Result;
+import static org.onlab.graph.TarjanGraphSearch.SCCResult;
+import static org.onlab.onos.net.Link.Type.INDIRECT;
+
+/**
+ * Default implementation of an immutable topology data carrier.
+ */
+class DefaultTopologyDescription implements TopologyDescription {
+
+ private static final GraphPathSearch<TopoVertex, TopoEdge> DIJKSTRA =
+ new DijkstraGraphSearch<>();
+ private static final TarjanGraphSearch<TopoVertex, TopoEdge> TARJAN =
+ new TarjanGraphSearch<>();
+
+ private final long nanos;
+ private final Map<DeviceId, TopoVertex> vertexesById = Maps.newHashMap();
+ private final Graph<TopoVertex, TopoEdge> graph;
+ private final Map<DeviceId, Result<TopoVertex, TopoEdge>> results;
+ private final Map<ClusterId, TopologyCluster> clusters;
+
+ // Secondary look-up indexes
+ private ImmutableSetMultimap<ClusterId, DeviceId> devicesByCluster;
+ private ImmutableSetMultimap<ClusterId, Link> linksByCluster;
+ private Map<DeviceId, TopologyCluster> clustersByDevice = Maps.newHashMap();
+
+ /**
+ * Creates a topology description to carry topology vitals to the core.
+ *
+ * @param nanos time in nanos of when the topology description was created
+ * @param devices collection of infrastructure devices
+ * @param links collection of infrastructure links
+ */
+ DefaultTopologyDescription(long nanos, Iterable<Device> devices, Iterable<Link> links) {
+ this.nanos = nanos;
+ this.graph = buildGraph(devices, links);
+ this.results = computeDefaultPaths();
+ this.clusters = computeClusters();
+ }
+
+ @Override
+ public long timestamp() {
+ return nanos;
+ }
+
+ @Override
+ public Graph<TopoVertex, TopoEdge> graph() {
+ return graph;
+ }
+
+ @Override
+ public Result<TopoVertex, TopoEdge> pathResults(DeviceId srcDeviceId) {
+ return results.get(srcDeviceId);
+ }
+
+ @Override
+ public Set<TopologyCluster> clusters() {
+ return ImmutableSet.copyOf(clusters.values());
+ }
+
+ @Override
+ public Set<DeviceId> clusterDevices(TopologyCluster cluster) {
+ return devicesByCluster.get(cluster.id());
+ }
+
+ @Override
+ public Set<Link> clusterLinks(TopologyCluster cluster) {
+ return linksByCluster.get(cluster.id());
+ }
+
+ @Override
+ public TopologyCluster clusterFor(DeviceId deviceId) {
+ return clustersByDevice.get(deviceId);
+ }
+
+
+ // Link weight for measuring link cost as hop count with indirect links
+ // being as expensive as traversing the entire graph to assume the worst.
+ private static class HopCountLinkWeight implements LinkWeight {
+ private final int indirectLinkCost;
+
+ HopCountLinkWeight(int indirectLinkCost) {
+ this.indirectLinkCost = indirectLinkCost;
+ }
+
+ @Override
+ public double weight(TopoEdge edge) {
+ // To force preference to use direct paths first, make indirect
+ // links as expensive as the linear vertex traversal.
+ return edge.link().type() == INDIRECT ? indirectLinkCost : 1;
+ }
+ }
+
+ // Link weight for preventing traversal over indirect links.
+ private static class NoIndirectLinksWeight implements LinkWeight {
+ @Override
+ public double weight(TopoEdge edge) {
+ return edge.link().type() == INDIRECT ? -1 : 1;
+ }
+ }
+
+ // Constructs the topology graph using the supplied devices and links.
+ private Graph<TopoVertex, TopoEdge> buildGraph(Iterable<Device> devices,
+ Iterable<Link> links) {
+ return new AdjacencyListsGraph<>(buildVertexes(devices),
+ buildEdges(links));
+ }
+
+ // Builds a set of topology vertexes from the specified list of devices
+ private Set<TopoVertex> buildVertexes(Iterable<Device> devices) {
+ Set<TopoVertex> vertexes = Sets.newHashSet();
+ for (Device device : devices) {
+ TopoVertex vertex = new DefaultTopoVertex(device.id());
+ vertexes.add(vertex);
+ vertexesById.put(vertex.deviceId(), vertex);
+ }
+ return vertexes;
+ }
+
+ // Builds a set of topology vertexes from the specified list of links
+ private Set<TopoEdge> buildEdges(Iterable<Link> links) {
+ Set<TopoEdge> edges = Sets.newHashSet();
+ for (Link link : links) {
+ edges.add(new DefaultTopoEdge(vertexOf(link.src()),
+ vertexOf(link.dst()), link));
+ }
+ return edges;
+ }
+
+ // Computes the default shortest paths for all source/dest pairs using
+ // the multi-path Dijkstra and hop-count as path cost.
+ private Map<DeviceId, Result<TopoVertex, TopoEdge>> computeDefaultPaths() {
+ LinkWeight weight = new HopCountLinkWeight(graph.getVertexes().size());
+ Map<DeviceId, Result<TopoVertex, TopoEdge>> results = Maps.newHashMap();
+
+ // Search graph paths for each source to all destinations.
+ for (TopoVertex src : vertexesById.values()) {
+ results.put(src.deviceId(), DIJKSTRA.search(graph, src, null, weight));
+ }
+ return results;
+ }
+
+ // Computes topology SCC clusters using Tarjan algorithm.
+ private Map<ClusterId, TopologyCluster> computeClusters() {
+ Map<ClusterId, TopologyCluster> clusters = Maps.newHashMap();
+ SCCResult<TopoVertex, TopoEdge> result = TARJAN.search(graph, new NoIndirectLinksWeight());
+
+ // Extract both vertexes and edges from the results; the lists form
+ // pairs along the same index.
+ List<Set<TopoVertex>> clusterVertexes = result.clusterVertexes();
+ List<Set<TopoEdge>> clusterEdges = result.clusterEdges();
+
+ Builder<ClusterId, DeviceId> devicesBuilder = ImmutableSetMultimap.builder();
+ Builder<ClusterId, Link> linksBuilder = ImmutableSetMultimap.builder();
+
+ // Scan over the lists and create a cluster from the results.
+ for (int i = 0, n = result.clusterCount(); i < n; i++) {
+ Set<TopoVertex> vertexSet = clusterVertexes.get(i);
+ Set<TopoEdge> edgeSet = clusterEdges.get(i);
+
+ DefaultTopologyCluster cluster =
+ new DefaultTopologyCluster(ClusterId.clusterId(i),
+ vertexSet.size(), edgeSet.size(),
+ findRoot(vertexSet).deviceId());
+ findClusterDevices(vertexSet, cluster, devicesBuilder);
+ findClusterLinks(edgeSet, cluster, linksBuilder);
+ }
+ return clusters;
+ }
+
+ // Scans through the set of cluster vertexes and puts their devices in a
+ // multi-map associated with the cluster. It also binds the devices to
+ // the cluster.
+ private void findClusterDevices(Set<TopoVertex> vertexSet,
+ DefaultTopologyCluster cluster,
+ Builder<ClusterId, DeviceId> builder) {
+ for (TopoVertex vertex : vertexSet) {
+ DeviceId deviceId = vertex.deviceId();
+ builder.put(cluster.id(), deviceId);
+ clustersByDevice.put(deviceId, cluster);
+ }
+ }
+
+ // Scans through the set of cluster edges and puts their links in a
+ // multi-map associated with the cluster.
+ private void findClusterLinks(Set<TopoEdge> edgeSet,
+ DefaultTopologyCluster cluster,
+ Builder<ClusterId, Link> builder) {
+ for (TopoEdge edge : edgeSet) {
+ builder.put(cluster.id(), edge.link());
+ }
+ }
+
+ // Finds the vertex whose device id is the lexicographical minimum in the
+ // specified set.
+ private TopoVertex findRoot(Set<TopoVertex> vertexSet) {
+ TopoVertex minVertex = null;
+ for (TopoVertex vertex : vertexSet) {
+ if (minVertex == null ||
+ minVertex.deviceId().toString()
+ .compareTo(minVertex.deviceId().toString()) < 0) {
+ minVertex = vertex;
+ }
+ }
+ return minVertex;
+ }
+
+ // Fetches a vertex corresponding to the given connection point device.
+ private TopoVertex vertexOf(ConnectPoint connectPoint) {
+ DeviceId id = connectPoint.deviceId();
+ TopoVertex vertex = vertexesById.get(id);
+ if (vertex == null) {
+ // If vertex does not exist, create one and register it.
+ vertex = new DefaultTopoVertex(id);
+ vertexesById.put(id, vertex);
+ }
+ return vertex;
+ }
+
+}
diff --git a/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleTopologyProvider.java b/core/trivial/src/main/java/org/onlab/onos/net/trivial/topology/provider/impl/SimpleTopologyProvider.java
similarity index 98%
rename from core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleTopologyProvider.java
rename to core/trivial/src/main/java/org/onlab/onos/net/trivial/topology/provider/impl/SimpleTopologyProvider.java
index 0e9ea3d..777a0e4 100644
--- a/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleTopologyProvider.java
+++ b/core/trivial/src/main/java/org/onlab/onos/net/trivial/topology/provider/impl/SimpleTopologyProvider.java
@@ -1,4 +1,4 @@
-package org.onlab.onos.net.trivial.impl;
+package org.onlab.onos.net.trivial.topology.provider.impl;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
@@ -115,7 +115,6 @@
// Builds the topology using the latest device and link information
// and citing the specified events as reasons for the change.
private void buildTopology(List<Event> reasons) {
- log.info("YO! Computing topology");
if (isStarted) {
TopologyDescription desc =
new DefaultTopologyDescription(System.nanoTime(),
diff --git a/core/trivial/src/main/javadoc/org/onlab/onos/event/impl/package.html b/core/trivial/src/main/javadoc/org/onlab/onos/event/impl/package.html
index a22d62d..87f0d91 100644
--- a/core/trivial/src/main/javadoc/org/onlab/onos/event/impl/package.html
+++ b/core/trivial/src/main/javadoc/org/onlab/onos/event/impl/package.html
@@ -1,3 +1,3 @@
<body>
-ONOS local event dispatching mechanism.
+Local event dispatching mechanism.
</body>
\ No newline at end of file
diff --git a/core/trivial/src/main/javadoc/org/onlab/onos/impl/package.html b/core/trivial/src/main/javadoc/org/onlab/onos/impl/package.html
index 087085c..84500a8 100644
--- a/core/trivial/src/main/javadoc/org/onlab/onos/impl/package.html
+++ b/core/trivial/src/main/javadoc/org/onlab/onos/impl/package.html
@@ -1,3 +1,3 @@
<body>
-ONOS Core infrastructure implementations.
+Core infrastructure implementations.
</body>
\ No newline at end of file
diff --git a/core/trivial/src/main/javadoc/org/onlab/onos/net/trivial/device/impl/package.html b/core/trivial/src/main/javadoc/org/onlab/onos/net/trivial/device/impl/package.html
new file mode 100644
index 0000000..2195da2
--- /dev/null
+++ b/core/trivial/src/main/javadoc/org/onlab/onos/net/trivial/device/impl/package.html
@@ -0,0 +1,3 @@
+<body>
+Core subsystem for tracking infrastructure devices.
+</body>
\ No newline at end of file
diff --git a/core/trivial/src/main/javadoc/org/onlab/onos/net/trivial/host/impl/package.html b/core/trivial/src/main/javadoc/org/onlab/onos/net/trivial/host/impl/package.html
new file mode 100644
index 0000000..79f7bb0
--- /dev/null
+++ b/core/trivial/src/main/javadoc/org/onlab/onos/net/trivial/host/impl/package.html
@@ -0,0 +1,3 @@
+<body>
+Core subsystem for tracking edn-station hosts.
+</body>
\ No newline at end of file
diff --git a/core/trivial/src/main/javadoc/org/onlab/onos/net/trivial/impl/package.html b/core/trivial/src/main/javadoc/org/onlab/onos/net/trivial/impl/package.html
deleted file mode 100644
index ba285bd..0000000
--- a/core/trivial/src/main/javadoc/org/onlab/onos/net/trivial/impl/package.html
+++ /dev/null
@@ -1,3 +0,0 @@
-<body>
-ONOS core implementations.
-</body>
\ No newline at end of file
diff --git a/core/trivial/src/main/javadoc/org/onlab/onos/net/trivial/link/impl/package.html b/core/trivial/src/main/javadoc/org/onlab/onos/net/trivial/link/impl/package.html
new file mode 100644
index 0000000..5bba317
--- /dev/null
+++ b/core/trivial/src/main/javadoc/org/onlab/onos/net/trivial/link/impl/package.html
@@ -0,0 +1,3 @@
+<body>
+Core subsystem for tracking infrastructure links.
+</body>
\ No newline at end of file
diff --git a/core/trivial/src/main/javadoc/org/onlab/onos/net/trivial/topology/impl/package.html b/core/trivial/src/main/javadoc/org/onlab/onos/net/trivial/topology/impl/package.html
new file mode 100644
index 0000000..b4cca07
--- /dev/null
+++ b/core/trivial/src/main/javadoc/org/onlab/onos/net/trivial/topology/impl/package.html
@@ -0,0 +1,3 @@
+<body>
+Core subsystem for tracking consistent topology graph views.
+</body>
\ No newline at end of file
diff --git a/core/trivial/src/main/javadoc/org/onlab/onos/net/trivial/topology/provider/impl/package.html b/core/trivial/src/main/javadoc/org/onlab/onos/net/trivial/topology/provider/impl/package.html
new file mode 100644
index 0000000..ee67aa8
--- /dev/null
+++ b/core/trivial/src/main/javadoc/org/onlab/onos/net/trivial/topology/provider/impl/package.html
@@ -0,0 +1,3 @@
+<body>
+Built-in protocol-agnostic topology builder & provider.
+</body>
\ No newline at end of file
diff --git a/core/trivial/src/test/java/org/onlab/onos/net/trivial/impl/TestEventDispatcher.java b/core/trivial/src/test/java/org/onlab/onos/event/impl/TestEventDispatcher.java
similarity index 94%
rename from core/trivial/src/test/java/org/onlab/onos/net/trivial/impl/TestEventDispatcher.java
rename to core/trivial/src/test/java/org/onlab/onos/event/impl/TestEventDispatcher.java
index 82f8be5..9eb3980 100644
--- a/core/trivial/src/test/java/org/onlab/onos/net/trivial/impl/TestEventDispatcher.java
+++ b/core/trivial/src/test/java/org/onlab/onos/event/impl/TestEventDispatcher.java
@@ -1,4 +1,4 @@
-package org.onlab.onos.net.trivial.impl;
+package org.onlab.onos.event.impl;
import org.onlab.onos.event.DefaultEventSinkRegistry;
import org.onlab.onos.event.Event;
diff --git a/core/trivial/src/test/java/org/onlab/onos/net/trivial/impl/SimpleDeviceManagerTest.java b/core/trivial/src/test/java/org/onlab/onos/net/trivial/device/impl/SimpleDeviceManagerTest.java
similarity index 98%
rename from core/trivial/src/test/java/org/onlab/onos/net/trivial/impl/SimpleDeviceManagerTest.java
rename to core/trivial/src/test/java/org/onlab/onos/net/trivial/device/impl/SimpleDeviceManagerTest.java
index bcece2d..4c1aff4 100644
--- a/core/trivial/src/test/java/org/onlab/onos/net/trivial/impl/SimpleDeviceManagerTest.java
+++ b/core/trivial/src/test/java/org/onlab/onos/net/trivial/device/impl/SimpleDeviceManagerTest.java
@@ -1,4 +1,4 @@
-package org.onlab.onos.net.trivial.impl;
+package org.onlab.onos.net.trivial.device.impl;
import org.junit.After;
import org.junit.Before;
@@ -22,6 +22,7 @@
import org.onlab.onos.net.device.PortDescription;
import org.onlab.onos.net.provider.AbstractProvider;
import org.onlab.onos.net.provider.ProviderId;
+import org.onlab.onos.event.impl.TestEventDispatcher;
import java.util.ArrayList;
import java.util.Iterator;
diff --git a/core/trivial/src/test/java/org/onlab/onos/net/trivial/impl/SimpleLinkManagerTest.java b/core/trivial/src/test/java/org/onlab/onos/net/trivial/link/impl/SimpleLinkManagerTest.java
similarity index 98%
rename from core/trivial/src/test/java/org/onlab/onos/net/trivial/impl/SimpleLinkManagerTest.java
rename to core/trivial/src/test/java/org/onlab/onos/net/trivial/link/impl/SimpleLinkManagerTest.java
index 8dd9e1d..6eace8f 100644
--- a/core/trivial/src/test/java/org/onlab/onos/net/trivial/impl/SimpleLinkManagerTest.java
+++ b/core/trivial/src/test/java/org/onlab/onos/net/trivial/link/impl/SimpleLinkManagerTest.java
@@ -1,4 +1,4 @@
-package org.onlab.onos.net.trivial.impl;
+package org.onlab.onos.net.trivial.link.impl;
import com.google.common.collect.ImmutableSet;
import org.junit.After;
@@ -21,6 +21,7 @@
import org.onlab.onos.net.link.LinkService;
import org.onlab.onos.net.provider.AbstractProvider;
import org.onlab.onos.net.provider.ProviderId;
+import org.onlab.onos.event.impl.TestEventDispatcher;
import java.util.ArrayList;
import java.util.Iterator;
diff --git a/pom.xml b/pom.xml
index 3ec7f1c..1002901 100644
--- a/pom.xml
+++ b/pom.xml
@@ -332,7 +332,7 @@
<group>
<title>Core Subsystems</title>
<packages>
- org.onlab.onos.net.trivial.impl:org.onlab.onos.net.*.impl:org.onlab.onos.impl:org.onlab.onos.event.impl
+ org.onlab.onos.net.trivial.*:org.onlab.onos.net.*.impl:org.onlab.onos.impl:org.onlab.onos.event.impl
</packages>
</group>
<group>
diff --git a/providers/of/link/src/main/java/org/onlab/onos/provider/of/link/impl/LinkDiscovery.java b/providers/of/link/src/main/java/org/onlab/onos/provider/of/link/impl/LinkDiscovery.java
index b0b86f0..da89681 100644
--- a/providers/of/link/src/main/java/org/onlab/onos/provider/of/link/impl/LinkDiscovery.java
+++ b/providers/of/link/src/main/java/org/onlab/onos/provider/of/link/impl/LinkDiscovery.java
@@ -42,7 +42,7 @@
import org.onlab.packet.Ethernet;
import org.onlab.packet.ONLabLddp;
import org.onlab.packet.ONLabLddp.DPIDandPort;
-import org.onlab.timer.Timer;
+import org.onlab.util.Timer;
import org.projectfloodlight.openflow.protocol.OFFactory;
import org.projectfloodlight.openflow.protocol.OFMessage;
import org.projectfloodlight.openflow.protocol.OFPacketOut;
diff --git a/providers/of/link/src/main/java/org/onlab/onos/provider/of/link/impl/OpenFlowLinkProvider.java b/providers/of/link/src/main/java/org/onlab/onos/provider/of/link/impl/OpenFlowLinkProvider.java
index b26d61c..218145d 100644
--- a/providers/of/link/src/main/java/org/onlab/onos/provider/of/link/impl/OpenFlowLinkProvider.java
+++ b/providers/of/link/src/main/java/org/onlab/onos/provider/of/link/impl/OpenFlowLinkProvider.java
@@ -1,10 +1,5 @@
package org.onlab.onos.provider.of.link.impl;
-import static org.slf4j.LoggerFactory.getLogger;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
@@ -28,6 +23,11 @@
import org.projectfloodlight.openflow.protocol.OFPortStatus;
import org.slf4j.Logger;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
/**
* Provider which uses an OpenFlow controller to detect network
* infrastructure links.
@@ -101,7 +101,7 @@
@Override
public void switchAdded(Dpid dpid) {
discoverers.put(dpid, new LinkDiscovery(controller.getSwitch(dpid),
- controller, providerService, useBDDP));
+ controller, providerService, useBDDP));
}
diff --git a/utils/misc/src/main/java/org/onlab/timer/Timer.java b/utils/misc/src/main/java/org/onlab/timer/Timer.java
deleted file mode 100644
index 1f821a7..0000000
--- a/utils/misc/src/main/java/org/onlab/timer/Timer.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package org.onlab.timer;
-
-import org.jboss.netty.util.HashedWheelTimer;
-
-
-public final class Timer {
-
- private Timer() {}
-
- private static HashedWheelTimer timer;
-
- public static HashedWheelTimer getTimer() {
- if (Timer.timer == null) {
- Timer.timer = new HashedWheelTimer();
- Timer.timer.start();
- }
- return Timer.timer;
- }
-
-}
diff --git a/utils/misc/src/main/java/org/onlab/util/Timer.java b/utils/misc/src/main/java/org/onlab/util/Timer.java
new file mode 100644
index 0000000..276138f
--- /dev/null
+++ b/utils/misc/src/main/java/org/onlab/util/Timer.java
@@ -0,0 +1,30 @@
+package org.onlab.util;
+
+import org.jboss.netty.util.HashedWheelTimer;
+
+/**
+ * Hashed-wheel timer singleton. Care must be taken to shutdown the timer
+ * only when the VM is ready to exit.
+ */
+public final class Timer {
+
+ private static HashedWheelTimer timer;
+
+ // Ban public construction
+ private Timer() {
+ }
+
+ /**
+ * Returns the singleton hashed-wheel timer.
+ *
+ * @return hashed-wheel timer
+ */
+ public static HashedWheelTimer getTimer() {
+ if (Timer.timer == null) {
+ Timer.timer = new HashedWheelTimer();
+ Timer.timer.start();
+ }
+ return Timer.timer;
+ }
+
+}