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.message.AbstractObjectWithTlvsParser;
13 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
14 import org.opendaylight.protocol.util.ByteArray;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.GcObject;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
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.pcreq.message.pcreq.message.svec.GcBuilder;
22 * Parser for {@link GcObject}
24 public class PCEPGlobalConstraintsObjectParser extends AbstractObjectWithTlvsParser<GcBuilder> {
26 public static final int CLASS = 24;
28 public static final int TYPE = 1;
30 private final static int MAX_HOP_F_LENGTH = 1;
31 private final static int MAX_UTIL_F_LENGTH = 1;
32 private final static int MIN_UTIL_F_LENGTH = 1;
33 private final static int OVER_BOOKING_FACTOR_F_LENGTH = 1;
35 private final static int MAX_HOP_F_OFFSET = 0;
36 private final static int MAX_UTIL_F_OFFSET = MAX_HOP_F_OFFSET + MAX_HOP_F_LENGTH;
37 private final static int MIN_UTIL_F_OFFSET = MAX_UTIL_F_OFFSET + MAX_UTIL_F_LENGTH;
38 private final static int OVER_BOOKING_FACTOR_F_OFFSET = MIN_UTIL_F_OFFSET + MIN_UTIL_F_LENGTH;
40 private final static int TLVS_OFFSET = OVER_BOOKING_FACTOR_F_OFFSET + OVER_BOOKING_FACTOR_F_LENGTH;
42 public PCEPGlobalConstraintsObjectParser(final TlvHandlerRegistry tlvReg) {
47 public GcObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, PCEPDocumentedException {
48 if (bytes == null || bytes.length == 0) {
49 throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
52 final GcBuilder builder = new GcBuilder();
54 parseTlvs(builder, ByteArray.cutBytes(bytes, TLVS_OFFSET));
56 builder.setIgnore(header.isIgnore());
57 builder.setProcessingRule(header.isProcessingRule());
59 builder.setMaxHop((short) (bytes[MAX_HOP_F_OFFSET] & 0xFF));
60 builder.setMinUtilization((short) (bytes[MIN_UTIL_F_OFFSET] & 0xFF));
61 builder.setMaxUtilization((short) (bytes[MAX_UTIL_F_OFFSET] & 0xFF));
62 builder.setOverBookingFactor((short) (bytes[OVER_BOOKING_FACTOR_F_OFFSET] & 0xFF));
64 return builder.build();
68 public void addTlv(final GcBuilder builder, final Tlv tlv) {
73 public byte[] serializeObject(final Object object) {
74 if (!(object instanceof GcObject)) {
75 throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed GcObject.");
78 final GcObject specObj = (GcObject) object;
80 // final byte[] tlvs = PCEPTlvParser.put(specObj.getTlvs());
81 final byte[] retBytes = new byte[TLVS_OFFSET + 0];
83 retBytes[MAX_HOP_F_OFFSET] = specObj.getMaxHop().byteValue();
84 retBytes[MAX_UTIL_F_OFFSET] = specObj.getMaxUtilization().byteValue();
85 retBytes[MIN_UTIL_F_OFFSET] = specObj.getMinUtilization().byteValue();
86 retBytes[OVER_BOOKING_FACTOR_F_OFFSET] = specObj.getOverBookingFactor().byteValue();
88 // ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET);
94 public int getObjectType() {
99 public int getObjectClass() {