package org.opendaylight.protocol.pcep.impl.object;
+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.PCEPErrors;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.pcep.spi.UnknownObject;
import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Tlvs2;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Tlvs2Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.db.version.tlv.LspDbVersion;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.predundancy.group.id.tlv.PredundancyGroupId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.stateful.capability.tlv.Stateful;
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.ProtocolVersion;
private static final int PCEP_VERSION = 1;
- public PCEPOpenObjectParser(final TlvHandlerRegistry tlvReg) {
+ public PCEPOpenObjectParser(final TlvRegistry tlvReg) {
super(tlvReg);
}
@Override
public void addTlv(final TlvsBuilder tbuilder, final Tlv tlv) {
- final Tlvs2Builder statefulBuilder = new Tlvs2Builder();
- if (tbuilder.getAugmentation(Tlvs2.class) != null) {
- final Tlvs2 t = tbuilder.getAugmentation(Tlvs2.class);
- if (t.getLspDbVersion() != null) {
- statefulBuilder.setLspDbVersion(t.getLspDbVersion());
- }
- if (t.getPredundancyGroupId() != null) {
- statefulBuilder.setPredundancyGroupId(t.getPredundancyGroupId());
- }
- if (t.getClass() != null) {
- statefulBuilder.setStateful(t.getStateful());
- }
- }
if (tlv instanceof OfList) {
tbuilder.setOfList((OfList) tlv);
- } else if (tlv instanceof Stateful) {
- statefulBuilder.setStateful((Stateful) tlv);
- } else if (tlv instanceof PredundancyGroupId) {
- statefulBuilder.setPredundancyGroupId((PredundancyGroupId) tlv);
- } else if (tlv instanceof LspDbVersion) {
- statefulBuilder.setLspDbVersion((LspDbVersion) tlv);
}
- tbuilder.addAugmentation(Tlvs2.class, statefulBuilder.build());
}
@Override
if (tlvs == null) {
return new byte[0];
}
- int finalLength = 0;
byte[] ofListBytes = null;
- byte[] statefulBytes = null;
- byte[] predundancyBytes = null;
- byte[] lspDbBytes = null;
if (tlvs.getOfList() != null) {
ofListBytes = serializeTlv(tlvs.getOfList());
- finalLength += ofListBytes.length;
- }
- if (tlvs.getAugmentation(Tlvs2.class) != null) {
- final Tlvs2 statefulTlvs = tlvs.getAugmentation(Tlvs2.class);
- if (statefulTlvs.getStateful() != null) {
- statefulBytes = serializeTlv(statefulTlvs.getStateful());
- finalLength += statefulBytes.length;
- }
- if (statefulTlvs.getPredundancyGroupId() != null) {
- predundancyBytes = serializeTlv(statefulTlvs.getPredundancyGroupId());
- finalLength += predundancyBytes.length;
- }
- if (statefulTlvs.getLspDbVersion() != null) {
- lspDbBytes = serializeTlv(statefulTlvs.getLspDbVersion());
- finalLength += lspDbBytes.length;
- }
}
-
- int offset = 0;
- final byte[] result = new byte[finalLength];
+ byte[] result = new byte[0];
if (ofListBytes != null) {
- ByteArray.copyWhole(ofListBytes, result, offset);
- offset += ofListBytes.length;
- }
- if (statefulBytes != null) {
- ByteArray.copyWhole(statefulBytes, result, offset);
- offset += statefulBytes.length;
- }
- if (lspDbBytes != null) {
- ByteArray.copyWhole(lspDbBytes, result, offset);
- offset += lspDbBytes.length;
- }
- if (predundancyBytes != null) {
- ByteArray.copyWhole(predundancyBytes, result, offset);
- offset += predundancyBytes.length;
+ result = new byte[ofListBytes.length];
+ ByteArray.copyWhole(ofListBytes, result, 0);
}
return result;
}
@Override
- public int getObjectType() {
+ public final int getObjectType() {
return TYPE;
}
@Override
- public int getObjectClass() {
+ public final int getObjectClass() {
return CLASS;
}
}