diff --git a/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java b/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java index 6cdcf712cdfb87732907b1c248c9d547de2e653d..75d900131e73fd842e895e3210e0c5e86c81c4a5 100644 --- a/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java +++ b/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java @@ -95,7 +95,8 @@ public abstract class OFSwitchBase implements IOFSwitch { protected IFloodlightProviderService floodlightProvider; protected IThreadPoolService threadPool; protected IDebugCounterService debugCounters; - protected Date connectedSince; + // FIXME: Don't use java.util.Date + protected volatile Date connectedSince; /* Switch features from initial featuresReply */ protected int capabilities; @@ -170,7 +171,7 @@ public abstract class OFSwitchBase implements IOFSwitch { public OFSwitchBase() { this.stringId = null; this.attributes = new ConcurrentHashMap<Object, Object>(); - this.connectedSince = new Date(); + this.connectedSince = null; this.transactionIdSource = new AtomicInteger(); this.connected = false; this.statsFutureMap = new ConcurrentHashMap<Integer,OFStatisticsFuture>(); @@ -1094,6 +1095,10 @@ public abstract class OFSwitchBase implements IOFSwitch { @JsonIgnore public void setConnected(boolean connected) { // No lock needed since we use volatile + if (connected && this.connectedSince == null) + this.connectedSince = new Date(); + else if (!connected) + this.connectedSince = null; this.connected = connected; } diff --git a/src/main/java/net/floodlightcontroller/core/web/ControllerSwitchesResource.java b/src/main/java/net/floodlightcontroller/core/web/ControllerSwitchesResource.java index b8d8e0bf9e34c73113c0aa955edaa5443aa18eef..eeaebe22c38aafb04834f2bac82e51be991e21be 100644 --- a/src/main/java/net/floodlightcontroller/core/web/ControllerSwitchesResource.java +++ b/src/main/java/net/floodlightcontroller/core/web/ControllerSwitchesResource.java @@ -92,6 +92,8 @@ public class ControllerSwitchesResource extends ServerResource { } public long getConnectedSince() { + if (sw.getConnectedSince() == null) + return 0; return sw.getConnectedSince().getTime(); }