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;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.Unpooled;
14 import org.opendaylight.protocol.pcep.spi.CommonObjectParser;
15 import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
16 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
17 import org.opendaylight.protocol.util.Ipv4Util;
18 import org.opendaylight.protocol.util.Ipv6Util;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcc.id.req.object.PccIdReq;
22 public abstract class AbstractPccIdReqObjectParser extends CommonObjectParser implements ObjectSerializer {
23 private static final int CLASS = 20;
25 public AbstractPccIdReqObjectParser(final int objectType) {
26 super(CLASS, objectType);
30 public void serializeObject(final Object object, final ByteBuf buffer) {
31 checkArgument(object instanceof PccIdReq, "Wrong instance of PCEPObject. Passed %s. Needed PccIdReqObject.",
33 final PccIdReq pccIdReq = (PccIdReq) object;
34 if (pccIdReq.getIpAddress().getIpv4AddressNoZone() != null) {
35 final ByteBuf body = Unpooled.buffer(Ipv4Util.IP4_LENGTH);
36 Ipv4Util.writeIpv4Address(pccIdReq.getIpAddress().getIpv4AddressNoZone(), body);
37 ObjectUtil.formatSubobject(getObjectType(), getObjectClass(), object.isProcessingRule(), object.isIgnore(),
39 } else if (pccIdReq.getIpAddress().getIpv6AddressNoZone() != null) {
40 final ByteBuf body = Unpooled.buffer(Ipv6Util.IPV6_LENGTH);
41 Ipv6Util.writeIpv6Address(pccIdReq.getIpAddress().getIpv6AddressNoZone(), body);
42 ObjectUtil.formatSubobject(getObjectType(), getObjectClass(), object.isProcessingRule(), object.isIgnore(),