import java.util.BitSet;
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.PCEPObject;
-import org.opendaylight.protocol.pcep.impl.PCEPObjectParser;
-import org.opendaylight.protocol.pcep.impl.PCEPTlvParser;
-import org.opendaylight.protocol.pcep.object.PCEPLspObject;
+import org.opendaylight.protocol.pcep.PCEPDocumentedException;
+import org.opendaylight.protocol.pcep.spi.AbstractObjectParser;
+import org.opendaylight.protocol.pcep.spi.HandlerRegistry;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspObject;
+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.pcinitiate.message.pcinitiate.message.requests.LspBuilder;
/**
* Parser for {@link org.opendaylight.protocol.pcep.object.PCEPLspObject PCEPLspObject}
*/
-public class PCEPLspObjectParser implements PCEPObjectParser {
+public class PCEPLspObjectParser extends AbstractObjectParser<LspBuilder> {
+
+ public static final int CLASS = 32;
+
+ public static final int TYPE = 1;
/*
* offset of TLVs offset of other fields are not defined as constants
private static final int SYNC_FLAG_OFFSET = 14;
private static final int REMOVE_FLAG_OFFSET = 12;
+ public PCEPLspObjectParser(final HandlerRegistry registry) {
+ super(registry);
+ }
+
@Override
- public PCEPObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException {
+ public LspObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, PCEPDocumentedException {
if (bytes == null || bytes.length == 0)
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
- if (bytes.length < TLVS_OFFSET)
- throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.length + "; Expected: >=" + TLVS_OFFSET + ".");
-
final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(bytes, 2, 2));
- return new PCEPLspObject((ByteArray.bytesToShort(ByteArray.subByte(bytes, 0, 2)) & 0xFFFF) << 4 | (bytes[2] & 0xFF) >> 4,
- flags.get(DELEGATE_FLAG_OFFSET), flags.get(SYNC_FLAG_OFFSET), flags.get(OPERATIONAL_FLAG_OFFSET), flags.get(REMOVE_FLAG_OFFSET),
- PCEPTlvParser.parse(ByteArray.cutBytes(bytes, TLVS_OFFSET)));
+ final LspBuilder builder = new LspBuilder();
+
+ parseTlvs(builder, ByteArray.cutBytes(bytes, TLVS_OFFSET));
+
+ builder.setIgnore(header.isIgnore());
+ builder.setProcessingRule(header.isProcessingRule());
+
+ // builder.setPlspId(new PlspId(ByteArray.bytesToLong(ByteArray.subByte(bytes, 0, 2)) & 0xFFFF) << 4 | (bytes[2]
+ // & 0xFF) >> 4));
+ builder.setDelegate(flags.get(DELEGATE_FLAG_OFFSET));
+ builder.setSync(flags.get(SYNC_FLAG_OFFSET));
+ // builder.setOperational(Operational.flags.get(OPERATIONAL_FLAG_OFFSET));
+ builder.setRemove(flags.get(REMOVE_FLAG_OFFSET));
+
+ return builder.build();
}
@Override
- public byte[] put(PCEPObject obj) {
- if (!(obj instanceof PCEPLspObject))
- throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPLspObject.");
+ public void addTlv(final LspBuilder builder, final Tlv tlv) {
+ // FIXME : finish
+ }
+
+ @Override
+ public byte[] serializeObject(final Object object) {
+ if (!(object instanceof LspObject))
+ throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed LspObject.");
- final PCEPLspObject specObj = (PCEPLspObject) obj;
+ final LspObject specObj = (LspObject) object;
- final byte[] tlvs = PCEPTlvParser.put(specObj.getTlvs());
+ // final byte[] tlvs = PCEPTlvParser.put(specObj.getTlvs());
- final byte[] retBytes = new byte[tlvs.length + TLVS_OFFSET];
+ final byte[] retBytes = new byte[0 + TLVS_OFFSET];
- final int lspID = specObj.getLspID();
+ final int lspID = specObj.getPlspId().getValue().intValue();
retBytes[0] = (byte) (lspID >> 12);
retBytes[1] = (byte) (lspID >> 4);
retBytes[2] = (byte) (lspID << 4);
if (specObj.isDelegate())
retBytes[3] |= 1 << (Byte.SIZE - (DELEGATE_FLAG_OFFSET - Byte.SIZE) - 1);
- if (specObj.isOperational())
- retBytes[3] |= 1 << (Byte.SIZE - (OPERATIONAL_FLAG_OFFSET - Byte.SIZE) - 1);
+ // FIXME: !!
+ // if (specObj.isOperational())
+ // retBytes[3] |= 1 << (Byte.SIZE - (OPERATIONAL_FLAG_OFFSET - Byte.SIZE) - 1);
if (specObj.isRemove())
retBytes[3] |= 1 << (Byte.SIZE - (REMOVE_FLAG_OFFSET - Byte.SIZE) - 1);
if (specObj.isSync())
retBytes[3] |= 1 << (Byte.SIZE - (SYNC_FLAG_OFFSET - Byte.SIZE) - 1);
- ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET);
+ // ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET);
return retBytes;
}
+ @Override
+ public int getObjectType() {
+ return TYPE;
+ }
+
+ @Override
+ public int getObjectClass() {
+ return CLASS;
+ }
}