Bug 5953: Fixed NPE in FlowRemovedTranslator. 45/39345/1
authorShigeru Yasuda <s-yasuda@da.jp.nec.com>
Tue, 24 May 2016 13:00:16 +0000 (22:00 +0900)
committerShigeru Yasuda <s-yasuda@da.jp.nec.com>
Tue, 24 May 2016 13:00:16 +0000 (22:00 +0900)
table-id in OF10 FlowRemoved should be ignored because OF10 FLOW_REMOVED
message doesn't contain table ID.

Change-Id: I5e9b1a69219b361bbe3e20210ff04221416f1039
Signed-off-by: Shigeru Yasuda <s-yasuda@da.jp.nec.com>
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/translator/FlowRemovedTranslator.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/translator/FlowRemovedV10Translator.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/translator/FlowRemovedTranslatorTest.java

index 956389a10362294c029f8d2901c5b707538d7b35..8ed2f223eb6cde20ad14ffaa585878b48580724e 100644 (file)
@@ -30,7 +30,7 @@ public class FlowRemovedTranslator implements MessageTranslator<FlowRemoved, org
                 .setCookie(new FlowCookie(input.getCookie()))
                 .setNode(new NodeRef(deviceState.getNodeInstanceIdentifier()))
                 .setPriority(input.getPriority())
-                .setTableId(input.getTableId().getValue().shortValue());
+                .setTableId(translateTableId(input));
 
         return flowRemovedBld.build();
     }
@@ -39,4 +39,14 @@ public class FlowRemovedTranslator implements MessageTranslator<FlowRemoved, org
         return MatchConvertorImpl.fromOFMatchToSALMatch(flowRemoved.getMatch(),
                 deviceState.getFeatures().getDatapathId(), OpenflowVersion.OF13);
     }
+
+    /**
+     * Translate the table ID in the FLOW_REMOVED message to SAL table ID.
+     *
+     * @param flowRemoved  FLOW_REMOVED message.
+     * @return  SAL table ID.
+     */
+    protected Short translateTableId(FlowRemoved flowRemoved) {
+        return flowRemoved.getTableId().getValue().shortValue();
+    }
 }
index 2436faeaebd3908b79a123a378fb478100f9e753..e684f857a249948aa4259afeee5a68fa6390d450 100644 (file)
@@ -25,4 +25,15 @@ public class FlowRemovedV10Translator extends FlowRemovedTranslator {
         return MatchConvertorImpl.fromOFMatchV10ToSALMatch(flowRemoved.getMatchV10(),
                 deviceState.getFeatures().getDatapathId(), OpenflowVersion.OF10);
     }
+
+    /**
+     * Always returns zero because OF10 FLOW_REMOVED doesn't contain table ID.
+     *
+     * @param flowRemoved  FLOW_REMOVED message.
+     * @return  Zero.
+     */
+    @Override
+    protected Short translateTableId(FlowRemoved flowRemoved) {
+        return Short.valueOf((short)0);
+    }
 }
index a695ef097017dbdde2df959cea31b6d0ac9061cd..823a5b14651c24b875f6315b5d7d5999706b741e 100644 (file)
@@ -91,21 +91,21 @@ public class FlowRemovedTranslatorTest {
 
         assertEquals(flowRemovedMessage.getCookie(), flowRemoved.getCookie().getValue());
         assertEquals(flowRemovedMessage.getPriority(), flowRemoved.getPriority());
-        assertEquals((long)flowRemovedMessage.getTableId().getValue(), (long)flowRemoved.getTableId());
+        assertEquals((short)0, flowRemoved.getTableId().shortValue());
     }
 
     private org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved buildMessage(boolean isV10) {
         FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder()
                 .setCookie(BigInteger.ONE)
-                .setPriority(1)
-                .setTableId(new TableId(42l));
+                .setPriority(1);
 
         if (isV10) {
             builder.setMatchV10(new MatchV10Builder().setWildcards(flowWildcards).build());
         } else {
-            builder.setMatch(new MatchBuilder().setMatchEntry(Collections.<MatchEntry>emptyList()).build());
+            builder.setMatch(new MatchBuilder().setMatchEntry(Collections.<MatchEntry>emptyList()).build())
+                .setTableId(new TableId(42l));
         }
 
         return builder.build();
     }
-}
\ No newline at end of file
+}