Bump upstreams
[lispflowmapping.git] / mappingservice / lisp-proto / src / main / java / org / opendaylight / lispflowmapping / lisp / util / MaskUtil.java
index 9be7e2bbe96940e0da02a3d9e1675349cc2d9987..f2ecd098956319697b25be94fe24520be834393f 100644 (file)
@@ -9,13 +9,11 @@ package org.opendaylight.lispflowmapping.lisp.util;
 
 import com.google.common.base.Preconditions;
 import com.google.common.net.InetAddresses;
-
 import java.net.Inet4Address;
 import java.net.Inet6Address;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.nio.ByteBuffer;
-
 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.IpPrefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
@@ -33,13 +31,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.typ
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv6Binary;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv6PrefixBinary;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yangtools.yang.common.Uint8;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public final class MaskUtil {
     private static final Logger LOG = LoggerFactory.getLogger(MaskUtil.class);
     public static final short IPV4_MAX_MASK = 32;
+    public static final Uint8 IPV4_MAX_MASK_UINT = Uint8.valueOf(IPV4_MAX_MASK);
     public static final short IPV6_MAX_MASK = 128;
+    public static final Uint8 IPV6_MAX_MASK_UINT = Uint8.valueOf(IPV6_MAX_MASK);
 
     // Utility class, should not be instantiated
     private MaskUtil() {
@@ -114,11 +115,11 @@ public final class MaskUtil {
         try {
             if (address instanceof Ipv4PrefixBinary) {
                 byte[] addr = ((Ipv4PrefixBinary) address).getIpv4AddressBinary().getValue();
-                short mask = ((Ipv4PrefixBinary) address).getIpv4MaskLength();
+                short mask = ((Ipv4PrefixBinary) address).getIpv4MaskLength().toJava();
                 return LispAddressUtil.asIpv4PrefixBinaryEid(eid, normalizeByteArray(addr, mask), mask);
             } else if (address instanceof Ipv6PrefixBinary) {
                 byte[] addr = ((Ipv6PrefixBinary) address).getIpv6AddressBinary().getValue();
-                short mask = ((Ipv6PrefixBinary) address).getIpv6MaskLength();
+                short mask = ((Ipv6PrefixBinary) address).getIpv6MaskLength().toJava();
                 return LispAddressUtil.asIpv6PrefixBinaryEid(eid, normalizeByteArray(addr, mask), mask);
             } else if (address instanceof Ipv4Prefix) {
                 String[] v4prefix = splitPrefix(((Ipv4Prefix)address).getIpv4Prefix().getValue());
@@ -141,8 +142,8 @@ public final class MaskUtil {
                 return normalizeSrcDst(eid);
             } else if (address instanceof ServicePath) {
                 // Build new Service Path eid with service index set to 0
-                long spi = ((ServicePath) address).getServicePath().getServicePathId().getValue();
-                long vni = eid.getVirtualNetworkId() != null ? eid.getVirtualNetworkId().getValue() : -1;
+                long spi = ((ServicePath) address).getServicePath().getServicePathId().getValue().toJava();
+                long vni = eid.getVirtualNetworkId() != null ? eid.getVirtualNetworkId().getValue().toJava() : -1;
                 return LispAddressUtil.asServicePathEid(vni, spi, (short)0);
             }
         } catch (UnknownHostException e) {
@@ -172,7 +173,7 @@ public final class MaskUtil {
         short mask = Short.parseShort(prefix[1]);
 
         InetAddress normalizedAddress = normalizeIP(InetAddresses.forString(prefix[0]), mask);
-        return IetfInetUtil.INSTANCE.ipPrefixFor(normalizedAddress.getAddress(), mask);
+        return IetfInetUtil.ipPrefixFor(normalizedAddress.getAddress(), mask);
     }
 
     private static InetAddress normalizeIP(InetAddress address, int maskLength) throws UnknownHostException {
@@ -187,7 +188,7 @@ public final class MaskUtil {
             if (mask >= 8) {
                 byteRepresentation.put(i, (byte) (byteMask & byteRepresentation.get(i)));
             } else if (mask > 0) {
-                byteRepresentation.put(i, (byte) ((byte) (byteMask << (8 - mask)) & byteRepresentation.get(i)));
+                byteRepresentation.put(i, (byte) ((byte) (byteMask << 8 - mask) & byteRepresentation.get(i)));
             } else {
                 byteRepresentation.put(i, (byte) (0 & byteRepresentation.get(i)));
             }
@@ -258,9 +259,9 @@ public final class MaskUtil {
         } else if (address instanceof InstanceId) {
             return getMaskForAddress(((InstanceId)address).getInstanceId().getAddress());
         } else if (address instanceof Ipv4PrefixBinary) {
-            return ((Ipv4PrefixBinary) address).getIpv4MaskLength();
+            return ((Ipv4PrefixBinary) address).getIpv4MaskLength().toJava();
         } else if (address instanceof Ipv6PrefixBinary) {
-            return ((Ipv6PrefixBinary) address).getIpv6MaskLength();
+            return ((Ipv6PrefixBinary) address).getIpv6MaskLength().toJava();
         }
         return -1;
     }