NETVIRT-1643: Added checkes to resolve NPE 75/86775/4
authorShashidhar Raja <shashidharr@altencalsoftlabs.com>
Tue, 7 Jan 2020 07:11:07 +0000 (12:41 +0530)
committerShashidhar Raja <shashidharr@altencalsoftlabs.com>
Wed, 8 Jan 2020 10:00:02 +0000 (15:30 +0530)
Change-Id: I728a4757d10bbf6465409181f7dd2561bd176821
Signed-off-by: Shashidhar Raja <shashidharr@altencalsoftlabs.com>
aclservice/impl/src/main/java/org/opendaylight/netvirt/aclservice/AbstractAclServiceImpl.java
aclservice/impl/src/main/java/org/opendaylight/netvirt/aclservice/listeners/AclEventListener.java

index dda7afd35db5f728e4c0dfccbd377484c10f09ec..42fc2bd26043cb294ebcf64323883ed25bde9626 100644 (file)
@@ -735,16 +735,27 @@ public abstract class AbstractAclServiceImpl implements AclServiceListener {
         List<FlowEntity> addFlowEntries = new ArrayList<>();
         List<FlowEntity> deleteFlowEntries = new ArrayList<>();
         if (!remoteAclsAdded.isEmpty() || !remoteAclsDeleted.isEmpty()) {
-            // delete and add flows in ACL dispatcher table for all applicable
-            // ports
+            // delete and add flows in ACL dispatcher table for all applicable ports
             for (AclInterface portBefore : portsBefore) {
-                programAclDispatcherTable(deleteFlowEntries, portBefore, NwConstants.DEL_FLOW);
+                if (portBefore.getDpId() != null) {
+                    programAclDispatcherTable(deleteFlowEntries, portBefore, NwConstants.DEL_FLOW);
+                } else {
+                    LOG.debug("Skip ACL dispatcher table update as DP ID for interface {} is not present.",
+                            portBefore.getInterfaceId());
+                }
             }
             for (AclInterface port : interfaceList) {
                 programAclDispatcherTable(addFlowEntries, port, NwConstants.ADD_FLOW);
             }
         }
-        Set<BigInteger> dpns = interfaceList.stream().map(AclInterface::getDpId).collect(Collectors.toSet());
+        Set<BigInteger> dpns = interfaceList.stream().filter(port -> {
+            if (port.getDpId() == null) {
+                LOG.debug("Skip remote ACL table update as DP ID for interface {} is not present.",
+                        port.getInterfaceId());
+                return false;
+            }
+            return true;
+        }).map(AclInterface::getDpId).collect(Collectors.toSet());
 
         programRemoteAclTable(deleteFlowEntries, aclName, remoteAclsDeleted, dpns, NwConstants.DEL_FLOW);
         programRemoteAclTable(addFlowEntries, aclName, remoteAclsAdded, dpns, NwConstants.ADD_FLOW);
index 6b7ce297ed7306bb77ca3398f56fb7762c6dd726..bbe44e0814eecec197501dace818f1e62a400669 100644 (file)
@@ -8,6 +8,8 @@
 package org.opendaylight.netvirt.aclservice.listeners;
 
 import com.google.common.collect.ImmutableSet;
+
+import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -147,8 +149,15 @@ public class AclEventListener extends AsyncDataTreeChangeListenerBase<Acl, AclEv
             AclServiceManager.Action action) {
         LOG.trace("update ace rules - action: {} , ace rules: {}", action.name(), aceList);
         for (AclInterface port : interfaceList) {
-            for (Ace aceRule : aceList) {
-                aclServiceManager.notifyAce(port, action, aclName, aceRule);
+            BigInteger dpId = port.getDpId();
+            Long elanId = port.getElanId();
+            if (dpId != null && elanId != null) {
+                for (Ace aceRule : aceList) {
+                    aclServiceManager.notifyAce(port, action, aclName, aceRule);
+                }
+            } else {
+                LOG.debug("Skip update ACE rules as DP ID or ELAN ID for interface {} is not present. "
+                        + "DP Id: {} ELAN ID: {}", port.getInterfaceId(), dpId, elanId);
             }
         }
     }