From 12b06012259c6609c4b40488c8611a9431a39643 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 6 Jan 2020 16:43:16 +0100 Subject: [PATCH] Move ipv4/ipv6 ByteBuf utilities to Ipv{4,6}Util 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 --- .../evpn/impl/esi/types/RouterIdParser.java | 3 +- .../RedirectIpNextHopEcHandler.java | 5 +- .../communities/RedirectIpv4EcHandler.java | 3 +- .../FSIpv4DestinationPrefixHandler.java | 3 +- .../handlers/FSIpv4SourcePrefixHandler.java | 7 +- .../bgp/inet/codec/Ipv4NlriParser.java | 6 +- .../bgp/inet/codec/Ipv6NlriParser.java | 6 +- .../bgp/inet/codec/Ipv4NlriParserTest.java | 7 +- .../mcast/nlri/L3vpnMcastNlriSerializer.java | 11 +- .../bgp/labeled/unicast/LUNlriParser.java | 5 +- .../impl/tlvs/BgpRouterIdTlvParser.java | 4 +- .../impl/tlvs/Ipv4InterfaceTlvParser.java | 4 +- .../impl/tlvs/Ipv4NeighborTlvParser.java | 8 +- .../impl/tlvs/Ipv6InterfaceTlvParser.java | 4 +- .../impl/tlvs/Ipv6NeighborTlvParser.java | 4 +- .../linkstate/impl/tlvs/ReachTlvParser.java | 31 ++--- .../linkstate/spi/AbstractTeLspNlriCodec.java | 16 ++- .../impl/message/BGPUpdateMessageParser.java | 12 +- .../communities/Ipv4SpecificEcHandler.java | 14 +- .../communities/RouteOriginIpv4EcHandler.java | 19 +-- .../route/target/RouteTargetIpv4Handler.java | 3 +- ...t4SpecificExtendedCommunityCommonUtil.java | 3 +- .../bmp/parser/message/PeerUpHandler.java | 22 ++- .../AbstractBmpPerPeerMessageParser.java | 7 +- .../object/AbstractPccIdReqObjectParser.java | 13 +- .../object/AbstractPceIdObjectParser.java | 13 +- .../points/PCEPEndPointsIpv4ObjectParser.java | 16 +-- .../points/PCEPEndPointsIpv6ObjectParser.java | 16 +-- .../PCEPP2MPEndPointsIpv4ObjectParser.java | 15 +-- .../PCEPP2MPEndPointsIpv6ObjectParser.java | 15 +-- .../PCEPIpv4UnreachDestinationParser.java | 10 +- .../PCEPIpv6UnreachDestinationParser.java | 10 +- .../EROIpv4PrefixSubobjectParser.java | 32 ++--- .../EROIpv6PrefixSubobjectParser.java | 22 +-- .../RROIpv4PrefixSubobjectParser.java | 35 +++-- .../RROIpv6PrefixSubobjectParser.java | 19 +-- .../XROIpv4PrefixSubobjectParser.java | 6 +- .../XROIpv6PrefixSubobjectParser.java | 3 +- .../Stateful07LSPIdentifierIpv4TlvParser.java | 7 +- .../Stateful07LSPIdentifierIpv6TlvParser.java | 7 +- .../Stateful07RSVPErrorSpecTlvParser.java | 6 +- .../routing/AbstractSrSubobjectParser.java | 14 +- .../ero/EROIpv4PrefixSubobjectParser.java | 32 ++--- .../ero/EROIpv6PrefixSubobjectParser.java | 26 ++-- .../rro/RROIpv4PrefixSubobjectParser.java | 39 +++--- .../rro/RROIpv6PrefixSubobjectParser.java | 24 ++-- .../xro/XROIpv4PrefixSubobjectParser.java | 30 +++-- .../xro/XROIpv6PrefixSubobjectParser.java | 26 ++-- .../impl/te/DetourObjectIpv4Parser.java | 11 +- .../protocol/util/ByteBufWriteUtil.java | 126 ------------------ .../opendaylight/protocol/util/Ipv4Util.java | 65 ++++++++- .../opendaylight/protocol/util/Ipv6Util.java | 57 ++++++++ .../protocol/util/ByteBufWriteUtilTest.java | 61 --------- .../protocol/util/Ipv4UtilTest.java | 47 +++++++ .../protocol/util/Ipv6UtilTest.java | 48 +++++++ 55 files changed, 509 insertions(+), 549 deletions(-) create mode 100644 util/src/test/java/org/opendaylight/protocol/util/Ipv4UtilTest.java create mode 100644 util/src/test/java/org/opendaylight/protocol/util/Ipv6UtilTest.java diff --git a/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/RouterIdParser.java b/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/RouterIdParser.java index f29ad02a8b..4cb3fb8a5f 100644 --- a/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/RouterIdParser.java +++ b/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/RouterIdParser.java @@ -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); } diff --git a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/RedirectIpNextHopEcHandler.java b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/RedirectIpNextHopEcHandler.java index 647e5353e7..bcb643d514 100644 --- a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/RedirectIpNextHopEcHandler.java +++ b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/RedirectIpNextHopEcHandler.java @@ -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); } diff --git a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/RedirectIpv4EcHandler.java b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/RedirectIpv4EcHandler.java index d31b5eed5a..3c3cf7ec4b 100644 --- a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/RedirectIpv4EcHandler.java +++ b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/RedirectIpv4EcHandler.java @@ -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()); } diff --git a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv4DestinationPrefixHandler.java b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv4DestinationPrefixHandler.java index f12849d145..1c5ed2b4b3 100644 --- a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv4DestinationPrefixHandler.java +++ b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv4DestinationPrefixHandler.java @@ -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 diff --git a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv4SourcePrefixHandler.java b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv4SourcePrefixHandler.java index c222eebabd..3205567967 100644 --- a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv4SourcePrefixHandler.java +++ b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv4SourcePrefixHandler.java @@ -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 diff --git a/bgp/extensions/inet/src/main/java/org/opendaylight/protocol/bgp/inet/codec/Ipv4NlriParser.java b/bgp/extensions/inet/src/main/java/org/opendaylight/protocol/bgp/inet/codec/Ipv4NlriParser.java index 3064f00778..70d1426a93 100644 --- a/bgp/extensions/inet/src/main/java/org/opendaylight/protocol/bgp/inet/codec/Ipv4NlriParser.java +++ b/bgp/extensions/inet/src/main/java/org/opendaylight/protocol/bgp/inet/codec/Ipv4NlriParser.java @@ -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); } } } diff --git a/bgp/extensions/inet/src/main/java/org/opendaylight/protocol/bgp/inet/codec/Ipv6NlriParser.java b/bgp/extensions/inet/src/main/java/org/opendaylight/protocol/bgp/inet/codec/Ipv6NlriParser.java index 7af69ba40f..12ee5b1820 100644 --- a/bgp/extensions/inet/src/main/java/org/opendaylight/protocol/bgp/inet/codec/Ipv6NlriParser.java +++ b/bgp/extensions/inet/src/main/java/org/opendaylight/protocol/bgp/inet/codec/Ipv6NlriParser.java @@ -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); } } } diff --git a/bgp/extensions/inet/src/test/java/org/opendaylight/protocol/bgp/inet/codec/Ipv4NlriParserTest.java b/bgp/extensions/inet/src/test/java/org/opendaylight/protocol/bgp/inet/codec/Ipv4NlriParserTest.java index e9e128aeed..c8a9a18b50 100644 --- a/bgp/extensions/inet/src/test/java/org/opendaylight/protocol/bgp/inet/codec/Ipv4NlriParserTest.java +++ b/bgp/extensions/inet/src/test/java/org/opendaylight/protocol/bgp/inet/codec/Ipv4NlriParserTest.java @@ -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()); diff --git a/bgp/extensions/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/mcast/nlri/L3vpnMcastNlriSerializer.java b/bgp/extensions/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/mcast/nlri/L3vpnMcastNlriSerializer.java index eaa0dc4c04..2fa9a3ce36 100644 --- a/bgp/extensions/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/mcast/nlri/L3vpnMcastNlriSerializer.java +++ b/bgp/extensions/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/mcast/nlri/L3vpnMcastNlriSerializer.java @@ -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) { diff --git a/bgp/extensions/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/LUNlriParser.java b/bgp/extensions/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/LUNlriParser.java index a34da0d4fb..44ebe7066a 100644 --- a/bgp/extensions/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/LUNlriParser.java +++ b/bgp/extensions/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/LUNlriParser.java @@ -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); } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/BgpRouterIdTlvParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/BgpRouterIdTlvParser.java index 1dde64647f..fd4f76b8a0 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/BgpRouterIdTlvParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/BgpRouterIdTlvParser.java @@ -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, LinkstateTlvParser.LinkstateTlvSerializer { - 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 diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/Ipv4InterfaceTlvParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/Ipv4InterfaceTlvParser.java index 5f2be7273c..34cdd6e254 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/Ipv4InterfaceTlvParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/Ipv4InterfaceTlvParser.java @@ -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, LinkstateTlvParser.LinkstateTlvSerializer { - 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, LinkstateTlvParser.LinkstateTlvSerializer { - - 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 diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/Ipv6InterfaceTlvParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/Ipv6InterfaceTlvParser.java index b4c7398b10..2c3b238843 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/Ipv6InterfaceTlvParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/Ipv6InterfaceTlvParser.java @@ -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, LinkstateTlvParser.LinkstateTlvSerializer { - 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, LinkstateTlvParser.LinkstateTlvSerializer { - 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 { + 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); } } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/AbstractTeLspNlriCodec.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/AbstractTeLspNlriCodec.java index 7813f2d9f2..58cfd5d904 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/AbstractTeLspNlriCodec.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/AbstractTeLspNlriCodec.java @@ -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) { diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPUpdateMessageParser.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPUpdateMessageParser.java index 7e4154eec7..77da9019c3 100755 --- a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPUpdateMessageParser.java +++ b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPUpdateMessageParser.java @@ -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 BGP-4 Update Message Format */ 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, diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/Ipv4SpecificEcHandler.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/Ipv4SpecificEcHandler.java index dc318c46a4..b3c271e828 100644 --- a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/Ipv4SpecificEcHandler.java +++ b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/Ipv4SpecificEcHandler.java @@ -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; } - } diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/RouteOriginIpv4EcHandler.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/RouteOriginIpv4EcHandler.java index 75fa2c71c6..3eac8d6dec 100644 --- a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/RouteOriginIpv4EcHandler.java +++ b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/RouteOriginIpv4EcHandler.java @@ -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 diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/route/target/RouteTargetIpv4Handler.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/route/target/RouteTargetIpv4Handler.java index 0aece7e491..1bf90ab02e 100644 --- a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/route/target/RouteTargetIpv4Handler.java +++ b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/route/target/RouteTargetIpv4Handler.java @@ -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()); } diff --git a/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/extended/community/Inet4SpecificExtendedCommunityCommonUtil.java b/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/extended/community/Inet4SpecificExtendedCommunityCommonUtil.java index bca69fe91d..3da2f02077 100644 --- a/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/extended/community/Inet4SpecificExtendedCommunityCommonUtil.java +++ b/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/extended/community/Inet4SpecificExtendedCommunityCommonUtil.java @@ -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()); } } diff --git a/bmp/bmp-parser-impl/src/main/java/org/opendaylight/protocol/bmp/parser/message/PeerUpHandler.java b/bmp/bmp-parser-impl/src/main/java/org/opendaylight/protocol/bmp/parser/message/PeerUpHandler.java index 2fadb1aaa3..2b03ce47cf 100644 --- a/bmp/bmp-parser-impl/src/main/java/org/opendaylight/protocol/bmp/parser/message/PeerUpHandler.java +++ b/bmp/bmp-parser-impl/src/main/java/org/opendaylight/protocol/bmp/parser/message/PeerUpHandler.java @@ -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> 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) { diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/AbstractPccIdReqObjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/AbstractPccIdReqObjectParser.java index 2b3c421293..a1ae5985d8 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/AbstractPccIdReqObjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/AbstractPccIdReqObjectParser.java @@ -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); } diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/AbstractPceIdObjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/AbstractPceIdObjectParser.java index 70e1404cf2..08a0cb5e86 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/AbstractPceIdObjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/AbstractPceIdObjectParser.java @@ -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); } diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/end/points/PCEPEndPointsIpv4ObjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/end/points/PCEPEndPointsIpv4ObjectParser.java index 54e8d50bbf..461c1e2272 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/end/points/PCEPEndPointsIpv4ObjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/end/points/PCEPEndPointsIpv4ObjectParser.java @@ -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."); diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/end/points/PCEPEndPointsIpv6ObjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/end/points/PCEPEndPointsIpv6ObjectParser.java index 5399cde7ec..775961fa21 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/end/points/PCEPEndPointsIpv6ObjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/end/points/PCEPEndPointsIpv6ObjectParser.java @@ -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."); diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/end/points/PCEPP2MPEndPointsIpv4ObjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/end/points/PCEPP2MPEndPointsIpv4ObjectParser.java index 6eb97d894e..369eadf1df 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/end/points/PCEPP2MPEndPointsIpv4ObjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/end/points/PCEPP2MPEndPointsIpv4ObjectParser.java @@ -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 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."); diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/end/points/PCEPP2MPEndPointsIpv6ObjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/end/points/PCEPP2MPEndPointsIpv6ObjectParser.java index dad61e6d0e..ff3d83c97a 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/end/points/PCEPP2MPEndPointsIpv6ObjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/end/points/PCEPP2MPEndPointsIpv6ObjectParser.java @@ -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 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()); diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/unreach/PCEPIpv4UnreachDestinationParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/unreach/PCEPIpv4UnreachDestinationParser.java index c3840e4013..25bfca7651 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/unreach/PCEPIpv4UnreachDestinationParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/unreach/PCEPIpv4UnreachDestinationParser.java @@ -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 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."); diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/unreach/PCEPIpv6UnreachDestinationParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/unreach/PCEPIpv6UnreachDestinationParser.java index 0c8be58cb3..21cf459a58 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/unreach/PCEPIpv6UnreachDestinationParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/unreach/PCEPIpv6UnreachDestinationParser.java @@ -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 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."); diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/EROIpv4PrefixSubobjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/EROIpv4PrefixSubobjectParser.java index c3e8877367..29a58f09c1 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/EROIpv4PrefixSubobjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/EROIpv4PrefixSubobjectParser.java @@ -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); } } diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/EROIpv6PrefixSubobjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/EROIpv6PrefixSubobjectParser.java index 8eeccaebbb..274e1a3769 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/EROIpv6PrefixSubobjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/EROIpv6PrefixSubobjectParser.java @@ -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); } diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/RROIpv4PrefixSubobjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/RROIpv4PrefixSubobjectParser.java index 014b3980d1..636107d23a 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/RROIpv4PrefixSubobjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/RROIpv4PrefixSubobjectParser.java @@ -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); } } diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/RROIpv6PrefixSubobjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/RROIpv6PrefixSubobjectParser.java index dc48654f28..d82c3fce73 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/RROIpv6PrefixSubobjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/RROIpv6PrefixSubobjectParser.java @@ -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); } diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROIpv4PrefixSubobjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROIpv4PrefixSubobjectParser.java index 92bd5271b8..d6b903d1d9 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROIpv4PrefixSubobjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROIpv4PrefixSubobjectParser.java @@ -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()); diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROIpv6PrefixSubobjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROIpv6PrefixSubobjectParser.java index e1692a7756..69c09127c4 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROIpv6PrefixSubobjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROIpv6PrefixSubobjectParser.java @@ -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()); diff --git a/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LSPIdentifierIpv4TlvParser.java b/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LSPIdentifierIpv4TlvParser.java index 04a177b1aa..53eb5691dd 100644 --- a/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LSPIdentifierIpv4TlvParser.java +++ b/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LSPIdentifierIpv4TlvParser.java @@ -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); } } diff --git a/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LSPIdentifierIpv6TlvParser.java b/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LSPIdentifierIpv6TlvParser.java index 007b270f51..badb1c7536 100644 --- a/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LSPIdentifierIpv6TlvParser.java +++ b/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LSPIdentifierIpv6TlvParser.java @@ -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); } } diff --git a/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07RSVPErrorSpecTlvParser.java b/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07RSVPErrorSpecTlvParser.java index c88b2b994c..01c908f6b9 100644 --- a/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07RSVPErrorSpecTlvParser.java +++ b/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07RSVPErrorSpecTlvParser.java @@ -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"); diff --git a/pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/segment/routing/AbstractSrSubobjectParser.java b/pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/segment/routing/AbstractSrSubobjectParser.java index b4ecebf9e0..6842b24e20 100644 --- a/pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/segment/routing/AbstractSrSubobjectParser.java +++ b/pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/segment/routing/AbstractSrSubobjectParser.java @@ -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; diff --git a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/ero/EROIpv4PrefixSubobjectParser.java b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/ero/EROIpv4PrefixSubobjectParser.java index ff21296293..a6c92bd18e 100644 --- a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/ero/EROIpv4PrefixSubobjectParser.java +++ b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/ero/EROIpv4PrefixSubobjectParser.java @@ -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); } } diff --git a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/ero/EROIpv6PrefixSubobjectParser.java b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/ero/EROIpv6PrefixSubobjectParser.java index 1f1af905c5..0ab248a47f 100644 --- a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/ero/EROIpv6PrefixSubobjectParser.java +++ b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/ero/EROIpv6PrefixSubobjectParser.java @@ -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); } diff --git a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/rro/RROIpv4PrefixSubobjectParser.java b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/rro/RROIpv4PrefixSubobjectParser.java index d0332feeb0..ef81d3535c 100644 --- a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/rro/RROIpv4PrefixSubobjectParser.java +++ b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/rro/RROIpv4PrefixSubobjectParser.java @@ -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); } } diff --git a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/rro/RROIpv6PrefixSubobjectParser.java b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/rro/RROIpv6PrefixSubobjectParser.java index dde28bf35c..aebbe288dc 100644 --- a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/rro/RROIpv6PrefixSubobjectParser.java +++ b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/rro/RROIpv6PrefixSubobjectParser.java @@ -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); } diff --git a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/xro/XROIpv4PrefixSubobjectParser.java b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/xro/XROIpv4PrefixSubobjectParser.java index d6e2a073b5..b87d01cbdf 100644 --- a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/xro/XROIpv4PrefixSubobjectParser.java +++ b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/xro/XROIpv4PrefixSubobjectParser.java @@ -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); } } diff --git a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/xro/XROIpv6PrefixSubobjectParser.java b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/xro/XROIpv6PrefixSubobjectParser.java index 5f78e0bdea..67f4809445 100644 --- a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/xro/XROIpv6PrefixSubobjectParser.java +++ b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/xro/XROIpv6PrefixSubobjectParser.java @@ -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); } } diff --git a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/DetourObjectIpv4Parser.java b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/DetourObjectIpv4Parser.java index 02ebd79f97..e3afde14ef 100644 --- a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/DetourObjectIpv4Parser.java +++ b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/DetourObjectIpv4Parser.java @@ -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 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); } } } diff --git a/util/src/main/java/org/opendaylight/protocol/util/ByteBufWriteUtil.java b/util/src/main/java/org/opendaylight/protocol/util/ByteBufWriteUtil.java index 4ef722db2b..53dedcb8f8 100644 --- a/util/src/main/java/org/opendaylight/protocol/util/ByteBufWriteUtil.java +++ b/util/src/main/java/org/opendaylight/protocol/util/ByteBufWriteUtil.java @@ -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 - * output 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 - * output 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 - * output 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 - * output 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 - * output 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 - * output 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 value if not null, otherwise writes zeros to * the output ByteBuf. ByteBuf's writerIndex is increased by 4. diff --git a/util/src/main/java/org/opendaylight/protocol/util/Ipv4Util.java b/util/src/main/java/org/opendaylight/protocol/util/Ipv4Util.java index ee65399879..3b10fca15d 100644 --- a/util/src/main/java/org/opendaylight/protocol/util/Ipv4Util.java +++ b/util/src/main/java/org/opendaylight/protocol/util/Ipv4Util.java @@ -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 + * output 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 + * output 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 + * output 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))); + } } diff --git a/util/src/main/java/org/opendaylight/protocol/util/Ipv6Util.java b/util/src/main/java/org/opendaylight/protocol/util/Ipv6Util.java index 48ac62f1fb..7cd6ec51c0 100644 --- a/util/src/main/java/org/opendaylight/protocol/util/Ipv6Util.java +++ b/util/src/main/java/org/opendaylight/protocol/util/Ipv6Util.java @@ -161,4 +161,61 @@ public final class Ipv6Util { } return list; } + + /** + * Writes IPv6 address if not null, otherwise writes zeros to the + * output 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 + * output 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 + * output 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]); + } } diff --git a/util/src/test/java/org/opendaylight/protocol/util/ByteBufWriteUtilTest.java b/util/src/test/java/org/opendaylight/protocol/util/ByteBufWriteUtilTest.java index 43241b7cb2..e6a5584de8 100644 --- a/util/src/test/java/org/opendaylight/protocol/util/ByteBufWriteUtilTest.java +++ b/util/src/test/java/org/opendaylight/protocol/util/ByteBufWriteUtilTest.java @@ -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 index 0000000000..8cfeeea0d2 --- /dev/null +++ b/util/src/test/java/org/opendaylight/protocol/util/Ipv4UtilTest.java @@ -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 index 0000000000..35afddaee0 --- /dev/null +++ b/util/src/test/java/org/opendaylight/protocol/util/Ipv6UtilTest.java @@ -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()); + } +} -- 2.36.6