ONOS-400 Topology creation and up time formatting fixes
Change-Id: Iaf6d4dbbc1c7eaae9465a2d931d40f07a75ad07d
diff --git a/core/api/src/main/java/org/onosproject/net/topology/DefaultGraphDescription.java b/core/api/src/main/java/org/onosproject/net/topology/DefaultGraphDescription.java
index 4d60e23..08db92f 100644
--- a/core/api/src/main/java/org/onosproject/net/topology/DefaultGraphDescription.java
+++ b/core/api/src/main/java/org/onosproject/net/topology/DefaultGraphDescription.java
@@ -34,30 +34,60 @@
* Default implementation of an immutable topology graph data carrier.
*/
public class DefaultGraphDescription extends AbstractDescription
- implements GraphDescription {
+implements GraphDescription {
private static final Logger log = getLogger(DefaultGraphDescription.class);
private final long nanos;
+ private final long creationTime;
private final ImmutableSet<TopologyVertex> vertexes;
private final ImmutableSet<TopologyEdge> edges;
- private final Map<DeviceId, TopologyVertex> vertexesById = Maps.newHashMap();
+ 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
+ * @param nanos time in nanos of when the topology description was created
+ *
+ * @param devices collection of infrastructure devices
+ *
+ * @param links collection of infrastructure links
+ *
* @param annotations optional key/value annotations map
+ *
*/
+ @Deprecated
public DefaultGraphDescription(long nanos, Iterable<Device> devices,
- Iterable<Link> links,
- SparseAnnotations... annotations) {
+ Iterable<Link> links,
+ SparseAnnotations... annotations) {
+ this(nanos, System.currentTimeMillis(), devices, links, annotations);
+ }
+
+ /**
+ * 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 millis time in millis of when the topology description was created
+ *
+ * @param devices collection of infrastructure devices
+ *
+ * @param links collection of infrastructure links
+ *
+ * @param annotations optional key/value annotations map
+ *
+ */
+ public DefaultGraphDescription(long nanos, long millis,
+ Iterable<Device> devices,
+ Iterable<Link> links,
+ SparseAnnotations... annotations) {
super(annotations);
this.nanos = nanos;
+ this.creationTime = millis;
this.vertexes = buildVertexes(devices);
this.edges = buildEdges(links);
vertexesById.clear();
@@ -69,6 +99,11 @@
}
@Override
+ public long creationTime() {
+ return creationTime;
+ }
+
+ @Override
public ImmutableSet<TopologyVertex> vertexes() {
return vertexes;
}
@@ -79,7 +114,8 @@
}
// Builds a set of topology vertexes from the specified list of devices
- private ImmutableSet<TopologyVertex> buildVertexes(Iterable<Device> devices) {
+ private ImmutableSet<TopologyVertex>
+ buildVertexes(Iterable<Device> devices) {
ImmutableSet.Builder<TopologyVertex> vertexes = ImmutableSet.builder();
for (Device device : devices) {
TopologyVertex vertex = new DefaultTopologyVertex(device.id());
@@ -95,7 +131,8 @@
for (Link link : links) {
try {
edges.add(new DefaultTopologyEdge(vertexOf(link.src()),
- vertexOf(link.dst()), link));
+ vertexOf(link.dst()),
+ link));
} catch (IllegalArgumentException e) {
log.debug("Ignoring {}, missing vertex", link);
}
diff --git a/core/api/src/main/java/org/onosproject/net/topology/GraphDescription.java b/core/api/src/main/java/org/onosproject/net/topology/GraphDescription.java
index 3a243df..cc22c33 100644
--- a/core/api/src/main/java/org/onosproject/net/topology/GraphDescription.java
+++ b/core/api/src/main/java/org/onosproject/net/topology/GraphDescription.java
@@ -15,9 +15,10 @@
*/
package org.onosproject.net.topology;
-import com.google.common.collect.ImmutableSet;
import org.onosproject.net.Description;
+import com.google.common.collect.ImmutableSet;
+
/**
* Describes attribute(s) of a network graph.
*/
@@ -32,6 +33,14 @@
long timestamp();
/**
+ * Returns the creation timestamp of the graph description. This is
+ * expressed in system millis to allow proper date and time formatting.
+ *
+ * @return graph description creation timestamp in millis
+ */
+ long creationTime();
+
+ /**
* Returns the set of topology graph vertexes.
*
* @return set of graph vertexes
@@ -46,4 +55,3 @@
ImmutableSet<TopologyEdge> edges();
}
-
diff --git a/core/api/src/main/java/org/onosproject/net/topology/Topology.java b/core/api/src/main/java/org/onosproject/net/topology/Topology.java
index df8d63c..a174219 100644
--- a/core/api/src/main/java/org/onosproject/net/topology/Topology.java
+++ b/core/api/src/main/java/org/onosproject/net/topology/Topology.java
@@ -23,16 +23,24 @@
public interface Topology extends Provided {
/**
- * Returns the time, specified in system nanos of when the topology
- * became available.
+ * Returns the time, specified in system nanos of when the topology became
+ * available.
*
* @return time in system nanos
*/
long time();
/**
- * Returns the time, specified in system nanos of how long the topology
- * took to compute.
+ * Returns the time, specified in system millis of when the topology became
+ * available.
+ *
+ * @return time in system nanos
+ */
+ long creationTime();
+
+ /**
+ * Returns the time, specified in system nanos of how long the topology took
+ * to compute.
*
* @return elapsed time in system nanos
*/
@@ -53,7 +61,6 @@
*/
int deviceCount();
-
/**
* Returns the number of infrastructure links in the topology.
*