Switch PCEP to no-zone ip addresses
[bgpcep.git] / util / src / main / java / org / opendaylight / protocol / util / ByteBufWriteUtil.java
index f26fffa9f7bd901b47238bb30f9791e99a8bb6d9..4ffd5e918754de1aa6d624429c9f704ef663b2f0 100644 (file)
@@ -12,8 +12,10 @@ import io.netty.buffer.ByteBuf;
 import java.math.BigInteger;
 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.Ipv4AddressNoZone;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
 
@@ -220,6 +222,23 @@ public final class ByteBufWriteUtil {
         }
     }
 
+    /**
+     * Writes IPv4 address if not null, otherwise writes zeros to the
+     * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 4.
+     *
+     * @param ipv4Address
+     *            IPv4 address to be written to the output.
+     * @param output
+     *            ByteBuf, where ipv4Address or zeros are written.
+     */
+    public static void writeIpv4Address(final Ipv4AddressNoZone ipv4Address, final ByteBuf output) {
+        if (ipv4Address != null) {
+            output.writeBytes(IetfInetUtil.INSTANCE.ipv4AddressNoZoneBytes(ipv4Address));
+        } else {
+            output.writeZero(Ipv4Util.IP4_LENGTH);
+        }
+    }
+
     /**
      * Writes IPv4 prefix if not null, otherwise writes zeros to the
      * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 5.
@@ -255,6 +274,23 @@ public final class ByteBufWriteUtil {
         }
     }
 
+    /**
+     * Writes IPv6 address if not null, otherwise writes zeros to the
+     * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 16.
+     *
+     * @param ipv6Address
+     *            IPv6 address to be written to the output.
+     * @param output
+     *            ByteBuf, where ipv6Address or zeros are written.
+     */
+    public static void writeIpv6Address(final Ipv6AddressNoZone ipv6Address, final ByteBuf output) {
+        if (ipv6Address != null) {
+            output.writeBytes(IetfInetUtil.INSTANCE.ipv6AddressNoZoneBytes(ipv6Address));
+        } else {
+            output.writeZero(Ipv6Util.IPV6_LENGTH);
+        }
+    }
+
     /**
      * Writes IPv6 prefix if not null, otherwise writes zeros to the
      * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 17.