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
9 package org.opendaylight.protocol.pcep.parser.object;
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;
13 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
15 import com.google.common.base.Preconditions;
16 import io.netty.buffer.ByteBuf;
17 import io.netty.buffer.Unpooled;
18 import org.opendaylight.protocol.pcep.spi.CommonObjectParser;
19 import org.opendaylight.protocol.pcep.spi.EnterpriseSpecificInformationParser;
20 import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
21 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
22 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.objects.VendorInformationObject;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.objects.VendorInformationObjectBuilder;
29 public abstract class AbstractVendorInformationObjectParser extends CommonObjectParser
30 implements ObjectSerializer, EnterpriseSpecificInformationParser {
32 public AbstractVendorInformationObjectParser(final int objectClass, final int objectType) {
33 super(objectClass, objectType);
37 public final Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException {
38 Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
39 final VendorInformationObjectBuilder builder = new VendorInformationObjectBuilder();
40 builder.setEnterpriseNumber(new EnterpriseNumber(getEnterpriseNumber()));
41 builder.setEnterpriseSpecificInformation(parseEnterpriseSpecificInformation(buffer));
42 return builder.build();
46 public final void serializeObject(final Object object, final ByteBuf buffer) {
47 Preconditions.checkArgument(object instanceof VendorInformationObject, "Wrong instance of PCEPObject. Passed %s. Needed VendorInformationObject.", object.getClass());
48 final ByteBuf body = Unpooled.buffer();
49 writeUnsignedInt(getEnterpriseNumber().getValue(), body);
50 serializeEnterpriseSpecificInformation(((VendorInformationObject) object).getEnterpriseSpecificInformation(), body);
51 ObjectUtil.formatSubobject(VENDOR_INFORMATION_OBJECT_TYPE, VENDOR_INFORMATION_OBJECT_CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);