From: Andrej Leitner Date: Wed, 10 Aug 2016 15:07:15 +0000 (+0200) Subject: Fix Ipv6 format compression X-Git-Tag: release/boron~45^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=a726ec64ea2e7f0437ca6eaa02be5848eb935bd9;p=openflowplugin.git Fix Ipv6 format compression - removed regex and replaced with existing methods - altered method that compresses Ipv6Address to take it as argument and not to accept any string - used Ipv6Address instead of String - updated IpConversionUtilTest - fixed yang descriptions Change-Id: I303d3f3c68bf463de9f017e0e65ec36adaf4e489 Signed-off-by: Andrej Leitner Signed-off-by: Tomas Slusny --- diff --git a/model/model-flow-base/src/main/yang/opendaylight-arbitrary-bitmask-fields.yang b/model/model-flow-base/src/main/yang/opendaylight-arbitrary-bitmask-fields.yang index a1fc528d43..4f1692d082 100644 --- a/model/model-flow-base/src/main/yang/opendaylight-arbitrary-bitmask-fields.yang +++ b/model/model-flow-base/src/main/yang/opendaylight-arbitrary-bitmask-fields.yang @@ -12,7 +12,7 @@ module opendaylight-arbitrary-bitmask-fields { grouping "ipv4-match-arbitrary-bitmask-fields" { leaf ipv4-source-address-no-mask { - description "IPv4 source address with no mask ."; + description "IPv4 source address with no mask."; type inet:ipv4-address; } @@ -22,12 +22,12 @@ module opendaylight-arbitrary-bitmask-fields { } leaf ipv4-source-arbitrary-bitmask { - description "IPv4 source address with no mask ."; + description "Arbitrary bit mask of IPv4 source address."; type yang:dotted-quad; } leaf ipv4-destination-arbitrary-bitmask { - description "IPv4 destination address with no mask."; + description "Arbitrary bit mask of IPv4 destination address."; type yang:dotted-quad; } } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/IpConversionUtil.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/IpConversionUtil.java index ea4815a16c..689f5a3fe4 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/IpConversionUtil.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/IpConversionUtil.java @@ -24,7 +24,6 @@ import java.util.Arrays; import java.util.BitSet; import java.util.Iterator; import java.util.List; - import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; @@ -35,12 +34,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.opendaylight.ipv6.arbitrary import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -/** - * Created by Martin Bobak <mbobak@cisco.com> on 5.3.2015. - * v6 routines added by Anton Ivanov on 14.6.2015 - * Arbitrary masks by sai.marapareddy@gmail.com - */ public final class IpConversionUtil { private static final Logger LOG = LoggerFactory.getLogger(IpConversionUtil.class); @@ -234,8 +227,6 @@ public final class IpConversionUtil { * @param ipv6Address - v6 Address object * @return - byte array of size 16. Last byte contains netmask */ - - public static byte[] canonicalBinaryV6Address(final Ipv6Address ipv6Address) { /* * Do not modify this routine to take direct strings input!!! @@ -243,10 +234,15 @@ public final class IpConversionUtil { * the input is validated via regexps in Ipv6Prefix() */ + return canonicalBinaryV6AddressFromString(ipv6Address.getValue()); + } + + + private static byte[] canonicalBinaryV6AddressFromString(final String ipv6Address) { Iterable splittedV6Address = Splitter.on("%") .trimResults() .omitEmptyStrings() - .split(ipv6Address.getValue()); + .split(ipv6Address); List partsV6Address = Lists.newArrayList(splittedV6Address.iterator()); int colonp; @@ -363,7 +359,7 @@ public final class IpConversionUtil { return dst; } - public static String byteArrayV6AddressToString (final byte [] _binary_form) throws UnknownHostException{ + public static String byteArrayV6AddressToString (final byte [] _binary_form) throws UnknownHostException { /* DO NOT DIY!!! - InetAddresses will actually print correct canonical * zero compressed form. */ @@ -762,14 +758,20 @@ public final class IpConversionUtil { return false; } - public static String compressedIpv6Format(final String ipv6Address) { - String compressedIpv6Address; - compressedIpv6Address = ipv6Address.replaceAll("((?::0+\\b){2,}):?(?!\\S*\\b\\1:0\\b)(\\S*)", "::$2"); - return compressedIpv6Address; + private static String compressedIpv6FormatFromString(final String ipv6Address) { + try { + return byteArrayV6AddressToString(canonicalBinaryV6AddressFromString(ipv6Address)); + } catch (UnknownHostException e) { + LOG.warn("Failed to compress IPv6 address {} because it is invalid", ipv6Address); + return ipv6Address; + } + } + + public static Ipv6Address compressedIpv6AddressFormat(final Ipv6Address ipv6Address) { + return new Ipv6Address(compressedIpv6FormatFromString(ipv6Address.getValue())); } public static Ipv6ArbitraryMask compressedIpv6MaskFormat(final Ipv6ArbitraryMask ipv6Mask) { - String stringIpv6Mask = ipv6Mask.getValue(); - return new Ipv6ArbitraryMask(compressedIpv6Format(stringIpv6Mask)); + return new Ipv6ArbitraryMask(compressedIpv6FormatFromString(ipv6Mask.getValue())); } } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/cases/OfToSalIpv6DstCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/cases/OfToSalIpv6DstCase.java index da1272ea1e..edd0175c9a 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/cases/OfToSalIpv6DstCase.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/cases/OfToSalIpv6DstCase.java @@ -49,11 +49,11 @@ public class OfToSalIpv6DstCase extends ConvertorCase