import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.spi.AbstractObjectParser;
-import org.opendaylight.protocol.pcep.spi.SubobjectHandlerRegistry;
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.ieee754.rev130819.Float32;
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.requests.segment.computation.p2p.LoadBalancingBuilder;
+import com.google.common.primitives.UnsignedBytes;
+
/**
- * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPLoadBalancingObject PCEPLoadBalancingObject}
+ * Parser for {@link LoadBalancingObject}
*/
-public class PCEPLoadBalancingObjectParser extends AbstractObjectParser<LoadBalancingBuilder> {
+public class PCEPLoadBalancingObjectParser extends AbstractObjectWithTlvsParser<LoadBalancingBuilder> {
public static final int CLASS = 14;
public static final int TYPE = 1;
- public static final int FLAGS_F_LENGTH = 1;
- public static final int MAX_LSP_F_LENGTH = 1;
- public static final int MIN_BAND_F_LENGTH = 4;
+ private static final int FLAGS_F_LENGTH = 1;
+ private static final int MAX_LSP_F_LENGTH = 1;
+ private static final int MIN_BAND_F_LENGTH = 4;
- public static final int FLAGS_F_OFFSET = 2;
- public static final int MAX_LSP_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH;
- public static final int MIN_BAND_F_OFFSET = MAX_LSP_F_OFFSET + MAX_LSP_F_LENGTH;
+ private static final int FLAGS_F_OFFSET = 2;
+ private static final int MAX_LSP_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH;
+ private static final int MIN_BAND_F_OFFSET = MAX_LSP_F_OFFSET + MAX_LSP_F_LENGTH;
- public static final int SIZE = MIN_BAND_F_OFFSET + MIN_BAND_F_LENGTH;
+ private static final int SIZE = MIN_BAND_F_OFFSET + MIN_BAND_F_LENGTH;
- public PCEPLoadBalancingObjectParser(final SubobjectHandlerRegistry subobjReg, final TlvHandlerRegistry tlvReg) {
- super(subobjReg, tlvReg);
+ public PCEPLoadBalancingObjectParser(final TlvHandlerRegistry tlvReg) {
+ super(tlvReg);
}
@Override
public LoadBalancingObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
- PCEPDocumentedException {
+ PCEPDocumentedException {
if (bytes == null || bytes.length == 0) {
throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty.");
}
-
if (bytes.length != SIZE) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.length + "; Expected: " + SIZE + ".");
}
-
final LoadBalancingBuilder builder = new LoadBalancingBuilder();
-
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
-
- builder.setMaxLsp((short) (bytes[MAX_LSP_F_OFFSET] & 0xFF));
+ builder.setMaxLsp((short) UnsignedBytes.toInt(bytes[MAX_LSP_F_OFFSET]));
builder.setMinBandwidth(new Float32(ByteArray.subByte(bytes, MIN_BAND_F_OFFSET, MIN_BAND_F_LENGTH)));
-
return builder.build();
}
throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass()
+ ". Needed LoadBalancingObject.");
}
-
final LoadBalancingObject specObj = (LoadBalancingObject) object;
-
final byte[] retBytes = new byte[SIZE];
-
- retBytes[MAX_LSP_F_OFFSET] = ByteArray.shortToBytes(specObj.getMaxLsp())[1];
+ retBytes[MAX_LSP_F_OFFSET] = UnsignedBytes.checkedCast(specObj.getMaxLsp());
ByteArray.copyWhole(specObj.getMinBandwidth().getValue(), retBytes, MIN_BAND_F_OFFSET);
-
return retBytes;
}