From 95355fd16e82f4c4e23c5c825a7649e1cace8413 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 17 Dec 2018 17:23:09 +0100 Subject: [PATCH] Enforce pcep-spi checkstyle This is trivial conversion, removing reflection-based tests and killing unneeded final's and splitting long lines. Change-Id: I158060d63cb59c387428897af9dc47efaf56dcee Signed-off-by: Robert Varga --- .../EROPathKey128SubobjectParser.java | 6 +- .../EROPathKey32SubobjectParser.java | 6 +- pcep/spi/pom.xml | 7 - .../AbstractEROPathKeySubobjectParser.java | 30 +++-- .../pcep/spi/AbstractMessageParser.java | 29 +++-- .../spi/AbstractObjectWithTlvsParser.java | 12 +- .../protocol/pcep/spi/EROSubobjectParser.java | 2 +- .../pcep/spi/EROSubobjectRegistry.java | 5 +- .../pcep/spi/EROSubobjectSerializer.java | 2 +- .../protocol/pcep/spi/EROSubobjectUtil.java | 1 - .../EnterpriseSpecificInformationParser.java | 7 +- .../protocol/pcep/spi/LabelParser.java | 3 +- .../protocol/pcep/spi/LabelRegistry.java | 7 +- .../protocol/pcep/spi/LabelSerializer.java | 3 +- .../protocol/pcep/spi/LabelUtil.java | 4 +- .../protocol/pcep/spi/MessageParser.java | 4 +- .../protocol/pcep/spi/MessageRegistry.java | 6 +- .../protocol/pcep/spi/MessageUtil.java | 3 +- .../protocol/pcep/spi/ObjectHeaderImpl.java | 16 +-- .../protocol/pcep/spi/ObjectParser.java | 3 +- .../protocol/pcep/spi/ObjectRegistry.java | 6 +- .../protocol/pcep/spi/ObjectSerializer.java | 5 +- .../protocol/pcep/spi/ObjectUtil.java | 7 +- .../pcep/spi/PCEPDeserializerException.java | 8 +- .../pcep/spi/PCEPErrorIdentifier.java | 2 +- .../protocol/pcep/spi/PCEPErrors.java | 106 ++++++++------- .../spi/PCEPExtensionProviderContext.java | 18 ++- .../pcep/spi/PCEPMessageConstants.java | 4 - .../protocol/pcep/spi/PSTUtil.java | 9 +- .../pcep/spi/RROSubobjectRegistry.java | 4 +- .../pcep/spi/RROSubobjectSerializer.java | 3 +- .../protocol/pcep/spi/RROSubobjectUtil.java | 1 - .../protocol/pcep/spi/TlvParser.java | 3 +- .../protocol/pcep/spi/TlvRegistry.java | 5 +- .../protocol/pcep/spi/TlvSerializer.java | 3 +- .../protocol/pcep/spi/TlvUtil.java | 3 +- .../protocol/pcep/spi/UnknownObject.java | 12 +- .../spi/VendorInformationObjectRegistry.java | 8 +- .../spi/VendorInformationTlvRegistry.java | 9 +- .../pcep/spi/VendorInformationUtil.java | 2 - .../protocol/pcep/spi/XROSubobjectParser.java | 3 +- .../pcep/spi/XROSubobjectRegistry.java | 5 +- .../pcep/spi/XROSubobjectSerializer.java | 3 +- .../protocol/pcep/spi/XROSubobjectUtil.java | 4 +- ...bstractPCEPExtensionProviderActivator.java | 5 +- ...iceLoaderPCEPExtensionProviderContext.java | 13 +- .../spi/pojo/SimpleEROSubobjectRegistry.java | 11 +- .../pcep/spi/pojo/SimpleLabelRegistry.java | 21 +-- .../pcep/spi/pojo/SimpleMessageRegistry.java | 11 +- .../pcep/spi/pojo/SimpleObjectRegistry.java | 24 ++-- .../SimplePCEPExtensionProviderContext.java | 36 +++--- ...PCEPExtensionProviderContextActivator.java | 4 +- .../spi/pojo/SimpleRROSubobjectRegistry.java | 23 ++-- .../pcep/spi/pojo/SimpleTlvRegistry.java | 5 - ...SimpleVendorInformationObjectRegistry.java | 18 +-- .../SimpleVendorInformationTlvRegistry.java | 15 ++- .../spi/pojo/SimpleXROSubobjectRegistry.java | 11 +- .../protocol/pcep/spi/APITest.java | 6 +- .../pcep/spi/AbstractMessageParserTest.java | 44 ++++--- .../pcep/spi/AbstractObjectWithTlvsTest.java | 54 ++++---- .../protocol/pcep/spi/RegistryTest.java | 70 +++++----- .../protocol/pcep/spi/UtilsTest.java | 122 ++---------------- 62 files changed, 391 insertions(+), 491 deletions(-) diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/EROPathKey128SubobjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/EROPathKey128SubobjectParser.java index 0a3978812a..db11074f7d 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/EROPathKey128SubobjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/EROPathKey128SubobjectParser.java @@ -20,9 +20,9 @@ public final class EROPathKey128SubobjectParser extends AbstractEROPathKeySubobj } @Override - protected void checkContentLenght(final int lenght) throws PCEPDeserializerException { - if (lenght != CONTENT128_LENGTH) { - throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + lenght + "; Expected: >" + protected void checkContentLength(final int length) throws PCEPDeserializerException { + if (length != CONTENT128_LENGTH) { + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + length + "; Expected: >" + CONTENT128_LENGTH + "."); } } diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/EROPathKey32SubobjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/EROPathKey32SubobjectParser.java index dc22e53667..fda2a5736a 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/EROPathKey32SubobjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/EROPathKey32SubobjectParser.java @@ -20,9 +20,9 @@ public final class EROPathKey32SubobjectParser extends AbstractEROPathKeySubobje } @Override - protected void checkContentLenght(final int lenght) throws PCEPDeserializerException { - if (lenght != CONTENT_LENGTH) { - throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + lenght + "; Expected: >" + protected void checkContentLength(final int length) throws PCEPDeserializerException { + if (length != CONTENT_LENGTH) { + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + length + "; Expected: >" + CONTENT_LENGTH + "."); } } diff --git a/pcep/spi/pom.xml b/pcep/spi/pom.xml index 8a2a641cf6..d14df44b25 100644 --- a/pcep/spi/pom.xml +++ b/pcep/spi/pom.xml @@ -88,13 +88,6 @@ - - org.apache.maven.plugins - maven-checkstyle-plugin - - warn - - 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 e93f57ad68..5bfc1ef9f3 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 @@ -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.spi; +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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.Subobject; @@ -22,7 +21,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.path.key._case.PathKeyBuilder; /** - * Parser for {@link PathKey} + * Parser for {@link PathKey}. */ public abstract class AbstractEROPathKeySubobjectParser implements EROSubobjectParser, EROSubobjectSerializer { @@ -33,14 +32,15 @@ public abstract class AbstractEROPathKeySubobjectParser implements EROSubobjectP protected static final int CONTENT128_LENGTH = 2 + PCE128_ID_F_LENGTH; protected static final int CONTENT_LENGTH = 2 + PCE_ID_F_LENGTH; - protected abstract byte[] readPceId(final ByteBuf buffer); + protected abstract byte[] readPceId(ByteBuf buffer); - protected abstract void checkContentLenght(final int i) throws PCEPDeserializerException; + protected abstract void checkContentLength(int length) throws PCEPDeserializerException; @Override public final 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."); - checkContentLenght(buffer.readableBytes()); + 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 byte[] pceId = readPceId(buffer); final PathKeyBuilder pBuilder = new PathKeyBuilder(); @@ -54,17 +54,19 @@ public abstract class AbstractEROPathKeySubobjectParser implements EROSubobjectP @Override public final 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(); - Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory."); - Preconditions.checkArgument(pk.getPathKey() != null, "PathKey is mandatory."); + .subobjects.subobject.type.path.key._case.PathKey pk = + ((PathKeyCase) subobject.getSubobjectType()).getPathKey(); + checkArgument(pk.getPathKey() != null, "PathKey is mandatory."); final byte[] pceID = pk.getPceId().getValue(); - Preconditions.checkArgument(pceID.length == PCE_ID_F_LENGTH || pceID.length == PCE128_ID_F_LENGTH, "PceId 32/128 Bit required."); + checkArgument(pceID.length == PCE_ID_F_LENGTH || pceID.length == PCE128_ID_F_LENGTH, + "PceId 32/128 Bit required."); final ByteBuf body = Unpooled.buffer(); writeUnsignedShort(pk.getPathKey().getValue(), body); body.writeBytes(pceID); - EROSubobjectUtil.formatSubobject(pceID.length == PCE_ID_F_LENGTH ? TYPE_32 : TYPE_128, subobject.isLoose(), body, buffer); + EROSubobjectUtil.formatSubobject(pceID.length == PCE_ID_F_LENGTH ? TYPE_32 : TYPE_128, subobject.isLoose(), + body, buffer); } } 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 32b06a0e05..7a7e9707aa 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 @@ -70,8 +70,8 @@ public abstract class AbstractMessageParser implements MessageParser, MessageSer final List objs = new ArrayList<>(); while (bytes.isReadable()) { if (bytes.readableBytes() < COMMON_OBJECT_HEADER_LENGTH) { - throw new PCEPDeserializerException("Too few bytes in passed array. Passed: " + bytes.readableBytes() + " Expected: >= " - + COMMON_OBJECT_HEADER_LENGTH + "."); + throw new PCEPDeserializerException("Too few bytes in passed array. Passed: " + bytes.readableBytes() + + " Expected: >= " + COMMON_OBJECT_HEADER_LENGTH + "."); } final int objClass = bytes.readUnsignedByte(); @@ -81,8 +81,8 @@ public abstract class AbstractMessageParser implements MessageParser, MessageSer final int objLength = bytes.readUnsignedShort(); if (bytes.readableBytes() < objLength - COMMON_OBJECT_HEADER_LENGTH) { - throw new PCEPDeserializerException("Too few bytes in passed array. Passed: " + bytes.readableBytes() + " Expected: >= " - + objLength + "."); + throw new PCEPDeserializerException("Too few bytes in passed array. Passed: " + bytes.readableBytes() + + " Expected: >= " + objLength + "."); } // copy bytes for deeper parsing final ByteBuf bytesToPass = bytes.readSlice(objLength - COMMON_OBJECT_HEADER_LENGTH); @@ -91,7 +91,8 @@ public abstract class AbstractMessageParser implements MessageParser, MessageSer if (VendorInformationUtil.isVendorInformationObject(objClass, objType)) { final EnterpriseNumber enterpriseNumber = new EnterpriseNumber(bytesToPass.readUnsignedInt()); - final Optional obj = this.registry.parseVendorInformationObject(enterpriseNumber, header, bytesToPass); + final Optional obj = this.registry.parseVendorInformationObject(enterpriseNumber, + header, bytesToPass); if (obj.isPresent()) { objs.add(obj.get()); } @@ -107,22 +108,23 @@ public abstract class AbstractMessageParser implements MessageParser, MessageSer return objs; } - public static Message createErrorMsg(final PCEPErrors e, final Optional rp) { + public static Message createErrorMsg(final PCEPErrors err, final Optional rp) { final PcerrMessageBuilder msgBuilder = new PcerrMessageBuilder(); if (rp.isPresent()) { - msgBuilder.setErrorType(new RequestCaseBuilder().setRequest(new RequestBuilder().setRps(Collections.singletonList(new RpsBuilder().setRp( - rp.get()).build())).build()).build()); + msgBuilder.setErrorType(new RequestCaseBuilder().setRequest(new RequestBuilder().setRps( + Collections.singletonList(new RpsBuilder().setRp(rp.get()).build())).build()).build()); } return new PcerrBuilder().setPcerrMessage( msgBuilder.setErrors(Collections.singletonList(new ErrorsBuilder().setErrorObject( - new ErrorObjectBuilder().setType(e.getErrorType()).setValue( - e.getErrorValue()).build()).build())).build()).build(); + new ErrorObjectBuilder().setType(err.getErrorType()).setValue( + err.getErrorValue()).build()).build())).build()).build(); } - protected abstract Message validate(final List objects, final List errors) throws PCEPDeserializerException; + protected abstract Message validate(List objects, List errors) throws PCEPDeserializerException; @Override - public final Message parseMessage(final ByteBuf buffer, final List errors) throws PCEPDeserializerException { + public final Message parseMessage(final ByteBuf buffer, final List errors) + throws PCEPDeserializerException { requireNonNull(buffer, "Buffer may not be null"); // Parse objects first @@ -132,7 +134,8 @@ public abstract class AbstractMessageParser implements MessageParser, MessageSer return validate(objs, errors); } - protected final void serializeVendorInformationObjects(final List viObjects, final ByteBuf buffer) { + protected final void serializeVendorInformationObjects(final List viObjects, + final ByteBuf buffer) { if (viObjects != null) { for (final VendorInformationObject viObject : viObjects) { this.registry.serializeVendorInformationObject(viObject, buffer); 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 f6999e16ec..22c89d600c 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 @@ -46,7 +46,8 @@ public abstract class AbstractObjectWithTlvsParser extends CommonObjectParser final int type = bytes.readUnsignedShort(); final int length = bytes.readUnsignedShort(); if (length > bytes.readableBytes()) { - throw new PCEPDeserializerException("Wrong length specified. Passed: " + length + "; Expected: <= " + bytes.readableBytes() + throw new PCEPDeserializerException("Wrong length specified. Passed: " + length + "; Expected: <= " + + bytes.readableBytes() + "."); } final ByteBuf tlvBytes = bytes.readSlice(length); @@ -54,14 +55,15 @@ public abstract class AbstractObjectWithTlvsParser extends CommonObjectParser if (VendorInformationUtil.isVendorInformationTlv(type)) { final EnterpriseNumber enterpriseNumber = new EnterpriseNumber(tlvBytes.readUnsignedInt()); - final Optional viTlv = this.viTlvReg.parseVendorInformationTlv(enterpriseNumber, tlvBytes); - if(viTlv.isPresent()) { + final Optional viTlv = this.viTlvReg.parseVendorInformationTlv(enterpriseNumber, + tlvBytes); + if (viTlv.isPresent()) { LOG.trace("Parsed VENDOR-INFORMATION TLV {}.", viTlv.get()); viTlvs.add(viTlv.get()); } } else { final Tlv tlv = this.tlvReg.parseTlv(type, tlvBytes); - if(tlv != null) { + if (tlv != null) { LOG.trace("Parsed PCEP TLV {}.", tlv); addTlv(builder, tlv); } @@ -82,7 +84,7 @@ public abstract class AbstractObjectWithTlvsParser extends CommonObjectParser // FIXME: No TLVs by default, fallback to augments } - protected abstract void addVendorInformationTlvs(final T builder, final List tlvs); + protected abstract void addVendorInformationTlvs(T builder, List tlvs); protected final void serializeVendorInformationTlvs(final List tlvs, final ByteBuf buffer) { if (tlvs != null) { diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/EROSubobjectParser.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/EROSubobjectParser.java index fc2ec4c96c..3f653f9bef 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/EROSubobjectParser.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/EROSubobjectParser.java @@ -14,5 +14,5 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ * Explicit Route Object Parser. */ public interface EROSubobjectParser { - Subobject parseSubobject(final ByteBuf buffer, final boolean loose) throws PCEPDeserializerException; + Subobject parseSubobject(ByteBuf buffer, boolean loose) throws PCEPDeserializerException; } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/EROSubobjectRegistry.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/EROSubobjectRegistry.java index ccd6e4eb8e..6dd6c2b52b 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/EROSubobjectRegistry.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/EROSubobjectRegistry.java @@ -23,8 +23,7 @@ public interface EROSubobjectRegistry { * @return null if the parser for this subobject could not be found * @throws PCEPDeserializerException if the parsing did not succeed */ - Subobject parseSubobject(final int subobjectType, final ByteBuf buffer, final boolean loose) - throws PCEPDeserializerException; + Subobject parseSubobject(int subobjectType, ByteBuf buffer, boolean loose) throws PCEPDeserializerException; /** * Find serializer for given subobject. Delegates parsing to found serializer. @@ -32,5 +31,5 @@ public interface EROSubobjectRegistry { * @param subobject to be parsed * @param buffer buffer where the serialized subobject will be parsed */ - void serializeSubobject(final Subobject subobject, final ByteBuf buffer); + void serializeSubobject(Subobject subobject, ByteBuf buffer); } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/EROSubobjectSerializer.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/EROSubobjectSerializer.java index c0cfb5719d..6c6276d00c 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/EROSubobjectSerializer.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/EROSubobjectSerializer.java @@ -14,5 +14,5 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ * Explicit Route Object Serializer. */ public interface EROSubobjectSerializer { - void serializeSubobject(final Subobject subobject, final ByteBuf buffer); + void serializeSubobject(Subobject subobject, ByteBuf buffer); } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/EROSubobjectUtil.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/EROSubobjectUtil.java index 0ef9ae7f06..0596583d6f 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/EROSubobjectUtil.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/EROSubobjectUtil.java @@ -16,7 +16,6 @@ public final class EROSubobjectUtil { private static final int LOOSE_BIT = 7; private EROSubobjectUtil() { - throw new UnsupportedOperationException(); } public static void formatSubobject(final int type, final Boolean loose, final ByteBuf body, final ByteBuf buffer) { diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/EnterpriseSpecificInformationParser.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/EnterpriseSpecificInformationParser.java index d570c16eed..1bcaa1c77d 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/EnterpriseSpecificInformationParser.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/EnterpriseSpecificInformationParser.java @@ -5,19 +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.pcep.spi; import io.netty.buffer.ByteBuf; - 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; public interface EnterpriseSpecificInformationParser { - void serializeEnterpriseSpecificInformation(final EnterpriseSpecificInformation enterpriseSpecificInformation, final ByteBuf buffer); + void serializeEnterpriseSpecificInformation(EnterpriseSpecificInformation enterpriseSpecificInformation, + ByteBuf buffer); - EnterpriseSpecificInformation parseEnterpriseSpecificInformation(final ByteBuf buffer) throws PCEPDeserializerException; + EnterpriseSpecificInformation parseEnterpriseSpecificInformation(ByteBuf buffer) throws PCEPDeserializerException; EnterpriseNumber getEnterpriseNumber(); } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/LabelParser.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/LabelParser.java index 232d5ec239..381bc9a73f 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/LabelParser.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/LabelParser.java @@ -8,9 +8,8 @@ package org.opendaylight.protocol.pcep.spi; import io.netty.buffer.ByteBuf; - import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.LabelType; public interface LabelParser { - LabelType parseLabel(final ByteBuf buffer) throws PCEPDeserializerException; + LabelType parseLabel(ByteBuf buffer) throws PCEPDeserializerException; } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/LabelRegistry.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/LabelRegistry.java index 0253be6b69..06dd76116f 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/LabelRegistry.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/LabelRegistry.java @@ -8,19 +8,18 @@ package org.opendaylight.protocol.pcep.spi; import io.netty.buffer.ByteBuf; - import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.LabelType; public interface LabelRegistry { /** * Finds parser for given label C-type in the registry. Delegates parsing to found parser. * - * @param cType label type, key in parser registry + * @param ctype label type, key in parser registry * @param buffer label wrapped in ByteBuf * @return null if the parser for this label could not be found * @throws PCEPDeserializerException if the parsing did not succeed */ - LabelType parseLabel(final int cType, final ByteBuf buffer) throws PCEPDeserializerException; + LabelType parseLabel(int ctype, ByteBuf buffer) throws PCEPDeserializerException; /** * Find serializer for given label. Delegates parsing to found serializer. @@ -30,5 +29,5 @@ public interface LabelRegistry { * @param label to be parsed * @param buffer buffer where the serialized label will be parsed */ - void serializeLabel(final boolean unidirectional, final boolean global, final LabelType label, final ByteBuf buffer); + void serializeLabel(boolean unidirectional, boolean global, LabelType label, ByteBuf buffer); } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/LabelSerializer.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/LabelSerializer.java index c805616308..d481f83397 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/LabelSerializer.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/LabelSerializer.java @@ -8,10 +8,9 @@ package org.opendaylight.protocol.pcep.spi; import io.netty.buffer.ByteBuf; - import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.LabelType; public interface LabelSerializer { - void serializeLabel(boolean unidirectional, boolean global, final LabelType subobject, final ByteBuf buffer); + void serializeLabel(boolean unidirectional, boolean global, LabelType subobject, ByteBuf buffer); } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/LabelUtil.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/LabelUtil.java index 1144a8b22f..cd8f7dbcc9 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/LabelUtil.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/LabelUtil.java @@ -18,10 +18,10 @@ public final class LabelUtil { private static final int GLOBAL = 7; private LabelUtil() { - throw new UnsupportedOperationException(); } - public static void formatLabel(final int type, final Boolean unidirectional, final Boolean global, final ByteBuf body, final ByteBuf buffer) { + public static void formatLabel(final int type, final Boolean unidirectional, final Boolean global, + final ByteBuf body, final ByteBuf buffer) { final BitArray reserved = new BitArray(FLAGS_SIZE); reserved.set(UNIDIRECTIONAL, unidirectional); reserved.set(GLOBAL, global); diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/MessageParser.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/MessageParser.java index f4243d7980..d2e4e7b01a 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/MessageParser.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/MessageParser.java @@ -8,11 +8,9 @@ package org.opendaylight.protocol.pcep.spi; import io.netty.buffer.ByteBuf; - import java.util.List; - import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Message; public interface MessageParser { - Message parseMessage(final ByteBuf buffer, final List errors) throws PCEPDeserializerException; + Message parseMessage(ByteBuf buffer, List errors) throws PCEPDeserializerException; } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/MessageRegistry.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/MessageRegistry.java index 9eb8c70389..2b5ed015bc 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/MessageRegistry.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/MessageRegistry.java @@ -8,9 +8,7 @@ package org.opendaylight.protocol.pcep.spi; import io.netty.buffer.ByteBuf; - import java.util.List; - import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Message; public interface MessageRegistry { @@ -23,7 +21,7 @@ public interface MessageRegistry { * @return null if the parser for this message could not be found * @throws PCEPDeserializerException if the parsing did not succeed */ - Message parseMessage(final int messageType, final ByteBuf buffer, final List errors) throws PCEPDeserializerException; + Message parseMessage(int messageType, ByteBuf buffer, List errors) throws PCEPDeserializerException; /** * Find serializer for given message. Delegates parsing to found serializer. @@ -31,5 +29,5 @@ public interface MessageRegistry { * @param message to be parsed * @param buffer byte buffer that will be filled with serialized message */ - void serializeMessage(final Message message, final ByteBuf buffer); + void serializeMessage(Message message, ByteBuf buffer); } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/MessageUtil.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/MessageUtil.java index 8ca36b2fd0..3d194834b2 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/MessageUtil.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/MessageUtil.java @@ -15,12 +15,11 @@ public final class MessageUtil { private static final int VERSION_SF_LENGTH = 3; private MessageUtil() { - throw new UnsupportedOperationException(); } public static void formatMessage(final int messageType, final ByteBuf body, final ByteBuf out) { final int msgLength = body.writerIndex(); - out.writeByte(PCEPMessageConstants.PCEP_VERSION << (Byte.SIZE - VERSION_SF_LENGTH)); + out.writeByte(PCEPMessageConstants.PCEP_VERSION << Byte.SIZE - VERSION_SF_LENGTH); out.writeByte(messageType); out.writeShort(msgLength + PCEPMessageConstants.COMMON_HEADER_LENGTH); Preconditions.checkState(out.writerIndex() == PCEPMessageConstants.COMMON_HEADER_LENGTH); diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectHeaderImpl.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectHeaderImpl.java index 91c86dd4b0..237d297b3e 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectHeaderImpl.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectHeaderImpl.java @@ -11,7 +11,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ import org.opendaylight.yangtools.yang.binding.DataContainer; /** - * Header parser for PCEP object + * Header parser for PCEP object. */ public class ObjectHeaderImpl implements ObjectHeader { @@ -40,12 +40,10 @@ public class ObjectHeaderImpl implements ObjectHeader { @Override public String toString() { - final String objectHeader = "ObjectHeader [objClass=" + - ", processed=" + - this.processed + - ", ignored=" + - this.ignored + - "]"; + final String objectHeader = "ObjectHeader [objClass=" + + ", processed=" + this.processed + + ", ignored=" + this.ignored + + "]"; return objectHeader; } @@ -53,8 +51,8 @@ public class ObjectHeaderImpl implements ObjectHeader { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((this.ignored == null) ? 0 : this.ignored.hashCode()); - result = prime * result + ((this.processed == null) ? 0 : this.processed.hashCode()); + result = prime * result + (this.ignored == null ? 0 : this.ignored.hashCode()); + result = prime * result + (this.processed == null ? 0 : this.processed.hashCode()); return result; } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectParser.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectParser.java index 2650758cd9..50f8fa2b51 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectParser.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectParser.java @@ -8,12 +8,11 @@ package org.opendaylight.protocol.pcep.spi; import io.netty.buffer.ByteBuf; - 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; public interface ObjectParser { - Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException; + Object parseObject(ObjectHeader header, ByteBuf buffer) throws PCEPDeserializerException; int getObjectClass(); diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectRegistry.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectRegistry.java index 241db9f9bb..00d49cbe62 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectRegistry.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectRegistry.java @@ -22,14 +22,14 @@ public interface ObjectRegistry extends VendorInformationObjectRegistry { * @return null if the parser for this object could not be found * @throws PCEPDeserializerException if the parsing did not succeed */ - Object parseObject(final int objectClass, final int objectType, final ObjectHeader header, final ByteBuf buffer) + Object parseObject(int objectClass, int objectType, ObjectHeader header, ByteBuf buffer) throws PCEPDeserializerException; /** * Find serializer for given object. Delegates parsing to found serializer. * * @param object to be parsed - * @param buffer ByteBuf wrapped aroung bytes representing given object + * @param buffer ByteBuf wrapped around bytes representing given object */ - void serializeObject(final Object object, final ByteBuf buffer); + void serializeObject(Object object, ByteBuf buffer); } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectSerializer.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectSerializer.java index f99fb4be8b..5f9afb03a8 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectSerializer.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectSerializer.java @@ -8,15 +8,14 @@ package org.opendaylight.protocol.pcep.spi; import io.netty.buffer.ByteBuf; - import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object; public interface ObjectSerializer { - /** * Serializes given object to bytes wrapped in given ByteBuf. + * * @param object PCEP object to be serialized * @param buffer ByteBuf wrapper around serialized object */ - void serializeObject(final Object object, final ByteBuf buffer); + void serializeObject(Object object, ByteBuf buffer); } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectUtil.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectUtil.java index 33d356fd5c..096481123d 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectUtil.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectUtil.java @@ -22,17 +22,16 @@ public final class ObjectUtil { private static final int IGNORED = 3; private ObjectUtil() { - throw new UnsupportedOperationException(); } - public static void formatSubobject(final int objectType, final int objectClass, final Boolean processingRule, final Boolean ignore, - final ByteBuf body, final ByteBuf out) { + public static void formatSubobject(final int objectType, final int objectClass, final Boolean processingRule, + final Boolean ignore, final ByteBuf body, final ByteBuf out) { out.writeByte(objectClass); final BitArray flags = new BitArray(FLAGS_SIZE); flags.set(IGNORED, ignore); flags.set(PROCESSED, processingRule); final byte flagB = flags.toByte(); - final int typeByte = objectType << FLAGS_SIZE | (flagB & 0xff); + final int typeByte = objectType << FLAGS_SIZE | flagB & 0xff; out.writeByte(typeByte); out.writeShort(body.writerIndex() + HEADER_SIZE); out.writeBytes(body); diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPDeserializerException.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPDeserializerException.java index 9495fbccca..92c92b7019 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPDeserializerException.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPDeserializerException.java @@ -14,7 +14,7 @@ public class PCEPDeserializerException extends Exception { private static final long serialVersionUID = 1L; /** - * Used when no exact error (from rfc or from draft) is specified. + * Used when no exact error (from an RFC or from a draft) is specified. * * @param err error message describing the error that occurred */ @@ -26,9 +26,9 @@ public class PCEPDeserializerException extends Exception { * Used when we want to pass also the exception that occurred. * * @param err error message describing the error that occurred - * @param e specific exception that occurred + * @param cause specific exception that occurred */ - public PCEPDeserializerException(final String err, final Throwable e) { - super(err, e); + public PCEPDeserializerException(final String err, final Throwable cause) { + super(err, cause); } } 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 df8152eb73..e17a12fa3f 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 @@ -10,7 +10,7 @@ package org.opendaylight.protocol.pcep.spi; import java.io.Serializable; /** - * Caret for combination of Error-type and Error-value + * Caret for combination of Error-type and Error-value. */ final class PCEPErrorIdentifier implements Serializable { private static final long serialVersionUID = 2434590156751699872L; 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 76e7db9546..cafcce23bf 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 @@ -13,10 +13,10 @@ import java.util.Map; /** * Possible errors listed in RFC5440, RFC 5455 and stateful draft. * - * @see PCEP-ERROR Object(RFC5440), PCEP-ERROR Object(stateful draft), - * Error Codes for CLASSTYPE Object(RFC5455), PCEP-Error Object + * @see PCEP-ERROR Object(RFC5440) + * @see PCEP-ERROR Object + * @see Error Codes for CLASSTYPE Object(RFC5455) + * @see PCEP-Error Object */ public enum PCEPErrors { @@ -81,23 +81,23 @@ public enum PCEPErrors { */ O_BIT_SET(5, 2), /** - * Objective function not allowed (request rejected) + * Objective function not allowed (request rejected). */ OF_NOT_ALLOWED(5, 3), /** - * OF bit of the RP object set (request rejected) + * OF bit of the RP object set (request rejected). */ OF_BIT_SET(5, 4), /** - * Global concurrent optimization not allowed (GCO extension) + * Global concurrent optimization not allowed (GCO extension). */ GCO_NOT_ALLOWED(5, 5), /** - * P2MP Path computation is not allowed + * P2MP Path computation is not allowed. */ P2MP_COMPUTATION_NOT_ALLOWED(5, 7), /** - * RP object missing + * RP object missing. */ RP_MISSING(6, 1), /** @@ -105,15 +105,15 @@ public enum PCEPErrors { */ RRO_MISSING(6, 2), /** - * END-POINTS object missing + * END-POINTS object missing. */ END_POINTS_MISSING(6, 3), /** - * LSP cleanup TLV missing + * LSP cleanup TLV missing. */ LSP_CLEANUP_TLV_MISSING(6, 13), /** - * SYMBOLIC-PATH-NAME TLV missing + * SYMBOLIC-PATH-NAME TLV missing. */ SYMBOLIC_PATH_NAME_MISSING(6, 14), /** @@ -121,7 +121,7 @@ public enum PCEPErrors { */ SYNC_PATH_COMP_REQ_MISSING(7, 0), /** - * Unknown request reference + * Unknown request reference. */ UNKNOWN_REQ_REF(8, 0), /** @@ -149,11 +149,11 @@ public enum PCEPErrors { */ P_FLAG_NOT_SET(10, 1), /** - * Insufficient memory (GCO extension) + * Insufficient memory (GCO extension). */ INSUFFICIENT_MEMORY(15, 1), /** - * Global concurrent optimization not supported (GCO extension) + * Global concurrent optimization not supported (GCO extension). */ GCO_NOT_SUPPORTED(15, 2), /** @@ -170,31 +170,31 @@ public enum PCEPErrors { CT_AND_SETUP_PRIORITY_DO_NOT_FORM_TE_CLASS(12, 3), /** - * The PCE cannot satisfy the request due to insufficient memory + * The PCE cannot satisfy the request due to insufficient memory. */ CANNOT_SATISFY_P2MP_REQUEST_DUE_TO_INSUFFISIENT_MEMMORY(16, 1), /** - * The PCE is not capable of P2MP computation + * The PCE is not capable of P2MP computation. */ NOT_CAPPABLE_P2MP_COMPUTATION(16, 2), /** - * The PCE is not capable to satisfy the request due to no END-POINTS with leaf type 2 + * The PCE is not capable to satisfy the request due to no END-POINTS with leaf type 2. */ P2MP_NOT_CAPPABLE_SATISFY_REQ_DUE_LT2(17, 1), /** - * The PCE is not capable to satisfy the request due to no END-POINTS with leaf type 3 + * The PCE is not capable to satisfy the request due to no END-POINTS with leaf type 3. */ P2MP_NOT_CAPPABLE_SATISFY_REQ_DUE_LT3(17, 2), /** - * The PCE is not capable to satisfy the request due to no END-POINTS with leaf type 4 + * The PCE is not capable to satisfy the request due to no END-POINTS with leaf type 4. */ P2MP_NOT_CAPPABLE_SATISFY_REQ_DUE_LT4(17, 3), /** - * The PCE is not capable to satisfy the request due to inconsistent END-POINTS + * The PCE is not capable to satisfy the request due to inconsistent END-POINTS. */ P2MP_NOT_CAPPABLE_SATISFY_REQ_DUE_INCONSISTENT_EP(17, 4), /** - * P2MP Fragmented request failure + * P2MP Fragmented request failure. */ P2MP_FRAGMENTATION_FAILRUE(18, 1), /** @@ -216,15 +216,15 @@ public enum PCEPErrors { */ RESOURCE_LIMIT_EXCEEDED(19, 4), /** - * PCE-initiated LSP limit reached + * PCE-initiated LSP limit reached. */ LSP_LIMIT_EXCEEDED(19, 6), /** - * Delegation for PCE-initiated LSP cannot be revoked + * Delegation for PCE-initiated LSP cannot be revoked. */ DELEGATION_NON_REVOKABLE(19, 7), /** - * Non-zero PLSP-ID in LSP initiation request + * Non-zero PLSP-ID in LSP initiation request. */ NON_ZERO_PLSPID(19, 8), /** @@ -241,39 +241,39 @@ public enum PCEPErrors { */ DB_VERSION_TLV_MISSING_WHEN_SYNC_ALLOWED(20, 3), /** - * A PCC indicates to a PCE that it can not complete the state synchronization, + * A PCC indicates to a PCE that it can not complete the state synchronization. */ CANNOT_COMPLETE_STATE_SYNC(20, 5), /** - * SYMBOLIC-PATH-NAME in use + * SYMBOLIC-PATH-NAME in use. */ USED_SYMBOLIC_PATH_NAME(23, 1), /** - * LSP instantiation error: Unacceptable instantiation parameters + * LSP instantiation error: Unacceptable instantiation parameters. */ LSP_UNACC_INST_PARAMS(24, 1), /** - * LSP instantiation error: Internal error + * LSP instantiation error: Internal error. */ LSP_INTERNAL_ERROR(24, 2), /** - * LSP instantiation error: RSVP signaling error + * LSP instantiation error: RSVP signaling error. */ LSP_RSVP_ERROR(24, 3), /** - * Segment Routing error: ERO subobject with invalid SID value + * Segment Routing error: ERO subobject with invalid SID value. */ BAD_LABEL_VALUE(10, 2), /** - * Segment Routing error: Unsupported number of Segment ERO subobjects + * Segment Routing error: Unsupported number of Segment ERO subobjects. */ UNSUPPORTED_NUMBER_OF_SR_ERO_SUBOBJECTS(10, 3), /** - * Segment Routing error: Bad label format + * Segment Routing error: Bad label format. */ BAD_LABEL_FORMAT(10, 4), /** - * Segment Routing error: Non-identical ERO subobjects + * Segment Routing error: Non-identical ERO subobjects. */ NON_IDENTICAL_ERO_SUBOBJECTS(10, 5), /** @@ -289,62 +289,60 @@ public enum PCEPErrors { */ SID_NON_IDENTICAL_RRO_SUBOBJECTS(10, 8), /** - * Invalid traffic engineering path setup type: Unsupported path setup type + * Invalid traffic engineering path setup type: Unsupported path setup type. */ UNSUPPORTED_PST(21, 1), /** - * Invalid traffic engineering path setup type: Mismatched path setup type + * Invalid traffic engineering path setup type: Mismatched path setup type. */ MISMATCHED_PST(21, 2), /** - * MONITORING object missing + * MONITORING object missing. */ MONITORING_OBJECT_MISSING(6, 4), /** - * Reception of StartTLS after any PCEP exchange - * TODO: error code to be assigned by IANA + * Reception of StartTLS after any PCEP exchange. */ + // FIXME: error code to be assigned by IANA STARTTLS_RCVD_INCORRECTLY(30, 1), /** - * Reception of non-StartTLS or non-PCErr message - * TODO: error code to be assigned by IANA + * Reception of non-StartTLS or non-PCErr message. */ + // FIXME: error code to be assigned by IANA NON_STARTTLS_MSG_RCVD(30, 2), /** - * Failure, connection without TLS not possible - * TODO: error code to be assigned by IANA + * Failure, connection without TLS not possible. */ + // FIXME: error code to be assigned by IANA NOT_POSSIBLE_WITHOUT_TLS(30, 3), /** - * Failure, connection without TLS possible - * TODO: error code to be assigned by IANA + * Failure, connection without TLS possible. */ + // FIXME: error code to be assigned by IANA POSSIBLE_WITHOUT_TLS(30, 4), /** - * No StartTLS message before StartTLSWait timer expired - * TODO: error code to be assigned by IANA + * No StartTLS message before StartTLSWait timer expired. */ + // FIXME: error code to be assigned by IANA STARTTLS_TIMER_EXP(30, 5), /** - * LSP is not PCE-initiated + * LSP is not PCE-initiated. */ LSP_NOT_PCE_INITIATED(19, 9), /** - * LSP-DB-VERSION TLV missing + * LSP-DB-VERSION TLV missing. */ LSP_DB_VERSION_MISSING(6, 12), /** - * Attempt to trigger a synchronization when the - * PCE triggered synchronization capability has not been advertised. + * Attempt to trigger a synchronization when the PCE triggered synchronization capability has not been advertised. */ UNEXPECTED_SYNCHRONIZATION_ATTEMPT(20, 4), /** - * No sufficient LSP change information for - * incremental LSP state synchronization. + * No sufficient LSP change information for incremental LSP state synchronization. */ NO_SUFFICIENT_LSP_CHANGE(20, 6), /** - * Received an invalid LSP DB Version Number + * Received an invalid LSP DB Version Number. */ INVALID_LSP_DB_VERSION(20, 7); diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPExtensionProviderContext.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPExtensionProviderContext.java index 919513479d..d39977a18d 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPExtensionProviderContext.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPExtensionProviderContext.java @@ -18,11 +18,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev public interface PCEPExtensionProviderContext extends PCEPExtensionConsumerContext { AutoCloseable registerLabelSerializer(Class labelClass, LabelSerializer serializer); - AutoCloseable registerLabelParser(int cType, LabelParser parser); + AutoCloseable registerLabelParser(int ctype, LabelParser parser); AutoCloseable registerEROSubobjectParser(int subobjectType, EROSubobjectParser parser); - AutoCloseable registerEROSubobjectSerializer(Class subobjectClass, EROSubobjectSerializer serializer); + AutoCloseable registerEROSubobjectSerializer(Class subobjectClass, + EROSubobjectSerializer serializer); AutoCloseable registerMessageParser(int messageType, MessageParser parser); @@ -37,23 +38,26 @@ public interface PCEPExtensionProviderContext extends PCEPExtensionConsumerConte AutoCloseable registerRROSubobjectParser(int subobjectType, RROSubobjectParser parser); - AutoCloseable registerRROSubobjectSerializer( - Class subobjectClass, + AutoCloseable registerRROSubobjectSerializer(Class subobjectClass, RROSubobjectSerializer serializer); AutoCloseable registerTlvSerializer(Class tlvClass, TlvSerializer serializer); AutoCloseable registerTlvParser(int tlvType, TlvParser parser); - AutoCloseable registerVendorInformationTlvSerializer(Class esInformationClass, TlvSerializer serializer); + AutoCloseable registerVendorInformationTlvSerializer( + Class esInformationClass, TlvSerializer serializer); AutoCloseable registerVendorInformationTlvParser(EnterpriseNumber enterpriseNumber, TlvParser parser); - AutoCloseable registerXROSubobjectSerializer(Class subobjectClass, XROSubobjectSerializer serializer); + AutoCloseable registerXROSubobjectSerializer(Class subobjectClass, + XROSubobjectSerializer serializer); AutoCloseable registerXROSubobjectParser(int subobjectType, XROSubobjectParser parser); - AutoCloseable registerVendorInformationObjectSerializer(Class esInformationClass, ObjectSerializer serializer); + AutoCloseable registerVendorInformationObjectSerializer( + Class esInformationClass, ObjectSerializer serializer); AutoCloseable registerVendorInformationObjectParser(EnterpriseNumber enterpriseNumber, ObjectParser parser); } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPMessageConstants.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPMessageConstants.java index cbc7acaeb2..d01c92d0d7 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPMessageConstants.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPMessageConstants.java @@ -7,9 +7,6 @@ */ package org.opendaylight.protocol.pcep.spi; -/** - * - */ public final class PCEPMessageConstants { /** * Length of the common message header, in bytes. @@ -22,6 +19,5 @@ public final class PCEPMessageConstants { public static final int PCEP_VERSION = 1; private PCEPMessageConstants() { - throw new UnsupportedOperationException(); } } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PSTUtil.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PSTUtil.java index f1f6b442b7..8ffa4311c7 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PSTUtil.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PSTUtil.java @@ -5,20 +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.pcep.spi; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.setup.type.tlv.PathSetupType; public final class PSTUtil { private PSTUtil() { - throw new UnsupportedOperationException(); } /** - * Check whether Path is setup via RSVP-TE signaling protocol - * @param pst - * @return true if setup is via RSVP-TE signaling protocol + * Check whether Path is setup via RSVP-TE signaling protocol. + * + * @param pst Path setup type + * @return true if setup is via RSVP-TE signaling protocol */ public static boolean isDefaultPST(final PathSetupType pst) { if (pst != null && pst.getPst() != null && pst.getPst() != 0) { diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/RROSubobjectRegistry.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/RROSubobjectRegistry.java index 477ffc040c..09c8f47884 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/RROSubobjectRegistry.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/RROSubobjectRegistry.java @@ -22,7 +22,7 @@ public interface RROSubobjectRegistry { * @return null if the parser for this subobject could not be found otherwise returns parser * @throws PCEPDeserializerException if the parsing did not succeed */ - Subobject parseSubobject(final int type, final ByteBuf buffer) throws PCEPDeserializerException; + Subobject parseSubobject(int type, ByteBuf buffer) throws PCEPDeserializerException; /** * Find serializer for given subobject. Delegates parsing to found serializer. @@ -30,5 +30,5 @@ public interface RROSubobjectRegistry { * @param subobject to be parsed * @param buffer buffer where the serialized subobject will be parsed */ - void serializeSubobject(final Subobject subobject, final ByteBuf buffer); + void serializeSubobject(Subobject subobject, ByteBuf buffer); } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/RROSubobjectSerializer.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/RROSubobjectSerializer.java index e9d864e44a..9e3521e3cb 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/RROSubobjectSerializer.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/RROSubobjectSerializer.java @@ -8,12 +8,11 @@ package org.opendaylight.protocol.pcep.spi; import io.netty.buffer.ByteBuf; - import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.Subobject; /** * Reported Route Object Serializer. */ public interface RROSubobjectSerializer { - void serializeSubobject(final Subobject subobject, final ByteBuf buffer); + void serializeSubobject(Subobject subobject, ByteBuf buffer); } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/RROSubobjectUtil.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/RROSubobjectUtil.java index f7602325f2..311e8ab360 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/RROSubobjectUtil.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/RROSubobjectUtil.java @@ -14,7 +14,6 @@ public final class RROSubobjectUtil { private static final int HEADER_SIZE = 2; private RROSubobjectUtil() { - throw new UnsupportedOperationException(); } public static void formatSubobject(final int type, final ByteBuf body, final ByteBuf buffer) { diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvParser.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvParser.java index 0f4c9a751f..0485b3ee5e 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvParser.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvParser.java @@ -8,9 +8,8 @@ package org.opendaylight.protocol.pcep.spi; import io.netty.buffer.ByteBuf; - import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv; public interface TlvParser { - Tlv parseTlv(final ByteBuf buffer) throws PCEPDeserializerException; + Tlv parseTlv(ByteBuf buffer) throws PCEPDeserializerException; } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvRegistry.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvRegistry.java index aaf0712022..47e341735a 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvRegistry.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvRegistry.java @@ -8,11 +8,10 @@ package org.opendaylight.protocol.pcep.spi; import io.netty.buffer.ByteBuf; - import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv; public interface TlvRegistry { - Tlv parseTlv(final int type, final ByteBuf buffer) throws PCEPDeserializerException; + Tlv parseTlv(int type, ByteBuf buffer) throws PCEPDeserializerException; - void serializeTlv(final Tlv tlv, final ByteBuf buffer); + void serializeTlv(Tlv tlv, ByteBuf buffer); } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvSerializer.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvSerializer.java index e08dd8521f..d3e10957a4 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvSerializer.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvSerializer.java @@ -8,10 +8,9 @@ package org.opendaylight.protocol.pcep.spi; import io.netty.buffer.ByteBuf; - import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv; public interface TlvSerializer { - void serializeTlv(final Tlv tlv, final ByteBuf buffer); + void serializeTlv(Tlv tlv, ByteBuf buffer); } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvUtil.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvUtil.java index 2d15c8320e..ea286ffadc 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvUtil.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvUtil.java @@ -16,7 +16,6 @@ public final class TlvUtil { public static final int PADDED_TO = 4; private TlvUtil() { - throw new UnsupportedOperationException(); } public static void formatTlv(final int type,final ByteBuf body, final ByteBuf out) { @@ -27,6 +26,6 @@ public final class TlvUtil { } public static int getPadding(final int length, final int padding) { - return (padding - (length % padding)) % padding; + return (padding - length % padding) % padding; } } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/UnknownObject.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/UnknownObject.java index 39d9a8e939..5380d206dc 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/UnknownObject.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/UnknownObject.java @@ -24,14 +24,14 @@ import org.opendaylight.yangtools.yang.binding.DataContainer; public final class UnknownObject implements Object { private final Object invalidObject; private final Errors error; - private final PCEPErrors e; + private final PCEPErrors err; public UnknownObject(final PCEPErrors error) { this(error, null); } public UnknownObject(final PCEPErrors error, final Object invalidObject) { - this.e = requireNonNull(error); + this.err = requireNonNull(error); this.error = new ErrorsBuilder().setErrorObject( new ErrorObjectBuilder().setType(error.getErrorType()).setValue( @@ -44,7 +44,7 @@ public final class UnknownObject implements Object { } public PCEPErrors getError() { - return this.e; + return this.err; } public Object getInvalidObject() { @@ -58,11 +58,11 @@ public final class UnknownObject implements Object { @Override public Boolean isIgnore() { - return false; + return Boolean.FALSE; } @Override public Boolean isProcessingRule() { - return false; + return Boolean.FALSE; } -} \ No newline at end of file +} diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/VendorInformationObjectRegistry.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/VendorInformationObjectRegistry.java index 98daacea30..672a314cd8 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/VendorInformationObjectRegistry.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/VendorInformationObjectRegistry.java @@ -5,11 +5,9 @@ * 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.spi; import io.netty.buffer.ByteBuf; - import java.util.Optional; 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.Object; @@ -18,8 +16,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ public interface VendorInformationObjectRegistry { - Optional parseVendorInformationObject(final EnterpriseNumber enterpriseNumber, final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException; - - void serializeVendorInformationObject(final VendorInformationObject viObject, final ByteBuf buffer); + Optional parseVendorInformationObject(EnterpriseNumber enterpriseNumber, ObjectHeader header, + ByteBuf buffer) throws PCEPDeserializerException; + void serializeVendorInformationObject(VendorInformationObject viObject, ByteBuf buffer); } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/VendorInformationTlvRegistry.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/VendorInformationTlvRegistry.java index d7d01d7739..259e0b6c36 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/VendorInformationTlvRegistry.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/VendorInformationTlvRegistry.java @@ -5,19 +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.pcep.spi; import io.netty.buffer.ByteBuf; - import java.util.Optional; 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.tlvs.VendorInformationTlv; public interface VendorInformationTlvRegistry { + Optional parseVendorInformationTlv(EnterpriseNumber enterpriseNumber, ByteBuf buffer) + throws PCEPDeserializerException; - Optional parseVendorInformationTlv(final EnterpriseNumber enterpriseNumber, final ByteBuf buffer) throws PCEPDeserializerException; - - void serializeVendorInformationTlv(final VendorInformationTlv viTlv, final ByteBuf buffer); - + void serializeVendorInformationTlv(VendorInformationTlv viTlv, ByteBuf buffer); } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/VendorInformationUtil.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/VendorInformationUtil.java index ea880449ca..94853134f4 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/VendorInformationUtil.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/VendorInformationUtil.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.spi; public final class VendorInformationUtil { @@ -17,7 +16,6 @@ public final class VendorInformationUtil { public static final int VENDOR_INFORMATION_OBJECT_TYPE = 1; private VendorInformationUtil() { - throw new UnsupportedOperationException(); } public static boolean isVendorInformationTlv(final int type) { diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/XROSubobjectParser.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/XROSubobjectParser.java index 72a8956b22..acd3ac016b 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/XROSubobjectParser.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/XROSubobjectParser.java @@ -8,9 +8,8 @@ package org.opendaylight.protocol.pcep.spi; import io.netty.buffer.ByteBuf; - import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.Subobject; public interface XROSubobjectParser { - Subobject parseSubobject(final ByteBuf buffer, boolean mandatory) throws PCEPDeserializerException; + Subobject parseSubobject(ByteBuf buffer, boolean mandatory) throws PCEPDeserializerException; } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/XROSubobjectRegistry.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/XROSubobjectRegistry.java index e163d081a4..98b7cfa342 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/XROSubobjectRegistry.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/XROSubobjectRegistry.java @@ -8,7 +8,6 @@ package org.opendaylight.protocol.pcep.spi; import io.netty.buffer.ByteBuf; - import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.Subobject; public interface XROSubobjectRegistry { @@ -21,7 +20,7 @@ public interface XROSubobjectRegistry { * @return null if the parser for this subobject could not be found * @throws PCEPDeserializerException if the parsing did not succeed */ - Subobject parseSubobject(final int type, final ByteBuf buffer, final boolean mandatory) throws PCEPDeserializerException; + Subobject parseSubobject(int type, ByteBuf buffer, boolean mandatory) throws PCEPDeserializerException; /** * Find serializer for given subobject. Delegates parsing to found serializer. @@ -29,5 +28,5 @@ public interface XROSubobjectRegistry { * @param subobject to be parsed * @param buffer buffer where the serialized subobject will be parsed */ - void serializeSubobject(final Subobject subobject, final ByteBuf buffer); + void serializeSubobject(Subobject subobject, ByteBuf buffer); } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/XROSubobjectSerializer.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/XROSubobjectSerializer.java index 4187335180..8ba32b8e3e 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/XROSubobjectSerializer.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/XROSubobjectSerializer.java @@ -8,10 +8,9 @@ package org.opendaylight.protocol.pcep.spi; import io.netty.buffer.ByteBuf; - import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.Subobject; public interface XROSubobjectSerializer { - void serializeSubobject(final Subobject subobject, final ByteBuf buffer); + void serializeSubobject(Subobject subobject, ByteBuf buffer); } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/XROSubobjectUtil.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/XROSubobjectUtil.java index be5db483dd..87dd84cbe9 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/XROSubobjectUtil.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/XROSubobjectUtil.java @@ -16,10 +16,10 @@ public final class XROSubobjectUtil { private static final int MANDATORY_BIT = 7; private XROSubobjectUtil() { - throw new UnsupportedOperationException(); } - public static void formatSubobject(final int type, final Boolean mandatory, final ByteBuf body, final ByteBuf buffer) { + public static void formatSubobject(final int type, final Boolean mandatory, final ByteBuf body, + final ByteBuf buffer) { if (mandatory == null) { buffer.writeByte(type); } else { diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/AbstractPCEPExtensionProviderActivator.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/AbstractPCEPExtensionProviderActivator.java index 5991ec6891..8876fa4c1d 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/AbstractPCEPExtensionProviderActivator.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/AbstractPCEPExtensionProviderActivator.java @@ -7,9 +7,9 @@ */ package org.opendaylight.protocol.pcep.spi.pojo; +import static com.google.common.base.Preconditions.checkState; import static java.util.Objects.requireNonNull; -import com.google.common.base.Preconditions; import java.util.List; import javax.annotation.concurrent.GuardedBy; import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderActivator; @@ -28,12 +28,13 @@ public abstract class AbstractPCEPExtensionProviderActivator implements AutoClos @Override public final synchronized void start(final PCEPExtensionProviderContext context) { - Preconditions.checkState(this.registrations == null); + checkState(this.registrations == null); this.registrations = requireNonNull(startImpl(context)); } @Override + @SuppressWarnings("checkstyle:illegalCatch") public final synchronized void stop() { if (this.registrations == null) { return; diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/ServiceLoaderPCEPExtensionProviderContext.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/ServiceLoaderPCEPExtensionProviderContext.java index aa696fcd7f..0fbdc34ac7 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/ServiceLoaderPCEPExtensionProviderContext.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/ServiceLoaderPCEPExtensionProviderContext.java @@ -13,18 +13,10 @@ import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext; public final class ServiceLoaderPCEPExtensionProviderContext extends SimplePCEPExtensionProviderContext { private static final class Holder { - private static final PCEPExtensionProviderContext INSTANCE; + private static final PCEPExtensionProviderContext INSTANCE = create(); private Holder() { } - - static { - try { - INSTANCE = create(); - } catch (final Exception e) { - throw new ExceptionInInitializerError(e); - } - } } private ServiceLoaderPCEPExtensionProviderContext() { @@ -34,7 +26,8 @@ public final class ServiceLoaderPCEPExtensionProviderContext extends SimplePCEPE public static PCEPExtensionProviderContext create() { final PCEPExtensionProviderContext ctx = new SimplePCEPExtensionProviderContext(); - final ServiceLoader loader = ServiceLoader.load(PCEPExtensionProviderActivator.class); + final ServiceLoader loader = + ServiceLoader.load(PCEPExtensionProviderActivator.class); for (final PCEPExtensionProviderActivator a : loader) { a.start(ctx); } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleEROSubobjectRegistry.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleEROSubobjectRegistry.java index 1d8fe9d52b..0b4a15b8ed 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleEROSubobjectRegistry.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleEROSubobjectRegistry.java @@ -8,9 +8,7 @@ package org.opendaylight.protocol.pcep.spi.pojo; import com.google.common.base.Preconditions; - import io.netty.buffer.ByteBuf; - import org.opendaylight.protocol.concepts.HandlerRegistry; import org.opendaylight.protocol.pcep.spi.EROSubobjectParser; import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry; @@ -22,7 +20,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev import org.opendaylight.yangtools.yang.binding.DataContainer; public final class SimpleEROSubobjectRegistry implements EROSubobjectRegistry { - private final HandlerRegistry handlers = new HandlerRegistry<>(); + private final HandlerRegistry handlers = + new HandlerRegistry<>(); public AutoCloseable registerSubobjectParser(final int subobjectType, final EROSubobjectParser parser) { Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Values.UNSIGNED_SHORT_MAX_VALUE); @@ -35,7 +34,8 @@ public final class SimpleEROSubobjectRegistry implements EROSubobjectRegistry { } @Override - public Subobject parseSubobject(final int type, final ByteBuf buffer, final boolean loose) throws PCEPDeserializerException { + public Subobject parseSubobject(final int type, final ByteBuf buffer, final boolean loose) + throws PCEPDeserializerException { Preconditions.checkArgument(type >= 0 && type <= Values.UNSIGNED_SHORT_MAX_VALUE); final EROSubobjectParser parser = this.handlers.getParser(type); if (parser == null) { @@ -46,7 +46,8 @@ public final class SimpleEROSubobjectRegistry implements EROSubobjectRegistry { @Override public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) { - final EROSubobjectSerializer serializer = this.handlers.getSerializer(subobject.getSubobjectType().getImplementedInterface()); + final EROSubobjectSerializer serializer = this.handlers.getSerializer( + subobject.getSubobjectType().getImplementedInterface()); if (serializer == null) { return; } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleLabelRegistry.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleLabelRegistry.java index 0d75b08f63..6962efa508 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleLabelRegistry.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleLabelRegistry.java @@ -7,10 +7,9 @@ */ package org.opendaylight.protocol.pcep.spi.pojo; -import com.google.common.base.Preconditions; +import static com.google.common.base.Preconditions.checkArgument; import io.netty.buffer.ByteBuf; - import org.opendaylight.protocol.concepts.HandlerRegistry; import org.opendaylight.protocol.pcep.spi.LabelParser; import org.opendaylight.protocol.pcep.spi.LabelRegistry; @@ -23,19 +22,20 @@ import org.opendaylight.yangtools.yang.binding.DataContainer; public class SimpleLabelRegistry implements LabelRegistry { private final HandlerRegistry handlers = new HandlerRegistry<>(); - public AutoCloseable registerLabelParser(final int cType, final LabelParser parser) { - Preconditions.checkArgument(cType >= 0 && cType <= Values.UNSIGNED_BYTE_MAX_VALUE); - return this.handlers.registerParser(cType, parser); + public AutoCloseable registerLabelParser(final int ctype, final LabelParser parser) { + checkArgument(ctype >= 0 && ctype <= Values.UNSIGNED_BYTE_MAX_VALUE); + return this.handlers.registerParser(ctype, parser); } - public AutoCloseable registerLabelSerializer(final Class labelClass, final LabelSerializer serializer) { + public AutoCloseable registerLabelSerializer(final Class labelClass, + final LabelSerializer serializer) { return this.handlers.registerSerializer(labelClass, serializer); } @Override - public LabelType parseLabel(final int cType, final ByteBuf buffer) throws PCEPDeserializerException { - Preconditions.checkArgument(cType >= 0 && cType <= Values.UNSIGNED_BYTE_MAX_VALUE); - final LabelParser parser = this.handlers.getParser(cType); + public LabelType parseLabel(final int ctype, final ByteBuf buffer) throws PCEPDeserializerException { + checkArgument(ctype >= 0 && ctype <= Values.UNSIGNED_BYTE_MAX_VALUE); + final LabelParser parser = this.handlers.getParser(ctype); if (parser == null) { return null; } @@ -43,7 +43,8 @@ public class SimpleLabelRegistry implements LabelRegistry { } @Override - public void serializeLabel(final boolean unidirectional, final boolean global, final LabelType label, final ByteBuf buffer) { + public void serializeLabel(final boolean unidirectional, final boolean global, final LabelType label, + final ByteBuf buffer) { final LabelSerializer serializer = this.handlers.getSerializer(label.getImplementedInterface()); if (serializer != null) { serializer.serializeLabel(unidirectional, global, label, buffer); diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleMessageRegistry.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleMessageRegistry.java index b4e33f0d56..7bdf5ecf0b 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleMessageRegistry.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleMessageRegistry.java @@ -8,11 +8,8 @@ package org.opendaylight.protocol.pcep.spi.pojo; import com.google.common.base.Preconditions; - import io.netty.buffer.ByteBuf; - import java.util.List; - import org.opendaylight.protocol.concepts.HandlerRegistry; import org.opendaylight.protocol.pcep.spi.MessageParser; import org.opendaylight.protocol.pcep.spi.MessageRegistry; @@ -35,12 +32,14 @@ public final class SimpleMessageRegistry implements MessageRegistry { return this.handlers.registerParser(messageType, parser); } - public AutoCloseable registerMessageSerializer(final Class msgClass, final MessageSerializer serializer) { + public AutoCloseable registerMessageSerializer(final Class msgClass, + final MessageSerializer serializer) { return this.handlers.registerSerializer(msgClass, serializer); } @Override - public Message parseMessage(final int messageType, final ByteBuf buffer, final List errors) throws PCEPDeserializerException { + public Message parseMessage(final int messageType, final ByteBuf buffer, final List errors) + throws PCEPDeserializerException { Preconditions.checkArgument(messageType >= 0 && messageType <= Values.UNSIGNED_BYTE_MAX_VALUE); final MessageParser parser = this.handlers.getParser(messageType); if (parser == null) { @@ -51,7 +50,7 @@ public final class SimpleMessageRegistry implements MessageRegistry { } @Override - public void serializeMessage(Message message, ByteBuf buffer) { + public void serializeMessage(final Message message, final ByteBuf buffer) { final MessageSerializer serializer = this.handlers.getSerializer(message.getImplementedInterface()); if (serializer == null) { LOG.warn("PCEP serializer for message type {} is not registered.", message.getClass()); diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleObjectRegistry.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleObjectRegistry.java index a8cfc2d3d5..2f0d7bff9e 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleObjectRegistry.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleObjectRegistry.java @@ -7,6 +7,8 @@ */ package org.opendaylight.protocol.pcep.spi.pojo; +import static com.google.common.base.Preconditions.checkArgument; + import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import java.util.Optional; @@ -29,35 +31,36 @@ public final class SimpleObjectRegistry implements ObjectRegistry { private final HandlerRegistry handlers = new HandlerRegistry<>(); private static final int MAX_OBJECT_TYPE = 15; - private static final int MAX_OBJECT_CLASS = 4; + private static final int MAX_OBJECT_CLASS = 4; + private final VendorInformationObjectRegistry viRegistry; public SimpleObjectRegistry(final VendorInformationObjectRegistry viRegistry) { this.viRegistry = viRegistry; - } private static int createKey(final int objectClass, final int objectType) { Preconditions.checkArgument(objectClass >= 0 && objectClass <= Values.UNSIGNED_BYTE_MAX_VALUE); Preconditions.checkArgument(objectType >= 0 && objectType <= MAX_OBJECT_TYPE); - return (objectClass << MAX_OBJECT_CLASS) | objectType; + return objectClass << MAX_OBJECT_CLASS | objectType; } public AutoCloseable registerObjectParser(final int objectClass, final int objectType, final ObjectParser parser) { - Preconditions.checkArgument(objectClass >= 0 && objectClass <= Values.UNSIGNED_BYTE_MAX_VALUE, "Illegal object class %s", + checkArgument(objectClass >= 0 && objectClass <= Values.UNSIGNED_BYTE_MAX_VALUE, "Illegal object class %s", objectClass); - Preconditions.checkArgument(objectType >= 0 && objectType <= MAX_OBJECT_TYPE, "Illegal object type %s", objectType); + checkArgument(objectType >= 0 && objectType <= MAX_OBJECT_TYPE, "Illegal object type %s", objectType); return this.handlers.registerParser(createKey(objectClass, objectType), parser); } - public AutoCloseable registerObjectSerializer(final Class objClass, final ObjectSerializer serializer) { + public AutoCloseable registerObjectSerializer(final Class objClass, + final ObjectSerializer serializer) { return this.handlers.registerSerializer(objClass, serializer); } @Override - public Object parseObject(final int objectClass, final int objectType, final ObjectHeader header, final ByteBuf buffer) - throws PCEPDeserializerException { - Preconditions.checkArgument(objectType >= 0 && objectType <= Values.UNSIGNED_SHORT_MAX_VALUE); + public Object parseObject(final int objectClass, final int objectType, final ObjectHeader header, + final ByteBuf buffer) throws PCEPDeserializerException { + checkArgument(objectType >= 0 && objectType <= Values.UNSIGNED_SHORT_MAX_VALUE); final ObjectParser parser = this.handlers.getParser(createKey(objectClass, objectType)); if (parser == null) { @@ -82,7 +85,8 @@ public final class SimpleObjectRegistry implements ObjectRegistry { return; } serializer.serializeObject(object, buffer); - } + } + @Override public Optional parseVendorInformationObject(final EnterpriseNumber enterpriseNumber, final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException { diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimplePCEPExtensionProviderContext.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimplePCEPExtensionProviderContext.java index 962fc6e55d..737d6bc313 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimplePCEPExtensionProviderContext.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimplePCEPExtensionProviderContext.java @@ -8,7 +8,6 @@ package org.opendaylight.protocol.pcep.spi.pojo; import javax.annotation.concurrent.ThreadSafe; - import org.opendaylight.protocol.pcep.spi.EROSubobjectParser; import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry; import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer; @@ -41,9 +40,6 @@ 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.basic.explicit.route.subobjects.SubobjectType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.LabelType; -/** - * - */ @ThreadSafe public class SimplePCEPExtensionProviderContext implements PCEPExtensionProviderContext { private final SimpleLabelRegistry labelReg = new SimpleLabelRegistry(); @@ -97,13 +93,14 @@ public class SimplePCEPExtensionProviderContext implements PCEPExtensionProvider } @Override - public final AutoCloseable registerLabelSerializer(final Class labelClass, final LabelSerializer serializer) { + public final AutoCloseable registerLabelSerializer(final Class labelClass, + final LabelSerializer serializer) { return this.labelReg.registerLabelSerializer(labelClass, serializer); } @Override - public final AutoCloseable registerLabelParser(final int cType, final LabelParser parser) { - return this.labelReg.registerLabelParser(cType, parser); + public final AutoCloseable registerLabelParser(final int ctype, final LabelParser parser) { + return this.labelReg.registerLabelParser(ctype, parser); } @Override @@ -123,12 +120,14 @@ public class SimplePCEPExtensionProviderContext implements PCEPExtensionProvider } @Override - public final AutoCloseable registerMessageSerializer(final Class msgClass, final MessageSerializer serializer) { + public final AutoCloseable registerMessageSerializer(final Class msgClass, + final MessageSerializer serializer) { return this.msgReg.registerMessageSerializer(msgClass, serializer); } @Override - public final AutoCloseable registerObjectParser(final int objectClass, final int objectType, final ObjectParser parser) { + public final AutoCloseable registerObjectParser(final int objectClass, final int objectType, + final ObjectParser parser) { return this.objReg.registerObjectParser(objectClass, objectType, parser); } @@ -138,7 +137,8 @@ public class SimplePCEPExtensionProviderContext implements PCEPExtensionProvider } @Override - public final AutoCloseable registerObjectSerializer(final Class objClass, final ObjectSerializer serializer) { + public final AutoCloseable registerObjectSerializer(final Class objClass, + final ObjectSerializer serializer) { return this.objReg.registerObjectSerializer(objClass, serializer); } @@ -148,8 +148,8 @@ public class SimplePCEPExtensionProviderContext implements PCEPExtensionProvider } @Override - public final AutoCloseable registerRROSubobjectSerializer( - final Class subobjectClass, + public final AutoCloseable registerRROSubobjectSerializer(final Class subobjectClass, final RROSubobjectSerializer serializer) { return this.rroSubReg.registerSubobjectSerializer(subobjectClass, serializer); } @@ -160,7 +160,8 @@ public class SimplePCEPExtensionProviderContext implements PCEPExtensionProvider } @Override - public final AutoCloseable registerTlvSerializer(final Class tlvClass, final TlvSerializer serializer) { + public final AutoCloseable registerTlvSerializer(final Class tlvClass, + final TlvSerializer serializer) { return this.tlvReg.registerTlvSerializer(tlvClass, serializer); } @@ -182,18 +183,21 @@ public class SimplePCEPExtensionProviderContext implements PCEPExtensionProvider } @Override - public AutoCloseable registerVendorInformationTlvParser(final EnterpriseNumber enterpriseNumber, final TlvParser parser) { + public AutoCloseable registerVendorInformationTlvParser(final EnterpriseNumber enterpriseNumber, + final TlvParser parser) { return this.viTlvReg.registerVendorInformationTlvParser(enterpriseNumber, parser); } @Override public AutoCloseable registerVendorInformationObjectSerializer( - final Class esInformationClass, final ObjectSerializer serializer) { + final Class esInformationClass, + final ObjectSerializer serializer) { return this.viObjReg.registerVendorInformationObjectSerializer(esInformationClass, serializer); } @Override - public AutoCloseable registerVendorInformationObjectParser(final EnterpriseNumber enterpriseNumber, final ObjectParser parser) { + public AutoCloseable registerVendorInformationObjectParser(final EnterpriseNumber enterpriseNumber, + final ObjectParser parser) { return this.viObjReg.registerVendorInformationObjectParser(enterpriseNumber, parser); } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimplePCEPExtensionProviderContextActivator.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimplePCEPExtensionProviderContextActivator.java index 5d02a17d95..ed4a7d73a9 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimplePCEPExtensionProviderContextActivator.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimplePCEPExtensionProviderContextActivator.java @@ -35,7 +35,7 @@ public class SimplePCEPExtensionProviderContextActivator implements AutoCloseabl public void start() { LOG.debug("Starting {} PCEPExtensionProviderActivator instances", this.extensionActivators.size()); - for(final PCEPExtensionProviderActivator e : this.extensionActivators) { + for (final PCEPExtensionProviderActivator e : this.extensionActivators) { e.start(this.providerContext); } } @@ -44,7 +44,7 @@ public class SimplePCEPExtensionProviderContextActivator implements AutoCloseabl public void close() { LOG.debug("Stopping {} BGPExtensionProviderActivator instances", this.extensionActivators.size()); - for(final PCEPExtensionProviderActivator e : this.extensionActivators) { + for (final PCEPExtensionProviderActivator e : this.extensionActivators) { e.stop(); } } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleRROSubobjectRegistry.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleRROSubobjectRegistry.java index 3d16f10a49..86efea2f1a 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleRROSubobjectRegistry.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleRROSubobjectRegistry.java @@ -7,10 +7,9 @@ */ package org.opendaylight.protocol.pcep.spi.pojo; -import com.google.common.base.Preconditions; +import static com.google.common.base.Preconditions.checkArgument; import io.netty.buffer.ByteBuf; - import org.opendaylight.protocol.concepts.HandlerRegistry; import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; import org.opendaylight.protocol.pcep.spi.RROSubobjectParser; @@ -22,10 +21,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev import org.opendaylight.yangtools.yang.binding.DataContainer; public final class SimpleRROSubobjectRegistry implements RROSubobjectRegistry { - private final HandlerRegistry handlers = new HandlerRegistry<>(); + private final HandlerRegistry handlers = + new HandlerRegistry<>(); public AutoCloseable registerSubobjectParser(final int subobjectType, final RROSubobjectParser parser) { - Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Values.UNSIGNED_SHORT_MAX_VALUE); + checkArgument(subobjectType >= 0 && subobjectType <= Values.UNSIGNED_SHORT_MAX_VALUE); return this.handlers.registerParser(subobjectType, parser); } @@ -36,20 +36,17 @@ public final class SimpleRROSubobjectRegistry implements RROSubobjectRegistry { @Override public Subobject parseSubobject(final int type, final ByteBuf buffer) throws PCEPDeserializerException { - Preconditions.checkArgument(type >= 0 && type <= Values.UNSIGNED_SHORT_MAX_VALUE); + checkArgument(type >= 0 && type <= Values.UNSIGNED_SHORT_MAX_VALUE); final RROSubobjectParser parser = this.handlers.getParser(type); - if (parser == null) { - return null; - } - return parser.parseSubobject(buffer); + return parser == null ? null : parser.parseSubobject(buffer); } @Override public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) { - final RROSubobjectSerializer serializer = this.handlers.getSerializer(subobject.getSubobjectType().getImplementedInterface()); - if (serializer == null) { - return; + final RROSubobjectSerializer serializer = this.handlers.getSerializer( + subobject.getSubobjectType().getImplementedInterface()); + if (serializer != null) { + serializer.serializeSubobject(subobject, buffer); } - serializer.serializeSubobject(subobject, buffer); } } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleTlvRegistry.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleTlvRegistry.java index 7a0c5b663e..1b718ef93f 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleTlvRegistry.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleTlvRegistry.java @@ -8,9 +8,7 @@ package org.opendaylight.protocol.pcep.spi.pojo; import com.google.common.base.Preconditions; - import io.netty.buffer.ByteBuf; - import org.opendaylight.protocol.concepts.HandlerRegistry; import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; import org.opendaylight.protocol.pcep.spi.TlvParser; @@ -20,9 +18,6 @@ import org.opendaylight.protocol.util.Values; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv; import org.opendaylight.yangtools.yang.binding.DataContainer; -/** - * - */ public final class SimpleTlvRegistry implements TlvRegistry { private final HandlerRegistry handlers = new HandlerRegistry<>(); diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleVendorInformationObjectRegistry.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleVendorInformationObjectRegistry.java index 4823ddfb57..7b0775c620 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleVendorInformationObjectRegistry.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleVendorInformationObjectRegistry.java @@ -5,13 +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.pcep.spi.pojo; import com.google.common.primitives.Ints; - import io.netty.buffer.ByteBuf; - import java.util.Optional; import org.opendaylight.protocol.concepts.HandlerRegistry; import org.opendaylight.protocol.pcep.spi.ObjectParser; @@ -28,19 +25,22 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ import org.opendaylight.yangtools.yang.binding.DataContainer; public class SimpleVendorInformationObjectRegistry implements VendorInformationObjectRegistry { - private final HandlerRegistry handlers = new HandlerRegistry<>(); - public AutoCloseable registerVendorInformationObjectParser(final EnterpriseNumber enterpriseNumber, final ObjectParser parser) { + public AutoCloseable registerVendorInformationObjectParser(final EnterpriseNumber enterpriseNumber, + final ObjectParser parser) { return this.handlers.registerParser(Ints.checkedCast(enterpriseNumber.getValue()), parser); } - public AutoCloseable registerVendorInformationObjectSerializer(final Class esInformationClass, final ObjectSerializer serializer) { + public AutoCloseable registerVendorInformationObjectSerializer( + final Class esInformationClass, + final ObjectSerializer serializer) { return this.handlers.registerSerializer(esInformationClass, serializer); } @Override - public Optional parseVendorInformationObject(final EnterpriseNumber enterpriseNumber, final ObjectHeader header, final ByteBuf buffer) + public Optional parseVendorInformationObject(final EnterpriseNumber enterpriseNumber, + final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException { final ObjectParser parser = this.handlers.getParser(Ints.checkedCast(enterpriseNumber.getValue())); if (parser == null) { @@ -54,11 +54,11 @@ public class SimpleVendorInformationObjectRegistry implements VendorInformationO @Override public void serializeVendorInformationObject(final VendorInformationObject viObject, final ByteBuf buffer) { - final ObjectSerializer serializer = this.handlers.getSerializer(viObject.getEnterpriseSpecificInformation().getImplementedInterface()); + final ObjectSerializer serializer = this.handlers.getSerializer( + viObject.getEnterpriseSpecificInformation().getImplementedInterface()); if (serializer == null) { return; } serializer.serializeObject(viObject, buffer); } - } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleVendorInformationTlvRegistry.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleVendorInformationTlvRegistry.java index 23d4be76f4..f1dbf4d66b 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleVendorInformationTlvRegistry.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleVendorInformationTlvRegistry.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.spi.pojo; import com.google.common.primitives.Ints; @@ -25,16 +24,19 @@ public class SimpleVendorInformationTlvRegistry implements VendorInformationTlvR private final HandlerRegistry handlers = new HandlerRegistry<>(); - public AutoCloseable registerVendorInformationTlvParser(final EnterpriseNumber enterpriseNumber, final TlvParser parser) { + public AutoCloseable registerVendorInformationTlvParser(final EnterpriseNumber enterpriseNumber, + final TlvParser parser) { return this.handlers.registerParser(Ints.checkedCast(enterpriseNumber.getValue()), parser); } - public AutoCloseable registerVendorInformationTlvSerializer(final Class esInformationClass, final TlvSerializer serializer) { + public AutoCloseable registerVendorInformationTlvSerializer( + final Class esInformationClass, final TlvSerializer serializer) { return this.handlers.registerSerializer(esInformationClass, serializer); } @Override - public Optional parseVendorInformationTlv(final EnterpriseNumber enterpriseNumber, final ByteBuf buffer) throws PCEPDeserializerException { + public Optional parseVendorInformationTlv(final EnterpriseNumber enterpriseNumber, + final ByteBuf buffer) throws PCEPDeserializerException { final TlvParser parser = this.handlers.getParser(Ints.checkedCast(enterpriseNumber.getValue())); if (parser == null) { return Optional.empty(); @@ -44,12 +46,11 @@ public class SimpleVendorInformationTlvRegistry implements VendorInformationTlvR @Override public void serializeVendorInformationTlv(final VendorInformationTlv viTlv, final ByteBuf buffer) { - final TlvSerializer serializer = this.handlers.getSerializer(viTlv.getEnterpriseSpecificInformation().getImplementedInterface()); + final TlvSerializer serializer = this.handlers.getSerializer( + viTlv.getEnterpriseSpecificInformation().getImplementedInterface()); if (serializer == null) { return; } serializer.serializeTlv(viTlv, buffer); } - - } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleXROSubobjectRegistry.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleXROSubobjectRegistry.java index 0902e313b6..cb2a4014e0 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleXROSubobjectRegistry.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleXROSubobjectRegistry.java @@ -8,9 +8,7 @@ package org.opendaylight.protocol.pcep.spi.pojo; import com.google.common.base.Preconditions; - import io.netty.buffer.ByteBuf; - import org.opendaylight.protocol.concepts.HandlerRegistry; import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; import org.opendaylight.protocol.pcep.spi.XROSubobjectParser; @@ -22,7 +20,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev import org.opendaylight.yangtools.yang.binding.DataContainer; public final class SimpleXROSubobjectRegistry implements XROSubobjectRegistry { - private final HandlerRegistry handlers = new HandlerRegistry<>(); + private final HandlerRegistry handlers = + new HandlerRegistry<>(); public AutoCloseable registerSubobjectParser(final int subobjectType, final XROSubobjectParser parser) { Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Values.UNSIGNED_SHORT_MAX_VALUE); @@ -35,7 +34,8 @@ public final class SimpleXROSubobjectRegistry implements XROSubobjectRegistry { } @Override - public Subobject parseSubobject(final int type, final ByteBuf buffer, final boolean mandatory) throws PCEPDeserializerException { + public Subobject parseSubobject(final int type, final ByteBuf buffer, final boolean mandatory) + throws PCEPDeserializerException { Preconditions.checkArgument(type >= 0 && type <= Values.UNSIGNED_SHORT_MAX_VALUE); final XROSubobjectParser parser = this.handlers.getParser(type); if (parser == null) { @@ -46,7 +46,8 @@ public final class SimpleXROSubobjectRegistry implements XROSubobjectRegistry { @Override public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) { - final XROSubobjectSerializer serializer = this.handlers.getSerializer(subobject.getSubobjectType().getImplementedInterface()); + final XROSubobjectSerializer serializer = this.handlers.getSerializer( + subobject.getSubobjectType().getImplementedInterface()); if (serializer == null) { return; } diff --git a/pcep/spi/src/test/java/org/opendaylight/protocol/pcep/spi/APITest.java b/pcep/spi/src/test/java/org/opendaylight/protocol/pcep/spi/APITest.java index 74b4b2adfb..a4f5d6e652 100644 --- a/pcep/spi/src/test/java/org/opendaylight/protocol/pcep/spi/APITest.java +++ b/pcep/spi/src/test/java/org/opendaylight/protocol/pcep/spi/APITest.java @@ -23,7 +23,8 @@ public class APITest { final PCEPDeserializerException e = new PCEPDeserializerException("Some error message."); assertEquals("Some error message.", e.getMessage()); - final PCEPDeserializerException e1 = new PCEPDeserializerException("Some error message.", new IllegalArgumentException()); + final PCEPDeserializerException e1 = new PCEPDeserializerException("Some error message.", + new IllegalArgumentException()); assertEquals("Some error message.", e1.getMessage()); assertTrue(e1.getCause() instanceof IllegalArgumentException); } @@ -45,7 +46,8 @@ public class APITest { assertFalse(un.isIgnore()); assertFalse(un.isProcessingRule()); assertEquals(PCEPErrors.CT_AND_SETUP_PRIORITY_DO_NOT_FORM_TE_CLASS, un.getError()); - assertEquals(PCEPErrors.CT_AND_SETUP_PRIORITY_DO_NOT_FORM_TE_CLASS.getErrorType(), un.getErrors().get(0).getErrorObject().getType().shortValue()); + assertEquals(PCEPErrors.CT_AND_SETUP_PRIORITY_DO_NOT_FORM_TE_CLASS.getErrorType(), + un.getErrors().get(0).getErrorObject().getType().shortValue()); final Object o = new CCloseBuilder().build(); UnknownObject unknown = new UnknownObject(PCEPErrors.LSP_RSVP_ERROR, o); diff --git a/pcep/spi/src/test/java/org/opendaylight/protocol/pcep/spi/AbstractMessageParserTest.java b/pcep/spi/src/test/java/org/opendaylight/protocol/pcep/spi/AbstractMessageParserTest.java index 5b4bd73da2..50a345bbc9 100644 --- a/pcep/spi/src/test/java/org/opendaylight/protocol/pcep/spi/AbstractMessageParserTest.java +++ b/pcep/spi/src/test/java/org/opendaylight/protocol/pcep/spi/AbstractMessageParserTest.java @@ -8,18 +8,25 @@ package org.opendaylight.protocol.pcep.spi; import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.only; +import static org.mockito.Mockito.verify; import com.google.common.collect.Lists; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; 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.Pcerr; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Pcrep; @@ -33,6 +40,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.vendor.information.objects.VendorInformationObject; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.objects.VendorInformationObjectBuilder; +@RunWith(MockitoJUnitRunner.class) public class AbstractMessageParserTest { private static final EnterpriseNumber EN = new EnterpriseNumber(0L); @@ -59,9 +67,9 @@ public class AbstractMessageParserTest { if (objects.get(0) instanceof VendorInformationObject) { final RepliesBuilder repsBuilder = new RepliesBuilder(); repsBuilder.setVendorInformationObject(addVendorInformationObjects(objects)); - final PcrepBuilder builder = new PcrepBuilder(); - builder.setPcrepMessage(new PcrepMessageBuilder().setReplies(Lists.newArrayList(repsBuilder.build())).build()); - return builder.build(); + return new PcrepBuilder().setPcrepMessage( + new PcrepMessageBuilder().setReplies(Arrays.asList(repsBuilder.build())).build()) + .build(); } else if (objects.get(0) instanceof ErrorObject) { final short errorType = ((ErrorObject) objects.get(0)).getType(); final short errorValue = ((ErrorObject) objects.get(0)).getValue(); @@ -73,13 +81,15 @@ public class AbstractMessageParserTest { @Before public void setUp() throws PCEPDeserializerException { - MockitoAnnotations.initMocks(this); this.object = new ErrorObjectBuilder().setType((short) 1).setValue((short) 1).build(); this.viObject = new VendorInformationObjectBuilder().setEnterpriseNumber(EN).build(); - Mockito.doNothing().when(this.registry).serializeVendorInformationObject(Mockito.any(VendorInformationObject.class), Mockito.any(ByteBuf.class)); - Mockito.doReturn(Optional.of(this.viObject)).when(this.registry).parseVendorInformationObject(Mockito.eq(EN), Mockito.eq(new ObjectHeaderImpl(true, true)), Mockito.any(ByteBuf.class)); - Mockito.doNothing().when(this.registry).serializeObject(Mockito.any(Object.class), Mockito.any(ByteBuf.class)); - Mockito.doReturn(this.object).when(this.registry).parseObject(13, 1, new ObjectHeaderImpl(true, true), Unpooled.wrappedBuffer(new byte[] { 0, 0, 1, 1 })); + doNothing().when(this.registry).serializeVendorInformationObject(any(VendorInformationObject.class), + any(ByteBuf.class)); + doReturn(Optional.of(this.viObject)).when(this.registry).parseVendorInformationObject(eq(EN), + eq(new ObjectHeaderImpl(true, true)), any(ByteBuf.class)); + doNothing().when(this.registry).serializeObject(any(Object.class), any(ByteBuf.class)); + doReturn(this.object).when(this.registry).parseObject(13, 1, new ObjectHeaderImpl(true, true), + Unpooled.wrappedBuffer(new byte[] { 0, 0, 1, 1 })); } @Test @@ -88,9 +98,10 @@ public class AbstractMessageParserTest { final ByteBuf buffer = Unpooled.buffer(); a.serializeObject(this.object, buffer); - Mockito.verify(this.registry, Mockito.only()).serializeObject(Mockito.any(Object.class), Mockito.any(ByteBuf.class)); + verify(this.registry, only()).serializeObject(any(Object.class), any(ByteBuf.class)); - final Message b = a.parseMessage(Unpooled.wrappedBuffer(new byte[] {0x0D, 0x13, 0, 0x08, 0, 0, 1, 1 }), Collections.emptyList()); + final Message b = a.parseMessage(Unpooled.wrappedBuffer(new byte[] {0x0D, 0x13, 0, 0x08, 0, 0, 1, 1 }), + Collections.emptyList()); assertEquals(this.object, ((Pcerr) b).getPcerrMessage().getErrors().get(0).getErrorObject()); } @@ -101,10 +112,13 @@ public class AbstractMessageParserTest { final ByteBuf buffer = Unpooled.buffer(); parser.serializeVendorInformationObjects(Lists.newArrayList(this.viObject), buffer); - Mockito.verify(this.registry, Mockito.only()).serializeVendorInformationObject(Mockito.any(VendorInformationObject.class), Mockito.any(ByteBuf.class)); + verify(this.registry, only()).serializeVendorInformationObject(any(VendorInformationObject.class), + any(ByteBuf.class)); - final Message msg = parser.parseMessage(Unpooled.wrappedBuffer(new byte[] {0x22, 0x13, 0x00, 0x08, 0, 0, 0, 0 }), Collections.emptyList()); + final Message msg = parser.parseMessage( + Unpooled.wrappedBuffer(new byte[] { 0x22, 0x13, 0x00, 0x08, 0, 0, 0, 0 }), Collections.emptyList()); - assertEquals(this.viObject, ((Pcrep)msg).getPcrepMessage().getReplies().get(0).getVendorInformationObject().get(0)); + assertEquals(this.viObject, ((Pcrep)msg).getPcrepMessage().getReplies().get(0).getVendorInformationObject() + .get(0)); } } diff --git a/pcep/spi/src/test/java/org/opendaylight/protocol/pcep/spi/AbstractObjectWithTlvsTest.java b/pcep/spi/src/test/java/org/opendaylight/protocol/pcep/spi/AbstractObjectWithTlvsTest.java index 4f7b007604..201665afd3 100644 --- a/pcep/spi/src/test/java/org/opendaylight/protocol/pcep/spi/AbstractObjectWithTlvsTest.java +++ b/pcep/spi/src/test/java/org/opendaylight/protocol/pcep/spi/AbstractObjectWithTlvsTest.java @@ -8,17 +8,23 @@ package org.opendaylight.protocol.pcep.spi; import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.only; +import static org.mockito.Mockito.verify; import com.google.common.collect.Lists; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; +import java.util.Collections; import java.util.List; import java.util.Optional; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; 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.Object; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader; @@ -30,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.vendor.information.tlvs.VendorInformationTlv; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.tlvs.VendorInformationTlvBuilder; +@RunWith(MockitoJUnitRunner.StrictStubs.class) public class AbstractObjectWithTlvsTest { private static final EnterpriseNumber EN = new EnterpriseNumber(0L); @@ -46,53 +53,54 @@ public class AbstractObjectWithTlvsTest { private class Abs extends AbstractObjectWithTlvsParser { - protected Abs(TlvRegistry tlvReg, VendorInformationTlvRegistry viTlvReg) { + protected Abs(final TlvRegistry tlvReg, final VendorInformationTlvRegistry viTlvReg) { super(tlvReg, viTlvReg, 0, 0); } @Override - public Object parseObject(ObjectHeader header, ByteBuf buffer) { + public Object parseObject(final ObjectHeader header, final ByteBuf buffer) { return null; } @Override - public void serializeObject(Object object, ByteBuf buffer) { + public void serializeObject(final Object object, final ByteBuf buffer) { } @Override - public void addTlv(final TlvsBuilder builder, final Tlv tlv) { - builder.setOfList((OfList) tlv); + public void addTlv(final TlvsBuilder builder, final Tlv newTlv) { + builder.setOfList((OfList) newTlv); } @Override - protected void addVendorInformationTlvs(TlvsBuilder builder, List tlvs) { + protected void addVendorInformationTlvs(final TlvsBuilder builder, final List tlvs) { builder.setVendorInformationTlv(tlvs); } } @Before public void setUp() throws PCEPDeserializerException { - MockitoAnnotations.initMocks(this); - this.tlv = new OfListBuilder().setCodes(Lists.newArrayList(new OfId(10))).build(); + this.tlv = new OfListBuilder().setCodes(Collections.singletonList(new OfId(10))).build(); this.viTlv = new VendorInformationTlvBuilder().setEnterpriseNumber(EN).build(); - Mockito.doNothing().when(this.viTlvRegistry).serializeVendorInformationTlv(Mockito.any(VendorInformationTlv.class), Mockito.any(ByteBuf.class)); - Mockito.doReturn(Optional.of(this.viTlv)).when(this.viTlvRegistry).parseVendorInformationTlv(EN, Unpooled.wrappedBuffer(new byte[0])); - Mockito.doNothing().when(this.tlvRegistry).serializeTlv(Mockito.any(Tlv.class), Mockito.any(ByteBuf.class)); - Mockito.doReturn(this.tlv).when(this.tlvRegistry).parseTlv(4, Unpooled.wrappedBuffer(new byte[] { 5, 6 })); + doNothing().when(this.viTlvRegistry).serializeVendorInformationTlv(any(VendorInformationTlv.class), + any(ByteBuf.class)); + doReturn(Optional.of(this.viTlv)).when(this.viTlvRegistry).parseVendorInformationTlv(EN, + Unpooled.wrappedBuffer(new byte[0])); + doNothing().when(this.tlvRegistry).serializeTlv(any(Tlv.class), any(ByteBuf.class)); + doReturn(this.tlv).when(this.tlvRegistry).parseTlv(4, Unpooled.wrappedBuffer(new byte[] { 5, 6 })); } @Test public void testParseTlvs() throws PCEPDeserializerException { - Abs a = new Abs(this.tlvRegistry, this.viTlvRegistry); + Abs abs = new Abs(this.tlvRegistry, this.viTlvRegistry); ByteBuf buffer = Unpooled.buffer(); - a.serializeTlv(this.tlv, buffer); + abs.serializeTlv(this.tlv, buffer); - Mockito.verify(this.tlvRegistry, Mockito.only()).serializeTlv(Mockito.any(Tlv.class), Mockito.any(ByteBuf.class)); + verify(this.tlvRegistry, only()).serializeTlv(any(Tlv.class), any(ByteBuf.class)); - TlvsBuilder b = new TlvsBuilder(); - a.parseTlvs(b, Unpooled.wrappedBuffer(new byte[] { 0, 4, 0, 2, 5, 6, 0, 0 })); + TlvsBuilder builder = new TlvsBuilder(); + abs.parseTlvs(builder, Unpooled.wrappedBuffer(new byte[] { 0, 4, 0, 2, 5, 6, 0, 0 })); - assertEquals(this.tlv, b.getOfList()); + assertEquals(this.tlv, builder.getOfList()); } @Test @@ -101,10 +109,12 @@ public class AbstractObjectWithTlvsTest { final ByteBuf buffer = Unpooled.buffer(); parser.serializeVendorInformationTlvs(Lists.newArrayList(this.viTlv), buffer); - Mockito.verify(this.viTlvRegistry, Mockito.only()).serializeVendorInformationTlv(Mockito.any(VendorInformationTlv.class), Mockito.any(ByteBuf.class)); + verify(this.viTlvRegistry, only()).serializeVendorInformationTlv(any(VendorInformationTlv.class), + any(ByteBuf.class)); final TlvsBuilder tlvsBuilder = new TlvsBuilder(); - parser.parseTlvs(tlvsBuilder, Unpooled.wrappedBuffer(new byte[] { 0x00, 0x07, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00 })); + parser.parseTlvs(tlvsBuilder, Unpooled.wrappedBuffer( + new byte[] { 0x00, 0x07, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00 })); assertEquals(this.viTlv, tlvsBuilder.getVendorInformationTlv().get(0)); } } diff --git a/pcep/spi/src/test/java/org/opendaylight/protocol/pcep/spi/RegistryTest.java b/pcep/spi/src/test/java/org/opendaylight/protocol/pcep/spi/RegistryTest.java index 2a1e0116e5..8ebe7587ba 100644 --- a/pcep/spi/src/test/java/org/opendaylight/protocol/pcep/spi/RegistryTest.java +++ b/pcep/spi/src/test/java/org/opendaylight/protocol/pcep/spi/RegistryTest.java @@ -7,6 +7,11 @@ */ package org.opendaylight.protocol.pcep.spi; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; + import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import java.util.ArrayList; @@ -14,9 +19,9 @@ import java.util.Collections; import java.util.List; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.opendaylight.protocol.pcep.spi.pojo.AbstractPCEPExtensionProviderActivator; import org.opendaylight.protocol.pcep.spi.pojo.ServiceLoaderPCEPExtensionProviderContext; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber; @@ -44,6 +49,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.IpPrefixCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.LabelCase; +@RunWith(MockitoJUnitRunner.StrictStubs.class) public class RegistryTest { @Mock @@ -105,37 +111,29 @@ public class RegistryTest { @Before public void setUp() throws PCEPDeserializerException { - MockitoAnnotations.initMocks(this); - Mockito.doReturn(null).when(this.xroParser).parseSubobject(Mockito.any(ByteBuf.class), Mockito.anyBoolean()); - Mockito.doNothing().when(this.xroSerializer).serializeSubobject(Mockito.any(Subobject.class), Mockito.any(ByteBuf.class)); - - Mockito.doReturn(null).when(this.rroParser).parseSubobject(Mockito.any(ByteBuf.class)); - Mockito.doNothing().when(this.rroSerializer).serializeSubobject(Mockito.any(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.Subobject.class), Mockito.any(ByteBuf.class)); - - Mockito.doReturn(null).when(this.eroParser).parseSubobject(Mockito.any(ByteBuf.class), Mockito.anyBoolean()); - Mockito.doNothing().when(this.eroSerializer).serializeSubobject(Mockito.any(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.Subobject.class), Mockito.any(ByteBuf.class)); - - Mockito.doReturn(this.viTlv).when(this.tlvParser).parseTlv(Mockito.any(ByteBuf.class)); - Mockito.doNothing().when(this.tlvSerializer).serializeTlv(Mockito.any(Tlv.class), Mockito.any(ByteBuf.class)); + doReturn(null).when(this.xroParser).parseSubobject(any(ByteBuf.class), anyBoolean()); + doNothing().when(this.xroSerializer).serializeSubobject(any(Subobject.class), any(ByteBuf.class)); - Mockito.doReturn(5).when(this.objectParser).getObjectClass(); - Mockito.doReturn(1).when(this.objectParser).getObjectType(); - Mockito.doReturn(new OpenBuilder().build()).when(this.objectParser).parseObject(Mockito.any(ObjectHeader.class), Mockito.any(ByteBuf.class)); - Mockito.doNothing().when(this.objectSerializer).serializeObject(Mockito.any(Object.class), Mockito.any(ByteBuf.class)); + doReturn(this.viTlv).when(this.tlvParser).parseTlv(any(ByteBuf.class)); + doNothing().when(this.tlvSerializer).serializeTlv(any(Tlv.class), any(ByteBuf.class)); - Mockito.doReturn(null).when(this.msgParser).parseMessage(Mockito.any(ByteBuf.class), Mockito.any(List.class)); - Mockito.doNothing().when(this.msgSerializer).serializeMessage(Mockito.any(Message.class), Mockito.any(ByteBuf.class)); + doReturn(5).when(this.objectParser).getObjectClass(); + doReturn(1).when(this.objectParser).getObjectType(); + doReturn(new OpenBuilder().build()).when(this.objectParser).parseObject(any(ObjectHeader.class), + any(ByteBuf.class)); + doNothing().when(this.objectSerializer).serializeObject(any(Object.class), any(ByteBuf.class)); - Mockito.doReturn(null).when(this.labelParser).parseLabel(Mockito.any(ByteBuf.class)); - Mockito.doNothing().when(this.labelSerializer).serializeLabel(Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.any(LabelType.class), Mockito.any(ByteBuf.class)); + doReturn(null).when(this.msgParser).parseMessage(any(ByteBuf.class), any(List.class)); + doNothing().when(this.msgSerializer).serializeMessage(any(Message.class), any(ByteBuf.class)); - Mockito.doReturn(this.es).when(this.esi).getEnterpriseSpecificInformation(); + doNothing().when(this.labelSerializer).serializeLabel(anyBoolean(), anyBoolean(), any(LabelType.class), + any(ByteBuf.class)); - Mockito.doReturn(EnterpriseSpecificInformation.class).when(this.es).getImplementedInterface(); + doReturn(this.es).when(this.esi).getEnterpriseSpecificInformation(); - Mockito.doReturn(this.es).when(this.viTlv).getEnterpriseSpecificInformation(); + doReturn(this.es).when(this.viTlv).getEnterpriseSpecificInformation(); - Mockito.doReturn(EnterpriseSpecificInformation.class).when(this.es).getImplementedInterface(); + doReturn(EnterpriseSpecificInformation.class).when(this.es).getImplementedInterface(); } @Test @@ -162,20 +160,27 @@ public class RegistryTest { this.regs.add(this.ctx.registerLabelSerializer(Type1LabelCase.class, this.labelSerializer)); this.regs.add(this.ctx.registerVendorInformationObjectParser(new EnterpriseNumber(10L), this.objectParser)); - this.regs.add(this.ctx.registerVendorInformationObjectSerializer(EnterpriseSpecificInformation.class, this.objectSerializer)); + this.regs.add(this.ctx.registerVendorInformationObjectSerializer(EnterpriseSpecificInformation.class, + this.objectSerializer)); this.regs.add(this.ctx.registerVendorInformationTlvParser(new EnterpriseNumber(12L), this.tlvParser)); - this.regs.add(this.ctx.registerVendorInformationTlvSerializer(EnterpriseSpecificInformation.class, this.tlvSerializer)); + this.regs.add(this.ctx.registerVendorInformationTlvSerializer(EnterpriseSpecificInformation.class, + this.tlvSerializer)); final ByteBuf buffer = Unpooled.buffer(); this.ctx.getXROSubobjectHandlerRegistry().parseSubobject(2, buffer, false); - this.ctx.getXROSubobjectHandlerRegistry().serializeSubobject(new SubobjectBuilder().setSubobjectType(new AsNumberCaseBuilder().build()).build(), buffer); + this.ctx.getXROSubobjectHandlerRegistry().serializeSubobject(new SubobjectBuilder() + .setSubobjectType(new AsNumberCaseBuilder().build()).build(), buffer); this.ctx.getEROSubobjectHandlerRegistry().parseSubobject(3, buffer, true); - this.ctx.getEROSubobjectHandlerRegistry().serializeSubobject(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.SubobjectBuilder().setSubobjectType(new AsNumberCaseBuilder().build()).build(), buffer); + this.ctx.getEROSubobjectHandlerRegistry().serializeSubobject(new org.opendaylight.yang.gen.v1.urn.opendaylight + .params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.SubobjectBuilder() + .setSubobjectType(new AsNumberCaseBuilder().build()).build(), buffer); this.ctx.getRROSubobjectHandlerRegistry().parseSubobject(4, buffer); - this.ctx.getRROSubobjectHandlerRegistry().serializeSubobject(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.SubobjectBuilder().setSubobjectType(new IpPrefixCaseBuilder().build()).build(), buffer); + this.ctx.getRROSubobjectHandlerRegistry().serializeSubobject(new org.opendaylight.yang.gen.v1.urn.opendaylight + .params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.SubobjectBuilder() + .setSubobjectType(new IpPrefixCaseBuilder().build()).build(), buffer); this.ctx.getLabelHandlerRegistry().parseLabel(1, buffer); this.ctx.getLabelHandlerRegistry().serializeLabel(true, false, new Type1LabelCaseBuilder().build(), buffer); @@ -189,7 +194,8 @@ public class RegistryTest { this.ctx.getMessageHandlerRegistry().parseMessage(6, buffer, Collections.emptyList()); this.ctx.getMessageHandlerRegistry().serializeMessage(new KeepaliveBuilder().build(), buffer); - this.ctx.getVendorInformationObjectRegistry().parseVendorInformationObject(new EnterpriseNumber(10L), new ObjectHeaderImpl(true, false), buffer); + this.ctx.getVendorInformationObjectRegistry().parseVendorInformationObject(new EnterpriseNumber(10L), + new ObjectHeaderImpl(true, false), buffer); this.ctx.getVendorInformationObjectRegistry().serializeVendorInformationObject(this.esi, buffer); this.ctx.getVendorInformationTlvRegistry().parseVendorInformationTlv(new EnterpriseNumber(12L), buffer); diff --git a/pcep/spi/src/test/java/org/opendaylight/protocol/pcep/spi/UtilsTest.java b/pcep/spi/src/test/java/org/opendaylight/protocol/pcep/spi/UtilsTest.java index 96c2de0c5d..138ae53e10 100644 --- a/pcep/spi/src/test/java/org/opendaylight/protocol/pcep/spi/UtilsTest.java +++ b/pcep/spi/src/test/java/org/opendaylight/protocol/pcep/spi/UtilsTest.java @@ -10,11 +10,12 @@ package org.opendaylight.protocol.pcep.spi; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.opendaylight.protocol.pcep.spi.VendorInformationUtil.VENDOR_INFORMATION_OBJECT_CLASS; +import static org.opendaylight.protocol.pcep.spi.VendorInformationUtil.VENDOR_INFORMATION_OBJECT_TYPE; +import static org.opendaylight.protocol.pcep.spi.VendorInformationUtil.VENDOR_INFORMATION_TLV_TYPE; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; import org.junit.Test; import org.opendaylight.protocol.util.ByteArray; @@ -128,111 +129,16 @@ public class UtilsTest { @Test public void testVendorInformationUtil() { - assertTrue(VendorInformationUtil.isVendorInformationTlv(VendorInformationUtil.VENDOR_INFORMATION_TLV_TYPE)); - assertFalse(VendorInformationUtil.isVendorInformationTlv(VendorInformationUtil.VENDOR_INFORMATION_OBJECT_CLASS)); - - assertTrue(VendorInformationUtil.isVendorInformationObject(VendorInformationUtil.VENDOR_INFORMATION_OBJECT_CLASS, VendorInformationUtil.VENDOR_INFORMATION_OBJECT_TYPE)); - assertFalse(VendorInformationUtil.isVendorInformationObject(VendorInformationUtil.VENDOR_INFORMATION_OBJECT_CLASS, VendorInformationUtil.VENDOR_INFORMATION_TLV_TYPE)); - assertFalse(VendorInformationUtil.isVendorInformationObject(VendorInformationUtil.VENDOR_INFORMATION_TLV_TYPE, VendorInformationUtil.VENDOR_INFORMATION_OBJECT_TYPE)); - assertFalse(VendorInformationUtil.isVendorInformationObject(VendorInformationUtil.VENDOR_INFORMATION_OBJECT_TYPE, VendorInformationUtil.VENDOR_INFORMATION_OBJECT_CLASS)); - } - - @Test(expected=UnsupportedOperationException.class) - public void testVendorInformationUtilPrivateConstructor() throws Throwable { - final Constructor c = VendorInformationUtil.class.getDeclaredConstructor(); - c.setAccessible(true); - try { - c.newInstance(); - } catch (final InvocationTargetException e) { - throw e.getCause(); - } - } - - @Test(expected=UnsupportedOperationException.class) - public void testEROSubobjectUtilPrivateConstructor() throws Throwable { - final Constructor c = EROSubobjectUtil.class.getDeclaredConstructor(); - c.setAccessible(true); - try { - c.newInstance(); - } catch (final InvocationTargetException e) { - throw e.getCause(); - } - } - - @Test(expected=UnsupportedOperationException.class) - public void testRROSubobjectUtilPrivateConstructor() throws Throwable { - final Constructor c = RROSubobjectUtil.class.getDeclaredConstructor(); - c.setAccessible(true); - try { - c.newInstance(); - } catch (final InvocationTargetException e) { - throw e.getCause(); - } - } - - @Test(expected=UnsupportedOperationException.class) - public void testTlvUtilPrivateConstructor() throws Throwable { - final Constructor c = TlvUtil.class.getDeclaredConstructor(); - c.setAccessible(true); - try { - c.newInstance(); - } catch (final InvocationTargetException e) { - throw e.getCause(); - } - } - - @Test(expected=UnsupportedOperationException.class) - public void testXROSubobjectUtilPrivateConstructor() throws Throwable { - final Constructor c = XROSubobjectUtil.class.getDeclaredConstructor(); - c.setAccessible(true); - try { - c.newInstance(); - } catch (final InvocationTargetException e) { - throw e.getCause(); - } - } - - @Test(expected=UnsupportedOperationException.class) - public void testObjectUtilPrivateConstructor() throws Throwable { - final Constructor c = ObjectUtil.class.getDeclaredConstructor(); - c.setAccessible(true); - try { - c.newInstance(); - } catch (final InvocationTargetException e) { - throw e.getCause(); - } - } - - @Test(expected=UnsupportedOperationException.class) - public void testMessageUtilPrivateConstructor() throws Throwable { - final Constructor c = MessageUtil.class.getDeclaredConstructor(); - c.setAccessible(true); - try { - c.newInstance(); - } catch (final InvocationTargetException e) { - throw e.getCause(); - } - } - - @Test(expected=UnsupportedOperationException.class) - public void testLabelUtilPrivateConstructor() throws Throwable { - final Constructor c = LabelUtil.class.getDeclaredConstructor(); - c.setAccessible(true); - try { - c.newInstance(); - } catch (final InvocationTargetException e) { - throw e.getCause(); - } - } - - @Test(expected=UnsupportedOperationException.class) - public void testPCEPMessageConstantsPrivateConstructor() throws Throwable { - final Constructor c = PCEPMessageConstants.class.getDeclaredConstructor(); - c.setAccessible(true); - try { - c.newInstance(); - } catch (final InvocationTargetException e) { - throw e.getCause(); - } + assertTrue(VendorInformationUtil.isVendorInformationTlv(VENDOR_INFORMATION_TLV_TYPE)); + assertFalse(VendorInformationUtil.isVendorInformationTlv(VENDOR_INFORMATION_OBJECT_CLASS)); + + assertTrue(VendorInformationUtil.isVendorInformationObject(VENDOR_INFORMATION_OBJECT_CLASS, + VENDOR_INFORMATION_OBJECT_TYPE)); + assertFalse(VendorInformationUtil.isVendorInformationObject(VENDOR_INFORMATION_OBJECT_CLASS, + VENDOR_INFORMATION_TLV_TYPE)); + assertFalse(VendorInformationUtil.isVendorInformationObject(VENDOR_INFORMATION_TLV_TYPE, + VENDOR_INFORMATION_OBJECT_TYPE)); + assertFalse(VendorInformationUtil.isVendorInformationObject(VENDOR_INFORMATION_OBJECT_TYPE, + VENDOR_INFORMATION_OBJECT_CLASS)); } } -- 2.36.6