Merge "Bug-2226: RFC5886 - Messages parsers/serializers"
authorRobert Varga <nite@hq.sk>
Fri, 16 Jan 2015 14:07:39 +0000 (14:07 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 16 Jan 2015 14:07:39 +0000 (14:07 +0000)
41 files changed:
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/BGPActivator.java
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAdjRIBsIn.java
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAttributeParser.java [deleted file]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/LinkstateNlriParser.java [deleted file]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/TlvCode.java [deleted file]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/TlvUtil.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/LinkAttributesParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/LinkstateAttributeParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/NodeAttributesParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/PrefixAttributesParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/LinkNlriParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/LinkstateNlriParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/NodeNlriParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/PrefixNlriParser.java [new file with mode: 0644]
bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAdjRIBsInTest.java
bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAttributeParserTest.java
bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateNlriParserTest.java
bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/TlvUtilTest.java [moved from bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/TlvCodeTest.java with 83% similarity]
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RIBImpl.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AdjacencyRIBsInTest.java
bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/AbstractAdjRIBsTest.java
bgp/topology-provider/src/main/java/org/opendaylight/bgpcep/bgp/topology/provider/AbstractTopologyBuilder.java
bgp/topology-provider/src/test/java/org/opendaylight/bgpcep/bgp/topology/provider/AbstractTopologyBuilderTest.java
bgp/topology-provider/src/test/java/org/opendaylight/bgpcep/bgp/topology/provider/Ipv4ReachabilityTopologyBuilderTest.java
bgp/topology-provider/src/test/java/org/opendaylight/bgpcep/bgp/topology/provider/Ipv6ReachabilityTopologyBuilderTest.java
bgp/topology-provider/src/test/java/org/opendaylight/bgpcep/bgp/topology/provider/LinkstateTopologyBuilderTest.java
concepts/src/test/java/org/opendaylight/protocol/concepts/DefaultInstanceReferenceTest.java
data-change-counter/src/main/java/org/opendaylight/controller/config/yang/bgpcep/data/change/counter/DataChangeCounterImplModule.java
data-change-counter/src/main/java/org/opendaylight/protocol/data/change/counter/TopologyDataChangeCounter.java
integration-tests/src/test/java/org/opendaylight/protocol/integration/pcep/PcepRpcServicesRoutingTest.java
pcep/segment-routing/.project
pcep/topology-provider/src/main/java/org/opendaylight/controller/config/yang/pcep/topology/provider/PCEPTopologyProviderModule.java
pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/AbstractPCEPSessionTest.java
pcep/tunnel-provider/src/main/java/org/opendaylight/bgpcep/pcep/tunnel/provider/NodeChangedListener.java
pcep/tunnel-provider/src/main/java/org/opendaylight/bgpcep/pcep/tunnel/provider/PCEPTunnelTopologyProvider.java
pcep/tunnel-provider/src/main/java/org/opendaylight/controller/config/yang/pcep/tunnel/provider/PCEPTunnelTopologyProviderModule.java
pcep/tunnel-provider/src/test/java/org/opendaylight/bgpcep/pcep/tunnel/provider/NodeChangedListenerTest.java
pcep/tunnel-provider/src/test/java/org/opendaylight/bgpcep/pcep/tunnel/provider/TunnelProgrammingTest.java
pom.xml
programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/ProgrammingServiceImpl.java
programming/impl/src/test/java/org/opendaylight/bgpcep/programming/impl/ProgrammingServiceImplTest.java

index 6cd8bf65cde58c89f827e4fa126b1cf4e3b6f685..e7846bff8e6c0e55d87d48ce24a4c06cb9aa45c4 100644 (file)
@@ -9,6 +9,8 @@ package org.opendaylight.protocol.bgp.linkstate;
 
 import java.util.ArrayList;
 import java.util.List;
+import org.opendaylight.protocol.bgp.linkstate.attribute.LinkstateAttributeParser;
+import org.opendaylight.protocol.bgp.linkstate.nlri.LinkstateNlriParser;
 import org.opendaylight.protocol.bgp.parser.spi.AbstractBGPExtensionProviderActivator;
 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.LinkstateAddressFamily;
@@ -33,7 +35,7 @@ public final class BGPActivator extends AbstractBGPExtensionProviderActivator {
         this.ianaLinkstateAttributeType = true;
     }
 
-    public BGPActivator(boolean ianaLinkstateAttributeType) {
+    public BGPActivator(final boolean ianaLinkstateAttributeType) {
         super();
         this.ianaLinkstateAttributeType = ianaLinkstateAttributeType;
     }
@@ -51,8 +53,8 @@ public final class BGPActivator extends AbstractBGPExtensionProviderActivator {
                 new LinkstateNlriParser(true)));
         regs.add(context.registerNlriSerializer(PathAttributes.class, new LinkstateNlriParser(false)));
 
-        regs.add(context.registerAttributeSerializer(PathAttributes1.class, new LinkstateAttributeParser(ianaLinkstateAttributeType)));
-        final LinkstateAttributeParser linkstateAttributeParser = new LinkstateAttributeParser(ianaLinkstateAttributeType);
+        regs.add(context.registerAttributeSerializer(PathAttributes1.class, new LinkstateAttributeParser(this.ianaLinkstateAttributeType)));
+        final LinkstateAttributeParser linkstateAttributeParser = new LinkstateAttributeParser(this.ianaLinkstateAttributeType);
         regs.add(context.registerAttributeParser(linkstateAttributeParser.getType(), linkstateAttributeParser));
 
         return regs;
index a1456d73abdc716c9306cd1fbcef265154c870ce..1d949d90aac28fadf1b07e1998f9a1722af3e880 100644 (file)
@@ -13,6 +13,7 @@ import com.google.common.collect.Lists;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import java.util.List;
+import org.opendaylight.protocol.bgp.linkstate.nlri.LinkstateNlriParser;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.bgp.rib.spi.AbstractAdjRIBs;
 import org.opendaylight.protocol.bgp.rib.spi.AdjRIBsTransaction;
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAttributeParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAttributeParser.java
deleted file mode 100644 (file)
index 44c40d0..0000000
+++ /dev/null
@@ -1,635 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.linkstate;
-
-import com.google.common.base.Charsets;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Multimap;
-import com.google.common.net.InetAddresses;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.ByteBufUtil;
-import io.netty.buffer.Unpooled;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.BitSet;
-import java.util.List;
-import java.util.Map.Entry;
-import org.opendaylight.protocol.bgp.parser.BGPParsingException;
-import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
-import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
-import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
-import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.protocol.util.Ipv4Util;
-import org.opendaylight.protocol.util.Ipv6Util;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.AdministrativeGroup;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.ExtendedRouteTag;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.IgpBits.UpDown;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv4RouterIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv6RouterIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.IsisAreaIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.LinkProtectionType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.MplsProtocolMask;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.NlriType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.NodeFlagBits;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.PathAttributes1;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.PathAttributes1Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.RouteTag;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.TopologyIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.link.state.UnreservedBandwidth;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.link.state.UnreservedBandwidthBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.CLinkstateDestination;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.prefix.state.IgpBitsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.LinkstatePathAttribute;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.LinkstatePathAttributeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.LinkStateAttribute;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.LinkAttributesCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.LinkAttributesCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.NodeAttributesCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.NodeAttributesCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.PrefixAttributesCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.PrefixAttributesCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.node.attributes._case.NodeAttributes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.node.attributes._case.NodeAttributesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.prefix.attributes._case.PrefixAttributes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.prefix.attributes._case.PrefixAttributesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes2;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.DestinationType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.IgpMetric;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Metric;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.TeMetric;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.SrlgId;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Parser for Link State Path Attribute.
- *
- * @see <a href="http://tools.ietf.org/html/draft-gredler-idr-ls-distribution-04">BGP-LS draft</a>
- */
-public class LinkstateAttributeParser implements AttributeParser, AttributeSerializer {
-
-    private static final int TYPE = 29;
-
-    private static final int LEGACY_TYPE = 99;
-
-    private static final Logger LOG = LoggerFactory.getLogger(LinkstateAttributeParser.class);
-
-    private static final int ROUTE_TAG_LENGTH = 4;
-
-    private static final int EXTENDED_ROUTE_TAG_LENGTH = 8;
-
-    private static final int UNRESERVED_BW_COUNT = 8;
-
-    private static final int BANDWIDTH_LENGTH = 4;
-
-    // node flag bits
-    private static final int OVERLOAD_BIT = 7;
-    private static final int ATTACHED_BIT = 6;
-    private static final int EXTERNAL_BIT = 5;
-    private static final int ABBR_BIT = 4;
-
-    // MPLS protection mask bits
-    private static final int LDP_BIT = 7;
-    private static final int RSVP_BIT = 6;
-
-    private static final int UP_DOWN_BIT = 7;
-
-    private final int type;
-
-    public LinkstateAttributeParser(final boolean isIanaAssignedType) {
-        if(isIanaAssignedType) {
-            this.type = TYPE;
-        } else {
-            this.type = LEGACY_TYPE;
-        }
-    }
-
-    public int getType() {
-        return this.type;
-    }
-
-    private NlriType getNlriType(final PathAttributesBuilder pab) {
-        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1 mpr = pab.getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1.class);
-        if (mpr != null && mpr.getMpReachNlri() != null) {
-            final DestinationType dt = mpr.getMpReachNlri().getAdvertizedRoutes().getDestinationType();
-            if (dt instanceof DestinationLinkstateCase) {
-                for (final CLinkstateDestination d : ((DestinationLinkstateCase) dt).getDestinationLinkstate().getCLinkstateDestination()) {
-                    return d.getNlriType();
-                }
-            }
-        } else {
-            LOG.debug("No MP_REACH attribute present");
-        }
-        final PathAttributes2 mpu = pab.getAugmentation(PathAttributes2.class);
-        if (mpu != null && mpu.getMpUnreachNlri() != null) {
-            final DestinationType dt = mpu.getMpUnreachNlri().getWithdrawnRoutes().getDestinationType();
-            if (dt instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCase) {
-                for (final CLinkstateDestination d : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCase) dt).getDestinationLinkstate().getCLinkstateDestination()) {
-                    return d.getNlriType();
-                }
-            }
-        } else {
-            LOG.debug("No MP_UNREACH attribute present");
-        }
-        return null;
-    }
-
-    @Override
-    public void parseAttribute(final ByteBuf buffer, final PathAttributesBuilder builder) throws BGPParsingException {
-        final NlriType nlriType = getNlriType(builder);
-        if (nlriType == null) {
-            LOG.warn("No Linkstate NLRI found, not parsing Linkstate attribute");
-            return;
-        }
-        final PathAttributes1 a = new PathAttributes1Builder().setLinkstatePathAttribute(parseLinkState(nlriType, buffer)).build();
-        builder.addAugmentation(PathAttributes1.class, a);
-    }
-
-    private static LinkstatePathAttribute parseLinkState(final NlriType nlri, final ByteBuf buffer) throws BGPParsingException {
-        /*
-         * e.g. IS-IS Area Identifier TLV can occur multiple times
-         */
-        final Multimap<Integer, ByteBuf> map = HashMultimap.create();
-        while (buffer.isReadable()) {
-            final int type = buffer.readUnsignedShort();
-            final int length = buffer.readUnsignedShort();
-            final ByteBuf value = buffer.slice(buffer.readerIndex(), length);
-            map.put(type, value);
-            buffer.skipBytes(length);
-        }
-        final LinkstatePathAttributeBuilder builder = new LinkstatePathAttributeBuilder();
-
-        switch (nlri) {
-        case Ipv4Prefix:
-        case Ipv6Prefix:
-            builder.setLinkStateAttribute(parsePrefixAttributes(map));
-            return builder.build();
-        case Link:
-            builder.setLinkStateAttribute(parseLinkAttributes(map));
-            return builder.build();
-        case Node:
-            builder.setLinkStateAttribute(parseNodeAttributes(map));
-            return builder.build();
-        default:
-            throw new IllegalStateException("Unhandled NLRI type " + nlri);
-        }
-    }
-
-    /**
-     * Parse Link Attributes.
-     *
-     * @param attributes key is the tlv type and value is the value of the tlv
-     * @return {@link LinkStateAttribute}
-     */
-    private static LinkStateAttribute parseLinkAttributes(final Multimap<Integer, ByteBuf> attributes) {
-        final LinkAttributesBuilder builder = new LinkAttributesBuilder();
-        for (final Entry<Integer, ByteBuf> entry : attributes.entries()) {
-            LOG.trace("Link attribute TLV {}", entry.getKey());
-            final int key = entry.getKey();
-            final ByteBuf value = entry.getValue();
-            switch (key) {
-            case TlvCode.LOCAL_IPV4_ROUTER_ID:
-                final Ipv4RouterIdentifier lipv4 = new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value));
-                builder.setLocalIpv4RouterId(lipv4);
-                LOG.debug("Parsed IPv4 Router-ID of local node: {}", lipv4);
-                break;
-            case TlvCode.LOCAL_IPV6_ROUTER_ID:
-                final Ipv6RouterIdentifier lipv6 = new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value));
-                builder.setLocalIpv6RouterId(lipv6);
-                LOG.debug("Parsed IPv6 Router-ID of local node: {}", lipv6);
-                break;
-            case TlvCode.REMOTE_IPV4_ROUTER_ID:
-                final Ipv4RouterIdentifier ripv4 = new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value));
-                builder.setRemoteIpv4RouterId(ripv4);
-                LOG.debug("Parsed IPv4 Router-ID of remote node: {}", ripv4);
-                break;
-            case TlvCode.REMOTE_IPV6_ROUTER_ID:
-                final Ipv6RouterIdentifier ripv6 = new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value));
-                builder.setRemoteIpv6RouterId(ripv6);
-                LOG.debug("Parsed IPv6 Router-ID of remote node: {}", ripv6);
-                break;
-            case TlvCode.ADMIN_GROUP:
-                builder.setAdminGroup(new AdministrativeGroup(value.readUnsignedInt()));
-                LOG.debug("Parsed Administrative Group {}", builder.getAdminGroup());
-                break;
-            case TlvCode.MAX_BANDWIDTH:
-                builder.setMaxLinkBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
-                LOG.debug("Parsed Max Bandwidth {}", builder.getMaxLinkBandwidth());
-                break;
-            case TlvCode.MAX_RESERVABLE_BANDWIDTH:
-                builder.setMaxReservableBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
-                LOG.debug("Parsed Max Reservable Bandwidth {}", builder.getMaxReservableBandwidth());
-                break;
-            case TlvCode.UNRESERVED_BANDWIDTH:
-                final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.link.state.UnreservedBandwidth> unreservedBandwidth = new ArrayList<>(UNRESERVED_BW_COUNT);
-                for (int i = 0; i < UNRESERVED_BW_COUNT; i++) {
-                    final ByteBuf v = value.slice(value.readerIndex(), BANDWIDTH_LENGTH);
-                    unreservedBandwidth.add(new UnreservedBandwidthBuilder().setBandwidth(new Bandwidth(ByteArray.readAllBytes(v))).setPriority((short) i).build());
-                    value.skipBytes(BANDWIDTH_LENGTH);
-                }
-                builder.setUnreservedBandwidth(unreservedBandwidth);
-                LOG.debug("Parsed Unreserved Bandwidth {}", builder.getUnreservedBandwidth());
-                break;
-            case TlvCode.TE_METRIC:
-                builder.setTeMetric(new TeMetric(ByteArray.bytesToLong(ByteArray.readAllBytes(value))));
-                LOG.debug("Parsed Metric {}", builder.getTeMetric());
-                break;
-            case TlvCode.LINK_PROTECTION_TYPE:
-                final int l = value.readShort();
-                final LinkProtectionType lpt = LinkProtectionType.forValue(l);
-                if (lpt == null) {
-                    LOG.warn("Link Protection Type not recognized: {}", l);
-                    break;
-                }
-                builder.setLinkProtection(lpt);
-                LOG.debug("Parsed Link Protection Type {}", lpt);
-                break;
-            case TlvCode.MPLS_PROTOCOL:
-                final BitSet bits = BitSet.valueOf(ByteArray.readAllBytes(value));
-                builder.setMplsProtocol(new MplsProtocolMask(bits.get(LDP_BIT), bits.get(RSVP_BIT)));
-                LOG.debug("Parsed MPLS Protocols: {}", builder.getMplsProtocol());
-                break;
-            case TlvCode.METRIC:
-                // length can 3, 2 or 1
-                builder.setMetric(new Metric(ByteArray.bytesToLong(ByteArray.readAllBytes(value))));
-                LOG.debug("Parsed Metric {}", builder.getMetric());
-                break;
-            case TlvCode.SHARED_RISK_LINK_GROUP:
-                final List<SrlgId> sharedRiskLinkGroups = new ArrayList<>();
-                while (value.isReadable()) {
-                    sharedRiskLinkGroups.add(new SrlgId(value.readUnsignedInt()));
-                }
-                builder.setSharedRiskLinkGroups(sharedRiskLinkGroups);
-                LOG.debug("Parsed Shared Risk Link Groups {}", Arrays.toString(sharedRiskLinkGroups.toArray()));
-                break;
-            case TlvCode.LINK_OPAQUE:
-                LOG.debug("Parsed Opaque value : {}", ByteBufUtil.hexDump(value));
-                break;
-            case TlvCode.LINK_NAME:
-                final String name = new String(ByteArray.readAllBytes(value), Charsets.US_ASCII);
-                builder.setLinkName(name);
-                LOG.debug("Parsed Link Name : {}", name);
-                break;
-            default:
-                LOG.warn("TLV {} is not a valid link attribute, ignoring it", key);
-            }
-        }
-        LOG.trace("Finished parsing Link Attributes.");
-        return new LinkAttributesCaseBuilder().setLinkAttributes(builder.build()).build();
-    }
-
-    /**
-     * Parse Node Attributes.
-     *
-     * @param attributes key is the tlv type and value is the value of the tlv
-     * @return {@link LinkStateAttribute}
-     */
-    private static LinkStateAttribute parseNodeAttributes(final Multimap<Integer, ByteBuf> attributes) {
-        final List<TopologyIdentifier> topologyMembership = Lists.newArrayList();
-        final List<IsisAreaIdentifier> areaMembership = Lists.newArrayList();
-        final NodeAttributesBuilder builder = new NodeAttributesBuilder();
-        for (final Entry<Integer, ByteBuf> entry : attributes.entries()) {
-            final int key = entry.getKey();
-            final ByteBuf value = entry.getValue();
-            LOG.trace("Node attribute TLV {}", key);
-            switch (key) {
-            case TlvCode.MULTI_TOPOLOGY_ID:
-                while (value.isReadable()) {
-                    final TopologyIdentifier topId = new TopologyIdentifier(value.readUnsignedShort() & LinkstateNlriParser.TOPOLOGY_ID_OFFSET);
-                    topologyMembership.add(topId);
-                    LOG.debug("Parsed Topology Identifier: {}", topId);
-                }
-                break;
-            case TlvCode.NODE_FLAG_BITS:
-                final BitSet flags = BitSet.valueOf(ByteArray.readAllBytes(value));
-                builder.setNodeFlags(new NodeFlagBits(flags.get(OVERLOAD_BIT), flags.get(ATTACHED_BIT), flags.get(EXTERNAL_BIT), flags.get(ABBR_BIT)));
-                LOG.debug("Parsed Overload bit: {}, attached bit: {}, external bit: {}, area border router: {}.",
-                    flags.get(OVERLOAD_BIT), flags.get(ATTACHED_BIT), flags.get(EXTERNAL_BIT), flags.get(ABBR_BIT));
-                break;
-            case TlvCode.NODE_OPAQUE:
-                LOG.debug("Ignoring opaque value: {}.", ByteBufUtil.hexDump(value));
-                break;
-            case TlvCode.DYNAMIC_HOSTNAME:
-                builder.setDynamicHostname(new String(ByteArray.readAllBytes(value), Charsets.US_ASCII));
-                LOG.debug("Parsed Node Name {}", builder.getDynamicHostname());
-                break;
-            case TlvCode.ISIS_AREA_IDENTIFIER:
-                final IsisAreaIdentifier ai = new IsisAreaIdentifier(ByteArray.readAllBytes(value));
-                areaMembership.add(ai);
-                LOG.debug("Parsed AreaIdentifier {}", ai);
-                break;
-            case TlvCode.LOCAL_IPV4_ROUTER_ID:
-                final Ipv4RouterIdentifier ip4 = new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value));
-                builder.setIpv4RouterId(ip4);
-                LOG.debug("Parsed IPv4 Router Identifier {}", ip4);
-                break;
-            case TlvCode.LOCAL_IPV6_ROUTER_ID:
-                final Ipv6RouterIdentifier ip6 = new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value));
-                builder.setIpv6RouterId(ip6);
-                LOG.debug("Parsed IPv6 Router Identifier {}", ip6);
-                break;
-            default:
-                LOG.warn("TLV {} is not a valid node attribute, ignoring it", key);
-            }
-        }
-        LOG.trace("Finished parsing Node Attributes.");
-        builder.setTopologyIdentifier(topologyMembership);
-        builder.setIsisAreaId(areaMembership);
-        return new NodeAttributesCaseBuilder().setNodeAttributes(builder.build()).build();
-    }
-
-    /**
-     * Parse prefix attributes.
-     *
-     * @param attributes key is the tlv type and value are the value bytes of the tlv
-     * @return {@link LinkStateAttribute}
-     */
-    private static LinkStateAttribute parsePrefixAttributes(final Multimap<Integer, ByteBuf> attributes) {
-        final PrefixAttributesBuilder builder = new PrefixAttributesBuilder();
-        final List<RouteTag> routeTags = Lists.newArrayList();
-        final List<ExtendedRouteTag> exRouteTags = Lists.newArrayList();
-        for (final Entry<Integer, ByteBuf> entry : attributes.entries()) {
-            final int key = entry.getKey();
-            final ByteBuf value = entry.getValue();
-            LOG.trace("Prefix attribute TLV {}", key);
-            switch (key) {
-            case TlvCode.IGP_FLAGS:
-                final BitSet flags = BitSet.valueOf(ByteArray.readAllBytes(value));
-                final boolean upDownBit = flags.get(UP_DOWN_BIT);
-                builder.setIgpBits(new IgpBitsBuilder().setUpDown(new UpDown(upDownBit)).build());
-                LOG.debug("Parsed IGP flag (up/down bit) : {}", upDownBit);
-                break;
-            case TlvCode.ROUTE_TAG:
-                while (value.isReadable()) {
-                    final RouteTag routeTag = new RouteTag(ByteArray.readBytes(value, ROUTE_TAG_LENGTH));
-                    routeTags.add(routeTag);
-                    LOG.debug("Parsed Route Tag: {}", routeTag);
-                }
-                break;
-            case TlvCode.EXTENDED_ROUTE_TAG:
-                while (value.isReadable()) {
-                    final ExtendedRouteTag exRouteTag = new ExtendedRouteTag(ByteArray.readBytes(value, EXTENDED_ROUTE_TAG_LENGTH));
-                    exRouteTags.add(exRouteTag);
-                    LOG.debug("Parsed Extended Route Tag: {}", exRouteTag);
-                }
-                break;
-            case TlvCode.PREFIX_METRIC:
-                final IgpMetric metric = new IgpMetric(value.readUnsignedInt());
-                builder.setPrefixMetric(metric);
-                LOG.debug("Parsed Metric: {}", metric);
-                break;
-            case TlvCode.FORWARDING_ADDRESS:
-                final IpAddress fwdAddress = parseForwardingAddress(value);
-                builder.setOspfForwardingAddress(fwdAddress);
-                LOG.debug("Parsed FWD Address: {}", fwdAddress);
-                break;
-            case TlvCode.PREFIX_OPAQUE:
-                LOG.debug("Parsed Opaque value: {}, not preserving it", ByteBufUtil.hexDump(value));
-                break;
-            default:
-                LOG.warn("TLV {} is not a valid prefix attribute, ignoring it", key);
-            }
-        }
-        LOG.trace("Finished parsing Prefix Attributes.");
-        builder.setRouteTags(routeTags);
-        builder.setExtendedTags(exRouteTags);
-        return new PrefixAttributesCaseBuilder().setPrefixAttributes(builder.build()).build();
-    }
-
-    private static IpAddress parseForwardingAddress(final ByteBuf value) {
-        IpAddress fwdAddress = null;
-        switch (value.readableBytes()) {
-        case Ipv4Util.IP4_LENGTH:
-            fwdAddress = new IpAddress(Ipv4Util.addressForByteBuf(value));
-            break;
-        case Ipv6Util.IPV6_LENGTH:
-            fwdAddress = new IpAddress(Ipv6Util.addressForByteBuf(value));
-            break;
-        default:
-            LOG.debug("Ignoring unsupported forwarding address length {}", value.readableBytes());
-        }
-        return fwdAddress;
-    }
-
-    /**
-     * Serialize linkstate attributes.
-     *
-     * @param attribute DataObject representing LinkstatePathAttribute
-     * @param byteAggregator ByteBuf where all serialized data are aggregated
-     */
-
-    @Override
-    public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
-        Preconditions.checkArgument(attribute instanceof PathAttributes, "Attribute parameter is not a PathAttribute object.");
-        final PathAttributes1 pathAttributes1 = ((PathAttributes) attribute).getAugmentation(PathAttributes1.class);
-        if (pathAttributes1 == null) {
-            return;
-        }
-        final LinkStateAttribute linkState = pathAttributes1.getLinkstatePathAttribute().getLinkStateAttribute();
-        final ByteBuf lsBuffer = Unpooled.buffer();
-        if (linkState instanceof LinkAttributesCase) {
-            serializeLinkAttributes((LinkAttributesCase) linkState, lsBuffer);
-        } else if (linkState instanceof NodeAttributesCase) {
-            serializeNodeAttributes((NodeAttributesCase) linkState, lsBuffer);
-        } else if (linkState instanceof PrefixAttributesCase) {
-            serializePrefixAttributes((PrefixAttributesCase) linkState, lsBuffer);
-        }
-        AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL, getType(), lsBuffer, byteAggregator);
-    }
-
-    private void serializeLinkAttributes(final LinkAttributesCase linkAttributesCase, final ByteBuf byteAggregator) {
-        final LinkAttributes linkAttributes = linkAttributesCase.getLinkAttributes();
-        LOG.trace("Started serializing Link Attributes");
-        if (linkAttributes.getLocalIpv4RouterId() != null) {
-            writeTLV(TlvCode.LOCAL_IPV4_ROUTER_ID, Unpooled.wrappedBuffer(InetAddresses.forString(linkAttributes.getLocalIpv4RouterId().getValue()).getAddress()), byteAggregator);
-        }
-        if (linkAttributes.getLocalIpv6RouterId() != null) {
-            writeTLV(TlvCode.LOCAL_IPV6_ROUTER_ID, Unpooled.wrappedBuffer(InetAddresses.forString(linkAttributes.getLocalIpv6RouterId().getValue()).getAddress()), byteAggregator);
-        }
-        if (linkAttributes.getRemoteIpv4RouterId() != null) {
-            writeTLV(TlvCode.REMOTE_IPV4_ROUTER_ID, Unpooled.wrappedBuffer(InetAddresses.forString(linkAttributes.getRemoteIpv4RouterId().getValue()).getAddress()), byteAggregator);
-        }
-        if (linkAttributes.getRemoteIpv6RouterId() != null) {
-            writeTLV(TlvCode.REMOTE_IPV6_ROUTER_ID, Unpooled.wrappedBuffer(InetAddresses.forString(linkAttributes.getRemoteIpv6RouterId().getValue()).getAddress()), byteAggregator);
-        }
-        if (linkAttributes.getAdminGroup() != null) {
-            writeTLV(TlvCode.ADMIN_GROUP, Unpooled.copyInt(linkAttributes.getAdminGroup().getValue().intValue()), byteAggregator);
-        }
-        if (linkAttributes.getMaxLinkBandwidth() != null) {
-            writeTLV(TlvCode.MAX_BANDWIDTH, Unpooled.wrappedBuffer(linkAttributes.getMaxLinkBandwidth().getValue()), byteAggregator);
-        }
-        if (linkAttributes.getMaxReservableBandwidth() != null) {
-            writeTLV(TlvCode.MAX_RESERVABLE_BANDWIDTH, Unpooled.wrappedBuffer(linkAttributes.getMaxReservableBandwidth().getValue()), byteAggregator);
-        }
-        // this sub-TLV contains eight 32-bit IEEE floating point numbers
-        final List<UnreservedBandwidth> ubList = linkAttributes.getUnreservedBandwidth();
-        if (ubList != null && !ubList.isEmpty()) {
-            final ByteBuf unreservedBandwithBuf = Unpooled.buffer();
-            for (final UnreservedBandwidth unreservedBandwidth : ubList) {
-                unreservedBandwithBuf.writeBytes(unreservedBandwidth.getBandwidth().getValue());
-            }
-            writeTLV(TlvCode.UNRESERVED_BANDWIDTH, unreservedBandwithBuf, byteAggregator);
-        }
-        if (linkAttributes.getTeMetric() != null) {
-            writeTLV(TlvCode.TE_METRIC, Unpooled.copyLong(linkAttributes.getTeMetric().getValue().longValue()), byteAggregator);
-        }
-        if (linkAttributes.getLinkProtection() != null) {
-            writeTLV(TlvCode.LINK_PROTECTION_TYPE, Unpooled.copyShort(linkAttributes.getLinkProtection().getIntValue()), byteAggregator);
-        }
-        serializeMplsProtocolMask(linkAttributes.getMplsProtocol(), byteAggregator);
-        if (linkAttributes.getMetric() != null) {
-            // size of metric can be 1,2 or 3 depending on the protocol
-            writeTLV(TlvCode.METRIC, Unpooled.copyMedium(linkAttributes.getMetric().getValue().intValue()), byteAggregator);
-        }
-        final List<SrlgId> srlgList = linkAttributes.getSharedRiskLinkGroups();
-        if (srlgList != null && !srlgList.isEmpty()) {
-            final ByteBuf sharedRLGBuf = Unpooled.buffer();
-            for (final SrlgId srlgId : srlgList) {
-                sharedRLGBuf.writeInt(srlgId.getValue().intValue());
-            }
-            writeTLV(TlvCode.SHARED_RISK_LINK_GROUP, sharedRLGBuf, byteAggregator);
-        }
-        if (linkAttributes.getLinkName() != null) {
-            writeTLV(TlvCode.LINK_NAME, Unpooled.wrappedBuffer(Charsets.UTF_8.encode(linkAttributes.getLinkName())), byteAggregator);
-        }
-        LOG.trace("Finished serializing Link Attributes");
-    }
-
-    private static void serializeMplsProtocolMask(final MplsProtocolMask mplsProtocolMask, final ByteBuf byteAggregator ) {
-        if (mplsProtocolMask != null) {
-            final ByteBuf mplsProtocolMaskBuf = Unpooled.buffer();
-            final BitSet mask = new BitSet();
-            if (mplsProtocolMask.isLdp() != null) {
-                mask.set(LDP_BIT, mplsProtocolMask.isLdp());
-            }
-            if (mplsProtocolMask.isRsvpte() != null) {
-                mask.set(RSVP_BIT, mplsProtocolMask.isRsvpte());
-            }
-            mplsProtocolMaskBuf.writeBytes(mask.toByteArray());
-            writeTLV(TlvCode.MPLS_PROTOCOL, mplsProtocolMaskBuf, byteAggregator);
-        }
-    }
-
-    private void serializeNodeAttributes(final NodeAttributesCase nodeAttributesCase, final ByteBuf byteAggregator) {
-        LOG.trace("Started serializing Node Attributes");
-        final NodeAttributes nodeAttributes = nodeAttributesCase.getNodeAttributes();
-        final List<TopologyIdentifier> topList = nodeAttributes.getTopologyIdentifier();
-        if (topList != null && !topList.isEmpty()) {
-            final ByteBuf mpIdBuf = Unpooled.buffer();
-            for (final TopologyIdentifier topologyIdentifier : topList) {
-                mpIdBuf.writeShort(topologyIdentifier.getValue());
-            }
-            writeTLV(TlvCode.MULTI_TOPOLOGY_ID, mpIdBuf, byteAggregator);
-        }
-        serializeNodeFlagBits(nodeAttributes.getNodeFlags(), byteAggregator);
-        if (nodeAttributes.getDynamicHostname() != null) {
-            writeTLV(TlvCode.DYNAMIC_HOSTNAME, Unpooled.wrappedBuffer(Charsets.UTF_8.encode(nodeAttributes.getDynamicHostname())), byteAggregator);
-        }
-        final List<IsisAreaIdentifier> isisList = nodeAttributes.getIsisAreaId();
-        if (isisList != null && !isisList.isEmpty()) {
-            for (final IsisAreaIdentifier isisAreaIdentifier : isisList) {
-                writeTLV(TlvCode.ISIS_AREA_IDENTIFIER, Unpooled.wrappedBuffer(isisAreaIdentifier.getValue()), byteAggregator);
-            }
-        }
-        if (nodeAttributes.getIpv4RouterId() != null) {
-            writeTLV(TlvCode.LOCAL_IPV4_ROUTER_ID, Unpooled.wrappedBuffer(InetAddresses.forString(nodeAttributes.getIpv4RouterId().getValue()).getAddress()), byteAggregator);
-        }
-        if (nodeAttributes.getIpv6RouterId() != null) {
-            writeTLV(TlvCode.LOCAL_IPV6_ROUTER_ID, Unpooled.wrappedBuffer(InetAddresses.forString(nodeAttributes.getIpv6RouterId().getValue()).getAddress()), byteAggregator);
-        }
-        LOG.trace("Finished serializing Node Attributes");
-    }
-
-    private static void serializeNodeFlagBits(final NodeFlagBits nodeFlagBits, final ByteBuf byteAggregator) {
-        if (nodeFlagBits != null) {
-            final ByteBuf nodeFlagBuf = Unpooled.buffer();
-            final BitSet flags = new BitSet();
-            if (nodeFlagBits.isOverload() != null) {
-                flags.set(OVERLOAD_BIT, nodeFlagBits.isOverload());
-            }
-            if (nodeFlagBits.isAttached() != null) {
-                flags.set(ATTACHED_BIT, nodeFlagBits.isAttached());
-            }
-            if (nodeFlagBits.isExternal() != null) {
-                flags.set(EXTERNAL_BIT, nodeFlagBits.isExternal());
-            }
-            if (nodeFlagBits.isAbr() != null) {
-                flags.set(ABBR_BIT, nodeFlagBits.isAbr());
-            }
-            nodeFlagBuf.writeBytes(flags.toByteArray());
-            writeTLV(TlvCode.NODE_FLAG_BITS, nodeFlagBuf, byteAggregator);
-        }
-    }
-
-    private void serializePrefixAttributes(final PrefixAttributesCase prefixAttributesCase, final ByteBuf byteAggregator) {
-        final PrefixAttributes prefixAtrributes = prefixAttributesCase.getPrefixAttributes();
-        if (prefixAtrributes.getIgpBits() != null) {
-            final BitSet igpBit = new BitSet();
-            final Boolean bit = prefixAtrributes.getIgpBits().getUpDown().isUpDown();
-            if (bit != null) {
-                igpBit.set(UP_DOWN_BIT, bit);
-            }
-            writeTLV(TlvCode.IGP_FLAGS, Unpooled.wrappedBuffer(igpBit.toByteArray()), byteAggregator);
-        }
-        if (prefixAtrributes.getRouteTags() != null) {
-            final ByteBuf routeTagsBuf = Unpooled.buffer();
-            for (final RouteTag routeTag : prefixAtrributes.getRouteTags()) {
-                routeTagsBuf.writeBytes(routeTag.getValue());
-            }
-            writeTLV(TlvCode.ROUTE_TAG, routeTagsBuf, byteAggregator);
-        }
-        final List<ExtendedRouteTag> routeTagList = prefixAtrributes.getExtendedTags();
-        if (routeTagList != null && !routeTagList.isEmpty()) {
-            final ByteBuf extendedBuf = Unpooled.buffer();
-            for (final ExtendedRouteTag extendedRouteTag : routeTagList) {
-                extendedBuf.writeBytes(extendedRouteTag.getValue());
-            }
-            writeTLV(TlvCode.EXTENDED_ROUTE_TAG, extendedBuf, byteAggregator);
-        }
-        if (prefixAtrributes.getPrefixMetric() != null) {
-            writeTLV(TlvCode.PREFIX_METRIC, Unpooled.copyInt(prefixAtrributes.getPrefixMetric().getValue().intValue()), byteAggregator);
-        }
-        serializeForwardingAddress(prefixAtrributes.getOspfForwardingAddress(), byteAggregator);
-    }
-
-    private static void serializeForwardingAddress(final IpAddress forwardingAddress, final ByteBuf byteAggregator) {
-        if (forwardingAddress != null) {
-            final ByteBuf ospfBuf = Unpooled.buffer();
-            if (forwardingAddress.getIpv4Address() != null) {
-                ospfBuf.writeBytes(Ipv4Util.bytesForAddress(forwardingAddress.getIpv4Address()));
-            } else if (forwardingAddress.getIpv6Address() != null) {
-                ospfBuf.writeBytes(Ipv6Util.bytesForAddress(forwardingAddress.getIpv6Address()));
-            }
-            writeTLV(TlvCode.FORWARDING_ADDRESS, ospfBuf, byteAggregator);
-        }
-    }
-
-    /**
-     * Util method for writing TLV header.
-     * @param type TLV type
-     * @param value TLV value
-     * @param byteAggregator final ByteBuf where the tlv should be serialized
-     */
-    protected static void writeTLV(final int type, final ByteBuf value, final ByteBuf byteAggregator){
-        byteAggregator.writeShort(type);
-        byteAggregator.writeShort(value.writerIndex());
-        byteAggregator.writeBytes(value);
-        value.readerIndex(0);
-        LOG.debug("Serialized tlv type {} to: {}", type, ByteBufUtil.hexDump(value));
-    }
-}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/LinkstateNlriParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/LinkstateNlriParser.java
deleted file mode 100644 (file)
index 16b93c2..0000000
+++ /dev/null
@@ -1,520 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.linkstate;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import com.google.common.primitives.UnsignedBytes;
-import com.google.common.primitives.UnsignedInteger;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.ByteBufUtil;
-import io.netty.buffer.Unpooled;
-import java.math.BigInteger;
-import java.util.List;
-import org.opendaylight.protocol.bgp.parser.BGPParsingException;
-import org.opendaylight.protocol.bgp.parser.spi.NlriParser;
-import org.opendaylight.protocol.bgp.parser.spi.NlriSerializer;
-import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.protocol.util.Ipv4Util;
-import org.opendaylight.protocol.util.Ipv6Util;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.AreaIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.DomainIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Identifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv4InterfaceIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv6InterfaceIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.NlriType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.NodeIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.OspfInterfaceIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.OspfRouteType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.ProtocolId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.RouteDistinguisher;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.TopologyIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.isis.lan.identifier.IsIsRouterIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.isis.lan.identifier.IsIsRouterIdentifierBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.CLinkstateDestination;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.CLinkstateDestinationBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.LinkDescriptors;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.LinkDescriptorsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.LocalNodeDescriptors;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.LocalNodeDescriptorsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.PrefixDescriptors;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.PrefixDescriptorsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptors;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptorsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.CRouterIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.IsisNodeCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.IsisNodeCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.IsisPseudonodeCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.IsisPseudonodeCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.OspfNodeCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.OspfNodeCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.OspfPseudonodeCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.OspfPseudonodeCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.isis.node._case.IsisNode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.isis.node._case.IsisNodeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.isis.pseudonode._case.IsisPseudonode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.isis.pseudonode._case.IsisPseudonodeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.ospf.node._case.OspfNodeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.ospf.pseudonode._case.OspfPseudonode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.ospf.pseudonode._case.OspfPseudonodeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes2;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpReachNlriBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpUnreachNlri;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpUnreachNlriBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.mp.reach.nlri.AdvertizedRoutes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.IsoSystemIdentifier;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Parser and serializer for Linkstate NLRI.
- */
-public final class LinkstateNlriParser implements NlriParser, NlriSerializer {
-    private static final Logger LOG = LoggerFactory.getLogger(LinkstateNlriParser.class);
-    private static final int ROUTE_DISTINGUISHER_LENGTH = 8;
-    private static final int PROTOCOL_ID_LENGTH = 1;
-    private static final int IDENTIFIER_LENGTH = 8;
-    private static final int OSPF_PSEUDONODE_ROUTER_ID_LENGTH = 8;
-    private static final int OSPF_ROUTER_ID_LENGTH = 4;
-    private static final int ISO_SYSTEM_ID_LENGTH = 6;
-    private static final int PSN_LENGTH = 1;
-
-    private static final int TYPE_LENGTH = 2;
-    private static final int LENGTH_SIZE = 2;
-
-    static final int TOPOLOGY_ID_OFFSET = 0x3fff;
-
-    private final boolean isVpn;
-
-    public LinkstateNlriParser(final boolean isVpn) {
-        this.isVpn = isVpn;
-    }
-
-    private static NodeIdentifier parseLink(final CLinkstateDestinationBuilder builder, final ByteBuf buffer) throws BGPParsingException {
-        final int type = buffer.readUnsignedShort();
-        final int length = buffer.readUnsignedShort();
-        final NodeIdentifier remote = null;
-        if (type == TlvCode.REMOTE_NODE_DESCRIPTORS) {
-            builder.setRemoteNodeDescriptors((RemoteNodeDescriptors) parseNodeDescriptors(buffer.slice(buffer.readerIndex(), length), false));
-            buffer.skipBytes(length);
-        }
-        builder.setLinkDescriptors(parseLinkDescriptors(buffer.slice()));
-        return remote;
-    }
-
-    private static LinkDescriptors parseLinkDescriptors(final ByteBuf buffer) throws BGPParsingException {
-        final LinkDescriptorsBuilder builder = new LinkDescriptorsBuilder();
-        while (buffer.isReadable()) {
-            final int type = buffer.readUnsignedShort();
-            final int length = buffer.readUnsignedShort();
-            final ByteBuf value = buffer.slice(buffer.readerIndex(), length);
-            LOG.trace("Parsing Link Descriptor: {}", ByteBufUtil.hexDump(value));
-            switch (type) {
-            case TlvCode.LINK_LR_IDENTIFIERS:
-                builder.setLinkLocalIdentifier(value.readUnsignedInt());
-                builder.setLinkRemoteIdentifier(value.readUnsignedInt());
-                LOG.debug("Parsed link local {} remote {} Identifiers.", builder.getLinkLocalIdentifier(),
-                    builder.getLinkRemoteIdentifier());
-                break;
-            case TlvCode.IPV4_IFACE_ADDRESS:
-                final Ipv4InterfaceIdentifier lipv4 = new Ipv4InterfaceIdentifier(Ipv4Util.addressForByteBuf(value));
-                builder.setIpv4InterfaceAddress(lipv4);
-                LOG.debug("Parsed IPv4 interface address {}.", lipv4);
-                break;
-            case TlvCode.IPV4_NEIGHBOR_ADDRESS:
-                final Ipv4InterfaceIdentifier ripv4 = new Ipv4InterfaceIdentifier(Ipv4Util.addressForByteBuf(value));
-                builder.setIpv4NeighborAddress(ripv4);
-                LOG.debug("Parsed IPv4 neighbor address {}.", ripv4);
-                break;
-            case TlvCode.IPV6_IFACE_ADDRESS:
-                final Ipv6InterfaceIdentifier lipv6 = new Ipv6InterfaceIdentifier(Ipv6Util.addressForByteBuf(value));
-                builder.setIpv6InterfaceAddress(lipv6);
-                LOG.debug("Parsed IPv6 interface address {}.", lipv6);
-                break;
-            case TlvCode.IPV6_NEIGHBOR_ADDRESS:
-                final Ipv6InterfaceIdentifier ripv6 = new Ipv6InterfaceIdentifier(Ipv6Util.addressForByteBuf(value));
-                builder.setIpv6NeighborAddress(ripv6);
-                LOG.debug("Parsed IPv6 neighbor address {}.", ripv6);
-                break;
-            case TlvCode.MULTI_TOPOLOGY_ID:
-                final TopologyIdentifier topId = new TopologyIdentifier(value.readUnsignedShort() & LinkstateNlriParser.TOPOLOGY_ID_OFFSET);
-                builder.setMultiTopologyId(topId);
-                LOG.debug("Parsed topology identifier {}.", topId);
-                break;
-            default:
-                throw new BGPParsingException("Link Descriptor not recognized, type: " + type);
-            }
-            buffer.skipBytes(length);
-        }
-        LOG.trace("Finished parsing Link descriptors.");
-        return builder.build();
-    }
-
-    private static NodeIdentifier parseNodeDescriptors(final ByteBuf buffer, final boolean local) throws BGPParsingException {
-        AsNumber asnumber = null;
-        DomainIdentifier bgpId = null;
-        AreaIdentifier ai = null;
-        CRouterIdentifier routerId = null;
-        while (buffer.isReadable()) {
-            final int type = buffer.readUnsignedShort();
-            final int length = buffer.readUnsignedShort();
-            final ByteBuf value = buffer.slice(buffer.readerIndex(), length);
-            LOG.trace("Parsing Node Descriptor: {}", ByteBufUtil.hexDump(value));
-            switch (type) {
-            case TlvCode.AS_NUMBER:
-                asnumber = new AsNumber(value.readUnsignedInt());
-                LOG.debug("Parsed {}", asnumber);
-                break;
-            case TlvCode.BGP_LS_ID:
-                bgpId = new DomainIdentifier(value.readUnsignedInt());
-                LOG.debug("Parsed {}", bgpId);
-                break;
-            case TlvCode.AREA_ID:
-                ai = new AreaIdentifier(value.readUnsignedInt());
-                LOG.debug("Parsed area identifier {}", ai);
-                break;
-            case TlvCode.IGP_ROUTER_ID:
-                routerId = parseRouterId(value);
-                LOG.debug("Parsed Router Identifier {}", routerId);
-                break;
-            default:
-                throw new BGPParsingException("Node Descriptor not recognized, type: " + type);
-            }
-            buffer.skipBytes(length);
-        }
-        LOG.trace("Finished parsing Node descriptors.");
-        return (local) ? new LocalNodeDescriptorsBuilder().setAsNumber(asnumber).setDomainId(bgpId).setAreaId(ai).setCRouterIdentifier(
-            routerId).build()
-            : new RemoteNodeDescriptorsBuilder().setAsNumber(asnumber).setDomainId(bgpId).setAreaId(ai).setCRouterIdentifier(routerId).build();
-    }
-
-    private static CRouterIdentifier parseRouterId(final ByteBuf value) throws BGPParsingException {
-        if (value.readableBytes() == ISO_SYSTEM_ID_LENGTH || (value.readableBytes() == ISO_SYSTEM_ID_LENGTH + PSN_LENGTH && value.getByte(ISO_SYSTEM_ID_LENGTH) == 0)) {
-            return new IsisNodeCaseBuilder().setIsisNode(
-                new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(ByteArray.readBytes(value, ISO_SYSTEM_ID_LENGTH))).build()).build();
-        }
-        if (value.readableBytes() == ISO_SYSTEM_ID_LENGTH + PSN_LENGTH) {
-            final IsIsRouterIdentifier iri = new IsIsRouterIdentifierBuilder().setIsoSystemId(
-                new IsoSystemIdentifier(ByteArray.readBytes(value, ISO_SYSTEM_ID_LENGTH))).build();
-            return new IsisPseudonodeCaseBuilder().setIsisPseudonode(new IsisPseudonodeBuilder().setIsIsRouterIdentifier(iri).setPsn((short) value.readByte()).build()).build();
-        }
-        if (value.readableBytes() == OSPF_ROUTER_ID_LENGTH) {
-            return new OspfNodeCaseBuilder().setOspfNode(
-                new OspfNodeBuilder().setOspfRouterId(value.readUnsignedInt()).build()).build();
-        }
-        if (value.readableBytes() == OSPF_PSEUDONODE_ROUTER_ID_LENGTH) {
-            return new OspfPseudonodeCaseBuilder().setOspfPseudonode(
-                new OspfPseudonodeBuilder().setOspfRouterId(value.readUnsignedInt()).setLanInterface(new OspfInterfaceIdentifier(value.readUnsignedInt())).build()).build();
-        }
-        throw new BGPParsingException("Router Id of invalid length " + value.readableBytes());
-    }
-
-    private static PrefixDescriptors parsePrefixDescriptors(final ByteBuf buffer, final boolean ipv4) throws BGPParsingException {
-        final PrefixDescriptorsBuilder builder = new PrefixDescriptorsBuilder();
-        while (buffer.isReadable()) {
-            final int type = buffer.readUnsignedShort();
-            final int length = buffer.readUnsignedShort();
-            final ByteBuf value = buffer.slice(buffer.readerIndex(), length);
-            LOG.trace("Parsing Prefix Descriptor: {}", ByteBufUtil.hexDump(value));
-            switch (type) {
-            case TlvCode.MULTI_TOPOLOGY_ID:
-                final TopologyIdentifier topologyId = new TopologyIdentifier(value.readShort() & LinkstateNlriParser.TOPOLOGY_ID_OFFSET);
-                builder.setMultiTopologyId(topologyId);
-                LOG.trace("Parsed Topology Identifier: {}", topologyId);
-                break;
-            case TlvCode.OSPF_ROUTE_TYPE:
-                final int rt = value.readByte();
-                final OspfRouteType routeType = OspfRouteType.forValue(rt);
-                if (routeType == null) {
-                    throw new BGPParsingException("Unknown OSPF Route Type: " + rt);
-                }
-                builder.setOspfRouteType(routeType);
-                LOG.trace("Parser RouteType: {}", routeType);
-                break;
-            case TlvCode.IP_REACHABILITY:
-                IpPrefix prefix = null;
-                final int prefixLength = value.readByte();
-                final int size = prefixLength / Byte.SIZE + ((prefixLength % Byte.SIZE == 0) ? 0 : 1);
-                if (size != value.readableBytes()) {
-                    LOG.debug("Expected length {}, actual length {}.", size, value.readableBytes());
-                    throw new BGPParsingException("Illegal length of IP reachability TLV: " + (value.readableBytes()));
-                }
-                if (ipv4) {
-                    prefix = new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.readBytes(value, size), prefixLength));
-                } else {
-                    prefix = new IpPrefix(Ipv6Util.prefixForBytes(ByteArray.readBytes(value, size), prefixLength));
-                }
-                builder.setIpReachabilityInformation(prefix);
-                LOG.trace("Parsed IP reachability info: {}", prefix);
-                break;
-            default:
-                throw new BGPParsingException("Prefix Descriptor not recognized, type: " + type);
-            }
-            buffer.skipBytes(length);
-        }
-        LOG.debug("Finished parsing Prefix descriptors.");
-        return builder.build();
-    }
-
-    /**
-     * Parses common parts for Link State Nodes, Links and Prefixes, that includes protocol ID and identifier tlv.
-     *
-     * @param nlri as byte array
-     * @return {@link CLinkstateDestination}
-     * @throws BGPParsingException if parsing was unsuccessful
-     */
-    public static List<CLinkstateDestination> parseNlri(final ByteBuf nlri, final boolean isVpn) throws BGPParsingException {
-        if (!nlri.isReadable()) {
-            return null;
-        }
-        final List<CLinkstateDestination> dests = Lists.newArrayList();
-
-        CLinkstateDestinationBuilder builder = null;
-
-        while (nlri.isReadable()) {
-            builder = new CLinkstateDestinationBuilder();
-            final NlriType type = NlriType.forValue(nlri.readUnsignedShort());
-            builder.setNlriType(type);
-
-            // length means total length of the tlvs including route distinguisher not including the type field
-            final int length = nlri.readUnsignedShort();
-            RouteDistinguisher distinguisher = null;
-            if (isVpn) {
-                // this parses route distinguisher
-                distinguisher = new RouteDistinguisher(BigInteger.valueOf(nlri.readLong()));
-                builder.setDistinguisher(distinguisher);
-            }
-            // parse source protocol
-            final ProtocolId sp = ProtocolId.forValue(nlri.readByte());
-            builder.setProtocolId(sp);
-
-            // parse identifier
-            final Identifier identifier = new Identifier(BigInteger.valueOf(nlri.readLong()));
-            builder.setIdentifier(identifier);
-
-            // if we are dealing with linkstate nodes/links, parse local node descriptor
-            NodeIdentifier localDescriptor = null;
-            int locallength = 0;
-            final int localtype = nlri.readUnsignedShort();
-            locallength = nlri.readUnsignedShort();
-            if (localtype == TlvCode.LOCAL_NODE_DESCRIPTORS) {
-                localDescriptor = parseNodeDescriptors(nlri.slice(nlri.readerIndex(), locallength), true);
-            }
-            nlri.skipBytes(locallength);
-            builder.setLocalNodeDescriptors((LocalNodeDescriptors) localDescriptor);
-            final int restLength = length - (isVpn ? ROUTE_DISTINGUISHER_LENGTH : 0) - PROTOCOL_ID_LENGTH - IDENTIFIER_LENGTH
-                - TYPE_LENGTH - LENGTH_SIZE - locallength;
-            LOG.trace("Restlength {}", restLength);
-            final ByteBuf rest = nlri.slice(nlri.readerIndex(), restLength);
-            switch (type) {
-            case Link:
-                parseLink(builder, rest);
-                break;
-            case Ipv4Prefix:
-                builder.setPrefixDescriptors(parsePrefixDescriptors(rest, true));
-                break;
-            case Ipv6Prefix:
-                builder.setPrefixDescriptors(parsePrefixDescriptors(rest, false));
-                break;
-            case Node:
-                // node nlri is already parsed as it contains only the common fields for node and link nlri
-                break;
-            default:
-                break;
-            }
-            nlri.skipBytes(restLength);
-            dests.add(builder.build());
-        }
-        return dests;
-    }
-
-    @Override
-    public void parseNlri(final ByteBuf nlri, final MpUnreachNlriBuilder builder) throws BGPParsingException {
-        if (!nlri.isReadable()) {
-            return;
-        }
-        final List<CLinkstateDestination> dst = parseNlri(nlri, this.isVpn);
-
-        builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
-            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCaseBuilder().setDestinationLinkstate(
-                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder().setCLinkstateDestination(
-                    dst).build()).build()).build());
-    }
-
-    @Override
-    public void parseNlri(final ByteBuf nlri, final MpReachNlriBuilder builder) throws BGPParsingException {
-        if (!nlri.isReadable()) {
-            return;
-        }
-        final List<CLinkstateDestination> dst = parseNlri(nlri, this.isVpn);
-
-        builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
-            new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
-                new DestinationLinkstateBuilder().setCLinkstateDestination(dst).build()).build()).build());
-    }
-
-    /**
-     * Serializes Linkstate NLRI to byte array. We need this as NLRI serves as a key in upper layers.
-     *
-     * @param destination Linkstate NLRI to be serialized
-     */
-    public static void serializeNlri(final CLinkstateDestination destination, final ByteBuf buffer) {
-        final ByteBuf nlriByteBuf = Unpooled.buffer();
-        if (destination.getDistinguisher() != null) {
-            nlriByteBuf.writeBytes(destination.getDistinguisher().getValue().toByteArray());
-        }
-        nlriByteBuf.writeByte(destination.getProtocolId().getIntValue());
-        nlriByteBuf.writeLong(destination.getIdentifier().getValue().longValue());
-
-        // serialize local node descriptors
-        final ByteBuf ldescs = Unpooled.buffer();
-        serializeNodeDescriptors(destination.getLocalNodeDescriptors(), ldescs);
-        LinkstateAttributeParser.writeTLV(TlvCode.LOCAL_NODE_DESCRIPTORS, ldescs, nlriByteBuf);
-
-        switch (destination.getNlriType()) {
-        case Ipv4Prefix:
-        case Ipv6Prefix:
-            if (destination.getPrefixDescriptors() != null) {
-                serializePrefixDescriptors(destination.getPrefixDescriptors(), nlriByteBuf);
-            }
-            break;
-        case Link:
-            final ByteBuf rdescs = Unpooled.buffer();
-            serializeNodeDescriptors(destination.getRemoteNodeDescriptors(), rdescs);
-            LinkstateAttributeParser.writeTLV(TlvCode.REMOTE_NODE_DESCRIPTORS, rdescs, nlriByteBuf);
-            if (destination.getLinkDescriptors() != null) {
-                serializeLinkDescriptors(destination.getLinkDescriptors(), nlriByteBuf);
-            }
-            break;
-        case Node:
-            break;
-        default:
-            LOG.warn("Unknown NLRI Type.");
-            break;
-        }
-        LinkstateAttributeParser.writeTLV(destination.getNlriType().getIntValue(), nlriByteBuf, buffer);
-    }
-
-    private static void serializeNodeDescriptors(final NodeIdentifier descriptors, final ByteBuf buffer) {
-        if (descriptors.getAsNumber() != null) {
-            LinkstateAttributeParser.writeTLV(TlvCode.AS_NUMBER, Unpooled.copyInt(UnsignedInteger.valueOf(descriptors.getAsNumber().getValue()).intValue()), buffer);
-        }
-        if (descriptors.getDomainId() != null) {
-            LinkstateAttributeParser.writeTLV(TlvCode.BGP_LS_ID, Unpooled.copyInt(UnsignedInteger.valueOf(descriptors.getDomainId().getValue()).intValue()), buffer);
-        }
-        if (descriptors.getAreaId() != null) {
-            LinkstateAttributeParser.writeTLV(TlvCode.AREA_ID, Unpooled.copyInt(UnsignedInteger.valueOf(descriptors.getAreaId().getValue()).intValue()), buffer);
-        }
-        if (descriptors.getCRouterIdentifier() != null) {
-            final ByteBuf routerIdBuf = Unpooled.buffer();
-            serializeRouterId(descriptors.getCRouterIdentifier(), routerIdBuf);
-            LinkstateAttributeParser.writeTLV(TlvCode.IGP_ROUTER_ID, routerIdBuf, buffer);
-        }
-    }
-
-    private static void serializeRouterId(final CRouterIdentifier routerId, final ByteBuf buffer) {
-        if (routerId instanceof IsisNodeCase) {
-            final IsisNode isis = ((IsisNodeCase) routerId).getIsisNode();
-            buffer.writeBytes(isis.getIsoSystemId().getValue());
-        } else if (routerId instanceof IsisPseudonodeCase) {
-            final IsisPseudonode isis = ((IsisPseudonodeCase) routerId).getIsisPseudonode();
-            buffer.writeBytes(isis.getIsIsRouterIdentifier().getIsoSystemId().getValue());
-            buffer.writeByte(((isis.getPsn() != null) ? isis.getPsn() : 0));
-        } else if (routerId instanceof OspfNodeCase) {
-            buffer.writeInt(UnsignedInteger.valueOf(((OspfNodeCase) routerId).getOspfNode().getOspfRouterId()).intValue());
-        } else if (routerId instanceof OspfPseudonodeCase) {
-            final OspfPseudonode node = ((OspfPseudonodeCase) routerId).getOspfPseudonode();
-            buffer.writeInt(UnsignedInteger.valueOf(node.getOspfRouterId()).intValue());
-            buffer.writeInt(UnsignedInteger.valueOf(node.getLanInterface().getValue()).intValue());
-        }
-    }
-
-    private static void serializeLinkDescriptors(final LinkDescriptors descriptors, final ByteBuf buffer) {
-        if (descriptors.getLinkLocalIdentifier() != null && descriptors.getLinkRemoteIdentifier() != null) {
-            final ByteBuf identifierBuf = Unpooled.buffer();
-            identifierBuf.writeInt(descriptors.getLinkLocalIdentifier().intValue());
-            identifierBuf.writeInt(descriptors.getLinkRemoteIdentifier().intValue());
-            LinkstateAttributeParser.writeTLV(TlvCode.LINK_LR_IDENTIFIERS, identifierBuf, buffer);
-        }
-        if (descriptors.getIpv4InterfaceAddress() != null) {
-            LinkstateAttributeParser.writeTLV(TlvCode.IPV4_IFACE_ADDRESS, Unpooled.wrappedBuffer(Ipv4Util.bytesForAddress(descriptors.getIpv4InterfaceAddress())), buffer);
-        }
-        if (descriptors.getIpv4NeighborAddress() != null) {
-            LinkstateAttributeParser.writeTLV(TlvCode.IPV4_NEIGHBOR_ADDRESS, Unpooled.wrappedBuffer(Ipv4Util.bytesForAddress(descriptors.getIpv4NeighborAddress())), buffer);
-        }
-        if (descriptors.getIpv6InterfaceAddress() != null) {
-            LinkstateAttributeParser.writeTLV(TlvCode.IPV6_IFACE_ADDRESS, Unpooled.wrappedBuffer(Ipv6Util.bytesForAddress(descriptors.getIpv6InterfaceAddress())), buffer);
-        }
-        if (descriptors.getIpv6NeighborAddress() != null) {
-            LinkstateAttributeParser.writeTLV(TlvCode.IPV6_NEIGHBOR_ADDRESS, Unpooled.wrappedBuffer(Ipv6Util.bytesForAddress(descriptors.getIpv6NeighborAddress())), buffer);
-        }
-        if (descriptors.getMultiTopologyId() != null) {
-            LinkstateAttributeParser.writeTLV(TlvCode.MULTI_TOPOLOGY_ID, Unpooled.copyShort(descriptors.getMultiTopologyId().getValue()), buffer);
-        }
-    }
-
-    private static void serializePrefixDescriptors(final PrefixDescriptors descriptors, final ByteBuf buffer) {
-        if (descriptors.getMultiTopologyId() != null) {
-            LinkstateAttributeParser.writeTLV(TlvCode.MULTI_TOPOLOGY_ID, Unpooled.copyShort(descriptors.getMultiTopologyId().getValue()), buffer);
-        }
-        if (descriptors.getOspfRouteType() != null) {
-            LinkstateAttributeParser.writeTLV(TlvCode.OSPF_ROUTE_TYPE,
-                Unpooled.wrappedBuffer(new byte[] {UnsignedBytes.checkedCast(descriptors.getOspfRouteType().getIntValue()) }), buffer);
-        }
-        if (descriptors.getIpReachabilityInformation() != null) {
-            final IpPrefix prefix = descriptors.getIpReachabilityInformation();
-            byte[] prefixBytes = null;
-            if (prefix.getIpv4Prefix() != null) {
-                prefixBytes = Ipv4Util.bytesForPrefixBegin(prefix.getIpv4Prefix());
-            } else if (prefix.getIpv6Prefix() != null) {
-                prefixBytes = Ipv6Util.bytesForPrefixBegin(prefix.getIpv6Prefix());
-            }
-            LinkstateAttributeParser.writeTLV(TlvCode.IP_REACHABILITY, Unpooled.wrappedBuffer(prefixBytes), buffer);
-        }
-    }
-
-    @Override
-    public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
-        Preconditions.checkArgument(attribute instanceof PathAttributes, "Attribute parameter is not a PathAttribute object.");
-        final PathAttributes pathAttributes = (PathAttributes) attribute;
-        final PathAttributes1 pathAttributes1 = pathAttributes.getAugmentation(PathAttributes1.class);
-        final PathAttributes2 pathAttributes2 = pathAttributes.getAugmentation(PathAttributes2.class);
-        if (pathAttributes1 != null) {
-            final AdvertizedRoutes routes = (pathAttributes1.getMpReachNlri()).getAdvertizedRoutes();
-            if (routes != null &&
-                routes.getDestinationType()
-                instanceof
-                org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase) {
-                final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase
-                linkstateCase = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase) routes.getDestinationType();
-
-                for (final CLinkstateDestination cLinkstateDestination : linkstateCase.getDestinationLinkstate().getCLinkstateDestination()) {
-                    serializeNlri(cLinkstateDestination, byteAggregator);
-                }
-            }
-        } else if (pathAttributes2 != null) {
-            final MpUnreachNlri mpUnreachNlri = pathAttributes2.getMpUnreachNlri();
-            if (mpUnreachNlri.getWithdrawnRoutes() != null && mpUnreachNlri.getWithdrawnRoutes().getDestinationType() instanceof DestinationLinkstateCase) {
-                final DestinationLinkstateCase linkstateCase = (DestinationLinkstateCase) mpUnreachNlri.getWithdrawnRoutes().getDestinationType();
-                for (final CLinkstateDestination cLinkstateDestination : linkstateCase.getDestinationLinkstate().getCLinkstateDestination()) {
-                    serializeNlri(cLinkstateDestination, byteAggregator);
-                }
-            }
-        }
-    }
-}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/TlvCode.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/TlvCode.java
deleted file mode 100644 (file)
index 0983f9e..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.linkstate;
-
-final class TlvCode {
-
-    private TlvCode() {
-        throw new UnsupportedOperationException();
-    }
-
-    static final int LOCAL_NODE_DESCRIPTORS = 256;
-
-    static final int REMOTE_NODE_DESCRIPTORS = 257;
-
-    /* Link Descriptor TLVs */
-
-    static final int LINK_LR_IDENTIFIERS = 258;
-
-    static final int IPV4_IFACE_ADDRESS = 259;
-
-    static final int IPV4_NEIGHBOR_ADDRESS = 260;
-
-    static final int IPV6_IFACE_ADDRESS = 261;
-
-    static final int IPV6_NEIGHBOR_ADDRESS = 262;
-
-    /* Link Attribute TLVs */
-
-    static final int LOCAL_IPV4_ROUTER_ID = 1028;
-
-    static final int LOCAL_IPV6_ROUTER_ID = 1029;
-
-    static final int REMOTE_IPV4_ROUTER_ID = 1030;
-
-    static final int REMOTE_IPV6_ROUTER_ID = 1031;
-
-    static final int ADMIN_GROUP = 1088;
-
-    static final int MAX_BANDWIDTH = 1089;
-
-    static final int MAX_RESERVABLE_BANDWIDTH = 1090;
-
-    static final int UNRESERVED_BANDWIDTH = 1091;
-
-    static final int TE_METRIC = 1092;
-
-    static final int LINK_PROTECTION_TYPE = 1093;
-
-    static final int MPLS_PROTOCOL = 1094;
-
-    static final int METRIC = 1095;
-
-    static final int SHARED_RISK_LINK_GROUP = 1096;
-
-    static final int LINK_OPAQUE = 1097;
-
-    static final int LINK_NAME = 1098;
-
-    /* Prefix Descriptor TLVs */
-
-    static final int MULTI_TOPOLOGY_ID = 263;
-
-    static final int OSPF_ROUTE_TYPE = 264;
-
-    static final int IP_REACHABILITY = 265;
-
-    /* Prefix Attribute TLVs */
-
-    static final int IGP_FLAGS = 1152;
-
-    static final int ROUTE_TAG = 1153;
-
-    static final int EXTENDED_ROUTE_TAG = 1154;
-
-    static final int PREFIX_METRIC = 1155;
-
-    static final int FORWARDING_ADDRESS = 1156;
-
-    static final int PREFIX_OPAQUE = 1157;
-
-    /* Node Descriptor TLVs */
-
-    static final int AS_NUMBER = 512;
-
-    static final int BGP_LS_ID = 513;
-
-    static final int AREA_ID = 514;
-
-    static final int IGP_ROUTER_ID = 515;
-
-    /* Node Attribute TLVs */
-
-    static final int NODE_FLAG_BITS = 1024;
-
-    static final int NODE_OPAQUE = 1025;
-
-    static final int DYNAMIC_HOSTNAME = 1026;
-
-    static final int ISIS_AREA_IDENTIFIER = 1027;
-}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/TlvUtil.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/TlvUtil.java
new file mode 100644 (file)
index 0000000..019f4db
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.linkstate;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class TlvUtil {
+
+    private TlvUtil() {
+        throw new UnsupportedOperationException();
+    }
+
+    private static final Logger LOG = LoggerFactory.getLogger(TlvUtil.class);
+
+    public static final int TOPOLOGY_ID_OFFSET = 0x3fff;
+
+    public static final int MULTI_TOPOLOGY_ID = 263;
+    public static final int LOCAL_IPV4_ROUTER_ID = 1028;
+    public static final int LOCAL_IPV6_ROUTER_ID = 1029;
+
+    /**
+     * Util method for writing TLV header.
+     * @param type TLV type
+     * @param value TLV value
+     * @param byteAggregator final ByteBuf where the tlv should be serialized
+     */
+    public static void writeTLV(final int type, final ByteBuf value, final ByteBuf byteAggregator){
+        byteAggregator.writeShort(type);
+        byteAggregator.writeShort(value.writerIndex());
+        byteAggregator.writeBytes(value);
+        value.readerIndex(0);
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Serialized tlv type {} to: {}", type, ByteBufUtil.hexDump(value));
+        }
+    }
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/LinkAttributesParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/LinkAttributesParser.java
new file mode 100644 (file)
index 0000000..b5fc04e
--- /dev/null
@@ -0,0 +1,245 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.linkstate.attribute;
+
+import com.google.common.base.Charsets;
+import com.google.common.collect.Multimap;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import io.netty.buffer.Unpooled;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.BitSet;
+import java.util.List;
+import java.util.Map.Entry;
+import org.opendaylight.protocol.bgp.linkstate.TlvUtil;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.Ipv4Util;
+import org.opendaylight.protocol.util.Ipv6Util;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.AdministrativeGroup;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv4RouterIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv6RouterIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.LinkProtectionType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.MplsProtocolMask;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.link.state.UnreservedBandwidth;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.link.state.UnreservedBandwidthBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.LinkStateAttribute;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.LinkAttributesCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.LinkAttributesCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Metric;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.TeMetric;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.SrlgId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+final class LinkAttributesParser {
+
+    private static final Logger LOG = LoggerFactory.getLogger(LinkAttributesParser.class);
+
+    private static final int UNRESERVED_BW_COUNT = 8;
+
+    private static final int BANDWIDTH_LENGTH = 4;
+
+    // MPLS protection mask bits
+    private static final int LDP_BIT = 7;
+    private static final int RSVP_BIT = 6;
+
+    /* Link Attribute TLVs */
+    private static final int REMOTE_IPV4_ROUTER_ID = 1030;
+    private static final int REMOTE_IPV6_ROUTER_ID = 1031;
+    private static final int ADMIN_GROUP = 1088;
+    private static final int MAX_BANDWIDTH = 1089;
+    private static final int MAX_RESERVABLE_BANDWIDTH = 1090;
+    private static final int UNRESERVED_BANDWIDTH = 1091;
+    private static final int TE_METRIC = 1092;
+    private static final int LINK_PROTECTION_TYPE = 1093;
+    private static final int MPLS_PROTOCOL = 1094;
+    private static final int METRIC = 1095;
+    private static final int SHARED_RISK_LINK_GROUP = 1096;
+    private static final int LINK_OPAQUE = 1097;
+    private static final int LINK_NAME = 1098;
+
+    /**
+     * Parse Link Attributes.
+     *
+     * @param attributes key is the tlv type and value is the value of the tlv
+     * @return {@link LinkStateAttribute}
+     */
+    static LinkStateAttribute parseLinkAttributes(final Multimap<Integer, ByteBuf> attributes) {
+        final LinkAttributesBuilder builder = new LinkAttributesBuilder();
+        for (final Entry<Integer, ByteBuf> entry : attributes.entries()) {
+            LOG.trace("Link attribute TLV {}", entry.getKey());
+            final int key = entry.getKey();
+            final ByteBuf value = entry.getValue();
+            switch (key) {
+            case TlvUtil.LOCAL_IPV4_ROUTER_ID:
+                final Ipv4RouterIdentifier lipv4 = new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value));
+                builder.setLocalIpv4RouterId(lipv4);
+                LOG.debug("Parsed IPv4 Router-ID of local node: {}", lipv4);
+                break;
+            case TlvUtil.LOCAL_IPV6_ROUTER_ID:
+                final Ipv6RouterIdentifier lipv6 = new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value));
+                builder.setLocalIpv6RouterId(lipv6);
+                LOG.debug("Parsed IPv6 Router-ID of local node: {}", lipv6);
+                break;
+            case REMOTE_IPV4_ROUTER_ID:
+                final Ipv4RouterIdentifier ripv4 = new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value));
+                builder.setRemoteIpv4RouterId(ripv4);
+                LOG.debug("Parsed IPv4 Router-ID of remote node: {}", ripv4);
+                break;
+            case REMOTE_IPV6_ROUTER_ID:
+                final Ipv6RouterIdentifier ripv6 = new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value));
+                builder.setRemoteIpv6RouterId(ripv6);
+                LOG.debug("Parsed IPv6 Router-ID of remote node: {}", ripv6);
+                break;
+            case ADMIN_GROUP:
+                builder.setAdminGroup(new AdministrativeGroup(value.readUnsignedInt()));
+                LOG.debug("Parsed Administrative Group {}", builder.getAdminGroup());
+                break;
+            case MAX_BANDWIDTH:
+                builder.setMaxLinkBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
+                LOG.debug("Parsed Max Bandwidth {}", builder.getMaxLinkBandwidth());
+                break;
+            case MAX_RESERVABLE_BANDWIDTH:
+                builder.setMaxReservableBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
+                LOG.debug("Parsed Max Reservable Bandwidth {}", builder.getMaxReservableBandwidth());
+                break;
+            case UNRESERVED_BANDWIDTH:
+                final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.link.state.UnreservedBandwidth> unreservedBandwidth = new ArrayList<>(UNRESERVED_BW_COUNT);
+                for (int i = 0; i < UNRESERVED_BW_COUNT; i++) {
+                    final ByteBuf v = value.slice(value.readerIndex(), BANDWIDTH_LENGTH);
+                    unreservedBandwidth.add(new UnreservedBandwidthBuilder().setBandwidth(new Bandwidth(ByteArray.readAllBytes(v))).setPriority((short) i).build());
+                    value.skipBytes(BANDWIDTH_LENGTH);
+                }
+                builder.setUnreservedBandwidth(unreservedBandwidth);
+                LOG.debug("Parsed Unreserved Bandwidth {}", builder.getUnreservedBandwidth());
+                break;
+            case TE_METRIC:
+                builder.setTeMetric(new TeMetric(ByteArray.bytesToLong(ByteArray.readAllBytes(value))));
+                LOG.debug("Parsed Metric {}", builder.getTeMetric());
+                break;
+            case LINK_PROTECTION_TYPE:
+                final int l = value.readShort();
+                final LinkProtectionType lpt = LinkProtectionType.forValue(l);
+                if (lpt == null) {
+                    LOG.warn("Link Protection Type not recognized: {}", l);
+                    break;
+                }
+                builder.setLinkProtection(lpt);
+                LOG.debug("Parsed Link Protection Type {}", lpt);
+                break;
+            case MPLS_PROTOCOL:
+                final BitSet bits = BitSet.valueOf(ByteArray.readAllBytes(value));
+                builder.setMplsProtocol(new MplsProtocolMask(bits.get(LDP_BIT), bits.get(RSVP_BIT)));
+                LOG.debug("Parsed MPLS Protocols: {}", builder.getMplsProtocol());
+                break;
+            case METRIC:
+                // length can 3, 2 or 1
+                builder.setMetric(new Metric(ByteArray.bytesToLong(ByteArray.readAllBytes(value))));
+                LOG.debug("Parsed Metric {}", builder.getMetric());
+                break;
+            case SHARED_RISK_LINK_GROUP:
+                final List<SrlgId> sharedRiskLinkGroups = new ArrayList<>();
+                while (value.isReadable()) {
+                    sharedRiskLinkGroups.add(new SrlgId(value.readUnsignedInt()));
+                }
+                builder.setSharedRiskLinkGroups(sharedRiskLinkGroups);
+                LOG.debug("Parsed Shared Risk Link Groups {}", Arrays.toString(sharedRiskLinkGroups.toArray()));
+                break;
+            case LINK_OPAQUE:
+                LOG.debug("Parsed Opaque value : {}", ByteBufUtil.hexDump(value));
+                break;
+            case LINK_NAME:
+                final String name = new String(ByteArray.readAllBytes(value), Charsets.US_ASCII);
+                builder.setLinkName(name);
+                LOG.debug("Parsed Link Name : {}", name);
+                break;
+            default:
+                LOG.warn("TLV {} is not a valid link attribute, ignoring it", key);
+            }
+        }
+        LOG.trace("Finished parsing Link Attributes.");
+        return new LinkAttributesCaseBuilder().setLinkAttributes(builder.build()).build();
+    }
+
+    static void serializeLinkAttributes(final LinkAttributesCase linkAttributesCase, final ByteBuf byteAggregator) {
+        final LinkAttributes linkAttributes = linkAttributesCase.getLinkAttributes();
+        LOG.trace("Started serializing Link Attributes");
+        if (linkAttributes.getLocalIpv4RouterId() != null) {
+            TlvUtil.writeTLV(TlvUtil.LOCAL_IPV4_ROUTER_ID, Ipv4Util.byteBufForAddress(linkAttributes.getLocalIpv4RouterId()), byteAggregator);
+        }
+        if (linkAttributes.getLocalIpv6RouterId() != null) {
+            TlvUtil.writeTLV(TlvUtil.LOCAL_IPV6_ROUTER_ID, Ipv6Util.byteBufForAddress(linkAttributes.getLocalIpv6RouterId()), byteAggregator);
+        }
+        if (linkAttributes.getRemoteIpv4RouterId() != null) {
+            TlvUtil.writeTLV(REMOTE_IPV4_ROUTER_ID, Ipv4Util.byteBufForAddress(linkAttributes.getRemoteIpv4RouterId()), byteAggregator);
+        }
+        if (linkAttributes.getRemoteIpv6RouterId() != null) {
+            TlvUtil.writeTLV(REMOTE_IPV6_ROUTER_ID, Ipv6Util.byteBufForAddress(linkAttributes.getRemoteIpv6RouterId()), byteAggregator);
+        }
+        if (linkAttributes.getAdminGroup() != null) {
+            TlvUtil.writeTLV(ADMIN_GROUP, Unpooled.copyInt(linkAttributes.getAdminGroup().getValue().intValue()), byteAggregator);
+        }
+        if (linkAttributes.getMaxLinkBandwidth() != null) {
+            TlvUtil.writeTLV(MAX_BANDWIDTH, Unpooled.wrappedBuffer(linkAttributes.getMaxLinkBandwidth().getValue()), byteAggregator);
+        }
+        if (linkAttributes.getMaxReservableBandwidth() != null) {
+            TlvUtil.writeTLV(MAX_RESERVABLE_BANDWIDTH, Unpooled.wrappedBuffer(linkAttributes.getMaxReservableBandwidth().getValue()), byteAggregator);
+        }
+        // this sub-TLV contains eight 32-bit IEEE floating point numbers
+        final List<UnreservedBandwidth> ubList = linkAttributes.getUnreservedBandwidth();
+        if (ubList != null && !ubList.isEmpty()) {
+            final ByteBuf unreservedBandwithBuf = Unpooled.buffer();
+            for (final UnreservedBandwidth unreservedBandwidth : ubList) {
+                unreservedBandwithBuf.writeBytes(unreservedBandwidth.getBandwidth().getValue());
+            }
+            TlvUtil.writeTLV(UNRESERVED_BANDWIDTH, unreservedBandwithBuf, byteAggregator);
+        }
+        if (linkAttributes.getTeMetric() != null) {
+            TlvUtil.writeTLV(TE_METRIC, Unpooled.copyLong(linkAttributes.getTeMetric().getValue().longValue()), byteAggregator);
+        }
+        if (linkAttributes.getLinkProtection() != null) {
+            TlvUtil.writeTLV(LINK_PROTECTION_TYPE, Unpooled.copyShort(linkAttributes.getLinkProtection().getIntValue()), byteAggregator);
+        }
+        serializeMplsProtocolMask(linkAttributes.getMplsProtocol(), byteAggregator);
+        if (linkAttributes.getMetric() != null) {
+            // size of metric can be 1,2 or 3 depending on the protocol
+            TlvUtil.writeTLV(METRIC, Unpooled.copyMedium(linkAttributes.getMetric().getValue().intValue()), byteAggregator);
+        }
+        final List<SrlgId> srlgList = linkAttributes.getSharedRiskLinkGroups();
+        if (srlgList != null && !srlgList.isEmpty()) {
+            final ByteBuf sharedRLGBuf = Unpooled.buffer();
+            for (final SrlgId srlgId : srlgList) {
+                sharedRLGBuf.writeInt(srlgId.getValue().intValue());
+            }
+            TlvUtil.writeTLV(SHARED_RISK_LINK_GROUP, sharedRLGBuf, byteAggregator);
+        }
+        if (linkAttributes.getLinkName() != null) {
+            TlvUtil.writeTLV(LINK_NAME, Unpooled.wrappedBuffer(Charsets.UTF_8.encode(linkAttributes.getLinkName())), byteAggregator);
+        }
+        LOG.trace("Finished serializing Link Attributes");
+    }
+
+    private static void serializeMplsProtocolMask(final MplsProtocolMask mplsProtocolMask, final ByteBuf byteAggregator ) {
+        if (mplsProtocolMask != null) {
+            final ByteBuf mplsProtocolMaskBuf = Unpooled.buffer(1);
+            final BitSet mask = new BitSet(Byte.SIZE);
+            if (mplsProtocolMask.isLdp() != null) {
+                mask.set(LDP_BIT, mplsProtocolMask.isLdp());
+            }
+            if (mplsProtocolMask.isRsvpte() != null) {
+                mask.set(RSVP_BIT, mplsProtocolMask.isRsvpte());
+            }
+            mplsProtocolMaskBuf.writeBytes(mask.toByteArray());
+            TlvUtil.writeTLV(MPLS_PROTOCOL, mplsProtocolMaskBuf, byteAggregator);
+        }
+    }
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/LinkstateAttributeParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/LinkstateAttributeParser.java
new file mode 100644 (file)
index 0000000..15e5e0f
--- /dev/null
@@ -0,0 +1,149 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.linkstate.attribute;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Multimap;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
+import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
+import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.NlriType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.PathAttributes1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.PathAttributes1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.CLinkstateDestination;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.LinkstatePathAttribute;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.LinkstatePathAttributeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.LinkStateAttribute;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.LinkAttributesCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.NodeAttributesCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.PrefixAttributesCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.DestinationType;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Parser for Link State Path Attribute.
+ *
+ * @see <a href="http://tools.ietf.org/html/draft-gredler-idr-ls-distribution-04">BGP-LS draft</a>
+ */
+public class LinkstateAttributeParser implements AttributeParser, AttributeSerializer {
+
+    private static final Logger LOG = LoggerFactory.getLogger(LinkstateAttributeParser.class);
+
+    private static final int TYPE = 29;
+
+    private static final int LEGACY_TYPE = 99;
+
+    private final int type;
+
+    public LinkstateAttributeParser(final boolean isIanaAssignedType) {
+        this.type = (isIanaAssignedType) ? TYPE : LEGACY_TYPE;
+    }
+
+    public int getType() {
+        return this.type;
+    }
+
+    @Override
+    public void parseAttribute(final ByteBuf buffer, final PathAttributesBuilder builder) throws BGPParsingException {
+        final NlriType nlriType = getNlriType(builder);
+        if (nlriType == null) {
+            LOG.warn("No Linkstate NLRI found, not parsing Linkstate attribute");
+            return;
+        }
+        final PathAttributes1 a = new PathAttributes1Builder().setLinkstatePathAttribute(parseLinkState(nlriType, buffer)).build();
+        builder.addAugmentation(PathAttributes1.class, a);
+    }
+
+    private NlriType getNlriType(final PathAttributesBuilder pab) {
+        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1 mpr = pab.getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1.class);
+        if (mpr != null && mpr.getMpReachNlri() != null) {
+            final DestinationType dt = mpr.getMpReachNlri().getAdvertizedRoutes().getDestinationType();
+            if (dt instanceof DestinationLinkstateCase) {
+                for (final CLinkstateDestination d : ((DestinationLinkstateCase) dt).getDestinationLinkstate().getCLinkstateDestination()) {
+                    return d.getNlriType();
+                }
+            }
+        }
+        final PathAttributes2 mpu = pab.getAugmentation(PathAttributes2.class);
+        if (mpu != null && mpu.getMpUnreachNlri() != null) {
+            final DestinationType dt = mpu.getMpUnreachNlri().getWithdrawnRoutes().getDestinationType();
+            if (dt instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCase) {
+                for (final CLinkstateDestination d : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCase) dt).getDestinationLinkstate().getCLinkstateDestination()) {
+                    return d.getNlriType();
+                }
+            }
+        }
+        return null;
+    }
+
+    private static LinkstatePathAttribute parseLinkState(final NlriType nlri, final ByteBuf buffer) throws BGPParsingException {
+        /*
+         * e.g. IS-IS Area Identifier TLV can occur multiple times
+         */
+        final Multimap<Integer, ByteBuf> map = HashMultimap.create();
+        while (buffer.isReadable()) {
+            final int type = buffer.readUnsignedShort();
+            final int length = buffer.readUnsignedShort();
+            final ByteBuf value = buffer.slice(buffer.readerIndex(), length);
+            map.put(type, value);
+            buffer.skipBytes(length);
+        }
+        final LinkstatePathAttributeBuilder builder = new LinkstatePathAttributeBuilder();
+
+        switch (nlri) {
+        case Ipv4Prefix:
+        case Ipv6Prefix:
+            builder.setLinkStateAttribute(PrefixAttributesParser.parsePrefixAttributes(map));
+            return builder.build();
+        case Link:
+            builder.setLinkStateAttribute(LinkAttributesParser.parseLinkAttributes(map));
+            return builder.build();
+        case Node:
+            builder.setLinkStateAttribute(NodeAttributesParser.parseNodeAttributes(map));
+            return builder.build();
+        default:
+            throw new IllegalStateException("Unhandled NLRI type " + nlri);
+        }
+    }
+
+    /**
+     * Serialize linkstate attributes.
+     *
+     * @param attribute DataObject representing LinkstatePathAttribute
+     * @param byteAggregator ByteBuf where all serialized data are aggregated
+     */
+
+    @Override
+    public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
+        Preconditions.checkArgument(attribute instanceof PathAttributes, "Attribute parameter is not a PathAttribute object.");
+        final PathAttributes1 pathAttributes1 = ((PathAttributes) attribute).getAugmentation(PathAttributes1.class);
+        if (pathAttributes1 == null) {
+            return;
+        }
+        final LinkStateAttribute linkState = pathAttributes1.getLinkstatePathAttribute().getLinkStateAttribute();
+        final ByteBuf lsBuffer = Unpooled.buffer();
+        if (linkState instanceof LinkAttributesCase) {
+            LinkAttributesParser.serializeLinkAttributes((LinkAttributesCase) linkState, lsBuffer);
+        } else if (linkState instanceof NodeAttributesCase) {
+            NodeAttributesParser.serializeNodeAttributes((NodeAttributesCase) linkState, lsBuffer);
+        } else if (linkState instanceof PrefixAttributesCase) {
+            PrefixAttributesParser.serializePrefixAttributes((PrefixAttributesCase) linkState, lsBuffer);
+        }
+        AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL, getType(), lsBuffer, byteAggregator);
+    }
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/NodeAttributesParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/NodeAttributesParser.java
new file mode 100644 (file)
index 0000000..b893c79
--- /dev/null
@@ -0,0 +1,164 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.linkstate.attribute;
+
+import com.google.common.base.Charsets;
+import com.google.common.collect.Multimap;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import io.netty.buffer.Unpooled;
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.List;
+import java.util.Map.Entry;
+import org.opendaylight.protocol.bgp.linkstate.TlvUtil;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.Ipv4Util;
+import org.opendaylight.protocol.util.Ipv6Util;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv4RouterIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv6RouterIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.IsisAreaIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.NodeFlagBits;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.TopologyIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.LinkStateAttribute;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.NodeAttributesCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.NodeAttributesCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.node.attributes._case.NodeAttributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.node.attributes._case.NodeAttributesBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+final class NodeAttributesParser {
+
+    private static final Logger LOG = LoggerFactory.getLogger(NodeAttributesParser.class);
+
+    // node flag bits
+    private static final int OVERLOAD_BIT = 7;
+    private static final int ATTACHED_BIT = 6;
+    private static final int EXTERNAL_BIT = 5;
+    private static final int ABBR_BIT = 4;
+
+    /* Node Attribute TLVs */
+    private static final int NODE_FLAG_BITS = 1024;
+    private static final int NODE_OPAQUE = 1025;
+    private static final int DYNAMIC_HOSTNAME = 1026;
+    private static final int ISIS_AREA_IDENTIFIER = 1027;
+
+    /**
+     * Parse Node Attributes.
+     *
+     * @param attributes key is the tlv type and value is the value of the tlv
+     * @return {@link LinkStateAttribute}
+     */
+    static LinkStateAttribute parseNodeAttributes(final Multimap<Integer, ByteBuf> attributes) {
+        final List<TopologyIdentifier> topologyMembership = new ArrayList<>();
+        final List<IsisAreaIdentifier> areaMembership = new ArrayList<>();
+        final NodeAttributesBuilder builder = new NodeAttributesBuilder();
+        for (final Entry<Integer, ByteBuf> entry : attributes.entries()) {
+            final int key = entry.getKey();
+            final ByteBuf value = entry.getValue();
+            LOG.trace("Node attribute TLV {}", key);
+            switch (key) {
+            case TlvUtil.MULTI_TOPOLOGY_ID:
+                while (value.isReadable()) {
+                    final TopologyIdentifier topId = new TopologyIdentifier(value.readUnsignedShort() & TlvUtil.TOPOLOGY_ID_OFFSET);
+                    topologyMembership.add(topId);
+                    LOG.debug("Parsed Topology Identifier: {}", topId);
+                }
+                break;
+            case NODE_FLAG_BITS:
+                final BitSet flags = BitSet.valueOf(ByteArray.readAllBytes(value));
+                builder.setNodeFlags(new NodeFlagBits(flags.get(OVERLOAD_BIT), flags.get(ATTACHED_BIT), flags.get(EXTERNAL_BIT), flags.get(ABBR_BIT)));
+                LOG.debug("Parsed Overload bit: {}, attached bit: {}, external bit: {}, area border router: {}.",
+                    flags.get(OVERLOAD_BIT), flags.get(ATTACHED_BIT), flags.get(EXTERNAL_BIT), flags.get(ABBR_BIT));
+                break;
+            case NODE_OPAQUE:
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Ignoring opaque value: {}.", ByteBufUtil.hexDump(value));
+                }
+                break;
+            case DYNAMIC_HOSTNAME:
+                builder.setDynamicHostname(new String(ByteArray.readAllBytes(value), Charsets.US_ASCII));
+                LOG.debug("Parsed Node Name {}", builder.getDynamicHostname());
+                break;
+            case ISIS_AREA_IDENTIFIER:
+                final IsisAreaIdentifier ai = new IsisAreaIdentifier(ByteArray.readAllBytes(value));
+                areaMembership.add(ai);
+                LOG.debug("Parsed AreaIdentifier {}", ai);
+                break;
+            case TlvUtil.LOCAL_IPV4_ROUTER_ID:
+                final Ipv4RouterIdentifier ip4 = new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value));
+                builder.setIpv4RouterId(ip4);
+                LOG.debug("Parsed IPv4 Router Identifier {}", ip4);
+                break;
+            case TlvUtil.LOCAL_IPV6_ROUTER_ID:
+                final Ipv6RouterIdentifier ip6 = new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value));
+                builder.setIpv6RouterId(ip6);
+                LOG.debug("Parsed IPv6 Router Identifier {}", ip6);
+                break;
+            default:
+                LOG.warn("TLV {} is not a valid node attribute, ignoring it", key);
+            }
+        }
+        LOG.trace("Finished parsing Node Attributes.");
+        builder.setTopologyIdentifier(topologyMembership);
+        builder.setIsisAreaId(areaMembership);
+        return new NodeAttributesCaseBuilder().setNodeAttributes(builder.build()).build();
+    }
+
+    static void serializeNodeAttributes(final NodeAttributesCase nodeAttributesCase, final ByteBuf byteAggregator) {
+        LOG.trace("Started serializing Node Attributes");
+        final NodeAttributes nodeAttributes = nodeAttributesCase.getNodeAttributes();
+        final List<TopologyIdentifier> topList = nodeAttributes.getTopologyIdentifier();
+        if (topList != null && !topList.isEmpty()) {
+            final ByteBuf mpIdBuf = Unpooled.buffer();
+            for (final TopologyIdentifier topologyIdentifier : topList) {
+                mpIdBuf.writeShort(topologyIdentifier.getValue());
+            }
+            TlvUtil.writeTLV(TlvUtil.MULTI_TOPOLOGY_ID, mpIdBuf, byteAggregator);
+        }
+        serializeNodeFlagBits(nodeAttributes.getNodeFlags(), byteAggregator);
+        if (nodeAttributes.getDynamicHostname() != null) {
+            TlvUtil.writeTLV(DYNAMIC_HOSTNAME, Unpooled.wrappedBuffer(Charsets.UTF_8.encode(nodeAttributes.getDynamicHostname())), byteAggregator);
+        }
+        final List<IsisAreaIdentifier> isisList = nodeAttributes.getIsisAreaId();
+        if (isisList != null && !isisList.isEmpty()) {
+            for (final IsisAreaIdentifier isisAreaIdentifier : isisList) {
+                TlvUtil.writeTLV(ISIS_AREA_IDENTIFIER, Unpooled.wrappedBuffer(isisAreaIdentifier.getValue()), byteAggregator);
+            }
+        }
+        if (nodeAttributes.getIpv4RouterId() != null) {
+            TlvUtil.writeTLV(TlvUtil.LOCAL_IPV4_ROUTER_ID, Ipv4Util.byteBufForAddress(nodeAttributes.getIpv4RouterId()), byteAggregator);
+        }
+        if (nodeAttributes.getIpv6RouterId() != null) {
+            TlvUtil.writeTLV(TlvUtil.LOCAL_IPV6_ROUTER_ID, Ipv6Util.byteBufForAddress(nodeAttributes.getIpv6RouterId()), byteAggregator);
+        }
+        LOG.trace("Finished serializing Node Attributes");
+    }
+
+    private static void serializeNodeFlagBits(final NodeFlagBits nodeFlagBits, final ByteBuf byteAggregator) {
+        if (nodeFlagBits != null) {
+            final ByteBuf nodeFlagBuf = Unpooled.buffer(1);
+            final BitSet flags = new BitSet(Byte.SIZE);
+            if (nodeFlagBits.isOverload() != null) {
+                flags.set(OVERLOAD_BIT, nodeFlagBits.isOverload());
+            }
+            if (nodeFlagBits.isAttached() != null) {
+                flags.set(ATTACHED_BIT, nodeFlagBits.isAttached());
+            }
+            if (nodeFlagBits.isExternal() != null) {
+                flags.set(EXTERNAL_BIT, nodeFlagBits.isExternal());
+            }
+            if (nodeFlagBits.isAbr() != null) {
+                flags.set(ABBR_BIT, nodeFlagBits.isAbr());
+            }
+            nodeFlagBuf.writeBytes(flags.toByteArray());
+            TlvUtil.writeTLV(NODE_FLAG_BITS, nodeFlagBuf, byteAggregator);
+        }
+    }
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/PrefixAttributesParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/PrefixAttributesParser.java
new file mode 100644 (file)
index 0000000..0842ec7
--- /dev/null
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.linkstate.attribute;
+
+import com.google.common.collect.Multimap;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import io.netty.buffer.Unpooled;
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.List;
+import java.util.Map.Entry;
+import org.opendaylight.protocol.bgp.linkstate.TlvUtil;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.Ipv4Util;
+import org.opendaylight.protocol.util.Ipv6Util;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.ExtendedRouteTag;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.IgpBits.UpDown;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.RouteTag;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.prefix.state.IgpBitsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.LinkStateAttribute;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.PrefixAttributesCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.PrefixAttributesCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.prefix.attributes._case.PrefixAttributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.prefix.attributes._case.PrefixAttributesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.IgpMetric;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+final class PrefixAttributesParser {
+
+    private static final Logger LOG = LoggerFactory.getLogger(PrefixAttributesParser.class);
+
+    private static final int ROUTE_TAG_LENGTH = 4;
+    private static final int EXTENDED_ROUTE_TAG_LENGTH = 8;
+    private static final int UP_DOWN_BIT = 7;
+
+    /* Prefix Attribute TLVs */
+    private static final int IGP_FLAGS = 1152;
+    private static final int ROUTE_TAG = 1153;
+    private static final int EXTENDED_ROUTE_TAG = 1154;
+    private static final int PREFIX_METRIC = 1155;
+    private static final int FORWARDING_ADDRESS = 1156;
+    private static final int PREFIX_OPAQUE = 1157;
+
+    /**
+     * Parse prefix attributes.
+     *
+     * @param attributes key is the tlv type and value are the value bytes of the tlv
+     * @return {@link LinkStateAttribute}
+     */
+    static LinkStateAttribute parsePrefixAttributes(final Multimap<Integer, ByteBuf> attributes) {
+        final PrefixAttributesBuilder builder = new PrefixAttributesBuilder();
+        final List<RouteTag> routeTags = new ArrayList<>();
+        final List<ExtendedRouteTag> exRouteTags = new ArrayList<>();
+        for (final Entry<Integer, ByteBuf> entry : attributes.entries()) {
+            final int key = entry.getKey();
+            final ByteBuf value = entry.getValue();
+            LOG.trace("Prefix attribute TLV {}", key);
+            switch (key) {
+            case IGP_FLAGS:
+                final BitSet flags = BitSet.valueOf(ByteArray.readAllBytes(value));
+                final boolean upDownBit = flags.get(UP_DOWN_BIT);
+                builder.setIgpBits(new IgpBitsBuilder().setUpDown(new UpDown(upDownBit)).build());
+                LOG.debug("Parsed IGP flag (up/down bit) : {}", upDownBit);
+                break;
+            case ROUTE_TAG:
+                while (value.isReadable()) {
+                    final RouteTag routeTag = new RouteTag(ByteArray.readBytes(value, ROUTE_TAG_LENGTH));
+                    routeTags.add(routeTag);
+                    LOG.debug("Parsed Route Tag: {}", routeTag);
+                }
+                break;
+            case EXTENDED_ROUTE_TAG:
+                while (value.isReadable()) {
+                    final ExtendedRouteTag exRouteTag = new ExtendedRouteTag(ByteArray.readBytes(value, EXTENDED_ROUTE_TAG_LENGTH));
+                    exRouteTags.add(exRouteTag);
+                    LOG.debug("Parsed Extended Route Tag: {}", exRouteTag);
+                }
+                break;
+            case PREFIX_METRIC:
+                final IgpMetric metric = new IgpMetric(value.readUnsignedInt());
+                builder.setPrefixMetric(metric);
+                LOG.debug("Parsed Metric: {}", metric);
+                break;
+            case FORWARDING_ADDRESS:
+                final IpAddress fwdAddress = parseForwardingAddress(value);
+                builder.setOspfForwardingAddress(fwdAddress);
+                LOG.debug("Parsed FWD Address: {}", fwdAddress);
+                break;
+            case PREFIX_OPAQUE:
+                LOG.debug("Parsed Opaque value: {}, not preserving it", ByteBufUtil.hexDump(value));
+                break;
+            default:
+                LOG.warn("TLV {} is not a valid prefix attribute, ignoring it", key);
+            }
+        }
+        LOG.trace("Finished parsing Prefix Attributes.");
+        builder.setRouteTags(routeTags);
+        builder.setExtendedTags(exRouteTags);
+        return new PrefixAttributesCaseBuilder().setPrefixAttributes(builder.build()).build();
+    }
+
+    private static IpAddress parseForwardingAddress(final ByteBuf value) {
+        IpAddress fwdAddress = null;
+        switch (value.readableBytes()) {
+        case Ipv4Util.IP4_LENGTH:
+            fwdAddress = new IpAddress(Ipv4Util.addressForByteBuf(value));
+            break;
+        case Ipv6Util.IPV6_LENGTH:
+            fwdAddress = new IpAddress(Ipv6Util.addressForByteBuf(value));
+            break;
+        default:
+            LOG.debug("Ignoring unsupported forwarding address length {}", value.readableBytes());
+        }
+        return fwdAddress;
+    }
+
+    static void serializePrefixAttributes(final PrefixAttributesCase prefixAttributesCase, final ByteBuf byteAggregator) {
+        final PrefixAttributes prefixAtrributes = prefixAttributesCase.getPrefixAttributes();
+        if (prefixAtrributes.getIgpBits() != null) {
+            final BitSet igpBit = new BitSet();
+            final Boolean bit = prefixAtrributes.getIgpBits().getUpDown().isUpDown();
+            if (bit != null) {
+                igpBit.set(UP_DOWN_BIT, bit);
+            }
+            TlvUtil.writeTLV(IGP_FLAGS, Unpooled.wrappedBuffer(igpBit.toByteArray()), byteAggregator);
+        }
+        if (prefixAtrributes.getRouteTags() != null) {
+            final ByteBuf routeTagsBuf = Unpooled.buffer();
+            for (final RouteTag routeTag : prefixAtrributes.getRouteTags()) {
+                routeTagsBuf.writeBytes(routeTag.getValue());
+            }
+            TlvUtil.writeTLV(ROUTE_TAG, routeTagsBuf, byteAggregator);
+        }
+        final List<ExtendedRouteTag> routeTagList = prefixAtrributes.getExtendedTags();
+        if (routeTagList != null && !routeTagList.isEmpty()) {
+            final ByteBuf extendedBuf = Unpooled.buffer();
+            for (final ExtendedRouteTag extendedRouteTag : routeTagList) {
+                extendedBuf.writeBytes(extendedRouteTag.getValue());
+            }
+            TlvUtil.writeTLV(EXTENDED_ROUTE_TAG, extendedBuf, byteAggregator);
+        }
+        if (prefixAtrributes.getPrefixMetric() != null) {
+            TlvUtil.writeTLV(PREFIX_METRIC, Unpooled.copyInt(prefixAtrributes.getPrefixMetric().getValue().intValue()), byteAggregator);
+        }
+        serializeForwardingAddress(prefixAtrributes.getOspfForwardingAddress(), byteAggregator);
+    }
+
+    private static void serializeForwardingAddress(final IpAddress forwardingAddress, final ByteBuf byteAggregator) {
+        if (forwardingAddress != null) {
+            final ByteBuf ospfBuf = Unpooled.buffer();
+            if (forwardingAddress.getIpv4Address() != null) {
+                ospfBuf.writeBytes(Ipv4Util.bytesForAddress(forwardingAddress.getIpv4Address()));
+            } else if (forwardingAddress.getIpv6Address() != null) {
+                ospfBuf.writeBytes(Ipv6Util.bytesForAddress(forwardingAddress.getIpv6Address()));
+            }
+            TlvUtil.writeTLV(FORWARDING_ADDRESS, ospfBuf, byteAggregator);
+        }
+    }
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/LinkNlriParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/LinkNlriParser.java
new file mode 100644 (file)
index 0000000..1663d68
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.linkstate.nlri;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.bgp.linkstate.TlvUtil;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.util.Ipv4Util;
+import org.opendaylight.protocol.util.Ipv6Util;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv4InterfaceIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv6InterfaceIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.TopologyIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.LinkDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.LinkDescriptorsBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+final class LinkNlriParser {
+
+    private static final Logger LOG = LoggerFactory.getLogger(LinkNlriParser.class);
+
+    /* Link Descriptor TLVs */
+    private static final int LINK_LR_IDENTIFIERS = 258;
+    private static final int IPV4_IFACE_ADDRESS = 259;
+    private static final int IPV4_NEIGHBOR_ADDRESS = 260;
+    private static final int IPV6_IFACE_ADDRESS = 261;
+    private static final int IPV6_NEIGHBOR_ADDRESS = 262;
+
+    static LinkDescriptors parseLinkDescriptors(final ByteBuf buffer) throws BGPParsingException {
+        final LinkDescriptorsBuilder builder = new LinkDescriptorsBuilder();
+        while (buffer.isReadable()) {
+            final int type = buffer.readUnsignedShort();
+            final int length = buffer.readUnsignedShort();
+            final ByteBuf value = buffer.slice(buffer.readerIndex(), length);
+            LOG.trace("Parsing Link Descriptor: {}", ByteBufUtil.hexDump(value));
+            switch (type) {
+            case LINK_LR_IDENTIFIERS:
+                builder.setLinkLocalIdentifier(value.readUnsignedInt());
+                builder.setLinkRemoteIdentifier(value.readUnsignedInt());
+                LOG.debug("Parsed link local {} remote {} Identifiers.", builder.getLinkLocalIdentifier(),
+                    builder.getLinkRemoteIdentifier());
+                break;
+            case IPV4_IFACE_ADDRESS:
+                final Ipv4InterfaceIdentifier lipv4 = new Ipv4InterfaceIdentifier(Ipv4Util.addressForByteBuf(value));
+                builder.setIpv4InterfaceAddress(lipv4);
+                LOG.debug("Parsed IPv4 interface address {}.", lipv4);
+                break;
+            case IPV4_NEIGHBOR_ADDRESS:
+                final Ipv4InterfaceIdentifier ripv4 = new Ipv4InterfaceIdentifier(Ipv4Util.addressForByteBuf(value));
+                builder.setIpv4NeighborAddress(ripv4);
+                LOG.debug("Parsed IPv4 neighbor address {}.", ripv4);
+                break;
+            case IPV6_IFACE_ADDRESS:
+                final Ipv6InterfaceIdentifier lipv6 = new Ipv6InterfaceIdentifier(Ipv6Util.addressForByteBuf(value));
+                builder.setIpv6InterfaceAddress(lipv6);
+                LOG.debug("Parsed IPv6 interface address {}.", lipv6);
+                break;
+            case IPV6_NEIGHBOR_ADDRESS:
+                final Ipv6InterfaceIdentifier ripv6 = new Ipv6InterfaceIdentifier(Ipv6Util.addressForByteBuf(value));
+                builder.setIpv6NeighborAddress(ripv6);
+                LOG.debug("Parsed IPv6 neighbor address {}.", ripv6);
+                break;
+            case TlvUtil.MULTI_TOPOLOGY_ID:
+                final TopologyIdentifier topId = new TopologyIdentifier(value.readUnsignedShort() & TlvUtil.TOPOLOGY_ID_OFFSET);
+                builder.setMultiTopologyId(topId);
+                LOG.debug("Parsed topology identifier {}.", topId);
+                break;
+            default:
+                throw new BGPParsingException("Link Descriptor not recognized, type: " + type);
+            }
+            buffer.skipBytes(length);
+        }
+        LOG.trace("Finished parsing Link descriptors.");
+        return builder.build();
+    }
+
+    static void serializeLinkDescriptors(final LinkDescriptors descriptors, final ByteBuf buffer) {
+        if (descriptors.getLinkLocalIdentifier() != null && descriptors.getLinkRemoteIdentifier() != null) {
+            final ByteBuf identifierBuf = Unpooled.buffer();
+            identifierBuf.writeInt(descriptors.getLinkLocalIdentifier().intValue());
+            identifierBuf.writeInt(descriptors.getLinkRemoteIdentifier().intValue());
+            TlvUtil.writeTLV(LINK_LR_IDENTIFIERS, identifierBuf, buffer);
+        }
+        if (descriptors.getIpv4InterfaceAddress() != null) {
+            TlvUtil.writeTLV(IPV4_IFACE_ADDRESS, Ipv4Util.byteBufForAddress(descriptors.getIpv4InterfaceAddress()), buffer);
+        }
+        if (descriptors.getIpv4NeighborAddress() != null) {
+            TlvUtil.writeTLV(IPV4_NEIGHBOR_ADDRESS, Ipv4Util.byteBufForAddress(descriptors.getIpv4NeighborAddress()), buffer);
+        }
+        if (descriptors.getIpv6InterfaceAddress() != null) {
+            TlvUtil.writeTLV(IPV6_IFACE_ADDRESS, Ipv6Util.byteBufForAddress(descriptors.getIpv6InterfaceAddress()), buffer);
+        }
+        if (descriptors.getIpv6NeighborAddress() != null) {
+            TlvUtil.writeTLV(IPV6_NEIGHBOR_ADDRESS, Ipv6Util.byteBufForAddress(descriptors.getIpv6NeighborAddress()), buffer);
+        }
+        if (descriptors.getMultiTopologyId() != null) {
+            TlvUtil.writeTLV(TlvUtil.MULTI_TOPOLOGY_ID, Unpooled.copyShort(descriptors.getMultiTopologyId().getValue()), buffer);
+        }
+    }
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/LinkstateNlriParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/LinkstateNlriParser.java
new file mode 100644 (file)
index 0000000..336b5dd
--- /dev/null
@@ -0,0 +1,247 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.linkstate.nlri;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import java.math.BigInteger;
+import java.util.List;
+import org.opendaylight.protocol.bgp.linkstate.TlvUtil;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.bgp.parser.spi.NlriParser;
+import org.opendaylight.protocol.bgp.parser.spi.NlriSerializer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Identifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.NlriType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.NodeIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.ProtocolId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.RouteDistinguisher;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.CLinkstateDestination;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.CLinkstateDestinationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.LocalNodeDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpUnreachNlri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpUnreachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.mp.reach.nlri.AdvertizedRoutes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Parser and serializer for Linkstate NLRI.
+ */
+public final class LinkstateNlriParser implements NlriParser, NlriSerializer {
+    private static final Logger LOG = LoggerFactory.getLogger(LinkstateNlriParser.class);
+    private static final int ROUTE_DISTINGUISHER_LENGTH = 8;
+    private static final int PROTOCOL_ID_LENGTH = 1;
+    private static final int IDENTIFIER_LENGTH = 8;
+
+    private static final int TYPE_LENGTH = 2;
+    private static final int LENGTH_SIZE = 2;
+
+
+    private static final int LOCAL_NODE_DESCRIPTORS = 256;
+    private static final int REMOTE_NODE_DESCRIPTORS = 257;
+
+    private final boolean isVpn;
+
+    public LinkstateNlriParser(final boolean isVpn) {
+        this.isVpn = isVpn;
+    }
+
+    private static NodeIdentifier parseLink(final CLinkstateDestinationBuilder builder, final ByteBuf buffer) throws BGPParsingException {
+        final int type = buffer.readUnsignedShort();
+        final int length = buffer.readUnsignedShort();
+        final NodeIdentifier remote = null;
+        if (type == REMOTE_NODE_DESCRIPTORS) {
+            builder.setRemoteNodeDescriptors((RemoteNodeDescriptors) NodeNlriParser.parseNodeDescriptors(buffer.slice(buffer.readerIndex(), length), false));
+            buffer.skipBytes(length);
+        }
+        builder.setLinkDescriptors(LinkNlriParser.parseLinkDescriptors(buffer.slice()));
+        return remote;
+    }
+
+    /**
+     * Parses common parts for Link State Nodes, Links and Prefixes, that includes protocol ID and identifier tlv.
+     *
+     * @param nlri as byte array
+     * @return {@link CLinkstateDestination}
+     * @throws BGPParsingException if parsing was unsuccessful
+     */
+    public static List<CLinkstateDestination> parseNlri(final ByteBuf nlri, final boolean isVpn) throws BGPParsingException {
+        if (!nlri.isReadable()) {
+            return null;
+        }
+        final List<CLinkstateDestination> dests = Lists.newArrayList();
+
+        CLinkstateDestinationBuilder builder = null;
+
+        while (nlri.isReadable()) {
+            builder = new CLinkstateDestinationBuilder();
+            final NlriType type = NlriType.forValue(nlri.readUnsignedShort());
+            builder.setNlriType(type);
+
+            // length means total length of the tlvs including route distinguisher not including the type field
+            final int length = nlri.readUnsignedShort();
+            RouteDistinguisher distinguisher = null;
+            if (isVpn) {
+                // this parses route distinguisher
+                distinguisher = new RouteDistinguisher(BigInteger.valueOf(nlri.readLong()));
+                builder.setDistinguisher(distinguisher);
+            }
+            // parse source protocol
+            final ProtocolId sp = ProtocolId.forValue(nlri.readByte());
+            builder.setProtocolId(sp);
+
+            // parse identifier
+            final Identifier identifier = new Identifier(BigInteger.valueOf(nlri.readLong()));
+            builder.setIdentifier(identifier);
+
+            // if we are dealing with linkstate nodes/links, parse local node descriptor
+            NodeIdentifier localDescriptor = null;
+            int locallength = 0;
+            final int localtype = nlri.readUnsignedShort();
+            locallength = nlri.readUnsignedShort();
+            if (localtype == LOCAL_NODE_DESCRIPTORS) {
+                localDescriptor = NodeNlriParser.parseNodeDescriptors(nlri.slice(nlri.readerIndex(), locallength), true);
+            }
+            nlri.skipBytes(locallength);
+            builder.setLocalNodeDescriptors((LocalNodeDescriptors) localDescriptor);
+            final int restLength = length - (isVpn ? ROUTE_DISTINGUISHER_LENGTH : 0) - PROTOCOL_ID_LENGTH - IDENTIFIER_LENGTH
+                - TYPE_LENGTH - LENGTH_SIZE - locallength;
+            LOG.trace("Restlength {}", restLength);
+            final ByteBuf rest = nlri.slice(nlri.readerIndex(), restLength);
+            switch (type) {
+            case Link:
+                parseLink(builder, rest);
+                break;
+            case Ipv4Prefix:
+                builder.setPrefixDescriptors(PrefixNlriParser.parsePrefixDescriptors(rest, true));
+                break;
+            case Ipv6Prefix:
+                builder.setPrefixDescriptors(PrefixNlriParser.parsePrefixDescriptors(rest, false));
+                break;
+            case Node:
+                // node nlri is already parsed as it contains only the common fields for node and link nlri
+                break;
+            default:
+                break;
+            }
+            nlri.skipBytes(restLength);
+            dests.add(builder.build());
+        }
+        return dests;
+    }
+
+    @Override
+    public void parseNlri(final ByteBuf nlri, final MpUnreachNlriBuilder builder) throws BGPParsingException {
+        if (!nlri.isReadable()) {
+            return;
+        }
+        final List<CLinkstateDestination> dst = parseNlri(nlri, this.isVpn);
+
+        builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
+            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCaseBuilder().setDestinationLinkstate(
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder().setCLinkstateDestination(
+                    dst).build()).build()).build());
+    }
+
+    @Override
+    public void parseNlri(final ByteBuf nlri, final MpReachNlriBuilder builder) throws BGPParsingException {
+        if (!nlri.isReadable()) {
+            return;
+        }
+        final List<CLinkstateDestination> dst = parseNlri(nlri, this.isVpn);
+
+        builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
+            new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
+                new DestinationLinkstateBuilder().setCLinkstateDestination(dst).build()).build()).build());
+    }
+
+    /**
+     * Serializes Linkstate NLRI to byte array. We need this as NLRI serves as a key in upper layers.
+     *
+     * @param destination Linkstate NLRI to be serialized
+     */
+    public static void serializeNlri(final CLinkstateDestination destination, final ByteBuf buffer) {
+        final ByteBuf nlriByteBuf = Unpooled.buffer();
+        if (destination.getDistinguisher() != null) {
+            nlriByteBuf.writeBytes(destination.getDistinguisher().getValue().toByteArray());
+        }
+        nlriByteBuf.writeByte(destination.getProtocolId().getIntValue());
+        nlriByteBuf.writeLong(destination.getIdentifier().getValue().longValue());
+
+        // serialize local node descriptors
+        final ByteBuf ldescs = Unpooled.buffer();
+        NodeNlriParser.serializeNodeDescriptors(destination.getLocalNodeDescriptors(), ldescs);
+        TlvUtil.writeTLV(LOCAL_NODE_DESCRIPTORS, ldescs, nlriByteBuf);
+
+        switch (destination.getNlriType()) {
+        case Ipv4Prefix:
+        case Ipv6Prefix:
+            if (destination.getPrefixDescriptors() != null) {
+                PrefixNlriParser.serializePrefixDescriptors(destination.getPrefixDescriptors(), nlriByteBuf);
+            }
+            break;
+        case Link:
+            final ByteBuf rdescs = Unpooled.buffer();
+            NodeNlriParser.serializeNodeDescriptors(destination.getRemoteNodeDescriptors(), rdescs);
+            TlvUtil.writeTLV(REMOTE_NODE_DESCRIPTORS, rdescs, nlriByteBuf);
+            if (destination.getLinkDescriptors() != null) {
+                LinkNlriParser.serializeLinkDescriptors(destination.getLinkDescriptors(), nlriByteBuf);
+            }
+            break;
+        case Node:
+            break;
+        default:
+            LOG.warn("Unknown NLRI Type.");
+            break;
+        }
+        TlvUtil.writeTLV(destination.getNlriType().getIntValue(), nlriByteBuf, buffer);
+    }
+
+    @Override
+    public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
+        Preconditions.checkArgument(attribute instanceof PathAttributes, "Attribute parameter is not a PathAttribute object.");
+        final PathAttributes pathAttributes = (PathAttributes) attribute;
+        final PathAttributes1 pathAttributes1 = pathAttributes.getAugmentation(PathAttributes1.class);
+        final PathAttributes2 pathAttributes2 = pathAttributes.getAugmentation(PathAttributes2.class);
+        if (pathAttributes1 != null) {
+            final AdvertizedRoutes routes = (pathAttributes1.getMpReachNlri()).getAdvertizedRoutes();
+            if (routes != null &&
+                routes.getDestinationType()
+                instanceof
+                org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase) {
+                final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase
+                linkstateCase = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase) routes.getDestinationType();
+
+                for (final CLinkstateDestination cLinkstateDestination : linkstateCase.getDestinationLinkstate().getCLinkstateDestination()) {
+                    serializeNlri(cLinkstateDestination, byteAggregator);
+                }
+            }
+        } else if (pathAttributes2 != null) {
+            final MpUnreachNlri mpUnreachNlri = pathAttributes2.getMpUnreachNlri();
+            if (mpUnreachNlri.getWithdrawnRoutes() != null && mpUnreachNlri.getWithdrawnRoutes().getDestinationType() instanceof DestinationLinkstateCase) {
+                final DestinationLinkstateCase linkstateCase = (DestinationLinkstateCase) mpUnreachNlri.getWithdrawnRoutes().getDestinationType();
+                for (final CLinkstateDestination cLinkstateDestination : linkstateCase.getDestinationLinkstate().getCLinkstateDestination()) {
+                    serializeNlri(cLinkstateDestination, byteAggregator);
+                }
+            }
+        }
+    }
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/NodeNlriParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/NodeNlriParser.java
new file mode 100644 (file)
index 0000000..433e52c
--- /dev/null
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.linkstate.nlri;
+
+import com.google.common.primitives.UnsignedInteger;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.bgp.linkstate.TlvUtil;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.AreaIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.DomainIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.NodeIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.OspfInterfaceIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.isis.lan.identifier.IsIsRouterIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.isis.lan.identifier.IsIsRouterIdentifierBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.LocalNodeDescriptorsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptorsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.CRouterIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.IsisNodeCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.IsisNodeCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.IsisPseudonodeCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.IsisPseudonodeCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.OspfNodeCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.OspfNodeCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.OspfPseudonodeCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.OspfPseudonodeCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.isis.node._case.IsisNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.isis.node._case.IsisNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.isis.pseudonode._case.IsisPseudonode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.isis.pseudonode._case.IsisPseudonodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.ospf.node._case.OspfNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.ospf.pseudonode._case.OspfPseudonode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.ospf.pseudonode._case.OspfPseudonodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.IsoSystemIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+final class NodeNlriParser {
+
+    private static final Logger LOG = LoggerFactory.getLogger(NodeNlriParser.class);
+
+    private static final int OSPF_PSEUDONODE_ROUTER_ID_LENGTH = 8;
+    private static final int OSPF_ROUTER_ID_LENGTH = 4;
+    private static final int ISO_SYSTEM_ID_LENGTH = 6;
+    private static final int PSN_LENGTH = 1;
+
+    /* Node Descriptor TLVs */
+    private static final int AS_NUMBER = 512;
+    private static final int BGP_LS_ID = 513;
+    private static final int AREA_ID = 514;
+    private static final int IGP_ROUTER_ID = 515;
+
+    static NodeIdentifier parseNodeDescriptors(final ByteBuf buffer, final boolean local) throws BGPParsingException {
+        AsNumber asnumber = null;
+        DomainIdentifier bgpId = null;
+        AreaIdentifier ai = null;
+        CRouterIdentifier routerId = null;
+        while (buffer.isReadable()) {
+            final int type = buffer.readUnsignedShort();
+            final int length = buffer.readUnsignedShort();
+            final ByteBuf value = buffer.slice(buffer.readerIndex(), length);
+            if (LOG.isTraceEnabled()) {
+                LOG.trace("Parsing Node Descriptor: {}", ByteBufUtil.hexDump(value));
+            }
+            switch (type) {
+            case AS_NUMBER:
+                asnumber = new AsNumber(value.readUnsignedInt());
+                LOG.debug("Parsed {}", asnumber);
+                break;
+            case BGP_LS_ID:
+                bgpId = new DomainIdentifier(value.readUnsignedInt());
+                LOG.debug("Parsed {}", bgpId);
+                break;
+            case AREA_ID:
+                ai = new AreaIdentifier(value.readUnsignedInt());
+                LOG.debug("Parsed area identifier {}", ai);
+                break;
+            case IGP_ROUTER_ID:
+                routerId = parseRouterId(value);
+                LOG.debug("Parsed Router Identifier {}", routerId);
+                break;
+            default:
+                throw new BGPParsingException("Node Descriptor not recognized, type: " + type);
+            }
+            buffer.skipBytes(length);
+        }
+        LOG.trace("Finished parsing Node descriptors.");
+        return (local) ? new LocalNodeDescriptorsBuilder().setAsNumber(asnumber).setDomainId(bgpId).setAreaId(ai).setCRouterIdentifier(
+            routerId).build()
+            : new RemoteNodeDescriptorsBuilder().setAsNumber(asnumber).setDomainId(bgpId).setAreaId(ai).setCRouterIdentifier(routerId).build();
+    }
+
+    private static CRouterIdentifier parseRouterId(final ByteBuf value) throws BGPParsingException {
+        if (value.readableBytes() == ISO_SYSTEM_ID_LENGTH || (value.readableBytes() == ISO_SYSTEM_ID_LENGTH + PSN_LENGTH && value.getByte(ISO_SYSTEM_ID_LENGTH) == 0)) {
+            return new IsisNodeCaseBuilder().setIsisNode(
+                new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(ByteArray.readBytes(value, ISO_SYSTEM_ID_LENGTH))).build()).build();
+        }
+        if (value.readableBytes() == ISO_SYSTEM_ID_LENGTH + PSN_LENGTH) {
+            final IsIsRouterIdentifier iri = new IsIsRouterIdentifierBuilder().setIsoSystemId(
+                new IsoSystemIdentifier(ByteArray.readBytes(value, ISO_SYSTEM_ID_LENGTH))).build();
+            return new IsisPseudonodeCaseBuilder().setIsisPseudonode(new IsisPseudonodeBuilder().setIsIsRouterIdentifier(iri).setPsn((short) value.readByte()).build()).build();
+        }
+        if (value.readableBytes() == OSPF_ROUTER_ID_LENGTH) {
+            return new OspfNodeCaseBuilder().setOspfNode(
+                new OspfNodeBuilder().setOspfRouterId(value.readUnsignedInt()).build()).build();
+        }
+        if (value.readableBytes() == OSPF_PSEUDONODE_ROUTER_ID_LENGTH) {
+            return new OspfPseudonodeCaseBuilder().setOspfPseudonode(
+                new OspfPseudonodeBuilder().setOspfRouterId(value.readUnsignedInt()).setLanInterface(new OspfInterfaceIdentifier(value.readUnsignedInt())).build()).build();
+        }
+        throw new BGPParsingException("Router Id of invalid length " + value.readableBytes());
+    }
+
+    static void serializeNodeDescriptors(final NodeIdentifier descriptors, final ByteBuf buffer) {
+        if (descriptors.getAsNumber() != null) {
+            TlvUtil.writeTLV(AS_NUMBER, Unpooled.copyInt(UnsignedInteger.valueOf(descriptors.getAsNumber().getValue()).intValue()), buffer);
+        }
+        if (descriptors.getDomainId() != null) {
+            TlvUtil.writeTLV(BGP_LS_ID, Unpooled.copyInt(UnsignedInteger.valueOf(descriptors.getDomainId().getValue()).intValue()), buffer);
+        }
+        if (descriptors.getAreaId() != null) {
+            TlvUtil.writeTLV(AREA_ID, Unpooled.copyInt(UnsignedInteger.valueOf(descriptors.getAreaId().getValue()).intValue()), buffer);
+        }
+        if (descriptors.getCRouterIdentifier() != null) {
+            final ByteBuf routerIdBuf = Unpooled.buffer();
+            serializeRouterId(descriptors.getCRouterIdentifier(), routerIdBuf);
+            TlvUtil.writeTLV(IGP_ROUTER_ID, routerIdBuf, buffer);
+        }
+    }
+
+    private static void serializeRouterId(final CRouterIdentifier routerId, final ByteBuf buffer) {
+        if (routerId instanceof IsisNodeCase) {
+            final IsisNode isis = ((IsisNodeCase) routerId).getIsisNode();
+            buffer.writeBytes(isis.getIsoSystemId().getValue());
+        } else if (routerId instanceof IsisPseudonodeCase) {
+            final IsisPseudonode isis = ((IsisPseudonodeCase) routerId).getIsisPseudonode();
+            buffer.writeBytes(isis.getIsIsRouterIdentifier().getIsoSystemId().getValue());
+            buffer.writeByte(((isis.getPsn() != null) ? isis.getPsn() : 0));
+        } else if (routerId instanceof OspfNodeCase) {
+            buffer.writeInt(UnsignedInteger.valueOf(((OspfNodeCase) routerId).getOspfNode().getOspfRouterId()).intValue());
+        } else if (routerId instanceof OspfPseudonodeCase) {
+            final OspfPseudonode node = ((OspfPseudonodeCase) routerId).getOspfPseudonode();
+            buffer.writeInt(UnsignedInteger.valueOf(node.getOspfRouterId()).intValue());
+            buffer.writeInt(UnsignedInteger.valueOf(node.getLanInterface().getValue()).intValue());
+        }
+    }
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/PrefixNlriParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/PrefixNlriParser.java
new file mode 100644 (file)
index 0000000..7ce7e66
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.linkstate.nlri;
+
+import com.google.common.primitives.UnsignedBytes;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.bgp.linkstate.TlvUtil;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.Ipv4Util;
+import org.opendaylight.protocol.util.Ipv6Util;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.OspfRouteType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.TopologyIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.PrefixDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.PrefixDescriptorsBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+final class PrefixNlriParser {
+
+    private static final Logger LOG = LoggerFactory.getLogger(PrefixNlriParser.class);
+
+    /* Prefix Descriptor TLVs */
+    private static final int OSPF_ROUTE_TYPE = 264;
+    private static final int IP_REACHABILITY = 265;
+
+    static PrefixDescriptors parsePrefixDescriptors(final ByteBuf buffer, final boolean ipv4) throws BGPParsingException {
+        final PrefixDescriptorsBuilder builder = new PrefixDescriptorsBuilder();
+        while (buffer.isReadable()) {
+            final int type = buffer.readUnsignedShort();
+            final int length = buffer.readUnsignedShort();
+            final ByteBuf value = buffer.slice(buffer.readerIndex(), length);
+            if (LOG.isTraceEnabled()) {
+                LOG.trace("Parsing Prefix Descriptor: {}", ByteBufUtil.hexDump(value));
+            }
+            switch (type) {
+            case TlvUtil.MULTI_TOPOLOGY_ID:
+                final TopologyIdentifier topologyId = new TopologyIdentifier(value.readShort() & TlvUtil.TOPOLOGY_ID_OFFSET);
+                builder.setMultiTopologyId(topologyId);
+                LOG.trace("Parsed Topology Identifier: {}", topologyId);
+                break;
+            case OSPF_ROUTE_TYPE:
+                final int rt = value.readByte();
+                final OspfRouteType routeType = OspfRouteType.forValue(rt);
+                if (routeType == null) {
+                    throw new BGPParsingException("Unknown OSPF Route Type: " + rt);
+                }
+                builder.setOspfRouteType(routeType);
+                LOG.trace("Parser RouteType: {}", routeType);
+                break;
+            case IP_REACHABILITY:
+                IpPrefix prefix = null;
+                final int prefixLength = value.readByte();
+                final int size = prefixLength / Byte.SIZE + ((prefixLength % Byte.SIZE == 0) ? 0 : 1);
+                if (size != value.readableBytes()) {
+                    LOG.debug("Expected length {}, actual length {}.", size, value.readableBytes());
+                    throw new BGPParsingException("Illegal length of IP reachability TLV: " + (value.readableBytes()));
+                }
+                prefix = (ipv4) ? new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.readBytes(value, size), prefixLength)):
+                    new IpPrefix(Ipv6Util.prefixForBytes(ByteArray.readBytes(value, size), prefixLength));
+                builder.setIpReachabilityInformation(prefix);
+                LOG.trace("Parsed IP reachability info: {}", prefix);
+                break;
+            default:
+                throw new BGPParsingException("Prefix Descriptor not recognized, type: " + type);
+            }
+            buffer.skipBytes(length);
+        }
+        LOG.debug("Finished parsing Prefix descriptors.");
+        return builder.build();
+    }
+
+    static void serializePrefixDescriptors(final PrefixDescriptors descriptors, final ByteBuf buffer) {
+        if (descriptors.getMultiTopologyId() != null) {
+            TlvUtil.writeTLV(TlvUtil.MULTI_TOPOLOGY_ID, Unpooled.copyShort(descriptors.getMultiTopologyId().getValue()), buffer);
+        }
+        if (descriptors.getOspfRouteType() != null) {
+            TlvUtil.writeTLV(OSPF_ROUTE_TYPE,
+                Unpooled.wrappedBuffer(new byte[] {UnsignedBytes.checkedCast(descriptors.getOspfRouteType().getIntValue()) }), buffer);
+        }
+        if (descriptors.getIpReachabilityInformation() != null) {
+            final IpPrefix prefix = descriptors.getIpReachabilityInformation();
+            byte[] prefixBytes = null;
+            if (prefix.getIpv4Prefix() != null) {
+                prefixBytes = Ipv4Util.bytesForPrefixBegin(prefix.getIpv4Prefix());
+            } else if (prefix.getIpv6Prefix() != null) {
+                prefixBytes = Ipv6Util.bytesForPrefixBegin(prefix.getIpv6Prefix());
+            }
+            TlvUtil.writeTLV(IP_REACHABILITY, Unpooled.wrappedBuffer(prefixBytes), buffer);
+        }
+    }
+}
index cda63e46733c878b1a9033cffcff6fdb9f22cc5a..980a1d040ed6bcb59f8b7ec53050c09a337bb355 100644 (file)
@@ -109,7 +109,7 @@ public class LinkstateAdjRIBsInTest extends AbstractDataBrokerTest {
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
-        final InstanceIdentifier<Rib> iid = InstanceIdentifier.builder(BgpRib.class).child(Rib.class, new RibKey(new RibId("test-rib"))).toInstance();
+        final InstanceIdentifier<Rib> iid = InstanceIdentifier.builder(BgpRib.class).child(Rib.class, new RibKey(new RibId("test-rib"))).build();
         final KeyedInstanceIdentifier<Tables, TablesKey> key = iid.child(LocRib.class).child(Tables.class, new TablesKey(LinkstateAddressFamily.class,
             LinkstateSubsequentAddressFamily.class));
 
index f19b3aed90d7ff56e6684be5411826b1b8f5f3af..867530bfa94a1bdcbbcfcd56571838c5cee749e4 100644 (file)
@@ -18,6 +18,7 @@ import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import java.util.Arrays;
 import org.junit.Test;
+import org.opendaylight.protocol.bgp.linkstate.attribute.LinkstateAttributeParser;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.LinkProtectionType;
index d6526d550b35a34b0f68cd945c6fb3c2aae224f2..da1339b2d586be0763098d27b19661d78c295fb7 100644 (file)
@@ -17,6 +17,7 @@ import io.netty.buffer.Unpooled;
 import java.math.BigInteger;
 import java.util.List;
 import org.junit.Test;
+import org.opendaylight.protocol.bgp.linkstate.nlri.LinkstateNlriParser;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
similarity index 83%
rename from bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/TlvCodeTest.java
rename to bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/TlvUtilTest.java
index d91c28a29d7d9e37bd0ceed2803d96e2fc251e9f..a8b3f811eb178ca76e3f10ae0487be4bb314fa30 100644 (file)
@@ -12,15 +12,15 @@ import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import org.junit.Test;
 
-public class TlvCodeTest {
+public class TlvUtilTest {
 
     @Test(expected=UnsupportedOperationException.class)
     public void testPrivateConstructor() throws Throwable {
-        final Constructor<TlvCode> c = TlvCode.class.getDeclaredConstructor();
+        final Constructor<TlvUtil> c = TlvUtil.class.getDeclaredConstructor();
         c.setAccessible(true);
         try {
             c.newInstance();
-        } catch (InvocationTargetException e) {
+        } catch (final InvocationTargetException e) {
             throw e.getCause();
         }
     }
index 708529c6224dc801ff7879d62b2a81c52aafbdbe..432869c178d25299a21209183a47d4f860841b32 100644 (file)
@@ -145,7 +145,7 @@ public final class RIBImpl extends DefaultRibReference implements AutoCloseable,
     public RIBImpl(final RibId ribId, final AsNumber localAs, final Ipv4Address localBgpId, final RIBExtensionConsumerContext extensions,
         final BGPDispatcher dispatcher, final ReconnectStrategyFactory tcpStrategyFactory,
         final ReconnectStrategyFactory sessionStrategyFactory, final DataBroker dps, final List<BgpTableType> localTables) {
-        super(InstanceIdentifier.builder(BgpRib.class).child(Rib.class, new RibKey(Preconditions.checkNotNull(ribId))).toInstance());
+        super(InstanceIdentifier.builder(BgpRib.class).child(Rib.class, new RibKey(Preconditions.checkNotNull(ribId))).build());
         this.chain = dps.createTransactionChain(this);
         this.localAs = Preconditions.checkNotNull(localAs);
         this.comparator = new BGPObjectComparator(localAs);
index 3636a9e3bb4a5658bb64a0fc2123d1f0aa1b498a..108c54dd6169536f674698bedc69adeca47e13f8 100644 (file)
@@ -59,7 +59,7 @@ public class AdjacencyRIBsInTest extends AbstractDataBrokerTest {
 
     private WriteTransaction trans;
 
-    private final DefaultRibReference rib = new DefaultRibReference(InstanceIdentifier.builder(BgpRib.class).child(Rib.class, new RibKey(new RibId("test"))).toInstance());
+    private final DefaultRibReference rib = new DefaultRibReference(InstanceIdentifier.builder(BgpRib.class).child(Rib.class, new RibKey(new RibId("test"))).build());
 
     private final RIBActivator act = new RIBActivator();
 
index 4caf3f3675f90f6e599c85f21991f40dc11bb302..7df05df800a6a7b0b57d1cc85dd68e28cc1307f3 100644 (file)
@@ -58,7 +58,7 @@ public class AbstractAdjRIBsTest {
 
     private static final Ipv4Prefix IPV4_PREFIX2 = new Ipv4Prefix("2.2.2.2/32");
 
-    private static final InstanceIdentifier<Rib> RIB_IID = InstanceIdentifier.builder(BgpRib.class).child(Rib.class, new RibKey(new RibId("test-rib"))).toInstance();
+    private static final InstanceIdentifier<Rib> RIB_IID = InstanceIdentifier.builder(BgpRib.class).child(Rib.class, new RibKey(new RibId("test-rib"))).build();
 
     private static final KeyedInstanceIdentifier<Tables, TablesKey> TABLES_IID = RIB_IID.child(LocRib.class).child(Tables.class, new TablesKey(Ipv4AddressFamily.class,
             UnicastSubsequentAddressFamily.class));
index 6b54314bf7d24662c24a50e5b36258c84ac9fcfb..c59e499395254b5197a305242b77461ba13816d5 100644 (file)
@@ -64,7 +64,7 @@ public abstract class AbstractTopologyBuilder<T extends Route> implements AutoCl
         this.chain = dataProvider.createTransactionChain(this);
 
         final TopologyKey tk = new TopologyKey(Preconditions.checkNotNull(topologyId));
-        this.topology = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, tk).toInstance();
+        this.topology = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, tk).build();
 
         LOG.debug("Initiating topology builder from {} at {}", locRibReference, this.topology);
 
@@ -89,7 +89,7 @@ public abstract class AbstractTopologyBuilder<T extends Route> implements AutoCl
 
     public final InstanceIdentifier<Tables> tableInstanceIdentifier(final Class<? extends AddressFamily> afi,
             final Class<? extends SubsequentAddressFamily> safi) {
-        return this.locRibReference.getInstanceIdentifier().builder().child(LocRib.class).child(Tables.class, new TablesKey(afi, safi)).toInstance();
+        return this.locRibReference.getInstanceIdentifier().builder().child(LocRib.class).child(Tables.class, new TablesKey(afi, safi)).build();
     }
 
     protected abstract void createObject(ReadWriteTransaction trans, InstanceIdentifier<T> id, T value);
index 99b07001840335c394ca433797b3d2e39e575a99..07da88cbd1dfff478d04b3b1d5cb1d582253fe4a 100644 (file)
@@ -36,7 +36,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 public abstract class AbstractTopologyBuilderTest extends AbstractDataBrokerTest {
 
     protected static final TopologyId TEST_TOPOLOGY_ID = new TopologyId("test-topo");
-    protected static RibReference LOC_RIB_REF = new DefaultRibReference(InstanceIdentifier.builder(BgpRib.class).child(Rib.class, new RibKey(Preconditions.checkNotNull(new RibId("test-rib")))).toInstance());
+    protected static RibReference LOC_RIB_REF = new DefaultRibReference(InstanceIdentifier.builder(BgpRib.class).child(Rib.class, new RibKey(Preconditions.checkNotNull(new RibId("test-rib")))).build());
 
     protected ListenerRegistration<DataChangeListener> reg;
 
@@ -47,7 +47,7 @@ public abstract class AbstractTopologyBuilderTest extends AbstractDataBrokerTest
 
     protected void createEmptyTopology() {
         final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
-        wTx.put(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.builder(NetworkTopology.class).toInstance(), new NetworkTopologyBuilder().setTopology(Collections.<Topology>emptyList()).build());
+        wTx.put(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.builder(NetworkTopology.class).build(), new NetworkTopologyBuilder().setTopology(Collections.<Topology>emptyList()).build());
         wTx.submit();
     }
 
index 614834968b561374162700ea0e867718a3fe2989..d75d5f6896eac30e8973dada5012668d52facee7 100644 (file)
@@ -58,7 +58,7 @@ public class Ipv4ReachabilityTopologyBuilderTest extends AbstractTopologyBuilder
         wTx.put(LogicalDatastoreType.OPERATIONAL, path, new TablesBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class)
                 .setAttributes(new AttributesBuilder().setUptodate(Boolean.TRUE).build()).setRoutes(new Ipv4RoutesCaseBuilder().build()).build(), true);
         wTx.submit();
-        this.ipv4RouteIID = path.builder().child(Ipv4Routes.class).child(Ipv4Route.class, new Ipv4RouteKey(new Ipv4Prefix(ROUTE_IP4PREFIX))).toInstance();
+        this.ipv4RouteIID = path.builder().child(Ipv4Routes.class).child(Ipv4Route.class, new Ipv4RouteKey(new Ipv4Prefix(ROUTE_IP4PREFIX))).build();
     }
 
     @Test
index 4b23724c6feebb93fcf74e13491a91cd07de3462..ac74610ecd264ed8bb935f73a1d01424b41f1ec5 100644 (file)
@@ -58,7 +58,7 @@ public class Ipv6ReachabilityTopologyBuilderTest extends AbstractTopologyBuilder
         wTx.put(LogicalDatastoreType.OPERATIONAL, path, new TablesBuilder().setAfi(Ipv6AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class)
                 .setAttributes(new AttributesBuilder().setUptodate(Boolean.TRUE).build()).setRoutes(new Ipv6RoutesCaseBuilder().build()).build(), true);
         wTx.submit();
-        this.ipv6RouteIID = path.builder().child(Ipv6Routes.class).child(Ipv6Route.class, new Ipv6RouteKey(new Ipv6Prefix(ROUTE_IP6PREFIX))).toInstance();
+        this.ipv6RouteIID = path.builder().child(Ipv6Routes.class).child(Ipv6Route.class, new Ipv6RouteKey(new Ipv6Prefix(ROUTE_IP6PREFIX))).build();
     }
 
     @Test
index 0d718cf28d15b1928f34ebfb1557e0b93e1695e9..804c14d901acaf5ecc8e0a47fa70f895767f3dce 100644 (file)
@@ -105,7 +105,7 @@ public class LinkstateTopologyBuilderTest extends AbstractTopologyBuilderTest {
         wTx.put(LogicalDatastoreType.OPERATIONAL, path, new TablesBuilder().setAfi(LinkstateAddressFamily.class).setSafi(LinkstateSubsequentAddressFamily.class)
                 .setAttributes(new AttributesBuilder().setUptodate(Boolean.TRUE).build()).setRoutes(new LinkstateRoutesCaseBuilder().build()).build(), true);
         wTx.submit();
-        this.linkstateRouteIID = (InstanceIdentifier<LinkstateRoute>) path.builder().child((Class)LinkstateRoutes.class).child(LinkstateRoute.class, new LinkstateRouteKey(LINKSTATE_ROUTE_KEY)).toInstance();
+        this.linkstateRouteIID = (InstanceIdentifier<LinkstateRoute>) path.builder().child((Class)LinkstateRoutes.class).child(LinkstateRoute.class, new LinkstateRouteKey(LINKSTATE_ROUTE_KEY)).build();
     }
 
     @Test
index 2a79514f4bce0c2ae9d6e7b7dfb6b9882e3b751a..1f258530470e84f10777a2ba4566e9c29851bcec 100644 (file)
@@ -15,7 +15,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 public class DefaultInstanceReferenceTest {
 
-    private static final InstanceIdentifier<NetworkTopology> IID = InstanceIdentifier.builder(NetworkTopology.class).toInstance();
+    private static final InstanceIdentifier<NetworkTopology> IID = InstanceIdentifier.builder(NetworkTopology.class).build();
 
     @Test
     public void testDefaultInstanceReference() {
index 64ffe5d0c6c181e6ddbe9d082d6e461a8dd29914..02fcd38436bf02cfac228c587a1e41d50221e394 100644 (file)
@@ -43,7 +43,7 @@ public class DataChangeCounterImplModule extends org.opendaylight.controller.con
     public java.lang.AutoCloseable createInstance() {
         final TopologyDataChangeCounter counter = new TopologyDataChangeCounter(getDataProviderDependency());
         final InstanceIdentifier<Topology> topoIId = InstanceIdentifier.builder(NetworkTopology.class)
-                .child(Topology.class, new TopologyKey(new TopologyId(getTopologyName()))).toInstance();
+                .child(Topology.class, new TopologyKey(new TopologyId(getTopologyName()))).build();
         final ListenerRegistration<DataChangeListener> registration = getDataProviderDependency().registerDataChangeListener(
                 LogicalDatastoreType.OPERATIONAL, topoIId, counter, DataBroker.DataChangeScope.SUBTREE);
         return new DataChangeCounterCloseable(counter, registration);
index 2ce311adb7ab9ad00c0f60b524c243ea1f5309e8..fc5067cfdf7f1bd11b42592d2d7a7182813f9fac 100644 (file)
@@ -26,7 +26,7 @@ public class TopologyDataChangeCounter implements DataChangeListener {
     private static final Logger LOG = LoggerFactory.getLogger(TopologyDataChangeCounter.class);
 
     protected static final InstanceIdentifier<DataChangeCounter> IID = InstanceIdentifier
-            .builder(DataChangeCounter.class).toInstance();
+            .builder(DataChangeCounter.class).build();
 
     private final DataBroker dataBroker;
     private AtomicLong count;
index 20e379678c775c09103226338ba045556794a8df..5125e1a986bb22f53016f70df3645963138480a9 100644 (file)
@@ -57,7 +57,7 @@ public class PcepRpcServicesRoutingTest extends AbstractPcepOsgiTest {
         assertNotNull(getBroker());
 
         final InstanceIdentifier<Topology> topology = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class,
-                new TopologyKey(getTopologyId("Topo1"))).toInstance();
+                new TopologyKey(getTopologyId("Topo1"))).build();
 
         BindingAwareProvider provider1 = new AbstractTestProvider() {
 
@@ -76,7 +76,7 @@ public class PcepRpcServicesRoutingTest extends AbstractPcepOsgiTest {
         broker.registerProvider(provider1, getBundleContext());
 
         final InstanceIdentifier<Topology> topology2 = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class,
-                new TopologyKey(getTopologyId("Topo2"))).toInstance();
+                new TopologyKey(getTopologyId("Topo2"))).build();
 
         BindingAwareProvider provider2 = new AbstractTestProvider() {
 
@@ -160,7 +160,7 @@ public class PcepRpcServicesRoutingTest extends AbstractPcepOsgiTest {
         assertNotNull(getBroker());
 
         final InstanceIdentifier<Topology> topology = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class,
-                new TopologyKey(getTopologyId("Topo1"))).toInstance();
+                new TopologyKey(getTopologyId("Topo1"))).build();
 
         BindingAwareProvider provider1 = new AbstractTestProvider() {
 
@@ -179,7 +179,7 @@ public class PcepRpcServicesRoutingTest extends AbstractPcepOsgiTest {
         broker.registerProvider(provider1, getBundleContext());
 
         final InstanceIdentifier<Topology> topology2 = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class,
-                new TopologyKey(getTopologyId("Topo2"))).toInstance();
+                new TopologyKey(getTopologyId("Topo2"))).build();
 
         BindingAwareProvider provider2 = new AbstractTestProvider() {
 
@@ -251,7 +251,7 @@ public class PcepRpcServicesRoutingTest extends AbstractPcepOsgiTest {
         assertNotNull(getBroker());
 
         final InstanceIdentifier<Topology> topology = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class,
-                new TopologyKey(getTopologyId("Topo1"))).toInstance();
+                new TopologyKey(getTopologyId("Topo1"))).build();
 
         BindingAwareProvider provider1 = new AbstractTestProvider() {
 
@@ -270,7 +270,7 @@ public class PcepRpcServicesRoutingTest extends AbstractPcepOsgiTest {
         broker.registerProvider(provider1, getBundleContext());
 
         final InstanceIdentifier<Topology> topology2 = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class,
-                new TopologyKey(getTopologyId("Topo2"))).toInstance();
+                new TopologyKey(getTopologyId("Topo2"))).build();
 
         BindingAwareProvider provider2 = new AbstractTestProvider() {
 
index 4ce7acbdf001d0752c43798bf1b5440d88071106..73246590e46a358721412bfaa4ce77b20947cf2c 100644 (file)
                        <arguments>
                        </arguments>
                </buildCommand>
+               <buildCommand>
+                       <name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
                <buildCommand>
                        <name>org.eclipse.m2e.core.maven2Builder</name>
                        <arguments>
@@ -20,5 +25,6 @@
                <nature>org.eclipse.pde.PluginNature</nature>
                <nature>org.eclipse.jdt.core.javanature</nature>
                <nature>org.eclipse.m2e.core.maven2Nature</nature>
+               <nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
        </natures>
 </projectDescription>
index e9e35eea1b6eef6fb8dd236d514b31b30c558f26..542f96e556c63dd4c5e18c3c1421dc12f98e690f 100644 (file)
@@ -127,7 +127,7 @@ public final class PCEPTopologyProviderModule extends
     @Override
     public java.lang.AutoCloseable createInstance() {
         final InstanceIdentifier<Topology> topology = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class,
-                new TopologyKey(getTopologyId())).toInstance();
+                new TopologyKey(getTopologyId())).build();
         final InetSocketAddress address = new InetSocketAddress(listenAddress(), getListenPort().getValue());
         final KeyMapping keys = contructKeys();
 
index 5b5ab8448fa6b6389e800a26d6fe1d17ec6f1aa6..93b1fa9d11f7e820f5c2565c252256dd0a1302ab 100644 (file)
@@ -67,7 +67,7 @@ public abstract class AbstractPCEPSessionTest<T extends TopologySessionListenerF
 
     protected static final String TEST_TOPOLOGY_NAME = "testtopo";
     protected static final InstanceIdentifier<Topology> TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(
-            Topology.class, new TopologyKey(new TopologyId(TEST_TOPOLOGY_NAME))).toInstance();
+            Topology.class, new TopologyKey(new TopologyId(TEST_TOPOLOGY_NAME))).build();
     protected static final String TEST_ADDRESS = "127.0.0.1";
     protected static final NodeId NODE_ID = new NodeId("pcc://" + TEST_ADDRESS);
     protected static final String TEST_LSP_NAME = "tunnel0";
index b8f2b0da373626f3d6c40fc399ad1b21e3263e9e..7c2b2c884491f1649247c72ad61618d878758a72 100644 (file)
@@ -105,7 +105,7 @@ public final class NodeChangedListener implements DataChangeListener {
         }
 
         for (final ReportedLsp l : pccnode.getPathComputationClient().getReportedLsp()) {
-            lsps.add(id.builder().augmentation(Node1.class).child(PathComputationClient.class).child(ReportedLsp.class, l.getKey()).toInstance());
+            lsps.add(id.builder().augmentation(Node1.class).child(PathComputationClient.class).child(ReportedLsp.class, l.getKey()).build());
         }
     }
 
@@ -167,7 +167,7 @@ public final class NodeChangedListener implements DataChangeListener {
                                 for (final IpAddress a : ((Ip) tpt).getIpAddress()) {
                                     if (addr.equals(a)) {
                                         handleSni(sni, n, inControl, trans);
-                                        return this.target.builder().child(Node.class, n.getKey()).child(TerminationPoint.class, tp.getKey()).toInstance();
+                                        return this.target.builder().child(Node.class, n.getKey()).child(TerminationPoint.class, tp.getKey()).build();
                                     }
                                 }
                             } else {
@@ -260,7 +260,7 @@ public final class NodeChangedListener implements DataChangeListener {
     }
 
     private InstanceIdentifier<TerminationPoint> tpIdentifier(final NodeId node, final TpId tp) {
-        return this.target.builder().child(Node.class, new NodeKey(node)).child(TerminationPoint.class, new TerminationPointKey(tp)).toInstance();
+        return this.target.builder().child(Node.class, new NodeKey(node)).child(TerminationPoint.class, new TerminationPointKey(tp)).build();
     }
 
     private InstanceIdentifier<Node> nodeIdentifier(final NodeId node) {
index f3c2cb11f6fedb8fdeaef7445717b273a4e5209d..9ac3bda833c49276ee45542a7119e2b918f82ee6 100644 (file)
@@ -35,7 +35,7 @@ public final class PCEPTunnelTopologyProvider implements AutoCloseable {
     public static PCEPTunnelTopologyProvider create(final DataBroker dataProvider,
             final InstanceIdentifier<Topology> sourceTopology, final TopologyId targetTopology) {
         final InstanceIdentifier<Topology> dst = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class,
-                new TopologyKey(targetTopology)).toInstance();
+                new TopologyKey(targetTopology)).build();
         final NodeChangedListener ncl = new NodeChangedListener(dataProvider, dst);
 
         final InstanceIdentifier<Node> src = sourceTopology.child(Node.class);
index b38cf6c37c3062e366b4d15064bbb995195ddafe..89264abc046f81b9b93efd77232ee15e3c6f5bc8 100644 (file)
@@ -61,7 +61,7 @@ public final class PCEPTunnelTopologyProviderModule extends AbstractPCEPTunnelTo
         final BindingAwareBroker.RoutedRpcRegistration<TopologyTunnelPcepProgrammingService> reg = getRpcRegistryDependency().addRoutedRpcImplementation(
                 TopologyTunnelPcepProgrammingService.class, tp);
         final InstanceIdentifier<Topology> topology = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class,
-                new TopologyKey(getTopologyId())).toInstance();
+                new TopologyKey(getTopologyId())).build();
         reg.registerPath(NetworkTopologyContext.class, topology);
 
         final class TunnelTopologyReferenceCloseable extends DefaultTopologyReference implements AutoCloseable {
index 29d0516c27c7158b7d37a5d799434c32bb22b85c..6518957c27ee6dfc75ad2c8b0d0f842b62907cd9 100644 (file)
@@ -75,8 +75,8 @@ public class NodeChangedListenerTest extends AbstractDataBrokerTest {
     private static final String LSP2_NAME = "lsp2";
     private static final long LSP2_ID = 2;
 
-    private static final InstanceIdentifier<Topology> PCEP_TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, new TopologyKey(PCEP_TOPOLOGY_ID)).toInstance();
-    private static final InstanceIdentifier<Topology> TUNNEL_TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, new TopologyKey(TUNNEL_TOPOLOGY_ID)).toInstance();
+    private static final InstanceIdentifier<Topology> PCEP_TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, new TopologyKey(PCEP_TOPOLOGY_ID)).build();
+    private static final InstanceIdentifier<Topology> TUNNEL_TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, new TopologyKey(TUNNEL_TOPOLOGY_ID)).build();
 
     private ListenerRegistration<DataChangeListener> listenerRegistration;
 
@@ -165,13 +165,13 @@ public class NodeChangedListenerTest extends AbstractDataBrokerTest {
         node1Builder.setPathComputationClient(new PathComputationClientBuilder().setStateSync(PccSyncState.Synchronized).setReportedLsp(Lists.newArrayList(reportedLps)).setIpAddress(new IpAddress(new Ipv4Address(ipv4Address))).build());
         nodeBuilder.addAugmentation(Node1.class, node1Builder.build());
         final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
-        wTx.put(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.builder().child(Node.class, new NodeKey(nodeId)).toInstance(), nodeBuilder.build());
+        wTx.put(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.builder().child(Node.class, new NodeKey(nodeId)).build(), nodeBuilder.build());
         wTx.submit().checkedGet();
     }
 
     private void removeNode(final NodeId nodeId) throws TransactionCommitFailedException {
         final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
-        wTx.delete(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.builder().child(Node.class, new NodeKey(nodeId)).toInstance());
+        wTx.delete(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.builder().child(Node.class, new NodeKey(nodeId)).build());
         wTx.submit().checkedGet();
     }
 
index 659f054d3c7f1898cd765285c48c47327f0bf276..4a558b6fda4b44f753b0269ab5e186987cd5af56 100644 (file)
@@ -100,7 +100,7 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
 public class TunnelProgrammingTest extends AbstractDataBrokerTest {
 
     private static final TopologyId TOPOLOGY_ID = new TopologyId("tunnel-topo");
-    private static final InstanceIdentifier<Topology> TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, new TopologyKey(TOPOLOGY_ID)).toInstance();
+    private static final InstanceIdentifier<Topology> TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, new TopologyKey(TOPOLOGY_ID)).build();
 
     private static final String NODE1_IPV4 = "127.0.0.1";
     private static final NodeId NODE1_ID = new NodeId("pcc://" + NODE1_IPV4);
@@ -301,7 +301,7 @@ public class TunnelProgrammingTest extends AbstractDataBrokerTest {
         linkBuilder.setKey(new LinkKey(LINK1_ID));
         linkBuilder.addAugmentation(Link1.class, new Link1Builder().setSymbolicPathName(LINK1_ID.getValue()).build());
         final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
-        wTx.put(LogicalDatastoreType.OPERATIONAL, TOPO_IID.builder().child(Link.class, new LinkKey(LINK1_ID)).toInstance(), linkBuilder.build(), true);
+        wTx.put(LogicalDatastoreType.OPERATIONAL, TOPO_IID.builder().child(Link.class, new LinkKey(LINK1_ID)).build(), linkBuilder.build(), true);
         wTx.submit().checkedGet();
     }
 
diff --git a/pom.xml b/pom.xml
index fa466ff128f6edf07a454968ca5a1117d8fa42b0..d904784e65e4b011db4fa704c6f75606d0ac7144 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@
 
     <artifactId>releasepom</artifactId>
     <packaging>pom</packaging>
-    <name>BGPCEP release</name>
+    <name>bgpcep</name> <!-- Used by Sonar to set project name -->
     <description>BGPCEP top-level pom</description>
 
     <modules>
index bbda508a0fe29e6ae62d67ffe6ab9e5f0f52f90e..791e2384462415779f649f92ced912dcf3bb0e1d 100644 (file)
@@ -116,7 +116,7 @@ public final class ProgrammingServiceImpl implements AutoCloseable, InstructionS
         this.notifs = Preconditions.checkNotNull(notifs);
         this.executor = Preconditions.checkNotNull(executor);
         this.timer = Preconditions.checkNotNull(timer);
-        this.qid = InstanceIdentifier.builder(InstructionsQueue.class).toInstance();
+        this.qid = InstanceIdentifier.builder(InstructionsQueue.class).build();
 
         final ReadWriteTransaction t = dataProvider.newReadWriteTransaction();
         try {
index f6c1b5c8d34ab53c4c0cb0ed0a4086aef938c66a..31c31476c6a83a21371bcbb9dd4af0561a594ef8 100644 (file)
@@ -333,7 +333,7 @@ public class ProgrammingServiceImplTest extends AbstractDataBrokerTest {
 
     private boolean assertInstructionExists(final InstructionId id) {
         try {
-            return getDataBroker().newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.builder(InstructionsQueue.class).toInstance().child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.instruction.queue.Instruction.class,
+            return getDataBroker().newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.builder(InstructionsQueue.class).build().child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.instruction.queue.Instruction.class,
                     new InstructionKey(id))).get().isPresent();
         } catch (InterruptedException | ExecutionException e) {
             return false;