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.spi.TlvHandlerRegistry;
12 import org.opendaylight.protocol.util.ByteArray;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfId;
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.of.object.Of;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.OfBuilder;
21 * Parser for {@link Of}
23 public class PCEPObjectiveFunctionObjectParser extends AbstractObjectWithTlvsParser<OfBuilder> {
25 public static final int CLASS = 21;
27 public static final int TYPE = 1;
31 private static final int OF_CODE_F_LENGTH = 2;
36 private static final int OF_CODE_F_OFFSET = 0;
37 private static final int TLVS_OFFSET = OF_CODE_F_OFFSET + OF_CODE_F_LENGTH + 2;
39 public PCEPObjectiveFunctionObjectParser(final TlvHandlerRegistry tlvReg) {
44 public Of parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException {
45 if (bytes == null || bytes.length == 0) {
46 throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
48 final OfBuilder builder = new OfBuilder();
49 builder.setIgnore(header.isIgnore());
50 builder.setProcessingRule(header.isProcessingRule());
51 builder.setCode(new OfId(ByteArray.bytesToInt(ByteArray.subByte(bytes, OF_CODE_F_OFFSET, OF_CODE_F_LENGTH))));
52 return builder.build();
56 public void addTlv(final OfBuilder builder, final Tlv tlv) {
61 public byte[] serializeObject(final Object object) {
62 if (!(object instanceof Of)) {
63 throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass()
64 + ". Needed PCEPObjectiveFunction.");
66 final Of specObj = (Of) object;
67 final byte[] retBytes = new byte[TLVS_OFFSET + 0];
68 ByteArray.copyWhole(ByteArray.shortToBytes(specObj.getCode().getValue().shortValue()), retBytes, OF_CODE_F_OFFSET);
73 public int getObjectType() {
78 public int getObjectClass() {