From 2af780b03b67c62c53047f3d24f93fbf1d3afcc1 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 14 Oct 2019 10:56:20 +0200 Subject: [PATCH] Add ByteBufUtils This adds ByteBufUtils, which are an evolution of ByteBufWriteUtils, covering reads of Uint types as well as writing using various approaches to nullness. We also migrate all uint reading tasks to these utility methods, fixing deprecation warnings in the process. Change-Id: I8466dbff77f8469278df4eb92a2aaebcbdeeb6b8 Signed-off-by: Robert Varga --- .../bgp/evpn/impl/esi/types/ASGenParser.java | 5 +- .../bgp/evpn/impl/esi/types/LacpParser.java | 3 +- .../bgp/evpn/impl/esi/types/LanParser.java | 3 +- .../bgp/evpn/impl/esi/types/MacParser.java | 3 +- .../evpn/impl/esi/types/RouterIdParser.java | 3 +- .../communities/Layer2AttributesExtCom.java | 4 +- .../extended/communities/MACMobExtCom.java | 7 +- .../bgp/evpn/impl/nlri/EthADRParser.java | 3 +- .../evpn/impl/nlri/IncMultEthTagRParser.java | 3 +- .../bgp/evpn/impl/nlri/MACIpAdvRParser.java | 3 +- .../protocol/bgp/flowspec/FSDscpHandler.java | 3 +- .../bgp/flowspec/FSIcmpCodeHandler.java | 7 +- .../bgp/flowspec/FSIcmpTypeHandler.java | 7 +- .../bgp/flowspec/FSIpProtocolHandler.java | 7 +- .../bgp/flowspec/FSIpv6NextHeaderHandler.java | 7 +- .../RedirectAsFourOctetEcHandler.java | 5 +- .../RedirectAsTwoOctetEcHandler.java | 4 +- .../communities/RedirectIpv4EcHandler.java | 3 +- .../communities/RedirectIpv6EcHandler.java | 3 +- .../communities/TrafficMarkingEcHandler.java | 3 +- .../communities/TrafficRateEcHandler.java | 3 +- .../labeled/unicast/LabelIndexTlvParser.java | 4 +- .../unicast/OriginatorSrgbTlvParser.java | 5 +- .../impl/attribute/LinkAttributesParser.java | 19 +- .../impl/attribute/NodeAttributesParser.java | 3 +- .../attribute/PrefixAttributesParser.java | 3 +- .../attribute/sr/BindingSidLabelParser.java | 3 +- .../impl/attribute/sr/RangeTlvParser.java | 3 +- .../attribute/sr/SidLabelIndexParser.java | 6 +- .../attribute/sr/SrLinkAttributesParser.java | 7 +- .../attribute/sr/SrNodeAttributesParser.java | 3 +- .../binding/sid/sub/tlvs/EroMetricParser.java | 3 +- .../sid/sub/tlvs/UnnumberedEroParser.java | 5 +- .../impl/nlri/TeLspIpv4NlriParser.java | 6 +- .../impl/nlri/TeLspIpv6NlriParser.java | 6 +- .../linkstate/impl/tlvs/AreaIdTlvParser.java | 3 +- .../linkstate/impl/tlvs/AsNumTlvParser.java | 3 +- .../impl/tlvs/DomainIdTlvParser.java | 3 +- .../impl/tlvs/MemAsNumTlvParser.java | 3 +- .../impl/tlvs/MultiTopoIdTlvParser.java | 2 +- .../impl/tlvs/RouterIdTlvParser.java | 9 +- .../linkstate/spi/AbstractNlriTypeCodec.java | 4 +- .../bgp/mvpn/impl/attributes/OpaqueUtil.java | 7 +- .../identifier/RsvpTeP2MpLspParser.java | 7 +- .../bgp/mvpn/impl/nlri/CMulticastUtil.java | 4 +- .../mvpn/impl/nlri/InterASIPmsiADHandler.java | 4 +- .../nlri/RouteTargetConstrainNlriHandler.java | 3 +- .../policy/spi/RouteEntryBaseAttributes.java | 1 + bgp/openconfig-rp-statement/pom.xml | 4 + .../statement/actions/AsPathPrepend.java | 3 +- .../protocol/bgp/state/NeighborUtil.java | 3 +- .../protocol/bgp/parser/AsNumberUtil.java | 2 +- .../protocol/bgp/parser/BGPError.java | 4 + .../impl/message/BGPOpenMessageParser.java | 6 +- .../message/open/As4CapabilityHandler.java | 3 +- .../open/LlGracefulCapabilityHandler.java | 2 +- .../update/AggregatorAttributeParser.java | 3 +- .../message/update/AigpAttributeParser.java | 4 +- .../message/update/AsPathSegmentParser.java | 3 +- .../impl/message/update/CommunityUtil.java | 12 +- .../LocalPreferenceAttributeParser.java | 3 +- ...MultiExitDiscriminatorAttributeParser.java | 3 +- .../communities/RouteOriginIpv4EcHandler.java | 3 +- .../as/specific/SourceAS4OctectHandler.java | 3 +- .../route/target/RouteTargetIpv4Handler.java | 3 +- .../protocol/bgp/parser/spi/PathIdUtil.java | 3 +- .../community/FourOctAsCommonECUtil.java | 6 +- .../spi/pojo/SimpleAttributeRegistry.java | 7 +- .../impl/AbstractBGPSessionNegotiator.java | 9 +- .../rib/impl/config/GracefulRestartUtil.java | 2 +- .../AbstractBGPSessionNegotiatorTest.java | 5 +- .../protocol/bgp/rib/impl/PeerUtil.java | 4 +- bgp/rib-mock/pom.xml | 4 + .../bgp/rib/mock/EventBusRegistration.java | 3 +- bgp/testtool/pom.xml | 4 + .../protocol/bgp/testtool/Arguments.java | 9 +- .../bgp/testtool/CommunitiesBuilder.java | 10 +- .../bgp/testtool/PrefixesBuilder.java | 7 +- .../bgp/topology/provider/ProtocolUtil.java | 4 +- .../protocol/bmp/impl/app/BmpRibInWriter.java | 8 +- .../protocol/bmp/mock/BmpMockUtil.java | 12 +- .../bmp/parser/message/PeerDownHandler.java | 11 +- .../bmp/parser/message/PeerUpHandler.java | 5 +- .../bmp/parser/tlv/StatType000TlvHandler.java | 3 +- .../bmp/parser/tlv/StatType001TlvHandler.java | 6 +- .../bmp/parser/tlv/StatType002TlvHandler.java | 3 +- .../bmp/parser/tlv/StatType003TlvHandler.java | 5 +- .../bmp/parser/tlv/StatType004TlvHandler.java | 3 +- .../bmp/parser/tlv/StatType005TlvHandler.java | 3 +- .../bmp/parser/tlv/StatType006TlvHandler.java | 3 +- .../bmp/parser/tlv/StatType011TlvHandler.java | 5 +- .../bmp/parser/tlv/StatType012TlvHandler.java | 5 +- .../bmp/parser/tlv/StatType013TlvHandler.java | 3 +- .../AbstractBmpPerPeerMessageParser.java | 7 +- .../counter/TopologyDataChangeCounter.java | 3 +- .../object/PCEPClassTypeObjectParser.java | 13 +- .../parser/object/PCEPCloseObjectParser.java | 15 +- .../parser/object/PCEPErrorObjectParser.java | 5 +- .../PCEPGlobalConstraintsObjectParser.java | 16 +- .../object/PCEPLoadBalancingObjectParser.java | 3 +- .../parser/object/PCEPLspaObjectParser.java | 18 +- .../parser/object/PCEPMetricObjectParser.java | 16 +- .../object/PCEPMonitoringObjectParser.java | 12 +- .../parser/object/PCEPNoPathObjectParser.java | 12 +- .../object/PCEPNotificationObjectParser.java | 5 +- .../PCEPObjectiveFunctionObjectParser.java | 5 +- .../parser/object/PCEPOpenObjectParser.java | 18 +- .../object/PCEPOverloadObjectParser.java | 3 +- .../object/PCEPProcTimeObjectParser.java | 24 +-- .../PCEPRequestParameterObjectParser.java | 16 +- .../parser/object/PCEPSvecObjectParser.java | 5 +- .../parser/subobject/AsNumberCaseParser.java | 14 +- ...EROUnnumberedInterfaceSubobjectParser.java | 20 ++- .../RROPathKey128SubobjectParser.java | 16 +- .../RROPathKey32SubobjectParser.java | 19 +- ...RROUnnumberedInterfaceSubobjectParser.java | 20 ++- .../parser/subobject/Type1LabelParser.java | 21 ++- .../WavebandSwitchingLabelParser.java | 30 ++-- .../XROIpv4PrefixSubobjectParser.java | 17 +- .../XROPathKey128SubobjectParser.java | 22 ++- .../XROPathKey32SubobjectParser.java | 24 +-- .../subobject/XROSRLGSubobjectParser.java | 31 ++-- ...XROUnnumberedInterfaceSubobjectParser.java | 23 +-- .../pcep/parser/tlv/OFListTlvParser.java | 10 +- .../pcep/parser/tlv/OrderTlvParser.java | 10 +- .../tlv/OverloadedDurationTlvParser.java | 7 +- .../pcep/parser/tlv/ReqMissingTlvParser.java | 3 +- .../ietf/stateful07/PathBindingTlvParser.java | 8 +- .../Stateful07LSPIdentifierIpv4TlvParser.java | 6 +- .../Stateful07LSPIdentifierIpv6TlvParser.java | 6 +- .../stateful07/Stateful07LspObjectParser.java | 3 +- .../Stateful07LspUpdateErrorTlvParser.java | 3 +- .../Stateful07RSVPErrorSpecTlvParser.java | 13 +- .../stateful07/Stateful07SrpObjectParser.java | 12 +- .../impl/BasePCEPSessionProposalFactory.java | 5 +- .../pcep/impl/PCEPDispatcherImpl.java | 2 +- .../pcep/impl/LabelSubobjectParserTest.java | 8 +- .../pcep/impl/PCEPEROSubobjectParserTest.java | 8 +- .../pcep/impl/PCEPObjectParserTest.java | 32 ++-- .../pcep/impl/PCEPRROSubobjectParserTest.java | 12 +- .../pcep/impl/PCEPXROSubobjectParserTest.java | 24 +-- .../TestVendorInformationObjectParser.java | 4 +- .../impl/TestVendorInformationTlvParser.java | 3 +- .../pcep/pcc/mock/PCCTunnelBuilder.java | 2 +- .../pcep/pcc/mock/PCCTunnelManagerImpl.java | 2 +- .../pcep/pcc/mock/spi/MsgBuilderUtil.java | 3 +- .../routing/AbstractSrSubobjectParser.java | 9 +- .../routing/PCEPSegmentRoutingCapability.java | 4 +- .../routing/SrPceCapabilityTlvParser.java | 10 +- .../AbstractEROPathKeySubobjectParser.java | 4 +- .../pcep/spi/AbstractMessageParser.java | 3 +- .../spi/AbstractObjectWithTlvsParser.java | 3 +- .../pcep/spi/PCEPErrorIdentifier.java | 2 + .../protocol/pcep/spi/PCEPErrors.java | 1 + .../AbstractTopologySessionListener.java | 3 +- .../Stateful07TopologySessionListener.java | 33 ++-- .../bgpcep/programming/NanotimeUtil.java | 18 +- .../impl/subobject/AsNumberCaseParser.java | 16 +- .../subobject/label/Type1LabelParser.java | 14 +- .../label/WavebandSwitchingLabelParser.java | 29 +-- .../rro/RROPathKey128SubobjectParser.java | 4 +- .../rro/RROPathKey32SubobjectParser.java | 17 +- ...RROUnnumberedInterfaceSubobjectParser.java | 17 +- .../subobject/xro/XROSrlgSubobjectParser.java | 33 ++-- .../impl/te/AbstractAssociationParser.java | 17 +- .../impl/te/FastRerouteObjectParser.java | 17 +- .../parser/impl/te/FlowSpecObjectParser.java | 15 +- .../InformationalFastRerouteObjectParser.java | 20 ++- .../parser/impl/te/MetricObjectParser.java | 19 +- .../impl/te/SenderTspecObjectParser.java | 19 +- .../te/SessionAttributeLspObjectParser.java | 18 +- .../te/SessionAttributeLspRaObjectParser.java | 21 ++- .../parser/impl/EROSubobjectParserTest.java | 4 +- .../parser/impl/LabelSubobjectParserTest.java | 8 +- .../parser/impl/RROSubobjectParserTest.java | 8 +- .../parser/impl/XROSubobjectParserTest.java | 8 +- .../spi/subobjects/CommonPathKeyParser.java | 11 +- ...monUnnumberedInterfaceSubobjectParser.java | 19 +- .../protocol/util/ByteBufUtils.java | 166 ++++++++++++++++++ .../protocol/util/ByteBufUtilsTest.java | 117 ++++++++++++ 180 files changed, 1152 insertions(+), 628 deletions(-) create mode 100644 util/src/main/java/org/opendaylight/protocol/util/ByteBufUtils.java create mode 100644 util/src/test/java/org/opendaylight/protocol/util/ByteBufUtilsTest.java diff --git a/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/ASGenParser.java b/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/ASGenParser.java index bf63114936..da03b1a9b4 100644 --- a/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/ASGenParser.java +++ b/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/ASGenParser.java @@ -13,6 +13,7 @@ import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.ext import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt; import io.netty.buffer.ByteBuf; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.EsiType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.esi.Esi; @@ -52,8 +53,8 @@ final class ASGenParser extends AbstractEsiType { public Esi parseEsi(final ByteBuf buffer) { return new AsGeneratedCaseBuilder() .setAsGenerated(new AsGeneratedBuilder() - .setAs(new AsNumber(buffer.readUnsignedInt())) - .setLocalDiscriminator(buffer.readUnsignedInt()) + .setAs(new AsNumber(ByteBufUtils.readUint32(buffer))) + .setLocalDiscriminator(ByteBufUtils.readUint32(buffer)) .build()) .build(); } diff --git a/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/LacpParser.java b/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/LacpParser.java index 4ee4b04771..a2bdc2e5a7 100644 --- a/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/LacpParser.java +++ b/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/LacpParser.java @@ -13,6 +13,7 @@ import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.ext import io.netty.buffer.ByteBuf; import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.protocol.util.ByteBufWriteUtil; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.IetfYangUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.EsiType; @@ -56,7 +57,7 @@ final class LacpParser extends AbstractEsiType { .setLacpAutoGenerated(new LacpAutoGeneratedBuilder() .setCeLacpMacAddress(IetfYangUtil.INSTANCE.macAddressFor( ByteArray.readBytes(buffer, MAC_ADDRESS_LENGTH))) - .setCeLacpPortKey(buffer.readUnsignedShort()) + .setCeLacpPortKey(ByteBufUtils.readUint16(buffer)) .build()) .build(); } diff --git a/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/LanParser.java b/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/LanParser.java index 6f1d3b41d1..0065a97ccd 100644 --- a/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/LanParser.java +++ b/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/LanParser.java @@ -13,6 +13,7 @@ import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.ext import io.netty.buffer.ByteBuf; import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.protocol.util.ByteBufWriteUtil; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.IetfYangUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.EsiType; @@ -56,7 +57,7 @@ final class LanParser extends AbstractEsiType { .setLanAutoGenerated(new LanAutoGeneratedBuilder() .setRootBridgeMacAddress(IetfYangUtil.INSTANCE.macAddressFor( ByteArray.readBytes(buffer, MAC_ADDRESS_LENGTH))) - .setRootBridgePriority(buffer.readUnsignedShort()) + .setRootBridgePriority(ByteBufUtils.readUint16(buffer)) .build()) .build(); } diff --git a/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/MacParser.java b/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/MacParser.java index e6135bd668..7aa9adcd8e 100644 --- a/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/MacParser.java +++ b/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/MacParser.java @@ -14,6 +14,7 @@ import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.ext import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.protocol.util.ByteBufWriteUtil; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.IetfYangUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.EsiType; @@ -58,7 +59,7 @@ final class MacParser extends AbstractEsiType { .setMacAutoGenerated(new MacAutoGeneratedBuilder() .setSystemMacAddress(IetfYangUtil.INSTANCE.macAddressFor( ByteArray.readBytes(buffer, MAC_ADDRESS_LENGTH))) - .setLocalDiscriminator(new Uint24(Long.valueOf(buffer.readUnsignedMedium()))) + .setLocalDiscriminator(new Uint24(ByteBufUtils.readUint24(buffer))) .build()) .build(); } 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 81d021b6b9..6ec1aa5037 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,6 +12,7 @@ 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.ByteBufUtils; import org.opendaylight.protocol.util.ByteBufWriteUtil; import org.opendaylight.protocol.util.Ipv4Util; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.EsiType; @@ -54,7 +55,7 @@ final class RouterIdParser extends AbstractEsiType { return new RouterIdGeneratedCaseBuilder() .setRouterIdGenerated(new RouterIdGeneratedBuilder() .setRouterId(Ipv4Util.addressForByteBuf(buffer)) - .setLocalDiscriminator(buffer.readUnsignedInt()) + .setLocalDiscriminator(ByteBufUtils.readUint32(buffer)) .build()) .build(); } diff --git a/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/Layer2AttributesExtCom.java b/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/Layer2AttributesExtCom.java index d4e85aacf2..b70751f02a 100644 --- a/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/Layer2AttributesExtCom.java +++ b/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/Layer2AttributesExtCom.java @@ -5,13 +5,13 @@ * 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.evpn.impl.extended.communities; import com.google.common.base.Preconditions; import com.google.common.primitives.UnsignedBytes; import io.netty.buffer.ByteBuf; import org.opendaylight.protocol.util.BitArray; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.protocol.util.ByteBufWriteUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.NormalizationType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.OperationalMode; @@ -52,7 +52,7 @@ public class Layer2AttributesExtCom extends AbstractExtendedCommunities { builder.setModeOfOperation(OperationalMode.forValue(getFlagShort(flags, MODE_OF_OPERATION))); builder.setOperatingPer(NormalizationType.forValue(getFlagShort(flags, NORMALIZATION_TYPE))); - builder.setL2Mtu(body.readUnsignedShort()); + builder.setL2Mtu(ByteBufUtils.readUint16(body)); body.skipBytes(RESERVED); return new Layer2AttributesExtendedCommunityCaseBuilder() .setLayer2AttributesExtendedCommunity(builder.build()).build(); diff --git a/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/MACMobExtCom.java b/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/MACMobExtCom.java index f0672de015..91683c1981 100644 --- a/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/MACMobExtCom.java +++ b/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/MACMobExtCom.java @@ -11,6 +11,7 @@ import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import org.opendaylight.protocol.bgp.parser.BGPDocumentedException; import org.opendaylight.protocol.bgp.parser.BGPParsingException; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.MacMobilityExtendedCommunityCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.MacMobilityExtendedCommunityCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.mac.mobility.extended.community.MacMobilityExtendedCommunity; @@ -26,10 +27,12 @@ public final class MACMobExtCom extends AbstractExtendedCommunities { throws BGPDocumentedException, BGPParsingException { final boolean isStatic = buffer.readBoolean(); buffer.skipBytes(RESERVED); - final long seqNumber = buffer.readUnsignedInt(); return new MacMobilityExtendedCommunityCaseBuilder() .setMacMobilityExtendedCommunity(new MacMobilityExtendedCommunityBuilder() - .setStatic(isStatic).setSeqNumber(seqNumber).build()).build(); + .setStatic(isStatic) + .setSeqNumber(ByteBufUtils.readUint32(buffer)) + .build()) + .build(); } @Override diff --git a/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/EthADRParser.java b/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/EthADRParser.java index 826f62265d..513c3ba2c5 100644 --- a/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/EthADRParser.java +++ b/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/EthADRParser.java @@ -17,6 +17,7 @@ import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.bgp.evpn.spi.pojo.SimpleEsiTypeRegistry; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.protocol.util.ByteBufWriteUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.NlriType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.esi.Esi; @@ -40,7 +41,7 @@ final class EthADRParser extends AbstractEvpnNlri { Preconditions.checkArgument(buffer.readableBytes() == CONTENT_LENGTH, "Wrong length of array of bytes. Passed: %s ;", buffer); final Esi esi = SimpleEsiTypeRegistry.getInstance().parseEsi(buffer.readSlice(ESI_SIZE)); - final EthernetTagId eti = new EthernetTagIdBuilder().setVlanId(buffer.readUnsignedInt()).build(); + final EthernetTagId eti = new EthernetTagIdBuilder().setVlanId(ByteBufUtils.readUint32(buffer)).build(); final MplsLabel label = mplsLabelForByteBuf(buffer); final EthernetADRouteBuilder builder = new EthernetADRouteBuilder() .setEsi(esi).setEthernetTagId(eti).setMplsLabel(label); diff --git a/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/IncMultEthTagRParser.java b/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/IncMultEthTagRParser.java index f6ca9d2bc4..ae151dfced 100644 --- a/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/IncMultEthTagRParser.java +++ b/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/IncMultEthTagRParser.java @@ -15,6 +15,7 @@ import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.bgp.concepts.IpAddressUtil; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.protocol.util.ByteBufWriteUtil; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.NlriType; @@ -46,7 +47,7 @@ final class IncMultEthTagRParser extends AbstractEvpnNlri { || buffer.readableBytes() == CONTENT_LENGTH2, "Wrong length of array of bytes. Passed: %s ;", buffer); - final EthernetTagId eti = new EthernetTagIdBuilder().setVlanId(buffer.readUnsignedInt()).build(); + final EthernetTagId eti = new EthernetTagIdBuilder().setVlanId(ByteBufUtils.readUint32(buffer)).build(); IpAddress ip = IpAddressUtil.addressForByteBuf(buffer); final IncMultiEthernetTagResBuilder builder = new IncMultiEthernetTagResBuilder() .setEthernetTagId(eti).setOrigRouteIp(ip); diff --git a/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/MACIpAdvRParser.java b/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/MACIpAdvRParser.java index d10e6ef48f..cea7f0d05b 100644 --- a/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/MACIpAdvRParser.java +++ b/bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/MACIpAdvRParser.java @@ -22,6 +22,7 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.bgp.evpn.spi.pojo.SimpleEsiTypeRegistry; import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.protocol.util.ByteBufWriteUtil; import org.opendaylight.protocol.util.Ipv4Util; import org.opendaylight.protocol.util.Ipv6Util; @@ -48,7 +49,7 @@ final class MACIpAdvRParser extends AbstractEvpnNlri { @Override public EvpnChoice parseEvpn(final ByteBuf buffer) { final Esi esi = SimpleEsiTypeRegistry.getInstance().parseEsi(buffer.readSlice(ESI_SIZE)); - final EthernetTagId eti = new EthernetTagIdBuilder().setVlanId(buffer.readUnsignedInt()).build(); + final EthernetTagId eti = new EthernetTagIdBuilder().setVlanId(ByteBufUtils.readUint32(buffer)).build(); buffer.skipBytes(1); final MacAddress mac = IetfYangUtil.INSTANCE.macAddressFor(ByteArray.readBytes(buffer, MAC_ADDRESS_LENGTH)); final IpAddress ip = parseIp(buffer); diff --git a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSDscpHandler.java b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSDscpHandler.java index 8ec58f146a..792026f6d2 100644 --- a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSDscpHandler.java +++ b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSDscpHandler.java @@ -18,6 +18,7 @@ import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser; import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer; import org.opendaylight.protocol.bgp.flowspec.handlers.NumericOneByteOperandParser; import org.opendaylight.protocol.bgp.flowspec.handlers.Util; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.Dscp; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.NumericOperand; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.flowspec.FlowspecType; @@ -47,7 +48,7 @@ public final class FSDscpHandler implements FlowspecTypeParser, FlowspecTypeSeri // RFC does not specify operator final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b); builder.setOp(op); - builder.setValue(new Dscp(nlri.readUnsignedByte())); + builder.setValue(new Dscp(ByteBufUtils.readUint8(nlri))); end = op.isEndOfList(); dscps.add(builder.build()); } diff --git a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIcmpCodeHandler.java b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIcmpCodeHandler.java index e9e6e124a6..79977b0d19 100644 --- a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIcmpCodeHandler.java +++ b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIcmpCodeHandler.java @@ -16,6 +16,7 @@ import java.util.List; import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser; import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer; import org.opendaylight.protocol.bgp.flowspec.handlers.NumericOneByteOperandParser; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.NumericOperand; 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.flowspec.flowspec.type.IcmpCodeCase; @@ -27,14 +28,14 @@ public final class FSIcmpCodeHandler implements FlowspecTypeParser, FlowspecType public static final int ICMP_CODE_VALUE = 8; @Override - public void serializeType(FlowspecType fsType, ByteBuf output) { + public void serializeType(final FlowspecType fsType, final ByteBuf output) { Preconditions.checkArgument(fsType instanceof IcmpCodeCase, "IcmpCodeCase class is mandatory!"); output.writeByte(ICMP_CODE_VALUE); NumericOneByteOperandParser.INSTANCE.serialize(((IcmpCodeCase) fsType).getCodes(), output); } @Override - public FlowspecType parseType(ByteBuf buffer) { + public FlowspecType parseType(final ByteBuf buffer) { requireNonNull(buffer, "input buffer is null, missing data to parse."); return new IcmpCodeCaseBuilder().setCodes(parseIcmpCode(buffer)).build(); } @@ -48,7 +49,7 @@ public final class FSIcmpCodeHandler implements FlowspecTypeParser, FlowspecType final byte b = nlri.readByte(); final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b); builder.setOp(op); - builder.setValue(nlri.readUnsignedByte()); + builder.setValue(ByteBufUtils.readUint8(nlri)); end = op.isEndOfList(); codes.add(builder.build()); } diff --git a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIcmpTypeHandler.java b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIcmpTypeHandler.java index 758df256c2..8dd1611831 100644 --- a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIcmpTypeHandler.java +++ b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIcmpTypeHandler.java @@ -16,6 +16,7 @@ import java.util.List; import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser; import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer; import org.opendaylight.protocol.bgp.flowspec.handlers.NumericOneByteOperandParser; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.NumericOperand; 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.flowspec.flowspec.type.IcmpTypeCase; @@ -27,14 +28,14 @@ public final class FSIcmpTypeHandler implements FlowspecTypeParser, FlowspecType public static final int ICMP_TYPE_VALUE = 7; @Override - public void serializeType(FlowspecType fsType, ByteBuf output) { + public void serializeType(final FlowspecType fsType, final ByteBuf output) { Preconditions.checkArgument(fsType instanceof IcmpTypeCase, "IcmpTypeCase class is mandatory!"); output.writeByte(ICMP_TYPE_VALUE); NumericOneByteOperandParser.INSTANCE.serialize(((IcmpTypeCase) fsType).getTypes(), output); } @Override - public FlowspecType parseType(ByteBuf buffer) { + public FlowspecType parseType(final ByteBuf buffer) { requireNonNull(buffer, "input buffer is null, missing data to parse."); return new IcmpTypeCaseBuilder().setTypes(parseIcmpType(buffer)).build(); } @@ -48,7 +49,7 @@ public final class FSIcmpTypeHandler implements FlowspecTypeParser, FlowspecType final byte b = nlri.readByte(); final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b); builder.setOp(op); - builder.setValue(nlri.readUnsignedByte()); + builder.setValue(ByteBufUtils.readUint8(nlri)); end = op.isEndOfList(); icmps.add(builder.build()); } diff --git a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIpProtocolHandler.java b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIpProtocolHandler.java index eb4bcf9e28..0dbabfc7cb 100644 --- a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIpProtocolHandler.java +++ b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIpProtocolHandler.java @@ -16,6 +16,7 @@ import java.util.List; import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser; import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer; import org.opendaylight.protocol.bgp.flowspec.handlers.NumericOneByteOperandParser; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.NumericOperand; 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.ProtocolIpCase; @@ -27,14 +28,14 @@ public final class FSIpProtocolHandler implements FlowspecTypeParser, FlowspecTy public static final int IP_PROTOCOL_VALUE = 3; @Override - public void serializeType(FlowspecType fsType, ByteBuf output) { + public void serializeType(final FlowspecType fsType, final ByteBuf output) { Preconditions.checkArgument(fsType instanceof ProtocolIpCase, "ProtocolIpCase class is mandatory!"); output.writeByte(IP_PROTOCOL_VALUE); NumericOneByteOperandParser.INSTANCE.serialize(((ProtocolIpCase) fsType).getProtocolIps(), output); } @Override - public FlowspecType parseType(ByteBuf buffer) { + public FlowspecType parseType(final ByteBuf buffer) { requireNonNull(buffer, "input buffer is null, missing data to parse."); return new ProtocolIpCaseBuilder().setProtocolIps(parseProtocolIp(buffer)).build(); } @@ -48,7 +49,7 @@ public final class FSIpProtocolHandler implements FlowspecTypeParser, FlowspecTy final byte b = nlri.readByte(); final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b); builder.setOp(op); - builder.setValue(nlri.readUnsignedByte()); + builder.setValue(ByteBufUtils.readUint8(nlri)); end = op.isEndOfList(); ips.add(builder.build()); } diff --git a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIpv6NextHeaderHandler.java b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIpv6NextHeaderHandler.java index ebeb9e4d1e..127cd0d131 100644 --- a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIpv6NextHeaderHandler.java +++ b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIpv6NextHeaderHandler.java @@ -14,6 +14,7 @@ import java.util.List; import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser; import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer; import org.opendaylight.protocol.bgp.flowspec.handlers.NumericOneByteOperandParser; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.NumericOperand; 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.ipv6.flowspec.flowspec.type.NextHeaderCase; @@ -25,14 +26,14 @@ public final class FSIpv6NextHeaderHandler implements FlowspecTypeParser, Flowsp public static final int NEXT_HEADER_VALUE = 3; @Override - public void serializeType(FlowspecType value, ByteBuf output) { + public void serializeType(final FlowspecType value, final ByteBuf output) { Preconditions.checkArgument(value instanceof NextHeaderCase, "NextHeaderCase class is mandatory!"); output.writeByte(NEXT_HEADER_VALUE); NumericOneByteOperandParser.INSTANCE.serialize(((NextHeaderCase) value).getNextHeaders(), output); } @Override - public FlowspecType parseType(ByteBuf buffer) { + public FlowspecType parseType(final ByteBuf buffer) { if (buffer == null) { return null; } @@ -48,7 +49,7 @@ public final class FSIpv6NextHeaderHandler implements FlowspecTypeParser, Flowsp final byte b = nlri.readByte(); final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b); builder.setOp(op); - builder.setValue(nlri.readUnsignedByte()); + builder.setValue(ByteBufUtils.readUint8(nlri)); end = op.isEndOfList(); headers.add(builder.build()); } diff --git a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/RedirectAsFourOctetEcHandler.java b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/RedirectAsFourOctetEcHandler.java index 5890b2bb7e..8775bc5cbf 100644 --- a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/RedirectAsFourOctetEcHandler.java +++ b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/RedirectAsFourOctetEcHandler.java @@ -12,6 +12,7 @@ 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.ByteBufUtils; import org.opendaylight.protocol.util.ByteBufWriteUtil; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.redirect.as4.extended.community.RedirectAs4; @@ -39,8 +40,8 @@ public final class RedirectAsFourOctetEcHandler implements ExtendedCommunityPars @Override public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) { final RedirectAs4Builder builder = new RedirectAs4Builder(); - builder.setGlobalAdministrator(new AsNumber(buffer.readUnsignedInt())); - builder.setLocalAdministrator(buffer.readUnsignedShort()); + builder.setGlobalAdministrator(new AsNumber(ByteBufUtils.readUint32(buffer))); + builder.setLocalAdministrator(ByteBufUtils.readUint16(buffer)); return new RedirectAs4ExtendedCommunityCaseBuilder().setRedirectAs4(builder.build()).build(); } diff --git a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/RedirectAsTwoOctetEcHandler.java b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/RedirectAsTwoOctetEcHandler.java index 7abd7f8974..50eb738c11 100644 --- a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/RedirectAsTwoOctetEcHandler.java +++ b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/RedirectAsTwoOctetEcHandler.java @@ -14,12 +14,14 @@ 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.ByteArray; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.protocol.util.ByteBufWriteUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.redirect.extended.community.RedirectExtendedCommunity; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.redirect.extended.community.RedirectExtendedCommunityBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.extended.communities.extended.community.RedirectExtendedCommunityCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.ShortAsNumber; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity; +import org.opendaylight.yangtools.yang.common.Uint32; public class RedirectAsTwoOctetEcHandler implements ExtendedCommunityParser, ExtendedCommunitySerializer { @@ -53,7 +55,7 @@ public class RedirectAsTwoOctetEcHandler implements ExtendedCommunityParser, Ext @Override public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) { - final ShortAsNumber as1 = new ShortAsNumber((long) buffer.readUnsignedShort()); + final ShortAsNumber as1 = new ShortAsNumber(Uint32.valueOf(ByteBufUtils.readUint16(buffer))); final byte[] byteValue = ByteArray.readBytes(buffer, TRAFFIC_RATE_SIZE); return new RedirectExtendedCommunityCaseBuilder().setRedirectExtendedCommunity( new RedirectExtendedCommunityBuilder() 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 ecafdaf9a7..6bc77768bc 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,6 +12,7 @@ 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.ByteBufUtils; import org.opendaylight.protocol.util.ByteBufWriteUtil; import org.opendaylight.protocol.util.Ipv4Util; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.redirect.ipv4.extended.community.RedirectIpv4; @@ -40,7 +41,7 @@ public class RedirectIpv4EcHandler implements ExtendedCommunityParser, ExtendedC public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) { final RedirectIpv4Builder builder = new RedirectIpv4Builder(); builder.setGlobalAdministrator(Ipv4Util.addressForByteBuf(buffer)); - builder.setLocalAdministrator(buffer.readUnsignedShort()); + builder.setLocalAdministrator(ByteBufUtils.readUint16(buffer)); return new RedirectIpv4ExtendedCommunityCaseBuilder().setRedirectIpv4(builder.build()).build(); } diff --git a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/RedirectIpv6EcHandler.java b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/RedirectIpv6EcHandler.java index e36ae75aaa..3065512345 100644 --- a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/RedirectIpv6EcHandler.java +++ b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/RedirectIpv6EcHandler.java @@ -11,6 +11,7 @@ import com.google.common.base.Preconditions; 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.ByteBufUtils; 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.flowspec.rev180329.RedirectIpv6ExtendedCommunity; @@ -49,7 +50,7 @@ public final class RedirectIpv6EcHandler implements ExtendedCommunityParser, Ext return new RedirectIpv6ExtendedCommunityCaseBuilder().setRedirectIpv6( new RedirectIpv6Builder() .setGlobalAdministrator(Ipv6Util.addressForByteBuf(buffer)) - .setLocalAdministrator(buffer.readUnsignedShort()) + .setLocalAdministrator(ByteBufUtils.readUint16(buffer)) .build()).build(); } diff --git a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/TrafficMarkingEcHandler.java b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/TrafficMarkingEcHandler.java index b1d3c1e57a..8a272906ed 100644 --- a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/TrafficMarkingEcHandler.java +++ b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/TrafficMarkingEcHandler.java @@ -12,6 +12,7 @@ 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.ByteBufUtils; import org.opendaylight.protocol.util.ByteBufWriteUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.Dscp; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.traffic.marking.extended.community.TrafficMarkingExtendedCommunity; @@ -53,7 +54,7 @@ public class TrafficMarkingEcHandler implements ExtendedCommunityParser, Extende @Override public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) { buffer.skipBytes(RESERVED); - final Dscp dscp = new Dscp(buffer.readUnsignedByte()); + final Dscp dscp = new Dscp(ByteBufUtils.readUint8(buffer)); return new TrafficMarkingExtendedCommunityCaseBuilder().setTrafficMarkingExtendedCommunity( new TrafficMarkingExtendedCommunityBuilder() .setGlobalAdministrator(dscp).build()).build(); diff --git a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/TrafficRateEcHandler.java b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/TrafficRateEcHandler.java index 98fcf7428a..4f7ce52a28 100644 --- a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/TrafficRateEcHandler.java +++ b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/TrafficRateEcHandler.java @@ -20,6 +20,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flow import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.ShortAsNumber; 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.network.concepts.rev131125.Bandwidth; +import org.opendaylight.yangtools.yang.common.Uint32; public class TrafficRateEcHandler implements ExtendedCommunityParser, ExtendedCommunitySerializer { @@ -54,7 +55,7 @@ public class TrafficRateEcHandler implements ExtendedCommunityParser, ExtendedCo @Override public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) { - final ShortAsNumber as = new ShortAsNumber((long) buffer.readUnsignedShort()); + final ShortAsNumber as = new ShortAsNumber(Uint32.valueOf(buffer.readUnsignedShort())); final Bandwidth value = new Bandwidth(ByteArray.readBytes(buffer, TRAFFIC_RATE_SIZE)); return new TrafficRateExtendedCommunityCaseBuilder().setTrafficRateExtendedCommunity( new TrafficRateExtendedCommunityBuilder() diff --git a/bgp/extensions/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/LabelIndexTlvParser.java b/bgp/extensions/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/LabelIndexTlvParser.java index 8392e4de9f..0ffc143045 100644 --- a/bgp/extensions/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/LabelIndexTlvParser.java +++ b/bgp/extensions/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/LabelIndexTlvParser.java @@ -11,6 +11,7 @@ import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import org.opendaylight.protocol.bgp.parser.spi.BgpPrefixSidTlvParser; import org.opendaylight.protocol.bgp.parser.spi.BgpPrefixSidTlvSerializer; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.bgp.prefix.sid.bgp.prefix.sid.tlvs.bgp.prefix.sid.tlv.LuLabelIndexTlv; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.bgp.prefix.sid.bgp.prefix.sid.tlvs.bgp.prefix.sid.tlv.LuLabelIndexTlvBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.bgp.prefix.sid.bgp.prefix.sid.tlvs.BgpPrefixSidTlv; @@ -33,8 +34,7 @@ final class LabelIndexTlvParser implements BgpPrefixSidTlvParser, BgpPrefixSidTl public LuLabelIndexTlv parseBgpPrefixSidTlv(final ByteBuf buffer) { buffer.readBytes(RESERVED); buffer.readBytes(LABEL_INDEX_FLAGS_BYTES); - final Long value = buffer.readUnsignedInt(); - return new LuLabelIndexTlvBuilder().setLabelIndexTlv(value).build(); + return new LuLabelIndexTlvBuilder().setLabelIndexTlv(ByteBufUtils.readUint32(buffer)).build(); } @Override diff --git a/bgp/extensions/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/OriginatorSrgbTlvParser.java b/bgp/extensions/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/OriginatorSrgbTlvParser.java index 35470da588..a0f49eef99 100644 --- a/bgp/extensions/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/OriginatorSrgbTlvParser.java +++ b/bgp/extensions/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/OriginatorSrgbTlvParser.java @@ -13,6 +13,7 @@ import java.util.ArrayList; import java.util.List; import org.opendaylight.protocol.bgp.parser.spi.BgpPrefixSidTlvParser; import org.opendaylight.protocol.bgp.parser.spi.BgpPrefixSidTlvSerializer; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.Srgb; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.originator.srgb.tlv.SrgbValue; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.originator.srgb.tlv.SrgbValueBuilder; @@ -38,8 +39,8 @@ final class OriginatorSrgbTlvParser implements BgpPrefixSidTlvParser, BgpPrefixS "Number of SRGBs does not fit available bytes."); final List ret = new ArrayList<>(); while (buffer.isReadable()) { - ret.add(new SrgbValueBuilder().setBase(new Srgb((long) buffer.readUnsignedMedium())) - .setRange(new Srgb((long) buffer.readUnsignedMedium())).build()); + ret.add(new SrgbValueBuilder().setBase(new Srgb(ByteBufUtils.readUint24(buffer))) + .setRange(new Srgb(ByteBufUtils.readUint24(buffer))).build()); } return ret; } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/LinkAttributesParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/LinkAttributesParser.java index 805fb3bff2..349c4f5eb7 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/LinkAttributesParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/LinkAttributesParser.java @@ -20,6 +20,7 @@ import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SrLinkAttribute import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil; import org.opendaylight.protocol.util.BitArray; import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.util.ByteBufUtils; 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; @@ -53,6 +54,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network. import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Metric; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.TeMetric; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.SrlgId; +import org.opendaylight.yangtools.yang.common.Uint8; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -142,7 +144,7 @@ public final class LinkAttributesParser { LOG.debug("Parsed IPv6 Router-ID of remote node: {}", builder.getRemoteIpv6RouterId()); break; case ADMIN_GROUP: - builder.setAdminGroup(new AdministrativeGroup(value.readUnsignedInt())); + builder.setAdminGroup(new AdministrativeGroup(ByteBufUtils.readUint32(value))); LOG.debug("Parsed Administrative Group {}", builder.getAdminGroup()); break; case MAX_BANDWIDTH: @@ -209,21 +211,22 @@ public final class LinkAttributesParser { break; // Performance Metrics case LINK_DELAY: - builder.setLinkDelay(new Delay(value.readUnsignedInt())); + builder.setLinkDelay(new Delay(ByteBufUtils.readUint32(value))); LOG.debug("Parsed Link Delay {}", builder.getLinkDelay()); break; case LINK_MIN_MAX_DELAY: builder.setLinkMinMaxDelay(new LinkMinMaxDelayBuilder() - .setMinDelay(new Delay(value.readUnsignedInt())) - .setMaxDelay(new Delay(value.readUnsignedInt())).build()); + .setMinDelay(new Delay(ByteBufUtils.readUint32(value))) + .setMaxDelay(new Delay(ByteBufUtils.readUint32(value))) + .build()); LOG.debug("Parsed Link Min/Max Delay {}", builder.getLinkMinMaxDelay()); break; case DELAY_VARIATION: - builder.setDelayVariation(new Delay(value.readUnsignedInt())); + builder.setDelayVariation(new Delay(ByteBufUtils.readUint32(value))); LOG.debug("Parsed Delay Variation {}", builder.getDelayVariation()); break; case LINK_LOSS: - builder.setLinkLoss(new Loss(value.readUnsignedInt())); + builder.setLinkLoss(new Loss(ByteBufUtils.readUint32(value))); LOG.debug("Parsed Link Loss {}", builder.getLinkLoss()); break; case RESIDUAL_BANDWIDTH: @@ -261,7 +264,7 @@ public final class LinkAttributesParser { for (int i = 0; i < UNRESERVED_BW_COUNT; i++) { final ByteBuf v = value.readSlice(BANDWIDTH_LENGTH); unreservedBandwidth.add(new UnreservedBandwidthBuilder().setBandwidth( - new Bandwidth(ByteArray.readAllBytes(v))).setPriority((short) i).build()); + new Bandwidth(ByteArray.readAllBytes(v))).setPriority(Uint8.valueOf(i)).build()); } builder.setUnreservedBandwidth(unreservedBandwidth); LOG.debug("Parsed Unreserved Bandwidth {}", builder.getUnreservedBandwidth()); @@ -270,7 +273,7 @@ public final class LinkAttributesParser { private static void parseSrlg(final ByteBuf value, final LinkAttributesBuilder builder) { final List sharedRiskLinkGroups = new ArrayList<>(); while (value.isReadable()) { - sharedRiskLinkGroups.add(new SrlgId(value.readUnsignedInt())); + sharedRiskLinkGroups.add(new SrlgId(ByteBufUtils.readUint32(value))); } builder.setSharedRiskLinkGroups(sharedRiskLinkGroups); LOG.debug("Parsed Shared Risk Link Groups {}", builder.getSharedRiskLinkGroups()); diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/NodeAttributesParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/NodeAttributesParser.java index 66ace44af0..53418d9bb6 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/NodeAttributesParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/NodeAttributesParser.java @@ -35,6 +35,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.link import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.path.attribute.link.state.attribute.node.attributes._case.NodeAttributesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.node.state.SrAlgorithm; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.node.state.SrCapabilities; +import org.opendaylight.yangtools.yang.common.Uint16; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -141,7 +142,7 @@ public final class NodeAttributesParser { private static void parseTopologyId(final List topologyMembership, final ByteBuf value) { while (value.isReadable()) { final TopologyIdentifier topId = new TopologyIdentifier( - value.readUnsignedShort() & TlvUtil.TOPOLOGY_ID_OFFSET); + Uint16.valueOf(value.readUnsignedShort() & TlvUtil.TOPOLOGY_ID_OFFSET)); topologyMembership.add(topId); LOG.debug("Parsed Topology Identifier: {}", topId); } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/PrefixAttributesParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/PrefixAttributesParser.java index 96c79a2ce5..4e983749fb 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/PrefixAttributesParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/PrefixAttributesParser.java @@ -25,6 +25,7 @@ import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SrPrefixAttribu import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil; import org.opendaylight.protocol.util.BitArray; import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.util.ByteBufUtils; 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; @@ -111,7 +112,7 @@ public final class PrefixAttributesParser { parseExtendedRouteTags(exRouteTags, value); break; case PREFIX_METRIC: - final IgpMetric metric = new IgpMetric(value.readUnsignedInt()); + final IgpMetric metric = new IgpMetric(ByteBufUtils.readUint32(value)); builder.setPrefixMetric(metric); LOG.debug("Parsed Metric: {}", metric); break; diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/BindingSidLabelParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/BindingSidLabelParser.java index 9519ea0621..2d0b52e8eb 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/BindingSidLabelParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/BindingSidLabelParser.java @@ -11,6 +11,7 @@ import io.netty.buffer.ByteBuf; import java.util.List; import org.opendaylight.protocol.bgp.linkstate.spi.pojo.SimpleBindingSubTlvsRegistry; import org.opendaylight.protocol.util.BitArray; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.ProtocolId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.prefix.state.SrBindingSidLabels; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.prefix.state.SrBindingSidLabelsBuilder; @@ -41,7 +42,7 @@ public final class BindingSidLabelParser { public static SrBindingSidLabels parseBindingSidLabel(final ByteBuf buffer, final ProtocolId protocolId) { final SrBindingSidLabelsBuilder bindingSid = new SrBindingSidLabelsBuilder(); - bindingSid.setWeight(new Weight(buffer.readUnsignedByte())); + bindingSid.setWeight(new Weight(ByteBufUtils.readUint8(buffer))); final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE); bindingSid.setFlags(parseBindingSidFlags(flags, protocolId)); buffer.skipBytes(RESERVED_BINDING_SID); diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/RangeTlvParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/RangeTlvParser.java index b5527fbe0f..84dae0f9fc 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/RangeTlvParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/RangeTlvParser.java @@ -19,6 +19,7 @@ import java.util.List; import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SidLabelIndexParser.Size; import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil; import org.opendaylight.protocol.util.BitArray; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.ProtocolId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.prefix.state.SrRange; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.prefix.state.SrRangeBuilder; @@ -56,7 +57,7 @@ public final class RangeTlvParser { range.setInterArea(Boolean.FALSE); } buffer.skipBytes(RESERVED); - range.setRangeSize(buffer.readUnsignedShort()); + range.setRangeSize(ByteBufUtils.readUint16(buffer)); range.setSubTlvs(parseRangeSubTlvs(buffer, protocolId)); return range.build(); } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SidLabelIndexParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SidLabelIndexParser.java index f2f78867cd..55e7ace872 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SidLabelIndexParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SidLabelIndexParser.java @@ -14,6 +14,7 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import java.util.Map; import org.opendaylight.protocol.util.BitArray; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.protocol.util.Ipv6Util; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.sid.label.index.SidLabelIndex; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.sid.label.index.sid.label.index.Ipv6AddressCase; @@ -23,6 +24,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segm import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.sid.label.index.sid.label.index.SidCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.sid.label.index.sid.label.index.SidCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.MplsLabel; +import org.opendaylight.yangtools.yang.common.Uint32; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -83,9 +85,9 @@ public final class SidLabelIndexParser { switch (length) { case LABEL: return new LocalLabelCaseBuilder() - .setLocalLabel(new MplsLabel(Long.valueOf(buffer.readUnsignedMedium() & LABEL_MASK))).build(); + .setLocalLabel(new MplsLabel(Uint32.valueOf(buffer.readUnsignedMedium() & LABEL_MASK))).build(); case SID: - return new SidCaseBuilder().setSid(buffer.readUnsignedInt()).build(); + return new SidCaseBuilder().setSid(ByteBufUtils.readUint32(buffer)).build(); case IPV6_ADD: return new Ipv6AddressCaseBuilder().setIpv6Address(Ipv6Util.addressForByteBuf(buffer)).build(); default: diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SrLinkAttributesParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SrLinkAttributesParser.java index ec7c1f97a1..6071900c01 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SrLinkAttributesParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SrLinkAttributesParser.java @@ -16,6 +16,7 @@ import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SidLabelIndexPa import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil; import org.opendaylight.protocol.util.BitArray; import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.protocol.util.Ipv4Util; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.ProtocolId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.attribute.SrAdjIds; @@ -77,7 +78,7 @@ public final class SrLinkAttributesParser { if (buffer.isReadable()) { final BitArray flags = BitArray.valueOf(buffer, FLAGS_BITS_SIZE); adjFlags = parseFlags(flags, protocolId); - weight = new Weight(buffer.readUnsignedByte()); + weight = new Weight(ByteBufUtils.readUint8(buffer)); buffer.skipBytes(RESERVED); sidValue = SidLabelIndexParser.parseSidLabelIndex(Size.forValue(buffer.readableBytes()), buffer); } else { @@ -93,7 +94,7 @@ public final class SrLinkAttributesParser { final SidLabelIndex sidValue; if (buffer.isReadable()) { buffer.skipBytes(FLAGS_BYTE_SIZE); - weight = new Weight(buffer.readUnsignedByte()); + weight = new Weight(ByteBufUtils.readUint8(buffer)); buffer.skipBytes(RESERVED); sidValue = SidLabelIndexParser.parseSidLabelIndex(Size.forValue(buffer.readableBytes()), buffer); } else { @@ -125,7 +126,7 @@ public final class SrLinkAttributesParser { final SrLanAdjIdsBuilder srLanAdjIdBuilder = new SrLanAdjIdsBuilder(); final BitArray flags = BitArray.valueOf(buffer, FLAGS_BITS_SIZE); srLanAdjIdBuilder.setFlags(parseFlags(flags, protocolId)); - srLanAdjIdBuilder.setWeight(new Weight(buffer.readUnsignedByte())); + srLanAdjIdBuilder.setWeight(new Weight(ByteBufUtils.readUint8(buffer))); buffer.skipBytes(RESERVED); switch (protocolId) { case IsisLevel1: diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SrNodeAttributesParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SrNodeAttributesParser.java index c0e956ad83..4a8b7de58d 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SrNodeAttributesParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SrNodeAttributesParser.java @@ -14,6 +14,7 @@ import java.util.ArrayList; import java.util.List; import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil; import org.opendaylight.protocol.util.BitArray; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.ProtocolId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.node.state.SrAlgorithm; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.node.state.SrAlgorithmBuilder; @@ -39,7 +40,7 @@ public final class SrNodeAttributesParser { final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE); setFlags(flags, protocol, builder); buffer.skipBytes(RESERVERED); - builder.setRangeSize((long) buffer.readUnsignedMedium()); + builder.setRangeSize(ByteBufUtils.readUint24(buffer)); builder.setSidLabelIndex(SidLabelIndexParser.parseSidSubTlv(buffer)); return builder.build(); } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/EroMetricParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/EroMetricParser.java index eb7f164137..0a55def424 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/EroMetricParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/EroMetricParser.java @@ -14,6 +14,7 @@ import io.netty.buffer.Unpooled; import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsParser; import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsSerializer; import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.ProtocolId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.BindingSubTlv; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.EroMetricCase; @@ -25,7 +26,7 @@ public final class EroMetricParser implements BindingSubTlvsParser, BindingSubTl @Override public BindingSubTlv parseSubTlv(final ByteBuf slice, final ProtocolId protocolId) { - return new EroMetricCaseBuilder().setEroMetric(new TeMetric(slice.readUnsignedInt())).build(); + return new EroMetricCaseBuilder().setEroMetric(new TeMetric(ByteBufUtils.readUint32(slice))).build(); } @Override diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/UnnumberedEroParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/UnnumberedEroParser.java index 502799fd5c..6fc9928ca1 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/UnnumberedEroParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/UnnumberedEroParser.java @@ -15,6 +15,7 @@ import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsParser; import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsSerializer; import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil; import org.opendaylight.protocol.util.BitArray; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.ProtocolId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.BindingSubTlv; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.UnnumberedInterfaceIdEroCase; @@ -51,8 +52,8 @@ public final class UnnumberedEroParser implements BindingSubTlvsParser, BindingS final BitArray flags = BitArray.valueOf(buffer, Ipv4EroParser.FLAGS_SIZE); builder.setLoose(flags.get(Ipv4EroParser.LOOSE)); buffer.skipBytes(Ipv4EroParser.RESERVED_ERO); - builder.setRouterId(buffer.readUnsignedInt()); - builder.setInterfaceId(buffer.readUnsignedInt()); + builder.setRouterId(ByteBufUtils.readUint32(buffer)); + builder.setInterfaceId(ByteBufUtils.readUint32(buffer)); return builder.build(); } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/TeLspIpv4NlriParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/TeLspIpv4NlriParser.java index 056e66540e..bd045250b9 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/TeLspIpv4NlriParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/TeLspIpv4NlriParser.java @@ -9,6 +9,7 @@ package org.opendaylight.protocol.bgp.linkstate.impl.nlri; import io.netty.buffer.ByteBuf; import org.opendaylight.protocol.bgp.linkstate.spi.AbstractTeLspNlriCodec; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.protocol.util.Ipv4Util; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.NlriType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.ObjectType; @@ -16,6 +17,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.link import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.te.lsp._case.address.family.Ipv4CaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.TunnelId; +import org.opendaylight.yangtools.yang.common.Uint32; public final class TeLspIpv4NlriParser extends AbstractTeLspNlriCodec { @Override @@ -23,8 +25,8 @@ public final class TeLspIpv4NlriParser extends AbstractTeLspNlriCodec { final TeLspCaseBuilder builder = new TeLspCaseBuilder(); final Ipv4CaseBuilder ipv4CaseBuilder = new Ipv4CaseBuilder(); ipv4CaseBuilder.setIpv4TunnelSenderAddress(Ipv4Util.addressForByteBuf(buffer)); - builder.setTunnelId(new TunnelId(buffer.readUnsignedShort())); - builder.setLspId(new LspId((long) buffer.readUnsignedShort())); + builder.setTunnelId(new TunnelId(ByteBufUtils.readUint16(buffer))); + builder.setLspId(new LspId(Uint32.valueOf(buffer.readUnsignedShort()))); ipv4CaseBuilder.setIpv4TunnelEndpointAddress(Ipv4Util.addressForByteBuf(buffer)); return builder.setAddressFamily(ipv4CaseBuilder.build()).build(); } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/TeLspIpv6NlriParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/TeLspIpv6NlriParser.java index 9edd5bcfe2..cb31d8fa62 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/TeLspIpv6NlriParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/TeLspIpv6NlriParser.java @@ -9,6 +9,7 @@ package org.opendaylight.protocol.bgp.linkstate.impl.nlri; import io.netty.buffer.ByteBuf; import org.opendaylight.protocol.bgp.linkstate.spi.AbstractTeLspNlriCodec; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.protocol.util.Ipv6Util; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.NlriType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.ObjectType; @@ -16,6 +17,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.link import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.te.lsp._case.address.family.Ipv6CaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.TunnelId; +import org.opendaylight.yangtools.yang.common.Uint32; public final class TeLspIpv6NlriParser extends AbstractTeLspNlriCodec { @Override @@ -23,8 +25,8 @@ public final class TeLspIpv6NlriParser extends AbstractTeLspNlriCodec { final TeLspCaseBuilder builder = new TeLspCaseBuilder(); final Ipv6CaseBuilder ipv6CaseBuilder = new Ipv6CaseBuilder(); ipv6CaseBuilder.setIpv6TunnelSenderAddress(Ipv6Util.addressForByteBuf(buffer)); - builder.setTunnelId(new TunnelId(buffer.readUnsignedShort())); - builder.setLspId(new LspId((long) buffer.readUnsignedShort())); + builder.setTunnelId(new TunnelId(ByteBufUtils.readUint16(buffer))); + builder.setLspId(new LspId(Uint32.valueOf(buffer.readUnsignedShort()))); ipv6CaseBuilder.setIpv6TunnelEndpointAddress(Ipv6Util.addressForByteBuf(buffer)); return builder.setAddressFamily(ipv6CaseBuilder.build()).build(); } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AreaIdTlvParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AreaIdTlvParser.java index f3115b0875..417664bd96 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AreaIdTlvParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AreaIdTlvParser.java @@ -9,6 +9,7 @@ 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.ByteBufUtils; import org.opendaylight.protocol.util.ByteBufWriteUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.AreaIdentifier; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.node._case.NodeDescriptors; @@ -28,7 +29,7 @@ public final class AreaIdTlvParser implements LinkstateTlvParser @Override public AreaIdentifier parseTlvBody(final ByteBuf value) { - return new AreaIdentifier(value.readUnsignedInt()); + return new AreaIdentifier(ByteBufUtils.readUint32(value)); } @Override diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AsNumTlvParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AsNumTlvParser.java index 147a4b09b0..26f9304450 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AsNumTlvParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AsNumTlvParser.java @@ -9,6 +9,7 @@ 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.ByteBufUtils; import org.opendaylight.protocol.util.ByteBufWriteUtil; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.node._case.NodeDescriptors; @@ -28,7 +29,7 @@ public final class AsNumTlvParser implements LinkstateTlvParser, @Override public AsNumber parseTlvBody(final ByteBuf value) { - return new AsNumber(value.readUnsignedInt()); + return new AsNumber(ByteBufUtils.readUint32(value)); } @Override diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/DomainIdTlvParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/DomainIdTlvParser.java index 73c126ea2d..4c6fc3b38a 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/DomainIdTlvParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/DomainIdTlvParser.java @@ -9,6 +9,7 @@ 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.ByteBufUtils; import org.opendaylight.protocol.util.ByteBufWriteUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.DomainIdentifier; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.node._case.NodeDescriptors; @@ -28,7 +29,7 @@ public final class DomainIdTlvParser implements LinkstateTlvParser, @Override public AsNumber parseTlvBody(final ByteBuf value) { - return new AsNumber(value.readUnsignedInt()); + return new AsNumber(ByteBufUtils.readUint32(value)); } @Override diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/MultiTopoIdTlvParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/MultiTopoIdTlvParser.java index b0eb0b823e..3e29dced8b 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/MultiTopoIdTlvParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/MultiTopoIdTlvParser.java @@ -35,7 +35,7 @@ public final class MultiTopoIdTlvParser implements LinkstateTlvParserorg.opendaylight.yangtools concepts + + org.opendaylight.yangtools + yang-common + org.opendaylight.mdsal yang-binding diff --git a/bgp/openconfig-rp-statement/src/main/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/actions/AsPathPrepend.java b/bgp/openconfig-rp-statement/src/main/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/actions/AsPathPrepend.java index bedd20d49e..8a7b56c103 100644 --- a/bgp/openconfig-rp-statement/src/main/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/actions/AsPathPrepend.java +++ b/bgp/openconfig-rp-statement/src/main/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/actions/AsPathPrepend.java @@ -15,6 +15,7 @@ import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryImportParameter import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.bgp.actions.SetAsPathPrepend; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes; +import org.opendaylight.yangtools.yang.common.Uint32; /** * Prepend local AS, one time(n times not supported yet). @@ -45,6 +46,6 @@ public final class AsPathPrepend extends AbstractPrependAsPath implements BgpAct final BGPRouteEntryExportParameters exportParameters, final Attributes attributes, final SetAsPathPrepend actions) { - return prependAS(attributes, new AsNumber(routeEntryInfo.getLocalAs())); + return prependAS(attributes, new AsNumber(Uint32.valueOf(routeEntryInfo.getLocalAs()))); } } \ No newline at end of file diff --git a/bgp/openconfig-state/src/main/java/org/opendaylight/protocol/bgp/state/NeighborUtil.java b/bgp/openconfig-state/src/main/java/org/opendaylight/protocol/bgp/state/NeighborUtil.java index 5e92f7334e..985e40cfed 100644 --- a/bgp/openconfig-state/src/main/java/org/opendaylight/protocol/bgp/state/NeighborUtil.java +++ b/bgp/openconfig-state/src/main/java/org/opendaylight/protocol/bgp/state/NeighborUtil.java @@ -81,6 +81,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.open import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180329.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.Sent; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180329.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.SentBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey; +import org.opendaylight.yangtools.yang.common.Uint32; /** * Util for create OpenConfig Neighbor with corresponding openConfig state. @@ -356,7 +357,7 @@ public final class NeighborUtil { .setReceived(neighbor.isGracefulRestartReceived(tablesKey)) .setLlAdvertised(neighbor.isLlGracefulRestartAdvertised(tablesKey)) .setLlReceived(neighbor.isLlGracefulRestartReceived(tablesKey)) - .setLlStaleTimer((long) neighbor.getLlGracefulRestartTimer(tablesKey)).build(); + .setLlStaleTimer(Uint32.valueOf(neighbor.getLlGracefulRestartTimer(tablesKey))).build(); return new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi .safi.list.afi.safi.GracefulRestartBuilder().setState(new org.opendaylight.yang.gen.v1.http.openconfig .net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.afi.safi.graceful.restart.StateBuilder() diff --git a/bgp/parser-api/src/main/java/org/opendaylight/protocol/bgp/parser/AsNumberUtil.java b/bgp/parser-api/src/main/java/org/opendaylight/protocol/bgp/parser/AsNumberUtil.java index e0991bcc88..b8a7b174b9 100644 --- a/bgp/parser-api/src/main/java/org/opendaylight/protocol/bgp/parser/AsNumberUtil.java +++ b/bgp/parser-api/src/main/java/org/opendaylight/protocol/bgp/parser/AsNumberUtil.java @@ -44,7 +44,7 @@ public final class AsNumberUtil { } } // Fallback to whatever is in the header - return new AsNumber(open.getMyAsNumber().longValue()); + return new AsNumber(Uint32.valueOf(open.getMyAsNumber())); } /** diff --git a/bgp/parser-api/src/main/java/org/opendaylight/protocol/bgp/parser/BGPError.java b/bgp/parser-api/src/main/java/org/opendaylight/protocol/bgp/parser/BGPError.java index 0de8bddca3..0638df957b 100644 --- a/bgp/parser-api/src/main/java/org/opendaylight/protocol/bgp/parser/BGPError.java +++ b/bgp/parser-api/src/main/java/org/opendaylight/protocol/bgp/parser/BGPError.java @@ -172,10 +172,12 @@ public enum BGPError { return e; } + // FIXME: Use Uint8 for this public short getCode() { return this.errorId.code; } + // FIXME: Use Uint8 for this public short getSubcode() { return this.errorId.subcode; } @@ -189,6 +191,8 @@ public enum BGPError { */ private static class BGPErrorIdentifier implements Serializable { private static final long serialVersionUID = 5722575354944165734L; + + // FIXME: Use Uint8 for these final short code; final short subcode; diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPOpenMessageParser.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPOpenMessageParser.java index 74400fd62e..af07832c45 100644 --- a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPOpenMessageParser.java +++ b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPOpenMessageParser.java @@ -40,6 +40,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mess import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.OpenBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.open.message.BgpParameters; import org.opendaylight.yangtools.yang.binding.Notification; +import org.opendaylight.yangtools.yang.common.Uint16; +import org.opendaylight.yangtools.yang.common.Uint32; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -186,7 +188,7 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali throw new BGPDocumentedException("BGP Protocol version " + version + " not supported.", BGPError.VERSION_NOT_SUPPORTED); } - final AsNumber as = new AsNumber((long) body.readUnsignedShort()); + final AsNumber as = new AsNumber(Uint32.valueOf(body.readUnsignedShort())); final int holdTime = body.readUnsignedShort(); if (holdTime == 1 || holdTime == 2) { throw new BGPDocumentedException("Hold time value not acceptable.", BGPError.HOLD_TIME_NOT_ACC); @@ -201,7 +203,7 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali final List optParams = parseParameters(body.slice(), optLength); LOG.debug("BGP Open message was parsed: AS = {}, holdTimer = {}, bgpId = {}, optParams = {}", as, holdTime, bgpId, optParams); - return new OpenBuilder().setMyAsNumber(as.getValue().intValue()).setHoldTimer(holdTime) + return new OpenBuilder().setMyAsNumber(Uint16.valueOf(as.getValue())).setHoldTimer(holdTime) .setBgpIdentifier(bgpId).setBgpParameters(optParams).build(); } diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/As4CapabilityHandler.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/As4CapabilityHandler.java index 0b02cb1f07..6fe4e7668e 100644 --- a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/As4CapabilityHandler.java +++ b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/As4CapabilityHandler.java @@ -12,6 +12,7 @@ import io.netty.buffer.Unpooled; import org.opendaylight.protocol.bgp.parser.spi.CapabilityParser; import org.opendaylight.protocol.bgp.parser.spi.CapabilitySerializer; import org.opendaylight.protocol.bgp.parser.spi.CapabilityUtil; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.open.message.bgp.parameters.optional.capabilities.CParameters; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.open.message.bgp.parameters.optional.capabilities.CParametersBuilder; @@ -24,7 +25,7 @@ public final class As4CapabilityHandler implements CapabilityParser, CapabilityS @Override public CParameters parseCapability(final ByteBuf buffer) { return new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder() - .setAsNumber(new AsNumber(buffer.readUnsignedInt())).build()).build(); + .setAsNumber(new AsNumber(ByteBufUtils.readUint32(buffer))).build()).build(); } @Override diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/LlGracefulCapabilityHandler.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/LlGracefulCapabilityHandler.java index 5dfa4425ac..11a991afe4 100644 --- a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/LlGracefulCapabilityHandler.java +++ b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/LlGracefulCapabilityHandler.java @@ -85,7 +85,7 @@ public final class LlGracefulCapabilityHandler implements CapabilityParser, Capa .setAfi(afi) .setSafi(safi) .setAfiFlags(new Tables.AfiFlags(Boolean.valueOf(afiFlags == AFI_FLAG_FORWARDING_STATE))) - .setLongLivedStaleTime(Long.valueOf(staleTime)) + .setLongLivedStaleTime(Uint32.valueOf(staleTime)) .build(); tables.add(table); } diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AggregatorAttributeParser.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AggregatorAttributeParser.java index 2e670fa440..728cf47419 100644 --- a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AggregatorAttributeParser.java +++ b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AggregatorAttributeParser.java @@ -16,6 +16,7 @@ import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer; import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil; import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint; import org.opendaylight.protocol.bgp.parser.spi.RevisedErrorHandling; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.protocol.util.Ipv4Util; import org.opendaylight.protocol.util.ReferenceCache; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber; @@ -52,7 +53,7 @@ public final class AggregatorAttributeParser extends AbstractAttributeParser imp builder.setAggregator(new AggregatorBuilder() // FIXME: above check should be expanded, so we report at least underflow errors - .setAsNumber(this.refCache.getSharedReference(new AsNumber(buffer.readUnsignedInt()))) + .setAsNumber(this.refCache.getSharedReference(new AsNumber(ByteBufUtils.readUint32(buffer)))) .setNetworkAddress(Ipv4Util.addressForByteBuf(buffer)) .build()); } diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AigpAttributeParser.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AigpAttributeParser.java index bb2ee26fe4..e224e06782 100644 --- a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AigpAttributeParser.java +++ b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AigpAttributeParser.java @@ -9,11 +9,11 @@ package org.opendaylight.protocol.bgp.parser.impl.message.update; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; -import java.math.BigInteger; import org.opendaylight.protocol.bgp.parser.spi.AttributeParser; import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer; import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil; import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.Aigp; @@ -64,7 +64,7 @@ public class AigpAttributeParser implements AttributeParser, AttributeSerializer LOG.warn("AIGP attribute contains unknown TLV type {}.", tlvType); return null; } - return new AigpTlvBuilder().setMetric(new AccumulatedIgpMetric(BigInteger.valueOf(buffer.readLong()))).build(); + return new AigpTlvBuilder().setMetric(new AccumulatedIgpMetric(ByteBufUtils.readUint64(buffer))).build(); } /** diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AsPathSegmentParser.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AsPathSegmentParser.java index d613c48c46..4eb32ea4f7 100644 --- a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AsPathSegmentParser.java +++ b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AsPathSegmentParser.java @@ -14,6 +14,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList.Builder; import io.netty.buffer.ByteBuf; import java.util.List; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.protocol.util.ReferenceCache; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber; @@ -66,7 +67,7 @@ public final class AsPathSegmentParser { final Builder coll = ImmutableList.builderWithExpectedSize(count); for (int i = 0; i < count; i++) { - coll.add(refCache.getSharedReference(new AsNumber(buffer.readUnsignedInt()))); + coll.add(refCache.getSharedReference(new AsNumber(ByteBufUtils.readUint32(buffer)))); } return coll.build(); } diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/CommunityUtil.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/CommunityUtil.java index e255c2fdf3..d7b8c36c15 100644 --- a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/CommunityUtil.java +++ b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/CommunityUtil.java @@ -14,6 +14,8 @@ import org.opendaylight.protocol.util.ReferenceCache; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.CommunitiesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Community; +import org.opendaylight.yangtools.yang.common.Uint16; +import org.opendaylight.yangtools.yang.common.Uint32; /** * Object representation of a RFC1997 Community tag. Communities are a way for the advertising entity to attach semantic @@ -81,10 +83,12 @@ public final class CommunityUtil { * @param semantics int * @return new Community */ + // FIXME: consider using Uint32 for asn + // FIXME: consider using Uint16 for semantics public static Community create(final ReferenceCache refCache, final long asn, final int semantics) { final CommunitiesBuilder builder = new CommunitiesBuilder(); - builder.setAsNumber(refCache.getSharedReference(new AsNumber(asn))); - builder.setSemantics(refCache.getSharedReference(semantics)); + builder.setAsNumber(refCache.getSharedReference(new AsNumber(Uint32.valueOf(asn)))); + builder.setSemantics(refCache.getSharedReference(Uint16.valueOf(semantics))); return refCache.getSharedReference(builder.build()); } @@ -108,8 +112,8 @@ public final class CommunityUtil { public static Community valueOf(final ReferenceCache refCache, final String string) { final String[] parts = string.split(":", 2); final CommunitiesBuilder builder = new CommunitiesBuilder(); - builder.setAsNumber(refCache.getSharedReference(new AsNumber(Long.valueOf(parts[0])))); - builder.setSemantics(refCache.getSharedReference(Integer.valueOf(parts[1]))); + builder.setAsNumber(refCache.getSharedReference(new AsNumber(Uint32.valueOf(parts[0])))); + builder.setSemantics(refCache.getSharedReference(Uint16.valueOf(parts[1]))); return refCache.getSharedReference(builder.build()); } } diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/LocalPreferenceAttributeParser.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/LocalPreferenceAttributeParser.java index cc1fd27d42..44adabd4b6 100644 --- a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/LocalPreferenceAttributeParser.java +++ b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/LocalPreferenceAttributeParser.java @@ -17,6 +17,7 @@ import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer; import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil; import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint; import org.opendaylight.protocol.bgp.parser.spi.RevisedErrorHandling; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.LocalPref; @@ -45,7 +46,7 @@ public final class LocalPreferenceAttributeParser extends AbstractAttributeParse throw errorHandling.reportError(BGPError.ATTR_LENGTH_ERROR, "Expected 4 bytes, have %s", readable); } - builder.setLocalPref(new LocalPrefBuilder().setPref(buffer.readUnsignedInt()).build()); + builder.setLocalPref(new LocalPrefBuilder().setPref(ByteBufUtils.readUint32(buffer)).build()); } @Override diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/MultiExitDiscriminatorAttributeParser.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/MultiExitDiscriminatorAttributeParser.java index 79412f27d5..e16ef84891 100644 --- a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/MultiExitDiscriminatorAttributeParser.java +++ b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/MultiExitDiscriminatorAttributeParser.java @@ -17,6 +17,7 @@ import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer; import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil; import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint; import org.opendaylight.protocol.bgp.parser.spi.RevisedErrorHandling; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.MultiExitDisc; @@ -36,7 +37,7 @@ public final class MultiExitDiscriminatorAttributeParser extends AbstractAttribu throw errorHandling.reportError(BGPError.ATTR_LENGTH_ERROR, "MULTI_EXIT_DISC has to have length 4, but has %s", readable); } - builder.setMultiExitDisc(new MultiExitDiscBuilder().setMed(buffer.readUnsignedInt()).build()); + builder.setMultiExitDisc(new MultiExitDiscBuilder().setMed(ByteBufUtils.readUint32(buffer)).build()); } @Override 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 a6cda3af3a..7516a67755 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 @@ -13,6 +13,7 @@ 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.ByteBufUtils; import org.opendaylight.protocol.util.ByteBufWriteUtil; import org.opendaylight.protocol.util.Ipv4Util; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity; @@ -39,7 +40,7 @@ public final class RouteOriginIpv4EcHandler extends AbstractIpv4ExtendedCommunit throws BGPDocumentedException, BGPParsingException { final RouteOriginIpv4 routeTarget = new RouteOriginIpv4Builder() .setGlobalAdministrator(Ipv4Util.addressForByteBuf(buffer)) - .setLocalAdministrator(buffer.readUnsignedShort()) + .setLocalAdministrator(ByteBufUtils.readUint16(buffer)) .build(); return new RouteOriginIpv4CaseBuilder().setRouteOriginIpv4(routeTarget).build(); } diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/four/octect/as/specific/SourceAS4OctectHandler.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/four/octect/as/specific/SourceAS4OctectHandler.java index a6ff8343c2..5dea91f7a9 100644 --- a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/four/octect/as/specific/SourceAS4OctectHandler.java +++ b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/extended/communities/four/octect/as/specific/SourceAS4OctectHandler.java @@ -11,6 +11,7 @@ package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.commun import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import org.opendaylight.protocol.bgp.parser.spi.extended.community.Abstract4OctetAsExtendedCommunity; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.protocol.util.ByteBufWriteUtil; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity; @@ -26,7 +27,7 @@ public final class SourceAS4OctectHandler extends Abstract4OctetAsExtendedCommun @Override public ExtendedCommunity parseExtendedCommunity(final ByteBuf body) { final SourceAs4ExtendedCommunityBuilder builder = new SourceAs4ExtendedCommunityBuilder(); - builder.setGlobalAdministrator(new AsNumber(body.readUnsignedInt())); + builder.setGlobalAdministrator(new AsNumber(ByteBufUtils.readUint32(body))); body.skipBytes(LOCAL_LENGTH); return new SourceAs4ExtendedCommunityCaseBuilder().setSourceAs4ExtendedCommunity( builder.build()).build(); 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 90d99f8822..af996e700b 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 @@ -9,6 +9,7 @@ package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.route.target; import io.netty.buffer.ByteBuf; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.protocol.util.ByteBufWriteUtil; import org.opendaylight.protocol.util.Ipv4Util; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.route.target.ipv4.grouping.RouteTargetIpv4; @@ -32,7 +33,7 @@ public final class RouteTargetIpv4Handler { public static RouteTargetIpv4 parse(final ByteBuf buffer) { return new RouteTargetIpv4Builder() .setGlobalAdministrator(Ipv4Util.addressForByteBuf(buffer)) - .setLocalAdministrator(buffer.readUnsignedShort()) + .setLocalAdministrator(ByteBufUtils.readUint16(buffer)) .build(); } } diff --git a/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/PathIdUtil.java b/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/PathIdUtil.java index 3aa1901064..081226d3fe 100644 --- a/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/PathIdUtil.java +++ b/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/PathIdUtil.java @@ -11,6 +11,7 @@ package org.opendaylight.protocol.bgp.parser.spi; import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import java.util.Optional; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.protocol.util.ByteBufWriteUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId; import org.opendaylight.yangtools.util.ImmutableOffsetMapTemplate; @@ -56,7 +57,7 @@ public final class PathIdUtil { */ public static PathId readPathId(final ByteBuf buffer) { Preconditions.checkArgument(buffer != null && buffer.isReadable(ByteBufWriteUtil.INT_BYTES_LENGTH)); - return new PathId(buffer.readUnsignedInt()); + return new PathId(ByteBufUtils.readUint32(buffer)); } /** diff --git a/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/extended/community/FourOctAsCommonECUtil.java b/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/extended/community/FourOctAsCommonECUtil.java index 2bb3ab1af9..f84c2370c3 100644 --- a/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/extended/community/FourOctAsCommonECUtil.java +++ b/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/extended/community/FourOctAsCommonECUtil.java @@ -5,10 +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.bgp.parser.spi.extended.community; import io.netty.buffer.ByteBuf; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.protocol.util.ByteBufWriteUtil; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.as._4.spec.common.As4SpecificCommon; @@ -20,8 +20,8 @@ public final class FourOctAsCommonECUtil { } public static As4SpecificCommon parseCommon(final ByteBuf body) { - return new As4SpecificCommonBuilder().setAsNumber(new AsNumber(body.readUnsignedInt())) - .setLocalAdministrator(body.readUnsignedShort()).build(); + return new As4SpecificCommonBuilder().setAsNumber(new AsNumber(ByteBufUtils.readUint32(body))) + .setLocalAdministrator(ByteBufUtils.readUint16(body)).build(); } public static void serializeCommon(final As4SpecificCommon extComm, final ByteBuf body) { diff --git a/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/SimpleAttributeRegistry.java b/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/SimpleAttributeRegistry.java index 2072fdb3e6..d4ea18d9fb 100644 --- a/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/SimpleAttributeRegistry.java +++ b/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/SimpleAttributeRegistry.java @@ -41,6 +41,7 @@ import org.opendaylight.yangtools.concepts.AbstractRegistration; import org.opendaylight.yangtools.concepts.Registration; import org.opendaylight.yangtools.yang.binding.DataContainer; import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.common.Uint8; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -126,11 +127,13 @@ final class SimpleAttributeRegistry implements AttributeRegistry { throw new BGPDocumentedException("Well known attribute not recognized.", BGPError.WELL_KNOWN_ATTR_NOT_RECOGNIZED); } + + final Uint8 typeVal = Uint8.valueOf(type); final UnrecognizedAttributes unrecognizedAttribute = new UnrecognizedAttributesBuilder() - .withKey(new UnrecognizedAttributesKey((short) type)) + .withKey(new UnrecognizedAttributesKey(typeVal)) .setPartial(flags.get(PARTIAL_BIT)) .setTransitive(flags.get(TRANSITIVE_BIT)) - .setType((short) type) + .setType(typeVal) .setValue(ByteArray.readBytes(buffer, len)).build(); this.unrecognizedAttributes.add(unrecognizedAttribute); LOG.debug("Unrecognized attribute were parsed: {}", unrecognizedAttribute); diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/AbstractBGPSessionNegotiator.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/AbstractBGPSessionNegotiator.java index ca46a6406c..a9ab4f49f5 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/AbstractBGPSessionNegotiator.java +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/AbstractBGPSessionNegotiator.java @@ -36,6 +36,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mess import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Open; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.OpenBuilder; import org.opendaylight.yangtools.yang.binding.Notification; +import org.opendaylight.yangtools.yang.common.Uint16; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,7 +50,7 @@ abstract class AbstractBGPSessionNegotiator extends ChannelInboundHandlerAdapter // BGP Support for 4-Octet AS Number Space @VisibleForTesting - static final int AS_TRANS = 23456; + static final Uint16 AS_TRANS = Uint16.valueOf(23456).intern(); private static final Logger LOG = LoggerFactory.getLogger(AbstractBGPSessionNegotiator.class); private final BGPPeerRegistry registry; private final Promise promise; @@ -107,7 +108,7 @@ abstract class AbstractBGPSessionNegotiator extends ChannelInboundHandlerAdapter } final BGPSessionPreferences preferences = this.registry.getPeerPreferences(remoteIp); - final int as = openASNumber(preferences.getMyAs().getValue().longValue()); + final Uint16 as = openASNumber(preferences.getMyAs().getValue().longValue()); sendMessage(new OpenBuilder().setMyAsNumber(as).setHoldTimer(preferences.getHoldTime()).setBgpIdentifier( preferences.getBgpId()).setBgpParameters(preferences.getParams()).build()); if (this.state != State.FINISHED) { @@ -306,8 +307,8 @@ abstract class AbstractBGPSessionNegotiator extends ChannelInboundHandlerAdapter } @VisibleForTesting - static int openASNumber(final long configuredASNumber) { + static Uint16 openASNumber(final long configuredASNumber) { // Return AS_TRANS if the value is bigger than 2B. - return configuredASNumber > Values.UNSIGNED_SHORT_MAX_VALUE ? AS_TRANS : (int) configuredASNumber; + return configuredASNumber > Values.UNSIGNED_SHORT_MAX_VALUE ? AS_TRANS : Uint16.valueOf(configuredASNumber); } } diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/config/GracefulRestartUtil.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/config/GracefulRestartUtil.java index a0c78d65fd..6cca2b2ae7 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/config/GracefulRestartUtil.java +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/config/GracefulRestartUtil.java @@ -77,7 +77,7 @@ public final class GracefulRestartUtil { .setAfi(dto.getTableKey().getAfi()) .setSafi(dto.getTableKey().getSafi()) .setAfiFlags(new AfiFlags(dto.isForwarding())) - .setLongLivedStaleTime((long) dto.getStaleTime()) + .setLongLivedStaleTime(Uint32.valueOf(dto.getStaleTime())) .build()) .collect(Collectors.toList()); return new CParametersBuilder().addAugmentation(CParameters1.class, diff --git a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractBGPSessionNegotiatorTest.java b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractBGPSessionNegotiatorTest.java index 693f331ebd..412402d2d0 100644 --- a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractBGPSessionNegotiatorTest.java +++ b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractBGPSessionNegotiatorTest.java @@ -12,12 +12,13 @@ import static org.opendaylight.protocol.bgp.rib.impl.AbstractBGPSessionNegotiato import static org.opendaylight.protocol.bgp.rib.impl.AbstractBGPSessionNegotiator.openASNumber; import org.junit.Test; +import org.opendaylight.yangtools.yang.common.Uint16; public class AbstractBGPSessionNegotiatorTest { @Test public void testOpenASNumber() { - assertEquals(0, openASNumber(0)); - assertEquals(65535, openASNumber(65535)); + assertEquals(Uint16.ZERO, openASNumber(0)); + assertEquals(Uint16.MAX_VALUE, openASNumber(65535)); assertEquals(AS_TRANS, openASNumber(65536)); assertEquals(AS_TRANS, openASNumber(Integer.MAX_VALUE)); assertEquals(AS_TRANS, openASNumber(2147483648L)); diff --git a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/PeerUtil.java b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/PeerUtil.java index 96c25f895a..be82db7ed7 100644 --- a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/PeerUtil.java +++ b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/PeerUtil.java @@ -67,6 +67,7 @@ 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.next.hop.c.next.hop.Ipv6NextHopCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.ipv6.next.hop._case.Ipv6NextHopBuilder; +import org.opendaylight.yangtools.yang.common.Uint32; final class PeerUtil { @@ -114,12 +115,13 @@ final class PeerUtil { static Update createUpdate(final BgpOrigin bgpOrigin, final List pathSegments, + // FIXME: consider using Uint32 final long preference, final MpReachNlri mpReach, final MpUnreachNlri mpUnreach) { final Origin origin = new OriginBuilder().setValue(bgpOrigin).build(); final AsPath asPath = new AsPathBuilder().setSegments(pathSegments).build(); - final LocalPref localPref = new LocalPrefBuilder().setPref(preference).build(); + final LocalPref localPref = new LocalPrefBuilder().setPref(Uint32.valueOf(preference)).build(); final AttributesBuilder attributeBuilder = new AttributesBuilder() .setOrigin(origin).setAsPath(asPath).setLocalPref(localPref); diff --git a/bgp/rib-mock/pom.xml b/bgp/rib-mock/pom.xml index d611163e3a..b77672da0a 100644 --- a/bgp/rib-mock/pom.xml +++ b/bgp/rib-mock/pom.xml @@ -49,6 +49,10 @@ org.opendaylight.yangtools concepts + + org.opendaylight.yangtools + yang-common + org.opendaylight.mdsal yang-binding diff --git a/bgp/rib-mock/src/main/java/org/opendaylight/protocol/bgp/rib/mock/EventBusRegistration.java b/bgp/rib-mock/src/main/java/org/opendaylight/protocol/bgp/rib/mock/EventBusRegistration.java index 604e0286ff..b9b219653c 100644 --- a/bgp/rib-mock/src/main/java/org/opendaylight/protocol/bgp/rib/mock/EventBusRegistration.java +++ b/bgp/rib-mock/src/main/java/org/opendaylight/protocol/bgp/rib/mock/EventBusRegistration.java @@ -38,6 +38,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mult import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.add.path.capability.AddressFamilies; import org.opendaylight.yangtools.concepts.AbstractListenerRegistration; import org.opendaylight.yangtools.yang.binding.Notification; +import org.opendaylight.yangtools.yang.common.Uint32; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -112,7 +113,7 @@ final class EventBusRegistration extends AbstractListenerRegistration addPathAfis; private final Set tts; diff --git a/bgp/testtool/pom.xml b/bgp/testtool/pom.xml index d07b6cb86d..7d7fc07ab9 100644 --- a/bgp/testtool/pom.xml +++ b/bgp/testtool/pom.xml @@ -72,6 +72,10 @@ ${project.groupId} testtool-util + + org.opendaylight.yangtools + yang-common + org.opendaylight.mdsal yang-binding diff --git a/bgp/testtool/src/main/java/org/opendaylight/protocol/bgp/testtool/Arguments.java b/bgp/testtool/src/main/java/org/opendaylight/protocol/bgp/testtool/Arguments.java index 040e3abd92..19afd9bfdc 100644 --- a/bgp/testtool/src/main/java/org/opendaylight/protocol/bgp/testtool/Arguments.java +++ b/bgp/testtool/src/main/java/org/opendaylight/protocol/bgp/testtool/Arguments.java @@ -25,6 +25,7 @@ import net.sourceforge.argparse4j.inf.Namespace; import org.opendaylight.protocol.util.ArgumentsInput; import org.opendaylight.protocol.util.InetSocketAddressUtil; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber; +import org.opendaylight.yangtools.yang.common.Uint32; final class Arguments implements ArgumentsInput { private static final String PROGRAM_NAME = "BGP testing tool."; @@ -67,7 +68,9 @@ final class Arguments implements ArgumentsInput { } private interface ArgumentTypeTool extends ArgumentType { - default T convert(ArgumentParser var1, Argument var2, String input) throws ArgumentParserException { + @Override + default T convert(final ArgumentParser var1, final Argument var2, final String input) + throws ArgumentParserException { return convert(input); } @@ -97,8 +100,8 @@ final class Arguments implements ArgumentsInput { parser.addArgument("-mp", toArgName(MULTIPATH_PARAMETER)).type(Boolean.class) .setDefault(false).help(MULTIPATH_PARAMETER_HELP); parser.addArgument("-" + AS_PARAMETER, toArgName(AS_PARAMETER)) - .type((ArgumentTypeTool) as -> new AsNumber(Long.valueOf(as))) - .setDefault(new AsNumber(64496L)).help(AS_PARAMETER_HELP); + .type((ArgumentTypeTool) as -> new AsNumber(Uint32.valueOf(as))) + .setDefault(new AsNumber(Uint32.valueOf(64496))).help(AS_PARAMETER_HELP); parser.addArgument("-ec", toArgName(EXTENDED_COMMUNITIES_PARAMETER)) .type((ArgumentTypeTool>) extComInput -> Arrays.asList(extComInput.split(","))).setDefault(Collections.emptyList()) diff --git a/bgp/testtool/src/main/java/org/opendaylight/protocol/bgp/testtool/CommunitiesBuilder.java b/bgp/testtool/src/main/java/org/opendaylight/protocol/bgp/testtool/CommunitiesBuilder.java index 3d7b94b6f6..b04145cadb 100644 --- a/bgp/testtool/src/main/java/org/opendaylight/protocol/bgp/testtool/CommunitiesBuilder.java +++ b/bgp/testtool/src/main/java/org/opendaylight/protocol/bgp/testtool/CommunitiesBuilder.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.bgp.testtool; import java.util.ArrayList; import java.util.List; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber; 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.message.rev180329.path.attributes.attributes.ExtendedCommunities; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.ExtendedCommunitiesBuilder; @@ -42,17 +40,19 @@ 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.route.target.ipv4.grouping.RouteTargetIpv4Builder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth; +import org.opendaylight.yangtools.yang.common.Uint16; +import org.opendaylight.yangtools.yang.common.Uint32; import org.slf4j.Logger; import org.slf4j.LoggerFactory; final class CommunitiesBuilder { private static final Logger LOG = LoggerFactory.getLogger(CommunitiesBuilder.class); + private static final ShortAsNumber SHORT_AS = new ShortAsNumber(Uint32.valueOf(20)); private static final As4SpecificCommon AS_4_COMMON = new As4SpecificCommonBuilder() - .setAsNumber(new AsNumber(20L)).setLocalAdministrator(100).build(); + .setAsNumber(SHORT_AS).setLocalAdministrator(Uint16.valueOf(100)).build(); private static final Ipv4Address IPV4 = new Ipv4Address("192.168.1.0"); private static final byte[] BYTE = new byte[]{(byte) 0x4f, (byte) 0x70, (byte) 0x00, (byte) 0x00}; - private static final int LA = 4660; - private static final ShortAsNumber SHORT_AS = new ShortAsNumber(20L); + private static final Uint16 LA = Uint16.valueOf(4660).intern(); private CommunitiesBuilder() { throw new UnsupportedOperationException(); diff --git a/bgp/testtool/src/main/java/org/opendaylight/protocol/bgp/testtool/PrefixesBuilder.java b/bgp/testtool/src/main/java/org/opendaylight/protocol/bgp/testtool/PrefixesBuilder.java index 89bba6014f..1fb51c7bd8 100644 --- a/bgp/testtool/src/main/java/org/opendaylight/protocol/bgp/testtool/PrefixesBuilder.java +++ b/bgp/testtool/src/main/java/org/opendaylight/protocol/bgp/testtool/PrefixesBuilder.java @@ -38,6 +38,7 @@ 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.next.hop.c.next.hop.Ipv4NextHopCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv4NextHopCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder; +import org.opendaylight.yangtools.yang.common.Uint32; final class PrefixesBuilder { private static final Ipv4NextHopCase NEXT_HOP; @@ -73,14 +74,14 @@ final class PrefixesBuilder { final AttributesBuilder attBuilder = new AttributesBuilder(); attBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Egp).build()); attBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.emptyList()).build()); - attBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build()); - attBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build()); + attBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed(Uint32.ZERO).build()); + attBuilder.setLocalPref(new LocalPrefBuilder().setPref(Uint32.valueOf(100L)).build()); attBuilder.setExtendedCommunities(createExtComm(extCom)); attBuilder.setUnrecognizedAttributes(Collections.emptyList()); final Ipv4PrefixesBuilder prefixes = new Ipv4PrefixesBuilder().setPrefix(addressPrefix); if (multiPathSupport) { - prefixes.setPathId(new PathId(5L)); + prefixes.setPathId(new PathId(Uint32.valueOf(5))); } attBuilder.addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri( new MpReachNlriBuilder().setCNextHop(NEXT_HOP).setAfi(Ipv4AddressFamily.class) diff --git a/bgp/topology-provider/src/main/java/org/opendaylight/bgpcep/bgp/topology/provider/ProtocolUtil.java b/bgp/topology-provider/src/main/java/org/opendaylight/bgpcep/bgp/topology/provider/ProtocolUtil.java index 99f6cd6501..9676a1cda9 100644 --- a/bgp/topology-provider/src/main/java/org/opendaylight/bgpcep/bgp/topology/provider/ProtocolUtil.java +++ b/bgp/topology-provider/src/main/java/org/opendaylight/bgpcep/bgp/topology/provider/ProtocolUtil.java @@ -258,7 +258,7 @@ public final class ProtocolUtil { final OspfLinkAttributesBuilder ilab = new OspfLinkAttributesBuilder(); ilab.setTed(tb.build()); if (topologyIdentifier != null) { - ilab.setMultiTopologyId(topologyIdentifier.getValue().shortValue()); + ilab.setMultiTopologyId(Uint8.valueOf(topologyIdentifier.getValue())); } return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021 @@ -301,7 +301,7 @@ public final class ProtocolUtil { final IsisLinkAttributesBuilder ilab = new IsisLinkAttributesBuilder(); ilab.setTed(tb.build()); if (topologyIdentifier != null) { - ilab.setMultiTopologyId(topologyIdentifier.getValue().shortValue()); + ilab.setMultiTopologyId(Uint8.valueOf(topologyIdentifier.getValue())); } return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021 diff --git a/bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/BmpRibInWriter.java b/bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/BmpRibInWriter.java index a2b9970325..e1f96f2686 100644 --- a/bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/BmpRibInWriter.java +++ b/bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/BmpRibInWriter.java @@ -43,8 +43,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.UnicastSubsequentAddressFamily; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceIdentifierBuilder; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; import org.slf4j.Logger; @@ -136,10 +134,8 @@ final class BmpRibInWriter { LOG.warn("No support for table type {}, skipping it", k); continue; } - final InstanceIdentifierBuilder idb = YangInstanceIdentifier.builder(yangTableRootIId); - final NodeIdentifierWithPredicates key = TablesUtil.toYangTablesKey(k); - idb.nodeWithKey(key.getNodeType(), key.asMap()); - final TableContext ctx = new TableContext(rs, idb.build(), tree); + final TableContext ctx = new TableContext(rs, + yangTableRootIId.node(TablesUtil.toYangTablesKey(k)).toOptimized(), tree); ctx.createTable(tx); tx.put(LogicalDatastoreType.OPERATIONAL, ctx.getTableId().node(BMP_ATTRIBUTES_QNAME) diff --git a/bmp/bmp-mock/src/main/java/org/opendaylight/protocol/bmp/mock/BmpMockUtil.java b/bmp/bmp-mock/src/main/java/org/opendaylight/protocol/bmp/mock/BmpMockUtil.java index e616538356..52ca59687f 100755 --- a/bmp/bmp-mock/src/main/java/org/opendaylight/protocol/bmp/mock/BmpMockUtil.java +++ b/bmp/bmp-mock/src/main/java/org/opendaylight/protocol/bmp/mock/BmpMockUtil.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.bmp.mock; import java.net.InetAddress; @@ -44,16 +43,19 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.mess import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev180329.peer.up.SentOpenBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev180329.route.monitoring.message.Update; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev180329.route.monitoring.message.UpdateBuilder; +import org.opendaylight.yangtools.yang.common.Uint16; +import org.opendaylight.yangtools.yang.common.Uint32; +import org.opendaylight.yangtools.yang.common.Uint8; final class BmpMockUtil { private static final String DESCRIPTION = "OpenDaylight"; private static final String NAME = "BMP mock"; private static final int HOLD_TIMER = 180; - private static final AsNumber ASN = new AsNumber(65431L); + private static final AsNumber ASN = new AsNumber(Uint32.valueOf(65431)); private static final Ipv4Address NEXT_HOP = new Ipv4Address("1.2.3.4"); - private static final PortNumber PEER_PORT = new PortNumber(179); - private static final ProtocolVersion PROTOCOL_VERSION = new ProtocolVersion((short) 4); + private static final PortNumber PEER_PORT = new PortNumber(Uint16.valueOf(179).intern()); + private static final ProtocolVersion PROTOCOL_VERSION = new ProtocolVersion(Uint8.valueOf(4)); private static final Origin ORIGIN = new OriginBuilder().setValue(BgpOrigin.Igp).build(); private static final AsPath AS_PATH = new AsPathBuilder().setSegments(Collections.emptyList()).build(); @@ -86,7 +88,7 @@ final class BmpMockUtil { final OpenBuilder msgBuilder = new OpenBuilder(); msgBuilder.setBgpIdentifier(address); msgBuilder.setHoldTimer(HOLD_TIMER); - msgBuilder.setMyAsNumber(ASN.getValue().intValue()); + msgBuilder.setMyAsNumber(Uint16.valueOf(ASN.getValue())); msgBuilder.setVersion(PROTOCOL_VERSION); return msgBuilder.build(); } diff --git a/bmp/bmp-parser-impl/src/main/java/org/opendaylight/protocol/bmp/parser/message/PeerDownHandler.java b/bmp/bmp-parser-impl/src/main/java/org/opendaylight/protocol/bmp/parser/message/PeerDownHandler.java index e322319e1e..dce1470de0 100644 --- a/bmp/bmp-parser-impl/src/main/java/org/opendaylight/protocol/bmp/parser/message/PeerDownHandler.java +++ b/bmp/bmp-parser-impl/src/main/java/org/opendaylight/protocol/bmp/parser/message/PeerDownHandler.java @@ -23,6 +23,7 @@ import org.opendaylight.protocol.bgp.parser.BGPParsingException; import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry; import org.opendaylight.protocol.bmp.spi.parser.AbstractBmpPerPeerMessageParser; import org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.protocol.util.ByteBufWriteUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.NotifyBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.NotifyMessage; @@ -86,20 +87,20 @@ public class PeerDownHandler extends AbstractBmpPerPeerMessageParser> exte } else { phBuilder.setAddress(new IpAddress(Ipv6Util.addressForByteBuf(bytes))); } - phBuilder.setAs(new AsNumber(bytes.readUnsignedInt())); + phBuilder.setAs(new AsNumber(ByteBufUtils.readUint32(bytes))); phBuilder.setBgpId(Ipv4Util.addressForByteBuf(bytes)); - phBuilder.setTimestampSec(new Timestamp(bytes.readUnsignedInt())); - phBuilder.setTimestampMicro(new Timestamp(bytes.readUnsignedInt())); + phBuilder.setTimestampSec(new Timestamp(ByteBufUtils.readUint32(bytes))); + phBuilder.setTimestampMicro(new Timestamp(ByteBufUtils.readUint32(bytes))); return phBuilder.build(); } diff --git a/data-change-counter/src/main/java/org/opendaylight/protocol/data/change/counter/TopologyDataChangeCounter.java b/data-change-counter/src/main/java/org/opendaylight/protocol/data/change/counter/TopologyDataChangeCounter.java index 0fe99669d0..a2535d0f1a 100644 --- a/data-change-counter/src/main/java/org/opendaylight/protocol/data/change/counter/TopologyDataChangeCounter.java +++ b/data-change-counter/src/main/java/org/opendaylight/protocol/data/change/counter/TopologyDataChangeCounter.java @@ -34,6 +34,7 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology. import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey; import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.common.Uint32; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -88,7 +89,7 @@ final class TopologyDataChangeCounter implements ClusteredDataTreeChangeListener private void putCount(final long totalCount) { final WriteTransaction wTx = this.transactionChain.newWriteOnlyTransaction(); - final Counter counter = new CounterBuilder().setId(this.counterId).setCount(totalCount).build(); + final Counter counter = new CounterBuilder().setId(this.counterId).setCount(Uint32.valueOf(totalCount)).build(); wTx.put(LogicalDatastoreType.OPERATIONAL, this.counterInstanceId, counter); wTx.commit().addCallback(new FutureCallback() { @Override diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPClassTypeObjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPClassTypeObjectParser.java index 11d7f9d6e0..9348146a00 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPClassTypeObjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPClassTypeObjectParser.java @@ -7,9 +7,9 @@ */ package org.opendaylight.protocol.pcep.parser.object; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte; -import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.pcep.spi.CommonObjectParser; @@ -55,14 +55,14 @@ public final class PCEPClassTypeObjectParser extends CommonObjectParser implemen @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. Cannot be null or empty."); if (!header.isProcessingRule()) { LOG.debug("Processed bit not set on CLASS TYPE OBJECT, ignoring it"); return null; } if (bytes.readableBytes() != SIZE) { - throw new PCEPDeserializerException("Size of byte array doesn't match defined size. Expected: " + SIZE + "; Passed: " - + bytes.readableBytes()); + throw new PCEPDeserializerException("Size of byte array doesn't match defined size. Expected: " + SIZE + + "; Passed: " + bytes.readableBytes()); } final ClassTypeBuilder builder = new ClassTypeBuilder(); builder.setIgnore(header.isIgnore()); @@ -81,11 +81,12 @@ public final class PCEPClassTypeObjectParser extends CommonObjectParser implemen @Override public void serializeObject(final Object object, final ByteBuf buffer) { - Preconditions.checkArgument(object instanceof ClassType, "Wrong instance of PCEPObject. Passed %s. Needed ClassTypeObject.", object.getClass()); + checkArgument(object instanceof ClassType, "Wrong instance of PCEPObject. Passed %s. Needed ClassTypeObject.", + object.getClass()); final ByteBuf body = Unpooled.buffer(SIZE); body.writeZero(SIZE - 1); final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ClassType classType = ((ClassType) object).getClassType(); - Preconditions.checkArgument(classType != null, "ClassType is mandatory."); + checkArgument(classType != null, "ClassType is mandatory."); writeUnsignedByte(classType.getValue(), body); ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer); } diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPCloseObjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPCloseObjectParser.java index fa8c3587eb..91b20afd0b 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPCloseObjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPCloseObjectParser.java @@ -7,9 +7,9 @@ */ package org.opendaylight.protocol.pcep.parser.object; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte; -import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import java.util.List; @@ -18,6 +18,7 @@ import org.opendaylight.protocol.pcep.spi.ObjectUtil; import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; import org.opendaylight.protocol.pcep.spi.TlvRegistry; import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.close.object.CClose; @@ -47,12 +48,13 @@ public final class PCEPCloseObjectParser extends AbstractObjectWithTlvsParser tlvs) { + protected void addVendorInformationTlvs(final TlvsBuilder builder, final List tlvs) { if (!tlvs.isEmpty()) { builder.setVendorInformationTlv(tlvs); } diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPErrorObjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPErrorObjectParser.java index f59cf94e86..bd08548581 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPErrorObjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPErrorObjectParser.java @@ -19,6 +19,7 @@ import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; import org.opendaylight.protocol.pcep.spi.PCEPErrors; import org.opendaylight.protocol.pcep.spi.TlvRegistry; import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv; @@ -51,8 +52,8 @@ public final class PCEPErrorObjectParser extends AbstractObjectWithTlvsParser tlvs) { + protected void addVendorInformationTlvs(final TlvsBuilder builder, final List tlvs) { if (!tlvs.isEmpty()) { builder.setVendorInformationTlv(tlvs); } diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPOpenObjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPOpenObjectParser.java index ad4709758f..f2d855883d 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPOpenObjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPOpenObjectParser.java @@ -5,12 +5,11 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.protocol.pcep.parser.object; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte; -import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import java.util.List; @@ -22,6 +21,7 @@ import org.opendaylight.protocol.pcep.spi.TlvRegistry; import org.opendaylight.protocol.pcep.spi.UnknownObject; import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry; import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ProtocolVersion; @@ -32,6 +32,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.open.Tlvs; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.open.TlvsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.tlvs.VendorInformationTlv; +import org.opendaylight.yangtools.yang.common.Uint8; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -62,7 +63,7 @@ public class PCEPOpenObjectParser extends AbstractObjectWithTlvsParser requestIDs = new ArrayList<>(); while (bytes.isReadable()) { - requestIDs.add(new RequestId(bytes.readUnsignedInt())); + requestIDs.add(new RequestId(ByteBufUtils.readUint32(bytes))); } if (requestIDs.isEmpty()) { throw new PCEPDeserializerException("Empty Svec Object - no request ids."); @@ -109,7 +110,7 @@ public final class PCEPSvecObjectParser extends CommonObjectParser implements Ob flags.toByteBuf(body); final List requestIDs = svecObj.getRequestsIds(); - assert !(requestIDs.isEmpty()) : "Empty Svec Object - no request ids."; + assert !requestIDs.isEmpty() : "Empty Svec Object - no request ids."; for (final RequestId requestId : requestIDs) { writeUnsignedInt(requestId.getValue(), body); } diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/AsNumberCaseParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/AsNumberCaseParser.java index 97e129b385..907cba65c7 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/AsNumberCaseParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/AsNumberCaseParser.java @@ -7,9 +7,9 @@ */ package org.opendaylight.protocol.pcep.parser.subobject; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeShort; -import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; @@ -18,6 +18,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.as.number._case.AsNumberBuilder; +import org.opendaylight.yangtools.yang.common.Uint32; final class AsNumberCaseParser { @@ -28,19 +29,20 @@ final class AsNumberCaseParser { private static final int CONTENT_LENGTH = 2; static AsNumberCase 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. Cannot be null or empty."); if (buffer.readableBytes() != CONTENT_LENGTH) { - throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: " - + CONTENT_LENGTH + "."); + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + + "; Expected: " + CONTENT_LENGTH + "."); } - return new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber((long) buffer.readUnsignedShort())).build()).build(); + return new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber( + new AsNumber(Uint32.valueOf(buffer.readUnsignedShort()))).build()).build(); } static ByteBuf serializeSubobject(final AsNumberCase asCase) { final AsNumberSubobject asNumber = asCase.getAsNumber(); final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH); - Preconditions.checkArgument(asNumber.getAsNumber() != null, "AsNumber is mandatory."); + checkArgument(asNumber.getAsNumber() != null, "AsNumber is mandatory."); writeShort(asNumber.getAsNumber().getValue().shortValue(), body); return body; } diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/EROUnnumberedInterfaceSubobjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/EROUnnumberedInterfaceSubobjectParser.java index dc3e08f140..5a57cd2e14 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/EROUnnumberedInterfaceSubobjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/EROUnnumberedInterfaceSubobjectParser.java @@ -7,15 +7,16 @@ */ package org.opendaylight.protocol.pcep.parser.subobject; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt; -import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.pcep.spi.EROSubobjectParser; import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer; import org.opendaylight.protocol.pcep.spi.EROSubobjectUtil; import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; +import org.opendaylight.protocol.util.ByteBufUtils; 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.UnnumberedSubobject; @@ -36,30 +37,31 @@ public class EROUnnumberedInterfaceSubobjectParser implements EROSubobjectParser @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. Cannot be null or empty."); if (buffer.readableBytes() != CONTENT_LENGTH) { - throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: " - + CONTENT_LENGTH + "."); + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + + "; Expected: " + CONTENT_LENGTH + "."); } final SubobjectBuilder builder = new SubobjectBuilder(); builder.setLoose(loose); final UnnumberedBuilder ubuilder = new UnnumberedBuilder(); buffer.skipBytes(RESERVED); - ubuilder.setRouterId(buffer.readUnsignedInt()); - ubuilder.setInterfaceId(buffer.readUnsignedInt()); + ubuilder.setRouterId(ByteBufUtils.readUint32(buffer)); + ubuilder.setInterfaceId(ByteBufUtils.readUint32(buffer)); builder.setSubobjectType(new UnnumberedCaseBuilder().setUnnumbered(ubuilder.build()).build()); return builder.build(); } @Override public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) { - Preconditions.checkArgument(subobject.getSubobjectType() instanceof UnnumberedCase, "Unknown subobject instance. Passed %s. Needed UnnumberedCase.", subobject.getSubobjectType().getClass()); + checkArgument(subobject.getSubobjectType() instanceof UnnumberedCase, + "Unknown subobject instance. Passed %s. Needed UnnumberedCase.", subobject.getSubobjectType().getClass()); final UnnumberedSubobject specObj = ((UnnumberedCase) subobject.getSubobjectType()).getUnnumbered(); final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH); body.writeZero(RESERVED); - Preconditions.checkArgument(specObj.getRouterId() != null, "RouterId is mandatory."); + checkArgument(specObj.getRouterId() != null, "RouterId is mandatory."); writeUnsignedInt(specObj.getRouterId(), body); - Preconditions.checkArgument(specObj.getInterfaceId() != null, "InterfaceId is mandatory"); + checkArgument(specObj.getInterfaceId() != null, "InterfaceId is mandatory"); writeUnsignedInt(specObj.getInterfaceId(), body); EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer); } diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/RROPathKey128SubobjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/RROPathKey128SubobjectParser.java index 7e64533730..b4d6118048 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/RROPathKey128SubobjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/RROPathKey128SubobjectParser.java @@ -7,15 +7,16 @@ */ package org.opendaylight.protocol.pcep.parser.subobject; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort; -import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; import org.opendaylight.protocol.pcep.spi.RROSubobjectParser; import org.opendaylight.protocol.pcep.spi.RROSubobjectUtil; import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.util.ByteBufUtils; 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.PathKey; @@ -23,6 +24,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.path.key._case.PathKeyBuilder; +import org.opendaylight.yangtools.yang.common.Uint16; public class RROPathKey128SubobjectParser implements RROSubobjectParser { @@ -39,12 +41,12 @@ public class RROPathKey128SubobjectParser implements RROSubobjectParser { @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. Cannot be null or empty."); if (buffer.readableBytes() != CONTENT128_LENGTH) { - throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >" - + CONTENT128_LENGTH + "."); + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + + "; Expected: >" + CONTENT128_LENGTH + "."); } - final int pathKey = buffer.readUnsignedShort(); + final Uint16 pathKey = ByteBufUtils.readUint16(buffer); final byte[] pceId = ByteArray.readBytes(buffer, PCE128_ID_F_LENGTH); final SubobjectBuilder builder = new SubobjectBuilder(); final PathKeyBuilder pBuilder = new PathKeyBuilder(); @@ -59,9 +61,9 @@ public class RROPathKey128SubobjectParser implements RROSubobjectParser { final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects .subobject.type.path.key._case.PathKey pk = pkcase.getPathKey(); final ByteBuf body = Unpooled.buffer(); - Preconditions.checkArgument(pk.getPathKey() != null, "PathKey is mandatory."); + checkArgument(pk.getPathKey() != null, "PathKey is mandatory."); writeUnsignedShort(pk.getPathKey().getValue(), body); - Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory."); + checkArgument(pk.getPceId() != null, "PceId is mandatory."); body.writeBytes(pk.getPceId().getValue()); RROSubobjectUtil.formatSubobject(TYPE, body, buffer); } diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/RROPathKey32SubobjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/RROPathKey32SubobjectParser.java index e514ae83dc..bba285a07f 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/RROPathKey32SubobjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/RROPathKey32SubobjectParser.java @@ -7,6 +7,7 @@ */ package org.opendaylight.protocol.pcep.parser.subobject; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort; import com.google.common.base.Preconditions; @@ -17,6 +18,7 @@ import org.opendaylight.protocol.pcep.spi.RROSubobjectParser; import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer; import org.opendaylight.protocol.pcep.spi.RROSubobjectUtil; import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.util.ByteBufUtils; 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.PathKey; @@ -24,6 +26,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.path.key._case.PathKeyBuilder; +import org.opendaylight.yangtools.yang.common.Uint16; public class RROPathKey32SubobjectParser implements RROSubobjectParser, RROSubobjectSerializer { @@ -39,12 +42,13 @@ public class RROPathKey32SubobjectParser implements RROSubobjectParser, RROSubob @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. Cannot be null or empty."); if (buffer.readableBytes() != CONTENT_LENGTH) { - throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >" - + CONTENT_LENGTH + "."); + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + + "; Expected: >" + CONTENT_LENGTH + "."); } - final int pathKey = buffer.readUnsignedShort(); + final Uint16 pathKey = ByteBufUtils.readUint16(buffer); final byte[] pceId = ByteArray.readBytes(buffer, PCE_ID_F_LENGTH); final SubobjectBuilder builder = new SubobjectBuilder(); final PathKeyBuilder pBuilder = new PathKeyBuilder(); @@ -56,18 +60,19 @@ public class RROPathKey32SubobjectParser implements RROSubobjectParser, RROSubob @Override public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) { - Preconditions.checkArgument(subobject.getSubobjectType() instanceof PathKeyCase, "Unknown subobject instance. Passed %s. Needed PathKey.", subobject.getSubobjectType().getClass()); + checkArgument(subobject.getSubobjectType() instanceof PathKeyCase, + "Unknown subobject instance. Passed %s. Needed PathKey.", subobject.getSubobjectType().getClass()); final PathKeyCase pkcase = (PathKeyCase) subobject.getSubobjectType(); final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects .subobject.type.path.key._case.PathKey pk = pkcase.getPathKey(); final ByteBuf body = Unpooled.buffer(); - Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory."); + checkArgument(pk.getPceId() != null, "PceId is mandatory."); final byte[] pceId = pk.getPceId().getValue(); if (pceId.length == RROPathKey128SubobjectParser.PCE128_ID_F_LENGTH) { RROPathKey128SubobjectParser.serializeSubobject(subobject,buffer); } - Preconditions.checkArgument(pk.getPathKey() != null, "PathKey is mandatory."); + checkArgument(pk.getPathKey() != null, "PathKey is mandatory."); writeUnsignedShort(pk.getPathKey().getValue(), body); Preconditions.checkArgument(pceId.length == PCE_ID_F_LENGTH, "PceId 32 Bit required."); body.writeBytes(pceId); diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/RROUnnumberedInterfaceSubobjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/RROUnnumberedInterfaceSubobjectParser.java index df4ce3f1c2..8d7b3589ae 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/RROUnnumberedInterfaceSubobjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/RROUnnumberedInterfaceSubobjectParser.java @@ -7,9 +7,9 @@ */ package org.opendaylight.protocol.pcep.parser.subobject; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt; -import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; @@ -17,6 +17,7 @@ import org.opendaylight.protocol.pcep.spi.RROSubobjectParser; import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer; import org.opendaylight.protocol.pcep.spi.RROSubobjectUtil; import org.opendaylight.protocol.util.BitArray; +import org.opendaylight.protocol.util.ByteBufUtils; 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.UnnumberedSubobject; @@ -41,10 +42,10 @@ public class RROUnnumberedInterfaceSubobjectParser implements RROSubobjectParser @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. Cannot be null or empty."); if (buffer.readableBytes() != CONTENT_LENGTH) { - throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: " - + CONTENT_LENGTH + "."); + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + + "; Expected: " + CONTENT_LENGTH + "."); } final SubobjectBuilder builder = new SubobjectBuilder(); final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE); @@ -52,15 +53,16 @@ public class RROUnnumberedInterfaceSubobjectParser implements RROSubobjectParser builder.setProtectionInUse(flags.get(LPIU_F_OFFSET)); final UnnumberedBuilder ubuilder = new UnnumberedBuilder(); buffer.skipBytes(RESERVED); - ubuilder.setRouterId(buffer.readUnsignedInt()); - ubuilder.setInterfaceId(buffer.readUnsignedInt()); + ubuilder.setRouterId(ByteBufUtils.readUint32(buffer)); + ubuilder.setInterfaceId(ByteBufUtils.readUint32(buffer)); builder.setSubobjectType(new UnnumberedCaseBuilder().setUnnumbered(ubuilder.build()).build()); return builder.build(); } @Override public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) { - Preconditions.checkArgument(subobject.getSubobjectType() instanceof UnnumberedCase, "Unknown subobject instance. Passed %s. Needed UnnumberedCase.", subobject.getSubobjectType().getClass()); + checkArgument(subobject.getSubobjectType() instanceof UnnumberedCase, + "Unknown subobject instance. Passed %s. Needed UnnumberedCase.", subobject.getSubobjectType().getClass()); final UnnumberedSubobject specObj = ((UnnumberedCase) subobject.getSubobjectType()).getUnnumbered(); final BitArray flags = new BitArray(FLAGS_SIZE); flags.set(LPA_F_OFFSET, subobject.isProtectionAvailable()); @@ -68,9 +70,9 @@ public class RROUnnumberedInterfaceSubobjectParser implements RROSubobjectParser final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH); flags.toByteBuf(body); body.writeZero(RESERVED); - Preconditions.checkArgument(specObj.getRouterId() != null, "RouterId is mandatory."); + checkArgument(specObj.getRouterId() != null, "RouterId is mandatory."); writeUnsignedInt(specObj.getRouterId(), body); - Preconditions.checkArgument(specObj.getInterfaceId() != null, "InterfaceId is mandatory."); + checkArgument(specObj.getInterfaceId() != null, "InterfaceId is mandatory."); writeUnsignedInt(specObj.getInterfaceId(), body); RROSubobjectUtil.formatSubobject(TYPE, body, buffer); } diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/Type1LabelParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/Type1LabelParser.java index e7a9053bc0..d23b0285df 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/Type1LabelParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/Type1LabelParser.java @@ -7,15 +7,16 @@ */ package org.opendaylight.protocol.pcep.parser.subobject; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt; -import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.pcep.spi.LabelParser; import org.opendaylight.protocol.pcep.spi.LabelSerializer; import org.opendaylight.protocol.pcep.spi.LabelUtil; import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.LabelType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.Type1LabelCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.Type1LabelCaseBuilder; @@ -33,20 +34,24 @@ public class Type1LabelParser implements LabelParser, LabelSerializer { @Override public LabelType parseLabel(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. Cannot be null or empty."); if (buffer.readableBytes() != LABEL_LENGTH) { - throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: " - + LABEL_LENGTH + "."); + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + + "; Expected: " + LABEL_LENGTH + "."); } - return new Type1LabelCaseBuilder().setType1Label(new Type1LabelBuilder().setType1Label(buffer.readUnsignedInt()).build()).build(); + return new Type1LabelCaseBuilder() + .setType1Label(new Type1LabelBuilder().setType1Label(ByteBufUtils.readUint32(buffer)).build()) + .build(); } @Override - public void serializeLabel(final boolean unidirectional, final boolean global, final LabelType subobject, final ByteBuf buffer) { - Preconditions.checkArgument(subobject instanceof Type1LabelCase, "Unknown Label Subobject instance. Passed {}. Needed Type1LabelCase.", subobject.getClass()); + public void serializeLabel(final boolean unidirectional, final boolean global, final LabelType subobject, + final ByteBuf buffer) { + checkArgument(subobject instanceof Type1LabelCase, + "Unknown Label Subobject instance. Passed {}. Needed Type1LabelCase.", subobject.getClass()); final ByteBuf body = Unpooled.buffer(LABEL_LENGTH); final Type1Label type1Label = ((Type1LabelCase) subobject).getType1Label(); - Preconditions.checkArgument(type1Label != null, "Type1Label is mandatory."); + checkArgument(type1Label != null, "Type1Label is mandatory."); writeUnsignedInt(type1Label.getType1Label(), body); LabelUtil.formatLabel(CTYPE, unidirectional, global, body, buffer); } diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/WavebandSwitchingLabelParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/WavebandSwitchingLabelParser.java index 7bcb77b38d..9b1869c66a 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/WavebandSwitchingLabelParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/WavebandSwitchingLabelParser.java @@ -7,15 +7,16 @@ */ package org.opendaylight.protocol.pcep.parser.subobject; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt; -import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.pcep.spi.LabelParser; import org.opendaylight.protocol.pcep.spi.LabelSerializer; import org.opendaylight.protocol.pcep.spi.LabelUtil; import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.LabelType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.WavebandSwitchingLabelCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.WavebandSwitchingLabelCaseBuilder; @@ -37,28 +38,31 @@ public class WavebandSwitchingLabelParser implements LabelParser, LabelSerialize @Override public LabelType parseLabel(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. Cannot be null or empty."); if (buffer.readableBytes() != CONTENT_LENGTH) { - throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: " - + CONTENT_LENGTH + "."); + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + + "; Expected: " + CONTENT_LENGTH + "."); } - final WavebandSwitchingLabelBuilder builder = new WavebandSwitchingLabelBuilder(); - builder.setWavebandId(buffer.readUnsignedInt()); - builder.setStartLabel(buffer.readUnsignedInt()); - builder.setEndLabel(buffer.readUnsignedInt()); - return new WavebandSwitchingLabelCaseBuilder().setWavebandSwitchingLabel(builder.build()).build(); + return new WavebandSwitchingLabelCaseBuilder() + .setWavebandSwitchingLabel(new WavebandSwitchingLabelBuilder() + .setWavebandId(ByteBufUtils.readUint32(buffer)) + .setStartLabel(ByteBufUtils.readUint32(buffer)) + .setEndLabel(ByteBufUtils.readUint32(buffer)) + .build()) + .build(); } @Override public void serializeLabel(final boolean unidirectional, final boolean global, final LabelType subobject, final ByteBuf buffer) { - Preconditions.checkArgument(subobject instanceof WavebandSwitchingLabelCase, "Unknown Label Subobject instance. Passed {}. Needed WavebandSwitchingLabelCase.", subobject.getClass()); + checkArgument(subobject instanceof WavebandSwitchingLabelCase, + "Unknown Label Subobject instance. Passed {}. Needed WavebandSwitchingLabelCase.", subobject.getClass()); final WavebandSwitchingLabel obj = ((WavebandSwitchingLabelCase) subobject).getWavebandSwitchingLabel(); final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH); - Preconditions.checkArgument(obj.getWavebandId() != null, "WavebandId is mandatory."); + checkArgument(obj.getWavebandId() != null, "WavebandId is mandatory."); writeUnsignedInt(obj.getWavebandId(), body); - Preconditions.checkArgument(obj.getStartLabel() != null, "StartLabel is mandatory."); + checkArgument(obj.getStartLabel() != null, "StartLabel is mandatory."); writeUnsignedInt(obj.getStartLabel(), body); - Preconditions.checkArgument(obj.getEndLabel() != null, "EndLabel is mandatory."); + checkArgument(obj.getEndLabel() != null, "EndLabel is mandatory."); writeUnsignedInt(obj.getEndLabel(), body); LabelUtil.formatLabel(CTYPE, unidirectional, global, 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 48e392fdd0..1f3641503e 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 @@ -7,6 +7,7 @@ */ package org.opendaylight.protocol.pcep.parser.subobject; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Prefix; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte; @@ -43,15 +44,17 @@ public class XROIpv4PrefixSubobjectParser implements XROSubobjectParser, XROSubo @Override public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory) 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. Cannot be null or empty."); final SubobjectBuilder builder = new SubobjectBuilder(); builder.setMandatory(mandatory); if (buffer.readableBytes() != CONTENT4_LENGTH) { - throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";"); + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + + ";"); } final int length = buffer.getUnsignedByte(PREFIX4_F_OFFSET); - final IpPrefixBuilder prefix = new IpPrefixBuilder().setIpPrefix(new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.readBytes(buffer, - Ipv4Util.IP4_LENGTH), length))); + final IpPrefixBuilder prefix = new IpPrefixBuilder() + .setIpPrefix(new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.readBytes(buffer, Ipv4Util.IP4_LENGTH), + length))); builder.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(prefix.build()).build()); buffer.skipBytes(PREFIX_F_LENGTH); builder.setAttribute(Attribute.forValue(buffer.readUnsignedByte())); @@ -60,10 +63,12 @@ public class XROIpv4PrefixSubobjectParser implements XROSubobjectParser, XROSubo @Override public void serializeSubobject(final Subobject 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()); + checkArgument(prefix.getIpv4Prefix() != null || prefix.getIpv6Prefix() != null, + "Unknown AbstractPrefix instance. Passed %s.", prefix.getClass()); if (prefix.getIpv6Prefix() != null) { new XROIpv6PrefixSubobjectParser().serializeSubobject(subobject, buffer); } else { diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROPathKey128SubobjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROPathKey128SubobjectParser.java index b1f26d56e5..8433fb9eaa 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROPathKey128SubobjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROPathKey128SubobjectParser.java @@ -7,15 +7,16 @@ */ package org.opendaylight.protocol.pcep.parser.subobject; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort; -import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; import org.opendaylight.protocol.pcep.spi.XROSubobjectParser; import org.opendaylight.protocol.pcep.spi.XROSubobjectUtil; import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.Subobject; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.SubobjectBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey; @@ -23,6 +24,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKeyBuilder; +import org.opendaylight.yangtools.yang.common.Uint16; /** * Parser for {@link PathKey} @@ -37,12 +39,12 @@ public class XROPathKey128SubobjectParser implements XROSubobjectParser { @Override public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory) 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. Cannot be null or empty."); if (buffer.readableBytes() != CONTENT128_LENGTH) { - throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >" - + CONTENT128_LENGTH + "."); + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + + "; Expected: >" + CONTENT128_LENGTH + "."); } - final int pathKey = buffer.readUnsignedShort(); + final Uint16 pathKey = ByteBufUtils.readUint16(buffer); final byte[] pceId = ByteArray.readBytes(buffer, PCE128_ID_F_LENGTH); final SubobjectBuilder builder = new SubobjectBuilder(); final PathKeyBuilder pBuilder = new PathKeyBuilder(); @@ -54,13 +56,15 @@ public class XROPathKey128SubobjectParser implements XROSubobjectParser { } public static void serializeSubobject(final Subobject subobject, final ByteBuf buffer) { - Preconditions.checkArgument(subobject.getSubobjectType() instanceof PathKeyCase, "Unknown subobject instance. Passed %s. Needed PathKey.", subobject.getSubobjectType().getClass()); + checkArgument(subobject.getSubobjectType() instanceof PathKeyCase, + "Unknown subobject instance. Passed %s. Needed PathKey.", subobject.getSubobjectType().getClass()); final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route - .subobjects.subobject.type.path.key._case.PathKey pk = ((PathKeyCase) subobject.getSubobjectType()).getPathKey(); + .subobjects.subobject.type.path.key._case.PathKey pk = + ((PathKeyCase) subobject.getSubobjectType()).getPathKey(); final ByteBuf body = Unpooled.buffer(); - Preconditions.checkArgument(pk.getPathKey() != null, "PathKey is mandatory."); + checkArgument(pk.getPathKey() != null, "PathKey is mandatory."); writeUnsignedShort(pk.getPathKey().getValue(), body); - Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory."); + checkArgument(pk.getPceId() != null, "PceId is mandatory."); body.writeBytes(pk.getPceId().getValue()); XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer); } diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROPathKey32SubobjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROPathKey32SubobjectParser.java index 59080767b7..1ccdb4d9f6 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROPathKey32SubobjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROPathKey32SubobjectParser.java @@ -7,9 +7,9 @@ */ package org.opendaylight.protocol.pcep.parser.subobject; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort; -import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; @@ -17,6 +17,7 @@ import org.opendaylight.protocol.pcep.spi.XROSubobjectParser; import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer; import org.opendaylight.protocol.pcep.spi.XROSubobjectUtil; import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.Subobject; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.SubobjectBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey; @@ -24,6 +25,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKeyBuilder; +import org.opendaylight.yangtools.yang.common.Uint16; /** * Parser for {@link PathKey} @@ -38,12 +40,12 @@ public class XROPathKey32SubobjectParser implements XROSubobjectParser, XROSubob @Override public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory) 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. Cannot be null or empty."); if (buffer.readableBytes() != CONTENT_LENGTH) { - throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >" - + CONTENT_LENGTH + "."); + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + + "; Expected: >" + CONTENT_LENGTH + "."); } - final int pathKey = buffer.readUnsignedShort(); + final Uint16 pathKey = ByteBufUtils.readUint16(buffer); final byte[] pceId = ByteArray.readBytes(buffer, PCE_ID_F_LENGTH); final SubobjectBuilder builder = new SubobjectBuilder(); final PathKeyBuilder pBuilder = new PathKeyBuilder(); @@ -56,19 +58,21 @@ public class XROPathKey32SubobjectParser implements XROSubobjectParser, XROSubob @Override public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) { - Preconditions.checkArgument(subobject.getSubobjectType() instanceof PathKeyCase, "Unknown subobject instance. Passed %s. Needed PathKey.", subobject.getSubobjectType().getClass()); + checkArgument(subobject.getSubobjectType() instanceof PathKeyCase, + "Unknown subobject instance. Passed %s. Needed PathKey.", subobject.getSubobjectType().getClass()); final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route - .subobjects.subobject.type.path.key._case.PathKey pk = ((PathKeyCase) subobject.getSubobjectType()).getPathKey(); + .subobjects.subobject.type.path.key._case.PathKey pk = + ((PathKeyCase) subobject.getSubobjectType()).getPathKey(); final ByteBuf body = Unpooled.buffer(); - Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory."); + checkArgument(pk.getPceId() != null, "PceId is mandatory."); final byte[] pceId = pk.getPceId().getValue(); if (pceId.length == XROPathKey128SubobjectParser.PCE128_ID_F_LENGTH) { XROPathKey128SubobjectParser.serializeSubobject(subobject,buffer); } - Preconditions.checkArgument(pk.getPathKey() != null, "PathKey is mandatory."); + checkArgument(pk.getPathKey() != null, "PathKey is mandatory."); writeUnsignedShort(pk.getPathKey().getValue(), body); - Preconditions.checkArgument(pceId.length == PCE_ID_F_LENGTH, "PceId 32 Bit required."); + checkArgument(pceId.length == PCE_ID_F_LENGTH, "PceId 32 Bit required."); body.writeBytes(pceId); XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer); } diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROSRLGSubobjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROSRLGSubobjectParser.java index c58ed4c97a..4b7d76f728 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROSRLGSubobjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROSRLGSubobjectParser.java @@ -7,16 +7,17 @@ */ package org.opendaylight.protocol.pcep.parser.subobject; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt; -import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; import org.opendaylight.protocol.pcep.spi.XROSubobjectParser; import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer; import org.opendaylight.protocol.pcep.spi.XROSubobjectUtil; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.Subobject; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.SubobjectBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects; @@ -38,28 +39,32 @@ public class XROSRLGSubobjectParser implements XROSubobjectParser, XROSubobjectS @Override public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory) 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. Cannot be null or empty."); if (buffer.readableBytes() != CONTENT_LENGTH) { - throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: " - + CONTENT_LENGTH + "."); + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + + "; Expected: " + CONTENT_LENGTH + "."); } - final SubobjectBuilder builder = new SubobjectBuilder(); - builder.setMandatory(mandatory); - - builder.setSubobjectType(new SrlgCaseBuilder().setSrlg(new SrlgBuilder().setSrlgId(new SrlgId(buffer.readUnsignedInt())).build()).build()); + final SubobjectBuilder builder = new SubobjectBuilder() + .setMandatory(mandatory) + .setSubobjectType(new SrlgCaseBuilder() + .setSrlg(new SrlgBuilder() + .setSrlgId(new SrlgId(ByteBufUtils.readUint32(buffer))) + .build()) + .build()); buffer.readByte(); - builder.setAttribute(ExcludeRouteSubobjects.Attribute.forValue(buffer.readUnsignedByte())); - return builder.build(); + return builder.setAttribute(ExcludeRouteSubobjects.Attribute.forValue(buffer.readUnsignedByte())) + .build(); } @Override public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) { - Preconditions.checkArgument(subobject.getSubobjectType() instanceof SrlgCase, "Unknown subobject instance. Passed %s. Needed SrlgCase.", subobject.getSubobjectType().getClass()); + checkArgument(subobject.getSubobjectType() instanceof SrlgCase, + "Unknown subobject instance. Passed %s. Needed SrlgCase.", subobject.getSubobjectType().getClass()); final SrlgSubobject specObj = ((SrlgCase) subobject.getSubobjectType()).getSrlg(); final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH); - Preconditions.checkArgument(specObj.getSrlgId() != null, "SrlgId is mandatory."); + checkArgument(specObj.getSrlgId() != null, "SrlgId is mandatory."); writeUnsignedInt(specObj.getSrlgId().getValue(), body); - Preconditions.checkArgument(subobject.getAttribute() != null, "Attribute is mandatory."); + checkArgument(subobject.getAttribute() != null, "Attribute is mandatory."); writeUnsignedByte((Uint8) null, body); writeUnsignedByte((short) subobject.getAttribute().getIntValue(), body); XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer); diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROUnnumberedInterfaceSubobjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROUnnumberedInterfaceSubobjectParser.java index 59fb28a108..350a9d35d5 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROUnnumberedInterfaceSubobjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROUnnumberedInterfaceSubobjectParser.java @@ -7,16 +7,17 @@ */ package org.opendaylight.protocol.pcep.parser.subobject; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt; -import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; import org.opendaylight.protocol.pcep.spi.XROSubobjectParser; import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer; import org.opendaylight.protocol.pcep.spi.XROSubobjectUtil; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.Subobject; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.SubobjectBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute; @@ -38,32 +39,34 @@ public class XROUnnumberedInterfaceSubobjectParser implements XROSubobjectParser @Override public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory) 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. Cannot be null or empty."); if (buffer.readableBytes() != CONTENT_LENGTH) { - throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: " - + CONTENT_LENGTH + "."); + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + + "; Expected: " + CONTENT_LENGTH + "."); } buffer.readerIndex(buffer.readerIndex() + RESERVED); final SubobjectBuilder builder = new SubobjectBuilder(); builder.setMandatory(mandatory); builder.setAttribute(Attribute.forValue(buffer.readUnsignedByte())); final UnnumberedBuilder ubuilder = new UnnumberedBuilder(); - ubuilder.setRouterId(buffer.readUnsignedInt()); - ubuilder.setInterfaceId(buffer.readUnsignedInt()); + ubuilder.setRouterId(ByteBufUtils.readUint32(buffer)); + ubuilder.setInterfaceId(ByteBufUtils.readUint32(buffer)); builder.setSubobjectType(new UnnumberedCaseBuilder().setUnnumbered(ubuilder.build()).build()); return builder.build(); } @Override public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) { - Preconditions.checkArgument(subobject.getSubobjectType() instanceof UnnumberedCase, "Unknown subobject instance. Passed %s. Needed UnnumberedCase.", subobject.getSubobjectType().getClass()); + checkArgument(subobject.getSubobjectType() instanceof UnnumberedCase, + "Unknown subobject instance. Passed %s. Needed UnnumberedCase.", subobject.getSubobjectType().getClass()); final UnnumberedSubobject specObj = ((UnnumberedCase) subobject.getSubobjectType()).getUnnumbered(); final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH); body.writeZero(RESERVED); - writeUnsignedByte(subobject.getAttribute() != null ? (short) subobject.getAttribute().getIntValue() : null, body); - Preconditions.checkArgument(specObj.getRouterId() != null, "RouterId is mandatory."); + writeUnsignedByte(subobject.getAttribute() != null ? (short) subobject.getAttribute().getIntValue() : null, + body); + checkArgument(specObj.getRouterId() != null, "RouterId is mandatory."); writeUnsignedInt(specObj.getRouterId(), body); - Preconditions.checkArgument(specObj.getInterfaceId() != null, "InterfaceId is mandatory."); + checkArgument(specObj.getInterfaceId() != null, "InterfaceId is mandatory."); writeUnsignedInt(specObj.getInterfaceId(), body); XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer); } diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/tlv/OFListTlvParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/tlv/OFListTlvParser.java index 054f4817a5..a8e575a039 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/tlv/OFListTlvParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/tlv/OFListTlvParser.java @@ -7,9 +7,9 @@ */ package org.opendaylight.protocol.pcep.parser.tlv; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort; -import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import java.util.ArrayList; @@ -18,6 +18,7 @@ import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; import org.opendaylight.protocol.pcep.spi.TlvParser; import org.opendaylight.protocol.pcep.spi.TlvSerializer; import org.opendaylight.protocol.pcep.spi.TlvUtil; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.OfId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.of.list.tlv.OfList; @@ -38,18 +39,19 @@ public class OFListTlvParser implements TlvParser, TlvSerializer { return null; } if (buffer.readableBytes() % OF_CODE_ELEMENT_LENGTH != 0) { - throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "."); + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + + "."); } final List ofCodes = new ArrayList<>(); while (buffer.isReadable()) { - ofCodes.add(new OfId(buffer.readUnsignedShort())); + ofCodes.add(new OfId(ByteBufUtils.readUint16(buffer))); } return new OfListBuilder().setCodes(ofCodes).build(); } @Override public void serializeTlv(final Tlv tlv, final ByteBuf buffer) { - Preconditions.checkArgument(tlv instanceof OfList, "OFListTlv is mandatory."); + checkArgument(tlv instanceof OfList, "OFListTlv is mandatory."); final OfList oft = (OfList) tlv; final ByteBuf body = Unpooled.buffer(); final List ofCodes = oft.getCodes(); diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/tlv/OrderTlvParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/tlv/OrderTlvParser.java index abfe6d5e57..5dff66950e 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/tlv/OrderTlvParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/tlv/OrderTlvParser.java @@ -7,15 +7,16 @@ */ package org.opendaylight.protocol.pcep.parser.tlv; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt; -import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; import org.opendaylight.protocol.pcep.spi.TlvParser; import org.opendaylight.protocol.pcep.spi.TlvSerializer; import org.opendaylight.protocol.pcep.spi.TlvUtil; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.order.tlv.Order; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.order.tlv.OrderBuilder; @@ -32,12 +33,15 @@ public class OrderTlvParser implements TlvParser, TlvSerializer { if (buffer == null) { return null; } - return new OrderBuilder().setDelete(buffer.readUnsignedInt()).setSetup(buffer.readUnsignedInt()).build(); + return new OrderBuilder() + .setDelete(ByteBufUtils.readUint32(buffer)) + .setSetup(ByteBufUtils.readUint32(buffer)) + .build(); } @Override public void serializeTlv(final Tlv tlv, final ByteBuf buffer) { - Preconditions.checkArgument(tlv instanceof Order, "OrderTlv is mandatory."); + checkArgument(tlv instanceof Order, "OrderTlv is mandatory."); final Order otlv = (Order) tlv; final ByteBuf body = Unpooled.buffer(); writeUnsignedInt(otlv.getDelete(), body); diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/tlv/OverloadedDurationTlvParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/tlv/OverloadedDurationTlvParser.java index 731a378ed1..e216fb268a 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/tlv/OverloadedDurationTlvParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/tlv/OverloadedDurationTlvParser.java @@ -7,15 +7,16 @@ */ package org.opendaylight.protocol.pcep.parser.tlv; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt; -import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; import org.opendaylight.protocol.pcep.spi.TlvParser; import org.opendaylight.protocol.pcep.spi.TlvSerializer; import org.opendaylight.protocol.pcep.spi.TlvUtil; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.overload.duration.tlv.OverloadDuration; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.overload.duration.tlv.OverloadDurationBuilder; @@ -32,12 +33,12 @@ public class OverloadedDurationTlvParser implements TlvParser, TlvSerializer { if (buffer == null) { return null; } - return new OverloadDurationBuilder().setDuration(buffer.readUnsignedInt()).build(); + return new OverloadDurationBuilder().setDuration(ByteBufUtils.readUint32(buffer)).build(); } @Override public void serializeTlv(final Tlv tlv, final ByteBuf buffer) { - Preconditions.checkArgument(tlv instanceof OverloadDuration, "OverloadedTlv is mandatory."); + checkArgument(tlv instanceof OverloadDuration, "OverloadedTlv is mandatory."); final ByteBuf body = Unpooled.buffer(); writeUnsignedInt(((OverloadDuration) tlv).getDuration(), body); TlvUtil.formatTlv(TYPE, body, buffer); diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/tlv/ReqMissingTlvParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/tlv/ReqMissingTlvParser.java index 558f270d35..93687af9ab 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/tlv/ReqMissingTlvParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/tlv/ReqMissingTlvParser.java @@ -16,6 +16,7 @@ import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; import org.opendaylight.protocol.pcep.spi.TlvParser; import org.opendaylight.protocol.pcep.spi.TlvSerializer; import org.opendaylight.protocol.pcep.spi.TlvUtil; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.RequestId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.req.missing.tlv.ReqMissing; @@ -33,7 +34,7 @@ public class ReqMissingTlvParser implements TlvParser, TlvSerializer { if (buffer == null) { return null; } - return new ReqMissingBuilder().setRequestId(new RequestId(buffer.readUnsignedInt())).build(); + return new ReqMissingBuilder().setRequestId(new RequestId(ByteBufUtils.readUint32(buffer))).build(); } @Override diff --git a/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/PathBindingTlvParser.java b/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/PathBindingTlvParser.java index 4b94f73c97..bd13a14d04 100644 --- a/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/PathBindingTlvParser.java +++ b/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/PathBindingTlvParser.java @@ -28,6 +28,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.iet import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.path.binding.tlv.path.binding.binding.type.value.MplsLabelEntryBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv; import org.opendaylight.yangtools.concepts.IllegalArgumentCodec; +import org.opendaylight.yangtools.yang.common.Uint32; +import org.opendaylight.yangtools.yang.common.Uint8; /** * Parser for {@link PathBinding}. @@ -146,9 +148,9 @@ public final class PathBindingTlvParser implements TlvParser, TlvSerializer { final MplsLabelEntryBuilder builder = new MplsLabelEntryBuilder(); final long entry = buffer.readUnsignedInt(); builder.setLabel(getMplsLabel(entry)); - builder.setTrafficClass((short) (entry >> TC_SHIFT & TC_MASK)); + builder.setTrafficClass(Uint8.valueOf(entry >> TC_SHIFT & TC_MASK)); builder.setBottomOfStack((entry >> S_SHIFT & S_MASK) == 1); - builder.setTimeToLive((short) (entry & TTL_MASK)); + builder.setTimeToLive(Uint8.valueOf(entry & TTL_MASK)); return builder.build(); } @@ -167,7 +169,7 @@ public final class PathBindingTlvParser implements TlvParser, TlvSerializer { private static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.MplsLabel getMplsLabel(final long mplsStackEntry) { return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125 - .MplsLabel(mplsStackEntry >> LABEL_SHIFT & LABEL_MASK); + .MplsLabel(Uint32.valueOf(mplsStackEntry >> LABEL_SHIFT & LABEL_MASK)); } @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", 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 acfe3d7d51..4f4443ee04 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 @@ -18,6 +18,7 @@ import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; import org.opendaylight.protocol.pcep.spi.TlvParser; import org.opendaylight.protocol.pcep.spi.TlvSerializer; import org.opendaylight.protocol.pcep.spi.TlvUtil; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.protocol.util.Ipv4Util; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.identifiers.tlv.LspIdentifiers; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.identifiers.tlv.LspIdentifiersBuilder; @@ -31,6 +32,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.Ipv4ExtendedTunnelId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.TunnelId; +import org.opendaylight.yangtools.yang.common.Uint32; /** * Parser for {@link LspIdentifiers}. @@ -50,8 +52,8 @@ public final class Stateful07LSPIdentifierIpv4TlvParser implements TlvParser, Tl buffer.readableBytes()); final Ipv4Builder builder = new Ipv4Builder(); builder.setIpv4TunnelSenderAddress(Ipv4Util.noZoneAddressForByteBuf(buffer)); - final LspId lspId = new LspId((long) buffer.readUnsignedShort()); - final TunnelId tunnelId = new TunnelId(buffer.readUnsignedShort()); + final LspId lspId = new LspId(Uint32.valueOf(buffer.readUnsignedShort())); + final TunnelId tunnelId = new TunnelId(ByteBufUtils.readUint16(buffer)); builder.setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(Ipv4Util.noZoneAddressForByteBuf(buffer))); builder.setIpv4TunnelEndpointAddress(Ipv4Util.noZoneAddressForByteBuf(buffer)); final AddressFamily afi = new Ipv4CaseBuilder().setIpv4(builder.build()).build(); 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 64346aef77..3a44c328ab 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 @@ -18,6 +18,7 @@ import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; import org.opendaylight.protocol.pcep.spi.TlvParser; import org.opendaylight.protocol.pcep.spi.TlvSerializer; import org.opendaylight.protocol.pcep.spi.TlvUtil; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.protocol.util.Ipv6Util; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.identifiers.tlv.LspIdentifiers; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.identifiers.tlv.LspIdentifiersBuilder; @@ -30,6 +31,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.Ipv6ExtendedTunnelId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.TunnelId; +import org.opendaylight.yangtools.yang.common.Uint32; /** * Parser for {@link LspIdentifiers}. @@ -49,8 +51,8 @@ public final class Stateful07LSPIdentifierIpv6TlvParser implements TlvParser, Tl buffer.readableBytes()); final Ipv6Builder builder = new Ipv6Builder(); builder.setIpv6TunnelSenderAddress(Ipv6Util.noZoneAddressForByteBuf(buffer)); - final LspId lspId = new LspId((long) buffer.readUnsignedShort()); - final TunnelId tunnelId = new TunnelId(buffer.readUnsignedShort()); + final LspId lspId = new LspId(Uint32.valueOf(buffer.readUnsignedShort())); + final TunnelId tunnelId = new TunnelId(ByteBufUtils.readUint16(buffer)); builder.setIpv6ExtendedTunnelId(new Ipv6ExtendedTunnelId(Ipv6Util.noZoneAddressForByteBuf(buffer))); builder.setIpv6TunnelEndpointAddress(Ipv6Util.noZoneAddressForByteBuf(buffer)); final AddressFamily afi = new Ipv6CaseBuilder().setIpv6(builder.build()).build(); diff --git a/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LspObjectParser.java b/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LspObjectParser.java index 45d333906c..9e9447d8ae 100644 --- a/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LspObjectParser.java +++ b/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LspObjectParser.java @@ -36,6 +36,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.tlvs.VendorInformationTlv; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vs.tlv.VsTlv; +import org.opendaylight.yangtools.yang.common.Uint32; /** * Parser for {@link Lsp}. @@ -70,7 +71,7 @@ public class Stateful07LspObjectParser extends AbstractObjectWithTlvsParser> FOUR_BITS_SHIFT))); parseFlags(builder, bytes); final TlvsBuilder b = new TlvsBuilder(); diff --git a/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LspUpdateErrorTlvParser.java b/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LspUpdateErrorTlvParser.java index ee7ee20f00..f1b686cc6c 100644 --- a/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LspUpdateErrorTlvParser.java +++ b/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LspUpdateErrorTlvParser.java @@ -16,6 +16,7 @@ import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; import org.opendaylight.protocol.pcep.spi.TlvParser; import org.opendaylight.protocol.pcep.spi.TlvSerializer; import org.opendaylight.protocol.pcep.spi.TlvUtil; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.error.code.tlv.LspErrorCode; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.error.code.tlv.LspErrorCodeBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv; @@ -34,7 +35,7 @@ public final class Stateful07LspUpdateErrorTlvParser implements TlvParser, TlvSe if (buffer == null) { return null; } - return new LspErrorCodeBuilder().setErrorCode(buffer.readUnsignedInt()).build(); + return new LspErrorCodeBuilder().setErrorCode(ByteBufUtils.readUint32(buffer)).build(); } @Override 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 f870009506..65a4499a52 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 @@ -23,6 +23,7 @@ import org.opendaylight.protocol.pcep.spi.TlvSerializer; import org.opendaylight.protocol.pcep.spi.TlvUtil; import org.opendaylight.protocol.util.BitArray; import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.util.ByteBufUtils; 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.IpAddressNoZone; @@ -97,10 +98,10 @@ public final class Stateful07RSVPErrorSpecTlvParser implements TlvParser, TlvSer private static UserCase parseUserError(final ByteBuf buffer) { final UserErrorBuilder error = new UserErrorBuilder(); - error.setEnterprise(new EnterpriseNumber(buffer.readUnsignedInt())); - error.setSubOrg(buffer.readUnsignedByte()); + error.setEnterprise(new EnterpriseNumber(ByteBufUtils.readUint32(buffer))); + error.setSubOrg(ByteBufUtils.readUint8(buffer)); final int errDescrLength = buffer.readUnsignedByte(); - error.setValue(buffer.readUnsignedShort()); + error.setValue(ByteBufUtils.readUint16(buffer)); error.setDescription(ByteArray.bytesToHRString(ByteArray.readBytes(buffer, errDescrLength))); // if we have any subobjects, place the implementation here return new UserCaseBuilder().setUserError(error.build()).build(); @@ -130,10 +131,8 @@ public final class Stateful07RSVPErrorSpecTlvParser implements TlvParser, TlvSer } final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE); builder.setFlags(new Flags(flags.get(IN_PLACE), flags.get(NOT_GUILTY))); - final short errorCode = buffer.readUnsignedByte(); - builder.setCode(errorCode); - final int errorValue = buffer.readUnsignedShort(); - builder.setValue(errorValue); + builder.setCode(ByteBufUtils.readUint8(buffer)); + builder.setValue(ByteBufUtils.readUint16(buffer)); return new RsvpCaseBuilder().setRsvpError(builder.build()).build(); } diff --git a/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07SrpObjectParser.java b/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07SrpObjectParser.java index 051588dc89..53d61a903c 100644 --- a/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07SrpObjectParser.java +++ b/pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07SrpObjectParser.java @@ -18,6 +18,7 @@ import org.opendaylight.protocol.pcep.spi.ObjectUtil; import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; import org.opendaylight.protocol.pcep.spi.TlvRegistry; import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.SrpIdNumber; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.srp.object.Srp; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.srp.object.SrpBuilder; @@ -55,15 +56,14 @@ public class Stateful07SrpObjectParser extends AbstractObjectWithTlvsParser=" + MIN_SIZE + "."); } - final SrpBuilder builder = new SrpBuilder(); - builder.setIgnore(header.isIgnore()); - builder.setProcessingRule(header.isProcessingRule()); + final SrpBuilder builder = new SrpBuilder() + .setIgnore(header.isIgnore()) + .setProcessingRule(header.isProcessingRule()); parseFlags(builder, bytes); - builder.setOperationId(new SrpIdNumber(bytes.readUnsignedInt())); + builder.setOperationId(new SrpIdNumber(ByteBufUtils.readUint32(bytes))); final TlvsBuilder tlvsBuilder = new TlvsBuilder(); parseTlvs(tlvsBuilder, bytes.slice()); - builder.setTlvs(tlvsBuilder.build()); - return builder.build(); + return builder.setTlvs(tlvsBuilder.build()).build(); } protected void parseFlags(final SrpBuilder builder, final ByteBuf bytes) { diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/BasePCEPSessionProposalFactory.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/BasePCEPSessionProposalFactory.java index 4db785d224..88a47f50ed 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/BasePCEPSessionProposalFactory.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/BasePCEPSessionProposalFactory.java @@ -18,6 +18,7 @@ import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.Open; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.OpenBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.open.TlvsBuilder; +import org.opendaylight.yangtools.yang.common.Uint8; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,7 +34,7 @@ public final class BasePCEPSessionProposalFactory implements PCEPSessionProposal final List capabilities) { if (keepAlive != 0) { Preconditions.checkArgument(keepAlive >= 1, "Minimum value for keep-alive-timer-value is 1"); - if (deadTimer != 0 && (deadTimer / keepAlive != KA_TO_DEADTIMER_RATIO)) { + if (deadTimer != 0 && deadTimer / keepAlive != KA_TO_DEADTIMER_RATIO) { LOG.warn("dead-timer-value should be {} times greater than keep-alive-timer-value", KA_TO_DEADTIMER_RATIO); } @@ -57,7 +58,7 @@ public final class BasePCEPSessionProposalFactory implements PCEPSessionProposal oBuilder.setSessionId((short) sessionId); oBuilder.setKeepalive((short) BasePCEPSessionProposalFactory.this.keepAlive); if (BasePCEPSessionProposalFactory.this.keepAlive == 0) { - oBuilder.setDeadTimer((short) 0); + oBuilder.setDeadTimer(Uint8.ZERO); } else { oBuilder.setDeadTimer((short) BasePCEPSessionProposalFactory.this.deadTimer); } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImpl.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImpl.java index d89095cfee..618608b541 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImpl.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImpl.java @@ -82,7 +82,7 @@ public class PCEPDispatcherImpl implements PCEPDispatcher, Closeable { public final synchronized ChannelFuture createServer(final PCEPDispatcherDependencies dispatcherDependencies) { this.keys = dispatcherDependencies.getKeys(); - @SuppressWarnings("unchecked") final ChannelPipelineInitializer initializer = (ch, promise) -> { + final ChannelPipelineInitializer initializer = (ch, promise) -> { ch.pipeline().addLast(this.hf.getDecoders()); ch.pipeline().addLast("negotiator", this.snf .getSessionNegotiator(dispatcherDependencies, ch, promise)); diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/LabelSubobjectParserTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/LabelSubobjectParserTest.java index 593a5b5850..34f1c67c93 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/LabelSubobjectParserTest.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/LabelSubobjectParserTest.java @@ -85,13 +85,13 @@ public class LabelSubobjectParserTest { parser.parseLabel(null); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } try { parser.parseLabel(Unpooled.EMPTY_BUFFER); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } } @@ -111,13 +111,13 @@ public class LabelSubobjectParserTest { parser.parseLabel(null); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } try { parser.parseLabel(Unpooled.EMPTY_BUFFER); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } } } diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPEROSubobjectParserTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPEROSubobjectParserTest.java index 441e939e9b..f97a13ec8e 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPEROSubobjectParserTest.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPEROSubobjectParserTest.java @@ -169,13 +169,13 @@ public class PCEPEROSubobjectParserTest { parser.parseSubobject(null, true); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } try { parser.parseSubobject(Unpooled.EMPTY_BUFFER, true); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } } @@ -196,13 +196,13 @@ public class PCEPEROSubobjectParserTest { parser.parseSubobject(null, true); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } try { parser.parseSubobject(Unpooled.EMPTY_BUFFER, true); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } } diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java index 27e6f5100c..ae0c01bb43 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java @@ -207,13 +207,13 @@ public class PCEPObjectParserTest { parser.parseObject(new ObjectHeaderImpl(true, true), null); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } try { parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } } @@ -239,13 +239,13 @@ public class PCEPObjectParserTest { parser.parseObject(new ObjectHeaderImpl(true, true), null); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } try { parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } } @@ -780,13 +780,13 @@ public class PCEPObjectParserTest { parser.parseObject(new ObjectHeaderImpl(true, true), null); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } try { parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } } @@ -827,13 +827,13 @@ public class PCEPObjectParserTest { parser.parseObject(new ObjectHeaderImpl(true, true), null); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } try { parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } } @@ -879,13 +879,13 @@ public class PCEPObjectParserTest { parser.parseObject(new ObjectHeaderImpl(true, true), null); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } try { parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } } @@ -989,13 +989,13 @@ public class PCEPObjectParserTest { parser.parseObject(new ObjectHeaderImpl(true, true), null); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } try { parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } } @@ -1081,13 +1081,13 @@ public class PCEPObjectParserTest { parser.parseObject(new ObjectHeaderImpl(true, true), null); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } try { parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } } @@ -1228,13 +1228,13 @@ public class PCEPObjectParserTest { parser.parseObject(new ObjectHeaderImpl(true, true), null); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } try { parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } } diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPRROSubobjectParserTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPRROSubobjectParserTest.java index 94d2b3b670..3f15b34bc5 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPRROSubobjectParserTest.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPRROSubobjectParserTest.java @@ -143,13 +143,13 @@ public class PCEPRROSubobjectParserTest { parser.parseSubobject(null); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } try { parser.parseSubobject(Unpooled.EMPTY_BUFFER); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } } @@ -171,13 +171,13 @@ public class PCEPRROSubobjectParserTest { parser.parseSubobject(null); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } try { parser.parseSubobject(Unpooled.EMPTY_BUFFER); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } } @@ -202,13 +202,13 @@ public class PCEPRROSubobjectParserTest { parser.parseSubobject(null); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } try { parser.parseSubobject(Unpooled.EMPTY_BUFFER); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } } diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPXROSubobjectParserTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPXROSubobjectParserTest.java index 5c8aa82fcf..f11ccd1904 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPXROSubobjectParserTest.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPXROSubobjectParserTest.java @@ -88,13 +88,13 @@ public class PCEPXROSubobjectParserTest { parser.parseSubobject(null, true); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } try { parser.parseSubobject(Unpooled.EMPTY_BUFFER, true); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } } @@ -151,13 +151,13 @@ public class PCEPXROSubobjectParserTest { parser.parseSubobject(null, true); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } try { parser.parseSubobject(Unpooled.EMPTY_BUFFER, true); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } } @@ -179,13 +179,13 @@ public class PCEPXROSubobjectParserTest { parser.parseSubobject(null, true); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } try { parser.parseSubobject(Unpooled.EMPTY_BUFFER, true); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } } @@ -207,13 +207,13 @@ public class PCEPXROSubobjectParserTest { parser.parseSubobject(null, true); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } try { parser.parseSubobject(Unpooled.EMPTY_BUFFER, true); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } } @@ -236,13 +236,13 @@ public class PCEPXROSubobjectParserTest { parser.parseSubobject(null, true); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } try { parser.parseSubobject(Unpooled.EMPTY_BUFFER, true); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } } @@ -268,13 +268,13 @@ public class PCEPXROSubobjectParserTest { parser.parseSubobject(null, true); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } try { parser.parseSubobject(Unpooled.EMPTY_BUFFER, true); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } } } diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/TestVendorInformationObjectParser.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/TestVendorInformationObjectParser.java index 346b2783d3..68430d1178 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/TestVendorInformationObjectParser.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/TestVendorInformationObjectParser.java @@ -9,15 +9,15 @@ package org.opendaylight.protocol.pcep.impl; import io.netty.buffer.ByteBuf; - import org.opendaylight.protocol.pcep.impl.TestVendorInformationTlvParser.TestEnterpriseSpecificInformation; import org.opendaylight.protocol.pcep.parser.object.AbstractVendorInformationObjectParser; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.EnterpriseSpecificInformation; +import org.opendaylight.yangtools.yang.common.Uint32; public class TestVendorInformationObjectParser extends AbstractVendorInformationObjectParser { - private static final EnterpriseNumber TEST_ENTERPRISE_NUMBER = new EnterpriseNumber(0L); + private static final EnterpriseNumber TEST_ENTERPRISE_NUMBER = new EnterpriseNumber(Uint32.ZERO); public TestVendorInformationObjectParser() { super(0, 0); diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/TestVendorInformationTlvParser.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/TestVendorInformationTlvParser.java index cd88de3e2d..7243542b28 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/TestVendorInformationTlvParser.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/TestVendorInformationTlvParser.java @@ -12,10 +12,11 @@ import io.netty.buffer.ByteBuf; import org.opendaylight.protocol.pcep.parser.tlv.AbstractVendorInformationTlvParser; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.EnterpriseSpecificInformation; +import org.opendaylight.yangtools.yang.common.Uint32; public class TestVendorInformationTlvParser extends AbstractVendorInformationTlvParser { - private static final EnterpriseNumber TEST_ENTERPRISE_NUMBER = new EnterpriseNumber(0L); + private static final EnterpriseNumber TEST_ENTERPRISE_NUMBER = new EnterpriseNumber(Uint32.ZERO); @Override public void serializeEnterpriseSpecificInformation( diff --git a/pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/PCCTunnelBuilder.java b/pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/PCCTunnelBuilder.java index b601aa33fb..976fe25be6 100644 --- a/pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/PCCTunnelBuilder.java +++ b/pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/PCCTunnelBuilder.java @@ -39,7 +39,7 @@ final class PCCTunnelBuilder { for (int i = 1; i <= lsps; i++) { final PCCTunnel tunnel = new PCCTunnel(MsgBuilderUtil.getDefaultPathName(address, Uint32.valueOf(i)), PCC_DELEGATION, LspType.PCC_LSP, createPath(Lists.newArrayList(DEFAULT_ENDPOINT_HOP))); - tunnels.put(new PlspId((long) i), tunnel); + tunnels.put(new PlspId(Uint32.valueOf(i)), tunnel); } return tunnels; } diff --git a/pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/PCCTunnelManagerImpl.java b/pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/PCCTunnelManagerImpl.java index bf2445e02f..4cffba7181 100644 --- a/pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/PCCTunnelManagerImpl.java +++ b/pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/PCCTunnelManagerImpl.java @@ -194,7 +194,7 @@ public final class PCCTunnelManagerImpl implements PCCTunnelManager { } protected void addTunnel(final Requests request, final PCCSession session) { - final PlspId plspId = new PlspId(this.plspIDsCounter.incrementAndGet()); + final PlspId plspId = new PlspId(Uint32.valueOf(this.plspIDsCounter.incrementAndGet())); final PCCTunnel tunnel = new PCCTunnel(request.getLsp().getTlvs().getSymbolicPathName() .getPathName().getValue(), session.getId(), LspType.PCE_LSP, reqToRptPath(request)); sendToAll(tunnel, plspId, request.getEro().getSubobject(), diff --git a/pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/spi/MsgBuilderUtil.java b/pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/spi/MsgBuilderUtil.java index 6ea2217c92..320338b157 100644 --- a/pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/spi/MsgBuilderUtil.java +++ b/pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/spi/MsgBuilderUtil.java @@ -53,6 +53,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.Ipv4ExtendedTunnelId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.TunnelId; +import org.opendaylight.yangtools.yang.common.Uint16; import org.opendaylight.yangtools.yang.common.Uint32; import org.opendaylight.yangtools.yang.common.Uint64; @@ -143,7 +144,7 @@ public final class MsgBuilderUtil { .setIpv4TunnelSenderAddress(new Ipv4AddressNoZone(tunnelSender)) .setIpv4ExtendedTunnelId( new Ipv4ExtendedTunnelId(extendedTunnelAddress)) - .build()).build()).setTunnelId(new TunnelId(lspId.intValue())).build()); + .build()).build()).setTunnelId(new TunnelId(Uint16.valueOf(lspId))).build()); if (symbolicPathName) { if (symbolicName.isPresent()) { tlvs.setSymbolicPathName(new SymbolicPathNameBuilder().setPathName( 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 9f08843317..cc60ea9d4a 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 @@ -17,6 +17,7 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; import org.opendaylight.protocol.util.BitArray; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.protocol.util.ByteBufWriteUtil; import org.opendaylight.protocol.util.Ipv4Util; import org.opendaylight.protocol.util.Ipv6Util; @@ -170,9 +171,11 @@ public abstract class AbstractSrSubobjectParser { .setLocalIpAddress(new IpAddressNoZone(Ipv6Util.noZoneAddressForByteBuf(buffer))) .setRemoteIpAddress(new IpAddressNoZone(Ipv6Util.noZoneAddressForByteBuf(buffer))).build(); case Unnumbered: - return new UnnumberedAdjacencyBuilder().setLocalNodeId(buffer.readUnsignedInt()) - .setLocalInterfaceId(buffer.readUnsignedInt()).setRemoteNodeId(buffer.readUnsignedInt()) - .setRemoteInterfaceId(buffer.readUnsignedInt()).build(); + return new UnnumberedAdjacencyBuilder() + .setLocalNodeId(ByteBufUtils.readUint32(buffer)) + .setLocalInterfaceId(ByteBufUtils.readUint32(buffer)) + .setRemoteNodeId(ByteBufUtils.readUint32(buffer)) + .setRemoteInterfaceId(ByteBufUtils.readUint32(buffer)).build(); default: return null; } diff --git a/pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/segment/routing/PCEPSegmentRoutingCapability.java b/pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/segment/routing/PCEPSegmentRoutingCapability.java index 4c8b99e39a..f7ec904bee 100644 --- a/pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/segment/routing/PCEPSegmentRoutingCapability.java +++ b/pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/segment/routing/PCEPSegmentRoutingCapability.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.pcep.segment.routing; import java.net.InetSocketAddress; @@ -14,6 +13,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.seg import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev181109.Tlvs1Builder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev181109.sr.pce.capability.tlv.SrPceCapabilityBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.open.TlvsBuilder; +import org.opendaylight.yangtools.yang.common.Uint8; public class PCEPSegmentRoutingCapability implements PCEPCapability { @@ -27,7 +27,7 @@ public class PCEPSegmentRoutingCapability implements PCEPCapability { public void setCapabilityProposal(final InetSocketAddress address, final TlvsBuilder builder) { if (this.isSegmentRoutingCapable) { builder.addAugmentation(Tlvs1.class, - new Tlvs1Builder().setSrPceCapability(new SrPceCapabilityBuilder().setMsd((short) 0).build()) + new Tlvs1Builder().setSrPceCapability(new SrPceCapabilityBuilder().setMsd(Uint8.ZERO).build()) .build()); } } diff --git a/pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/segment/routing/SrPceCapabilityTlvParser.java b/pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/segment/routing/SrPceCapabilityTlvParser.java index 02e7b19413..e7b52fa9e9 100644 --- a/pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/segment/routing/SrPceCapabilityTlvParser.java +++ b/pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/segment/routing/SrPceCapabilityTlvParser.java @@ -7,15 +7,16 @@ */ package org.opendaylight.protocol.pcep.segment.routing; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte; -import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; import org.opendaylight.protocol.pcep.spi.TlvParser; import org.opendaylight.protocol.pcep.spi.TlvSerializer; import org.opendaylight.protocol.pcep.spi.TlvUtil; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev181109.sr.pce.capability.tlv.SrPceCapability; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev181109.sr.pce.capability.tlv.SrPceCapabilityBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv; @@ -30,7 +31,7 @@ public class SrPceCapabilityTlvParser implements TlvParser, TlvSerializer { @Override public void serializeTlv(final Tlv tlv, final ByteBuf buffer) { - Preconditions.checkArgument(tlv instanceof SrPceCapability, "SrPceCapability is mandatory."); + checkArgument(tlv instanceof SrPceCapability, "SrPceCapability is mandatory."); final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH); body.writerIndex(OFFSET); writeUnsignedByte(((SrPceCapability) tlv).getMsd(), body); @@ -42,7 +43,8 @@ public class SrPceCapabilityTlvParser implements TlvParser, TlvSerializer { if (buffer == null) { return null; } - final short msd = buffer.readerIndex(OFFSET).readUnsignedByte(); - return new SrPceCapabilityBuilder().setMsd(msd).build(); + return new SrPceCapabilityBuilder() + .setMsd(ByteBufUtils.readUint8(buffer.readerIndex(OFFSET))) + .build(); } } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractEROPathKeySubobjectParser.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractEROPathKeySubobjectParser.java index 5bfc1ef9f3..ceb164f1e1 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractEROPathKeySubobjectParser.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractEROPathKeySubobjectParser.java @@ -12,6 +12,7 @@ import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; +import org.opendaylight.protocol.util.ByteBufUtils; 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.PathKey; @@ -19,6 +20,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKeyBuilder; +import org.opendaylight.yangtools.yang.common.Uint16; /** * Parser for {@link PathKey}. @@ -41,7 +43,7 @@ public abstract class AbstractEROPathKeySubobjectParser implements EROSubobjectP checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); checkContentLength(buffer.readableBytes()); - final int pathKey = buffer.readUnsignedShort(); + final Uint16 pathKey = ByteBufUtils.readUint16(buffer); final byte[] pceId = readPceId(buffer); final PathKeyBuilder pBuilder = new PathKeyBuilder(); pBuilder.setPceId(new PceId(pceId)); diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractMessageParser.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractMessageParser.java index 7b61ee8f4a..640a26a2be 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractMessageParser.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractMessageParser.java @@ -18,6 +18,7 @@ import java.util.Optional; import org.eclipse.jdt.annotation.Nullable; import org.opendaylight.protocol.util.BitArray; import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.PcerrBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Message; @@ -89,7 +90,7 @@ public abstract class AbstractMessageParser implements MessageParser, MessageSer final ObjectHeader header = new ObjectHeaderImpl(flags.get(PROCESSED), flags.get(IGNORED)); if (VendorInformationUtil.isVendorInformationObject(objClass, objType)) { - final EnterpriseNumber enterpriseNumber = new EnterpriseNumber(bytesToPass.readUnsignedInt()); + final EnterpriseNumber enterpriseNumber = new EnterpriseNumber(ByteBufUtils.readUint32(bytesToPass)); final Optional obj = this.registry.parseVendorInformationObject(enterpriseNumber, header, bytesToPass); if (obj.isPresent()) { diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractObjectWithTlvsParser.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractObjectWithTlvsParser.java index 8fd30c66f4..54414d26f8 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractObjectWithTlvsParser.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractObjectWithTlvsParser.java @@ -15,6 +15,7 @@ import io.netty.buffer.ByteBufUtil; import java.util.ArrayList; import java.util.List; import java.util.Optional; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.tlvs.VendorInformationTlv; @@ -54,7 +55,7 @@ public abstract class AbstractObjectWithTlvsParser extends CommonObjectParser LOG.trace("Parsing PCEP TLV : {}", ByteBufUtil.hexDump(tlvBytes)); if (VendorInformationUtil.isVendorInformationTlv(type)) { - final EnterpriseNumber enterpriseNumber = new EnterpriseNumber(tlvBytes.readUnsignedInt()); + final EnterpriseNumber enterpriseNumber = new EnterpriseNumber(ByteBufUtils.readUint32(tlvBytes)); final Optional viTlv = this.viTlvReg.parseVendorInformationTlv(enterpriseNumber, tlvBytes); if (viTlv.isPresent()) { diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPErrorIdentifier.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPErrorIdentifier.java index 0871128d23..56f67e66a9 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPErrorIdentifier.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPErrorIdentifier.java @@ -14,6 +14,8 @@ import java.io.Serializable; */ final class PCEPErrorIdentifier implements Serializable { private static final long serialVersionUID = 2434590156751699872L; + + // FIXME: these should be Uint8s private final short type; private final short value; diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPErrors.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPErrors.java index 48b8548de7..ee521bb738 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPErrors.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPErrors.java @@ -365,6 +365,7 @@ public enum PCEPErrors { return this.errorId; } + // FIXME: these should be Uint8s public short getErrorType() { return this.errorId.getType(); } diff --git a/pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/AbstractTopologySessionListener.java b/pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/AbstractTopologySessionListener.java index 71cfb6e76c..ccdab8a7fd 100755 --- a/pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/AbstractTopologySessionListener.java +++ b/pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/AbstractTopologySessionListener.java @@ -69,6 +69,7 @@ import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; +import org.opendaylight.yangtools.yang.common.Uint8; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -82,7 +83,7 @@ import org.slf4j.LoggerFactory; */ public abstract class AbstractTopologySessionListener implements TopologySessionListener, TopologySessionStats { static final MessageHeader MESSAGE_HEADER = new MessageHeader() { - private final ProtocolVersion version = new ProtocolVersion((short) 1); + private final ProtocolVersion version = new ProtocolVersion(Uint8.ONE); @Override public Class implementedInterface() { diff --git a/pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/Stateful07TopologySessionListener.java b/pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/Stateful07TopologySessionListener.java index ad28c5b8a0..c092700b07 100644 --- a/pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/Stateful07TopologySessionListener.java +++ b/pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/Stateful07TopologySessionListener.java @@ -92,11 +92,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev181109.pcep.client.attributes.path.computation.client.reported.lsp.Path; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.common.Uint32; import org.slf4j.Logger; import org.slf4j.LoggerFactory; class Stateful07TopologySessionListener extends AbstractTopologySessionListener { private static final Logger LOG = LoggerFactory.getLogger(Stateful07TopologySessionListener.class); + private static final PlspId PLSPID_ZERO = new PlspId(Uint32.ZERO); private final AtomicLong requestId = new AtomicLong(1L); @@ -202,7 +204,7 @@ class Stateful07TopologySessionListener extends AbstractTopologySessionListener< private SrpIdNumber createUpdateMessageSync(final PcupdMessageBuilder pcupdMessageBuilder) { final UpdatesBuilder updBuilder = new UpdatesBuilder(); // LSP mandatory in Upd - final Lsp lsp = new LspBuilder().setPlspId(new PlspId(0L)).setSync(Boolean.TRUE).build(); + final Lsp lsp = new LspBuilder().setPlspId(PLSPID_ZERO).setSync(Boolean.TRUE).build(); // SRP Mandatory in Upd final SrpBuilder srpBuilder = new SrpBuilder(); // not sue whether use 0 instead of nextRequest() or do not insert srp == SRP-ID-number = 0 @@ -333,7 +335,7 @@ class Stateful07TopologySessionListener extends AbstractTopologySessionListener< return true; } - private Path buildPath(final Reports report, final Srp srp, final Lsp lsp) { + private static Path buildPath(final Reports report, final Srp srp, final Lsp lsp) { final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev181109.pcep.client .attributes.path.computation.client.reported.lsp.PathBuilder pb = new org.opendaylight.yang.gen.v1 .urn.opendaylight.params.xml.ns.yang.topology.pcep.rev181109.pcep.client.attributes.path.computation @@ -386,7 +388,7 @@ class Stateful07TopologySessionListener extends AbstractTopologySessionListener< } private SrpIdNumber nextRequest() { - return new SrpIdNumber(this.requestId.getAndIncrement()); + return new SrpIdNumber(Uint32.valueOf(this.requestId.getAndIncrement())); } @Override @@ -734,9 +736,9 @@ class Stateful07TopologySessionListener extends AbstractTopologySessionListener< new SymbolicPathNameBuilder().setPathName(new SymbolicPathName(this.input.getName() .getBytes(StandardCharsets.UTF_8))).build()); - final SrpBuilder srpBuilder = new SrpBuilder(); - srpBuilder.setOperationId(nextRequest()); - srpBuilder.setProcessingRule(Boolean.TRUE); + final SrpBuilder srpBuilder = new SrpBuilder() + .setOperationId(nextRequest()) + .setProcessingRule(Boolean.TRUE); if (!PSTUtil.isDefaultPST(args.getPathSetupType())) { srpBuilder.setTlvs( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf @@ -745,15 +747,20 @@ class Stateful07TopologySessionListener extends AbstractTopologySessionListener< } rb.setSrp(srpBuilder.build()); - rb.setLsp(new LspBuilder().setAdministrative(inputLsp.isAdministrative()).setDelegate( - inputLsp.isDelegate()).setPlspId(new PlspId(0L)).setTlvs(tlvsBuilder.build()).build()); - - final PcinitiateMessageBuilder ib = new PcinitiateMessageBuilder(MESSAGE_HEADER); - ib.setRequests(Collections.singletonList(rb.build())); + rb.setLsp(new LspBuilder() + .setAdministrative(inputLsp.isAdministrative()) + .setDelegate(inputLsp.isDelegate()) + .setPlspId(PLSPID_ZERO) + .setTlvs(tlvsBuilder.build()) + .build()); // Send the message - return sendMessage(new PcinitiateBuilder().setPcinitiateMessage(ib.build()).build(), - rb.getSrp().getOperationId(), this.input.getArguments().getMetadata()); + return sendMessage(new PcinitiateBuilder() + .setPcinitiateMessage(new PcinitiateMessageBuilder(MESSAGE_HEADER) + .setRequests(Collections.singletonList(rb.build())) + .build()) + .build(), + rb.getSrp().getOperationId(), this.input.getArguments().getMetadata()); } } diff --git a/programming/api/src/main/java/org/opendaylight/bgpcep/programming/NanotimeUtil.java b/programming/api/src/main/java/org/opendaylight/bgpcep/programming/NanotimeUtil.java index b295c41caa..b2f500beed 100644 --- a/programming/api/src/main/java/org/opendaylight/bgpcep/programming/NanotimeUtil.java +++ b/programming/api/src/main/java/org/opendaylight/bgpcep/programming/NanotimeUtil.java @@ -7,8 +7,9 @@ */ package org.opendaylight.bgpcep.programming; -import java.math.BigInteger; +import java.util.concurrent.TimeUnit; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.Nanotime; +import org.opendaylight.yangtools.yang.common.Uint64; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -17,8 +18,8 @@ import org.slf4j.LoggerFactory; */ public final class NanotimeUtil { private static final Logger LOG = LoggerFactory.getLogger(NanotimeUtil.class); - private static final BigInteger MILLION = BigInteger.valueOf(1000000); - private static volatile BigInteger nanoTimeOffset = null; + + private static volatile Long nanoTimeOffset = null; private NanotimeUtil() { throw new UnsupportedOperationException(); @@ -30,7 +31,8 @@ public final class NanotimeUtil { * @return Nanotime object filled with current time in nanoseconds. */ public static Nanotime currentTime() { - return new Nanotime(BigInteger.valueOf(System.currentTimeMillis()).multiply(MILLION)); + final long millis = Uint64.valueOf(System.currentTimeMillis()).longValue(); + return new Nanotime(Uint64.fromLongBits(TimeUnit.MILLISECONDS.toNanos(millis))); } /** @@ -42,7 +44,7 @@ public final class NanotimeUtil { if (nanoTimeOffset == null) { calibrate(); } - return new Nanotime(BigInteger.valueOf(System.nanoTime()).add(nanoTimeOffset)); + return new Nanotime(Uint64.fromLongBits(System.nanoTime() + nanoTimeOffset.longValue())); } /** @@ -58,9 +60,9 @@ public final class NanotimeUtil { LOG.debug("Calibrated currentTime and nanoTime to {}m <= {}n <= {}m <= {}n", tm1, nt1, tm2, nt2); - final BigInteger tm = BigInteger.valueOf(tm1).add(BigInteger.valueOf(tm2)).divide(BigInteger.valueOf(2)); - final BigInteger nt = BigInteger.valueOf(nt1).add(BigInteger.valueOf(nt2)).divide(BigInteger.valueOf(2)); + final long tm = (tm1 + tm2) / 2; + final long nt = (nt1 + nt2) / 2; - nanoTimeOffset = tm.multiply(MILLION).subtract(nt); + nanoTimeOffset = Long.valueOf(TimeUnit.MILLISECONDS.toNanos(tm) - nt); } } diff --git a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/AsNumberCaseParser.java b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/AsNumberCaseParser.java index 66a7be7b1f..829710dfc9 100644 --- a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/AsNumberCaseParser.java +++ b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/AsNumberCaseParser.java @@ -5,12 +5,11 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.protocol.rsvp.parser.impl.subobject; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeShort; -import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException; @@ -19,6 +18,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.as.number._case.AsNumberBuilder; +import org.opendaylight.yangtools.yang.common.Uint32; public final class AsNumberCaseParser { private static final int CONTENT_LENGTH = 2; @@ -28,21 +28,23 @@ public final class AsNumberCaseParser { } public static AsNumberCase 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. Cannot be null or empty."); if (buffer.readableBytes() != CONTENT_LENGTH) { throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; " + "Expected: " + CONTENT_LENGTH + "."); } - return new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber((long) buffer - .readUnsignedShort())).build()).build(); + return new AsNumberCaseBuilder() + .setAsNumber(new AsNumberBuilder() + .setAsNumber(new AsNumber(Uint32.valueOf(buffer.readUnsignedShort()))) + .build()) + .build(); } public static ByteBuf serializeSubobject(final AsNumberCase asCase) { final AsNumberSubobject asNumber = asCase.getAsNumber(); final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH); - Preconditions.checkArgument(asNumber.getAsNumber() != null, "AsNumber is mandatory."); + checkArgument(asNumber.getAsNumber() != null, "AsNumber is mandatory."); writeShort(asNumber.getAsNumber().getValue().shortValue(), body); return body; } diff --git a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/label/Type1LabelParser.java b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/label/Type1LabelParser.java index 32e147d942..b62c3408d7 100644 --- a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/label/Type1LabelParser.java +++ b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/label/Type1LabelParser.java @@ -8,6 +8,7 @@ package org.opendaylight.protocol.rsvp.parser.impl.subobject.label; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt; import com.google.common.base.Preconditions; @@ -16,6 +17,7 @@ import io.netty.buffer.Unpooled; import org.opendaylight.protocol.rsvp.parser.spi.LabelParser; import org.opendaylight.protocol.rsvp.parser.spi.LabelSerializer; import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.LabelType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.Type1LabelCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.Type1LabelCaseBuilder; @@ -33,21 +35,21 @@ public class Type1LabelParser implements LabelParser, LabelSerializer { @Override public LabelType parseLabel(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. Cannot be null or empty."); if (buffer.readableBytes() != LABEL_LENGTH) { throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; " + "Expected: " + LABEL_LENGTH + "."); } - return new Type1LabelCaseBuilder().setType1Label(new Type1LabelBuilder().setType1Label( - buffer.readUnsignedInt()).build()).build(); + return new Type1LabelCaseBuilder() + .setType1Label(new Type1LabelBuilder().setType1Label(ByteBufUtils.readUint32(buffer)).build()) + .build(); } @Override public void serializeLabel(final boolean unidirectional, final boolean global, final LabelType subobject, final ByteBuf buffer) { - Preconditions.checkArgument(subobject instanceof Type1LabelCase, - "Unknown Label Subobject instance. Passed {}. Needed Type1LabelCase.", subobject.getClass()); + checkArgument(subobject instanceof Type1LabelCase, + "Unknown Label Subobject instance. Passed %s. Needed Type1LabelCase.", subobject.getClass()); final ByteBuf body = Unpooled.buffer(LABEL_LENGTH); final Type1Label type1Label = ((Type1LabelCase) subobject).getType1Label(); Preconditions.checkArgument(type1Label != null, "Type1Label is mandatory."); diff --git a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/label/WavebandSwitchingLabelParser.java b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/label/WavebandSwitchingLabelParser.java index 133844007a..48b348088b 100644 --- a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/label/WavebandSwitchingLabelParser.java +++ b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/label/WavebandSwitchingLabelParser.java @@ -5,17 +5,17 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.protocol.rsvp.parser.impl.subobject.label; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt; -import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.rsvp.parser.spi.LabelParser; import org.opendaylight.protocol.rsvp.parser.spi.LabelSerializer; import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.LabelType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.WavebandSwitchingLabelCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.WavebandSwitchingLabelCaseBuilder; @@ -37,32 +37,33 @@ public class WavebandSwitchingLabelParser implements LabelParser, LabelSerialize @Override public final LabelType parseLabel(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. Cannot be null or empty."); if (buffer.readableBytes() != CONTENT_LENGTH) { throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: " + CONTENT_LENGTH + "."); } - final WavebandSwitchingLabelBuilder builder = new WavebandSwitchingLabelBuilder(); - builder.setWavebandId(buffer.readUnsignedInt()); - builder.setStartLabel(buffer.readUnsignedInt()); - builder.setEndLabel(buffer.readUnsignedInt()); - return new WavebandSwitchingLabelCaseBuilder().setWavebandSwitchingLabel(builder.build()).build(); + return new WavebandSwitchingLabelCaseBuilder() + .setWavebandSwitchingLabel(new WavebandSwitchingLabelBuilder() + .setWavebandId(ByteBufUtils.readUint32(buffer)) + .setStartLabel(ByteBufUtils.readUint32(buffer)) + .setEndLabel(ByteBufUtils.readUint32(buffer)) + .build()) + .build(); } @Override public final void serializeLabel(final boolean unidirectional, final boolean global, final LabelType subobject, final ByteBuf buffer) { - Preconditions.checkArgument(subobject instanceof WavebandSwitchingLabelCase, - "Unknown Label Subobject instance. Passed {}. Needed WavebandSwitchingLabelCase.", + checkArgument(subobject instanceof WavebandSwitchingLabelCase, + "Unknown Label Subobject instance. Passed %s. Needed WavebandSwitchingLabelCase.", subobject.getClass()); final WavebandSwitchingLabel obj = ((WavebandSwitchingLabelCase) subobject).getWavebandSwitchingLabel(); final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH); - Preconditions.checkArgument(obj.getWavebandId() != null, "WavebandId is mandatory."); + checkArgument(obj.getWavebandId() != null, "WavebandId is mandatory."); writeUnsignedInt(obj.getWavebandId(), body); - Preconditions.checkArgument(obj.getStartLabel() != null, "StartLabel is mandatory."); + checkArgument(obj.getStartLabel() != null, "StartLabel is mandatory."); writeUnsignedInt(obj.getStartLabel(), body); - Preconditions.checkArgument(obj.getEndLabel() != null, "EndLabel is mandatory."); + checkArgument(obj.getEndLabel() != null, "EndLabel is mandatory."); writeUnsignedInt(obj.getEndLabel(), body); LabelUtil.formatLabel(CTYPE, unidirectional, global, body, buffer); } diff --git a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/rro/RROPathKey128SubobjectParser.java b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/rro/RROPathKey128SubobjectParser.java index 07f76dcc6b..accd2c9fc3 100644 --- a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/rro/RROPathKey128SubobjectParser.java +++ b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/rro/RROPathKey128SubobjectParser.java @@ -15,6 +15,7 @@ import io.netty.buffer.Unpooled; import org.opendaylight.protocol.rsvp.parser.spi.RROSubobjectParser; import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException; import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.list.SubobjectContainer; @@ -22,6 +23,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.path.key._case.PathKeyBuilder; +import org.opendaylight.yangtools.yang.common.Uint16; public class RROPathKey128SubobjectParser implements RROSubobjectParser { @@ -53,7 +55,7 @@ public class RROPathKey128SubobjectParser implements RROSubobjectParser { throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; " + "Expected: >" + CONTENT128_LENGTH + "."); } - final int pathKey = buffer.readUnsignedShort(); + final Uint16 pathKey = ByteBufUtils.readUint16(buffer); final byte[] pceId = ByteArray.readBytes(buffer, PCE128_ID_F_LENGTH); final SubobjectContainerBuilder builder = new SubobjectContainerBuilder(); final PathKeyBuilder pBuilder = new PathKeyBuilder(); diff --git a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/rro/RROPathKey32SubobjectParser.java b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/rro/RROPathKey32SubobjectParser.java index 16cefb96b0..a1eaa8248d 100644 --- a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/rro/RROPathKey32SubobjectParser.java +++ b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/rro/RROPathKey32SubobjectParser.java @@ -7,15 +7,16 @@ */ package org.opendaylight.protocol.rsvp.parser.impl.subobject.rro; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort; -import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.rsvp.parser.spi.RROSubobjectParser; import org.opendaylight.protocol.rsvp.parser.spi.RROSubobjectSerializer; import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException; import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.list.SubobjectContainer; @@ -23,6 +24,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.path.key._case.PathKeyBuilder; +import org.opendaylight.yangtools.yang.common.Uint16; public class RROPathKey32SubobjectParser implements RROSubobjectParser, RROSubobjectSerializer { @@ -38,13 +40,12 @@ public class RROPathKey32SubobjectParser implements RROSubobjectParser, RROSubob @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. Cannot be null or empty."); if (buffer.readableBytes() != CONTENT_LENGTH) { throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; " + "Expected: >" + CONTENT_LENGTH + "."); } - final int pathKey = buffer.readUnsignedShort(); + final Uint16 pathKey = ByteBufUtils.readUint16(buffer); final byte[] pceId = ByteArray.readBytes(buffer, PCE_ID_F_LENGTH); final SubobjectContainerBuilder builder = new SubobjectContainerBuilder(); final PathKeyBuilder pBuilder = new PathKeyBuilder(); @@ -56,21 +57,21 @@ public class RROPathKey32SubobjectParser implements RROSubobjectParser, RROSubob @Override public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) { - Preconditions.checkArgument(subobject.getSubobjectType() instanceof PathKeyCase, + checkArgument(subobject.getSubobjectType() instanceof PathKeyCase, "Unknown subobject instance.Passed %s. Needed PathKey.", subobject.getSubobjectType().getClass()); final PathKeyCase pkcase = (PathKeyCase) subobject.getSubobjectType(); final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects .subobject.type.path.key._case.PathKey pk = pkcase.getPathKey(); final ByteBuf body = Unpooled.buffer(); - Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory."); + checkArgument(pk.getPceId() != null, "PceId is mandatory."); final byte[] pceId = pk.getPceId().getValue(); if (pceId.length == RROPathKey128SubobjectParser.PCE128_ID_F_LENGTH) { RROPathKey128SubobjectParser.serializeSubobject(subobject, buffer); } - Preconditions.checkArgument(pk.getPathKey() != null, "PathKey is mandatory."); - Preconditions.checkArgument(pceId.length == PCE_ID_F_LENGTH, "PathKey 32Bit is mandatory."); + checkArgument(pk.getPathKey() != null, "PathKey is mandatory."); + checkArgument(pceId.length == PCE_ID_F_LENGTH, "PathKey 32Bit is mandatory."); writeUnsignedShort(pk.getPathKey().getValue(), body); body.writeBytes(pceId); RROSubobjectUtil.formatSubobject(TYPE, body, buffer); diff --git a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/rro/RROUnnumberedInterfaceSubobjectParser.java b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/rro/RROUnnumberedInterfaceSubobjectParser.java index 5f2dd20c1c..b0d8f305e5 100644 --- a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/rro/RROUnnumberedInterfaceSubobjectParser.java +++ b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/rro/RROUnnumberedInterfaceSubobjectParser.java @@ -5,18 +5,18 @@ * 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 com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt; -import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.rsvp.parser.spi.RROSubobjectParser; import org.opendaylight.protocol.rsvp.parser.spi.RROSubobjectSerializer; import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException; import org.opendaylight.protocol.util.BitArray; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.UnnumberedSubobject; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.list.SubobjectContainer; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.list.SubobjectContainerBuilder; @@ -41,8 +41,7 @@ public class RROUnnumberedInterfaceSubobjectParser implements RROSubobjectParser @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. Cannot be null or empty."); if (buffer.readableBytes() != CONTENT_LENGTH) { throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; " + "Expected: " + CONTENT_LENGTH + "."); @@ -53,15 +52,15 @@ public class RROUnnumberedInterfaceSubobjectParser implements RROSubobjectParser builder.setProtectionInUse(flags.get(LPIU_F_OFFSET)); final UnnumberedBuilder ubuilder = new UnnumberedBuilder(); buffer.skipBytes(RESERVED); - ubuilder.setRouterId(buffer.readUnsignedInt()); - ubuilder.setInterfaceId(buffer.readUnsignedInt()); + ubuilder.setRouterId(ByteBufUtils.readUint32(buffer)); + ubuilder.setInterfaceId(ByteBufUtils.readUint32(buffer)); builder.setSubobjectType(new UnnumberedCaseBuilder().setUnnumbered(ubuilder.build()).build()); return builder.build(); } @Override public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) { - Preconditions.checkArgument(subobject.getSubobjectType() instanceof UnnumberedCase, + checkArgument(subobject.getSubobjectType() instanceof UnnumberedCase, "Unknown subobject instance. Passed %s. Needed UnnumberedCase.", subobject.getSubobjectType().getClass()); final UnnumberedSubobject specObj = ((UnnumberedCase) subobject.getSubobjectType()).getUnnumbered(); @@ -71,9 +70,9 @@ public class RROUnnumberedInterfaceSubobjectParser implements RROSubobjectParser final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH); flags.toByteBuf(body); body.writeZero(RESERVED); - Preconditions.checkArgument(specObj.getRouterId() != null, "RouterId is mandatory."); + checkArgument(specObj.getRouterId() != null, "RouterId is mandatory."); writeUnsignedInt(specObj.getRouterId(), body); - Preconditions.checkArgument(specObj.getInterfaceId() != null, "InterfaceId is mandatory."); + checkArgument(specObj.getInterfaceId() != null, "InterfaceId is mandatory."); writeUnsignedInt(specObj.getInterfaceId(), body); RROSubobjectUtil.formatSubobject(TYPE, body, buffer); } diff --git a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/xro/XROSrlgSubobjectParser.java b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/xro/XROSrlgSubobjectParser.java index e99725fb50..dabc961e85 100644 --- a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/xro/XROSrlgSubobjectParser.java +++ b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/xro/XROSrlgSubobjectParser.java @@ -5,18 +5,18 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.protocol.rsvp.parser.impl.subobject.xro; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt; -import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException; import org.opendaylight.protocol.rsvp.parser.spi.XROSubobjectParser; import org.opendaylight.protocol.rsvp.parser.spi.XROSubobjectSerializer; +import org.opendaylight.protocol.util.ByteBufUtils; 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.SrlgId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.SrlgSubobject; @@ -37,33 +37,32 @@ public class XROSrlgSubobjectParser implements XROSubobjectParser, XROSubobjectS private static final int CONTENT_LENGTH = 6; @Override - public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean mandatory) throws - RSVPParsingException { - Preconditions.checkArgument(buffer != null && buffer.isReadable(), - "Array of bytes is mandatory. Can't be null or empty."); + public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean mandatory) + throws RSVPParsingException { + checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Cannot be null or empty."); if (buffer.readableBytes() != CONTENT_LENGTH) { throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; " + "Expected: " + CONTENT_LENGTH + "."); } - final SubobjectContainerBuilder builder = new SubobjectContainerBuilder(); - builder.setMandatory(mandatory); - builder.setSubobjectType(new SrlgCaseBuilder().setSrlg(new SrlgBuilder().setSrlgId(new SrlgId(buffer - .readUnsignedInt())).build()).build()); + final SubobjectContainerBuilder builder = new SubobjectContainerBuilder() + .setMandatory(mandatory) + .setSubobjectType(new SrlgCaseBuilder() + .setSrlg(new SrlgBuilder().setSrlgId(new SrlgId(ByteBufUtils.readUint32(buffer))).build()) + .build()); buffer.readByte(); - builder.setAttribute(ExcludeRouteSubobjects.Attribute.forValue(buffer.readUnsignedByte())); - return builder.build(); + return builder.setAttribute(ExcludeRouteSubobjects.Attribute.forValue(buffer.readUnsignedByte())) + .build(); } @Override public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) { - Preconditions.checkArgument(subobject.getSubobjectType() instanceof SrlgCase, - "Unknown subobject instance. Passed %s. Needed SrlgCase.", - subobject.getSubobjectType().getClass()); + checkArgument(subobject.getSubobjectType() instanceof SrlgCase, + "Unknown subobject instance. Passed %s. Needed SrlgCase.", subobject.getSubobjectType().getClass()); final SrlgSubobject specObj = ((SrlgCase) subobject.getSubobjectType()).getSrlg(); final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH); - Preconditions.checkArgument(specObj.getSrlgId() != null, "SrlgId is mandatory."); + checkArgument(specObj.getSrlgId() != null, "SrlgId is mandatory."); writeUnsignedInt(specObj.getSrlgId().getValue(), body); - Preconditions.checkArgument(subobject.getAttribute() != null, "Attribute is mandatory."); + checkArgument(subobject.getAttribute() != null, "Attribute is mandatory."); writeUnsignedByte((Uint8) null, body); writeUnsignedByte((short) subobject.getAttribute().getIntValue(), body); XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer); diff --git a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/AbstractAssociationParser.java b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/AbstractAssociationParser.java index 003e9640ea..3f9bd2a5f3 100644 --- a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/AbstractAssociationParser.java +++ b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/AbstractAssociationParser.java @@ -5,13 +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 org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException; import org.opendaylight.protocol.rsvp.parser.spi.subobjects.AbstractRSVPObjectParser; +import org.opendaylight.protocol.util.ByteBufUtils; 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.IpAddressNoZone; @@ -31,7 +32,7 @@ public abstract class AbstractAssociationParser extends AbstractRSVPObjectParser @Override protected final void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf output) { - Preconditions.checkArgument(teLspObject instanceof AssociationObject, "AssociationObject is mandatory."); + checkArgument(teLspObject instanceof AssociationObject, "AssociationObject is mandatory."); final AssociationObject assObject = (AssociationObject) teLspObject; if (assObject.getIpAddress().getIpv4AddressNoZone() != null) { @@ -49,10 +50,10 @@ public abstract class AbstractAssociationParser extends AbstractRSVPObjectParser @Override protected final RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException { - final AssociationObjectBuilder asso = new AssociationObjectBuilder(); - asso.setAssociationType(AssociationType.forValue(byteBuf.readUnsignedShort())); - asso.setAssociationId(byteBuf.readUnsignedShort()); - asso.setIpAddress(parseAssociationIpAddress(byteBuf)); - return asso.build(); + return new AssociationObjectBuilder() + .setAssociationType(AssociationType.forValue(byteBuf.readUnsignedShort())) + .setAssociationId(ByteBufUtils.readUint16(byteBuf)) + .setIpAddress(parseAssociationIpAddress(byteBuf)) + .build(); } } diff --git a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/FastRerouteObjectParser.java b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/FastRerouteObjectParser.java index 3dbb69c1c2..c4e91ce042 100644 --- a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/FastRerouteObjectParser.java +++ b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/FastRerouteObjectParser.java @@ -12,6 +12,7 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.rsvp.parser.spi.subobjects.AbstractRSVPObjectParser; import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AttributeFilter; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.FastRerouteFlags; @@ -26,16 +27,16 @@ public final class FastRerouteObjectParser extends AbstractRSVPObjectParser { @Override protected RsvpTeObject localParseObject(final ByteBuf byteBuf) { - final BasicFastRerouteObjectBuilder builder = new BasicFastRerouteObjectBuilder(); - builder.setSetupPriority(byteBuf.readUnsignedByte()); - builder.setHoldPriority(byteBuf.readUnsignedByte()); - builder.setHopLimit(byteBuf.readUnsignedByte()); - builder.setFlags(FastRerouteFlags.forValue(byteBuf.readUnsignedByte())); + final BasicFastRerouteObjectBuilder builder = new BasicFastRerouteObjectBuilder() + .setSetupPriority(ByteBufUtils.readUint8(byteBuf)) + .setHoldPriority(ByteBufUtils.readUint8(byteBuf)) + .setHopLimit(ByteBufUtils.readUint8(byteBuf)) + .setFlags(FastRerouteFlags.forValue(byteBuf.readUnsignedByte())); final ByteBuf v = byteBuf.readSlice(METRIC_VALUE_F_LENGTH); builder.setBandwidth(new Bandwidth(ByteArray.readAllBytes(v))); - builder.setIncludeAny(new AttributeFilter(byteBuf.readUnsignedInt())); - builder.setExcludeAny(new AttributeFilter(byteBuf.readUnsignedInt())); - builder.setIncludeAll(new AttributeFilter(byteBuf.readUnsignedInt())); + builder.setIncludeAny(new AttributeFilter(ByteBufUtils.readUint32(byteBuf))); + builder.setExcludeAny(new AttributeFilter(ByteBufUtils.readUint32(byteBuf))); + builder.setIncludeAll(new AttributeFilter(ByteBufUtils.readUint32(byteBuf))); return builder.build(); } diff --git a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/FlowSpecObjectParser.java b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/FlowSpecObjectParser.java index 33dac52d7a..32a06aa5bf 100644 --- a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/FlowSpecObjectParser.java +++ b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/FlowSpecObjectParser.java @@ -16,6 +16,7 @@ import io.netty.buffer.ByteBuf; import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException; import org.opendaylight.protocol.rsvp.parser.spi.subobjects.AbstractRSVPObjectParser; import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.protocol.util.ByteBufWriteUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.RsvpTeObject; @@ -47,18 +48,18 @@ public final class FlowSpecObjectParser extends AbstractRSVPObjectParser { byteBuf.skipBytes(ByteBufWriteUtil.SHORT_BYTES_LENGTH); //skip parameter ID 127 and 127 flags byteBuf.skipBytes(ByteBufWriteUtil.INT_BYTES_LENGTH); - final TspecObjectBuilder tBuilder = new TspecObjectBuilder(); - tBuilder.setTokenBucketRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH))); - tBuilder.setTokenBucketSize(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH))); - tBuilder.setPeakDataRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH))); - tBuilder.setMinimumPolicedUnit(byteBuf.readUnsignedInt()); - tBuilder.setMaximumPacketSize(byteBuf.readUnsignedInt()); + final TspecObjectBuilder tBuilder = new TspecObjectBuilder() + .setTokenBucketRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH))) + .setTokenBucketSize(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH))) + .setPeakDataRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH))) + .setMinimumPolicedUnit(ByteBufUtils.readUint32(byteBuf)) + .setMaximumPacketSize(ByteBufUtils.readUint32(byteBuf)); builder.setTspecObject(tBuilder.build()); if (builder.getServiceHeader().getIntValue() == 2) { //skip parameter ID 130, flags, lenght byteBuf.skipBytes(ByteBufWriteUtil.INT_BYTES_LENGTH); builder.setRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH))); - builder.setSlackTerm(byteBuf.readUnsignedInt()); + builder.setSlackTerm(ByteBufUtils.readUint32(byteBuf)); } return builder.build(); } diff --git a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/InformationalFastRerouteObjectParser.java b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/InformationalFastRerouteObjectParser.java index c71661d7ea..c4482cf7fa 100644 --- a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/InformationalFastRerouteObjectParser.java +++ b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/InformationalFastRerouteObjectParser.java @@ -5,15 +5,16 @@ * 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 io.netty.buffer.Unpooled; import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException; import org.opendaylight.protocol.rsvp.parser.spi.subobjects.AbstractRSVPObjectParser; import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.protocol.util.ByteBufWriteUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AttributeFilter; @@ -29,22 +30,23 @@ public final class InformationalFastRerouteObjectParser extends AbstractRSVPObje @Override protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException { - final LegacyFastRerouteObjectBuilder builder = new LegacyFastRerouteObjectBuilder(); - builder.setSetupPriority(byteBuf.readUnsignedByte()); - builder.setHoldPriority(byteBuf.readUnsignedByte()); - builder.setHopLimit(byteBuf.readUnsignedByte()); + final LegacyFastRerouteObjectBuilder builder = new LegacyFastRerouteObjectBuilder() + .setSetupPriority(ByteBufUtils.readUint8(byteBuf)) + .setHoldPriority(ByteBufUtils.readUint8(byteBuf)) + .setHopLimit(ByteBufUtils.readUint8(byteBuf)); + //skip reserved byteBuf.skipBytes(ByteBufWriteUtil.ONE_BYTE_LENGTH); final ByteBuf v = byteBuf.readSlice(METRIC_VALUE_F_LENGTH); builder.setBandwidth(new Bandwidth(ByteArray.readAllBytes(v))); - builder.setIncludeAny(new AttributeFilter(byteBuf.readUnsignedInt())); - builder.setExcludeAny(new AttributeFilter(byteBuf.readUnsignedInt())); + builder.setIncludeAny(new AttributeFilter(ByteBufUtils.readUint32(byteBuf))); + builder.setExcludeAny(new AttributeFilter(ByteBufUtils.readUint32(byteBuf))); return builder.build(); } @Override public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf byteAggregator) { - Preconditions.checkArgument(teLspObject instanceof LegacyFastRerouteObject, "FastRerouteObject is mandatory."); + checkArgument(teLspObject instanceof LegacyFastRerouteObject, "FastRerouteObject is mandatory."); final LegacyFastRerouteObject fastRerouteObject = (LegacyFastRerouteObject) teLspObject; serializeAttributeHeader(BODY_SIZE_C7, CLASS_NUM, CTYPE, byteAggregator); diff --git a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/MetricObjectParser.java b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/MetricObjectParser.java index 690a611dcd..39d2abf9b7 100644 --- a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/MetricObjectParser.java +++ b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/MetricObjectParser.java @@ -5,17 +5,17 @@ * 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 static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32; -import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException; import org.opendaylight.protocol.rsvp.parser.spi.subobjects.AbstractRSVPObjectParser; import org.opendaylight.protocol.util.BitArray; import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.protocol.util.ByteBufWriteUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.RsvpTeObject; @@ -31,19 +31,20 @@ public final class MetricObjectParser extends AbstractRSVPObjectParser { @Override protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException { - final MetricObjectBuilder builder = new MetricObjectBuilder(); byteBuf.skipBytes(ByteBufWriteUtil.SHORT_BYTES_LENGTH); final BitArray flags = BitArray.valueOf(byteBuf.readByte()); - builder.setBound(flags.get(BOUND)); - builder.setComputed(flags.get(COMPUTED)); - builder.setMetricType(byteBuf.readUnsignedByte()); - builder.setValue(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH))); - return builder.build(); + + return new MetricObjectBuilder() + .setBound(flags.get(BOUND)) + .setComputed(flags.get(COMPUTED)) + .setMetricType(ByteBufUtils.readUint8(byteBuf)) + .setValue(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH))) + .build(); } @Override public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf output) { - Preconditions.checkArgument(teLspObject instanceof MetricObject, "BandwidthObject is mandatory."); + checkArgument(teLspObject instanceof MetricObject, "BandwidthObject is mandatory."); final MetricObject metric = (MetricObject) teLspObject; serializeAttributeHeader(BODY_SIZE, CLASS_NUM, CTYPE, output); output.writeZero(ByteBufWriteUtil.SHORT_BYTES_LENGTH); diff --git a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/SenderTspecObjectParser.java b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/SenderTspecObjectParser.java index b51442560a..9642c7e2fd 100644 --- a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/SenderTspecObjectParser.java +++ b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/SenderTspecObjectParser.java @@ -7,14 +7,15 @@ */ package org.opendaylight.protocol.rsvp.parser.impl.te; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt; -import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException; import org.opendaylight.protocol.rsvp.parser.spi.subobjects.AbstractRSVPObjectParser; import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.protocol.util.ByteBufWriteUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.RsvpTeObject; @@ -29,7 +30,6 @@ public class SenderTspecObjectParser extends AbstractRSVPObjectParser { @Override protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException { - final TspecObjectBuilder builder = new TspecObjectBuilder(); //skip version number, reserved, Overall length byteBuf.skipBytes(ByteBufWriteUtil.INT_BYTES_LENGTH); //skip Service header, reserved, Length of service @@ -37,17 +37,18 @@ public class SenderTspecObjectParser extends AbstractRSVPObjectParser { //skip Parameter ID, Parameter 127 flags, Parameter 127 length byteBuf.skipBytes(ByteBufWriteUtil.INT_BYTES_LENGTH); - builder.setTokenBucketRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH))); - builder.setTokenBucketSize(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH))); - builder.setPeakDataRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH))); - builder.setMinimumPolicedUnit(byteBuf.readUnsignedInt()); - builder.setMaximumPacketSize(byteBuf.readUnsignedInt()); - return builder.build(); + return new TspecObjectBuilder() + .setTokenBucketRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH))) + .setTokenBucketSize(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH))) + .setPeakDataRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH))) + .setMinimumPolicedUnit(ByteBufUtils.readUint32(byteBuf)) + .setMaximumPacketSize(ByteBufUtils.readUint32(byteBuf)) + .build(); } @Override public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf output) { - Preconditions.checkArgument(teLspObject instanceof TspecObject, "SenderTspecObject is mandatory."); + checkArgument(teLspObject instanceof TspecObject, "SenderTspecObject is mandatory."); final TspecObject tspecObj = (TspecObject) teLspObject; serializeAttributeHeader(BODY_SIZE, CLASS_NUM, CTYPE, output); output.writeZero(ByteBufWriteUtil.SHORT_BYTES_LENGTH); diff --git a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/SessionAttributeLspObjectParser.java b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/SessionAttributeLspObjectParser.java index e40c7e3c66..1a630ba950 100644 --- a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/SessionAttributeLspObjectParser.java +++ b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/SessionAttributeLspObjectParser.java @@ -5,10 +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.te; -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 java.nio.charset.StandardCharsets; @@ -16,6 +16,7 @@ import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException; import org.opendaylight.protocol.rsvp.parser.spi.subobjects.AbstractRSVPObjectParser; import org.opendaylight.protocol.util.BitArray; import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.util.ByteBufUtils; 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.session.attribute.object.session.attribute.object.BasicSessionAttributeObject; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.session.attribute.object.session.attribute.object.BasicSessionAttributeObjectBuilder; @@ -35,15 +36,15 @@ public final class SessionAttributeLspObjectParser extends AbstractRSVPObjectPar @Override protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException { - final BasicSessionAttributeObjectBuilder builder = new BasicSessionAttributeObjectBuilder(); - builder.setSetupPriority(byteBuf.readUnsignedByte()); - builder.setHoldPriority(byteBuf.readUnsignedByte()); + final BasicSessionAttributeObjectBuilder builder = new BasicSessionAttributeObjectBuilder() + .setSetupPriority(ByteBufUtils.readUint8(byteBuf)) + .setHoldPriority(ByteBufUtils.readUint8(byteBuf)); final BitArray bs = BitArray.valueOf(byteBuf.readByte()); builder.setLocalProtectionDesired(bs.get(LOCAL_PROTECTION)); builder.setLabelRecordingDesired(bs.get(LABEL_RECORDING)); builder.setSeStyleDesired(bs.get(SE_STYLE)); - final short nameLenght = byteBuf.readUnsignedByte(); - final ByteBuf auxBuf = byteBuf.readSlice(nameLenght); + final short nameLength = byteBuf.readUnsignedByte(); + final ByteBuf auxBuf = byteBuf.readSlice(nameLength); final String name = new String(ByteArray.readAllBytes(auxBuf), StandardCharsets.US_ASCII); builder.setSessionName(name); return builder.build(); @@ -51,8 +52,7 @@ public final class SessionAttributeLspObjectParser extends AbstractRSVPObjectPar @Override public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf output) { - Preconditions.checkArgument(teLspObject instanceof BasicSessionAttributeObject, - "SessionAttributeObject is mandatory."); + checkArgument(teLspObject instanceof BasicSessionAttributeObject, "SessionAttributeObject is mandatory."); final BasicSessionAttributeObject sessionObject = (BasicSessionAttributeObject) teLspObject; final ByteBuf sessionName = Unpooled.wrappedBuffer(StandardCharsets.US_ASCII.encode(sessionObject diff --git a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/SessionAttributeLspRaObjectParser.java b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/SessionAttributeLspRaObjectParser.java index dd4356717f..4f04467093 100644 --- a/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/SessionAttributeLspRaObjectParser.java +++ b/rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/SessionAttributeLspRaObjectParser.java @@ -7,7 +7,8 @@ */ 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 io.netty.buffer.Unpooled; import java.nio.charset.StandardCharsets; @@ -15,6 +16,7 @@ import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException; import org.opendaylight.protocol.rsvp.parser.spi.subobjects.AbstractRSVPObjectParser; import org.opendaylight.protocol.util.BitArray; import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AttributeFilter; 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.session.attribute.object.session.attribute.object.SessionAttributeObjectWithResourcesAffinities; @@ -27,13 +29,14 @@ public final class SessionAttributeLspRaObjectParser extends AbstractRSVPObjectP @Override protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException { - final SessionAttributeObjectWithResourcesAffinitiesBuilder builder = new - SessionAttributeObjectWithResourcesAffinitiesBuilder(); - builder.setIncludeAny(new AttributeFilter(byteBuf.readUnsignedInt())); - builder.setExcludeAny(new AttributeFilter(byteBuf.readUnsignedInt())); - builder.setIncludeAll(new AttributeFilter(byteBuf.readUnsignedInt())); - builder.setSetupPriority(byteBuf.readUnsignedByte()); - builder.setHoldPriority(byteBuf.readUnsignedByte()); + final SessionAttributeObjectWithResourcesAffinitiesBuilder builder = + new SessionAttributeObjectWithResourcesAffinitiesBuilder() + .setIncludeAny(new AttributeFilter(ByteBufUtils.readUint32(byteBuf))) + .setExcludeAny(new AttributeFilter(ByteBufUtils.readUint32(byteBuf))) + .setIncludeAll(new AttributeFilter(ByteBufUtils.readUint32(byteBuf))) + .setSetupPriority(ByteBufUtils.readUint8(byteBuf)) + .setHoldPriority(ByteBufUtils.readUint8(byteBuf)); + final BitArray bs = BitArray.valueOf(byteBuf.readByte()); builder.setLocalProtectionDesired(bs.get(SessionAttributeLspObjectParser.LOCAL_PROTECTION)); builder.setLabelRecordingDesired(bs.get(SessionAttributeLspObjectParser.LABEL_RECORDING)); @@ -47,7 +50,7 @@ public final class SessionAttributeLspRaObjectParser extends AbstractRSVPObjectP @Override public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf output) { - Preconditions.checkArgument(teLspObject instanceof SessionAttributeObjectWithResourcesAffinities, + checkArgument(teLspObject instanceof SessionAttributeObjectWithResourcesAffinities, "SessionAttributeObject is mandatory."); final SessionAttributeObjectWithResourcesAffinities sessionObject = diff --git a/rsvp/impl/src/test/java/org/opendaylight/protocol/rsvp/parser/impl/EROSubobjectParserTest.java b/rsvp/impl/src/test/java/org/opendaylight/protocol/rsvp/parser/impl/EROSubobjectParserTest.java index 377ed5ab8b..96e46efc63 100644 --- a/rsvp/impl/src/test/java/org/opendaylight/protocol/rsvp/parser/impl/EROSubobjectParserTest.java +++ b/rsvp/impl/src/test/java/org/opendaylight/protocol/rsvp/parser/impl/EROSubobjectParserTest.java @@ -158,13 +158,13 @@ public class EROSubobjectParserTest { parser.parseSubobject(null, true); Assert.fail(); } catch (final IllegalArgumentException e) { - Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + Assert.assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } try { parser.parseSubobject(Unpooled.EMPTY_BUFFER, true); Assert.fail(); } catch (final IllegalArgumentException e) { - Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + Assert.assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } } diff --git a/rsvp/impl/src/test/java/org/opendaylight/protocol/rsvp/parser/impl/LabelSubobjectParserTest.java b/rsvp/impl/src/test/java/org/opendaylight/protocol/rsvp/parser/impl/LabelSubobjectParserTest.java index 855b88d2b0..d23142a93b 100644 --- a/rsvp/impl/src/test/java/org/opendaylight/protocol/rsvp/parser/impl/LabelSubobjectParserTest.java +++ b/rsvp/impl/src/test/java/org/opendaylight/protocol/rsvp/parser/impl/LabelSubobjectParserTest.java @@ -82,13 +82,13 @@ public class LabelSubobjectParserTest { parser.parseLabel(null); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } try { parser.parseLabel(Unpooled.EMPTY_BUFFER); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } } @@ -108,13 +108,13 @@ public class LabelSubobjectParserTest { parser.parseLabel(null); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } try { parser.parseLabel(Unpooled.EMPTY_BUFFER); fail(); } catch (final IllegalArgumentException e) { - assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } } } diff --git a/rsvp/impl/src/test/java/org/opendaylight/protocol/rsvp/parser/impl/RROSubobjectParserTest.java b/rsvp/impl/src/test/java/org/opendaylight/protocol/rsvp/parser/impl/RROSubobjectParserTest.java index 68d405f8ea..de42e88510 100644 --- a/rsvp/impl/src/test/java/org/opendaylight/protocol/rsvp/parser/impl/RROSubobjectParserTest.java +++ b/rsvp/impl/src/test/java/org/opendaylight/protocol/rsvp/parser/impl/RROSubobjectParserTest.java @@ -132,13 +132,13 @@ public class RROSubobjectParserTest { parser.parseSubobject(null); Assert.fail(); } catch (final IllegalArgumentException e) { - Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + Assert.assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } try { parser.parseSubobject(Unpooled.EMPTY_BUFFER); Assert.fail(); } catch (final IllegalArgumentException e) { - Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + Assert.assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } } @@ -160,13 +160,13 @@ public class RROSubobjectParserTest { parser.parseSubobject(null); Assert.fail(); } catch (final IllegalArgumentException e) { - Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + Assert.assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } try { parser.parseSubobject(Unpooled.EMPTY_BUFFER); Assert.fail(); } catch (final IllegalArgumentException e) { - Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + Assert.assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } } diff --git a/rsvp/impl/src/test/java/org/opendaylight/protocol/rsvp/parser/impl/XROSubobjectParserTest.java b/rsvp/impl/src/test/java/org/opendaylight/protocol/rsvp/parser/impl/XROSubobjectParserTest.java index 1247fb1d2c..a93b5edb7f 100644 --- a/rsvp/impl/src/test/java/org/opendaylight/protocol/rsvp/parser/impl/XROSubobjectParserTest.java +++ b/rsvp/impl/src/test/java/org/opendaylight/protocol/rsvp/parser/impl/XROSubobjectParserTest.java @@ -139,13 +139,13 @@ public class XROSubobjectParserTest { parser.parseSubobject(null, true); Assert.fail(); } catch (final IllegalArgumentException e) { - Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + Assert.assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } try { parser.parseSubobject(Unpooled.EMPTY_BUFFER, true); Assert.fail(); } catch (final IllegalArgumentException e) { - Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + Assert.assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } } @@ -194,13 +194,13 @@ public class XROSubobjectParserTest { parser.parseSubobject(null, true); Assert.fail(); } catch (final IllegalArgumentException e) { - Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + Assert.assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } try { parser.parseSubobject(Unpooled.EMPTY_BUFFER, true); Assert.fail(); } catch (final IllegalArgumentException e) { - Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); + Assert.assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage()); } } diff --git a/rsvp/spi/src/main/java/org/opendaylight/protocol/rsvp/parser/spi/subobjects/CommonPathKeyParser.java b/rsvp/spi/src/main/java/org/opendaylight/protocol/rsvp/parser/spi/subobjects/CommonPathKeyParser.java index ae9b847bfd..b54dfef179 100644 --- a/rsvp/spi/src/main/java/org/opendaylight/protocol/rsvp/parser/spi/subobjects/CommonPathKeyParser.java +++ b/rsvp/spi/src/main/java/org/opendaylight/protocol/rsvp/parser/spi/subobjects/CommonPathKeyParser.java @@ -5,18 +5,19 @@ * 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.spi.subobjects; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort; -import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKeyBuilder; +import org.opendaylight.yangtools.yang.common.Uint16; public class CommonPathKeyParser { protected CommonPathKeyParser() { @@ -25,7 +26,7 @@ public class CommonPathKeyParser { public static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route .subobjects.subobject.type.path.key._case.PathKey parsePathKey(final int pceIdFLength, final ByteBuf buffer) { - final int pathKey = buffer.readUnsignedShort(); + final Uint16 pathKey = ByteBufUtils.readUint16(buffer); final byte[] pceId = ByteArray.readBytes(buffer, pceIdFLength); final PathKeyBuilder pBuilder = new PathKeyBuilder(); pBuilder.setPceId(new PceId(pceId)); @@ -36,9 +37,9 @@ public class CommonPathKeyParser { public static ByteBuf serializePathKey(final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang .rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKey pk) { final ByteBuf body = Unpooled.buffer(); - Preconditions.checkArgument(pk.getPathKey() != null, "PathKey is mandatory."); + checkArgument(pk.getPathKey() != null, "PathKey is mandatory."); writeUnsignedShort(pk.getPathKey().getValue(), body); - Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory."); + checkArgument(pk.getPceId() != null, "PceId is mandatory."); body.writeBytes(pk.getPceId().getValue()); return body; } diff --git a/rsvp/spi/src/main/java/org/opendaylight/protocol/rsvp/parser/spi/subobjects/CommonUnnumberedInterfaceSubobjectParser.java b/rsvp/spi/src/main/java/org/opendaylight/protocol/rsvp/parser/spi/subobjects/CommonUnnumberedInterfaceSubobjectParser.java index 66ca6e7863..1d7d25b19f 100644 --- a/rsvp/spi/src/main/java/org/opendaylight/protocol/rsvp/parser/spi/subobjects/CommonUnnumberedInterfaceSubobjectParser.java +++ b/rsvp/spi/src/main/java/org/opendaylight/protocol/rsvp/parser/spi/subobjects/CommonUnnumberedInterfaceSubobjectParser.java @@ -5,11 +5,12 @@ * 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.spi.subobjects; -import com.google.common.base.Preconditions; +import static com.google.common.base.Preconditions.checkArgument; + import io.netty.buffer.ByteBuf; +import org.opendaylight.protocol.util.ByteBufUtils; import org.opendaylight.protocol.util.ByteBufWriteUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.UnnumberedCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.UnnumberedCaseBuilder; @@ -22,16 +23,18 @@ public class CommonUnnumberedInterfaceSubobjectParser { } protected static UnnumberedCase parseUnnumeredInterface(final ByteBuf buffer) { - final UnnumberedBuilder ubuilder = new UnnumberedBuilder(); - ubuilder.setRouterId(buffer.readUnsignedInt()); - ubuilder.setInterfaceId(buffer.readUnsignedInt()); - return new UnnumberedCaseBuilder().setUnnumbered(ubuilder.build()).build(); + return new UnnumberedCaseBuilder() + .setUnnumbered(new UnnumberedBuilder() + .setRouterId(ByteBufUtils.readUint32(buffer)) + .setInterfaceId(ByteBufUtils.readUint32(buffer)) + .build()) + .build(); } protected static void serializeUnnumeredInterface(final Unnumbered unnumbered, final ByteBuf body) { - Preconditions.checkArgument(unnumbered.getRouterId() != null, "RouterId is mandatory."); + checkArgument(unnumbered.getRouterId() != null, "RouterId is mandatory."); ByteBufWriteUtil.writeUnsignedInt(unnumbered.getRouterId(), body); - Preconditions.checkArgument(unnumbered.getInterfaceId() != null, "InterfaceId is mandatory."); + checkArgument(unnumbered.getInterfaceId() != null, "InterfaceId is mandatory."); ByteBufWriteUtil.writeUnsignedInt(unnumbered.getInterfaceId(), body); } } diff --git a/util/src/main/java/org/opendaylight/protocol/util/ByteBufUtils.java b/util/src/main/java/org/opendaylight/protocol/util/ByteBufUtils.java new file mode 100644 index 0000000000..8b6dbcf413 --- /dev/null +++ b/util/src/main/java/org/opendaylight/protocol/util/ByteBufUtils.java @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2019 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 io.netty.buffer.ByteBuf; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.opendaylight.yangtools.yang.common.Uint16; +import org.opendaylight.yangtools.yang.common.Uint32; +import org.opendaylight.yangtools.yang.common.Uint64; +import org.opendaylight.yangtools.yang.common.Uint8; + +/** + * Utility methods for interacting with {@link ByteBuf}s. These add a number of methods for reading and writing various + * data types from/to ByteBufs. + */ +public final class ByteBufUtils { + private ByteBufUtils() { + + } + + public static @NonNull Uint8 readUint8(final ByteBuf buf) { + return Uint8.fromByteBits(buf.readByte()); + } + + public static @NonNull Uint16 readUint16(final ByteBuf buf) { + return Uint16.fromShortBits(buf.readShort()); + } + + // TODO: this probably wants a dedicated concept + public static @NonNull Uint32 readUint24(final ByteBuf buf) { + return Uint32.fromIntBits(buf.readMedium()); + } + + public static @NonNull Uint32 readUint32(final ByteBuf buf) { + return Uint32.fromIntBits(buf.readInt()); + } + + public static @NonNull Uint64 readUint64(final ByteBuf buf) { + return Uint64.fromLongBits(buf.readLong()); + } + + public static void writeMandatory(final ByteBuf buf, final Byte value, final String name) { + buf.writeByte(nonNullArgument(value, name).byteValue()); + } + + public static void writeMandatory(final ByteBuf buf, final Short value, final String name) { + buf.writeShort(nonNullArgument(value, name).shortValue()); + } + + public static void writeMandatory(final ByteBuf buf, final Integer value, final String name) { + buf.writeInt(nonNullArgument(value, name).intValue()); + } + + public static void writeMandatory(final ByteBuf buf, final Long value, final String name) { + buf.writeLong(nonNullArgument(value, name).longValue()); + } + + public static void writeMandatory(final ByteBuf buf, final Uint8 value, final String name) { + buf.writeByte(nonNullArgument(value, name).byteValue()); + } + + public static void writeMandatory(final ByteBuf buf, final Uint16 value, final String name) { + buf.writeShort(nonNullArgument(value, name).shortValue()); + } + + public static void writeMandatory(final ByteBuf buf, final Uint32 value, final String name) { + buf.writeInt(nonNullArgument(value, name).intValue()); + } + + public static void writeMandatory(final ByteBuf buf, final Uint64 value, final String name) { + buf.writeLong(nonNullArgument(value, name).longValue()); + } + + public static void writeOptional(final ByteBuf buf, final @Nullable Byte value) { + if (value != null) { + buf.writeByte(value.byteValue()); + } + } + + public static void writeOptional(final ByteBuf buf, final @Nullable Short value) { + if (value != null) { + buf.writeShort(value.shortValue()); + } + } + + public static void writeOptional(final ByteBuf buf, final @Nullable Integer value) { + if (value != null) { + buf.writeInt(value.intValue()); + } + } + + public static void writeOptional(final ByteBuf buf, final @Nullable Long value) { + if (value != null) { + buf.writeLong(value.longValue()); + } + } + + public static void writeOptional(final ByteBuf buf, final @Nullable Uint8 value) { + if (value != null) { + buf.writeByte(value.byteValue()); + } + } + + public static void writeOptional(final ByteBuf buf, final @Nullable Uint16 value) { + if (value != null) { + buf.writeShort(value.shortValue()); + } + } + + public static void writeOptional(final ByteBuf buf, final @Nullable Uint32 value) { + if (value != null) { + buf.writeInt(value.intValue()); + } + } + + public static void writeOptional(final ByteBuf buf, final @Nullable Uint64 value) { + if (value != null) { + buf.writeLong(value.longValue()); + } + } + + public static void writeOrZero(final ByteBuf buf, final @Nullable Byte value) { + buf.writeByte(value != null ? value.byteValue() : 0); + } + + public static void writeOrZero(final ByteBuf buf, final @Nullable Short value) { + buf.writeShort(value != null ? value.shortValue() : (short) 0); + } + + public static void writeOrZero(final ByteBuf buf, final @Nullable Integer value) { + buf.writeInt(value != null ? value.intValue() : 0); + } + + public static void writeOrZero(final ByteBuf buf, final @Nullable Long value) { + buf.writeLong(value != null ? value.longValue() : 0L); + } + + public static void writeOrZero(final ByteBuf buf, final @Nullable Uint8 value) { + buf.writeByte(value != null ? value.byteValue() : 0); + } + + public static void writeOrZero(final ByteBuf buf, final @Nullable Uint16 value) { + buf.writeShort(value != null ? value.shortValue() : (short) 0); + } + + public static void writeOrZero(final ByteBuf buf, final @Nullable Uint32 value) { + buf.writeInt(value != null ? value.intValue() : 0); + } + + public static void writeOrZero(final ByteBuf buf, final @Nullable Uint64 value) { + buf.writeLong(value != null ? value.longValue() : 0L); + } + + private static @NonNull T nonNullArgument(final @Nullable T obj, final String name) { + if (obj == null) { + throw new IllegalArgumentException(name + " is mandatory"); + } + return obj; + } +} diff --git a/util/src/test/java/org/opendaylight/protocol/util/ByteBufUtilsTest.java b/util/src/test/java/org/opendaylight/protocol/util/ByteBufUtilsTest.java new file mode 100644 index 0000000000..a6af8c57d0 --- /dev/null +++ b/util/src/test/java/org/opendaylight/protocol/util/ByteBufUtilsTest.java @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2019 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.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import java.util.function.BiConsumer; +import java.util.function.Function; +import org.junit.Test; +import org.opendaylight.yangtools.yang.common.Uint16; +import org.opendaylight.yangtools.yang.common.Uint32; +import org.opendaylight.yangtools.yang.common.Uint64; +import org.opendaylight.yangtools.yang.common.Uint8; + +public class ByteBufUtilsTest { + + @Test + public void testByte() { + testWrite(Byte.valueOf((byte) 1), 1, ByteBufUtils::writeOptional, ByteBufUtils::writeOrZero, + ByteBufUtils::writeMandatory); + } + + @Test + public void testShort() { + testWrite(Short.valueOf((short) 1), 2, ByteBufUtils::writeOptional, ByteBufUtils::writeOrZero, + ByteBufUtils::writeMandatory); + } + + @Test + public void testInteger() { + testWrite(Integer.valueOf(1), 4, ByteBufUtils::writeOptional, ByteBufUtils::writeOrZero, + ByteBufUtils::writeMandatory); + } + + @Test + public void testLong() { + testWrite(Long.valueOf(1L), 8, ByteBufUtils::writeOptional, ByteBufUtils::writeOrZero, + ByteBufUtils::writeMandatory); + } + + @Test + public void testUint8() { + testRead(Uint8.ONE, ByteBufUtils::readUint8, (byte) 1); + testWrite(Uint8.ONE, 1, ByteBufUtils::writeOptional, ByteBufUtils::writeOrZero, ByteBufUtils::writeMandatory); + } + + @Test + public void testUint16() { + testRead(Uint16.ONE, ByteBufUtils::readUint16, (byte) 0, (byte) 1); + testWrite(Uint16.ONE, 2, ByteBufUtils::writeOptional, ByteBufUtils::writeOrZero, ByteBufUtils::writeMandatory); + } + + @Test + public void testUint32() { + testRead(Uint32.ONE, ByteBufUtils::readUint32, (byte) 0, (byte) 0, (byte) 0, (byte) 1); + testWrite(Uint32.ONE, 4, ByteBufUtils::writeOptional, ByteBufUtils::writeOrZero, ByteBufUtils::writeMandatory); + } + + @Test + public void testUint64() { + testRead(Uint64.ONE, ByteBufUtils::readUint64, + (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 1); + testWrite(Uint64.ONE, 8, ByteBufUtils::writeOptional, ByteBufUtils::writeOrZero, ByteBufUtils::writeMandatory); + } + + private static void testRead(final T expected, final Function readFunc, final byte... bytes) { + final ByteBuf buf = Unpooled.wrappedBuffer(bytes); + assertEquals(expected, readFunc.apply(buf)); + assertFalse(buf.isReadable()); + } + + private static void testWrite(final T obj, final int size, final WriteNullable writeOptional, + final WriteNullable writeOrZero, final WriteMandatory writeMandatory) { + final ByteBuf buf = Unpooled.buffer(size); + + writeOptional.accept(buf, null); + assertEquals(0, buf.writerIndex()); + writeOptional.accept(buf, obj); + assertEquals(size, buf.writerIndex()); + + writeOrZero.accept(buf, null); + assertEquals(2 * size, buf.writerIndex()); + writeOrZero.accept(buf, obj); + assertEquals(3 * size, buf.writerIndex()); + + buf.clear(); + try { + writeMandatory.accept(buf, null, "name"); + fail("IAE should have been thrown"); + } catch (IllegalArgumentException e) { + assertEquals("name is mandatory", e.getMessage()); + } + assertEquals(0, buf.writerIndex()); + + writeMandatory.accept(buf, obj, null); + assertEquals(size, buf.writerIndex()); + } + + @FunctionalInterface + interface WriteNullable extends BiConsumer { + + } + + @FunctionalInterface + interface WriteMandatory { + void accept(ByteBuf buf, T value, String name); + } +} -- 2.36.6