2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.pcep.impl.object;
10 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
11 import org.opendaylight.protocol.pcep.PCEPErrors;
12 import org.opendaylight.protocol.pcep.UnknownObject;
13 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.classtype.object.ClassType;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.classtype.object.ClassTypeBuilder;
20 import com.google.common.primitives.UnsignedBytes;
23 * Parser for {@link ClassType}
25 public class PCEPClassTypeObjectParser extends AbstractObjectWithTlvsParser<ClassTypeBuilder> {
27 public static final int CLASS = 22;
29 public static final int TYPE = 1;
32 * Length of Class Type field in bits.
34 private static final int CT_F_LENGTH = 3;
37 * Reserved field bit length.
39 private static final int RESERVED = 29;
42 * Size of the object in bytes.
44 private static final int SIZE = (RESERVED + CT_F_LENGTH) / 8;
46 public PCEPClassTypeObjectParser(final TlvHandlerRegistry tlvReg) {
51 public Object parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException {
53 throw new IllegalArgumentException("Byte array is mandatory.");
55 if (bytes.length != SIZE) {
56 throw new PCEPDeserializerException("Size of byte array doesn't match defined size. Expected: " + SIZE + "; Passed: "
59 if (!header.isProcessingRule()) {
60 //LOG.debug("Processed bit not set on CLASS TYPE OBJECT, ignoring it");
63 final ClassTypeBuilder builder = new ClassTypeBuilder();
65 builder.setIgnore(header.isIgnore());
66 builder.setProcessingRule(header.isProcessingRule());
68 final short ct = (short) UnsignedBytes.toInt(bytes[SIZE - 1]);
69 builder.setClassType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClassType(ct));
71 if (ct < 0 || ct > 8) {
72 // LOG.info("Invalid class type {}", ct);
73 return new UnknownObject(PCEPErrors.INVALID_CT);
75 return builder.build();
79 public void addTlv(final ClassTypeBuilder builder, final Tlv tlv) {
84 public byte[] serializeObject(final Object object) {
85 if (!(object instanceof ClassType)) {
86 throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed ClasstypeObject.");
88 final byte[] retBytes = new byte[SIZE];
89 retBytes[SIZE - 1] = UnsignedBytes.checkedCast(((ClassType) object).getClassType().getValue());
94 public int getObjectType() {
99 public int getObjectClass() {