Migrate evpn to use ByteBufUtils 04/86704/1
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 5 Jan 2020 08:51:12 +0000 (09:51 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 5 Jan 2020 08:51:12 +0000 (09:51 +0100)
yangtools is providing utility methods similar to ByteBufWriteUtils,
this patch migrates evpn to use those instead of ours.

Change-Id: Ia2f0e16098d3ef6b89fb5e40b4ada60d0411c240
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/ASGenParser.java
bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/LacpParser.java
bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/LanParser.java
bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/MacParser.java
bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/RouterIdParser.java
bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/ESImpRouteTargetExtCom.java
bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/Layer2AttributesExtCom.java
bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/EthADRParser.java
bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/IncMultEthTagRParser.java
bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/MACIpAdvRParser.java

index 3f10cfe08405d8f01cb44ce0c4a4855f9d30918d..0b6eb7382d2c114e9b48f9635ba6e0e50cd32048 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.protocol.bgp.evpn.impl.esi.types;
 import static com.google.common.base.Preconditions.checkArgument;
 import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.extractAS;
 import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.extractLD;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
@@ -29,8 +28,8 @@ final class ASGenParser extends AbstractEsiType {
     public ByteBuf serializeBody(final Esi esi, final ByteBuf body) {
         checkArgument(esi instanceof AsGeneratedCase, "Unknown esi instance. Passed %s. Needed AsGeneratedCase.", esi);
         final AsGenerated asGen = ((AsGeneratedCase) esi).getAsGenerated();
-        writeUnsignedInt(asGen.getAs().getValue(), body);
-        writeUnsignedInt(asGen.getLocalDiscriminator(), body);
+        ByteBufUtils.write(body, asGen.getAs().getValue());
+        ByteBufUtils.writeOrZero(body, asGen.getLocalDiscriminator());
         return body.writeByte(0);
     }
 
index e3a12066add66a8d9593b9e2a1e1479e4ef651f7..5834d93627ce3065d9ab70ab9e882a182f54f576 100644 (file)
@@ -13,7 +13,6 @@ import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.ext
 
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.IetfYangUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.EsiType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.esi.Esi;
@@ -31,8 +30,8 @@ final class LacpParser extends AbstractEsiType {
         checkArgument(esi instanceof LacpAutoGeneratedCase,
             "Unknown esi instance. Passed %s. Needed LacpAutoGeneratedCase.", esi);
         final LacpAutoGenerated lacp = ((LacpAutoGeneratedCase) esi).getLacpAutoGenerated();
-        body.writeBytes(IetfYangUtil.INSTANCE.bytesFor(lacp.getCeLacpMacAddress()));
-        ByteBufWriteUtil.writeUnsignedShort(lacp.getCeLacpPortKey(), body);
+        body.writeBytes(IetfYangUtil.INSTANCE.macAddressBytes(lacp.getCeLacpMacAddress()));
+        ByteBufUtils.writeOrZero(body, lacp.getCeLacpPortKey());
         return body.writeByte(0);
     }
 
index 4bcfb9df4a37cb944228fdb2b1cf6385e2fb3d27..e6a000bbb938c9dfa2f97c491e3a4157abf265e8 100644 (file)
@@ -13,7 +13,6 @@ import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.ext
 
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.IetfYangUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.EsiType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.esi.Esi;
@@ -31,8 +30,8 @@ final class LanParser extends AbstractEsiType {
         checkArgument(esi instanceof LanAutoGeneratedCase,
             "Unknown esi instance. Passed %s. Needed LanAutoGeneratedCase.", esi);
         final LanAutoGenerated lan = ((LanAutoGeneratedCase) esi).getLanAutoGenerated();
-        body.writeBytes(IetfYangUtil.INSTANCE.bytesFor(lan.getRootBridgeMacAddress()));
-        ByteBufWriteUtil.writeUnsignedShort(lan.getRootBridgePriority(), body);
+        body.writeBytes(IetfYangUtil.INSTANCE.macAddressBytes(lan.getRootBridgeMacAddress()));
+        ByteBufUtils.writeOrZero(body, lan.getRootBridgePriority());
         return body.writeByte(0);
     }
 
index 34bd30cf8c01936c700c37b5a2252eaeeb754dc4..7633410c8af1987255f86754218dd8fc3478c822 100644 (file)
@@ -32,7 +32,7 @@ final class MacParser extends AbstractEsiType {
         Preconditions.checkArgument(esi instanceof MacAutoGeneratedCase,
                 "Unknown esi instance. Passed %s. Needed MacAutoGeneratedCase.", esi.getClass());
         final MacAutoGenerated macAuto = ((MacAutoGeneratedCase) esi).getMacAutoGenerated();
-        body.writeBytes(IetfYangUtil.INSTANCE.bytesFor(macAuto.getSystemMacAddress()));
+        body.writeBytes(IetfYangUtil.INSTANCE.macAddressBytes(macAuto.getSystemMacAddress()));
         ByteBufWriteUtil.writeMedium(macAuto.getLocalDiscriminator().getValue().intValue(), body);
         return body;
     }
index d39f05ac9cbaee38de73903c9d008641112f7556..f29ad02a8b0409f3304698051222bdb1ce306e89 100644 (file)
@@ -31,7 +31,7 @@ final class RouterIdParser extends AbstractEsiType {
             "Unknown esi instance. Passed %s. Needed RouterIdGeneratedCase.", esi);
         final RouterIdGenerated routerID = ((RouterIdGeneratedCase) esi).getRouterIdGenerated();
         ByteBufWriteUtil.writeIpv4Address(routerID.getRouterId(), body);
-        ByteBufWriteUtil.writeUnsignedInt(routerID.getLocalDiscriminator(), body);
+        ByteBufUtils.writeOrZero(body, routerID.getLocalDiscriminator());
         return body.writeByte(0);
     }
 
index 0df285023c6915b4bff5c19d7d2980427b84c504..6a199967e10db6dbd3bd600a7c9c095d59102481 100644 (file)
@@ -37,7 +37,7 @@ public final class ESImpRouteTargetExtCom extends AbstractExtendedCommunities {
                 extendedCommunity);
         final EsImportRouteExtendedCommunity extCom = ((EsImportRouteExtendedCommunityCase) extendedCommunity)
                 .getEsImportRouteExtendedCommunity();
-        byteAggregator.writeBytes(IetfYangUtil.INSTANCE.bytesFor(extCom.getEsImport()));
+        byteAggregator.writeBytes(IetfYangUtil.INSTANCE.macAddressBytes(extCom.getEsImport()));
     }
 
     @Override
index 99c98b1a6c3453084865347b97a7eb37f6b05171..a55e802003b0c4cf5be99fed63b8c4fd1111438d 100644 (file)
@@ -11,7 +11,6 @@ import com.google.common.base.Preconditions;
 import com.google.common.primitives.UnsignedBytes;
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.protocol.util.BitArray;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.NormalizationType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.OperationalMode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.Layer2AttributesExtendedCommunityCase;
@@ -43,16 +42,17 @@ public class Layer2AttributesExtCom extends AbstractExtendedCommunities {
 
     @Override
     public ExtendedCommunity parseExtendedCommunity(final ByteBuf body) {
-        final Layer2AttributesExtendedCommunityBuilder builder = new Layer2AttributesExtendedCommunityBuilder();
         final BitArray flags = BitArray.valueOf(body, FLAGS_SIZE);
-        builder.setBackupPe(flags.get(BACKUP_PE_OFFSET));
-        builder.setPrimaryPe(flags.get(PRIMARY_PE_OFFSET));
-        builder.setControlWord(flags.get(CONTROL_WORD_OFFSET));
 
-        builder.setModeOfOperation(OperationalMode.forValue(getFlagShort(flags, MODE_OF_OPERATION)));
-        builder.setOperatingPer(NormalizationType.forValue(getFlagShort(flags, NORMALIZATION_TYPE)));
+        final Layer2AttributesExtendedCommunityBuilder builder = new Layer2AttributesExtendedCommunityBuilder()
+                .setBackupPe(flags.get(BACKUP_PE_OFFSET))
+                .setPrimaryPe(flags.get(PRIMARY_PE_OFFSET))
+                .setControlWord(flags.get(CONTROL_WORD_OFFSET))
 
-        builder.setL2Mtu(ByteBufUtils.readUint16(body));
+                .setModeOfOperation(OperationalMode.forValue(getFlagShort(flags, MODE_OF_OPERATION)))
+                .setOperatingPer(NormalizationType.forValue(getFlagShort(flags, NORMALIZATION_TYPE)))
+
+                .setL2Mtu(ByteBufUtils.readUint16(body));
         body.skipBytes(RESERVED);
         return new Layer2AttributesExtendedCommunityCaseBuilder()
                 .setLayer2AttributesExtendedCommunity(builder.build()).build();
@@ -85,8 +85,8 @@ public class Layer2AttributesExtCom extends AbstractExtendedCommunities {
             aux = (byte) (aux << FIVE_BITS_SHIFT);
             res[res.length - 1] = (byte) (res[res.length - 1] | aux);
         }
-        ByteBufWriteUtil.writeUnsignedShort((int) res[res.length - 1], body);
-        ByteBufWriteUtil.writeUnsignedShort(extCom.getL2Mtu(), body);
+        body.writeShort(res[res.length - 1]);
+        ByteBufUtils.writeOrZero(body, extCom.getL2Mtu());
         body.writeZero(RESERVED);
     }
 
index 92a4530e70dedab3ef5cb481c2c714c4db8aa142..4587d74337729b8182a0ee73f5799efa70c41a07 100644 (file)
@@ -17,7 +17,6 @@ import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import org.opendaylight.protocol.bgp.evpn.spi.pojo.SimpleEsiTypeRegistry;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.NlriType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.esi.Esi;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.ethernet.a.d.route.EthernetADRoute;
@@ -61,7 +60,7 @@ final class EthADRParser extends AbstractEvpnNlri {
         final EthernetADRoute evpn = ((EthernetADRouteCase) evpnChoice).getEthernetADRoute();
         final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
         SimpleEsiTypeRegistry.getInstance().serializeEsi(evpn.getEsi(), body);
-        ByteBufWriteUtil.writeUnsignedInt(evpn.getEthernetTagId().getVlanId(), body);
+        ByteBufUtils.writeOrZero(body, evpn.getEthernetTagId().getVlanId());
 
         final MplsLabel mpls = evpn.getMplsLabel();
         if (mpls != null) {
@@ -83,9 +82,8 @@ final class EthADRParser extends AbstractEvpnNlri {
     }
 
     private static EthernetADRouteBuilder serializeKeyModel(final ContainerNode evpn) {
-        final EthernetADRouteBuilder builder = new EthernetADRouteBuilder();
-        builder.setEsi(serializeEsi(evpn));
-        builder.setEthernetTagId(extractETI(evpn));
-        return builder;
+        return new EthernetADRouteBuilder()
+                .setEsi(serializeEsi(evpn))
+                .setEthernetTagId(extractETI(evpn));
     }
 }
index a06cf5d1429a52650f06fa8c148cc8cea6e101f7..0adef2f87c332f9234c77627809b5df383de31f6 100644 (file)
@@ -14,7 +14,6 @@ import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import org.opendaylight.bgp.concepts.IpAddressUtil;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.NlriType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.ethernet.tag.id.EthernetTagId;
@@ -66,7 +65,7 @@ final class IncMultEthTagRParser extends AbstractEvpnNlri {
 
         final IncMultiEthernetTagRes evpn = ((IncMultiEthernetTagResCase) evpnChoice).getIncMultiEthernetTagRes();
         final ByteBuf body = Unpooled.buffer();
-        ByteBufWriteUtil.writeUnsignedInt(evpn.getEthernetTagId().getVlanId(), body);
+        ByteBufUtils.writeOrZero(body, evpn.getEthernetTagId().getVlanId());
         final ByteBuf orig = IpAddressUtil.bytesFor(evpn.getOrigRouteIp());
         Preconditions.checkArgument(orig.readableBytes() > 0);
         body.writeBytes(orig);
index 87e38b1f5ee3c48974360d2cc9a9f61e569868c7..092fbcabdcd22f7cdef35bfdf3cdf25f87ea49d3 100644 (file)
@@ -21,7 +21,6 @@ import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import org.opendaylight.protocol.bgp.evpn.spi.pojo.SimpleEsiTypeRegistry;
 import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.protocol.util.Ipv4Util;
 import org.opendaylight.protocol.util.Ipv6Util;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
@@ -81,11 +80,11 @@ final class MACIpAdvRParser extends AbstractEvpnNlri {
         if (esi != null) {
             SimpleEsiTypeRegistry.getInstance().serializeEsi(evpn.getEsi(), body);
         }
-        ByteBufWriteUtil.writeUnsignedInt(evpn.getEthernetTagId().getVlanId(), body);
+        ByteBufUtils.writeOrZero(body, evpn.getEthernetTagId().getVlanId());
 
         final MacAddress mac = evpn.getMacAddress();
         body.writeByte(MAC_ADDRESS_LENGTH * BITS_SIZE);
-        body.writeBytes(IetfYangUtil.INSTANCE.bytesFor(mac));
+        body.writeBytes(IetfYangUtil.INSTANCE.macAddressBytes(mac));
         final ByteBuf ipAddress = serializeIp(evpn.getIpAddress());
         Preconditions.checkArgument(ipAddress.readableBytes() > 0);
         body.writeBytes(ipAddress);