Fix NPE when clearing SFF initialization flows 46/46946/1
authorMiguel Duarte <miguel.duarte.de.mora.barroso@ericsson.com>
Fri, 14 Oct 2016 12:50:40 +0000 (14:50 +0200)
committerMiguel Duarte <miguel.duarte.de.mora.barroso@ericsson.com>
Fri, 14 Oct 2016 13:08:25 +0000 (15:08 +0200)
NPE whenever initialization flows did not exist (for instance, no RSP
ever created). Fixed by checking their existence before filtering
the ones that belong to orphan SFFs.

Change-Id: Id5601c630395551d031658de8e74f847904c6124
Signed-off-by: Miguel Duarte <miguel.duarte.de.mora.barroso@ericsson.com>
sfc-renderers/sfc-openflow-renderer/src/main/java/org/opendaylight/sfc/ofrenderer/openflow/SfcOfFlowWriterImpl.java
sfc-renderers/sfc-openflow-renderer/src/test/java/org/opendaylight/sfc/ofrenderer/SfcOfRspTransactionalProcessorTest.java

index 2b1bfed7bc99bbe06c5bc8f06cecc83ab4de1809..a88dcc26b51b269f0ad57c57040701de81e6b98c 100644 (file)
@@ -393,6 +393,11 @@ public class SfcOfFlowWriterImpl implements SfcOfFlowWriterInterface {
     public Set<NodeId> clearSffsIfNoRspExists() {
         Set<NodeId> sffNodeIDs = new HashSet<>();
 
+        if (!rspNameToFlowsMap.containsKey(SfcOfRspProcessor.SFC_FLOWS)) {
+            LOG.warn("clearSffsIfNoRspExists() - Attempting to delete initialization flows, and they do not exist");
+            return sffNodeIDs;
+        }
+
         Map<String, List<FlowDetails>> theInitializationFlows =
                 rspNameToFlowsMap.get(SfcOfRspProcessor.SFC_FLOWS);
 
index 86c0041cee873dff1756b91be7e19ba50766e7c2..05366a3af12bf74eb98e56900978dc5ef995fd96 100644 (file)
@@ -46,6 +46,7 @@ import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev1407
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sl.rev140701.VxlanGpe;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sl.rev140701.Nsh;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.powermock.api.mockito.PowerMockito;
 import org.powermock.core.classloader.annotations.PrepareForTest;
 import org.powermock.modules.junit4.PowerMockRunner;
@@ -139,7 +140,13 @@ public class SfcOfRspTransactionalProcessorTest {
         sfcFlowWriterTestMock.deleteRspFlows((long) 31);
         Set<SfcOfFlowWriterImpl.FlowDetails> flowsToDelete = Whitebox
                 .getInternalState(sfcFlowWriterTestMock, "setOfFlowsToDelete");
-        Assert.assertEquals(0, flowsToDelete.size());
+        Assert.assertTrue(flowsToDelete.isEmpty());
+    }
+
+    @Test
+    public void clearNonExistentInitializationFlows() {
+        Set<NodeId> theOrphanSffs = sfcFlowWriterTestMock.clearSffsIfNoRspExists();
+        Assert.assertTrue(theOrphanSffs.isEmpty());
     }
 
     /*