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 com.google.common.primitives.UnsignedBytes;
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.Unpooled;
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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.gc.object.Gc;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.gc.object.GcBuilder;
26 * Parser for {@link Gc}
28 public class PCEPGlobalConstraintsObjectParser extends AbstractObjectWithTlvsParser<GcBuilder> {
30 public static final int CLASS = 24;
32 public static final int TYPE = 1;
34 public PCEPGlobalConstraintsObjectParser(final TlvRegistry tlvReg) {
39 public Gc parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
40 Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
41 final GcBuilder builder = new GcBuilder();
43 builder.setIgnore(header.isIgnore());
44 builder.setProcessingRule(header.isProcessingRule());
46 builder.setMaxHop((short) UnsignedBytes.toInt(bytes.readByte()));
47 builder.setMaxUtilization((short) UnsignedBytes.toInt(bytes.readByte()));
48 builder.setMinUtilization((short) UnsignedBytes.toInt(bytes.readByte()));
49 builder.setOverBookingFactor((short) UnsignedBytes.toInt(bytes.readByte()));
50 return builder.build();
54 public void serializeObject(final Object object, final ByteBuf buffer) {
55 Preconditions.checkArgument(object instanceof Gc, "Wrong instance of PCEPObject. Passed %s. Needed GcObject.", object.getClass());
56 final Gc specObj = (Gc) object;
57 final ByteBuf body = Unpooled.buffer();
58 writeUnsignedByte(specObj.getMaxHop(), body);
59 writeUnsignedByte(specObj.getMaxUtilization(), body);
60 writeUnsignedByte(specObj.getMinUtilization(), body);
61 writeUnsignedByte(specObj.getOverBookingFactor(), body);
62 ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);