Lei Xu
Committed by Gerrit Code Review

[emu][onos-3159] fix concurrency flaws in OpenFlowDeviceProvider.java and OpenFlowGroupProvider.java

Change-Id: I76b21b221d3ef71e1701c13810c4df374afe1776
......@@ -319,6 +319,9 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
}
DeviceId did = deviceId(uri(dpid));
OpenFlowSwitch sw = controller.getSwitch(dpid);
if (sw == null) {
return;
}
ChassisId cId = new ChassisId(dpid.value());
......@@ -339,9 +342,14 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
providerService.updatePorts(did, buildPortDescriptions(sw));
PortStatsCollector psc =
new PortStatsCollector(controller.getSwitch(dpid), portStatsPollFrequency);
new PortStatsCollector(sw, portStatsPollFrequency);
psc.start();
collectors.put(dpid, psc);
//figure out race condition for collectors.remove() and collectors.put()
if (controller.getSwitch(dpid) == null) {
switchRemoved(dpid);
}
}
@Override
......@@ -364,6 +372,9 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
}
DeviceId did = deviceId(uri(dpid));
OpenFlowSwitch sw = controller.getSwitch(dpid);
if (sw == null) {
return;
}
providerService.updatePorts(did, buildPortDescriptions(sw));
}
......
......@@ -334,12 +334,20 @@ public class OpenFlowGroupProvider extends AbstractProvider implements GroupProv
@Override
public void switchAdded(Dpid dpid) {
OpenFlowSwitch sw = controller.getSwitch(dpid);
if (sw == null) {
return;
}
if (isGroupSupported(sw)) {
GroupStatsCollector gsc = new GroupStatsCollector(
controller.getSwitch(dpid), POLL_INTERVAL);
gsc.start();
collectors.put(dpid, gsc);
}
//figure out race condition
if (controller.getSwitch(dpid) == null) {
switchRemoved(dpid);
}
}
@Override
......