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.impl.Util;
13 import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
14 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
15 import org.opendaylight.protocol.util.ByteArray;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.CloseObject;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
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.close.message.c.close.message.CClose;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.c.close.message.CCloseBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.Tlvs;
25 * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPCloseObject PCEPCloseObject}
27 public class PCEPCloseObjectParser extends AbstractObjectWithTlvsParser<CCloseBuilder> {
29 public static final int CLASS = 15;
31 public static final int TYPE = 1;
34 * lengths of fields in bytes
36 public static final int FLAGS_F_LENGTH = 1;
37 public static final int REASON_F_LENGTH = 1;
40 * offsets of fields in bytes
42 public static final int FLAGS_F_OFFSET = 2; // added reserved field of size 2 bytes
43 public static final int REASON_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH;
46 * total size of object in bytes
48 public static final int TLVS_OFFSET = REASON_F_OFFSET + REASON_F_LENGTH;
50 public PCEPCloseObjectParser(final TlvHandlerRegistry tlvReg) {
55 public CloseObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, PCEPDocumentedException {
57 throw new IllegalArgumentException("Byte array is mandatory.");
60 final CCloseBuilder builder = new CCloseBuilder();
62 parseTlvs(builder, ByteArray.cutBytes(bytes, TLVS_OFFSET));
64 builder.setIgnore(header.isIgnore());
65 builder.setProcessingRule(header.isProcessingRule());
67 builder.setReason((short) (bytes[REASON_F_OFFSET] & 0xFF));
69 return builder.build();
73 public void addTlv(final CCloseBuilder builder, final Tlv tlv) {
78 public byte[] serializeObject(final Object object) {
79 if (!(object instanceof CloseObject)) {
80 throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed CloseObject.");
83 final CloseObject obj = (CloseObject) object;
85 final byte[] tlvs = serializeTlvs(obj.getTlvs());
88 tlvsLength = tlvs.length;
90 final byte[] retBytes = new byte[TLVS_OFFSET + tlvsLength + Util.getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
93 ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET);
96 final int reason = ((CClose) obj).getReason().intValue();
98 retBytes[REASON_F_OFFSET] = (byte) reason;
103 public byte[] serializeTlvs(final Tlvs tlvs) {
109 public int getObjectType() {
114 public int getObjectClass() {