import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.PCEPDocumentedException;
import org.opendaylight.protocol.pcep.PCEPErrors;
-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;
+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;
/**
* Parser for {@link org.opendaylight.protocol.pcep.object.PCEPClassTypeObject PCEPClassTypeObject}
*/
-public class PCEPClassTypeObjectParser extends AbstractObjectParser<ClassTypeBuilder> {
-
- public static final int CLASS = 22;
-
- public static final int TYPE = 1;
+public class PCEPClassTypeObjectParser implements PCEPObjectParser {
/**
* 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 ClasstypeObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
- PCEPDocumentedException {
+ public PCEPObject parse(byte[] bytes, boolean processed, boolean ignored)
+ 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 (!header.isProcessingRule())
+ throw new PCEPDeserializerException("Size of byte array doesn't match defined size. Expected: " + SIZE + "; Passed: " + bytes.length);
+ if (!processed)
throw new PCEPDocumentedException("Processed bit not set", PCEPErrors.P_FLAG_NOT_SET);
-
- 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);
+ final short classType = (short) (bytes[SIZE-1] & 0xFF);
+ if (classType < 0 || classType > 8) {
+ throw new PCEPDocumentedException("Invalid class type " + classType, PCEPErrors.INVALID_CT);
}
- return builder.build();
+ return new PCEPClassTypeObject(classType);
}
@Override
- 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.");
+ public byte[] put(PCEPObject obj) {
+ if (!(obj instanceof PCEPClassTypeObject))
+ throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPClassTypeObject.");
final byte[] retBytes = new byte[SIZE];
- retBytes[SIZE - 1] = ((ClasstypeObject) object).getClassType().getValue().byteValue();
+ retBytes[SIZE-1] = ByteArray.shortToBytes(((PCEPClassTypeObject) obj).getClassType())[1];
return retBytes;
}
-
- @Override
- public int getObjectType() {
- return TYPE;
- }
-
- @Override
- public int getObjectClass() {
- return CLASS;
- }
}