Prince Pereira
Committed by Gerrit Code Review

Fix for ONOS-4944

Change-Id: Ib9e769cca386390f3f38769e957f423692b5b43a
...@@ -19,6 +19,8 @@ import com.google.common.cache.Cache; ...@@ -19,6 +19,8 @@ import com.google.common.cache.Cache;
19 import com.google.common.cache.CacheBuilder; 19 import com.google.common.cache.CacheBuilder;
20 import com.google.common.cache.RemovalCause; 20 import com.google.common.cache.RemovalCause;
21 import com.google.common.cache.RemovalNotification; 21 import com.google.common.cache.RemovalNotification;
22 +import com.google.common.collect.ImmutableSet;
23 +import com.google.common.collect.Lists;
22 import com.google.common.collect.Maps; 24 import com.google.common.collect.Maps;
23 import com.google.common.collect.Sets; 25 import com.google.common.collect.Sets;
24 import org.apache.felix.scr.annotations.Activate; 26 import org.apache.felix.scr.annotations.Activate;
...@@ -267,6 +269,9 @@ public class OpenFlowRuleProvider extends AbstractProvider ...@@ -267,6 +269,9 @@ public class OpenFlowRuleProvider extends AbstractProvider
267 private void applyRule(FlowRule flowRule) { 269 private void applyRule(FlowRule flowRule) {
268 Dpid dpid = Dpid.dpid(flowRule.deviceId().uri()); 270 Dpid dpid = Dpid.dpid(flowRule.deviceId().uri());
269 OpenFlowSwitch sw = controller.getSwitch(dpid); 271 OpenFlowSwitch sw = controller.getSwitch(dpid);
272 + if (sw == null) {
273 + return;
274 + }
270 275
271 FlowRuleExtPayLoad flowRuleExtPayLoad = flowRule.payLoad(); 276 FlowRuleExtPayLoad flowRuleExtPayLoad = flowRule.payLoad();
272 if (hasPayload(flowRuleExtPayLoad)) { 277 if (hasPayload(flowRuleExtPayLoad)) {
...@@ -296,6 +301,9 @@ public class OpenFlowRuleProvider extends AbstractProvider ...@@ -296,6 +301,9 @@ public class OpenFlowRuleProvider extends AbstractProvider
296 private void removeRule(FlowRule flowRule) { 301 private void removeRule(FlowRule flowRule) {
297 Dpid dpid = Dpid.dpid(flowRule.deviceId().uri()); 302 Dpid dpid = Dpid.dpid(flowRule.deviceId().uri());
298 OpenFlowSwitch sw = controller.getSwitch(dpid); 303 OpenFlowSwitch sw = controller.getSwitch(dpid);
304 + if (sw == null) {
305 + return;
306 + }
299 307
300 FlowRuleExtPayLoad flowRuleExtPayLoad = flowRule.payLoad(); 308 FlowRuleExtPayLoad flowRuleExtPayLoad = flowRule.payLoad();
301 if (hasPayload(flowRuleExtPayLoad)) { 309 if (hasPayload(flowRuleExtPayLoad)) {
...@@ -329,6 +337,13 @@ public class OpenFlowRuleProvider extends AbstractProvider ...@@ -329,6 +337,13 @@ public class OpenFlowRuleProvider extends AbstractProvider
329 337
330 Dpid dpid = Dpid.dpid(batch.deviceId().uri()); 338 Dpid dpid = Dpid.dpid(batch.deviceId().uri());
331 OpenFlowSwitch sw = controller.getSwitch(dpid); 339 OpenFlowSwitch sw = controller.getSwitch(dpid);
340 + if (sw == null) {
341 + Set<FlowRule> failures = ImmutableSet.copyOf(Lists.transform(batch.getOperations(), e -> e.target()));
342 + providerService.batchOperationCompleted(batch.id(),
343 + new CompletedBatchOperation(false, failures, batch.deviceId()));
344 + return;
345 + }
346 +
332 OFFlowMod mod; 347 OFFlowMod mod;
333 for (FlowRuleBatchEntry fbe : batch.getOperations()) { 348 for (FlowRuleBatchEntry fbe : batch.getOperations()) {
334 // flow is the third party privacy flow 349 // flow is the third party privacy flow
......