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.AbstractObjectParser;
13 import org.opendaylight.protocol.pcep.spi.HandlerRegistry;
14 import org.opendaylight.protocol.util.ByteArray;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfId;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfObject;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.OfBuilder;
23 * Parser for {@link OfObject}
25 public class PCEPObjectiveFunctionObjectParser extends AbstractObjectParser<OfBuilder> {
27 public static final int CLASS = 21;
29 public static final int TYPE = 1;
33 public static final int OF_CODE_F_LENGTH = 2;
38 public static final int OF_CODE_F_OFFSET = 0;
39 public static final int TLVS_OFFSET = OF_CODE_F_OFFSET + OF_CODE_F_LENGTH + 2; // added reserved field of size 2
41 public PCEPObjectiveFunctionObjectParser(final HandlerRegistry registry) {
46 public OfObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, PCEPDocumentedException {
47 if (bytes == null || bytes.length == 0)
48 throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
50 final OfBuilder builder = new OfBuilder();
52 parseTlvs(builder, ByteArray.cutBytes(bytes, TLVS_OFFSET));
54 builder.setIgnore(header.isIgnore());
55 builder.setProcessingRule(header.isProcessingRule());
56 builder.setCode(new OfId(ByteArray.bytesToInt(ByteArray.subByte(bytes, OF_CODE_F_OFFSET, OF_CODE_F_LENGTH)) & 0xFFFF));
58 return builder.build();
62 public void addTlv(final OfBuilder builder, final Tlv tlv) {
67 public byte[] serializeObject(final Object object) {
68 if (!(object instanceof OfObject))
69 throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass()
70 + ". Needed PCEPObjectiveFunction.");
72 final OfObject specObj = (OfObject) object;
74 // final byte[] tlvs = PCEPTlvParser.put(specObj.getTlvs());
75 final byte[] retBytes = new byte[TLVS_OFFSET + 0];
77 // ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET);
79 ByteArray.copyWhole(ByteArray.shortToBytes(specObj.getCode().getValue().shortValue()), retBytes, OF_CODE_F_OFFSET);
85 public int getObjectType() {
90 public int getObjectClass() {