BUG-47 : unfinished PCEP migration to generated DTOs.
[bgpcep.git] / concepts / src / main / java / org / opendaylight / protocol / concepts / Ipv6Util.java
index 985e82bc1de391e500e9033cf83291b3cd6712b6..6eb959d8de32b944340df9631346cfe713000ff6 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.protocol.concepts;
 
 import java.net.Inet6Address;
+import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.Collections;
 import java.util.List;
@@ -33,6 +34,16 @@ public class Ipv6Util {
                }
        }
 
+       public static byte[] bytesForAddress(final Ipv6Address address) {
+               Inet6Address a;
+               try {
+                       a = (Inet6Address) InetAddress.getByName(address.getValue());
+               } catch (final UnknownHostException e) {
+                       throw new IllegalArgumentException(e.getMessage());
+               }
+               return a.getAddress();
+       }
+
        public static Ipv6Prefix prefixForBytes(final byte[] bytes, final int length) {
                Preconditions.checkArgument(length <= bytes.length * 8);
                return new Ipv6Prefix(addressForBytes(bytes).toString() + "/" + length);