tom

Adding more topology manager/store implementation.

......@@ -20,6 +20,13 @@ public interface TopologyService {
Topology currentTopology();
/**
* Indicates whether the specified topology is the latest or not.
* @param topology topology descriptor
* @return true if the topology is the most recent; false otherwise
*/
boolean isLatest(Topology topology);
/**
* Returns the set of clusters in the specified topology.
*
* @param topology topology descriptor
......
package org.onlab.onos.net.trivial.impl;
import org.onlab.onos.net.AbstractModel;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.net.topology.Topology;
/**
* Default implementation of the topology descriptor. This carries the
* backing topology data.
*/
public class DefaultTopology extends AbstractModel implements Topology {
private final long time;
private final int clusterCount;
private final int deviceCount;
private final int linkCount;
private final int pathCount;
/**
* Creates a topology descriptor attributed to the specified provider.
*
* @param providerId identity of the provider
* @param time creation time in system nanos
* @param clusterCount number of clusters
* @param deviceCount number of devices
* @param linkCount number of links
* @param pathCount number of pre-computed paths
*/
DefaultTopology(ProviderId providerId, long time, int clusterCount,
int deviceCount, int linkCount, int pathCount) {
super(providerId);
this.time = time;
this.clusterCount = clusterCount;
this.deviceCount = deviceCount;
this.linkCount = linkCount;
this.pathCount = pathCount;
}
@Override
public long time() {
return time;
}
@Override
public int clusterCount() {
return clusterCount;
}
@Override
public int deviceCount() {
return deviceCount;
}
@Override
public int linkCount() {
return linkCount;
}
@Override
public int pathCount() {
return pathCount;
}
}
......@@ -150,7 +150,8 @@ public class SimpleDeviceManager
}
// Personalized device provider service issued to the supplied provider.
private class InternalDeviceProviderService extends AbstractProviderService<DeviceProvider>
private class InternalDeviceProviderService
extends AbstractProviderService<DeviceProvider>
implements DeviceProviderService {
InternalDeviceProviderService(DeviceProvider provider) {
......
......@@ -158,7 +158,7 @@ public class SimpleHostManager
// Posts the specified event to the local event dispatcher.
private void post(HostEvent event) {
if (event != null && eventDispatcher != null) {
if (event != null) {
eventDispatcher.post(event);
}
}
......
......@@ -36,8 +36,8 @@ import com.google.common.collect.Sets;
@Component(immediate = true)
@Service
public class SimpleLinkManager
extends AbstractProviderRegistry<LinkProvider, LinkProviderService>
implements LinkService, LinkAdminService, LinkProviderRegistry {
extends AbstractProviderRegistry<LinkProvider, LinkProviderService>
implements LinkService, LinkAdminService, LinkProviderRegistry {
private static final String DEVICE_ID_NULL = "Device ID cannot be null";
private static final String LINK_DESC_NULL = "Link description cannot be null";
......@@ -46,7 +46,7 @@ implements LinkService, LinkAdminService, LinkProviderRegistry {
private final Logger log = getLogger(getClass());
private final AbstractListenerRegistry<LinkEvent, LinkListener>
listenerRegistry = new AbstractListenerRegistry<>();
listenerRegistry = new AbstractListenerRegistry<>();
private final SimpleLinkStore store = new SimpleLinkStore();
......@@ -79,7 +79,7 @@ implements LinkService, LinkAdminService, LinkProviderRegistry {
public Set<Link> getDeviceLinks(DeviceId deviceId) {
checkNotNull(deviceId, DEVICE_ID_NULL);
return Sets.union(store.getDeviceEgressLinks(deviceId),
store.getDeviceIngressLinks(deviceId));
store.getDeviceIngressLinks(deviceId));
}
@Override
......@@ -98,7 +98,7 @@ implements LinkService, LinkAdminService, LinkProviderRegistry {
public Set<Link> getLinks(ConnectPoint connectPoint) {
checkNotNull(connectPoint, CONNECT_POINT_NULL);
return Sets.union(store.getEgressLinks(connectPoint),
store.getIngressLinks(connectPoint));
store.getIngressLinks(connectPoint));
}
@Override
......@@ -146,8 +146,9 @@ implements LinkService, LinkAdminService, LinkProviderRegistry {
}
// Personalized link provider service issued to the supplied provider.
private class InternalLinkProviderService extends AbstractProviderService<LinkProvider>
implements LinkProviderService {
private class InternalLinkProviderService
extends AbstractProviderService<LinkProvider>
implements LinkProviderService {
InternalLinkProviderService(LinkProvider provider) {
super(provider);
......@@ -157,27 +158,31 @@ implements LinkService, LinkAdminService, LinkProviderRegistry {
public void linkDetected(LinkDescription linkDescription) {
checkNotNull(linkDescription, LINK_DESC_NULL);
checkValidity();
log.debug("Link {} detected", linkDescription);
LinkEvent event = store.createOrUpdateLink(provider().id(),
linkDescription);
post(event);
linkDescription);
if (event != null) {
log.debug("Link {} detected", linkDescription);
post(event);
}
}
@Override
public void linkVanished(LinkDescription linkDescription) {
checkNotNull(linkDescription, LINK_DESC_NULL);
checkValidity();
log.info("Link {} vanished", linkDescription);
LinkEvent event = store.removeLink(linkDescription.src(),
linkDescription.dst());
post(event);
linkDescription.dst());
if (event != null) {
log.info("Link {} vanished", linkDescription);
post(event);
}
}
@Override
public void linksVanished(ConnectPoint connectPoint) {
checkNotNull(connectPoint, "Connect point cannot be null");
checkValidity();
log.info("Link for connection point {} vanished", connectPoint);
log.info("Links for connection point {} vanished", connectPoint);
removeLinks(getLinks(connectPoint));
}
......@@ -185,7 +190,7 @@ implements LinkService, LinkAdminService, LinkProviderRegistry {
public void linksVanished(DeviceId deviceId) {
checkNotNull(deviceId, DEVICE_ID_NULL);
checkValidity();
log.info("Link for device {} vanished", deviceId);
log.info("Links for device {} vanished", deviceId);
removeLinks(getDeviceLinks(deviceId));
}
}
......@@ -200,7 +205,7 @@ implements LinkService, LinkAdminService, LinkProviderRegistry {
// Posts the specified event to the local event dispatcher.
private void post(LinkEvent event) {
if (event != null && eventDispatcher != null) {
if (event != null) {
eventDispatcher.post(event);
}
}
......
......@@ -72,25 +72,26 @@ public class SimpleTopologyManager
}
@Override
protected TopologyProviderService createProviderService(TopologyProvider provider) {
return new InternalTopologyProviderService(provider);
public Topology currentTopology() {
return store.currentTopology();
}
@Override
public Topology currentTopology() {
return null;
public boolean isLatest(Topology topology) {
checkNotNull(topology, TOPOLOGY_NULL);
return store.isLatest(topology);
}
@Override
public Set<TopologyCluster> getClusters(Topology topology) {
checkNotNull(topology, TOPOLOGY_NULL);
return null;
return store.getClusters(topology);
}
@Override
public Graph<TopoVertex, TopoEdge> getGraph(Topology topology) {
checkNotNull(topology, TOPOLOGY_NULL);
return null;
return store.getGraph(topology);
}
@Override
......@@ -98,7 +99,7 @@ public class SimpleTopologyManager
checkNotNull(topology, TOPOLOGY_NULL);
checkNotNull(src, DEVICE_ID_NULL);
checkNotNull(dst, DEVICE_ID_NULL);
return null;
return store.getPaths(topology, src, dst);
}
@Override
......@@ -107,21 +108,21 @@ public class SimpleTopologyManager
checkNotNull(src, DEVICE_ID_NULL);
checkNotNull(dst, DEVICE_ID_NULL);
checkNotNull(weight, "Link weight cannot be null");
return null;
return store.getPaths(topology, src, dst, weight);
}
@Override
public boolean isInfrastructure(Topology topology, ConnectPoint connectPoint) {
checkNotNull(topology, TOPOLOGY_NULL);
checkNotNull(connectPoint, CONNECTION_POINT_NULL);
return false;
return store.isInfrastructure(topology, connectPoint);
}
@Override
public boolean isInBroadcastTree(Topology topology, ConnectPoint connectPoint) {
checkNotNull(topology, TOPOLOGY_NULL);
checkNotNull(connectPoint, CONNECTION_POINT_NULL);
return false;
return store.isInBroadcastTree(topology, connectPoint);
}
@Override
......@@ -135,6 +136,11 @@ public class SimpleTopologyManager
}
// Personalized host provider service issued to the supplied provider.
@Override
protected TopologyProviderService createProviderService(TopologyProvider provider) {
return new InternalTopologyProviderService(provider);
}
private class InternalTopologyProviderService
extends AbstractProviderService<TopologyProvider>
implements TopologyProviderService {
......@@ -147,8 +153,12 @@ public class SimpleTopologyManager
public void topologyChanged(TopologyDescription topoDescription,
List<Event> reasons) {
checkNotNull(topoDescription, "Topology description cannot be null");
log.info("Topology changed due to: {}",
reasons == null ? "initial compute" : reasons);
TopologyEvent event = store.updateTopology(topoDescription, reasons);
if (event != null) {
log.info("Topology changed due to: {}",
reasons == null ? "initial compute" : reasons);
eventDispatcher.post(event);
}
}
}
......
package org.onlab.onos.net.trivial.impl;
import org.onlab.graph.Graph;
import org.onlab.onos.event.Event;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.Path;
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.Topology;
import org.onlab.onos.net.topology.TopologyCluster;
import org.onlab.onos.net.topology.TopologyDescription;
import org.onlab.onos.net.topology.TopologyEvent;
import java.util.List;
import java.util.Set;
/**
* Manages inventory of topology snapshots using trivial in-memory
* implementation.
*/
public class SimpleTopologyStore {
private volatile DefaultTopology current;
/**
* Returns the current topology snapshot.
*
* @return current topology descriptor
*/
Topology currentTopology() {
return current;
}
/**
* Indicates whether the topology is the latest.
* @param topology topology descriptor
* @return true if topology is the most recent one
*/
boolean isLatest(Topology topology) {
return topology == current;
}
/**
* Returns the set of topology SCC clusters.
*
* @param topology topology descriptor
* @return set of clusters
*/
Set<TopologyCluster> getClusters(Topology topology) {
return null;
}
/**
* Returns the immutable graph view of the current topology.
*
* @param topology topology descriptor
* @return graph view
*/
Graph<TopoVertex, TopoEdge> getGraph(Topology topology) {
return null;
}
/**
* Returns the set of pre-computed shortest paths between src and dest.
*
* @param topology topology descriptor
* @param src source device
* @param dst destination device
* @return set of shortest paths
*/
Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst) {
return null;
}
/**
* Computes and returns the set of shortest paths between src and dest.
*
* @param topology topology descriptor
* @param src source device
* @param dst destination device
* @param weight link weight function
* @return set of shortest paths
*/
Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst,
LinkWeight weight) {
return null;
}
/**
* Indicates whether the given connect point is part of the network fabric.
*
* @param topology topology descriptor
* @param connectPoint connection point
* @return true if infrastructure; false otherwise
*/
boolean isInfrastructure(Topology topology, ConnectPoint connectPoint) {
return false;
}
/**
* Indicates whether the given connect point is part of the broadcast tree.
*
* @param topology topology descriptor
* @param connectPoint connection point
* @return true if in broadcast tree; false otherwise
*/
boolean isInBroadcastTree(Topology topology, ConnectPoint connectPoint) {
return false;
}
/**
* Generates a new topology snapshot from the specified description.
*
* @param topoDescription topology description
* @param reasons list of events that triggered the update
* @return topology update event or null if the description is old
*/
TopologyEvent updateTopology(TopologyDescription topoDescription, List<Event> reasons) {
return null;
}
}
......