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 static java.util.Objects.requireNonNull;
12 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.LinkLrIdentifiers;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.common.Uint32;
17 import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
19 public final class LinkIdTlvParser implements LinkstateTlvParser.LinkstateTlvSerializer<LinkLrIdentifiers>,
20 LinkstateTlvParser<LinkLrIdentifiers> {
21 private static final int LINK_LR_IDENTIFIERS = 258;
24 public void serializeTlvBody(final LinkLrIdentifiers tlv, final ByteBuf body) {
25 ByteBufUtils.writeOrZero(body, tlv.getLinkLocalIdentifier());
26 ByteBufUtils.writeOrZero(body, tlv.getLinkRemoteIdentifier());
30 public LinkLrIdentifiers parseTlvBody(final ByteBuf value) {
31 final Uint32 localId = ByteBufUtils.readUint32(value);
32 final Uint32 remoteId = ByteBufUtils.readUint32(value);
33 return new AnonymousLinkLrIdentifiers(localId, remoteId);
37 public QName getTlvQName() {
38 return LinkLrIdentifiers.QNAME;
42 public int getType() {
43 return LINK_LR_IDENTIFIERS;
46 private static final class AnonymousLinkLrIdentifiers implements LinkLrIdentifiers {
47 private final Uint32 localId;
48 private final Uint32 remoteId;
50 AnonymousLinkLrIdentifiers(final Uint32 localId, final Uint32 remoteId) {
51 this.localId = requireNonNull(localId);
52 this.remoteId = requireNonNull(remoteId);
56 public Class<LinkLrIdentifiers> implementedInterface() {
57 return LinkLrIdentifiers.class;
61 public Uint32 getLinkRemoteIdentifier() {
66 public Uint32 getLinkLocalIdentifier() {