* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.protocol.pcep.parser.object;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.pcep.spi.VendorInformationUtil.VENDOR_INFORMATION_OBJECT_CLASS;
import static org.opendaylight.protocol.pcep.spi.VendorInformationUtil.VENDOR_INFORMATION_OBJECT_TYPE;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.pcep.spi.CommonObjectParser;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.objects.VendorInformationObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.objects.VendorInformationObjectBuilder;
+import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
public abstract class AbstractVendorInformationObjectParser extends CommonObjectParser
implements ObjectSerializer, EnterpriseSpecificInformationParser {
-
public AbstractVendorInformationObjectParser(final int objectClass, final int objectType) {
super(objectClass, objectType);
}
@Override
public final Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(),
- "Array of bytes is mandatory. Can't be null or empty.");
- final VendorInformationObjectBuilder builder = new VendorInformationObjectBuilder();
- builder.setEnterpriseNumber(new EnterpriseNumber(getEnterpriseNumber()));
- builder.setEnterpriseSpecificInformation(parseEnterpriseSpecificInformation(buffer));
- return builder.build();
+ checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ return new VendorInformationObjectBuilder()
+ .setEnterpriseNumber(new EnterpriseNumber(getEnterpriseNumber()))
+ .setEnterpriseSpecificInformation(parseEnterpriseSpecificInformation(buffer))
+ .build();
}
@Override
public final void serializeObject(final Object object, final ByteBuf buffer) {
- Preconditions.checkArgument(object instanceof VendorInformationObject,
+ checkArgument(object instanceof VendorInformationObject,
"Wrong instance of PCEPObject. Passed %s. Needed VendorInformationObject.", object.getClass());
final ByteBuf body = Unpooled.buffer();
- writeUnsignedInt(getEnterpriseNumber().getValue(), body);
+ ByteBufUtils.write(body, getEnterpriseNumber().getValue());
serializeEnterpriseSpecificInformation(((VendorInformationObject) object).getEnterpriseSpecificInformation(),
body);
ObjectUtil.formatSubobject(VENDOR_INFORMATION_OBJECT_TYPE, VENDOR_INFORMATION_OBJECT_CLASS,
package org.opendaylight.protocol.pcep.parser.object;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
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.classtype.object.ClassType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.classtype.object.ClassTypeBuilder;
import org.opendaylight.yangtools.yang.common.Uint8;
+import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* Parser for {@link ClassType}.
*/
public final class PCEPClassTypeObjectParser extends CommonObjectParser implements ObjectSerializer {
-
private static final Logger LOG = LoggerFactory.getLogger(PCEPClassTypeObjectParser.class);
private static final int CLASS = 22;
private static final int TYPE = 1;
* Length of Class Type field in bits.
*/
private static final int CT_F_LENGTH = 3;
-
/**
* Reserved field bit length.
*/
private static final int RESERVED = 29;
-
/**
* Size of the object in bytes.
*/
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109
.ClassType classType = ((ClassType) object).getClassType();
checkArgument(classType != null, "ClassType is mandatory.");
- writeUnsignedByte(classType.getValue(), body);
+ ByteBufUtils.write(body, classType.getValue());
ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
}
}
package org.opendaylight.protocol.pcep.parser.object;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
final CClose obj = (CClose) object;
final ByteBuf body = Unpooled.buffer();
body.writeZero(RESERVED + FLAGS_F_LENGTH);
- checkArgument(obj.getReason() != null, "Reason is mandatory.");
- writeUnsignedByte(obj.getReason(), body);
+ ByteBufUtils.writeMandatory(body, obj.getReason(), "Reason");
serializeTlvs(obj.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) {
+ serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
}
- serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
}
@Override
*/
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;
@Override
public ErrorObject 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(FLAGS_F_LENGTH + RESERVED);
final ErrorObjectBuilder builder = new ErrorObjectBuilder()
.setIgnore(header.isIgnore())
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
- Preconditions.checkArgument(object instanceof ErrorObject,
- "Wrong instance of PCEPObject. Passed %s. Needed ErrorObject.", object.getClass());
+ checkArgument(object instanceof ErrorObject, "Wrong instance of PCEPObject. Passed %s. Needed ErrorObject.",
+ object.getClass());
final ErrorObject errObj = (ErrorObject) object;
final ByteBuf body = Unpooled.buffer();
body.writeZero(FLAGS_F_LENGTH + RESERVED);
- Preconditions.checkArgument(errObj.getType() != null, "Type is mandatory.");
- writeUnsignedByte(errObj.getType(), body);
- Preconditions.checkArgument(errObj.getValue() != null, "Value is mandatory.");
- writeUnsignedByte(errObj.getValue(), body);
+ ByteBufUtils.writeMandatory(body, errObj.getType(), "Type");
+ ByteBufUtils.writeMandatory(body, errObj.getValue(), "Value");
serializeTlvs(errObj.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.getReqMissing() != null) {
+ serializeTlv(tlvs.getReqMissing(), body);
+ }
+ serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
}
- if (tlvs.getReqMissing() != null) {
- serializeTlv(tlvs.getReqMissing(), body);
- }
- serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
}
@Override
- protected void addVendorInformationTlvs(
- final ErrorObjectBuilder builder,
- final List<VendorInformationTlv> tlvs) {
+ protected void addVendorInformationTlvs(final ErrorObjectBuilder builder, final List<VendorInformationTlv> tlvs) {
if (!tlvs.isEmpty()) {
builder.setTlvs(new TlvsBuilder(builder.getTlvs()).setVendorInformationTlv(tlvs).build());
}
*/
package org.opendaylight.protocol.pcep.parser.object;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBoolean;
+import static com.google.common.base.Preconditions.checkArgument;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
* Parser for {@link Xro}.
*/
public final class PCEPExcludeRouteObjectParser extends AbstractXROWithSubobjectsParser {
-
private static final int CLASS = 17;
private static final int TYPE = 1;
private static final int FLAGS_OFFSET = 3;
@Override
public Xro 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(FLAGS_OFFSET);
- final XroBuilder builder = new XroBuilder()
+ return new XroBuilder()
.setIgnore(header.isIgnore())
.setProcessingRule(header.isProcessingRule())
.setFlags(new Flags(bytes.readBoolean()))
- .setSubobject(parseSubobjects(bytes.slice()));
- return builder.build();
+ .setSubobject(parseSubobjects(bytes.slice()))
+ .build();
}
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
- Preconditions.checkArgument(object instanceof Xro,
- "Wrong instance of PCEPObject. Passed %s. Needed XroObject.", object.getClass());
+ checkArgument(object instanceof Xro, "Wrong instance of PCEPObject. Passed %s. Needed XroObject.",
+ object.getClass());
final Xro obj = (Xro) object;
final ByteBuf body = Unpooled.buffer();
body.writeZero(FLAGS_OFFSET);
- writeBoolean(obj.getFlags() != null ? obj.getFlags().isFail() : null, body);
+ final Flags flags = obj.getFlags();
+ body.writeBoolean(flags != null && Boolean.TRUE.equals(flags.isFail()));
serializeSubobject(obj.getSubobject(), body);
ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
}
package org.opendaylight.protocol.pcep.parser.object;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
.setOverBookingFactor(ByteBufUtils.readUint8(bytes));
final TlvsBuilder tlvsBuilder = new TlvsBuilder();
parseTlvs(tlvsBuilder, bytes.slice());
- builder.setTlvs(tlvsBuilder.build());
- return builder.build();
+ return builder.setTlvs(tlvsBuilder.build()).build();
}
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
- checkArgument(object instanceof Gc,
- "Wrong instance of PCEPObject. Passed %s. Needed GcObject.", object.getClass());
+ checkArgument(object instanceof Gc, "Wrong instance of PCEPObject. Passed %s. Needed GcObject.",
+ object.getClass());
final Gc specObj = (Gc) object;
final ByteBuf body = Unpooled.buffer();
- writeUnsignedByte(specObj.getMaxHop(), body);
- writeUnsignedByte(specObj.getMaxUtilization(), body);
- writeUnsignedByte(specObj.getMinUtilization(), body);
- writeUnsignedByte(specObj.getOverBookingFactor(), body);
+ ByteBufUtils.writeOrZero(body, specObj.getMaxHop());
+ ByteBufUtils.writeOrZero(body, specObj.getMaxUtilization());
+ ByteBufUtils.writeOrZero(body, specObj.getMinUtilization());
+ ByteBufUtils.writeOrZero(body, specObj.getOverBookingFactor());
serializeTlvs(specObj.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) {
+ serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
}
- serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
}
@Override
*/
package org.opendaylight.protocol.pcep.parser.object;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.pcep.spi.CommonObjectParser;
@Override
public LoadBalancing parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
- Preconditions.checkArgument(bytes != null && bytes.isReadable(),
- "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
if (bytes.readableBytes() != SIZE) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: "
+ bytes.readableBytes() + "; Expected: " + SIZE + ".");
}
bytes.skipBytes(RESERVED + FLAGS_F_LENGTH);
- final LoadBalancingBuilder builder = new LoadBalancingBuilder()
+ return new LoadBalancingBuilder()
.setIgnore(header.isIgnore())
.setProcessingRule(header.isProcessingRule())
.setMaxLsp(ByteBufUtils.readUint8(bytes))
- .setMinBandwidth(new Bandwidth(ByteArray.readAllBytes(bytes)));
- return builder.build();
+ .setMinBandwidth(new Bandwidth(ByteArray.readAllBytes(bytes)))
+ .build();
}
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
- Preconditions.checkArgument(object instanceof LoadBalancing,
- "Wrong instance of PCEPObject. Passed %s. Needed LoadBalancingObject.",
- object.getClass());
+ checkArgument(object instanceof LoadBalancing,
+ "Wrong instance of PCEPObject. Passed %s. Needed LoadBalancingObject.", object.getClass());
final LoadBalancing specObj = (LoadBalancing) object;
final ByteBuf body = Unpooled.buffer(SIZE);
body.writeZero(RESERVED + FLAGS_F_LENGTH);
- writeUnsignedByte(specObj.getMaxLsp(), body);
+ ByteBufUtils.writeOrZero(body, specObj.getMaxLsp());
writeFloat32(specObj.getMinBandwidth(), body);
ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
}
package org.opendaylight.protocol.pcep.parser.object;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
* lengths of fields in bytes
*/
private static final int FLAGS_SIZE = 8;
-
/*
* offsets of flags inside flags field in bits
*/
private static final int L_FLAG_OFFSET = 7;
-
private static final int RESERVED = 1;
public PCEPLspaObjectParser(final TlvRegistry tlvReg, final VendorInformationTlvRegistry viTlvReg) {
final TlvsBuilder tbuilder = new TlvsBuilder();
bytes.skipBytes(RESERVED);
parseTlvs(tbuilder, bytes.slice());
- builder.setTlvs(tbuilder.build());
- return builder.build();
+ return builder.setTlvs(tbuilder.build()).build();
}
@Override
writeAttributeFilter(lspaObj.getExcludeAny(), body);
writeAttributeFilter(lspaObj.getIncludeAny(), body);
writeAttributeFilter(lspaObj.getIncludeAll(), body);
- writeUnsignedByte(lspaObj.getSetupPriority(), body);
- writeUnsignedByte(lspaObj.getHoldPriority(), body);
+ ByteBufUtils.writeOrZero(body, lspaObj.getSetupPriority());
+ ByteBufUtils.writeOrZero(body, lspaObj.getHoldPriority());
final BitArray flags = new BitArray(FLAGS_SIZE);
flags.set(L_FLAG_OFFSET, lspaObj.isLocalProtectionDesired());
flags.toByteBuf(body);
}
public void serializeTlvs(final Tlvs tlvs, final ByteBuf body) {
- if (tlvs == null) {
- return;
+ if (tlvs != null) {
+ serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
}
- serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
}
private static void writeAttributeFilter(final AttributeFilter attributeFilter, final ByteBuf body) {
- writeUnsignedInt(attributeFilter != null ? attributeFilter.getValue() : null, body);
+ if (attributeFilter != null) {
+ ByteBufUtils.write(body, attributeFilter.getValue());
+ } else {
+ body.writeInt(0);
+ }
}
@Override
import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
*/
private static final int FLAGS_SIZE = 8;
private static final int METRIC_VALUE_F_LENGTH = 4;
-
/*
* offsets of fields in bytes
*/
private static final int RESERVED = 2;
-
/*
* flags offsets inside flags field in bits
*/
}
bytes.skipBytes(RESERVED);
final BitArray flags = BitArray.valueOf(bytes.readByte());
- final MetricBuilder builder = new MetricBuilder()
+ return new MetricBuilder()
.setIgnore(header.isIgnore())
.setProcessingRule(header.isProcessingRule())
.setBound(flags.get(B_FLAG_OFFSET))
.setComputed(flags.get(C_FLAG_OFFSET))
.setMetricType(ByteBufUtils.readUint8(bytes))
- .setValue(new Float32(ByteArray.readBytes(bytes, METRIC_VALUE_F_LENGTH)));
- return builder.build();
+ .setValue(new Float32(ByteArray.readBytes(bytes, METRIC_VALUE_F_LENGTH)))
+ .build();
}
@Override
flags.set(C_FLAG_OFFSET, mObj.isComputed());
flags.set(B_FLAG_OFFSET, mObj.isBound());
flags.toByteBuf(body);
- checkArgument(mObj.getMetricType() != null, "MetricType is mandatory.");
- writeUnsignedByte(mObj.getMetricType(), body);
+ ByteBufUtils.writeMandatory(body, mObj.getMetricType(), "MetricType");
writeFloat32(mObj.getValue(), body);
ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
}
import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
import org.opendaylight.protocol.util.BitArray;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.Monitoring;
final Uint32 monitoring = ByteBufUtils.readUint32(buffer);
final TlvsBuilder tbuilder = new TlvsBuilder();
parseTlvs(tbuilder, buffer.slice());
- final MonitoringBuilder builder = new MonitoringBuilder()
+ return new MonitoringBuilder()
.setFlags(flags)
.setMonitoringId(monitoring)
- .setTlvs(tbuilder.build());
- return builder.build();
+ .setTlvs(tbuilder.build())
+ .build();
}
@Override
flagBits.set(G_FLAG_POS, flags.isGeneral());
flagBits.set(L_FLAG_POS, flags.isLiveness());
flagBits.toByteBuf(body);
- ByteBufWriteUtil.writeUnsignedInt(monitoring.getMonitoringId(), body);
+ ByteBufUtils.writeOrZero(body, monitoring.getMonitoringId());
serializeTlvs(monitoring.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) {
+ serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
}
- serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
}
}
package org.opendaylight.protocol.pcep.parser.object;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
bytes.skipBytes(RESERVED_F_LENGTH);
final TlvsBuilder tlvsBuilder = new TlvsBuilder();
parseTlvs(tlvsBuilder, bytes.slice());
- final NoPathBuilder builder = new NoPathBuilder()
+ return new NoPathBuilder()
.setIgnore(header.isIgnore())
.setProcessingRule(header.isProcessingRule())
.setNatureOfIssue(issue)
.setUnsatisfiedConstraints(flags.get(C_FLAG_OFFSET))
- .setTlvs(tlvsBuilder.build());
- return builder.build();
+ .setTlvs(tlvsBuilder.build())
+ .build();
}
@Override
object.getClass());
final NoPath nPObj = (NoPath) object;
final ByteBuf body = Unpooled.buffer();
- checkArgument(nPObj.getNatureOfIssue() != null, "NatureOfIssue is mandatory.");
- writeUnsignedByte(nPObj.getNatureOfIssue(), body);
+ ByteBufUtils.writeMandatory(body, nPObj.getNatureOfIssue(), "NatureOfIssue");
final BitArray flags = new BitArray(FLAGS_SIZE);
flags.set(C_FLAG_OFFSET, nPObj.isUnsatisfiedConstraints());
flags.toByteBuf(body);
}
public void serializeTlvs(final Tlvs tlvs, final ByteBuf body) {
- if (tlvs == null) {
- return;
+ if (tlvs != null) {
+ if (tlvs.getNoPathVector() != null) {
+ serializeTlv(tlvs.getNoPathVector(), body);
+ }
+ serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
}
- if (tlvs.getNoPathVector() != null) {
- serializeTlv(tlvs.getNoPathVector(), body);
- }
- serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
}
@Override
*/
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;
@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())
@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<VendorInformationTlv> tlvs) {
+ protected void addVendorInformationTlvs(final CNotificationBuilder builder, final List<VendorInformationTlv> tlvs) {
if (!tlvs.isEmpty()) {
builder.setTlvs(new TlvsBuilder(builder.getTlvs()).setVendorInformationTlv(tlvs).build());
}
*/
package org.opendaylight.protocol.pcep.parser.object;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
+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;
@Override
public Of parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
- Preconditions.checkArgument(bytes != null && bytes.isReadable(),
- "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
final Uint16 ofId = ByteBufUtils.readUint16(bytes);
bytes.readBytes(RESERVED);
final TlvsBuilder tlvsBuilder = new TlvsBuilder();
parseTlvs(tlvsBuilder, bytes.slice());
- final OfBuilder builder = new OfBuilder()
+ return new OfBuilder()
.setIgnore(header.isIgnore())
.setProcessingRule(header.isProcessingRule())
.setCode(new OfId(ofId))
- .setTlvs(tlvsBuilder.build());
- return builder.build();
+ .setTlvs(tlvsBuilder.build())
+ .build();
}
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
- Preconditions.checkArgument(object instanceof Of,
- "Wrong instance of PCEPObject. Passed %s. Needed OfObject.", object.getClass());
+ checkArgument(object instanceof Of, "Wrong instance of PCEPObject. Passed %s. Needed OfObject.",
+ object.getClass());
final Of specObj = (Of) object;
final ByteBuf body = Unpooled.buffer();
- Preconditions.checkArgument(specObj.getCode() != null, "Code is mandatory");
- writeUnsignedShort(specObj.getCode().getValue(), body);
+
+ final OfId code = specObj.getCode();
+ checkArgument(code != null, "Code is mandatory");
+ ByteBufUtils.write(body, code.getValue());
body.writeZero(RESERVED);
serializeTlvs(specObj.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) {
+ serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
}
- serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
}
@Override
package org.opendaylight.protocol.pcep.parser.object;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
object.getClass());
final Open open = (Open) object;
final ByteBuf body = Unpooled.buffer();
- writeUnsignedByte(Uint8.valueOf(PCEP_VERSION << Byte.SIZE - VERSION_SF_LENGTH), body);
- writeUnsignedByte(open.getKeepalive(), body);
- writeUnsignedByte(open.getDeadTimer(), body);
- checkArgument(open.getSessionId() != null, "SessionId is mandatory.");
- writeUnsignedByte(open.getSessionId(), body);
+ body.writeByte(PCEP_VERSION << Byte.SIZE - VERSION_SF_LENGTH);
+ ByteBufUtils.writeOrZero(body, open.getKeepalive());
+ ByteBufUtils.writeOrZero(body, open.getDeadTimer());
+ ByteBufUtils.writeMandatory(body, open.getSessionId(), "SessionId");
serializeTlvs(open.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.getOfList() != null) {
+ serializeTlv(tlvs.getOfList(), body);
+ }
+ serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
}
- if (tlvs.getOfList() != null) {
- serializeTlv(tlvs.getOfList(), body);
- }
- serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
}
@Override
*/
package org.opendaylight.protocol.pcep.parser.object;
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.pcep.spi.CommonObjectParser;
import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.overload.object.Overload;
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
- Preconditions.checkArgument(object instanceof Overload,
- "Wrong instance of PCEPObject. Passed %s. Needed OverloadObject.", object.getClass());
+ checkArgument(object instanceof Overload, "Wrong instance of PCEPObject. Passed %s. Needed OverloadObject.",
+ object.getClass());
final Overload overload = (Overload) object;
final ByteBuf body = Unpooled.buffer(BODY_SIZE);
body.writeZero(RESERVED + FLAGS);
- ByteBufWriteUtil.writeUnsignedShort(overload.getDuration(), body);
+ ByteBufUtils.writeOrZero(body, overload.getDuration());
ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
}
@Override
public Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(),
- "Array of bytes is mandatory. Can't be null or empty.");
- final OverloadBuilder builder = new OverloadBuilder();
+ checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
buffer.readBytes(RESERVED + FLAGS);
- builder.setDuration(ByteBufUtils.readUint16(buffer));
- return builder.build();
+ return new OverloadBuilder()
+ .setDuration(ByteBufUtils.readUint16(buffer))
+ .build();
}
}
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.util.BitArray;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.proc.time.object.ProcTime;
final BitArray flagBits = new BitArray(FLAGS);
flagBits.set(E_FLAG_POSITION, procTime.isEstimated());
flagBits.toByteBuf(body);
- ByteBufWriteUtil.writeUnsignedInt(procTime.getCurrentProcTime(), body);
- ByteBufWriteUtil.writeUnsignedInt(procTime.getMinProcTime(), body);
- ByteBufWriteUtil.writeUnsignedInt(procTime.getMaxProcTime(), body);
- ByteBufWriteUtil.writeUnsignedInt(procTime.getAverageProcTime(), body);
- ByteBufWriteUtil.writeUnsignedInt(procTime.getVarianceProcTime(), body);
+ ByteBufUtils.writeOrZero(body, procTime.getCurrentProcTime());
+ ByteBufUtils.writeOrZero(body, procTime.getMinProcTime());
+ ByteBufUtils.writeOrZero(body, procTime.getMaxProcTime());
+ ByteBufUtils.writeOrZero(body, procTime.getAverageProcTime());
+ ByteBufUtils.writeOrZero(body, procTime.getVarianceProcTime());
ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
}
@Override
public Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException {
- checkArgument(buffer != null && buffer.isReadable(),
- "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
buffer.skipBytes(RESERVED);
final BitArray flagBits = BitArray.valueOf(buffer, FLAGS);
package org.opendaylight.protocol.pcep.parser.object;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
res[res.length - 1] = (byte) (res[res.length - 1] | p);
}
body.writeBytes(res);
- checkArgument(rpObj.getRequestId() != null, "RequestId is mandatory");
- writeUnsignedInt(rpObj.getRequestId().getValue(), body);
+ final RequestId requestId = rpObj.getRequestId();
+ checkArgument(requestId != null, "RequestId is mandatory");
+ ByteBufUtils.write(body, requestId.getValue());
serializeTlvs(rpObj.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.getOrder() != null) {
+ serializeTlv(tlvs.getOrder(), body);
+ }
+ if (tlvs.getPathSetupType() != null) {
+ serializeTlv(tlvs.getPathSetupType(), body);
+ }
+ serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
}
- if (tlvs.getOrder() != null) {
- serializeTlv(tlvs.getOrder(), body);
- }
- if (tlvs.getPathSetupType() != null) {
- serializeTlv(tlvs.getPathSetupType(), body);
- }
- serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
}
@Override
*/
package org.opendaylight.protocol.pcep.parser.object;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
+import static com.google.common.base.Preconditions.checkArgument;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.util.ArrayList;
@Override
public Svec parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
- Preconditions.checkArgument(bytes != null && bytes.isReadable(),
- "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
if (bytes.readableBytes() < MIN_SIZE) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: "
+ bytes.readableBytes() + "; Expected: >=" + MIN_SIZE + ".");
if (requestIDs.isEmpty()) {
throw new PCEPDeserializerException("Empty Svec Object - no request ids.");
}
- final SvecBuilder builder = new SvecBuilder()
+ return new SvecBuilder()
.setIgnore(header.isIgnore())
.setProcessingRule(header.isProcessingRule())
.setLinkDiverse(flags.get(L_FLAG_OFFSET))
.setSrlgDiverse(flags.get(S_FLAG_OFFSET))
.setLinkDirectionDiverse(flags.get(D_FLAG_OFFSET))
.setPartialPathDiverse(flags.get(P_FLAG_OFFSET))
- .setRequestsIds(requestIDs);
- return builder.build();
+ .setRequestsIds(requestIDs)
+ .build();
}
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
- Preconditions.checkArgument(object instanceof Svec,
- "Wrong instance of PCEPObject. Passed %s. Needed SvecObject.", object.getClass());
+ checkArgument(object instanceof Svec, "Wrong instance of PCEPObject. Passed %s. Needed SvecObject.",
+ object.getClass());
final Svec svecObj = (Svec) object;
final ByteBuf body = Unpooled.buffer();
body.writeZero(FLAGS_F_OFFSET);
flags.toByteBuf(body);
final List<RequestId> requestIDs = svecObj.getRequestsIds();
+ // FIXME: remove this assert
assert !requestIDs.isEmpty() : "Empty Svec Object - no request ids.";
for (final RequestId requestId : requestIDs) {
- writeUnsignedInt(requestId.getValue(), body);
+ ByteBufUtils.write(body, requestId.getValue());
}
ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
}
package org.opendaylight.protocol.pcep.parser.subobject;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeShort;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.as.number._case.AsNumberBuilder;
-import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
final class AsNumberCaseParser {
private static final int CONTENT_LENGTH = 2;
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
+ "; Expected: " + CONTENT_LENGTH + ".");
}
- return new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(
- new AsNumber(Uint32.valueOf(buffer.readUnsignedShort()))).build()).build();
+ return new AsNumberCaseBuilder()
+ .setAsNumber(new AsNumberBuilder()
+ .setAsNumber(new AsNumber(ByteBufUtils.readUint16(buffer).toUint32()))
+ .build())
+ .build();
}
static ByteBuf serializeSubobject(final AsNumberCase asCase) {
final AsNumberSubobject asNumber = asCase.getAsNumber();
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
- checkArgument(asNumber.getAsNumber() != null, "AsNumber is mandatory.");
- writeShort(asNumber.getAsNumber().getValue().shortValue(), body);
+ final AsNumber asn = asNumber.getAsNumber();
+ checkArgument(asn != null, "AsNumber is mandatory.");
+ body.writeShort(asn.getValue().shortValue());
return body;
}
}
package org.opendaylight.protocol.pcep.parser.subobject;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
+ "; Expected: " + CONTENT_LENGTH + ".");
}
buffer.skipBytes(RESERVED);
- final UnnumberedBuilder ubuilder = new UnnumberedBuilder()
- .setRouterId(ByteBufUtils.readUint32(buffer))
- .setInterfaceId(ByteBufUtils.readUint32(buffer));
- final SubobjectBuilder builder = new SubobjectBuilder()
+ return new SubobjectBuilder()
.setLoose(loose)
- .setSubobjectType(new UnnumberedCaseBuilder().setUnnumbered(ubuilder.build()).build());
- return builder.build();
+ .setSubobjectType(new UnnumberedCaseBuilder()
+ .setUnnumbered(new UnnumberedBuilder()
+ .setRouterId(ByteBufUtils.readUint32(buffer))
+ .setInterfaceId(ByteBufUtils.readUint32(buffer))
+ .build())
+ .build())
+ .build();
}
@Override
final UnnumberedSubobject specObj = ((UnnumberedCase) subobject.getSubobjectType()).getUnnumbered();
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
body.writeZero(RESERVED);
- checkArgument(specObj.getRouterId() != null, "RouterId is mandatory.");
- writeUnsignedInt(specObj.getRouterId(), body);
- checkArgument(specObj.getInterfaceId() != null, "InterfaceId is mandatory");
- writeUnsignedInt(specObj.getInterfaceId(), body);
+ ByteBufUtils.writeMandatory(body, specObj.getRouterId(), "RouterId");
+ ByteBufUtils.writeMandatory(body, specObj.getInterfaceId(), "InterfaceId");
EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
}
}
package org.opendaylight.protocol.pcep.parser.subobject;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.path.key._case.PathKeyBuilder;
-import org.opendaylight.yangtools.yang.common.Uint16;
import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
public class RROPathKey128SubobjectParser implements RROSubobjectParser {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
+ "; Expected: >" + CONTENT128_LENGTH + ".");
}
- final Uint16 pathKey = ByteBufUtils.readUint16(buffer);
- final byte[] pceId = ByteArray.readBytes(buffer, PCE128_ID_F_LENGTH);
- final SubobjectBuilder builder = new SubobjectBuilder();
- final PathKeyBuilder pBuilder = new PathKeyBuilder();
- pBuilder.setPceId(new PceId(pceId));
- pBuilder.setPathKey(new PathKey(pathKey));
- builder.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
- return builder.build();
+ return new SubobjectBuilder()
+ .setSubobjectType(new PathKeyCaseBuilder()
+ .setPathKey(new PathKeyBuilder()
+ .setPathKey(new PathKey(ByteBufUtils.readUint16(buffer)))
+ .setPceId(new PceId(ByteArray.readBytes(buffer, PCE128_ID_F_LENGTH)))
+ .build())
+ .build())
+ .build();
}
public static void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects
.subobject.type.path.key._case.PathKey pk = pkcase.getPathKey();
final ByteBuf body = Unpooled.buffer();
- checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
- writeUnsignedShort(pk.getPathKey().getValue(), body);
- checkArgument(pk.getPceId() != null, "PceId is mandatory.");
- body.writeBytes(pk.getPceId().getValue());
+ final PathKey pathKey = pk.getPathKey();
+ checkArgument(pathKey != null, "PathKey is mandatory.");
+ ByteBufUtils.write(body, pathKey.getValue());
+ final PceId pceId = pk.getPceId();
+ checkArgument(pceId != null, "PceId is mandatory.");
+ body.writeBytes(pceId.getValue());
RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
}
}
package org.opendaylight.protocol.pcep.parser.subobject;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.path.key._case.PathKeyBuilder;
-import org.opendaylight.yangtools.yang.common.Uint16;
import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
public class RROPathKey32SubobjectParser implements RROSubobjectParser, RROSubobjectSerializer {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
+ "; Expected: >" + CONTENT_LENGTH + ".");
}
- final Uint16 pathKey = ByteBufUtils.readUint16(buffer);
- final byte[] pceId = ByteArray.readBytes(buffer, PCE_ID_F_LENGTH);
- final PathKeyBuilder pBuilder = new PathKeyBuilder()
- .setPceId(new PceId(pceId))
- .setPathKey(new PathKey(pathKey));
- final SubobjectBuilder builder = new SubobjectBuilder()
- .setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
- return builder.build();
+ return new SubobjectBuilder()
+ .setSubobjectType(new PathKeyCaseBuilder()
+ .setPathKey(new PathKeyBuilder()
+ .setPathKey(new PathKey(ByteBufUtils.readUint16(buffer)))
+ .setPceId(new PceId(ByteArray.readBytes(buffer, PCE_ID_F_LENGTH)))
+ .build())
+ .build())
+ .build();
}
@Override
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route
.subobjects.subobject.type.path.key._case.PathKey pk = pkcase.getPathKey();
final ByteBuf body = Unpooled.buffer();
- checkArgument(pk.getPceId() != null, "PceId is mandatory.");
- final byte[] pceId = pk.getPceId().getValue();
- if (pceId.length == RROPathKey128SubobjectParser.PCE128_ID_F_LENGTH) {
+ final PceId pceId = pk.getPceId();
+ checkArgument(pceId != null, "PceId is mandatory.");
+
+ final byte[] idBytes = pceId.getValue();
+ if (idBytes.length == RROPathKey128SubobjectParser.PCE128_ID_F_LENGTH) {
RROPathKey128SubobjectParser.serializeSubobject(subobject, buffer);
}
- checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
- writeUnsignedShort(pk.getPathKey().getValue(), body);
- Preconditions.checkArgument(pceId.length == PCE_ID_F_LENGTH, "PceId 32 Bit required.");
- body.writeBytes(pceId);
+ final PathKey pathKey = pk.getPathKey();
+ checkArgument(pathKey != null, "PathKey is mandatory.");
+ ByteBufUtils.write(body, pathKey.getValue());
+ checkArgument(idBytes.length == PCE_ID_F_LENGTH, "PceId 32 Bit required.");
+ body.writeBytes(idBytes);
RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
}
}
package org.opendaylight.protocol.pcep.parser.subobject;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
}
final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
buffer.skipBytes(RESERVED);
- final UnnumberedBuilder ubuilder = new UnnumberedBuilder()
- .setRouterId(ByteBufUtils.readUint32(buffer))
- .setInterfaceId(ByteBufUtils.readUint32(buffer));
- final SubobjectBuilder builder = new SubobjectBuilder()
+ return new SubobjectBuilder()
.setProtectionAvailable(flags.get(LPA_F_OFFSET))
.setProtectionInUse(flags.get(LPIU_F_OFFSET))
- .setSubobjectType(new UnnumberedCaseBuilder().setUnnumbered(ubuilder.build()).build());
- return builder.build();
+ .setSubobjectType(new UnnumberedCaseBuilder()
+ .setUnnumbered(new UnnumberedBuilder()
+ .setRouterId(ByteBufUtils.readUint32(buffer))
+ .setInterfaceId(ByteBufUtils.readUint32(buffer))
+ .build())
+ .build())
+ .build();
}
@Override
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
flags.toByteBuf(body);
body.writeZero(RESERVED);
- checkArgument(specObj.getRouterId() != null, "RouterId is mandatory.");
- writeUnsignedInt(specObj.getRouterId(), body);
- checkArgument(specObj.getInterfaceId() != null, "InterfaceId is mandatory.");
- writeUnsignedInt(specObj.getInterfaceId(), body);
+ ByteBufUtils.writeMandatory(body, specObj.getRouterId(), "RouterId");
+ ByteBufUtils.writeMandatory(body, specObj.getInterfaceId(), "InterfaceId");
RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
}
}
package org.opendaylight.protocol.pcep.parser.subobject;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
final ByteBuf body = Unpooled.buffer(LABEL_LENGTH);
final Type1Label type1Label = ((Type1LabelCase) subobject).getType1Label();
checkArgument(type1Label != null, "Type1Label is mandatory.");
- writeUnsignedInt(type1Label.getType1Label(), body);
+ ByteBufUtils.writeOrZero(body, type1Label.getType1Label());
LabelUtil.formatLabel(CTYPE, unidirectional, global, body, buffer);
}
}
package org.opendaylight.protocol.pcep.parser.subobject;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
"Unknown Label Subobject instance. Passed {}. Needed WavebandSwitchingLabelCase.", subobject.getClass());
final WavebandSwitchingLabel obj = ((WavebandSwitchingLabelCase) subobject).getWavebandSwitchingLabel();
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
- checkArgument(obj.getWavebandId() != null, "WavebandId is mandatory.");
- writeUnsignedInt(obj.getWavebandId(), body);
- checkArgument(obj.getStartLabel() != null, "StartLabel is mandatory.");
- writeUnsignedInt(obj.getStartLabel(), body);
- checkArgument(obj.getEndLabel() != null, "EndLabel is mandatory.");
- writeUnsignedInt(obj.getEndLabel(), body);
+ ByteBufUtils.writeMandatory(body, obj.getWavebandId(), "WavebandId");
+ ByteBufUtils.writeMandatory(body, obj.getStartLabel(), "StartLabel");
+ ByteBufUtils.writeMandatory(body, obj.getEndLabel(), "EndLabel");
LabelUtil.formatLabel(CTYPE, unidirectional, global, body, buffer);
}
}
import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Prefix;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.Subobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.SubobjectBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder;
-import org.opendaylight.yangtools.yang.common.Uint8;
/**
* Parser for {@link IpPrefixCase}.
.setIpPrefix(new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.readBytes(buffer, Ipv4Util.IP4_LENGTH),
length)));
buffer.skipBytes(PREFIX_F_LENGTH);
- final SubobjectBuilder builder = new SubobjectBuilder()
+ return new SubobjectBuilder()
.setMandatory(mandatory)
.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(prefix.build()).build())
- .setAttribute(Attribute.forValue(buffer.readUnsignedByte()));
- return builder.build();
+ .setAttribute(Attribute.forValue(buffer.readUnsignedByte()))
+ .build();
}
@Override
"Unknown subobject instance. Passed %s. Needed IpPrefixCase.", subobject.getSubobjectType().getClass());
final IpPrefixSubobject specObj = ((IpPrefixCase) subobject.getSubobjectType()).getIpPrefix();
final IpPrefix prefix = specObj.getIpPrefix();
- checkArgument(prefix.getIpv4Prefix() != null || prefix.getIpv6Prefix() != null,
- "Unknown AbstractPrefix instance. Passed %s.", prefix.getClass());
- if (prefix.getIpv6Prefix() != null) {
- new XROIpv6PrefixSubobjectParser().serializeSubobject(subobject, buffer);
- } else {
- final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH);
- Preconditions.checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
- writeIpv4Prefix(prefix.getIpv4Prefix(), body);
- Preconditions.checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
- writeUnsignedByte(Uint8.valueOf(subobject.getAttribute().getIntValue()), body);
- XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
+ final Ipv6Prefix ipv6Prefix = prefix.getIpv6Prefix();
+ if (ipv6Prefix != null) {
+ XROIpv6PrefixSubobjectParser.serializeSubobject(buffer, subobject, ipv6Prefix);
+ return;
}
+
+ final Ipv4Prefix ipv4Prefix = prefix.getIpv4Prefix();
+ checkArgument(ipv4Prefix != null, "Ipv4Prefix is mandatory.");
+
+ final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH);
+ writeIpv4Prefix(ipv4Prefix, body);
+ final Attribute attribute = subobject.getAttribute();
+ checkArgument(attribute != null, "Attribute is mandatory.");
+ body.writeByte(attribute.getIntValue());
+ XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
}
}
*/
package org.opendaylight.protocol.pcep.parser.subobject;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Prefix;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.protocol.util.Ipv6Util;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.Subobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.SubobjectBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder;
-import org.opendaylight.yangtools.yang.common.Uint8;
/**
* Parser for {@link IpPrefixCase}.
*/
public class XROIpv6PrefixSubobjectParser implements XROSubobjectParser, XROSubobjectSerializer {
-
public static final int TYPE = 2;
private static final int PREFIX_F_LENGTH = 1;
-
private static final int PREFIX6_F_OFFSET = Ipv6Util.IPV6_LENGTH;
-
private static final int CONTENT6_LENGTH = PREFIX6_F_OFFSET + PREFIX_F_LENGTH + 1;
@Override
public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory) throws PCEPDeserializerException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(),
- "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
if (buffer.readableBytes() != CONTENT6_LENGTH) {
throw new PCEPDeserializerException(
"Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
@Override
public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
- Preconditions.checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase,
+ checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase,
"Unknown subobject instance. Passed %s. Needed IpPrefixCase.", subobject.getSubobjectType().getClass());
final IpPrefixSubobject specObj = ((IpPrefixCase) subobject.getSubobjectType()).getIpPrefix();
- final IpPrefix prefix = specObj.getIpPrefix();
+ final Ipv6Prefix ipv6Prefix = specObj.getIpPrefix().getIpv6Prefix();
+ checkArgument(ipv6Prefix != null, "Ipv6Prefix is mandatory.");
+ serializeSubobject(buffer, subobject, ipv6Prefix);
+ }
+
+ static void serializeSubobject(final ByteBuf buffer, final Subobject subobject, final Ipv6Prefix ipv6Prefix) {
final ByteBuf body = Unpooled.buffer(CONTENT6_LENGTH);
- Preconditions.checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory.");
- writeIpv6Prefix(prefix.getIpv6Prefix(), body);
- Preconditions.checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
- writeUnsignedByte(Uint8.valueOf(subobject.getAttribute().getIntValue()), body);
+ writeIpv6Prefix(ipv6Prefix, body);
+ final Attribute attribute = subobject.getAttribute();
+ checkArgument(attribute != null, "Attribute is mandatory.");
+ body.writeByte(attribute.getIntValue());
XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
}
}
package org.opendaylight.protocol.pcep.parser.subobject;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
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.exclude.route.object.xro.SubobjectBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.SubobjectType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKeyBuilder;
-import org.opendaylight.yangtools.yang.common.Uint16;
import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
/**
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
+ "; Expected: >" + CONTENT128_LENGTH + ".");
}
- final Uint16 pathKey = ByteBufUtils.readUint16(buffer);
- final byte[] pceId = ByteArray.readBytes(buffer, PCE128_ID_F_LENGTH);
- final PathKeyBuilder pBuilder = new PathKeyBuilder()
- .setPceId(new PceId(pceId))
- .setPathKey(new PathKey(pathKey));
- final SubobjectBuilder builder = new SubobjectBuilder()
+ return new SubobjectBuilder()
.setMandatory(mandatory)
- .setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
- return builder.build();
+ .setSubobjectType(new PathKeyCaseBuilder()
+ .setPathKey(new PathKeyBuilder()
+ .setPathKey(new PathKey(ByteBufUtils.readUint16(buffer)))
+ .setPceId(new PceId(ByteArray.readBytes(buffer, PCE128_ID_F_LENGTH)))
+ .build())
+ .build())
+ .build();
}
public static void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
- checkArgument(subobject.getSubobjectType() instanceof PathKeyCase,
- "Unknown subobject instance. Passed %s. Needed PathKey.", subobject.getSubobjectType().getClass());
+ final SubobjectType type = subobject.getSubobjectType();
+ checkArgument(type instanceof PathKeyCase, "Unknown subobject instance. Passed %s. Needed PathKey.",
+ type.getClass());
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route
- .subobjects.subobject.type.path.key._case.PathKey pk =
- ((PathKeyCase) subobject.getSubobjectType()).getPathKey();
+ .subobjects.subobject.type.path.key._case.PathKey pk = ((PathKeyCase) type).getPathKey();
final ByteBuf body = Unpooled.buffer();
- checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
- writeUnsignedShort(pk.getPathKey().getValue(), body);
- checkArgument(pk.getPceId() != null, "PceId is mandatory.");
- body.writeBytes(pk.getPceId().getValue());
+ final PathKey pathKey = pk.getPathKey();
+ checkArgument(pathKey != null, "PathKey is mandatory.");
+ ByteBufUtils.write(body, pathKey.getValue());
+ final PceId pceId = pk.getPceId();
+ checkArgument(pceId != null, "PceId is mandatory.");
+ body.writeBytes(pceId.getValue());
XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
}
}
package org.opendaylight.protocol.pcep.parser.subobject;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKeyBuilder;
-import org.opendaylight.yangtools.yang.common.Uint16;
import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
/**
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
+ "; Expected: >" + CONTENT_LENGTH + ".");
}
- final Uint16 pathKey = ByteBufUtils.readUint16(buffer);
- final byte[] pceId = ByteArray.readBytes(buffer, PCE_ID_F_LENGTH);
- final PathKeyBuilder pBuilder = new PathKeyBuilder()
- .setPceId(new PceId(pceId))
- .setPathKey(new PathKey(pathKey));
- final SubobjectBuilder builder = new SubobjectBuilder()
+ return new SubobjectBuilder()
.setMandatory(mandatory)
- .setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
- return builder.build();
+ .setSubobjectType(new PathKeyCaseBuilder()
+ .setPathKey(new PathKeyBuilder()
+ .setPathKey(new PathKey(ByteBufUtils.readUint16(buffer)))
+ .setPceId(new PceId(ByteArray.readBytes(buffer, PCE_ID_F_LENGTH)))
+ .build())
+ .build())
+ .build();
}
@Override
if (pceId.length == XROPathKey128SubobjectParser.PCE128_ID_F_LENGTH) {
XROPathKey128SubobjectParser.serializeSubobject(subobject, buffer);
}
- checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
- writeUnsignedShort(pk.getPathKey().getValue(), body);
+
+ final PathKey pathKey = pk.getPathKey();
+ checkArgument(pathKey != null, "PathKey is mandatory.");
+ ByteBufUtils.write(body, pathKey.getValue());
checkArgument(pceId.length == PCE_ID_F_LENGTH, "PceId 32 Bit required.");
body.writeBytes(pceId);
XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
package org.opendaylight.protocol.pcep.parser.subobject;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.Subobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.SubobjectBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.SrlgId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.SrlgSubobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.SrlgCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.SrlgCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.srlg._case.SrlgBuilder;
-import org.opendaylight.yangtools.yang.common.Uint8;
import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
/**
"Unknown subobject instance. Passed %s. Needed SrlgCase.", subobject.getSubobjectType().getClass());
final SrlgSubobject specObj = ((SrlgCase) subobject.getSubobjectType()).getSrlg();
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
- checkArgument(specObj.getSrlgId() != null, "SrlgId is mandatory.");
- writeUnsignedInt(specObj.getSrlgId().getValue(), body);
- checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
- writeUnsignedByte((Uint8) null, body);
- writeUnsignedByte(Uint8.valueOf(subobject.getAttribute().getIntValue()), body);
+
+ final SrlgId srlgId = specObj.getSrlgId();
+ checkArgument(srlgId != null, "SrlgId is mandatory.");
+ ByteBufUtils.write(body, srlgId.getValue());
+
+ final Attribute attribute = subobject.getAttribute();
+ checkArgument(attribute != null, "Attribute is mandatory.");
+ body.writeByte(0);
+ body.writeByte(attribute.getIntValue());
XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
}
}
package org.opendaylight.protocol.pcep.parser.subobject;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.UnnumberedCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.UnnumberedCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.unnumbered._case.UnnumberedBuilder;
-import org.opendaylight.yangtools.yang.common.Uint8;
import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
/**
final UnnumberedSubobject specObj = ((UnnumberedCase) subobject.getSubobjectType()).getUnnumbered();
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
body.writeZero(RESERVED);
- writeUnsignedByte(
- subobject.getAttribute() != null ? Uint8.valueOf(subobject.getAttribute().getIntValue()) : (Uint8) null,
- body);
- checkArgument(specObj.getRouterId() != null, "RouterId is mandatory.");
- writeUnsignedInt(specObj.getRouterId(), body);
- checkArgument(specObj.getInterfaceId() != null, "InterfaceId is mandatory.");
- writeUnsignedInt(specObj.getInterfaceId(), body);
+
+ final Attribute attribute = subobject.getAttribute();
+ body.writeByte(attribute != null ? attribute.getIntValue() : 0);
+
+ ByteBufUtils.writeMandatory(body, specObj.getRouterId(), "RouterId");
+ ByteBufUtils.writeMandatory(body, specObj.getInterfaceId(), "InterfaceId");
XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
}
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.protocol.pcep.parser.tlv;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.pcep.spi.VendorInformationUtil.VENDOR_INFORMATION_TLV_TYPE;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.pcep.spi.EnterpriseSpecificInformationParser;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.EnterpriseSpecificInformation;
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;
+import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
public abstract class AbstractVendorInformationTlvParser
implements TlvSerializer, TlvParser, EnterpriseSpecificInformationParser {
@Override
public final void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
- Preconditions.checkArgument(tlv instanceof VendorInformationTlv, "Vendor Specific Tlv is mandatory.");
+ checkArgument(tlv instanceof VendorInformationTlv, "Vendor Specific Tlv is mandatory.");
final VendorInformationTlv viTlv = (VendorInformationTlv) tlv;
final ByteBuf body = Unpooled.buffer();
- writeUnsignedInt(getEnterpriseNumber().getValue(), body);
+ ByteBufUtils.write(body, getEnterpriseNumber().getValue());
serializeEnterpriseSpecificInformation(viTlv.getEnterpriseSpecificInformation(), body);
TlvUtil.formatTlv(VENDOR_INFORMATION_TLV_TYPE, body, buffer);
}
if (buffer == null) {
return null;
}
- final VendorInformationTlvBuilder viTlvBuider = new VendorInformationTlvBuilder();
- viTlvBuider.setEnterpriseNumber(getEnterpriseNumber());
+ final VendorInformationTlvBuilder viTlvBuider = new VendorInformationTlvBuilder()
+ .setEnterpriseNumber(getEnterpriseNumber());
if (buffer.isReadable()) {
final EnterpriseSpecificInformation esInformation = parseEnterpriseSpecificInformation(buffer.slice());
if (esInformation != null) {
package org.opendaylight.protocol.pcep.parser.tlv;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
final ByteBuf body = Unpooled.buffer();
final List<OfId> ofCodes = oft.getCodes();
for (OfId id : ofCodes) {
- writeUnsignedShort(id.getValue(), body);
+ ByteBufUtils.write(body, id.getValue());
}
TlvUtil.formatTlv(TYPE, body, buffer);
}
package org.opendaylight.protocol.pcep.parser.tlv;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
checkArgument(tlv instanceof Order, "OrderTlv is mandatory.");
final Order otlv = (Order) tlv;
final ByteBuf body = Unpooled.buffer();
- writeUnsignedInt(otlv.getDelete(), body);
- writeUnsignedInt(otlv.getSetup(), body);
+ ByteBufUtils.writeOrZero(body, otlv.getDelete());
+ ByteBufUtils.writeOrZero(body, otlv.getSetup());
TlvUtil.formatTlv(TYPE, body, buffer);
}
}
package org.opendaylight.protocol.pcep.parser.tlv;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
checkArgument(tlv instanceof OverloadDuration, "OverloadedTlv is mandatory.");
final ByteBuf body = Unpooled.buffer();
- writeUnsignedInt(((OverloadDuration) tlv).getDuration(), body);
+ ByteBufUtils.writeOrZero(body, ((OverloadDuration) tlv).getDuration());
TlvUtil.formatTlv(TYPE, body, buffer);
}
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.protocol.pcep.parser.tlv;
-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.HashSet;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.setup.type.tlv.PathSetupType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.setup.type.tlv.PathSetupTypeBuilder;
import org.opendaylight.yangtools.yang.common.Uint8;
+import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
public class PathSetupTypeTlvParser implements TlvParser, TlvSerializer {
-
public static final int TYPE = 28;
private static final int CONTENT_LENGTH = 4;
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
- Preconditions.checkArgument(tlv instanceof PathSetupType, "PathSetupType is mandatory.");
+ checkArgument(tlv instanceof PathSetupType, "PathSetupType is mandatory.");
final PathSetupType pstTlv = (PathSetupType) tlv;
- Preconditions.checkArgument(checkPST(pstTlv.getPst()), UNSUPPORTED_PST);
+ checkArgument(checkPST(pstTlv.getPst()), UNSUPPORTED_PST);
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
body.writeZero(OFFSET);
- writeUnsignedByte(pstTlv.getPst(), body);
+ ByteBufUtils.writeOrZero(body, pstTlv.getPst());
TlvUtil.formatTlv(TYPE, body, buffer);
}
if (buffer == null) {
return null;
}
- final Uint8 pst = Uint8.valueOf(buffer.readerIndex(OFFSET).readUnsignedByte());
+ final Uint8 pst = ByteBufUtils.readUint8(buffer.readerIndex(OFFSET));
if (!checkPST(pst)) {
throw new PCEPDeserializerException(UNSUPPORTED_PST);
}
*/
package org.opendaylight.protocol.pcep.parser.tlv;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
+import static com.google.common.base.Preconditions.checkArgument;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
- Preconditions.checkArgument(tlv instanceof ReqMissing, "ReqMissingTlv is mandatory.");
+ checkArgument(tlv instanceof ReqMissing, "ReqMissingTlv is mandatory.");
final ReqMissing req = (ReqMissing) tlv;
final ByteBuf body = Unpooled.buffer();
- Preconditions.checkArgument(req.getRequestId() != null, "RequestId is mandatory.");
- writeUnsignedInt(req.getRequestId().getValue(), body);
+
+ final RequestId reqId = req.getRequestId();
+ checkArgument(reqId != null, "RequestId is mandatory.");
+ ByteBufUtils.write(body, reqId.getValue());
TlvUtil.formatTlv(TYPE, body, buffer);
}
}