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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.BandwidthObject;
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.Tlv;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.segment.computation.p2p.reported.route.BandwidthBuilder;
21 * Parser for {@link BandwidthObject}
23 public class PCEPBandwidthObjectParser extends AbstractObjectWithTlvsParser<BandwidthBuilder> {
25 public static final int E_CLASS = 5;
27 public static final int E_TYPE = 1;
29 public static final int CLASS = 5;
31 public static final int TYPE = 2;
33 private static final int BANDWIDTH_F_LENGTH = 4;
35 public PCEPBandwidthObjectParser(final TlvHandlerRegistry tlvReg) {
40 public BandwidthObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
41 PCEPDocumentedException {
42 if (bytes == null || bytes.length == 0) {
43 throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
45 if (bytes.length != BANDWIDTH_F_LENGTH) {
46 throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.length + "; Expected: "
47 + BANDWIDTH_F_LENGTH + ".");
49 final BandwidthBuilder builder = new BandwidthBuilder();
50 builder.setIgnore(header.isIgnore());
51 builder.setProcessingRule(header.isProcessingRule());
52 builder.setBandwidth(new Float32(bytes));
53 return builder.build();
57 public void addTlv(final BandwidthBuilder builder, final Tlv tlv) {
62 public byte[] serializeObject(final Object object) {
63 if (!(object instanceof BandwidthObject)) {
64 throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed BandwidthObject.");
66 return ((BandwidthObject) object).getBandwidth().getValue();
70 public int getObjectType() {
75 public int getObjectClass() {
79 public int getEObjectType() {
83 public int getEObjectClass() {