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 static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
12 import com.google.common.base.Preconditions;
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.Unpooled;
15 import java.util.List;
16 import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
17 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
18 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
19 import org.opendaylight.protocol.pcep.spi.TlvRegistry;
20 import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.gc.object.Gc;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.gc.object.GcBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.gc.object.gc.Tlvs;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.gc.object.gc.TlvsBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv;
30 * Parser for {@link Gc}
32 public class PCEPGlobalConstraintsObjectParser extends AbstractObjectWithTlvsParser<TlvsBuilder> {
34 public static final int CLASS = 24;
36 public static final int TYPE = 1;
38 public PCEPGlobalConstraintsObjectParser(final TlvRegistry tlvReg, final VendorInformationTlvRegistry viTlvReg) {
39 super(tlvReg, viTlvReg);
43 public Gc parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
44 Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
45 final GcBuilder builder = new GcBuilder();
47 builder.setIgnore(header.isIgnore());
48 builder.setProcessingRule(header.isProcessingRule());
50 builder.setMaxHop(bytes.readUnsignedByte());
51 builder.setMaxUtilization(bytes.readUnsignedByte());
52 builder.setMinUtilization(bytes.readUnsignedByte());
53 builder.setOverBookingFactor(bytes.readUnsignedByte());
54 final TlvsBuilder tlvsBuilder = new TlvsBuilder();
55 parseTlvs(tlvsBuilder, bytes.slice());
56 builder.setTlvs(tlvsBuilder.build());
57 return builder.build();
61 public void serializeObject(final Object object, final ByteBuf buffer) {
62 Preconditions.checkArgument(object instanceof Gc, "Wrong instance of PCEPObject. Passed %s. Needed GcObject.", object.getClass());
63 final Gc specObj = (Gc) object;
64 final ByteBuf body = Unpooled.buffer();
65 writeUnsignedByte(specObj.getMaxHop(), body);
66 writeUnsignedByte(specObj.getMaxUtilization(), body);
67 writeUnsignedByte(specObj.getMinUtilization(), body);
68 writeUnsignedByte(specObj.getOverBookingFactor(), body);
69 serializeTlvs(specObj.getTlvs(), body);
70 ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
73 public void serializeTlvs(final Tlvs tlvs, final ByteBuf body) {
77 serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
81 protected final void addVendorInformationTlvs(final TlvsBuilder builder, final List<VendorInformationTlv> tlvs) {
82 if (!tlvs.isEmpty()) {
83 builder.setVendorInformationTlv(tlvs);