Minimize use of ByteBufWriteUtil in rsvp-impl 14/86714/2
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 5 Jan 2020 12:09:17 +0000 (13:09 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 5 Jan 2020 13:46:54 +0000 (14:46 +0100)
ByteBufUtils are up to most of the tasks, make sure we use them
instead of our home-grown utilities.

Change-Id: I34bcc5410774b2c00749a62249d9e4595a13be16
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
12 files changed:
rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/AsNumberCaseParser.java
rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/label/Type1LabelParser.java
rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/label/WavebandSwitchingLabelParser.java
rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/rro/RROPathKey128SubobjectParser.java
rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/rro/RROPathKey32SubobjectParser.java
rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/rro/RROUnnumberedInterfaceSubobjectParser.java
rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/xro/XROIpv4PrefixSubobjectParser.java
rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/xro/XROIpv6PrefixSubobjectParser.java
rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/xro/XROSrlgSubobjectParser.java
rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/xro/XROUnnumberedInterfaceSubobjectParser.java
rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/FlowSpecObjectParser.java
rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/SenderTspecObjectParser.java

index 531764e512ba36ad8e40829ba5c9e391d32d08a9..4b70aec2ed82ec851755217f79b9c5499d53ecf9 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.rsvp.parser.impl.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;
@@ -44,7 +43,7 @@ public final class AsNumberCaseParser {
         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);
+        body.writeShort(asNumber.getAsNumber().getValue().shortValue());
         return body;
     }
 }
index e93b21ad2db55763e47e4eb3150aa8c8b3be21ab..15258037df3386008a80199823453136c83b446f 100644 (file)
@@ -5,13 +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.rsvp.parser.impl.subobject.label;
 
 import static com.google.common.base.Preconditions.checkArgument;
-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.rsvp.parser.spi.LabelParser;
@@ -50,8 +47,8 @@ public class Type1LabelParser implements LabelParser, LabelSerializer {
             "Unknown Label Subobject instance. Passed %s. Needed Type1LabelCase.", subobject.getClass());
         final ByteBuf body = Unpooled.buffer(LABEL_LENGTH);
         final Type1Label type1Label = ((Type1LabelCase) subobject).getType1Label();
-        Preconditions.checkArgument(type1Label != null, "Type1Label is mandatory.");
-        writeUnsignedInt(type1Label.getType1Label(), body);
+        checkArgument(type1Label != null, "Type1Label is mandatory.");
+        ByteBufUtils.writeOrZero(body, type1Label.getType1Label());
         LabelUtil.formatLabel(CTYPE, unidirectional, global, body, buffer);
     }
 }
index c773ce09b35e40254f5a6ee7dd624e8d7aff39da..0874921ceec717d5b5a84e861616ed9fbda4b3bc 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.rsvp.parser.impl.subobject.label;
 
 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
             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 e61443611d4b5ac2cab0ddb3e30bb794cdeaf2ce..fc33c71545f3cebc0818215544b7e0f8cc5987a2 100644 (file)
@@ -7,9 +7,8 @@
  */
 package org.opendaylight.protocol.rsvp.parser.impl.subobject.rro;
 
-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 org.opendaylight.protocol.rsvp.parser.spi.RROSubobjectParser;
@@ -22,7 +21,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 {
@@ -40,28 +38,31 @@ 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();
-        Preconditions.checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
-        writeUnsignedShort(pk.getPathKey().getValue(), body);
-        Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory.");
-        body.writeBytes(pk.getPceId().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);
     }
 
     @Override
     public SubobjectContainer parseSubobject(final ByteBuf buffer) throws RSVPParsingException {
-        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() != CONTENT128_LENGTH) {
             throw new RSVPParsingException("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 SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
-        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 SubobjectContainerBuilder()
+                .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();
     }
 }
index cc21957fe8e6adde908dcc952e379ddb91a70296..6614a1056512e4a8378b4fb18e5babc60286b5e3 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.rsvp.parser.impl.subobject.rro;
 
 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 RROPathKey32SubobjectParser implements RROSubobjectParser, RROSubobjectSerializer {
@@ -42,14 +40,14 @@ public class RROPathKey32SubobjectParser implements RROSubobjectParser, RROSubob
             throw new RSVPParsingException("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 SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
-        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 SubobjectContainerBuilder()
+                .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
@@ -67,9 +65,11 @@ public class RROPathKey32SubobjectParser implements RROSubobjectParser, RROSubob
         if (pceId.length == RROPathKey128SubobjectParser.PCE128_ID_F_LENGTH) {
             RROPathKey128SubobjectParser.serializeSubobject(subobject, buffer);
         }
-        checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
+
+        final PathKey pathKey = pk.getPathKey();
+        checkArgument(pathKey != null, "PathKey is mandatory.");
         checkArgument(pceId.length == PCE_ID_F_LENGTH, "PathKey 32Bit is mandatory.");
-        writeUnsignedShort(pk.getPathKey().getValue(), body);
+        ByteBufUtils.write(body, pathKey.getValue());
         body.writeBytes(pceId);
         RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
     }
index adbc9286017c8473d3ac7ea073d0f74c3fcf200c..d3e68d43a2fc992239883c49f5b7ac28954e3baa 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.rsvp.parser.impl.subobject.rro;
 
 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;
@@ -17,6 +16,7 @@ import org.opendaylight.protocol.rsvp.parser.spi.RROSubobjectSerializer;
 import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
 import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.UnnumberedSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.SubobjectType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.list.SubobjectContainer;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.list.SubobjectContainerBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.UnnumberedCase;
@@ -43,34 +43,35 @@ public class RROUnnumberedInterfaceSubobjectParser implements RROSubobjectParser
             throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; "
                 + "Expected: " + CONTENT_LENGTH + ".");
         }
-        final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
         final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
-        builder.setProtectionAvailable(flags.get(LPA_F_OFFSET));
-        builder.setProtectionInUse(flags.get(LPIU_F_OFFSET));
-        final UnnumberedBuilder ubuilder = new UnnumberedBuilder();
         buffer.skipBytes(RESERVED);
-        ubuilder.setRouterId(ByteBufUtils.readUint32(buffer));
-        ubuilder.setInterfaceId(ByteBufUtils.readUint32(buffer));
-        builder.setSubobjectType(new UnnumberedCaseBuilder().setUnnumbered(ubuilder.build()).build());
-        return builder.build();
+        return new SubobjectContainerBuilder()
+                .setProtectionAvailable(flags.get(LPA_F_OFFSET))
+                .setProtectionInUse(flags.get(LPIU_F_OFFSET))
+                .setSubobjectType(new UnnumberedCaseBuilder()
+                    .setUnnumbered(new UnnumberedBuilder()
+                        .setRouterId(ByteBufUtils.readUint32(buffer))
+                        .setInterfaceId(ByteBufUtils.readUint32(buffer))
+                        .build())
+                    .build())
+                .build();
     }
 
     @Override
     public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
-        checkArgument(subobject.getSubobjectType() instanceof UnnumberedCase,
-            "Unknown subobject instance. Passed %s. Needed UnnumberedCase.",
-            subobject.getSubobjectType().getClass());
-        final UnnumberedSubobject specObj = ((UnnumberedCase) subobject.getSubobjectType()).getUnnumbered();
+        final SubobjectType type = subobject.getSubobjectType();
+        checkArgument(type instanceof UnnumberedCase, "Unknown subobject instance. Passed %s. Needed UnnumberedCase.",
+            type.getClass());
         final BitArray flags = new BitArray(FLAGS_SIZE);
         flags.set(LPA_F_OFFSET, subobject.isProtectionAvailable());
         flags.set(LPIU_F_OFFSET, subobject.isProtectionInUse());
         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);
+
+        final UnnumberedSubobject specObj = ((UnnumberedCase) type).getUnnumbered();
+        ByteBufUtils.writeMandatory(body, specObj.getRouterId(), "RouterId");
+        ByteBufUtils.writeMandatory(body, specObj.getInterfaceId(), "InterfaceId");
         RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
     }
 }
index 4c1e9810f844d58e911a5c850074bd7d30130bd1..d6e2a073b5cc33e3460a9277f24a5b0acc200a01 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.rsvp.parser.impl.subobject.xro;
 
+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.rsvp.parser.spi.RSVPParsingException;
@@ -22,6 +20,7 @@ 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.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.IpPrefixSubobject;
+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.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;
@@ -32,16 +31,13 @@ public class XROIpv4PrefixSubobjectParser implements XROSubobjectParser, XROSubo
     public static final int TYPE = 1;
 
     private static final int PREFIX_F_LENGTH = 1;
-
     private static final int PREFIX4_F_OFFSET = Ipv4Util.IP4_LENGTH;
-
     private static final int CONTENT4_LENGTH = PREFIX4_F_OFFSET + PREFIX_F_LENGTH + 1;
 
     @Override
     public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean mandatory) throws
         RSVPParsingException {
-        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.");
         final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
         builder.setMandatory(mandatory);
         if (buffer.readableBytes() != CONTENT4_LENGTH) {
@@ -58,21 +54,21 @@ public class XROIpv4PrefixSubobjectParser implements XROSubobjectParser, XROSubo
 
     @Override
     public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
-        Preconditions.checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase,
-            "Unknown subobject instance. Passed %s. Needed IpPrefixCase.",
-            subobject.getSubobjectType().getClass());
-        final IpPrefixSubobject specObj = ((IpPrefixCase) subobject.getSubobjectType()).getIpPrefix();
+        final SubobjectType type = subobject.getSubobjectType();
+        checkArgument(type instanceof IpPrefixCase, "Unknown subobject instance. Passed %s. Needed IpPrefixCase.",
+            type.getClass());
+        final IpPrefixSubobject specObj = ((IpPrefixCase) type).getIpPrefix();
         final IpPrefix prefix = specObj.getIpPrefix();
-        Preconditions.checkArgument(prefix.getIpv4Prefix() != null || prefix.getIpv6Prefix() != null,
+        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.");
+            checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
             writeIpv4Prefix(prefix.getIpv4Prefix(), body);
-            Preconditions.checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
-            writeUnsignedByte((short) subobject.getAttribute().getIntValue(), body);
+            checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
+            body.writeByte(subobject.getAttribute().getIntValue());
             XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
         }
     }
index 6842f7f5cb6191a752bea50ac1bc17e1e5b35d69..5f78e0bdea6da4c98a8217ee9b3c00a6161a848a 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.rsvp.parser.impl.subobject.xro;
 
+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.rsvp.parser.spi.RSVPParsingException;
@@ -22,6 +20,7 @@ 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.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.IpPrefixSubobject;
+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.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;
@@ -32,20 +31,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
  * 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 SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean mandatory) throws
         RSVPParsingException {
-        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.");
         final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
         builder.setMandatory(mandatory);
         if (buffer.readableBytes() != CONTENT6_LENGTH) {
@@ -62,16 +57,17 @@ public class XROIpv6PrefixSubobjectParser implements XROSubobjectParser, XROSubo
 
     @Override
     public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
-        Preconditions.checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase,
+        final SubobjectType type = subobject.getSubobjectType();
+        checkArgument(type instanceof IpPrefixCase,
             "Unknown subobject instance. Passed %s. Needed IpPrefixCase.",
-            subobject.getSubobjectType().getClass());
-        final IpPrefixSubobject specObj = ((IpPrefixCase) subobject.getSubobjectType()).getIpPrefix();
+            type.getClass());
+        final IpPrefixSubobject specObj = ((IpPrefixCase) type).getIpPrefix();
         final IpPrefix prefix = specObj.getIpPrefix();
         final ByteBuf body = Unpooled.buffer(CONTENT6_LENGTH);
-        Preconditions.checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory.");
+        checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory.");
         writeIpv6Prefix(prefix.getIpv6Prefix(), body);
-        Preconditions.checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
-        writeUnsignedByte((short) subobject.getAttribute().getIntValue(), body);
+        checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
+        body.writeByte(subobject.getAttribute().getIntValue());
         XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
     }
 }
index 434bf010d66dcb475fbf46ee1b5c21e05c4fa33f..0230bb3a264dafa609dd27d6ab362a0953e0e64f 100644 (file)
@@ -8,8 +8,6 @@
 package org.opendaylight.protocol.rsvp.parser.impl.subobject.xro;
 
 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;
@@ -17,14 +15,15 @@ import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
 import org.opendaylight.protocol.rsvp.parser.spi.XROSubobjectParser;
 import org.opendaylight.protocol.rsvp.parser.spi.XROSubobjectSerializer;
 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.SubobjectType;
 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.exclude.route.object.exclude.route.object.SubobjectContainer;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.exclude.route.object.exclude.route.object.SubobjectContainerBuilder;
-import org.opendaylight.yangtools.yang.common.Uint8;
 import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
 
 /**
@@ -55,15 +54,20 @@ public class XROSrlgSubobjectParser implements XROSubobjectParser, XROSubobjectS
 
     @Override
     public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
-        checkArgument(subobject.getSubobjectType() instanceof SrlgCase,
-            "Unknown subobject instance. Passed %s. Needed SrlgCase.", subobject.getSubobjectType().getClass());
-        final SrlgSubobject specObj = ((SrlgCase) subobject.getSubobjectType()).getSrlg();
+        final SubobjectType type = subobject.getSubobjectType();
+        checkArgument(type instanceof SrlgCase, "Unknown subobject instance. Passed %s. Needed SrlgCase.",
+            type.getClass());
+        final SrlgSubobject specObj = ((SrlgCase) type).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((short) 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 8ba342042f7b4c4daef462e31b7884bb64483e1a..caf37d8039a53518dd0b596ccfb4907ba7e8629d 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.rsvp.parser.impl.subobject.xro;
 
-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 org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
@@ -18,6 +16,8 @@ import org.opendaylight.protocol.rsvp.parser.spi.XROSubobjectParser;
 import org.opendaylight.protocol.rsvp.parser.spi.XROSubobjectSerializer;
 import org.opendaylight.protocol.rsvp.parser.spi.subobjects.CommonUnnumberedInterfaceSubobjectParser;
 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.basic.explicit.route.subobjects.SubobjectType;
 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.exclude.route.object.exclude.route.object.SubobjectContainer;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.exclude.route.object.exclude.route.object.SubobjectContainerBuilder;
@@ -26,40 +26,39 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
  * Parser for {@link UnnumberedCase}.
  */
 public class XROUnnumberedInterfaceSubobjectParser extends CommonUnnumberedInterfaceSubobjectParser
-    implements XROSubobjectParser, XROSubobjectSerializer {
+        implements XROSubobjectParser, XROSubobjectSerializer {
     public static final int TYPE = 4;
 
     private static final int RESERVED = 1;
-
     private static final int CONTENT_LENGTH = 10;
 
     @Override
     public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean mandatory) throws
         RSVPParsingException {
-        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() != CONTENT_LENGTH) {
             throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
                 + "; " + "Expected: " + CONTENT_LENGTH + ".");
         }
         buffer.readerIndex(buffer.readerIndex() + RESERVED);
-        final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
-        builder.setMandatory(mandatory);
-        builder.setAttribute(ExcludeRouteSubobjects.Attribute.forValue(buffer.readUnsignedByte()));
-        builder.setSubobjectType(parseUnnumeredInterface(buffer));
-        return builder.build();
+        return new SubobjectContainerBuilder()
+                .setMandatory(mandatory)
+                .setAttribute(ExcludeRouteSubobjects.Attribute.forValue(buffer.readUnsignedByte()))
+                .setSubobjectType(parseUnnumeredInterface(buffer))
+                .build();
     }
 
     @Override
     public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
-        Preconditions.checkArgument(subobject.getSubobjectType() instanceof UnnumberedCase,
-            "Unknown subobject instance. Passed %s. Needed UnnumberedCase.",
-            subobject.getSubobjectType().getClass());
+        final SubobjectType type = subobject.getSubobjectType();
+        checkArgument(type instanceof UnnumberedCase, "Unknown subobject instance. Passed %s. Needed UnnumberedCase.",
+            type.getClass());
         final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
         body.writeZero(RESERVED);
-        writeUnsignedByte(subobject.getAttribute() != null ? (short) subobject.getAttribute().getIntValue() : null,
-            body);
-        serializeUnnumeredInterface(((UnnumberedCase) subobject.getSubobjectType()).getUnnumbered(), body);
+
+        final Attribute attribute = subobject.getAttribute();
+        body.writeByte(attribute != null ? attribute.getIntValue() : 0);
+        serializeUnnumeredInterface(((UnnumberedCase) type).getUnnumbered(), body);
         XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
     }
 }
index b539bcf50ec95f6e2d6fcc76f6129d0ebebebb05..f340b2c69b3471d5c91187b254ec26383f0702fa 100644 (file)
@@ -7,10 +7,9 @@
  */
 package org.opendaylight.protocol.rsvp.parser.impl.te;
 
+import static com.google.common.base.Preconditions.checkArgument;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 
-import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
 import org.opendaylight.protocol.rsvp.parser.spi.subobjects.AbstractRSVPObjectParser;
@@ -64,7 +63,7 @@ public final class FlowSpecObjectParser extends AbstractRSVPObjectParser {
 
     @Override
     public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf output) {
-        Preconditions.checkArgument(teLspObject instanceof FlowSpecObject, "SenderTspecObject is mandatory.");
+        checkArgument(teLspObject instanceof FlowSpecObject, "SenderTspecObject is mandatory.");
         final FlowSpecObject flowObj = (FlowSpecObject) teLspObject;
         final int sHeader = flowObj.getServiceHeader().getIntValue();
         if (sHeader == 2) {
@@ -91,8 +90,8 @@ public final class FlowSpecObjectParser extends AbstractRSVPObjectParser {
         writeFloat32(tSpec.getTokenBucketRate(), output);
         writeFloat32(tSpec.getTokenBucketSize(), output);
         writeFloat32(tSpec.getPeakDataRate(), output);
-        writeUnsignedInt(tSpec.getMinimumPolicedUnit(), output);
-        writeUnsignedInt(tSpec.getMaximumPacketSize(), output);
+        ByteBufUtils.writeOrZero(output, tSpec.getMinimumPolicedUnit());
+        ByteBufUtils.writeOrZero(output, tSpec.getMaximumPacketSize());
 
         if (sHeader != 2) {
             return;
@@ -101,6 +100,6 @@ public final class FlowSpecObjectParser extends AbstractRSVPObjectParser {
         output.writeByte(0);
         output.writeShort(PARAMETER_130_LENGTH);
         writeFloat32(flowObj.getRate(), output);
-        writeUnsignedInt(flowObj.getSlackTerm(), output);
+        ByteBufUtils.writeOrZero(output, flowObj.getSlackTerm());
     }
 }
index 00721867b5e78570917162c0d4c42e67dfcc1312..0b75d6cdfdac77c71d2442fbaad076fe58936853 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.protocol.rsvp.parser.impl.te;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
@@ -62,7 +61,7 @@ public class SenderTspecObjectParser extends AbstractRSVPObjectParser {
         writeFloat32(tspecObj.getTokenBucketRate(), output);
         writeFloat32(tspecObj.getTokenBucketSize(), output);
         writeFloat32(tspecObj.getPeakDataRate(), output);
-        writeUnsignedInt(tspecObj.getMinimumPolicedUnit(), output);
-        writeUnsignedInt(tspecObj.getMaximumPacketSize(), output);
+        ByteBufUtils.writeOrZero(output, tspecObj.getMinimumPolicedUnit());
+        ByteBufUtils.writeOrZero(output, tspecObj.getMaximumPacketSize());
     }
 }