[ONOS-4931] fix doc of FlowEntry.life(), add life(TimeUnit)

Fix the doc: life() returns the time in seconds, not milliseconds.

Add new method life(TimeUnit) that allows specifying the timeunit to
receive the life value as as seconds might not be enough for
all applications and OpenFlow can provide this value to nanoseconds resolution
(in its spec).

Change-Id: Ia6a7573797249e0edc04e03c7204a550a2823742
diff --git a/core/api/src/main/java/org/onosproject/net/flow/DefaultFlowEntry.java b/core/api/src/main/java/org/onosproject/net/flow/DefaultFlowEntry.java
index dbd5e08..a770e97 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/DefaultFlowEntry.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/DefaultFlowEntry.java
@@ -16,16 +16,22 @@
 package org.onosproject.net.flow;
 
 import static com.google.common.base.MoreObjects.toStringHelper;
+import static java.util.concurrent.TimeUnit.NANOSECONDS;
+import static java.util.concurrent.TimeUnit.SECONDS;
 import static org.slf4j.LoggerFactory.getLogger;
 
 import org.slf4j.Logger;
 
+import java.util.concurrent.TimeUnit;
+
 public class DefaultFlowEntry extends DefaultFlowRule
     implements StoredFlowEntry {
 
     private static final Logger log = getLogger(DefaultFlowEntry.class);
 
+    /* Stored in nanoseconds (allows for 292 years) */
     private long life;
+
     private long packets;
     private long bytes;
     private FlowEntryState state;
@@ -37,10 +43,10 @@
     private final int errCode;
 
     public DefaultFlowEntry(FlowRule rule, FlowEntryState state,
-            long life, long packets, long bytes) {
+                            long life, TimeUnit lifeTimeUnit, long packets, long bytes) {
         super(rule);
         this.state = state;
-        this.life = life;
+        this.life = lifeTimeUnit.toNanos(life);
         this.packets = packets;
         this.bytes = bytes;
         this.errCode = -1;
@@ -48,15 +54,13 @@
         this.lastSeen = System.currentTimeMillis();
     }
 
+    public DefaultFlowEntry(FlowRule rule, FlowEntryState state,
+                            long lifeSecs, long packets, long bytes) {
+        this(rule, state, lifeSecs, SECONDS, packets, bytes);
+    }
+
     public DefaultFlowEntry(FlowRule rule) {
-        super(rule);
-        this.state = FlowEntryState.PENDING_ADD;
-        this.life = 0;
-        this.packets = 0;
-        this.bytes = 0;
-        this.errCode = -1;
-        this.errType = -1;
-        this.lastSeen = System.currentTimeMillis();
+        this(rule, FlowEntryState.PENDING_ADD, 0, 0, 0);
     }
 
     public DefaultFlowEntry(FlowRule rule, int errType, int errCode) {
@@ -69,7 +73,12 @@
 
     @Override
     public long life() {
-        return life;
+        return life(SECONDS);
+    }
+
+    @Override
+    public long life(TimeUnit timeUnit) {
+        return timeUnit.convert(life, NANOSECONDS);
     }
 
     @Override
@@ -104,7 +113,12 @@
 
     @Override
     public void setLife(long life) {
-        this.life = life;
+        setLife(life, SECONDS);
+    }
+
+    @Override
+    public void setLife(long life, TimeUnit timeUnit) {
+        this.life = timeUnit.toNanos(life);
     }
 
     @Override