Move ipv4/ipv6 ByteBuf utilities to Ipv{4,6}Util 46/86746/4
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 6 Jan 2020 15:43:16 +0000 (16:43 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 6 Jan 2020 18:33:07 +0000 (19:33 +0100)
There is little point in criss-crossing between util classes
and ByteBufWriteUtil -- move the methods so they are hosted
in their appropriate classes.

Change-Id: Ifa3326c03372b86843ce45b5c72782142e10d9a5
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
55 files changed:
bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/RouterIdParser.java
bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/RedirectIpNextHopEcHandler.java
bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/RedirectIpv4EcHandler.java
bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv4DestinationPrefixHandler.java
bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv4SourcePrefixHandler.java
bgp/extensions/inet/src/main/java/org/opendaylight/protocol/bgp/inet/codec/Ipv4NlriParser.java
bgp/extensions/inet/src/main/java/org/opendaylight/protocol/bgp/inet/codec/Ipv6NlriParser.java
bgp/extensions/inet/src/test/java/org/opendaylight/protocol/bgp/inet/codec/Ipv4NlriParserTest.java
bgp/extensions/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/mcast/nlri/L3vpnMcastNlriSerializer.java
bgp/extensions/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/LUNlriParser.java
bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/BgpRouterIdTlvParser.java
bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/Ipv4InterfaceTlvParser.java
bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/Ipv4NeighborTlvParser.java
bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/Ipv6InterfaceTlvParser.java
bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/Ipv6NeighborTlvParser.java
bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/ReachTlvParser.java
bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/AbstractTeLspNlriCodec.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPUpdateMessageParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/Ipv4SpecificEcHandler.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/route/target/RouteTargetIpv4Handler.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/extended/community/Inet4SpecificExtendedCommunityCommonUtil.java
bmp/bmp-parser-impl/src/main/java/org/opendaylight/protocol/bmp/parser/message/PeerUpHandler.java
bmp/bmp-spi/src/main/java/org/opendaylight/protocol/bmp/spi/parser/AbstractBmpPerPeerMessageParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/AbstractPccIdReqObjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/AbstractPceIdObjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/end/points/PCEPEndPointsIpv4ObjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/end/points/PCEPEndPointsIpv6ObjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/end/points/PCEPP2MPEndPointsIpv4ObjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/end/points/PCEPP2MPEndPointsIpv6ObjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/unreach/PCEPIpv4UnreachDestinationParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/unreach/PCEPIpv6UnreachDestinationParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/EROIpv4PrefixSubobjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/EROIpv6PrefixSubobjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/RROIpv4PrefixSubobjectParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/RROIpv6PrefixSubobjectParser.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/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LSPIdentifierIpv4TlvParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LSPIdentifierIpv6TlvParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07RSVPErrorSpecTlvParser.java
pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/segment/routing/AbstractSrSubobjectParser.java
rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/ero/EROIpv4PrefixSubobjectParser.java
rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/ero/EROIpv6PrefixSubobjectParser.java
rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/rro/RROIpv4PrefixSubobjectParser.java
rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/rro/RROIpv6PrefixSubobjectParser.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/te/DetourObjectIpv4Parser.java
util/src/main/java/org/opendaylight/protocol/util/ByteBufWriteUtil.java
util/src/main/java/org/opendaylight/protocol/util/Ipv4Util.java
util/src/main/java/org/opendaylight/protocol/util/Ipv6Util.java
util/src/test/java/org/opendaylight/protocol/util/ByteBufWriteUtilTest.java
util/src/test/java/org/opendaylight/protocol/util/Ipv4UtilTest.java [new file with mode: 0644]
util/src/test/java/org/opendaylight/protocol/util/Ipv6UtilTest.java [new file with mode: 0644]

index f29ad02a8b0409f3304698051222bdb1ce306e89..4cb3fb8a5f4e7ab4c1281041e452ed212a70b86c 100644 (file)
@@ -12,7 +12,6 @@ import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.ext
 import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.extractRD;
 
 import io.netty.buffer.ByteBuf;
-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.evpn.rev180329.EsiType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.esi.Esi;
@@ -30,7 +29,7 @@ final class RouterIdParser extends AbstractEsiType {
         checkArgument(esi instanceof RouterIdGeneratedCase,
             "Unknown esi instance. Passed %s. Needed RouterIdGeneratedCase.", esi);
         final RouterIdGenerated routerID = ((RouterIdGeneratedCase) esi).getRouterIdGenerated();
-        ByteBufWriteUtil.writeIpv4Address(routerID.getRouterId(), body);
+        Ipv4Util.writeIpv4Address(routerID.getRouterId(), body);
         ByteBufUtils.writeOrZero(body, routerID.getLocalDiscriminator());
         return body.writeByte(0);
     }
index 647e5353e70b01868f4927c6a6cfcfa87c746640..bcb643d51457d931ae5c84153d23b431fd50d80d 100644 (file)
@@ -12,7 +12,6 @@ import static com.google.common.base.Preconditions.checkArgument;
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunityParser;
 import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunitySerializer;
-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;
@@ -37,9 +36,9 @@ public class RedirectIpNextHopEcHandler implements ExtendedCommunityParser, Exte
                 .getRedirectIpNhExtendedCommunity();
         final IpAddress nextHopAddress = redirect.getNextHopAddress();
         if (nextHopAddress.getIpv4Address() != null) {
-            ByteBufWriteUtil.writeIpv4Address(nextHopAddress.getIpv4Address(), byteAggregator);
+            Ipv4Util.writeIpv4Address(nextHopAddress.getIpv4Address(), byteAggregator);
         } else {
-            ByteBufWriteUtil.writeIpv6Address(nextHopAddress.getIpv6Address(), byteAggregator);
+            Ipv6Util.writeIpv6Address(nextHopAddress.getIpv6Address(), byteAggregator);
         }
         byteAggregator.writeShort(Boolean.TRUE.equals(redirect.isCopy()) ? 1 : 0);
     }
index d31b5eed5a78e80fc6bc3ed19dfcc25110eff25b..3c3cf7ec4b8d477c9fbab88518f0f703691f3369 100644 (file)
@@ -12,7 +12,6 @@ import static com.google.common.base.Preconditions.checkArgument;
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunityParser;
 import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunitySerializer;
-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.flowspec.rev180329.redirect.ipv4.extended.community.RedirectIpv4;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.redirect.ipv4.extended.community.RedirectIpv4Builder;
@@ -31,7 +30,7 @@ public class RedirectIpv4EcHandler implements ExtendedCommunityParser, ExtendedC
                 "The extended community %s is not RedirectIpv4ExtendedCommunityCase type.", extendedCommunity);
         final RedirectIpv4 redirect = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec
                 .rev180329.RedirectIpv4ExtendedCommunity) extendedCommunity).getRedirectIpv4();
-        ByteBufWriteUtil.writeIpv4Address(redirect.getGlobalAdministrator(), byteAggregator);
+        Ipv4Util.writeIpv4Address(redirect.getGlobalAdministrator(), byteAggregator);
         ByteBufUtils.writeOrZero(byteAggregator, redirect.getLocalAdministrator());
     }
 
index f12849d14511a746dff2e5bfd693e0eb66c83d85..1c5ed2b4b305f672aee909dca761680a7a4a3f63 100644 (file)
@@ -11,7 +11,6 @@ import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Objects.requireNonNull;
 
 import io.netty.buffer.ByteBuf;
-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.flowspec.rev180329.flowspec.destination.flowspec.FlowspecType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.group.ipv4.flowspec.flowspec.type.DestinationPrefixCase;
@@ -24,7 +23,7 @@ public final class FSIpv4DestinationPrefixHandler implements FlowspecTypeParser,
     public void serializeType(final FlowspecType value, final ByteBuf output) {
         checkArgument(value instanceof DestinationPrefixCase, "DestinationPrefixCase class is mandatory!");
         output.writeByte(DESTINATION_PREFIX_VALUE);
-        ByteBufWriteUtil.writeMinimalPrefix(((DestinationPrefixCase) value).getDestinationPrefix(), output);
+        Ipv4Util.writeMinimalPrefix(((DestinationPrefixCase) value).getDestinationPrefix(), output);
     }
 
     @Override
index c222eebabd18776edf758e985d3a4d60276cdc01..3205567967dc6a5e5ac43cf1d39cb261253fbb70 100644 (file)
@@ -7,11 +7,10 @@
  */
 package org.opendaylight.protocol.bgp.flowspec.handlers;
 
+import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Objects.requireNonNull;
 
-import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
-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.flowspec.rev180329.flowspec.destination.flowspec.FlowspecType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.group.ipv4.flowspec.flowspec.type.SourcePrefixCase;
@@ -22,9 +21,9 @@ public final class FSIpv4SourcePrefixHandler implements FlowspecTypeParser, Flow
 
     @Override
     public void serializeType(final FlowspecType value, final ByteBuf output) {
-        Preconditions.checkArgument(value instanceof SourcePrefixCase, "SourcePrefixCase class is mandatory!");
+        checkArgument(value instanceof SourcePrefixCase, "SourcePrefixCase class is mandatory!");
         output.writeByte(SOURCE_PREFIX_VALUE);
-        ByteBufWriteUtil.writeMinimalPrefix(((SourcePrefixCase) value).getSourcePrefix(), output);
+        Ipv4Util.writeMinimalPrefix(((SourcePrefixCase) value).getSourcePrefix(), output);
     }
 
     @Override
index 3064f0077810d65491f05138980b5ef0fa1aeced..70d1426a93ad7b27f84daff88c19bb127db19e7e 100644 (file)
@@ -5,7 +5,6 @@
  * 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.bgp.inet.codec;
 
 import io.netty.buffer.ByteBuf;
@@ -17,7 +16,6 @@ import org.opendaylight.protocol.bgp.parser.spi.NlriParser;
 import org.opendaylight.protocol.bgp.parser.spi.NlriSerializer;
 import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
 import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
-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.inet.rev180329.ipv4.prefixes.DestinationIpv4;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.prefixes.DestinationIpv4Builder;
@@ -82,7 +80,7 @@ public final class Ipv4NlriParser implements NlriParser, NlriSerializer {
                         (DestinationIpv4Case) advertizedRoutes.getDestinationType();
                 for (final Ipv4Prefixes ipv4Prefix : destinationIpv4Case.getDestinationIpv4().getIpv4Prefixes()) {
                     PathIdUtil.writePathId(ipv4Prefix.getPathId(), byteAggregator);
-                    ByteBufWriteUtil.writeMinimalPrefix(ipv4Prefix.getPrefix(), byteAggregator);
+                    Ipv4Util.writeMinimalPrefix(ipv4Prefix.getPrefix(), byteAggregator);
                 }
             }
         } else if (pathAttributes2 != null) {
@@ -97,7 +95,7 @@ public final class Ipv4NlriParser implements NlriParser, NlriSerializer {
                         .destination.type.DestinationIpv4Case) withdrawnRoutes.getDestinationType();
                 for (final Ipv4Prefixes ipv4Prefix : destinationIpv4Case.getDestinationIpv4().getIpv4Prefixes()) {
                     PathIdUtil.writePathId(ipv4Prefix.getPathId(), byteAggregator);
-                    ByteBufWriteUtil.writeMinimalPrefix(ipv4Prefix.getPrefix(), byteAggregator);
+                    Ipv4Util.writeMinimalPrefix(ipv4Prefix.getPrefix(), byteAggregator);
                 }
             }
         }
index 7af69ba40f14613a237edf553a7305b3ab66060e..12ee5b1820737743b0226953f88ee872576de99a 100644 (file)
@@ -5,7 +5,6 @@
  * 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.bgp.inet.codec;
 
 import io.netty.buffer.ByteBuf;
@@ -17,7 +16,6 @@ import org.opendaylight.protocol.bgp.parser.spi.NlriParser;
 import org.opendaylight.protocol.bgp.parser.spi.NlriSerializer;
 import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
 import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.protocol.util.Ipv6Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.prefixes.DestinationIpv6;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.prefixes.DestinationIpv6Builder;
@@ -82,7 +80,7 @@ public final class Ipv6NlriParser implements NlriParser, NlriSerializer {
                         (DestinationIpv6Case) advertizedRoutes.getDestinationType();
                 for (final Ipv6Prefixes ipv6Prefix : destinationIpv6Case.getDestinationIpv6().getIpv6Prefixes()) {
                     PathIdUtil.writePathId(ipv6Prefix.getPathId(), byteAggregator);
-                    ByteBufWriteUtil.writeMinimalPrefix(ipv6Prefix.getPrefix(), byteAggregator);
+                    Ipv6Util.writeMinimalPrefix(ipv6Prefix.getPrefix(), byteAggregator);
                 }
             }
         } else if (pathAttributes2 != null) {
@@ -98,7 +96,7 @@ public final class Ipv6NlriParser implements NlriParser, NlriSerializer {
                                 .DestinationIpv6Case) withdrawnRoutes.getDestinationType();
                 for (final Ipv6Prefixes ipv6Prefix : destinationIpv6Case.getDestinationIpv6().getIpv6Prefixes()) {
                     PathIdUtil.writePathId(ipv6Prefix.getPathId(), byteAggregator);
-                    ByteBufWriteUtil.writeMinimalPrefix(ipv6Prefix.getPrefix(), byteAggregator);
+                    Ipv6Util.writeMinimalPrefix(ipv6Prefix.getPrefix(), byteAggregator);
                 }
             }
         }
index e9e128aeed88c761a3739f0d551f6d6aec78613a..c8a9a18b505b4fb9075247ffa6d9bd9f1f521eae 100644 (file)
@@ -5,7 +5,6 @@
  * 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.bgp.inet.codec;
 
 import static org.junit.Assert.assertEquals;
@@ -27,7 +26,7 @@ import org.mockito.MockitoAnnotations;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.bgp.parser.spi.MultiPathSupport;
 import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
+import org.opendaylight.protocol.util.Ipv4Util;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.prefixes.DestinationIpv4Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.prefixes.destination.ipv4.Ipv4Prefixes;
@@ -106,11 +105,11 @@ public class Ipv4NlriParserTest {
                 .setIpv4Prefixes(fakePrefixes).build()).build();
 
         final ByteBuf buffer1 = Unpooled.buffer(5);
-        ByteBufWriteUtil.writeMinimalPrefix(prefix1, buffer1);
+        Ipv4Util.writeMinimalPrefix(prefix1, buffer1);
         this.inputBytes.writeBytes(buffer1.array());
 
         final ByteBuf buffer2 = Unpooled.buffer(5);
-        ByteBufWriteUtil.writeMinimalPrefix(prefix2, buffer2);
+        Ipv4Util.writeMinimalPrefix(prefix2, buffer2);
         this.inputBytes.writeBytes(buffer2.array());
 
         Mockito.doReturn(Optional.of(this.muliPathSupport)).when(this.constraint).getPeerConstraint(Mockito.any());
index eaa0dc4c042f3e43c7ffce8b9047861c721cff48..2fa9a3ce3636c143f2bcd35b872cf5b37c944306 100644 (file)
@@ -7,15 +7,12 @@
  */
 package org.opendaylight.protocol.bgp.l3vpn.mcast.nlri;
 
-import static org.opendaylight.protocol.util.Ipv6Util.IPV6_BITS_LENGTH;
-
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import java.util.ArrayList;
 import java.util.List;
 import org.opendaylight.bgp.concepts.RouteDistinguisherUtil;
 import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
-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.IpPrefix;
@@ -38,7 +35,7 @@ public final class L3vpnMcastNlriSerializer {
 
             final int initialLength = nlri.readableBytes();
             builder.setRouteDistinguisher(RouteDistinguisherUtil.parseRouteDistinguisher(nlri));
-            if (length == IPV6_BITS_LENGTH) {
+            if (length == Ipv6Util.IPV6_BITS_LENGTH) {
                 builder.setPrefix(new IpPrefix(Ipv6Util.prefixForByteBuf(nlri)));
             } else {
                 builder.setPrefix(new IpPrefix(Ipv4Util.prefixForByteBuf(nlri)));
@@ -61,10 +58,10 @@ public final class L3vpnMcastNlriSerializer {
             final IpPrefix prefix = dest.getPrefix();
             if (prefix.getIpv4Prefix() != null) {
                 output.writeByte(Ipv4Util.IP4_BITS_LENGTH);
-                ByteBufWriteUtil.writeMinimalPrefix(prefix.getIpv4Prefix(), prefixBuf);
+                Ipv4Util.writeMinimalPrefix(prefix.getIpv4Prefix(), prefixBuf);
             } else {
-                output.writeByte(IPV6_BITS_LENGTH);
-                ByteBufWriteUtil.writeMinimalPrefix(prefix.getIpv6Prefix(), prefixBuf);
+                output.writeByte(Ipv6Util.IPV6_BITS_LENGTH);
+                Ipv6Util.writeMinimalPrefix(prefix.getIpv6Prefix(), prefixBuf);
             }
             // FIXME: remove this funky loop
             while (prefixBuf.readableBytes() % 8 != 0) {
index a34da0d4fb594621e05dd12ba95b925790b029ae..44ebe7066ab389e445ee8ddb0cd0b28cf8f85bc4 100644 (file)
@@ -20,7 +20,6 @@ import org.opendaylight.protocol.bgp.parser.spi.NlriSerializer;
 import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
 import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
 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.protocol.util.MplsLabelUtil;
@@ -162,9 +161,9 @@ public class LUNlriParser implements NlriParser, NlriSerializer {
         final ByteBuf buffer = Unpooled.buffer();
 
         if (prefix.getIpv4Prefix() != null) {
-            ByteBufWriteUtil.writeMinimalPrefix(prefix.getIpv4Prefix(), buffer);
+            Ipv4Util.writeMinimalPrefix(prefix.getIpv4Prefix(), buffer);
         } else {
-            ByteBufWriteUtil.writeMinimalPrefix(prefix.getIpv6Prefix(), buffer);
+            Ipv6Util.writeMinimalPrefix(prefix.getIpv6Prefix(), buffer);
         }
         return ByteArray.readAllBytes(buffer);
     }
index 1dde64647f92dc2be6f3072033dca04fc2fc9e32..fd4f76b8a0efcfb4b4c289eab6c6ee3b7e580ca7 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.protocol.bgp.linkstate.impl.tlvs;
 
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.protocol.util.Ipv4Util;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.epe.rev150622.EpeNodeDescriptors;
@@ -17,14 +16,13 @@ import org.opendaylight.yangtools.yang.common.QName;
 
 public final class BgpRouterIdTlvParser implements LinkstateTlvParser<Ipv4Address>,
         LinkstateTlvParser.LinkstateTlvSerializer<Ipv4Address> {
-
     private static final int BGP_ROUTER_ID = 516;
 
     public static final QName BGP_ROUTER_ID_QNAME = QName.create(EpeNodeDescriptors.QNAME, "bgp-router-id").intern();
 
     @Override
     public void serializeTlvBody(final Ipv4Address tlv, final ByteBuf body) {
-        ByteBufWriteUtil.writeIpv4Address(tlv, body);
+        Ipv4Util.writeIpv4Address(tlv, body);
     }
 
     @Override
index 5f2be7273c48088abcad6a53831535fe5d8fcd08..34cdd6e2546040e9fae62afe16306eaf30429ba5 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.protocol.bgp.linkstate.impl.tlvs;
 
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
-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.linkstate.rev180329.Ipv4InterfaceIdentifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.link._case.LinkDescriptors;
@@ -17,7 +16,6 @@ import org.opendaylight.yangtools.yang.common.QName;
 
 public final class Ipv4InterfaceTlvParser implements LinkstateTlvParser<Ipv4InterfaceIdentifier>,
         LinkstateTlvParser.LinkstateTlvSerializer<Ipv4InterfaceIdentifier> {
-
     private static final int IPV4_IFACE_ADDRESS = 259;
 
     public static final QName IPV4_IFACE_ADDRESS_QNAME = QName.create(LinkDescriptors.QNAME, "ipv4-interface-address")
@@ -25,7 +23,7 @@ public final class Ipv4InterfaceTlvParser implements LinkstateTlvParser<Ipv4Inte
 
     @Override
     public void serializeTlvBody(final Ipv4InterfaceIdentifier tlv, final ByteBuf body) {
-        ByteBufWriteUtil.writeIpv4Address(tlv, body);
+        Ipv4Util.writeIpv4Address(tlv, body);
     }
 
     @Override
index 9524a6e4d1df7a99a7f8af6a69c0656eb0db57e5..51c8639e31a1b465f03694185bf2a1a47774d944 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.protocol.bgp.linkstate.impl.tlvs;
 
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
-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.linkstate.rev180329.Ipv4InterfaceIdentifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.link._case.LinkDescriptors;
@@ -17,15 +16,14 @@ import org.opendaylight.yangtools.yang.common.QName;
 
 public final class Ipv4NeighborTlvParser implements LinkstateTlvParser<Ipv4InterfaceIdentifier>,
         LinkstateTlvParser.LinkstateTlvSerializer<Ipv4InterfaceIdentifier> {
-
-    private static final int IPV4_NEIGHBOR_ADDRESS = 260;
-
     public static final QName IPV4_NEIGHBOR_ADDRESS_QNAME = QName.create(LinkDescriptors.QNAME, "ipv4-neighbor-address")
             .intern();
 
+    private static final int IPV4_NEIGHBOR_ADDRESS = 260;
+
     @Override
     public void serializeTlvBody(final Ipv4InterfaceIdentifier tlv, final ByteBuf body) {
-        ByteBufWriteUtil.writeIpv4Address(tlv, body);
+        Ipv4Util.writeIpv4Address(tlv, body);
     }
 
     @Override
index b4c7398b109946892d9211bb5f61c1d591d788a1..2c3b238843e98acf37526933d2d60417b92af696 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.protocol.bgp.linkstate.impl.tlvs;
 
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.protocol.util.Ipv6Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.Ipv6InterfaceIdentifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.link._case.LinkDescriptors;
@@ -17,7 +16,6 @@ import org.opendaylight.yangtools.yang.common.QName;
 
 public final class Ipv6InterfaceTlvParser implements LinkstateTlvParser<Ipv6InterfaceIdentifier>,
         LinkstateTlvParser.LinkstateTlvSerializer<Ipv6InterfaceIdentifier> {
-
     private static final int IPV6_IFACE_ADDRESS = 261;
 
     public static final QName IPV6_IFACE_ADDRESS_QNAME = QName.create(LinkDescriptors.QNAME, "ipv6-interface-address")
@@ -25,7 +23,7 @@ public final class Ipv6InterfaceTlvParser implements LinkstateTlvParser<Ipv6Inte
 
     @Override
     public void serializeTlvBody(final Ipv6InterfaceIdentifier tlv, final ByteBuf body) {
-        ByteBufWriteUtil.writeIpv6Address(tlv, body);
+        Ipv6Util.writeIpv6Address(tlv, body);
     }
 
     @Override
index fb254d4a8e774c0c1f5ca5003b576293a01163e9..24e6cd223bf931636718ae831bf1065d7a216cc3 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.protocol.bgp.linkstate.impl.tlvs;
 
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.protocol.util.Ipv6Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.Ipv6InterfaceIdentifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.link._case.LinkDescriptors;
@@ -17,7 +16,6 @@ import org.opendaylight.yangtools.yang.common.QName;
 
 public final class Ipv6NeighborTlvParser implements LinkstateTlvParser<Ipv6InterfaceIdentifier>,
         LinkstateTlvParser.LinkstateTlvSerializer<Ipv6InterfaceIdentifier> {
-
     private static final int IPV6_NEIGHBOR_ADDRESS = 262;
 
     public static final QName IPV6_NEIGHBOR_ADDRESS_QNAME = QName.create(LinkDescriptors.QNAME, "ipv6-neighbor-address")
@@ -25,7 +23,7 @@ public final class Ipv6NeighborTlvParser implements LinkstateTlvParser<Ipv6Inter
 
     @Override
     public void serializeTlvBody(final Ipv6InterfaceIdentifier tlv, final ByteBuf body) {
-        ByteBufWriteUtil.writeIpv6Address(tlv, body);
+        Ipv6Util.writeIpv6Address(tlv, body);
     }
 
     @Override
index 1ca75ec1c1d8f540b80d7d3ec82b231d9ef1ae51..d47be628dfbc46049f5efeb366b81311b227d4ea 100644 (file)
@@ -11,8 +11,8 @@ import com.google.common.annotations.VisibleForTesting;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
-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.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;
@@ -45,9 +45,9 @@ public final class ReachTlvParser implements LinkstateTlvParser.LinkstateTlvSeri
     @Override
     public void serializeTlvBody(final IpPrefix tlv, final ByteBuf body) {
         if (tlv.getIpv4Prefix() != null) {
-            ByteBufWriteUtil.writeMinimalPrefix(tlv.getIpv4Prefix(), body);
+            Ipv4Util.writeMinimalPrefix(tlv.getIpv4Prefix(), body);
         } else if (tlv.getIpv6Prefix() != null) {
-            ByteBufWriteUtil.writeMinimalPrefix(tlv.getIpv6Prefix(), body);
+            Ipv6Util.writeMinimalPrefix(tlv.getIpv6Prefix(), body);
         }
     }
 
@@ -57,17 +57,18 @@ public final class ReachTlvParser implements LinkstateTlvParser.LinkstateTlvSeri
     }
 
     public static IpPrefix serializeModel(final ContainerNode prefixDesc) {
-        if (prefixDesc.getChild(IP_REACH_NID).isPresent()) {
-            final String prefix = (String) prefixDesc.getChild(IP_REACH_NID).get().getValue();
-            try {
-                final ByteBuf buffer = Unpooled.buffer(5);
-                ByteBufWriteUtil.writeMinimalPrefix(new Ipv4Prefix(prefix), buffer);
-                return new IpPrefix(new Ipv4Prefix(prefix));
-            } catch (final IllegalArgumentException e) {
-                LOG.debug("Creating Ipv6 prefix because", e);
-                return new IpPrefix(new Ipv6Prefix(prefix));
-            }
-        }
-        return null;
+        return prefixDesc.getChild(IP_REACH_NID)
+                .map(child -> {
+                    final String prefix = (String) child.getValue();
+                    try {
+                        final ByteBuf buffer = Unpooled.buffer(5);
+                        Ipv4Util.writeMinimalPrefix(new Ipv4Prefix(prefix), buffer);
+                        return new IpPrefix(new Ipv4Prefix(prefix));
+                    } catch (final IllegalArgumentException e) {
+                        LOG.debug("Creating Ipv6 prefix because", e);
+                        return new IpPrefix(new Ipv6Prefix(prefix));
+                    }
+                })
+                .orElse(null);
     }
 }
index 7813f2d9f2ae78924a234511dd02120c9c0f5873..58cfd5d90457087321cfbcdb5c0f2c1d4f78f756 100644 (file)
@@ -7,10 +7,12 @@
  */
 package org.opendaylight.protocol.bgp.linkstate.spi;
 
+import static com.google.common.base.Preconditions.checkArgument;
+
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
-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.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.ObjectType;
@@ -89,7 +91,7 @@ public abstract class AbstractTeLspNlriCodec extends AbstractNlriTypeCodec {
 
     @Override
     protected final void serializeObjectType(final ObjectType objectType, final ByteBuf buffer) {
-        Preconditions.checkArgument(objectType instanceof TeLspCase);
+        checkArgument(objectType instanceof TeLspCase);
         final TeLspCase teLSP = (TeLspCase) objectType;
         final AddressFamily addressFamily = teLSP.getAddressFamily();
         if (addressFamily instanceof Ipv4Case) {
@@ -100,15 +102,15 @@ public abstract class AbstractTeLspNlriCodec extends AbstractNlriTypeCodec {
     }
 
     private static void serializeIpv4Case(final TeLspCase teLSP, final Ipv4Case ipv4Case, final ByteBuf buffer) {
-        ByteBufWriteUtil.writeIpv4Address(ipv4Case.getIpv4TunnelSenderAddress(), buffer);
+        Ipv4Util.writeIpv4Address(ipv4Case.getIpv4TunnelSenderAddress(), buffer);
         serializeTunnelIdAndLspId(buffer, teLSP);
-        ByteBufWriteUtil.writeIpv4Address(ipv4Case.getIpv4TunnelEndpointAddress(), buffer);
+        Ipv4Util.writeIpv4Address(ipv4Case.getIpv4TunnelEndpointAddress(), buffer);
     }
 
     private static void serializeIpv6Case(final TeLspCase teLSP, final Ipv6Case ipv6Case, final ByteBuf buffer) {
-        ByteBufWriteUtil.writeIpv6Address(ipv6Case.getIpv6TunnelSenderAddress(), buffer);
+        Ipv6Util.writeIpv6Address(ipv6Case.getIpv6TunnelSenderAddress(), buffer);
         serializeTunnelIdAndLspId(buffer, teLSP);
-        ByteBufWriteUtil.writeIpv6Address(ipv6Case.getIpv6TunnelEndpointAddress(), buffer);
+        Ipv6Util.writeIpv6Address(ipv6Case.getIpv6TunnelEndpointAddress(), buffer);
     }
 
     private static void serializeTunnelIdAndLspId(final ByteBuf buffer, final TeLspCase teLSP) {
index 7e4154eec7b156ed3ac0e728a9b348ba7fcbfd2b..77da9019c3c1dad678b83cd2339613174d129e70 100755 (executable)
@@ -7,9 +7,9 @@
  */
 package org.opendaylight.protocol.bgp.parser.impl.message;
 
+import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Objects.requireNonNull;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Streams;
 import io.netty.buffer.ByteBuf;
@@ -35,7 +35,6 @@ import org.opendaylight.protocol.bgp.parser.spi.ParsedAttributes;
 import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
 import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
 import org.opendaylight.protocol.bgp.parser.spi.RevisedErrorHandling;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.protocol.util.Ipv4Util;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId;
@@ -65,13 +64,11 @@ import org.slf4j.LoggerFactory;
  * @see <a href="http://tools.ietf.org/html/rfc4271#section-4.3">BGP-4 Update Message Format</a>
  */
 public final class BGPUpdateMessageParser implements MessageParser, MessageSerializer {
-
     private static final Logger LOG = LoggerFactory.getLogger(BGPUpdateMessageParser.class);
 
     public static final int TYPE = 2;
 
     private final AttributeRegistry attrReg;
-
     private final NlriRegistry nlriReg;
 
     public BGPUpdateMessageParser(final AttributeRegistry attrReg, final NlriRegistry nlriReg) {
@@ -81,7 +78,7 @@ public final class BGPUpdateMessageParser implements MessageParser, MessageSeria
 
     @Override
     public void serializeMessage(final Notification message, final ByteBuf bytes) {
-        Preconditions.checkArgument(message instanceof Update, "Message needs to be of type Update");
+        checkArgument(message instanceof Update, "Message needs to be of type Update");
         final Update update = (Update) message;
 
         final ByteBuf messageBody = Unpooled.buffer();
@@ -112,7 +109,7 @@ public final class BGPUpdateMessageParser implements MessageParser, MessageSeria
 
     private static void writePathIdPrefix(final ByteBuf byteBuf, final PathId pathId, final Ipv4Prefix ipv4Prefix) {
         PathIdUtil.writePathId(pathId, byteBuf);
-        ByteBufWriteUtil.writeMinimalPrefix(ipv4Prefix, byteBuf);
+        Ipv4Util.writeMinimalPrefix(ipv4Prefix, byteBuf);
     }
 
     /**
@@ -127,8 +124,7 @@ public final class BGPUpdateMessageParser implements MessageParser, MessageSeria
     @Override
     public Update parseMessageBody(final ByteBuf buffer, final int messageLength,
             final PeerSpecificParserConstraint constraint) throws BGPDocumentedException {
-        Preconditions.checkArgument(buffer != null && buffer.isReadable(),
-                "Buffer cannot be null or empty.");
+        checkArgument(buffer != null && buffer.isReadable(),"Buffer cannot be null or empty.");
 
         final UpdateBuilder builder = new UpdateBuilder();
         final boolean isMultiPathSupported = MultiPathSupportUtil.isTableTypeSupported(constraint,
index dc318c46a42e2f2c896bb29db6d50d9a08e6ff68..b3c271e828b7c95280b321587eaea470667b5ee7 100644 (file)
@@ -5,16 +5,15 @@
  * 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.bgp.parser.impl.message.update.extended.communities;
 
+import static com.google.common.base.Preconditions.checkArgument;
 import static org.opendaylight.protocol.bgp.parser.spi.extended.community.Inet4SpecificExtendedCommunityCommonUtil.parseCommon;
 import static org.opendaylight.protocol.bgp.parser.spi.extended.community.Inet4SpecificExtendedCommunityCommonUtil.serializeCommon;
 
-import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.protocol.bgp.parser.spi.extended.community.AbstractIpv4ExtendedCommunity;
-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.extended.community.ExtendedCommunity;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.Inet4SpecificExtendedCommunityCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.Inet4SpecificExtendedCommunityCaseBuilder;
@@ -23,7 +22,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.inet4.specific.extended.community.common.Inet4SpecificExtendedCommunityCommon;
 
 public final class Ipv4SpecificEcHandler extends AbstractIpv4ExtendedCommunity {
-
     private static final int SUBTYPE = 0;
 
     @Override
@@ -36,9 +34,8 @@ public final class Ipv4SpecificEcHandler extends AbstractIpv4ExtendedCommunity {
 
     @Override
     public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf byteAggregator) {
-        Preconditions.checkArgument(extendedCommunity instanceof Inet4SpecificExtendedCommunityCase,
-                "The extended community %s is not Inet4SpecificExtendedCommunityCase type.",
-                extendedCommunity);
+        checkArgument(extendedCommunity instanceof Inet4SpecificExtendedCommunityCase,
+                "The extended community %s is not Inet4SpecificExtendedCommunityCase type.", extendedCommunity);
         final Inet4SpecificExtendedCommunity inet4SpecificExtendedCommunity
                 = ((Inet4SpecificExtendedCommunityCase) extendedCommunity).getInet4SpecificExtendedCommunity();
 
@@ -47,7 +44,7 @@ public final class Ipv4SpecificEcHandler extends AbstractIpv4ExtendedCommunity {
         if (common != null) {
             serializeCommon(inet4SpecificExtendedCommunity.getInet4SpecificExtendedCommunityCommon(), byteAggregator);
         } else {
-            ByteBufWriteUtil.writeIpv4Address(inet4SpecificExtendedCommunity.getGlobalAdministrator(), byteAggregator);
+            Ipv4Util.writeIpv4Address(inet4SpecificExtendedCommunity.getGlobalAdministrator(), byteAggregator);
             byteAggregator.writeBytes(inet4SpecificExtendedCommunity.getLocalAdministrator());
         }
     }
@@ -56,5 +53,4 @@ public final class Ipv4SpecificEcHandler extends AbstractIpv4ExtendedCommunity {
     public int getSubType() {
         return SUBTYPE;
     }
-
 }
index 75fa2c71c68d8f97a3289932af2715577b0af19f..3eac8d6dec2e41da6f8f8fd29b56fc34b8a9308d 100644 (file)
@@ -7,12 +7,12 @@
  */
 package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.bgp.parser.spi.extended.community.AbstractIpv4ExtendedCommunity;
-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.extended.community.ExtendedCommunity;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.RouteOriginIpv4Case;
@@ -26,21 +26,22 @@ public final class RouteOriginIpv4EcHandler extends AbstractIpv4ExtendedCommunit
 
     @Override
     public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf byteAggregator) {
-        Preconditions.checkArgument(extendedCommunity instanceof RouteOriginIpv4Case,
+        checkArgument(extendedCommunity instanceof RouteOriginIpv4Case,
                 "The extended community %s is not RouteOriginIpv4Case type.", extendedCommunity);
         final RouteOriginIpv4 routeTarget = ((RouteOriginIpv4Case) extendedCommunity).getRouteOriginIpv4();
-        ByteBufWriteUtil.writeIpv4Address(routeTarget.getGlobalAdministrator(), byteAggregator);
+        Ipv4Util.writeIpv4Address(routeTarget.getGlobalAdministrator(), byteAggregator);
         ByteBufUtils.writeOrZero(byteAggregator, routeTarget.getLocalAdministrator());
     }
 
     @Override
     public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer)
             throws BGPDocumentedException, BGPParsingException {
-        final RouteOriginIpv4 routeTarget = new RouteOriginIpv4Builder()
-            .setGlobalAdministrator(Ipv4Util.addressForByteBuf(buffer))
-            .setLocalAdministrator(ByteBufUtils.readUint16(buffer))
-            .build();
-        return new RouteOriginIpv4CaseBuilder().setRouteOriginIpv4(routeTarget).build();
+        return new RouteOriginIpv4CaseBuilder()
+                .setRouteOriginIpv4(new RouteOriginIpv4Builder()
+                    .setGlobalAdministrator(Ipv4Util.addressForByteBuf(buffer))
+                    .setLocalAdministrator(ByteBufUtils.readUint16(buffer))
+                    .build())
+                .build();
     }
 
     @Override
index 0aece7e4912ca7d5c99f7a621edc073318547952..1bf90ab02e948be9fb954ac90f69623236bdf44c 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.route.target;
 
 import io.netty.buffer.ByteBuf;
-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;
@@ -25,7 +24,7 @@ public final class RouteTargetIpv4Handler {
     }
 
     public static void serialize(final RouteTargetIpv4 routeTarget, final ByteBuf byteAggregator) {
-        ByteBufWriteUtil.writeIpv4Address(routeTarget.getGlobalAdministrator(), byteAggregator);
+        Ipv4Util.writeIpv4Address(routeTarget.getGlobalAdministrator(), byteAggregator);
         ByteBufUtils.writeOrZero(byteAggregator, routeTarget.getLocalAdministrator());
     }
 
index bca69fe91de1e0ab07e6534e2b97fe0c31d70b2b..3da2f02077abc2af2051b4ef7c86520c5dee926b 100644 (file)
@@ -11,7 +11,6 @@ import static org.opendaylight.protocol.bgp.parser.spi.extended.community.Abstra
 
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.protocol.util.ByteArray;
-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.inet4.specific.extended.community.common.Inet4SpecificExtendedCommunityCommon;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.inet4.specific.extended.community.common.Inet4SpecificExtendedCommunityCommonBuilder;
@@ -30,7 +29,7 @@ public final class Inet4SpecificExtendedCommunityCommonUtil {
 
     public static void serializeCommon(final Inet4SpecificExtendedCommunityCommon extComm,
             final ByteBuf byteAggregator) {
-        ByteBufWriteUtil.writeIpv4Address(extComm.getGlobalAdministrator(), byteAggregator);
+        Ipv4Util.writeIpv4Address(extComm.getGlobalAdministrator(), byteAggregator);
         byteAggregator.writeBytes(extComm.getLocalAdministrator());
     }
 }
index 2fadb1aaa3167b5e6297256e5822f9cc6c22ea04..2b03ce47cffbb2a9e7574eb3b391b3c82163d85c 100644 (file)
@@ -7,9 +7,9 @@
  */
 package org.opendaylight.protocol.bmp.parser.message;
 
+import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Objects.requireNonNull;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
@@ -19,7 +19,6 @@ import org.opendaylight.protocol.bgp.parser.spi.MessageUtil;
 import org.opendaylight.protocol.bmp.spi.parser.AbstractBmpPerPeerMessageParser;
 import org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException;
 import org.opendaylight.protocol.bmp.spi.parser.BmpTlvRegistry;
-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;
@@ -52,15 +51,14 @@ public class PeerUpHandler extends AbstractBmpPerPeerMessageParser<InformationBu
     @Override
     public void serializeMessageBody(final Notification message, final ByteBuf buffer) {
         super.serializeMessageBody(message, buffer);
-        Preconditions.checkArgument(message instanceof PeerUpNotification,
-            "An instance of Peer Up notification is required");
+        checkArgument(message instanceof PeerUpNotification, "An instance of Peer Up notification is required");
         final PeerUpNotification peerUp = (PeerUpNotification) message;
 
         if (peerUp.getLocalAddress().getIpv4Address() != null) {
             buffer.writeZero(Ipv6Util.IPV6_LENGTH - Ipv4Util.IP4_LENGTH);
-            ByteBufWriteUtil.writeIpv4Address(peerUp.getLocalAddress().getIpv4Address(), buffer);
+            Ipv4Util.writeIpv4Address(peerUp.getLocalAddress().getIpv4Address(), buffer);
         } else {
-            ByteBufWriteUtil.writeIpv6Address(peerUp.getLocalAddress().getIpv6Address(), buffer);
+            Ipv6Util.writeIpv6Address(peerUp.getLocalAddress().getIpv6Address(), buffer);
         }
         ByteBufUtils.write(buffer, peerUp.getLocalPort().getValue());
         ByteBufUtils.write(buffer, peerUp.getRemotePort().getValue());
@@ -96,18 +94,14 @@ public class PeerUpHandler extends AbstractBmpPerPeerMessageParser<InformationBu
         try {
             final Notification opSent = this.msgRegistry
                     .parseMessage(bytes.readSlice(getBgpMessageLength(bytes)), null);
-            requireNonNull(opSent,
-                    "Error on parse Sent OPEN Message, Sent OPEN Message is null");
-            Preconditions.checkArgument(opSent instanceof OpenMessage,
-                    "An instance of OpenMessage notification is required");
+            requireNonNull(opSent, "Error on parse Sent OPEN Message, Sent OPEN Message is null");
+            checkArgument(opSent instanceof OpenMessage, "An instance of OpenMessage notification is required");
             final OpenMessage sent = (OpenMessage) opSent;
 
             final Notification opRec = this.msgRegistry
                     .parseMessage(bytes.readSlice(getBgpMessageLength(bytes)), null);
-            requireNonNull(opRec,
-                    "Error on parse Received  OPEN Message, Received  OPEN Message is null");
-            Preconditions.checkArgument(opRec instanceof OpenMessage,
-                    "An instance of OpenMessage notification is required");
+            requireNonNull(opRec, "Error on parse Received  OPEN Message, Received  OPEN Message is null");
+            checkArgument(opRec instanceof OpenMessage, "An instance of OpenMessage notification is required");
             final OpenMessage received = (OpenMessage) opRec;
 
             peerUpNot.setSentOpen(new SentOpenBuilder(sent).build());
index 652fb2acf1f215edfe6098e0c3d8f5208397321f..27539f2a633ea48e1e34d6a09c41fc2514d86b32 100644 (file)
@@ -15,7 +15,6 @@ import org.opendaylight.bgp.concepts.RouteDistinguisherUtil;
 import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
 import org.opendaylight.protocol.util.BitArray;
 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.AsNumber;
@@ -118,12 +117,12 @@ public abstract class AbstractBmpPerPeerMessageParser<T extends Builder<?>> exte
         }
         if (peerHeader.isIpv4()) {
             output.writeZero(Ipv6Util.IPV6_LENGTH - Ipv4Util.IP4_LENGTH);
-            ByteBufWriteUtil.writeIpv4Address(peerHeader.getAddress().getIpv4Address(), output);
+            Ipv4Util.writeIpv4Address(peerHeader.getAddress().getIpv4Address(), output);
         } else {
-            ByteBufWriteUtil.writeIpv6Address(peerHeader.getAddress().getIpv6Address(), output);
+            Ipv6Util.writeIpv6Address(peerHeader.getAddress().getIpv6Address(), output);
         }
         ByteBufUtils.write(output, peerHeader.getAs().getValue());
-        ByteBufWriteUtil.writeIpv4Address(peerHeader.getBgpId(), output);
+        Ipv4Util.writeIpv4Address(peerHeader.getBgpId(), output);
 
         final Timestamp stampSec = peerHeader.getTimestampSec();
         if (stampSec != null) {
index 2b3c42129350231e614fd73ace3cb61007a50d66..a1ae5985d8dca4fb05049b6da18073a0206248f8 100644 (file)
@@ -5,16 +5,15 @@
  * 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 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.util.ByteBufWriteUtil;
 import org.opendaylight.protocol.util.Ipv4Util;
 import org.opendaylight.protocol.util.Ipv6Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
@@ -29,17 +28,17 @@ public abstract class AbstractPccIdReqObjectParser extends CommonObjectParser im
 
     @Override
     public void serializeObject(final Object object, final ByteBuf buffer) {
-        Preconditions.checkArgument(object instanceof PccIdReq,
-                "Wrong instance of PCEPObject. Passed %s. Needed PccIdReqObject.", object.getClass());
+        checkArgument(object instanceof PccIdReq, "Wrong instance of PCEPObject. Passed %s. Needed PccIdReqObject.",
+            object.getClass());
         final PccIdReq pccIdReq = (PccIdReq) object;
         if (pccIdReq.getIpAddress().getIpv4AddressNoZone() != null) {
             final ByteBuf body = Unpooled.buffer(Ipv4Util.IP4_LENGTH);
-            ByteBufWriteUtil.writeIpv4Address(pccIdReq.getIpAddress().getIpv4AddressNoZone(), body);
+            Ipv4Util.writeIpv4Address(pccIdReq.getIpAddress().getIpv4AddressNoZone(), body);
             ObjectUtil.formatSubobject(getObjectType(), getObjectClass(), object.isProcessingRule(), object.isIgnore(),
                     body, buffer);
         } else if (pccIdReq.getIpAddress().getIpv6AddressNoZone() != null) {
             final ByteBuf body = Unpooled.buffer(Ipv6Util.IPV6_LENGTH);
-            ByteBufWriteUtil.writeIpv6Address(pccIdReq.getIpAddress().getIpv6AddressNoZone(), body);
+            Ipv6Util.writeIpv6Address(pccIdReq.getIpAddress().getIpv6AddressNoZone(), body);
             ObjectUtil.formatSubobject(getObjectType(), getObjectClass(), object.isProcessingRule(), object.isIgnore(),
                     body, buffer);
         }
index 70e1404cf26a5ac16fd3a2102da39f0c254cea20..08a0cb5e86f5eb367d252e7a2e898f9039510f2a 100644 (file)
@@ -5,16 +5,15 @@
  * 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 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.util.ByteBufWriteUtil;
 import org.opendaylight.protocol.util.Ipv4Util;
 import org.opendaylight.protocol.util.Ipv6Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
@@ -29,17 +28,17 @@ public abstract class AbstractPceIdObjectParser extends CommonObjectParser imple
 
     @Override
     public void serializeObject(final Object object, final ByteBuf buffer) {
-        Preconditions.checkArgument(object instanceof PceId,
-            "Wrong instance of PCEPObject. Passed %s. Needed PccIdReqObject.", object.getClass());
+        checkArgument(object instanceof PceId, "Wrong instance of PCEPObject. Passed %s. Needed PccIdReqObject.",
+            object.getClass());
         final PceId pceId = (PceId) object;
         if (pceId.getIpAddress().getIpv4AddressNoZone() != null) {
             final ByteBuf body = Unpooled.buffer(Ipv4Util.IP4_LENGTH);
-            ByteBufWriteUtil.writeIpv4Address(pceId.getIpAddress().getIpv4AddressNoZone(), body);
+            Ipv4Util.writeIpv4Address(pceId.getIpAddress().getIpv4AddressNoZone(), body);
             ObjectUtil.formatSubobject(getObjectType(), getObjectClass(), object.isProcessingRule(), object.isIgnore(),
                 body, buffer);
         } else if (pceId.getIpAddress().getIpv6AddressNoZone() != null) {
             final ByteBuf body = Unpooled.buffer(Ipv6Util.IPV6_LENGTH);
-            ByteBufWriteUtil.writeIpv6Address(pceId.getIpAddress().getIpv6AddressNoZone(), body);
+            Ipv6Util.writeIpv6Address(pceId.getIpAddress().getIpv6AddressNoZone(), body);
             ObjectUtil.formatSubobject(getObjectType(), getObjectClass(), object.isProcessingRule(), object.isIgnore(),
                 body, buffer);
         }
index 54e8d50bbf1cc24ddd6e35616eaa133df800f498..461c1e2272fcd5c370294939bfcf7263adf6ab3b 100644 (file)
@@ -7,9 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.parser.object.end.points;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Address;
+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.CommonObjectParser;
@@ -47,19 +46,16 @@ public class PCEPEndPointsIpv4ObjectParser extends CommonObjectParser {
         final Ipv4 ipv4,
         final ByteBuf buffer) {
         final ByteBuf body = Unpooled.buffer(Ipv4Util.IP4_LENGTH + Ipv4Util.IP4_LENGTH);
-        Preconditions.checkArgument(ipv4.getSourceIpv4Address() != null,
-            "SourceIpv4Address is mandatory.");
-        writeIpv4Address(ipv4.getSourceIpv4Address(), body);
-        Preconditions.checkArgument(ipv4.getDestinationIpv4Address() != null,
-            "DestinationIpv4Address is mandatory.");
-        writeIpv4Address(ipv4.getDestinationIpv4Address(), body);
+        checkArgument(ipv4.getSourceIpv4Address() != null, "SourceIpv4Address is mandatory.");
+        Ipv4Util.writeIpv4Address(ipv4.getSourceIpv4Address(), body);
+        checkArgument(ipv4.getDestinationIpv4Address() != null, "DestinationIpv4Address is mandatory.");
+        Ipv4Util.writeIpv4Address(ipv4.getDestinationIpv4Address(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, processing, ignore, body, buffer);
     }
 
     @Override
     public Object 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 EndpointsObjBuilder builder = new EndpointsObjBuilder();
         if (!header.isProcessingRule()) {
             LOG.debug("Processed bit not set on Endpoints OBJECT, ignoring it.");
index 5399cde7ec51f7ef496c0a9a8d9051a1026ea76b..775961fa219e27c05d8e50a474e148abe0071844 100644 (file)
@@ -7,9 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.parser.object.end.points;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Address;
+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.CommonObjectParser;
@@ -47,19 +46,16 @@ public final class PCEPEndPointsIpv6ObjectParser extends CommonObjectParser {
         final Ipv6 ipv6,
         final ByteBuf buffer) {
         final ByteBuf body = Unpooled.buffer(Ipv6Util.IPV6_LENGTH + Ipv6Util.IPV6_LENGTH);
-        Preconditions.checkArgument(ipv6.getSourceIpv6Address() != null,
-            "SourceIpv6Address is mandatory.");
-        writeIpv6Address(ipv6.getSourceIpv6Address(), body);
-        Preconditions.checkArgument(ipv6.getDestinationIpv6Address() != null,
-            "DestinationIpv6Address is mandatory.");
-        writeIpv6Address(ipv6.getDestinationIpv6Address(), body);
+        checkArgument(ipv6.getSourceIpv6Address() != null, "SourceIpv6Address is mandatory.");
+        Ipv6Util.writeIpv6Address(ipv6.getSourceIpv6Address(), body);
+        checkArgument(ipv6.getDestinationIpv6Address() != null, "DestinationIpv6Address is mandatory.");
+        Ipv6Util.writeIpv6Address(ipv6.getDestinationIpv6Address(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, processing, ignore, body, buffer);
     }
 
     @Override
     public Object 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 EndpointsObjBuilder builder = new EndpointsObjBuilder();
         if (!header.isProcessingRule()) {
             LOG.debug("Processed bit not set on Endpoints OBJECT, ignoring it.");
index 6eb97d894ec13ae55c679558076d5c36790f05a9..369eadf1df6a6af87af541b7b50ef825db9ec456 100644 (file)
@@ -7,9 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.parser.object.end.points;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Address;
+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;
@@ -47,20 +46,18 @@ public class PCEPP2MPEndPointsIpv4ObjectParser extends CommonObjectParser {
         final P2mpIpv4 p2mpIpv4,
         final ByteBuf buffer) {
         final List<Ipv4AddressNoZone> dest = p2mpIpv4.getDestinationIpv4Address();
-        Preconditions.checkArgument(dest != null, "DestinationIpv4Address is mandatory.");
+        checkArgument(dest != null, "DestinationIpv4Address is mandatory.");
         final ByteBuf body = Unpooled.buffer(LEAF_TYPE_SIZE + Ipv4Util.IP4_LENGTH + Ipv4Util.IP4_LENGTH * dest.size());
-        Preconditions.checkArgument(p2mpIpv4.getSourceIpv4Address() != null,
-            "SourceIpv4Address is mandatory.");
+        checkArgument(p2mpIpv4.getSourceIpv4Address() != null, "SourceIpv4Address is mandatory.");
         body.writeInt(p2mpIpv4.getP2mpLeaves().getIntValue());
-        writeIpv4Address(p2mpIpv4.getSourceIpv4Address(), body);
-        dest.forEach(ipv4 -> writeIpv4Address(ipv4, body));
+        Ipv4Util.writeIpv4Address(p2mpIpv4.getSourceIpv4Address(), body);
+        dest.forEach(ipv4 -> Ipv4Util.writeIpv4Address(ipv4, body));
         ObjectUtil.formatSubobject(TYPE, CLASS, processing, ignore, body, buffer);
     }
 
     @Override
     public Object 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 EndpointsObjBuilder builder = new EndpointsObjBuilder();
         if (!header.isProcessingRule()) {
             LOG.debug("Processed bit not set on Endpoints OBJECT, ignoring it.");
index dad61e6d0e8b9b4baa715af4707ba4e42c6cbcfa..ff3d83c97ab523f21470d4efdff04ce6de6d0b51 100644 (file)
@@ -7,9 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.parser.object.end.points;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Address;
+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;
@@ -47,21 +46,19 @@ public class PCEPP2MPEndPointsIpv6ObjectParser extends CommonObjectParser {
         final P2mpIpv6 p2mpIpv6,
         final ByteBuf buffer) {
         final List<Ipv6AddressNoZone> dest = p2mpIpv6.getDestinationIpv6Address();
-        Preconditions.checkArgument(dest != null, "DestinationIpv6Address is mandatory.");
+        checkArgument(dest != null, "DestinationIpv6Address is mandatory.");
         final ByteBuf body =
             Unpooled.buffer(LEAF_TYPE_SIZE + Ipv6Util.IPV6_LENGTH + Ipv6Util.IPV6_LENGTH * dest.size());
-        Preconditions.checkArgument(p2mpIpv6.getSourceIpv6Address() != null,
-            "SourceIpv6Address is mandatory.");
+        checkArgument(p2mpIpv6.getSourceIpv6Address() != null, "SourceIpv6Address is mandatory.");
         body.writeInt(p2mpIpv6.getP2mpLeaves().getIntValue());
-        writeIpv6Address(p2mpIpv6.getSourceIpv6Address(), body);
-        dest.forEach(ipv6 -> writeIpv6Address(ipv6, body));
+        Ipv6Util.writeIpv6Address(p2mpIpv6.getSourceIpv6Address(), body);
+        dest.forEach(ipv6 -> Ipv6Util.writeIpv6Address(ipv6, body));
         ObjectUtil.formatSubobject(TYPE, CLASS, processing, ignore, body, buffer);
     }
 
     @Override
     public Object 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 (!header.isProcessingRule()) {
             LOG.debug("Processed bit not set on Endpoints OBJECT, ignoring it.");
             return new UnknownObject(PCEPErrors.P_FLAG_NOT_SET, new EndpointsObjBuilder().build());
index c3840e401358d0edaccf1623e8a19899e4650ccc..25bfca7651af1093b05a4e84a9b112ba5a99d034 100644 (file)
@@ -7,9 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.parser.object.unreach;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Address;
+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;
@@ -39,17 +38,16 @@ public final class PCEPIpv4UnreachDestinationParser extends CommonObjectParser {
         final Ipv4DestinationCase ipv4Case,
         final ByteBuf buffer) {
         final List<Ipv4AddressNoZone> dest = ipv4Case.getDestinationIpv4Address();
-        Preconditions.checkArgument(dest != null, "DestinationIpv4Address is mandatory.");
+        checkArgument(dest != null, "DestinationIpv4Address is mandatory.");
         final ByteBuf body = Unpooled.buffer(Ipv4Util.IP4_LENGTH * dest.size());
-        dest.forEach(ipv4 -> writeIpv4Address(ipv4, body));
+        dest.forEach(ipv4 -> Ipv4Util.writeIpv4Address(ipv4, body));
         ObjectUtil.formatSubobject(TYPE, CLASS, processing, ignore, body, buffer);
     }
 
     @Override
     public UnreachDestinationObj 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 UnreachDestinationObjBuilder builder = new UnreachDestinationObjBuilder();
         if (bytes.readableBytes() % Ipv4Util.IP4_LENGTH != 0) {
             throw new PCEPDeserializerException("Wrong length of array of bytes.");
index 0c8be58cb3aa3046439a410fe6a9aeec11dcfa98..21cf459a58f902a19cc4ba07f6970ca5b8b554b5 100644 (file)
@@ -7,9 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.parser.object.unreach;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Address;
+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;
@@ -39,17 +38,16 @@ public final class PCEPIpv6UnreachDestinationParser extends CommonObjectParser {
         final Ipv6DestinationCase ipv6Case,
         final ByteBuf buffer) {
         final List<Ipv6AddressNoZone> dest = ipv6Case.getDestinationIpv6Address();
-        Preconditions.checkArgument(dest != null, "Destinationipv6Address is mandatory.");
+        checkArgument(dest != null, "Destinationipv6Address is mandatory.");
         final ByteBuf body = Unpooled.buffer(Ipv6Util.IPV6_LENGTH * dest.size());
-        dest.forEach(ipv6 -> writeIpv6Address(ipv6, body));
+        dest.forEach(ipv6 -> Ipv6Util.writeIpv6Address(ipv6, body));
         ObjectUtil.formatSubobject(TYPE, CLASS, processing, ignore, body, buffer);
     }
 
     @Override
     public UnreachDestinationObj 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 UnreachDestinationObjBuilder builder = new UnreachDestinationObjBuilder();
         if (bytes.readableBytes() % Ipv6Util.IPV6_LENGTH != 0) {
             throw new PCEPDeserializerException("Wrong length of array of bytes.");
index c3e8877367a1544b69f79a034c9980f942046c4d..29a58f09c1edc92b444b5a805e4c2799ad0333cf 100644 (file)
@@ -7,9 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.parser.subobject;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Prefix;
+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.EROSubobjectParser;
@@ -19,6 +18,7 @@ import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 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.Ipv6Prefix;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.Subobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.SubobjectBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.IpPrefixSubobject;
@@ -30,19 +30,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
  * Parser for {@link IpPrefixCase}.
  */
 public class EROIpv4PrefixSubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
-
     public static final int TYPE = 1;
 
     private static final int PREFIX4_F_OFFSET = Ipv4Util.IP4_LENGTH;
-
     private static final int RESERVED = 1;
-
     private static final int CONTENT4_LENGTH = PREFIX4_F_OFFSET + RESERVED + 1;
 
     @Override
     public Subobject parseSubobject(final ByteBuf buffer, final boolean loose) 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() != CONTENT4_LENGTH) {
             throw new PCEPDeserializerException(
                     "Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
@@ -58,20 +54,20 @@ public class EROIpv4PrefixSubobjectParser implements EROSubobjectParser, EROSubo
 
     @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();
-        Preconditions.checkArgument(prefix.getIpv4Prefix() != null || prefix.getIpv6Prefix() != null,
-                "Unknown AbstractPrefix instance. Passed %s.", prefix.getClass());
-        if (prefix.getIpv6Prefix() != null) {
-            new EROIpv6PrefixSubobjectParser().serializeSubobject(subobject, buffer);
-        } else {
-            final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH);
-            Preconditions.checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
-            writeIpv4Prefix(prefix.getIpv4Prefix(), body);
-            body.writeZero(RESERVED);
-            EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
+        final Ipv6Prefix ipv6prefix = prefix.getIpv6Prefix();
+        if (ipv6prefix != null) {
+            EROIpv6PrefixSubobjectParser.serializeSubobject(buffer, subobject, ipv6prefix);
+            return;
         }
+
+        final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH);
+        checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
+        Ipv4Util.writeIpv4Prefix(prefix.getIpv4Prefix(), body);
+        body.writeZero(RESERVED);
+        EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
     }
 }
index 8eeccaebbb5dc69ee0c532c52159b94f5920b166..274e1a3769a993e3732f557deedd5b49826f8c55 100644 (file)
@@ -7,9 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.parser.subobject;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Prefix;
+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.EROSubobjectParser;
@@ -19,6 +18,7 @@ import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 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.explicit.route.object.ero.Subobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.SubobjectBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.IpPrefixSubobject;
@@ -30,19 +30,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
  * Parser for {@link IpPrefixCase}.
  */
 public class EROIpv6PrefixSubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
-
     public static final int TYPE = 2;
 
     private static final int PREFIX_F_OFFSET = Ipv6Util.IPV6_LENGTH;
-
     private static final int RESERVED = 1;
-
     private static final int CONTENT_LENGTH = PREFIX_F_OFFSET + RESERVED + 1;
 
     @Override
     public Subobject parseSubobject(final ByteBuf buffer, final boolean loose) 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() != CONTENT_LENGTH) {
             throw new PCEPDeserializerException(
                     "Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
@@ -58,13 +54,17 @@ public class EROIpv6PrefixSubobjectParser implements EROSubobjectParser, EROSubo
 
     @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();
-        Preconditions.checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory.");
-        writeIpv6Prefix(prefix.getIpv6Prefix(), body);
+        Ipv6Util.writeIpv6Prefix(ipv6prefix, body);
         body.writeZero(RESERVED);
         EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
     }
index 014b3980d13fa3bd61db31933a76b1f8728b0a8a..636107d23a718622835d4ea641b54cec4e182997 100644 (file)
@@ -7,9 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.parser.subobject;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Prefix;
+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;
@@ -20,6 +19,7 @@ import org.opendaylight.protocol.util.BitArray;
 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.Ipv6Prefix;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.Subobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.SubobjectBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.IpPrefixSubobject;
@@ -46,8 +46,7 @@ public class RROIpv4PrefixSubobjectParser implements RROSubobjectParser, RROSubo
 
     @Override
     public Subobject parseSubobject(final ByteBuf buffer) 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() != CONTENT4_LENGTH) {
             throw new PCEPDeserializerException(
                     "Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
@@ -68,23 +67,23 @@ public class RROIpv4PrefixSubobjectParser implements RROSubobjectParser, RROSubo
 
     @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();
-        Preconditions.checkArgument(prefix.getIpv4Prefix() != null || prefix.getIpv6Prefix() != null,
-                "Unknown AbstractPrefix instance. Passed %s.", prefix.getClass());
-        if (prefix.getIpv6Prefix() != null) {
-            new RROIpv6PrefixSubobjectParser().serializeSubobject(subobject, buffer);
-        } else {
-            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(CONTENT4_LENGTH);
-            Preconditions.checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
-            writeIpv4Prefix(prefix.getIpv4Prefix(), body);
-            flags.toByteBuf(body);
-            RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
+        final Ipv6Prefix ipv6Prefix = prefix.getIpv6Prefix();
+        if (ipv6Prefix != null) {
+            RROIpv6PrefixSubobjectParser.serializeSubobject(buffer, subobject, ipv6Prefix);
+            return;
         }
+
+        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(CONTENT4_LENGTH);
+        checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
+        Ipv4Util.writeIpv4Prefix(prefix.getIpv4Prefix(), body);
+        flags.toByteBuf(body);
+        RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
     }
 }
index dc48654f28c2829cb87543348ceb24d3b7f20a81..d82c3fce73f1540ce22c86d46d0d02f7b02a4b42 100644 (file)
@@ -7,9 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.parser.subobject;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Prefix;
+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;
@@ -20,6 +19,7 @@ import org.opendaylight.protocol.util.BitArray;
 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.reported.route.object.rro.Subobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.SubobjectBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.IpPrefixSubobject;
@@ -46,8 +46,7 @@ public class RROIpv6PrefixSubobjectParser implements RROSubobjectParser, RROSubo
 
     @Override
     public Subobject parseSubobject(final ByteBuf buffer) 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() != CONTENT_LENGTH) {
             throw new PCEPDeserializerException(
                     "Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
@@ -66,16 +65,20 @@ public class RROIpv6PrefixSubobjectParser implements RROSubobjectParser, RROSubo
 
     @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 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);
-        Preconditions.checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory.");
-        writeIpv6Prefix(prefix.getIpv6Prefix(), body);
+        Ipv6Util.writeIpv6Prefix(ipv6prefix, body);
         flags.toByteBuf(body);
         RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
     }
index 92bd5271b85302dff4920d55c527b3e2d1894920..d6b903d1d91a465cdf2c8a5a1b0ed0ef67408c92 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.writeIpv4Prefix;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -33,13 +32,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
  * Parser for {@link IpPrefixCase}.
  */
 public class XROIpv4PrefixSubobjectParser implements XROSubobjectParser, XROSubobjectSerializer {
-
     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
@@ -77,7 +73,7 @@ public class XROIpv4PrefixSubobjectParser implements XROSubobjectParser, XROSubo
         checkArgument(ipv4Prefix != null, "Ipv4Prefix is mandatory.");
 
         final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH);
-        writeIpv4Prefix(ipv4Prefix, body);
+        Ipv4Util.writeIpv4Prefix(ipv4Prefix, body);
         final Attribute attribute = subobject.getAttribute();
         checkArgument(attribute != null, "Attribute is mandatory.");
         body.writeByte(attribute.getIntValue());
index e1692a77568dff141b2c0ee88a0c04ddc4e9b85a..69c09127c4afcaa6855165c37f771b379f643dce 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.writeIpv6Prefix;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -68,7 +67,7 @@ public class XROIpv6PrefixSubobjectParser implements XROSubobjectParser, XROSubo
 
     static void serializeSubobject(final ByteBuf buffer, final Subobject subobject, final Ipv6Prefix ipv6Prefix) {
         final ByteBuf body = Unpooled.buffer(CONTENT6_LENGTH);
-        writeIpv6Prefix(ipv6Prefix, body);
+        Ipv6Util.writeIpv6Prefix(ipv6Prefix, body);
         final Attribute attribute = subobject.getAttribute();
         checkArgument(attribute != null, "Attribute is mandatory.");
         body.writeByte(attribute.getIntValue());
index 04a177b1aa0ad3b1922534b85d63b7b6649a7a91..53eb5691dda3a0f79cf38784752ae8bb39a44e09 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.pcep.ietf.stateful07;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Address;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -72,16 +71,16 @@ public final class Stateful07LSPIdentifierIpv4TlvParser implements TlvParser, Tl
         }
         final Ipv4 ipv4 = ((Ipv4Case) afi).getIpv4();
         checkArgument(ipv4.getIpv4TunnelSenderAddress() != null, "Ipv4TunnelSenderAddress is mandatory.");
-        writeIpv4Address(ipv4.getIpv4TunnelSenderAddress(), body);
+        Ipv4Util.writeIpv4Address(ipv4.getIpv4TunnelSenderAddress(), body);
         checkArgument(lsp.getLspId() != null, "LspId is mandatory.");
         body.writeShort(lsp.getLspId().getValue().shortValue());
         final TunnelId tunnelId = lsp.getTunnelId();
         checkArgument(tunnelId != null, "TunnelId is mandatory.");
         ByteBufUtils.write(body, tunnelId.getValue());
         checkArgument(ipv4.getIpv4ExtendedTunnelId() != null, "Ipv4ExtendedTunnelId is mandatory.");
-        writeIpv4Address(ipv4.getIpv4ExtendedTunnelId(), body);
+        Ipv4Util.writeIpv4Address(ipv4.getIpv4ExtendedTunnelId(), body);
         checkArgument(ipv4.getIpv4TunnelEndpointAddress() != null, "Ipv4TunnelEndpointAddress is mandatory.");
-        writeIpv4Address(ipv4.getIpv4TunnelEndpointAddress(), body);
+        Ipv4Util.writeIpv4Address(ipv4.getIpv4TunnelEndpointAddress(), body);
         TlvUtil.formatTlv(TYPE, body, buffer);
     }
 }
index 007b270f511980dda0b00565557e32b34c03680d..badb1c753691007a88d2b0416b77585e83c2f630 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.pcep.ietf.stateful07;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Address;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -63,7 +62,7 @@ public final class Stateful07LSPIdentifierIpv6TlvParser implements TlvParser, Tl
         final ByteBuf body = Unpooled.buffer();
         final Ipv6 ipv6 = ((Ipv6Case) lsp.getAddressFamily()).getIpv6();
         checkArgument(ipv6.getIpv6TunnelSenderAddress() != null, "Ipv6TunnelSenderAddress is mandatory.");
-        writeIpv6Address(ipv6.getIpv6TunnelSenderAddress(), body);
+        Ipv6Util.writeIpv6Address(ipv6.getIpv6TunnelSenderAddress(), body);
 
         final LspId lspId = lsp.getLspId();
         checkArgument(lspId != null, "LspId is mandatory.");
@@ -72,9 +71,9 @@ public final class Stateful07LSPIdentifierIpv6TlvParser implements TlvParser, Tl
         checkArgument(tunnelId != null, "TunnelId is mandatory.");
         ByteBufUtils.write(body, tunnelId.getValue());
         checkArgument(ipv6.getIpv6ExtendedTunnelId() != null, "Ipv6ExtendedTunnelId is mandatory.");
-        writeIpv6Address(ipv6.getIpv6ExtendedTunnelId(), body);
+        Ipv6Util.writeIpv6Address(ipv6.getIpv6ExtendedTunnelId(), body);
         checkArgument(ipv6.getIpv6TunnelEndpointAddress() != null, "Ipv6TunnelEndpointAddress is mandatory.");
-        writeIpv6Address(ipv6.getIpv6TunnelEndpointAddress(), body);
+        Ipv6Util.writeIpv6Address(ipv6.getIpv6TunnelEndpointAddress(), body);
         TlvUtil.formatTlv(TYPE, body, buffer);
     }
 }
index c88b2b994c1e5be86310f110698fc4ed1f9fac77..01c908f6b937962618099eeb8277708c8d8ec16e 100644 (file)
@@ -8,8 +8,6 @@
 package org.opendaylight.protocol.pcep.ietf.stateful07;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Address;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Address;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -142,10 +140,10 @@ public final class Stateful07RSVPErrorSpecTlvParser implements TlvParser, TlvSer
         int type = 0;
         if (node.getIpv4AddressNoZone() != null) {
             type = RSVP_IPV4_ERROR_CLASS_TYPE;
-            writeIpv4Address(node.getIpv4AddressNoZone(), rsvpObjBuf);
+            Ipv4Util.writeIpv4Address(node.getIpv4AddressNoZone(), rsvpObjBuf);
         } else {
             type = RSVP_IPV6_ERROR_CLASS_TYPE;
-            writeIpv6Address(node.getIpv6AddressNoZone(), rsvpObjBuf);
+            Ipv6Util.writeIpv6Address(node.getIpv6AddressNoZone(), rsvpObjBuf);
         }
         flags.toByteBuf(rsvpObjBuf);
         ByteBufUtils.writeMandatory(rsvpObjBuf, rsvp.getCode(), "Code");
index b4ecebf9e042db91dab28c9688b297ecb401bd0c..6842b24e2020db8fa50f87d42d5a3cae6a6e0a6d 100644 (file)
@@ -8,8 +8,6 @@
 package org.opendaylight.protocol.pcep.segment.routing;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Address;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Address;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -125,18 +123,18 @@ public abstract class AbstractSrSubobjectParser {
     private static void serializeNai(final Nai nai, final SidType sidType, final ByteBuf buffer) {
         switch (sidType) {
             case Ipv4NodeId:
-                writeIpv4Address(((IpNodeId) nai).getIpAddress().getIpv4AddressNoZone(), buffer);
+                Ipv4Util.writeIpv4Address(((IpNodeId) nai).getIpAddress().getIpv4AddressNoZone(), buffer);
                 break;
             case Ipv6NodeId:
-                writeIpv6Address(((IpNodeId) nai).getIpAddress().getIpv6AddressNoZone(), buffer);
+                Ipv6Util.writeIpv6Address(((IpNodeId) nai).getIpAddress().getIpv6AddressNoZone(), buffer);
                 break;
             case Ipv4Adjacency:
-                writeIpv4Address(((IpAdjacency) nai).getLocalIpAddress().getIpv4AddressNoZone(), buffer);
-                writeIpv4Address(((IpAdjacency) nai).getRemoteIpAddress().getIpv4AddressNoZone(), buffer);
+                Ipv4Util.writeIpv4Address(((IpAdjacency) nai).getLocalIpAddress().getIpv4AddressNoZone(), buffer);
+                Ipv4Util.writeIpv4Address(((IpAdjacency) nai).getRemoteIpAddress().getIpv4AddressNoZone(), buffer);
                 break;
             case Ipv6Adjacency:
-                writeIpv6Address(((IpAdjacency) nai).getLocalIpAddress().getIpv6AddressNoZone(), buffer);
-                writeIpv6Address(((IpAdjacency) nai).getRemoteIpAddress().getIpv6AddressNoZone(), buffer);
+                Ipv6Util.writeIpv6Address(((IpAdjacency) nai).getLocalIpAddress().getIpv6AddressNoZone(), buffer);
+                Ipv6Util.writeIpv6Address(((IpAdjacency) nai).getRemoteIpAddress().getIpv6AddressNoZone(), buffer);
                 break;
             case Unnumbered:
                 final UnnumberedAdjacency unnumbered = (UnnumberedAdjacency) nai;
index ff21296293aabda103339fd70f9ebe856e66b0cc..a6c92bd18e08ff3c4d69eb6a7135f711de73ca8b 100644 (file)
@@ -7,9 +7,8 @@
  */
 package org.opendaylight.protocol.rsvp.parser.impl.subobject.ero;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Prefix;
+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.EROSubobjectParser;
@@ -19,6 +18,7 @@ import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
 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.Ipv6Prefix;
 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.subobject.type.IpPrefixCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
@@ -30,19 +30,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
  * Parser for {@link IpPrefixCase}.
  */
 public class EROIpv4PrefixSubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
-
     public static final int TYPE = 1;
 
     private static final int PREFIX4_F_OFFSET = Ipv4Util.IP4_LENGTH;
-
     private static final int RESERVED = 1;
-
     private static final int CONTENT4_LENGTH = PREFIX4_F_OFFSET + RESERVED + 1;
 
     @Override
     public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean loose) 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.setLoose(loose);
         if (buffer.readableBytes() != CONTENT4_LENGTH) {
@@ -57,21 +53,21 @@ public class EROIpv4PrefixSubobjectParser implements EROSubobjectParser, EROSubo
 
     @Override
     public void serializeSubobject(final SubobjectContainer 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();
-        Preconditions.checkArgument(prefix.getIpv4Prefix() != null || prefix.getIpv6Prefix() != null,
-            "Unknown AbstractPrefix instance. Passed %s.", prefix.getClass());
-        if (prefix.getIpv6Prefix() != null) {
-            new EROIpv6PrefixSubobjectParser().serializeSubobject(subobject, buffer);
-        } else {
-            final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH);
-            Preconditions.checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
-            writeIpv4Prefix(prefix.getIpv4Prefix(), body);
-            body.writeZero(RESERVED);
-            EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
+        final Ipv6Prefix ipv6prefix = prefix.getIpv6Prefix();
+        if (ipv6prefix != null) {
+            EROIpv6PrefixSubobjectParser.serializeSubobject(buffer, subobject, ipv6prefix);
+            return;
         }
+
+        final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH);
+        checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
+        Ipv4Util.writeIpv4Prefix(prefix.getIpv4Prefix(), body);
+        body.writeZero(RESERVED);
+        EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
     }
 }
index 1f1af905c52c135024f45f59eb9cdf200a9bb994..0ab248a47fdcc85469b248634fd19525e95f2ebb 100644 (file)
@@ -7,9 +7,8 @@
  */
 package org.opendaylight.protocol.rsvp.parser.impl.subobject.ero;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Prefix;
+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.EROSubobjectParser;
@@ -19,6 +18,7 @@ import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
 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.rsvp.rev150820.IpPrefixSubobject;
 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;
@@ -30,19 +30,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
  * Parser for {@link IpPrefixCase}.
  */
 public class EROIpv6PrefixSubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
-
     public static final int TYPE = 2;
 
     private static final int PREFIX_F_OFFSET = Ipv6Util.IPV6_LENGTH;
-
     private static final int RESERVED = 1;
-
     private static final int CONTENT_LENGTH = PREFIX_F_OFFSET + RESERVED + 1;
 
     @Override
     public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean loose) 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.setLoose(loose);
         if (buffer.readableBytes() != CONTENT_LENGTH) {
@@ -57,14 +53,18 @@ public class EROIpv6PrefixSubobjectParser implements EROSubobjectParser, EROSubo
 
     @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());
+        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 SubobjectContainer subobject,
+            final Ipv6Prefix ipv6prefix) {
         final ByteBuf body = Unpooled.buffer();
-        Preconditions.checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory.");
-        writeIpv6Prefix(prefix.getIpv6Prefix(), body);
+        Ipv6Util.writeIpv6Prefix(ipv6prefix, body);
         body.writeZero(RESERVED);
         EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
     }
index d0332feeb0f9c2acc31cd197a605173519922ce0..ef81d3535c4baa37e61905bcd2027a8caa4c008c 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.rro;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Prefix;
+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;
@@ -20,6 +18,7 @@ import org.opendaylight.protocol.util.BitArray;
 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.Ipv6Prefix;
 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.record.route.subobjects.list.SubobjectContainer;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.list.SubobjectContainerBuilder;
@@ -46,8 +45,7 @@ public class RROIpv4PrefixSubobjectParser implements RROSubobjectParser, RROSubo
 
     @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() != CONTENT4_LENGTH) {
             throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
         }
@@ -66,24 +64,23 @@ public class RROIpv4PrefixSubobjectParser implements RROSubobjectParser, RROSubo
 
     @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());
+        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();
-        Preconditions.checkArgument(prefix.getIpv4Prefix() != null || prefix.getIpv6Prefix() != null,
-            "Unknown AbstractPrefix instance. Passed %s.", prefix.getClass());
-        if (prefix.getIpv6Prefix() != null) {
-            new RROIpv6PrefixSubobjectParser().serializeSubobject(subobject, buffer);
-        } else {
-            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(CONTENT4_LENGTH);
-            Preconditions.checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
-            writeIpv4Prefix(prefix.getIpv4Prefix(), body);
-            flags.toByteBuf(body);
-            RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
+        final Ipv6Prefix ipv6Prefix = prefix.getIpv6Prefix();
+        if (ipv6Prefix != null) {
+            RROIpv6PrefixSubobjectParser.serializeSubobject(buffer, subobject, ipv6Prefix);
+            return;
         }
+
+        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(CONTENT4_LENGTH);
+        checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
+        Ipv4Util.writeIpv4Prefix(prefix.getIpv4Prefix(), body);
+        flags.toByteBuf(body);
+        RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
     }
 }
index dde28bf35c7daf3fbf9b957a841730c740830c6d..aebbe288dce15ef3dc1b915ae02bbb92d1214d9c 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.rro;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Prefix;
+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;
@@ -20,6 +18,7 @@ import org.opendaylight.protocol.util.BitArray;
 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.rsvp.rev150820.IpPrefixSubobject;
 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;
@@ -46,8 +45,7 @@ public class RROIpv6PrefixSubobjectParser implements RROSubobjectParser, RROSubo
 
     @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.");
         final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
         if (buffer.readableBytes() != CONTENT_LENGTH) {
             throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
@@ -65,17 +63,21 @@ public class RROIpv6PrefixSubobjectParser implements RROSubobjectParser, RROSubo
 
     @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());
+        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 SubobjectContainer subobject,
+            final Ipv6Prefix ipv6Prefix) {
         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);
-        Preconditions.checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory.");
-        writeIpv6Prefix(prefix.getIpv6Prefix(), body);
+        Ipv6Util.writeIpv6Prefix(ipv6Prefix, body);
         flags.toByteBuf(body);
         RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
     }
index d6e2a073b5cc33e3460a9277f24a5b0acc200a01..b87d01cbdfa4fc6cbfbb59e2d9a9b1f188277bd9 100644 (file)
@@ -8,7 +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.writeIpv4Prefix;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -18,7 +17,9 @@ import org.opendaylight.protocol.rsvp.parser.spi.XROSubobjectSerializer;
 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.Ipv6Prefix;
 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.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;
@@ -35,8 +36,8 @@ public class XROIpv4PrefixSubobjectParser implements XROSubobjectParser, XROSubo
     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 {
+    public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean mandatory)
+            throws RSVPParsingException {
         checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
         final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
         builder.setMandatory(mandatory);
@@ -59,17 +60,18 @@ public class XROIpv4PrefixSubobjectParser implements XROSubobjectParser, XROSubo
             type.getClass());
         final IpPrefixSubobject specObj = ((IpPrefixCase) type).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);
-            checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
-            writeIpv4Prefix(prefix.getIpv4Prefix(), body);
-            checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
-            body.writeByte(subobject.getAttribute().getIntValue());
-            XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
+        final Ipv6Prefix ipv6Prefix = prefix.getIpv6Prefix();
+        if (ipv6Prefix != null) {
+            XROIpv6PrefixSubobjectParser.serializeSubobject(buffer, subobject, ipv6Prefix);
+            return;
         }
+
+        final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH);
+        checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
+        Ipv4Util.writeIpv4Prefix(prefix.getIpv4Prefix(), body);
+        final Attribute attribute = subobject.getAttribute();
+        checkArgument(attribute != null, "Attribute is mandatory.");
+        body.writeByte(attribute.getIntValue());
+        XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
     }
 }
index 5f78e0bdea6da4c98a8217ee9b3c00a6161a848a..67f48094456ea758e1511a0b03585fe55eed28b9 100644 (file)
@@ -8,7 +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.writeIpv6Prefix;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -18,7 +17,9 @@ import org.opendaylight.protocol.rsvp.parser.spi.XROSubobjectSerializer;
 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.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.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;
@@ -38,8 +39,8 @@ public class XROIpv6PrefixSubobjectParser implements XROSubobjectParser, XROSubo
     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 {
+    public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean mandatory)
+            throws RSVPParsingException {
         checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
         final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
         builder.setMandatory(mandatory);
@@ -58,16 +59,21 @@ public class XROIpv6PrefixSubobjectParser implements XROSubobjectParser, XROSubo
     @Override
     public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
         final SubobjectType type = subobject.getSubobjectType();
-        checkArgument(type instanceof IpPrefixCase,
-            "Unknown subobject instance. Passed %s. Needed IpPrefixCase.",
+        checkArgument(type instanceof IpPrefixCase, "Unknown subobject instance. Passed %s. Needed IpPrefixCase.",
             type.getClass());
         final IpPrefixSubobject specObj = ((IpPrefixCase) type).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 SubobjectContainer subobject,
+            final Ipv6Prefix ipv6Prefix) {
         final ByteBuf body = Unpooled.buffer(CONTENT6_LENGTH);
-        checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory.");
-        writeIpv6Prefix(prefix.getIpv6Prefix(), body);
-        checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
-        body.writeByte(subobject.getAttribute().getIntValue());
+        Ipv6Util.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 02ebd79f97061700923af793b45e9c650877d8cf..e3afde14ef68940ab15228a83e1b2d41bb67aa63 100644 (file)
@@ -5,15 +5,14 @@
  * 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.te;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+
 import io.netty.buffer.ByteBuf;
 import java.util.ArrayList;
 import java.util.List;
 import org.opendaylight.protocol.rsvp.parser.spi.subobjects.AbstractRSVPObjectParser;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.protocol.util.Ipv4Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.RsvpTeObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.detour.object.detour.object.Ipv4DetourObject;
@@ -41,14 +40,14 @@ public final class DetourObjectIpv4Parser extends AbstractRSVPObjectParser {
 
     @Override
     public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf byteAggregator) {
-        Preconditions.checkArgument(teLspObject instanceof Ipv4DetourObject, "DetourObject is mandatory.");
+        checkArgument(teLspObject instanceof Ipv4DetourObject, "DetourObject is mandatory.");
         final Ipv4DetourObject detourObject = (Ipv4DetourObject) teLspObject;
 
         final List<Plr> list = detourObject.getPlr();
         serializeAttributeHeader(list.size() * 2 * Ipv4Util.IP4_LENGTH, CLASS_NUM, CTYPE, byteAggregator);
         for (final Plr plr : list) {
-            ByteBufWriteUtil.writeIpv4Address(plr.getPlrId(), byteAggregator);
-            ByteBufWriteUtil.writeIpv4Address(plr.getAvoidNode(), byteAggregator);
+            Ipv4Util.writeIpv4Address(plr.getPlrId(), byteAggregator);
+            Ipv4Util.writeIpv4Address(plr.getAvoidNode(), byteAggregator);
         }
     }
 }
index 4ef722db2b93a89d5e3a19abbcdf3e07bed6f8ba..53dedcb8f8bd59b5bd55b0469ef94daf3a00090e 100644 (file)
@@ -8,13 +8,6 @@
 package org.opendaylight.protocol.util;
 
 import io.netty.buffer.ByteBuf;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
-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.Ipv6Address;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone;
-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.ieee754.rev130819.Float32;
 
 /**
@@ -25,125 +18,6 @@ public final class ByteBufWriteUtil {
         // Hidden on purpose
     }
 
-    /**
-     * Writes IPv4 address if not null, otherwise writes zeros to the
-     * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 4.
-     *
-     * @param ipv4Address
-     *            IPv4 address to be written to the output.
-     * @param output
-     *            ByteBuf, where ipv4Address or zeros are written.
-     */
-    public static void writeIpv4Address(final Ipv4Address ipv4Address, final ByteBuf output) {
-        if (ipv4Address != null) {
-            output.writeBytes(Ipv4Util.bytesForAddress(ipv4Address));
-        } else {
-            output.writeInt(0);
-        }
-    }
-
-    /**
-     * Writes IPv4 address if not null, otherwise writes zeros to the
-     * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 4.
-     *
-     * @param ipv4Address
-     *            IPv4 address to be written to the output.
-     * @param output
-     *            ByteBuf, where ipv4Address or zeros are written.
-     */
-    public static void writeIpv4Address(final Ipv4AddressNoZone ipv4Address, final ByteBuf output) {
-        if (ipv4Address != null) {
-            output.writeBytes(IetfInetUtil.INSTANCE.ipv4AddressNoZoneBytes(ipv4Address));
-        } else {
-            output.writeInt(0);
-        }
-    }
-
-    /**
-     * Writes IPv4 prefix if not null, otherwise writes zeros to the
-     * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 5.
-     *
-     * @param ipv4Prefix
-     *            IPv4 prefix value to be written to the output. Prefix is
-     *            written in the last byte.
-     * @param output
-     *            ByteBuf, where ipv4Prefix or zeros are written.
-     */
-    public static void writeIpv4Prefix(final Ipv4Prefix ipv4Prefix, final ByteBuf output) {
-        if (ipv4Prefix != null) {
-            output.writeBytes(Ipv4Util.bytesForPrefix(ipv4Prefix));
-        } else {
-            output.writeZero(Ipv4Util.PREFIX_BYTE_LENGTH);
-        }
-    }
-
-    /**
-     * Writes IPv6 address if not null, otherwise writes zeros to the
-     * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 16.
-     *
-     * @param ipv6Address
-     *            IPv6 address to be written to the output.
-     * @param output
-     *            ByteBuf, where ipv6Address or zeros are written.
-     */
-    public static void writeIpv6Address(final Ipv6Address ipv6Address, final ByteBuf output) {
-        if (ipv6Address != null) {
-            output.writeBytes(Ipv6Util.bytesForAddress(ipv6Address));
-        } else {
-            output.writeZero(Ipv6Util.IPV6_LENGTH);
-        }
-    }
-
-    /**
-     * Writes IPv6 address if not null, otherwise writes zeros to the
-     * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 16.
-     *
-     * @param ipv6Address
-     *            IPv6 address to be written to the output.
-     * @param output
-     *            ByteBuf, where ipv6Address or zeros are written.
-     */
-    public static void writeIpv6Address(final Ipv6AddressNoZone ipv6Address, final ByteBuf output) {
-        if (ipv6Address != null) {
-            output.writeBytes(IetfInetUtil.INSTANCE.ipv6AddressNoZoneBytes(ipv6Address));
-        } else {
-            output.writeZero(Ipv6Util.IPV6_LENGTH);
-        }
-    }
-
-    /**
-     * Writes IPv6 prefix if not null, otherwise writes zeros to the
-     * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 17.
-     *
-     * @param ipv6Prefix
-     *            IPv6 prefix to be written to the output. Prefix is written in
-     *            the last byte.
-     * @param output
-     *            ByteBuf, where ipv6Prefix or zeros are written.
-     */
-    public static void writeIpv6Prefix(final Ipv6Prefix ipv6Prefix, final ByteBuf output) {
-        if (ipv6Prefix != null) {
-            output.writeBytes(Ipv6Util.bytesForPrefix(ipv6Prefix));
-        } else {
-            output.writeZero(Ipv6Util.PREFIX_BYTE_LENGTH);
-        }
-    }
-
-    public static void writeMinimalPrefix(final Ipv4Prefix ipv4Prefix, final ByteBuf output) {
-        final byte[] bytes = IetfInetUtil.INSTANCE.ipv4PrefixToBytes(ipv4Prefix);
-        writeMinimalPrefix(output, bytes, bytes[Ipv4Util.IP4_LENGTH]);
-    }
-
-    public static void writeMinimalPrefix(final Ipv6Prefix ipv6Prefix, final ByteBuf output) {
-        final byte[] bytes = IetfInetUtil.INSTANCE.ipv6PrefixToBytes(ipv6Prefix);
-        writeMinimalPrefix(output, bytes, bytes[Ipv6Util.IPV6_LENGTH]);
-    }
-
-    private static void writeMinimalPrefix(final ByteBuf output, final byte[] bytes, final byte prefixBits) {
-        output.writeByte(prefixBits);
-        output.writeBytes(bytes, 0, Ipv4Util.prefixBitsToBytes(Byte.toUnsignedInt(prefixBits)));
-    }
-
     /**
      * Writes Float32 <code>value</code> if not null, otherwise writes zeros to
      * the <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 4.
index ee65399879d23cacd734bc247296587d9f2ce23a..3b10fca15d49b663769a98bd50c16e0a2df56871 100644 (file)
@@ -92,7 +92,7 @@ public final class Ipv4Util {
      * Returns number of minimum bytes needed to cover all bits of prefix.
      */
     public static int getPrefixLengthBytes(final String prefix) {
-        return prefixBitsToBytes(Ipv4Util.getPrefixLength(prefix));
+        return prefixBitsToBytes(getPrefixLength(prefix));
     }
 
     /**
@@ -255,4 +255,67 @@ public final class Ipv4Util {
         }
         return ipAddress.getIpv6Address().getValue();
     }
+
+
+    /**
+     * Writes IPv4 address if not null, otherwise writes zeros to the
+     * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 4.
+     *
+     * @param ipv4Address
+     *            IPv4 address to be written to the output.
+     * @param output
+     *            ByteBuf, where ipv4Address or zeros are written.
+     */
+    public static void writeIpv4Address(final Ipv4Address ipv4Address, final ByteBuf output) {
+        if (ipv4Address != null) {
+            output.writeBytes(bytesForAddress(ipv4Address));
+        } else {
+            output.writeInt(0);
+        }
+    }
+
+    /**
+     * Writes IPv4 address if not null, otherwise writes zeros to the
+     * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 4.
+     *
+     * @param ipv4Address
+     *            IPv4 address to be written to the output.
+     * @param output
+     *            ByteBuf, where ipv4Address or zeros are written.
+     */
+    public static void writeIpv4Address(final Ipv4AddressNoZone ipv4Address, final ByteBuf output) {
+        if (ipv4Address != null) {
+            output.writeBytes(IetfInetUtil.INSTANCE.ipv4AddressNoZoneBytes(ipv4Address));
+        } else {
+            output.writeInt(0);
+        }
+    }
+
+    /**
+     * Writes IPv4 prefix if not null, otherwise writes zeros to the
+     * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 5.
+     *
+     * @param ipv4Prefix
+     *            IPv4 prefix value to be written to the output. Prefix is
+     *            written in the last byte.
+     * @param output
+     *            ByteBuf, where ipv4Prefix or zeros are written.
+     */
+    public static void writeIpv4Prefix(final Ipv4Prefix ipv4Prefix, final ByteBuf output) {
+        if (ipv4Prefix != null) {
+            output.writeBytes(bytesForPrefix(ipv4Prefix));
+        } else {
+            output.writeZero(PREFIX_BYTE_LENGTH);
+        }
+    }
+
+    public static void writeMinimalPrefix(final Ipv4Prefix ipv4Prefix, final ByteBuf output) {
+        final byte[] bytes = IetfInetUtil.INSTANCE.ipv4PrefixToBytes(ipv4Prefix);
+        writeMinimalPrefix(output, bytes, bytes[IP4_LENGTH]);
+    }
+
+    static void writeMinimalPrefix(final ByteBuf output, final byte[] bytes, final byte prefixBits) {
+        output.writeByte(prefixBits);
+        output.writeBytes(bytes, 0, prefixBitsToBytes(Byte.toUnsignedInt(prefixBits)));
+    }
 }
index 48ac62f1fb0c3594deb631594fb4b29b5ae6f69b..7cd6ec51c04cfb807861e4cd5abc171fc7d3d61e 100644 (file)
@@ -161,4 +161,61 @@ public final class Ipv6Util {
         }
         return list;
     }
+
+    /**
+     * Writes IPv6 address if not null, otherwise writes zeros to the
+     * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 16.
+     *
+     * @param ipv6Address
+     *            IPv6 address to be written to the output.
+     * @param output
+     *            ByteBuf, where ipv6Address or zeros are written.
+     */
+    public static void writeIpv6Address(final Ipv6Address ipv6Address, final ByteBuf output) {
+        if (ipv6Address != null) {
+            output.writeBytes(bytesForAddress(ipv6Address));
+        } else {
+            output.writeZero(IPV6_LENGTH);
+        }
+    }
+
+    /**
+     * Writes IPv6 address if not null, otherwise writes zeros to the
+     * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 16.
+     *
+     * @param ipv6Address
+     *            IPv6 address to be written to the output.
+     * @param output
+     *            ByteBuf, where ipv6Address or zeros are written.
+     */
+    public static void writeIpv6Address(final Ipv6AddressNoZone ipv6Address, final ByteBuf output) {
+        if (ipv6Address != null) {
+            output.writeBytes(IetfInetUtil.INSTANCE.ipv6AddressNoZoneBytes(ipv6Address));
+        } else {
+            output.writeZero(IPV6_LENGTH);
+        }
+    }
+
+    /**
+     * Writes IPv6 prefix if not null, otherwise writes zeros to the
+     * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 17.
+     *
+     * @param ipv6Prefix
+     *            IPv6 prefix to be written to the output. Prefix is written in
+     *            the last byte.
+     * @param output
+     *            ByteBuf, where ipv6Prefix or zeros are written.
+     */
+    public static void writeIpv6Prefix(final Ipv6Prefix ipv6Prefix, final ByteBuf output) {
+        if (ipv6Prefix != null) {
+            output.writeBytes(bytesForPrefix(ipv6Prefix));
+        } else {
+            output.writeZero(PREFIX_BYTE_LENGTH);
+        }
+    }
+
+    public static void writeMinimalPrefix(final Ipv6Prefix ipv6Prefix, final ByteBuf output) {
+        final byte[] bytes = IetfInetUtil.INSTANCE.ipv6PrefixToBytes(ipv6Prefix);
+        Ipv4Util.writeMinimalPrefix(output, bytes, bytes[IPV6_LENGTH]);
+    }
 }
index 43241b7cb27c04c2b474eee951c9276213eb5a16..e6a5584de86079dc41eee329b2a6c313f3a3b79e 100644 (file)
@@ -9,76 +9,15 @@ package org.opendaylight.protocol.util;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Address;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Prefix;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Address;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Prefix;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
-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.Ipv6Address;
-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.ieee754.rev130819.Float32;
 
 public class ByteBufWriteUtilTest {
     private static final byte[] FOUR_BYTE_ZEROS = { 0, 0, 0, 0 };
 
-    @Test
-    public void testWriteIpv4Address() {
-        final byte[] result = { 127, 0, 0, 1 };
-        final ByteBuf output = Unpooled.buffer(Ipv4Util.IP4_LENGTH);
-        writeIpv4Address(new Ipv4Address("127.0.0.1"), output);
-        assertArrayEquals(result, output.array());
-
-        output.clear();
-        writeIpv4Address(null, output);
-        assertArrayEquals(FOUR_BYTE_ZEROS, output.array());
-    }
-
-    @Test
-    public void testWriteIpv4Prefix() {
-        final byte[] result = { 123, 122, 4, 5, 8 };
-        final ByteBuf output = Unpooled.buffer(Ipv4Util.PREFIX_BYTE_LENGTH);
-        writeIpv4Prefix(new Ipv4Prefix("123.122.4.5/8"), output);
-        assertArrayEquals(result, output.array());
-
-        output.clear();
-        final byte[] zeroResult = { 0, 0, 0, 0, 0 };
-        writeIpv4Prefix(null, output);
-        assertArrayEquals(zeroResult, output.array());
-    }
-
-    @Test
-    public void testWriteIpv6Address() {
-        final byte[] result = { 0x20, (byte) 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-            0x00, 0x00, 0x01 };
-        final ByteBuf output = Unpooled.buffer(Ipv6Util.IPV6_LENGTH);
-        writeIpv6Address(new Ipv6Address("2001::1"), output);
-        assertArrayEquals(result, output.array());
-
-        output.clear();
-        final byte[] zeroResult = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,};
-        writeIpv6Address(null, output);
-        assertArrayEquals(zeroResult, output.array());
-    }
-
-    @Test
-    public void testWriteIpv6Prefix() {
-        final byte[] result = { 0x20, (byte) 0x01, 0x0d, (byte) 0xb8, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
-            0x00, 0x00, 0x00, 0x00, 0x40 };
-        final ByteBuf output = Unpooled.buffer(Ipv6Util.PREFIX_BYTE_LENGTH);
-        writeIpv6Prefix(new Ipv6Prefix("2001:db8:1:2::/64"), output);
-        assertArrayEquals(result, output.array());
-
-        output.clear();
-        final byte[] zeroResult = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-        writeIpv6Prefix(null, output);
-        assertArrayEquals(zeroResult, output.array());
-    }
-
     @Test
     public void testWriteFloat32() {
         final byte[] result = { 0, 0, 0, 5 };
diff --git a/util/src/test/java/org/opendaylight/protocol/util/Ipv4UtilTest.java b/util/src/test/java/org/opendaylight/protocol/util/Ipv4UtilTest.java
new file mode 100644 (file)
index 0000000..8cfeeea
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.util;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.opendaylight.protocol.util.Ipv4Util.writeIpv4Address;
+import static org.opendaylight.protocol.util.Ipv4Util.writeIpv4Prefix;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
+
+public class Ipv4UtilTest {
+    private static final byte[] FOUR_BYTE_ZEROS = { 0, 0, 0, 0 };
+
+    @Test
+    public void testWriteIpv4Address() {
+        final byte[] result = { 127, 0, 0, 1 };
+        final ByteBuf output = Unpooled.buffer(Ipv4Util.IP4_LENGTH);
+        writeIpv4Address(new Ipv4Address("127.0.0.1"), output);
+        assertArrayEquals(result, output.array());
+
+        output.clear();
+        writeIpv4Address(null, output);
+        assertArrayEquals(FOUR_BYTE_ZEROS, output.array());
+    }
+
+    @Test
+    public void testWriteIpv4Prefix() {
+        final byte[] result = { 123, 122, 4, 5, 8 };
+        final ByteBuf output = Unpooled.buffer(Ipv4Util.PREFIX_BYTE_LENGTH);
+        writeIpv4Prefix(new Ipv4Prefix("123.122.4.5/8"), output);
+        assertArrayEquals(result, output.array());
+
+        output.clear();
+        final byte[] zeroResult = { 0, 0, 0, 0, 0 };
+        writeIpv4Prefix(null, output);
+        assertArrayEquals(zeroResult, output.array());
+    }
+}
diff --git a/util/src/test/java/org/opendaylight/protocol/util/Ipv6UtilTest.java b/util/src/test/java/org/opendaylight/protocol/util/Ipv6UtilTest.java
new file mode 100644 (file)
index 0000000..35afdda
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.util;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.opendaylight.protocol.util.Ipv6Util.writeIpv6Address;
+import static org.opendaylight.protocol.util.Ipv6Util.writeIpv6Prefix;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
+
+public class Ipv6UtilTest {
+    @Test
+    public void testWriteIpv6Address() {
+        final byte[] result = { 0x20, (byte) 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+            0x00, 0x00, 0x01 };
+        final ByteBuf output = Unpooled.buffer(Ipv6Util.IPV6_LENGTH);
+        writeIpv6Address(new Ipv6Address("2001::1"), output);
+        assertArrayEquals(result, output.array());
+
+        output.clear();
+        final byte[] zeroResult = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,};
+        writeIpv6Address(null, output);
+        assertArrayEquals(zeroResult, output.array());
+    }
+
+    @Test
+    public void testWriteIpv6Prefix() {
+        final byte[] result = { 0x20, (byte) 0x01, 0x0d, (byte) 0xb8, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
+            0x00, 0x00, 0x00, 0x00, 0x40 };
+        final ByteBuf output = Unpooled.buffer(Ipv6Util.PREFIX_BYTE_LENGTH);
+        writeIpv6Prefix(new Ipv6Prefix("2001:db8:1:2::/64"), output);
+        assertArrayEquals(result, output.array());
+
+        output.clear();
+        final byte[] zeroResult = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+        writeIpv6Prefix(null, output);
+        assertArrayEquals(zeroResult, output.array());
+    }
+}