X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=pcep%2Fbase-parser%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fpcep%2Fparser%2Fobject%2FPCEPNotificationObjectParser.java;fp=pcep%2Fbase-parser%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fpcep%2Fparser%2Fobject%2FPCEPNotificationObjectParser.java;h=df8c1922c297db5963456041e84c750ec556edc2;hb=59bd8a58570b93fef65340808e37cab3c6fced8c;hp=b99ae7c2e566311e4af66c10d53138e3cbe9584d;hpb=3b658310b793d4882ce59198a6d2563ce6ba114d;p=bgpcep.git diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPNotificationObjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPNotificationObjectParser.java index b99ae7c2e5..df8c1922c2 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPNotificationObjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPNotificationObjectParser.java @@ -7,9 +7,8 @@ */ package org.opendaylight.protocol.pcep.parser.object; -import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte; +import static com.google.common.base.Preconditions.checkArgument; -import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import java.util.List; @@ -47,8 +46,7 @@ public final class PCEPNotificationObjectParser extends AbstractObjectWithTlvsPa @Override public CNotification parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException { - Preconditions.checkArgument(bytes != null && bytes.isReadable(), - "Array of bytes is mandatory. Can't be null or empty."); + checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); bytes.skipBytes(NT_F_OFFSET); final CNotificationBuilder builder = new CNotificationBuilder() .setIgnore(header.isIgnore()) @@ -68,34 +66,28 @@ public final class PCEPNotificationObjectParser extends AbstractObjectWithTlvsPa @Override public void serializeObject(final Object object, final ByteBuf buffer) { - Preconditions.checkArgument(object instanceof CNotification, - "Wrong instance of PCEPObject. Passed %s. Needed CNotificationObject.", - object.getClass()); + checkArgument(object instanceof CNotification, + "Wrong instance of PCEPObject. Passed %s. Needed CNotificationObject.", object.getClass()); final CNotification notObj = (CNotification) object; final ByteBuf body = Unpooled.buffer(); body.writeZero(NT_F_OFFSET); - Preconditions.checkArgument(notObj.getType() != null, "Type is mandatory."); - writeUnsignedByte(notObj.getType(), body); - Preconditions.checkArgument(notObj.getValue() != null, "Value is mandatory."); - writeUnsignedByte(notObj.getValue(), body); + ByteBufUtils.writeMandatory(body, notObj.getType(), "Type"); + ByteBufUtils.writeMandatory(body, notObj.getValue(), "Value"); serializeTlvs(notObj.getTlvs(), body); ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer); } public void serializeTlvs(final Tlvs tlvs, final ByteBuf body) { - if (tlvs == null) { - return; + if (tlvs != null) { + if (tlvs.getOverloadDuration() != null) { + serializeTlv(tlvs.getOverloadDuration(), body); + } + serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body); } - if (tlvs.getOverloadDuration() != null) { - serializeTlv(tlvs.getOverloadDuration(), body); - } - serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body); } @Override - protected void addVendorInformationTlvs( - final CNotificationBuilder builder, - final List tlvs) { + protected void addVendorInformationTlvs(final CNotificationBuilder builder, final List tlvs) { if (!tlvs.isEmpty()) { builder.setTlvs(new TlvsBuilder(builder.getTlvs()).setVendorInformationTlv(tlvs).build()); }