X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=pcep%2Fimpl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fpcep%2Fimpl%2Fobject%2FPCEPGlobalConstraintsObjectParser.java;h=c33e6f07b7312564dc149e0cbac19be59278f74a;hb=feb60ff47fd4150ce14915506d380704fbf36595;hp=c088927df2a09f24697b636159dc3968bd954cd3;hpb=a6b9c4d7906c40f7d6c2ed5ebdadcaefe06b66d0;p=bgpcep.git diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPGlobalConstraintsObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPGlobalConstraintsObjectParser.java index c088927df2..c33e6f07b7 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPGlobalConstraintsObjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPGlobalConstraintsObjectParser.java @@ -9,15 +9,15 @@ package org.opendaylight.protocol.pcep.impl.object; import org.opendaylight.protocol.pcep.PCEPDeserializerException; import org.opendaylight.protocol.pcep.PCEPDocumentedException; -import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser; import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry; -import org.opendaylight.protocol.util.ByteArray; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.GcObject; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.svec.GcBuilder; +import com.google.common.primitives.UnsignedBytes; + /** * Parser for {@link GcObject} */ @@ -27,17 +27,17 @@ public class PCEPGlobalConstraintsObjectParser extends AbstractObjectWithTlvsPar public static final int TYPE = 1; - private final static int MAX_HOP_F_LENGTH = 1; - private final static int MAX_UTIL_F_LENGTH = 1; - private final static int MIN_UTIL_F_LENGTH = 1; - private final static int OVER_BOOKING_FACTOR_F_LENGTH = 1; + private static final int MAX_HOP_F_LENGTH = 1; + private static final int MAX_UTIL_F_LENGTH = 1; + private static final int MIN_UTIL_F_LENGTH = 1; + private static final int OVER_BOOKING_FACTOR_F_LENGTH = 1; - private final static int MAX_HOP_F_OFFSET = 0; - private final static int MAX_UTIL_F_OFFSET = MAX_HOP_F_OFFSET + MAX_HOP_F_LENGTH; - private final static int MIN_UTIL_F_OFFSET = MAX_UTIL_F_OFFSET + MAX_UTIL_F_LENGTH; - private final static int OVER_BOOKING_FACTOR_F_OFFSET = MIN_UTIL_F_OFFSET + MIN_UTIL_F_LENGTH; + private static final int MAX_HOP_F_OFFSET = 0; + private static final int MAX_UTIL_F_OFFSET = MAX_HOP_F_OFFSET + MAX_HOP_F_LENGTH; + private static final int MIN_UTIL_F_OFFSET = MAX_UTIL_F_OFFSET + MAX_UTIL_F_LENGTH; + private static final int OVER_BOOKING_FACTOR_F_OFFSET = MIN_UTIL_F_OFFSET + MIN_UTIL_F_LENGTH; - private final static int TLVS_OFFSET = OVER_BOOKING_FACTOR_F_OFFSET + OVER_BOOKING_FACTOR_F_LENGTH; + private static final int TLVS_OFFSET = OVER_BOOKING_FACTOR_F_OFFSET + OVER_BOOKING_FACTOR_F_LENGTH; public PCEPGlobalConstraintsObjectParser(final TlvHandlerRegistry tlvReg) { super(tlvReg); @@ -48,19 +48,15 @@ public class PCEPGlobalConstraintsObjectParser extends AbstractObjectWithTlvsPar if (bytes == null || bytes.length == 0) { throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty."); } - final GcBuilder builder = new GcBuilder(); - parseTlvs(builder, ByteArray.cutBytes(bytes, TLVS_OFFSET)); - builder.setIgnore(header.isIgnore()); builder.setProcessingRule(header.isProcessingRule()); - builder.setMaxHop((short) (bytes[MAX_HOP_F_OFFSET] & 0xFF)); - builder.setMinUtilization((short) (bytes[MIN_UTIL_F_OFFSET] & 0xFF)); - builder.setMaxUtilization((short) (bytes[MAX_UTIL_F_OFFSET] & 0xFF)); - builder.setOverBookingFactor((short) (bytes[OVER_BOOKING_FACTOR_F_OFFSET] & 0xFF)); - + builder.setMaxHop((short) UnsignedBytes.toInt(bytes[MAX_HOP_F_OFFSET])); + builder.setMinUtilization((short) UnsignedBytes.toInt(bytes[MIN_UTIL_F_OFFSET])); + builder.setMaxUtilization((short) UnsignedBytes.toInt(bytes[MAX_UTIL_F_OFFSET])); + builder.setOverBookingFactor((short) UnsignedBytes.toInt(bytes[OVER_BOOKING_FACTOR_F_OFFSET])); return builder.build(); } @@ -74,19 +70,12 @@ public class PCEPGlobalConstraintsObjectParser extends AbstractObjectWithTlvsPar if (!(object instanceof GcObject)) { throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed GcObject."); } - final GcObject specObj = (GcObject) object; - - // final byte[] tlvs = PCEPTlvParser.put(specObj.getTlvs()); final byte[] retBytes = new byte[TLVS_OFFSET + 0]; - - retBytes[MAX_HOP_F_OFFSET] = specObj.getMaxHop().byteValue(); - retBytes[MAX_UTIL_F_OFFSET] = specObj.getMaxUtilization().byteValue(); - retBytes[MIN_UTIL_F_OFFSET] = specObj.getMinUtilization().byteValue(); - retBytes[OVER_BOOKING_FACTOR_F_OFFSET] = specObj.getOverBookingFactor().byteValue(); - - // ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET); - + retBytes[MAX_HOP_F_OFFSET] = UnsignedBytes.checkedCast(specObj.getMaxHop()); + retBytes[MAX_UTIL_F_OFFSET] = UnsignedBytes.checkedCast(specObj.getMaxUtilization()); + retBytes[MIN_UTIL_F_OFFSET] = UnsignedBytes.checkedCast(specObj.getMinUtilization()); + retBytes[OVER_BOOKING_FACTOR_F_OFFSET] = UnsignedBytes.checkedCast(specObj.getOverBookingFactor()); return retBytes; }