From: Milos Fabian Date: Thu, 14 Jul 2016 14:38:04 +0000 (+0200) Subject: Move IPv4/6 Unicast extension to bgp-inet X-Git-Tag: release/boron~73 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=5c7acb767406a36a4fcc78e4ebd10b9a8a1f85df;p=bgpcep.git Move IPv4/6 Unicast extension to bgp-inet Separates IPv4/6 Unicast multiprotocol extension from core implementation modules (rib-impl, parser-impl). Motivation: Moving code wiring to blueprint caused that rib-spi's RIBExtensionProviderActivator service is waiting for all RIB extensions activators and rib-impl contains such extension too. On the other hand, rib-impl's RIBImpl depends on rib-spi's RIBExtensionConsumerContext service. In a result cyclic dependency is created - neither blueprint container is resolved. Change-Id: Ie2eae4458382a67dd446b2260c70f7a542384b1f Signed-off-by: Milos Fabian --- diff --git a/bgp/bmp-impl/src/test/java/org/opendaylight/protocol/bmp/impl/app/BmpMonitorImplTest.java b/bgp/bmp-impl/src/test/java/org/opendaylight/protocol/bmp/impl/app/BmpMonitorImplTest.java index d6c356c989..30e60a9e25 100644 --- a/bgp/bmp-impl/src/test/java/org/opendaylight/protocol/bmp/impl/app/BmpMonitorImplTest.java +++ b/bgp/bmp-impl/src/test/java/org/opendaylight/protocol/bmp/impl/app/BmpMonitorImplTest.java @@ -49,10 +49,10 @@ import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCo import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; +import org.opendaylight.protocol.bgp.inet.RIBActivator; import org.opendaylight.protocol.bgp.parser.impl.BGPActivator; import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext; import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext; -import org.opendaylight.protocol.bgp.rib.impl.RIBActivator; import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext; import org.opendaylight.protocol.bgp.rib.spi.SimpleRIBExtensionProviderContext; import org.opendaylight.protocol.bmp.api.BmpDispatcher; diff --git a/bgp/flowspec/pom.xml b/bgp/flowspec/pom.xml index bf022f6331..d1d3e6e272 100644 --- a/bgp/flowspec/pom.xml +++ b/bgp/flowspec/pom.xml @@ -50,7 +50,7 @@ ${project.groupId} - bgp-parser-impl + bgp-inet ${project.groupId} diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/BGPActivator.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/BGPActivator.java index 29336718e5..1990c49271 100644 --- a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/BGPActivator.java +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/BGPActivator.java @@ -21,8 +21,8 @@ import org.opendaylight.protocol.bgp.flowspec.extended.communities.TrafficMarkin import org.opendaylight.protocol.bgp.flowspec.extended.communities.TrafficRateEcHandler; import org.opendaylight.protocol.bgp.flowspec.l3vpn.ipv4.FlowspecL3vpnIpv4NlriParser; import org.opendaylight.protocol.bgp.flowspec.l3vpn.ipv6.FlowspecL3vpnIpv6NlriParser; -import org.opendaylight.protocol.bgp.parser.impl.message.update.next.hop.Ipv4NextHopParserSerializer; -import org.opendaylight.protocol.bgp.parser.impl.message.update.next.hop.Ipv6NextHopParserSerializer; +import org.opendaylight.protocol.bgp.inet.codec.nexthop.Ipv4NextHopParserSerializer; +import org.opendaylight.protocol.bgp.inet.codec.nexthop.Ipv6NextHopParserSerializer; import org.opendaylight.protocol.bgp.parser.spi.AbstractBGPExtensionProviderActivator; import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.FlowspecL3vpnSubsequentAddressFamily; @@ -69,30 +69,30 @@ public final class BGPActivator extends AbstractBGPExtensionProviderActivator { final SimpleFlowspecIpv4NlriParser fsIpv4Handler = new SimpleFlowspecIpv4NlriParser(flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4, SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC)); final SimpleFlowspecIpv6NlriParser fsIpv6Handler = new SimpleFlowspecIpv6NlriParser(flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV6, SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC)); regs.add( - context.registerNlriParser( - Ipv4AddressFamily.class, FlowspecSubsequentAddressFamily.class, fsIpv4Handler, ipv4NextHopParser, Ipv4NextHopCase.class - ) - ); + context.registerNlriParser( + Ipv4AddressFamily.class, FlowspecSubsequentAddressFamily.class, fsIpv4Handler, ipv4NextHopParser, Ipv4NextHopCase.class + ) + ); regs.add( - context.registerNlriParser( - Ipv6AddressFamily.class, FlowspecSubsequentAddressFamily.class, fsIpv6Handler, ipv6NextHopParser, Ipv6NextHopCase.class - ) - ); + context.registerNlriParser( + Ipv6AddressFamily.class, FlowspecSubsequentAddressFamily.class, fsIpv6Handler, ipv6NextHopParser, Ipv6NextHopCase.class + ) + ); regs.add(context.registerNlriSerializer(FlowspecRoutes.class, fsIpv4Handler)); regs.add(context.registerNlriSerializer(FlowspecIpv6Routes.class, fsIpv6Handler)); final FlowspecL3vpnIpv4NlriParser fsL3vpnIpv4Handler = new FlowspecL3vpnIpv4NlriParser(flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4, SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN)); final FlowspecL3vpnIpv6NlriParser fsL3vpnIpv6Handler = new FlowspecL3vpnIpv6NlriParser(flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV6, SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN)); regs.add( - context.registerNlriParser( - Ipv4AddressFamily.class, FlowspecL3vpnSubsequentAddressFamily.class, fsL3vpnIpv4Handler, ipv4NextHopParser, Ipv4NextHopCase.class - ) - ); + context.registerNlriParser( + Ipv4AddressFamily.class, FlowspecL3vpnSubsequentAddressFamily.class, fsL3vpnIpv4Handler, ipv4NextHopParser, Ipv4NextHopCase.class + ) + ); regs.add( - context.registerNlriParser( - Ipv6AddressFamily.class, FlowspecL3vpnSubsequentAddressFamily.class, fsL3vpnIpv6Handler, ipv6NextHopParser, Ipv6NextHopCase.class - ) - ); + context.registerNlriParser( + Ipv6AddressFamily.class, FlowspecL3vpnSubsequentAddressFamily.class, fsL3vpnIpv6Handler, ipv6NextHopParser, Ipv6NextHopCase.class + ) + ); regs.add(context.registerNlriSerializer(FlowspecL3vpnIpv4Routes.class, fsL3vpnIpv4Handler)); regs.add(context.registerNlriSerializer(FlowspecL3vpnIpv6Routes.class, fsL3vpnIpv6Handler)); diff --git a/bgp/inet/pom.xml b/bgp/inet/pom.xml index a4a617b687..c993299381 100644 --- a/bgp/inet/pom.xml +++ b/bgp/inet/pom.xml @@ -44,6 +44,10 @@ ${project.groupId} bgp-rib-api + + ${project.groupId} + bgp-rib-spi + org.opendaylight.mdsal @@ -76,6 +80,26 @@ junit junit + + ${project.groupId} + bgp-rib-spi + test-jar + test + + + org.mockito + mockito-core + + + org.opendaylight.controller + sal-binding-broker-impl + test + + + ${project.groupId} + bgp-parser-impl + test + diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/AbstractIPRIBSupport.java b/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/AbstractIPRIBSupport.java similarity index 99% rename from bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/AbstractIPRIBSupport.java rename to bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/AbstractIPRIBSupport.java index a7cb472a5d..9e9a604867 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/AbstractIPRIBSupport.java +++ b/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/AbstractIPRIBSupport.java @@ -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.rib.impl; +package org.opendaylight.protocol.bgp.inet; import com.google.common.base.Optional; import com.google.common.base.Preconditions; diff --git a/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/BGPActivator.java b/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/BGPActivator.java index 026e673957..c3562c858e 100644 --- a/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/BGPActivator.java +++ b/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/BGPActivator.java @@ -9,15 +9,40 @@ package org.opendaylight.protocol.bgp.inet; import java.util.ArrayList; import java.util.List; +import org.opendaylight.protocol.bgp.inet.codec.Ipv4NlriParser; +import org.opendaylight.protocol.bgp.inet.codec.Ipv6BgpPrefixSidParser; +import org.opendaylight.protocol.bgp.inet.codec.Ipv6NlriParser; +import org.opendaylight.protocol.bgp.inet.codec.nexthop.Ipv4NextHopParserSerializer; +import org.opendaylight.protocol.bgp.inet.codec.nexthop.Ipv6NextHopParserSerializer; import org.opendaylight.protocol.bgp.parser.spi.AbstractBGPExtensionProviderActivator; import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.Ipv4Routes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.routes.Ipv6Routes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.bgp.prefix.sid.bgp.prefix.sid.tlvs.bgp.prefix.sid.tlv.Ipv6SidTlv; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily; +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; public final class BGPActivator extends AbstractBGPExtensionProviderActivator { @Override protected List startImpl(final BGPExtensionProviderContext context) { - final List regs = new ArrayList<>(2); + final List regs = new ArrayList<>(6); + + final Ipv4NextHopParserSerializer ipv4NextHopParser = new Ipv4NextHopParserSerializer(); + final Ipv4NlriParser ipv4Codec = new Ipv4NlriParser(); + regs.add(context.registerNlriParser(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, + ipv4Codec, ipv4NextHopParser, Ipv4NextHopCase.class, Ipv6NextHopCase.class)); + regs.add(context.registerNlriSerializer(Ipv4Routes.class, ipv4Codec)); + + final Ipv6NextHopParserSerializer ipv6NextHopParser = new Ipv6NextHopParserSerializer(); + final Ipv6NlriParser ipv6Codec = new Ipv6NlriParser(); + regs.add(context.registerNlriParser(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, ipv6Codec, + ipv6NextHopParser, Ipv4NextHopCase.class, Ipv6NextHopCase.class)); + regs.add(context.registerNlriSerializer(Ipv6Routes.class, ipv6Codec)); + final Ipv6BgpPrefixSidParser tlvHandler = new Ipv6BgpPrefixSidParser(); regs.add(context.registerBgpPrefixSidTlvParser(tlvHandler.getType(), tlvHandler)); regs.add(context.registerBgpPrefixSidTlvSerializer(Ipv6SidTlv.class, tlvHandler)); diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/IPv4RIBSupport.java b/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/IPv4RIBSupport.java similarity index 91% rename from bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/IPv4RIBSupport.java rename to bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/IPv4RIBSupport.java index a2e660382a..2b185ef72b 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/IPv4RIBSupport.java +++ b/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/IPv4RIBSupport.java @@ -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.rib.impl; +package org.opendaylight.protocol.bgp.inet; import java.util.ArrayList; import java.util.Collection; @@ -35,7 +35,7 @@ final class IPv4RIBSupport extends AbstractIPRIBSupport { private IPv4RIBSupport() { super(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.Ipv4Prefix.class, Ipv4AddressFamily.class, - Ipv4RoutesCase.class, Ipv4Routes.class, Ipv4Route.class, DestinationIpv4.QNAME, Ipv4Prefixes.QNAME); + Ipv4RoutesCase.class, Ipv4Routes.class, Ipv4Route.class, DestinationIpv4.QNAME, Ipv4Prefixes.QNAME); } static IPv4RIBSupport getInstance() { @@ -45,9 +45,9 @@ final class IPv4RIBSupport extends AbstractIPRIBSupport { private List extractPrefixes(final Collection routes) { final List prefs = new ArrayList<>(routes.size()); for (final MapEntryNode route : routes) { - final String prefix = (String) NormalizedNodes.findNode(route, this.routePrefixIdentifier()).get().getValue(); + final String prefix = (String) NormalizedNodes.findNode(route, routePrefixIdentifier()).get().getValue(); final Ipv4PrefixesBuilder prefixBuilder = new Ipv4PrefixesBuilder().setPrefix(new Ipv4Prefix(prefix)); - prefixBuilder.setPathId(PathIdUtil.buildPathId(route, this.routePathIdNid())); + prefixBuilder.setPathId(PathIdUtil.buildPathId(route, routePathIdNid())); prefs.add(prefixBuilder.build()); } return prefs; @@ -63,6 +63,6 @@ final class IPv4RIBSupport extends AbstractIPRIBSupport { @Override protected DestinationType buildWithdrawnDestination(@Nonnull final Collection routes) { return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv4CaseBuilder().setDestinationIpv4( - new DestinationIpv4Builder().setIpv4Prefixes(extractPrefixes(routes)).build()).build(); + new DestinationIpv4Builder().setIpv4Prefixes(extractPrefixes(routes)).build()).build(); } } diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/IPv6RIBSupport.java b/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/IPv6RIBSupport.java similarity index 86% rename from bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/IPv6RIBSupport.java rename to bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/IPv6RIBSupport.java index aff4d51c37..d5061a87eb 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/IPv6RIBSupport.java +++ b/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/IPv6RIBSupport.java @@ -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.rib.impl; +package org.opendaylight.protocol.bgp.inet; import java.util.ArrayList; import java.util.Collection; @@ -35,7 +35,7 @@ final class IPv6RIBSupport extends AbstractIPRIBSupport { private IPv6RIBSupport() { super(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.Ipv6Prefix.class, - Ipv6AddressFamily.class, Ipv6RoutesCase.class, Ipv6Routes.class, Ipv6Route.class, DestinationIpv6.QNAME, Ipv6Prefixes.QNAME); + Ipv6AddressFamily.class, Ipv6RoutesCase.class, Ipv6Routes.class, Ipv6Route.class, DestinationIpv6.QNAME, Ipv6Prefixes.QNAME); } static IPv6RIBSupport getInstance() { @@ -52,15 +52,15 @@ final class IPv6RIBSupport extends AbstractIPRIBSupport { @Override protected DestinationType buildWithdrawnDestination(@Nonnull final Collection routes) { return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.unreach.nlri.withdrawn.routes - .destination.type.DestinationIpv6CaseBuilder().setDestinationIpv6( - new DestinationIpv6Builder().setIpv6Prefixes(extractPrefixes(routes)).build()).build(); + .destination.type.DestinationIpv6CaseBuilder().setDestinationIpv6( + new DestinationIpv6Builder().setIpv6Prefixes(extractPrefixes(routes)).build()).build(); } private List extractPrefixes(final Collection routes) { final List prefs = new ArrayList<>(routes.size()); for (final MapEntryNode route : routes) { - final String prefix = (String) NormalizedNodes.findNode(route, this.routePrefixIdentifier()).get().getValue(); - prefs.add(new Ipv6PrefixesBuilder().setPathId(PathIdUtil.buildPathId(route, this.routePathIdNid())).setPrefix(new Ipv6Prefix(prefix)).build()); + final String prefix = (String) NormalizedNodes.findNode(route, routePrefixIdentifier()).get().getValue(); + prefs.add(new Ipv6PrefixesBuilder().setPathId(PathIdUtil.buildPathId(route, routePathIdNid())).setPrefix(new Ipv6Prefix(prefix)).build()); } return prefs; } diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RIBActivator.java b/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/RIBActivator.java similarity index 76% rename from bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RIBActivator.java rename to bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/RIBActivator.java index 78e75359a0..b8c735593c 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RIBActivator.java +++ b/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/RIBActivator.java @@ -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.rib.impl; +package org.opendaylight.protocol.bgp.inet; import com.google.common.collect.Lists; import java.util.List; @@ -20,7 +20,7 @@ public final class RIBActivator extends AbstractRIBExtensionProviderActivator { @Override protected List startRIBExtensionProviderImpl(final RIBExtensionProviderContext context) { return Lists.newArrayList( - (AutoCloseable)context.registerRIBSupport(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, IPv4RIBSupport.getInstance()), - (AutoCloseable)context.registerRIBSupport(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, IPv6RIBSupport.getInstance())); + (AutoCloseable)context.registerRIBSupport(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, IPv4RIBSupport.getInstance()), + (AutoCloseable)context.registerRIBSupport(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, IPv6RIBSupport.getInstance())); } } diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/Ipv4NlriParser.java b/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/codec/Ipv4NlriParser.java similarity index 59% rename from bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/Ipv4NlriParser.java rename to bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/codec/Ipv4NlriParser.java index 9b545295fc..9e9dd68456 100644 --- a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/Ipv4NlriParser.java +++ b/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/codec/Ipv4NlriParser.java @@ -1,11 +1,12 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2013, 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.parser.impl.message.update; + +package org.opendaylight.protocol.bgp.inet.codec; import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; @@ -19,16 +20,20 @@ import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil; import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint; 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.rev130715.Ipv4Prefix; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.prefixes.DestinationIpv4; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.prefixes.DestinationIpv4Builder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.prefixes.destination.ipv4.Ipv4Prefixes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.prefixes.destination.ipv4.Ipv4PrefixesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv4Case; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv4CaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.message.Nlri; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes; +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.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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily; @@ -36,15 +41,6 @@ import org.opendaylight.yangtools.yang.binding.DataObject; public final class Ipv4NlriParser implements NlriParser, NlriSerializer { - @Override - public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) { - Preconditions.checkArgument(attribute instanceof Nlri, "Attribute parameter is not a Nlri object."); - final Nlri nlri = (Nlri) attribute; - for (final Ipv4Prefix ipv4Prefix : nlri.getNlri()) { - ByteBufWriteUtil.writeMinimalPrefix(ipv4Prefix, byteAggregator); - } - } - private static DestinationIpv4 prefixes(final ByteBuf nlri, final PeerSpecificParserConstraint constraints, final Class afi, final Class safi) { final List prefixes = new ArrayList<>(); @@ -80,4 +76,32 @@ public final class Ipv4NlriParser implements NlriParser, NlriSerializer { builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv4CaseBuilder().setDestinationIpv4( prefixes(nlri, constraint, builder.getAfi(), builder.getSafi())).build()).build()); } + + @Override + public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) { + Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object."); + final Attributes pathAttributes = (Attributes) attribute; + final Attributes1 pathAttributes1 = pathAttributes.getAugmentation(Attributes1.class); + final Attributes2 pathAttributes2 = pathAttributes.getAugmentation(Attributes2.class); + if (pathAttributes1 != null) { + final AdvertizedRoutes advertizedRoutes = pathAttributes1.getMpReachNlri().getAdvertizedRoutes(); + if (advertizedRoutes != null && advertizedRoutes.getDestinationType() instanceof DestinationIpv4Case) { + final DestinationIpv4Case destinationIpv4Case = (DestinationIpv4Case) advertizedRoutes.getDestinationType(); + for (final Ipv4Prefixes ipv4Prefix : destinationIpv4Case.getDestinationIpv4().getIpv4Prefixes()) { + PathIdUtil.writePathId(ipv4Prefix.getPathId(), byteAggregator); + ByteBufWriteUtil.writeMinimalPrefix(ipv4Prefix.getPrefix(), byteAggregator); + } + } + } else if (pathAttributes2 != null) { + final WithdrawnRoutes withdrawnRoutes = pathAttributes2.getMpUnreachNlri().getWithdrawnRoutes(); + if (withdrawnRoutes != null && withdrawnRoutes.getDestinationType() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv4Case) { + final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv4Case destinationIpv4Case = + (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv4Case) withdrawnRoutes.getDestinationType(); + for (final Ipv4Prefixes ipv4Prefix : destinationIpv4Case.getDestinationIpv4().getIpv4Prefixes()) { + PathIdUtil.writePathId(ipv4Prefix.getPathId(), byteAggregator); + ByteBufWriteUtil.writeMinimalPrefix(ipv4Prefix.getPrefix(), byteAggregator); + } + } + } + } } \ No newline at end of file diff --git a/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/Ipv6BgpPrefixSidParser.java b/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/codec/Ipv6BgpPrefixSidParser.java similarity index 97% rename from bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/Ipv6BgpPrefixSidParser.java rename to bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/codec/Ipv6BgpPrefixSidParser.java index f806665fc0..9891d70773 100644 --- a/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/Ipv6BgpPrefixSidParser.java +++ b/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/codec/Ipv6BgpPrefixSidParser.java @@ -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.inet; +package org.opendaylight.protocol.bgp.inet.codec; import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/Ipv6NlriParser.java b/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/codec/Ipv6NlriParser.java similarity index 50% rename from bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/Ipv6NlriParser.java rename to bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/codec/Ipv6NlriParser.java index 6549a5219c..1f0dde518e 100644 --- a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/Ipv6NlriParser.java +++ b/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/codec/Ipv6NlriParser.java @@ -1,12 +1,14 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2013, 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.parser.impl.message.update; +package org.opendaylight.protocol.bgp.inet.codec; + +import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import java.util.ArrayList; import java.util.List; @@ -16,25 +18,34 @@ import org.opendaylight.protocol.bgp.parser.BGPParsingException; import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl; import org.opendaylight.protocol.bgp.parser.spi.MultiPathSupportUtil; import org.opendaylight.protocol.bgp.parser.spi.NlriParser; +import org.opendaylight.protocol.bgp.parser.spi.NlriSerializer; import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil; import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint; +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.inet.rev150305.ipv6.prefixes.DestinationIpv6; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.prefixes.DestinationIpv6Builder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.prefixes.destination.ipv6.Ipv6Prefixes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.prefixes.destination.ipv6.Ipv6PrefixesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv6Case; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv6CaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes; +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.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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily; +import org.opendaylight.yangtools.yang.binding.DataObject; -public final class Ipv6NlriParser implements NlriParser { +public final class Ipv6NlriParser implements NlriParser, NlriSerializer { private static DestinationIpv6 prefixes(final ByteBuf nlri, final PeerSpecificParserConstraint constraint, - final Class afi, final Class safi) { + final Class afi, final Class safi) { final List prefixes = new ArrayList<>(); final boolean supported = MultiPathSupportUtil.isTableTypeSupported(constraint, new BgpTableTypeImpl(afi, safi)); while (nlri.isReadable()) { @@ -60,14 +71,42 @@ public final class Ipv6NlriParser implements NlriParser { @Override public void parseNlri(@Nonnull final ByteBuf nlri, @Nonnull final MpReachNlriBuilder builder, - @Nullable final PeerSpecificParserConstraint constraint) throws BGPParsingException { + @Nullable final PeerSpecificParserConstraint constraint) throws BGPParsingException { builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationIpv6CaseBuilder(). - setDestinationIpv6(prefixes(nlri, constraint, builder.getAfi(), builder.getSafi())).build()).build()); + setDestinationIpv6(prefixes(nlri, constraint, builder.getAfi(), builder.getSafi())).build()).build()); } @Override public void parseNlri(@Nonnull final ByteBuf nlri, @Nonnull final MpUnreachNlriBuilder builder, @Nullable final PeerSpecificParserConstraint constraint) throws BGPParsingException { builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6CaseBuilder().setDestinationIpv6( - prefixes(nlri, constraint, builder.getAfi(), builder.getSafi())).build()).build()); + prefixes(nlri, constraint, builder.getAfi(), builder.getSafi())).build()).build()); + } + + @Override + public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) { + Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object."); + final Attributes pathAttributes = (Attributes) attribute; + final Attributes1 pathAttributes1 = pathAttributes.getAugmentation(Attributes1.class); + final Attributes2 pathAttributes2 = pathAttributes.getAugmentation(Attributes2.class); + if (pathAttributes1 != null) { + final AdvertizedRoutes advertizedRoutes = pathAttributes1.getMpReachNlri().getAdvertizedRoutes(); + if (advertizedRoutes != null && advertizedRoutes.getDestinationType() instanceof DestinationIpv6Case) { + final DestinationIpv6Case destinationIpv6Case = (DestinationIpv6Case) advertizedRoutes.getDestinationType(); + for (final Ipv6Prefixes ipv6Prefix : destinationIpv6Case.getDestinationIpv6().getIpv6Prefixes()) { + PathIdUtil.writePathId(ipv6Prefix.getPathId(), byteAggregator); + ByteBufWriteUtil.writeMinimalPrefix(ipv6Prefix.getPrefix(), byteAggregator); + } + } + } else if (pathAttributes2 != null) { + final WithdrawnRoutes withdrawnRoutes = pathAttributes2.getMpUnreachNlri().getWithdrawnRoutes(); + if (withdrawnRoutes != null && withdrawnRoutes.getDestinationType() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6Case) { + final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6Case destinationIpv6Case = + (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6Case) withdrawnRoutes.getDestinationType(); + for (final Ipv6Prefixes ipv6Prefix : destinationIpv6Case.getDestinationIpv6().getIpv6Prefixes()) { + PathIdUtil.writePathId(ipv6Prefix.getPathId(), byteAggregator); + ByteBufWriteUtil.writeMinimalPrefix(ipv6Prefix.getPrefix(), byteAggregator); + } + } + } } } \ No newline at end of file diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/next/hop/Ipv4NextHopParserSerializer.java b/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/codec/nexthop/Ipv4NextHopParserSerializer.java similarity index 95% rename from bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/next/hop/Ipv4NextHopParserSerializer.java rename to bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/codec/nexthop/Ipv4NextHopParserSerializer.java index 1a27f7bae1..7860faa1dc 100644 --- a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/next/hop/Ipv4NextHopParserSerializer.java +++ b/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/codec/nexthop/Ipv4NextHopParserSerializer.java @@ -6,7 +6,7 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.protocol.bgp.parser.impl.message.update.next.hop; +package org.opendaylight.protocol.bgp.inet.codec.nexthop; import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/next/hop/Ipv6NextHopParserSerializer.java b/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/codec/nexthop/Ipv6NextHopParserSerializer.java similarity index 94% rename from bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/next/hop/Ipv6NextHopParserSerializer.java rename to bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/codec/nexthop/Ipv6NextHopParserSerializer.java index 68e7817d01..a69eb44fa1 100644 --- a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/next/hop/Ipv6NextHopParserSerializer.java +++ b/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/codec/nexthop/Ipv6NextHopParserSerializer.java @@ -6,7 +6,7 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.protocol.bgp.parser.impl.message.update.next.hop; +package org.opendaylight.protocol.bgp.inet.codec.nexthop; import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; diff --git a/bgp/inet/src/main/resources/META-INF/services/org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderActivator b/bgp/inet/src/main/resources/META-INF/services/org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderActivator new file mode 100644 index 0000000000..c3e5136356 --- /dev/null +++ b/bgp/inet/src/main/resources/META-INF/services/org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderActivator @@ -0,0 +1,7 @@ +# 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 +org.opendaylight.protocol.bgp.inet.BGPActivator diff --git a/bgp/rib-impl/src/main/resources/META-INF/services/org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderActivator b/bgp/inet/src/main/resources/META-INF/services/org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderActivator similarity index 84% rename from bgp/rib-impl/src/main/resources/META-INF/services/org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderActivator rename to bgp/inet/src/main/resources/META-INF/services/org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderActivator index 67f3f66819..bb8d0d8be9 100644 --- a/bgp/rib-impl/src/main/resources/META-INF/services/org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderActivator +++ b/bgp/inet/src/main/resources/META-INF/services/org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderActivator @@ -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.rib.impl.RIBActivator +org.opendaylight.protocol.bgp.inet.RIBActivator diff --git a/bgp/inet/src/main/resources/org/opendaylight/blueprint/bgp-inet.xml b/bgp/inet/src/main/resources/org/opendaylight/blueprint/bgp-inet.xml new file mode 100644 index 0000000000..e335b6d045 --- /dev/null +++ b/bgp/inet/src/main/resources/org/opendaylight/blueprint/bgp-inet.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/IPv4RIBSupportTest.java b/bgp/inet/src/test/java/org/opendaylight/protocol/bgp/inet/IPv4RIBSupportTest.java similarity index 94% rename from bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/IPv4RIBSupportTest.java rename to bgp/inet/src/test/java/org/opendaylight/protocol/bgp/inet/IPv4RIBSupportTest.java index 733441a4ac..886a164d75 100644 --- a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/IPv4RIBSupportTest.java +++ b/bgp/inet/src/test/java/org/opendaylight/protocol/bgp/inet/IPv4RIBSupportTest.java @@ -6,11 +6,10 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.protocol.bgp.rib.impl; +package org.opendaylight.protocol.bgp.inet; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; - import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; @@ -54,14 +53,14 @@ public final class IPv4RIBSupportTest extends AbstractRIBSupportTest { private static final Ipv4Prefix PREFIX = new Ipv4Prefix("1.2.3.4/32"); private static final Ipv4RouteKey ROUTE_KEY = new Ipv4RouteKey(PATH_ID, PREFIX); private static final Ipv4Prefixes IPV4_PREFIXES = new Ipv4PrefixesBuilder().setPathId(PATH_ID) - .setPrefix(PREFIX).build(); + .setPrefix(PREFIX).build(); private static final DestinationIpv4Case REACH_NLRI = new DestinationIpv4CaseBuilder().setDestinationIpv4(new DestinationIpv4Builder() - .setIpv4Prefixes(Lists.newArrayList(IPV4_PREFIXES)).build()).build(); + .setIpv4Prefixes(Lists.newArrayList(IPV4_PREFIXES)).build()).build(); private static final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update - .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv4Case UNREACH_NLRI = - new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update - .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv4CaseBuilder().setDestinationIpv4( + .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv4Case UNREACH_NLRI = + new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update + .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv4CaseBuilder().setDestinationIpv4( new DestinationIpv4Builder().setIpv4Prefixes(Lists.newArrayList(IPV4_PREFIXES)).build()).build(); private static final Ipv4Route ROUTE = new Ipv4RouteBuilder().setAttributes(ATTRIBUTES).setPathId(PATH_ID).setPrefix(PREFIX).build(); @@ -148,7 +147,7 @@ public final class IPv4RIBSupportTest extends AbstractRIBSupportTest { @Test public void testRouteAttributesIdentifier() { Assert.assertEquals(new NodeIdentifier(QName.create(Ipv4Routes.QNAME, Attributes.QNAME.getLocalName().intern())), RIB_SUPPORT - .routeAttributesIdentifier()); + .routeAttributesIdentifier()); } @Test diff --git a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/IPv6RIBSupportTest.java b/bgp/inet/src/test/java/org/opendaylight/protocol/bgp/inet/IPv6RIBSupportTest.java similarity index 99% rename from bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/IPv6RIBSupportTest.java rename to bgp/inet/src/test/java/org/opendaylight/protocol/bgp/inet/IPv6RIBSupportTest.java index ee0143e0bf..ec1b8a60b1 100644 --- a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/IPv6RIBSupportTest.java +++ b/bgp/inet/src/test/java/org/opendaylight/protocol/bgp/inet/IPv6RIBSupportTest.java @@ -6,12 +6,11 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.protocol.bgp.rib.impl; +package org.opendaylight.protocol.bgp.inet; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; - import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; diff --git a/bgp/inet/src/test/java/org/opendaylight/protocol/bgp/inet/Ipv6BgpPrefixSidParserTest.java b/bgp/inet/src/test/java/org/opendaylight/protocol/bgp/inet/Ipv6BgpPrefixSidParserTest.java index 74576760f6..1424b8b36f 100644 --- a/bgp/inet/src/test/java/org/opendaylight/protocol/bgp/inet/Ipv6BgpPrefixSidParserTest.java +++ b/bgp/inet/src/test/java/org/opendaylight/protocol/bgp/inet/Ipv6BgpPrefixSidParserTest.java @@ -10,9 +10,11 @@ package org.opendaylight.protocol.bgp.inet; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; + import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.junit.Test; +import org.opendaylight.protocol.bgp.inet.codec.Ipv6BgpPrefixSidParser; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.bgp.prefix.sid.bgp.prefix.sid.tlvs.bgp.prefix.sid.tlv.Ipv6SidTlvBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.bgp.prefix.sid.bgp.prefix.sid.tlvs.BgpPrefixSidTlv; import org.opendaylight.yangtools.yang.binding.DataContainer; diff --git a/bgp/inet/src/test/java/org/opendaylight/protocol/bgp/inet/codec/BGPParserTest.java b/bgp/inet/src/test/java/org/opendaylight/protocol/bgp/inet/codec/BGPParserTest.java new file mode 100644 index 0000000000..056f6b2690 --- /dev/null +++ b/bgp/inet/src/test/java/org/opendaylight/protocol/bgp/inet/codec/BGPParserTest.java @@ -0,0 +1,214 @@ +/* + * 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.inet.codec; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import com.google.common.collect.Lists; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import org.junit.BeforeClass; +import org.junit.Test; +import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry; +import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext; +import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.prefixes.DestinationIpv6Builder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.prefixes.destination.ipv6.Ipv6Prefixes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.prefixes.destination.ipv6.Ipv6PrefixesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv6CaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.UpdateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.AsPathBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.ClusterIdBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.MultiExitDiscBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.OriginBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.OriginatorIdBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.UnrecognizedAttributes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.as.path.Segments; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.as.path.SegmentsBuilder; +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.Attributes1Builder; +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.mp.reach.nlri.AdvertizedRoutesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv6NextHopCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv6NextHopCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.ipv6.next.hop._case.Ipv6NextHopBuilder; + +public class BGPParserTest { + + private static int MAX_SIZE = 300; + + private static MessageRegistry messageRegistry; + + private static byte[] input; + + @BeforeClass + public static void setUp() throws Exception { + messageRegistry = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getMessageRegistry(); + + final String name = "/up2.bin"; + try (final InputStream is = BGPParserTest.class.getResourceAsStream(name)) { + if (is == null) { + throw new IOException("Failed to get resource " + name); + } + final ByteArrayOutputStream bis = new ByteArrayOutputStream(); + final byte[] data = new byte[MAX_SIZE]; + int nRead = 0; + while ((nRead = is.read(data, 0, data.length)) != -1) { + bis.write(data, 0, nRead); + } + bis.flush(); + + input = bis.toByteArray(); + is.close(); + } + } + + /* + * Tests IPv6 NEXT_HOP, NLRI, ORIGIN.IGP, MULTI_EXIT_DISC, ORIGINATOR-ID, CLUSTER_LIST. + * + * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker + * 00 80 <- length (128) - including header + * 02 <- message type + * 00 00 <- withdrawn routes length + * 00 69 <- total path attribute length (105) + * 40 <- attribute flags + * 01 <- attribute type code (origin) + * 01 <- attribute length + * 00 <- Origin value (IGP) + * 40 <- attribute flags + * 02 <- attribute type code (as path) + * 06 <- attribute length + * 02 <- AS_SEQUENCE + * 01 <- path segment count + * 00 00 fd e9 <- path segment value (65001) + * 40 <- attribute flags + * 03 <- attribute type code (next hop) + * 04 <- attribute length + * 0a 00 00 00 <- next hop value (10.0.0.0) + * 80 <- attribute flags + * 04 <- attribute type code (multi exit disc) + * 04 <- attribute length + * 00 00 00 00 <- value + * 80 <- attribute flags + * 09 <- attribute type code (originator id) + * 04 <- attribute length + * 7f 00 00 01 <- value (localhost ip) + * 80 <- attribute flags + * 0a <- attribute type code (cluster list) + * 08 <- attribute length + * 01 02 03 04 <- value + * 05 06 07 08 <- value + * 80 <- attribute flags + * 0e <- attribute type code (mp reach nlri) + * 40 <- attribute length + * 00 02 <- AFI (Ipv6) + * 01 <- SAFI (Unicast) + * 20 <- length of next hop + * 20 01 0d b8 00 00 00 00 00 00 00 00 00 00 00 01 <- global + * fe 80 00 00 00 00 00 00 c0 01 0b ff fe 7e 00 <- link local + * 00 <- reserved + * + * //NLRI + * 40 20 01 0d b8 00 01 00 02 <- IPv6 Prefix (2001:db8:1:2:: / 64) + * 40 20 01 0d b8 00 01 00 01 <- IPv6 Prefix (2001:db8:1:1:: / 64) + * 40 20 01 0d b8 00 01 00 00 <- IPv6 Prefix (2001:db8:1:: / 64) + * + */ + @Test + public void testIPv6Nlri() throws Exception { + final Update message = (Update) messageRegistry.parseMessage(Unpooled.wrappedBuffer(input), null); + + // check fields + assertNull(message.getWithdrawnRoutes()); + + final UpdateBuilder builder = new UpdateBuilder(); + + // check NLRI + + final List prefs = new ArrayList<>(); + prefs.add(new Ipv6PrefixesBuilder().setPrefix(new Ipv6Prefix("2001:db8:1:2::/64")).build()); + prefs.add(new Ipv6PrefixesBuilder().setPrefix(new Ipv6Prefix("2001:db8:1:1::/64")).build()); + prefs.add(new Ipv6PrefixesBuilder().setPrefix(new Ipv6Prefix("2001:db8:1::/64")).build()); + + assertNull(message.getNlri()); + + // attributes + final List asNumbers = new ArrayList(); + asNumbers.add(new AsNumber(65001L)); + final List asPath = Lists.newArrayList(); + asPath.add(new SegmentsBuilder().setAsSequence(asNumbers).build()); + + final Ipv6NextHopCase nextHop = new Ipv6NextHopCaseBuilder().setIpv6NextHop( + new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).setLinkLocal(new Ipv6Address("fe80::c001:bff:fe7e:0")).build()).build(); + + final List clusters = Lists.newArrayList(new ClusterIdentifier(new Ipv4Address("1.2.3.4")), + new ClusterIdentifier(new Ipv4Address("5.6.7.8"))); + + // check path attributes + + final Attributes attrs = message.getAttributes(); + + final AttributesBuilder paBuilder = new AttributesBuilder(); + + paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build()); + assertEquals(paBuilder.getOrigin(), attrs.getOrigin()); + + paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build()); + assertEquals(paBuilder.getAsPath(), attrs.getAsPath()); + + paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build()); + assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc()); + + paBuilder.setOriginatorId(new OriginatorIdBuilder().setOriginator(new Ipv4Address("127.0.0.1")).build()); + assertEquals(paBuilder.getOriginatorId(), attrs.getOriginatorId()); + + paBuilder.setClusterId(new ClusterIdBuilder().setCluster(clusters).build()); + assertEquals(paBuilder.getClusterId(), attrs.getClusterId()); + + final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder(); + mpBuilder.setAfi(Ipv6AddressFamily.class); + mpBuilder.setSafi(UnicastSubsequentAddressFamily.class); + mpBuilder.setCNextHop(nextHop); + mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType( + new DestinationIpv6CaseBuilder().setDestinationIpv6(new DestinationIpv6Builder().setIpv6Prefixes(prefs).build()).build()).build()); + + paBuilder.addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(mpBuilder.build()).build()); + assertEquals(paBuilder.getAugmentation(Attributes1.class).getMpReachNlri(), + attrs.getAugmentation(Attributes1.class).getMpReachNlri()); + paBuilder.setUnrecognizedAttributes(Collections. emptyList()); + // check API message + + builder.setAttributes(paBuilder.build()); + assertEquals(builder.build(), message); + + final ByteBuf buffer = Unpooled.buffer(); + messageRegistry.serializeMessage(message, buffer); + assertArrayEquals(input, ByteArray.readAllBytes(buffer)); + } + +} diff --git a/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/Ipv4NlriParserTest.java b/bgp/inet/src/test/java/org/opendaylight/protocol/bgp/inet/codec/Ipv4NlriParserTest.java similarity index 85% rename from bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/Ipv4NlriParserTest.java rename to bgp/inet/src/test/java/org/opendaylight/protocol/bgp/inet/codec/Ipv4NlriParserTest.java index 7d6aed6e10..bbf8d4abc6 100644 --- a/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/Ipv4NlriParserTest.java +++ b/bgp/inet/src/test/java/org/opendaylight/protocol/bgp/inet/codec/Ipv4NlriParserTest.java @@ -6,9 +6,8 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.protocol.bgp.parser.impl; +package org.opendaylight.protocol.bgp.inet.codec; -import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -17,9 +16,7 @@ import static org.junit.Assert.assertTrue; import com.google.common.collect.Lists; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; -import java.io.UnsupportedEncodingException; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Optional; import org.junit.Assert; @@ -29,9 +26,6 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.opendaylight.protocol.bgp.parser.BGPParsingException; -import org.opendaylight.protocol.bgp.parser.impl.message.update.AdvertizedRoutesSerializer; -import org.opendaylight.protocol.bgp.parser.impl.message.update.Ipv4NlriParser; -import org.opendaylight.protocol.bgp.parser.impl.message.update.WithdrawnRoutesSerializer; import org.opendaylight.protocol.bgp.parser.spi.MultiPathSupport; import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint; import org.opendaylight.protocol.util.Ipv4Util; @@ -44,8 +38,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.PathId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.message.Nlri; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.message.NlriBuilder; 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.Attributes1Builder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2; @@ -84,9 +76,6 @@ public class Ipv4NlriParserTest { private DestinationIpv4Case ip4caseAD; private DestinationIpv4Case ip4caseADWrong; - private Nlri nlri; - private Nlri nlriWrong; - @Mock private PeerSpecificParserConstraint constraint; @@ -103,26 +92,19 @@ public class Ipv4NlriParserTest { this.prefixes.add(new Ipv4PrefixesBuilder().setPrefix(prefix2).build()); this.ip4caseWD = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv4CaseBuilder().setDestinationIpv4( - new DestinationIpv4Builder().setIpv4Prefixes(this.prefixes).build()).build(); + new DestinationIpv4Builder().setIpv4Prefixes(this.prefixes).build()).build(); this.ip4caseAD = new DestinationIpv4CaseBuilder().setDestinationIpv4(new DestinationIpv4Builder().setIpv4Prefixes(this.prefixes).build()).build(); final ArrayList fakePrefixes = new ArrayList(this.prefixes); fakePrefixes.add(new Ipv4PrefixesBuilder().setPrefix(wrongPrefix).build()); this.ip4caseWDWrong = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv4CaseBuilder().setDestinationIpv4( - new DestinationIpv4Builder().setIpv4Prefixes(fakePrefixes).build()).build(); + new DestinationIpv4Builder().setIpv4Prefixes(fakePrefixes).build()).build(); this.ip4caseADWrong = new DestinationIpv4CaseBuilder().setDestinationIpv4(new DestinationIpv4Builder().setIpv4Prefixes(fakePrefixes).build()).build(); this.inputBytes.writeBytes(Ipv4Util.bytesForPrefixBegin(prefix1)); this.inputBytes.writeBytes(Ipv4Util.bytesForPrefixBegin(prefix2)); - final List prefixList = new ArrayList(); - prefixList.add(prefix1); - prefixList.add(prefix2); - this.nlri = new NlriBuilder().setNlri(prefixList).build(); - final List prefixWrongList = Lists.newArrayList(prefixList.iterator()); - prefixWrongList.add(wrongPrefix); - this.nlriWrong = new NlriBuilder().setNlri(prefixWrongList).build(); - Mockito.doReturn(Optional.of(this.muliPathSupport)).when(constraint).getPeerConstraint(Mockito.any()); + Mockito.doReturn(Optional.of(this.muliPathSupport)).when(this.constraint).getPeerConstraint(Mockito.any()); Mockito.doReturn(true).when(this.muliPathSupport).isTableTypeSupported(Mockito.any()); } @@ -133,16 +115,6 @@ public class Ipv4NlriParserTest { assertEquals(2, this.prefixes.size()); } - @Test - public void serializeAttributeTest() throws UnsupportedEncodingException { - final ByteBuf outputBytes = Unpooled.buffer(); - - this.parser.serializeAttribute(this.nlri, outputBytes); - assertArrayEquals(this.inputBytes.array(), outputBytes.array()); - this.parser.serializeAttribute(this.nlriWrong, outputBytes); - assertFalse(Arrays.equals(this.inputBytes.array(), outputBytes.array())); - } - @Test public void parseUnreachedNlriTest() { final MpUnreachNlriBuilder b = new MpUnreachNlriBuilder(); @@ -184,7 +156,7 @@ public class Ipv4NlriParserTest { mpReachNlriBuilder.setAfi(null).setSafi(null); Assert.assertEquals(mpReachNlri, mpReachNlriBuilder.build()); - final AdvertizedRoutesSerializer serializer = new AdvertizedRoutesSerializer(); + final Ipv4NlriParser serializer = new Ipv4NlriParser(); final ByteBuf output = Unpooled.buffer(MP_NLRI_BYTES.length); final Attributes attributes = new AttributesBuilder().addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(mpReachNlri).build()).build(); @@ -205,7 +177,7 @@ public class Ipv4NlriParserTest { mpUnreachNlriBuilder.setAfi(null).setSafi(null); Assert.assertEquals(mpUnreachNlri, mpUnreachNlriBuilder.build()); - final WithdrawnRoutesSerializer serializer = new WithdrawnRoutesSerializer(); + final Ipv4NlriParser serializer = new Ipv4NlriParser(); final ByteBuf output = Unpooled.buffer(MP_NLRI_BYTES.length); final Attributes attributes = new AttributesBuilder().addAugmentation(Attributes2.class, new Attributes2Builder().setMpUnreachNlri(mpUnreachNlri).build()).build(); diff --git a/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/next/hop/NextHopParserSerializerTest.java b/bgp/inet/src/test/java/org/opendaylight/protocol/bgp/inet/codec/nexthop/NextHopParserSerializerTest.java similarity index 95% rename from bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/next/hop/NextHopParserSerializerTest.java rename to bgp/inet/src/test/java/org/opendaylight/protocol/bgp/inet/codec/nexthop/NextHopParserSerializerTest.java index 3fcaa13c0b..42b1d8c898 100644 --- a/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/next/hop/NextHopParserSerializerTest.java +++ b/bgp/inet/src/test/java/org/opendaylight/protocol/bgp/inet/codec/nexthop/NextHopParserSerializerTest.java @@ -6,7 +6,7 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.protocol.bgp.parser.impl.message.update.next.hop; +package org.opendaylight.protocol.bgp.inet.codec.nexthop; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; @@ -16,6 +16,8 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.junit.Before; import org.junit.Test; +import org.opendaylight.protocol.bgp.inet.codec.nexthop.Ipv4NextHopParserSerializer; +import org.opendaylight.protocol.bgp.inet.codec.nexthop.Ipv6NextHopParserSerializer; import org.opendaylight.protocol.bgp.parser.BGPParsingException; import org.opendaylight.protocol.util.ByteArray; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; diff --git a/bgp/inet/src/test/resources/up2.bin b/bgp/inet/src/test/resources/up2.bin new file mode 100644 index 0000000000..c3aba85ff8 Binary files /dev/null and b/bgp/inet/src/test/resources/up2.bin differ diff --git a/bgp/labeled-unicast/pom.xml b/bgp/labeled-unicast/pom.xml index 377bfe48b2..2b90853fd6 100644 --- a/bgp/labeled-unicast/pom.xml +++ b/bgp/labeled-unicast/pom.xml @@ -50,7 +50,7 @@ ${project.groupId} - bgp-parser-impl + bgp-inet ${project.groupId} diff --git a/bgp/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/BGPActivator.java b/bgp/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/BGPActivator.java index bbf36b34e0..dadfa5befa 100644 --- a/bgp/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/BGPActivator.java +++ b/bgp/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/BGPActivator.java @@ -9,8 +9,8 @@ package org.opendaylight.protocol.bgp.labeled.unicast; import java.util.ArrayList; import java.util.List; -import org.opendaylight.protocol.bgp.parser.impl.message.update.next.hop.Ipv4NextHopParserSerializer; -import org.opendaylight.protocol.bgp.parser.impl.message.update.next.hop.Ipv6NextHopParserSerializer; +import org.opendaylight.protocol.bgp.inet.codec.nexthop.Ipv4NextHopParserSerializer; +import org.opendaylight.protocol.bgp.inet.codec.nexthop.Ipv6NextHopParserSerializer; import org.opendaylight.protocol.bgp.parser.spi.AbstractBGPExtensionProviderActivator; import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.LabeledUnicastSubsequentAddressFamily; @@ -36,9 +36,9 @@ public final class BGPActivator extends AbstractBGPExtensionProviderActivator { final Ipv4NextHopParserSerializer ipv4NextHopParser = new Ipv4NextHopParserSerializer(); final Ipv6NextHopParserSerializer ipv6NextHopParser = new Ipv6NextHopParserSerializer(); regs.add(context.registerNlriParser(Ipv4AddressFamily.class, LabeledUnicastSubsequentAddressFamily.class, - luNlriParser, ipv4NextHopParser, Ipv4NextHopCase.class)); + luNlriParser, ipv4NextHopParser, Ipv4NextHopCase.class)); regs.add(context.registerNlriParser(Ipv6AddressFamily.class, LabeledUnicastSubsequentAddressFamily.class, - luNlriParser, ipv6NextHopParser, Ipv6NextHopCase.class)); + luNlriParser, ipv6NextHopParser, Ipv6NextHopCase.class)); regs.add(context.registerNlriSerializer(LabeledUnicastRoutes.class, luNlriParser)); diff --git a/bgp/parser-impl/pom.xml b/bgp/parser-impl/pom.xml index 13c19d57f4..3b7b98558e 100644 --- a/bgp/parser-impl/pom.xml +++ b/bgp/parser-impl/pom.xml @@ -40,10 +40,6 @@ ${project.groupId} bgp-concepts - - ${project.groupId} - bgp-inet - ${project.groupId} bgp-parser-api diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/BGPActivator.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/BGPActivator.java index d25d56a407..851a4b0764 100755 --- a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/BGPActivator.java +++ b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/BGPActivator.java @@ -23,7 +23,6 @@ import org.opendaylight.protocol.bgp.parser.impl.message.open.MultiProtocolCapab import org.opendaylight.protocol.bgp.parser.impl.message.open.RouteRefreshCapabilityHandler; import org.opendaylight.protocol.bgp.parser.impl.message.update.AS4AggregatorAttributeParser; import org.opendaylight.protocol.bgp.parser.impl.message.update.AS4PathAttributeParser; -import org.opendaylight.protocol.bgp.parser.impl.message.update.AdvertizedRoutesSerializer; import org.opendaylight.protocol.bgp.parser.impl.message.update.AggregatorAttributeParser; import org.opendaylight.protocol.bgp.parser.impl.message.update.AigpAttributeParser; import org.opendaylight.protocol.bgp.parser.impl.message.update.AsPathAttributeParser; @@ -32,8 +31,6 @@ import org.opendaylight.protocol.bgp.parser.impl.message.update.BgpPrefixSidAttr import org.opendaylight.protocol.bgp.parser.impl.message.update.ClusterIdAttributeParser; import org.opendaylight.protocol.bgp.parser.impl.message.update.CommunitiesAttributeParser; import org.opendaylight.protocol.bgp.parser.impl.message.update.ExtendedCommunitiesAttributeParser; -import org.opendaylight.protocol.bgp.parser.impl.message.update.Ipv4NlriParser; -import org.opendaylight.protocol.bgp.parser.impl.message.update.Ipv6NlriParser; import org.opendaylight.protocol.bgp.parser.impl.message.update.LocalPreferenceAttributeParser; import org.opendaylight.protocol.bgp.parser.impl.message.update.MPReachAttributeParser; import org.opendaylight.protocol.bgp.parser.impl.message.update.MPUnreachAttributeParser; @@ -42,7 +39,6 @@ import org.opendaylight.protocol.bgp.parser.impl.message.update.NextHopAttribute import org.opendaylight.protocol.bgp.parser.impl.message.update.OriginAttributeParser; import org.opendaylight.protocol.bgp.parser.impl.message.update.OriginatorIdAttributeParser; import org.opendaylight.protocol.bgp.parser.impl.message.update.UnrecognizedAttributesSerializer; -import org.opendaylight.protocol.bgp.parser.impl.message.update.WithdrawnRoutesSerializer; import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.AsTwoOctetSpecificEcHandler; import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.EncapsulationEC; import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.Ipv4SpecificEcHandler; @@ -55,8 +51,6 @@ import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communi import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.four.octect.as.specific.Generic4OctASEcHandler; import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.four.octect.as.specific.RouteOrigin4OctectASEcHandler; import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.four.octect.as.specific.RouteTarget4OctectASEcHandler; -import org.opendaylight.protocol.bgp.parser.impl.message.update.next.hop.Ipv4NextHopParserSerializer; -import org.opendaylight.protocol.bgp.parser.impl.message.update.next.hop.Ipv6NextHopParserSerializer; import org.opendaylight.protocol.bgp.parser.spi.AbstractBGPExtensionProviderActivator; import org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry; import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext; @@ -82,7 +76,6 @@ 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.message.rev130919.path.attributes.attributes.Origin; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.OriginatorId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.UnrecognizedAttributes; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.message.WithdrawnRoutes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.RouteRefresh; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.AddPathCapability; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.GracefulRestartCapability; @@ -90,7 +83,6 @@ 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.mp.capabilities.RouteRefreshCapability; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlri; 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.mp.reach.nlri.AdvertizedRoutes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.MplsLabeledVpnSubsequentAddressFamily; @@ -108,8 +100,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.RouteOriginIpv4Case; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.RouteTargetExtendedCommunityCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.RouteTargetIpv4Case; -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; public final class BGPActivator extends AbstractBGPExtensionProviderActivator { @@ -123,27 +113,16 @@ public final class BGPActivator extends AbstractBGPExtensionProviderActivator { protected List startImpl(final BGPExtensionProviderContext context) { final List regs = new ArrayList<>(); - regs.add(context.registerNlriSerializer(AdvertizedRoutes.class, new AdvertizedRoutesSerializer())); - regs.add(context.registerNlriSerializer(WithdrawnRoutes.class, new WithdrawnRoutesSerializer())); - regs.add(context.registerAddressFamily(Ipv4AddressFamily.class, IPV4_AFI)); regs.add(context.registerAddressFamily(Ipv6AddressFamily.class, IPV6_AFI)); regs.add(context.registerSubsequentAddressFamily(UnicastSubsequentAddressFamily.class, UNICAST_SAFI)); regs.add(context.registerSubsequentAddressFamily(MplsLabeledVpnSubsequentAddressFamily.class, VPN_SAFI)); - final Ipv4NextHopParserSerializer ipv4NextHopParser = new Ipv4NextHopParserSerializer(); - regs.add(context.registerNlriParser(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, - new Ipv4NlriParser(), ipv4NextHopParser, Ipv4NextHopCase.class, Ipv6NextHopCase.class)); - - final Ipv6NextHopParserSerializer ipv6NextHopParser = new Ipv6NextHopParserSerializer(); - regs.add(context.registerNlriParser(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, new - Ipv6NlriParser(), ipv6NextHopParser, Ipv4NextHopCase.class, Ipv6NextHopCase.class)); - - this.registerExtendedCommunities(regs, context); - this.registerCapabilityParsers(regs, context); - this.registerAttributeParsers(regs, context); - this.registerMessageParsers(regs, context); + registerExtendedCommunities(regs, context); + registerCapabilityParsers(regs, context); + registerAttributeParsers(regs, context); + registerMessageParsers(regs, context); return regs; } @@ -276,56 +255,56 @@ public final class BGPActivator extends AbstractBGPExtensionProviderActivator { private void registerExtendedCommunities(final List regs, final BGPExtensionProviderContext context) { final AsTwoOctetSpecificEcHandler twoOctetSpecificEcHandler = new AsTwoOctetSpecificEcHandler(); regs.add(context.registerExtendedCommunityParser(twoOctetSpecificEcHandler.getType(true), twoOctetSpecificEcHandler.getSubType(), - twoOctetSpecificEcHandler)); + twoOctetSpecificEcHandler)); regs.add(context.registerExtendedCommunityParser(twoOctetSpecificEcHandler.getType(false), twoOctetSpecificEcHandler.getSubType(), - twoOctetSpecificEcHandler)); + twoOctetSpecificEcHandler)); regs.add(context.registerExtendedCommunitySerializer(AsSpecificExtendedCommunityCase.class, twoOctetSpecificEcHandler)); final Ipv4SpecificEcHandler ipv4SpecificEcHandler = new Ipv4SpecificEcHandler(); regs.add(context.registerExtendedCommunityParser(ipv4SpecificEcHandler.getType(true), ipv4SpecificEcHandler.getSubType(), - ipv4SpecificEcHandler)); + ipv4SpecificEcHandler)); regs.add(context.registerExtendedCommunityParser(ipv4SpecificEcHandler.getType(false), ipv4SpecificEcHandler.getSubType(), - ipv4SpecificEcHandler)); + ipv4SpecificEcHandler)); regs.add(context.registerExtendedCommunitySerializer(Inet4SpecificExtendedCommunityCase.class, ipv4SpecificEcHandler)); final OpaqueEcHandler opaqueEcHandler = new OpaqueEcHandler(); regs.add(context.registerExtendedCommunityParser(opaqueEcHandler.getType(true), opaqueEcHandler.getSubType(), - opaqueEcHandler)); + opaqueEcHandler)); regs.add(context.registerExtendedCommunityParser(opaqueEcHandler.getType(false), opaqueEcHandler.getSubType(), - opaqueEcHandler)); + opaqueEcHandler)); regs.add(context.registerExtendedCommunitySerializer(OpaqueExtendedCommunityCase.class, opaqueEcHandler)); final RouteOriginAsTwoOctetEcHandler routeOriginAS2bEcHandler = new RouteOriginAsTwoOctetEcHandler(); regs.add(context.registerExtendedCommunityParser(routeOriginAS2bEcHandler.getType(true), routeOriginAS2bEcHandler.getSubType(), - routeOriginAS2bEcHandler)); + routeOriginAS2bEcHandler)); regs.add(context.registerExtendedCommunityParser(routeOriginAS2bEcHandler.getType(false), routeOriginAS2bEcHandler.getSubType(), - routeOriginAS2bEcHandler)); + routeOriginAS2bEcHandler)); regs.add(context.registerExtendedCommunitySerializer(RouteOriginExtendedCommunityCase.class, routeOriginAS2bEcHandler)); final RouteTargetAsTwoOctetEcHandler routeTargetAS2bEcHandler = new RouteTargetAsTwoOctetEcHandler(); regs.add(context.registerExtendedCommunityParser(routeTargetAS2bEcHandler.getType(true), routeTargetAS2bEcHandler.getSubType(), - routeTargetAS2bEcHandler)); + routeTargetAS2bEcHandler)); regs.add(context.registerExtendedCommunityParser(routeTargetAS2bEcHandler.getType(false), routeTargetAS2bEcHandler.getSubType(), - routeTargetAS2bEcHandler)); + routeTargetAS2bEcHandler)); regs.add(context.registerExtendedCommunitySerializer(RouteTargetExtendedCommunityCase.class, routeTargetAS2bEcHandler)); final RouteOriginIpv4EcHandler routeOriginIpv4EcHandler = new RouteOriginIpv4EcHandler(); regs.add(context.registerExtendedCommunityParser(routeOriginIpv4EcHandler.getType(true), routeOriginIpv4EcHandler.getSubType(), - routeOriginIpv4EcHandler)); + routeOriginIpv4EcHandler)); regs.add(context.registerExtendedCommunityParser(routeOriginIpv4EcHandler.getType(false), routeOriginIpv4EcHandler.getSubType(), - routeOriginIpv4EcHandler)); + routeOriginIpv4EcHandler)); regs.add(context.registerExtendedCommunitySerializer(RouteOriginIpv4Case.class, routeOriginIpv4EcHandler)); final RouteTargetIpv4EcHandler routeTargetIpv4EcHandler = new RouteTargetIpv4EcHandler(); regs.add(context.registerExtendedCommunityParser(routeTargetIpv4EcHandler.getType(true), routeTargetIpv4EcHandler.getSubType(), - routeTargetIpv4EcHandler)); + routeTargetIpv4EcHandler)); regs.add(context.registerExtendedCommunityParser(routeTargetIpv4EcHandler.getType(false), routeTargetIpv4EcHandler.getSubType(), - routeTargetIpv4EcHandler)); + routeTargetIpv4EcHandler)); regs.add(context.registerExtendedCommunitySerializer(RouteTargetIpv4Case.class, routeTargetIpv4EcHandler)); final LinkBandwidthEC linkBandwidthECHandler = new LinkBandwidthEC(); regs.add(context.registerExtendedCommunityParser(linkBandwidthECHandler.getType(false), linkBandwidthECHandler.getSubType(), - linkBandwidthECHandler)); + linkBandwidthECHandler)); regs.add(context.registerExtendedCommunitySerializer(LinkBandwidthCase.class, linkBandwidthECHandler)); final Generic4OctASEcHandler gen4OctASEcHandler = new Generic4OctASEcHandler(); diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AdvertizedRoutesSerializer.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AdvertizedRoutesSerializer.java deleted file mode 100644 index 60b7f551c3..0000000000 --- a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AdvertizedRoutesSerializer.java +++ /dev/null @@ -1,53 +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.parser.impl.message.update; - -import com.google.common.base.Preconditions; -import io.netty.buffer.ByteBuf; -import org.opendaylight.protocol.bgp.parser.spi.NlriSerializer; -import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil; -import org.opendaylight.protocol.util.ByteBufWriteUtil; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.prefixes.destination.ipv4.Ipv4Prefixes; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.prefixes.destination.ipv6.Ipv6Prefixes; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv4Case; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv6Case; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes; -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.update.attributes.MpReachNlri; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutes; -import org.opendaylight.yangtools.yang.binding.DataObject; - -public class AdvertizedRoutesSerializer implements NlriSerializer { - - @Override - public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) { - Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object."); - final Attributes1 pathAttributes1 = ((Attributes) attribute).getAugmentation(Attributes1.class); - if (pathAttributes1 == null) { - return; - } - final MpReachNlri mpReachNlri = pathAttributes1.getMpReachNlri(); - if (mpReachNlri == null) { - return; - } - final AdvertizedRoutes routes = mpReachNlri.getAdvertizedRoutes(); - if (routes.getDestinationType() instanceof DestinationIpv4Case) { - final DestinationIpv4Case destinationIpv4Case = (DestinationIpv4Case) routes.getDestinationType(); - for (final Ipv4Prefixes ipv4Prefix : destinationIpv4Case.getDestinationIpv4().getIpv4Prefixes()) { - PathIdUtil.writePathId(ipv4Prefix.getPathId(), byteAggregator); - ByteBufWriteUtil.writeMinimalPrefix(ipv4Prefix.getPrefix(), byteAggregator); - } - } else if (routes.getDestinationType() instanceof DestinationIpv6Case) { - final DestinationIpv6Case destinationIpv6Case = (DestinationIpv6Case) routes.getDestinationType(); - for (final Ipv6Prefixes ipv6Prefix : destinationIpv6Case.getDestinationIpv6().getIpv6Prefixes()) { - PathIdUtil.writePathId(ipv6Prefix.getPathId(), byteAggregator); - ByteBufWriteUtil.writeMinimalPrefix(ipv6Prefix.getPrefix(), byteAggregator); - } - } - } -} diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/WithdrawnRoutesSerializer.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/WithdrawnRoutesSerializer.java deleted file mode 100644 index 706fc4c45c..0000000000 --- a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/WithdrawnRoutesSerializer.java +++ /dev/null @@ -1,63 +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.parser.impl.message.update; - -import com.google.common.base.Preconditions; -import io.netty.buffer.ByteBuf; -import org.opendaylight.protocol.bgp.parser.spi.NlriSerializer; -import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil; -import org.opendaylight.protocol.util.ByteBufWriteUtil; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.prefixes.destination.ipv4.Ipv4Prefixes; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.prefixes.destination.ipv6.Ipv6Prefixes; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv4Case; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6Case; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes; -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.MpUnreachNlri; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutes; -import org.opendaylight.yangtools.yang.binding.DataObject; - -public class WithdrawnRoutesSerializer implements NlriSerializer { - - @Override - public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) { - Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object."); - final Attributes2 pathAttributes2 = ((Attributes) attribute).getAugmentation(Attributes2.class); - if (pathAttributes2 == null) { - return; - } - final MpUnreachNlri mpUnreachNlri = pathAttributes2.getMpUnreachNlri(); - if (mpUnreachNlri == null) { - return; - } - final WithdrawnRoutes routes = mpUnreachNlri.getWithdrawnRoutes(); - if (routes != null) { - serializeRoutes(routes, byteAggregator); - } - } - - private static void serializeRoutes(final WithdrawnRoutes routes, final ByteBuf byteAggregator) { - if (routes.getDestinationType() instanceof DestinationIpv4Case) { - final DestinationIpv4Case destinationIpv4Case = (DestinationIpv4Case) routes.getDestinationType(); - if (destinationIpv4Case.getDestinationIpv4().getIpv4Prefixes() != null) { - for (final Ipv4Prefixes ipv4Prefix : destinationIpv4Case.getDestinationIpv4().getIpv4Prefixes()) { - PathIdUtil.writePathId(ipv4Prefix.getPathId(), byteAggregator); - ByteBufWriteUtil.writeMinimalPrefix(ipv4Prefix.getPrefix(), byteAggregator); - } - } - } else if (routes.getDestinationType() instanceof DestinationIpv6Case) { - final DestinationIpv6Case destinationIpv6Case = (DestinationIpv6Case) routes.getDestinationType(); - if (destinationIpv6Case.getDestinationIpv6().getIpv6Prefixes() != null) { - for (final Ipv6Prefixes ipv6Prefix : destinationIpv6Case.getDestinationIpv6().getIpv6Prefixes()) { - PathIdUtil.writePathId(ipv6Prefix.getPathId(), byteAggregator); - ByteBufWriteUtil.writeMinimalPrefix(ipv6Prefix.getPrefix(), byteAggregator); - } - } - } - } -} diff --git a/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/BGPParserTest.java b/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/BGPParserTest.java index f50a5953b7..5170e99019 100644 --- a/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/BGPParserTest.java +++ b/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/BGPParserTest.java @@ -32,12 +32,6 @@ import org.opendaylight.protocol.util.NoopReferenceCache; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.prefixes.DestinationIpv6Builder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.prefixes.destination.ipv6.Ipv6Prefixes; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.prefixes.destination.ipv6.Ipv6PrefixesBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv6CaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.UpdateBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes; @@ -46,28 +40,21 @@ 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.message.rev130919.path.attributes.attributes.AggregatorBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.AsPathBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.AtomicAggregateBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.ClusterIdBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.Communities; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.ExtendedCommunities; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.ExtendedCommunitiesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.LocalPrefBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.MultiExitDiscBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.OriginBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.OriginatorIdBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.UnrecognizedAttributes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.as.path.Segments; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.as.path.SegmentsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.message.Nlri; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.message.NlriBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.message.WithdrawnRoutesBuilder; -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.Attributes1Builder; 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.mp.reach.nlri.AdvertizedRoutesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily; @@ -75,10 +62,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.route.target.ipv4._case.RouteTargetIpv4Builder; 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.Ipv4NextHopCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv6NextHopCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv6NextHopCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.ipv6.next.hop._case.Ipv6NextHopBuilder; public class BGPParserTest { @@ -184,7 +168,7 @@ public class BGPParserTest { asPath.add(new SegmentsBuilder().setAsSequence(asNumbers).build()); final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop( - new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.2")).build()).build(); + new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.2")).build()).build(); final List comms = Lists.newArrayList(); comms.add((Communities) CommunityUtil.NO_EXPORT); @@ -242,131 +226,6 @@ public class BGPParserTest { assertArrayEquals(inputBytes.get(0), ByteArray.readAllBytes(buffer)); } - /* - * Tests IPv6 NEXT_HOP, NLRI, ORIGIN.IGP, MULTI_EXIT_DISC, ORIGINATOR-ID, CLUSTER_LIST. - * - * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker - * 00 80 <- length (128) - including header - * 02 <- message type - * 00 00 <- withdrawn routes length - * 00 69 <- total path attribute length (105) - * 40 <- attribute flags - * 01 <- attribute type code (origin) - * 01 <- attribute length - * 00 <- Origin value (IGP) - * 40 <- attribute flags - * 02 <- attribute type code (as path) - * 06 <- attribute length - * 02 <- AS_SEQUENCE - * 01 <- path segment count - * 00 00 fd e9 <- path segment value (65001) - * 40 <- attribute flags - * 03 <- attribute type code (next hop) - * 04 <- attribute length - * 0a 00 00 00 <- next hop value (10.0.0.0) - * 80 <- attribute flags - * 04 <- attribute type code (multi exit disc) - * 04 <- attribute length - * 00 00 00 00 <- value - * 80 <- attribute flags - * 09 <- attribute type code (originator id) - * 04 <- attribute length - * 7f 00 00 01 <- value (localhost ip) - * 80 <- attribute flags - * 0a <- attribute type code (cluster list) - * 08 <- attribute length - * 01 02 03 04 <- value - * 05 06 07 08 <- value - * 80 <- attribute flags - * 0e <- attribute type code (mp reach nlri) - * 40 <- attribute length - * 00 02 <- AFI (Ipv6) - * 01 <- SAFI (Unicast) - * 20 <- length of next hop - * 20 01 0d b8 00 00 00 00 00 00 00 00 00 00 00 01 <- global - * fe 80 00 00 00 00 00 00 c0 01 0b ff fe 7e 00 <- link local - * 00 <- reserved - * - * //NLRI - * 40 20 01 0d b8 00 01 00 02 <- IPv6 Prefix (2001:db8:1:2:: / 64) - * 40 20 01 0d b8 00 01 00 01 <- IPv6 Prefix (2001:db8:1:1:: / 64) - * 40 20 01 0d b8 00 01 00 00 <- IPv6 Prefix (2001:db8:1:: / 64) - * - */ - @Test - public void testGetUpdateMessage2() throws Exception { - final byte[] body = ByteArray.cutBytes(inputBytes.get(1), MessageUtil.COMMON_HEADER_LENGTH); - final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(1), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH)); - final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength); - - // check fields - assertNull(message.getWithdrawnRoutes()); - - final UpdateBuilder builder = new UpdateBuilder(); - - // check NLRI - - final List prefs = new ArrayList<>(); - prefs.add(new Ipv6PrefixesBuilder().setPrefix(new Ipv6Prefix("2001:db8:1:2::/64")).build()); - prefs.add(new Ipv6PrefixesBuilder().setPrefix(new Ipv6Prefix("2001:db8:1:1::/64")).build()); - prefs.add(new Ipv6PrefixesBuilder().setPrefix(new Ipv6Prefix("2001:db8:1::/64")).build()); - - assertNull(message.getNlri()); - - // attributes - final List asNumbers = new ArrayList(); - asNumbers.add(new AsNumber(65001L)); - final List asPath = Lists.newArrayList(); - asPath.add(new SegmentsBuilder().setAsSequence(asNumbers).build()); - - final Ipv6NextHopCase nextHop = new Ipv6NextHopCaseBuilder().setIpv6NextHop( - new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).setLinkLocal(new Ipv6Address("fe80::c001:bff:fe7e:0")).build()).build(); - - final List clusters = Lists.newArrayList(new ClusterIdentifier(new Ipv4Address("1.2.3.4")), - new ClusterIdentifier(new Ipv4Address("5.6.7.8"))); - - // check path attributes - - final Attributes attrs = message.getAttributes(); - - final AttributesBuilder paBuilder = new AttributesBuilder(); - - paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build()); - assertEquals(paBuilder.getOrigin(), attrs.getOrigin()); - - paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build()); - assertEquals(paBuilder.getAsPath(), attrs.getAsPath()); - - paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build()); - assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc()); - - paBuilder.setOriginatorId(new OriginatorIdBuilder().setOriginator(new Ipv4Address("127.0.0.1")).build()); - assertEquals(paBuilder.getOriginatorId(), attrs.getOriginatorId()); - - paBuilder.setClusterId(new ClusterIdBuilder().setCluster(clusters).build()); - assertEquals(paBuilder.getClusterId(), attrs.getClusterId()); - - final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder(); - mpBuilder.setAfi(Ipv6AddressFamily.class); - mpBuilder.setSafi(UnicastSubsequentAddressFamily.class); - mpBuilder.setCNextHop(nextHop); - mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType( - new DestinationIpv6CaseBuilder().setDestinationIpv6(new DestinationIpv6Builder().setIpv6Prefixes(prefs).build()).build()).build()); - - paBuilder.addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(mpBuilder.build()).build()); - assertEquals(paBuilder.getAugmentation(Attributes1.class).getMpReachNlri(), - attrs.getAugmentation(Attributes1.class).getMpReachNlri()); - paBuilder.setUnrecognizedAttributes(Collections. emptyList()); - // check API message - - builder.setAttributes(paBuilder.build()); - assertEquals(builder.build(), message); - - final ByteBuf buffer = Unpooled.buffer(); - BGPParserTest.updateParser.serializeMessage(message, buffer); - assertArrayEquals(inputBytes.get(1), ByteArray.readAllBytes(buffer)); - } - /* * Tests more AS Numbers in AS_PATH, AGGREGATOR, ORIGIN.INCOMPLETE * @@ -433,9 +292,9 @@ public class BGPParserTest { asPath.add(new SegmentsBuilder().setAsSet(asSet).build()); final Aggregator aggregator = new AggregatorBuilder().setAsNumber(new AsNumber((long) 30)).setNetworkAddress( - new Ipv4Address("10.0.0.9")).build(); + new Ipv4Address("10.0.0.9")).build(); final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop( - new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.9")).build()).build(); + new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.9")).build()).build(); // check path attributes final Attributes attrs = message.getAttributes(); @@ -527,13 +386,13 @@ public class BGPParserTest { // attributes final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop( - new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("3.3.3.3")).build()).build(); + new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("3.3.3.3")).build()).build(); final List comms = Lists.newArrayList(); comms.add(new ExtendedCommunitiesBuilder().setTransitive(true).setExtendedCommunity( - new RouteTargetIpv4CaseBuilder().setRouteTargetIpv4( - new RouteTargetIpv4Builder().setGlobalAdministrator( - new Ipv4Address("192.168.1.0")).setLocalAdministrator(4660).build()).build()).build()); + new RouteTargetIpv4CaseBuilder().setRouteTargetIpv4( + new RouteTargetIpv4Builder().setGlobalAdministrator( + new Ipv4Address("192.168.1.0")).setLocalAdministrator(4660).build()).build()).build()); // check path attributes final Attributes attrs = message.getAttributes(); @@ -589,7 +448,7 @@ public class BGPParserTest { // check API message final Update expectedMessage = new UpdateBuilder().setWithdrawnRoutes( - new WithdrawnRoutesBuilder().setWithdrawnRoutes(prefs).build()).build(); + new WithdrawnRoutesBuilder().setWithdrawnRoutes(prefs).build()).build(); assertEquals(expectedMessage.getWithdrawnRoutes(), message.getWithdrawnRoutes()); diff --git a/bgp/path-selection-mode/pom.xml b/bgp/path-selection-mode/pom.xml index c93c424776..c80d8839cb 100644 --- a/bgp/path-selection-mode/pom.xml +++ b/bgp/path-selection-mode/pom.xml @@ -92,6 +92,11 @@ config-util test + + org.opendaylight.bgpcep + bgp-inet + test + diff --git a/bgp/rib-impl/pom.xml b/bgp/rib-impl/pom.xml index 24255195c7..0cc8294863 100644 --- a/bgp/rib-impl/pom.xml +++ b/bgp/rib-impl/pom.xml @@ -172,6 +172,10 @@ ${project.groupId} bgp-path-selection-mode + + ${project.groupId} + bgp-inet + org.osgi diff --git a/bgp/rib-impl/src/main/resources/org/opendaylight/blueprint/bgp-rib.xml b/bgp/rib-impl/src/main/resources/org/opendaylight/blueprint/bgp-rib.xml index e5c43440c2..afa6e24bb7 100644 --- a/bgp/rib-impl/src/main/resources/org/opendaylight/blueprint/bgp-rib.xml +++ b/bgp/rib-impl/src/main/resources/org/opendaylight/blueprint/bgp-rib.xml @@ -2,10 +2,6 @@ - - - diff --git a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractRIBTestSetup.java b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractRIBTestSetup.java index c74b57ac4e..68262083c2 100755 --- a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractRIBTestSetup.java +++ b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractRIBTestSetup.java @@ -36,6 +36,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService; import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier; import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain; +import org.opendaylight.protocol.bgp.inet.RIBActivator; import org.opendaylight.protocol.bgp.mode.impl.base.BasePathSelectionModeFactory; import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl; import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher; @@ -144,8 +145,8 @@ public class AbstractRIBTestSetup { mockedMethods(); this.rib = new RIBImpl(new RibId("test"), new AsNumber(5L), this.RIB_ID, this.CLUSTER_ID, context, this.dispatcher, this.codecFactory, this.dom, - localTables, Collections.singletonMap(new TablesKey(AFI, SAFI), BasePathSelectionModeFactory.createBestPathSelectionStrategy()), - GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy()); + localTables, Collections.singletonMap(new TablesKey(AFI, SAFI), BasePathSelectionModeFactory.createBestPathSelectionStrategy()), + GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy()); this.rib.onGlobalContextUpdated(schemaContext); this.ribSupport = getRib().getRibSupportContext().getRIBSupportContext(KEY).getRibSupport(); } @@ -251,6 +252,7 @@ public class AbstractRIBTestSetup { return null; } + @Override public void close() { } } diff --git a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriterTest.java b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriterTest.java index dacd8dd818..9449b8af74 100644 --- a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriterTest.java +++ b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriterTest.java @@ -26,7 +26,6 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener; @@ -34,11 +33,14 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService; import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier; import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain; +import org.opendaylight.protocol.bgp.inet.RIBActivator; import org.opendaylight.protocol.bgp.mode.impl.base.BasePathSelectionModeFactory; import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContext; import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContextRegistry; import org.opendaylight.protocol.bgp.rib.impl.stats.UnsignedInt32Counter; +import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext; import org.opendaylight.protocol.bgp.rib.spi.RibSupportUtils; +import org.opendaylight.protocol.bgp.rib.spi.SimpleRIBExtensionProviderContext; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes.Ipv4Route; @@ -84,40 +86,39 @@ public class LocRibWriterTest { private final TablesKey tablesKey = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class); private final UnsignedInt32Counter routeCounter = new UnsignedInt32Counter("loc-rib"); + private RIBActivator ribActivator; + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - Answer answer = new Answer() { - @Override - public Object answer(final InvocationOnMock invocation) throws Throwable { - final Object[] args = invocation.getArguments(); - final NormalizedNode node = (NormalizedNode) args[2]; - if (node.getNodeType().equals(Ipv4Route.QNAME) || node.getNodeType().equals(PREFIX_QNAME)) { - LocRibWriterTest.this.routes.add((YangInstanceIdentifier) args[1]); - } - return args[1]; + this.ribActivator = new RIBActivator(); + final RIBExtensionProviderContext ribExtension = new SimpleRIBExtensionProviderContext(); + this.ribActivator.startRIBExtensionProvider(ribExtension); + + final Answer answer = invocation -> { + final Object[] args = invocation.getArguments(); + final NormalizedNode node = (NormalizedNode) args[2]; + if (node.getNodeType().equals(Ipv4Route.QNAME) || node.getNodeType().equals(PREFIX_QNAME)) { + LocRibWriterTest.this.routes.add((YangInstanceIdentifier) args[1]); } + return args[1]; }; doAnswer(answer).when(this.domTransWrite).put(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class)); doAnswer(answer).when(this.domTransWrite).merge(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class)); - doAnswer(new Answer() { - - @Override - public Object answer(final InvocationOnMock invocation) throws Throwable { - final Object[] args = invocation.getArguments(); - LocRibWriterTest.this.routes.remove(args[1]); - return args[1]; - } + doAnswer(invocation -> { + final Object[] args = invocation.getArguments(); + LocRibWriterTest.this.routes.remove(args[1]); + return args[1]; }).when(this.domTransWrite).delete(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class)); doReturn(this.context).when(this.registry).getRIBSupportContext(any(TablesKey.class)); - doReturn(IPv4RIBSupport.getInstance()).when(this.context).getRibSupport(); + doReturn(ribExtension.getRIBSupport(this.tablesKey)).when(this.context).getRibSupport(); doReturn(this.domTransWrite).when(this.chain).newWriteOnlyTransaction(); doReturn(this.future).when(this.domTransWrite).submit(); doReturn(null).when(this.service).registerDataTreeChangeListener(any(DOMDataTreeIdentifier.class), any(DOMDataTreeChangeListener.class)); this.locRibWriter = LocRibWriter.create(this.registry, this.tablesKey, this.chain, YangInstanceIdentifier.of(BgpRib.QNAME), - new AsNumber((long) 35), this.service, this.pd, new CacheDisconnectedPeersImpl(), BasePathSelectionModeFactory.createBestPathSelectionStrategy(), - routeCounter); + new AsNumber((long) 35), this.service, this.pd, new CacheDisconnectedPeersImpl(), BasePathSelectionModeFactory.createBestPathSelectionStrategy(), + this.routeCounter); } private DataTreeCandidate prepareUpdate() { diff --git a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ParserToSalTest.java b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ParserToSalTest.java index 75cadeac9e..8a2e3eb056 100755 --- a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ParserToSalTest.java +++ b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ParserToSalTest.java @@ -9,7 +9,7 @@ package org.opendaylight.protocol.bgp.rib.impl; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import com.google.common.base.Function; + import com.google.common.base.Optional; import com.google.common.base.Throwables; import com.google.common.collect.Collections2; @@ -23,7 +23,6 @@ import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.concurrent.ExecutionException; -import javax.annotation.Nullable; import org.junit.After; import org.junit.Test; import org.mockito.Mock; @@ -34,6 +33,7 @@ import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest; import org.opendaylight.controller.md.sal.binding.test.DataBrokerTestCustomizer; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.sal.core.api.model.SchemaService; +import org.opendaylight.protocol.bgp.inet.RIBActivator; import org.opendaylight.protocol.bgp.mode.impl.base.BasePathSelectionModeFactory; import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl; import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext; @@ -45,7 +45,6 @@ import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext; import org.opendaylight.protocol.bgp.rib.spi.SimpleRIBExtensionProviderContext; import org.opendaylight.protocol.bgp.util.HexDumpBGPFileParser; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes.Ipv4Route; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.routes.ipv6.routes.Ipv6Route; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateAddressFamily; @@ -133,9 +132,9 @@ public class ParserToSalTest extends AbstractDataBrokerTest { final List tables = ImmutableList.of( (BgpTableType) new BgpTableTypeImpl(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class)); final RIBImpl rib = new RIBImpl(new RibId(TEST_RIB_ID), new AsNumber(72L), new BgpId("127.0.0.1"), null, this.ext2, this.dispatcher, - this.codecFactory, getDomBroker(), tables, - Collections.singletonMap(new TablesKey(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class), - BasePathSelectionModeFactory.createBestPathSelectionStrategy()), GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy()); + this.codecFactory, getDomBroker(), tables, + Collections.singletonMap(new TablesKey(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class), + BasePathSelectionModeFactory.createBestPathSelectionStrategy()), GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy()); assertTablesExists(tables, true); rib.onGlobalContextUpdated(this.schemaService.getGlobalContext()); final BGPPeer peer = new BGPPeer("peer-" + this.mock.toString(), rib, PeerRole.Ibgp, null); @@ -148,9 +147,9 @@ public class ParserToSalTest extends AbstractDataBrokerTest { public void testWithoutLinkstate() throws InterruptedException, ExecutionException { final List tables = ImmutableList.of((BgpTableType) new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class)); final RIBImpl rib = new RIBImpl(new RibId(TEST_RIB_ID), new AsNumber(72L), new BgpId("127.0.0.1"), null, this.ext1, this.dispatcher, - this.codecFactory, getDomBroker(), tables, - Collections.singletonMap(new TablesKey(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class), - BasePathSelectionModeFactory.createBestPathSelectionStrategy()), GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy()); + this.codecFactory, getDomBroker(), tables, + Collections.singletonMap(new TablesKey(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class), + BasePathSelectionModeFactory.createBestPathSelectionStrategy()), GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy()); rib.onGlobalContextUpdated(this.schemaService.getGlobalContext()); assertTablesExists(tables, true); final BGPPeer peer = new BGPPeer("peer-" + this.mock.toString(), rib, PeerRole.Ibgp, null); @@ -160,19 +159,14 @@ public class ParserToSalTest extends AbstractDataBrokerTest { } private static Collection fixMessages(final Collection bgpMessages) { - return Collections2.transform(bgpMessages, new Function() { - - @Nullable - @Override - public byte[] apply(@Nullable final byte[] input) { - final byte[] ret = new byte[input.length + 1]; - // ff - ret[0] = -1; - for (int i = 0; i < input.length; i++) { - ret[i + 1] = input[i]; - } - return ret; + return Collections2.transform(bgpMessages, input -> { + final byte[] ret = new byte[input.length + 1]; + // ff + ret[0] = -1; + for (int i = 0; i < input.length; i++) { + ret[i + 1] = input[i]; } + return ret; }); } diff --git a/bgp/rib-spi/pom.xml b/bgp/rib-spi/pom.xml index b35fbd1d54..28793b3b32 100644 --- a/bgp/rib-spi/pom.xml +++ b/bgp/rib-spi/pom.xml @@ -46,11 +46,11 @@ ${project.groupId} - bgp-rib-api + bgp-parser-spi ${project.groupId} - bgp-inet + bgp-rib-api org.opendaylight.mdsal.model @@ -88,6 +88,10 @@ com.google.guava guava + + io.netty + netty-transport + com.google.code.findbugs diff --git a/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/SimpleRIBExtensionTest.java b/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/SimpleRIBExtensionTest.java index d6bb5388bd..68c23c4ee5 100644 --- a/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/SimpleRIBExtensionTest.java +++ b/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/SimpleRIBExtensionTest.java @@ -12,11 +12,10 @@ import java.util.List; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.bgp.rib.rib.loc.rib.tables.routes.Ipv4RoutesCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.Ipv4Routes; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes.Ipv4Route; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.Route; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily; +import org.opendaylight.yangtools.yang.binding.DataObject; public class SimpleRIBExtensionTest { @@ -35,10 +34,10 @@ public class SimpleRIBExtensionTest { private final class TestActivator extends AbstractRIBExtensionProviderActivator { @Override protected List startRIBExtensionProviderImpl(final RIBExtensionProviderContext context) { - RIBSupport support = Mockito.mock(RIBSupport.class); - Mockito.doReturn(Ipv4Route.class).when(support).routesListClass(); - Mockito.doReturn(Ipv4Routes.class).when(support).routesContainerClass(); - Mockito.doReturn(Ipv4RoutesCase.class).when(support).routesCaseClass(); + final RIBSupport support = Mockito.mock(RIBSupport.class); + Mockito.doReturn(Route.class).when(support).routesListClass(); + Mockito.doReturn(DataObject.class).when(support).routesContainerClass(); + Mockito.doReturn(DataObject.class).when(support).routesCaseClass(); return Lists.newArrayList((AutoCloseable)context.registerRIBSupport(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, support)); } } diff --git a/features/bgp/src/main/features/features.xml b/features/bgp/src/main/features/features.xml index 5b1feca8fc..61a23472a7 100644 --- a/features/bgp/src/main/features/features.xml +++ b/features/bgp/src/main/features/features.xml @@ -68,19 +68,14 @@ - odl-bgpcep-bgp-dependencies - odl-config-api - odl-yangtools-yang-data - mvn:org.opendaylight.bgpcep/bgp-parser-api/{{VERSION}} - mvn:org.opendaylight.bgpcep/bgp-parser-spi/{{VERSION}} - mvn:org.opendaylight.bgpcep/bgp-rib-api/{{VERSION}} + odl-bgpcep-bgp-parser + odl-bgpcep-bgp-rib-api mvn:org.opendaylight.bgpcep/bgp-inet/{{VERSION}} mvn:org.opendaylight.bgpcep/bgp-bmp-api/{{VERSION}} odl-bgpcep-bgp-dependencies - odl-bgpcep-bgp-inet odl-config-api odl-yangtools-yang-data mvn:org.opendaylight.bgpcep/bgp-parser-api/{{VERSION}} @@ -109,6 +104,7 @@ odl-bgpcep-bgp-parser odl-bgpcep-bgp-rib-api + odl-bgpcep-bgp-inet mvn:org.opendaylight.bgpcep/bgp-flowspec/{{VERSION}} mvn:org.opendaylight.bgpcep/bgp-bmp-api/{{VERSION}} @@ -116,6 +112,7 @@ odl-bgpcep-bgp-parser odl-bgpcep-bgp-rib-api + odl-bgpcep-bgp-inet mvn:org.opendaylight.bgpcep/bgp-labeled-unicast/{{VERSION}} mvn:org.opendaylight.bgpcep/bgp-bmp-api/{{VERSION}} @@ -149,6 +146,7 @@ odl-bgpcep-bgp-linkstate odl-bgpcep-bgp-rib-api odl-bgpcep-bgp-path-selection-mode + odl-bgpcep-bgp-inet mvn:org.opendaylight.bgpcep/bgp-openconfig-spi/{{VERSION}} mvn:org.opendaylight.bgpcep/bgp-rib-impl/{{VERSION}}