Refactoring to eliminate duplicate DefaultTopology and DefaultTopologyGraph; eli…
…minating a few fixmes. Change-Id: Ie0e38dbf812bafdb7c94bba5278f0dd9af5be929
Showing
5 changed files
with
31 additions
and
24 deletions
| ... | @@ -474,11 +474,10 @@ public class ReactiveForwarding { | ... | @@ -474,11 +474,10 @@ public class ReactiveForwarding { |
| 474 | 474 | ||
| 475 | // Otherwise, pick a path that does not lead back to where we | 475 | // Otherwise, pick a path that does not lead back to where we |
| 476 | // came from; if no such path, flood and bail. | 476 | // came from; if no such path, flood and bail. |
| 477 | - Path path = pickForwardPath(paths, pkt.receivedFrom().port()); | 477 | + Path path = pickForwardPathIfPossible(paths, pkt.receivedFrom().port()); |
| 478 | if (path == null) { | 478 | if (path == null) { |
| 479 | - log.warn("Doh... don't know where to go... {} -> {} received on {}", | 479 | + log.warn("Don't know where to go from here {} for {} -> {}", |
| 480 | - ethPkt.getSourceMAC(), ethPkt.getDestinationMAC(), | 480 | + pkt.receivedFrom(), ethPkt.getSourceMAC(), ethPkt.getDestinationMAC()); |
| 481 | - pkt.receivedFrom()); | ||
| 482 | flood(context); | 481 | flood(context); |
| 483 | return; | 482 | return; |
| 484 | } | 483 | } |
| ... | @@ -501,14 +500,16 @@ public class ReactiveForwarding { | ... | @@ -501,14 +500,16 @@ public class ReactiveForwarding { |
| 501 | } | 500 | } |
| 502 | 501 | ||
| 503 | // Selects a path from the given set that does not lead back to the | 502 | // Selects a path from the given set that does not lead back to the |
| 504 | - // specified port. | 503 | + // specified port if possible. |
| 505 | - private Path pickForwardPath(Set<Path> paths, PortNumber notToPort) { | 504 | + private Path pickForwardPathIfPossible(Set<Path> paths, PortNumber notToPort) { |
| 505 | + Path lastPath = null; | ||
| 506 | for (Path path : paths) { | 506 | for (Path path : paths) { |
| 507 | + lastPath = path; | ||
| 507 | if (!path.src().port().equals(notToPort)) { | 508 | if (!path.src().port().equals(notToPort)) { |
| 508 | return path; | 509 | return path; |
| 509 | } | 510 | } |
| 510 | } | 511 | } |
| 511 | - return null; | 512 | + return lastPath; |
| 512 | } | 513 | } |
| 513 | 514 | ||
| 514 | // Floods the specified packet if permissible. | 515 | // Floods the specified packet if permissible. |
| ... | @@ -734,7 +735,7 @@ public class ReactiveForwarding { | ... | @@ -734,7 +735,7 @@ public class ReactiveForwarding { |
| 734 | Set<Path> pathsFromCurDevice = | 735 | Set<Path> pathsFromCurDevice = |
| 735 | topologyService.getPaths(topologyService.currentTopology(), | 736 | topologyService.getPaths(topologyService.currentTopology(), |
| 736 | curDevice, dstId); | 737 | curDevice, dstId); |
| 737 | - if (pickForwardPath(pathsFromCurDevice, curLink.src().port()) != null) { | 738 | + if (pickForwardPathIfPossible(pathsFromCurDevice, curLink.src().port()) != null) { |
| 738 | break; | 739 | break; |
| 739 | } else { | 740 | } else { |
| 740 | if (i + 1 == pathLinks.size()) { | 741 | if (i + 1 == pathLinks.size()) { |
| ... | @@ -792,8 +793,8 @@ public class ReactiveForwarding { | ... | @@ -792,8 +793,8 @@ public class ReactiveForwarding { |
| 792 | return builder.build(); | 793 | return builder.build(); |
| 793 | } | 794 | } |
| 794 | 795 | ||
| 795 | - // Returns set of flowEntries which were created by this application and which egress from the | 796 | + // Returns set of flow entries which were created by this application and |
| 796 | - // specified connection port | 797 | + // which egress from the specified connection port |
| 797 | private Set<FlowEntry> getFlowRulesFrom(ConnectPoint egress) { | 798 | private Set<FlowEntry> getFlowRulesFrom(ConnectPoint egress) { |
| 798 | ImmutableSet.Builder<FlowEntry> builder = ImmutableSet.builder(); | 799 | ImmutableSet.Builder<FlowEntry> builder = ImmutableSet.builder(); |
| 799 | flowRuleService.getFlowEntries(egress.deviceId()).forEach(r -> { | 800 | flowRuleService.getFlowEntries(egress.deviceId()).forEach(r -> { | ... | ... |
| ... | @@ -27,6 +27,7 @@ import org.slf4j.Logger; | ... | @@ -27,6 +27,7 @@ import org.slf4j.Logger; |
| 27 | 27 | ||
| 28 | import java.util.Map; | 28 | import java.util.Map; |
| 29 | 29 | ||
| 30 | +import static com.google.common.base.Preconditions.checkArgument; | ||
| 30 | import static org.slf4j.LoggerFactory.getLogger; | 31 | import static org.slf4j.LoggerFactory.getLogger; |
| 31 | 32 | ||
| 32 | /** | 33 | /** |
| ... | @@ -133,9 +134,7 @@ public class DefaultGraphDescription extends AbstractDescription | ... | @@ -133,9 +134,7 @@ public class DefaultGraphDescription extends AbstractDescription |
| 133 | private TopologyVertex vertexOf(ConnectPoint connectPoint) { | 134 | private TopologyVertex vertexOf(ConnectPoint connectPoint) { |
| 134 | DeviceId id = connectPoint.deviceId(); | 135 | DeviceId id = connectPoint.deviceId(); |
| 135 | TopologyVertex vertex = vertexesById.get(id); | 136 | TopologyVertex vertex = vertexesById.get(id); |
| 136 | - if (vertex == null) { | 137 | + checkArgument(vertex != null, "Vertex missing for %s", id); |
| 137 | - throw new IllegalArgumentException("Vertex missing for " + id); | ||
| 138 | - } | ||
| 139 | return vertex; | 138 | return vertex; |
| 140 | } | 139 | } |
| 141 | 140 | ... | ... |
| ... | @@ -50,7 +50,9 @@ import java.util.Map; | ... | @@ -50,7 +50,9 @@ import java.util.Map; |
| 50 | import java.util.Set; | 50 | import java.util.Set; |
| 51 | 51 | ||
| 52 | import static com.google.common.base.MoreObjects.toStringHelper; | 52 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 53 | +import static com.google.common.base.Preconditions.checkArgument; | ||
| 53 | import static org.onlab.graph.GraphPathSearch.ALL_PATHS; | 54 | import static org.onlab.graph.GraphPathSearch.ALL_PATHS; |
| 55 | +import static org.onlab.util.Tools.isNullOrEmpty; | ||
| 54 | import static org.onosproject.core.CoreService.CORE_PROVIDER_ID; | 56 | import static org.onosproject.core.CoreService.CORE_PROVIDER_ID; |
| 55 | import static org.onosproject.net.Link.State.ACTIVE; | 57 | import static org.onosproject.net.Link.State.ACTIVE; |
| 56 | import static org.onosproject.net.Link.State.INACTIVE; | 58 | import static org.onosproject.net.Link.State.INACTIVE; |
| ... | @@ -228,15 +230,12 @@ public class DefaultTopology extends AbstractModel implements Topology { | ... | @@ -228,15 +230,12 @@ public class DefaultTopology extends AbstractModel implements Topology { |
| 228 | 230 | ||
| 229 | // Find the cluster to which the device belongs. | 231 | // Find the cluster to which the device belongs. |
| 230 | TopologyCluster cluster = clustersByDevice().get(connectPoint.deviceId()); | 232 | TopologyCluster cluster = clustersByDevice().get(connectPoint.deviceId()); |
| 231 | - if (cluster == null) { | 233 | + checkArgument(cluster != null, "No cluster found for device %s", connectPoint.deviceId()); |
| 232 | - throw new IllegalArgumentException("No cluster found for device " | ||
| 233 | - + connectPoint.deviceId()); | ||
| 234 | - } | ||
| 235 | 234 | ||
| 236 | // If the broadcast set is null or empty, or if the point explicitly | 235 | // If the broadcast set is null or empty, or if the point explicitly |
| 237 | - // belongs to it, return true; | 236 | + // belongs to it, return true. |
| 238 | Set<ConnectPoint> points = broadcastSets.get().get(cluster.id()); | 237 | Set<ConnectPoint> points = broadcastSets.get().get(cluster.id()); |
| 239 | - return (points == null) || points.isEmpty() || points.contains(connectPoint); | 238 | + return isNullOrEmpty(points) || points.contains(connectPoint); |
| 240 | } | 239 | } |
| 241 | 240 | ||
| 242 | /** | 241 | /** |
| ... | @@ -250,6 +249,16 @@ public class DefaultTopology extends AbstractModel implements Topology { | ... | @@ -250,6 +249,16 @@ public class DefaultTopology extends AbstractModel implements Topology { |
| 250 | } | 249 | } |
| 251 | 250 | ||
| 252 | /** | 251 | /** |
| 252 | + * Returns the set of the cluster broadcast points. | ||
| 253 | + * | ||
| 254 | + * @param clusterId cluster identifier | ||
| 255 | + * @return set of cluster broadcast points | ||
| 256 | + */ | ||
| 257 | + public Set<ConnectPoint> broadcastPoints(ClusterId clusterId) { | ||
| 258 | + return broadcastSets.get().get(clusterId); | ||
| 259 | + } | ||
| 260 | + | ||
| 261 | + /** | ||
| 253 | * Returns the set of pre-computed shortest paths between source and | 262 | * Returns the set of pre-computed shortest paths between source and |
| 254 | * destination devices. | 263 | * destination devices. |
| 255 | * | 264 | * | ... | ... |
| ... | @@ -279,8 +279,7 @@ public class DefaultTopologyProvider extends AbstractProvider | ... | @@ -279,8 +279,7 @@ public class DefaultTopologyProvider extends AbstractProvider |
| 279 | try { | 279 | try { |
| 280 | buildTopology(reasons); | 280 | buildTopology(reasons); |
| 281 | } catch (Exception e) { | 281 | } catch (Exception e) { |
| 282 | - log.warn("Unable to compute topology due to: {}", e.getMessage()); | 282 | + log.warn("Unable to compute topology", e); |
| 283 | - log.debug("Unable to compute topology", e); | ||
| 284 | } | 283 | } |
| 285 | } | 284 | } |
| 286 | } | 285 | } | ... | ... |
| ... | @@ -65,7 +65,7 @@ public class DistributedTopologyStore | ... | @@ -65,7 +65,7 @@ public class DistributedTopologyStore |
| 65 | 65 | ||
| 66 | private volatile DefaultTopology current = | 66 | private volatile DefaultTopology current = |
| 67 | new DefaultTopology(ProviderId.NONE, | 67 | new DefaultTopology(ProviderId.NONE, |
| 68 | - new DefaultGraphDescription(0L, 0L, | 68 | + new DefaultGraphDescription(0L, System.currentTimeMillis(), |
| 69 | Collections.<Device>emptyList(), | 69 | Collections.<Device>emptyList(), |
| 70 | Collections.<Link>emptyList())); | 70 | Collections.<Link>emptyList())); |
| 71 | 71 | ||
| ... | @@ -147,8 +147,7 @@ public class DistributedTopologyStore | ... | @@ -147,8 +147,7 @@ public class DistributedTopologyStore |
| 147 | } | 147 | } |
| 148 | 148 | ||
| 149 | // Have the default topology construct self from the description data. | 149 | // Have the default topology construct self from the description data. |
| 150 | - DefaultTopology newTopology = | 150 | + DefaultTopology newTopology = new DefaultTopology(providerId, graphDescription); |
| 151 | - new DefaultTopology(providerId, graphDescription); | ||
| 152 | 151 | ||
| 153 | // Promote the new topology to current and return a ready-to-send event. | 152 | // Promote the new topology to current and return a ready-to-send event. |
| 154 | synchronized (this) { | 153 | synchronized (this) { | ... | ... |
-
Please register or login to post a comment