2 * Copyright (c) 2013 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.bgp.linkstate.spi;
10 import io.netty.buffer.ByteBuf;
11 import io.netty.buffer.ByteBufUtil;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
15 public final class TlvUtil {
18 throw new UnsupportedOperationException();
21 private static final Logger LOG = LoggerFactory.getLogger(TlvUtil.class);
23 public static final int TOPOLOGY_ID_OFFSET = 0x3fff;
25 public static final int MULTI_TOPOLOGY_ID = 263;
26 public static final int LOCAL_IPV4_ROUTER_ID = 1028;
27 public static final int LOCAL_IPV6_ROUTER_ID = 1029;
30 * Util method for writing TLV header.
31 * @param type TLV type (2B)
32 * @param value TLV value (2B)
33 * @param byteAggregator final ByteBuf where the tlv should be serialized
35 public static void writeTLV(final int type, final ByteBuf value, final ByteBuf byteAggregator){
36 byteAggregator.writeShort(type);
37 byteAggregator.writeShort(value.writerIndex());
38 byteAggregator.writeBytes(value);
40 if (LOG.isDebugEnabled()) {
41 LOG.debug("Serialized tlv type {} to: {}", type, ByteBufUtil.hexDump(value));
46 * Util method for writing Segment routing TLV header.
47 * @param type TLV type (1B)
48 * @param value TLV value (1B)
49 * @param byteAggregator final ByteBuf where the tlv should be serialized
51 public static void writeSrTLV(final int type, final ByteBuf value, final ByteBuf byteAggregator){
52 byteAggregator.writeByte(type);
53 byteAggregator.writeByte(value.writerIndex());
54 byteAggregator.writeBytes(value);
56 if (LOG.isDebugEnabled()) {
57 LOG.debug("Serialized tlv type {} to: {}", type, ByteBufUtil.hexDump(value));