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.bgp.linkstate.impl.tlvs;
10 import io.netty.buffer.ByteBuf;
11 import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
12 import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.TopologyIdentifier;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.link._case.LinkDescriptors;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.common.Uint16;
17 import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
18 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
20 public final class MultiTopoIdTlvParser implements LinkstateTlvParser<TopologyIdentifier>,
21 LinkstateTlvParser.LinkstateTlvSerializer<TopologyIdentifier> {
22 public static final QName MULTI_TOPOLOGY_ID_QNAME = QName.create(LinkDescriptors.QNAME, "multi-topology-id")
26 public void serializeTlvBody(final TopologyIdentifier tlv, final ByteBuf body) {
27 ByteBufUtils.write(body, tlv.getValue());
31 public int getType() {
32 return TlvUtil.MULTI_TOPOLOGY_ID;
36 public TopologyIdentifier parseTlvBody(final ByteBuf value) {
37 return new TopologyIdentifier(Uint16.valueOf(value.readShort() & TlvUtil.TOPOLOGY_ID_OFFSET));
41 public QName getTlvQName() {
42 return MULTI_TOPOLOGY_ID_QNAME;
45 public static TopologyIdentifier serializeModel(final ContainerNode prefixDesc) {
46 return prefixDesc.getChild(TlvUtil.MULTI_TOPOLOGY_NID)
47 .map(child -> new TopologyIdentifier((Uint16) child.getValue()))