tom | 8bf2e6b | 2014-09-10 20:53:54 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.trivial.topology.impl; |
tom | 0efbb1d | 2014-09-09 11:54:28 -0700 | [diff] [blame] | 2 | |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 3 | import org.onlab.onos.event.Event; |
| 4 | import org.onlab.onos.net.ConnectPoint; |
| 5 | import org.onlab.onos.net.DeviceId; |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame^] | 6 | import org.onlab.onos.net.Link; |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 7 | import org.onlab.onos.net.Path; |
tom | e52ce70 | 2014-09-11 00:12:54 -0700 | [diff] [blame] | 8 | import org.onlab.onos.net.provider.ProviderId; |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame^] | 9 | import org.onlab.onos.net.topology.ClusterId; |
tom | 9793755 | 2014-09-11 10:48:42 -0700 | [diff] [blame] | 10 | import org.onlab.onos.net.topology.GraphDescription; |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 11 | import org.onlab.onos.net.topology.LinkWeight; |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 12 | import org.onlab.onos.net.topology.Topology; |
| 13 | import org.onlab.onos.net.topology.TopologyCluster; |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 14 | import org.onlab.onos.net.topology.TopologyEvent; |
tom | 9793755 | 2014-09-11 10:48:42 -0700 | [diff] [blame] | 15 | import org.onlab.onos.net.topology.TopologyGraph; |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 16 | |
| 17 | import java.util.List; |
| 18 | import java.util.Set; |
| 19 | |
tom | 0efbb1d | 2014-09-09 11:54:28 -0700 | [diff] [blame] | 20 | /** |
| 21 | * Manages inventory of topology snapshots using trivial in-memory |
tom | cbff939 | 2014-09-10 00:45:23 -0700 | [diff] [blame] | 22 | * structures implementation. |
tom | 0efbb1d | 2014-09-09 11:54:28 -0700 | [diff] [blame] | 23 | */ |
tom | cbff939 | 2014-09-10 00:45:23 -0700 | [diff] [blame] | 24 | class SimpleTopologyStore { |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 25 | |
| 26 | private volatile DefaultTopology current; |
| 27 | |
| 28 | /** |
| 29 | * Returns the current topology snapshot. |
| 30 | * |
| 31 | * @return current topology descriptor |
| 32 | */ |
| 33 | Topology currentTopology() { |
| 34 | return current; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Indicates whether the topology is the latest. |
tom | cbff939 | 2014-09-10 00:45:23 -0700 | [diff] [blame] | 39 | * |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 40 | * @param topology topology descriptor |
| 41 | * @return true if topology is the most recent one |
| 42 | */ |
| 43 | boolean isLatest(Topology topology) { |
tom | cbff939 | 2014-09-10 00:45:23 -0700 | [diff] [blame] | 44 | // Topology is current only if it is the same as our current topology |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 45 | return topology == current; |
| 46 | } |
| 47 | |
| 48 | /** |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame^] | 49 | * Returns the immutable graph view of the current topology. |
| 50 | * |
| 51 | * @param topology topology descriptor |
| 52 | * @return graph view |
| 53 | */ |
| 54 | TopologyGraph getGraph(DefaultTopology topology) { |
| 55 | return topology.getGraph(); |
| 56 | } |
| 57 | |
| 58 | /** |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 59 | * Returns the set of topology SCC clusters. |
| 60 | * |
| 61 | * @param topology topology descriptor |
| 62 | * @return set of clusters |
| 63 | */ |
tom | e52ce70 | 2014-09-11 00:12:54 -0700 | [diff] [blame] | 64 | Set<TopologyCluster> getClusters(DefaultTopology topology) { |
| 65 | return topology.getClusters(); |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /** |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame^] | 69 | * Returns the cluster of the specified topology. |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 70 | * |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame^] | 71 | * @param topology topology descriptor |
| 72 | * @param clusterId cluster identity |
| 73 | * @return topology cluster |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 74 | */ |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame^] | 75 | TopologyCluster getCluster(DefaultTopology topology, ClusterId clusterId) { |
| 76 | return topology.getCluster(clusterId); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Returns the cluster of the specified topology. |
| 81 | * |
| 82 | * @param topology topology descriptor |
| 83 | * @param cluster topology cluster |
| 84 | * @return set of cluster links |
| 85 | */ |
| 86 | Set<DeviceId> getClusterDevices(DefaultTopology topology, TopologyCluster cluster) { |
| 87 | return topology.getClusterDevices(cluster); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Returns the cluster of the specified topology. |
| 92 | * |
| 93 | * @param topology topology descriptor |
| 94 | * @param cluster topology cluster |
| 95 | * @return set of cluster links |
| 96 | */ |
| 97 | Set<Link> getClusterLinks(DefaultTopology topology, TopologyCluster cluster) { |
| 98 | return topology.getClusterLinks(cluster); |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Returns the set of pre-computed shortest paths between src and dest. |
| 103 | * |
| 104 | * @param topology topology descriptor |
| 105 | * @param src source device |
| 106 | * @param dst destination device |
| 107 | * @return set of shortest paths |
| 108 | */ |
tom | e52ce70 | 2014-09-11 00:12:54 -0700 | [diff] [blame] | 109 | Set<Path> getPaths(DefaultTopology topology, DeviceId src, DeviceId dst) { |
| 110 | return topology.getPaths(src, dst); |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Computes and returns the set of shortest paths between src and dest. |
| 115 | * |
| 116 | * @param topology topology descriptor |
| 117 | * @param src source device |
| 118 | * @param dst destination device |
| 119 | * @param weight link weight function |
| 120 | * @return set of shortest paths |
| 121 | */ |
tom | e52ce70 | 2014-09-11 00:12:54 -0700 | [diff] [blame] | 122 | Set<Path> getPaths(DefaultTopology topology, DeviceId src, DeviceId dst, |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 123 | LinkWeight weight) { |
tom | 9793755 | 2014-09-11 10:48:42 -0700 | [diff] [blame] | 124 | return topology.getPaths(src, dst, weight); |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Indicates whether the given connect point is part of the network fabric. |
| 129 | * |
| 130 | * @param topology topology descriptor |
| 131 | * @param connectPoint connection point |
| 132 | * @return true if infrastructure; false otherwise |
| 133 | */ |
tom | e52ce70 | 2014-09-11 00:12:54 -0700 | [diff] [blame] | 134 | boolean isInfrastructure(DefaultTopology topology, ConnectPoint connectPoint) { |
| 135 | return topology.isInfrastructure(connectPoint); |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Indicates whether the given connect point is part of the broadcast tree. |
| 140 | * |
| 141 | * @param topology topology descriptor |
| 142 | * @param connectPoint connection point |
| 143 | * @return true if in broadcast tree; false otherwise |
| 144 | */ |
tom | e52ce70 | 2014-09-11 00:12:54 -0700 | [diff] [blame] | 145 | boolean isInBroadcastTree(DefaultTopology topology, ConnectPoint connectPoint) { |
| 146 | return topology.isInBroadcastTree(connectPoint); |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Generates a new topology snapshot from the specified description. |
| 151 | * |
tom | 9793755 | 2014-09-11 10:48:42 -0700 | [diff] [blame] | 152 | * @param providerId provider identification |
| 153 | * @param graphDescription topology graph description |
| 154 | * @param reasons list of events that triggered the update |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 155 | * @return topology update event or null if the description is old |
| 156 | */ |
tom | e52ce70 | 2014-09-11 00:12:54 -0700 | [diff] [blame] | 157 | TopologyEvent updateTopology(ProviderId providerId, |
tom | 9793755 | 2014-09-11 10:48:42 -0700 | [diff] [blame] | 158 | GraphDescription graphDescription, |
tom | cbff939 | 2014-09-10 00:45:23 -0700 | [diff] [blame] | 159 | List<Event> reasons) { |
tom | e52ce70 | 2014-09-11 00:12:54 -0700 | [diff] [blame] | 160 | // First off, make sure that what we're given is indeed newer than |
| 161 | // what we already have. |
tom | 9793755 | 2014-09-11 10:48:42 -0700 | [diff] [blame] | 162 | if (current != null && graphDescription.timestamp() < current.time()) { |
tom | e52ce70 | 2014-09-11 00:12:54 -0700 | [diff] [blame] | 163 | return null; |
| 164 | } |
| 165 | |
| 166 | // Have the default topology construct self from the description data. |
| 167 | DefaultTopology newTopology = |
tom | 9793755 | 2014-09-11 10:48:42 -0700 | [diff] [blame] | 168 | new DefaultTopology(providerId, graphDescription); |
tom | e52ce70 | 2014-09-11 00:12:54 -0700 | [diff] [blame] | 169 | |
| 170 | // Promote the new topology to current and return a ready-to-send event. |
tom | 9793755 | 2014-09-11 10:48:42 -0700 | [diff] [blame] | 171 | synchronized (this) { |
| 172 | current = newTopology; |
| 173 | return new TopologyEvent(TopologyEvent.Type.TOPOLOGY_CHANGED, current); |
| 174 | } |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 175 | } |
| 176 | |
tom | 0efbb1d | 2014-09-09 11:54:28 -0700 | [diff] [blame] | 177 | } |