Minimize use of ByteBufWriteUtil in bgp-parser-impl 12/86712/2
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 5 Jan 2020 11:20:24 +0000 (12:20 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 5 Jan 2020 13:46:54 +0000 (14:46 +0100)
We can either use direct ByteBuf methods or employ ByteBufUtils
more efficiently.

Change-Id: I5c2c095c12a81007ca581bdd7c6fa493c995c3ca
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/GracefulCapabilityHandler.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/RouteOriginIpv4EcHandler.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/four/octect/as/specific/SourceAS4OctectHandler.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/route/target/RouteTargetIpv4Handler.java

index fa5979f9be636639082e893b2dbe75cf7b3a8463..440f82b82d6a8f76764fe01ac875c8d4afda3c5a 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.bgp.parser.impl.message.open;
 
 import static java.util.Objects.requireNonNull;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
 
 import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
@@ -103,9 +102,9 @@ public final class GracefulCapabilityHandler implements CapabilityParser, Capabi
         Preconditions.checkArgument(timeval >= 0 && timeval <= MAX_RESTART_TIME, "Restart time is " + time);
         final GracefulRestartCapability.RestartFlags flags = grace.getRestartFlags();
         if (flags != null && flags.isRestartState()) {
-            writeUnsignedShort(RESTART_FLAG_STATE | timeval, bytes);
+            bytes.writeShort(RESTART_FLAG_STATE | timeval);
         } else {
-            writeUnsignedShort(timeval, bytes);
+            bytes.writeShort(timeval);
         }
         serializeTables(tables, bytes);
         return bytes;
index 1973e7529d54642df3818b2419f22095c079ad17..75fa2c71c68d8f97a3289932af2715577b0af19f 100644 (file)
@@ -30,7 +30,7 @@ public final class RouteOriginIpv4EcHandler extends AbstractIpv4ExtendedCommunit
                 "The extended community %s is not RouteOriginIpv4Case type.", extendedCommunity);
         final RouteOriginIpv4 routeTarget = ((RouteOriginIpv4Case) extendedCommunity).getRouteOriginIpv4();
         ByteBufWriteUtil.writeIpv4Address(routeTarget.getGlobalAdministrator(), byteAggregator);
-        ByteBufWriteUtil.writeUnsignedShort(routeTarget.getLocalAdministrator(), byteAggregator);
+        ByteBufUtils.writeOrZero(byteAggregator, routeTarget.getLocalAdministrator());
     }
 
     @Override
index f3770abb23c59a399f6ab1b51e180e0344b895ad..1f2316220fd0d0851657959c4dc9e583846cf8f7 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.commun
 import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.protocol.bgp.parser.spi.extended.community.Abstract4OctetAsExtendedCommunity;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.SourceAs4ExtendedCommunityCase;
@@ -25,11 +24,12 @@ public final class SourceAS4OctectHandler extends Abstract4OctetAsExtendedCommun
 
     @Override
     public ExtendedCommunity parseExtendedCommunity(final ByteBuf body) {
-        final SourceAs4ExtendedCommunityBuilder builder = new SourceAs4ExtendedCommunityBuilder();
-        builder.setGlobalAdministrator(new AsNumber(ByteBufUtils.readUint32(body)));
+        final SourceAs4ExtendedCommunityBuilder builder = new SourceAs4ExtendedCommunityBuilder()
+                .setGlobalAdministrator(new AsNumber(ByteBufUtils.readUint32(body)));
         body.skipBytes(LOCAL_LENGTH);
-        return new SourceAs4ExtendedCommunityCaseBuilder().setSourceAs4ExtendedCommunity(
-                builder.build()).build();
+        return new SourceAs4ExtendedCommunityCaseBuilder()
+                .setSourceAs4ExtendedCommunity(builder.build())
+                .build();
     }
 
     @Override
@@ -38,9 +38,9 @@ public final class SourceAS4OctectHandler extends Abstract4OctetAsExtendedCommun
                 "The extended community %s is not SourceAs4ExtendedCommunityCase type.",
                 extendedCommunity);
 
-        body.writeInt(((SourceAs4ExtendedCommunityCase) extendedCommunity).getSourceAs4ExtendedCommunity()
-                .getGlobalAdministrator().getValue().intValue());
-        ByteBufWriteUtil.writeUnsignedShort(LOCAL_ADMIN, body);
+        ByteBufUtils.write(body, ((SourceAs4ExtendedCommunityCase) extendedCommunity).getSourceAs4ExtendedCommunity()
+                .getGlobalAdministrator().getValue());
+        body.writeShort(LOCAL_ADMIN);
     }
 
     @Override
index 135a68c5a5f88adfc7f6f6658c03269ec6ef22eb..0aece7e4912ca7d5c99f7a621edc073318547952 100644 (file)
@@ -8,11 +8,11 @@
 package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.route.target;
 
 import io.netty.buffer.ByteBuf;
-import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
 import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.protocol.util.Ipv4Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.route.target.ipv4.grouping.RouteTargetIpv4;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.route.target.ipv4.grouping.RouteTargetIpv4Builder;
+import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
 
 /**
  * Route Target Ipv4 Handler.
@@ -26,7 +26,7 @@ public final class RouteTargetIpv4Handler {
 
     public static void serialize(final RouteTargetIpv4 routeTarget, final ByteBuf byteAggregator) {
         ByteBufWriteUtil.writeIpv4Address(routeTarget.getGlobalAdministrator(), byteAggregator);
-        ByteBufWriteUtil.writeUnsignedShort(routeTarget.getLocalAdministrator(), byteAggregator);
+        ByteBufUtils.writeOrZero(byteAggregator, routeTarget.getLocalAdministrator());
     }
 
     public static RouteTargetIpv4 parse(final ByteBuf buffer) {