Enforce checkstyle in bgp-linkstate
[bgpcep.git] / bgp / extensions / linkstate / src / main / java / org / opendaylight / protocol / bgp / linkstate / spi / TlvUtil.java
1 /*
2  * Copyright (c) 2013 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 package org.opendaylight.protocol.bgp.linkstate.spi;
9
10 import io.netty.buffer.ByteBuf;
11 import io.netty.buffer.ByteBufUtil;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.prefix._case.PrefixDescriptors;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 public final class TlvUtil {
19
20     public static final int TOPOLOGY_ID_OFFSET = 0x3fff;
21     public static final int MULTI_TOPOLOGY_ID = 263;
22     public static final NodeIdentifier MULTI_TOPOLOGY_NID = new NodeIdentifier(QName.create(PrefixDescriptors.QNAME,
23         "topology-identifier").intern());
24     public static final int LOCAL_IPV4_ROUTER_ID = 1028;
25     public static final int LOCAL_IPV6_ROUTER_ID = 1029;
26     private static final Logger LOG = LoggerFactory.getLogger(TlvUtil.class);
27
28     private TlvUtil() {
29     }
30
31     /**
32      * Util method for writing TLV header.
33      *
34      * @param type TLV type (2B)
35      * @param value TLV value (2B)
36      * @param byteAggregator final ByteBuf where the tlv should be serialized
37      */
38     public static void writeTLV(final int type, final ByteBuf value, final ByteBuf byteAggregator) {
39         byteAggregator.writeShort(type);
40         byteAggregator.writeShort(value.writerIndex());
41         byteAggregator.writeBytes(value);
42         if (LOG.isDebugEnabled()) {
43             value.readerIndex(0);
44             LOG.debug("Serialized tlv type {} to: {}", type, ByteBufUtil.hexDump(value));
45         }
46     }
47 }