Fixed stack overflow bug when using BMv2 table entry service
Similarly to ONOS-4206, due to a bug in kryo, a non-registered class
(Date in this case) was causing such a problem.
Change-Id: I993f4b41d4deaa617065b29086a49d834832eca8
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2FlowRuleProgrammable.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2FlowRuleProgrammable.java
index d8fed8a..5fc9908 100644
--- a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2FlowRuleProgrammable.java
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2FlowRuleProgrammable.java
@@ -47,7 +47,6 @@
import java.util.Collection;
import java.util.Collections;
-import java.util.Date;
import java.util.List;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.locks.Lock;
@@ -152,7 +151,7 @@
log.debug("getFlowEntries(): inconsistent entry id! BUG? Updating it... remote={}, local={}",
remoteEntryId, localEntryId);
frWrapper = new Bmv2FlowRuleWrapper(frWrapper.rule(), remoteEntryId,
- frWrapper.creationDate());
+ frWrapper.installedOnMillis());
tableEntryService.bind(entryRef, frWrapper);
}
@@ -255,7 +254,7 @@
}
// Add entry.
entryId = doAddEntry(deviceAgent, bmv2Entry);
- frWrapper = new Bmv2FlowRuleWrapper(rule, entryId, new Date());
+ frWrapper = new Bmv2FlowRuleWrapper(rule, entryId, System.currentTimeMillis());
} else {
// Remove entry
if (frWrapper == null) {
diff --git a/protocols/bmv2/api/src/main/java/org/onosproject/bmv2/api/runtime/Bmv2FlowRuleWrapper.java b/protocols/bmv2/api/src/main/java/org/onosproject/bmv2/api/runtime/Bmv2FlowRuleWrapper.java
index 31bab78..e23059d 100644
--- a/protocols/bmv2/api/src/main/java/org/onosproject/bmv2/api/runtime/Bmv2FlowRuleWrapper.java
+++ b/protocols/bmv2/api/src/main/java/org/onosproject/bmv2/api/runtime/Bmv2FlowRuleWrapper.java
@@ -20,8 +20,6 @@
import com.google.common.base.Objects;
import org.onosproject.net.flow.FlowRule;
-import java.util.Date;
-
/**
* A wrapper for a ONOS flow rule installed on a BMv2 device.
*/
@@ -30,19 +28,20 @@
private final FlowRule rule;
private final long entryId;
- private final Date creationDate;
+ private final long installedOnMillis;
/**
* Creates a new flow rule wrapper.
*
- * @param rule a flow rule
- * @param entryId a BMv2 table entry ID
- * @param creationDate the creation date of the flow rule
+ * @param rule a flow rule
+ * @param entryId a BMv2 table entry ID
+ * @param installedOnMillis the time (in milliseconds, since January 1, 1970 UTC) when the flow rule was installed
+ * on the device
*/
- public Bmv2FlowRuleWrapper(FlowRule rule, long entryId, Date creationDate) {
+ public Bmv2FlowRuleWrapper(FlowRule rule, long entryId, long installedOnMillis) {
this.rule = rule;
this.entryId = entryId;
- this.creationDate = new Date();
+ this.installedOnMillis = installedOnMillis;
}
/**
@@ -55,21 +54,22 @@
}
/**
- * Return the seconds since when this flow rule was installed on the device.
+ * Return the number of seconds since when this flow rule was installed on the device.
*
* @return an integer value
*/
public long lifeInSeconds() {
- return (new Date().getTime() - creationDate.getTime()) / 1000;
+ return (System.currentTimeMillis() - installedOnMillis) / 1000;
}
/**
- * Returns the creation date of this flow rule.
+ * Returns the the time (in milliseconds, since January 1, 1970 UTC) when the flow rule was installed on
+ * the device.
*
- * @return a date
+ * @return a long value
*/
- public Date creationDate() {
- return creationDate;
+ public long installedOnMillis() {
+ return installedOnMillis;
}
/**
@@ -83,7 +83,7 @@
@Override
public int hashCode() {
- return Objects.hashCode(rule, entryId, creationDate);
+ return Objects.hashCode(rule, entryId, installedOnMillis);
}
@Override
@@ -97,11 +97,11 @@
final Bmv2FlowRuleWrapper other = (Bmv2FlowRuleWrapper) obj;
return Objects.equal(this.rule, other.rule)
&& Objects.equal(this.entryId, other.entryId)
- && Objects.equal(this.creationDate, other.creationDate);
+ && Objects.equal(this.installedOnMillis, other.installedOnMillis);
}
@Override
public String toString() {
- return creationDate + "-" + rule.hashCode();
+ return installedOnMillis + "-" + rule.hashCode();
}
}