Carmelo Cascone
Committed by Jonathan Hart

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
......@@ -47,7 +47,6 @@ import org.slf4j.LoggerFactory;
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 @@ public class Bmv2FlowRuleProgrammable extends AbstractHandlerBehaviour implement
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 @@ public class Bmv2FlowRuleProgrammable extends AbstractHandlerBehaviour implement
}
// 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) {
......
......@@ -20,8 +20,6 @@ import com.google.common.annotations.Beta;
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 @@ public final class Bmv2FlowRuleWrapper {
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 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 @@ public final class Bmv2FlowRuleWrapper {
}
/**
* 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 @@ public final class Bmv2FlowRuleWrapper {
@Override
public int hashCode() {
return Objects.hashCode(rule, entryId, creationDate);
return Objects.hashCode(rule, entryId, installedOnMillis);
}
@Override
......@@ -97,11 +97,11 @@ public final class Bmv2FlowRuleWrapper {
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();
}
}
......