Merge "Fix codestyle"
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / common / IpConversionUtil.java
index 689f5a3fe4216102b3ba59aa61af79161512b5e9..f5b8c44d5a5461def93e1c974564e9904bec45bf 100644 (file)
@@ -124,6 +124,10 @@ public final class IpConversionUtil {
     }
 
     public static Ipv4Prefix createPrefix(final Ipv4Address ipv4Address, final byte [] bytemask){
+        if (bytemask == null) {
+            return createPrefix(ipv4Address);
+        }
+
         return IetfInetUtil.INSTANCE.ipv4PrefixFor(ipv4Address, countBits(bytemask));
     }
 
@@ -178,6 +182,10 @@ public final class IpConversionUtil {
     }
 
     public static Ipv6Prefix createPrefix(final Ipv6Address ipv6Address, final byte [] bytemask){
+        if (bytemask == null) {
+            return createPrefix(ipv6Address);
+        }
+
         return IetfInetUtil.INSTANCE.ipv6PrefixFor(ipv6Address, countBits(bytemask));
     }
 
@@ -398,7 +406,7 @@ public final class IpConversionUtil {
         List<String> partsV6Prefix = Lists.newArrayList(splittedV6Prefix.iterator());
 
         boolean valid = true;
-        
+
         try {
             mask = Integer.parseInt(partsV6Prefix.get(1));
             if (mask > 128) {
@@ -574,6 +582,17 @@ public final class IpConversionUtil {
         return sb.toString();
     }
 
+    /**
+     * Check if the supplied IPv6Address has any prefix
+     *
+     * @param ipv6Prefix Ipv6 prefix
+     * @return prefix if there is one, else null
+     */
+    public static Integer hasIpv6Prefix(final Ipv6Prefix ipv6Prefix) {
+        final int prefix = IpConversionUtil.extractIpv6Prefix(ipv6Prefix);
+        return prefix < IPV6_ADDRESS_LENGTH ? prefix : null;
+    }
+
     private static int ipv6PrefixByteArrayOffset(final int mask) {
         if (mask < 0) {
             return 0;
@@ -713,7 +732,7 @@ public final class IpConversionUtil {
 
     public static final byte[] convertIpv6ArbitraryMaskToByteArray(final Ipv6ArbitraryMask mask) {
         String maskValue;
-        if (mask.getValue() != null) {
+        if (mask != null && mask.getValue() != null) {
             maskValue  = mask.getValue();
         } else {
             maskValue = DEFAULT_IPV6_ARBITRARY_BITMASK;