Ayaka Koshibe

Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next

Showing 40 changed files with 749 additions and 468 deletions
package org.onlab.onos.cli;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onlab.onos.GreetService;
/**
* Simple command example to demonstrate use of Karaf shell extensions; shows
* use of an optional parameter as well.
*/
@Command(scope = "onos", name = "greet", description = "Issues a greeting")
public class GreetCommand extends AbstractShellCommand {
@Argument(index = 0, name = "name", description = "Name to greet",
required = false, multiValued = false)
String name = "dude";
@Override
protected Object doExecute() throws Exception {
print(getService(GreetService.class).yo(name));
return null;
}
}
package org.onlab.onos.cli.net;
import com.google.common.collect.Lists;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.topology.TopologyCluster;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import static org.onlab.onos.net.topology.ClusterId.clusterId;
/**
* Lists devices of the specified topology cluster in the current topology.
*/
@Command(scope = "onos", name = "cluster-devices",
description = "Lists devices of the specified topology cluster in the current topology")
public class ClusterDevicesCommand extends ClustersListCommand {
@Argument(index = 0, name = "id", description = "Cluster ID",
required = false, multiValued = false)
String id = null;
protected static final Comparator<DeviceId> ID_COMPARATOR = new Comparator<DeviceId>() {
@Override
public int compare(DeviceId id1, DeviceId id2) {
return id1.uri().toString().compareTo(id2.uri().toString());
}
};
@Override
protected Object doExecute() throws Exception {
int cid = Integer.parseInt(id);
init();
TopologyCluster cluster = service.getCluster(topology, clusterId(cid));
List<DeviceId> ids = Lists.newArrayList(service.getClusterDevices(topology, cluster));
Collections.sort(ids, ID_COMPARATOR);
for (DeviceId deviceId : ids) {
print("%s", deviceId);
}
return null;
}
}
package org.onlab.onos.cli;
package org.onlab.onos.cli.net;
import org.apache.karaf.shell.console.Completer;
import org.apache.karaf.shell.console.completer.StringsCompleter;
import org.onlab.onos.GreetService;
import org.onlab.onos.cli.AbstractShellCommand;
import org.onlab.onos.net.topology.Topology;
import org.onlab.onos.net.topology.TopologyCluster;
import org.onlab.onos.net.topology.TopologyService;
import java.util.Iterator;
import java.util.List;
import java.util.SortedSet;
/**
* Simple example of a command-line parameter completer.
* For a more open-ended sets a more efficient implementation would be required.
* Cluster ID completer.
*/
public class NameCompleter implements Completer {
public class ClusterIdCompleter implements Completer {
@Override
public int complete(String buffer, int cursor, List<String> candidates) {
// Delegate string completer
StringsCompleter delegate = new StringsCompleter();
// Fetch our service and feed it's offerings to the string completer
GreetService greetService = AbstractShellCommand.get(GreetService.class);
Iterator<String> it = greetService.names().iterator();
TopologyService service = AbstractShellCommand.get(TopologyService.class);
Topology topology = service.currentTopology();
SortedSet<String> strings = delegate.getStrings();
while (it.hasNext()) {
strings.add(it.next());
for (TopologyCluster cluster : service.getClusters(topology)) {
strings.add(Integer.toString(cluster.id().index()));
}
// Now let the completer do the work for figuring out what to offer.
......
package org.onlab.onos.cli.net;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.topology.TopologyCluster;
import static org.onlab.onos.cli.net.LinksListCommand.linkString;
import static org.onlab.onos.net.topology.ClusterId.clusterId;
/**
* Lists links of the specified topology cluster in the current topology.
*/
@Command(scope = "onos", name = "cluster-links",
description = "Lists links of the specified topology cluster in the current topology")
public class ClusterLinksCommand extends ClustersListCommand {
@Argument(index = 0, name = "id", description = "Cluster ID",
required = false, multiValued = false)
String id = null;
@Override
protected Object doExecute() throws Exception {
int cid = Integer.parseInt(id);
init();
TopologyCluster cluster = service.getCluster(topology, clusterId(cid));
for (Link link : service.getClusterLinks(topology, cluster)) {
print(linkString(link));
}
return null;
}
}
package org.onlab.onos.cli.net;
import com.google.common.collect.Lists;
import org.apache.karaf.shell.commands.Command;
import org.onlab.onos.net.topology.TopologyCluster;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
* Lists all clusters in the current topology.
*/
@Command(scope = "onos", name = "clusters",
description = "Lists all clusters in the current topology")
public class ClustersListCommand extends TopologyCommand {
private static final String FMT =
"id=%s, devices=%d, links=%d";
protected static final Comparator<TopologyCluster> ID_COMPARATOR =
new Comparator<TopologyCluster>() {
@Override
public int compare(TopologyCluster c1, TopologyCluster c2) {
return c1.id().index() - c2.id().index();
}
};
@Override
protected Object doExecute() throws Exception {
init();
List<TopologyCluster> clusters = Lists.newArrayList(service.getClusters(topology));
Collections.sort(clusters, ID_COMPARATOR);
for (TopologyCluster cluster : clusters) {
print(FMT, cluster.id(), cluster.deviceCount(), cluster.linkCount());
}
return null;
}
}
......@@ -27,9 +27,20 @@ public class LinksListCommand extends AbstractShellCommand {
Iterable<Link> links = uri != null ?
service.getDeviceLinks(deviceId(uri)) : service.getLinks();
for (Link link : links) {
print(FMT, link.src().deviceId(), link.src().port(),
link.dst().deviceId(), link.dst().port(), link.type());
print(linkString(link));
}
return null;
}
/**
* Returns a formated string representing the gien link.
*
* @param link infrastructure link
* @return formated link string
*/
public static String linkString(Link link) {
return String.format(FMT, link.src().deviceId(), link.src().port(),
link.dst().deviceId(), link.dst().port(), link.type());
}
}
......
package org.onlab.onos.cli.net;
import org.apache.karaf.shell.commands.Command;
import org.onlab.onos.cli.AbstractShellCommand;
import org.onlab.onos.net.topology.Topology;
import org.onlab.onos.net.topology.TopologyService;
/**
* Lists summary of the current topology.
*/
@Command(scope = "onos", name = "topology",
description = "Lists summary of the current topology")
public class TopologyCommand extends AbstractShellCommand {
private static final String FMT =
"time=%s, devices=%d, links=%d, clusters=%d, paths=%d";
protected TopologyService service;
protected Topology topology;
/**
* Initializes the context for all cluster commands.
*/
protected void init() {
service = getService(TopologyService.class);
topology = service.currentTopology();
}
@Override
protected Object doExecute() throws Exception {
init();
print(FMT, topology.time(), topology.deviceCount(), topology.linkCount(),
topology.clusterCount(), topology.pathCount());
return null;
}
}
......@@ -32,16 +32,27 @@
</command>
<command>
<action class="org.onlab.onos.cli.GreetCommand"/>
<action class="org.onlab.onos.cli.net.TopologyCommand"/>
</command>
<command>
<action class="org.onlab.onos.cli.net.ClustersListCommand"/>
</command>
<command>
<action class="org.onlab.onos.cli.net.ClusterDevicesCommand"/>
<completers>
<ref component-id="nameCompleter"/>
<ref component-id="clusterIdCompleter"/>
</completers>
</command>
<command>
<action class="org.onlab.onos.cli.net.ClusterLinksCommand"/>
<completers>
<ref component-id="clusterIdCompleter"/>
</completers>
</command>
</command-bundle>
<bean id="deviceIdCompleter" class="org.onlab.onos.cli.net.DeviceIdCompleter"/>
<bean id="clusterIdCompleter" class="org.onlab.onos.cli.net.ClusterIdCompleter"/>
<bean id="roleCompleter" class="org.onlab.onos.cli.net.RoleCompleter"/>
<bean id="nameCompleter" class="org.onlab.onos.cli.NameCompleter"/>
</blueprint>
......
......@@ -16,7 +16,7 @@ public class DefaultLink extends AbstractModel implements Link {
private final Type type;
/**
* Creates a link description using the supplied information.
* Creates an infrastructure link using the supplied information.
*
* @param providerId provider identity
* @param src link source
......
package org.onlab.onos.net;
import com.google.common.collect.ImmutableList;
import org.onlab.onos.net.provider.ProviderId;
import java.util.List;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Default implementation of a network path.
*/
public class DefaultPath extends DefaultLink implements Path {
private final List<Link> links;
private final double cost;
/**
* Creates a path from the specified source and destination using the
* supplied list of links.
*
* @param providerId provider identity
* @param links contiguous links that comprise the path
* @param cost unit-less path cost
*/
public DefaultPath(ProviderId providerId, List<Link> links, double cost) {
super(providerId, source(links), destination(links), Type.INDIRECT);
this.links = ImmutableList.copyOf(links);
this.cost = cost;
}
@Override
public List<Link> links() {
return links;
}
@Override
public double cost() {
return cost;
}
// Returns the source of the first link.
private static ConnectPoint source(List<Link> links) {
checkNotNull(links, "List of path links cannot be null");
checkArgument(!links.isEmpty(), "List of path links cannot be empty");
return links.get(0).src();
}
// Returns the destination of the last link.
private static ConnectPoint destination(List<Link> links) {
checkNotNull(links, "List of path links cannot be null");
checkArgument(!links.isEmpty(), "List of path links cannot be empty");
return links.get(links.size() - 1).dst();
}
@Override
public int hashCode() {
return 31 * super.hashCode() + Objects.hash(links);
}
@Override
public boolean equals(Object obj) {
if (obj instanceof DefaultPath) {
final DefaultPath other = (DefaultPath) obj;
return Objects.equals(this.links, other.links);
}
return false;
}
}
......@@ -17,4 +17,11 @@ public interface Path extends Link {
*/
List<Link> links();
/**
* Returns the path cost as a unit-less value.
*
* @return unit-less path cost
*/
double cost();
}
......
......@@ -27,6 +27,15 @@ public final class ClusterId {
return new ClusterId(id);
}
/**
* Returns the backing integer index.
*
* @return backing integer index
*/
public int index() {
return id;
}
@Override
public int hashCode() {
return Objects.hash(id);
......
package org.onlab.onos.net.topology;
import com.google.common.collect.ImmutableSet;
import org.onlab.onos.net.Description;
/**
* Describes attribute(s) of a network graph.
*/
public interface GraphDescription extends Description {
/**
* Returns the creation timestamp of the graph description. This is
* expressed in system nanos to allow proper sequencing.
*
* @return graph description creation timestamp
*/
long timestamp();
/**
* Returns the set of topology graph vertexes.
*
* @return set of graph vertexes
*/
ImmutableSet<TopologyVertex> vertexes();
/**
* Returns the set of topology graph edges.
*
* @return set of graph edges
*/
ImmutableSet<TopologyEdge> edges();
}
......@@ -6,5 +6,5 @@ import org.onlab.graph.EdgeWeight;
* Entity capable of determining cost or weight of a specified topology
* graph edge.
*/
public interface LinkWeight extends EdgeWeight<TopoVertex, TopoEdge> {
public interface LinkWeight extends EdgeWeight<TopologyVertex, TopologyEdge> {
}
......
package org.onlab.onos.net.topology;
import org.onlab.graph.Graph;
import org.onlab.graph.GraphPathSearch;
import org.onlab.onos.net.Description;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.Link;
import java.util.Set;
/**
* Describes attribute(s) of a network topology.
*/
public interface TopologyDescription extends Description {
/**
* Returns the creation timestamp of the topology description. This is
* expressed in system nanos to allow proper sequencing.
*
* @return topology description creation timestamp
*/
long timestamp();
/**
* Returns the topology graph.
*
* @return network graph
*/
Graph<TopoVertex, TopoEdge> graph();
/**
* Returns the results of the path search through the network graph. This
* is assumed to contain results of seach fro the given device to all
* other devices.
*
* @param srcDeviceId source device identifier
* @return path search result for the given source node
*/
GraphPathSearch.Result pathResults(DeviceId srcDeviceId);
/**
* Returns the set of topology SCC clusters.
*
* @return set of SCC clusters
*/
Set<TopologyCluster> clusters();
/**
* Returns the set of devices contained by the specified topology cluster.
*
* @return set of devices that belong to the specified cluster
*/
Set<DeviceId> clusterDevices(TopologyCluster cluster);
/**
* Returns the set of infrastructure links contained by the specified cluster.
*
* @return set of links that form the given cluster
*/
Set<Link> clusterLinks(TopologyCluster cluster);
/**
* Returns the topology SCC cluster which contains the given device.
*
* @param deviceId device identifier
* @return topology cluster that contains the specified device
*/
TopologyCluster clusterFor(DeviceId deviceId);
}
......@@ -6,7 +6,7 @@ import org.onlab.onos.net.Link;
/**
* Represents an edge in the topology graph.
*/
public interface TopoEdge extends Edge<TopoVertex> {
public interface TopologyEdge extends Edge<TopologyVertex> {
/**
* Returns the associated infrastructure link.
......
package org.onlab.onos.net.topology;
import org.onlab.graph.Graph;
/**
* Represents an immutable topology graph.
*/
public interface TopologyGraph extends Graph<TopologyVertex, TopologyEdge> {
}
......@@ -10,16 +10,13 @@ import java.util.List;
*/
public interface TopologyProviderService extends ProviderService<TopologyProvider> {
// What can be conveyed in a topology that isn't by individual
// providers?
/**
* Signals the core that some aspect of the topology has changed.
*
* @param topoDescription information about topology
* @param reasons events that triggered topology change
* @param graphDescription information about the network graph
* @param reasons events that triggered topology change
*/
void topologyChanged(TopologyDescription topoDescription,
void topologyChanged(GraphDescription graphDescription,
List<Event> reasons);
}
......
package org.onlab.onos.net.topology;
import org.onlab.graph.Graph;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.Path;
import java.util.Set;
......@@ -21,12 +21,21 @@ public interface TopologyService {
/**
* 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 graph view of the specified topology.
*
* @param topology topology descriptor
* @return topology graph view
*/
TopologyGraph getGraph(Topology topology);
/**
* Returns the set of clusters in the specified topology.
*
* @param topology topology descriptor
......@@ -35,12 +44,31 @@ public interface TopologyService {
Set<TopologyCluster> getClusters(Topology topology);
/**
* Returns the graph view of the specified topology.
* Returns the cluster with the specified ID.
*
* @param topology topology descriptor
* @return topology graph view
* @param topology topology descriptor
* @param clusterId cluster identifier
* @return topology cluster
*/
TopologyCluster getCluster(Topology topology, ClusterId clusterId);
/**
* Returns the set of devices that belong to the specified cluster.
*
* @param topology topology descriptor
* @param cluster topology cluster
* @return set of cluster devices
*/
Set<DeviceId> getClusterDevices(Topology topology, TopologyCluster cluster);
/**
* Returns the set of links that form the specified cluster.
*
* @param topology topology descriptor
* @param cluster topology cluster
* @return set of cluster links
*/
Graph<TopoVertex, TopoEdge> getGraph(Topology topology);
Set<Link> getClusterLinks(Topology topology, TopologyCluster cluster);
/**
* Returns the set of all shortest paths, precomputed in terms of hop-count,
......
......@@ -6,7 +6,7 @@ import org.onlab.onos.net.DeviceId;
/**
* Represents a vertex in the topology graph.
*/
public interface TopoVertex extends Vertex {
public interface TopologyVertex extends Vertex {
/**
* Returns the associated infrastructure device identification.
......
package org.onlab.onos.net.trivial.impl;
package org.onlab.onos.net.trivial.host.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.host.impl;
import static org.onlab.onos.net.host.HostEvent.Type.HOST_ADDED;
import static org.onlab.onos.net.host.HostEvent.Type.HOST_MOVED;
import static org.onlab.onos.net.host.HostEvent.Type.HOST_REMOVED;
import static org.onlab.onos.net.host.HostEvent.Type.HOST_UPDATED;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DefaultHost;
......@@ -15,17 +26,6 @@ import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import static org.onlab.onos.net.host.HostEvent.Type.HOST_REMOVED;
import static org.onlab.onos.net.host.HostEvent.Type.HOST_ADDED;
import static org.onlab.onos.net.host.HostEvent.Type.HOST_UPDATED;
import static org.onlab.onos.net.host.HostEvent.Type.HOST_MOVED;
/**
* Manages inventory of end-station hosts using trivial in-memory
* implementation.
......@@ -36,6 +36,7 @@ public class SimpleHostStore {
// hosts sorted based on their location
private final Multimap<ConnectPoint, Host> locations = HashMultimap.create();
/**
* Creates a new host or updates the existing one based on the specified
* description.
......@@ -46,7 +47,7 @@ public class SimpleHostStore {
* @return appropriate event or null if no change resulted
*/
HostEvent createOrUpdateHost(ProviderId providerId, HostId hostId,
HostDescription hostDescription) {
HostDescription hostDescription) {
Host host = hosts.get(hostId);
if (host == null) {
return createHost(providerId, hostId, hostDescription);
......
package org.onlab.onos.net.trivial.topology.impl;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
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.GraphDescription;
import org.onlab.onos.net.topology.TopologyEdge;
import org.onlab.onos.net.topology.TopologyVertex;
import java.util.Map;
/**
* Default implementation of an immutable topology graph data carrier.
*/
class DefaultGraphDescription implements GraphDescription {
private final long nanos;
private final ImmutableSet<TopologyVertex> vertexes;
private final ImmutableSet<TopologyEdge> edges;
private final Map<DeviceId, TopologyVertex> vertexesById = Maps.newHashMap();
/**
* Creates a minimal topology graph description to allow core to construct
* and process the topology graph.
*
* @param nanos time in nanos of when the topology description was created
* @param devices collection of infrastructure devices
* @param links collection of infrastructure links
*/
DefaultGraphDescription(long nanos, Iterable<Device> devices, Iterable<Link> links) {
this.nanos = nanos;
this.vertexes = buildVertexes(devices);
this.edges = buildEdges(links);
vertexesById.clear();
}
@Override
public long timestamp() {
return nanos;
}
@Override
public ImmutableSet<TopologyVertex> vertexes() {
return vertexes;
}
@Override
public ImmutableSet<TopologyEdge> edges() {
return edges;
}
// Builds a set of topology vertexes from the specified list of devices
private ImmutableSet<TopologyVertex> buildVertexes(Iterable<Device> devices) {
ImmutableSet.Builder<TopologyVertex> vertexes = ImmutableSet.builder();
for (Device device : devices) {
TopologyVertex vertex = new DefaultTopologyVertex(device.id());
vertexes.add(vertex);
vertexesById.put(vertex.deviceId(), vertex);
}
return vertexes.build();
}
// Builds a set of topology vertexes from the specified list of links
private ImmutableSet<TopologyEdge> buildEdges(Iterable<Link> links) {
ImmutableSet.Builder<TopologyEdge> edges = ImmutableSet.builder();
for (Link link : links) {
edges.add(new DefaultTopologyEdge(vertexOf(link.src()),
vertexOf(link.dst()), link));
}
return edges.build();
}
// Fetches a vertex corresponding to the given connection point device.
private TopologyVertex vertexOf(ConnectPoint connectPoint) {
DeviceId id = connectPoint.deviceId();
TopologyVertex vertex = vertexesById.get(id);
if (vertex == null) {
// If vertex does not exist, create one and register it.
vertex = new DefaultTopologyVertex(id);
vertexesById.put(id, vertex);
}
return vertex;
}
}
package org.onlab.onos.net.trivial.topology.provider.impl;
package org.onlab.onos.net.trivial.topology.impl;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.topology.TopoEdge;
import org.onlab.onos.net.topology.TopoVertex;
import org.onlab.onos.net.topology.TopologyEdge;
import org.onlab.onos.net.topology.TopologyVertex;
import java.util.Objects;
......@@ -11,11 +11,11 @@ import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Implementation of the topology edge backed by a link.
*/
class DefaultTopoEdge implements TopoEdge {
class DefaultTopologyEdge implements TopologyEdge {
private final Link link;
private final TopoVertex src;
private final TopoVertex dst;
private final TopologyVertex src;
private final TopologyVertex dst;
/**
* Creates a new topology edge.
......@@ -24,7 +24,7 @@ class DefaultTopoEdge implements TopoEdge {
* @param dst destination vertex
* @param link infrastructure link
*/
DefaultTopoEdge(TopoVertex src, TopoVertex dst, Link link) {
DefaultTopologyEdge(TopologyVertex src, TopologyVertex dst, Link link) {
this.src = src;
this.dst = dst;
this.link = link;
......@@ -36,12 +36,12 @@ class DefaultTopoEdge implements TopoEdge {
}
@Override
public TopoVertex src() {
public TopologyVertex src() {
return src;
}
@Override
public TopoVertex dst() {
public TopologyVertex dst() {
return dst;
}
......@@ -52,8 +52,8 @@ class DefaultTopoEdge implements TopoEdge {
@Override
public boolean equals(Object obj) {
if (obj instanceof DefaultTopoEdge) {
final DefaultTopoEdge other = (DefaultTopoEdge) obj;
if (obj instanceof DefaultTopologyEdge) {
final DefaultTopologyEdge other = (DefaultTopologyEdge) obj;
return Objects.equals(this.link, other.link);
}
return false;
......
package org.onlab.onos.net.trivial.topology.impl;
import org.onlab.graph.AdjacencyListsGraph;
import org.onlab.onos.net.topology.TopologyEdge;
import org.onlab.onos.net.topology.TopologyGraph;
import org.onlab.onos.net.topology.TopologyVertex;
import java.util.Set;
/**
* Default implementation of an immutable topology graph based on a generic
* implementation of adjacency lists graph.
*/
public class DefaultTopologyGraph
extends AdjacencyListsGraph<TopologyVertex, TopologyEdge>
implements TopologyGraph {
/**
* Creates a topology graph comprising of the specified vertexes and edges.
*
* @param vertexes set of graph vertexes
* @param edges set of graph edges
*/
public DefaultTopologyGraph(Set<TopologyVertex> vertexes, Set<TopologyEdge> edges) {
super(vertexes, edges);
}
}
package org.onlab.onos.net.trivial.topology.provider.impl;
package org.onlab.onos.net.trivial.topology.impl;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
......@@ -16,7 +16,7 @@ import org.onlab.onos.net.link.LinkListener;
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.net.topology.TopologyDescription;
import org.onlab.onos.net.topology.GraphDescription;
import org.onlab.onos.net.topology.TopologyProvider;
import org.onlab.onos.net.topology.TopologyProviderRegistry;
import org.onlab.onos.net.topology.TopologyProviderService;
......@@ -32,10 +32,12 @@ import static org.onlab.util.Tools.namedThreads;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Simple implementation of a network topology provider/computor.
* Default implementation of a network topology provider that feeds off
* device and link subsystem events to trigger assembly and computation of
* new topology snapshots.
*/
@Component(immediate = true)
public class SimpleTopologyProvider extends AbstractProvider
public class DefaultTopologyProvider extends AbstractProvider
implements TopologyProvider {
// TODO: make these configurable
......@@ -70,13 +72,13 @@ public class SimpleTopologyProvider extends AbstractProvider
/**
* Creates a provider with the supplier identifier.
*/
public SimpleTopologyProvider() {
public DefaultTopologyProvider() {
super(new ProviderId("org.onlab.onos.provider.topology"));
}
@Activate
public synchronized void activate() {
executor = newFixedThreadPool(MAX_THREADS, namedThreads("topo-compute-%d"));
executor = newFixedThreadPool(MAX_THREADS, namedThreads("topo-build-%d"));
accumulator = new TopologyChangeAccumulator();
providerService = providerRegistry.register(this);
......@@ -90,6 +92,8 @@ public class SimpleTopologyProvider extends AbstractProvider
@Deactivate
public synchronized void deactivate() {
isStarted = false;
deviceService.removeListener(deviceListener);
linkService.removeListener(linkListener);
providerRegistry.unregister(this);
......@@ -98,7 +102,6 @@ public class SimpleTopologyProvider extends AbstractProvider
executor.shutdownNow();
executor = null;
isStarted = false;
log.info("Stopped");
}
......@@ -108,18 +111,20 @@ public class SimpleTopologyProvider extends AbstractProvider
*
* @param reasons events which triggered the topology change
*/
private void triggerTopologyBuild(List<Event> reasons) {
executor.execute(new TopologyBuilderTask(reasons));
private synchronized void triggerTopologyBuild(List<Event> reasons) {
if (executor != null) {
executor.execute(new TopologyBuilderTask(reasons));
}
}
// 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) {
if (isStarted) {
TopologyDescription desc =
new DefaultTopologyDescription(System.nanoTime(),
deviceService.getDevices(),
linkService.getLinks());
GraphDescription desc =
new DefaultGraphDescription(System.nanoTime(),
deviceService.getDevices(),
linkService.getLinks());
providerService.topologyChanged(desc, reasons);
}
}
......
package org.onlab.onos.net.trivial.topology.provider.impl;
package org.onlab.onos.net.trivial.topology.impl;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.topology.TopoVertex;
import org.onlab.onos.net.topology.TopologyVertex;
import java.util.Objects;
/**
* Implementation of the topology vertex backed by a device id.
*/
class DefaultTopoVertex implements TopoVertex {
class DefaultTopologyVertex implements TopologyVertex {
private final DeviceId deviceId;
......@@ -17,7 +17,7 @@ class DefaultTopoVertex implements TopoVertex {
*
* @param deviceId backing infrastructure device identifier
*/
DefaultTopoVertex(DeviceId deviceId) {
DefaultTopologyVertex(DeviceId deviceId) {
this.deviceId = deviceId;
}
......@@ -33,8 +33,8 @@ class DefaultTopoVertex implements TopoVertex {
@Override
public boolean equals(Object obj) {
if (obj instanceof DefaultTopoVertex) {
final DefaultTopoVertex other = (DefaultTopoVertex) obj;
if (obj instanceof DefaultTopologyVertex) {
final DefaultTopologyVertex other = (DefaultTopologyVertex) obj;
return Objects.equals(this.deviceId, other.deviceId);
}
return false;
......
package org.onlab.onos.net.trivial.topology.impl;
import org.onlab.onos.net.DeviceId;
import java.util.Objects;
/**
* Key for filing pre-computed paths between source and destination devices.
*/
class PathKey {
private final DeviceId src;
private final DeviceId dst;
/**
* Creates a path key from the given source/dest pair.
* @param src source device
* @param dst destination device
*/
PathKey(DeviceId src, DeviceId dst) {
this.src = src;
this.dst = dst;
}
@Override
public int hashCode() {
return Objects.hash(src, dst);
}
@Override
public boolean equals(Object obj) {
if (obj instanceof PathKey) {
final PathKey other = (PathKey) obj;
return Objects.equals(this.src, other.src) && Objects.equals(this.dst, other.dst);
}
return false;
}
}
......@@ -6,22 +6,22 @@ import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.graph.Graph;
import org.onlab.onos.event.AbstractListenerRegistry;
import org.onlab.onos.event.Event;
import org.onlab.onos.event.EventDeliveryService;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.Path;
import org.onlab.onos.net.provider.AbstractProviderRegistry;
import org.onlab.onos.net.provider.AbstractProviderService;
import org.onlab.onos.net.topology.ClusterId;
import org.onlab.onos.net.topology.GraphDescription;
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 org.onlab.onos.net.topology.TopologyGraph;
import org.onlab.onos.net.topology.TopologyListener;
import org.onlab.onos.net.topology.TopologyProvider;
import org.onlab.onos.net.topology.TopologyProviderRegistry;
......@@ -46,6 +46,8 @@ public class SimpleTopologyManager
public static final String TOPOLOGY_NULL = "Topology cannot be null";
private static final String DEVICE_ID_NULL = "Device ID cannot be null";
private static final String CLUSTER_ID_NULL = "Cluster ID cannot be null";
private static final String CLUSTER_NULL = "Topology cluster cannot be null";
public static final String CONNECTION_POINT_NULL = "Connection point cannot be null";
private final Logger log = getLogger(getClass());
......@@ -79,19 +81,49 @@ public class SimpleTopologyManager
@Override
public boolean isLatest(Topology topology) {
checkNotNull(topology, TOPOLOGY_NULL);
return store.isLatest(topology);
return store.isLatest(defaultTopology(topology));
}
// Validates the specified topology and returns it as a default
private DefaultTopology defaultTopology(Topology topology) {
if (topology instanceof DefaultTopology) {
return (DefaultTopology) topology;
}
throw new IllegalArgumentException("Topology class " + topology.getClass() +
" not supported");
}
@Override
public Set<TopologyCluster> getClusters(Topology topology) {
checkNotNull(topology, TOPOLOGY_NULL);
return store.getClusters(topology);
return store.getClusters(defaultTopology(topology));
}
@Override
public TopologyCluster getCluster(Topology topology, ClusterId clusterId) {
checkNotNull(topology, TOPOLOGY_NULL);
checkNotNull(topology, CLUSTER_ID_NULL);
return store.getCluster(defaultTopology(topology), clusterId);
}
@Override
public Set<DeviceId> getClusterDevices(Topology topology, TopologyCluster cluster) {
checkNotNull(topology, TOPOLOGY_NULL);
checkNotNull(topology, CLUSTER_NULL);
return store.getClusterDevices(defaultTopology(topology), cluster);
}
@Override
public Set<Link> getClusterLinks(Topology topology, TopologyCluster cluster) {
checkNotNull(topology, TOPOLOGY_NULL);
checkNotNull(topology, CLUSTER_NULL);
return store.getClusterLinks(defaultTopology(topology), cluster);
}
@Override
public Graph<TopoVertex, TopoEdge> getGraph(Topology topology) {
public TopologyGraph getGraph(Topology topology) {
checkNotNull(topology, TOPOLOGY_NULL);
return store.getGraph(topology);
return store.getGraph(defaultTopology(topology));
}
@Override
......@@ -99,7 +131,7 @@ public class SimpleTopologyManager
checkNotNull(topology, TOPOLOGY_NULL);
checkNotNull(src, DEVICE_ID_NULL);
checkNotNull(dst, DEVICE_ID_NULL);
return store.getPaths(topology, src, dst);
return store.getPaths(defaultTopology(topology), src, dst);
}
@Override
......@@ -108,21 +140,21 @@ public class SimpleTopologyManager
checkNotNull(src, DEVICE_ID_NULL);
checkNotNull(dst, DEVICE_ID_NULL);
checkNotNull(weight, "Link weight cannot be null");
return store.getPaths(topology, src, dst, weight);
return store.getPaths(defaultTopology(topology), src, dst, weight);
}
@Override
public boolean isInfrastructure(Topology topology, ConnectPoint connectPoint) {
checkNotNull(topology, TOPOLOGY_NULL);
checkNotNull(connectPoint, CONNECTION_POINT_NULL);
return store.isInfrastructure(topology, connectPoint);
return store.isInfrastructure(defaultTopology(topology), connectPoint);
}
@Override
public boolean isInBroadcastTree(Topology topology, ConnectPoint connectPoint) {
checkNotNull(topology, TOPOLOGY_NULL);
checkNotNull(connectPoint, CONNECTION_POINT_NULL);
return store.isInBroadcastTree(topology, connectPoint);
return store.isInBroadcastTree(defaultTopology(topology), connectPoint);
}
@Override
......@@ -150,15 +182,14 @@ public class SimpleTopologyManager
}
@Override
public void topologyChanged(TopologyDescription topoDescription,
public void topologyChanged(GraphDescription topoDescription,
List<Event> reasons) {
checkNotNull(topoDescription, "Topology description cannot be null");
log.info("Topology changed due to: {}", // to be removed soon
reasons == null ? "initial compute" : reasons);
TopologyEvent event = store.updateTopology(topoDescription, reasons);
TopologyEvent event = store.updateTopology(provider().id(),
topoDescription, reasons);
if (event != null) {
log.info("Topology changed due to: {}",
log.info("Topology {} changed due to: {}", event.subject(),
reasons == null ? "initial compute" : reasons);
eventDispatcher.post(event);
}
......
package org.onlab.onos.net.trivial.topology.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.Link;
import org.onlab.onos.net.Path;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.net.topology.ClusterId;
import org.onlab.onos.net.topology.GraphDescription;
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 org.onlab.onos.net.topology.TopologyGraph;
import java.util.List;
import java.util.Set;
......@@ -45,23 +46,56 @@ class SimpleTopologyStore {
}
/**
* Returns the immutable graph view of the current topology.
*
* @param topology topology descriptor
* @return graph view
*/
TopologyGraph getGraph(DefaultTopology topology) {
return topology.getGraph();
}
/**
* Returns the set of topology SCC clusters.
*
* @param topology topology descriptor
* @return set of clusters
*/
Set<TopologyCluster> getClusters(Topology topology) {
return null;
Set<TopologyCluster> getClusters(DefaultTopology topology) {
return topology.getClusters();
}
/**
* Returns the immutable graph view of the current topology.
* Returns the cluster of the specified topology.
*
* @param topology topology descriptor
* @return graph view
* @param topology topology descriptor
* @param clusterId cluster identity
* @return topology cluster
*/
Graph<TopoVertex, TopoEdge> getGraph(Topology topology) {
return null;
TopologyCluster getCluster(DefaultTopology topology, ClusterId clusterId) {
return topology.getCluster(clusterId);
}
/**
* Returns the cluster of the specified topology.
*
* @param topology topology descriptor
* @param cluster topology cluster
* @return set of cluster links
*/
Set<DeviceId> getClusterDevices(DefaultTopology topology, TopologyCluster cluster) {
return topology.getClusterDevices(cluster);
}
/**
* Returns the cluster of the specified topology.
*
* @param topology topology descriptor
* @param cluster topology cluster
* @return set of cluster links
*/
Set<Link> getClusterLinks(DefaultTopology topology, TopologyCluster cluster) {
return topology.getClusterLinks(cluster);
}
/**
......@@ -72,8 +106,8 @@ class SimpleTopologyStore {
* @param dst destination device
* @return set of shortest paths
*/
Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst) {
return null;
Set<Path> getPaths(DefaultTopology topology, DeviceId src, DeviceId dst) {
return topology.getPaths(src, dst);
}
/**
......@@ -85,9 +119,9 @@ class SimpleTopologyStore {
* @param weight link weight function
* @return set of shortest paths
*/
Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst,
Set<Path> getPaths(DefaultTopology topology, DeviceId src, DeviceId dst,
LinkWeight weight) {
return null;
return topology.getPaths(src, dst, weight);
}
/**
......@@ -97,8 +131,8 @@ class SimpleTopologyStore {
* @param connectPoint connection point
* @return true if infrastructure; false otherwise
*/
boolean isInfrastructure(Topology topology, ConnectPoint connectPoint) {
return false;
boolean isInfrastructure(DefaultTopology topology, ConnectPoint connectPoint) {
return topology.isInfrastructure(connectPoint);
}
/**
......@@ -108,20 +142,36 @@ class SimpleTopologyStore {
* @param connectPoint connection point
* @return true if in broadcast tree; false otherwise
*/
boolean isInBroadcastTree(Topology topology, ConnectPoint connectPoint) {
return false;
boolean isInBroadcastTree(DefaultTopology topology, ConnectPoint connectPoint) {
return topology.isInBroadcastTree(connectPoint);
}
/**
* Generates a new topology snapshot from the specified description.
*
* @param topoDescription topology description
* @param reasons list of events that triggered the update
* @param providerId provider identification
* @param graphDescription topology graph 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,
TopologyEvent updateTopology(ProviderId providerId,
GraphDescription graphDescription,
List<Event> reasons) {
return null;
// First off, make sure that what we're given is indeed newer than
// what we already have.
if (current != null && graphDescription.timestamp() < current.time()) {
return null;
}
// Have the default topology construct self from the description data.
DefaultTopology newTopology =
new DefaultTopology(providerId, graphDescription);
// Promote the new topology to current and return a ready-to-send event.
synchronized (this) {
current = newTopology;
return new TopologyEvent(TopologyEvent.Type.TOPOLOGY_CHANGED, current);
}
}
}
......
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;
}
}
<body>
Built-in protocol-agnostic topology builder &amp; provider.
</body>
\ No newline at end of file
......@@ -7,6 +7,7 @@ import org.projectfloodlight.openflow.protocol.OFPacketIn;
import org.projectfloodlight.openflow.protocol.OFPacketOut;
import org.projectfloodlight.openflow.protocol.action.OFAction;
import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
import org.projectfloodlight.openflow.protocol.match.MatchField;
import org.projectfloodlight.openflow.types.OFBufferId;
import org.projectfloodlight.openflow.types.OFPort;
......@@ -83,12 +84,18 @@ public final class DefaultPacketContext implements PacketContext {
@Override
public Integer inPort() {
return pktin.getInPort().getPortNumber();
try {
return pktin.getInPort().getPortNumber();
} catch (UnsupportedOperationException e) {
return pktin.getMatch().get(MatchField.IN_PORT).getPortNumber();
}
}
@Override
public byte[] unparsed() {
return pktin.getData().clone();
}
private OFActionOutput buildOutput(Integer port) {
......
......@@ -250,9 +250,12 @@ public class OpenFlowControllerImpl implements OpenFlowController {
}
OpenFlowSwitch sw = activeMasterSwitches.remove(dpid);
if (sw == null) {
log.error("Transition to equal called on sw {}, but switch "
+ "was not found in controller-cache", dpid);
return;
sw = getSwitch(dpid);
if (sw == null) {
log.error("Transition to equal called on sw {}, but switch "
+ "was not found in controller-cache", dpid);
return;
}
}
log.info("Transitioned switch {} to EQUAL", dpid);
activeEqualSwitches.put(dpid, sw);
......
......@@ -2,10 +2,15 @@ package org.onlab.onos.of.drivers.impl;
import java.util.Collections;
import java.util.List;
import org.onlab.onos.of.controller.Dpid;
import org.onlab.onos.of.controller.driver.AbstractOpenFlowSwitch;
import org.onlab.onos.of.controller.driver.OpenFlowSwitchDriver;
import org.onlab.onos.of.controller.driver.OpenFlowSwitchDriverFactory;
import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
import org.projectfloodlight.openflow.protocol.OFMessage;
import org.projectfloodlight.openflow.protocol.OFVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -51,8 +56,36 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory {
}
log.warn("DriverManager could not identify switch desc: {}. "
+ "Assigning OFSwitchImplBase", desc);
return null;
+ "Assigning AbstractOpenFlowSwich", desc);
return new AbstractOpenFlowSwitch(dpid) {
@Override
public void write(List<OFMessage> msgs) {
channel.write(msgs);
}
@Override
public void write(OFMessage msg) {
channel.write(Collections.singletonList(msg));
}
@Override
public Boolean supportNxRole() {
return false;
}
@Override
public void startDriverHandshake() {}
@Override
public void processDriverHandshakeMessage(OFMessage m) {}
@Override
public boolean isDriverHandshakeComplete() {
return true;
}
};
}
/**
......
......@@ -320,6 +320,7 @@
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<show>package</show>
<docfilessubdirs>true</docfilessubdirs>
<doctitle>ONOS Java API</doctitle>
<groups>
......
......@@ -60,7 +60,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
* Creates an OpenFlow device provider.
*/
public OpenFlowDeviceProvider() {
super(new ProviderId("org.onlab.onos.provider.of.device"));
super(new ProviderId("org.onlab.onos.provider.openflow"));
}
@Activate
......
......@@ -37,7 +37,7 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid
* Creates an OpenFlow host provider.
*/
public OpenFlowHostProvider() {
super(new ProviderId("org.onlab.onos.provider.of.host"));
super(new ProviderId("org.onlab.onos.provider.openflow"));
}
@Activate
......
......@@ -55,7 +55,7 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid
* Creates an OpenFlow link provider.
*/
public OpenFlowLinkProvider() {
super(new ProviderId("org.onlab.onos.provider.of.link"));
super(new ProviderId("org.onlab.onos.provider.openflow"));
}
@Activate
......