Enable restart of CSS modules on blueprint container restart
[bgpcep.git] / pcep / base-parser / src / main / java / org / opendaylight / protocol / pcep / parser / object / AbstractPceIdObjectParser.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.protocol.pcep.parser.object;
10
11 import com.google.common.base.Preconditions;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.Unpooled;
14 import org.opendaylight.protocol.pcep.spi.ObjectParser;
15 import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
16 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
17 import org.opendaylight.protocol.util.ByteBufWriteUtil;
18 import org.opendaylight.protocol.util.Ipv4Util;
19 import org.opendaylight.protocol.util.Ipv6Util;
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.pce.id.object.PceId;
22
23 public abstract class AbstractPceIdObjectParser implements ObjectParser, ObjectSerializer {
24
25     public static final int CLASS = 25;
26
27     public static final int IPV4_TYPE = 1;
28     public static final int IPV6_TYPE = 2;
29
30     @Override
31     public void serializeObject(final Object object, final ByteBuf buffer) {
32         Preconditions.checkArgument(object instanceof PceId, "Wrong instance of PCEPObject. Passed %s. Needed PccIdReqObject.", object.getClass());
33         final PceId pceId = (PceId) object;
34         if (pceId.getIpAddress().getIpv4Address() != null) {
35             final ByteBuf body = Unpooled.buffer(Ipv4Util.IP4_LENGTH);
36             ByteBufWriteUtil.writeIpv4Address(pceId.getIpAddress().getIpv4Address(), body);
37             ObjectUtil.formatSubobject(IPV4_TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
38         } else if (pceId.getIpAddress().getIpv6Address() != null) {
39             final ByteBuf body = Unpooled.buffer(Ipv6Util.IPV6_LENGTH);
40             ByteBufWriteUtil.writeIpv6Address(pceId.getIpAddress().getIpv6Address(), body);
41             ObjectUtil.formatSubobject(IPV6_TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
42         }
43     }
44
45 }