alshabib

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

1 +package org.onlab.onos.net.topology;
2 +
3 +import java.util.Objects;
4 +
5 +import static com.google.common.base.MoreObjects.toStringHelper;
6 +
7 +/**
8 + * Representation of the topology cluster identity.
9 + */
10 +public final class ClusterId {
11 +
12 + private final int id;
13 +
14 + // Public construction is prohibit
15 + private ClusterId(int id) {
16 + this.id = id;
17 + }
18 +
19 + /**
20 + * Returns the cluster identifier, represented by the specified integer
21 + * serial number.
22 + *
23 + * @param id integer serial number
24 + * @return cluster identifier
25 + */
26 + public static ClusterId clusterId(int id) {
27 + return new ClusterId(id);
28 + }
29 +
30 + @Override
31 + public int hashCode() {
32 + return Objects.hash(id);
33 + }
34 +
35 + @Override
36 + public boolean equals(Object obj) {
37 + if (obj instanceof ClusterId) {
38 + final ClusterId other = (ClusterId) obj;
39 + return Objects.equals(this.id, other.id);
40 + }
41 + return false;
42 + }
43 +
44 + @Override
45 + public String toString() {
46 + return toStringHelper(this).add("id", id).toString();
47 + }
48 +
49 +}
1 +package org.onlab.onos.net.topology;
2 +
3 +import org.onlab.onos.net.DeviceId;
4 +
5 +import java.util.Objects;
6 +
7 +import static com.google.common.base.MoreObjects.toStringHelper;
8 +
9 +/**
10 + * Default implementation of a network topology cluster.
11 + */
12 +public class DefaultTopologyCluster implements TopologyCluster {
13 +
14 + private final ClusterId id;
15 + private final int deviceCount;
16 + private final int linkCount;
17 + private final DeviceId root;
18 +
19 + /**
20 + * Creates a new topology cluster descriptor with the specified attributes.
21 + *
22 + * @param id cluster id
23 + * @param deviceCount number of devices in the cluster
24 + * @param linkCount number of links in the cluster
25 + * @param root cluster root node
26 + */
27 + public DefaultTopologyCluster(ClusterId id, int deviceCount, int linkCount,
28 + DeviceId root) {
29 + this.id = id;
30 + this.deviceCount = deviceCount;
31 + this.linkCount = linkCount;
32 + this.root = root;
33 + }
34 +
35 + @Override
36 + public ClusterId id() {
37 + return id;
38 + }
39 +
40 + @Override
41 + public int deviceCount() {
42 + return deviceCount;
43 + }
44 +
45 + @Override
46 + public int linkCount() {
47 + return linkCount;
48 + }
49 +
50 + @Override
51 + public DeviceId root() {
52 + return root;
53 + }
54 +
55 + @Override
56 + public int hashCode() {
57 + return Objects.hash(id, deviceCount, linkCount, root);
58 + }
59 +
60 + @Override
61 + public boolean equals(Object obj) {
62 + if (obj instanceof DefaultTopologyCluster) {
63 + final DefaultTopologyCluster other = (DefaultTopologyCluster) obj;
64 + return Objects.equals(this.id, other.id) &&
65 + Objects.equals(this.deviceCount, other.deviceCount) &&
66 + Objects.equals(this.linkCount, other.linkCount) &&
67 + Objects.equals(this.root, other.root);
68 + }
69 + return false;
70 + }
71 +
72 + @Override
73 + public String toString() {
74 + return toStringHelper(this)
75 + .add("id", id)
76 + .add("deviceCount", deviceCount)
77 + .add("linkCount", linkCount)
78 + .add("root", root)
79 + .toString();
80 + }
81 +}
1 -package org.onlab.onos.net; 1 +package org.onlab.onos.net.topology;
2 +
3 +import org.onlab.onos.net.Provided;
2 4
3 /** 5 /**
4 * Represents a network topology computation snapshot. 6 * Represents a network topology computation snapshot.
......
1 package org.onlab.onos.net.topology; 1 package org.onlab.onos.net.topology;
2 2
3 +import org.onlab.onos.net.DeviceId;
4 +
3 /** 5 /**
4 * Representation of an SCC (strongly-connected component) in a network topology. 6 * Representation of an SCC (strongly-connected component) in a network topology.
5 */ 7 */
6 public interface TopologyCluster { 8 public interface TopologyCluster {
7 9
8 - // TODO: add stuff in here: id, deviceCount, linkCount 10 + /**
11 + * Returns the cluster id.
12 + *
13 + * @return cluster identifier
14 + */
15 + ClusterId id();
16 +
17 + /**
18 + * Returns the number of devices in the cluster.
19 + *
20 + * @return number of cluster devices
21 + */
22 + int deviceCount();
23 +
24 + /**
25 + * Returns the number of infrastructure links in the cluster.
26 + *
27 + * @return number of cluster links
28 + */
29 + int linkCount();
30 +
31 + /**
32 + * Returns the device identifier of the cluster root device.
33 + *
34 + * @return cluster root device identifier
35 + */
36 + DeviceId root();
9 37
10 } 38 }
......
1 package org.onlab.onos.net.topology; 1 package org.onlab.onos.net.topology;
2 2
3 +import org.onlab.graph.Graph;
4 +import org.onlab.graph.GraphPathSearch;
3 import org.onlab.onos.net.Description; 5 import org.onlab.onos.net.Description;
6 +import org.onlab.onos.net.DeviceId;
7 +import org.onlab.onos.net.Link;
4 8
5 -import java.util.Collection; 9 +import java.util.Set;
6 10
7 /** 11 /**
8 * Describes attribute(s) of a network topology. 12 * Describes attribute(s) of a network topology.
...@@ -10,21 +14,58 @@ import java.util.Collection; ...@@ -10,21 +14,58 @@ import java.util.Collection;
10 public interface TopologyDescription extends Description { 14 public interface TopologyDescription extends Description {
11 15
12 /** 16 /**
13 - * A collection of Device, Link, and Host descriptors that describe 17 + * Returns the creation timestamp of the topology description. This is
14 - * the changes tha have occurred in the network topology. 18 + * expressed in system nanos to allow proper sequencing.
15 * 19 *
16 - * @return network element descriptions describing topology change 20 + * @return topology description creation timestamp
17 */ 21 */
18 - Collection<Description> details(); 22 + long timestamp();
19 23
20 - // Default topology provider/computor should do the following: 24 + /**
21 - // create graph 25 + * Returns the topology graph.
22 - // search graph for SCC clusters (Tarjan) 26 + *
23 - // search graph for all pairs shortest paths based on hop-count 27 + * @return network graph
24 - // this means all shortest paths, between all pairs; not just one shortest path 28 + */
25 - // optionally use path results to produce destination-rooted broadcast trees 29 + Graph<TopoVertex, TopoEdge> graph();
30 +
31 + /**
32 + * Returns the results of the path search through the network graph. This
33 + * is assumed to contain results of seach fro the given device to all
34 + * other devices.
35 + *
36 + * @param srcDeviceId source device identifier
37 + * @return path search result for the given source node
38 + */
39 + GraphPathSearch.Result pathResults(DeviceId srcDeviceId);
40 +
41 + /**
42 + * Returns the set of topology SCC clusters.
43 + *
44 + * @return set of SCC clusters
45 + */
46 + Set<TopologyCluster> clusters();
26 47
27 - // provide description with the graph, clusters, paths and trees upwards 48 + /**
49 + * Returns the set of devices contained by the specified topology cluster.
50 + *
51 + * @return set of devices that belong to the specified cluster
52 + */
53 + Set<DeviceId> clusterDevices(TopologyCluster cluster);
54 +
55 + /**
56 + * Returns the set of infrastructure links contained by the specified cluster.
57 + *
58 + * @return set of links that form the given cluster
59 + */
60 + Set<Link> clusterLinks(TopologyCluster cluster);
61 +
62 + /**
63 + * Returns the topology SCC cluster which contains the given device.
64 + *
65 + * @param deviceId device identifier
66 + * @return topology cluster that contains the specified device
67 + */
68 + TopologyCluster clusterFor(DeviceId deviceId);
28 69
29 } 70 }
30 71
......
1 package org.onlab.onos.net.topology; 1 package org.onlab.onos.net.topology;
2 2
3 import org.onlab.onos.event.AbstractEvent; 3 import org.onlab.onos.event.AbstractEvent;
4 -import org.onlab.onos.net.Topology;
5 4
6 /** 5 /**
7 * Describes network topology event. 6 * Describes network topology event.
......
1 package org.onlab.onos.net.topology; 1 package org.onlab.onos.net.topology;
2 2
3 +import org.onlab.onos.event.Event;
3 import org.onlab.onos.net.provider.ProviderService; 4 import org.onlab.onos.net.provider.ProviderService;
4 5
6 +import java.util.List;
7 +
5 /** 8 /**
6 * Means for injecting topology information into the core. 9 * Means for injecting topology information into the core.
7 */ 10 */
...@@ -14,7 +17,9 @@ public interface TopologyProviderService extends ProviderService<TopologyProvide ...@@ -14,7 +17,9 @@ public interface TopologyProviderService extends ProviderService<TopologyProvide
14 * Signals the core that some aspect of the topology has changed. 17 * Signals the core that some aspect of the topology has changed.
15 * 18 *
16 * @param topoDescription information about topology 19 * @param topoDescription information about topology
20 + * @param reasons events that triggered topology change
17 */ 21 */
18 - void topologyChanged(TopologyDescription topoDescription); 22 + void topologyChanged(TopologyDescription topoDescription,
23 + List<Event> reasons);
19 24
20 } 25 }
......
...@@ -4,7 +4,6 @@ import org.onlab.graph.Graph; ...@@ -4,7 +4,6 @@ import org.onlab.graph.Graph;
4 import org.onlab.onos.net.ConnectPoint; 4 import org.onlab.onos.net.ConnectPoint;
5 import org.onlab.onos.net.DeviceId; 5 import org.onlab.onos.net.DeviceId;
6 import org.onlab.onos.net.Path; 6 import org.onlab.onos.net.Path;
7 -import org.onlab.onos.net.Topology;
8 7
9 import java.util.Set; 8 import java.util.Set;
10 9
...@@ -37,8 +36,8 @@ public interface TopologyService { ...@@ -37,8 +36,8 @@ public interface TopologyService {
37 Graph<TopoVertex, TopoEdge> getGraph(Topology topology); 36 Graph<TopoVertex, TopoEdge> getGraph(Topology topology);
38 37
39 /** 38 /**
40 - * Returns the set of all shortest paths, in terms of hop-count, between 39 + * Returns the set of all shortest paths, precomputed in terms of hop-count,
41 - * the specified source and destination devices. 40 + * between the specified source and destination devices.
42 * 41 *
43 * @param topology topology descriptor 42 * @param topology topology descriptor
44 * @param src source device 43 * @param src source device
...@@ -71,7 +70,8 @@ public interface TopologyService { ...@@ -71,7 +70,8 @@ public interface TopologyService {
71 70
72 71
73 /** 72 /**
74 - * Indicates whether the specified connection point allows broadcast. 73 + * Indicates whether the specified connection point belong to the
74 + * broadcast tree.
75 * 75 *
76 * @param topology topology descriptor 76 * @param topology topology descriptor
77 * @param connectPoint connection point 77 * @param connectPoint connection point
......
1 +package org.onlab.onos.net.trivial.impl;
2 +
3 +import com.google.common.collect.ImmutableSet;
4 +import com.google.common.collect.Multimap;
5 +import org.onlab.graph.Graph;
6 +import org.onlab.graph.GraphPathSearch;
7 +import org.onlab.onos.net.DeviceId;
8 +import org.onlab.onos.net.Link;
9 +import org.onlab.onos.net.topology.ClusterId;
10 +import org.onlab.onos.net.topology.TopoEdge;
11 +import org.onlab.onos.net.topology.TopoVertex;
12 +import org.onlab.onos.net.topology.TopologyCluster;
13 +import org.onlab.onos.net.topology.TopologyDescription;
14 +
15 +import java.util.Map;
16 +import java.util.Set;
17 +
18 +/**
19 + * Default implementation of an immutable topology data carrier.
20 + */
21 +public class DefaultTopologyDescription implements TopologyDescription {
22 +
23 + private final long nanos;
24 + private final Graph<TopoVertex, TopoEdge> graph;
25 + private final Map<DeviceId, GraphPathSearch.Result<TopoVertex, TopoEdge>> results;
26 + private final Map<ClusterId, TopologyCluster> clusters;
27 + private final Multimap<ClusterId, DeviceId> clusterDevices;
28 + private final Multimap<ClusterId, Link> clusterLinks;
29 + private final Map<DeviceId, TopologyCluster> deviceClusters;
30 +
31 + public DefaultTopologyDescription(long nanos, Graph<TopoVertex, TopoEdge> graph,
32 + Map<DeviceId, GraphPathSearch.Result<TopoVertex, TopoEdge>> results,
33 + Map<ClusterId, TopologyCluster> clusters,
34 + Multimap<ClusterId, DeviceId> clusterDevices,
35 + Multimap<ClusterId, Link> clusterLinks,
36 + Map<DeviceId, TopologyCluster> deviceClusters) {
37 + this.nanos = nanos;
38 + this.graph = graph;
39 + this.results = results;
40 + this.clusters = clusters;
41 + this.clusterDevices = clusterDevices;
42 + this.clusterLinks = clusterLinks;
43 + this.deviceClusters = deviceClusters;
44 + }
45 +
46 + @Override
47 + public long timestamp() {
48 + return nanos;
49 + }
50 +
51 + @Override
52 + public Graph<TopoVertex, TopoEdge> graph() {
53 + return graph;
54 + }
55 +
56 + @Override
57 + public GraphPathSearch.Result<TopoVertex, TopoEdge> pathResults(DeviceId srcDeviceId) {
58 + return results.get(srcDeviceId);
59 + }
60 +
61 + @Override
62 + public Set<TopologyCluster> clusters() {
63 + return ImmutableSet.copyOf(clusters.values());
64 + }
65 +
66 + @Override
67 + public Set<DeviceId> clusterDevices(TopologyCluster cluster) {
68 + return null; // clusterDevices.get(cluster.id());
69 + }
70 +
71 + @Override
72 + public Set<Link> clusterLinks(TopologyCluster cluster) {
73 + return null; // clusterLinks.get(cluster.id());
74 + }
75 +
76 + @Override
77 + public TopologyCluster clusterFor(DeviceId deviceId) {
78 + return deviceClusters.get(deviceId);
79 + }
80 +}
...@@ -150,7 +150,7 @@ public class SimpleDeviceManager ...@@ -150,7 +150,7 @@ public class SimpleDeviceManager
150 private class InternalDeviceProviderService extends AbstractProviderService<DeviceProvider> 150 private class InternalDeviceProviderService extends AbstractProviderService<DeviceProvider>
151 implements DeviceProviderService { 151 implements DeviceProviderService {
152 152
153 - public InternalDeviceProviderService(DeviceProvider provider) { 153 + InternalDeviceProviderService(DeviceProvider provider) {
154 super(provider); 154 super(provider);
155 } 155 }
156 156
......
...@@ -59,7 +59,7 @@ public class SimpleHostManager ...@@ -59,7 +59,7 @@ public class SimpleHostManager
59 private class InternalHostProviderService extends AbstractProviderService<HostProvider> 59 private class InternalHostProviderService extends AbstractProviderService<HostProvider>
60 implements HostProviderService { 60 implements HostProviderService {
61 61
62 - public InternalHostProviderService(HostProvider provider) { 62 + InternalHostProviderService(HostProvider provider) {
63 super(provider); 63 super(provider);
64 } 64 }
65 65
......
...@@ -149,7 +149,7 @@ implements LinkService, LinkAdminService, LinkProviderRegistry { ...@@ -149,7 +149,7 @@ implements LinkService, LinkAdminService, LinkProviderRegistry {
149 private class InternalLinkProviderService extends AbstractProviderService<LinkProvider> 149 private class InternalLinkProviderService extends AbstractProviderService<LinkProvider>
150 implements LinkProviderService { 150 implements LinkProviderService {
151 151
152 - public InternalLinkProviderService(LinkProvider provider) { 152 + InternalLinkProviderService(LinkProvider provider) {
153 super(provider); 153 super(provider);
154 } 154 }
155 155
......
1 +package org.onlab.onos.net.trivial.impl;
2 +
3 +import org.apache.felix.scr.annotations.Activate;
4 +import org.apache.felix.scr.annotations.Component;
5 +import org.apache.felix.scr.annotations.Deactivate;
6 +import org.apache.felix.scr.annotations.Reference;
7 +import org.apache.felix.scr.annotations.ReferenceCardinality;
8 +import org.apache.felix.scr.annotations.Service;
9 +import org.onlab.graph.Graph;
10 +import org.onlab.onos.event.AbstractListenerRegistry;
11 +import org.onlab.onos.event.Event;
12 +import org.onlab.onos.event.EventDeliveryService;
13 +import org.onlab.onos.net.ConnectPoint;
14 +import org.onlab.onos.net.DeviceId;
15 +import org.onlab.onos.net.Path;
16 +import org.onlab.onos.net.provider.AbstractProviderRegistry;
17 +import org.onlab.onos.net.provider.AbstractProviderService;
18 +import org.onlab.onos.net.topology.LinkWeight;
19 +import org.onlab.onos.net.topology.TopoEdge;
20 +import org.onlab.onos.net.topology.TopoVertex;
21 +import org.onlab.onos.net.topology.Topology;
22 +import org.onlab.onos.net.topology.TopologyCluster;
23 +import org.onlab.onos.net.topology.TopologyDescription;
24 +import org.onlab.onos.net.topology.TopologyEvent;
25 +import org.onlab.onos.net.topology.TopologyListener;
26 +import org.onlab.onos.net.topology.TopologyProvider;
27 +import org.onlab.onos.net.topology.TopologyProviderRegistry;
28 +import org.onlab.onos.net.topology.TopologyProviderService;
29 +import org.onlab.onos.net.topology.TopologyService;
30 +import org.slf4j.Logger;
31 +
32 +import java.util.List;
33 +import java.util.Set;
34 +
35 +import static com.google.common.base.Preconditions.checkNotNull;
36 +import static org.slf4j.LoggerFactory.getLogger;
37 +
38 +/**
39 + * Provides basic implementation of the topology SB &amp; NB APIs.
40 + */
41 +@Component(immediate = true)
42 +@Service
43 +public class SimpleTopologyManager
44 + extends AbstractProviderRegistry<TopologyProvider, TopologyProviderService>
45 + implements TopologyService, TopologyProviderRegistry {
46 +
47 + public static final String TOPOLOGY_NULL = "Topology cannot be null";
48 + private static final String DEVICE_ID_NULL = "Device ID cannot be null";
49 + public static final String CONNECTION_POINT_NULL = "Connection point cannot be null";
50 +
51 + private final Logger log = getLogger(getClass());
52 +
53 + private final AbstractListenerRegistry<TopologyEvent, TopologyListener>
54 + listenerRegistry = new AbstractListenerRegistry<>();
55 +
56 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
57 + private EventDeliveryService eventDispatcher;
58 +
59 +
60 + @Activate
61 + public void activate() {
62 + eventDispatcher.addSink(TopologyEvent.class, listenerRegistry);
63 + log.info("Started");
64 + }
65 +
66 + @Deactivate
67 + public void deactivate() {
68 + eventDispatcher.removeSink(TopologyEvent.class);
69 + log.info("Stopped");
70 + }
71 +
72 + @Override
73 + protected TopologyProviderService createProviderService(TopologyProvider provider) {
74 + return new InternalTopologyProviderService(provider);
75 + }
76 +
77 + @Override
78 + public Topology currentTopology() {
79 + return null;
80 + }
81 +
82 + @Override
83 + public Set<TopologyCluster> getClusters(Topology topology) {
84 + checkNotNull(topology, TOPOLOGY_NULL);
85 + return null;
86 + }
87 +
88 + @Override
89 + public Graph<TopoVertex, TopoEdge> getGraph(Topology topology) {
90 + checkNotNull(topology, TOPOLOGY_NULL);
91 + return null;
92 + }
93 +
94 + @Override
95 + public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst) {
96 + checkNotNull(topology, TOPOLOGY_NULL);
97 + checkNotNull(src, DEVICE_ID_NULL);
98 + checkNotNull(dst, DEVICE_ID_NULL);
99 + return null;
100 + }
101 +
102 + @Override
103 + public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst, LinkWeight weight) {
104 + checkNotNull(topology, TOPOLOGY_NULL);
105 + checkNotNull(src, DEVICE_ID_NULL);
106 + checkNotNull(dst, DEVICE_ID_NULL);
107 + checkNotNull(weight, "Link weight cannot be null");
108 + return null;
109 + }
110 +
111 + @Override
112 + public boolean isInfrastructure(Topology topology, ConnectPoint connectPoint) {
113 + checkNotNull(topology, TOPOLOGY_NULL);
114 + checkNotNull(connectPoint, CONNECTION_POINT_NULL);
115 + return false;
116 + }
117 +
118 + @Override
119 + public boolean isInBroadcastTree(Topology topology, ConnectPoint connectPoint) {
120 + checkNotNull(topology, TOPOLOGY_NULL);
121 + checkNotNull(connectPoint, CONNECTION_POINT_NULL);
122 + return false;
123 + }
124 +
125 + @Override
126 + public void addListener(TopologyListener listener) {
127 + listenerRegistry.addListener(listener);
128 + }
129 +
130 + @Override
131 + public void removeListener(TopologyListener listener) {
132 + listenerRegistry.removeListener(listener);
133 + }
134 +
135 + // Personalized host provider service issued to the supplied provider.
136 + private class InternalTopologyProviderService
137 + extends AbstractProviderService<TopologyProvider>
138 + implements TopologyProviderService {
139 +
140 + InternalTopologyProviderService(TopologyProvider provider) {
141 + super(provider);
142 + }
143 +
144 + @Override
145 + public void topologyChanged(TopologyDescription topoDescription,
146 + List<Event> reasons) {
147 + checkNotNull(topoDescription, "Topology description cannot be null");
148 + log.info("Topology changed due to: {}",
149 + reasons == null ? "initial compute" : reasons);
150 + }
151 + }
152 +
153 +}
1 +<html>
2 +<body>
3 +<img src="doc-files/onos-tiers.png" alt="ONOS architecture tiers"><br>
4 +ONOS architecture is strictly segmented into protocol-agnostic system core and
5 +protocol-aware providers tiers.
6 +
7 +<em>More information to come later...</em>
8 +
9 +</body>
...\ No newline at end of file ...\ No newline at end of file