tom

Refactored the topology provider.

1 +package org.onlab.onos.net.trivial.topology.provider.impl;
2 +
3 +import org.onlab.onos.net.Link;
4 +import org.onlab.onos.net.topology.TopoEdge;
5 +import org.onlab.onos.net.topology.TopoVertex;
6 +
7 +import java.util.Objects;
8 +
9 +import static com.google.common.base.MoreObjects.toStringHelper;
10 +
11 +/**
12 + * Implementation of the topology edge backed by a link.
13 + */
14 +class DefaultTopoEdge implements TopoEdge {
15 +
16 + private final Link link;
17 + private final TopoVertex src;
18 + private final TopoVertex dst;
19 +
20 + /**
21 + * Creates a new topology edge.
22 + *
23 + * @param src source vertex
24 + * @param dst destination vertex
25 + * @param link infrastructure link
26 + */
27 + DefaultTopoEdge(TopoVertex src, TopoVertex dst, Link link) {
28 + this.src = src;
29 + this.dst = dst;
30 + this.link = link;
31 + }
32 +
33 + @Override
34 + public Link link() {
35 + return link;
36 + }
37 +
38 + @Override
39 + public TopoVertex src() {
40 + return src;
41 + }
42 +
43 + @Override
44 + public TopoVertex dst() {
45 + return dst;
46 + }
47 +
48 + @Override
49 + public int hashCode() {
50 + return Objects.hash(link);
51 + }
52 +
53 + @Override
54 + public boolean equals(Object obj) {
55 + if (obj instanceof DefaultTopoEdge) {
56 + final DefaultTopoEdge other = (DefaultTopoEdge) obj;
57 + return Objects.equals(this.link, other.link);
58 + }
59 + return false;
60 + }
61 +
62 + @Override
63 + public String toString() {
64 + return toStringHelper(this).add("src", src).add("dst", dst).toString();
65 + }
66 +
67 +}
68 +
1 +package org.onlab.onos.net.trivial.topology.provider.impl;
2 +
3 +import org.onlab.onos.net.DeviceId;
4 +import org.onlab.onos.net.topology.TopoVertex;
5 +
6 +import java.util.Objects;
7 +
8 +/**
9 + * Implementation of the topology vertex backed by a device id.
10 + */
11 +class DefaultTopoVertex implements TopoVertex {
12 +
13 + private final DeviceId deviceId;
14 +
15 + /**
16 + * Creates a new topology vertex.
17 + *
18 + * @param deviceId backing infrastructure device identifier
19 + */
20 + DefaultTopoVertex(DeviceId deviceId) {
21 + this.deviceId = deviceId;
22 + }
23 +
24 + @Override
25 + public DeviceId deviceId() {
26 + return deviceId;
27 + }
28 +
29 + @Override
30 + public int hashCode() {
31 + return Objects.hash(deviceId);
32 + }
33 +
34 + @Override
35 + public boolean equals(Object obj) {
36 + if (obj instanceof DefaultTopoVertex) {
37 + final DefaultTopoVertex other = (DefaultTopoVertex) obj;
38 + return Objects.equals(this.deviceId, other.deviceId);
39 + }
40 + return false;
41 + }
42 +
43 + @Override
44 + public String toString() {
45 + return deviceId.toString();
46 + }
47 +
48 +}
49 +
...@@ -115,7 +115,6 @@ public class SimpleTopologyProvider extends AbstractProvider ...@@ -115,7 +115,6 @@ public class SimpleTopologyProvider extends AbstractProvider
115 // Builds the topology using the latest device and link information 115 // Builds the topology using the latest device and link information
116 // and citing the specified events as reasons for the change. 116 // and citing the specified events as reasons for the change.
117 private void buildTopology(List<Event> reasons) { 117 private void buildTopology(List<Event> reasons) {
118 - log.info("YO! Computing topology");
119 if (isStarted) { 118 if (isStarted) {
120 TopologyDescription desc = 119 TopologyDescription desc =
121 new DefaultTopologyDescription(System.nanoTime(), 120 new DefaultTopologyDescription(System.nanoTime(),
......