Migrate pcep-base-parser to use ByteBufUtils 31/86731/5
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 5 Jan 2020 22:50:53 +0000 (23:50 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 6 Jan 2020 15:52:50 +0000 (16:52 +0100)
Most of the parser interactions can be reformulated in terms
of ByteBufUtils, do that.

Change-Id: I73b97e2d4ff5210c45d7b938a09a57110e8f43cb
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
37 files changed:
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/AbstractVendorInformationObjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPClassTypeObjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPCloseObjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPErrorObjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPExcludeRouteObjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPGlobalConstraintsObjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPLoadBalancingObjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPLspaObjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPMetricObjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPMonitoringObjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPNoPathObjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPNotificationObjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPObjectiveFunctionObjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPOpenObjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPOverloadObjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPProcTimeObjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPRequestParameterObjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPSvecObjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/AsNumberCaseParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/EROUnnumberedInterfaceSubobjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/RROPathKey128SubobjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/RROPathKey32SubobjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/RROUnnumberedInterfaceSubobjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/Type1LabelParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/WavebandSwitchingLabelParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROIpv4PrefixSubobjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROIpv6PrefixSubobjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROPathKey128SubobjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROPathKey32SubobjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROSrlgSubobjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROUnnumberedInterfaceSubobjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/tlv/AbstractVendorInformationTlvParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/tlv/OFListTlvParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/tlv/OrderTlvParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/tlv/OverloadedDurationTlvParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/tlv/PathSetupTypeTlvParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/tlv/ReqMissingTlvParser.java

index 53a83eca77721328720439d6664cf886802884b0..7a5df2b5ef013abf1136cdfe5ed4a22235009828 100644 (file)
@@ -5,14 +5,12 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.protocol.pcep.parser.object;
 
+import static com.google.common.base.Preconditions.checkArgument;
 import static org.opendaylight.protocol.pcep.spi.VendorInformationUtil.VENDOR_INFORMATION_OBJECT_CLASS;
 import static org.opendaylight.protocol.pcep.spi.VendorInformationUtil.VENDOR_INFORMATION_OBJECT_TYPE;
-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.CommonObjectParser;
@@ -25,30 +23,29 @@ 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.rev181109.ObjectHeader;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.objects.VendorInformationObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.objects.VendorInformationObjectBuilder;
+import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
 
 public abstract class AbstractVendorInformationObjectParser extends CommonObjectParser
         implements ObjectSerializer, EnterpriseSpecificInformationParser {
-
     public AbstractVendorInformationObjectParser(final int objectClass, final int objectType) {
         super(objectClass, objectType);
     }
 
     @Override
     public final Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException {
-        Preconditions.checkArgument(buffer != null && buffer.isReadable(),
-                "Array of bytes is mandatory. Can't be null or empty.");
-        final VendorInformationObjectBuilder builder = new VendorInformationObjectBuilder();
-        builder.setEnterpriseNumber(new EnterpriseNumber(getEnterpriseNumber()));
-        builder.setEnterpriseSpecificInformation(parseEnterpriseSpecificInformation(buffer));
-        return builder.build();
+        checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+        return new VendorInformationObjectBuilder()
+                .setEnterpriseNumber(new EnterpriseNumber(getEnterpriseNumber()))
+                .setEnterpriseSpecificInformation(parseEnterpriseSpecificInformation(buffer))
+                .build();
     }
 
     @Override
     public final void serializeObject(final Object object, final ByteBuf buffer) {
-        Preconditions.checkArgument(object instanceof VendorInformationObject,
+        checkArgument(object instanceof VendorInformationObject,
                 "Wrong instance of PCEPObject. Passed %s. Needed VendorInformationObject.", object.getClass());
         final ByteBuf body = Unpooled.buffer();
-        writeUnsignedInt(getEnterpriseNumber().getValue(), body);
+        ByteBufUtils.write(body, getEnterpriseNumber().getValue());
         serializeEnterpriseSpecificInformation(((VendorInformationObject) object).getEnterpriseSpecificInformation(),
                 body);
         ObjectUtil.formatSubobject(VENDOR_INFORMATION_OBJECT_TYPE, VENDOR_INFORMATION_OBJECT_CLASS,
index ad075640f7101d80651009d847316ec6297b5b5c..d880153ae8347bdc237e64cf54c096a570c12032 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.pcep.parser.object;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -23,6 +22,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.rev181109.classtype.object.ClassType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.classtype.object.ClassTypeBuilder;
 import org.opendaylight.yangtools.yang.common.Uint8;
+import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -30,7 +30,6 @@ import org.slf4j.LoggerFactory;
  * Parser for {@link ClassType}.
  */
 public final class PCEPClassTypeObjectParser extends CommonObjectParser implements ObjectSerializer {
-
     private static final Logger LOG = LoggerFactory.getLogger(PCEPClassTypeObjectParser.class);
     private static final int CLASS = 22;
     private static final int TYPE = 1;
@@ -39,12 +38,10 @@ public final class PCEPClassTypeObjectParser extends CommonObjectParser implemen
      * Length of Class Type field in bits.
      */
     private static final int CT_F_LENGTH = 3;
-
     /**
      * Reserved field bit length.
      */
     private static final int RESERVED = 29;
-
     /**
      * Size of the object in bytes.
      */
@@ -88,7 +85,7 @@ public final class PCEPClassTypeObjectParser extends CommonObjectParser implemen
         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109
             .ClassType classType = ((ClassType) object).getClassType();
         checkArgument(classType != null, "ClassType is mandatory.");
-        writeUnsignedByte(classType.getValue(), body);
+        ByteBufUtils.write(body, classType.getValue());
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
 }
index 8eb14b53e2bec9e7df0bf61cbf1344d89407c963..dec46c3389c00a6d5d30e1961d12df1a5525f051 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.pcep.parser.object;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -70,17 +69,15 @@ public final class PCEPCloseObjectParser extends AbstractObjectWithTlvsParser<Tl
         final CClose obj = (CClose) object;
         final ByteBuf body = Unpooled.buffer();
         body.writeZero(RESERVED + FLAGS_F_LENGTH);
-        checkArgument(obj.getReason() != null, "Reason is mandatory.");
-        writeUnsignedByte(obj.getReason(), body);
+        ByteBufUtils.writeMandatory(body, obj.getReason(), "Reason");
         serializeTlvs(obj.getTlvs(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
 
     public void serializeTlvs(final Tlvs tlvs, final ByteBuf body) {
-        if (tlvs == null) {
-            return;
+        if (tlvs != null) {
+            serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
         }
-        serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
     }
 
     @Override
index 40a914c585dba787cd66216bca3b71ea3ee5baf6..51c16ae6b4120a6a69466f6806621f5dc9389a6e 100644 (file)
@@ -7,9 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.parser.object;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
+import static com.google.common.base.Preconditions.checkArgument;
 
-import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import java.util.List;
@@ -45,8 +44,7 @@ public final class PCEPErrorObjectParser extends AbstractObjectWithTlvsParser<Er
 
     @Override
     public ErrorObject parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
-        Preconditions.checkArgument(bytes != null && bytes.isReadable(),
-            "Array of bytes is mandatory. Can't be null or empty.");
+        checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
         bytes.skipBytes(FLAGS_F_LENGTH + RESERVED);
         final ErrorObjectBuilder builder = new ErrorObjectBuilder()
                 .setIgnore(header.isIgnore())
@@ -67,33 +65,28 @@ public final class PCEPErrorObjectParser extends AbstractObjectWithTlvsParser<Er
 
     @Override
     public void serializeObject(final Object object, final ByteBuf buffer) {
-        Preconditions.checkArgument(object instanceof ErrorObject,
-            "Wrong instance of PCEPObject. Passed %s. Needed ErrorObject.", object.getClass());
+        checkArgument(object instanceof ErrorObject, "Wrong instance of PCEPObject. Passed %s. Needed ErrorObject.",
+            object.getClass());
         final ErrorObject errObj = (ErrorObject) object;
         final ByteBuf body = Unpooled.buffer();
         body.writeZero(FLAGS_F_LENGTH + RESERVED);
-        Preconditions.checkArgument(errObj.getType() != null, "Type is mandatory.");
-        writeUnsignedByte(errObj.getType(), body);
-        Preconditions.checkArgument(errObj.getValue() != null, "Value is mandatory.");
-        writeUnsignedByte(errObj.getValue(), body);
+        ByteBufUtils.writeMandatory(body, errObj.getType(), "Type");
+        ByteBufUtils.writeMandatory(body, errObj.getValue(), "Value");
         serializeTlvs(errObj.getTlvs(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
 
     public void serializeTlvs(final Tlvs tlvs, final ByteBuf body) {
-        if (tlvs == null) {
-            return;
+        if (tlvs != null) {
+            if (tlvs.getReqMissing() != null) {
+                serializeTlv(tlvs.getReqMissing(), body);
+            }
+            serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
         }
-        if (tlvs.getReqMissing() != null) {
-            serializeTlv(tlvs.getReqMissing(), body);
-        }
-        serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
     }
 
     @Override
-    protected void addVendorInformationTlvs(
-        final ErrorObjectBuilder builder,
-        final List<VendorInformationTlv> tlvs) {
+    protected void addVendorInformationTlvs(final ErrorObjectBuilder builder, final List<VendorInformationTlv> tlvs) {
         if (!tlvs.isEmpty()) {
             builder.setTlvs(new TlvsBuilder(builder.getTlvs()).setVendorInformationTlv(tlvs).build());
         }
index f2c04f71efa2371e684c43b0de90b043e45b6662..b93bb87cf0c5ea8c2ec4d6b4cee46920de869721 100644 (file)
@@ -7,9 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.parser.object;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBoolean;
+import static com.google.common.base.Preconditions.checkArgument;
 
-import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
@@ -25,7 +24,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
  * Parser for {@link Xro}.
  */
 public final class PCEPExcludeRouteObjectParser extends AbstractXROWithSubobjectsParser {
-
     private static final int CLASS = 17;
     private static final int TYPE = 1;
     private static final int FLAGS_OFFSET = 3;
@@ -36,25 +34,25 @@ public final class PCEPExcludeRouteObjectParser extends AbstractXROWithSubobject
 
     @Override
     public Xro parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
-        Preconditions.checkArgument(bytes != null && bytes.isReadable(),
-            "Array of bytes is mandatory. Can't be null or empty.");
+        checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
         bytes.skipBytes(FLAGS_OFFSET);
-        final XroBuilder builder = new XroBuilder()
+        return new XroBuilder()
                 .setIgnore(header.isIgnore())
                 .setProcessingRule(header.isProcessingRule())
                 .setFlags(new Flags(bytes.readBoolean()))
-                .setSubobject(parseSubobjects(bytes.slice()));
-        return builder.build();
+                .setSubobject(parseSubobjects(bytes.slice()))
+                .build();
     }
 
     @Override
     public void serializeObject(final Object object, final ByteBuf buffer) {
-        Preconditions.checkArgument(object instanceof Xro,
-            "Wrong instance of PCEPObject. Passed %s. Needed XroObject.", object.getClass());
+        checkArgument(object instanceof Xro, "Wrong instance of PCEPObject. Passed %s. Needed XroObject.",
+            object.getClass());
         final Xro obj = (Xro) object;
         final ByteBuf body = Unpooled.buffer();
         body.writeZero(FLAGS_OFFSET);
-        writeBoolean(obj.getFlags() != null ? obj.getFlags().isFail() : null, body);
+        final Flags flags = obj.getFlags();
+        body.writeBoolean(flags != null && Boolean.TRUE.equals(flags.isFail()));
         serializeSubobject(obj.getSubobject(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
index 9fe7ac011f4959566a7b1b4a5dfcef340c033442..709f61a560d1f2a44ecbcf5cab0ed4e5cbfa0a04 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.pcep.parser.object;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -50,29 +49,27 @@ public class PCEPGlobalConstraintsObjectParser extends AbstractObjectWithTlvsPar
                 .setOverBookingFactor(ByteBufUtils.readUint8(bytes));
         final TlvsBuilder tlvsBuilder = new TlvsBuilder();
         parseTlvs(tlvsBuilder, bytes.slice());
-        builder.setTlvs(tlvsBuilder.build());
-        return builder.build();
+        return builder.setTlvs(tlvsBuilder.build()).build();
     }
 
     @Override
     public void serializeObject(final Object object, final ByteBuf buffer) {
-        checkArgument(object instanceof Gc,
-            "Wrong instance of PCEPObject. Passed %s. Needed GcObject.", object.getClass());
+        checkArgument(object instanceof Gc, "Wrong instance of PCEPObject. Passed %s. Needed GcObject.",
+            object.getClass());
         final Gc specObj = (Gc) object;
         final ByteBuf body = Unpooled.buffer();
-        writeUnsignedByte(specObj.getMaxHop(), body);
-        writeUnsignedByte(specObj.getMaxUtilization(), body);
-        writeUnsignedByte(specObj.getMinUtilization(), body);
-        writeUnsignedByte(specObj.getOverBookingFactor(), body);
+        ByteBufUtils.writeOrZero(body, specObj.getMaxHop());
+        ByteBufUtils.writeOrZero(body, specObj.getMaxUtilization());
+        ByteBufUtils.writeOrZero(body, specObj.getMinUtilization());
+        ByteBufUtils.writeOrZero(body, specObj.getOverBookingFactor());
         serializeTlvs(specObj.getTlvs(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
 
     public void serializeTlvs(final Tlvs tlvs, final ByteBuf body) {
-        if (tlvs == null) {
-            return;
+        if (tlvs != null) {
+            serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
         }
-        serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
     }
 
     @Override
index 3111215b370c0b96bdc0880dd7e3c263eaf028d3..906307c4a883265a7140e16ead5490583ab77b48 100644 (file)
@@ -7,10 +7,9 @@
  */
 package org.opendaylight.protocol.pcep.parser.object;
 
+import static com.google.common.base.Preconditions.checkArgument;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
-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.CommonObjectParser;
@@ -41,30 +40,28 @@ public final class PCEPLoadBalancingObjectParser extends CommonObjectParser impl
 
     @Override
     public LoadBalancing parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
-        Preconditions.checkArgument(bytes != null && bytes.isReadable(),
-            "Array of bytes is mandatory. Can't be null or empty.");
+        checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
         if (bytes.readableBytes() != SIZE) {
             throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: "
                 + bytes.readableBytes() + "; Expected: " + SIZE + ".");
         }
         bytes.skipBytes(RESERVED + FLAGS_F_LENGTH);
-        final LoadBalancingBuilder builder = new LoadBalancingBuilder()
+        return new LoadBalancingBuilder()
                 .setIgnore(header.isIgnore())
                 .setProcessingRule(header.isProcessingRule())
                 .setMaxLsp(ByteBufUtils.readUint8(bytes))
-                .setMinBandwidth(new Bandwidth(ByteArray.readAllBytes(bytes)));
-        return builder.build();
+                .setMinBandwidth(new Bandwidth(ByteArray.readAllBytes(bytes)))
+                .build();
     }
 
     @Override
     public void serializeObject(final Object object, final ByteBuf buffer) {
-        Preconditions.checkArgument(object instanceof LoadBalancing,
-            "Wrong instance of PCEPObject. Passed %s. Needed LoadBalancingObject.",
-            object.getClass());
+        checkArgument(object instanceof LoadBalancing,
+            "Wrong instance of PCEPObject. Passed %s. Needed LoadBalancingObject.", object.getClass());
         final LoadBalancing specObj = (LoadBalancing) object;
         final ByteBuf body = Unpooled.buffer(SIZE);
         body.writeZero(RESERVED + FLAGS_F_LENGTH);
-        writeUnsignedByte(specObj.getMaxLsp(), body);
+        ByteBufUtils.writeOrZero(body, specObj.getMaxLsp());
         writeFloat32(specObj.getMinBandwidth(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
index db1cd0a8fbee9a38ffd7f143e197cd3fd402c386..f8edc250bb8ae61e81a3b544b4903c3ba0977c53 100644 (file)
@@ -8,8 +8,6 @@
 package org.opendaylight.protocol.pcep.parser.object;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -41,12 +39,10 @@ public class PCEPLspaObjectParser extends AbstractObjectWithTlvsParser<TlvsBuild
      * lengths of fields in bytes
      */
     private static final int FLAGS_SIZE = 8;
-
     /*
      * offsets of flags inside flags field in bits
      */
     private static final int L_FLAG_OFFSET = 7;
-
     private static final int RESERVED = 1;
 
     public PCEPLspaObjectParser(final TlvRegistry tlvReg, final VendorInformationTlvRegistry viTlvReg) {
@@ -70,8 +66,7 @@ public class PCEPLspaObjectParser extends AbstractObjectWithTlvsParser<TlvsBuild
         final TlvsBuilder tbuilder = new TlvsBuilder();
         bytes.skipBytes(RESERVED);
         parseTlvs(tbuilder, bytes.slice());
-        builder.setTlvs(tbuilder.build());
-        return builder.build();
+        return builder.setTlvs(tbuilder.build()).build();
     }
 
     @Override
@@ -83,8 +78,8 @@ public class PCEPLspaObjectParser extends AbstractObjectWithTlvsParser<TlvsBuild
         writeAttributeFilter(lspaObj.getExcludeAny(), body);
         writeAttributeFilter(lspaObj.getIncludeAny(), body);
         writeAttributeFilter(lspaObj.getIncludeAll(), body);
-        writeUnsignedByte(lspaObj.getSetupPriority(), body);
-        writeUnsignedByte(lspaObj.getHoldPriority(), body);
+        ByteBufUtils.writeOrZero(body, lspaObj.getSetupPriority());
+        ByteBufUtils.writeOrZero(body, lspaObj.getHoldPriority());
         final BitArray flags = new BitArray(FLAGS_SIZE);
         flags.set(L_FLAG_OFFSET, lspaObj.isLocalProtectionDesired());
         flags.toByteBuf(body);
@@ -94,14 +89,17 @@ public class PCEPLspaObjectParser extends AbstractObjectWithTlvsParser<TlvsBuild
     }
 
     public void serializeTlvs(final Tlvs tlvs, final ByteBuf body) {
-        if (tlvs == null) {
-            return;
+        if (tlvs != null) {
+            serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
         }
-        serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
     }
 
     private static void writeAttributeFilter(final AttributeFilter attributeFilter, final ByteBuf body) {
-        writeUnsignedInt(attributeFilter != null ? attributeFilter.getValue() : null, body);
+        if (attributeFilter != null) {
+            ByteBufUtils.write(body, attributeFilter.getValue());
+        } else {
+            body.writeInt(0);
+        }
     }
 
     @Override
index 75d83d6c23d2e6b88f82241a85cd714067cfe376..438ad68d467f0c9d3de3398dc62af80194a0dbb1 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.protocol.pcep.parser.object;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -38,12 +37,10 @@ public final class PCEPMetricObjectParser extends CommonObjectParser implements
      */
     private static final int FLAGS_SIZE = 8;
     private static final int METRIC_VALUE_F_LENGTH = 4;
-
     /*
      * offsets of fields in bytes
      */
     private static final int RESERVED = 2;
-
     /*
      * flags offsets inside flags field in bits
      */
@@ -65,14 +62,14 @@ public final class PCEPMetricObjectParser extends CommonObjectParser implements
         }
         bytes.skipBytes(RESERVED);
         final BitArray flags = BitArray.valueOf(bytes.readByte());
-        final MetricBuilder builder = new MetricBuilder()
+        return new MetricBuilder()
                 .setIgnore(header.isIgnore())
                 .setProcessingRule(header.isProcessingRule())
                 .setBound(flags.get(B_FLAG_OFFSET))
                 .setComputed(flags.get(C_FLAG_OFFSET))
                 .setMetricType(ByteBufUtils.readUint8(bytes))
-                .setValue(new Float32(ByteArray.readBytes(bytes, METRIC_VALUE_F_LENGTH)));
-        return builder.build();
+                .setValue(new Float32(ByteArray.readBytes(bytes, METRIC_VALUE_F_LENGTH)))
+                .build();
     }
 
     @Override
@@ -86,8 +83,7 @@ public final class PCEPMetricObjectParser extends CommonObjectParser implements
         flags.set(C_FLAG_OFFSET, mObj.isComputed());
         flags.set(B_FLAG_OFFSET, mObj.isBound());
         flags.toByteBuf(body);
-        checkArgument(mObj.getMetricType() != null, "MetricType is mandatory.");
-        writeUnsignedByte(mObj.getMetricType(), body);
+        ByteBufUtils.writeMandatory(body, mObj.getMetricType(), "MetricType");
         writeFloat32(mObj.getValue(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
index 07be21c18de9e4024328828e64b2a1a6fed9ddd1..493c4c13618fc4bcb5711b3edd594550c52f0e53 100644 (file)
@@ -18,7 +18,6 @@ import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvRegistry;
 import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
 import org.opendaylight.protocol.util.BitArray;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.Monitoring;
@@ -61,11 +60,11 @@ public class PCEPMonitoringObjectParser extends AbstractObjectWithTlvsParser<Tlv
         final Uint32 monitoring = ByteBufUtils.readUint32(buffer);
         final TlvsBuilder tbuilder = new TlvsBuilder();
         parseTlvs(tbuilder, buffer.slice());
-        final MonitoringBuilder builder = new MonitoringBuilder()
+        return new MonitoringBuilder()
                 .setFlags(flags)
                 .setMonitoringId(monitoring)
-                .setTlvs(tbuilder.build());
-        return builder.build();
+                .setTlvs(tbuilder.build())
+                .build();
     }
 
     @Override
@@ -83,7 +82,7 @@ public class PCEPMonitoringObjectParser extends AbstractObjectWithTlvsParser<Tlv
         flagBits.set(G_FLAG_POS, flags.isGeneral());
         flagBits.set(L_FLAG_POS, flags.isLiveness());
         flagBits.toByteBuf(body);
-        ByteBufWriteUtil.writeUnsignedInt(monitoring.getMonitoringId(), body);
+        ByteBufUtils.writeOrZero(body, monitoring.getMonitoringId());
         serializeTlvs(monitoring.getTlvs(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
@@ -96,9 +95,8 @@ public class PCEPMonitoringObjectParser extends AbstractObjectWithTlvsParser<Tlv
     }
 
     public void serializeTlvs(final Tlvs tlvs, final ByteBuf body) {
-        if (tlvs == null) {
-            return;
+        if (tlvs != null) {
+            serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
         }
-        serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
     }
 }
index cfc41b37ea0fe7aa8fe980be13f03d0d8b5c41af..374ce2a6df567cbe14ce24b10ab2001b7b07cd5c 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.pcep.parser.object;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -62,13 +61,13 @@ public class PCEPNoPathObjectParser extends AbstractObjectWithTlvsParser<TlvsBui
         bytes.skipBytes(RESERVED_F_LENGTH);
         final TlvsBuilder tlvsBuilder = new TlvsBuilder();
         parseTlvs(tlvsBuilder, bytes.slice());
-        final NoPathBuilder builder = new NoPathBuilder()
+        return new NoPathBuilder()
                 .setIgnore(header.isIgnore())
                 .setProcessingRule(header.isProcessingRule())
                 .setNatureOfIssue(issue)
                 .setUnsatisfiedConstraints(flags.get(C_FLAG_OFFSET))
-                .setTlvs(tlvsBuilder.build());
-        return builder.build();
+                .setTlvs(tlvsBuilder.build())
+                .build();
     }
 
     @Override
@@ -84,8 +83,7 @@ public class PCEPNoPathObjectParser extends AbstractObjectWithTlvsParser<TlvsBui
             object.getClass());
         final NoPath nPObj = (NoPath) object;
         final ByteBuf body = Unpooled.buffer();
-        checkArgument(nPObj.getNatureOfIssue() != null, "NatureOfIssue is mandatory.");
-        writeUnsignedByte(nPObj.getNatureOfIssue(), body);
+        ByteBufUtils.writeMandatory(body, nPObj.getNatureOfIssue(), "NatureOfIssue");
         final BitArray flags = new BitArray(FLAGS_SIZE);
         flags.set(C_FLAG_OFFSET, nPObj.isUnsatisfiedConstraints());
         flags.toByteBuf(body);
@@ -95,13 +93,12 @@ public class PCEPNoPathObjectParser extends AbstractObjectWithTlvsParser<TlvsBui
     }
 
     public void serializeTlvs(final Tlvs tlvs, final ByteBuf body) {
-        if (tlvs == null) {
-            return;
+        if (tlvs != null) {
+            if (tlvs.getNoPathVector() != null) {
+                serializeTlv(tlvs.getNoPathVector(), body);
+            }
+            serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
         }
-        if (tlvs.getNoPathVector() != null) {
-            serializeTlv(tlvs.getNoPathVector(), body);
-        }
-        serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
     }
 
     @Override
index b99ae7c2e566311e4af66c10d53138e3cbe9584d..df8c1922c297db5963456041e84c750ec556edc2 100644 (file)
@@ -7,9 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.parser.object;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
+import static com.google.common.base.Preconditions.checkArgument;
 
-import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import java.util.List;
@@ -47,8 +46,7 @@ public final class PCEPNotificationObjectParser extends AbstractObjectWithTlvsPa
 
     @Override
     public CNotification parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
-        Preconditions.checkArgument(bytes != null && bytes.isReadable(),
-            "Array of bytes is mandatory. Can't be null or empty.");
+        checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
         bytes.skipBytes(NT_F_OFFSET);
         final CNotificationBuilder builder = new CNotificationBuilder()
                 .setIgnore(header.isIgnore())
@@ -68,34 +66,28 @@ public final class PCEPNotificationObjectParser extends AbstractObjectWithTlvsPa
 
     @Override
     public void serializeObject(final Object object, final ByteBuf buffer) {
-        Preconditions.checkArgument(object instanceof CNotification,
-            "Wrong instance of PCEPObject. Passed %s. Needed CNotificationObject.",
-            object.getClass());
+        checkArgument(object instanceof CNotification,
+            "Wrong instance of PCEPObject. Passed %s. Needed CNotificationObject.", object.getClass());
         final CNotification notObj = (CNotification) object;
         final ByteBuf body = Unpooled.buffer();
         body.writeZero(NT_F_OFFSET);
-        Preconditions.checkArgument(notObj.getType() != null, "Type is mandatory.");
-        writeUnsignedByte(notObj.getType(), body);
-        Preconditions.checkArgument(notObj.getValue() != null, "Value is mandatory.");
-        writeUnsignedByte(notObj.getValue(), body);
+        ByteBufUtils.writeMandatory(body, notObj.getType(), "Type");
+        ByteBufUtils.writeMandatory(body, notObj.getValue(), "Value");
         serializeTlvs(notObj.getTlvs(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
 
     public void serializeTlvs(final Tlvs tlvs, final ByteBuf body) {
-        if (tlvs == null) {
-            return;
+        if (tlvs != null) {
+            if (tlvs.getOverloadDuration() != null) {
+                serializeTlv(tlvs.getOverloadDuration(), body);
+            }
+            serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
         }
-        if (tlvs.getOverloadDuration() != null) {
-            serializeTlv(tlvs.getOverloadDuration(), body);
-        }
-        serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
     }
 
     @Override
-    protected void addVendorInformationTlvs(
-        final CNotificationBuilder builder,
-        final List<VendorInformationTlv> tlvs) {
+    protected void addVendorInformationTlvs(final CNotificationBuilder builder, final List<VendorInformationTlv> tlvs) {
         if (!tlvs.isEmpty()) {
             builder.setTlvs(new TlvsBuilder(builder.getTlvs()).setVendorInformationTlv(tlvs).build());
         }
index 61e7714b43e5f661d3376dab25185a1b24f0eaee..969bf5c8e366f97328275266f9b87a550b0ca880 100644 (file)
@@ -7,9 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.parser.object;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
+import static com.google.common.base.Preconditions.checkArgument;
 
-import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import java.util.List;
@@ -43,38 +42,38 @@ public final class PCEPObjectiveFunctionObjectParser extends AbstractObjectWithT
 
     @Override
     public Of parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
-        Preconditions.checkArgument(bytes != null && bytes.isReadable(),
-            "Array of bytes is mandatory. Can't be null or empty.");
+        checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
         final Uint16 ofId = ByteBufUtils.readUint16(bytes);
         bytes.readBytes(RESERVED);
         final TlvsBuilder tlvsBuilder = new TlvsBuilder();
         parseTlvs(tlvsBuilder, bytes.slice());
-        final OfBuilder builder = new OfBuilder()
+        return new OfBuilder()
                 .setIgnore(header.isIgnore())
                 .setProcessingRule(header.isProcessingRule())
                 .setCode(new OfId(ofId))
-                .setTlvs(tlvsBuilder.build());
-        return builder.build();
+                .setTlvs(tlvsBuilder.build())
+                .build();
     }
 
     @Override
     public void serializeObject(final Object object, final ByteBuf buffer) {
-        Preconditions.checkArgument(object instanceof Of,
-            "Wrong instance of PCEPObject. Passed %s. Needed OfObject.", object.getClass());
+        checkArgument(object instanceof Of, "Wrong instance of PCEPObject. Passed %s. Needed OfObject.",
+            object.getClass());
         final Of specObj = (Of) object;
         final ByteBuf body = Unpooled.buffer();
-        Preconditions.checkArgument(specObj.getCode() != null, "Code is mandatory");
-        writeUnsignedShort(specObj.getCode().getValue(), body);
+
+        final OfId code = specObj.getCode();
+        checkArgument(code != null, "Code is mandatory");
+        ByteBufUtils.write(body, code.getValue());
         body.writeZero(RESERVED);
         serializeTlvs(specObj.getTlvs(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
 
     public void serializeTlvs(final Tlvs tlvs, final ByteBuf body) {
-        if (tlvs == null) {
-            return;
+        if (tlvs != null) {
+            serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
         }
-        serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
     }
 
     @Override
index a458537cc5fcadee309815e360a647a0d8a65525..bd1099d1bccb6928a31dd09caacc99f29147f66f 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.pcep.parser.object;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -107,23 +106,21 @@ public class PCEPOpenObjectParser extends AbstractObjectWithTlvsParser<TlvsBuild
             object.getClass());
         final Open open = (Open) object;
         final ByteBuf body = Unpooled.buffer();
-        writeUnsignedByte(Uint8.valueOf(PCEP_VERSION << Byte.SIZE - VERSION_SF_LENGTH), body);
-        writeUnsignedByte(open.getKeepalive(), body);
-        writeUnsignedByte(open.getDeadTimer(), body);
-        checkArgument(open.getSessionId() != null, "SessionId is mandatory.");
-        writeUnsignedByte(open.getSessionId(), body);
+        body.writeByte(PCEP_VERSION << Byte.SIZE - VERSION_SF_LENGTH);
+        ByteBufUtils.writeOrZero(body, open.getKeepalive());
+        ByteBufUtils.writeOrZero(body, open.getDeadTimer());
+        ByteBufUtils.writeMandatory(body, open.getSessionId(), "SessionId");
         serializeTlvs(open.getTlvs(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
 
     public void serializeTlvs(final Tlvs tlvs, final ByteBuf body) {
-        if (tlvs == null) {
-            return;
+        if (tlvs != null) {
+            if (tlvs.getOfList() != null) {
+                serializeTlv(tlvs.getOfList(), body);
+            }
+            serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
         }
-        if (tlvs.getOfList() != null) {
-            serializeTlv(tlvs.getOfList(), body);
-        }
-        serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
     }
 
     @Override
index f738f0a7641eb49471889b36e2728889706e1007..2daae370100feab6c1c7331b2178dff47e86980b 100644 (file)
@@ -7,14 +7,14 @@
  */
 package org.opendaylight.protocol.pcep.parser.object;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import org.opendaylight.protocol.pcep.spi.CommonObjectParser;
 import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.overload.object.Overload;
@@ -34,22 +34,21 @@ public class PCEPOverloadObjectParser extends CommonObjectParser implements Obje
 
     @Override
     public void serializeObject(final Object object, final ByteBuf buffer) {
-        Preconditions.checkArgument(object instanceof Overload,
-            "Wrong instance of PCEPObject. Passed %s. Needed OverloadObject.", object.getClass());
+        checkArgument(object instanceof Overload, "Wrong instance of PCEPObject. Passed %s. Needed OverloadObject.",
+            object.getClass());
         final Overload overload = (Overload) object;
         final ByteBuf body = Unpooled.buffer(BODY_SIZE);
         body.writeZero(RESERVED + FLAGS);
-        ByteBufWriteUtil.writeUnsignedShort(overload.getDuration(), body);
+        ByteBufUtils.writeOrZero(body, overload.getDuration());
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
 
     @Override
     public Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException {
-        Preconditions.checkArgument(buffer != null && buffer.isReadable(),
-            "Array of bytes is mandatory. Can't be null or empty.");
-        final OverloadBuilder builder = new OverloadBuilder();
+        checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
         buffer.readBytes(RESERVED + FLAGS);
-        builder.setDuration(ByteBufUtils.readUint16(buffer));
-        return builder.build();
+        return new OverloadBuilder()
+                .setDuration(ByteBufUtils.readUint16(buffer))
+                .build();
     }
 }
index b1567c2a86bc79d76bfdedd6792bddfabee9607d..b2f0b23faa164b20610b2a34041658c3fa32d07f 100644 (file)
@@ -16,7 +16,6 @@ import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.util.BitArray;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.proc.time.object.ProcTime;
@@ -50,18 +49,17 @@ public class PCEPProcTimeObjectParser extends CommonObjectParser implements Obje
         final BitArray flagBits = new BitArray(FLAGS);
         flagBits.set(E_FLAG_POSITION, procTime.isEstimated());
         flagBits.toByteBuf(body);
-        ByteBufWriteUtil.writeUnsignedInt(procTime.getCurrentProcTime(), body);
-        ByteBufWriteUtil.writeUnsignedInt(procTime.getMinProcTime(), body);
-        ByteBufWriteUtil.writeUnsignedInt(procTime.getMaxProcTime(), body);
-        ByteBufWriteUtil.writeUnsignedInt(procTime.getAverageProcTime(), body);
-        ByteBufWriteUtil.writeUnsignedInt(procTime.getVarianceProcTime(), body);
+        ByteBufUtils.writeOrZero(body, procTime.getCurrentProcTime());
+        ByteBufUtils.writeOrZero(body, procTime.getMinProcTime());
+        ByteBufUtils.writeOrZero(body, procTime.getMaxProcTime());
+        ByteBufUtils.writeOrZero(body, procTime.getAverageProcTime());
+        ByteBufUtils.writeOrZero(body, procTime.getVarianceProcTime());
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
 
     @Override
     public Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException {
-        checkArgument(buffer != null && buffer.isReadable(),
-            "Array of bytes is mandatory. Can't be null or empty.");
+        checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
         buffer.skipBytes(RESERVED);
         final BitArray flagBits = BitArray.valueOf(buffer, FLAGS);
 
index a17688d5cf9202d665575cd890e82ae0469a7709..7d8ffc243acf9b46f846563dae433266ff924478 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.pcep.parser.object;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -156,23 +155,23 @@ public class PCEPRequestParameterObjectParser extends AbstractObjectWithTlvsPars
             res[res.length - 1] = (byte) (res[res.length - 1] | p);
         }
         body.writeBytes(res);
-        checkArgument(rpObj.getRequestId() != null, "RequestId is mandatory");
-        writeUnsignedInt(rpObj.getRequestId().getValue(), body);
+        final RequestId requestId = rpObj.getRequestId();
+        checkArgument(requestId != null, "RequestId is mandatory");
+        ByteBufUtils.write(body, requestId.getValue());
         serializeTlvs(rpObj.getTlvs(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
 
     public void serializeTlvs(final Tlvs tlvs, final ByteBuf body) {
-        if (tlvs == null) {
-            return;
+        if (tlvs != null) {
+            if (tlvs.getOrder() != null) {
+                serializeTlv(tlvs.getOrder(), body);
+            }
+            if (tlvs.getPathSetupType() != null) {
+                serializeTlv(tlvs.getPathSetupType(), body);
+            }
+            serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
         }
-        if (tlvs.getOrder() != null) {
-            serializeTlv(tlvs.getOrder(), body);
-        }
-        if (tlvs.getPathSetupType() != null) {
-            serializeTlv(tlvs.getPathSetupType(), body);
-        }
-        serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
     }
 
     @Override
index 310bef3ea516914ed2f5e7ad78d55e95e7cbecb3..6b32e78ffe0cf723a417f7372e0d5698e21e2ae8 100644 (file)
@@ -7,9 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.parser.object;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
+import static com.google.common.base.Preconditions.checkArgument;
 
-import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import java.util.ArrayList;
@@ -63,8 +62,7 @@ public final class PCEPSvecObjectParser extends CommonObjectParser implements Ob
 
     @Override
     public Svec parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
-        Preconditions.checkArgument(bytes != null && bytes.isReadable(),
-            "Array of bytes is mandatory. Can't be null or empty.");
+        checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
         if (bytes.readableBytes() < MIN_SIZE) {
             throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: "
                 + bytes.readableBytes() + "; Expected: >=" + MIN_SIZE + ".");
@@ -79,7 +77,7 @@ public final class PCEPSvecObjectParser extends CommonObjectParser implements Ob
         if (requestIDs.isEmpty()) {
             throw new PCEPDeserializerException("Empty Svec Object - no request ids.");
         }
-        final SvecBuilder builder = new SvecBuilder()
+        return new SvecBuilder()
                 .setIgnore(header.isIgnore())
                 .setProcessingRule(header.isProcessingRule())
                 .setLinkDiverse(flags.get(L_FLAG_OFFSET))
@@ -87,14 +85,14 @@ public final class PCEPSvecObjectParser extends CommonObjectParser implements Ob
                 .setSrlgDiverse(flags.get(S_FLAG_OFFSET))
                 .setLinkDirectionDiverse(flags.get(D_FLAG_OFFSET))
                 .setPartialPathDiverse(flags.get(P_FLAG_OFFSET))
-                .setRequestsIds(requestIDs);
-        return builder.build();
+                .setRequestsIds(requestIDs)
+                .build();
     }
 
     @Override
     public void serializeObject(final Object object, final ByteBuf buffer) {
-        Preconditions.checkArgument(object instanceof Svec,
-            "Wrong instance of PCEPObject. Passed %s. Needed SvecObject.", object.getClass());
+        checkArgument(object instanceof Svec, "Wrong instance of PCEPObject. Passed %s. Needed SvecObject.",
+            object.getClass());
         final Svec svecObj = (Svec) object;
         final ByteBuf body = Unpooled.buffer();
         body.writeZero(FLAGS_F_OFFSET);
@@ -107,9 +105,10 @@ public final class PCEPSvecObjectParser extends CommonObjectParser implements Ob
         flags.toByteBuf(body);
 
         final List<RequestId> requestIDs = svecObj.getRequestsIds();
+        // FIXME: remove this assert
         assert !requestIDs.isEmpty() : "Empty Svec Object - no request ids.";
         for (final RequestId requestId : requestIDs) {
-            writeUnsignedInt(requestId.getValue(), body);
+            ByteBufUtils.write(body, requestId.getValue());
         }
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
index d3329e44d0dd4ef140f9fde2111f661d8080cc00..336ae5e0d070de2dda66b69d7b6ef9bc2ce4ba0c 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.pcep.parser.subobject;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeShort;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -18,7 +17,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.as.number._case.AsNumberBuilder;
-import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
 
 final class AsNumberCaseParser {
     private static final int CONTENT_LENGTH = 2;
@@ -33,15 +32,19 @@ final class AsNumberCaseParser {
             throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
                 + "; Expected: " + CONTENT_LENGTH + ".");
         }
-        return new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(
-            new AsNumber(Uint32.valueOf(buffer.readUnsignedShort()))).build()).build();
+        return new AsNumberCaseBuilder()
+                .setAsNumber(new AsNumberBuilder()
+                    .setAsNumber(new AsNumber(ByteBufUtils.readUint16(buffer).toUint32()))
+                    .build())
+                .build();
     }
 
     static ByteBuf serializeSubobject(final AsNumberCase asCase) {
         final AsNumberSubobject asNumber = asCase.getAsNumber();
         final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
-        checkArgument(asNumber.getAsNumber() != null, "AsNumber is mandatory.");
-        writeShort(asNumber.getAsNumber().getValue().shortValue(), body);
+        final AsNumber asn = asNumber.getAsNumber();
+        checkArgument(asn != null, "AsNumber is mandatory.");
+        body.writeShort(asn.getValue().shortValue());
         return body;
     }
 }
index 1fd942791c7a13f02f25e101cf41e273cbe18e0a..b51e412bbc0922dc63c3c9f22b0a625ca9512222 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.pcep.parser.subobject;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -41,13 +40,15 @@ public class EROUnnumberedInterfaceSubobjectParser implements EROSubobjectParser
                 + "; Expected: " + CONTENT_LENGTH + ".");
         }
         buffer.skipBytes(RESERVED);
-        final UnnumberedBuilder ubuilder = new UnnumberedBuilder()
-                .setRouterId(ByteBufUtils.readUint32(buffer))
-                .setInterfaceId(ByteBufUtils.readUint32(buffer));
-        final SubobjectBuilder builder = new SubobjectBuilder()
+        return new SubobjectBuilder()
                 .setLoose(loose)
-                .setSubobjectType(new UnnumberedCaseBuilder().setUnnumbered(ubuilder.build()).build());
-        return builder.build();
+                .setSubobjectType(new UnnumberedCaseBuilder()
+                    .setUnnumbered(new UnnumberedBuilder()
+                        .setRouterId(ByteBufUtils.readUint32(buffer))
+                        .setInterfaceId(ByteBufUtils.readUint32(buffer))
+                        .build())
+                    .build())
+                .build();
     }
 
     @Override
@@ -57,10 +58,8 @@ public class EROUnnumberedInterfaceSubobjectParser implements EROSubobjectParser
         final UnnumberedSubobject specObj = ((UnnumberedCase) subobject.getSubobjectType()).getUnnumbered();
         final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
         body.writeZero(RESERVED);
-        checkArgument(specObj.getRouterId() != null, "RouterId is mandatory.");
-        writeUnsignedInt(specObj.getRouterId(), body);
-        checkArgument(specObj.getInterfaceId() != null, "InterfaceId is mandatory");
-        writeUnsignedInt(specObj.getInterfaceId(), body);
+        ByteBufUtils.writeMandatory(body, specObj.getRouterId(), "RouterId");
+        ByteBufUtils.writeMandatory(body, specObj.getInterfaceId(), "InterfaceId");
         EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
     }
 }
index 81f1b88bf9f401a2726fba62b076ad774fe2213e..33e26f9c2af03e4ea289d88c6036e9369dabc8c7 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.pcep.parser.subobject;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -23,7 +22,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.path.key._case.PathKeyBuilder;
-import org.opendaylight.yangtools.yang.common.Uint16;
 import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
 
 public class RROPathKey128SubobjectParser implements RROSubobjectParser {
@@ -44,14 +42,14 @@ public class RROPathKey128SubobjectParser implements RROSubobjectParser {
             throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
                     + "; Expected: >" + CONTENT128_LENGTH + ".");
         }
-        final Uint16 pathKey = ByteBufUtils.readUint16(buffer);
-        final byte[] pceId = ByteArray.readBytes(buffer, PCE128_ID_F_LENGTH);
-        final SubobjectBuilder builder = new SubobjectBuilder();
-        final PathKeyBuilder pBuilder = new PathKeyBuilder();
-        pBuilder.setPceId(new PceId(pceId));
-        pBuilder.setPathKey(new PathKey(pathKey));
-        builder.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
-        return builder.build();
+        return new SubobjectBuilder()
+                .setSubobjectType(new PathKeyCaseBuilder()
+                    .setPathKey(new PathKeyBuilder()
+                        .setPathKey(new PathKey(ByteBufUtils.readUint16(buffer)))
+                        .setPceId(new PceId(ByteArray.readBytes(buffer, PCE128_ID_F_LENGTH)))
+                        .build())
+                    .build())
+                .build();
     }
 
     public static void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
@@ -59,10 +57,12 @@ public class RROPathKey128SubobjectParser implements RROSubobjectParser {
         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects
             .subobject.type.path.key._case.PathKey pk = pkcase.getPathKey();
         final ByteBuf body = Unpooled.buffer();
-        checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
-        writeUnsignedShort(pk.getPathKey().getValue(), body);
-        checkArgument(pk.getPceId() != null, "PceId is mandatory.");
-        body.writeBytes(pk.getPceId().getValue());
+        final PathKey pathKey = pk.getPathKey();
+        checkArgument(pathKey != null, "PathKey is mandatory.");
+        ByteBufUtils.write(body, pathKey.getValue());
+        final PceId pceId = pk.getPceId();
+        checkArgument(pceId != null, "PceId is mandatory.");
+        body.writeBytes(pceId.getValue());
         RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
     }
 }
index 35a6de2091aa498cd422cdd14f0eb9c00ca5729c..bd7605df14f466b623420db7652b78147272fe47 100644 (file)
@@ -8,9 +8,7 @@
 package org.opendaylight.protocol.pcep.parser.subobject;
 
 import static com.google.common.base.Preconditions.checkArgument;
-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;
@@ -25,7 +23,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.path.key._case.PathKeyBuilder;
-import org.opendaylight.yangtools.yang.common.Uint16;
 import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
 
 public class RROPathKey32SubobjectParser implements RROSubobjectParser, RROSubobjectSerializer {
@@ -45,14 +42,14 @@ public class RROPathKey32SubobjectParser implements RROSubobjectParser, RROSubob
             throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
                 + "; Expected: >" + CONTENT_LENGTH + ".");
         }
-        final Uint16 pathKey = ByteBufUtils.readUint16(buffer);
-        final byte[] pceId = ByteArray.readBytes(buffer, PCE_ID_F_LENGTH);
-        final PathKeyBuilder pBuilder = new PathKeyBuilder()
-                .setPceId(new PceId(pceId))
-                .setPathKey(new PathKey(pathKey));
-        final SubobjectBuilder builder = new SubobjectBuilder()
-                .setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
-        return builder.build();
+        return new SubobjectBuilder()
+                .setSubobjectType(new PathKeyCaseBuilder()
+                    .setPathKey(new PathKeyBuilder()
+                        .setPathKey(new PathKey(ByteBufUtils.readUint16(buffer)))
+                        .setPceId(new PceId(ByteArray.readBytes(buffer, PCE_ID_F_LENGTH)))
+                        .build())
+                    .build())
+                .build();
     }
 
     @Override
@@ -63,16 +60,19 @@ public class RROPathKey32SubobjectParser implements RROSubobjectParser, RROSubob
         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route
             .subobjects.subobject.type.path.key._case.PathKey pk = pkcase.getPathKey();
         final ByteBuf body = Unpooled.buffer();
-        checkArgument(pk.getPceId() != null, "PceId is mandatory.");
 
-        final byte[] pceId = pk.getPceId().getValue();
-        if (pceId.length == RROPathKey128SubobjectParser.PCE128_ID_F_LENGTH) {
+        final PceId pceId = pk.getPceId();
+        checkArgument(pceId != null, "PceId is mandatory.");
+
+        final byte[] idBytes = pceId.getValue();
+        if (idBytes.length == RROPathKey128SubobjectParser.PCE128_ID_F_LENGTH) {
             RROPathKey128SubobjectParser.serializeSubobject(subobject, buffer);
         }
-        checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
-        writeUnsignedShort(pk.getPathKey().getValue(), body);
-        Preconditions.checkArgument(pceId.length == PCE_ID_F_LENGTH, "PceId 32 Bit required.");
-        body.writeBytes(pceId);
+        final PathKey pathKey = pk.getPathKey();
+        checkArgument(pathKey != null, "PathKey is mandatory.");
+        ByteBufUtils.write(body, pathKey.getValue());
+        checkArgument(idBytes.length == PCE_ID_F_LENGTH, "PceId 32 Bit required.");
+        body.writeBytes(idBytes);
         RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
     }
 }
index 2af20a1e7186833866fdc5c1bd39bcc867befc1e..57f8820d90a02c1e5a10b484404d075cf07e4406 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.pcep.parser.subobject;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -48,14 +47,16 @@ public class RROUnnumberedInterfaceSubobjectParser implements RROSubobjectParser
         }
         final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
         buffer.skipBytes(RESERVED);
-        final UnnumberedBuilder ubuilder = new UnnumberedBuilder()
-                .setRouterId(ByteBufUtils.readUint32(buffer))
-                .setInterfaceId(ByteBufUtils.readUint32(buffer));
-        final SubobjectBuilder builder = new SubobjectBuilder()
+        return new SubobjectBuilder()
                 .setProtectionAvailable(flags.get(LPA_F_OFFSET))
                 .setProtectionInUse(flags.get(LPIU_F_OFFSET))
-                .setSubobjectType(new UnnumberedCaseBuilder().setUnnumbered(ubuilder.build()).build());
-        return builder.build();
+                .setSubobjectType(new UnnumberedCaseBuilder()
+                    .setUnnumbered(new UnnumberedBuilder()
+                        .setRouterId(ByteBufUtils.readUint32(buffer))
+                        .setInterfaceId(ByteBufUtils.readUint32(buffer))
+                        .build())
+                    .build())
+                .build();
     }
 
     @Override
@@ -69,10 +70,8 @@ public class RROUnnumberedInterfaceSubobjectParser implements RROSubobjectParser
         final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
         flags.toByteBuf(body);
         body.writeZero(RESERVED);
-        checkArgument(specObj.getRouterId() != null, "RouterId is mandatory.");
-        writeUnsignedInt(specObj.getRouterId(), body);
-        checkArgument(specObj.getInterfaceId() != null, "InterfaceId is mandatory.");
-        writeUnsignedInt(specObj.getInterfaceId(), body);
+        ByteBufUtils.writeMandatory(body, specObj.getRouterId(), "RouterId");
+        ByteBufUtils.writeMandatory(body, specObj.getInterfaceId(), "InterfaceId");
         RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
     }
 }
index 80adfb6ade1f422b6ed2237ce693ee7a179b72ec..30e77e49388358afce108b6a38195986850d1a42 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.pcep.parser.subobject;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -50,7 +49,7 @@ public class Type1LabelParser implements LabelParser, LabelSerializer {
         final ByteBuf body = Unpooled.buffer(LABEL_LENGTH);
         final Type1Label type1Label = ((Type1LabelCase) subobject).getType1Label();
         checkArgument(type1Label != null, "Type1Label is mandatory.");
-        writeUnsignedInt(type1Label.getType1Label(), body);
+        ByteBufUtils.writeOrZero(body, type1Label.getType1Label());
         LabelUtil.formatLabel(CTYPE, unidirectional, global, body, buffer);
     }
 }
index bcb1e81cc081d590c7584867324fe6cb78d0360a..7a1f2acd806e7f12ad8e0008ae2a2ed84697fa36 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.pcep.parser.subobject;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -57,12 +56,9 @@ public class WavebandSwitchingLabelParser implements LabelParser, LabelSerialize
             "Unknown Label Subobject instance. Passed {}. Needed WavebandSwitchingLabelCase.", subobject.getClass());
         final WavebandSwitchingLabel obj = ((WavebandSwitchingLabelCase) subobject).getWavebandSwitchingLabel();
         final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
-        checkArgument(obj.getWavebandId() != null, "WavebandId is mandatory.");
-        writeUnsignedInt(obj.getWavebandId(), body);
-        checkArgument(obj.getStartLabel() != null, "StartLabel is mandatory.");
-        writeUnsignedInt(obj.getStartLabel(), body);
-        checkArgument(obj.getEndLabel() != null, "EndLabel is mandatory.");
-        writeUnsignedInt(obj.getEndLabel(), body);
+        ByteBufUtils.writeMandatory(body, obj.getWavebandId(), "WavebandId");
+        ByteBufUtils.writeMandatory(body, obj.getStartLabel(), "StartLabel");
+        ByteBufUtils.writeMandatory(body, obj.getEndLabel(), "EndLabel");
         LabelUtil.formatLabel(CTYPE, unidirectional, global, body, buffer);
     }
 }
index 4977a35dd3c662e1be4fad8ae337a3dfa9deacb9..92bd5271b85302dff4920d55c527b3e2d1894920 100644 (file)
@@ -9,9 +9,7 @@ package org.opendaylight.protocol.pcep.parser.subobject;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Prefix;
-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.PCEPDeserializerException;
@@ -21,6 +19,8 @@ import org.opendaylight.protocol.pcep.spi.XROSubobjectUtil;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.protocol.util.Ipv4Util;
 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.inet.types.rev130715.Ipv4Prefix;
+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.pcep.types.rev181109.exclude.route.object.xro.Subobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.SubobjectBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute;
@@ -28,7 +28,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder;
-import org.opendaylight.yangtools.yang.common.Uint8;
 
 /**
  * Parser for {@link IpPrefixCase}.
@@ -55,11 +54,11 @@ public class XROIpv4PrefixSubobjectParser implements XROSubobjectParser, XROSubo
                 .setIpPrefix(new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.readBytes(buffer, Ipv4Util.IP4_LENGTH),
                     length)));
         buffer.skipBytes(PREFIX_F_LENGTH);
-        final SubobjectBuilder builder = new SubobjectBuilder()
+        return new SubobjectBuilder()
                 .setMandatory(mandatory)
                 .setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(prefix.build()).build())
-                .setAttribute(Attribute.forValue(buffer.readUnsignedByte()));
-        return builder.build();
+                .setAttribute(Attribute.forValue(buffer.readUnsignedByte()))
+                .build();
     }
 
     @Override
@@ -68,17 +67,20 @@ public class XROIpv4PrefixSubobjectParser implements XROSubobjectParser, XROSubo
             "Unknown subobject instance. Passed %s. Needed IpPrefixCase.", subobject.getSubobjectType().getClass());
         final IpPrefixSubobject specObj = ((IpPrefixCase) subobject.getSubobjectType()).getIpPrefix();
         final IpPrefix prefix = specObj.getIpPrefix();
-        checkArgument(prefix.getIpv4Prefix() != null || prefix.getIpv6Prefix() != null,
-                "Unknown AbstractPrefix instance. Passed %s.", prefix.getClass());
-        if (prefix.getIpv6Prefix() != null) {
-            new XROIpv6PrefixSubobjectParser().serializeSubobject(subobject, buffer);
-        } else {
-            final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH);
-            Preconditions.checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
-            writeIpv4Prefix(prefix.getIpv4Prefix(), body);
-            Preconditions.checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
-            writeUnsignedByte(Uint8.valueOf(subobject.getAttribute().getIntValue()), body);
-            XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
+        final Ipv6Prefix ipv6Prefix = prefix.getIpv6Prefix();
+        if (ipv6Prefix != null) {
+            XROIpv6PrefixSubobjectParser.serializeSubobject(buffer, subobject, ipv6Prefix);
+            return;
         }
+
+        final Ipv4Prefix ipv4Prefix = prefix.getIpv4Prefix();
+        checkArgument(ipv4Prefix != null, "Ipv4Prefix is mandatory.");
+
+        final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH);
+        writeIpv4Prefix(ipv4Prefix, body);
+        final Attribute attribute = subobject.getAttribute();
+        checkArgument(attribute != null, "Attribute is mandatory.");
+        body.writeByte(attribute.getIntValue());
+        XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
     }
 }
index 513d70083467a921231bfaec181a7170aa58f21f..e1692a77568dff141b2c0ee88a0c04ddc4e9b85a 100644 (file)
@@ -7,10 +7,9 @@
  */
 package org.opendaylight.protocol.pcep.parser.subobject;
 
+import static com.google.common.base.Preconditions.checkArgument;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Prefix;
-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.PCEPDeserializerException;
@@ -20,6 +19,7 @@ import org.opendaylight.protocol.pcep.spi.XROSubobjectUtil;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.protocol.util.Ipv6Util;
 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.inet.types.rev130715.Ipv6Prefix;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.Subobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.SubobjectBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute;
@@ -27,25 +27,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder;
-import org.opendaylight.yangtools.yang.common.Uint8;
 
 /**
  * Parser for {@link IpPrefixCase}.
  */
 public class XROIpv6PrefixSubobjectParser implements XROSubobjectParser, XROSubobjectSerializer {
-
     public static final int TYPE = 2;
 
     private static final int PREFIX_F_LENGTH = 1;
-
     private static final int PREFIX6_F_OFFSET = Ipv6Util.IPV6_LENGTH;
-
     private static final int CONTENT6_LENGTH = PREFIX6_F_OFFSET + PREFIX_F_LENGTH + 1;
 
     @Override
     public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory) throws PCEPDeserializerException {
-        Preconditions.checkArgument(buffer != null && buffer.isReadable(),
-                "Array of bytes is mandatory. Can't be null or empty.");
+        checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
         if (buffer.readableBytes() != CONTENT6_LENGTH) {
             throw new PCEPDeserializerException(
                     "Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
@@ -63,15 +58,20 @@ public class XROIpv6PrefixSubobjectParser implements XROSubobjectParser, XROSubo
 
     @Override
     public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
-        Preconditions.checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase,
+        checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase,
                 "Unknown subobject instance. Passed %s. Needed IpPrefixCase.", subobject.getSubobjectType().getClass());
         final IpPrefixSubobject specObj = ((IpPrefixCase) subobject.getSubobjectType()).getIpPrefix();
-        final IpPrefix prefix = specObj.getIpPrefix();
+        final Ipv6Prefix ipv6Prefix = specObj.getIpPrefix().getIpv6Prefix();
+        checkArgument(ipv6Prefix != null, "Ipv6Prefix is mandatory.");
+        serializeSubobject(buffer, subobject, ipv6Prefix);
+    }
+
+    static void serializeSubobject(final ByteBuf buffer, final Subobject subobject, final Ipv6Prefix ipv6Prefix) {
         final ByteBuf body = Unpooled.buffer(CONTENT6_LENGTH);
-        Preconditions.checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory.");
-        writeIpv6Prefix(prefix.getIpv6Prefix(), body);
-        Preconditions.checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
-        writeUnsignedByte(Uint8.valueOf(subobject.getAttribute().getIntValue()), body);
+        writeIpv6Prefix(ipv6Prefix, body);
+        final Attribute attribute = subobject.getAttribute();
+        checkArgument(attribute != null, "Attribute is mandatory.");
+        body.writeByte(attribute.getIntValue());
         XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
     }
 }
index 72c44e56d3bcdb8a6cd7be59349bc33d3b1fb36a..80829a2a03aa9a6e1e10ea8b32e2a8b2ab14bab2 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.pcep.parser.subobject;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -20,10 +19,10 @@ 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.rev181109.exclude.route.object.xro.SubobjectBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.SubobjectType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKeyBuilder;
-import org.opendaylight.yangtools.yang.common.Uint16;
 import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
 
 /**
@@ -43,28 +42,30 @@ public class XROPathKey128SubobjectParser implements XROSubobjectParser {
             throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
                 + "; Expected: >" + CONTENT128_LENGTH + ".");
         }
-        final Uint16 pathKey = ByteBufUtils.readUint16(buffer);
-        final byte[] pceId = ByteArray.readBytes(buffer, PCE128_ID_F_LENGTH);
-        final PathKeyBuilder pBuilder = new PathKeyBuilder()
-                .setPceId(new PceId(pceId))
-                .setPathKey(new PathKey(pathKey));
-        final SubobjectBuilder builder = new SubobjectBuilder()
+        return new SubobjectBuilder()
                 .setMandatory(mandatory)
-                .setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
-        return builder.build();
+                .setSubobjectType(new PathKeyCaseBuilder()
+                    .setPathKey(new PathKeyBuilder()
+                        .setPathKey(new PathKey(ByteBufUtils.readUint16(buffer)))
+                        .setPceId(new PceId(ByteArray.readBytes(buffer, PCE128_ID_F_LENGTH)))
+                        .build())
+                    .build())
+                .build();
     }
 
     public static void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
-        checkArgument(subobject.getSubobjectType() instanceof PathKeyCase,
-            "Unknown subobject instance. Passed %s. Needed PathKey.", subobject.getSubobjectType().getClass());
+        final SubobjectType type = subobject.getSubobjectType();
+        checkArgument(type instanceof PathKeyCase, "Unknown subobject instance. Passed %s. Needed PathKey.",
+            type.getClass());
         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route
-            .subobjects.subobject.type.path.key._case.PathKey pk =
-                ((PathKeyCase) subobject.getSubobjectType()).getPathKey();
+            .subobjects.subobject.type.path.key._case.PathKey pk = ((PathKeyCase) type).getPathKey();
         final ByteBuf body = Unpooled.buffer();
-        checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
-        writeUnsignedShort(pk.getPathKey().getValue(), body);
-        checkArgument(pk.getPceId() != null, "PceId is mandatory.");
-        body.writeBytes(pk.getPceId().getValue());
+        final PathKey pathKey = pk.getPathKey();
+        checkArgument(pathKey != null, "PathKey is mandatory.");
+        ByteBufUtils.write(body, pathKey.getValue());
+        final PceId pceId = pk.getPceId();
+        checkArgument(pceId != null, "PceId is mandatory.");
+        body.writeBytes(pceId.getValue());
         XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
     }
 }
index ac9bc24d6844146ac91a86d848735d8b2f792784..620e1862272cd3e0615172d52169612da7ebf025 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.pcep.parser.subobject;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -24,7 +23,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKeyBuilder;
-import org.opendaylight.yangtools.yang.common.Uint16;
 import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
 
 /**
@@ -43,15 +41,15 @@ public class XROPathKey32SubobjectParser implements XROSubobjectParser, XROSubob
             throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
             + "; Expected: >" + CONTENT_LENGTH + ".");
         }
-        final Uint16 pathKey = ByteBufUtils.readUint16(buffer);
-        final byte[] pceId = ByteArray.readBytes(buffer, PCE_ID_F_LENGTH);
-        final PathKeyBuilder pBuilder = new PathKeyBuilder()
-                .setPceId(new PceId(pceId))
-                .setPathKey(new PathKey(pathKey));
-        final SubobjectBuilder builder = new SubobjectBuilder()
+        return new SubobjectBuilder()
                 .setMandatory(mandatory)
-                .setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
-        return builder.build();
+                .setSubobjectType(new PathKeyCaseBuilder()
+                    .setPathKey(new PathKeyBuilder()
+                        .setPathKey(new PathKey(ByteBufUtils.readUint16(buffer)))
+                        .setPceId(new PceId(ByteArray.readBytes(buffer, PCE_ID_F_LENGTH)))
+                        .build())
+                    .build())
+                .build();
     }
 
     @Override
@@ -68,8 +66,10 @@ public class XROPathKey32SubobjectParser implements XROSubobjectParser, XROSubob
         if (pceId.length == XROPathKey128SubobjectParser.PCE128_ID_F_LENGTH) {
             XROPathKey128SubobjectParser.serializeSubobject(subobject, buffer);
         }
-        checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
-        writeUnsignedShort(pk.getPathKey().getValue(), body);
+
+        final PathKey pathKey = pk.getPathKey();
+        checkArgument(pathKey != null, "PathKey is mandatory.");
+        ByteBufUtils.write(body, pathKey.getValue());
         checkArgument(pceId.length == PCE_ID_F_LENGTH, "PceId 32 Bit required.");
         body.writeBytes(pceId);
         XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
index 7787de14cf01f42b18999995ca15af6f6f34932e..8f65a808a58250103710fbe6e3f7929116789dfc 100644 (file)
@@ -8,8 +8,6 @@
 package org.opendaylight.protocol.pcep.parser.subobject;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -20,12 +18,12 @@ import org.opendaylight.protocol.pcep.spi.XROSubobjectUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.Subobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.SubobjectBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.SrlgId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.SrlgSubobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.SrlgCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.SrlgCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.srlg._case.SrlgBuilder;
-import org.opendaylight.yangtools.yang.common.Uint8;
 import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
 
 /**
@@ -61,11 +59,15 @@ public class XROSrlgSubobjectParser implements XROSubobjectParser, XROSubobjectS
             "Unknown subobject instance. Passed %s. Needed SrlgCase.", subobject.getSubobjectType().getClass());
         final SrlgSubobject specObj = ((SrlgCase) subobject.getSubobjectType()).getSrlg();
         final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
-        checkArgument(specObj.getSrlgId() != null, "SrlgId is mandatory.");
-        writeUnsignedInt(specObj.getSrlgId().getValue(), body);
-        checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
-        writeUnsignedByte((Uint8) null, body);
-        writeUnsignedByte(Uint8.valueOf(subobject.getAttribute().getIntValue()), body);
+
+        final SrlgId srlgId = specObj.getSrlgId();
+        checkArgument(srlgId != null, "SrlgId is mandatory.");
+        ByteBufUtils.write(body, srlgId.getValue());
+
+        final Attribute attribute = subobject.getAttribute();
+        checkArgument(attribute != null, "Attribute is mandatory.");
+        body.writeByte(0);
+        body.writeByte(attribute.getIntValue());
         XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
     }
 }
index 3e1cda2cbf0c3347f70276e0ef4d69e07783d6ed..920789e5c74655f82a5136a04f96d3a4e4b643cc 100644 (file)
@@ -8,8 +8,6 @@
 package org.opendaylight.protocol.pcep.parser.subobject;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -24,7 +22,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.UnnumberedCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.UnnumberedCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.unnumbered._case.UnnumberedBuilder;
-import org.opendaylight.yangtools.yang.common.Uint8;
 import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
 
 /**
@@ -62,13 +59,12 @@ public class XROUnnumberedInterfaceSubobjectParser implements XROSubobjectParser
         final UnnumberedSubobject specObj = ((UnnumberedCase) subobject.getSubobjectType()).getUnnumbered();
         final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
         body.writeZero(RESERVED);
-        writeUnsignedByte(
-                subobject.getAttribute() != null ? Uint8.valueOf(subobject.getAttribute().getIntValue()) : (Uint8) null,
-                body);
-        checkArgument(specObj.getRouterId() != null, "RouterId is mandatory.");
-        writeUnsignedInt(specObj.getRouterId(), body);
-        checkArgument(specObj.getInterfaceId() != null, "InterfaceId is mandatory.");
-        writeUnsignedInt(specObj.getInterfaceId(), body);
+
+        final Attribute attribute = subobject.getAttribute();
+        body.writeByte(attribute != null ? attribute.getIntValue() : 0);
+
+        ByteBufUtils.writeMandatory(body, specObj.getRouterId(), "RouterId");
+        ByteBufUtils.writeMandatory(body, specObj.getInterfaceId(), "InterfaceId");
         XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
     }
 }
index d0269e0d1ec2875ebb5a7e0f7faba9043fb52eab..7580afc72a69f3f1feb74a7d46aa8fdfdab0edd0 100644 (file)
@@ -5,13 +5,11 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.protocol.pcep.parser.tlv;
 
+import static com.google.common.base.Preconditions.checkArgument;
 import static org.opendaylight.protocol.pcep.spi.VendorInformationUtil.VENDOR_INFORMATION_TLV_TYPE;
-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.EnterpriseSpecificInformationParser;
@@ -23,16 +21,17 @@ 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.rev181109.vendor.information.EnterpriseSpecificInformation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.tlvs.VendorInformationTlv;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.tlvs.VendorInformationTlvBuilder;
+import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
 
 public abstract class AbstractVendorInformationTlvParser
         implements TlvSerializer, TlvParser, EnterpriseSpecificInformationParser {
 
     @Override
     public final void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
-        Preconditions.checkArgument(tlv instanceof VendorInformationTlv, "Vendor Specific Tlv is mandatory.");
+        checkArgument(tlv instanceof VendorInformationTlv, "Vendor Specific Tlv is mandatory.");
         final VendorInformationTlv viTlv = (VendorInformationTlv) tlv;
         final ByteBuf body = Unpooled.buffer();
-        writeUnsignedInt(getEnterpriseNumber().getValue(), body);
+        ByteBufUtils.write(body, getEnterpriseNumber().getValue());
         serializeEnterpriseSpecificInformation(viTlv.getEnterpriseSpecificInformation(), body);
         TlvUtil.formatTlv(VENDOR_INFORMATION_TLV_TYPE, body, buffer);
     }
@@ -42,8 +41,8 @@ public abstract class AbstractVendorInformationTlvParser
         if (buffer == null) {
             return null;
         }
-        final VendorInformationTlvBuilder viTlvBuider = new VendorInformationTlvBuilder();
-        viTlvBuider.setEnterpriseNumber(getEnterpriseNumber());
+        final VendorInformationTlvBuilder viTlvBuider = new VendorInformationTlvBuilder()
+                .setEnterpriseNumber(getEnterpriseNumber());
         if (buffer.isReadable()) {
             final EnterpriseSpecificInformation esInformation = parseEnterpriseSpecificInformation(buffer.slice());
             if (esInformation != null) {
index ee6b109a3904bde410276b5c585cec9dd47d2075..db25120e727d91ab36acea8d54af0e93e2aeb37c 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.pcep.parser.tlv;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -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) {
-            writeUnsignedShort(id.getValue(), body);
+            ByteBufUtils.write(body, id.getValue());
         }
         TlvUtil.formatTlv(TYPE, body, buffer);
     }
index 3a21b4efa3cee8bbfe408868daea9c5f671764db..7c7c5ef6bf1513c1058fabe38b13c175c66bf28b 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.pcep.parser.tlv;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -43,8 +42,8 @@ public class OrderTlvParser implements TlvParser, TlvSerializer {
         checkArgument(tlv instanceof Order, "OrderTlv is mandatory.");
         final Order otlv = (Order) tlv;
         final ByteBuf body = Unpooled.buffer();
-        writeUnsignedInt(otlv.getDelete(), body);
-        writeUnsignedInt(otlv.getSetup(), body);
+        ByteBufUtils.writeOrZero(body, otlv.getDelete());
+        ByteBufUtils.writeOrZero(body, otlv.getSetup());
         TlvUtil.formatTlv(TYPE, body, buffer);
     }
 }
index fd6044ae3efeb57c4188003fecb54a7a26b4c247..73847c5436b3fc7c6f5224b5afc7246583e758ba 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.pcep.parser.tlv;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -39,7 +38,7 @@ public class OverloadedDurationTlvParser implements TlvParser, TlvSerializer {
     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
         checkArgument(tlv instanceof OverloadDuration, "OverloadedTlv is mandatory.");
         final ByteBuf body = Unpooled.buffer();
-        writeUnsignedInt(((OverloadDuration) tlv).getDuration(), body);
+        ByteBufUtils.writeOrZero(body, ((OverloadDuration) tlv).getDuration());
         TlvUtil.formatTlv(TYPE, body, buffer);
     }
 }
index d37bf376f7e81d292abc7c1b522b6e883e81017a..0a00e9d0a8fa05a1465b128a540c755ee0762b7e 100644 (file)
@@ -5,12 +5,10 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.protocol.pcep.parser.tlv;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
+import static com.google.common.base.Preconditions.checkArgument;
 
-import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import java.util.HashSet;
@@ -23,9 +21,9 @@ 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.rev181109.path.setup.type.tlv.PathSetupType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.setup.type.tlv.PathSetupTypeBuilder;
 import org.opendaylight.yangtools.yang.common.Uint8;
+import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
 
 public class PathSetupTypeTlvParser implements TlvParser, TlvSerializer {
-
     public static final int TYPE = 28;
 
     private static final int CONTENT_LENGTH = 4;
@@ -47,12 +45,12 @@ public class PathSetupTypeTlvParser implements TlvParser, TlvSerializer {
 
     @Override
     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
-        Preconditions.checkArgument(tlv instanceof PathSetupType, "PathSetupType is mandatory.");
+        checkArgument(tlv instanceof PathSetupType, "PathSetupType is mandatory.");
         final PathSetupType pstTlv = (PathSetupType) tlv;
-        Preconditions.checkArgument(checkPST(pstTlv.getPst()), UNSUPPORTED_PST);
+        checkArgument(checkPST(pstTlv.getPst()), UNSUPPORTED_PST);
         final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
         body.writeZero(OFFSET);
-        writeUnsignedByte(pstTlv.getPst(), body);
+        ByteBufUtils.writeOrZero(body, pstTlv.getPst());
         TlvUtil.formatTlv(TYPE, body, buffer);
     }
 
@@ -61,7 +59,7 @@ public class PathSetupTypeTlvParser implements TlvParser, TlvSerializer {
         if (buffer == null) {
             return null;
         }
-        final Uint8 pst = Uint8.valueOf(buffer.readerIndex(OFFSET).readUnsignedByte());
+        final Uint8 pst = ByteBufUtils.readUint8(buffer.readerIndex(OFFSET));
         if (!checkPST(pst)) {
             throw new PCEPDeserializerException(UNSUPPORTED_PST);
         }
index b0339c1c40c5fcd8ece91d265c6107394585e096..7701c5772001211672849de2bc2aafc02544d063 100644 (file)
@@ -7,9 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.parser.tlv;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
+import static com.google.common.base.Preconditions.checkArgument;
 
-import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
@@ -38,11 +37,13 @@ public class ReqMissingTlvParser implements TlvParser, TlvSerializer {
 
     @Override
     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
-        Preconditions.checkArgument(tlv instanceof ReqMissing, "ReqMissingTlv is mandatory.");
+        checkArgument(tlv instanceof ReqMissing, "ReqMissingTlv is mandatory.");
         final ReqMissing req = (ReqMissing) tlv;
         final ByteBuf body = Unpooled.buffer();
-        Preconditions.checkArgument(req.getRequestId() != null, "RequestId is mandatory.");
-        writeUnsignedInt(req.getRequestId().getValue(), body);
+
+        final RequestId reqId = req.getRequestId();
+        checkArgument(reqId != null, "RequestId is mandatory.");
+        ByteBufUtils.write(body, reqId.getValue());
         TlvUtil.formatTlv(TYPE, body, buffer);
     }
 }