From dc04e8ff371e27cc0c31b55f38978f61ce8eeb0f Mon Sep 17 00:00:00 2001 From: Tomas Cechvala Date: Wed, 9 Mar 2016 16:33:41 +0100 Subject: [PATCH] Bug 5483 - added support for num values in rules Added mapping for numerical values of neutron security-group-rules. Change-Id: Id4166300a2a922a30fb553ea5593385fed408652 Signed-off-by: Tomas Cechvala --- .../api/sf/IpProtoClassifierDefinition.java | 4 ++++ .../mapper/mapping/rule/SecRuleEntityDecoder.java | 14 ++++++++++++-- .../neutron/mapper/util/NeutronUtils.java | 1 + .../mapping/rule/SecRuleEntityDecoderTest.java | 6 ++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/api/sf/IpProtoClassifierDefinition.java b/groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/api/sf/IpProtoClassifierDefinition.java index bfb59e73a..a68036e15 100755 --- a/groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/api/sf/IpProtoClassifierDefinition.java +++ b/groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/api/sf/IpProtoClassifierDefinition.java @@ -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 */ diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SecRuleEntityDecoder.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SecRuleEntityDecoder.java index bfda7e364..e9d42f469 100755 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SecRuleEntityDecoder.java +++ b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SecRuleEntityDecoder.java @@ -237,7 +237,7 @@ public class SecRuleEntityDecoder { * empty; Otherwise protocol number * @throws IllegalArgumentException if return value of * {@link NeutronSecurityRule#getSecurityRuleProtocol()} is not empty/null and is other - * than "tcp", "udp", "icmp" + * than "tcp", "udp", "icmp", "icmpv6" or string values that can be decoded to {@link Short}. */ public static Long getProtocol(NeutronSecurityRule secRule) { String protocol = secRule.getSecurityRuleProtocol(); @@ -253,6 +253,16 @@ public class SecRuleEntityDecoder { if (NeutronUtils.ICMP.equals(protocol)) { return IpProtoClassifierDefinition.ICMP_VALUE; } - throw new IllegalArgumentException("Protocol " + protocol + " is not supported."); + if (NeutronUtils.ICMPv6.equals(protocol)) { + return IpProtoClassifierDefinition.ICMPv6_VALUE; + } + Long protocolNum; + try { + protocolNum = Long.valueOf(protocol); + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Neutron Security Rule Protocol value " + protocol + + " is not supported."); + } + return protocolNum; } } diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/NeutronUtils.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/NeutronUtils.java index d44b76c46..b1c960403 100644 --- a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/NeutronUtils.java +++ b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/NeutronUtils.java @@ -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."); diff --git a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SecRuleEntityDecoderTest.java b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SecRuleEntityDecoderTest.java index e73f50129..ccda7b17d 100644 --- a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SecRuleEntityDecoderTest.java +++ b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SecRuleEntityDecoderTest.java @@ -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); -- 2.36.6