import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.PCEPDocumentedException;
import org.opendaylight.protocol.pcep.PCEPErrors;
-import org.opendaylight.protocol.pcep.PCEPObject;
-import org.opendaylight.protocol.pcep.impl.PCEPObjectParser;
-import org.opendaylight.protocol.pcep.object.PCEPClassTypeObject;
-import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.pcep.spi.AbstractObjectParser;
+import org.opendaylight.protocol.pcep.spi.HandlerRegistry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClassType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClasstypeObject;
+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.ClassTypeBuilder;
/**
* Parser for {@link org.opendaylight.protocol.pcep.object.PCEPClassTypeObject PCEPClassTypeObject}
*/
-public class PCEPClassTypeObjectParser implements PCEPObjectParser {
+public class PCEPClassTypeObjectParser extends AbstractObjectParser<ClassTypeBuilder> {
+
+ public static final int CLASS = 22;
+
+ public static final int TYPE = 1;
/**
* Length of Class Type field in bits.
*/
public static final int SIZE = (RESERVED + CT_F_LENGTH) / 8;
+ public PCEPClassTypeObjectParser(final HandlerRegistry registry) {
+ super(registry);
+ }
+
@Override
- public PCEPObject parse(byte[] bytes, boolean processed, boolean ignored)
- throws PCEPDeserializerException, PCEPDocumentedException {
+ public ClasstypeObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
+ PCEPDocumentedException {
if (bytes == null)
throw new IllegalArgumentException("Byte array is mandatory.");
if (bytes.length != SIZE)
- throw new PCEPDeserializerException("Size of byte array doesn't match defined size. Expected: " + SIZE + "; Passed: " + bytes.length);
- if (!processed)
+ throw new PCEPDeserializerException("Size of byte array doesn't match defined size. Expected: " + SIZE + "; Passed: "
+ + bytes.length);
+ if (!header.isProcessingRule())
throw new PCEPDocumentedException("Processed bit not set", PCEPErrors.P_FLAG_NOT_SET);
- final short classType = (short) (bytes[SIZE-1] & 0xFF);
- if (classType < 0 || classType > 8) {
- throw new PCEPDocumentedException("Invalid class type " + classType, PCEPErrors.INVALID_CT);
+
+ final ClassTypeBuilder builder = new ClassTypeBuilder();
+
+ builder.setIgnore(header.isIgnore());
+ builder.setProcessingRule(header.isProcessingRule());
+
+ final short ct = (short) (bytes[SIZE - 1] & 0xFF);
+ builder.setClassType(new ClassType(ct));
+
+ if (ct < 0 || ct > 8) {
+ throw new PCEPDocumentedException("Invalid class type " + ct, PCEPErrors.INVALID_CT);
}
- return new PCEPClassTypeObject(classType);
+ return builder.build();
}
@Override
- public byte[] put(PCEPObject obj) {
- if (!(obj instanceof PCEPClassTypeObject))
- throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPClassTypeObject.");
+ public void addTlv(final ClassTypeBuilder builder, final Tlv tlv) {
+ // No tlvs defined
+ }
+
+ @Override
+ public byte[] serializeObject(final Object object) {
+ if (!(object instanceof ClasstypeObject))
+ throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed ClasstypeObject.");
final byte[] retBytes = new byte[SIZE];
- retBytes[SIZE-1] = ByteArray.shortToBytes(((PCEPClassTypeObject) obj).getClassType())[1];
+ retBytes[SIZE - 1] = ((ClasstypeObject) object).getClassType().getValue().byteValue();
return retBytes;
}
+
+ @Override
+ public int getObjectType() {
+ return TYPE;
+ }
+
+ @Override
+ public int getObjectClass() {
+ return CLASS;
+ }
}