Bug-612: Base PCEP serializers - more defensive code 55/8555/4
authorMilos Fabian <milfabia@cisco.com>
Wed, 2 Jul 2014 13:15:51 +0000 (15:15 +0200)
committerMilos Fabian <milfabia@cisco.com>
Mon, 7 Jul 2014 08:34:10 +0000 (10:34 +0200)
-check mandatory arguments
-set zeros for missing arguments

Change-Id: I02cf0b4c220846f2c8a9cfe3e9d4bd82bad72fa5
Signed-off-by: Milos Fabian <milfabia@cisco.com>
45 files changed:
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/AbstractBandwidthParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPClassTypeObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPCloseObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPEndPointsIpv4ObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPEndPointsIpv6ObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPErrorObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPExcludeRouteObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPGlobalConstraintsObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPLoadBalancingObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPLspaObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPMetricObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNoPathObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNotificationObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPObjectiveFunctionObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPOpenObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPRequestParameterObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPSvecObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROAsNumberSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROIpv4PrefixSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROIpv6PrefixSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROPathKey128SubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROPathKey32SubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROUnnumberedInterfaceSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/GeneralizedLabelParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/RROIpv4PrefixSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/RROIpv6PrefixSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/RROPathKey128SubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/RROPathKey32SubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/RROUnnumberedInterfaceSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/Type1LabelParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/WavebandSwitchingLabelParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/XROAsNumberSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/XROIpv4PrefixSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/XROIpv6PrefixSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/XROPathKey128SubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/XROPathKey32SubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/XROSRLGSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/XROUnnumberedInterfaceSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/AbstractVendorSpecificTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/NoPathVectorTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OFListTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OrderTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OverloadedDurationTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/ReqMissingTlvParser.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java

index cdf354cc85801a14f7c889f1ca96dd354ec090fd..697fe1a58eed82c30a1bd40b60b7ab59b59d1de2 100644 (file)
@@ -7,11 +7,11 @@
  */
 package org.opendaylight.protocol.pcep.impl.object;
 
-import com.google.common.base.Preconditions;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
 
+import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvRegistry;
@@ -47,7 +47,7 @@ abstract class AbstractBandwidthParser extends AbstractObjectWithTlvsParser<Band
     public void serializeObject(final Object object, final ByteBuf buffer) {
         Preconditions.checkArgument(object instanceof Bandwidth, "Wrong instance of PCEPObject. Passed %s. Needed BandwidthObject.", object.getClass());
         final ByteBuf body = Unpooled.buffer();
-        body.writeBytes(((Bandwidth) object).getBandwidth().getValue());
+        writeFloat32(((Bandwidth) object).getBandwidth(), body);
         formatBandwidth(object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
 
index b86077d4915ca2f1290e5deebd7a74529a57b178..2ccf3eb3e119ef5646b79f94ab7bb534ee465e42 100644 (file)
@@ -7,11 +7,11 @@
  */
 package org.opendaylight.protocol.pcep.impl.object;
 
-import com.google.common.base.Preconditions;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
 
+import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
@@ -85,7 +85,9 @@ public class PCEPClassTypeObjectParser extends AbstractObjectWithTlvsParser<Clas
         Preconditions.checkArgument(object instanceof ClassType, "Wrong instance of PCEPObject. Passed %s. Needed ClassTypeObject.", object.getClass());
         final ByteBuf body = Unpooled.buffer(SIZE);
         body.writeZero(SIZE -1);
-        body.writeByte(((ClassType) object).getClassType().getValue());
+        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClassType classType = ((ClassType) object).getClassType();
+        Preconditions.checkArgument(classType != null, "ClassType is mandatory.");
+        writeUnsignedByte(classType.getValue(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
 }
index 46137653d96b196bc870d13e958a4bcdff196cda..8369aff26d251f0afa07c9bb17b3fcc7b6e6d11c 100644 (file)
@@ -7,12 +7,12 @@
  */
 package org.opendaylight.protocol.pcep.impl.object;
 
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
+
 import com.google.common.base.Preconditions;
 import com.google.common.primitives.UnsignedBytes;
-
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
@@ -60,17 +60,13 @@ public class PCEPCloseObjectParser extends AbstractObjectWithTlvsParser<CCloseBu
         final CClose obj = (CClose) object;
         final ByteBuf body = Unpooled.buffer();
         body.writeZero(RESERVED + FLAGS_F_LENGTH);
-        body.writeByte(obj.getReason());
-        // FIXME: switch to ByteBuf
-        final byte[] tlvs = serializeTlvs(obj.getTlvs());
-        if (tlvs != null) {
-            body.writeBytes(tlvs);
-        }
+        Preconditions.checkArgument(obj.getReason() != null, "Reason is mandatory.");
+        writeUnsignedByte(obj.getReason(), body);
+        serializeTlvs(obj.getTlvs(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
 
-    public byte[] serializeTlvs(final Tlvs tlvs) {
-        // No tlvs defined
-        return new byte[0];
+    public void serializeTlvs(final Tlvs tlvs, final ByteBuf body) {
+        return;
     }
 }
index 316c9e02f23db29e7f468f0bbe8c7d6dbb12bb91..1728e50655e58cc5a5c5d879b8c9afec0ffd19aa 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.impl.object;
 
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Address;
+
 import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -23,6 +25,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.AddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv4Case;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv4CaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv4._case.Ipv4;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv4._case.Ipv4Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.EndpointsObj;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.EndpointsObjBuilder;
@@ -70,9 +73,12 @@ public class PCEPEndPointsIpv4ObjectParser extends AbstractObjectWithTlvsParser<
         final EndpointsObj ePObj = (EndpointsObj) object;
         final AddressFamily afi = ePObj.getAddressFamily();
         Preconditions.checkArgument(afi instanceof Ipv4Case, "Wrong instance of NetworkAddress. Passed %s. Needed IPv4", afi.getClass());
+        final Ipv4 ipv4 = ((Ipv4Case) afi).getIpv4();
         final ByteBuf body = Unpooled.buffer(Ipv4Util.IP4_LENGTH + Ipv4Util.IP4_LENGTH);
-        body.writeBytes(Ipv4Util.bytesForAddress((((Ipv4Case) afi).getIpv4()).getSourceIpv4Address()));
-        body.writeBytes(Ipv4Util.bytesForAddress((((Ipv4Case) afi).getIpv4()).getDestinationIpv4Address()));
+        Preconditions.checkArgument(ipv4.getSourceIpv4Address() != null, "SourceIpv4Address is mandatory.");
+        writeIpv4Address(ipv4.getSourceIpv4Address(), body);
+        Preconditions.checkArgument(ipv4.getDestinationIpv4Address() != null, "DestinationIpv4Address is mandatory.");
+        writeIpv4Address(ipv4.getDestinationIpv4Address(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
 }
index 8b3aaf7ea99492e88588db94fb8ab362d369441d..aefbd1777c03a2f73cee33cdead689eabc47e2b6 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.impl.object;
 
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Address;
+
 import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -23,6 +25,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.AddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv6Case;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv6CaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv6._case.Ipv6;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv6._case.Ipv6Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.EndpointsObj;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.EndpointsObjBuilder;
@@ -71,8 +74,11 @@ public class PCEPEndPointsIpv6ObjectParser extends AbstractObjectWithTlvsParser<
         final AddressFamily afi = ePObj.getAddressFamily();
         Preconditions.checkArgument(afi instanceof Ipv6Case, "Wrong instance of NetworkAddress. Passed %s. Needed IPv6", afi.getClass());
         final ByteBuf body = Unpooled.buffer(Ipv6Util.IPV6_LENGTH + Ipv6Util.IPV6_LENGTH);
-        body.writeBytes(Ipv6Util.bytesForAddress((((Ipv6Case) afi).getIpv6()).getSourceIpv6Address()));
-        body.writeBytes(Ipv6Util.bytesForAddress((((Ipv6Case) afi).getIpv6()).getDestinationIpv6Address()));
+        final Ipv6 ipv6 = ((Ipv6Case) afi).getIpv6();
+        Preconditions.checkArgument(ipv6.getSourceIpv6Address() != null, "SourceIpv6Address is mandatory.");
+        writeIpv6Address(ipv6.getSourceIpv6Address(), body);
+        Preconditions.checkArgument(ipv6.getDestinationIpv6Address() != null, "DestinationIpv6Address is mandatory.");
+        writeIpv6Address(ipv6.getDestinationIpv6Address(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
 }
index dee4e8fb3fbc16584966e4e6990f5650791f87fd..3402676d271091181ac90d7e899f2c1e6748d534 100644 (file)
@@ -7,12 +7,12 @@
  */
 package org.opendaylight.protocol.pcep.impl.object;
 
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
+
 import com.google.common.base.Preconditions;
 import com.google.common.primitives.UnsignedBytes;
-
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
@@ -69,8 +69,10 @@ public class PCEPErrorObjectParser extends AbstractObjectWithTlvsParser<ErrorObj
         final ErrorObject errObj = (ErrorObject) object;
         final ByteBuf body = Unpooled.buffer();
         body.writeZero(FLAGS_F_LENGTH + RESERVED);
-        body.writeByte(errObj.getType());
-        body.writeByte(errObj.getValue());
+        Preconditions.checkArgument(errObj.getType() != null, "Type is mandatory.");
+        writeUnsignedByte(errObj.getType(), body);
+        Preconditions.checkArgument(errObj.getValue() != null, "Value is mandatory.");
+        writeUnsignedByte(errObj.getValue(), body);
         serializeTlvs(errObj.getTlvs(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
index cff7277677d8525497a61692c0db72422e285da6..4117b1a3cb37c277c77b8d7a9f9c01663f08e503 100644 (file)
@@ -7,11 +7,11 @@
  */
 package org.opendaylight.protocol.pcep.impl.object;
 
-import com.google.common.base.Preconditions;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBoolean;
 
+import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.XROSubobjectRegistry;
@@ -54,9 +54,7 @@ public final class PCEPExcludeRouteObjectParser extends AbstractXROWithSubobject
         final Xro obj = (Xro) object;
         final ByteBuf body = Unpooled.buffer();
         body.writeZero(FLAGS_OFFSET);
-        if (obj.getFlags().isFail() != null) {
-            body.writeBoolean(obj.getFlags().isFail());
-        }
+        writeBoolean(obj.getFlags() != null ? obj.getFlags().isFail() : null, body);
         serializeSubobject(obj.getSubobject(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
index cbf16002a4b0d1dcd43d535dd0ba312dfee475ec..ecfb8c815ec3acc672a2b09966a8b39aaa6b4ee1 100644 (file)
@@ -7,12 +7,12 @@
  */
 package org.opendaylight.protocol.pcep.impl.object;
 
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
+
 import com.google.common.base.Preconditions;
 import com.google.common.primitives.UnsignedBytes;
-
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
@@ -55,10 +55,10 @@ public class PCEPGlobalConstraintsObjectParser extends AbstractObjectWithTlvsPar
         Preconditions.checkArgument(object instanceof Gc, "Wrong instance of PCEPObject. Passed %s. Needed GcObject.", object.getClass());
         final Gc specObj = (Gc) object;
         final ByteBuf body = Unpooled.buffer();
-        body.writeByte(specObj.getMaxHop());
-        body.writeByte(specObj.getMaxUtilization());
-        body.writeByte(specObj.getMinUtilization());
-        body.writeByte(specObj.getOverBookingFactor());
+        writeUnsignedByte(specObj.getMaxHop(), body);
+        writeUnsignedByte(specObj.getMaxUtilization(), body);
+        writeUnsignedByte(specObj.getMinUtilization(), body);
+        writeUnsignedByte(specObj.getOverBookingFactor(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
 }
index 5d3bf27b3782da5ae24f3aae483ee0f705e9ad88..e46475ba37960b057e86ddbfea9481cc7b28c088 100644 (file)
@@ -7,12 +7,13 @@
  */
 package org.opendaylight.protocol.pcep.impl.object;
 
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
+
 import com.google.common.base.Preconditions;
 import com.google.common.primitives.UnsignedBytes;
-
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
@@ -64,8 +65,8 @@ public class PCEPLoadBalancingObjectParser extends AbstractObjectWithTlvsParser<
         final LoadBalancing specObj = (LoadBalancing) object;
         final ByteBuf body = Unpooled.buffer(SIZE);
         body.writeZero(RESERVED + FLAGS_F_LENGTH);
-        body.writeByte(specObj.getMaxLsp());
-        body.writeBytes(specObj.getMinBandwidth().getValue());
+        writeUnsignedByte(specObj.getMaxLsp(), body);
+        writeFloat32(specObj.getMinBandwidth(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
 }
index 184c13eb973a05545e636a702de378f0cb3f32e1..de2ee0dd37669c9bb84d0bdbc3d4f87798d2f4e4 100644 (file)
@@ -7,14 +7,15 @@
  */
 package org.opendaylight.protocol.pcep.impl.object;
 
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBitSet;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
+
 import com.google.common.base.Preconditions;
 import com.google.common.primitives.UnsignedBytes;
-
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import java.util.BitSet;
-
 import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
@@ -80,36 +81,16 @@ public class PCEPLspaObjectParser extends AbstractObjectWithTlvsParser<TlvsBuild
         Preconditions.checkArgument(object instanceof Lspa, "Wrong instance of PCEPObject. Passed %s. Needed LspaObject.", object.getClass());
         final Lspa lspaObj = (Lspa) object;
         final ByteBuf body = Unpooled.buffer();
-        if (lspaObj.getExcludeAny() != null) {
-            body.writeInt(lspaObj.getExcludeAny().getValue().intValue());
-        } else {
-            body.writeZero(Integer.SIZE / Byte.SIZE);
-        }
-        if (lspaObj.getIncludeAny() != null) {
-            body.writeInt(lspaObj.getIncludeAny().getValue().intValue());
-        } else {
-            body.writeZero(Integer.SIZE / Byte.SIZE);
-        }
-        if (lspaObj.getIncludeAll() != null) {
-            body.writeInt(lspaObj.getIncludeAll().getValue().intValue());
-        } else {
-            body.writeZero(Integer.SIZE / Byte.SIZE);
-        }
-        if (lspaObj.getSetupPriority() != null) {
-            body.writeByte(lspaObj.getSetupPriority());
-        } else {
-            body.writeZero(1);
-        }
-        if (lspaObj.getHoldPriority() != null) {
-            body.writeByte(lspaObj.getHoldPriority());
-        } else {
-            body.writeZero(1);
-        }
+        writeAttributeFilter(lspaObj.getExcludeAny(), body);
+        writeAttributeFilter(lspaObj.getIncludeAny(), body);
+        writeAttributeFilter(lspaObj.getIncludeAll(), body);
+        writeUnsignedByte(lspaObj.getSetupPriority(), body);
+        writeUnsignedByte(lspaObj.getHoldPriority(), body);
         final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
         if (lspaObj.isLocalProtectionDesired() != null) {
             flags.set(L_FLAG_OFFSET, lspaObj.isLocalProtectionDesired());
         }
-        body.writeBytes(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH));
+        writeBitSet(flags, FLAGS_F_LENGTH, body);
         body.writeZero(RESERVED);
         serializeTlvs(lspaObj.getTlvs(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
@@ -118,4 +99,8 @@ public class PCEPLspaObjectParser extends AbstractObjectWithTlvsParser<TlvsBuild
     public void serializeTlvs(final Tlvs tlvs, final ByteBuf body) {
         return;
     }
+
+    private void writeAttributeFilter(final AttributeFilter attributeFilter, final ByteBuf body) {
+        writeUnsignedInt(attributeFilter != null ? attributeFilter.getValue() : null, body);
+    }
 }
index 2fd343772d529b7317091e5df7c8d3a852448fda..6bbeaa3404e43e400ce5b3ec468e453cf064bf01 100644 (file)
@@ -7,14 +7,15 @@
  */
 package org.opendaylight.protocol.pcep.impl.object;
 
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBitSet;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
+
 import com.google.common.base.Preconditions;
 import com.google.common.primitives.UnsignedBytes;
-
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import java.util.BitSet;
-
 import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
@@ -91,9 +92,10 @@ public class PCEPMetricObjectParser extends AbstractObjectWithTlvsParser<MetricB
         if (mObj.isBound() != null) {
             flags.set(B_FLAG_OFFSET, mObj.isBound());
         }
-        body.writeBytes(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH));
-        body.writeByte(mObj.getMetricType());
-        body.writeBytes(mObj.getValue().getValue());
+        writeBitSet(flags, FLAGS_F_LENGTH, body);
+        Preconditions.checkArgument(mObj.getMetricType() != null, "MetricType is mandatory.");
+        writeUnsignedByte(mObj.getMetricType(), body);
+        writeFloat32(mObj.getValue(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
 }
index 72c879b90702e613300adc2cbddeadeff4e81c24..a6c02c523ee068500e41fdfbab01a647e78ae495 100644 (file)
@@ -7,14 +7,14 @@
  */
 package org.opendaylight.protocol.pcep.impl.object;
 
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBitSet;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
+
 import com.google.common.base.Preconditions;
 import com.google.common.primitives.UnsignedBytes;
-
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import java.util.BitSet;
-
 import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
@@ -81,12 +81,13 @@ public class PCEPNoPathObjectParser extends AbstractObjectWithTlvsParser<NoPathB
         Preconditions.checkArgument(object instanceof NoPath, "Wrong instance of PCEPObject. Passed %s. Needed NoPathObject.", object.getClass());
         final NoPath nPObj = (NoPath) object;
         final ByteBuf body = Unpooled.buffer();
-        body.writeByte(nPObj.getNatureOfIssue());
+        Preconditions.checkArgument(nPObj.getNatureOfIssue() != null, "NatureOfIssue is mandatory.");
+        writeUnsignedByte(nPObj.getNatureOfIssue(), body);
         final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
         if (nPObj.isUnsatisfiedConstraints() != null) {
             flags.set(C_FLAG_OFFSET, nPObj.isUnsatisfiedConstraints());
         }
-        body.writeBytes(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH));
+        writeBitSet(flags, FLAGS_F_LENGTH, body);
         body.writeZero(RESERVED_F_LENGTH);
         serializeTlvs(nPObj.getTlvs(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
index 51e03d26588e94d2deacf70660dc0572ba63ef2e..af5c5063a22266f0748021bae695cd85365850bc 100644 (file)
@@ -7,12 +7,12 @@
  */
 package org.opendaylight.protocol.pcep.impl.object;
 
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
+
 import com.google.common.base.Preconditions;
 import com.google.common.primitives.UnsignedBytes;
-
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
@@ -70,8 +70,10 @@ public class PCEPNotificationObjectParser extends AbstractObjectWithTlvsParser<C
         final CNotification notObj = (CNotification) object;
         final ByteBuf body = Unpooled.buffer();
         body.writeZero(NT_F_OFFSET);
-        body.writeByte(notObj.getType());
-        body.writeByte(notObj.getValue());
+        Preconditions.checkArgument(notObj.getType() != null, "Type is mandatory.");
+        writeUnsignedByte(notObj.getType(), body);
+        Preconditions.checkArgument(notObj.getValue() != null, "Value is mandatory.");
+        writeUnsignedByte(notObj.getValue(), body);
         serializeTlvs(notObj.getTlvs(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
index 1dffc2ed7c089ad26bd2761551e44e72e654dee3..b494a4a7157866a49f76d09578367ed2c9390072 100644 (file)
@@ -7,11 +7,11 @@
  */
 package org.opendaylight.protocol.pcep.impl.object;
 
-import com.google.common.base.Preconditions;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
 
+import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
@@ -52,7 +52,8 @@ public class PCEPObjectiveFunctionObjectParser extends AbstractObjectWithTlvsPar
         Preconditions.checkArgument(object instanceof Of, "Wrong instance of PCEPObject. Passed %s. Needed OfObject.", object.getClass());
         final Of specObj = (Of) object;
         final ByteBuf body = Unpooled.buffer();
-        body.writeShort(specObj.getCode().getValue().shortValue());
+        Preconditions.checkArgument(specObj.getCode() != null, "Code is mandatory");
+        writeUnsignedShort(specObj.getCode().getValue(), body);
         body.writeZero(RESERVED);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
index fde8aa13cc6ed6b885c1b5c04c687812a4df5c0e..7d2dc4de2e20e861878abb104c4e958519638f3b 100644 (file)
@@ -8,6 +8,8 @@
 
 package org.opendaylight.protocol.pcep.impl.object;
 
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
+
 import com.google.common.base.Preconditions;
 import com.google.common.primitives.UnsignedBytes;
 import io.netty.buffer.ByteBuf;
@@ -102,10 +104,11 @@ public class PCEPOpenObjectParser extends AbstractObjectWithTlvsParser<TlvsBuild
         Preconditions.checkArgument(object instanceof Open, "Wrong instance of PCEPObject. Passed %s. Needed OpenObject.", object.getClass());
         final Open open = (Open) object;
         final ByteBuf body = Unpooled.buffer();
-        body.writeByte(PCEP_VERSION << (Byte.SIZE - VERSION_SF_LENGTH));
-        body.writeByte(open.getKeepalive());
-        body.writeByte(open.getDeadTimer());
-        body.writeByte(open.getSessionId());
+        writeUnsignedByte((short) (PCEP_VERSION << (Byte.SIZE - VERSION_SF_LENGTH)), body);
+        writeUnsignedByte(open.getKeepalive(), body);
+        writeUnsignedByte(open.getDeadTimer(), body);
+        Preconditions.checkArgument(open.getSessionId() != null, "SessionId is mandatory.");
+        writeUnsignedByte(open.getSessionId(), body);
         serializeTlvs(open.getTlvs(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
index 8a31586adc44058c2cceb0a11e9aceb09bf5ceec..aee1b1f7af2e3a30ea255aecccf8b299a0fd8c28 100644 (file)
@@ -8,14 +8,14 @@
 
 package org.opendaylight.protocol.pcep.impl.object;
 
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBitSet;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
+
 import com.google.common.base.Preconditions;
 import com.google.common.primitives.UnsignedBytes;
-
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import java.util.BitSet;
-
 import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
@@ -169,8 +169,9 @@ public class PCEPRequestParameterObjectParser extends AbstractObjectWithTlvsPars
             final byte[] p = { 0, 0, 0, UnsignedBytes.checkedCast(rpObj.getPriority().shortValue())};
             flags.or(ByteArray.bytesToBitSet(p));
         }
-        body.writeBytes(ByteArray.bitSetToBytes(flags, FLAGS_PRI_MF_LENGTH));
-        body.writeInt(rpObj.getRequestId().getValue().intValue());
+        writeBitSet(flags, FLAGS_PRI_MF_LENGTH, body);
+        Preconditions.checkArgument(rpObj.getRequestId() != null, "RequestId is mandatory");
+        writeUnsignedInt(rpObj.getRequestId().getValue(), body);
         serializeTlvs(rpObj.getTlvs(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
index 16f26554e969f8dee03cf1eea17ee0dff60bcd3c..afc85beab26dc72d224f5939e4f4553b0c299cd4 100644 (file)
@@ -7,15 +7,15 @@
  */
 package org.opendaylight.protocol.pcep.impl.object;
 
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBitSet;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
+
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
-
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import java.util.BitSet;
 import java.util.List;
-
 import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
@@ -107,12 +107,12 @@ public class PCEPSvecObjectParser extends AbstractObjectWithTlvsParser<SvecBuild
         if (svecObj.isSrlgDiverse() != null) {
             flags.set(S_FLAG_OFFSET, svecObj.isSrlgDiverse());
         }
-        body.writeBytes(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH));
+        writeBitSet(flags, FLAGS_F_LENGTH, body);
 
         final List<RequestId> requestIDs = svecObj.getRequestsIds();
         assert !(requestIDs.isEmpty()) : "Empty Svec Object - no request ids.";
-        for (int i = 0; i < requestIDs.size(); i++) {
-            body.writeInt(requestIDs.get(i).getValue().intValue());
+        for(final RequestId requestId : requestIDs) {
+            writeUnsignedInt(requestId.getValue(), body);
         }
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
index cbf7042543e7517a7835a601ed4d1867868ea8fa..a688813c65878745b62524c8be3230f0edc52e3b 100644 (file)
@@ -7,11 +7,11 @@
  */
 package org.opendaylight.protocol.pcep.impl.subobject;
 
-import com.google.common.base.Preconditions;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeShort;
 
+import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectUtil;
@@ -48,7 +48,10 @@ public class EROAsNumberSubobjectParser implements EROSubobjectParser, EROSubobj
     @Override
     public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
         Preconditions.checkArgument(subobject.getSubobjectType() instanceof AsNumberCase, "Unknown subobject instance. Passed %s. Needed AsNumberCase.", subobject.getSubobjectType().getClass());
-        final AsNumberSubobject s = ((AsNumberCase) subobject.getSubobjectType()).getAsNumber();
-        EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), Unpooled.copyShort(s.getAsNumber().getValue().shortValue()), buffer);
+        final AsNumberSubobject asNumber = ((AsNumberCase) subobject.getSubobjectType()).getAsNumber();
+        final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
+        Preconditions.checkArgument(asNumber.getAsNumber() != null, "AsNumber is mandatory.");
+        writeShort(asNumber.getAsNumber().getValue().shortValue(), body);
+        EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
     }
 }
index 45f2bfe3a12db02637f63c33f3c3f532cdeaf07c..74b9b908eb957d8c075813ea0c511d117024576c 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.impl.subobject;
 
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Prefix;
+
 import com.google.common.base.Preconditions;
 import com.google.common.primitives.UnsignedBytes;
 import io.netty.buffer.ByteBuf;
@@ -63,7 +65,8 @@ public class EROIpv4PrefixSubobjectParser implements EROSubobjectParser, EROSubo
             new EROIpv6PrefixSubobjectParser().serializeSubobject(subobject, buffer);
         } else {
             final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH);
-            body.writeBytes(Ipv4Util.bytesForPrefix(prefix.getIpv4Prefix()));
+            Preconditions.checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
+            writeIpv4Prefix(prefix.getIpv4Prefix(), body);
             body.writeZero(RESERVED);
             EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
         }
index 5ea1309fb1d372875a13dd085580d91b2f43e424..8c65b46d38d01f715b4947608f369328b8c4031e 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.impl.subobject;
 
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Prefix;
+
 import com.google.common.base.Preconditions;
 import com.google.common.primitives.UnsignedBytes;
 import io.netty.buffer.ByteBuf;
@@ -59,7 +61,8 @@ public class EROIpv6PrefixSubobjectParser implements EROSubobjectParser, EROSubo
         final IpPrefixSubobject specObj = ((IpPrefixCase) subobject.getSubobjectType()).getIpPrefix();
         final IpPrefix prefix = specObj.getIpPrefix();
         final ByteBuf body = Unpooled.buffer();
-        body.writeBytes(Ipv6Util.bytesForPrefix(prefix.getIpv6Prefix()));
+        Preconditions.checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory.");
+        writeIpv6Prefix(prefix.getIpv6Prefix(), body);
         body.writeZero(RESERVED);
         EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
     }
index 0d131d2928a7244f468a40572b3d7f967d14a92d..dabae21c1a4f37b397b013fa128a599d07e628b1 100644 (file)
@@ -7,11 +7,11 @@
  */
 package org.opendaylight.protocol.pcep.impl.subobject;
 
-import com.google.common.base.Preconditions;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
 
+import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectUtil;
@@ -59,7 +59,9 @@ public class EROPathKey128SubobjectParser implements EROSubobjectParser, EROSubo
         Preconditions.checkArgument(subobject.getSubobjectType() instanceof PathKeyCase, "Unknown subobject instance. Passed %s. Needed PathKey.", subobject.getSubobjectType().getClass());
         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.subobject.subobject.type.path.key._case.PathKey pk = ((PathKeyCase) subobject.getSubobjectType()).getPathKey();
         final ByteBuf body = Unpooled.buffer();
-        body.writeShort(pk.getPathKey().getValue().shortValue());
+        Preconditions.checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
+        writeUnsignedShort(pk.getPathKey().getValue(), body);
+        Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory.");
         body.writeBytes(pk.getPceId().getBinary());
         EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
     }
index af0433766debe9a8d1e46386b8fd55e73c53078d..9ca00216738364c957f920842831def7f2d78b3e 100644 (file)
@@ -7,11 +7,11 @@
  */
 package org.opendaylight.protocol.pcep.impl.subobject;
 
-import com.google.common.base.Preconditions;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
 
+import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectUtil;
@@ -60,8 +60,10 @@ public class EROPathKey32SubobjectParser implements EROSubobjectParser, EROSubob
         Preconditions.checkArgument(subobject.getSubobjectType() instanceof PathKeyCase, "Unknown subobject instance. Passed %s. Needed PathKey.", subobject.getSubobjectType().getClass());
         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.subobject.subobject.type.path.key._case.PathKey pk = ((PathKeyCase) subobject.getSubobjectType()).getPathKey();
         final ByteBuf body = Unpooled.buffer();
-        body.writeShort(pk.getPathKey().getValue().shortValue());
+        Preconditions.checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
+        writeUnsignedShort(pk.getPathKey().getValue(), body);
+        Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory.");
         body.writeBytes(pk.getPceId().getBinary());
-        EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);;
+        EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
     }
 }
index cf44fbd06e0afdcf19e90ed24cbe1f15ac7c08f7..a7656df90d86900a4d1ad179c2f65f1e88f32589 100644 (file)
@@ -7,11 +7,11 @@
  */
 package org.opendaylight.protocol.pcep.impl.subobject;
 
-import com.google.common.base.Preconditions;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 
+import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectUtil;
@@ -57,8 +57,10 @@ public class EROUnnumberedInterfaceSubobjectParser implements EROSubobjectParser
         final UnnumberedSubobject specObj = ((UnnumberedCase) subobject.getSubobjectType()).getUnnumbered();
         final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
         body.writeZero(RESERVED);
-        body.writeInt(specObj.getRouterId().intValue());
-        body.writeInt(specObj.getInterfaceId().intValue());
+        Preconditions.checkArgument(specObj.getRouterId() != null, "RouterId is mandatory.");
+        writeUnsignedInt(specObj.getRouterId(), body);
+        Preconditions.checkArgument(specObj.getInterfaceId() != null, "InterfaceId is mandatory");
+        writeUnsignedInt(specObj.getInterfaceId(), body);
         EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
     }
 }
index 79680e8f5bb4dbc9be15c01cd7abd9dfa5bf9bd9..63daa41ce3f4a4c0a12c88b3d0ccfda1bcb014b3 100644 (file)
@@ -8,10 +8,8 @@
 package org.opendaylight.protocol.pcep.impl.subobject;
 
 import com.google.common.base.Preconditions;
-
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import org.opendaylight.protocol.pcep.spi.LabelParser;
 import org.opendaylight.protocol.pcep.spi.LabelSerializer;
 import org.opendaylight.protocol.pcep.spi.LabelUtil;
@@ -20,6 +18,7 @@ import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedLabelCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedLabelCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.generalized.label._case.GeneralizedLabel;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.generalized.label._case.GeneralizedLabelBuilder;
 
 /**
@@ -39,7 +38,9 @@ public class GeneralizedLabelParser implements LabelParser, LabelSerializer {
     @Override
     public void serializeLabel(final boolean unidirectional, final boolean global, final LabelType subobject, final ByteBuf buffer) {
         Preconditions.checkArgument(subobject instanceof GeneralizedLabelCase, "Unknown Label Subobject instance. Passed {}. Needed GeneralizedLabelCase.", subobject.getClass());
-        final ByteBuf body = Unpooled.wrappedBuffer(((GeneralizedLabelCase) subobject).getGeneralizedLabel().getGeneralizedLabel());
+        final GeneralizedLabel gl = ((GeneralizedLabelCase) subobject).getGeneralizedLabel();
+        Preconditions.checkArgument(gl != null, "GeneralizedLabel is mandatory.");
+        final ByteBuf body = Unpooled.wrappedBuffer(gl.getGeneralizedLabel());
         LabelUtil.formatLabel(CTYPE, unidirectional, global, body, buffer);
     }
 }
index fbf4870ce9d1d99e14d4a7db854464e567e5fc98..596eae823f6ce93983bd8e7a9cfb465ad1e97f3e 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.protocol.pcep.impl.subobject;
 
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBitSet;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Prefix;
+
 import com.google.common.base.Preconditions;
 import com.google.common.primitives.UnsignedBytes;
 import io.netty.buffer.ByteBuf;
@@ -78,8 +81,9 @@ public class RROIpv4PrefixSubobjectParser implements RROSubobjectParser, RROSubo
                 flags.set(LPIU_F_OFFSET, subobject.isProtectionInUse());
             }
             final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH);
-            body.writeBytes(Ipv4Util.bytesForPrefix(prefix.getIpv4Prefix()));
-            body.writeBytes(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH));
+            Preconditions.checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
+            writeIpv4Prefix(prefix.getIpv4Prefix(), body);
+            writeBitSet(flags, FLAGS_F_LENGTH, body);
             RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
         }
     }
index 895cd2c05c79f9031a84709b0194ca0203b7137c..cf2314c15c0f99db61cd7b5b558f332f9ee962bd 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.protocol.pcep.impl.subobject;
 
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBitSet;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Prefix;
+
 import com.google.common.base.Preconditions;
 import com.google.common.primitives.UnsignedBytes;
 import io.netty.buffer.ByteBuf;
@@ -74,8 +77,9 @@ public class RROIpv6PrefixSubobjectParser implements RROSubobjectParser, RROSubo
             flags.set(LPIU_F_OFFSET, subobject.isProtectionInUse());
         }
         final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
-        body.writeBytes(Ipv6Util.bytesForPrefix(prefix.getIpv6Prefix()));
-        body.writeBytes(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH));
+        Preconditions.checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory.");
+        writeIpv6Prefix(prefix.getIpv6Prefix(), body);
+        writeBitSet(flags, FLAGS_F_LENGTH, body);
         RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
     }
 }
index 558f12eada3af24865b0b1870a4aa85259f72a59..30c94810aea1d6db87798bcfa6aeb1ffa1b108aa 100644 (file)
@@ -7,11 +7,11 @@
  */
 package org.opendaylight.protocol.pcep.impl.subobject;
 
-import com.google.common.base.Preconditions;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
 
+import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
@@ -60,7 +60,9 @@ public class RROPathKey128SubobjectParser implements RROSubobjectParser, RROSubo
         final PathKeyCase pkcase = (PathKeyCase) subobject.getSubobjectType();
         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.subobject.subobject.type.path.key._case.PathKey pk = pkcase.getPathKey();
         final ByteBuf body = Unpooled.buffer();
-        body.writeShort(pk.getPathKey().getValue().shortValue());
+        Preconditions.checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
+        writeUnsignedShort(pk.getPathKey().getValue(), body);
+        Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory.");
         body.writeBytes(pk.getPceId().getBinary());
         RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
     }
index 0f2fa992b4ddf12f6d720efd80c483f3138f0e4e..cf642025fdc991e99d03fcfa9c25fb6504163a16 100644 (file)
@@ -7,11 +7,11 @@
  */
 package org.opendaylight.protocol.pcep.impl.subobject;
 
-import com.google.common.base.Preconditions;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
 
+import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
@@ -60,7 +60,9 @@ public class RROPathKey32SubobjectParser implements RROSubobjectParser, RROSubob
         final PathKeyCase pkcase = (PathKeyCase) subobject.getSubobjectType();
         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.subobject.subobject.type.path.key._case.PathKey pk = pkcase.getPathKey();
         final ByteBuf body = Unpooled.buffer();
-        body.writeShort(pk.getPathKey().getValue().shortValue());
+        Preconditions.checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
+        writeUnsignedShort(pk.getPathKey().getValue(), body);
+        Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory.");
         body.writeBytes(pk.getPceId().getBinary());
         RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
     }
index 2bd1b7e6afab3d63901683a905d70f055cdfd4ef..a7dcdf61171a41f20c567651c716334976879c56 100644 (file)
@@ -7,13 +7,13 @@
  */
 package org.opendaylight.protocol.pcep.impl.subobject;
 
-import com.google.common.base.Preconditions;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBitSet;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 
+import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import java.util.BitSet;
-
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
@@ -72,10 +72,12 @@ public class RROUnnumberedInterfaceSubobjectParser implements RROSubobjectParser
             flags.set(LPIU_F_OFFSET, subobject.isProtectionInUse());
         }
         final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
-        body.writeBytes(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH));
+        writeBitSet(flags, FLAGS_F_LENGTH, body);
         body.writeZero(RESERVED);
-        body.writeInt(specObj.getRouterId().intValue());
-        body.writeInt(specObj.getInterfaceId().intValue());
+        Preconditions.checkArgument(specObj.getRouterId() != null, "RouterId is mandatory.");
+        writeUnsignedInt(specObj.getRouterId(), body);
+        Preconditions.checkArgument(specObj.getInterfaceId() != null, "InterfaceId is mandatory.");
+        writeUnsignedInt(specObj.getInterfaceId(), body);
         RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
     }
 }
index 7ced7b3406a9cd649373989bd04b11ffc9760fae..ec732600e335f59b2cca3b73675567f276d195c8 100644 (file)
@@ -7,11 +7,11 @@
  */
 package org.opendaylight.protocol.pcep.impl.subobject;
 
-import com.google.common.base.Preconditions;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 
+import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import org.opendaylight.protocol.pcep.spi.LabelParser;
 import org.opendaylight.protocol.pcep.spi.LabelSerializer;
 import org.opendaylight.protocol.pcep.spi.LabelUtil;
@@ -19,6 +19,7 @@ import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.Type1LabelCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.Type1LabelCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.type1.label._case.Type1Label;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.type1.label._case.Type1LabelBuilder;
 
 /**
@@ -43,7 +44,10 @@ public class Type1LabelParser implements LabelParser, LabelSerializer {
     @Override
     public void serializeLabel(final boolean unidirectional, final boolean global, final LabelType subobject, final ByteBuf buffer) {
         Preconditions.checkArgument(subobject instanceof Type1LabelCase, "Unknown Label Subobject instance. Passed {}. Needed Type1LabelCase.", subobject.getClass());
-        LabelUtil.formatLabel(CTYPE, unidirectional, global, Unpooled.copyInt(
-                ((Type1LabelCase) subobject).getType1Label().getType1Label().intValue()), buffer);
+        final ByteBuf body = Unpooled.buffer(LABEL_LENGTH);
+        final Type1Label type1Label = ((Type1LabelCase) subobject).getType1Label();
+        Preconditions.checkArgument(type1Label != null, "Type1Label is mandatory.");
+        writeUnsignedInt(type1Label.getType1Label(), body);
+        LabelUtil.formatLabel(CTYPE, unidirectional, global, body, buffer);
     }
 }
index c12815efd394a9a35a33433a68b2af6646945e16..6f636a0bf4f863709c6692755ec9d141b5ca155c 100644 (file)
@@ -7,11 +7,11 @@
  */
 package org.opendaylight.protocol.pcep.impl.subobject;
 
-import com.google.common.base.Preconditions;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 
+import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import org.opendaylight.protocol.pcep.spi.LabelParser;
 import org.opendaylight.protocol.pcep.spi.LabelSerializer;
 import org.opendaylight.protocol.pcep.spi.LabelUtil;
@@ -54,9 +54,12 @@ public class WavebandSwitchingLabelParser implements LabelParser, LabelSerialize
         Preconditions.checkArgument(subobject instanceof WavebandSwitchingLabelCase, "Unknown Label Subobject instance. Passed {}. Needed WavebandSwitchingLabelCase.", subobject.getClass());
         final WavebandSwitchingLabel obj = ((WavebandSwitchingLabelCase) subobject).getWavebandSwitchingLabel();
         final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
-        body.writeInt(obj.getWavebandId().intValue());
-        body.writeInt(obj.getStartLabel().intValue());
-        body.writeInt(obj.getEndLabel().intValue());
+        Preconditions.checkArgument(obj.getWavebandId() != null, "WavebandId is mandatory.");
+        writeUnsignedInt(obj.getWavebandId(), body);
+        Preconditions.checkArgument(obj.getStartLabel() != null, "StartLabel is mandatory.");
+        writeUnsignedInt(obj.getStartLabel(), body);
+        Preconditions.checkArgument(obj.getEndLabel() != null, "EndLabel is mandatory.");
+        writeUnsignedInt(obj.getEndLabel(), body);
         LabelUtil.formatLabel(CTYPE, unidirectional, global, body, buffer);
     }
 }
index a706adcaf2440ab0fb058628e779899228c01820..4600934b61cf1960192f05208ea8f1fb5fddbc0b 100644 (file)
@@ -7,11 +7,11 @@
  */
 package org.opendaylight.protocol.pcep.impl.subobject;
 
-import com.google.common.base.Preconditions;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeShort;
 
+import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
@@ -48,7 +48,10 @@ public class XROAsNumberSubobjectParser implements XROSubobjectParser, XROSubobj
     @Override
     public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
         Preconditions.checkArgument(subobject.getSubobjectType() instanceof AsNumberCase, "Unknown subobject instance. Passed %s. Needed AsNumberCase.", subobject.getSubobjectType().getClass());
-        final AsNumberSubobject s = ((AsNumberCase) subobject.getSubobjectType()).getAsNumber();
-        XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), Unpooled.copyShort(s.getAsNumber().getValue().shortValue()), buffer);
+        final AsNumberSubobject asNumber = ((AsNumberCase) subobject.getSubobjectType()).getAsNumber();
+        final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
+        Preconditions.checkArgument(asNumber.getAsNumber() != null, "AsNumber is mandatory.");
+        writeShort(asNumber.getAsNumber().getValue().shortValue(), body);
+        XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
     }
 }
index c94cf5fb9ce30eb62711b93ea94bcb48a600f31b..14c644b3894fde26ea32a9074b7186e394257596 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.protocol.pcep.impl.subobject;
 
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Prefix;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
+
 import com.google.common.base.Preconditions;
 import com.google.common.primitives.UnsignedBytes;
 import io.netty.buffer.ByteBuf;
@@ -66,8 +69,10 @@ public class XROIpv4PrefixSubobjectParser implements XROSubobjectParser, XROSubo
             new XROIpv6PrefixSubobjectParser().serializeSubobject(subobject, buffer);
         } else {
             final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH);
-            body.writeBytes(Ipv4Util.bytesForPrefix(prefix.getIpv4Prefix()));
-            body.writeByte(subobject.getAttribute().getIntValue());
+            Preconditions.checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
+            writeIpv4Prefix(prefix.getIpv4Prefix(), body);
+            Preconditions.checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
+            writeUnsignedByte((short) subobject.getAttribute().getIntValue(), body);
             XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
         }
     }
index 5b1aa120b374fc553456fbb638959ffb40b09fc8..2908cdb0b48d88e0ae55175e43447eba62b289c4 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.protocol.pcep.impl.subobject;
 
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Prefix;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
+
 import com.google.common.base.Preconditions;
 import com.google.common.primitives.UnsignedBytes;
 import io.netty.buffer.ByteBuf;
@@ -62,8 +65,10 @@ public class XROIpv6PrefixSubobjectParser implements XROSubobjectParser, XROSubo
         final IpPrefixSubobject specObj = ((IpPrefixCase) subobject.getSubobjectType()).getIpPrefix();
         final IpPrefix prefix = specObj.getIpPrefix();
         final ByteBuf body = Unpooled.buffer(CONTENT6_LENGTH);
-        body.writeBytes(Ipv6Util.bytesForPrefix(prefix.getIpv6Prefix()));
-        body.writeByte(subobject.getAttribute().getIntValue());
+        Preconditions.checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory.");
+        writeIpv6Prefix(prefix.getIpv6Prefix(), body);
+        Preconditions.checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
+        writeUnsignedByte((short) subobject.getAttribute().getIntValue(), body);
         XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
     }
 }
index 1af2c28c0a06f9d6cee6e10f437293a8ace3798d..c902640d97491327c3fe8bcbe4dae6ad8bcc2fd4 100644 (file)
@@ -7,11 +7,11 @@
  */
 package org.opendaylight.protocol.pcep.impl.subobject;
 
-import com.google.common.base.Preconditions;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
 
+import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
@@ -59,7 +59,9 @@ public class XROPathKey128SubobjectParser implements XROSubobjectParser, XROSubo
         Preconditions.checkArgument(subobject.getSubobjectType() instanceof PathKeyCase, "Unknown subobject instance. Passed %s. Needed PathKey.", subobject.getSubobjectType().getClass());
         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.subobject.subobject.type.path.key._case.PathKey pk = ((PathKeyCase) subobject.getSubobjectType()).getPathKey();
         final ByteBuf body = Unpooled.buffer();
-        body.writeShort(pk.getPathKey().getValue().shortValue());
+        Preconditions.checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
+        writeUnsignedShort(pk.getPathKey().getValue(), body);
+        Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory.");
         body.writeBytes(pk.getPceId().getBinary());
         XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
     }
index 4019a00c83478e34a86b191197a7723c6068d172..2870a047c653516e1195c1d3547ee79a6d9225f2 100644 (file)
@@ -7,11 +7,11 @@
  */
 package org.opendaylight.protocol.pcep.impl.subobject;
 
-import com.google.common.base.Preconditions;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
 
+import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
@@ -59,7 +59,9 @@ public class XROPathKey32SubobjectParser implements XROSubobjectParser, XROSubob
         Preconditions.checkArgument(subobject.getSubobjectType() instanceof PathKeyCase, "Unknown subobject instance. Passed %s. Needed PathKey.", subobject.getSubobjectType().getClass());
         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.subobject.subobject.type.path.key._case.PathKey pk = ((PathKeyCase) subobject.getSubobjectType()).getPathKey();
         final ByteBuf body = Unpooled.buffer();
-        body.writeShort(pk.getPathKey().getValue().shortValue());
+        Preconditions.checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
+        writeUnsignedShort(pk.getPathKey().getValue(), body);
+        Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory.");
         body.writeBytes(pk.getPceId().getBinary());
         XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
     }
index c424fd6b57c0801c25540b2bdbea0a495576e227..9cbd321e03f9d6ffb4a92c3f3c4b1f48bcd32516 100644 (file)
@@ -7,11 +7,12 @@
  */
 package org.opendaylight.protocol.pcep.impl.subobject;
 
-import com.google.common.base.Preconditions;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 
+import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
@@ -53,8 +54,10 @@ public class XROSRLGSubobjectParser implements XROSubobjectParser, XROSubobjectS
         Preconditions.checkArgument(subobject.getSubobjectType() instanceof SrlgCase, "Unknown subobject instance. Passed %s. Needed SrlgCase.", subobject.getSubobjectType().getClass());
         final SrlgSubobject specObj = ((SrlgCase) subobject.getSubobjectType()).getSrlg();
         final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
-        body.writeInt(specObj.getSrlgId().getValue().intValue());
-        body.writeByte(subobject.getAttribute().getIntValue());
+        Preconditions.checkArgument(specObj.getSrlgId() != null, "SrlgId is mandatory.");
+        writeUnsignedInt(specObj.getSrlgId().getValue(), body);
+        Preconditions.checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
+        writeUnsignedByte((short) subobject.getAttribute().getIntValue(), body);
         XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
     }
 }
index 63f42f0e850feb794b14a928bbaf65bbaab8aab4..380d120189844197205133d4ace4c29880d7f93e 100644 (file)
@@ -7,12 +7,13 @@
  */
 package org.opendaylight.protocol.pcep.impl.subobject;
 
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
+
 import com.google.common.base.Preconditions;
 import com.google.common.primitives.UnsignedBytes;
-
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
@@ -60,9 +61,11 @@ public class XROUnnumberedInterfaceSubobjectParser implements XROSubobjectParser
         final UnnumberedSubobject specObj = ((UnnumberedCase) subobject.getSubobjectType()).getUnnumbered();
         final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
         body.writeZero(RESERVED);
-        body.writeByte(subobject.getAttribute().getIntValue());
-        body.writeInt(specObj.getRouterId().intValue());
-        body.writeInt(specObj.getInterfaceId().intValue());
+        writeUnsignedByte(subobject.getAttribute() != null ? (short) subobject.getAttribute().getIntValue() : null, body);
+        Preconditions.checkArgument(specObj.getRouterId() != null, "RouterId is mandatory.");
+        writeUnsignedInt(specObj.getRouterId(), body);
+        Preconditions.checkArgument(specObj.getInterfaceId() != null, "InterfaceId is mandatory.");
+        writeUnsignedInt(specObj.getInterfaceId(), body);
         XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
     }
 }
index 245d2c34c7a023ac186e2188680d4f4fa49a643a..512587cd42cf7f331f6b96ab48757f5af373d90b 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.impl.tlv;
 
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
+
 import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -32,7 +34,8 @@ public abstract class AbstractVendorSpecificTlvParser implements TlvParser, TlvS
         final VsTlv vsTlv = (VsTlv) tlv;
         final ByteBuf body = Unpooled.buffer();
         if (vsTlv.getEnterpriseNumber().getValue() == getEnterpriseNumber()) {
-            body.writeInt(vsTlv.getEnterpriseNumber().getValue().intValue());
+            Preconditions.checkArgument(vsTlv.getEnterpriseNumber() != null, "EnterpriseNumber is mandatory.");
+            writeUnsignedInt(vsTlv.getEnterpriseNumber().getValue(), body);
             serializeVendorPayload(vsTlv.getVendorPayload(), body);
             TlvUtil.formatTlv(TYPE, body, buffer);
         }
index ec87c54a53efb8356c5cf159e4cb59823e0103ca..721536453d96507f43fde01ae74ddaf69da848a0 100644 (file)
@@ -8,17 +8,15 @@
 package org.opendaylight.protocol.pcep.impl.tlv;
 
 import com.google.common.base.Preconditions;
-
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import java.util.BitSet;
-
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvParser;
 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
 import org.opendaylight.protocol.pcep.spi.TlvUtil;
 import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathVectorTlv.Flags;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure._case.no.path.tlvs.NoPathVector;
@@ -87,7 +85,7 @@ public class NoPathVectorTlvParser implements TlvParser, TlvSerializer {
         if (f.isPceUnavailable() != null) {
             flags.set(PCE_UNAVAILABLE, f.isPceUnavailable());
         }
-        body.writeBytes(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH));
+        ByteBufWriteUtil.writeBitSet(flags, FLAGS_F_LENGTH, body);
         TlvUtil.formatTlv(TYPE, body, buffer);
     }
 }
index 258e78adb3bdea2db1f8ced12f84428ba06ef927..e2afdffd235af306eb722aad2bd93cdf19dea5e0 100644 (file)
@@ -7,14 +7,13 @@
  */
 package org.opendaylight.protocol.pcep.impl.tlv;
 
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
+
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
-
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import java.util.List;
-
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvParser;
 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
@@ -55,7 +54,7 @@ public class OFListTlvParser implements TlvParser, TlvSerializer {
         final ByteBuf body = Unpooled.buffer();
         final List<OfId> ofCodes = oft.getCodes();
         for (OfId id : ofCodes) {
-            body.writeShort(id.getValue().shortValue());
+            writeUnsignedShort(id.getValue(), body);
         }
         TlvUtil.formatTlv(TYPE, body, buffer);
     }
index b94fc55b8d4942574465f8f632c5bda41681a2fe..26d1c019e22290e0be5b6a886bef9f05b52f2ed2 100644 (file)
@@ -7,11 +7,11 @@
  */
 package org.opendaylight.protocol.pcep.impl.tlv;
 
-import com.google.common.base.Preconditions;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 
+import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvParser;
 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
@@ -40,8 +40,8 @@ public class OrderTlvParser implements TlvParser, TlvSerializer {
         Preconditions.checkArgument(tlv != null, "OrderTlv is mandatory.");
         final Order otlv = (Order) tlv;
         final ByteBuf body = Unpooled.buffer();
-        body.writeInt(otlv.getDelete().intValue());
-        body.writeInt(otlv.getSetup().intValue());
+        writeUnsignedInt(otlv.getDelete(), body);
+        writeUnsignedInt(otlv.getSetup(), body);
         TlvUtil.formatTlv(TYPE, body, buffer);
     }
 }
index 9701d8218085ea2777eca98836d3f9cf008c7349..aa354340082fc7897dbb32dc045ac79261504026 100644 (file)
@@ -7,11 +7,11 @@
  */
 package org.opendaylight.protocol.pcep.impl.tlv;
 
-import com.google.common.base.Preconditions;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 
+import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvParser;
 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
@@ -38,6 +38,8 @@ public class OverloadedDurationTlvParser implements TlvParser, TlvSerializer {
     @Override
     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
         Preconditions.checkArgument(tlv != null, "OverloadedTlv is mandatory.");
-        TlvUtil.formatTlv(TYPE, Unpooled.copyInt(((OverloadDuration) tlv).getDuration().intValue()), buffer);
+        final ByteBuf body = Unpooled.buffer();
+        writeUnsignedInt(((OverloadDuration) tlv).getDuration(), body);
+        TlvUtil.formatTlv(TYPE, body, buffer);
     }
 }
index 2033c29eea5d44ede0771ee5062ae8e07868ecb1..7523db5cec0abd3f5114fb055531040b02d73f69 100644 (file)
@@ -7,11 +7,11 @@
  */
 package org.opendaylight.protocol.pcep.impl.tlv;
 
-import com.google.common.base.Preconditions;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 
+import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvParser;
 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
@@ -41,7 +41,8 @@ public class ReqMissingTlvParser implements TlvParser, TlvSerializer {
         Preconditions.checkArgument(tlv != null, "ReqMissingTlv is mandatory.");
         final ReqMissing req = (ReqMissing) tlv;
         final ByteBuf body = Unpooled.buffer();
-        body.writeInt(req.getRequestId().getValue().intValue());
+        Preconditions.checkArgument(req.getRequestId() != null, "RequestId is mandatory.");
+        writeUnsignedInt(req.getRequestId().getValue(), body);
         TlvUtil.formatTlv(TYPE, body, buffer);
     }
 }
index a88d6b256fb321d24911c4c34ac1de61b5fa8b68..1f3790775cec27a142a6e323583b256eee9f3349 100644 (file)
@@ -138,7 +138,7 @@ public class PCEPObjectParserTest {
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
         ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
-        assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+        assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
     }
 
     @Test
@@ -154,7 +154,7 @@ public class PCEPObjectParserTest {
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
         ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
-        assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+        assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
     }
 
     @Test
@@ -171,7 +171,7 @@ public class PCEPObjectParserTest {
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
         ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
-        assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+        assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
     }
 
     @Test
@@ -199,7 +199,7 @@ public class PCEPObjectParserTest {
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
         ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
-        assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+        assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
     }
 
     @Test
@@ -229,7 +229,7 @@ public class PCEPObjectParserTest {
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
         ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
-        assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+        assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
     }
 
     @Test
@@ -263,7 +263,7 @@ public class PCEPObjectParserTest {
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
         ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
-        assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+        assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
     }
 
     @Test
@@ -279,7 +279,7 @@ public class PCEPObjectParserTest {
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
         ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
-        assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+        assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
     }
 
     @Test
@@ -295,7 +295,7 @@ public class PCEPObjectParserTest {
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
         ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
-        assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+        assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
     }
 
     @Test
@@ -316,7 +316,7 @@ public class PCEPObjectParserTest {
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
         ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
-        assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+        assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
     }
 
     @Test
@@ -356,7 +356,7 @@ public class PCEPObjectParserTest {
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
         ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
-        assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+        assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
 
         result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject3.bin"));
 
@@ -367,7 +367,7 @@ public class PCEPObjectParserTest {
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
         buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
-        assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+        assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
     }
 
     @Test
@@ -389,7 +389,7 @@ public class PCEPObjectParserTest {
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
         ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
-        assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+        assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
 
         result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject2UpperBounds.bin"));
 
@@ -403,7 +403,7 @@ public class PCEPObjectParserTest {
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
         buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
-        assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+        assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
     }
 
     @Test
@@ -422,7 +422,7 @@ public class PCEPObjectParserTest {
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
         ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
-        assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+        assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
 
         result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPMetricObject2UpperBounds.bin"));
 
@@ -434,7 +434,7 @@ public class PCEPObjectParserTest {
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
         buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
-        assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+        assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
     }
 
     @Test
@@ -451,7 +451,7 @@ public class PCEPObjectParserTest {
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
         ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
-        assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+        assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
 
         result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNoPathObject2WithTLV.bin"));
 
@@ -466,7 +466,7 @@ public class PCEPObjectParserTest {
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
         buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
-        assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+        assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
     }
 
     @Test
@@ -495,7 +495,7 @@ public class PCEPObjectParserTest {
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
         buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
-        assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+        assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
     }
 
     @Test
@@ -540,7 +540,7 @@ public class PCEPObjectParserTest {
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
         buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
-        assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+        assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
     }
 
     @Test
@@ -559,7 +559,7 @@ public class PCEPObjectParserTest {
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
         ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
-        assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+        assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
 
         result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPSvecObject1_10ReqIDs.bin"));
 
@@ -584,7 +584,7 @@ public class PCEPObjectParserTest {
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
         buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
-        assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+        assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
     }
 
     @Test
@@ -600,7 +600,7 @@ public class PCEPObjectParserTest {
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
         ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
-        assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+        assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
     }
 
     @Test
@@ -624,7 +624,7 @@ public class PCEPObjectParserTest {
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
         ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
-        assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+        assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
     }
 
     @Test
@@ -643,7 +643,7 @@ public class PCEPObjectParserTest {
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
         ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
-        assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+        assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
     }
 
     @Test
@@ -659,7 +659,7 @@ public class PCEPObjectParserTest {
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
         ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
-        assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+        assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
     }
 
     @Test
@@ -678,7 +678,7 @@ public class PCEPObjectParserTest {
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
         ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
-        assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+        assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
     }
 
     @Test
@@ -702,4 +702,19 @@ public class PCEPObjectParserTest {
         assertTrue(object instanceof UnknownObject);
         assertEquals(PCEPErrors.UNRECOGNIZED_OBJ_CLASS, ((UnknownObject) object).getError());
     }
+
+    @Test
+    public void testLspaObjectSerializerDefence() throws IOException, PCEPDeserializerException {
+        final PCEPLspaObjectParser parser = new PCEPLspaObjectParser(this.tlvRegistry);
+        ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject1LowerBounds.bin"));
+
+        final LspaBuilder builder = new LspaBuilder();
+        builder.setProcessingRule(true);
+        builder.setIgnore(true);
+        builder.setLocalProtectionDesired(false);
+
+        final ByteBuf buf = Unpooled.buffer(result.readableBytes());
+        parser.serializeObject(builder.build(), buf);
+        assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+    }
 }