2 * Copyright (c) 2016 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.labeled.unicast;
10 import com.google.common.base.Preconditions;
11 import io.netty.buffer.ByteBuf;
12 import org.opendaylight.protocol.bgp.parser.spi.BgpPrefixSidTlvParser;
13 import org.opendaylight.protocol.bgp.parser.spi.BgpPrefixSidTlvSerializer;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.bgp.prefix.sid.bgp.prefix.sid.tlvs.bgp.prefix.sid.tlv.LuLabelIndexTlv;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.bgp.prefix.sid.bgp.prefix.sid.tlvs.bgp.prefix.sid.tlv.LuLabelIndexTlvBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.bgp.prefix.sid.bgp.prefix.sid.tlvs.BgpPrefixSidTlv;
18 final class LabelIndexTlvParser implements BgpPrefixSidTlvParser, BgpPrefixSidTlvSerializer {
20 private static final int LABEL_INDEX_TYPE = 1;
21 private static final int RESERVED = 1;
22 private static final int LABEL_INDEX_FLAGS_BYTES = 2;
25 public void serializeBgpPrefixSidTlv(final BgpPrefixSidTlv tlv, final ByteBuf valueBuf) {
26 Preconditions.checkArgument(tlv instanceof LuLabelIndexTlv, "Incoming TLV is not LuLabelIndexTlv");
27 valueBuf.writeZero(RESERVED);
28 valueBuf.writeZero(LABEL_INDEX_FLAGS_BYTES);
29 valueBuf.writeInt(((LuLabelIndexTlv) tlv).getLabelIndexTlv().intValue());
33 public LuLabelIndexTlv parseBgpPrefixSidTlv(final ByteBuf buffer) {
34 buffer.readBytes(RESERVED);
35 buffer.readBytes(LABEL_INDEX_FLAGS_BYTES);
36 final Long value = buffer.readUnsignedInt();
37 return new LuLabelIndexTlvBuilder().setLabelIndexTlv(value).build();
41 public int getType() {
42 return LABEL_INDEX_TYPE;