Madan Jampani
Committed by Gerrit Code Review

Misc fixes in openflow provider subsystem

Change-Id: I5e6ab619f66ca71badc25efc7be7560070639051
......@@ -787,7 +787,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
OFPortStatsReply portStatsReply = (OFPortStatsReply) msg;
List<OFPortStatsEntry> portStatsReplyList = portStatsReplies.get(dpid);
if (portStatsReplyList == null) {
portStatsReplyList = Lists.newArrayList();
portStatsReplyList = Lists.newCopyOnWriteArrayList();
}
portStatsReplyList.addAll(portStatsReply.getEntries());
portStatsReplies.put(dpid, portStatsReplyList);
......
......@@ -15,6 +15,7 @@
*/
package org.onosproject.provider.of.flow.impl;
import static com.google.common.base.Preconditions.checkNotNull;
import org.onlab.util.SharedExecutors;
import org.onosproject.openflow.controller.OpenFlowSwitch;
import org.onosproject.openflow.controller.RoleState;
......@@ -52,7 +53,7 @@ class FlowStatsCollector implements SwitchDataCollector {
*/
FlowStatsCollector(Timer timer, OpenFlowSwitch sw, int pollInterval) {
this.timer = timer;
this.sw = sw;
this.sw = checkNotNull(sw, "Null switch");
this.pollInterval = pollInterval;
}
......
......@@ -19,8 +19,11 @@ import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.RemovalCause;
import com.google.common.cache.RemovalNotification;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
......@@ -217,6 +220,7 @@ public class OpenFlowRuleProvider extends AbstractProvider
}
private void createCollector(OpenFlowSwitch sw) {
checkNotNull(sw, "Null switch");
if (adaptiveFlowSampling) {
// NewAdaptiveFlowStatsCollector Constructor
NewAdaptiveFlowStatsCollector fsc =
......@@ -339,10 +343,17 @@ public class OpenFlowRuleProvider extends AbstractProvider
public void executeBatch(FlowRuleBatchOperation batch) {
checkNotNull(batch);
pendingBatches.put(batch.id(), new InternalCacheEntry(batch));
Dpid dpid = Dpid.dpid(batch.deviceId().uri());
OpenFlowSwitch sw = controller.getSwitch(dpid);
// If switch no longer exists, simply return.
if (sw == null) {
Set<FlowRule> failures = ImmutableSet.copyOf(Lists.transform(batch.getOperations(), e -> e.target()));
providerService.batchOperationCompleted(batch.id(),
new CompletedBatchOperation(false, failures, batch.deviceId()));
return;
}
pendingBatches.put(batch.id(), new InternalCacheEntry(batch));
OFFlowMod mod;
for (FlowRuleBatchEntry fbe : batch.getOperations()) {
// flow is the third party privacy flow
......
......@@ -56,6 +56,11 @@ public class MeterStatsCollector implements TimerTask {
@Override
public void run(Timeout timeout) throws Exception {
if (!sw.isConnected()) {
log.debug("Switch {} disconnected. Aborting meter stats collection", sw.getStringId());
return;
}
log.trace("Collecting stats for {}", sw.getStringId());
sendMeterStatistic();
......
......@@ -204,7 +204,7 @@ public class OpenFlowMeterProvider extends AbstractProvider implements MeterProv
}
private void createStatsCollection(OpenFlowSwitch sw) {
if (isMeterSupported(sw)) {
if (sw != null && isMeterSupported(sw)) {
MeterStatsCollector msc = new MeterStatsCollector(sw, POLL_INTERVAL);
msc.start();
stopCollectorIfNeeded(collectors.put(new Dpid(sw.getId()), msc));
......