2 * Copyright (c) 2014 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.parser.object;
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static org.opendaylight.protocol.pcep.spi.VendorInformationUtil.VENDOR_INFORMATION_OBJECT_CLASS;
12 import static org.opendaylight.protocol.pcep.spi.VendorInformationUtil.VENDOR_INFORMATION_OBJECT_TYPE;
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.Unpooled;
16 import org.opendaylight.protocol.pcep.spi.CommonObjectParser;
17 import org.opendaylight.protocol.pcep.spi.EnterpriseSpecificInformationParser;
18 import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
19 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
20 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.objects.VendorInformationObject;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.objects.VendorInformationObjectBuilder;
26 import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
28 public abstract class AbstractVendorInformationObjectParser extends CommonObjectParser
29 implements ObjectSerializer, EnterpriseSpecificInformationParser {
30 public AbstractVendorInformationObjectParser(final int objectClass, final int objectType) {
31 super(objectClass, objectType);
35 public final Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException {
36 checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
37 return new VendorInformationObjectBuilder()
38 .setEnterpriseNumber(new EnterpriseNumber(getEnterpriseNumber()))
39 .setEnterpriseSpecificInformation(parseEnterpriseSpecificInformation(buffer))
44 public final void serializeObject(final Object object, final ByteBuf buffer) {
45 checkArgument(object instanceof VendorInformationObject,
46 "Wrong instance of PCEPObject. Passed %s. Needed VendorInformationObject.", object.getClass());
47 final ByteBuf body = Unpooled.buffer();
48 ByteBufUtils.write(body, getEnterpriseNumber().getValue());
49 serializeEnterpriseSpecificInformation(((VendorInformationObject) object).getEnterpriseSpecificInformation(),
51 ObjectUtil.formatSubobject(VENDOR_INFORMATION_OBJECT_TYPE, VENDOR_INFORMATION_OBJECT_CLASS,
52 object.isProcessingRule(), object.isIgnore(), body, buffer);