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.PCEPDocumentedException;
12 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
13 import org.opendaylight.protocol.util.ByteArray;
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.OfId;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfObject;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.OfBuilder;
22 * Parser for {@link OfObject}
24 public class PCEPObjectiveFunctionObjectParser extends AbstractObjectWithTlvsParser<OfBuilder> {
26 public static final int CLASS = 21;
28 public static final int TYPE = 1;
32 private static final int OF_CODE_F_LENGTH = 2;
37 private static final int OF_CODE_F_OFFSET = 0;
38 private static final int TLVS_OFFSET = OF_CODE_F_OFFSET + OF_CODE_F_LENGTH + 2;
40 public PCEPObjectiveFunctionObjectParser(final TlvHandlerRegistry tlvReg) {
45 public OfObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, PCEPDocumentedException {
46 if (bytes == null || bytes.length == 0) {
47 throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
49 final OfBuilder builder = new OfBuilder();
50 builder.setIgnore(header.isIgnore());
51 builder.setProcessingRule(header.isProcessingRule());
52 builder.setCode(new OfId(ByteArray.bytesToInt(ByteArray.subByte(bytes, OF_CODE_F_OFFSET, OF_CODE_F_LENGTH))));
53 return builder.build();
57 public void addTlv(final OfBuilder builder, final Tlv tlv) {
62 public byte[] serializeObject(final Object object) {
63 if (!(object instanceof OfObject)) {
64 throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass()
65 + ". Needed PCEPObjectiveFunction.");
67 final OfObject specObj = (OfObject) object;
68 final byte[] retBytes = new byte[TLVS_OFFSET + 0];
69 ByteArray.copyWhole(ByteArray.shortToBytes(specObj.getCode().getValue().shortValue()), retBytes, OF_CODE_F_OFFSET);
74 public int getObjectType() {
79 public int getObjectClass() {