BUG-7706: Fix ServiceUnavailableException 18/51218/5
authorClaudio D. Gasparini <cgaspari@cisco.com>
Mon, 30 Jan 2017 09:17:02 +0000 (10:17 +0100)
committerRobert Varga <nite@hq.sk>
Sat, 11 Feb 2017 15:41:35 +0000 (15:41 +0000)
Reconfigure BGP Server durin a session, will produce
ServiceUnavailableException at the moment session is
closed and tries to remove peer from StrictRegistry.
Fix by put aside registry from Peer Acceptor, therefore
when BP container is restarted reference wont be lost.

Change-Id: I4eb018a24e5c5ea2a4b479cba61d94cb3658f583
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
Signed-off-by: Robert Varga <rovarga@cisco.com>
21 files changed:
bgp/peer-acceptor/src/main/java/org/opendaylight/protocol/bgp/peer/acceptor/BGPPeerAcceptorImpl.java
bgp/peer-acceptor/src/main/resources/org/opendaylight/blueprint/bgp-acceptor.xml
bgp/peer-acceptor/src/test/java/org/opendaylight/protocol/bgp/peer/acceptor/BGPPeerAcceptorImplTest.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPDispatcherImpl.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/config/BgpPeer.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/spi/BGPDispatcher.java
bgp/rib-impl/src/main/resources/org/opendaylight/blueprint/bgp-rib.xml
bgp/rib-impl/src/test/java/org/opendaylight/controller/config/yang/bgp/rib/impl/AbstractRIBImplModuleTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractAddPathTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractBGPDispatcherTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AddPathAllPathsTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AddPathBasePathsTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AddPathNPathsTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/BGPDispatcherImplTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ParserToSalTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/SynchronizationAndExceptionTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/config/AbstractConfig.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/config/BgpDeployerImplTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/config/BgpPeerTest.java
bgp/testtool/src/main/java/org/opendaylight/protocol/bgp/testtool/BGPPeerBuilder.java
bgp/testtool/src/main/java/org/opendaylight/protocol/bgp/testtool/BGPTestTool.java

index c6a809a6316278ba58a88958e91039ba7039111f..9cb88c2cd20a51a73909e20ec2c6c47a275d62c1 100644 (file)
@@ -34,15 +34,13 @@ import org.slf4j.LoggerFactory;
 public final class BGPPeerAcceptorImpl implements AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(BGPPeerAcceptorImpl.class);
     private static final int PRIVILEGED_PORTS = 1024;
-    private final BGPPeerRegistry peerRegistry;
     private final BGPDispatcher bgpDispatcher;
     private final InetSocketAddress address;
     private ChannelFuture futureChannel;
     private AutoCloseable listenerRegistration;
 
     public BGPPeerAcceptorImpl(final IpAddress bindingAddress, final PortNumber portNumber,
-        final BGPPeerRegistry peerRegistry, final BGPDispatcher bgpDispatcher) {
-        this.peerRegistry = Preconditions.checkNotNull(peerRegistry);
+        final BGPDispatcher bgpDispatcher) {
         this.bgpDispatcher = Preconditions.checkNotNull(bgpDispatcher);
         this.address = getAddress(Preconditions.checkNotNull(bindingAddress), Preconditions.checkNotNull(portNumber));
         if (!PlatformDependent.isWindows() && !PlatformDependent.isRoot()
@@ -55,14 +53,14 @@ public final class BGPPeerAcceptorImpl implements AutoCloseable {
     public void start() {
         LOG.debug("Instantiating BGP Peer Acceptor : {}", this.address);
 
-        this.futureChannel = this.bgpDispatcher.createServer(this.peerRegistry, this.address);
+        this.futureChannel = this.bgpDispatcher.createServer(this.address);
         // Validate future success
         this.futureChannel.addListener(future -> {
             Preconditions.checkArgument(future.isSuccess(), "Unable to start bgp server on %s",
                 this.address, future.cause());
             final Channel channel = this.futureChannel.channel();
             if (Epoll.isAvailable()) {
-                this.listenerRegistration = this.peerRegistry.registerPeerRegisterListener(
+                this.listenerRegistration = this.bgpDispatcher.getBGPPeerRegistry().registerPeerRegisterListener(
                     new BGPPeerAcceptorImpl.PeerRegistryListenerImpl(channel.config()));
             }
         });
index f68747613d638d266e083f0c9ef027ae085e9155..41a1af616783937b618f5e7ab90bee6677b49faa 100644 (file)
@@ -1,7 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
            xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0">
-    <reference id="BGPPeerRegistry" interface="org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry"/>
     <reference id="BGPDispatcher" interface="org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher"/>
 
     <odl:clustered-app-config id="bgpPeerAcceptorConfig"
@@ -25,7 +24,6 @@
         <argument>
             <bean factory-ref="bgpPeerAcceptorConfig" factory-method="getBindingPort"/>
         </argument>
-        <argument ref="BGPPeerRegistry"/>
         <argument ref="BGPDispatcher"/>
     </bean>
 </blueprint>
\ No newline at end of file
index 80c0e3e25fd7136da683fba964d3df411c514b12..d412d3233e6a5aba91a95b58dabf5a553a7347d4 100644 (file)
@@ -32,10 +32,10 @@ public class BGPPeerAcceptorImplTest extends AbstractBGPDispatcherTest {
         this.registry.addPeer(serverIpAddress, this.serverListener, createPreferences(inetServerAddress));
 
         final BGPPeerAcceptorImpl bgpPeerAcceptor = new BGPPeerAcceptorImpl(serverIpAddress, portNumber,
-            this.registry, this.serverDispatcher);
+            this.serverDispatcher);
         bgpPeerAcceptor.start();
         final Future<BGPSessionImpl> futureClient = this.clientDispatcher
-            .createClient(this.clientAddress, inetServerAddress, this.registry, 2, true);
+            .createClient(this.clientAddress, inetServerAddress, 2, true);
         waitFutureSuccess(futureClient);
         final BGPSessionImpl session = futureClient.get();
         Assert.assertEquals(State.UP, this.clientListener.getState());
index 5160d566b496ac3836ba4a0951f5f06ecd5a118f..077fa1b117cea880e41e3ae2ec8942fea688b1eb 100644 (file)
@@ -58,8 +58,10 @@ public class BGPDispatcherImpl implements BGPDispatcher, AutoCloseable {
     private final BGPHandlerFactory handlerFactory;
     private final EventLoopGroup bossGroup;
     private final EventLoopGroup workerGroup;
+    private final BGPPeerRegistry bgpPeerRegistry;
 
-    public BGPDispatcherImpl(final MessageRegistry messageRegistry, final EventLoopGroup bossGroup, final EventLoopGroup workerGroup) {
+    public BGPDispatcherImpl(final MessageRegistry messageRegistry, final EventLoopGroup bossGroup,
+        final EventLoopGroup workerGroup, final BGPPeerRegistry bgpPeerRegistry) {
         if (Epoll.isAvailable()) {
             this.bossGroup = new EpollEventLoopGroup();
             this.workerGroup = new EpollEventLoopGroup();
@@ -67,20 +69,22 @@ public class BGPDispatcherImpl implements BGPDispatcher, AutoCloseable {
             this.bossGroup = Preconditions.checkNotNull(bossGroup);
             this.workerGroup = Preconditions.checkNotNull(workerGroup);
         }
+        this.bgpPeerRegistry = Preconditions.checkNotNull(bgpPeerRegistry);
         this.handlerFactory = new BGPHandlerFactory(messageRegistry);
     }
 
     @Override
-    public synchronized Future<BGPSessionImpl> createClient(final InetSocketAddress remoteAddress, final BGPPeerRegistry listener, final int retryTimer) {
-        return createClient(remoteAddress, listener, retryTimer, createClientBootStrap(Optional.absent(), false));
+    public synchronized Future<BGPSessionImpl> createClient(final InetSocketAddress remoteAddress, final int retryTimer) {
+        return createClient(remoteAddress, retryTimer, createClientBootStrap(Optional.absent(), false));
     }
 
-    private synchronized Future<BGPSessionImpl> createClient(final InetSocketAddress remoteAddress, final BGPPeerRegistry listener, final int retryTimer,
-            final Bootstrap clientBootStrap) {
-        final BGPClientSessionNegotiatorFactory snf = new BGPClientSessionNegotiatorFactory(listener);
+    private synchronized Future<BGPSessionImpl> createClient(final InetSocketAddress remoteAddress,
+        final int retryTimer, final Bootstrap clientBootStrap) {
+        final BGPClientSessionNegotiatorFactory snf = new BGPClientSessionNegotiatorFactory(this.bgpPeerRegistry);
         final ChannelPipelineInitializer initializer = BGPChannel.createChannelPipelineInitializer(this.handlerFactory, snf);
 
-        final BGPProtocolSessionPromise sessionPromise = new BGPProtocolSessionPromise(remoteAddress, retryTimer, clientBootStrap, listener);
+        final BGPProtocolSessionPromise sessionPromise = new BGPProtocolSessionPromise(remoteAddress, retryTimer,
+            clientBootStrap, this.bgpPeerRegistry);
         clientBootStrap.handler(BGPChannel.createClientChannelHandler(initializer, sessionPromise));
         sessionPromise.connect();
         LOG.debug("Client created.");
@@ -88,11 +92,11 @@ public class BGPDispatcherImpl implements BGPDispatcher, AutoCloseable {
     }
 
     @VisibleForTesting
-    public synchronized Future<BGPSessionImpl> createClient(final InetSocketAddress localAddress, final InetSocketAddress remoteAddress,
-            final BGPPeerRegistry strictBGPPeerRegistry, final int retryTimer, final boolean reuseAddress) {
+    public synchronized Future<BGPSessionImpl> createClient(final InetSocketAddress localAddress,
+        final InetSocketAddress remoteAddress, final int retryTimer, final boolean reuseAddress) {
         final Bootstrap clientBootStrap = createClientBootStrap(Optional.absent(), reuseAddress);
         clientBootStrap.localAddress(localAddress);
-        return createClient(remoteAddress, strictBGPPeerRegistry, retryTimer, clientBootStrap);
+        return createClient(remoteAddress, retryTimer, clientBootStrap);
     }
 
     private synchronized Bootstrap createClientBootStrap(final Optional<KeyMapping> keys, final boolean reuseAddress) {
@@ -135,26 +139,28 @@ public class BGPDispatcherImpl implements BGPDispatcher, AutoCloseable {
     }
 
     @Override
-    public synchronized Future<Void> createReconnectingClient(final InetSocketAddress remoteAddress, final BGPPeerRegistry peerRegistry,
+    public synchronized Future<Void> createReconnectingClient(final InetSocketAddress remoteAddress,
             final int retryTimer, final Optional<KeyMapping> keys) {
-        return createReconnectingClient(remoteAddress, peerRegistry, retryTimer, keys, null, false);
+        return createReconnectingClient(remoteAddress, retryTimer, keys, null, false);
     }
 
     @VisibleForTesting
-    protected synchronized Future<Void> createReconnectingClient(final InetSocketAddress remoteAddress, final BGPPeerRegistry peerRegistry,
-        final int retryTimer, final Optional<KeyMapping> keys, final InetSocketAddress localAddress, final boolean reuseAddress) {
-        final BGPClientSessionNegotiatorFactory snf = new BGPClientSessionNegotiatorFactory(peerRegistry);
+    protected synchronized Future<Void> createReconnectingClient(final InetSocketAddress remoteAddress,
+        final int retryTimer, final Optional<KeyMapping> keys, final InetSocketAddress localAddress,
+        final boolean reuseAddress) {
+        final BGPClientSessionNegotiatorFactory snf = new BGPClientSessionNegotiatorFactory(this.bgpPeerRegistry);
         final Bootstrap bootstrap = createClientBootStrap(keys, reuseAddress);
         bootstrap.localAddress(localAddress);
-        final BGPReconnectPromise reconnectPromise = new BGPReconnectPromise(GlobalEventExecutor.INSTANCE, remoteAddress,
-            retryTimer, bootstrap, peerRegistry, BGPChannel.createChannelPipelineInitializer(this.handlerFactory, snf));
+        final BGPReconnectPromise reconnectPromise = new BGPReconnectPromise(GlobalEventExecutor.INSTANCE,
+            remoteAddress, retryTimer, bootstrap, this.bgpPeerRegistry,
+            BGPChannel.createChannelPipelineInitializer(this.handlerFactory, snf));
         reconnectPromise.connect();
         return reconnectPromise;
     }
 
     @Override
-    public synchronized ChannelFuture createServer(final BGPPeerRegistry registry, final InetSocketAddress serverAddress) {
-        final BGPServerSessionNegotiatorFactory snf = new BGPServerSessionNegotiatorFactory(registry);
+    public synchronized ChannelFuture createServer(final InetSocketAddress serverAddress) {
+        final BGPServerSessionNegotiatorFactory snf = new BGPServerSessionNegotiatorFactory(this.bgpPeerRegistry);
         final ChannelPipelineInitializer initializer = BGPChannel.createChannelPipelineInitializer(this.handlerFactory, snf);
         final ServerBootstrap serverBootstrap = createServerBootstrap(initializer);
         final ChannelFuture channelFuture = serverBootstrap.bind(serverAddress);
@@ -162,6 +168,11 @@ public class BGPDispatcherImpl implements BGPDispatcher, AutoCloseable {
         return channelFuture;
     }
 
+    @Override
+    public BGPPeerRegistry getBGPPeerRegistry() {
+        return this.bgpPeerRegistry;
+    }
+
     private synchronized ServerBootstrap createServerBootstrap(final ChannelPipelineInitializer initializer) {
         final ServerBootstrap serverBootstrap = new ServerBootstrap();
         if (Epoll.isAvailable()) {
index 31b0cd37c94a6daf144cc6aaeff0e95c35a9c29c..dea2d865e28ba89aa4fbbc785f94c6ec49f7ebd9 100644 (file)
@@ -71,14 +71,12 @@ public final class BgpPeer implements PeerBean, BGPPeerStateConsumer, BGPPeerRun
     private static final Logger LOG = LoggerFactory.getLogger(BgpPeer.class);
 
     private final RpcProviderRegistry rpcRegistry;
-    private final BGPPeerRegistry peerRegistry;
     private ServiceRegistration<?> serviceRegistration;
     private Neighbor currentConfiguration;
     private BgpPeerSingletonService bgpPeerSingletonService;
 
-    public BgpPeer(final RpcProviderRegistry rpcRegistry, final BGPPeerRegistry peerRegistry) {
+    public BgpPeer(final RpcProviderRegistry rpcRegistry) {
         this.rpcRegistry = rpcRegistry;
-        this.peerRegistry = peerRegistry;
     }
 
     @Override
@@ -262,10 +260,9 @@ public final class BgpPeer implements PeerBean, BGPPeerStateConsumer, BGPPeerRun
             }
             LOG.info("Peer Singleton Service {} instantiated", getIdentifier().getValue());
             this.bgpPeer.instantiateServiceInstance();
-            BgpPeer.this.peerRegistry.addPeer(this.neighborAddress, this.bgpPeer, this.prefs);
+            this.dispatcher.getBGPPeerRegistry().addPeer(this.neighborAddress, this.bgpPeer, this.prefs);
             if (this.activeConnection) {
-                this.connection = this.dispatcher.createReconnectingClient(this.inetAddress, BgpPeer.this.peerRegistry,
-                    this.retryTimer, this.key);
+                this.connection = this.dispatcher.createReconnectingClient(this.inetAddress, this.retryTimer, this.key);
             }
         }
 
@@ -278,7 +275,7 @@ public final class BgpPeer implements PeerBean, BGPPeerStateConsumer, BGPPeerRun
             }
             this.bgpPeer.close();
             if(BgpPeer.this.currentConfiguration != null) {
-                BgpPeer.this.peerRegistry.removePeer(BgpPeer.this.currentConfiguration.getNeighborAddress());
+                this.dispatcher.getBGPPeerRegistry().removePeer(BgpPeer.this.currentConfiguration.getNeighborAddress());
             }
             return Futures.immediateFuture(null);
         }
index 0b2b35a764957e604685e0264964ae4c04e4a2e9..18e40f9559558391885a131099a079cb6da06e5c 100755 (executable)
@@ -23,31 +23,33 @@ public interface BGPDispatcher{
      * Creates BGP client.
      *
      * @param remoteAddress remote Peer address
-     * @param peerRegistry BGP peer registry
      * @param retryTimer Retry timer
      * @return Future promising a client session
      */
-    Future<? extends BGPSession> createClient(InetSocketAddress remoteAddress, BGPPeerRegistry peerRegistry, int retryTimer);
+    Future<? extends BGPSession> createClient(InetSocketAddress remoteAddress, int retryTimer);
 
     /**
      * Creates Reconnecting client.
      *
      * @param remoteAddress remote Peer Address
-     * @param peerRegistry BGP peer registry
      * @param retryTimer Retry timer
      * @param keys for TCPMD5
      * @return Future promising a client session
      */
-    Future<Void> createReconnectingClient(InetSocketAddress remoteAddress,
-        BGPPeerRegistry peerRegistry, int retryTimer, Optional<KeyMapping> keys);
+    Future<Void> createReconnectingClient(InetSocketAddress remoteAddress, int retryTimer, Optional<KeyMapping> keys);
 
     /**
      * Create new BGP server to accept incoming bgp connections (bound to provided socket localAddress).
      *
-     * @param peerRegistry BGP peer registry
      * @param localAddress Peer localAddress
      *
      * @return ChannelFuture promising a client session
      */
-    ChannelFuture createServer(BGPPeerRegistry peerRegistry, InetSocketAddress localAddress);
+    ChannelFuture createServer(InetSocketAddress localAddress);
+
+    /**
+     * Return BGP Peer Registry
+     * @return BGPPeerRegistry
+     */
+    BGPPeerRegistry getBGPPeerRegistry();
 }
index 6fa18b2c5a3ae3471b32da12bdd748df848c2a62..d3a78a34acb4eb781f5f883857cbbacdb3beb988 100644 (file)
@@ -7,12 +7,28 @@
   <reference id="globalWorkerGroup" interface="io.netty.channel.EventLoopGroup" odl:type="global-worker-group"/>
   <reference id="clusterSingletonServiceProvider" interface="org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider"/>
 
+  <bean id="BGPPeerRegistry" class="org.opendaylight.protocol.bgp.rib.impl.StrictBGPPeerRegistry"
+          factory-method="instance" destroy-method="close"/>
+
+  <service ref="BGPPeerRegistry" interface="org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry"
+          odl:type="default">
+    <!-- The following service properties specify the config system module and instance that correspond to
+         this OSGi service which enables the config system module to be restarted when this blueprint
+         container is restarted. -->
+    <service-properties>
+      <entry key="config-module-namespace" value="urn:opendaylight:params:xml:ns:yang:controller:bgp:rib:impl"/>
+      <entry key="config-module-name" value="strict-bgp-peer-registry"/>
+      <entry key="config-instance-name" value="global-bgp-peer-registry"/>
+    </service-properties>
+  </service>
+
   <bean id="BGPDispatcher" class="org.opendaylight.protocol.bgp.rib.impl.BGPDispatcherImpl"  destroy-method="close">
     <argument>
       <bean factory-ref="BGPExtensionContext" factory-method="getMessageRegistry"/>
     </argument>
     <argument ref="globalBossGroup"/>
     <argument ref="globalWorkerGroup"/>
+    <argument ref="BGPPeerRegistry"/>
   </bean>
 
   <service ref="BGPDispatcher" interface="org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher">
     </service-properties>
   </service>
 
-  <bean id="BGPPeerRegistry" class="org.opendaylight.protocol.bgp.rib.impl.StrictBGPPeerRegistry"
-          factory-method="instance" destroy-method="close"/>
-
-  <service ref="BGPPeerRegistry" interface="org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry"
-          odl:type="default">
-    <!-- The following service properties specify the config system module and instance that correspond to
-         this OSGi service which enables the config system module to be restarted when this blueprint
-         container is restarted. -->
-    <service-properties>
-      <entry key="config-module-namespace" value="urn:opendaylight:params:xml:ns:yang:controller:bgp:rib:impl"/>
-      <entry key="config-module-name" value="strict-bgp-peer-registry"/>
-      <entry key="config-instance-name" value="global-bgp-peer-registry"/>
-    </service-properties>
-  </service>
-
   <reference id="dataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker" odl:type="pingpong"/>
   <reference id="globalBgpExtensions" interface="org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext"/>
   <reference id="codecTreeFactory" interface="org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeFactory"/>
@@ -70,7 +71,6 @@
 
   <bean id="bgpPeer" class="org.opendaylight.protocol.bgp.rib.impl.config.BgpPeer" scope="prototype">
     <argument ref="rpcRegistry"/>
-    <argument ref="BGPPeerRegistry"/>
   </bean>
 
   <bean id="appPeer" class="org.opendaylight.protocol.bgp.rib.impl.config.AppPeer" scope="prototype"/>
index 507e577b7823939589a71ec215a1c7ec1c0c39b7..2d582b3d7e3d1b6a53dc32620d1599bb5868d6e2 100755 (executable)
@@ -261,8 +261,8 @@ public abstract class AbstractRIBImplModuleTest extends AbstractConfigTest {
         setupMockService(DOMMountPointService.class, mock(DOMMountPointService.class));
 
         setupMockService(BGPDispatcher.class, this.mockedBGPDispatcher);
-        doReturn(new SucceededFuture<>(ImmediateEventExecutor.INSTANCE, null)).when(this.mockedBGPDispatcher).createReconnectingClient(
-                any(InetSocketAddress.class), any(BGPPeerRegistry.class), anyInt(), any(Optional.class));
+        doReturn(new SucceededFuture<>(ImmediateEventExecutor.INSTANCE, null)).when(this.mockedBGPDispatcher)
+            .createReconnectingClient(any(InetSocketAddress.class), anyInt(), any(Optional.class));
 
         setupMockService(BgpDeployer.class, this.bgpDeployer);
         final Global global = mock(Global.class);
index 025686f9c647115f39cff2306faf133166a44638..81a44ebfebb2858b0ef2570396049c5674ab2e87 100644 (file)
@@ -15,7 +15,6 @@ import static org.opendaylight.protocol.util.CheckUtil.waitFutureSuccess;
 import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
-import com.google.common.net.InetAddresses;
 import io.netty.channel.epoll.Epoll;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.util.concurrent.Future;
@@ -45,7 +44,6 @@ import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
 import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
-import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
 import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext;
 import org.opendaylight.protocol.bgp.rib.spi.SimpleRIBExtensionProviderContext;
 import org.opendaylight.protocol.util.InetSocketAddressUtil;
@@ -94,7 +92,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.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.BgpRib;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.Peer;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
@@ -147,13 +144,14 @@ class AbstractAddPathTest extends AbstractDataBrokerTest {
     @Mock
     protected ClusterSingletonServiceProvider clusterSingletonServiceProvider;
     BindingToNormalizedNodeCodec mappingService;
-    BGPDispatcherImpl dispatcher;
+    BGPDispatcherImpl serverDispatcher;
     RIBExtensionProviderContext ribExtension;
     private RIBActivator ribActivator;
     private BGPActivator bgpActivator;
     private NioEventLoopGroup worker;
     private NioEventLoopGroup boss;
     private org.opendaylight.protocol.bgp.inet.BGPActivator inetActivator;
+    protected StrictBGPPeerRegistry serverRegistry;
 
     @Before
     public void setUp() throws Exception {
@@ -187,14 +185,16 @@ class AbstractAddPathTest extends AbstractDataBrokerTest {
             this.worker = new NioEventLoopGroup();
             this.boss = new NioEventLoopGroup();
         }
-        this.dispatcher = new BGPDispatcherImpl(this.context.getMessageRegistry(), this.boss, this.worker);
+        this.serverRegistry = new StrictBGPPeerRegistry();
+        this.serverDispatcher = new BGPDispatcherImpl(this.context.getMessageRegistry(), this.boss, this.worker,
+            this.serverRegistry);
         doReturn(Mockito.mock(ClusterSingletonServiceRegistration.class)).when(this.clusterSingletonServiceProvider)
             .registerClusterSingletonService(any(ClusterSingletonService.class));
     }
 
     @After
     public void tearDown() throws ExecutionException, InterruptedException {
-        this.dispatcher.close();
+        this.serverDispatcher.close();
         if (!Epoll.isAvailable()) {
             this.worker.shutdownGracefully(0, 0, TimeUnit.SECONDS);
             this.boss.shutdownGracefully(0, 0, TimeUnit.SECONDS);
@@ -247,42 +247,38 @@ class AbstractAddPathTest extends AbstractDataBrokerTest {
         });
     }
 
-    BGPSessionImpl createPeerSession(final Ipv4Address peer, final BgpParameters nonAddPathParams,
-        final SimpleSessionListener sessionListener) throws InterruptedException, ExecutionException {
-        return connectPeer(peer, nonAddPathParams, this.dispatcher, sessionListener);
-    }
+    BGPSessionImpl createPeerSession(final Ipv4Address peer, final BgpParameters bgpParameters,
+        final SimpleSessionListener sessionListener) throws InterruptedException {
+        StrictBGPPeerRegistry clientRegistry = new StrictBGPPeerRegistry();
+        BGPDispatcherImpl clientDispatcher = new BGPDispatcherImpl(this.context.getMessageRegistry(), this.boss,
+            this.worker, clientRegistry);
+        clientRegistry.addPeer(new IpAddress(new Ipv4Address(RIB_ID)), sessionListener,
+            new BGPSessionPreferences(AS_NUMBER, HOLDTIMER, new BgpId(peer),
+                AS_NUMBER, Lists.newArrayList(bgpParameters), Optional.absent()));
 
-    private static int getPeerRibOutSize(final Peer peer) {
-        return ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.bgp.rib.rib.peer.adj.rib.out.tables.routes.Ipv4RoutesCase) peer.getAdjRibOut().getTables().get(0).getRoutes()).getIpv4Routes().getIpv4Route().size();
+        return connectPeer(peer, clientDispatcher);
     }
 
-    protected static BGPPeer configurePeer(final Ipv4Address localAddress, final RIBImpl ribImpl, final BgpParameters bgpParameters, final PeerRole peerRole) {
-        final IpAddress ipAddress = new IpAddress(new Ipv4Address(InetAddresses.forString(localAddress.getValue())
-            .getHostAddress()));
-
+    protected static BGPPeer configurePeer(final Ipv4Address peerAddress, final RIBImpl ribImpl,
+        final BgpParameters bgpParameters, final PeerRole peerRole, BGPPeerRegistry bgpPeerRegistry) {
+        final IpAddress ipAddress = new IpAddress(peerAddress);
 
-        final BGPPeer bgpPeer = new BGPPeer(localAddress.getValue(), ribImpl, peerRole, null, AFI_SAFIS_ADVERTIZED,
-            Collections.emptySet());
+        final BGPPeer bgpPeer = new BGPPeer(peerAddress.getValue(), ribImpl, peerRole, null,
+            AFI_SAFIS_ADVERTIZED, Collections.emptySet());
         final List<BgpParameters> tlvs = Lists.newArrayList(bgpParameters);
-        StrictBGPPeerRegistry.GLOBAL.addPeer(ipAddress, bgpPeer,
+        bgpPeerRegistry.addPeer(ipAddress, bgpPeer,
             new BGPSessionPreferences(AS_NUMBER, HOLDTIMER, new BgpId(RIB_ID), AS_NUMBER, tlvs, Optional.absent()));
         bgpPeer.instantiateServiceInstance();
         return bgpPeer;
     }
 
-    private static BGPSessionImpl connectPeer(final Ipv4Address localAddress, final BgpParameters bgpParameters,
-        final BGPDispatcherImpl dispatcherImpl, final BGPSessionListener sessionListener) throws InterruptedException {
-        final BGPPeerRegistry peerRegistry = new StrictBGPPeerRegistry();
-        peerRegistry.addPeer(new IpAddress(new Ipv4Address(RIB_ID)), sessionListener,
-            new BGPSessionPreferences(AS_NUMBER, HOLDTIMER, new BgpId(localAddress),
-                AS_NUMBER, Lists.newArrayList(bgpParameters), Optional.absent()));
-
+    private static BGPSessionImpl connectPeer(final Ipv4Address localAddress, final BGPDispatcherImpl dispatcherImpl)
+        throws InterruptedException {
         final Future<BGPSessionImpl> future = dispatcherImpl.createClient(new InetSocketAddress(localAddress.getValue(), PORT),
-            new InetSocketAddress(RIB_ID, PORT), peerRegistry, RETRY_TIMER, true);
+            new InetSocketAddress(RIB_ID, PORT), RETRY_TIMER, true);
         Thread.sleep(200);
         waitFutureSuccess(future);
-        final BGPSessionImpl client = future.getNow();
-        return client;
+        return future.getNow();
     }
 
     protected static BgpParameters createParameter(final boolean addPath) {
index 191588b9216d065a72ac80ce5b4e53ba5be522de..ac69f2419cac6f1bb080953aa43a35f207e91777 100644 (file)
@@ -55,7 +55,8 @@ import org.slf4j.LoggerFactory;
 public class AbstractBGPDispatcherTest {
     protected static final AsNumber AS_NUMBER = new AsNumber(30L);
     protected static final int RETRY_TIMER = 1;
-    protected static final BgpTableType IPV_4_TT = new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
+    protected static final BgpTableType IPV_4_TT = new BgpTableTypeImpl(Ipv4AddressFamily.class,
+        UnicastSubsequentAddressFamily.class);
     private static final short HOLD_TIMER = 30;
     protected BGPDispatcherImpl clientDispatcher;
     protected BGPPeerRegistry registry;
@@ -76,12 +77,12 @@ public class AbstractBGPDispatcherTest {
         this.clientListener = new SimpleSessionListener();
         this.serverListener = new SimpleSessionListener();
         final BGPExtensionProviderContext ctx = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance();
-        this.serverDispatcher = new BGPDispatcherImpl(ctx.getMessageRegistry(), this.boss, this.worker);
+        this.serverDispatcher = new BGPDispatcherImpl(ctx.getMessageRegistry(), this.boss, this.worker, this.registry);
 
         this.clientAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
         final IpAddress clientPeerIp = new IpAddress(new Ipv4Address(this.clientAddress.getAddress().getHostAddress()));
         this.registry.addPeer(clientPeerIp, this.clientListener, createPreferences(this.clientAddress));
-        this.clientDispatcher = new BGPDispatcherImpl(ctx.getMessageRegistry(), this.boss, this.worker);
+        this.clientDispatcher = new BGPDispatcherImpl(ctx.getMessageRegistry(), this.boss, this.worker, this.registry);
     }
 
     @After
@@ -108,7 +109,7 @@ public class AbstractBGPDispatcherTest {
         return new BGPSessionPreferences(AS_NUMBER, HOLD_TIMER, bgpId, AS_NUMBER, tlvs, Optional.absent());
     }
 
-    public static void checkIdleState(final SimpleSessionListener listener) {
+    protected static void checkIdleState(final SimpleSessionListener listener) {
         final Stopwatch sw = Stopwatch.createStarted();
         while (sw.elapsed(TimeUnit.SECONDS) <= 10) {
             if (State.IDLE != listener.getState()) {
@@ -121,10 +122,12 @@ public class AbstractBGPDispatcherTest {
     }
 
     protected Channel createServer(final InetSocketAddress serverAddress) throws InterruptedException {
-        this.registry.addPeer(new IpAddress(new Ipv4Address(serverAddress.getAddress().getHostAddress())), this.serverListener, createPreferences(serverAddress));
+        this.registry.addPeer(new IpAddress(new Ipv4Address(serverAddress.getAddress().getHostAddress())),
+            this.serverListener, createPreferences(serverAddress));
         LoggerFactory.getLogger(AbstractBGPDispatcherTest.class).info("createServer");
-        final ChannelFuture future = this.serverDispatcher.createServer(this.registry, serverAddress);
-        future.addListener(future1 -> Preconditions.checkArgument(future1.isSuccess(), "Unable to start bgp server on %s", future1.cause()));
+        final ChannelFuture future = this.serverDispatcher.createServer(serverAddress);
+        future.addListener(future1 -> Preconditions.checkArgument(future1.isSuccess(),
+            "Unable to start bgp server on %s", future1.cause()));
         waitFutureSuccess(future);
         return future.channel();
     }
index 13463863eb3ade88d657a790aaaf684d7e8c915b..2be5ce5d135ac742278d00f8f5a1f75b60535b84 100644 (file)
@@ -63,13 +63,12 @@ public class AddPathAllPathsTest extends AbstractAddPathTest {
         final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(TABLES_KEY, new AllPathSelection());
 
         this.ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId("test-rib"),
-            AS_NUMBER, BGP_ID, null, this.ribExtension, this.dispatcher, this.mappingService.getCodecFactory(),
+            AS_NUMBER, BGP_ID, null, this.ribExtension, this.serverDispatcher, this.mappingService.getCodecFactory(),
             getDomBroker(), TABLES_TYPE, pathTables, this.ribExtension.getClassLoadingStrategy(), null);
 
         this.ribImpl.instantiateServiceInstance();
         this.ribImpl.onGlobalContextUpdated(this.schemaContext);
-        final ChannelFuture channelFuture = this.dispatcher.createServer(StrictBGPPeerRegistry.GLOBAL,
-            new InetSocketAddress(RIB_ID, PORT));
+        final ChannelFuture channelFuture = this.serverDispatcher.createServer(new InetSocketAddress(RIB_ID, PORT));
         waitFutureSuccess(channelFuture);
         this.serverChannel = channelFuture.channel();
     }
@@ -94,17 +93,17 @@ public class AddPathAllPathsTest extends AbstractAddPathTest {
         final BgpParameters nonAddPathParams = createParameter(false);
         final BgpParameters addPathParams = createParameter(true);
 
-        final BGPPeer peer1 = configurePeer(PEER1, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
+        final BGPPeer peer1 = configurePeer(PEER1, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
         final BGPSessionImpl session1 = createPeerSession(PEER1, nonAddPathParams, new SimpleSessionListener());
 
-        configurePeer(PEER2, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
+        configurePeer(PEER2, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
         final BGPSessionImpl session2 = createPeerSession(PEER2, nonAddPathParams, new SimpleSessionListener());
 
-        configurePeer(PEER3, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
+        configurePeer(PEER3, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
         final BGPSessionImpl session3 = createPeerSession(PEER3, nonAddPathParams, new SimpleSessionListener());
 
         final SimpleSessionListener listener4 = new SimpleSessionListener();
-        final BGPPeer peer4 = configurePeer(PEER4, this.ribImpl, nonAddPathParams, PeerRole.RrClient);
+        final BGPPeer peer4 = configurePeer(PEER4, this.ribImpl, nonAddPathParams, PeerRole.RrClient, this.serverRegistry);
 
         BGPPeerState peer4State = peer4.getPeerState();
         assertNull(peer4State.getGroupId());
@@ -140,7 +139,7 @@ public class AddPathAllPathsTest extends AbstractAddPathTest {
         final BGPSessionImpl session4 = createPeerSession(PEER4, nonAddPathParams, listener4);
 
         final SimpleSessionListener listener5 = new SimpleSessionListener();
-        configurePeer(PEER5, this.ribImpl, addPathParams, PeerRole.RrClient);
+        configurePeer(PEER5, this.ribImpl, addPathParams, PeerRole.RrClient, this.serverRegistry);
         final BGPSessionImpl session5 = createPeerSession(PEER5, addPathParams, listener5);
         checkPeersPresentOnDataStore(5);
 
@@ -199,7 +198,7 @@ public class AddPathAllPathsTest extends AbstractAddPathTest {
         assertEquals(1L, ribState.getTotalPrefixesCount());
 
         final SimpleSessionListener listener6 = new SimpleSessionListener();
-        final BGPPeer peer6 = configurePeer(PEER6, this.ribImpl, nonAddPathParams, PeerRole.RrClient);
+        final BGPPeer peer6 = configurePeer(PEER6, this.ribImpl, nonAddPathParams, PeerRole.RrClient, this.serverRegistry);
         final BGPSessionImpl session6 = createPeerSession(PEER6, nonAddPathParams, listener6);
         checkPeersPresentOnDataStore(6);
         checkReceivedMessages(listener6, 1);
index 8e2d3aec08ff67115474b681a6aae613b184bc83..f2ada6e6e6f961bfd2fa390bf38b2c13f184cb59 100644 (file)
@@ -43,13 +43,12 @@ public class AddPathBasePathsTest extends AbstractAddPathTest {
             BasePathSelectionModeFactory.createBestPathSelectionStrategy());
 
         this.ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId("test-rib"),
-            AS_NUMBER, new BgpId(RIB_ID), null, this.ribExtension, this.dispatcher,
+            AS_NUMBER, new BgpId(RIB_ID), null, this.ribExtension, this.serverDispatcher,
             this.mappingService.getCodecFactory(), getDomBroker(), TABLES_TYPE, pathTables,
             this.ribExtension.getClassLoadingStrategy(), null);
         this.ribImpl.instantiateServiceInstance();
         this.ribImpl.onGlobalContextUpdated(this.schemaContext);
-        final ChannelFuture channelFuture = this.dispatcher.createServer(StrictBGPPeerRegistry.GLOBAL,
-            new InetSocketAddress(RIB_ID, PORT));
+        final ChannelFuture channelFuture = this.serverDispatcher.createServer(new InetSocketAddress(RIB_ID, PORT));
         waitFutureSuccess(channelFuture);
         this.serverChannel = channelFuture.channel();
     }
@@ -73,21 +72,21 @@ public class AddPathBasePathsTest extends AbstractAddPathTest {
     public void testUseCase1() throws Exception {
         final BgpParameters nonAddPathParams = createParameter(false);
 
-        configurePeer(PEER1, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
+        configurePeer(PEER1, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
         final BGPSessionImpl session1 = createPeerSession(PEER1, nonAddPathParams, new SimpleSessionListener());
 
-        configurePeer(PEER2, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
+        configurePeer(PEER2, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
         final BGPSessionImpl session2 = createPeerSession(PEER2, nonAddPathParams, new SimpleSessionListener());
 
-        configurePeer(PEER3, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
+        configurePeer(PEER3, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
         final BGPSessionImpl session3 = createPeerSession(PEER3,nonAddPathParams, new SimpleSessionListener());
 
         final SimpleSessionListener listener4 = new SimpleSessionListener();
-        configurePeer(PEER4, this.ribImpl, nonAddPathParams, PeerRole.RrClient);
+        configurePeer(PEER4, this.ribImpl, nonAddPathParams, PeerRole.RrClient, this.serverRegistry);
         final BGPSessionImpl session4 = createPeerSession(PEER4, nonAddPathParams, listener4);
 
         final SimpleSessionListener listener5 = new SimpleSessionListener();
-        configurePeer(PEER5, this.ribImpl, nonAddPathParams, PeerRole.Ebgp);
+        configurePeer(PEER5, this.ribImpl, nonAddPathParams, PeerRole.Ebgp, this.serverRegistry);
         final BGPSessionImpl session5 = createPeerSession(PEER5, nonAddPathParams, listener5);
         checkPeersPresentOnDataStore(5);
 
@@ -111,7 +110,7 @@ public class AddPathBasePathsTest extends AbstractAddPathTest {
         assertEquals(UPD_NA_200_EBGP, listener5.getListMsg().get(1));
 
         final SimpleSessionListener listener6 = new SimpleSessionListener();
-        configurePeer(PEER6, this.ribImpl, nonAddPathParams, PeerRole.RrClient);
+        configurePeer(PEER6, this.ribImpl, nonAddPathParams, PeerRole.RrClient, this.serverRegistry);
         final BGPSessionImpl session6 = createPeerSession(PEER6, nonAddPathParams, listener6);
 
         checkPeersPresentOnDataStore(6);
index 516ebe1865e46e385a2321e57d7c64854ed65859..ae662a2ee26e06bbf187d9ab2fbd81beb55f0be1 100644 (file)
@@ -42,14 +42,13 @@ public class AddPathNPathsTest extends AbstractAddPathTest {
         final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(tk, new AddPathBestNPathSelection(2L));
 
         this.ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId("test-rib"),
-            AS_NUMBER, new BgpId(RIB_ID), null, this.ribExtension, this.dispatcher,
+            AS_NUMBER, new BgpId(RIB_ID), null, this.ribExtension, this.serverDispatcher,
             this.mappingService.getCodecFactory(), getDomBroker(), TABLES_TYPE, pathTables,
             this.ribExtension.getClassLoadingStrategy(), null);
 
         this.ribImpl.instantiateServiceInstance();
         this.ribImpl.onGlobalContextUpdated(this.schemaContext);
-        final ChannelFuture channelFuture = this.dispatcher.createServer(StrictBGPPeerRegistry.GLOBAL,
-            new InetSocketAddress(RIB_ID, PORT));
+        final ChannelFuture channelFuture = this.serverDispatcher.createServer(new InetSocketAddress(RIB_ID, PORT));
         waitFutureSuccess(channelFuture);
         this.serverChannel = channelFuture.channel();
     }
@@ -74,21 +73,21 @@ public class AddPathNPathsTest extends AbstractAddPathTest {
         final BgpParameters nonAddPathParams = createParameter(false);
         final BgpParameters addPathParams = createParameter(true);
 
-        configurePeer(PEER1, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
+        configurePeer(PEER1, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
         final BGPSessionImpl session1 = createPeerSession(PEER1, nonAddPathParams, new SimpleSessionListener());
 
-        configurePeer(PEER2, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
-        final BGPSessionImpl session2 = createPeerSession(PEER2, nonAddPathParams, new SimpleSessionListener());
+        configurePeer(PEER2, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
+       final BGPSessionImpl session2 = createPeerSession(PEER2, nonAddPathParams, new SimpleSessionListener());
 
-        configurePeer(PEER3, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
+        configurePeer(PEER3, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
         final BGPSessionImpl session3 = createPeerSession(PEER3, nonAddPathParams, new SimpleSessionListener());
 
         final SimpleSessionListener listener4 = new SimpleSessionListener();
-        configurePeer(PEER4, this.ribImpl, nonAddPathParams, PeerRole.RrClient);
+        configurePeer(PEER4, this.ribImpl, nonAddPathParams, PeerRole.RrClient, this.serverRegistry);
         final BGPSessionImpl session4 = createPeerSession(PEER4, nonAddPathParams, listener4);
 
         final SimpleSessionListener listener5 = new SimpleSessionListener();
-        configurePeer(PEER5, this.ribImpl, addPathParams, PeerRole.RrClient);
+        configurePeer(PEER5, this.ribImpl, addPathParams, PeerRole.RrClient, this.serverRegistry);
         final BGPSessionImpl session5 = createPeerSession(PEER5, addPathParams, listener5);
         checkPeersPresentOnDataStore(5);
 
@@ -99,7 +98,7 @@ public class AddPathNPathsTest extends AbstractAddPathTest {
         assertEquals(UPD_100, listener5.getListMsg().get(0));
 
         final SimpleSessionListener listener6 = new SimpleSessionListener();
-        configurePeer(PEER6, this.ribImpl, nonAddPathParams, PeerRole.RrClient);
+        configurePeer(PEER6, this.ribImpl, nonAddPathParams, PeerRole.RrClient, this.serverRegistry);
         final BGPSessionImpl session6 = createPeerSession(PEER6, nonAddPathParams, listener6);
         checkPeersPresentOnDataStore(6);
         checkReceivedMessages(listener6, 1);
index 17c801c15da422ef5d607ea5f1eaf19f62fba59d..d7e4bb3bcb8582f897cd48557aca397465d13865 100755 (executable)
@@ -26,7 +26,8 @@ public class BGPDispatcherImplTest extends AbstractBGPDispatcherTest {
     public void testCreateClient() throws InterruptedException, ExecutionException {
         final InetSocketAddress serverAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
         final Channel serverChannel = createServer(serverAddress);
-        final Future<BGPSessionImpl> futureClient = this.clientDispatcher.createClient(this.clientAddress, serverAddress, this.registry, 2, true);
+        final Future<BGPSessionImpl> futureClient = this.clientDispatcher.createClient(this.clientAddress,
+            serverAddress, 2, true);
         waitFutureSuccess(futureClient);
         final BGPSessionImpl session = futureClient.get();
         Assert.assertEquals(State.UP, this.clientListener.getState());
@@ -43,8 +44,8 @@ public class BGPDispatcherImplTest extends AbstractBGPDispatcherTest {
     @Test
     public void testCreateReconnectingClient() throws Exception {
         final InetSocketAddress serverAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
-        final Future<Void> future = this.clientDispatcher.createReconnectingClient(serverAddress, this.registry, RETRY_TIMER, Optional.absent(),
-            this.clientAddress, true);
+        final Future<Void> future = this.clientDispatcher.createReconnectingClient(serverAddress, RETRY_TIMER,
+            Optional.absent(), this.clientAddress, true);
         waitFutureSuccess(future);
         final Channel serverChannel = createServer(serverAddress);
         Assert.assertEquals(State.UP, this.serverListener.getState());
index 8838b94db93cbb8774fe25c57481d3793a59ccd5..7d07420faf4fb7ff3db92241254c92bb19513c6b 100755 (executable)
@@ -48,7 +48,6 @@ 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;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
-import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
 import org.opendaylight.protocol.bgp.rib.mock.BGPMock;
 import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBExtensionProviderActivator;
 import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext;
@@ -83,6 +82,7 @@ public class ParserToSalTest extends AbstractDataBrokerTest {
     private AbstractRIBExtensionProviderActivator baseact, lsact;
     private RIBExtensionProviderContext ext1, ext2;
     private String localAddress = "127.0.0.1";
+
     @Mock
     private BGPDispatcher dispatcher;
     @Mock
@@ -128,8 +128,8 @@ public class ParserToSalTest extends AbstractDataBrokerTest {
             .getSingletonInstance().getMessageRegistry(), Lists.newArrayList(fixMessages(bgpMessages)));
 
         Mockito.doReturn(GlobalEventExecutor.INSTANCE.newSucceededFuture(null)).when(this.dispatcher)
-            .createReconnectingClient(Mockito.any(InetSocketAddress.class), Mockito.any(BGPPeerRegistry.class),
-                Mockito.anyInt(), Mockito.any(Optional.class));
+            .createReconnectingClient(Mockito.any(InetSocketAddress.class), Mockito.anyInt(),
+                Mockito.any(Optional.class));
 
         this.ext1 = new SimpleRIBExtensionProviderContext();
         this.ext2 = new SimpleRIBExtensionProviderContext();
index 17343e2e7d742a8056d96e6137a3a9a317ad209c..74cac34aeecbb01c6d6662260ec369ef031c207d 100644 (file)
@@ -204,7 +204,7 @@ public class SynchronizationAndExceptionTest extends AbstractAddPathTest {
         final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(TABLES_KEY,
             BasePathSelectionModeFactory.createBestPathSelectionStrategy());
         final RIBImpl ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId(RIB_ID), AS_NUMBER,
-            new BgpId(RIB_ID), null, this.ribExtension, this.dispatcher, this.mappingService.getCodecFactory(),
+            new BgpId(RIB_ID), null, this.ribExtension, this.serverDispatcher, this.mappingService.getCodecFactory(),
             this.domBroker, ImmutableList.of(this.ipv4tt), pathTables, this.ribExtension.getClassLoadingStrategy(),
             null);
         ribImpl.instantiateServiceInstance();
@@ -245,7 +245,7 @@ public class SynchronizationAndExceptionTest extends AbstractAddPathTest {
         final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(TABLES_KEY,
             BasePathSelectionModeFactory.createBestPathSelectionStrategy());
         final RIBImpl ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId(RIB_ID), AS_NUMBER,
-            new BgpId(RIB_ID), null, this.ribExtension, this.dispatcher, this.mappingService.getCodecFactory(),
+            new BgpId(RIB_ID), null, this.ribExtension, this.serverDispatcher, this.mappingService.getCodecFactory(),
             this.domBroker, ImmutableList.of(this.ipv4tt), pathTables, this.ribExtension.getClassLoadingStrategy(),
             null);
         ribImpl.instantiateServiceInstance();
index 2c3d32f11caf2583ae1caec19ea901fc3729c50e..2215b66009738bde3ca72a1144f97e5c79de6108 100644 (file)
@@ -147,7 +147,7 @@ class AbstractConfig {
         Mockito.doReturn(new BgpId("127.0.0.1")).when(this.rib).getBgpIdentifier();
         Mockito.doReturn(true).when(this.future).cancel(true);
         Mockito.doReturn(this.future).when(this.dispatcher)
-            .createReconnectingClient(any(InetSocketAddress.class), any(BGPPeerRegistry.class), anyInt(), any(Optional.class));
+            .createReconnectingClient(any(InetSocketAddress.class), anyInt(), any(Optional.class));
         Mockito.doReturn(this.dispatcher).when(this.rib).getDispatcher();
 
         Mockito.doReturn(java.util.Optional.of(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class)))
@@ -161,5 +161,6 @@ class AbstractConfig {
         Mockito.doNothing().when(this.bgpPeerRegistry).removePeer(any(IpAddress.class));
         Mockito.doReturn("registry").when(this.bgpPeerRegistry).toString();
         Mockito.doNothing().when(this.listener).close();
+        Mockito.doReturn(this.bgpPeerRegistry).when(this.dispatcher).getBGPPeerRegistry();
     }
 }
index 46ecc65199f3ca0570d5940289252d87bb32ad7c..2006d81eb282abcc43b664fdb6b34bd526e3b9e5 100644 (file)
@@ -195,7 +195,7 @@ public class BgpDeployerImplTest {
             mock(BGPDispatcher.class), mock(BindingCodecTreeFactory.class), domDataBroker, schemaService);
         Mockito.doReturn(ribImpl).when(this.blueprintContainer).getComponentInstance(eq("ribImpl"));
 
-        final BgpPeer bgpPeer = new BgpPeer(mock(RpcProviderRegistry.class), mock(BGPPeerRegistry.class));
+        final BgpPeer bgpPeer = new BgpPeer(mock(RpcProviderRegistry.class));
         Mockito.doReturn(bgpPeer).when(this.blueprintContainer).getComponentInstance(eq("bgpPeer"));
         this.collection = Collections.singleton(this.modification);
     }
index 8660771b5636a9910f2d64aef2581f9aa12a8c1b..c28fb25057c037e072305856755ca5ed7443fee2 100644 (file)
@@ -71,14 +71,15 @@ public class BgpPeerTest extends AbstractConfig {
     @Before
     public void setUp() throws Exception {
         super.setUp();
-        this.bgpPeer = new BgpPeer(Mockito.mock(RpcProviderRegistry.class), this.bgpPeerRegistry);
+        this.bgpPeer = new BgpPeer(Mockito.mock(RpcProviderRegistry.class));
         Mockito.doNothing().when(this.serviceRegistration).unregister();
     }
 
     @Test
     public void testBgpPeer() throws Exception {
-        final Neighbor neighbor = new NeighborBuilder().setAfiSafis(createAfiSafi()).setConfig(createConfig()).setNeighborAddress(NEIGHBOR_ADDRESS)
-            .setRouteReflector(createRR()).setTimers(createTimers()).setTransport(createTransport()).setAddPaths(createAddPath()).build();
+        final Neighbor neighbor = new NeighborBuilder().setAfiSafis(createAfiSafi()).setConfig(createConfig())
+            .setNeighborAddress(NEIGHBOR_ADDRESS).setRouteReflector(createRR()).setTimers(createTimers())
+            .setTransport(createTransport()).setAddPaths(createAddPath()).build();
 
         this.bgpPeer.start(this.rib, neighbor, this.tableTypeRegistry, this.configurationWriter);
         Mockito.verify(this.rib).createPeerChain(any());
@@ -91,7 +92,8 @@ public class BgpPeerTest extends AbstractConfig {
         Mockito.verify(this.render).getConfiguredPeerCounter();
         Mockito.verify(this.configurationWriter).apply();
         Mockito.verify(this.bgpPeerRegistry).addPeer(any(), any(), any());
-        Mockito.verify(this.dispatcher).createReconnectingClient(any(InetSocketAddress.class), any(BGPPeerRegistry.class), anyInt(), any(Optional.class));
+        Mockito.verify(this.dispatcher).createReconnectingClient(any(InetSocketAddress.class),
+            anyInt(), any(Optional.class));
 
         try {
             this.bgpPeer.start(this.rib, neighbor, this.tableTypeRegistry, this.configurationWriter);
index 0ccae805e9a9602e215ac3ba9d7a94c5fcc5b586..9e86b719dc8b1feb3352dda5495b9a4cc30b20c9 100644 (file)
@@ -16,6 +16,7 @@ import java.util.Collections;
 import org.opendaylight.protocol.bgp.rib.impl.BGPDispatcherImpl;
 import org.opendaylight.protocol.bgp.rib.impl.StrictBGPPeerRegistry;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
+import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
 import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
@@ -32,27 +33,33 @@ final class BGPPeerBuilder {
         throw new UnsupportedOperationException();
     }
 
-    static void createPeer(final BGPDispatcher dispatcher, final Arguments arguments, final InetSocketAddress localAddress,
-            final BGPSessionListener sessionListener, final BgpParameters bgpParameters) {
+    static void createPeer(final BGPDispatcher dispatcher, final Arguments arguments,
+        final InetSocketAddress localAddress, final BGPSessionListener sessionListener,
+        final BgpParameters bgpParameters) {
         final AsNumber as = arguments.getAs();
-        final BGPSessionPreferences proposal = new BGPSessionPreferences(as, arguments.getHoldTimer(), new BgpId(localAddress.getAddress().getHostAddress()),
-                as, Collections.singletonList(bgpParameters), Optional.absent());
-        final StrictBGPPeerRegistry strictBGPPeerRegistry = new StrictBGPPeerRegistry();
+        final BGPSessionPreferences proposal = new BGPSessionPreferences(as, arguments.getHoldTimer(),
+            new BgpId(localAddress.getAddress().getHostAddress()), as, Collections.singletonList(bgpParameters),
+            Optional.absent());
+        final BGPPeerRegistry strictBGPPeerRegistry = dispatcher.getBGPPeerRegistry();
         if (arguments.getInitiateConnection()) {
             for (final InetSocketAddress remoteAddress : arguments.getRemoteAddresses()) {
-                strictBGPPeerRegistry.addPeer(StrictBGPPeerRegistry.getIpAddress(remoteAddress), sessionListener, proposal);
-                addFutureListener(localAddress, ((BGPDispatcherImpl) dispatcher).createClient(localAddress, remoteAddress, strictBGPPeerRegistry, RETRY_TIMER, true));
+                strictBGPPeerRegistry.addPeer(StrictBGPPeerRegistry.getIpAddress(remoteAddress), sessionListener,
+                    proposal);
+                addFutureListener(localAddress, ((BGPDispatcherImpl) dispatcher).createClient(localAddress,
+                    remoteAddress, RETRY_TIMER, true));
             }
         } else {
             for (final InetSocketAddress remoteAddress : arguments.getRemoteAddresses()) {
-                strictBGPPeerRegistry.addPeer(StrictBGPPeerRegistry.getIpAddress(remoteAddress), sessionListener, proposal);
+                strictBGPPeerRegistry.addPeer(StrictBGPPeerRegistry.getIpAddress(remoteAddress), sessionListener,
+                    proposal);
             }
-            addFutureListener(localAddress, dispatcher.createServer(strictBGPPeerRegistry, localAddress));
+            addFutureListener(localAddress, dispatcher.createServer(localAddress));
         }
         LOG.debug("{} {}", sessionListener, proposal);
     }
 
     private static <T> void addFutureListener(final InetSocketAddress localAddress, final Future<T> future) {
-        future.addListener(future1 -> Preconditions.checkArgument(future1.isSuccess(), "Unable to start bgp session on %s", localAddress, future1.cause()));
+        future.addListener(future1 -> Preconditions.checkArgument(future1.isSuccess(),
+            "Unable to start bgp session on %s", localAddress, future1.cause()));
     }
 }
index 12dca52ac7746029195d92dcca8bb2a9ad5505cc..dc5dfef7b566a2b076078c4ee8e5f120c6f938c3 100644 (file)
@@ -25,6 +25,7 @@ import org.opendaylight.protocol.bgp.parser.impl.BGPActivator;
 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
 import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
 import org.opendaylight.protocol.bgp.rib.impl.BGPDispatcherImpl;
+import org.opendaylight.protocol.bgp.rib.impl.StrictBGPPeerRegistry;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
 import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
@@ -99,7 +100,8 @@ final class BGPTestTool {
         final org.opendaylight.protocol.bgp.l3vpn.ipv6.BgpIpv6Activator bgpIpv6Activator = new org.opendaylight.protocol.bgp.l3vpn.ipv6.BgpIpv6Activator();
         bgpIpv6Activator.start(ctx);
 
-        return new BGPDispatcherImpl(ctx.getMessageRegistry(), new NioEventLoopGroup(), new NioEventLoopGroup());
+        return new BGPDispatcherImpl(ctx.getMessageRegistry(), new NioEventLoopGroup(), new NioEventLoopGroup(),
+            new StrictBGPPeerRegistry());
     }
 
     private static OptionalCapabilities createMPCapability(final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi) {