import java.util.BitSet;
-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.ObjectUtil;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
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.LspaObject;
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.lsp.attributes.LspaBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.Lspa;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.LspaBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.lspa.Tlvs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.lspa.TlvsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.AttributeFilter;
import com.google.common.primitives.UnsignedBytes;
/**
- * Parser for {@link LspaObject}
+ * Parser for {@link Lspa}
*/
-public class PCEPLspaObjectParser extends AbstractObjectWithTlvsParser<LspaBuilder> {
+public class PCEPLspaObjectParser extends AbstractObjectWithTlvsParser<TlvsBuilder> {
public static final int CLASS = 9;
/*
* offsets of flags inside flags field in bits
*/
- private static final int S_FLAG_OFFSET = 6;
private static final int L_FLAG_OFFSET = 7;
/*
private static final int SET_PRIO_F_OFFSET = INC_ALL_F_OFFSET + INC_ALL_F_LENGTH;
private static final int HOLD_PRIO_F_OFFSET = SET_PRIO_F_OFFSET + SET_PRIO_F_LENGTH;
private static final int FLAGS_F_OFFSET = HOLD_PRIO_F_OFFSET + HOLD_PRIO_F_LENGTH;
- private static final int TLVS_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH + 1; // added reserved field of length 1B
+ private static final int TLVS_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH + 1;
public PCEPLspaObjectParser(final TlvHandlerRegistry tlvReg) {
super(tlvReg);
}
@Override
- public LspaObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, PCEPDocumentedException {
+ public Lspa parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException {
if (bytes == null) {
throw new IllegalArgumentException("Bytes array is mandatory.");
}
final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(bytes, FLAGS_F_OFFSET, FLAGS_F_LENGTH));
final LspaBuilder builder = new LspaBuilder();
- parseTlvs(builder, ByteArray.cutBytes(bytes, TLVS_F_OFFSET));
+ final TlvsBuilder tbuilder = new TlvsBuilder();
+ parseTlvs(tbuilder, ByteArray.cutBytes(bytes, TLVS_F_OFFSET));
+ builder.setTlvs(tbuilder.build());
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
return builder.build();
}
- @Override
- public void addTlv(final LspaBuilder builder, final Tlv tlv) {
- // No tlvs defined
- }
-
@Override
public byte[] serializeObject(final Object object) {
- if (!(object instanceof LspaObject)) {
+ if (!(object instanceof Lspa)) {
throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed LspaObject.");
}
- final LspaObject lspaObj = (LspaObject) object;
+ final Lspa lspaObj = (Lspa) object;
- final byte[] retBytes = new byte[TLVS_F_OFFSET];
+ final byte[] tlvs = serializeTlvs(lspaObj.getTlvs());
+ final byte[] retBytes = new byte[TLVS_F_OFFSET + tlvs.length + getPadding(TLVS_F_OFFSET + tlvs.length, PADDED_TO)];
- System.arraycopy(ByteArray.longToBytes(lspaObj.getExcludeAny().getValue()), 4, retBytes, EXC_ANY_F_OFFSET, EXC_ANY_F_LENGTH);
- System.arraycopy(ByteArray.longToBytes(lspaObj.getIncludeAny().getValue()), 4, retBytes, INC_ANY_F_OFFSET, INC_ANY_F_LENGTH);
- System.arraycopy(ByteArray.longToBytes(lspaObj.getIncludeAll().getValue()), 4, retBytes, INC_ALL_F_OFFSET, INC_ALL_F_LENGTH);
- retBytes[SET_PRIO_F_OFFSET] = UnsignedBytes.checkedCast(lspaObj.getSetupPriority());
- retBytes[HOLD_PRIO_F_OFFSET] = UnsignedBytes.checkedCast(lspaObj.getHoldPriority());
+ if (lspaObj.getExcludeAny() != null) {
+ System.arraycopy(ByteArray.longToBytes(lspaObj.getExcludeAny().getValue(), EXC_ANY_F_LENGTH), 0, retBytes, EXC_ANY_F_OFFSET,
+ EXC_ANY_F_LENGTH);
+ }
+ if (lspaObj.getIncludeAny() != null) {
+ System.arraycopy(ByteArray.longToBytes(lspaObj.getIncludeAny().getValue(), INC_ANY_F_LENGTH), 0, retBytes, INC_ANY_F_OFFSET,
+ INC_ANY_F_LENGTH);
+ }
+ if (lspaObj.getIncludeAll() != null) {
+ System.arraycopy(ByteArray.longToBytes(lspaObj.getIncludeAll().getValue(), INC_ALL_F_LENGTH), 0, retBytes, INC_ALL_F_OFFSET,
+ INC_ALL_F_LENGTH);
+ }
+ if (lspaObj.getSetupPriority() != null) {
+ retBytes[SET_PRIO_F_OFFSET] = UnsignedBytes.checkedCast(lspaObj.getSetupPriority());
+ }
+ if (lspaObj.getHoldPriority() != null) {
+ retBytes[HOLD_PRIO_F_OFFSET] = UnsignedBytes.checkedCast(lspaObj.getHoldPriority());
+ }
final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
- flags.set(L_FLAG_OFFSET, lspaObj.isLocalProtectionDesired());
+ if (lspaObj.isLocalProtectionDesired() != null && lspaObj.isLocalProtectionDesired()) {
+ flags.set(L_FLAG_OFFSET, lspaObj.isLocalProtectionDesired());
+ }
ByteArray.copyWhole(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH), retBytes, FLAGS_F_OFFSET);
- return retBytes;
+ ByteArray.copyWhole(tlvs, retBytes, TLVS_F_OFFSET);
+ return ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), retBytes);
+ }
+
+ public byte[] serializeTlvs(final Tlvs tlvs) {
+ return new byte[0];
}
@Override
public int getObjectType() {
- return TYPE;
+ return TYPE;
}
@Override