Bug 5483 - added support for num values in rules 40/36040/2
authorTomas Cechvala <tcechval@cisco.com>
Wed, 9 Mar 2016 15:33:41 +0000 (16:33 +0100)
committerMartin Sunal <msunal@cisco.com>
Tue, 29 Mar 2016 16:21:04 +0000 (16:21 +0000)
Added mapping for numerical values of neutron
security-group-rules.

Change-Id: Id4166300a2a922a30fb553ea5593385fed408652
Signed-off-by: Tomas Cechvala <tcechval@cisco.com>
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/api/sf/IpProtoClassifierDefinition.java
neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SecRuleEntityDecoder.java
neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/NeutronUtils.java
neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SecRuleEntityDecoderTest.java

index bfb59e73a2b53088c71676e9003ff41ea24a7b9b..a68036e15ae2c3ee7a6094905c97ef5485490bd6 100755 (executable)
@@ -43,6 +43,10 @@ public class IpProtoClassifierDefinition {
      * ICMP protocol value
      */
     public static final Long ICMP_VALUE = Long.valueOf(1);
+    /**
+     * ICMPv6 protocol value
+     */
+    public static final Long ICMPv6_VALUE = Long.valueOf(58);
     /**
      * SCTP protocol value
      */
index bfda7e364d52eea7586773412a1845ea6b5b91cb..e9d42f469d3f0c138fc7c548b87f4c0836ca9b01 100755 (executable)
@@ -237,7 +237,7 @@ public class SecRuleEntityDecoder {
      *         empty; Otherwise protocol number\r
      * @throws IllegalArgumentException if return value of\r
      *         {@link NeutronSecurityRule#getSecurityRuleProtocol()} is not empty/null and is other\r
-     *         than "tcp", "udp", "icmp"\r
+     *         than "tcp", "udp", "icmp", "icmpv6" or string values that can be decoded to {@link Short}.\r
      */\r
     public static Long getProtocol(NeutronSecurityRule secRule) {\r
         String protocol = secRule.getSecurityRuleProtocol();\r
@@ -253,6 +253,16 @@ public class SecRuleEntityDecoder {
         if (NeutronUtils.ICMP.equals(protocol)) {\r
             return IpProtoClassifierDefinition.ICMP_VALUE;\r
         }\r
-        throw new IllegalArgumentException("Protocol " + protocol + " is not supported.");\r
+        if (NeutronUtils.ICMPv6.equals(protocol)) {\r
+            return IpProtoClassifierDefinition.ICMPv6_VALUE;\r
+        }\r
+        Long protocolNum;\r
+        try {\r
+            protocolNum = Long.valueOf(protocol);\r
+        } catch (NumberFormatException e) {\r
+            throw new IllegalArgumentException("Neutron Security Rule Protocol value " + protocol\r
+                    + " is not supported.");\r
+        }\r
+        return protocolNum;\r
     }\r
 }\r
index d44b76c4616f974626dba54f1256dcdbbac5479f..b1c960403c08e21fb945a70abab637eed9a03468 100644 (file)
@@ -18,6 +18,7 @@ public final class NeutronUtils {
     public static final String UDP = "udp";
     public static final String TCP = "tcp";
     public static final String ICMP = "icmp";
+    public static final String ICMPv6 = "icmpv6";
 
     private NeutronUtils() {
         throw new UnsupportedOperationException("Cannot create an instance.");
index e73f50129b63a45b10c40b570b216d8513326df4..ccda7b17dc819a3554c5a47884b9e2cc105d6705 100644 (file)
@@ -656,6 +656,12 @@ public class SecRuleEntityDecoderTest {
         Assert.assertEquals(IpProtoClassifierDefinition.ICMP_VALUE, SecRuleEntityDecoder.getProtocol(secRule));
     }
 
+    @Test
+    public final void testGetProtocol_numValue() {
+        secRule.setSecurityRuleProtocol("199");
+        Assert.assertEquals(Long.valueOf(199) , SecRuleEntityDecoder.getProtocol(secRule));
+    }
+
     @Test
     public final void testGetProtocol_protoNull() {
         secRule.setSecurityRuleProtocol(null);