You need to sign in or sign up before continuing.
tom

Added javadocs and separated trivial implementations into distinct packages.

Showing 23 changed files with 128 additions and 30 deletions
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;
......
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;
......
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;
......
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;
......
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;
......
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;
......
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;
......
package org.onlab.onos.net.trivial.impl;
package org.onlab.onos.net.trivial.topology.provider.impl;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
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.HashSet;
import java.util.List;
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.graph.TarjanGraphSearch.SCCResult;
import static org.onlab.onos.net.Link.Type.INDIRECT;
/**
......@@ -33,25 +39,32 @@ 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;
// private final Multimap<ClusterId, DeviceId> clusterDevices;
// private final Multimap<ClusterId, Link> clusterLinks;
// private final Map<DeviceId, TopologyCluster> deviceClusters;
// Secondary look-up indexes
private Multimap<ClusterId, DeviceId> devicesByCluster;
private Multimap<ClusterId, Link> linksByCluster;
private Map<DeviceId, TopologyCluster> clustersByDevice;
/**
* 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 devices
* @param links
*/
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.
......@@ -99,9 +112,62 @@ class DefaultTopologyDescription implements TopologyDescription {
// 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();
// 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);
findClusterLinks(edgeSet, cluster);
}
return clusters;
}
// Scan through the set of cluster vertices and convert it to a set of
// device ids; register the cluster by device id as well.
private void findClusterDevices(Set<TopoVertex> vertexSet,
DefaultTopologyCluster cluster) {
Set<DeviceId> ids = new HashSet<>(vertexSet.size());
for (TopoVertex v : vertexSet) {
DeviceId deviceId = v.deviceId();
devicesByCluster.put(cluster.id(), deviceId);
clustersByDevice.put(deviceId, cluster);
}
}
private void findClusterLinks(Set<TopoEdge> edgeSet,
DefaultTopologyCluster cluster) {
for (TopoEdge e : edgeSet) {
linksByCluster.put(cluster.id(), e.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();
......@@ -232,7 +298,7 @@ class DefaultTopologyDescription implements TopologyDescription {
// 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 static class HopCountLinkWeight implements LinkWeight {
private final int indirectLinkCost;
public HopCountLinkWeight(int indirectLinkCost) {
......@@ -247,4 +313,12 @@ class DefaultTopologyDescription implements TopologyDescription {
}
}
// 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;
}
}
}
......
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;
......
<body>
ONOS local event dispatching mechanism.
Local event dispatching mechanism.
</body>
\ No newline at end of file
......
<body>
ONOS Core infrastructure implementations.
Core infrastructure implementations.
</body>
\ No newline at end of file
......
<body>
ONOS core implementations.
Core subsystem for tracking infrastructure devices.
</body>
\ No newline at end of file
......
<body>
Core subsystem for tracking edn-station hosts.
</body>
\ No newline at end of file
<body>
Core subsystem for tracking infrastructure links.
</body>
\ No newline at end of file
<body>
Core subsystem for tracking consistent topology graph views.
</body>
\ No newline at end of file
<body>
Built-in protocol-agnostic topology builder &amp; provider.
</body>
\ No newline at end of file
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;
......
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.DeviceService;
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;
......
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.LinkProviderService;
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;
......
......@@ -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>
......
......@@ -42,7 +42,7 @@ import org.onlab.onos.of.controller.OpenFlowSwitch;
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;
......
......@@ -23,7 +23,7 @@ import org.onlab.onos.of.controller.OpenFlowController;
import org.onlab.onos.of.controller.OpenFlowSwitchListener;
import org.onlab.onos.of.controller.PacketContext;
import org.onlab.onos.of.controller.PacketListener;
import org.onlab.timer.Timer;
import org.onlab.util.Timer;
import org.projectfloodlight.openflow.protocol.OFPortConfig;
import org.projectfloodlight.openflow.protocol.OFPortDesc;
import org.projectfloodlight.openflow.protocol.OFPortState;
......
package org.onlab.timer;
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 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();
......