BUG 5031: 08/37708/12
authorOmair <of8826@att.com>
Mon, 18 Apr 2016 03:44:05 +0000 (20:44 -0700)
committerMilos Fabian <milfabia@cisco.com>
Tue, 12 Jul 2016 14:31:25 +0000 (14:31 +0000)
Bring order into the BGP-LS encoders/decoders by introducing simple codecs
and their registers for BGP-LS's NLRI TLV types, to make it more extensible.

-Introduction Nlri registry
-Introduction of BindingSubTlvs registry
...

Change-Id: I76207fd1781d0e1f5bb88118bee26bc962199200
Signed-off-by: Omair <of8826@att.com>
Signed-off-by: Milos Fabian <milfabia@cisco.com>
85 files changed:
bgp/linkstate/src/main/java/org/opendaylight/controller/config/yang/bgp/linkstate/LinkstateModule.java
bgp/linkstate/src/main/java/org/opendaylight/controller/config/yang/bgp/linkstate/LinkstateModuleFactory.java
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/BGPActivator.java [deleted file]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/sr/BindingSidLabelParser.java [deleted file]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/BGPActivator.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/LinkstateRIBSupport.java [moved from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/LinkstateRIBSupport.java with 81% similarity]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/RIBActivator.java [moved from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/RIBActivator.java with 90% similarity]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/LinkAttributesParser.java [moved from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/LinkAttributesParser.java with 77% similarity]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/LinkstateAttributeParser.java [moved from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/LinkstateAttributeParser.java with 94% similarity]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/NodeAttributesParser.java [moved from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/NodeAttributesParser.java with 93% similarity]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/PrefixAttributesParser.java [moved from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/PrefixAttributesParser.java with 75% similarity]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/TeLspAttributesParser.java [moved from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/TeLspAttributesParser.java with 97% similarity]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/BindingSidLabelParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/Ipv6SrPrefixAttributesParser.java [moved from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/sr/Ipv6SrPrefixAttributesParser.java with 95% similarity]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/RangeTlvParser.java [moved from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/sr/RangeTlvParser.java with 86% similarity]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SidLabelIndexParser.java [moved from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/sr/SidLabelIndexParser.java with 87% similarity]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SrLinkAttributesParser.java [moved from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/sr/SrLinkAttributesParser.java with 95% similarity]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SrNodeAttributesParser.java [moved from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/sr/SrNodeAttributesParser.java with 91% similarity]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SrPrefixAttributesParser.java [moved from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/sr/SrPrefixAttributesParser.java with 94% similarity]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/BackupUnnumberedParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/EroMetricParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv4BackupEro.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv4EroParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv4PrefixSidParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv6BackupEro.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv6EroParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv6PrefixSidParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/SIDParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/UnnumberedEroParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/AbstractPrefixNlriParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/Ipv4PrefixNlriParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/Ipv6PrefixNlriParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/LinkNlriParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/LinkstateNlriParser.java [moved from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/LinkstateNlriParser.java with 68% similarity]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/NodeNlriParser.java [moved from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/NodeNlriParser.java with 58% similarity]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/TeLspIpv4NlriParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/TeLspIpv6NlriParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AbstractLocalNodeDescriptorTlvCodec.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AbstractNodeDescriptorTlvCodec.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AdvertisingNodeDescriptorTlvParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AreaIdTlvParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AsNumTlvParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/BgpRouterIdTlvParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/DomainIdTlvParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/Ipv4InterfaceTlvParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/Ipv4NeighborTlvParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/Ipv6InterfaceTlvParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/Ipv6NeighborTlvParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/LinkIdTlvParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/LocalNodeDescriptorTlvParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/MemAsNumTlvParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/MultiTopoIdTlvParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/NodeDescriptorTlvParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/OspfRouteTlvParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/ReachTlvParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/RemoteNodeDescriptorTlvParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/RouterIdTlvParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/LinkNlriParser.java [deleted file]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/NlriTypeCaseParser.java [deleted file]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/PrefixIpv4NlriParser.java [deleted file]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/PrefixIpv6NlriParser.java [deleted file]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/PrefixNlriSerializer.java [deleted file]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/SimpleNlriTypeRegistry.java [deleted file]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/TeLspIpv4NlriParser.java [deleted file]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/TeLspIpv6NlriParser.java [deleted file]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/AbstractNlriTypeCodec.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/AbstractTeLspNlriCodec.java [moved from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/TeLspNlriSerializer.java with 60% similarity]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/BindingSubTlvsParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/BindingSubTlvsSerializer.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/LinkstateTlvParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/NlriTypeCaseParser.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/NlriTypeCaseSerializer.java [moved from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/NlriTypeCaseSerializer.java with 60% similarity]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/TlvUtil.java
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/pojo/SimpleBindingSubTlvsRegistry.java [new file with mode: 0644]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/pojo/SimpleNlriTypeRegistry.java [new file with mode: 0644]
bgp/linkstate/src/main/resources/META-INF/services/org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderActivator
bgp/linkstate/src/main/resources/META-INF/services/org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderActivator
bgp/linkstate/src/main/resources/org/opendaylight/blueprint/bgp-linkstate.xml
bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/ActivatorTest.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/LinkstateRIBSupportTest.java
bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/ParserTest.java
bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/SrAttributeParserTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ParserToSalTest.java

index 30b2dcd023f90392c0f4dbf24a358633d893c64c..08661160dffc95e43c5797e0a649eb506442b873 100644 (file)
@@ -16,8 +16,8 @@
  */
 package org.opendaylight.controller.config.yang.bgp.linkstate;
 
-import org.opendaylight.protocol.bgp.linkstate.BGPActivator;
-import org.opendaylight.protocol.bgp.linkstate.RIBActivator;
+import org.opendaylight.protocol.bgp.linkstate.impl.BGPActivator;
+import org.opendaylight.protocol.bgp.linkstate.impl.RIBActivator;
 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderActivator;
 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
 import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderActivator;
index c89eb20cc79ddd4c3f822efaa7d1d3e7cb1be266..e89a536566b218461125fcfb1e1a4d40077af2a8 100644 (file)
@@ -19,6 +19,6 @@ package org.opendaylight.controller.config.yang.bgp.linkstate;
 /**
 *
 */
-public class LinkstateModuleFactory extends org.opendaylight.controller.config.yang.bgp.linkstate.AbstractLinkstateModuleFactory {
+public final class LinkstateModuleFactory extends org.opendaylight.controller.config.yang.bgp.linkstate.AbstractLinkstateModuleFactory {
 
 }
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/BGPActivator.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/BGPActivator.java
deleted file mode 100644 (file)
index 13c6840..0000000
+++ /dev/null
@@ -1,114 +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 java.util.ArrayList;
-import java.util.List;
-import org.opendaylight.protocol.bgp.linkstate.attribute.LinkstateAttributeParser;
-import org.opendaylight.protocol.bgp.linkstate.nlri.LinkNlriParser;
-import org.opendaylight.protocol.bgp.linkstate.nlri.LinkstateNlriParser;
-import org.opendaylight.protocol.bgp.linkstate.nlri.NodeNlriParser;
-import org.opendaylight.protocol.bgp.linkstate.nlri.PrefixIpv4NlriParser;
-import org.opendaylight.protocol.bgp.linkstate.nlri.PrefixIpv6NlriParser;
-import org.opendaylight.protocol.bgp.linkstate.nlri.PrefixNlriSerializer;
-import org.opendaylight.protocol.bgp.linkstate.nlri.SimpleNlriTypeRegistry;
-import org.opendaylight.protocol.bgp.linkstate.nlri.TeLspIpv4NlriParser;
-import org.opendaylight.protocol.bgp.linkstate.nlri.TeLspIpv6NlriParser;
-import org.opendaylight.protocol.bgp.linkstate.nlri.TeLspNlriSerializer;
-import org.opendaylight.protocol.bgp.parser.spi.AbstractBGPExtensionProviderActivator;
-import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
-import org.opendaylight.protocol.bgp.parser.spi.NextHopParserSerializer;
-import org.opendaylight.protocol.rsvp.parser.spi.RSVPTeObjectRegistry;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Attributes1;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateAddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateSubsequentAddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NlriType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.LinkCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.NodeCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.PrefixCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.TeLspCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.LinkstateRoutes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.MplsLabeledVpnSubsequentAddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv6NextHopCase;
-
-/**
- * Activator for registering linkstate extensions to BGP parser.
- */
-public final class BGPActivator extends AbstractBGPExtensionProviderActivator {
-
-    private static final int LINKSTATE_AFI = 16388;
-
-    private static final int LINKSTATE_SAFI = 71;
-
-    private final boolean ianaLinkstateAttributeType;
-
-    private final RSVPTeObjectRegistry rsvpTeObjectRegistry;
-
-    public BGPActivator() {
-        super();
-        this.ianaLinkstateAttributeType = true;
-        rsvpTeObjectRegistry = null;
-    }
-
-    public BGPActivator(final boolean ianaLinkstateAttributeType, final RSVPTeObjectRegistry rsvpTeObjectRegistry) {
-        super();
-        this.rsvpTeObjectRegistry = rsvpTeObjectRegistry;
-        this.ianaLinkstateAttributeType = ianaLinkstateAttributeType;
-    }
-
-    @Override
-    protected List<AutoCloseable> startImpl(final BGPExtensionProviderContext context) {
-        final List<AutoCloseable> regs = new ArrayList<>();
-
-        final SimpleNlriTypeRegistry nlriTypeReg = SimpleNlriTypeRegistry.getInstance();
-
-        regs.add(context.registerAddressFamily(LinkstateAddressFamily.class, LINKSTATE_AFI));
-        regs.add(context.registerSubsequentAddressFamily(LinkstateSubsequentAddressFamily.class, LINKSTATE_SAFI));
-
-        final NextHopParserSerializer linkstateNextHopParser = new NextHopParserSerializer(){};
-        regs.add(context.registerNlriParser(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class,
-            new LinkstateNlriParser(false), linkstateNextHopParser, Ipv4NextHopCase.class, Ipv6NextHopCase.class));
-
-        regs.add(context.registerNlriParser(LinkstateAddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class,
-            new LinkstateNlriParser(true), linkstateNextHopParser, Ipv4NextHopCase.class, Ipv6NextHopCase.class));
-        regs.add(context.registerNlriSerializer(LinkstateRoutes.class, new LinkstateNlriParser(false)));
-
-        regs.add(context.registerAttributeSerializer(Attributes1.class, new LinkstateAttributeParser(this.ianaLinkstateAttributeType, this.rsvpTeObjectRegistry)));
-        final LinkstateAttributeParser linkstateAttributeParser = new LinkstateAttributeParser(this.ianaLinkstateAttributeType, this.rsvpTeObjectRegistry);
-        regs.add(context.registerAttributeParser(linkstateAttributeParser.getType(), linkstateAttributeParser));
-
-        final NodeNlriParser nodeParser = new NodeNlriParser();
-        regs.add(nlriTypeReg.registerNlriTypeParser(NlriType.Node, nodeParser));
-        regs.add(nlriTypeReg.registerNlriTypeSerializer(NodeCase.class, nodeParser));
-
-        final LinkNlriParser linkParser = new LinkNlriParser();
-        regs.add(nlriTypeReg.registerNlriTypeParser(NlriType.Link, linkParser));
-        regs.add( nlriTypeReg.registerNlriTypeSerializer(LinkCase.class, linkParser));
-
-        final PrefixIpv4NlriParser ipv4PrefParser = new PrefixIpv4NlriParser();
-        regs.add(nlriTypeReg.registerNlriTypeParser(NlriType.Ipv4Prefix, ipv4PrefParser));
-
-        final PrefixIpv6NlriParser ipv6PrefParser = new PrefixIpv6NlriParser();
-        regs.add(nlriTypeReg.registerNlriTypeParser(NlriType.Ipv6Prefix, ipv6PrefParser));
-
-        final PrefixNlriSerializer prefixSerializer = new PrefixNlriSerializer();
-        regs.add(nlriTypeReg.registerNlriTypeSerializer(PrefixCase.class, prefixSerializer));
-
-        final TeLspIpv4NlriParser telSPipv4Parser = new TeLspIpv4NlriParser();
-        regs.add(nlriTypeReg.registerNlriTypeParser(NlriType.Ipv4TeLsp, telSPipv4Parser));
-
-        final TeLspIpv6NlriParser telSPipv6Parser = new TeLspIpv6NlriParser();
-        regs.add(nlriTypeReg.registerNlriTypeParser(NlriType.Ipv6TeLsp, telSPipv6Parser));
-
-        final TeLspNlriSerializer telSpSerializer = new TeLspNlriSerializer();
-        regs.add(nlriTypeReg.registerNlriTypeSerializer(TeLspCase.class, telSpSerializer));
-
-        return regs;
-    }
-}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/sr/BindingSidLabelParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/sr/BindingSidLabelParser.java
deleted file mode 100644 (file)
index 40de244..0000000
+++ /dev/null
@@ -1,328 +0,0 @@
-/*
- * Copyright (c) 2015 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.sr;
-
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
-import java.util.ArrayList;
-import java.util.List;
-import org.opendaylight.protocol.bgp.linkstate.attribute.PrefixAttributesParser;
-import org.opendaylight.protocol.bgp.linkstate.attribute.sr.SidLabelIndexParser.Size;
-import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
-import org.opendaylight.protocol.util.BitArray;
-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.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.ProtocolId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.prefix.state.Ipv6SrPrefix;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.prefix.state.SrBindingSidLabels;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.prefix.state.SrBindingSidLabelsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.prefix.state.SrPrefix;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.Weight;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sid.tlv.BindingSubTlvs;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sid.tlv.BindingSubTlvsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sid.tlv.Flags;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sid.tlv.flags.IsisBindingFlagsCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sid.tlv.flags.IsisBindingFlagsCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sid.tlv.flags.OspfBindingFlagsCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sid.tlv.flags.OspfBindingFlagsCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.BindingSubTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.EroMetricCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.EroMetricCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv4EroBackupCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv4EroBackupCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv4EroCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv4EroCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv6EroBackupCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv6EroBackupCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv6EroCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv6EroCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv6PrefixSidCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv6PrefixSidCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.PrefixSidCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.PrefixSidCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.SidLabelCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.SidLabelCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.UnnumberedInterfaceIdBackupEroCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.UnnumberedInterfaceIdBackupEroCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.UnnumberedInterfaceIdEroCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.UnnumberedInterfaceIdEroCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.sid.label.index.SidLabelIndex;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.TeMetric;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public final class BindingSidLabelParser {
-
-    private static final Logger LOG = LoggerFactory.getLogger(BindingSidLabelParser.class);
-
-    private BindingSidLabelParser() {
-        throw new UnsupportedOperationException();
-    }
-
-    /* Flags */
-    private static final int FLAGS_SIZE = 8;
-    private static final int AFI = 0;
-    private static final int MIRROR_CONTEXT = 1;
-    private static final int MIRROR_CONTEXT_OSPF = 0;
-    private static final int SPREAD_TLV = 2;
-    private static final int LEAKED = 3;
-    private static final int ATTACHED = 4;
-    private static final int LOOSE = 0;
-
-    /* SID Label Tlv types */
-    private static final int ERO_METRIC = 1162;
-    private static final int ERO_IPV4 = 1163;
-    private static final int ERO_IPV6 = 1164;
-    private static final int UNNUMBERED_ERO = 1165;
-    private static final int BACKUP_ERO_IPV4 = 1166;
-    private static final int BACKUP_ERO_IPV6 = 1167;
-    private static final int BACKUP_UNNUMBERED_ERO = 1168;
-
-    private static final int RESERVED_BINDING_SID = 2;
-    private static final int RESERVED_ERO = 3;
-
-    public static SrBindingSidLabels parseBindingSidLabel(final ByteBuf buffer, final ProtocolId protocolId) {
-        final SrBindingSidLabelsBuilder bindingSid = new SrBindingSidLabelsBuilder();
-        bindingSid.setWeight(new Weight(buffer.readUnsignedByte()));
-        final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
-        bindingSid.setFlags(parseBindingSidFlags(flags, protocolId));
-        buffer.skipBytes(RESERVED_BINDING_SID);
-        bindingSid.setBindingSubTlvs(parseBindingSubTlvs(buffer, protocolId));
-        return bindingSid.build();
-    }
-
-    private static Flags parseBindingSidFlags(final BitArray flags, final ProtocolId protocol) {
-        switch (protocol) {
-        case IsisLevel1:
-        case IsisLevel2:
-            return new IsisBindingFlagsCaseBuilder().setAddressFamily(flags.get(AFI)).setMirrorContext(flags.get(MIRROR_CONTEXT))
-                .setSpreadTlv(flags.get(SPREAD_TLV)).setLeakedFromLevel2(flags.get(LEAKED)).setAttachedFlag(flags.get(ATTACHED)).build();
-        case Ospf:
-        case OspfV3:
-            return new OspfBindingFlagsCaseBuilder().setMirroring(flags.get(MIRROR_CONTEXT_OSPF)).build();
-        default:
-            return null;
-        }
-    }
-
-    private static List<BindingSubTlvs> parseBindingSubTlvs(final ByteBuf buffer, final ProtocolId protocolId) {
-        final List<BindingSubTlvs> subTlvs = new ArrayList<BindingSubTlvs>();
-        while (buffer.isReadable()) {
-            final int type = buffer.readUnsignedShort();
-            final int length = buffer.readUnsignedShort();
-            final ByteBuf slice = buffer.readSlice(length);
-            final BindingSubTlvsBuilder builder = new BindingSubTlvsBuilder();
-            parseSubTlv(type, slice, builder, protocolId);
-            subTlvs.add(builder.build());
-        }
-        return subTlvs;
-    }
-
-    private static void parseSubTlv(final int type, final ByteBuf slice, final BindingSubTlvsBuilder builder, final ProtocolId protocolId) {
-        switch (type) {
-        case SidLabelIndexParser.SID_TYPE:
-            final SidLabelIndex sid = SidLabelIndexParser.parseSidLabelIndex(Size.forValue(slice.readableBytes()), slice);
-            builder.setBindingSubTlv(new SidLabelCaseBuilder()
-                .setSidLabelIndex(sid).build());
-            break;
-        case PrefixAttributesParser.PREFIX_SID:
-            final SrPrefix prefix = SrPrefixAttributesParser.parseSrPrefix(slice, protocolId);
-            builder.setBindingSubTlv(new PrefixSidCaseBuilder()
-                .setAlgorithm(prefix.getAlgorithm())
-                .setFlags(prefix.getFlags())
-                .setSidLabelIndex(prefix.getSidLabelIndex()).build());
-            break;
-        case PrefixAttributesParser.IPV6_PREFIX_SID:
-            final Ipv6SrPrefix ipv6Prefix = Ipv6SrPrefixAttributesParser.parseSrIpv6Prefix(slice);
-            builder.setBindingSubTlv(new Ipv6PrefixSidCaseBuilder().setAlgorithm(ipv6Prefix.getAlgorithm()).build());
-            break;
-        case ERO_METRIC:
-            builder.setBindingSubTlv(new EroMetricCaseBuilder()
-                .setEroMetric(new TeMetric(slice.readUnsignedInt())).build());
-            break;
-        case ERO_IPV4:
-            final Ipv4EroCase ipv4Ero = parseIpv4EroCase(slice);
-            builder.setBindingSubTlv(new Ipv4EroCaseBuilder()
-                .setAddress(ipv4Ero.getAddress())
-                .setLoose(ipv4Ero.isLoose()).build());
-            break;
-        case BACKUP_ERO_IPV4:
-            final Ipv4EroCase ipv4Backup = parseIpv4EroCase(slice);
-            builder.setBindingSubTlv(new Ipv4EroBackupCaseBuilder()
-                .setAddress(ipv4Backup.getAddress())
-                .setLoose(ipv4Backup.isLoose()).build());
-            break;
-        case ERO_IPV6:
-            final Ipv6EroCase ipv6ero = parseIpv6EroCase(slice);
-            builder.setBindingSubTlv(new Ipv6EroCaseBuilder()
-                .setAddress(ipv6ero.getAddress())
-                .setLoose(ipv6ero.isLoose()).build());
-            break;
-        case BACKUP_ERO_IPV6:
-            final Ipv6EroCase ipv6backup = parseIpv6EroCase(slice);
-            builder.setBindingSubTlv(new Ipv6EroBackupCaseBuilder()
-                .setAddress(ipv6backup.getAddress())
-                .setLoose(ipv6backup.isLoose()).build());
-            break;
-        case UNNUMBERED_ERO:
-            final UnnumberedInterfaceIdEroCase unnumbered = parseUnnumberedEroCase(slice);
-            builder.setBindingSubTlv(new UnnumberedInterfaceIdEroCaseBuilder()
-                .setLoose(unnumbered.isLoose())
-                .setRouterId(unnumbered.getRouterId())
-                .setInterfaceId(unnumbered.getInterfaceId()).build());
-            break;
-        case BACKUP_UNNUMBERED_ERO:
-            final UnnumberedInterfaceIdEroCase unnumberedBackup = parseUnnumberedEroCase(slice);
-            builder.setBindingSubTlv(new UnnumberedInterfaceIdBackupEroCaseBuilder()
-                .setLoose(unnumberedBackup.isLoose())
-                .setRouterId(unnumberedBackup.getRouterId())
-                .setInterfaceId(unnumberedBackup.getInterfaceId()).build());
-            break;
-        default:
-            LOG.info("Unknown binding sub Tlv type {}", type);
-            break;
-        }
-    }
-
-    private static Ipv4EroCase parseIpv4EroCase(final ByteBuf buffer) {
-        final Ipv4EroCaseBuilder builder = new Ipv4EroCaseBuilder();
-        final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
-        builder.setLoose(flags.get(LOOSE));
-        buffer.skipBytes(RESERVED_ERO);
-        builder.setAddress(Ipv4Util.addressForByteBuf(buffer));
-        return builder.build();
-    }
-
-    private static Ipv6EroCase parseIpv6EroCase(final ByteBuf buffer) {
-        final Ipv6EroCaseBuilder builder = new Ipv6EroCaseBuilder();
-        final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
-        builder.setLoose(flags.get(LOOSE));
-        buffer.skipBytes(RESERVED_ERO);
-        builder.setAddress(Ipv6Util.addressForByteBuf(buffer));
-        return builder.build();
-    }
-
-    private static UnnumberedInterfaceIdEroCase parseUnnumberedEroCase(final ByteBuf buffer) {
-        final UnnumberedInterfaceIdEroCaseBuilder builder = new UnnumberedInterfaceIdEroCaseBuilder();
-        final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
-        builder.setLoose(flags.get(LOOSE));
-        buffer.skipBytes(RESERVED_ERO);
-        builder.setRouterId(buffer.readUnsignedInt());
-        builder.setInterfaceId(buffer.readUnsignedInt());
-        return builder.build();
-    }
-
-    public static void serializeBindingSidLabels(final List<SrBindingSidLabels> bindingSids, final ByteBuf aggregator, final int sidType) {
-        for (final SrBindingSidLabels bindingSid : bindingSids) {
-            final ByteBuf sidBuffer = Unpooled.buffer();
-            serializeBindingSidAttributes(bindingSid.getWeight(), bindingSid.getFlags(), bindingSid.getBindingSubTlvs(), sidBuffer);
-            TlvUtil.writeTLV(sidType, sidBuffer, aggregator);
-        }
-    }
-
-    static void serializeBindingSidAttributes(final Weight weight, final Flags flags, final List<BindingSubTlvs> bindingSubTlvs, final ByteBuf aggregator) {
-        aggregator.writeByte(weight.getValue());
-        final BitArray bitFlags = serializeBindingSidFlags(flags);
-        bitFlags.toByteBuf(aggregator);
-        aggregator.writeZero(RESERVED_BINDING_SID);
-        serializeBindingSubTlvs(bindingSubTlvs, aggregator);
-    }
-
-    private static BitArray serializeBindingSidFlags(final Flags flags) {
-        final BitArray bitFlags = new BitArray(FLAGS_SIZE);
-        if (flags instanceof IsisBindingFlagsCase) {
-            final IsisBindingFlagsCase isisFlags = (IsisBindingFlagsCase) flags;
-            bitFlags.set(AFI, isisFlags.isAddressFamily());
-            bitFlags.set(MIRROR_CONTEXT, isisFlags.isMirrorContext());
-            bitFlags.set(SPREAD_TLV, isisFlags.isSpreadTlv());
-            bitFlags.set(LEAKED, isisFlags.isLeakedFromLevel2());
-            bitFlags.set(ATTACHED, isisFlags.isAttachedFlag());
-        } else if (flags instanceof OspfBindingFlagsCase) {
-            final OspfBindingFlagsCase ospfFlags = (OspfBindingFlagsCase) flags;
-            bitFlags.set(MIRROR_CONTEXT_OSPF, ospfFlags.isMirroring());
-        }
-        return bitFlags;
-    }
-
-    private static void serializeBindingSubTlvs(final List<BindingSubTlvs> bindingSubTlvs, final ByteBuf aggregator) {
-        for (final BindingSubTlvs subTlv : bindingSubTlvs) {
-            ByteBuf buffer = Unpooled.buffer();
-            final BindingSubTlv bindingSubTlv = subTlv.getBindingSubTlv();
-            if (bindingSubTlv instanceof SidLabelCase) {
-                buffer = SidLabelIndexParser.serializeSidValue(((SidLabelCase) bindingSubTlv).getSidLabelIndex());
-                TlvUtil.writeTLV(SidLabelIndexParser.SID_TYPE, buffer, aggregator);
-            } else if (bindingSubTlv instanceof PrefixSidCase) {
-                final PrefixSidCase prefix = (PrefixSidCase) bindingSubTlv;
-                SrPrefixAttributesParser.serializePrefixAttributes(prefix.getFlags(), prefix.getAlgorithm(), prefix.getSidLabelIndex(), buffer);
-                TlvUtil.writeTLV(PrefixAttributesParser.PREFIX_SID, buffer, aggregator);
-            } else if (bindingSubTlv instanceof Ipv6PrefixSidCase) {
-                final Ipv6PrefixSidCase prefix = (Ipv6PrefixSidCase) bindingSubTlv;
-                Ipv6SrPrefixAttributesParser.serializePrefixAttributes(prefix.getAlgorithm(), buffer);
-                TlvUtil.writeTLV(PrefixAttributesParser.IPV6_PREFIX_SID, buffer, aggregator);
-            } else if (bindingSubTlv instanceof EroMetricCase) {
-                buffer.writeInt(((EroMetricCase) bindingSubTlv).getEroMetric().getValue().intValue());
-                TlvUtil.writeTLV(ERO_METRIC, buffer, aggregator);
-            } else if (bindingSubTlv instanceof Ipv4EroBackupCase) {
-                final Ipv4EroBackupCase ipv4Backup = (Ipv4EroBackupCase) bindingSubTlv;
-                buffer = serializeIpv4EroCase(ipv4Backup.isLoose(), ipv4Backup.getAddress());
-                TlvUtil.writeTLV(BACKUP_ERO_IPV4, buffer, aggregator);
-            } else if (bindingSubTlv instanceof Ipv4EroCase) {
-                final Ipv4EroCase ipv4Ero = (Ipv4EroCase) bindingSubTlv;
-                buffer = serializeIpv4EroCase(ipv4Ero.isLoose(), ipv4Ero.getAddress());
-                TlvUtil.writeTLV(ERO_IPV4, buffer, aggregator);
-            } else if (bindingSubTlv instanceof Ipv6EroBackupCase) {
-                final Ipv6EroBackupCase ipv6Backup = (Ipv6EroBackupCase) bindingSubTlv;
-                buffer = serializeIpv6EroCase(ipv6Backup.isLoose(), ipv6Backup.getAddress());
-                TlvUtil.writeTLV(BACKUP_ERO_IPV6, buffer, aggregator);
-            } else if (bindingSubTlv instanceof Ipv6EroCase) {
-                final Ipv6EroCase ipv6Ero = (Ipv6EroCase) bindingSubTlv;
-                buffer = serializeIpv6EroCase(ipv6Ero.isLoose(), ipv6Ero.getAddress());
-                TlvUtil.writeTLV(ERO_IPV6, buffer, aggregator);
-            } else if (bindingSubTlv instanceof UnnumberedInterfaceIdEroCase) {
-                final UnnumberedInterfaceIdEroCase unnumberedEro = (UnnumberedInterfaceIdEroCase) bindingSubTlv;
-                buffer = serializeUnnumberedIdEro(unnumberedEro.isLoose(), unnumberedEro.getRouterId(), unnumberedEro.getInterfaceId());
-                TlvUtil.writeTLV(UNNUMBERED_ERO, buffer, aggregator);
-            } else if (bindingSubTlv instanceof UnnumberedInterfaceIdBackupEroCase) {
-                final UnnumberedInterfaceIdBackupEroCase unnumberedBackup = (UnnumberedInterfaceIdBackupEroCase) bindingSubTlv;
-                buffer = serializeUnnumberedIdEro(unnumberedBackup.isLoose(), unnumberedBackup.getRouterId(), unnumberedBackup.getInterfaceId());
-                TlvUtil.writeTLV(BACKUP_UNNUMBERED_ERO, buffer, aggregator);
-            }
-        }
-    }
-
-    private static ByteBuf serializeIpv4EroCase(final Boolean loose, final Ipv4Address address) {
-        final ByteBuf buffer = Unpooled.buffer();
-        serializeEroFlags(buffer, loose);
-        buffer.writeBytes(Ipv4Util.byteBufForAddress(address));
-        return buffer;
-    }
-
-    private static ByteBuf serializeIpv6EroCase(final Boolean loose, final Ipv6Address address) {
-        final ByteBuf buffer = Unpooled.buffer();
-        serializeEroFlags(buffer, loose);
-        buffer.writeBytes(Ipv6Util.byteBufForAddress(address));
-        return buffer;
-    }
-
-    private static ByteBuf serializeUnnumberedIdEro(final Boolean loose, final Long routerId, final Long interfaceId) {
-        final ByteBuf buffer = Unpooled.buffer();
-        serializeEroFlags(buffer, loose);
-        buffer.writeInt(routerId.intValue());
-        buffer.writeInt(interfaceId.intValue());
-        return buffer;
-    }
-
-    private static void serializeEroFlags(final ByteBuf buffer, final Boolean loose) {
-        final BitArray flags = new BitArray(FLAGS_SIZE);
-        flags.set(LOOSE, loose);
-        flags.toByteBuf(buffer);
-        buffer.writeZero(RESERVED_ERO);
-    }
-}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/BGPActivator.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/BGPActivator.java
new file mode 100644 (file)
index 0000000..12ec731
--- /dev/null
@@ -0,0 +1,266 @@
+/*
+ * Copyright (c) 2016 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.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.LinkstateAttributeParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs.BackupUnnumberedParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs.EroMetricParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs.Ipv4BackupEro;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs.Ipv4EroParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs.Ipv4PrefixSidParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs.Ipv6BackupEro;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs.Ipv6EroParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs.Ipv6PrefixSidParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs.SIDParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs.UnnumberedEroParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.nlri.Ipv4PrefixNlriParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.nlri.Ipv6PrefixNlriParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.nlri.LinkNlriParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.nlri.LinkstateNlriParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.nlri.NodeNlriParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.nlri.TeLspIpv4NlriParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.nlri.TeLspIpv6NlriParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.AdvertisingNodeDescriptorTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.AreaIdTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.AsNumTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.BgpRouterIdTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.DomainIdTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.Ipv4InterfaceTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.Ipv4NeighborTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.Ipv6InterfaceTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.Ipv6NeighborTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.LinkIdTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.LocalNodeDescriptorTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.MemAsNumTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.MultiTopoIdTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.NodeDescriptorTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.OspfRouteTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.ReachTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.RemoteNodeDescriptorTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.RouterIdTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.spi.pojo.SimpleBindingSubTlvsRegistry;
+import org.opendaylight.protocol.bgp.linkstate.spi.pojo.SimpleNlriTypeRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.AbstractBGPExtensionProviderActivator;
+import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
+import org.opendaylight.protocol.bgp.parser.spi.NextHopParserSerializer;
+import org.opendaylight.protocol.rsvp.parser.spi.RSVPTeObjectRegistry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Attributes1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.LinkCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.NodeCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.PrefixCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.TeLspCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.LinkstateRoutes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.EroMetricCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv4EroBackupCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv4EroCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv6EroBackupCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv6EroCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv6PrefixSidCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.PrefixSidCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.SidLabelCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.UnnumberedInterfaceIdBackupEroCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.UnnumberedInterfaceIdEroCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv6NextHopCase;
+
+/**
+ * Activator for registering linkstate extensions to BGP parser.
+ */
+public final class BGPActivator extends AbstractBGPExtensionProviderActivator {
+
+    private static final int LINKSTATE_AFI = 16388;
+
+    private static final int LINKSTATE_SAFI = 71;
+
+    private final boolean ianaLinkstateAttributeType;
+
+    private final RSVPTeObjectRegistry rsvpTeObjectRegistry;
+
+    public BGPActivator() {
+        super();
+        this.ianaLinkstateAttributeType = true;
+        rsvpTeObjectRegistry = null;
+    }
+
+    public BGPActivator(final boolean ianaLinkstateAttributeType, final RSVPTeObjectRegistry rsvpTeObjectRegistry) {
+        super();
+        this.rsvpTeObjectRegistry = rsvpTeObjectRegistry;
+        this.ianaLinkstateAttributeType = ianaLinkstateAttributeType;
+    }
+
+    @Override
+    protected List<AutoCloseable> startImpl(final BGPExtensionProviderContext context) {
+        final List<AutoCloseable> regs = new ArrayList<>();
+
+        final SimpleNlriTypeRegistry nlriTypeReg = SimpleNlriTypeRegistry.getInstance();
+
+        regs.add(context.registerAddressFamily(LinkstateAddressFamily.class, LINKSTATE_AFI));
+        regs.add(context.registerSubsequentAddressFamily(LinkstateSubsequentAddressFamily.class, LINKSTATE_SAFI));
+
+        final NextHopParserSerializer linkstateNextHopParser = new NextHopParserSerializer() {
+        };
+        final LinkstateNlriParser parser = new LinkstateNlriParser();
+        regs.add(context.registerNlriParser(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class,
+            parser, linkstateNextHopParser, Ipv4NextHopCase.class, Ipv6NextHopCase.class));
+        regs.add(context.registerNlriSerializer(LinkstateRoutes.class, parser));
+
+        regs.add(context.registerAttributeSerializer(Attributes1.class, new LinkstateAttributeParser(this.ianaLinkstateAttributeType, this.rsvpTeObjectRegistry)));
+        final LinkstateAttributeParser linkstateAttributeParser = new LinkstateAttributeParser(this.ianaLinkstateAttributeType, this.rsvpTeObjectRegistry);
+        regs.add(context.registerAttributeParser(linkstateAttributeParser.getType(), linkstateAttributeParser));
+
+        registerNlriCodecs(regs, nlriTypeReg);
+        registerNlriTlvCodecs(regs, nlriTypeReg);
+        registerBindingSubTlvs(regs);
+        return regs;
+    }
+
+    private void registerBindingSubTlvs(final List<AutoCloseable> regs) {
+        final SimpleBindingSubTlvsRegistry simpleReg = SimpleBindingSubTlvsRegistry.getInstance();
+
+        final SIDParser sidParser = new SIDParser();
+        regs.add(simpleReg.registerBindingSubTlvsParser(sidParser.getType(), sidParser));
+        regs.add(simpleReg.registerBindingSubTlvsSerializer(SidLabelCase.class, sidParser));
+
+        final Ipv4PrefixSidParser prefixSidParser = new Ipv4PrefixSidParser();
+        regs.add(simpleReg.registerBindingSubTlvsParser(prefixSidParser.getType(), prefixSidParser));
+        regs.add(simpleReg.registerBindingSubTlvsSerializer(PrefixSidCase.class, prefixSidParser));
+
+        final Ipv6PrefixSidParser ipv6PrefixSidParser = new Ipv6PrefixSidParser();
+        regs.add(simpleReg.registerBindingSubTlvsParser(ipv6PrefixSidParser.getType(), ipv6PrefixSidParser));
+        regs.add(simpleReg.registerBindingSubTlvsSerializer(Ipv6PrefixSidCase.class, ipv6PrefixSidParser));
+
+        final EroMetricParser eroMetricParser = new EroMetricParser();
+        regs.add(simpleReg.registerBindingSubTlvsParser(eroMetricParser.getType(), eroMetricParser));
+        regs.add(simpleReg.registerBindingSubTlvsSerializer(EroMetricCase.class, eroMetricParser));
+
+        final Ipv4EroParser ipv4EroParser = new Ipv4EroParser();
+        regs.add(simpleReg.registerBindingSubTlvsParser(ipv4EroParser.getType(), ipv4EroParser));
+        regs.add(simpleReg.registerBindingSubTlvsSerializer(Ipv4EroCase.class, ipv4EroParser));
+
+        final Ipv4BackupEro ipv4BackupEro = new Ipv4BackupEro();
+        regs.add(simpleReg.registerBindingSubTlvsParser(ipv4BackupEro.getType(), ipv4BackupEro));
+        regs.add(simpleReg.registerBindingSubTlvsSerializer(Ipv4EroBackupCase.class, ipv4BackupEro));
+
+        final Ipv6EroParser ipv6EroParser = new Ipv6EroParser();
+        regs.add(simpleReg.registerBindingSubTlvsParser(ipv6EroParser.getType(), ipv6EroParser));
+        regs.add(simpleReg.registerBindingSubTlvsSerializer(Ipv6EroCase.class, ipv6EroParser));
+
+        final Ipv6BackupEro ipv6BackupEro = new Ipv6BackupEro();
+        regs.add(simpleReg.registerBindingSubTlvsParser(ipv6BackupEro.getType(), ipv6BackupEro));
+        regs.add(simpleReg.registerBindingSubTlvsSerializer(Ipv6EroBackupCase.class, ipv6BackupEro));
+
+        final UnnumberedEroParser unnumberedEroParser = new UnnumberedEroParser();
+        regs.add(simpleReg.registerBindingSubTlvsParser(unnumberedEroParser.getType(), unnumberedEroParser));
+        regs.add(simpleReg.registerBindingSubTlvsSerializer(UnnumberedInterfaceIdEroCase.class, unnumberedEroParser));
+
+        final BackupUnnumberedParser backupUnnumberedParser = new BackupUnnumberedParser();
+        regs.add(simpleReg.registerBindingSubTlvsParser(backupUnnumberedParser.getType(), backupUnnumberedParser));
+        regs.add(simpleReg.registerBindingSubTlvsSerializer(UnnumberedInterfaceIdBackupEroCase.class, backupUnnumberedParser));
+    }
+
+    private void registerNlriCodecs(final List<AutoCloseable> regs, final SimpleNlriTypeRegistry nlriTypeReg) {
+
+        final NodeNlriParser nodeParser = new NodeNlriParser();
+        regs.add(nlriTypeReg.registerNlriParser(nodeParser.getNlriType(), nodeParser));
+        regs.add(nlriTypeReg.registerNlriSerializer(NodeCase.class, nodeParser));
+
+        final LinkNlriParser linkParser = new LinkNlriParser();
+        regs.add(nlriTypeReg.registerNlriParser(linkParser.getNlriType(), linkParser));
+        regs.add(nlriTypeReg.registerNlriSerializer(LinkCase.class, linkParser));
+
+        final Ipv4PrefixNlriParser ipv4PrefixParser = new Ipv4PrefixNlriParser();
+        regs.add(nlriTypeReg.registerNlriParser(ipv4PrefixParser.getNlriType(), ipv4PrefixParser));
+        regs.add(nlriTypeReg.registerNlriSerializer(PrefixCase.class, ipv4PrefixParser));
+        final Ipv6PrefixNlriParser ipv6PrefixParser = new Ipv6PrefixNlriParser();
+        regs.add(nlriTypeReg.registerNlriParser(ipv6PrefixParser.getNlriType(), ipv6PrefixParser));
+
+        final TeLspIpv4NlriParser teLspIpv4Parser = new TeLspIpv4NlriParser();
+        regs.add(nlriTypeReg.registerNlriParser(teLspIpv4Parser.getNlriType(), teLspIpv4Parser));
+        regs.add(nlriTypeReg.registerNlriSerializer(TeLspCase.class, teLspIpv4Parser));
+        final TeLspIpv6NlriParser teLspIpv6Parser = new TeLspIpv6NlriParser();
+        regs.add(nlriTypeReg.registerNlriParser(teLspIpv6Parser.getNlriType(), teLspIpv6Parser));
+
+    }
+
+    private void registerNlriTlvCodecs(final List<AutoCloseable> regs, final SimpleNlriTypeRegistry nlriTypeReg) {
+
+        final LocalNodeDescriptorTlvParser localParser = new LocalNodeDescriptorTlvParser();
+        regs.add(nlriTypeReg.registerTlvParser(localParser.getType(), localParser));
+        regs.add(nlriTypeReg.registerTlvSerializer(localParser.getTlvQName(), localParser));
+
+        final NodeDescriptorTlvParser nodeParser = new NodeDescriptorTlvParser();
+        regs.add(nlriTypeReg.registerTlvSerializer(nodeParser.getTlvQName(), nodeParser));
+
+        final AdvertisingNodeDescriptorTlvParser advParser = new AdvertisingNodeDescriptorTlvParser();
+        regs.add(nlriTypeReg.registerTlvSerializer(advParser.getTlvQName(), advParser));
+
+        final RemoteNodeDescriptorTlvParser remoteParser = new RemoteNodeDescriptorTlvParser();
+        regs.add(nlriTypeReg.registerTlvParser(remoteParser.getType(), remoteParser));
+        regs.add(nlriTypeReg.registerTlvSerializer(remoteParser.getTlvQName(), remoteParser));
+
+        final RouterIdTlvParser bgpCrouterIdParser = new RouterIdTlvParser();
+        regs.add(nlriTypeReg.registerTlvParser(bgpCrouterIdParser.getType(), bgpCrouterIdParser));
+        regs.add(nlriTypeReg.registerTlvSerializer(bgpCrouterIdParser.getTlvQName(), bgpCrouterIdParser));
+
+        final AsNumTlvParser asNumParser = new AsNumTlvParser();
+        regs.add(nlriTypeReg.registerTlvParser(asNumParser.getType(), asNumParser));
+        regs.add(nlriTypeReg.registerTlvSerializer(asNumParser.getTlvQName(), asNumParser));
+
+        final DomainIdTlvParser bgpDomainIdParser = new DomainIdTlvParser();
+        regs.add(nlriTypeReg.registerTlvParser(bgpDomainIdParser.getType(), bgpDomainIdParser));
+        regs.add(nlriTypeReg.registerTlvSerializer(bgpDomainIdParser.getTlvQName(), bgpDomainIdParser));
+
+        final AreaIdTlvParser areaIdParser = new AreaIdTlvParser();
+        regs.add(nlriTypeReg.registerTlvParser(areaIdParser.getType(), areaIdParser));
+        regs.add(nlriTypeReg.registerTlvSerializer(areaIdParser.getTlvQName(), areaIdParser));
+
+        final BgpRouterIdTlvParser bgpRouterIdParser = new BgpRouterIdTlvParser();
+        regs.add(nlriTypeReg.registerTlvParser(bgpRouterIdParser.getType(), bgpRouterIdParser));
+        regs.add(nlriTypeReg.registerTlvSerializer(bgpRouterIdParser.getTlvQName(), bgpRouterIdParser));
+
+        final MemAsNumTlvParser memAsnParser = new MemAsNumTlvParser();
+        regs.add(nlriTypeReg.registerTlvParser(memAsnParser.getType(), memAsnParser));
+        regs.add(nlriTypeReg.registerTlvSerializer(memAsnParser.getTlvQName(), memAsnParser));
+
+        final LinkIdTlvParser linkIdParser = new LinkIdTlvParser();
+        regs.add(nlriTypeReg.registerTlvParser(linkIdParser.getType(), linkIdParser));
+        regs.add(nlriTypeReg.registerTlvSerializer(linkIdParser.getTlvQName(), linkIdParser));
+
+        final Ipv4NeighborTlvParser ipv4nNeighborParser = new Ipv4NeighborTlvParser();
+        regs.add(nlriTypeReg.registerTlvParser(ipv4nNeighborParser.getType(), ipv4nNeighborParser));
+        regs.add(nlriTypeReg.registerTlvSerializer(ipv4nNeighborParser.getTlvQName(), ipv4nNeighborParser));
+
+        final Ipv6NeighborTlvParser ipv6NeighborParser = new Ipv6NeighborTlvParser();
+        regs.add(nlriTypeReg.registerTlvParser(ipv6NeighborParser.getType(), ipv6NeighborParser));
+        regs.add(nlriTypeReg.registerTlvSerializer(ipv6NeighborParser.getTlvQName(), ipv6NeighborParser));
+
+        final Ipv4InterfaceTlvParser ipv4InterfaceParser = new Ipv4InterfaceTlvParser();
+        regs.add(nlriTypeReg.registerTlvParser(ipv4InterfaceParser.getType(), ipv4InterfaceParser));
+        regs.add(nlriTypeReg.registerTlvSerializer(ipv4InterfaceParser.getTlvQName(), ipv4InterfaceParser));
+
+        final Ipv6InterfaceTlvParser ipv6InterfaceParser = new Ipv6InterfaceTlvParser();
+        regs.add(nlriTypeReg.registerTlvParser(ipv6InterfaceParser.getType(), ipv6InterfaceParser));
+        regs.add(nlriTypeReg.registerTlvSerializer(ipv6InterfaceParser.getTlvQName(), ipv6InterfaceParser));
+
+        final MultiTopoIdTlvParser multiTopoIdParser = new MultiTopoIdTlvParser();
+        regs.add(nlriTypeReg.registerTlvParser(multiTopoIdParser.getType(), multiTopoIdParser));
+        regs.add(nlriTypeReg.registerTlvSerializer(multiTopoIdParser.getTlvQName(), multiTopoIdParser));
+
+        final ReachTlvParser ipv4ReachParser = new ReachTlvParser();
+        regs.add(nlriTypeReg.registerTlvParser(ipv4ReachParser.getType(), ipv4ReachParser));
+        regs.add(nlriTypeReg.registerTlvSerializer(ipv4ReachParser.getTlvQName(), ipv4ReachParser));
+
+        final OspfRouteTlvParser ospfRouterParser = new OspfRouteTlvParser();
+        regs.add(nlriTypeReg.registerTlvParser(ospfRouterParser.getType(), ospfRouterParser));
+        regs.add(nlriTypeReg.registerTlvSerializer(ospfRouterParser.getTlvQName(), ospfRouterParser));
+    }
+}
similarity index 81%
rename from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/LinkstateRIBSupport.java
rename to bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/LinkstateRIBSupport.java
index 634ed91f4e05508c240d26995ed5360e890aa4b6..f06663ef1952e175789653b70759acb8d20d1cbc 100644 (file)
@@ -1,11 +1,11 @@
 /*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2016 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;
+package org.opendaylight.protocol.bgp.linkstate.impl;
 
 import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableCollection;
@@ -17,7 +17,8 @@ import java.util.List;
 import java.util.stream.Collectors;
 import javax.annotation.Nonnull;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
-import org.opendaylight.protocol.bgp.linkstate.nlri.LinkstateNlriParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.nlri.LinkstateNlriParser;
+import org.opendaylight.protocol.bgp.linkstate.spi.pojo.SimpleNlriTypeRegistry;
 import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupport;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateAddressFamily;
@@ -44,7 +45,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-final class LinkstateRIBSupport extends AbstractRIBSupport {
+public final class LinkstateRIBSupport extends AbstractRIBSupport {
     private static final Logger LOG = LoggerFactory.getLogger(LinkstateRIBSupport.class);
     private static final QName ROUTE_KEY = QName.create(LinkstateRoute.QNAME, "route-key").intern();
     private static final LinkstateRIBSupport SINGLETON = new LinkstateRIBSupport();
@@ -56,7 +57,7 @@ final class LinkstateRIBSupport extends AbstractRIBSupport {
             DestinationLinkstate.QNAME);
     }
 
-    static LinkstateRIBSupport getInstance() {
+    public static LinkstateRIBSupport getInstance() {
         return SINGLETON;
     }
 
@@ -80,17 +81,22 @@ final class LinkstateRIBSupport extends AbstractRIBSupport {
         final ContainerNode destination, final ContainerNode attributes, final ApplyRoute function) {
         if (destination != null) {
             final Optional<DataContainerChild<? extends PathArgument, ?>> maybeRoutes = destination.getChild(this.nlriRoutesList);
-            if (maybeRoutes.isPresent()) {
-                final DataContainerChild<? extends PathArgument, ?> routes = maybeRoutes.get();
-                if (routes instanceof UnkeyedListNode) {
-                    final YangInstanceIdentifier base = routesPath.node(routesContainerIdentifier()).node(this.route);
-                    for (final UnkeyedListEntryNode e : ((UnkeyedListNode) routes).getValue()) {
-                        final NodeIdentifierWithPredicates routeKey = createRouteKey(e);
-                        function.apply(tx, base, routeKey, e, attributes);
-                    }
-                } else {
-                    LOG.warn("Routes {} are not a map", routes);
+            processRoute(maybeRoutes, routesPath, attributes, function, tx);
+        }
+    }
+
+    private void processRoute(final Optional<DataContainerChild<? extends PathArgument, ?>> maybeRoutes, final YangInstanceIdentifier routesPath,
+        final ContainerNode attributes, final ApplyRoute function, final DOMDataWriteTransaction tx) {
+        if (maybeRoutes.isPresent()) {
+            final DataContainerChild<? extends PathArgument, ?> routes = maybeRoutes.get();
+            if (routes instanceof UnkeyedListNode) {
+                final YangInstanceIdentifier base = routesPath.node(routesContainerIdentifier()).node(this.route);
+                for (final UnkeyedListEntryNode e : ((UnkeyedListNode) routes).getValue()) {
+                    final NodeIdentifierWithPredicates routeKey = createRouteKey(e);
+                    function.apply(tx, base, routeKey, e, attributes);
                 }
+            } else {
+                LOG.warn("Routes {} are not a map", routes);
             }
         }
     }
@@ -98,7 +104,7 @@ final class LinkstateRIBSupport extends AbstractRIBSupport {
     private NodeIdentifierWithPredicates createRouteKey(final UnkeyedListEntryNode linkstate) {
         final ByteBuf buffer = Unpooled.buffer();
         final CLinkstateDestination cLinkstateDestination = LinkstateNlriParser.extractLinkstateDestination(linkstate);
-        LinkstateNlriParser.serializeNlri(cLinkstateDestination, buffer);
+        SimpleNlriTypeRegistry.getInstance().serializeNlriType(cLinkstateDestination, buffer);
 
         return new NodeIdentifierWithPredicates(LinkstateRoute.QNAME, ROUTE_KEY, ByteArray.readAllBytes(buffer));
     }
similarity index 90%
rename from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/RIBActivator.java
rename to bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/RIBActivator.java
index 008986e10539005f679b02eb36f73dad84a496ec..7367675d74357a59fdd729a856882a734082f21f 100644 (file)
@@ -1,11 +1,11 @@
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2016 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;
+package org.opendaylight.protocol.bgp.linkstate.impl;
 
 import com.google.common.collect.Lists;
 import java.util.List;
similarity index 77%
rename from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/LinkAttributesParser.java
rename to bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/LinkAttributesParser.java
index 7c2bdd394cebe894e0f8b87c58b0397f71ca0564..8aadc64d593c852f578b74d4b283367e22767c17 100644 (file)
@@ -5,7 +5,7 @@
  * 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;
+package org.opendaylight.protocol.bgp.linkstate.impl.attribute;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Charsets;
@@ -16,19 +16,23 @@ import io.netty.buffer.Unpooled;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map.Entry;
-import org.opendaylight.protocol.bgp.linkstate.attribute.sr.SrLinkAttributesParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SrLinkAttributesParser;
 import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
 import org.opendaylight.protocol.util.BitArray;
 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.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.AdministrativeGroup;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Ipv4RouterIdentifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Ipv6RouterIdentifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkProtectionType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.MplsProtocolMask;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.ProtocolId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.link.state.PeerAdjSid;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.link.state.PeerAdjSidBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.link.state.PeerNodeSid;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.link.state.PeerNodeSidBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.link.state.PeerSetSids;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.link.state.PeerSetSidsBuilder;
@@ -51,12 +55,8 @@ import org.slf4j.LoggerFactory;
 @VisibleForTesting
 public final class LinkAttributesParser {
 
+    public static final int SR_LAN_ADJ_ID = 1100;
     private static final Logger LOG = LoggerFactory.getLogger(LinkAttributesParser.class);
-
-    private LinkAttributesParser() {
-        throw new UnsupportedOperationException();
-    }
-
     private static final int UNRESERVED_BW_COUNT = 8;
 
     private static final int BANDWIDTH_LENGTH = 4;
@@ -82,11 +82,19 @@ public final class LinkAttributesParser {
     private static final int LINK_OPAQUE = 1097;
     private static final int LINK_NAME = 1098;
     private static final int SR_ADJ_ID = 1099;
-    private static final int SR_LAN_ADJ_ID = 1100;
     private static final int PEER_NODE_SID_CODE = 1101;
     private static final int PEER_ADJ_SID_CODE = 1102;
     private static final int PEER_SET_SID_CODE = 1103;
 
+    private LinkAttributesParser() {
+        throw new UnsupportedOperationException();
+    }
+
+    @FunctionalInterface
+    private interface SerializerInterface {
+        void check(Object cont);
+    }
+
     /**
      * Parse Link Attributes.
      *
@@ -96,9 +104,9 @@ public final class LinkAttributesParser {
      */
     static LinkStateAttribute parseLinkAttributes(final Multimap<Integer, ByteBuf> attributes, final ProtocolId protocolId) {
         final LinkAttributesBuilder builder = new LinkAttributesBuilder();
-        final List<SrAdjIds> srAdjIds = new ArrayList<SrAdjIds>();
-        final List<SrLanAdjIds> srLanAdjIds = new ArrayList<SrLanAdjIds>();
-        final List<PeerSetSids> peerSetSids = new ArrayList<PeerSetSids>();
+        final List<SrAdjIds> srAdjIds = new ArrayList<>();
+        final List<SrLanAdjIds> srLanAdjIds = new ArrayList<>();
+        final List<PeerSetSids> peerSetSids = new ArrayList<>();
         for (final Entry<Integer, ByteBuf> entry : attributes.entries()) {
             LOG.trace("Link attribute TLV {}", entry.getKey());
             final int key = entry.getKey();
@@ -165,11 +173,11 @@ public final class LinkAttributesParser {
                 break;
             case SR_ADJ_ID:
                 srAdjIds.add(SrLinkAttributesParser.parseAdjacencySegmentIdentifier(value, protocolId));
-                LOG.debug("Parsed Adjacency Segment Identifier :{}", srAdjIds.get(srAdjIds.size()-1));
+                LOG.debug("Parsed Adjacency Segment Identifier :{}", srAdjIds.get(srAdjIds.size() - 1));
                 break;
             case SR_LAN_ADJ_ID:
                 srLanAdjIds.add(SrLinkAttributesParser.parseLanAdjacencySegmentIdentifier(value, protocolId));
-                LOG.debug("Parsed Adjacency Segment Identifier :{}", srLanAdjIds.get(srLanAdjIds.size()-1));
+                LOG.debug("Parsed Adjacency Segment Identifier :{}", srLanAdjIds.get(srLanAdjIds.size() - 1));
                 break;
             case PEER_NODE_SID_CODE:
                 builder.setPeerNodeSid(new PeerNodeSidBuilder(SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build());
@@ -181,7 +189,7 @@ public final class LinkAttributesParser {
                 break;
             case PEER_SET_SID_CODE:
                 peerSetSids.add(new PeerSetSidsBuilder(SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build());
-                LOG.debug("Parsed Peer Set Sid :{}", peerSetSids.get(peerSetSids.size()-1));
+                LOG.debug("Parsed Peer Set Sid :{}", peerSetSids.get(peerSetSids.size() - 1));
                 break;
             default:
                 LOG.warn("TLV {} is not a valid link attribute, ignoring it", key);
@@ -219,61 +227,35 @@ public final class LinkAttributesParser {
         LOG.debug("Parsed Shared Risk Link Groups {}", builder.getSharedRiskLinkGroups());
     }
 
-    static void serializeLinkAttributes(final LinkAttributesCase linkAttributesCase, final ByteBuf byteAggregator) {
+    private static void ifPresentApply(final Object tlv, final SerializerInterface serializer) {
+        if (tlv != null) {
+            serializer.check(tlv);
+        }
+    }
+
+
+    static void serializeLinkAttributes(final LinkAttributesCase linkAttributesCase, final ByteBuf output) {
         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);
-        }
-        serializeUnreservedBw(linkAttributes.getUnreservedBandwidth(), 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);
-        }
-        serializeSrlg(linkAttributes.getSharedRiskLinkGroups(), byteAggregator);
-        if (linkAttributes.getLinkName() != null) {
-            TlvUtil.writeTLV(LINK_NAME, Unpooled.wrappedBuffer(Charsets.UTF_8.encode(linkAttributes.getLinkName())), byteAggregator);
-        }
-        if (linkAttributes.getSrAdjIds() != null) {
-            SrLinkAttributesParser.serializeAdjacencySegmentIdentifiers(linkAttributes.getSrAdjIds(), SR_ADJ_ID, byteAggregator);
-        }
-        if (linkAttributes.getSrLanAdjIds() != null) {
-            SrLinkAttributesParser.serializeLanAdjacencySegmentIdentifiers(linkAttributes.getSrLanAdjIds(), SR_LAN_ADJ_ID, byteAggregator);
-        }
-        if (linkAttributes.getPeerNodeSid() != null) {
-            TlvUtil.writeTLV(PEER_NODE_SID_CODE, SrLinkAttributesParser.serializeAdjacencySegmentIdentifier(linkAttributes.getPeerNodeSid()), byteAggregator);
-        }
-        if (linkAttributes.getPeerAdjSid() != null) {
-            TlvUtil.writeTLV(PEER_ADJ_SID_CODE, SrLinkAttributesParser.serializeAdjacencySegmentIdentifier(linkAttributes.getPeerAdjSid()), byteAggregator);
-        }
-        if (linkAttributes.getPeerSetSids() != null) {
-            SrLinkAttributesParser.serializeAdjacencySegmentIdentifiers(linkAttributes.getPeerSetSids(), PEER_SET_SID_CODE, byteAggregator);
-        }
+        ifPresentApply(linkAttributes.getLocalIpv4RouterId(), value -> TlvUtil.writeTLV(TlvUtil.LOCAL_IPV4_ROUTER_ID, Ipv4Util.byteBufForAddress((Ipv4Address) value), output));
+        ifPresentApply(linkAttributes.getLocalIpv6RouterId(), value -> TlvUtil.writeTLV(TlvUtil.LOCAL_IPV6_ROUTER_ID, Ipv6Util.byteBufForAddress((Ipv6Address) value), output));
+        ifPresentApply(linkAttributes.getRemoteIpv4RouterId(), value -> TlvUtil.writeTLV(REMOTE_IPV4_ROUTER_ID, Ipv4Util.byteBufForAddress((Ipv4Address) value), output));
+        ifPresentApply(linkAttributes.getRemoteIpv6RouterId(), value -> TlvUtil.writeTLV(REMOTE_IPV6_ROUTER_ID, Ipv6Util.byteBufForAddress((Ipv6Address) value), output));
+        ifPresentApply(linkAttributes.getAdminGroup(), value -> TlvUtil.writeTLV(ADMIN_GROUP, Unpooled.copyInt((((AdministrativeGroup) value).getValue()).intValue()), output));
+        ifPresentApply(linkAttributes.getMaxLinkBandwidth(), value -> TlvUtil.writeTLV(MAX_BANDWIDTH, Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output));
+        ifPresentApply(linkAttributes.getMaxReservableBandwidth(), value -> TlvUtil.writeTLV(MAX_RESERVABLE_BANDWIDTH, Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output));
+        serializeUnreservedBw(linkAttributes.getUnreservedBandwidth(), output);
+        ifPresentApply(linkAttributes.getTeMetric(), value -> TlvUtil.writeTLV(TE_METRIC, Unpooled.copyLong(((TeMetric) value).getValue()), output));
+        ifPresentApply(linkAttributes.getLinkProtection(), value -> TlvUtil.writeTLV(LINK_PROTECTION_TYPE, Unpooled.copyShort(((LinkProtectionType) value).getIntValue()), output));
+        serializeMplsProtocolMask(linkAttributes.getMplsProtocol(), output);
+        ifPresentApply(linkAttributes.getMetric(), value -> TlvUtil.writeTLV(METRIC, Unpooled.copyMedium(((Metric) value).getValue().intValue()), output));
+        serializeSrlg(linkAttributes.getSharedRiskLinkGroups(), output);
+        ifPresentApply(linkAttributes.getLinkName(), value -> TlvUtil.writeTLV(LINK_NAME, Unpooled.wrappedBuffer(Charsets.UTF_8.encode((String) value)), output));
+        ifPresentApply(linkAttributes.getSrAdjIds(), value -> SrLinkAttributesParser.serializeAdjacencySegmentIdentifiers((List<SrAdjIds>) value, SR_ADJ_ID, output));
+        ifPresentApply(linkAttributes.getSrLanAdjIds(), value -> SrLinkAttributesParser.serializeLanAdjacencySegmentIdentifiers((List<SrLanAdjIds>) value, output));
+        ifPresentApply(linkAttributes.getPeerNodeSid(), value -> TlvUtil.writeTLV(PEER_NODE_SID_CODE, SrLinkAttributesParser.serializeAdjacencySegmentIdentifier((PeerNodeSid) value), output));
+        ifPresentApply(linkAttributes.getPeerAdjSid(), value -> TlvUtil.writeTLV(PEER_ADJ_SID_CODE, SrLinkAttributesParser.serializeAdjacencySegmentIdentifier((PeerAdjSid) value), output));
+        ifPresentApply(linkAttributes.getPeerSetSids(), value -> SrLinkAttributesParser.serializeAdjacencySegmentIdentifiers((List<PeerSetSids>) value, PEER_SET_SID_CODE, output));
         LOG.trace("Finished serializing Link Attributes");
     }
 
@@ -298,7 +280,7 @@ public final class LinkAttributesParser {
         }
     }
 
-    private static void serializeMplsProtocolMask(final MplsProtocolMask mplsProtocolMask, final ByteBuf byteAggregator ) {
+    private static void serializeMplsProtocolMask(final MplsProtocolMask mplsProtocolMask, final ByteBuf byteAggregator) {
         if (mplsProtocolMask != null) {
             final ByteBuf mplsProtocolMaskBuf = Unpooled.buffer(1);
             final BitArray mask = new BitArray(FLAGS_SIZE);
similarity index 94%
rename from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/LinkstateAttributeParser.java
rename to bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/LinkstateAttributeParser.java
index 65e8401f6aca89731d49b3e87e64242a0cd73653..d8ca16911e8b1d3a139b4517ed02017aded86d27 100644 (file)
@@ -5,7 +5,7 @@
  * 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;
+package org.opendaylight.protocol.bgp.linkstate.impl.attribute;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.HashMultimap;
@@ -45,7 +45,7 @@ import org.slf4j.LoggerFactory;
  *
  * @see <a href="http://tools.ietf.org/html/draft-gredler-idr-ls-distribution-04">BGP-LS draft</a>
  */
-public class LinkstateAttributeParser implements AttributeParser, AttributeSerializer {
+public final class LinkstateAttributeParser implements AttributeParser, AttributeSerializer {
 
     private static final Logger LOG = LoggerFactory.getLogger(LinkstateAttributeParser.class);
 
@@ -107,7 +107,8 @@ public class LinkstateAttributeParser implements AttributeParser, AttributeSeria
         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.rev150210.update.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.rev150210.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCase) dt).getDestinationLinkstate().getCLinkstateDestination()) {
+                for(final CLinkstateDestination d :((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.unreach.nlri.withdrawn.
+                    routes.destination.type.DestinationLinkstateCase) dt).getDestinationLinkstate().getCLinkstateDestination()) {
                     return d;
                 }
             }
@@ -134,7 +135,7 @@ public class LinkstateAttributeParser implements AttributeParser, AttributeSeria
     /**
      * Serialize linkstate attributes.
      *
-     * @param attribute      DataObject representing LinkstatePathAttribute
+     * @param attribute DataObject representing LinkstatePathAttribute
      * @param byteAggregator ByteBuf where all serialized data are aggregated
      */
 
similarity index 93%
rename from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/NodeAttributesParser.java
rename to bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/NodeAttributesParser.java
index 3a0469e4824ecd7531fb56621521aa1d6644369d..39979b9d906a708e6bc688cc96cc3db5a3e0b304 100644 (file)
@@ -5,7 +5,7 @@
  * 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;
+package org.opendaylight.protocol.bgp.linkstate.impl.attribute;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Charsets;
@@ -16,7 +16,7 @@ import io.netty.buffer.Unpooled;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map.Entry;
-import org.opendaylight.protocol.bgp.linkstate.attribute.sr.SrNodeAttributesParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SrNodeAttributesParser;
 import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
 import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.protocol.util.ByteArray;
@@ -42,13 +42,7 @@ import org.slf4j.LoggerFactory;
 public final class NodeAttributesParser {
 
     private static final Logger LOG = LoggerFactory.getLogger(NodeAttributesParser.class);
-
-    private NodeAttributesParser() {
-        throw new UnsupportedOperationException();
-    }
-
     private static final int FLAGS_SIZE = 8;
-
     // node flag bits
     private static final int OVERLOAD_BIT = 0;
     private static final int ATTACHED_BIT = 1;
@@ -56,16 +50,18 @@ public final class NodeAttributesParser {
     private static final int ABBR_BIT = 3;
     private static final int ROUTER_BIT = 4;
     private static final int V6_BIT = 5;
-
     /* 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;
-
     /* Segment routing TLVs */
     private static final int SR_CAPABILITIES = 1034;
     private static final int SR_ALGORITHMS = 1035;
+    
+    private NodeAttributesParser() {
+        throw new UnsupportedOperationException();
+    }
 
     /**
      * Parse Node Attributes.
@@ -87,11 +83,7 @@ public final class NodeAttributesParser {
                 parseTopologyId(topologyMembership, value);
                 break;
             case NODE_FLAG_BITS:
-                final BitArray flags = BitArray.valueOf(value, FLAGS_SIZE);
-                builder.setNodeFlags(new NodeFlagBits(flags.get(OVERLOAD_BIT), flags.get(ATTACHED_BIT), flags.get
-                    (EXTERNAL_BIT), flags.get(ABBR_BIT), flags.get(ROUTER_BIT), flags.get(V6_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));
+                parseNodeFlags(value, builder);
                 break;
             case NODE_OPAQUE:
                 if (LOG.isDebugEnabled()) {
@@ -137,6 +129,14 @@ public final class NodeAttributesParser {
         return new NodeAttributesCaseBuilder().setNodeAttributes(builder.build()).build();
     }
 
+    private static void parseNodeFlags(final ByteBuf value, final NodeAttributesBuilder builder) {
+        final BitArray flags = BitArray.valueOf(value, FLAGS_SIZE);
+        builder.setNodeFlags(new NodeFlagBits(flags.get(OVERLOAD_BIT), flags.get(ATTACHED_BIT), flags.get
+            (EXTERNAL_BIT), flags.get(ABBR_BIT), flags.get(ROUTER_BIT), flags.get(V6_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));
+    }
+
     private static void parseTopologyId(final List<TopologyIdentifier> topologyMembership, final ByteBuf value) {
         while (value.isReadable()) {
             final TopologyIdentifier topId = new TopologyIdentifier(value.readUnsignedShort() & TlvUtil.TOPOLOGY_ID_OFFSET);
similarity index 75%
rename from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/PrefixAttributesParser.java
rename to bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/PrefixAttributesParser.java
index bf63919bf60e28702fb45a45dd4d2e5b87341480..e70bbaa2ebee7567db9bd2e9d02a3e6951ee5104 100644 (file)
@@ -5,7 +5,10 @@
  * 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;
+package org.opendaylight.protocol.bgp.linkstate.impl.attribute;
+
+import static org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs.Ipv4PrefixSidParser.PREFIX_SID;
+import static org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs.Ipv6PrefixSidParser.IPV6_PREFIX_SID;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.Multimap;
@@ -15,10 +18,10 @@ import io.netty.buffer.Unpooled;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map.Entry;
-import org.opendaylight.protocol.bgp.linkstate.attribute.sr.BindingSidLabelParser;
-import org.opendaylight.protocol.bgp.linkstate.attribute.sr.Ipv6SrPrefixAttributesParser;
-import org.opendaylight.protocol.bgp.linkstate.attribute.sr.RangeTlvParser;
-import org.opendaylight.protocol.bgp.linkstate.attribute.sr.SrPrefixAttributesParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.BindingSidLabelParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.Ipv6SrPrefixAttributesParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.RangeTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SrPrefixAttributesParser;
 import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
 import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.protocol.util.ByteArray;
@@ -47,21 +50,16 @@ import org.slf4j.LoggerFactory;
 @VisibleForTesting
 public final class PrefixAttributesParser {
 
+    /* Segment routing TLV */
+    public static final int BINDING_SID = 1160;
     private static final Logger LOG = LoggerFactory.getLogger(PrefixAttributesParser.class);
-
-    private PrefixAttributesParser() {
-        throw new UnsupportedOperationException();
-    }
-
     private static final int ROUTE_TAG_LENGTH = 4;
     private static final int EXTENDED_ROUTE_TAG_LENGTH = 8;
-
     private static final int FLAGS_SIZE = 8;
     private static final int UP_DOWN_BIT = 0;
     private static final int OSPF_NO_UNICAST = 1;
     private static final int OSPF_LOCAL_ADDRESS = 2;
     private static final int OSPF_PROPAGATE_ADDRESS = 3;
-
     /* Prefix Attribute TLVs */
     private static final int IGP_FLAGS = 1152;
     private static final int ROUTE_TAG = 1153;
@@ -69,12 +67,11 @@ public final class PrefixAttributesParser {
     private static final int PREFIX_METRIC = 1155;
     private static final int FORWARDING_ADDRESS = 1156;
     private static final int PREFIX_OPAQUE = 1157;
+    private static final int RANGE = 1159;
 
-    /* Segment routing TLV */
-    public static final int PREFIX_SID = 1158;
-    public static final int IPV6_PREFIX_SID = 1169;
-    public static final int RANGE = 1159;
-    public static final int BINDING_SID = 1160;
+    private PrefixAttributesParser() {
+        throw new UnsupportedOperationException();
+    }
 
     /**
      * Parse prefix attributes.
@@ -102,18 +99,7 @@ public final class PrefixAttributesParser {
     private static void parseAttribute(final int key, final ByteBuf value, final ProtocolId protocolId, final PrefixAttributesBuilder builder, final List<RouteTag> routeTags, final List<ExtendedRouteTag> exRouteTags) {
         switch (key) {
         case IGP_FLAGS:
-            final BitArray flags = BitArray.valueOf(value, FLAGS_SIZE);
-            final boolean upDownBit = flags.get(UP_DOWN_BIT);
-            final boolean ospfNoUnicast = flags.get(OSPF_NO_UNICAST);
-            final boolean ospfLocalAddress = flags.get(OSPF_LOCAL_ADDRESS);
-            final boolean ospfPropagateAddress = flags.get(OSPF_PROPAGATE_ADDRESS);
-            builder.setIgpBits(new IgpBitsBuilder().setUpDown(new UpDown(upDownBit))
-                .setIsIsUpDown(upDownBit)
-                .setOspfNoUnicast(ospfNoUnicast)
-                .setOspfLocalAddress(ospfLocalAddress)
-                .setOspfPropagateNssa(ospfPropagateAddress)
-                .build());
-            LOG.debug("Parsed IGP flag (up/down bit) : {}", upDownBit);
+            parseIgpFags(builder, value);
             break;
         case ROUTE_TAG:
             parseRouteTags(routeTags, value);
@@ -152,21 +138,34 @@ public final class PrefixAttributesParser {
             LOG.debug("Parsed SR Range: {}", range);
             break;
         case BINDING_SID:
-            final SrBindingSidLabels label = BindingSidLabelParser.parseBindingSidLabel(value, protocolId);
-            if (builder.getSrBindingSidLabels() != null) {
-                builder.getSrBindingSidLabels().add(label);
-            } else {
-                final List<SrBindingSidLabels> labels = new ArrayList<SrBindingSidLabels>();
-                labels.add(label);
-                builder.setSrBindingSidLabels(labels);
-            }
-            LOG.debug("Parsed SR Binding SID {}", label);
+            parseBindingSid(builder, value, protocolId);
             break;
         default:
             LOG.warn("TLV {} is not a valid prefix attribute, ignoring it", key);
         }
     }
 
+    private static void parseIgpFags(final PrefixAttributesBuilder builder, final ByteBuf value) {
+        final BitArray flags = BitArray.valueOf(value, FLAGS_SIZE);
+        final boolean upDownBit = flags.get(UP_DOWN_BIT);
+        builder.setIgpBits(new IgpBitsBuilder().setUpDown(new UpDown(upDownBit)).setIsIsUpDown(upDownBit).setOspfNoUnicast(flags.get(OSPF_NO_UNICAST))
+            .setOspfLocalAddress(flags.get(OSPF_LOCAL_ADDRESS)).setOspfPropagateNssa(flags.get(OSPF_PROPAGATE_ADDRESS)).build());
+        LOG.debug("Parsed IGP flag (up/down bit) : {}", upDownBit);
+    }
+
+    private static void parseBindingSid(final PrefixAttributesBuilder builder, final ByteBuf value, final ProtocolId protocolId) {
+        final List<SrBindingSidLabels> labels;
+        if (builder.getSrBindingSidLabels() != null) {
+            labels = builder.getSrBindingSidLabels();
+        } else {
+            labels = new ArrayList<>();
+            builder.setSrBindingSidLabels(labels);
+        }
+        final SrBindingSidLabels label = BindingSidLabelParser.parseBindingSidLabel(value, protocolId);
+        labels.add(label);
+        LOG.debug("Parsed SR Binding SID {}", label);
+    }
+
     private static void parseRouteTags(final List<RouteTag> routeTags, final ByteBuf value) {
         while (value.isReadable()) {
             final RouteTag routeTag = new RouteTag(ByteArray.readBytes(value, ROUTE_TAG_LENGTH));
@@ -211,27 +210,51 @@ public final class PrefixAttributesParser {
         }
         serializeRouteTags(prefixAtrributes.getRouteTags(), byteAggregator);
         serializeExtendedRouteTags(prefixAtrributes.getExtendedTags(), byteAggregator);
-        if (prefixAtrributes.getPrefixMetric() != null) {
-            TlvUtil.writeTLV(PREFIX_METRIC, Unpooled.copyInt(prefixAtrributes.getPrefixMetric().getValue().intValue()), byteAggregator);
-        }
+        serializePrefixMetric(prefixAtrributes.getPrefixMetric(), byteAggregator);
         serializeForwardingAddress(prefixAtrributes.getOspfForwardingAddress(), byteAggregator);
-        if (prefixAtrributes.getSrPrefix() != null) {
-            final ByteBuf buffer = Unpooled.buffer();
-            SrPrefixAttributesParser.serializeSrPrefix(prefixAtrributes.getSrPrefix(), buffer);
-            TlvUtil.writeTLV(PREFIX_SID, buffer, byteAggregator);
+        serializeSrPrefix(prefixAtrributes.getSrPrefix(), byteAggregator);
+        serializeIpv6SrPrefix(prefixAtrributes.getIpv6SrPrefix(), byteAggregator);
+        serializeSrRange(prefixAtrributes.getSrRange(), byteAggregator);
+        serializeSrBindingLabel(prefixAtrributes.getSrBindingSidLabels(), byteAggregator);
+    }
+
+    private static void serializeSrBindingLabel(final List<SrBindingSidLabels> srBindingSidLabels, final ByteBuf byteAggregator) {
+        if (srBindingSidLabels != null) {
+            for (final SrBindingSidLabels bindingSid : srBindingSidLabels) {
+                final ByteBuf sidBuffer = Unpooled.buffer();
+                BindingSidLabelParser.serializeBindingSidAttributes(bindingSid.getWeight(), bindingSid.getFlags(), bindingSid.getBindingSubTlvs(), sidBuffer);
+                TlvUtil.writeTLV(PrefixAttributesParser.BINDING_SID, sidBuffer, byteAggregator);
+            }
+        }
+    }
+
+    private static void serializeSrRange(final SrRange srRange, final ByteBuf byteAggregator) {
+        if (srRange != null) {
+            final ByteBuf sidBuffer = Unpooled.buffer();
+            RangeTlvParser.serializeSrRange(srRange, sidBuffer);
+            TlvUtil.writeTLV(RANGE, sidBuffer, byteAggregator);
         }
-        if (prefixAtrributes.getIpv6SrPrefix() != null) {
+    }
+
+    private static void serializeIpv6SrPrefix(final Ipv6SrPrefix ipv6SrPrefix, final ByteBuf byteAggregator) {
+        if (ipv6SrPrefix != null) {
             final ByteBuf buffer = Unpooled.buffer();
-            Ipv6SrPrefixAttributesParser.serializeIpv6SrPrefix(prefixAtrributes.getIpv6SrPrefix(), buffer);
+            Ipv6SrPrefixAttributesParser.serializeIpv6SrPrefix(ipv6SrPrefix, buffer);
             TlvUtil.writeTLV(IPV6_PREFIX_SID, buffer, byteAggregator);
         }
-        if (prefixAtrributes.getSrRange() != null) {
-            final ByteBuf sidBuffer = Unpooled.buffer();
-            RangeTlvParser.serializeSrRange(prefixAtrributes.getSrRange(), sidBuffer);
-            TlvUtil.writeTLV(RANGE, sidBuffer, byteAggregator);
+    }
+
+    private static void serializeSrPrefix(final SrPrefix srPrefix, final ByteBuf byteAggregator) {
+        if (srPrefix != null) {
+            final ByteBuf buffer = Unpooled.buffer();
+            SrPrefixAttributesParser.serializeSrPrefix(srPrefix, buffer);
+            TlvUtil.writeTLV(PREFIX_SID, buffer, byteAggregator);
         }
-        if (prefixAtrributes.getSrBindingSidLabels() != null) {
-            BindingSidLabelParser.serializeBindingSidLabels(prefixAtrributes.getSrBindingSidLabels(), byteAggregator, BINDING_SID);
+    }
+
+    private static void serializePrefixMetric(final IgpMetric prefixMetric, final ByteBuf byteAggregator) {
+        if (prefixMetric != null) {
+            TlvUtil.writeTLV(PREFIX_METRIC, Unpooled.copyInt(prefixMetric.getValue().intValue()), byteAggregator);
         }
     }
 
similarity index 97%
rename from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/TeLspAttributesParser.java
rename to bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/TeLspAttributesParser.java
index 4a07446f0cb853133ea814bd6103295802c1ff03..1fce348175098e9b4c1fd7f4f3433e7b7be22a7e 100644 (file)
@@ -6,7 +6,7 @@
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 
-package org.opendaylight.protocol.bgp.linkstate.attribute;
+package org.opendaylight.protocol.bgp.linkstate.impl.attribute;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -53,14 +53,14 @@ import org.slf4j.LoggerFactory;
 final class TeLspAttributesParser {
 
     private static final Logger LOG = LoggerFactory.getLogger(TeLspAttributesParser.class);
-    // TODO: TBD BY IANA
+    //TBD BY IANA
     private static final int MAGIC_NUMBER = 99;
 
     private TeLspAttributesParser() {
         throw new UnsupportedOperationException();
     }
 
-    public static LinkStateAttribute parseTeLspAttributes(final RSVPTeObjectRegistry registry, final ByteBuf attributes) throws BGPParsingException {
+    static LinkStateAttribute parseTeLspAttributes(final RSVPTeObjectRegistry registry, final ByteBuf attributes) throws BGPParsingException {
 
         final TeLspAttributesBuilder builder = new TeLspAttributesBuilder();
         LOG.trace("Initiated parsing TE LSP Objects.");
@@ -123,7 +123,7 @@ final class TeLspAttributesParser {
     }
 
 
-    public static void serializeLspAttributes(final RSVPTeObjectRegistry registry, final TeLspAttributesCase linkState, final ByteBuf output) {
+    static void serializeLspAttributes(final RSVPTeObjectRegistry registry, final TeLspAttributesCase linkState, final ByteBuf output) {
         LOG.trace("Started serializing TE LSP Objects");
         final ByteBuf byteBuf = Unpooled.buffer();
 
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/BindingSidLabelParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/BindingSidLabelParser.java
new file mode 100644 (file)
index 0000000..3d9dbab
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2015 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.impl.attribute.sr;
+
+import io.netty.buffer.ByteBuf;
+import java.util.List;
+import org.opendaylight.protocol.bgp.linkstate.spi.pojo.SimpleBindingSubTlvsRegistry;
+import org.opendaylight.protocol.util.BitArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.ProtocolId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.prefix.state.SrBindingSidLabels;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.prefix.state.SrBindingSidLabelsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.Weight;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sid.tlv.BindingSubTlvs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sid.tlv.Flags;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sid.tlv.flags.IsisBindingFlagsCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sid.tlv.flags.IsisBindingFlagsCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sid.tlv.flags.OspfBindingFlagsCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sid.tlv.flags.OspfBindingFlagsCaseBuilder;
+
+public final class BindingSidLabelParser {
+    /* Flags */
+    private static final int FLAGS_SIZE = 8;
+    private static final int AFI = 0;
+    private static final int MIRROR_CONTEXT = 1;
+    private static final int MIRROR_CONTEXT_OSPF = 0;
+    private static final int SPREAD_TLV = 2;
+    private static final int LEAKED = 3;
+    private static final int ATTACHED = 4;
+
+    /* SID Label Tlv types */
+    private static final int RESERVED_BINDING_SID = 2;
+
+    private BindingSidLabelParser() {
+        throw new UnsupportedOperationException();
+    }
+
+    public static SrBindingSidLabels parseBindingSidLabel(final ByteBuf buffer, final ProtocolId protocolId) {
+        final SrBindingSidLabelsBuilder bindingSid = new SrBindingSidLabelsBuilder();
+        bindingSid.setWeight(new Weight(buffer.readUnsignedByte()));
+        final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
+        bindingSid.setFlags(parseBindingSidFlags(flags, protocolId));
+        buffer.skipBytes(RESERVED_BINDING_SID);
+        bindingSid.setBindingSubTlvs(SimpleBindingSubTlvsRegistry.getInstance().parseBindingSubTlvs(buffer, protocolId));
+        return bindingSid.build();
+    }
+
+    private static Flags parseBindingSidFlags(final BitArray flags, final ProtocolId protocol) {
+        switch (protocol) {
+        case IsisLevel1:
+        case IsisLevel2:
+            return new IsisBindingFlagsCaseBuilder().setAddressFamily(flags.get(AFI)).setMirrorContext(flags.get(MIRROR_CONTEXT))
+                .setSpreadTlv(flags.get(SPREAD_TLV)).setLeakedFromLevel2(flags.get(LEAKED)).setAttachedFlag(flags.get(ATTACHED)).build();
+        case Ospf:
+        case OspfV3:
+            return new OspfBindingFlagsCaseBuilder().setMirroring(flags.get(MIRROR_CONTEXT_OSPF)).build();
+        default:
+            return null;
+        }
+    }
+
+    public static void serializeBindingSidAttributes(final Weight weight, final Flags flags, final List<BindingSubTlvs> bindingSubTlvs, final ByteBuf aggregator) {
+        aggregator.writeByte(weight.getValue());
+        final BitArray bitFlags = serializeBindingSidFlags(flags);
+        bitFlags.toByteBuf(aggregator);
+        aggregator.writeZero(RESERVED_BINDING_SID);
+        SimpleBindingSubTlvsRegistry.getInstance().serializeBindingSubTlvs(bindingSubTlvs, aggregator);
+    }
+
+    private static BitArray serializeBindingSidFlags(final Flags flags) {
+        final BitArray bitFlags = new BitArray(FLAGS_SIZE);
+        if (flags instanceof IsisBindingFlagsCase) {
+            final IsisBindingFlagsCase isisFlags = (IsisBindingFlagsCase) flags;
+            bitFlags.set(AFI, isisFlags.isAddressFamily());
+            bitFlags.set(MIRROR_CONTEXT, isisFlags.isMirrorContext());
+            bitFlags.set(SPREAD_TLV, isisFlags.isSpreadTlv());
+            bitFlags.set(LEAKED, isisFlags.isLeakedFromLevel2());
+            bitFlags.set(ATTACHED, isisFlags.isAttachedFlag());
+        } else if (flags instanceof OspfBindingFlagsCase) {
+            final OspfBindingFlagsCase ospfFlags = (OspfBindingFlagsCase) flags;
+            bitFlags.set(MIRROR_CONTEXT_OSPF, ospfFlags.isMirroring());
+        }
+        return bitFlags;
+    }
+}
similarity index 86%
rename from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/sr/RangeTlvParser.java
rename to bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/RangeTlvParser.java
index c5d9e16e72bca097cc9281d596ed937cb73fe891..3b6c7728de292245346b81e54daf92511701bb25 100644 (file)
@@ -5,14 +5,18 @@
  * 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.sr;
+package org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr;
+
+import static org.opendaylight.protocol.bgp.linkstate.impl.attribute.PrefixAttributesParser.BINDING_SID;
+import static org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs.Ipv4PrefixSidParser.PREFIX_SID;
+import static org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs.Ipv6PrefixSidParser.IPV6_PREFIX_SID;
+import static org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs.SIDParser.SID_TYPE;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import java.util.ArrayList;
 import java.util.List;
-import org.opendaylight.protocol.bgp.linkstate.attribute.PrefixAttributesParser;
-import org.opendaylight.protocol.bgp.linkstate.attribute.sr.SidLabelIndexParser.Size;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SidLabelIndexParser.Size;
 import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
 import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.ProtocolId;
@@ -33,19 +37,16 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public final class RangeTlvParser {
-
     private static final Logger LOG = LoggerFactory.getLogger(RangeTlvParser.class);
-
-    private RangeTlvParser() {
-        throw new UnsupportedOperationException();
-    }
-
     /* Flags */
     private static final int FLAGS_SIZE = 8;
     private static final int INNER_AREA = 0;
-
     private static final int RESERVED = 1;
 
+    private RangeTlvParser() {
+        throw new UnsupportedOperationException();
+    }
+
     public static SrRange parseSrRange(final ByteBuf buffer, final ProtocolId protocolId) {
         final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
         final SrRangeBuilder range = new SrRangeBuilder();
@@ -64,20 +65,20 @@ public final class RangeTlvParser {
         final List<SubTlvs> subTlvs = new ArrayList<>();
         while (buffer.isReadable()) {
             final SubTlvsBuilder subTlv = new SubTlvsBuilder();
-            RangeSubTlv subTlvCase = null;
+            final RangeSubTlv subTlvCase;
             final int type = buffer.readUnsignedShort();
             final int length = buffer.readUnsignedShort();
             switch (type) {
-            case PrefixAttributesParser.PREFIX_SID:
+            case PREFIX_SID:
                 subTlvCase = new PrefixSidTlvCaseBuilder(SrPrefixAttributesParser.parseSrPrefix(buffer.readSlice(length), protocolId)).build();
                 break;
-            case PrefixAttributesParser.IPV6_PREFIX_SID:
+            case IPV6_PREFIX_SID:
                 subTlvCase = new Ipv6PrefixSidTlvCaseBuilder(Ipv6SrPrefixAttributesParser.parseSrIpv6Prefix(buffer.readSlice(length))).build();
                 break;
-            case PrefixAttributesParser.BINDING_SID:
+            case BINDING_SID:
                 subTlvCase = new BindingSidTlvCaseBuilder(BindingSidLabelParser.parseBindingSidLabel(buffer.readSlice(length), protocolId)).build();
                 break;
-            case SidLabelIndexParser.SID_TYPE:
+            case SID_TYPE:
                 subTlvCase = new SidLabelTlvCaseBuilder().setSidLabelIndex(SidLabelIndexParser.parseSidLabelIndex(Size.forValue(length), buffer.readSlice(length))).build();
                 break;
             default:
@@ -110,11 +111,11 @@ public final class RangeTlvParser {
                     prefixSidTlv.getAlgorithm(),
                     prefixSidTlv.getSidLabelIndex(),
                     buffer);
-                TlvUtil.writeTLV(PrefixAttributesParser.PREFIX_SID, buffer, aggregator);
+                TlvUtil.writeTLV(PREFIX_SID, buffer, aggregator);
             } else if (rangeSubTlv instanceof Ipv6PrefixSidTlvCase) {
                 final Ipv6PrefixSidTlvCase prefixSidTlv = (Ipv6PrefixSidTlvCase) rangeSubTlv;
                 Ipv6SrPrefixAttributesParser.serializePrefixAttributes(prefixSidTlv.getAlgorithm(), buffer);
-                TlvUtil.writeTLV(PrefixAttributesParser.IPV6_PREFIX_SID, buffer, aggregator);
+                TlvUtil.writeTLV(IPV6_PREFIX_SID, buffer, aggregator);
             } else if (rangeSubTlv instanceof BindingSidTlvCase) {
                 final BindingSidTlvCase rangeTlv = (BindingSidTlvCase) rangeSubTlv;
                 BindingSidLabelParser.serializeBindingSidAttributes(
@@ -122,10 +123,10 @@ public final class RangeTlvParser {
                     rangeTlv.getFlags(),
                     rangeTlv.getBindingSubTlvs(),
                     buffer);
-                TlvUtil.writeTLV(PrefixAttributesParser.BINDING_SID, buffer, aggregator);
+                TlvUtil.writeTLV(BINDING_SID, buffer, aggregator);
             } else if (rangeSubTlv instanceof SidLabelTlvCase) {
                 buffer = SidLabelIndexParser.serializeSidValue(((SidLabelTlvCase) rangeSubTlv).getSidLabelIndex());
-                TlvUtil.writeTLV(SidLabelIndexParser.SID_TYPE, buffer, aggregator);
+                TlvUtil.writeTLV(SID_TYPE, buffer, aggregator);
             }
         }
     }
similarity index 87%
rename from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/sr/SidLabelIndexParser.java
rename to bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SidLabelIndexParser.java
index 2d223ba9772f51b75ba9ade01c1e639214acb7e6..64f41d31bd85c1097eae9449a87004d2fe135687 100644 (file)
@@ -5,7 +5,9 @@
  * 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.sr;
+package org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr;
+
+import static org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs.SIDParser.SID_TYPE;
 
 import com.google.common.collect.ImmutableMap;
 import io.netty.buffer.ByteBuf;
@@ -33,28 +35,30 @@ public final class SidLabelIndexParser {
         throw new UnsupportedOperationException();
     }
 
-    enum Size {
+    public enum Size {
         LABEL(3), SID(4), IPV6_ADD(16);
-        private int size;
         private static final Map<Integer, Size> VALUE_MAP;
+
         static {
             final ImmutableMap.Builder<java.lang.Integer, Size> b = ImmutableMap.builder();
-            for (final Size enumItem : Size.values()){
-                b.put(enumItem.size, enumItem);
+            for (final Size enumItem : Size.values()) {
+                b.put(enumItem.length, enumItem);
             }
             VALUE_MAP = b.build();
         }
-        Size(final int size) {
-            this.size = size;
+
+        private final int length;
+
+        Size(final int length) {
+            this.length = length;
         }
-        static Size forValue(final int value) {
+
+        public static Size forValue(final int value) {
             return VALUE_MAP.get(value);
         }
     }
 
-    static final int SID_TYPE = 1161;
-
-    static ByteBuf serializeSidValue(final SidLabelIndex tlv) {
+    public static ByteBuf serializeSidValue(final SidLabelIndex tlv) {
         if (tlv instanceof Ipv6AddressCase) {
             return Ipv6Util.byteBufForAddress(((Ipv6AddressCase) tlv).getIpv6Address());
         } else if (tlv instanceof LocalLabelCase) {
@@ -75,7 +79,7 @@ public final class SidLabelIndexParser {
         return parseSidLabelIndex(Size.forValue(length), buffer);
     }
 
-    static SidLabelIndex parseSidLabelIndex(final Size length, final ByteBuf buffer) {
+    public static SidLabelIndex parseSidLabelIndex(final Size length, final ByteBuf buffer) {
         switch (length) {
         case LABEL:
             return new LocalLabelCaseBuilder().setLocalLabel(new MplsLabel(new Long(buffer.readUnsignedMedium() & LABEL_MASK))).build();
similarity index 95%
rename from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/sr/SrLinkAttributesParser.java
rename to bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SrLinkAttributesParser.java
index cd34b5e2dba101f5dfc4b18323752c84bebd533c..4c714295eb9cfc090236ee956c8ea7cae194f7ce 100644 (file)
@@ -5,12 +5,14 @@
  * 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.sr;
+package org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr;
+
+import static org.opendaylight.protocol.bgp.linkstate.impl.attribute.LinkAttributesParser.SR_LAN_ADJ_ID;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import java.util.List;
-import org.opendaylight.protocol.bgp.linkstate.attribute.sr.SidLabelIndexParser.Size;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SidLabelIndexParser.Size;
 import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
 import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.protocol.util.ByteArray;
@@ -132,6 +134,8 @@ public final class SrLinkAttributesParser {
         case OspfV3:
             srLanAdjIdBuilder.setNeighborId(Ipv4Util.addressForByteBuf(buffer));
             break;
+        default:
+            return null;
         }
         // length determines a type of next field, which is used for parsing
         srLanAdjIdBuilder.setSidLabelIndex(SidLabelIndexParser.parseSidLabelIndex(Size.forValue(buffer.readableBytes()), buffer));
@@ -173,9 +177,9 @@ public final class SrLinkAttributesParser {
         return value;
     }
 
-    public static void serializeLanAdjacencySegmentIdentifiers(final List<SrLanAdjIds> srLanAdjIds, final int srLanAdjId, final ByteBuf byteAggregator) {
+    public static void serializeLanAdjacencySegmentIdentifiers(final List<SrLanAdjIds> srLanAdjIds, final ByteBuf byteAggregator) {
         for (final SrLanAdjIds id : srLanAdjIds) {
-            TlvUtil.writeTLV(srLanAdjId, serializeLanAdjacencySegmentIdentifier(id), byteAggregator);
+            TlvUtil.writeTLV(SR_LAN_ADJ_ID, serializeLanAdjacencySegmentIdentifier(id), byteAggregator);
         }
     }
 
similarity index 91%
rename from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/sr/SrNodeAttributesParser.java
rename to bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SrNodeAttributesParser.java
index e2463b2385281032f72cdfdbbb5b424b77237f6c..37b1e410c4492a217dc99d3c66298e0a2d1e7a88 100644 (file)
@@ -5,7 +5,9 @@
  * 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.sr;
+package org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr;
+
+import static org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs.SIDParser.SID_TYPE;
 
 import io.netty.buffer.ByteBuf;
 import java.util.ArrayList;
@@ -21,25 +23,23 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segm
 
 public final class SrNodeAttributesParser {
 
-    private SrNodeAttributesParser() {
-        throw new UnsupportedOperationException();
-    }
-
     private static final int FLAGS_SIZE = 8;
-
     /* SR Capabilities flags */
     private static final int MPLS_IPV4 = 0;
     private static final int MPLS_IPV6 = 1;
     private static final int SR_IPV6 = 2;
-
     private static final int RESERVERED = 1;
 
+    private SrNodeAttributesParser() {
+        throw new UnsupportedOperationException();
+    }
+
     public static SrCapabilities parseSrCapabilities(final ByteBuf buffer, final ProtocolId protocol) {
         final SrCapabilitiesBuilder builder = new SrCapabilitiesBuilder();
         final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
         setFlags(flags, protocol, builder);
         buffer.skipBytes(RESERVERED);
-        builder.setRangeSize((long)buffer.readUnsignedMedium());
+        builder.setRangeSize((long) buffer.readUnsignedMedium());
         builder.setSidLabelIndex(SidLabelIndexParser.parseSidSubTlv(buffer));
         return builder.build();
     }
@@ -64,7 +64,7 @@ public final class SrNodeAttributesParser {
         bs.toByteBuf(buffer);
         buffer.writeZero(RESERVERED);
         buffer.writeMedium(caps.getRangeSize().intValue());
-        TlvUtil.writeTLV(SidLabelIndexParser.SID_TYPE, SidLabelIndexParser.serializeSidValue(caps.getSidLabelIndex()), buffer);
+        TlvUtil.writeTLV(SID_TYPE, SidLabelIndexParser.serializeSidValue(caps.getSidLabelIndex()), buffer);
     }
 
     public static SrAlgorithm parseSrAlgorithms(final ByteBuf buffer) {
@@ -5,10 +5,10 @@
  * 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.sr;
+package org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr;
 
 import io.netty.buffer.ByteBuf;
-import org.opendaylight.protocol.bgp.linkstate.attribute.sr.SidLabelIndexParser.Size;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SidLabelIndexParser.Size;
 import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.ProtocolId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.prefix.state.SrPrefix;
@@ -23,10 +23,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segm
 
 public final class SrPrefixAttributesParser {
 
-    private SrPrefixAttributesParser() {
-        throw new UnsupportedOperationException();
-    }
-
     /* Flags */
     private static final int RE_ADVERTISEMENT = 0;
     private static final int NODE_SID = 1;
@@ -37,9 +33,12 @@ public final class SrPrefixAttributesParser {
     private static final int VALUE = 4;
     private static final int LOCAL = 5;
     private static final int FLAGS_SIZE = 8;
-
     private static final int RESERVED_PREFIX = 2;
 
+    private SrPrefixAttributesParser() {
+        throw new UnsupportedOperationException();
+    }
+
     public static SrPrefix parseSrPrefix(final ByteBuf buffer, final ProtocolId protocol) {
         final SrPrefixBuilder builder = new SrPrefixBuilder();
         builder.setFlags(parsePrefixFlags(BitArray.valueOf(buffer, FLAGS_SIZE), protocol));
@@ -68,7 +67,7 @@ public final class SrPrefixAttributesParser {
         serializePrefixAttributes(srPrefix.getFlags(), srPrefix.getAlgorithm(), srPrefix.getSidLabelIndex(), aggregator);
     }
 
-    static void serializePrefixAttributes(final Flags flags, final Algorithm algorithm, final SidLabelIndex sidLabelIndex, final ByteBuf buffer) {
+    public static void serializePrefixAttributes(final Flags flags, final Algorithm algorithm, final SidLabelIndex sidLabelIndex, final ByteBuf buffer) {
         final BitArray bitFlags = serializePrefixFlags(flags, sidLabelIndex);
         bitFlags.toByteBuf(buffer);
         buffer.writeByte(algorithm.getIntValue());
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/BackupUnnumberedParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/BackupUnnumberedParser.java
new file mode 100644 (file)
index 0000000..3771f83
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2016 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.impl.attribute.sr.binding.sid.sub.tlvs;
+
+import static org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs.UnnumberedEroParser.parseUnnumberedEroCase;
+import static org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs.UnnumberedEroParser.serializeUnnumberedIdEro;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsParser;
+import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsSerializer;
+import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.ProtocolId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.BindingSubTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.UnnumberedInterfaceIdBackupEroCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.UnnumberedInterfaceIdBackupEroCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.UnnumberedInterfaceIdEroCase;
+
+public final class BackupUnnumberedParser implements BindingSubTlvsParser, BindingSubTlvsSerializer {
+    private static final int BACKUP_UNNUMBERED_ERO = 1168;
+
+    @Override
+    public BindingSubTlv parseSubTlv(final ByteBuf slice, final ProtocolId protocolId) {
+        final UnnumberedInterfaceIdEroCase unnumberedBackup = parseUnnumberedEroCase(slice);
+        return new UnnumberedInterfaceIdBackupEroCaseBuilder().setLoose(unnumberedBackup.isLoose())
+            .setRouterId(unnumberedBackup.getRouterId()).setInterfaceId(unnumberedBackup.getInterfaceId()).build();
+    }
+
+    @Override
+    public int getType() {
+        return BACKUP_UNNUMBERED_ERO;
+    }
+
+    @Override
+    public void serializeSubTlv(final BindingSubTlv bindingSubTlv, final ByteBuf aggregator) {
+        Preconditions.checkArgument(bindingSubTlv instanceof UnnumberedInterfaceIdBackupEroCase, "Wrong BindingSubTlv instance expected", bindingSubTlv);
+        final UnnumberedInterfaceIdBackupEroCase unnumberedBackup = (UnnumberedInterfaceIdBackupEroCase) bindingSubTlv;
+        TlvUtil.writeTLV(BACKUP_UNNUMBERED_ERO, serializeUnnumberedIdEro(unnumberedBackup.isLoose(), unnumberedBackup.getRouterId(),
+            unnumberedBackup.getInterfaceId()), aggregator);
+    }
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/EroMetricParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/EroMetricParser.java
new file mode 100644 (file)
index 0000000..379b0c9
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2016 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.impl.attribute.sr.binding.sid.sub.tlvs;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsParser;
+import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsSerializer;
+import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.ProtocolId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.BindingSubTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.EroMetricCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.EroMetricCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.TeMetric;
+
+public final class EroMetricParser implements BindingSubTlvsParser, BindingSubTlvsSerializer {
+    private static final int ERO_METRIC = 1162;
+
+    @Override
+    public BindingSubTlv parseSubTlv(final ByteBuf slice, final ProtocolId protocolId) {
+        return new EroMetricCaseBuilder().setEroMetric(new TeMetric(slice.readUnsignedInt())).build();
+    }
+
+    @Override
+    public int getType() {
+        return ERO_METRIC;
+    }
+
+    @Override
+    public void serializeSubTlv(final BindingSubTlv bindingSubTlv, final ByteBuf aggregator) {
+        Preconditions.checkArgument(bindingSubTlv instanceof EroMetricCase, "Wrong BindingSubTlv instance expected", bindingSubTlv);
+        final ByteBuf buffer = Unpooled.buffer();
+        buffer.writeInt(((EroMetricCase) bindingSubTlv).getEroMetric().getValue().intValue());
+        TlvUtil.writeTLV(getType(), buffer, aggregator);
+    }
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv4BackupEro.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv4BackupEro.java
new file mode 100644 (file)
index 0000000..4b21bc9
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2016 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.impl.attribute.sr.binding.sid.sub.tlvs;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsParser;
+import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsSerializer;
+import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.ProtocolId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.BindingSubTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv4EroBackupCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv4EroBackupCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv4EroCase;
+
+public final class Ipv4BackupEro implements BindingSubTlvsParser, BindingSubTlvsSerializer {
+    private static final int BACKUP_ERO_IPV4 = 1166;
+
+    @Override
+    public BindingSubTlv parseSubTlv(final ByteBuf slice, final ProtocolId protocolId) {
+        final Ipv4EroCase ipv4Backup = Ipv4EroParser.parseIpv4EroCase(slice);
+        return new Ipv4EroBackupCaseBuilder().setAddress(ipv4Backup.getAddress()).setLoose(ipv4Backup.isLoose()).build();
+    }
+
+    @Override
+    public int getType() {
+        return BACKUP_ERO_IPV4;
+    }
+
+    @Override
+    public void serializeSubTlv(final BindingSubTlv bindingSubTlv, final ByteBuf aggregator) {
+        Preconditions.checkArgument(bindingSubTlv instanceof Ipv4EroBackupCase, "Wrong BindingSubTlv instance expected", bindingSubTlv);
+        final Ipv4EroBackupCase ipv4Backup = (Ipv4EroBackupCase) bindingSubTlv;
+        TlvUtil.writeTLV(getType(), Ipv4EroParser.serializeIpv4EroCase(ipv4Backup.isLoose(), ipv4Backup.getAddress()), aggregator);
+    }
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv4EroParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv4EroParser.java
new file mode 100644 (file)
index 0000000..6a7e557
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2016 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.impl.attribute.sr.binding.sid.sub.tlvs;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsParser;
+import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsSerializer;
+import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
+import org.opendaylight.protocol.util.BitArray;
+import org.opendaylight.protocol.util.Ipv4Util;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.ProtocolId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.BindingSubTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv4EroCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv4EroCaseBuilder;
+
+public final class Ipv4EroParser implements BindingSubTlvsParser, BindingSubTlvsSerializer {
+    private static final int ERO_IPV4 = 1163;
+    static final int FLAGS_SIZE = 8;
+    static final int LOOSE = 0;
+    static final int RESERVED_ERO = 3;
+
+    @Override
+    public BindingSubTlv parseSubTlv(final ByteBuf slice, final ProtocolId protocolId) {
+        final Ipv4EroCase ipv4Ero = parseIpv4EroCase(slice);
+        return new Ipv4EroCaseBuilder().setAddress(ipv4Ero.getAddress()).setLoose(ipv4Ero.isLoose()).build();
+    }
+
+    @Override
+    public int getType() {
+        return ERO_IPV4;
+    }
+
+    @Override
+    public void serializeSubTlv(final BindingSubTlv bindingSubTlv, final ByteBuf aggregator) {
+        Preconditions.checkArgument(bindingSubTlv instanceof Ipv4EroCase, "Wrong BindingSubTlv instance expected", bindingSubTlv);
+        final Ipv4EroCase ipv4Ero = (Ipv4EroCase) bindingSubTlv;
+        TlvUtil.writeTLV(getType(), serializeIpv4EroCase(ipv4Ero.isLoose(), ipv4Ero.getAddress()), aggregator);
+    }
+
+    static Ipv4EroCase parseIpv4EroCase(final ByteBuf buffer) {
+        final Ipv4EroCaseBuilder builder = new Ipv4EroCaseBuilder();
+        final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
+        builder.setLoose(flags.get(LOOSE));
+        buffer.skipBytes(RESERVED_ERO);
+        builder.setAddress(Ipv4Util.addressForByteBuf(buffer));
+        return builder.build();
+    }
+
+
+    static ByteBuf serializeIpv4EroCase(final Boolean loose, final Ipv4Address address) {
+        final ByteBuf buffer = Unpooled.buffer();
+        serializeEroFlags(buffer, loose);
+        buffer.writeBytes(Ipv4Util.byteBufForAddress(address));
+        return buffer;
+    }
+
+    static void serializeEroFlags(final ByteBuf buffer, final Boolean loose) {
+        final BitArray flags = new BitArray(FLAGS_SIZE);
+        flags.set(LOOSE, loose);
+        flags.toByteBuf(buffer);
+        buffer.writeZero(RESERVED_ERO);
+    }
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv4PrefixSidParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv4PrefixSidParser.java
new file mode 100644 (file)
index 0000000..afe6f4f
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2016 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.impl.attribute.sr.binding.sid.sub.tlvs;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SrPrefixAttributesParser;
+import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsParser;
+import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsSerializer;
+import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.ProtocolId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.prefix.state.SrPrefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.BindingSubTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.PrefixSidCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.PrefixSidCaseBuilder;
+
+public final class Ipv4PrefixSidParser implements BindingSubTlvsParser, BindingSubTlvsSerializer {
+    public static final int PREFIX_SID = 1158;
+
+    @Override
+    public BindingSubTlv parseSubTlv(final ByteBuf slice, final ProtocolId protocolId) {
+        final SrPrefix prefix = SrPrefixAttributesParser.parseSrPrefix(slice, protocolId);
+        return new PrefixSidCaseBuilder().setAlgorithm(prefix.getAlgorithm()).setFlags(prefix.getFlags())
+            .setSidLabelIndex(prefix.getSidLabelIndex()).build();
+    }
+
+    @Override
+    public int getType() {
+        return PREFIX_SID;
+    }
+
+    @Override
+    public void serializeSubTlv(final BindingSubTlv bindingSubTlv, final ByteBuf aggregator) {
+        Preconditions.checkArgument(bindingSubTlv instanceof PrefixSidCase, "Wrong BindingSubTlv instance expected", bindingSubTlv);
+        final PrefixSidCase prefix = (PrefixSidCase) bindingSubTlv;
+        final ByteBuf buffer = Unpooled.buffer();
+        SrPrefixAttributesParser.serializePrefixAttributes(prefix.getFlags(), prefix.getAlgorithm(), prefix.getSidLabelIndex(), buffer);
+        TlvUtil.writeTLV(getType(), buffer, aggregator);
+    }
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv6BackupEro.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv6BackupEro.java
new file mode 100644 (file)
index 0000000..0bd66f0
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2016 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.impl.attribute.sr.binding.sid.sub.tlvs;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsParser;
+import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsSerializer;
+import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.ProtocolId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.BindingSubTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv6EroBackupCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv6EroBackupCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv6EroCase;
+
+public final class Ipv6BackupEro implements BindingSubTlvsParser, BindingSubTlvsSerializer {
+    private static final int BACKUP_ERO_IPV6 = 1167;
+
+    @Override
+    public BindingSubTlv parseSubTlv(final ByteBuf slice, final ProtocolId protocolId) {
+        final Ipv6EroCase ipv6backup = Ipv6EroParser.parseIpv6EroCase(slice);
+        return new Ipv6EroBackupCaseBuilder().setAddress(ipv6backup.getAddress()).setLoose(ipv6backup.isLoose()).build();
+    }
+
+    @Override
+    public int getType() {
+        return BACKUP_ERO_IPV6;
+    }
+
+    @Override
+    public void serializeSubTlv(final BindingSubTlv bindingSubTlv, final ByteBuf aggregator) {
+        Preconditions.checkArgument(bindingSubTlv instanceof Ipv6EroBackupCase, "Wrong BindingSubTlv instance expected", bindingSubTlv);
+        final Ipv6EroBackupCase ipv6Backup = (Ipv6EroBackupCase) bindingSubTlv;
+        TlvUtil.writeTLV(getType(), Ipv6EroParser.serializeIpv6EroCase(ipv6Backup.isLoose(), ipv6Backup.getAddress()), aggregator);
+    }
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv6EroParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv6EroParser.java
new file mode 100644 (file)
index 0000000..eaf5f8a
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2016 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.impl.attribute.sr.binding.sid.sub.tlvs;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsParser;
+import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsSerializer;
+import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
+import org.opendaylight.protocol.util.BitArray;
+import org.opendaylight.protocol.util.Ipv6Util;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.ProtocolId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.BindingSubTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv6EroCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv6EroCaseBuilder;
+
+public final class Ipv6EroParser implements BindingSubTlvsParser, BindingSubTlvsSerializer {
+    private static final int ERO_IPV6 = 1164;
+
+    @Override
+    public BindingSubTlv parseSubTlv(final ByteBuf slice, final ProtocolId protocolId) {
+        final Ipv6EroCase ipv6ero = parseIpv6EroCase(slice);
+        return new Ipv6EroCaseBuilder().setAddress(ipv6ero.getAddress()).setLoose(ipv6ero.isLoose()).build();
+    }
+
+    @Override
+    public int getType() {
+        return ERO_IPV6;
+    }
+
+    @Override
+    public void serializeSubTlv(final BindingSubTlv bindingSubTlv, final ByteBuf aggregator) {
+        Preconditions.checkArgument(bindingSubTlv instanceof Ipv6EroCase, "Wrong BindingSubTlv instance expected", bindingSubTlv);
+        final Ipv6EroCase ipv6Ero = (Ipv6EroCase) bindingSubTlv;
+        TlvUtil.writeTLV(getType(), serializeIpv6EroCase(ipv6Ero.isLoose(), ipv6Ero.getAddress()), aggregator);
+    }
+
+    public static Ipv6EroCase parseIpv6EroCase(final ByteBuf buffer) {
+        final Ipv6EroCaseBuilder builder = new Ipv6EroCaseBuilder();
+        final BitArray flags = BitArray.valueOf(buffer, Ipv4EroParser.FLAGS_SIZE);
+        builder.setLoose(flags.get(Ipv4EroParser.LOOSE));
+        buffer.skipBytes(Ipv4EroParser.RESERVED_ERO);
+        builder.setAddress(Ipv6Util.addressForByteBuf(buffer));
+        return builder.build();
+    }
+
+    static ByteBuf serializeIpv6EroCase(final Boolean loose, final Ipv6Address address) {
+        final ByteBuf buffer = Unpooled.buffer();
+        Ipv4EroParser.serializeEroFlags(buffer, loose);
+        buffer.writeBytes(Ipv6Util.byteBufForAddress(address));
+        return buffer;
+    }
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv6PrefixSidParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv6PrefixSidParser.java
new file mode 100644 (file)
index 0000000..21159b3
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2016 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.impl.attribute.sr.binding.sid.sub.tlvs;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.Ipv6SrPrefixAttributesParser;
+import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsParser;
+import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsSerializer;
+import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.ProtocolId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.prefix.state.Ipv6SrPrefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.BindingSubTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv6PrefixSidCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv6PrefixSidCaseBuilder;
+
+public final class Ipv6PrefixSidParser implements BindingSubTlvsParser, BindingSubTlvsSerializer {
+    public static final int IPV6_PREFIX_SID = 1169;
+
+    @Override
+    public BindingSubTlv parseSubTlv(final ByteBuf slice, final ProtocolId protocolId) {
+        final Ipv6SrPrefix ipv6Prefix = Ipv6SrPrefixAttributesParser.parseSrIpv6Prefix(slice);
+        return new Ipv6PrefixSidCaseBuilder().setAlgorithm(ipv6Prefix.getAlgorithm()).build();
+    }
+
+    @Override
+    public int getType() {
+        return IPV6_PREFIX_SID;
+    }
+
+    @Override
+    public void serializeSubTlv(final BindingSubTlv bindingSubTlv, final ByteBuf aggregator) {
+        Preconditions.checkArgument(bindingSubTlv instanceof Ipv6PrefixSidCase, "Wrong BindingSubTlv instance expected", bindingSubTlv);
+        final Ipv6PrefixSidCase prefix = (Ipv6PrefixSidCase) bindingSubTlv;
+        final ByteBuf buffer = Unpooled.buffer();
+        Ipv6SrPrefixAttributesParser.serializePrefixAttributes(prefix.getAlgorithm(), buffer);
+        TlvUtil.writeTLV(getType(), buffer, aggregator);
+    }
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/SIDParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/SIDParser.java
new file mode 100644 (file)
index 0000000..5c4d0fe
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2016 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.impl.attribute.sr.binding.sid.sub.tlvs;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SidLabelIndexParser;
+import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsParser;
+import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsSerializer;
+import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.ProtocolId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.BindingSubTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.SidLabelCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.SidLabelCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.sid.label.index.SidLabelIndex;
+
+public final class SIDParser implements BindingSubTlvsParser, BindingSubTlvsSerializer {
+    public static final int SID_TYPE = 1161;
+
+    @Override
+    public BindingSubTlv parseSubTlv(final ByteBuf slice, final ProtocolId protocolId) {
+        final SidLabelIndex sid = SidLabelIndexParser.parseSidLabelIndex(SidLabelIndexParser.Size.forValue(slice.readableBytes()), slice);
+        return new SidLabelCaseBuilder().setSidLabelIndex(sid).build();
+    }
+
+    @Override
+    public int getType() {
+        return SID_TYPE;
+    }
+
+    @Override
+    public void serializeSubTlv(final BindingSubTlv bindingSubTlv, final ByteBuf aggregator) {
+        Preconditions.checkArgument(bindingSubTlv instanceof SidLabelCase, "Wrong BindingSubTlv instance expected", bindingSubTlv);
+        TlvUtil.writeTLV(getType(), SidLabelIndexParser.serializeSidValue(((SidLabelCase) bindingSubTlv).getSidLabelIndex()), aggregator);
+    }
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/UnnumberedEroParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/UnnumberedEroParser.java
new file mode 100644 (file)
index 0000000..c005f67
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2016 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.impl.attribute.sr.binding.sid.sub.tlvs;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsParser;
+import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsSerializer;
+import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
+import org.opendaylight.protocol.util.BitArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.ProtocolId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.BindingSubTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.UnnumberedInterfaceIdEroCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.UnnumberedInterfaceIdEroCaseBuilder;
+
+public final class UnnumberedEroParser implements BindingSubTlvsParser, BindingSubTlvsSerializer {
+    private static final int UNNUMBERED_ERO = 1165;
+
+    @Override
+    public BindingSubTlv parseSubTlv(final ByteBuf slice, final ProtocolId protocolId) {
+        final UnnumberedInterfaceIdEroCase unnumbered = parseUnnumberedEroCase(slice);
+        return new UnnumberedInterfaceIdEroCaseBuilder().setLoose(unnumbered.isLoose()).setRouterId(unnumbered.getRouterId())
+            .setInterfaceId(unnumbered.getInterfaceId()).build();
+    }
+
+    @Override
+    public int getType() {
+        return UNNUMBERED_ERO;
+    }
+
+    @Override
+    public void serializeSubTlv(final BindingSubTlv bindingSubTlv, final ByteBuf aggregator) {
+        Preconditions.checkArgument(bindingSubTlv instanceof UnnumberedInterfaceIdEroCase, "Wrong BindingSubTlv instance expected", bindingSubTlv);
+        final UnnumberedInterfaceIdEroCase unnumberedEro = (UnnumberedInterfaceIdEroCase) bindingSubTlv;
+        TlvUtil.writeTLV(getType(), serializeUnnumberedIdEro(unnumberedEro.isLoose(), unnumberedEro.getRouterId(), unnumberedEro.getInterfaceId()), aggregator);
+    }
+
+    static UnnumberedInterfaceIdEroCase parseUnnumberedEroCase(final ByteBuf buffer) {
+        final UnnumberedInterfaceIdEroCaseBuilder builder = new UnnumberedInterfaceIdEroCaseBuilder();
+        final BitArray flags = BitArray.valueOf(buffer, Ipv4EroParser.FLAGS_SIZE);
+        builder.setLoose(flags.get(Ipv4EroParser.LOOSE));
+        buffer.skipBytes(Ipv4EroParser.RESERVED_ERO);
+        builder.setRouterId(buffer.readUnsignedInt());
+        builder.setInterfaceId(buffer.readUnsignedInt());
+        return builder.build();
+    }
+
+    static ByteBuf serializeUnnumberedIdEro(final Boolean loose, final Long routerId, final Long interfaceId) {
+        final ByteBuf buffer = Unpooled.buffer();
+        Ipv4EroParser.serializeEroFlags(buffer, loose);
+        buffer.writeInt(routerId.intValue());
+        buffer.writeInt(interfaceId.intValue());
+        return buffer;
+    }
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/AbstractPrefixNlriParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/AbstractPrefixNlriParser.java
new file mode 100644 (file)
index 0000000..fd79da8
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2016 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.impl.nlri;
+
+import io.netty.buffer.ByteBuf;
+import java.util.Map;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.MultiTopoIdTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.OspfRouteTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.ReachTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.spi.AbstractNlriTypeCodec;
+import org.opendaylight.protocol.bgp.linkstate.spi.pojo.SimpleNlriTypeRegistry;
+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.rev150210.NodeIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.OspfRouteType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.TopologyIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.ObjectType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.PrefixCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.PrefixCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.prefix._case.AdvertisingNodeDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.prefix._case.AdvertisingNodeDescriptorsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.prefix._case.PrefixDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.prefix._case.PrefixDescriptorsBuilder;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+
+abstract class AbstractPrefixNlriParser extends AbstractNlriTypeCodec {
+    @Override
+    protected final ObjectType parseObjectType(final ByteBuf buffer) {
+        final NodeIdentifier oType = SimpleNlriTypeRegistry.getInstance().parseTlv(buffer);
+        final PrefixCaseBuilder builder = new PrefixCaseBuilder();
+        builder.setAdvertisingNodeDescriptors(new AdvertisingNodeDescriptorsBuilder(oType).build());
+        builder.setPrefixDescriptors(parsePrefixDescriptor(buffer));
+        return builder.build();
+    }
+
+    @Override
+    protected final void serializeObjectType(final ObjectType objectType, final ByteBuf buffer) {
+        final PrefixCase prefix = (PrefixCase) objectType;
+        SimpleNlriTypeRegistry.getInstance().serializeTlv(AdvertisingNodeDescriptors.QNAME, prefix.getAdvertisingNodeDescriptors(), buffer);
+        serializePrefixDescriptor(prefix.getPrefixDescriptors(), buffer);
+    }
+
+    private PrefixDescriptors parsePrefixDescriptor(final ByteBuf buffer) {
+        final Map<QName, Object> tlvs = SimpleNlriTypeRegistry.getInstance().parseSubTlvs(buffer);
+        final PrefixDescriptorsBuilder builder = new PrefixDescriptorsBuilder();
+        builder.setMultiTopologyId((TopologyIdentifier) tlvs.get(MultiTopoIdTlvParser.MULTI_TOPOLOGY_ID_QNAME));
+        builder.setOspfRouteType((OspfRouteType) tlvs.get(OspfRouteTlvParser.OSPF_ROUTE_TYPE_QNAME));
+        builder.setIpReachabilityInformation((IpPrefix) tlvs.get(ReachTlvParser.IP_REACHABILITY_QNAME));
+        return builder.build();
+    }
+
+    private void serializePrefixDescriptor(final PrefixDescriptors tlv, final ByteBuf buffer) {
+        final SimpleNlriTypeRegistry reg = SimpleNlriTypeRegistry.getInstance();
+        reg.serializeTlv(MultiTopoIdTlvParser.MULTI_TOPOLOGY_ID_QNAME, tlv.getMultiTopologyId(), buffer);
+        reg.serializeTlv(OspfRouteTlvParser.OSPF_ROUTE_TYPE_QNAME, tlv.getOspfRouteType(), buffer);
+        reg.serializeTlv(ReachTlvParser.IP_REACHABILITY_QNAME, tlv.getIpReachabilityInformation(), buffer);
+    }
+
+    static PrefixDescriptors serializePrefixDescriptors(final ContainerNode prefixDesc) {
+        final PrefixDescriptorsBuilder prefixDescBuilder = new PrefixDescriptorsBuilder();
+        prefixDescBuilder.setMultiTopologyId(MultiTopoIdTlvParser.serializeModel(prefixDesc));
+        prefixDescBuilder.setOspfRouteType(OspfRouteTlvParser.serializeModel(prefixDesc));
+        prefixDescBuilder.setIpReachabilityInformation(ReachTlvParser.serializeModel(prefixDesc));
+        return prefixDescBuilder.build();
+    }
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/Ipv4PrefixNlriParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/Ipv4PrefixNlriParser.java
new file mode 100644 (file)
index 0000000..bd0e349
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2016 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.impl.nlri;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NlriType;
+
+public final class Ipv4PrefixNlriParser extends AbstractPrefixNlriParser {
+    @Override
+    public int getNlriType() {
+        return NlriType.Ipv4Prefix.getIntValue();
+    }
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/Ipv6PrefixNlriParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/Ipv6PrefixNlriParser.java
new file mode 100644 (file)
index 0000000..efc6b82
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2016 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.impl.nlri;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NlriType;
+
+public final class Ipv6PrefixNlriParser extends AbstractPrefixNlriParser {
+    @Override
+    public int getNlriType() {
+        return NlriType.Ipv6Prefix.getIntValue();
+    }
+}
\ No newline at end of file
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/LinkNlriParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/LinkNlriParser.java
new file mode 100644 (file)
index 0000000..c15d577
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+ * 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.impl.nlri;
+
+import com.google.common.annotations.VisibleForTesting;
+import io.netty.buffer.ByteBuf;
+import java.util.Map;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.Ipv4InterfaceTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.Ipv4NeighborTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.Ipv6InterfaceTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.Ipv6NeighborTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.MultiTopoIdTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.spi.AbstractNlriTypeCodec;
+import org.opendaylight.protocol.bgp.linkstate.spi.pojo.SimpleNlriTypeRegistry;
+import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Ipv4InterfaceIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Ipv6InterfaceIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkLrIdentifiers;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NlriType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.TopologyIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.ObjectType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.LinkCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.LinkCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LinkDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LinkDescriptorsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LocalNodeDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.RemoteNodeDescriptors;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+
+public final class LinkNlriParser extends AbstractNlriTypeCodec {
+
+    /* Link Descriptor QNames */
+    @VisibleForTesting
+    public static final NodeIdentifier IPV4_IFACE_NID = new NodeIdentifier(Ipv4InterfaceTlvParser.IPV4_IFACE_ADDRESS_QNAME);
+    @VisibleForTesting
+    public static final NodeIdentifier IPV4_NEIGHBOR_NID = new NodeIdentifier(Ipv4NeighborTlvParser.IPV4_NEIGHBOR_ADDRESS_QNAME);
+    @VisibleForTesting
+    public static final NodeIdentifier LINK_LOCAL_NID = new NodeIdentifier(QName.create(LinkDescriptors.QNAME, "link-local-identifier").intern());
+    @VisibleForTesting
+    public static final NodeIdentifier LINK_REMOTE_NID = new NodeIdentifier(QName.create(LinkDescriptors.QNAME, "link-remote-identifier").intern());
+    private static final NodeIdentifier IPV6_IFACE_NID = new NodeIdentifier(Ipv6InterfaceTlvParser.IPV6_IFACE_ADDRESS_QNAME);
+    private static final NodeIdentifier IPV6_NEIGHBOR_NID = new NodeIdentifier(Ipv6NeighborTlvParser.IPV6_NEIGHBOR_ADDRESS_QNAME);
+
+    @FunctionalInterface
+    private interface SerializerInterface {
+        void check(Object cont);
+    }
+
+    static LinkDescriptors serializeLinkDescriptors(final ContainerNode descriptors) {
+        final LinkDescriptorsBuilder linkDescBuilder = new LinkDescriptorsBuilder();
+
+        if (descriptors.getChild(LINK_LOCAL_NID).isPresent() && descriptors.getChild(LINK_REMOTE_NID).isPresent()) {
+            linkDescBuilder.setLinkLocalIdentifier((Long) descriptors.getChild(LINK_LOCAL_NID).get().getValue());
+            linkDescBuilder.setLinkRemoteIdentifier((Long) descriptors.getChild(LINK_REMOTE_NID).get().getValue());
+        }
+        ifPresentApply(descriptors, IPV4_IFACE_NID, value -> linkDescBuilder.setIpv4InterfaceAddress(new Ipv4InterfaceIdentifier((String) value)));
+        ifPresentApply(descriptors, IPV6_IFACE_NID, value -> linkDescBuilder.setIpv6InterfaceAddress(new Ipv6InterfaceIdentifier((String) value)));
+        ifPresentApply(descriptors, IPV4_NEIGHBOR_NID, value -> linkDescBuilder.setIpv4NeighborAddress(new Ipv4InterfaceIdentifier((String) value)));
+        ifPresentApply(descriptors, IPV6_NEIGHBOR_NID, value -> linkDescBuilder.setIpv6NeighborAddress(new Ipv6InterfaceIdentifier((String) value)));
+        ifPresentApply(descriptors, TlvUtil.MULTI_TOPOLOGY_NID, value -> linkDescBuilder.setMultiTopologyId(new TopologyIdentifier((Integer) value)));
+        return linkDescBuilder.build();
+    }
+
+    private static void ifPresentApply(final ContainerNode descriptors, final NodeIdentifier nid, final SerializerInterface serializer) {
+        if (descriptors.getChild(nid).isPresent()) {
+            serializer.check(descriptors.getChild(nid).get().getValue());
+        }
+    }
+
+    private LinkDescriptors parseLinkDescriptor(final ByteBuf buffer) {
+        final Map<QName, Object> tlvs = SimpleNlriTypeRegistry.getInstance().parseSubTlvs(buffer);
+        final LinkDescriptorsBuilder builder = new LinkDescriptorsBuilder();
+
+        final LinkLrIdentifiers linkIdentifiers = (LinkLrIdentifiers) tlvs.get(LinkLrIdentifiers.QNAME);
+        if (linkIdentifiers != null) {
+            builder.setLinkLocalIdentifier(linkIdentifiers.getLinkLocalIdentifier());
+            builder.setLinkRemoteIdentifier(linkIdentifiers.getLinkRemoteIdentifier());
+        }
+        builder.setIpv4InterfaceAddress((Ipv4InterfaceIdentifier) tlvs.get(Ipv4InterfaceTlvParser.IPV4_IFACE_ADDRESS_QNAME));
+        builder.setIpv4NeighborAddress((Ipv4InterfaceIdentifier) tlvs.get(Ipv4NeighborTlvParser.IPV4_NEIGHBOR_ADDRESS_QNAME));
+        builder.setIpv6InterfaceAddress((Ipv6InterfaceIdentifier) tlvs.get(Ipv6InterfaceTlvParser.IPV6_IFACE_ADDRESS_QNAME));
+        builder.setIpv6NeighborAddress((Ipv6InterfaceIdentifier) tlvs.get(Ipv6NeighborTlvParser.IPV6_NEIGHBOR_ADDRESS_QNAME));
+        builder.setMultiTopologyId((TopologyIdentifier) tlvs.get(MultiTopoIdTlvParser.MULTI_TOPOLOGY_ID_QNAME));
+
+        return builder.build();
+    }
+
+    @Override
+    protected ObjectType parseObjectType(final ByteBuf buffer) {
+        final SimpleNlriTypeRegistry reg = SimpleNlriTypeRegistry.getInstance();
+        final LocalNodeDescriptors localDescriptor = reg.parseTlv(buffer);
+        final RemoteNodeDescriptors remoteDescriptor = reg.parseTlv(buffer);
+        final LinkDescriptors linkDescriptor = parseLinkDescriptor(buffer);
+        return new LinkCaseBuilder()
+            .setLinkDescriptors(linkDescriptor)
+            .setLocalNodeDescriptors(localDescriptor)
+            .setRemoteNodeDescriptors(remoteDescriptor)
+            .build();
+    }
+
+    @Override
+    protected void serializeObjectType(final ObjectType objectType, final ByteBuf buffer) {
+        final LinkCase linkNlri = (LinkCase) objectType;
+        final SimpleNlriTypeRegistry reg = SimpleNlriTypeRegistry.getInstance();
+        reg.serializeTlv(LocalNodeDescriptors.QNAME, linkNlri.getLocalNodeDescriptors(), buffer);
+        reg.serializeTlv(RemoteNodeDescriptors.QNAME, linkNlri.getRemoteNodeDescriptors(), buffer);
+        serializeLinkDescriptor(linkNlri.getLinkDescriptors(), buffer);
+    }
+
+    private void serializeLinkDescriptor(final LinkDescriptors linkDescriptor, final ByteBuf body) {
+        final SimpleNlriTypeRegistry reg = SimpleNlriTypeRegistry.getInstance();
+        if (linkDescriptor.getLinkLocalIdentifier() != null && linkDescriptor.getLinkRemoteIdentifier() != null) {
+            reg.serializeTlv(LinkLrIdentifiers.QNAME, linkDescriptor, body);
+        }
+        reg.serializeTlv(Ipv4InterfaceTlvParser.IPV4_IFACE_ADDRESS_QNAME, linkDescriptor.getIpv4InterfaceAddress(), body);
+        reg.serializeTlv(Ipv4NeighborTlvParser.IPV4_NEIGHBOR_ADDRESS_QNAME, linkDescriptor.getIpv4NeighborAddress(), body);
+        reg.serializeTlv(Ipv6InterfaceTlvParser.IPV6_IFACE_ADDRESS_QNAME, linkDescriptor.getIpv6InterfaceAddress(), body);
+        reg.serializeTlv(Ipv6NeighborTlvParser.IPV6_NEIGHBOR_ADDRESS_QNAME, linkDescriptor.getIpv6NeighborAddress(), body);
+        reg.serializeTlv(MultiTopoIdTlvParser.MULTI_TOPOLOGY_ID_QNAME, linkDescriptor.getMultiTopologyId(), body);
+    }
+
+    @Override
+    public int getNlriType() {
+        return NlriType.Link.getIntValue();
+    }
+}
similarity index 68%
rename from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/LinkstateNlriParser.java
rename to bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/LinkstateNlriParser.java
index 8281d91406ca600bdd947ddd505161b6ea58e5ee..0b89a0d23dede07607c2c9315b86f97ba4e291f5 100644 (file)
@@ -5,22 +5,21 @@
  * 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;
+package org.opendaylight.protocol.bgp.linkstate.impl.nlri;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.List;
-import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
+import org.opendaylight.protocol.bgp.linkstate.spi.AbstractTeLspNlriCodec;
+import org.opendaylight.protocol.bgp.linkstate.spi.pojo.SimpleNlriTypeRegistry;
 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.rev150210.Identifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NlriType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.ProtocolId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.RouteDistinguisher;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.ObjectType;
@@ -42,10 +41,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mess
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlriBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlri;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlriBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -63,18 +62,6 @@ import org.slf4j.LoggerFactory;
  */
 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_TYPE = 256;
-    private static final int REMOTE_NODE_DESCRIPTORS_TYPE = 257;
-
     @VisibleForTesting
     public static final NodeIdentifier OBJECT_TYPE_NID = new NodeIdentifier(ObjectType.QNAME);
     @VisibleForTesting
@@ -89,67 +76,30 @@ public final class LinkstateNlriParser implements NlriParser, NlriSerializer {
     public static final NodeIdentifier PREFIX_DESCRIPTORS_NID = new NodeIdentifier(PrefixDescriptors.QNAME);
     @VisibleForTesting
     public static final NodeIdentifier LINK_DESCRIPTORS_NID = new NodeIdentifier(LinkDescriptors.QNAME);
-
-    @VisibleForTesting
-    public static final NodeIdentifier DISTINGUISHER_NID = new NodeIdentifier(QName.create(CLinkstateDestination.QNAME, "distinguisher").intern());
     @VisibleForTesting
     public static final NodeIdentifier PROTOCOL_ID_NID = new NodeIdentifier(QName.create(CLinkstateDestination.QNAME, "protocol-id").intern());
     @VisibleForTesting
     public static final NodeIdentifier IDENTIFIER_NID = new NodeIdentifier(QName.create(CLinkstateDestination.QNAME, "identifier").intern());
-
-    private final boolean isVpn;
-
-    public LinkstateNlriParser(final boolean isVpn) {
-        this.isVpn = isVpn;
-    }
+    private static final Logger LOG = LoggerFactory.getLogger(LinkstateNlriParser.class);
+    @VisibleForTesting
+    private static final NodeIdentifier DISTINGUISHER_NID = new NodeIdentifier(QName.create(CLinkstateDestination.QNAME, "distinguisher").intern());
+    private final SimpleNlriTypeRegistry nlriTypeReg = SimpleNlriTypeRegistry.getInstance();
 
 
     /**
      * Parses common parts for Link State Nodes, Links and Prefixes, that includes protocol ID and identifier tlv.
      *
      * @param nlri as byte array
-     * @param isVpn flag which determines that destination has route distinguisher
      * @return {@link CLinkstateDestination}
-     * @throws BGPParsingException if parsing was unsuccessful
      */
-    public static List<CLinkstateDestination> parseNlri(final ByteBuf nlri, final boolean isVpn) throws BGPParsingException {
+    private List<CLinkstateDestination> parseNlri(final ByteBuf nlri) {
         final List<CLinkstateDestination> dests = new ArrayList<>();
         while (nlri.isReadable()) {
-            final CLinkstateDestinationBuilder builder = new CLinkstateDestinationBuilder();
-            final NlriType type = NlriType.forValue(nlri.readUnsignedShort());
-
-            // 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
-            org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier localDescriptor = null;
-            ByteBuf rest = null;
-            if (!type.equals(NlriType.Ipv4TeLsp) && !type.equals(NlriType.Ipv6TeLsp)) {
-                final int localtype = nlri.readUnsignedShort();
-                final int locallength = nlri.readUnsignedShort();
-                if (localtype == LOCAL_NODE_DESCRIPTORS_TYPE) {
-                    localDescriptor = NodeNlriParser.parseNodeDescriptors(nlri.readSlice(locallength), type, true);
-                }
-                final int restLength = length - (isVpn ? ROUTE_DISTINGUISHER_LENGTH : 0) - PROTOCOL_ID_LENGTH -
-                    IDENTIFIER_LENGTH - TYPE_LENGTH - LENGTH_SIZE - locallength;
-                LOG.trace("Restlength {}", restLength);
-                rest = nlri.readSlice(restLength);
+            final CLinkstateDestination destination = this.nlriTypeReg.parseNlriType(nlri);
+            if (destination == null) {
+                continue;
             }
-            builder.setObjectType(SimpleNlriTypeRegistry.getInstance().parseNlriType(nlri, type, localDescriptor, rest));
-            dests.add(builder.build());
+            dests.add(destination);
         }
         return dests;
     }
@@ -159,7 +109,7 @@ public final class LinkstateNlriParser implements NlriParser, NlriSerializer {
         if (!nlri.isReadable()) {
             return;
         }
-        final List<CLinkstateDestination> dst = parseNlri(nlri, this.isVpn);
+        final List<CLinkstateDestination> dst = parseNlri(nlri);
 
         builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
             new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCaseBuilder().setDestinationLinkstate(
@@ -172,32 +122,13 @@ public final class LinkstateNlriParser implements NlriParser, NlriSerializer {
         if (!nlri.isReadable()) {
             return;
         }
-        final List<CLinkstateDestination> dst = parseNlri(nlri, this.isVpn);
+        final List<CLinkstateDestination> dst = parseNlri(nlri);
 
         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
-     * @param buffer where Linkstate NLRI will 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());
-        final ByteBuf ldescs = Unpooled.buffer();
-        final NlriType nlriType = SimpleNlriTypeRegistry.getInstance().serializeNlriType(destination, ldescs, nlriByteBuf);
-        Preconditions.checkNotNull(nlriType, "NLRI Type value should not be null.");
-        TlvUtil.writeTLV(nlriType.getIntValue(), nlriByteBuf, buffer);
-    }
-
     @Override
     public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
         Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object.");
@@ -205,25 +136,30 @@ public final class LinkstateNlriParser implements NlriParser, NlriSerializer {
         final Attributes1 pathAttributes1 = pathAttributes.getAugmentation(Attributes1.class);
         final Attributes2 pathAttributes2 = pathAttributes.getAugmentation(Attributes2.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.rev150210.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase) {
-                final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase
-                    linkstateCase = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase) routes.getDestinationType();
+            serializeAdvertisedRoutes((pathAttributes1.getMpReachNlri()).getAdvertizedRoutes(), byteAggregator);
+        } else if (pathAttributes2 != null) {
+            serializeWithDrawnRoutes(pathAttributes2.getMpUnreachNlri().getWithdrawnRoutes(), byteAggregator);
+        }
+    }
 
-                for (final CLinkstateDestination cLinkstateDestination : linkstateCase.getDestinationLinkstate().getCLinkstateDestination()) {
-                    serializeNlri(cLinkstateDestination, byteAggregator);
-                }
+    private void serializeWithDrawnRoutes(final WithdrawnRoutes withdrawnRoutes, final ByteBuf byteAggregator) {
+        if (withdrawnRoutes != null && withdrawnRoutes.getDestinationType() instanceof DestinationLinkstateCase) {
+            final DestinationLinkstateCase linkstateCase = (DestinationLinkstateCase) withdrawnRoutes.getDestinationType();
+            for (final CLinkstateDestination cLinkstateDestination : linkstateCase.getDestinationLinkstate().getCLinkstateDestination()) {
+                this.nlriTypeReg.serializeNlriType(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);
-                }
+        }
+    }
+
+    private void serializeAdvertisedRoutes(final AdvertizedRoutes advertizedRoutes, final ByteBuf byteAggregator) {
+        if (advertizedRoutes != null && advertizedRoutes.getDestinationType()
+            instanceof
+            org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase) {
+            final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase
+                linkstateCase = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase) advertizedRoutes.getDestinationType();
+
+            for (final CLinkstateDestination cLinkstateDestination : linkstateCase.getDestinationLinkstate().getCLinkstateDestination()) {
+                this.nlriTypeReg.serializeNlriType(cLinkstateDestination, byteAggregator);
             }
         }
     }
@@ -265,8 +201,8 @@ public final class LinkstateNlriParser implements NlriParser, NlriSerializer {
             serializeLocalNodeDescriptor(builder, objectType);
         } else if (objectType.getChild(NODE_DESCRIPTORS_NID).isPresent()) {
             serializeNodeDescriptor(builder, objectType);
-        } else if (TeLspNlriSerializer.isTeLsp(objectType)) {
-            builder.setObjectType(TeLspNlriSerializer.serializeTeLsp(objectType));
+        } else if (AbstractTeLspNlriCodec.isTeLsp(objectType)) {
+            builder.setObjectType(AbstractTeLspNlriCodec.serializeTeLsp(objectType));
         } else {
             LOG.warn("Unknown Object Type: {}.", objectType);
         }
@@ -306,7 +242,7 @@ public final class LinkstateNlriParser implements NlriParser, NlriSerializer {
         // prefix descriptors
         final Optional<DataContainerChild<? extends PathArgument, ?>> prefixDescriptors = objectType.getChild(PREFIX_DESCRIPTORS_NID);
         if (prefixDescriptors.isPresent()) {
-            prefixBuilder.setPrefixDescriptors(PrefixNlriSerializer.serializePrefixDescriptors((ContainerNode) prefixDescriptors.get()));
+            prefixBuilder.setPrefixDescriptors(AbstractPrefixNlriParser.serializePrefixDescriptors((ContainerNode) prefixDescriptors.get()));
         }
         builder.setObjectType(prefixBuilder.build());
     }
similarity index 58%
rename from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/NodeNlriParser.java
rename to bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/NodeNlriParser.java
index c8efba11d81d0e10c266a4a9b3ff977ebd6b3572..83e167e1bedecdfbddaa25f154c06b747c0f1041 100644 (file)
@@ -5,30 +5,26 @@
  * 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;
+package org.opendaylight.protocol.bgp.linkstate.impl.nlri;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Optional;
-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.spi.TlvUtil;
-import org.opendaylight.protocol.bgp.parser.BGPParsingException;
-import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.protocol.util.Ipv4Util;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.AreaIdTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.AsNumTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.BgpRouterIdTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.DomainIdTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.tlvs.MemAsNumTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.spi.AbstractNlriTypeCodec;
+import org.opendaylight.protocol.bgp.linkstate.spi.pojo.SimpleNlriTypeRegistry;
 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.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.epe.rev150622.EpeNodeDescriptors;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.AreaIdentifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.DomainIdentifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NlriType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.OspfInterfaceIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.isis.lan.identifier.IsIsRouterIdentifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.isis.lan.identifier.IsIsRouterIdentifierBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.ObjectType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.CLinkstateDestination;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.NodeCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.NodeCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LocalNodeDescriptors;
@@ -46,7 +42,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.link
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.IsisPseudonodeCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.OspfNodeCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.OspfNodeCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.OspfPseudonodeCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.OspfPseudonodeCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.isis.node._case.IsisNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.isis.node._case.IsisNodeBuilder;
@@ -63,46 +58,22 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgum
 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@VisibleForTesting
-public final class NodeNlriParser implements NlriTypeCaseParser, NlriTypeCaseSerializer {
-
-    private static final Logger LOG = LoggerFactory.getLogger(NodeNlriParser.class);
-
-    public NodeNlriParser() {
-    }
-
-    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;
-    private static final int BGP_ROUTER_ID = 516;
-    private static final int MEMBER_AS_NUMBER = 517;
-
-    /* Node Descriptor Type */
-    private static final int LOCAL_NODE_DESCRIPTORS_TYPE = 256;
+public final class NodeNlriParser extends AbstractNlriTypeCodec {
 
     /* Node Descriptor QNames */
     @VisibleForTesting
-    public static final NodeIdentifier AS_NUMBER_NID = new NodeIdentifier(QName.create(NodeDescriptors.QNAME, "as-number").intern());
+    public static final NodeIdentifier AS_NUMBER_NID = new NodeIdentifier(AsNumTlvParser.AS_NUMBER_QNAME);
     @VisibleForTesting
-    public static final NodeIdentifier AREA_NID = new NodeIdentifier(QName.create(NodeDescriptors.QNAME, "area-id").intern());
+    public static final NodeIdentifier AREA_NID = new NodeIdentifier(AreaIdTlvParser.AREA_ID_QNAME);
     @VisibleForTesting
-    public static final NodeIdentifier DOMAIN_NID = new NodeIdentifier(QName.create(NodeDescriptors.QNAME, "domain-id").intern());
+    public static final NodeIdentifier DOMAIN_NID = new NodeIdentifier(DomainIdTlvParser.DOMAIN_ID_QNAME);
     @VisibleForTesting
-    public static final NodeIdentifier ROUTER_NID = new NodeIdentifier(CRouterIdentifier.QNAME);
+    private static final NodeIdentifier ROUTER_NID = new NodeIdentifier(CRouterIdentifier.QNAME);
     @VisibleForTesting
-    public static final NodeIdentifier BGP_ROUTER_NID = new NodeIdentifier(QName.create(NodeDescriptors.QNAME, "bgp-router-id").intern());
+    public static final NodeIdentifier BGP_ROUTER_NID = new NodeIdentifier(BgpRouterIdTlvParser.BGP_ROUTER_ID_QNAME);
     @VisibleForTesting
-    public static final NodeIdentifier MEMBER_ASN_NID = new NodeIdentifier(QName.create(NodeDescriptors.QNAME, "member-asn").intern());
+    public static final NodeIdentifier MEMBER_ASN_NID = new NodeIdentifier(MemAsNumTlvParser.MEMBER_AS_NUMBER_QNAME);
 
     /* Router Identifier QNames */
     @VisibleForTesting
@@ -112,7 +83,7 @@ public final class NodeNlriParser implements NlriTypeCaseParser, NlriTypeCaseSer
     @VisibleForTesting
     public static final NodeIdentifier OSPF_NODE_NID = new NodeIdentifier(OspfNode.QNAME);
     @VisibleForTesting
-    public static final NodeIdentifier OSPF_PSEUDONODE_NID = new NodeIdentifier(OspfPseudonode.QNAME);
+    private static final NodeIdentifier OSPF_PSEUDONODE_NID = new NodeIdentifier(OspfPseudonode.QNAME);
     @VisibleForTesting
     public static final NodeIdentifier ISO_SYSTEM_NID = new NodeIdentifier(QName.create(NodeDescriptors.QNAME, "iso-system-id").intern());
     @VisibleForTesting
@@ -123,133 +94,22 @@ public final class NodeNlriParser implements NlriTypeCaseParser, NlriTypeCaseSer
     public static final NodeIdentifier OSPF_ROUTER_NID = new NodeIdentifier(QName.create(NodeDescriptors.QNAME, "ospf-router-id").intern());
     private static final NodeIdentifier LAN_IFACE_NID = new NodeIdentifier(QName.create(NodeDescriptors.QNAME, "lan-interface").intern());
 
-    static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier parseNodeDescriptors(final ByteBuf buffer, final NlriType nlriType, final boolean local) throws BGPParsingException {
-        AsNumber asnumber = null;
-        DomainIdentifier bgpId = null;
-        AreaIdentifier ai = null;
-        CRouterIdentifier routerId = null;
-        AsNumber memberAsn = null;
-        Ipv4Address bgpRouterId = null;
-        while (buffer.isReadable()) {
-            final int type = buffer.readUnsignedShort();
-            final int length = buffer.readUnsignedShort();
-            final ByteBuf value = buffer.readSlice(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;
-            case BGP_ROUTER_ID:
-                bgpRouterId = Ipv4Util.addressForByteBuf(value);
-                LOG.debug("Parsed BGP Router Identifier {}", bgpRouterId);
-                break;
-            case MEMBER_AS_NUMBER:
-                memberAsn = new AsNumber(value.readUnsignedInt());
-                LOG.debug("Parsed Member AsNumber {}", memberAsn);
-                break;
-            default:
-                throw new BGPParsingException("Node Descriptor not recognized, type: " + type);
-            }
-        }
-        LOG.trace("Finished parsing Node descriptors.");
-        return correctType(nlriType, local, asnumber, ai, routerId, bgpId, bgpRouterId, memberAsn);
-    }
-
-    private static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier correctType(final NlriType nlriType, final boolean local, final AsNumber asnumber, final AreaIdentifier ai, final CRouterIdentifier routerId, final DomainIdentifier bgpId, final Ipv4Address bgpRouterId, final AsNumber memberAsn) {
-        switch (nlriType) {
-        case Link:
-            if (local) {
-                return new LocalNodeDescriptorsBuilder().setAsNumber(asnumber).setAreaId(ai).setCRouterIdentifier(routerId).setDomainId(bgpId).setBgpRouterId(bgpRouterId).setMemberAsn(memberAsn).build();
-            } else {
-                return new RemoteNodeDescriptorsBuilder().setAsNumber(asnumber).setAreaId(ai).setCRouterIdentifier(routerId).setDomainId(bgpId).setBgpRouterId(bgpRouterId).setMemberAsn(memberAsn).build();
-            }
-        case Node:
-            return new NodeDescriptorsBuilder().setAsNumber(asnumber).setAreaId(ai).setCRouterIdentifier(routerId).setDomainId(bgpId).build();
-        case Ipv4Prefix:
-        case Ipv6Prefix:
-            return new AdvertisingNodeDescriptorsBuilder().setAsNumber(asnumber).setAreaId(ai).setCRouterIdentifier(routerId).setDomainId(bgpId).build();
-        default:
-            throw new IllegalStateException("NLRI type not recognized.");
-        }
-    }
-
-    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 serializeNodeIdentifier(final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.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);
-        }
+    @Override
+    protected ObjectType parseObjectType(final ByteBuf buffer) {
+        final NodeCaseBuilder builder = new NodeCaseBuilder();
+        builder.setNodeDescriptors(new NodeDescriptorsBuilder((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier) SimpleNlriTypeRegistry.getInstance().parseTlv(buffer)).build());
+        return builder.build();
     }
 
-    static void serializeEpeNodeDescriptors(final EpeNodeDescriptors epends, final ByteBuf buffer) {
-        if (epends.getBgpRouterId() != null) {
-            TlvUtil.writeTLV(BGP_ROUTER_ID, Ipv4Util.byteBufForAddress(epends.getBgpRouterId()), buffer);
-        }
-        if (epends.getMemberAsn() != null) {
-            TlvUtil.writeTLV(MEMBER_AS_NUMBER, Unpooled.copyInt(UnsignedInteger.valueOf(epends.getMemberAsn().getValue()).intValue()), buffer);
-        }
+    @Override
+    protected void serializeObjectType(final ObjectType objectType, final ByteBuf buffer) {
+        final NodeCase node = (NodeCase) objectType;
+        SimpleNlriTypeRegistry.getInstance().serializeTlv(NodeDescriptors.QNAME, node.getNodeDescriptors(), 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());
-        }
+    @Override
+    public int getNlriType() {
+        return NlriType.Node.getIntValue();
     }
 
     private static IsisNodeCase serializeIsisNode(final ContainerNode isis) {
@@ -401,22 +261,4 @@ public final class NodeNlriParser implements NlriTypeCaseParser, NlriTypeCaseSer
         builder.setCRouterIdentifier(serializeRouterId(descriptorsData));
         return builder.build();
     }
-
-    @Override
-    public ObjectType parseTypeNlri(final ByteBuf nlri, final NlriType type, final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier localdescriptor, final ByteBuf restNlri) throws BGPParsingException {
-
-        NodeCaseBuilder nodebuilder = new NodeCaseBuilder();
-        NodeCase nodecase = nodebuilder.setNodeDescriptors((NodeDescriptors) localdescriptor).build();
-        return nodecase;
-
-    }
-
-    @Override
-    public NlriType serializeTypeNlri(final CLinkstateDestination destination, final ByteBuf localdescs, final ByteBuf byteAggregator) {
-        final NodeCase nCase = ((NodeCase)destination.getObjectType());
-        NodeNlriParser.serializeNodeIdentifier(nCase.getNodeDescriptors(), localdescs);
-        TlvUtil.writeTLV(LOCAL_NODE_DESCRIPTORS_TYPE, localdescs, byteAggregator);
-        return NlriType.Node;
-    }
-
 }
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/TeLspIpv4NlriParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/TeLspIpv4NlriParser.java
new file mode 100644 (file)
index 0000000..5b4f794
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2015 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.impl.nlri;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.linkstate.spi.AbstractTeLspNlriCodec;
+import org.opendaylight.protocol.util.Ipv4Util;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NlriType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.ObjectType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.TeLspCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.te.lsp._case.address.family.Ipv4CaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.TunnelId;
+
+public final class TeLspIpv4NlriParser extends AbstractTeLspNlriCodec {
+    @Override
+    protected ObjectType parseObjectType(final ByteBuf buffer) {
+        final TeLspCaseBuilder builder = new TeLspCaseBuilder();
+        final Ipv4CaseBuilder ipv4CaseBuilder = new Ipv4CaseBuilder();
+        ipv4CaseBuilder.setIpv4TunnelSenderAddress(Ipv4Util.addressForByteBuf(buffer));
+        builder.setTunnelId(new TunnelId(buffer.readUnsignedShort()));
+        builder.setLspId(new LspId((long) buffer.readUnsignedShort()));
+        ipv4CaseBuilder.setIpv4TunnelEndpointAddress(Ipv4Util.addressForByteBuf(buffer));
+        return builder.setAddressFamily(ipv4CaseBuilder.build()).build();
+    }
+
+    @Override
+    public int getNlriType() {
+        return NlriType.Ipv4TeLsp.getIntValue();
+    }
+
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/TeLspIpv6NlriParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/TeLspIpv6NlriParser.java
new file mode 100644 (file)
index 0000000..a483707
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2015 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.impl.nlri;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.linkstate.spi.AbstractTeLspNlriCodec;
+import org.opendaylight.protocol.util.Ipv6Util;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NlriType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.ObjectType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.TeLspCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.te.lsp._case.address.family.Ipv6CaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.TunnelId;
+
+public final class TeLspIpv6NlriParser extends AbstractTeLspNlriCodec {
+    @Override
+    protected ObjectType parseObjectType(final ByteBuf buffer) {
+        final TeLspCaseBuilder builder = new TeLspCaseBuilder();
+        final Ipv6CaseBuilder ipv6CaseBuilder = new Ipv6CaseBuilder();
+        ipv6CaseBuilder.setIpv6TunnelSenderAddress(Ipv6Util.addressForByteBuf(buffer));
+        builder.setTunnelId(new TunnelId(buffer.readUnsignedShort()));
+        builder.setLspId(new LspId((long) buffer.readUnsignedShort()));
+        ipv6CaseBuilder.setIpv6TunnelEndpointAddress(Ipv6Util.addressForByteBuf(buffer));
+        return builder.setAddressFamily(ipv6CaseBuilder.build()).build();
+    }
+
+    @Override
+    public int getNlriType() {
+        return NlriType.Ipv6TeLsp.getIntValue();
+    }
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AbstractLocalNodeDescriptorTlvCodec.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AbstractLocalNodeDescriptorTlvCodec.java
new file mode 100644 (file)
index 0000000..20976bb
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2016 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.impl.tlvs;
+
+import io.netty.buffer.ByteBuf;
+import java.util.HashMap;
+import java.util.Map;
+import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
+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.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LocalNodeDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LocalNodeDescriptorsBuilder;
+import org.opendaylight.yangtools.yang.common.QName;
+
+
+public abstract class AbstractLocalNodeDescriptorTlvCodec<T extends NodeIdentifier> extends AbstractNodeDescriptorTlvCodec implements
+    LinkstateTlvParser<LocalNodeDescriptors>, LinkstateTlvParser.LinkstateTlvSerializer<T> {
+
+    private static final int LOCAL_NODE_DESCRIPTORS_TYPE = 256;
+
+    @Override
+    public final LocalNodeDescriptors parseTlvBody(final ByteBuf value) {
+        final Map<QName, Object> parsedSubTlvs = new HashMap<>();
+        final LocalNodeDescriptorsBuilder builder = new LocalNodeDescriptorsBuilder(parseNodeDescriptor(value, parsedSubTlvs));
+        builder.setBgpRouterId((Ipv4Address) parsedSubTlvs.get(BgpRouterIdTlvParser.BGP_ROUTER_ID_QNAME));
+        builder.setMemberAsn((AsNumber) parsedSubTlvs.get(MemAsNumTlvParser.MEMBER_AS_NUMBER_QNAME));
+        return builder.build();
+    }
+
+    @Override
+    public final int getType() {
+        return LOCAL_NODE_DESCRIPTORS_TYPE;
+    }
+
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AbstractNodeDescriptorTlvCodec.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AbstractNodeDescriptorTlvCodec.java
new file mode 100644 (file)
index 0000000..384c930
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2016 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.impl.tlvs;
+
+import io.netty.buffer.ByteBuf;
+import java.util.Map;
+import org.opendaylight.protocol.bgp.linkstate.spi.pojo.SimpleNlriTypeRegistry;
+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.rev150210.AreaIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.DomainIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.CRouterIdentifier;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
+import org.opendaylight.yangtools.yang.common.QName;
+
+abstract class AbstractNodeDescriptorTlvCodec {
+    protected final NodeIdentifier parseNodeDescriptor(final ByteBuf value, final Map<QName, Object> parsedSubTlvs) {
+        parsedSubTlvs.putAll(SimpleNlriTypeRegistry.getInstance().parseSubTlvs(value));
+        final AsNumber asNumber = (AsNumber) parsedSubTlvs.get(AsNumTlvParser.AS_NUMBER_QNAME);
+        final DomainIdentifier domainId = (DomainIdentifier) parsedSubTlvs.get(DomainIdTlvParser.DOMAIN_ID_QNAME);
+        final AreaIdentifier areaId = (AreaIdentifier) parsedSubTlvs.get(AreaIdTlvParser.AREA_ID_QNAME);
+        final CRouterIdentifier routerId = (CRouterIdentifier) parsedSubTlvs.get(CRouterIdentifier.QNAME);
+
+        return new NodeIdentifier() {
+            @Override
+            public Class<? extends DataContainer> getImplementedInterface() {
+                return NodeIdentifier.class;
+            }
+            @Override
+            public AsNumber getAsNumber() {
+                return asNumber;
+            }
+            @Override
+            public DomainIdentifier getDomainId() {
+                return domainId;
+            }
+            @Override
+            public AreaIdentifier getAreaId() {
+                return areaId;
+            }
+            @Override
+            public CRouterIdentifier getCRouterIdentifier() {
+                return routerId;
+            }
+        };
+    }
+
+    protected final void serializeNodeDescriptor(final NodeIdentifier tlv, final ByteBuf body) {
+        final SimpleNlriTypeRegistry tlvReg = SimpleNlriTypeRegistry.getInstance();
+        tlvReg.serializeTlv(AsNumTlvParser.AS_NUMBER_QNAME, tlv.getAsNumber(), body);
+        tlvReg.serializeTlv(DomainIdTlvParser.DOMAIN_ID_QNAME, tlv.getDomainId(), body);
+        tlvReg.serializeTlv(AreaIdTlvParser.AREA_ID_QNAME, tlv.getAreaId(), body);
+        tlvReg.serializeTlv(CRouterIdentifier.QNAME, tlv.getCRouterIdentifier(), body);
+    }
+
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AdvertisingNodeDescriptorTlvParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AdvertisingNodeDescriptorTlvParser.java
new file mode 100644 (file)
index 0000000..1f27ae6
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2016 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.impl.tlvs;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.prefix._case.AdvertisingNodeDescriptors;
+import org.opendaylight.yangtools.yang.common.QName;
+
+public final class AdvertisingNodeDescriptorTlvParser extends AbstractLocalNodeDescriptorTlvCodec<AdvertisingNodeDescriptors> {
+    @Override
+    public void serializeTlvBody(final AdvertisingNodeDescriptors tlv, final ByteBuf body) {
+        serializeNodeDescriptor(tlv, body);
+    }
+
+    @Override
+    public QName getTlvQName() {
+        return AdvertisingNodeDescriptors.QNAME;
+    }
+
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AreaIdTlvParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AreaIdTlvParser.java
new file mode 100644 (file)
index 0000000..f19d755
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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.impl.tlvs;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
+import org.opendaylight.protocol.util.ByteBufWriteUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.AreaIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.node._case.NodeDescriptors;
+import org.opendaylight.yangtools.yang.common.QName;
+
+public final class AreaIdTlvParser implements LinkstateTlvParser<AreaIdentifier>, LinkstateTlvParser.LinkstateTlvSerializer<AreaIdentifier> {
+
+    private static final int AREA_ID = 514;
+
+    public static final QName AREA_ID_QNAME = QName.create(NodeDescriptors.QNAME, "area-id").intern();
+
+    @Override
+    public void serializeTlvBody(final AreaIdentifier tlv, final ByteBuf body) {
+        ByteBufWriteUtil.writeUnsignedInt(tlv.getValue(), body);
+    }
+
+    @Override
+    public AreaIdentifier parseTlvBody(final ByteBuf value) {
+        return new AreaIdentifier(value.readUnsignedInt());
+    }
+
+    @Override
+    public int getType() {
+        return AREA_ID;
+    }
+
+    @Override
+    public QName getTlvQName() {
+        return AREA_ID_QNAME;
+    }
+
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AsNumTlvParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AsNumTlvParser.java
new file mode 100644 (file)
index 0000000..0f8aaf9
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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.impl.tlvs;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
+import org.opendaylight.protocol.util.ByteBufWriteUtil;
+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.rev150210.linkstate.object.type.node._case.NodeDescriptors;
+import org.opendaylight.yangtools.yang.common.QName;
+
+public final class AsNumTlvParser implements LinkstateTlvParser<AsNumber>, LinkstateTlvParser.LinkstateTlvSerializer<AsNumber> {
+
+    private static final int AS_NUMBER = 512;
+
+    public static final QName AS_NUMBER_QNAME = QName.create(NodeDescriptors.QNAME, "as-number").intern();
+
+    @Override
+    public void serializeTlvBody(final AsNumber tlv, final ByteBuf body) {
+        ByteBufWriteUtil.writeUnsignedInt(tlv.getValue(), body);
+    }
+
+    @Override
+    public AsNumber parseTlvBody(final ByteBuf value) {
+        return new AsNumber(value.readUnsignedInt());
+    }
+
+    @Override
+    public int getType() {
+        return AS_NUMBER;
+    }
+
+    @Override
+    public QName getTlvQName() {
+        return AS_NUMBER_QNAME;
+    }
+
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/BgpRouterIdTlvParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/BgpRouterIdTlvParser.java
new file mode 100644 (file)
index 0000000..1b58f67
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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.impl.tlvs;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
+import org.opendaylight.protocol.util.ByteBufWriteUtil;
+import org.opendaylight.protocol.util.Ipv4Util;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.epe.rev150622.EpeNodeDescriptors;
+import org.opendaylight.yangtools.yang.common.QName;
+
+public final class BgpRouterIdTlvParser implements LinkstateTlvParser<Ipv4Address>, LinkstateTlvParser.LinkstateTlvSerializer<Ipv4Address> {
+
+    private static final int BGP_ROUTER_ID = 516;
+
+    public static final QName BGP_ROUTER_ID_QNAME = QName.create(EpeNodeDescriptors.QNAME, "bgp-router-id").intern();
+
+
+    @Override
+    public void serializeTlvBody(final Ipv4Address tlv, final ByteBuf body) {
+        ByteBufWriteUtil.writeIpv4Address(tlv, body);
+    }
+
+    @Override
+    public Ipv4Address parseTlvBody(final ByteBuf value) {
+        return Ipv4Util.addressForByteBuf(value);
+    }
+
+    @Override
+    public int getType() {
+        return BGP_ROUTER_ID;
+    }
+
+    @Override
+    public QName getTlvQName() {
+        return BGP_ROUTER_ID_QNAME;
+    }
+
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/DomainIdTlvParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/DomainIdTlvParser.java
new file mode 100644 (file)
index 0000000..0596921
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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.impl.tlvs;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
+import org.opendaylight.protocol.util.ByteBufWriteUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.DomainIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.node._case.NodeDescriptors;
+import org.opendaylight.yangtools.yang.common.QName;
+
+public final class DomainIdTlvParser implements LinkstateTlvParser<DomainIdentifier>, LinkstateTlvParser.LinkstateTlvSerializer<DomainIdentifier> {
+
+    private static final int BGP_LS_ID = 513;
+
+    public static final QName DOMAIN_ID_QNAME = QName.create(NodeDescriptors.QNAME, "domain-id").intern();
+
+    @Override
+    public void serializeTlvBody(final DomainIdentifier tlv, final ByteBuf body) {
+        ByteBufWriteUtil.writeUnsignedInt(tlv.getValue(), body);
+    }
+
+    @Override
+    public DomainIdentifier parseTlvBody(final ByteBuf value) {
+        return new DomainIdentifier(value.readUnsignedInt());
+    }
+
+    @Override
+    public int getType() {
+        return BGP_LS_ID;
+    }
+
+    @Override
+    public QName getTlvQName() {
+        return DOMAIN_ID_QNAME;
+    }
+
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/Ipv4InterfaceTlvParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/Ipv4InterfaceTlvParser.java
new file mode 100644 (file)
index 0000000..c2d846e
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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.impl.tlvs;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
+import org.opendaylight.protocol.util.ByteBufWriteUtil;
+import org.opendaylight.protocol.util.Ipv4Util;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Ipv4InterfaceIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LinkDescriptors;
+import org.opendaylight.yangtools.yang.common.QName;
+
+public final class Ipv4InterfaceTlvParser implements LinkstateTlvParser<Ipv4InterfaceIdentifier>, LinkstateTlvParser.LinkstateTlvSerializer<Ipv4InterfaceIdentifier> {
+
+    private static final int IPV4_IFACE_ADDRESS = 259;
+
+    public static final QName IPV4_IFACE_ADDRESS_QNAME = QName.create(LinkDescriptors.QNAME, "ipv4-interface-address").intern();
+
+
+    @Override
+    public void serializeTlvBody(final Ipv4InterfaceIdentifier tlv, final ByteBuf body) {
+        ByteBufWriteUtil.writeIpv4Address(tlv, body);
+    }
+
+    @Override
+    public Ipv4InterfaceIdentifier parseTlvBody(final ByteBuf value) {
+        return new Ipv4InterfaceIdentifier(Ipv4Util.addressForByteBuf(value));
+    }
+
+    @Override
+    public int getType() {
+        return IPV4_IFACE_ADDRESS;
+    }
+
+    @Override
+    public QName getTlvQName() {
+        return IPV4_IFACE_ADDRESS_QNAME;
+    }
+
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/Ipv4NeighborTlvParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/Ipv4NeighborTlvParser.java
new file mode 100644 (file)
index 0000000..daeba13
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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.impl.tlvs;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
+import org.opendaylight.protocol.util.ByteBufWriteUtil;
+import org.opendaylight.protocol.util.Ipv4Util;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Ipv4InterfaceIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LinkDescriptors;
+import org.opendaylight.yangtools.yang.common.QName;
+
+public final class Ipv4NeighborTlvParser implements LinkstateTlvParser<Ipv4InterfaceIdentifier>, LinkstateTlvParser.LinkstateTlvSerializer<Ipv4InterfaceIdentifier> {
+
+    private static final int IPV4_NEIGHBOR_ADDRESS = 260;
+
+    public static final QName IPV4_NEIGHBOR_ADDRESS_QNAME = QName.create(LinkDescriptors.QNAME, "ipv4-neighbor-address").intern();
+
+
+    @Override
+    public void serializeTlvBody(final Ipv4InterfaceIdentifier tlv, final ByteBuf body) {
+        ByteBufWriteUtil.writeIpv4Address(tlv, body);
+    }
+
+    @Override
+    public Ipv4InterfaceIdentifier parseTlvBody(final ByteBuf value) {
+        return new Ipv4InterfaceIdentifier(Ipv4Util.addressForByteBuf(value));
+    }
+
+    @Override
+    public int getType() {
+        return IPV4_NEIGHBOR_ADDRESS;
+    }
+
+    @Override
+    public QName getTlvQName() {
+        return IPV4_NEIGHBOR_ADDRESS_QNAME;
+    }
+
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/Ipv6InterfaceTlvParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/Ipv6InterfaceTlvParser.java
new file mode 100644 (file)
index 0000000..3b4536a
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * 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.impl.tlvs;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
+import org.opendaylight.protocol.util.ByteBufWriteUtil;
+import org.opendaylight.protocol.util.Ipv6Util;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Ipv6InterfaceIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LinkDescriptors;
+import org.opendaylight.yangtools.yang.common.QName;
+
+public final class Ipv6InterfaceTlvParser implements LinkstateTlvParser<Ipv6InterfaceIdentifier>, LinkstateTlvParser.LinkstateTlvSerializer<Ipv6InterfaceIdentifier> {
+
+    private static final int IPV6_IFACE_ADDRESS = 261;
+
+    public static final QName IPV6_IFACE_ADDRESS_QNAME = QName.create(LinkDescriptors.QNAME, "ipv6-interface-address").intern();
+
+
+    @Override
+    public void serializeTlvBody(final Ipv6InterfaceIdentifier tlv, final ByteBuf body) {
+        ByteBufWriteUtil.writeIpv6Address(tlv, body);
+    }
+
+    @Override
+    public Ipv6InterfaceIdentifier parseTlvBody(final ByteBuf value) {
+        return new Ipv6InterfaceIdentifier(Ipv6Util.addressForByteBuf(value));
+    }
+
+    @Override
+    public int getType() {
+        return IPV6_IFACE_ADDRESS;
+    }
+
+    @Override
+    public QName getTlvQName() {
+        return IPV6_IFACE_ADDRESS_QNAME;
+    }
+
+}
+
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/Ipv6NeighborTlvParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/Ipv6NeighborTlvParser.java
new file mode 100644 (file)
index 0000000..47a741d
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * 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.impl.tlvs;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
+import org.opendaylight.protocol.util.ByteBufWriteUtil;
+import org.opendaylight.protocol.util.Ipv6Util;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Ipv6InterfaceIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LinkDescriptors;
+import org.opendaylight.yangtools.yang.common.QName;
+
+public final class Ipv6NeighborTlvParser implements LinkstateTlvParser<Ipv6InterfaceIdentifier>, LinkstateTlvParser.LinkstateTlvSerializer<Ipv6InterfaceIdentifier> {
+
+    private static final int IPV6_NEIGHBOR_ADDRESS = 262;
+
+    public static final QName IPV6_NEIGHBOR_ADDRESS_QNAME = QName.create(LinkDescriptors.QNAME, "ipv6-neighbor-address").intern();
+
+
+    @Override
+    public void serializeTlvBody(final Ipv6InterfaceIdentifier tlv, final ByteBuf body) {
+        ByteBufWriteUtil.writeIpv6Address(tlv, body);
+    }
+
+    @Override
+    public Ipv6InterfaceIdentifier parseTlvBody(final ByteBuf value) {
+        return new Ipv6InterfaceIdentifier(Ipv6Util.addressForByteBuf(value));
+    }
+
+    @Override
+    public int getType() {
+        return IPV6_NEIGHBOR_ADDRESS;
+    }
+
+    @Override
+    public QName getTlvQName() {
+        return IPV6_NEIGHBOR_ADDRESS_QNAME;
+    }
+
+}
+
+
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/LinkIdTlvParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/LinkIdTlvParser.java
new file mode 100644 (file)
index 0000000..de7df88
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * 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.impl.tlvs;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
+import org.opendaylight.protocol.util.ByteBufWriteUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkLrIdentifiers;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
+import org.opendaylight.yangtools.yang.common.QName;
+
+public final class LinkIdTlvParser implements LinkstateTlvParser.LinkstateTlvSerializer<LinkLrIdentifiers>, LinkstateTlvParser<LinkLrIdentifiers> {
+
+    private static final int LINK_LR_IDENTIFIERS = 258;
+
+    @Override
+    public void serializeTlvBody(final LinkLrIdentifiers tlv, final ByteBuf body) {
+        ByteBufWriteUtil.writeUnsignedInt(tlv.getLinkLocalIdentifier(), body);
+        ByteBufWriteUtil.writeUnsignedInt(tlv.getLinkRemoteIdentifier(), body);
+    }
+
+    @Override
+    public LinkLrIdentifiers parseTlvBody(final ByteBuf value) {
+        final long localId = value.readUnsignedInt();
+        final long remoteId = value.readUnsignedInt();
+        return new LinkLrIdentifiers() {
+            @Override
+            public Class<? extends DataContainer> getImplementedInterface() {
+                return LinkLrIdentifiers.class;
+            }
+            @Override
+            public Long getLinkRemoteIdentifier() {
+                return remoteId;
+            }
+            @Override
+            public Long getLinkLocalIdentifier() {
+                return localId;
+            }
+        };
+    }
+
+    @Override
+    public QName getTlvQName() {
+        return LinkLrIdentifiers.QNAME;
+    }
+
+    @Override
+    public int getType() {
+        return LINK_LR_IDENTIFIERS;
+    }
+}
\ No newline at end of file
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/LocalNodeDescriptorTlvParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/LocalNodeDescriptorTlvParser.java
new file mode 100644 (file)
index 0000000..dd84c1c
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * 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.impl.tlvs;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.linkstate.spi.pojo.SimpleNlriTypeRegistry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LocalNodeDescriptors;
+import org.opendaylight.yangtools.yang.common.QName;
+
+public final class LocalNodeDescriptorTlvParser extends AbstractLocalNodeDescriptorTlvCodec<LocalNodeDescriptors> {
+    @Override
+    public void serializeTlvBody(final LocalNodeDescriptors tlv, final ByteBuf body) {
+        serializeNodeDescriptor(tlv, body);
+        final SimpleNlriTypeRegistry tlvReg = SimpleNlriTypeRegistry.getInstance();
+        tlvReg.serializeTlv(BgpRouterIdTlvParser.BGP_ROUTER_ID_QNAME, tlv.getBgpRouterId(), body);
+        tlvReg.serializeTlv(MemAsNumTlvParser.MEMBER_AS_NUMBER_QNAME, tlv.getMemberAsn(), body);
+    }
+
+    @Override
+    public QName getTlvQName() {
+        return LocalNodeDescriptors.QNAME;
+    }
+
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/MemAsNumTlvParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/MemAsNumTlvParser.java
new file mode 100644 (file)
index 0000000..ab0a7dc
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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.impl.tlvs;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
+import org.opendaylight.protocol.util.ByteBufWriteUtil;
+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.epe.rev150622.EpeNodeDescriptors;
+import org.opendaylight.yangtools.yang.common.QName;
+
+public final class MemAsNumTlvParser implements LinkstateTlvParser<AsNumber>, LinkstateTlvParser.LinkstateTlvSerializer<AsNumber> {
+
+    private static final int MEMBER_AS_NUMBER = 517;
+
+    public static final QName MEMBER_AS_NUMBER_QNAME = QName.create(EpeNodeDescriptors.QNAME, "member-asn").intern();
+
+    @Override
+    public void serializeTlvBody(final AsNumber tlv, final ByteBuf body) {
+        ByteBufWriteUtil.writeUnsignedInt(tlv.getValue(), body);
+    }
+
+    @Override
+    public AsNumber parseTlvBody(final ByteBuf value) {
+        return new AsNumber(value.readUnsignedInt());
+    }
+
+    @Override
+    public int getType() {
+        return MEMBER_AS_NUMBER;
+    }
+
+    @Override
+    public QName getTlvQName() {
+        return MEMBER_AS_NUMBER_QNAME;
+    }
+
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/MultiTopoIdTlvParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/MultiTopoIdTlvParser.java
new file mode 100644 (file)
index 0000000..8b9dce2
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * 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.impl.tlvs;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
+import org.opendaylight.protocol.util.ByteBufWriteUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.TopologyIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LinkDescriptors;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+
+public final class MultiTopoIdTlvParser implements LinkstateTlvParser<TopologyIdentifier>, LinkstateTlvParser.LinkstateTlvSerializer<TopologyIdentifier> {
+
+    public static final QName MULTI_TOPOLOGY_ID_QNAME = QName.create(LinkDescriptors.QNAME, "multi-topology-id").intern();
+
+    @Override
+    public void serializeTlvBody(final TopologyIdentifier tlv, final ByteBuf body) {
+        ByteBufWriteUtil.writeUnsignedShort(tlv.getValue(), body);
+    }
+
+    @Override
+    public int getType() {
+        return TlvUtil.MULTI_TOPOLOGY_ID;
+    }
+
+    @Override
+    public TopologyIdentifier parseTlvBody(final ByteBuf value) {
+        return new TopologyIdentifier(value.readShort() & TlvUtil.TOPOLOGY_ID_OFFSET);
+    }
+
+    @Override
+    public QName getTlvQName() {
+        return MULTI_TOPOLOGY_ID_QNAME;
+    }
+
+    public static TopologyIdentifier serializeModel(final ContainerNode prefixDesc) {
+        if (prefixDesc.getChild(TlvUtil.MULTI_TOPOLOGY_NID).isPresent()) {
+            return new TopologyIdentifier((Integer) prefixDesc.getChild(TlvUtil.MULTI_TOPOLOGY_NID).get().getValue());
+        }
+        return null;
+    }
+}
+
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/NodeDescriptorTlvParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/NodeDescriptorTlvParser.java
new file mode 100644 (file)
index 0000000..997c518
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2016 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.impl.tlvs;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.node._case.NodeDescriptors;
+import org.opendaylight.yangtools.yang.common.QName;
+
+public final class NodeDescriptorTlvParser extends AbstractLocalNodeDescriptorTlvCodec<NodeDescriptors> {
+    @Override
+    public void serializeTlvBody(final NodeDescriptors tlv, final ByteBuf body) {
+        serializeNodeDescriptor(tlv, body);
+    }
+
+    @Override
+    public QName getTlvQName() {
+        return NodeDescriptors.QNAME;
+    }
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/OspfRouteTlvParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/OspfRouteTlvParser.java
new file mode 100644 (file)
index 0000000..a83678e
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * 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.impl.tlvs;
+
+import com.google.common.base.Optional;
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
+import org.opendaylight.protocol.util.ByteBufWriteUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.OspfRouteType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.prefix._case.PrefixDescriptors;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
+
+public final class OspfRouteTlvParser implements LinkstateTlvParser<OspfRouteType>, LinkstateTlvParser.LinkstateTlvSerializer<OspfRouteType> {
+
+    public static final QName OSPF_ROUTE_TYPE_QNAME = QName.create(PrefixDescriptors.QNAME, "ospf-route-type").intern();
+    public static final NodeIdentifier OSPF_ROUTE_NID = new NodeIdentifier(OspfRouteTlvParser.OSPF_ROUTE_TYPE_QNAME);
+    private static final int OSPF_ROUTE_TYPE = 264;
+
+    @Override
+    public void serializeTlvBody(final OspfRouteType tlv, final ByteBuf body) {
+        ByteBufWriteUtil.writeUnsignedByte((short) tlv.getIntValue(), body);
+    }
+
+    @Override
+    public int getType() {
+        return OSPF_ROUTE_TYPE;
+    }
+
+    @Override
+    public OspfRouteType parseTlvBody(final ByteBuf value) {
+        return OspfRouteType.forValue(value.readUnsignedByte());
+    }
+
+    @Override
+    public QName getTlvQName() {
+        return OSPF_ROUTE_TYPE_QNAME;
+    }
+
+    public static OspfRouteType serializeModel(final ContainerNode prefixDesc) {
+        final Optional<DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> ospfRoute = prefixDesc.getChild(OSPF_ROUTE_NID);
+        if (ospfRoute.isPresent()) {
+            return OspfRouteType.forValue(domOspfRouteTypeValue((String) ospfRoute.get().getValue()));
+        }
+        return null;
+    }
+
+
+    // FIXME : use codec
+    private static int domOspfRouteTypeValue(final String ospfRouteType) {
+        switch (ospfRouteType) {
+        case "intra-area":
+            return OspfRouteType.IntraArea.getIntValue();
+        case "inter-area":
+            return OspfRouteType.InterArea.getIntValue();
+        case "external1":
+            return OspfRouteType.External1.getIntValue();
+        case "external2":
+            return OspfRouteType.External2.getIntValue();
+        case "nssa1":
+            return OspfRouteType.Nssa1.getIntValue();
+        case "nssa2":
+            return OspfRouteType.Nssa2.getIntValue();
+        default:
+            return 0;
+        }
+    }
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/ReachTlvParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/ReachTlvParser.java
new file mode 100644 (file)
index 0000000..433bcc0
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2016 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.impl.tlvs;
+
+import com.google.common.annotations.VisibleForTesting;
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
+import org.opendaylight.protocol.util.ByteBufWriteUtil;
+import org.opendaylight.protocol.util.Ipv4Util;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.prefix._case.PrefixDescriptors;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class ReachTlvParser implements LinkstateTlvParser.LinkstateTlvSerializer<IpPrefix>, LinkstateTlvParser<IpPrefix> {
+    public static final QName IP_REACHABILITY_QNAME = QName.create(PrefixDescriptors.QNAME, "ip-reachability-information").intern();
+    @VisibleForTesting
+    public static final YangInstanceIdentifier.NodeIdentifier IP_REACH_NID = new YangInstanceIdentifier.NodeIdentifier(IP_REACHABILITY_QNAME);
+    private static final Logger LOG = LoggerFactory.getLogger(ReachTlvParser.class);
+    private static final int IP_REACHABILITY = 265;
+
+    @Override
+    public IpPrefix parseTlvBody(final ByteBuf value) {
+        return new IpPrefix(Ipv4Util.prefixForByteBuf(value));
+    }
+
+    @Override
+    public QName getTlvQName() {
+        return IP_REACHABILITY_QNAME;
+    }
+
+    @Override
+    public void serializeTlvBody(final IpPrefix tlv, final ByteBuf body) {
+        if (tlv.getIpv4Prefix() != null) {
+            ByteBufWriteUtil.writeMinimalPrefix(tlv.getIpv4Prefix(), body);
+        } else if (tlv.getIpv6Prefix() != null) {
+            ByteBufWriteUtil.writeMinimalPrefix(tlv.getIpv6Prefix(), body);
+        }
+    }
+
+    @Override
+    public int getType() {
+        return IP_REACHABILITY;
+    }
+
+    public static IpPrefix serializeModel(final ContainerNode prefixDesc) {
+        if (prefixDesc.getChild(IP_REACH_NID).isPresent()) {
+            final String prefix = (String) prefixDesc.getChild(IP_REACH_NID).get().getValue();
+            try {
+                Ipv4Util.bytesForPrefixBegin(new Ipv4Prefix(prefix));
+                return new IpPrefix(new Ipv4Prefix(prefix));
+            } catch (final IllegalArgumentException e) {
+                LOG.debug("Creating Ipv6 prefix because", e);
+                return new IpPrefix(new Ipv6Prefix(prefix));
+            }
+        }
+        return null;
+    }
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/RemoteNodeDescriptorTlvParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/RemoteNodeDescriptorTlvParser.java
new file mode 100644 (file)
index 0000000..4029f91
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2016 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.impl.tlvs;
+
+import io.netty.buffer.ByteBuf;
+import java.util.HashMap;
+import java.util.Map;
+import org.opendaylight.protocol.bgp.linkstate.spi.pojo.SimpleNlriTypeRegistry;
+import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
+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.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.RemoteNodeDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.RemoteNodeDescriptorsBuilder;
+import org.opendaylight.yangtools.yang.common.QName;
+
+public final class RemoteNodeDescriptorTlvParser extends AbstractNodeDescriptorTlvCodec implements LinkstateTlvParser<RemoteNodeDescriptors>, LinkstateTlvParser.LinkstateTlvSerializer<RemoteNodeDescriptors> {
+    private static final int REMOTE_NODE_DESCRIPTORS_TYPE = 257;
+
+    @Override
+    public void serializeTlvBody(final RemoteNodeDescriptors tlv, final ByteBuf body) {
+        serializeNodeDescriptor(tlv, body);
+        final SimpleNlriTypeRegistry tlvReg = SimpleNlriTypeRegistry.getInstance();
+        tlvReg.serializeTlv(BgpRouterIdTlvParser.BGP_ROUTER_ID_QNAME, tlv.getBgpRouterId(), body);
+        tlvReg.serializeTlv(MemAsNumTlvParser.MEMBER_AS_NUMBER_QNAME, tlv.getMemberAsn(), body);
+    }
+
+    @Override
+    public RemoteNodeDescriptors parseTlvBody(final ByteBuf value) {
+        final Map<QName, Object> parsedSubTlvs = new HashMap<>();
+        final RemoteNodeDescriptorsBuilder builder = new RemoteNodeDescriptorsBuilder(parseNodeDescriptor(value, parsedSubTlvs));
+        builder.setBgpRouterId((Ipv4Address) parsedSubTlvs.get(BgpRouterIdTlvParser.BGP_ROUTER_ID_QNAME));
+        builder.setMemberAsn((AsNumber) parsedSubTlvs.get(MemAsNumTlvParser.MEMBER_AS_NUMBER_QNAME));
+        return builder.build();
+    }
+
+    @Override
+    public QName getTlvQName() {
+        return RemoteNodeDescriptors.QNAME;
+    }
+
+    @Override
+    public int getType() {
+        return REMOTE_NODE_DESCRIPTORS_TYPE;
+    }
+
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/RouterIdTlvParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/RouterIdTlvParser.java
new file mode 100644 (file)
index 0000000..e0a3688
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * 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.impl.tlvs;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufWriteUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.OspfInterfaceIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.isis.lan.identifier.IsIsRouterIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.isis.lan.identifier.IsIsRouterIdentifierBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.CRouterIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.IsisNodeCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.IsisNodeCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.IsisPseudonodeCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.IsisPseudonodeCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.OspfNodeCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.OspfNodeCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.OspfPseudonodeCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.OspfPseudonodeCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.isis.node._case.IsisNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.isis.node._case.IsisNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.isis.pseudonode._case.IsisPseudonode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.isis.pseudonode._case.IsisPseudonodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.ospf.node._case.OspfNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.ospf.pseudonode._case.OspfPseudonode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.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.opendaylight.yangtools.yang.common.QName;
+
+public final class RouterIdTlvParser implements LinkstateTlvParser<CRouterIdentifier>, LinkstateTlvParser.LinkstateTlvSerializer<CRouterIdentifier> {
+
+    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 IGP_ROUTER_ID = 515;
+
+    @Override
+    public void serializeTlvBody(final CRouterIdentifier tlv, final ByteBuf body) {
+        if (tlv instanceof IsisNodeCase) {
+            final IsisNode isis = ((IsisNodeCase) tlv).getIsisNode();
+            body.writeBytes(isis.getIsoSystemId().getValue());
+        } else if (tlv instanceof IsisPseudonodeCase) {
+            final IsisPseudonode isis = ((IsisPseudonodeCase) tlv).getIsisPseudonode();
+            body.writeBytes(isis.getIsIsRouterIdentifier().getIsoSystemId().getValue());
+            ByteBufWriteUtil.writeUnsignedByte(isis.getPsn(), body);
+        } else if (tlv instanceof OspfNodeCase) {
+            ByteBufWriteUtil.writeUnsignedInt(((OspfNodeCase) tlv).getOspfNode().getOspfRouterId(), body);
+        } else if (tlv instanceof OspfPseudonodeCase) {
+            final OspfPseudonode node = ((OspfPseudonodeCase) tlv).getOspfPseudonode();
+            ByteBufWriteUtil.writeUnsignedInt(node.getOspfRouterId(), body);
+            ByteBufWriteUtil.writeUnsignedInt(node.getLanInterface().getValue(), body);
+        }
+    }
+
+    @Override
+    public CRouterIdentifier parseTlvBody(final ByteBuf value) {
+        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();
+        }
+        return null;
+    }
+
+    @Override
+    public int getType() {
+        return IGP_ROUTER_ID;
+    }
+
+    @Override
+    public QName getTlvQName() {
+        return CRouterIdentifier.QNAME;
+    }
+
+}
+
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
deleted file mode 100644 (file)
index 4427de4..0000000
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * 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.annotations.VisibleForTesting;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.ByteBufUtil;
-import io.netty.buffer.Unpooled;
-import org.opendaylight.protocol.bgp.linkstate.spi.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.rev150210.Ipv4InterfaceIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Ipv6InterfaceIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NlriType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.TopologyIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.ObjectType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.CLinkstateDestination;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.LinkCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.LinkCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LinkDescriptors;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LinkDescriptorsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LocalNodeDescriptors;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.RemoteNodeDescriptors;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@VisibleForTesting
-public final class LinkNlriParser implements NlriTypeCaseParser, NlriTypeCaseSerializer {
-
-    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;
-
-    /* Node Descriptor Type */
-    private static final int LOCAL_NODE_DESCRIPTORS_TYPE = 256;
-    private static final int REMOTE_NODE_DESCRIPTORS_TYPE = 257;
-
-
-    /* Link Descriptor QNames */
-    @VisibleForTesting
-    public static final NodeIdentifier IPV4_IFACE_NID = new NodeIdentifier(QName.create(LinkDescriptors.QNAME, "ipv4-interface-address").intern());
-    private static final NodeIdentifier IPV6_IFACE_NID = new NodeIdentifier(QName.create(LinkDescriptors.QNAME, "ipv6-interface-address").intern());
-    @VisibleForTesting
-    public static final NodeIdentifier IPV4_NEIGHBOR_NID = new NodeIdentifier(QName.create(LinkDescriptors.QNAME, "ipv4-neighbor-address").intern());
-    private static final NodeIdentifier IPV6_NEIGHBOR_NID = new NodeIdentifier(QName.create(LinkDescriptors.QNAME, "ipv6-neighbor-address").intern());
-    @VisibleForTesting
-    public static final NodeIdentifier LINK_LOCAL_NID = new NodeIdentifier(QName.create(LinkDescriptors.QNAME, "link-local-identifier").intern());
-    @VisibleForTesting
-    public static final NodeIdentifier LINK_REMOTE_NID = new NodeIdentifier(QName.create(LinkDescriptors.QNAME, "link-remote-identifier").intern());
-
-    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.readSlice(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);
-            }
-        }
-        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);
-        }
-    }
-
-    static LinkDescriptors serializeLinkDescriptors(final ContainerNode descriptors) {
-        final LinkDescriptorsBuilder linkDescBuilder = new LinkDescriptorsBuilder();
-
-        if (descriptors.getChild(LINK_LOCAL_NID).isPresent() && descriptors.getChild(LINK_REMOTE_NID).isPresent()) {
-            linkDescBuilder.setLinkLocalIdentifier((Long) descriptors.getChild(LINK_LOCAL_NID).get().getValue());
-            linkDescBuilder.setLinkRemoteIdentifier((Long) descriptors.getChild(LINK_REMOTE_NID).get().getValue());
-        }
-        if (descriptors.getChild(IPV4_IFACE_NID).isPresent()) {
-            linkDescBuilder.setIpv4InterfaceAddress(new Ipv4InterfaceIdentifier((String) descriptors.getChild(IPV4_IFACE_NID).get().getValue()));
-        }
-        if (descriptors.getChild(IPV6_IFACE_NID).isPresent()) {
-            linkDescBuilder.setIpv6InterfaceAddress(new Ipv6InterfaceIdentifier((String) descriptors.getChild(IPV6_IFACE_NID).get().getValue()));
-        }
-        if (descriptors.getChild(IPV4_NEIGHBOR_NID).isPresent()) {
-            linkDescBuilder.setIpv4NeighborAddress(new Ipv4InterfaceIdentifier((String) descriptors.getChild(IPV4_NEIGHBOR_NID).get().getValue()));
-        }
-        if (descriptors.getChild(IPV6_NEIGHBOR_NID).isPresent()) {
-            linkDescBuilder.setIpv6NeighborAddress(new Ipv6InterfaceIdentifier((String) descriptors.getChild(IPV6_NEIGHBOR_NID).get().getValue()));
-        }
-        if (descriptors.getChild(TlvUtil.MULTI_TOPOLOGY_NID).isPresent()) {
-            linkDescBuilder.setMultiTopologyId(new TopologyIdentifier((Integer) descriptors.getChild(TlvUtil.MULTI_TOPOLOGY_NID).get().getValue()));
-        }
-        return linkDescBuilder.build();
-    }
-
-
-    @Override
-    public ObjectType parseTypeNlri(final ByteBuf nlri, final NlriType type, final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier localdescriptor, final ByteBuf restNlri) throws BGPParsingException {
-
-        final int nodetype = restNlri.readUnsignedShort();
-        final int length = restNlri.readUnsignedShort();
-
-        RemoteNodeDescriptors remoteDescriptors = null;
-
-        if (nodetype == REMOTE_NODE_DESCRIPTORS_TYPE) {
-            remoteDescriptors = (RemoteNodeDescriptors) NodeNlriParser.parseNodeDescriptors(restNlri.readSlice(length), type, false);
-        }
-        LinkDescriptors linkdescriptor = parseLinkDescriptors(restNlri.slice());
-        LinkCaseBuilder linkbuilder = new LinkCaseBuilder();
-        LinkCase linkcase = linkbuilder.setLocalNodeDescriptors((LocalNodeDescriptors) localdescriptor).setRemoteNodeDescriptors(remoteDescriptors).setLinkDescriptors(linkdescriptor).build();
-        return linkcase;
-    }
-
-    @Override
-    public NlriType serializeTypeNlri(final CLinkstateDestination destination, final ByteBuf localdescs, final ByteBuf byteAggregator) {
-
-        final LinkCase lCase = ((LinkCase)destination.getObjectType());
-        NodeNlriParser.serializeNodeIdentifier(lCase.getLocalNodeDescriptors(), localdescs);
-        NodeNlriParser.serializeEpeNodeDescriptors(lCase.getLocalNodeDescriptors(), localdescs);
-        TlvUtil.writeTLV(LOCAL_NODE_DESCRIPTORS_TYPE, localdescs, byteAggregator);
-        final ByteBuf rdescs = Unpooled.buffer();
-        NodeNlriParser.serializeNodeIdentifier(lCase.getRemoteNodeDescriptors(), rdescs);
-        NodeNlriParser.serializeEpeNodeDescriptors(lCase.getRemoteNodeDescriptors(), rdescs);
-        TlvUtil.writeTLV(REMOTE_NODE_DESCRIPTORS_TYPE, rdescs, byteAggregator);
-        if (lCase.getLinkDescriptors() != null) {
-            LinkNlriParser.serializeLinkDescriptors(lCase.getLinkDescriptors(), byteAggregator);
-        }
-        return NlriType.Link;
-    }
-
-
-
-}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/NlriTypeCaseParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/NlriTypeCaseParser.java
deleted file mode 100644 (file)
index 9289a7f..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright (c) 2016 AT&T 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 org.opendaylight.protocol.bgp.parser.BGPParsingException;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NlriType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.ObjectType;
-
-/**
- * Common interface for encoding different NLRI types.
- */
-public interface NlriTypeCaseParser {
-
-    ObjectType parseTypeNlri(ByteBuf nlri, NlriType type, NodeIdentifier localdescriptor, ByteBuf restNlri) throws BGPParsingException;
-
-}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/PrefixIpv4NlriParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/PrefixIpv4NlriParser.java
deleted file mode 100644 (file)
index 062120a..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * 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.annotations.VisibleForTesting;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.ByteBufUtil;
-import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
-import org.opendaylight.protocol.bgp.parser.BGPParsingException;
-import org.opendaylight.protocol.util.Ipv4Util;
-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.rev150210.NlriType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.OspfRouteType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.TopologyIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.ObjectType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.PrefixCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.PrefixCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.prefix._case.AdvertisingNodeDescriptors;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.prefix._case.PrefixDescriptors;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.prefix._case.PrefixDescriptorsBuilder;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@VisibleForTesting
-public final class PrefixIpv4NlriParser implements NlriTypeCaseParser  {
-
-    private static final Logger LOG = LoggerFactory.getLogger(PrefixIpv4NlriParser.class);
-
-    /* Prefix Descriptor TLVs */
-    private static final int OSPF_ROUTE_TYPE = 264;
-    private static final int IP_REACHABILITY = 265;
-
-    /* Prefix Descriptor QNames */
-    @VisibleForTesting
-    public static final NodeIdentifier OSPF_ROUTE_NID = new NodeIdentifier(QName.create(PrefixDescriptors.QNAME, "ospf-route-type").intern());
-    @VisibleForTesting
-    public static final NodeIdentifier IP_REACH_NID = new NodeIdentifier(QName.create(PrefixDescriptors.QNAME, "ip-reachability-information").intern());
-
-    static PrefixDescriptors parseIpv4PrefixDescriptors(final ByteBuf buffer) throws BGPParsingException {
-        final PrefixDescriptorsBuilder builder = new PrefixDescriptorsBuilder();
-        while (buffer.isReadable()) {
-            final int type = buffer.readUnsignedShort();
-            final int length = buffer.readUnsignedShort();
-            final ByteBuf value = buffer.readSlice(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:
-                final IpPrefix prefix = new IpPrefix(Ipv4Util.prefixForByteBuf(value));
-                builder.setIpReachabilityInformation(prefix);
-                LOG.trace("Parsed IP reachability info: {}", prefix);
-                break;
-            default:
-                throw new BGPParsingException("Prefix Descriptor not recognized, type: " + type);
-            }
-        }
-        LOG.debug("Finished parsing Ipv4 Prefix descriptors.");
-        return builder.build();
-    }
-
-    @Override
-    public ObjectType parseTypeNlri(final ByteBuf nlri, final NlriType type, final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier localdescriptor, final ByteBuf restNlri) throws BGPParsingException {
-        PrefixCaseBuilder prefixbuilder = new PrefixCaseBuilder();
-        PrefixDescriptors prefdesc = parseIpv4PrefixDescriptors(restNlri);
-        PrefixCase prefixcase = prefixbuilder.setAdvertisingNodeDescriptors((AdvertisingNodeDescriptors) localdescriptor).setPrefixDescriptors(prefdesc).build();
-        return prefixcase;
-    }
-
-}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/PrefixIpv6NlriParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/PrefixIpv6NlriParser.java
deleted file mode 100644 (file)
index 32c15d4..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * 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.annotations.VisibleForTesting;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.ByteBufUtil;
-import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
-import org.opendaylight.protocol.bgp.parser.BGPParsingException;
-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.rev150210.NlriType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.OspfRouteType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.TopologyIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.ObjectType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.PrefixCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.PrefixCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.prefix._case.AdvertisingNodeDescriptors;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.prefix._case.PrefixDescriptors;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.prefix._case.PrefixDescriptorsBuilder;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@VisibleForTesting
-public final class PrefixIpv6NlriParser implements NlriTypeCaseParser {
-
-    private static final Logger LOG = LoggerFactory.getLogger(PrefixIpv6NlriParser.class);
-
-    /* Prefix Descriptor TLVs */
-    private static final int OSPF_ROUTE_TYPE = 264;
-    private static final int IP_REACHABILITY = 265;
-
-    /* Prefix Descriptor QNames */
-    @VisibleForTesting
-    public static final NodeIdentifier OSPF_ROUTE_NID = new NodeIdentifier(QName.create(PrefixDescriptors.QNAME, "ospf-route-type").intern());
-    @VisibleForTesting
-    public static final NodeIdentifier IP_REACH_NID = new NodeIdentifier(QName.create(PrefixDescriptors.QNAME, "ip-reachability-information").intern());
-
-    static PrefixDescriptors parseIpv6PrefixDescriptors(final ByteBuf buffer) throws BGPParsingException {
-        final PrefixDescriptorsBuilder builder = new PrefixDescriptorsBuilder();
-        while (buffer.isReadable()) {
-            final int type = buffer.readUnsignedShort();
-            final int length = buffer.readUnsignedShort();
-            final ByteBuf value = buffer.readSlice(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:
-                final IpPrefix prefix = new IpPrefix(Ipv6Util.prefixForByteBuf(value));
-                builder.setIpReachabilityInformation(prefix);
-                LOG.trace("Parsed IP reachability info: {}", prefix);
-                break;
-            default:
-                throw new BGPParsingException("Prefix Descriptor not recognized, type: " + type);
-            }
-        }
-        LOG.debug("Finished parsing Ipv6 Prefix descriptors.");
-        return builder.build();
-    }
-
-    @Override
-    public ObjectType parseTypeNlri(final ByteBuf nlri, final NlriType type, final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier localdescriptor, final ByteBuf restNlri) throws BGPParsingException {
-        PrefixCaseBuilder prefixbuilder = new PrefixCaseBuilder();
-        PrefixDescriptors prefdesc = parseIpv6PrefixDescriptors(restNlri);
-        PrefixCase prefixcase = prefixbuilder.setAdvertisingNodeDescriptors((AdvertisingNodeDescriptors) localdescriptor).setPrefixDescriptors(prefdesc).build();
-        return prefixcase;
-    }
-
-}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/PrefixNlriSerializer.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/PrefixNlriSerializer.java
deleted file mode 100644 (file)
index 131da71..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * 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.annotations.VisibleForTesting;
-import com.google.common.base.Optional;
-import com.google.common.primitives.UnsignedBytes;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
-import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
-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.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NlriType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.OspfRouteType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.TopologyIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.CLinkstateDestination;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.PrefixCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.prefix._case.PrefixDescriptors;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.prefix._case.PrefixDescriptorsBuilder;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public final class PrefixNlriSerializer implements NlriTypeCaseSerializer {
-
-    private static final Logger LOG = LoggerFactory.getLogger(PrefixNlriSerializer.class);
-
-
-    /* Prefix Descriptor TLVs */
-    private static final int OSPF_ROUTE_TYPE = 264;
-    private static final int IP_REACHABILITY = 265;
-
-    /* Node Descriptor Type */
-    private static final int LOCAL_NODE_DESCRIPTORS_TYPE = 256;
-
-    /* Prefix Descriptor QNames */
-    @VisibleForTesting
-    public static final NodeIdentifier OSPF_ROUTE_NID = new NodeIdentifier(QName.create(PrefixDescriptors.QNAME, "ospf-route-type").intern());
-    @VisibleForTesting
-    public static final NodeIdentifier IP_REACH_NID = new NodeIdentifier(QName.create(PrefixDescriptors.QNAME, "ip-reachability-information").intern());
-
-    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();
-
-            final ByteBuf buf;
-            if (prefix.getIpv4Prefix() != null) {
-                buf = Unpooled.buffer(Ipv4Util.IP4_LENGTH + 1);
-                ByteBufWriteUtil.writeMinimalPrefix(prefix.getIpv4Prefix(), buf);
-            } else if (prefix.getIpv6Prefix() != null) {
-                buf = Unpooled.buffer(Ipv6Util.IPV6_LENGTH + 1);
-                ByteBufWriteUtil.writeMinimalPrefix(prefix.getIpv6Prefix(), buf);
-            } else {
-                buf = null;
-            }
-            TlvUtil.writeTLV(IP_REACHABILITY, buf, buffer);
-        }
-    }
-
-    // FIXME : use codec
-    private static int domOspfRouteTypeValue(final String ospfRouteType) {
-        switch (ospfRouteType) {
-        case "intra-area":
-            return OspfRouteType.IntraArea.getIntValue();
-        case "inter-area":
-            return OspfRouteType.InterArea.getIntValue();
-        case "external1":
-            return OspfRouteType.External1.getIntValue();
-        case "external2":
-            return OspfRouteType.External2.getIntValue();
-        case "nssa1":
-            return OspfRouteType.Nssa1.getIntValue();
-        case "nssa2":
-            return OspfRouteType.Nssa2.getIntValue();
-        default:
-            return 0;
-        }
-    }
-
-    public static PrefixDescriptors serializePrefixDescriptors(final ContainerNode prefixDesc) {
-        final PrefixDescriptorsBuilder prefixDescBuilder = new PrefixDescriptorsBuilder();
-        if (prefixDesc.getChild(TlvUtil.MULTI_TOPOLOGY_NID).isPresent()) {
-            prefixDescBuilder.setMultiTopologyId(new TopologyIdentifier((Integer) prefixDesc.getChild(TlvUtil.MULTI_TOPOLOGY_NID).get().getValue()));
-        }
-        final Optional<DataContainerChild<? extends PathArgument, ?>> ospfRoute = prefixDesc.getChild(OSPF_ROUTE_NID);
-        if (ospfRoute.isPresent()) {
-            prefixDescBuilder.setOspfRouteType(OspfRouteType.forValue(domOspfRouteTypeValue((String) ospfRoute.get().getValue())));
-        }
-        if (prefixDesc.getChild(IP_REACH_NID).isPresent()) {
-            final String prefix = (String) prefixDesc.getChild(IP_REACH_NID).get().getValue();
-
-            try {
-                Ipv4Util.bytesForPrefixBegin(new Ipv4Prefix(prefix));
-                prefixDescBuilder.setIpReachabilityInformation(new IpPrefix(new Ipv4Prefix(prefix)));
-            } catch (final IllegalArgumentException e) {
-                LOG.debug("Creating Ipv6 prefix because", e);
-                prefixDescBuilder.setIpReachabilityInformation(new IpPrefix(new Ipv6Prefix(prefix)));
-            }
-        }
-        return prefixDescBuilder.build();
-    }
-
-    @Override
-    public NlriType serializeTypeNlri(final CLinkstateDestination destination, final ByteBuf localdescs, final ByteBuf byteAggregator)  {
-        final PrefixCase pCase = ((PrefixCase)destination.getObjectType());
-        NodeNlriParser.serializeNodeIdentifier(pCase.getAdvertisingNodeDescriptors(), localdescs);
-        TlvUtil.writeTLV(LOCAL_NODE_DESCRIPTORS_TYPE, localdescs, byteAggregator);
-        if (pCase.getPrefixDescriptors() != null) {
-            serializePrefixDescriptors(pCase.getPrefixDescriptors(), byteAggregator);
-            if (pCase.getPrefixDescriptors().getIpReachabilityInformation().getIpv4Prefix() != null) {
-                return NlriType.Ipv4Prefix;
-            } else {
-                return NlriType.Ipv6Prefix;
-            }
-        }
-        return null;
-    }
-
-}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/SimpleNlriTypeRegistry.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/SimpleNlriTypeRegistry.java
deleted file mode 100644 (file)
index 57010ef..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright (c) 2016 AT&T 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.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
-import io.netty.buffer.ByteBuf;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import org.opendaylight.protocol.bgp.parser.BGPParsingException;
-import org.opendaylight.protocol.concepts.AbstractRegistration;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NlriType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.ObjectType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.CLinkstateDestination;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public final class SimpleNlriTypeRegistry {
-
-    private static final Logger LOG = LoggerFactory.getLogger(SimpleNlriTypeRegistry.class);
-
-    private final ConcurrentMap<NlriType, NlriTypeCaseParser> parsers = new ConcurrentHashMap<>();
-    private final ConcurrentMap<Class<? extends ObjectType>, NlriTypeCaseSerializer> serializers = new ConcurrentHashMap<>();
-    private static final SimpleNlriTypeRegistry SINGLETON = new SimpleNlriTypeRegistry();
-
-    private SimpleNlriTypeRegistry () {
-
-    }
-
-    public static SimpleNlriTypeRegistry getInstance() {
-        return SINGLETON;
-    }
-
-    public synchronized AutoCloseable registerNlriTypeSerializer(final Class<? extends ObjectType> classKey, final NlriTypeCaseSerializer serializer) {
-        this.serializers.put(classKey, serializer);
-
-        final Object lock = this;
-        return new AbstractRegistration() {
-            @Override
-            protected void removeRegistration() {
-                synchronized (lock) {
-                    SimpleNlriTypeRegistry.this.serializers.remove(classKey);
-                }
-            }
-        };
-
-    }
-
-    public synchronized AutoCloseable registerNlriTypeParser(final NlriType key, final NlriTypeCaseParser parser) {
-        this.parsers.put(key, parser);
-
-        final Object lock = this;
-        return new AbstractRegistration() {
-            @Override
-            protected void removeRegistration() {
-                synchronized (lock) {
-                    SimpleNlriTypeRegistry.this.parsers.remove(key);
-                }
-            }
-        };
-
-    }
-
-    @VisibleForTesting
-    public NlriTypeCaseSerializer getSerializer(Class<? extends ObjectType> objtyp) {
-        return this.serializers.get(objtyp);
-    }
-
-    @VisibleForTesting
-    public NlriTypeCaseParser getParser(NlriType nlrityp) {
-        return this.parsers.get(nlrityp);
-    }
-
-
-    public ObjectType parseNlriType (final ByteBuf buffer, final NlriType type, final NodeIdentifier localdescriptor, final ByteBuf restBuffer) throws BGPParsingException {
-        final NlriTypeCaseParser parser = this.parsers.get(type);
-        Preconditions.checkNotNull(parser, "Parser for Nlri type %s not found.", type);
-        ObjectType nlriObjectType = parser.parseTypeNlri(buffer, type, localdescriptor, restBuffer);
-        return nlriObjectType;
-    }
-
-    public NlriType serializeNlriType (final CLinkstateDestination destination, final ByteBuf localdesc, final ByteBuf byteAggregator) {
-        final NlriTypeCaseSerializer serializer = this.serializers.get(destination.getObjectType().getImplementedInterface());
-        Preconditions.checkNotNull(serializer, "Serializer for %s not found.", destination.getObjectType().getImplementedInterface().getSimpleName());
-        NlriType nlriTypeVal = serializer.serializeTypeNlri(destination, localdesc, byteAggregator);
-        if (nlriTypeVal == null) {
-            LOG.warn("NLRI Type value is null.");
-        }
-        return nlriTypeVal;
-    }
-}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/TeLspIpv4NlriParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/TeLspIpv4NlriParser.java
deleted file mode 100644 (file)
index e6a39ef..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2015 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 org.opendaylight.protocol.bgp.parser.BGPParsingException;
-import org.opendaylight.protocol.util.Ipv4Util;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NlriType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.ObjectType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.TeLspCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.TeLspCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.te.lsp._case.address.family.Ipv4CaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.TunnelId;
-
-public final class TeLspIpv4NlriParser implements NlriTypeCaseParser {
-
-    @Override
-    public ObjectType parseTypeNlri(final ByteBuf nlri, final NlriType type, final NodeIdentifier localdescriptor, final ByteBuf restNlri) throws BGPParsingException {
-        final TeLspCaseBuilder telspipv4builder = new TeLspCaseBuilder();
-        final Ipv4CaseBuilder ipv4Builder = new Ipv4CaseBuilder();
-        ipv4Builder.setIpv4TunnelSenderAddress(Ipv4Util.addressForByteBuf(nlri));
-        final TunnelId tunnelId = new TunnelId(nlri.readUnsignedShort());
-        final LspId lspId = new LspId((long)nlri.readUnsignedShort());
-        ipv4Builder.setIpv4TunnelEndpointAddress(Ipv4Util.addressForByteBuf(nlri));
-        TeLspCase telspipv4Case = telspipv4builder.setAddressFamily(ipv4Builder.build()).setLspId(lspId).setTunnelId(tunnelId).build();
-        return telspipv4Case;
-    }
-
-}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/TeLspIpv6NlriParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/TeLspIpv6NlriParser.java
deleted file mode 100644 (file)
index 6cd4bd3..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2015 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 org.opendaylight.protocol.bgp.parser.BGPParsingException;
-import org.opendaylight.protocol.util.Ipv6Util;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NlriType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.ObjectType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.TeLspCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.TeLspCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.te.lsp._case.address.family.Ipv6CaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.TunnelId;
-
-public final class TeLspIpv6NlriParser implements NlriTypeCaseParser {
-
-    @Override
-    public ObjectType parseTypeNlri(ByteBuf nlri, NlriType type, NodeIdentifier localdescriptor, ByteBuf restNlri) throws BGPParsingException {
-        final TeLspCaseBuilder telspipv6builder = new TeLspCaseBuilder();
-        final Ipv6CaseBuilder ipv6Builder = new Ipv6CaseBuilder();
-        ipv6Builder.setIpv6TunnelSenderAddress(Ipv6Util.addressForByteBuf(nlri));
-        final TunnelId tunnelId6 = new TunnelId(nlri.readUnsignedShort());
-        final LspId lspId6 = new LspId((long)nlri.readUnsignedShort());
-        ipv6Builder.setIpv6TunnelEndpointAddress(Ipv6Util.addressForByteBuf(nlri));
-        TeLspCase telspipv6Case = telspipv6builder.setAddressFamily(ipv6Builder.build()).setLspId(lspId6).setTunnelId(tunnelId6).build();
-        return telspipv6Case;
-    }
-
-}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/AbstractNlriTypeCodec.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/AbstractNlriTypeCodec.java
new file mode 100644 (file)
index 0000000..416db15
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2016 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.spi;
+
+import io.netty.buffer.ByteBuf;
+import java.math.BigInteger;
+import org.opendaylight.protocol.bgp.linkstate.spi.NlriTypeCaseParser;
+import org.opendaylight.protocol.bgp.linkstate.spi.NlriTypeCaseSerializer;
+import org.opendaylight.protocol.util.ByteBufWriteUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Identifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.ProtocolId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.ObjectType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.CLinkstateDestination;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.CLinkstateDestinationBuilder;
+
+public abstract class AbstractNlriTypeCodec implements NlriTypeCaseParser, NlriTypeCaseSerializer {
+    @Override
+    public final CLinkstateDestination parseTypeNlri(final ByteBuf nlri) {
+        final CLinkstateDestinationBuilder builder = new CLinkstateDestinationBuilder();
+        builder.setProtocolId(ProtocolId.forValue(nlri.readUnsignedByte()));
+        builder.setIdentifier(new Identifier(BigInteger.valueOf(nlri.readLong())));
+        builder.setObjectType(parseObjectType(nlri));
+        return builder.build();
+    }
+
+    @Override
+    public final void serializeTypeNlri(final CLinkstateDestination nlriType, final ByteBuf byteAggregator) {
+        ByteBufWriteUtil.writeUnsignedByte((short) nlriType.getProtocolId().getIntValue(), byteAggregator);
+        ByteBufWriteUtil.writeUnsignedLong(nlriType.getIdentifier().getValue(), byteAggregator);
+        serializeObjectType(nlriType.getObjectType(), byteAggregator);
+    }
+
+    protected abstract ObjectType parseObjectType(ByteBuf buffer);
+
+    protected abstract void serializeObjectType(ObjectType objectType, ByteBuf buffer);
+}
similarity index 60%
rename from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/TeLspNlriSerializer.java
rename to bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/AbstractTeLspNlriCodec.java
index 3d8abbb26f62d49328d43b54cb98838c181be3f5..2cbe866212a1b2edc47e3a83e8f80e3c89d7bcb8 100644 (file)
@@ -1,23 +1,20 @@
 /*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2016 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 static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Address;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Address;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeShort;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
+package org.opendaylight.protocol.bgp.linkstate.spi;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NlriType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.ObjectType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.CLinkstateDestination;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.TeLspCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.TeLspCaseBuilder;
@@ -32,8 +29,7 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
 
-@VisibleForTesting
-public final class TeLspNlriSerializer implements NlriTypeCaseSerializer {
+public abstract class AbstractTeLspNlriCodec extends AbstractNlriTypeCodec {
 
     @VisibleForTesting
     public static final YangInstanceIdentifier.NodeIdentifier LSP_ID = new YangInstanceIdentifier.NodeIdentifier(
@@ -48,54 +44,15 @@ public final class TeLspNlriSerializer implements NlriTypeCaseSerializer {
     public static final YangInstanceIdentifier.NodeIdentifier IPV4_TUNNEL_ENDPOINT_ADDRESS = new YangInstanceIdentifier
         .NodeIdentifier(QName.create(CLinkstateDestination.QNAME, "ipv4-tunnel-endpoint-address").intern());
     @VisibleForTesting
-    public static final YangInstanceIdentifier.NodeIdentifier IPV6_TUNNEL_SENDER_ADDRESS = new YangInstanceIdentifier
-        .NodeIdentifier( QName.create(CLinkstateDestination.QNAME, "ipv6-tunnel-sender-address").intern());
+    private static final YangInstanceIdentifier.NodeIdentifier IPV6_TUNNEL_SENDER_ADDRESS = new YangInstanceIdentifier
+        .NodeIdentifier(QName.create(CLinkstateDestination.QNAME, "ipv6-tunnel-sender-address").intern());
     @VisibleForTesting
-    public static final YangInstanceIdentifier.NodeIdentifier IPV6_TUNNEL_ENDPOINT_ADDRESS = new YangInstanceIdentifier
+    private static final YangInstanceIdentifier.NodeIdentifier IPV6_TUNNEL_ENDPOINT_ADDRESS = new YangInstanceIdentifier
         .NodeIdentifier(QName.create(CLinkstateDestination.QNAME, "ipv6-tunnel-endpoint-address").intern());
 
     @VisibleForTesting
     public static final YangInstanceIdentifier.NodeIdentifier ADDRESS_FAMILY = new YangInstanceIdentifier.NodeIdentifier(AddressFamily.QNAME);
 
-    public static NlriType serializeIpvTSA(final AddressFamily addressFamily, final ByteBuf body) {
-        if (addressFamily.equals(Ipv6Case.class)) {
-            final Ipv6Address ipv6 = ((Ipv6Case) addressFamily).getIpv6TunnelSenderAddress();
-            Preconditions.checkArgument(ipv6 != null, "Ipv6TunnelSenderAddress is mandatory.");
-            writeIpv6Address(ipv6, body);
-            return NlriType.Ipv6TeLsp;
-        }
-
-        final Ipv4Address ipv4 = ((Ipv4Case) addressFamily).getIpv4TunnelSenderAddress();
-        Preconditions.checkArgument(ipv4 != null, "Ipv4TunnelSenderAddress is mandatory.");
-        writeIpv4Address(ipv4, body);
-
-        return NlriType.Ipv4TeLsp;
-    }
-
-    public static void serializeTunnelID(final TunnelId tunnelID, final ByteBuf body) {
-        Preconditions.checkArgument(tunnelID != null, "TunnelId is mandatory.");
-        writeUnsignedShort(tunnelID.getValue(), body);
-    }
-
-    public static void serializeLspID(final LspId lspId, final ByteBuf body) {
-        Preconditions.checkArgument(lspId != null, "LspId is mandatory.");
-        writeShort(lspId.getValue().shortValue(), body);
-    }
-
-    public static void serializeTEA(final AddressFamily addressFamily, final ByteBuf body) {
-        if (addressFamily.equals(Ipv6Case.class)) {
-            final Ipv6Address ipv6 = ((Ipv6Case) addressFamily).getIpv6TunnelEndpointAddress();
-            Preconditions.checkArgument(ipv6 != null, "Ipv6TunnelEndpointAddress is mandatory.");
-            writeIpv6Address(ipv6, body);
-            return;
-        }
-
-        final Ipv4Address ipv4 = ((Ipv4Case) addressFamily).getIpv4TunnelEndpointAddress();
-        Preconditions.checkArgument(ipv4 != null, "Ipv4TunnelEndpointAddress is mandatory.");
-        Preconditions.checkArgument(ipv4 != null, "Ipv4TunnelEndpointAddress is mandatory.");
-        writeIpv4Address(ipv4, body);
-    }
-
     public static boolean isTeLsp(final ChoiceNode objectType) {
         return objectType.getChild(ADDRESS_FAMILY).isPresent();
     }
@@ -111,7 +68,7 @@ public final class TeLspNlriSerializer implements NlriTypeCaseSerializer {
     }
 
     private static AddressFamily serializeAddressFamily(final ChoiceNode addressFamily, final boolean ipv4Case) {
-        if(ipv4Case) {
+        if (ipv4Case) {
             return new Ipv4CaseBuilder()
                 .setIpv4TunnelSenderAddress(new Ipv4Address((String) addressFamily.getChild(IPV4_TUNNEL_SENDER_ADDRESS).get().getValue()))
                 .setIpv4TunnelEndpointAddress(new Ipv4Address((String) addressFamily.getChild(IPV4_TUNNEL_ENDPOINT_ADDRESS).get().getValue()))
@@ -125,14 +82,31 @@ public final class TeLspNlriSerializer implements NlriTypeCaseSerializer {
     }
 
     @Override
-    public NlriType serializeTypeNlri(final CLinkstateDestination destination, final ByteBuf localdescs, final ByteBuf byteAggregator) {
-        final TeLspCase teLSP = ((TeLspCase) destination.getObjectType());
-        final AddressFamily afi = teLSP.getAddressFamily();
-        NlriType nlriType = serializeIpvTSA(afi, localdescs);
-        serializeTunnelID(teLSP.getTunnelId(), localdescs);
-        serializeLspID(teLSP.getLspId(), localdescs);
-        serializeTEA(afi, localdescs);
-        return nlriType;
+    protected final void serializeObjectType(final ObjectType objectType, final ByteBuf buffer) {
+        Preconditions.checkArgument(objectType instanceof TeLspCase);
+        final TeLspCase teLSP = (TeLspCase) objectType;
+        final AddressFamily addressFamily = teLSP.getAddressFamily();
+        if (addressFamily instanceof Ipv4Case) {
+            serializeIpv4Case(teLSP, (Ipv4Case) addressFamily, buffer);
+        } else {
+            serializeIpv6Case(teLSP, (Ipv6Case) addressFamily, buffer);
+        }
     }
 
+    private static void serializeIpv4Case(final TeLspCase teLSP, final Ipv4Case ipv4Case, final ByteBuf buffer) {
+        ByteBufWriteUtil.writeIpv4Address(ipv4Case.getIpv4TunnelSenderAddress(), buffer);
+        serializeTunnelIdAndLspId(buffer, teLSP);
+        ByteBufWriteUtil.writeIpv4Address(ipv4Case.getIpv4TunnelEndpointAddress(), buffer);
+    }
+
+    private static void serializeIpv6Case(final TeLspCase teLSP, final Ipv6Case ipv6Case, final ByteBuf buffer) {
+        ByteBufWriteUtil.writeIpv6Address(ipv6Case.getIpv6TunnelSenderAddress(), buffer);
+        serializeTunnelIdAndLspId(buffer, teLSP);
+        ByteBufWriteUtil.writeIpv6Address(ipv6Case.getIpv6TunnelEndpointAddress(), buffer);
+    }
+
+    private static void serializeTunnelIdAndLspId(final ByteBuf buffer, final TeLspCase teLSP) {
+        ByteBufWriteUtil.writeUnsignedShort(teLSP.getTunnelId().getValue(), buffer);
+        ByteBufWriteUtil.writeUnsignedShort(teLSP.getLspId().getValue().intValue(), buffer);
+    }
 }
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/BindingSubTlvsParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/BindingSubTlvsParser.java
new file mode 100644 (file)
index 0000000..751c019
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2016 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.spi;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.ProtocolId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.BindingSubTlv;
+
+public interface BindingSubTlvsParser {
+    BindingSubTlv parseSubTlv(ByteBuf slice, ProtocolId protocolId);
+
+    int getType();
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/BindingSubTlvsSerializer.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/BindingSubTlvsSerializer.java
new file mode 100644 (file)
index 0000000..6b8a269
--- /dev/null
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2016 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.spi;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.BindingSubTlv;
+
+public interface BindingSubTlvsSerializer {
+    void serializeSubTlv(BindingSubTlv bindingSubTlv, ByteBuf aggregator);
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/LinkstateTlvParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/LinkstateTlvParser.java
new file mode 100644 (file)
index 0000000..029cf02
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2016 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.spi;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.yangtools.yang.common.QName;
+
+public interface LinkstateTlvParser<T> {
+
+    T parseTlvBody(ByteBuf value);
+
+    QName getTlvQName();
+
+    interface LinkstateTlvSerializer<T> {
+
+        void serializeTlvBody(final T tlv, final ByteBuf body);
+
+        int getType();
+
+    }
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/NlriTypeCaseParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/NlriTypeCaseParser.java
new file mode 100644 (file)
index 0000000..fb5da77
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2016 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.spi;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.CLinkstateDestination;
+
+/**
+ * Common interface for encoding different NLRI types.
+ */
+public interface NlriTypeCaseParser {
+
+    CLinkstateDestination parseTypeNlri(ByteBuf nlri);
+
+}
similarity index 60%
rename from bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/nlri/NlriTypeCaseSerializer.java
rename to bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/NlriTypeCaseSerializer.java
index daf1f49f593f8283068524fe919cf7e619f1f5ea..001800e2e12e1d70a25ceb95943bdc3bdc12fa39 100644 (file)
@@ -1,14 +1,13 @@
 /*
- * Copyright (c) 2016 AT&T Inc. and others.  All rights reserved.
+ * Copyright (c) 2016 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;
+package org.opendaylight.protocol.bgp.linkstate.spi;
 
 import io.netty.buffer.ByteBuf;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NlriType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.CLinkstateDestination;
 
 /**
@@ -16,6 +15,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.link
  */
 public interface NlriTypeCaseSerializer {
 
-    NlriType serializeTypeNlri(CLinkstateDestination destination, ByteBuf localdescs, ByteBuf byteAggregator);
+    void serializeTypeNlri(CLinkstateDestination nlriType, ByteBuf byteAggregator);
+
+    int getNlriType();
 
 }
index b875083674d625809dc5bec4a31b52d4cd745722..1866d3d186f8f12fc5b69a3774ddd0f1f3ddb6c4 100644 (file)
@@ -17,26 +17,24 @@ 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 NodeIdentifier MULTI_TOPOLOGY_NID = new NodeIdentifier(QName.create(PrefixDescriptors.QNAME, "topology-identifier").intern());
     public static final int LOCAL_IPV4_ROUTER_ID = 1028;
     public static final int LOCAL_IPV6_ROUTER_ID = 1029;
+    private static final Logger LOG = LoggerFactory.getLogger(TlvUtil.class);
+    private TlvUtil() {
+        throw new UnsupportedOperationException();
+    }
 
     /**
      * Util method for writing TLV header.
+     *
      * @param type TLV type (2B)
      * @param value TLV value (2B)
      * @param byteAggregator final ByteBuf where the tlv should be serialized
      */
-    public static void writeTLV(final int type, final ByteBuf value, final ByteBuf byteAggregator){
+    public static void writeTLV(final int type, final ByteBuf value, final ByteBuf byteAggregator) {
         byteAggregator.writeShort(type);
         byteAggregator.writeShort(value.writerIndex());
         byteAggregator.writeBytes(value);
@@ -45,20 +43,4 @@ public final class TlvUtil {
             LOG.debug("Serialized tlv type {} to: {}", type, ByteBufUtil.hexDump(value));
         }
     }
-
-    /**
-     * Util method for writing Segment routing TLV header.
-     * @param type TLV type (1B)
-     * @param value TLV value (1B)
-     * @param byteAggregator final ByteBuf where the tlv should be serialized
-     */
-    public static void writeSrTLV(final int type, final ByteBuf value, final ByteBuf byteAggregator){
-        byteAggregator.writeByte(type);
-        byteAggregator.writeByte(value.writerIndex());
-        byteAggregator.writeBytes(value);
-        if (LOG.isDebugEnabled()) {
-            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/spi/pojo/SimpleBindingSubTlvsRegistry.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/pojo/SimpleBindingSubTlvsRegistry.java
new file mode 100644 (file)
index 0000000..ce8ef41
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2016 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.spi.pojo;
+
+import io.netty.buffer.ByteBuf;
+import java.util.ArrayList;
+import java.util.List;
+import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsParser;
+import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsSerializer;
+import org.opendaylight.protocol.concepts.HandlerRegistry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.ProtocolId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sid.tlv.BindingSubTlvs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sid.tlv.BindingSubTlvsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.BindingSubTlv;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class SimpleBindingSubTlvsRegistry {
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleBindingSubTlvsRegistry.class);
+    private static final SimpleBindingSubTlvsRegistry SINGLETON = new SimpleBindingSubTlvsRegistry();
+    private final HandlerRegistry<DataContainer, BindingSubTlvsParser, BindingSubTlvsSerializer> handlers = new HandlerRegistry<>();
+
+    private SimpleBindingSubTlvsRegistry() {
+    }
+
+
+    public static SimpleBindingSubTlvsRegistry getInstance() {
+        return SINGLETON;
+    }
+
+    public AutoCloseable registerBindingSubTlvsParser(final int bindingSubTlvsType, final BindingSubTlvsParser parser) {
+        return this.handlers.registerParser(bindingSubTlvsType, parser);
+    }
+
+    public AutoCloseable registerBindingSubTlvsSerializer(final Class<? extends BindingSubTlv> esiType, final BindingSubTlvsSerializer serializer) {
+        return this.handlers.registerSerializer(esiType, serializer);
+    }
+
+    public void serializeBindingSubTlvs(final List<BindingSubTlvs> bindingSubTlvs, final ByteBuf aggregator) {
+        for (final BindingSubTlvs subTlv : bindingSubTlvs) {
+            final BindingSubTlv bindingSubTlv = subTlv.getBindingSubTlv();
+            final BindingSubTlvsSerializer serializer = this.handlers.getSerializer(bindingSubTlv.getImplementedInterface());
+            if (serializer == null) {
+                LOG.info("Unknown binding sub Tlv type {}", subTlv);
+                return;
+            }
+            serializer.serializeSubTlv(bindingSubTlv, aggregator);
+        }
+    }
+
+    public List<BindingSubTlvs> parseBindingSubTlvs(final ByteBuf buffer, final ProtocolId protocolId) {
+        final List<BindingSubTlvs> subTlvs = new ArrayList<>();
+        if (buffer != null) {
+            while (buffer.isReadable()) {
+                final int type = buffer.readUnsignedShort();
+                final int length = buffer.readUnsignedShort();
+                final ByteBuf slice = buffer.readSlice(length);
+                final BindingSubTlvsParser parser = this.handlers.getParser(type);
+                if (parser == null) {
+                    return null;
+                }
+                subTlvs.add(new BindingSubTlvsBuilder().setBindingSubTlv(parser.parseSubTlv(slice, protocolId)).build());
+            }
+        }
+        return subTlvs;
+    }
+}
diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/pojo/SimpleNlriTypeRegistry.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/pojo/SimpleNlriTypeRegistry.java
new file mode 100644 (file)
index 0000000..65e4445
--- /dev/null
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) 2016 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.spi.pojo;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import java.util.HashMap;
+import java.util.Map;
+import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.spi.NlriTypeCaseParser;
+import org.opendaylight.protocol.bgp.linkstate.spi.NlriTypeCaseSerializer;
+import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
+import org.opendaylight.protocol.concepts.HandlerRegistry;
+import org.opendaylight.protocol.concepts.MultiRegistry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.ObjectType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.CLinkstateDestination;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class SimpleNlriTypeRegistry {
+
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleNlriTypeRegistry.class);
+    private static final SimpleNlriTypeRegistry SINGLETON = new SimpleNlriTypeRegistry();
+    private final HandlerRegistry<ObjectType, NlriTypeCaseParser, NlriTypeCaseSerializer> nlriRegistry = new HandlerRegistry<>();
+    private final MultiRegistry<QName, LinkstateTlvParser.LinkstateTlvSerializer<?>> tlvSerializers = new MultiRegistry<>();
+    private final MultiRegistry<Integer, LinkstateTlvParser<?>> tlvParsers = new MultiRegistry<>();
+
+    private SimpleNlriTypeRegistry() {
+    }
+
+    public static SimpleNlriTypeRegistry getInstance() {
+        return SINGLETON;
+    }
+
+    public AutoCloseable registerNlriParser(final int type, final NlriTypeCaseParser parser) {
+        return this.nlriRegistry.registerParser(type, parser);
+    }
+
+    public AutoCloseable registerNlriSerializer(final Class<? extends ObjectType> clazzType, final NlriTypeCaseSerializer serializer) {
+        return this.nlriRegistry.registerSerializer(clazzType, serializer);
+    }
+
+    public <T> AutoCloseable registerTlvParser(final int tlvType, final LinkstateTlvParser<T> parser) {
+        return this.tlvParsers.register(tlvType, parser);
+    }
+
+    public <T> AutoCloseable registerTlvSerializer(final QName tlvQName, final LinkstateTlvParser.LinkstateTlvSerializer<T> serializer) {
+        return this.tlvSerializers.register(tlvQName, serializer);
+    }
+
+    public CLinkstateDestination parseNlriType(final ByteBuf buffer) {
+        final int type = buffer.readUnsignedShort();
+        final int length = buffer.readUnsignedShort();
+        final NlriTypeCaseParser parser = this.nlriRegistry.getParser(type);
+        if (parser == null) {
+            LOG.warn("Linkstate NLRI parser for Type: {} was not found.", type);
+            return null;
+        }
+        return parser.parseTypeNlri(buffer.readSlice(length));
+    }
+
+    public void serializeNlriType(final CLinkstateDestination nlri, final ByteBuf byteAggregator) {
+        if (nlri == null) {
+            return;
+        }
+        Preconditions.checkNotNull(byteAggregator);
+        final ObjectType objectType = nlri.getObjectType();
+        final NlriTypeCaseSerializer serializer = this.nlriRegistry.getSerializer((Class<? extends ObjectType>) objectType.getImplementedInterface());
+        if (serializer == null) {
+            LOG.warn("Linkstate NLRI serializer for Type: {} was not found.", objectType.getImplementedInterface());
+        }
+        final ByteBuf nlriType = Unpooled.buffer();
+        serializer.serializeTypeNlri(nlri, nlriType);
+        TlvUtil.writeTLV(serializer.getNlriType(), nlriType, byteAggregator);
+    }
+
+    public <T> T parseTlv(final ByteBuf buffer) {
+        return parseTlv(buffer, getParser(buffer));
+    }
+
+    public Map<QName, Object> parseSubTlvs(final ByteBuf buffer) {
+        final Map<QName, Object> tlvs = new HashMap<>();
+        while (buffer.isReadable()) {
+            final LinkstateTlvParser<?> tlvParser = getParser(buffer);
+            final Object tlvBody = parseTlv(buffer, tlvParser);
+            if (tlvBody != null) {
+                tlvs.put(tlvParser.getTlvQName(), tlvBody);
+            }
+        }
+        return tlvs;
+    }
+
+    private <T> LinkstateTlvParser<T> getParser(final ByteBuf buffer) {
+        Preconditions.checkArgument(buffer != null && buffer.isReadable());
+        final int type = buffer.readUnsignedShort();
+        final LinkstateTlvParser<T> parser = (LinkstateTlvParser<T>) this.tlvParsers.get(type);
+        if (parser == null) {
+            LOG.warn("Linkstate TLV parser for Type: {} was not found.", type);
+        }
+        return parser;
+    }
+
+    private static <T> T parseTlv(final ByteBuf buffer, final LinkstateTlvParser<T> parser) {
+        if (parser == null) {
+            return null;
+        }
+        Preconditions.checkArgument(buffer != null && buffer.isReadable());
+        final int length = buffer.readUnsignedShort();
+        return parser.parseTlvBody(buffer.readSlice(length));
+    }
+
+
+    public <T> void serializeTlv(final QName tlvQName, final T tlv, final ByteBuf buffer) {
+        if (tlv == null) {
+            return;
+        }
+        Preconditions.checkNotNull(tlvQName);
+        Preconditions.checkNotNull(buffer);
+        final LinkstateTlvParser.LinkstateTlvSerializer<T> tlvSerializer = (LinkstateTlvParser.LinkstateTlvSerializer<T>) this.tlvSerializers.get(tlvQName);
+        if (tlvSerializer == null) {
+            LOG.warn("Linkstate TLV serializer for QName: {} was not found.", tlvQName);
+            return;
+        }
+        final ByteBuf body = Unpooled.buffer();
+        tlvSerializer.serializeTlvBody(tlv, body);
+        TlvUtil.writeTLV(tlvSerializer.getType(), body, buffer);
+    }
+}
index a640301709b18d802526eab3ee9d32aa28a2d5f9..be962e2824fe3abdc62f4c70fd8bd52ab8417971 100644 (file)
@@ -4,4 +4,4 @@
 # 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
-org.opendaylight.protocol.bgp.linkstate.BGPActivator
+org.opendaylight.protocol.bgp.linkstate.impl.BGPActivator
index 33a12a368f2c8498bcc0da9664eae1094e8871c6..3c5ffda5ea7b2dfa5a6a49e8d9eb6114c5c1f0c1 100644 (file)
@@ -4,4 +4,4 @@
 # 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
-org.opendaylight.protocol.bgp.linkstate.RIBActivator
+org.opendaylight.protocol.bgp.linkstate.impl.RIBActivator
index eabe9d12cc0f69151879d19607ad745f2394cf71..f5605cb86a6f2f03427b6ffcf23e0f3f891e1e88 100644 (file)
@@ -7,7 +7,7 @@
   <odl:clustered-app-config id="linkStateAppConfig"
       binding-class="org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.bgp.linkstate.app.config.rev160614.BgpLinkstateAppConfig"/>
 
-  <bean id="BGPActivator" class="org.opendaylight.protocol.bgp.linkstate.BGPActivator">
+  <bean id="BGPActivator" class="org.opendaylight.protocol.bgp.linkstate.impl.BGPActivator">
     <argument>
       <bean factory-ref="linkStateAppConfig" factory-method="isIanaLinkstateAttributeType"/>
     </argument>
     </argument>
   </bean>
 
-  <bean id="RIBActivator" class="org.opendaylight.protocol.bgp.linkstate.RIBActivator"/>
+  <bean id="RIBActivator" class="org.opendaylight.protocol.bgp.linkstate.impl.RIBActivator"/>
 
   <service ref="BGPActivator" interface="org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderActivator"
-          odl:type="org.opendaylight.protocol.bgp.linkstate.BGPActivator"/>
+          odl:type="org.opendaylight.protocol.bgp.linkstate.impl.BGPActivator"/>
 
   <service ref="RIBActivator" interface="org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderActivator"
-          odl:type="org.opendaylight.protocol.bgp.linkstate.RIBActivator"/>
+          odl:type="org.opendaylight.protocol.bgp.linkstate.impl.RIBActivator"/>
 </blueprint>
\ No newline at end of file
index 27c84ea78246153636a606ccb934087ff65e17b6..fcb8db65319571a4827987caab1154805dceec7b 100644 (file)
@@ -10,17 +10,10 @@ package org.opendaylight.protocol.bgp.linkstate;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+
 import org.junit.Test;
-import org.opendaylight.protocol.bgp.linkstate.nlri.LinkNlriParser;
-import org.opendaylight.protocol.bgp.linkstate.nlri.NodeNlriParser;
-import org.opendaylight.protocol.bgp.linkstate.nlri.PrefixIpv4NlriParser;
-import org.opendaylight.protocol.bgp.linkstate.nlri.PrefixIpv6NlriParser;
-import org.opendaylight.protocol.bgp.linkstate.nlri.PrefixNlriSerializer;
-import org.opendaylight.protocol.bgp.linkstate.nlri.SimpleNlriTypeRegistry;
-import org.opendaylight.protocol.bgp.linkstate.nlri.TeLspIpv4NlriParser;
-import org.opendaylight.protocol.bgp.linkstate.nlri.TeLspIpv6NlriParser;
-import org.opendaylight.protocol.bgp.linkstate.nlri.TeLspNlriSerializer;
+import org.opendaylight.protocol.bgp.linkstate.impl.BGPActivator;
+import org.opendaylight.protocol.bgp.linkstate.impl.RIBActivator;
 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
 import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
 import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext;
@@ -28,11 +21,6 @@ import org.opendaylight.protocol.bgp.rib.spi.SimpleRIBExtensionProviderContext;
 import org.opendaylight.protocol.rsvp.parser.spi.pojo.ServiceLoaderRSVPExtensionProviderContext;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateSubsequentAddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NlriType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.LinkCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.NodeCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.PrefixCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.TeLspCase;
 
 public class ActivatorTest {
 
@@ -40,8 +28,6 @@ public class ActivatorTest {
     public void testActivator() throws Exception {
         final BGPActivator act = new BGPActivator(true, ServiceLoaderRSVPExtensionProviderContext.getSingletonInstance().getRsvpRegistry());
         final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
-        final SimpleNlriTypeRegistry typeReg = SimpleNlriTypeRegistry.getInstance();
-
         assertNull(context.getAddressFamilyRegistry().classForFamily(16388));
         assertNull(context.getSubsequentAddressFamilyRegistry().classForFamily(71));
 
@@ -49,16 +35,6 @@ public class ActivatorTest {
 
         assertEquals(LinkstateAddressFamily.class, context.getAddressFamilyRegistry().classForFamily(16388));
         assertEquals(LinkstateSubsequentAddressFamily.class, context.getSubsequentAddressFamilyRegistry().classForFamily(71));
-        assertTrue(typeReg.getParser(NlriType.Node) instanceof NodeNlriParser);
-        assertTrue(typeReg.getParser(NlriType.Link) instanceof LinkNlriParser);
-        assertTrue(typeReg.getParser(NlriType.Ipv4Prefix) instanceof PrefixIpv4NlriParser);
-        assertTrue(typeReg.getParser(NlriType.Ipv6Prefix) instanceof PrefixIpv6NlriParser);
-        assertTrue(typeReg.getParser(NlriType.Ipv4TeLsp) instanceof TeLspIpv4NlriParser);
-        assertTrue(typeReg.getParser(NlriType.Ipv6TeLsp) instanceof TeLspIpv6NlriParser);
-        assertTrue(typeReg.getSerializer(NodeCase.class) instanceof NodeNlriParser);
-        assertTrue(typeReg.getSerializer(LinkCase.class) instanceof LinkNlriParser);
-        assertTrue(typeReg.getSerializer(PrefixCase.class) instanceof PrefixNlriSerializer);
-        assertTrue(typeReg.getSerializer(TeLspCase.class) instanceof TeLspNlriSerializer);
 
         act.close();
     }
index 6dd0e829c08d0c031daa30a849e547a57f3a6a9a..68a004c43f2669fe43b570ee7ca116f4b9e1266e 100644 (file)
@@ -20,10 +20,10 @@ import java.lang.reflect.InvocationTargetException;
 import java.util.Arrays;
 import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.protocol.bgp.linkstate.attribute.LinkAttributesParser;
-import org.opendaylight.protocol.bgp.linkstate.attribute.LinkstateAttributeParser;
-import org.opendaylight.protocol.bgp.linkstate.attribute.NodeAttributesParser;
-import org.opendaylight.protocol.bgp.linkstate.attribute.PrefixAttributesParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.LinkAttributesParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.LinkstateAttributeParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.NodeAttributesParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.PrefixAttributesParser;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.rsvp.parser.impl.RSVPActivator;
 import org.opendaylight.protocol.rsvp.parser.spi.RSVPExtensionProviderContext;
@@ -65,13 +65,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mult
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlriBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.Weight;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.adj.flags.Flags;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.adj.flags.flags.IsisAdjFlagsCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.adj.flags.flags.IsisAdjFlagsCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.sid.label.index.sid.label.index.LocalLabelCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.sid.label.index.sid.label.index.SidCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.sid.label.index.sid.label.index.SidCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AssociationType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.association.object.AssociationObject;
@@ -79,7 +76,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 
 public class LinkstateAttributeParserTest {
 
-    static final byte[] TE_LSP_ATTR = {0x00, (byte) 0x63, 0x00, (byte) 0x30, // TE LSP Attribute Type, lenght, value
+    private static final byte[] TE_LSP_ATTR = {0x00, (byte) 0x63, 0x00, (byte) 0x30, // TE LSP Attribute Type, lenght, value
         0x00, (byte) 0x20, (byte) 0x0c, 0x02,  // Lenght, Class, Ctype
         0x00, 0x00, 0x00, 0x07,
         0x01, 0x00, 0x00, 0x06,
@@ -269,7 +266,8 @@ public class LinkstateAttributeParserTest {
 
     @Test
     public void testPositiveV4Prefixes() throws BGPParsingException {
-        final AttributesBuilder builder = createUnreachBuilder(new PrefixCaseBuilder().setPrefixDescriptors(new PrefixDescriptorsBuilder().setIpReachabilityInformation(new IpPrefix(new Ipv4Prefix("127.0.0.1/32"))).build()).build());
+        final AttributesBuilder builder = createUnreachBuilder(new PrefixCaseBuilder().setPrefixDescriptors(
+            new PrefixDescriptorsBuilder().setIpReachabilityInformation(new IpPrefix(new Ipv4Prefix("127.0.0.1/32"))).build()).build());
         this.parser.parseAttribute(Unpooled.copiedBuffer(P4_ATTR), builder);
 
         final Attributes1 attrs = builder.getAugmentation(Attributes1.class);
index 3f166a7583ed389f043acae642971ced310c3aa4..b5993903e662050cc8118b68bfd9ae2f60f3b608 100644 (file)
@@ -10,6 +10,8 @@ package org.opendaylight.protocol.bgp.linkstate;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
+import static org.opendaylight.protocol.bgp.linkstate.impl.tlvs.OspfRouteTlvParser.OSPF_ROUTE_NID;
+import static org.opendaylight.protocol.bgp.linkstate.impl.tlvs.ReachTlvParser.IP_REACH_NID;
 
 import com.google.common.collect.Lists;
 import io.netty.buffer.ByteBuf;
@@ -17,24 +19,22 @@ import io.netty.buffer.Unpooled;
 import java.math.BigInteger;
 import java.util.List;
 import org.junit.Test;
-import org.opendaylight.protocol.bgp.linkstate.nlri.LinkNlriParser;
-import org.opendaylight.protocol.bgp.linkstate.nlri.LinkstateNlriParser;
-import org.opendaylight.protocol.bgp.linkstate.nlri.NodeNlriParser;
-import org.opendaylight.protocol.bgp.linkstate.nlri.PrefixIpv4NlriParser;
-import org.opendaylight.protocol.bgp.linkstate.nlri.PrefixIpv6NlriParser;
-import org.opendaylight.protocol.bgp.linkstate.nlri.PrefixNlriSerializer;
-import org.opendaylight.protocol.bgp.linkstate.nlri.SimpleNlriTypeRegistry;
-import org.opendaylight.protocol.bgp.linkstate.nlri.TeLspIpv4NlriParser;
-import org.opendaylight.protocol.bgp.linkstate.nlri.TeLspIpv6NlriParser;
-import org.opendaylight.protocol.bgp.linkstate.nlri.TeLspNlriSerializer;
+import org.opendaylight.protocol.bgp.linkstate.impl.BGPActivator;
+import org.opendaylight.protocol.bgp.linkstate.spi.AbstractTeLspNlriCodec;
+import org.opendaylight.protocol.bgp.linkstate.impl.nlri.LinkNlriParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.nlri.LinkstateNlriParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.nlri.NodeNlriParser;
+import org.opendaylight.protocol.bgp.linkstate.spi.pojo.SimpleNlriTypeRegistry;
 import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
+import org.opendaylight.protocol.rsvp.parser.spi.pojo.ServiceLoaderRSVPExtensionProviderContext;
 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.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.DomainIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NlriType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.OspfRouteType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.ProtocolId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.TopologyIdentifier;
@@ -131,7 +131,7 @@ public class LinkstateNlriParserTest {
         (byte) 0x00, (byte) 0x03, (byte) 0x10, (byte) 0xFF, (byte) 0xFF };
 
     private final byte[] teLspNlri = new byte[] { (byte) 0x00, (byte) 0x05, //NLRI Type Te-IPV4
-        (byte) 0x00, (byte) 0x12, // length
+        (byte) 0x00, (byte) 0x15, // length
         (byte) 0x08,    //Protocol-ID
         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, // Identifier
         (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, //IPv4 Tunnel Sender Address
@@ -140,37 +140,15 @@ public class LinkstateNlriParserTest {
         (byte) 0x04, (byte) 0x03, (byte) 0x02, (byte) 0x01 }; // IPv4 Tunnel End-point Address
 
     private CLinkstateDestination dest;
+    private SimpleNlriTypeRegistry registry;
 
     private void setUp(final byte[] data) throws BGPParsingException {
-        final LinkstateNlriParser parser = new LinkstateNlriParser(false);
+        final LinkstateNlriParser parser = new LinkstateNlriParser();
         final MpReachNlriBuilder builder = new MpReachNlriBuilder();
-        final SimpleNlriTypeRegistry testreg = SimpleNlriTypeRegistry.getInstance();
-
-        final NodeNlriParser nodeParser = new NodeNlriParser();
-        testreg.registerNlriTypeParser(NlriType.Node, nodeParser);
-        testreg.registerNlriTypeSerializer(NodeCase.class, nodeParser);
-
-        final LinkNlriParser linkParser = new LinkNlriParser();
-        testreg.registerNlriTypeParser(NlriType.Link, linkParser);
-        testreg.registerNlriTypeSerializer(LinkCase.class, linkParser);
-
-        final PrefixIpv4NlriParser ipv4PrefParser = new PrefixIpv4NlriParser();
-        testreg.registerNlriTypeParser(NlriType.Ipv4Prefix, ipv4PrefParser);
-
-        final PrefixIpv6NlriParser ipv6PrefParser = new PrefixIpv6NlriParser();
-        testreg.registerNlriTypeParser(NlriType.Ipv6Prefix, ipv6PrefParser);
-
-        final TeLspIpv4NlriParser telSPipv4Parser = new TeLspIpv4NlriParser();
-        testreg.registerNlriTypeParser(NlriType.Ipv4TeLsp, telSPipv4Parser);
-
-        final TeLspIpv6NlriParser telSPipv6Parser = new TeLspIpv6NlriParser();
-        testreg.registerNlriTypeParser(NlriType.Ipv6TeLsp, telSPipv6Parser);
-
-        final PrefixNlriSerializer prefixSerializer = new PrefixNlriSerializer();
-        testreg.registerNlriTypeSerializer(PrefixCase.class, prefixSerializer);
-
-        final TeLspNlriSerializer telSpSerializer = new TeLspNlriSerializer();
-        testreg.registerNlriTypeSerializer(TeLspCase.class, telSpSerializer);
+        this.registry = SimpleNlriTypeRegistry.getInstance();
+        final BGPActivator act = new BGPActivator(true, ServiceLoaderRSVPExtensionProviderContext.getSingletonInstance().getRsvpRegistry());
+        final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
+        act.start(context);
 
         parser.parseNlri(Unpooled.copiedBuffer(data), builder);
 
@@ -198,7 +176,7 @@ public class LinkstateNlriParserTest {
                new IsIsRouterIdentifierBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[] { 0, 0, 0, 0, 0, (byte) 0x39 })).build()).build()).build(), nodeD.getCRouterIdentifier());
 
         final ByteBuf buffer = Unpooled.buffer();
-        LinkstateNlriParser.serializeNlri(this.dest, buffer);
+        this.registry.serializeNlriType(this.dest, buffer);
         assertArrayEquals(this.nodeNlri, ByteArray.readAllBytes(buffer));
 
         // test BI form
@@ -296,7 +274,7 @@ public class LinkstateNlriParserTest {
         assertEquals("197.20.160.40", ld.getIpv4NeighborAddress().getValue());
 
         final ByteBuf buffer = Unpooled.buffer();
-        LinkstateNlriParser.serializeNlri(this.dest, buffer);
+        this.registry.serializeNlriType(this.dest, buffer);
         assertArrayEquals(this.linkNlri, ByteArray.readAllBytes(buffer));
 
         // test BI form
@@ -447,7 +425,7 @@ public class LinkstateNlriParserTest {
         assertEquals(new Ipv4Prefix("255.255.0.0/16"), pd.getIpReachabilityInformation().getIpv4Prefix());
 
         final ByteBuf buffer = Unpooled.buffer();
-        LinkstateNlriParser.serializeNlri(this.dest, buffer);
+        this.registry.serializeNlriType(this.dest, buffer);
         assertArrayEquals(this.prefixNlri, ByteArray.readAllBytes(buffer));
 
         // test BI form
@@ -508,13 +486,13 @@ public class LinkstateNlriParserTest {
         prefixDescriptors.addChild(multiTopologyId.build());
 
         final ImmutableLeafNodeBuilder<String> ipReachabilityInformation = new ImmutableLeafNodeBuilder<>();
-        ipReachabilityInformation.withNodeIdentifier(PrefixIpv4NlriParser.IP_REACH_NID);
+        ipReachabilityInformation.withNodeIdentifier(IP_REACH_NID);
         ipReachabilityInformation.withValue("255.255.0.0/16");
 
         prefixDescriptors.addChild(ipReachabilityInformation.build());
 
         final ImmutableLeafNodeBuilder<String> ospfRouteType = new ImmutableLeafNodeBuilder<>();
-        ospfRouteType.withNodeIdentifier(PrefixIpv4NlriParser.OSPF_ROUTE_NID);
+        ospfRouteType.withNodeIdentifier(OSPF_ROUTE_NID);
         ospfRouteType.withValue("external1");
 
         prefixDescriptors.addChild(ospfRouteType.build());
@@ -558,22 +536,22 @@ public class LinkstateNlriParserTest {
         objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);
 
         final ImmutableLeafNodeBuilder<Long> lspId = new ImmutableLeafNodeBuilder<>();
-        lspId.withNodeIdentifier(TeLspNlriSerializer.LSP_ID);
+        lspId.withNodeIdentifier(AbstractTeLspNlriCodec.LSP_ID);
         lspId.withValue(1L);
 
         final ImmutableLeafNodeBuilder<Integer> tunnelId = new ImmutableLeafNodeBuilder<>();
-        tunnelId.withNodeIdentifier(TeLspNlriSerializer.TUNNEL_ID);
+        tunnelId.withNodeIdentifier(AbstractTeLspNlriCodec.TUNNEL_ID);
         tunnelId.withValue(1);
 
         final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> addressFamily = Builders.choiceBuilder();
-        addressFamily.withNodeIdentifier(TeLspNlriSerializer.ADDRESS_FAMILY);
+        addressFamily.withNodeIdentifier(AbstractTeLspNlriCodec.ADDRESS_FAMILY);
 
         final ImmutableLeafNodeBuilder<String> ipv4TunnelSenderAddress = new ImmutableLeafNodeBuilder<>();
-        ipv4TunnelSenderAddress.withNodeIdentifier(TeLspNlriSerializer.IPV4_TUNNEL_SENDER_ADDRESS);
+        ipv4TunnelSenderAddress.withNodeIdentifier(AbstractTeLspNlriCodec.IPV4_TUNNEL_SENDER_ADDRESS);
         ipv4TunnelSenderAddress.withValue("1.2.3.4");
 
         final ImmutableLeafNodeBuilder<String> ipv4TunnelEndPointAddress = new ImmutableLeafNodeBuilder<>();
-        ipv4TunnelEndPointAddress.withNodeIdentifier(TeLspNlriSerializer.IPV4_TUNNEL_ENDPOINT_ADDRESS);
+        ipv4TunnelEndPointAddress.withNodeIdentifier(AbstractTeLspNlriCodec.IPV4_TUNNEL_ENDPOINT_ADDRESS);
         ipv4TunnelEndPointAddress.withValue("4.3.2.1");
 
         addressFamily.addChild(ipv4TunnelSenderAddress.build());
@@ -588,7 +566,7 @@ public class LinkstateNlriParserTest {
     }
     @Test
     public void testSerializeAttribute() throws BGPParsingException {
-        final LinkstateNlriParser parser = new LinkstateNlriParser(true);
+        final LinkstateNlriParser parser = new LinkstateNlriParser();
         setUp(this.prefixNlri);
         final List<CLinkstateDestination> dests = Lists.newArrayList(this.dest);
         final DestinationLinkstateCase dlc = new DestinationLinkstateCaseBuilder().setDestinationLinkstate(new DestinationLinkstateBuilder().setCLinkstateDestination(dests).build()).build();
index 6133474715d6e49339a6034b750cdd95d092526c..b6e3d338c416fabbbc009e434f7dc97c1a125b28 100644 (file)
@@ -20,7 +20,10 @@ import java.util.Collection;
 import java.util.Collections;
 import org.junit.Assert;
 import org.junit.Test;
-import org.opendaylight.protocol.bgp.linkstate.nlri.LinkstateNlriParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.BGPActivator;
+import org.opendaylight.protocol.bgp.linkstate.impl.LinkstateRIBSupport;
+import org.opendaylight.protocol.bgp.linkstate.impl.nlri.LinkstateNlriParser;
+import org.opendaylight.protocol.bgp.linkstate.spi.pojo.SimpleNlriTypeRegistry;
 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
 import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
 import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest;
@@ -101,7 +104,7 @@ public final class LinkstateRIBSupportTest extends AbstractRIBSupportTest {
         assertEquals(LinkstateAddressFamily.class, context.getAddressFamilyRegistry().classForFamily(16388));
         assertEquals(LinkstateSubsequentAddressFamily.class, context.getSubsequentAddressFamilyRegistry().classForFamily(71));
         final ByteBuf buffer = Unpooled.buffer();
-        LinkstateNlriParser.serializeNlri(LINKSTATE_DESTINATION, buffer);
+        SimpleNlriTypeRegistry.getInstance().serializeNlriType(LINKSTATE_DESTINATION, buffer);
         final byte[] arrayKey = ByteArray.readAllBytes(buffer);
         ROUTE_KEY = new LinkstateRouteKey(arrayKey);
         ROUTE = new LinkstateRouteBuilder().setKey(ROUTE_KEY).setDistinguisher(RD).setIdentifier(ID).setObjectType(OBJECT_TYPE2)
index 9d7d77d99fd343465a6ab88d184821e75ab22c8f..b212b5b740e4d484177d42d243a0559ab6d69d05 100644 (file)
@@ -98,11 +98,11 @@ public class ParserTest {
     /**
      * Used by other tests as well
      */
-    static final List<byte[]> inputBytes = new ArrayList<byte[]>();
+    private static final List<byte[]> inputBytes = new ArrayList<>();
 
-    private static int COUNTER = 4;
+    private static final int COUNTER = 4;
 
-    private static int MAX_SIZE = 300;
+    private static final int MAX_SIZE = 300;
 
     private static BGPUpdateMessageParser updateParser;
 
@@ -119,7 +119,7 @@ public class ParserTest {
                 }
                 final ByteArrayOutputStream bis = new ByteArrayOutputStream();
                 final byte[] data = new byte[MAX_SIZE];
-                int nRead = 0;
+                int nRead;
                 while ((nRead = is.read(data, 0, data.length)) != -1) {
                     bis.write(data, 0, nRead);
                 }
index 178a089cdda7692662e2b0a9992f548dd5cee9e4..4cfbbfa10e3b01ba93ecb9589fe8ccaf23caaf90 100644 (file)
@@ -18,14 +18,19 @@ import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.protocol.bgp.linkstate.attribute.sr.BindingSidLabelParser;
-import org.opendaylight.protocol.bgp.linkstate.attribute.sr.Ipv6SrPrefixAttributesParser;
-import org.opendaylight.protocol.bgp.linkstate.attribute.sr.RangeTlvParser;
-import org.opendaylight.protocol.bgp.linkstate.attribute.sr.SidLabelIndexParser;
-import org.opendaylight.protocol.bgp.linkstate.attribute.sr.SrLinkAttributesParser;
-import org.opendaylight.protocol.bgp.linkstate.attribute.sr.SrNodeAttributesParser;
-import org.opendaylight.protocol.bgp.linkstate.attribute.sr.SrPrefixAttributesParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.BGPActivator;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.BindingSidLabelParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.Ipv6SrPrefixAttributesParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.RangeTlvParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SidLabelIndexParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SrLinkAttributesParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SrNodeAttributesParser;
+import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SrPrefixAttributesParser;
+import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
+import org.opendaylight.protocol.rsvp.parser.spi.pojo.ServiceLoaderRSVPExtensionProviderContext;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.protocol.util.Ipv6Util;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
@@ -108,6 +113,13 @@ public class SrAttributeParserTest {
         .setBackup(Boolean.FALSE)
         .setSet(Boolean.FALSE).build();
 
+    @Before
+    public void setUp() throws Exception {
+        final BGPActivator act = new BGPActivator(true, ServiceLoaderRSVPExtensionProviderContext.getSingletonInstance().getRsvpRegistry());
+        final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
+        act.start(context);
+    }
+
     @Test
     public void testSrAlgorithm() {
         final byte[] bytes = { 0 };
@@ -191,7 +203,7 @@ public class SrAttributeParserTest {
         };
         final SrRange parsedRange = RangeTlvParser.parseSrRange(Unpooled.wrappedBuffer(tested), ProtocolId.IsisLevel1);
 
-        final List<SubTlvs> rangeSubTlvs = new ArrayList<SubTlvs>();
+        final List<SubTlvs> rangeSubTlvs = new ArrayList<>();
         addSubTlvs(rangeSubTlvs);
         final SrRange expected = new SrRangeBuilder().setInterArea(Boolean.FALSE).setRangeSize(5).setSubTlvs(rangeSubTlvs).build();
 
@@ -211,7 +223,7 @@ public class SrAttributeParserTest {
                 .setFlags(ISIS_PREFIX_FLAGS)
                 .setAlgorithm(Algorithm.StrictShortestPathFirst)
                 .setSidLabelIndex(new LocalLabelCaseBuilder().setLocalLabel(new MplsLabel(66048L)).build()).build()).build());
-        final List<BindingSubTlvs> bindingSubTlvs = new ArrayList<BindingSubTlvs>();
+        final List<BindingSubTlvs> bindingSubTlvs = new ArrayList<>();
         addBindingSubTlvs(bindingSubTlvs);
         rangeSubTlvs.add(new SubTlvsBuilder().setRangeSubTlv(
             new BindingSidTlvCaseBuilder()
@@ -253,8 +265,8 @@ public class SrAttributeParserTest {
             );
         final SrRange parsedRange = RangeTlvParser.parseSrRange(Unpooled.wrappedBuffer(tested), ProtocolId.IsisLevel1);
 
-        final List<SubTlvs> rangeSubTlvs = new ArrayList<SubTlvs>();
-        final List<BindingSubTlvs> bindingSubTlvs = new ArrayList<BindingSubTlvs>();
+        final List<SubTlvs> rangeSubTlvs = new ArrayList<>();
+        final List<BindingSubTlvs> bindingSubTlvs = new ArrayList<>();
         bindingSubTlvs.add(new BindingSubTlvsBuilder().setBindingSubTlv(
             new Ipv6EroCaseBuilder().setLoose(Boolean.FALSE).setAddress(new Ipv6Address(IPV6_A)).build()).build());
         bindingSubTlvs.add(new BindingSubTlvsBuilder().setBindingSubTlv(
index 6606fb9408ae953e93584e2a8eef595e03a4135d..7763e64c859f650caf20cbe9c916c89a97bc3fb8 100755 (executable)
@@ -115,7 +115,7 @@ public class ParserToSalTest extends AbstractDataBrokerTest {
         this.ext1 = new SimpleRIBExtensionProviderContext();
         this.ext2 = new SimpleRIBExtensionProviderContext();
         this.baseact = new RIBActivator();
-        this.lsact = new org.opendaylight.protocol.bgp.linkstate.RIBActivator();
+        this.lsact = new org.opendaylight.protocol.bgp.linkstate.impl.RIBActivator();
 
         this.baseact.startRIBExtensionProvider(this.ext1);
         this.lsact.startRIBExtensionProvider(this.ext2);