BUG-4692: Migrate TCP-MD5 support in bgp package to netty's native-epoll 68/39268/25
authorOm Prakash <op317q@att.com>
Sat, 18 Jun 2016 02:35:18 +0000 (22:35 -0400)
committerMilos Fabian <milfabia@cisco.com>
Tue, 12 Jul 2016 10:48:36 +0000 (10:48 +0000)
The reason for migration is that TCP-MD5 are part of the netty library so There is no need to inject any md5 config modules in bgp package.
This change will include to extended concepts package change , upgrade Netty 4.0.33.Final -> 4.0.36.Final and remove the code of md5 package to use e-poll for this change.

Change-Id: Id6d4b7ed5062ec31fedf05f6494290e1e30e3028
Signed-off-by: Om Prakash <op317q@att.com>
21 files changed:
bgp/openconfig-impl/pom.xml
bgp/openconfig-impl/src/main/java/org/opendaylight/protocol/bgp/openconfig/impl/moduleconfig/BGPPeerProvider.java
bgp/openconfig-impl/src/main/java/org/opendaylight/protocol/bgp/openconfig/impl/openconfig/BGPNeighborProviderImpl.java
bgp/openconfig-impl/src/test/java/org/opendaylight/protocol/bgp/openconfig/impl/openconfig/BGPNeighborProviderImplTest.java
bgp/openconfig-spi/pom.xml
bgp/openconfig-spi/src/main/java/org/opendaylight/protocol/bgp/openconfig/spi/pojo/BGPPeerInstanceConfiguration.java
bgp/openconfig-spi/src/test/java/org/opendaylight/protocol/bgp/openconfig/spi/pojo/BGPPeerInstanceConfigurationTest.java
bgp/rib-impl/pom.xml
bgp/rib-impl/src/main/java/org/opendaylight/controller/config/yang/bgp/rib/impl/BGPDispatcherImplModule.java
bgp/rib-impl/src/main/java/org/opendaylight/controller/config/yang/bgp/rib/impl/BGPPeerModule.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/spi/BGPDispatcher.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/spi/BGPServerDispatcher.java
bgp/rib-impl/src/main/yang/bgp-peer.yang
bgp/rib-impl/src/main/yang/odl-bgp-rib-impl-cfg.yang
bgp/rib-impl/src/test/java/org/opendaylight/controller/config/yang/bgp/rib/impl/BGPPeerAcceptorModuleTest.java
bgp/rib-impl/src/test/java/org/opendaylight/controller/config/yang/bgp/rib/impl/BGPPeerModuleTest.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/TestClientDispatcher.java
bgp/topology-provider/pom.xml
concepts/src/main/java/org/opendaylight/protocol/concepts/KeyMapping.java

index 6a5ab1944edbc1377c3f7cae1f02a12a0505b0b3..0ffef637d25d6815658ac1984246fe4f6acd78c8 100644 (file)
             <groupId>org.opendaylight.mdsal.model</groupId>
             <artifactId>ietf-topology</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.opendaylight.tcpmd5</groupId>
-            <artifactId>tcpmd5-api</artifactId>
-        </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
index 51cda9397d62f94a6e53e749d9bc303ae4a7fcb6..108132462bb502b96cf4b514686531ac9f7d7181 100644 (file)
@@ -44,7 +44,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controll
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.rev130405.modules.ModuleBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.rev130405.modules.ModuleKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.binding.rev131028.BindingRpcRegistry;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.tcpmd5.cfg.rev140427.Rfc2385Key;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.rfc2385.cfg.rev160324.Rfc2385Key;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
index 1f41128894aa452d073ea6a66e8605c49e22297d..969ab048315474554cab490db6dd8289bfaaa959 100644 (file)
@@ -24,7 +24,7 @@ import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009
 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.controller.bgp.rib.impl.rev160330.BgpPeer;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.rev130405.modules.ModuleKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.tcpmd5.cfg.rev140427.Rfc2385Key;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.rfc2385.cfg.rev160324.Rfc2385Key;
 
 final class BGPNeighborProviderImpl extends AbstractBGPNeighborProvider<BGPPeerInstanceConfiguration> {
 
index 41cb3bd6806b45436b0f938b707ee8e6dc2f7f53..651864e02298140584652f7fcf7d6549ef1a6bbd 100644 (file)
@@ -48,7 +48,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.Ipv6AddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.bgp.rib.impl.rev160330.BgpPeer;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.rev130405.modules.ModuleKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.tcpmd5.cfg.rev140427.Rfc2385Key;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.rfc2385.cfg.rev160324.Rfc2385Key;
 
 public class BGPNeighborProviderImplTest {
 
index ee1b16e24b782c169d8c49142315a830f41a8345..7ba7234e13877369117b7f4d6b2d2996fb94e6cf 100644 (file)
             <groupId>com.google.guava</groupId>
             <artifactId>guava</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.opendaylight.tcpmd5</groupId>
-            <artifactId>tcpmd5-api</artifactId>
-        </dependency>
         <!-- test dependencies -->
         <dependency>
             <groupId>junit</groupId>
index 8fedb1bbe801d47629c2ab95c762a49ccc6df187..abba9ef2d11ab3946e759fd374c28405699a7ccf 100644 (file)
@@ -18,7 +18,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.add.path.capability.AddressFamilies;
 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.controller.tcpmd5.cfg.rev140427.Rfc2385Key;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.rfc2385.cfg.rev160324.Rfc2385Key;
 
 /**
  * POJO for holding BGP Peer module instance configuration
index bae03e8cc2efb0418a47b70fa3ef6b5f92b82a87..d1aca50153665430420f977f48b6850fad91d4fe 100644 (file)
@@ -19,8 +19,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 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.PortNumber;
 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.controller.tcpmd5.cfg.rev140427.Rfc2385Key;
-
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.rfc2385.cfg.rev160324.Rfc2385Key;
 public class BGPPeerInstanceConfigurationTest {
 
     private static final InstanceConfigurationIdentifier INSTANCE_NAME = new InstanceConfigurationIdentifier("instanceName");
index 98e18d9c235caf88fed0a1bef475aec6166d3c20..7e85777a3ac2f99fb58dd5b31e6564c84347afcc 100644 (file)
             <type>test-jar</type>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>org.opendaylight.tcpmd5</groupId>
-            <artifactId>tcpmd5-api</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.opendaylight.tcpmd5</groupId>
-            <artifactId>tcpmd5-netty</artifactId>
-        </dependency>
         <dependency>
             <groupId>com.google.code.findbugs</groupId>
             <artifactId>jsr305</artifactId>
             <groupId>io.netty</groupId>
             <artifactId>netty-transport</artifactId>
         </dependency>
+        <dependency>
+            <groupId>io.netty</groupId>
+            <artifactId>netty-transport-native-epoll</artifactId>
+            <classifier>${os.detected.classifier}</classifier>
+        </dependency>
+        <dependency>
+            <groupId>io.netty</groupId>
+            <artifactId>netty-handler</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
             <artifactId>netty-threadgroup-config</artifactId>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>org.opendaylight.tcpmd5</groupId>
-            <artifactId>tcpmd5-jni</artifactId>
-            <type>test-jar</type>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.opendaylight.tcpmd5</groupId>
-            <artifactId>tcpmd5-jni</artifactId>
-            <scope>test</scope>
-        </dependency>
         <dependency>
             <groupId>org.opendaylight.controller</groupId>
             <artifactId>sal-binding-broker-impl</artifactId>
index 991a0939043ff52e2654e1c95373980190504b02..f4dff5659cf6fb1775d7155169e1c59cacafb199 100644 (file)
@@ -38,6 +38,6 @@ public final class BGPDispatcherImplModule extends org.opendaylight.controller.c
     @Override
     public java.lang.AutoCloseable createInstance() {
         final BGPExtensionConsumerContext bgpExtensions = getBgpExtensionsDependency();
-        return new BGPDispatcherImpl(bgpExtensions.getMessageRegistry(), getBossGroupDependency(), getWorkerGroupDependency(), getMd5ChannelFactoryDependency(), getMd5ServerChannelFactoryDependency());
+        return new BGPDispatcherImpl(bgpExtensions.getMessageRegistry(), getBossGroupDependency(), getWorkerGroupDependency());
     }
 }
index fab5bba911ddad005ae4759883e5e4d26b2a48cd..ada1deba45b4ee61c9b3de6778856132ba725d8d 100755 (executable)
  */
 package org.opendaylight.controller.config.yang.bgp.rib.impl;
 
-import com.google.common.base.Charsets;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.net.InetAddresses;
+import io.netty.channel.epoll.Epoll;
 import io.netty.util.concurrent.Future;
 import java.net.InetSocketAddress;
 import java.util.ArrayList;
@@ -39,8 +39,8 @@ import org.opendaylight.protocol.bgp.rib.impl.StrictBGPPeerRegistry;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
 import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
+import org.opendaylight.protocol.concepts.KeyMapping;
 import org.opendaylight.protocol.util.Ipv6Util;
-import org.opendaylight.tcpmd5.api.KeyMapping;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.BgpParameters;
@@ -57,7 +57,7 @@ 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.MultiprotocolCapabilityBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.add.path.capability.AddressFamilies;
 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.controller.tcpmd5.cfg.rev140427.Rfc2385Key;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.rfc2385.cfg.rev160324.Rfc2385Key;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -88,31 +88,17 @@ public final class BGPPeerModule extends org.opendaylight.controller.config.yang
 
         JmxAttributeValidationException.checkNotNull(getPort(), "value is not set.", portJmxAttribute);
 
-        if (getOptionalPassword(getPassword()).isPresent()) {
-            /*
-             *  This is a nasty hack, but we don't have another clean solution. We cannot allow
-             *  password being set if the injected dispatcher does not have the optional
-             *  md5-server-channel-factory set.
-             *
-             *  FIXME: this is a use case for Module interfaces, e.g. RibImplModule
-             *         should something like isMd5ServerSupported()
-             */
-
-            final RIBImplModuleMXBean ribProxy = this.dependencyResolver.newMXBeanProxy(getRib(), RIBImplModuleMXBean.class);
-            final BGPDispatcherImplModuleMXBean bgpDispatcherProxy = this.dependencyResolver.newMXBeanProxy(
-                ribProxy.getBgpDispatcher(), BGPDispatcherImplModuleMXBean.class);
-            final boolean isMd5Supported = bgpDispatcherProxy.getMd5ChannelFactory() != null;
-
-            JmxAttributeValidationException.checkCondition(isMd5Supported,
-                "Underlying dispatcher does not support MD5 clients", passwordJmxAttribute);
-
-        }
-
         if (getPeerRole() != null) {
             final boolean isNotPeerRoleInternal= getPeerRole() != PeerRole.Internal;
             JmxAttributeValidationException.checkCondition(isNotPeerRoleInternal,
                 "Internal Peer Role is reserved for Application Peer use.", peerRoleJmxAttribute);
         }
+
+        if (getOptionalPassword(getPassword()).isPresent()) {
+            JmxAttributeValidationException.checkCondition(Epoll.isAvailable(),
+                    "BGP Peer is configured with password but native transport is not available", passwordJmxAttribute);
+        }
+
     }
 
     private InetSocketAddress createAddress() {
@@ -238,12 +224,7 @@ public final class BGPPeerModule extends org.opendaylight.controller.config.yang
     }
 
     private io.netty.util.concurrent.Future<Void> initiateConnection(final InetSocketAddress address, final Optional<Rfc2385Key> password, final BGPPeerRegistry registry) {
-        KeyMapping keys = null;
-        if (password.isPresent()) {
-            keys = new KeyMapping();
-            keys.put(address.getAddress(), password.get().getValue().getBytes(Charsets.US_ASCII));
-        }
-
+        KeyMapping keys = KeyMapping.getKeyMapping(address.getAddress(), password);
         final RIB rib = getRibDependency();
         final Optional<KeyMapping> optionalKey = Optional.fromNullable(keys);
         return rib.getDispatcher().createReconnectingClient(address, registry, getRetrytimer(), optionalKey);
@@ -302,4 +283,4 @@ public final class BGPPeerModule extends org.opendaylight.controller.config.yang
         return password != null && ! password.getValue().isEmpty() ? Optional.of(password) : Optional.<Rfc2385Key>absent();
     }
 
-}
+}
\ No newline at end of file
index ce70ddc4901a5064eb87693afc3c98d7943cd674..bcd48ea277f928e7ead36183bafb3045368deea2 100755 (executable)
@@ -17,6 +17,11 @@ import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelInitializer;
 import io.netty.channel.ChannelOption;
 import io.netty.channel.EventLoopGroup;
+import io.netty.channel.epoll.Epoll;
+import io.netty.channel.epoll.EpollChannelOption;
+import io.netty.channel.epoll.EpollEventLoopGroup;
+import io.netty.channel.epoll.EpollServerSocketChannel;
+import io.netty.channel.epoll.EpollSocketChannel;
 import io.netty.channel.socket.SocketChannel;
 import io.netty.channel.socket.nio.NioServerSocketChannel;
 import io.netty.channel.socket.nio.NioSocketChannel;
@@ -33,10 +38,7 @@ import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
 import org.opendaylight.protocol.bgp.rib.impl.spi.ChannelPipelineInitializer;
 import org.opendaylight.protocol.bgp.rib.spi.BGPSession;
 import org.opendaylight.protocol.bgp.rib.spi.BGPSessionNegotiatorFactory;
-import org.opendaylight.tcpmd5.api.KeyMapping;
-import org.opendaylight.tcpmd5.netty.MD5ChannelFactory;
-import org.opendaylight.tcpmd5.netty.MD5ChannelOption;
-import org.opendaylight.tcpmd5.netty.MD5ServerChannelFactory;
+import org.opendaylight.protocol.concepts.KeyMapping;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -49,30 +51,24 @@ public class BGPDispatcherImpl implements BGPDispatcher, AutoCloseable {
     private static final int HIGH_WATER_MARK = 256 * 1024;
     private static final int LOW_WATER_MARK = 128 * 1024;
 
-    private final MD5ServerChannelFactory<?> serverChannelFactory;
-    private final MD5ChannelFactory<?> channelFactory;
     private final BGPHandlerFactory handlerFactory;
     private final EventLoopGroup bossGroup;
     private final EventLoopGroup workerGroup;
-    private Optional<KeyMapping> keys;
 
     public BGPDispatcherImpl(final MessageRegistry messageRegistry, final EventLoopGroup bossGroup, final EventLoopGroup workerGroup) {
-        this(messageRegistry, bossGroup, workerGroup, null, null);
-    }
-
-    public BGPDispatcherImpl(final MessageRegistry messageRegistry, final EventLoopGroup bossGroup, final EventLoopGroup workerGroup,
-        final MD5ChannelFactory<?> cf, final MD5ServerChannelFactory<?> scf) {
-        this.bossGroup = Preconditions.checkNotNull(bossGroup);
-        this.workerGroup = Preconditions.checkNotNull(workerGroup);
+        if (Epoll.isAvailable()) {
+            this.bossGroup = new EpollEventLoopGroup();
+            this.workerGroup = new EpollEventLoopGroup();
+        } else {
+            this.bossGroup = Preconditions.checkNotNull(bossGroup);
+            this.workerGroup = Preconditions.checkNotNull(workerGroup);
+        }
         this.handlerFactory = new BGPHandlerFactory(messageRegistry);
-        this.channelFactory = cf;
-        this.serverChannelFactory = scf;
-        this.keys = Optional.absent();
     }
 
     @Override
     public synchronized Future<BGPSessionImpl> createClient(final InetSocketAddress remoteAddress, final BGPPeerRegistry listener, final int retryTimer) {
-        return createClient(remoteAddress, listener, retryTimer, createClientBootStrap());
+        return createClient(remoteAddress, listener, retryTimer, createClientBootStrap(Optional.<KeyMapping>absent(), this.workerGroup));
     }
 
     private Future<BGPSessionImpl> createClient(final InetSocketAddress remoteAddress, final BGPPeerRegistry listener, final int retryTimer,
@@ -89,27 +85,25 @@ public class BGPDispatcherImpl implements BGPDispatcher, AutoCloseable {
 
     public Future<BGPSessionImpl> createClient(final InetSocketAddress localAddress, final InetSocketAddress remoteAddress,
         final StrictBGPPeerRegistry strictBGPPeerRegistry, final int retryTimer) {
-        final Bootstrap clientBootStrap = createClientBootStrap();
+        final Bootstrap clientBootStrap = createClientBootStrap(Optional.<KeyMapping>absent(), this.workerGroup);
         clientBootStrap.localAddress(localAddress);
         return createClient(remoteAddress, strictBGPPeerRegistry, retryTimer, clientBootStrap);
     }
 
-    protected Bootstrap createClientBootStrap() {
-        return createClientBootStrap(this.keys, this.channelFactory, this.workerGroup);
-    }
-
-    private static Bootstrap createClientBootStrap(final Optional<KeyMapping> keys, final MD5ChannelFactory<?> channelFactory, final EventLoopGroup
-        workerGroup) {
+    protected Bootstrap createClientBootStrap(final Optional<KeyMapping> keys, final EventLoopGroup workerGroup) {
         final Bootstrap bootstrap = new Bootstrap();
-        if (keys.isPresent()) {
-            if (channelFactory == null) {
-                throw new UnsupportedOperationException("No key access instance available, cannot use key mapping");
-            }
-            bootstrap.channelFactory(channelFactory);
-            bootstrap.option(MD5ChannelOption.TCP_MD5SIG, keys.get());
+        if (Epoll.isAvailable()) {
+            bootstrap.channel(EpollSocketChannel.class);
         } else {
             bootstrap.channel(NioSocketChannel.class);
         }
+        if (keys.isPresent()) {
+            if (Epoll.isAvailable()) {
+                bootstrap.option(EpollChannelOption.TCP_MD5SIG, keys.get());
+            } else {
+                throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause());
+            }
+        }
 
         // Make sure we are doing round-robin processing
         bootstrap.option(ChannelOption.MAX_MESSAGES_PER_READ, 1);
@@ -126,18 +120,20 @@ public class BGPDispatcherImpl implements BGPDispatcher, AutoCloseable {
 
     @Override
     public void close() {
+        if (Epoll.isAvailable()) {
+            this.workerGroup.shutdownGracefully().awaitUninterruptibly();
+            this.bossGroup.shutdownGracefully().awaitUninterruptibly();
+        }
     }
 
     @Override
     public synchronized Future<Void> createReconnectingClient(final InetSocketAddress remoteAddress, final BGPPeerRegistry peerRegistry,
             final int retryTimer, final Optional<KeyMapping> keys) {
         final BGPClientSessionNegotiatorFactory snf = new BGPClientSessionNegotiatorFactory(peerRegistry);
-        this.keys = keys;
-        final Bootstrap bootstrap = createClientBootStrap();
+        final Bootstrap bootstrap = createClientBootStrap(keys, this.workerGroup);
         final BGPReconnectPromise reconnectPromise = new BGPReconnectPromise(GlobalEventExecutor.INSTANCE, remoteAddress,
             retryTimer, bootstrap, BGPChannel.createChannelPipelineInitializer(BGPDispatcherImpl.this.handlerFactory, snf));
         reconnectPromise.connect();
-        this.keys = Optional.absent();
         return reconnectPromise;
     }
 
@@ -145,15 +141,21 @@ public class BGPDispatcherImpl implements BGPDispatcher, AutoCloseable {
     public ChannelFuture createServer(final BGPPeerRegistry registry, final InetSocketAddress localAddress) {
         final BGPServerSessionNegotiatorFactory snf = new BGPServerSessionNegotiatorFactory(registry);
         final ChannelPipelineInitializer initializer = BGPChannel.createChannelPipelineInitializer(BGPDispatcherImpl.this.handlerFactory, snf);
-        final ServerBootstrap serverBootstrap = createServerBootstrap(initializer, this.keys, serverChannelFactory, this.bossGroup, this.workerGroup);
+        final ServerBootstrap serverBootstrap = createServerBootstrap(initializer, Optional.<KeyMapping>absent(), this.bossGroup, this.workerGroup);
         final ChannelFuture channelFuture = serverBootstrap.bind(localAddress);
         LOG.debug("Initiated server {} at {}.", channelFuture, localAddress);
         return channelFuture;
     }
 
     public static ServerBootstrap createServerBootstrap(final ChannelPipelineInitializer initializer, final Optional<KeyMapping> keys,
-        final MD5ServerChannelFactory<?> serverChannelFactory, final EventLoopGroup bossGroup, final EventLoopGroup workerGroup) {
+        final EventLoopGroup bossGroup, final EventLoopGroup workerGroup) {
         final ServerBootstrap serverBootstrap = new ServerBootstrap();
+        if (Epoll.isAvailable()) {
+            //FIXME Bug-5566
+            serverBootstrap.channel(EpollServerSocketChannel.class);
+        } else {
+            serverBootstrap.channel(NioServerSocketChannel.class);
+        }
         final ChannelHandler serverChannelHandler = BGPChannel.createServerChannelHandler(initializer);
         serverBootstrap.childHandler(serverChannelHandler);
 
@@ -162,13 +164,11 @@ public class BGPDispatcherImpl implements BGPDispatcher, AutoCloseable {
         serverBootstrap.childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, HIGH_WATER_MARK);
         serverBootstrap.childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, LOW_WATER_MARK);
         if (keys.isPresent()) {
-            if (serverChannelFactory == null) {
-                throw new UnsupportedOperationException("No key access instance available, cannot use key mapping");
+            if (Epoll.isAvailable()) {
+                serverBootstrap.option(EpollChannelOption.TCP_MD5SIG, keys.get());
+            } else {
+                throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause());
             }
-            serverBootstrap.channelFactory(serverChannelFactory);
-            serverBootstrap.option(MD5ChannelOption.TCP_MD5SIG, keys.get());
-        } else {
-            serverBootstrap.channel(NioServerSocketChannel.class);
         }
 
         // Make sure we are doing round-robin processing
@@ -217,4 +217,4 @@ public class BGPDispatcherImpl implements BGPDispatcher, AutoCloseable {
             };
         }
     }
-}
+}
\ No newline at end of file
index e066a876b37e5276a2b78742fedaaf57a5a4cdc1..0b2b35a764957e604685e0264964ae4c04e4a2e9 100755 (executable)
@@ -12,7 +12,7 @@ import io.netty.channel.ChannelFuture;
 import io.netty.util.concurrent.Future;
 import java.net.InetSocketAddress;
 import org.opendaylight.protocol.bgp.rib.spi.BGPSession;
-import org.opendaylight.tcpmd5.api.KeyMapping;
+import org.opendaylight.protocol.concepts.KeyMapping;
 
 /**
  * Dispatcher class for creating BGP clients.
index c2977140aaaca6226958a1455ed6b4c5afe18fb2..7325d6d73f06cb244184461e6142fa5e1ab10756 100644 (file)
@@ -9,7 +9,7 @@ package org.opendaylight.protocol.bgp.rib.impl.spi;
 
 import io.netty.channel.ChannelFuture;
 import java.net.InetSocketAddress;
-import org.opendaylight.tcpmd5.api.KeyMapping;
+import org.opendaylight.protocol.concepts.KeyMapping;
 
 /**
  * Dispatcher class for creating BGP server.
index bbf385b4ae48b97003d11e07c039a5253978ea40..327345a4472b7e84abc9533114d9c53b1cc1681f 100644 (file)
@@ -7,8 +7,8 @@ module bgp-peer {
     import bgp-multiprotocol { prefix bgp-mp; revision-date 2013-09-19; }
     import config { prefix config; revision-date 2013-04-05; }
     import ietf-inet-types { prefix inet; revision-date 2010-09-24; }
-    import odl-tcpmd5-cfg { prefix tcpmd5; revision-date 2014-04-27; }
     import opendaylight-md-sal-binding {prefix mdsb; revision-date 2013-10-28; }
+    import rfc2385 { prefix rfc2385; revision-date 2016-03-24; }
 
     organization "Brocade Communications Systems, Inc.";
     contact "Kevin Wang <kwang@brocade.com>";
@@ -84,7 +84,7 @@ module bgp-peer {
         }
 
         leaf password {
-            type tcpmd5:rfc2385-key;
+            type rfc2385:rfc2385-key;
             description "RFC2385 shared secret";
         }
     }
index b12744d537453ef84a984aa05a0d96e4cb7ddb97..298b032006f36f97b5a4bd58c15882c22897e80b 100644 (file)
@@ -17,8 +17,6 @@ module odl-bgp-rib-impl-cfg {
     import opendaylight-md-sal-dom {prefix sal; revision-date 2013-10-28; }
     import netty { prefix netty; revision-date 2013-11-19; }
     import config { prefix config; revision-date 2013-04-05; }
-    import odl-tcpmd5-cfg { prefix tcpmd5; revision-date 2014-04-27; }
-    import odl-tcpmd5-netty-cfg { prefix tcpmd5n; revision-date 2014-04-27; }
     import rpc-context { prefix rpcx; revision-date 2013-06-17; }
     import odl-bgp-openconfig-spi-cfg { prefix bgp-oc-spi; revision-date 2015-09-25; }
     import odl-bgp-path-selection-mode { prefix bps; revision-date 2016-03-01;}
@@ -94,24 +92,6 @@ module odl-bgp-rib-impl-cfg {
                     }
                 }
             }
-
-            container md5-channel-factory {
-                uses config:service-ref {
-                    refine type {
-                        mandatory false;
-                        config:required-identity tcpmd5n:md5-channel-factory;
-                    }
-                }
-            }
-
-            container md5-server-channel-factory {
-                uses config:service-ref {
-                    refine type {
-                        mandatory false;
-                        config:required-identity tcpmd5n:md5-server-channel-factory;
-                    }
-                }
-            }
         }
     }
 
@@ -523,4 +503,3 @@ module odl-bgp-rib-impl-cfg {
     }
 }
 
-
index b41c9031d58dc7f2890e57630e4f47d7c1c33f7c..d59aae33c8e281fe1659951b931f6d6b5b543d0b 100644 (file)
@@ -160,22 +160,10 @@ public class BGPPeerAcceptorModuleTest extends AbstractConfigTest {
         @Override
         public void setBgpExtensions(final ObjectName bgpExtensions) {}
 
-        @Override
-        public ObjectName getMd5ChannelFactory() {return null;}
-
-        @Override
-        public void setMd5ChannelFactory(final ObjectName md5ChannelFactory) {}
-
         @Override
         public ObjectName getBossGroup() {return null;}
 
         @Override
         public void setBossGroup(final ObjectName bossGroup) {}
-
-        @Override
-        public ObjectName getMd5ServerChannelFactory() {return null;}
-
-        @Override
-        public void setMd5ServerChannelFactory(final ObjectName md5ServerChannelFactory) {}
     }
 }
index 2880bd925bceadb95a8193e1a9a9db3ef62ac87d..d2e096d174ff0ae81c4bad00c2eff60987d93808 100755 (executable)
@@ -11,6 +11,7 @@ import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.mockito.Mockito.doReturn;
 import com.google.common.collect.Lists;
+import io.netty.channel.epoll.Epoll;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -22,10 +23,6 @@ import org.opendaylight.controller.config.api.ValidationException;
 import org.opendaylight.controller.config.api.jmx.CommitStatus;
 import org.opendaylight.controller.config.spi.ModuleFactory;
 import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
-import org.opendaylight.controller.config.yang.tcpmd5.jni.cfg.NativeKeyAccessFactoryModuleFactory;
-import org.opendaylight.controller.config.yang.tcpmd5.netty.cfg.MD5ClientChannelFactoryModuleFactory;
-import org.opendaylight.controller.config.yang.tcpmd5.netty.cfg.MD5ClientChannelFactoryModuleMXBean;
-import org.opendaylight.tcpmd5.jni.NativeTestSupport;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
@@ -33,7 +30,7 @@ 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.rib.rev130925.PeerRole;
 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.MplsLabeledVpnSubsequentAddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.tcpmd5.cfg.rev140427.Rfc2385Key;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.rfc2385.cfg.rev160324.Rfc2385Key;
 import org.opendaylight.yangtools.sal.binding.generator.util.BindingRuntimeContext;
 
 public class BGPPeerModuleTest extends AbstractRIBImplModuleTest {
@@ -57,8 +54,6 @@ public class BGPPeerModuleTest extends AbstractRIBImplModuleTest {
         final List<ModuleFactory> moduleFactories = super.getModuleFactories();
         moduleFactories.add(new BGPPeerModuleFactory());
         moduleFactories.add(new BGPTableTypeImplModuleFactory());
-        moduleFactories.add(new NativeKeyAccessFactoryModuleFactory());
-        moduleFactories.add(new MD5ClientChannelFactoryModuleFactory());
         moduleFactories.add(new StrictBgpPeerRegistryModuleFactory());
         moduleFactories.add(new AddPathImplModuleFactory());
         return moduleFactories;
@@ -101,32 +96,6 @@ public class BGPPeerModuleTest extends AbstractRIBImplModuleTest {
         assertStatus(status, 21, 0, 0);
     }
 
-    @Test
-    public void testCreateBeanWithMD5() throws Exception {
-        NativeTestSupport.assumeSupportedPlatform();
-        final CommitStatus status = createBgpPeerInstance(true);
-        assertBeanCount(1, FACTORY_NAME);
-        assertStatus(status, 23, 0, 0);
-    }
-
-    @Test
-    public void testMD5ValidationFailure() throws Exception {
-        NativeTestSupport.assumeSupportedPlatform();
-        createBgpPeerInstance(true);
-        // now remove md5 from dispatcher
-        final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
-        final ObjectName nameCreated = transaction.lookupConfigBean(FACTORY_NAME, INSTANCE_NAME);
-        final BGPPeerModuleMXBean mxBean = transaction.newMXBeanProxy(nameCreated, BGPPeerModuleMXBean.class);
-        final BGPDispatcherImplModuleMXBean bgpDispatcherImplModuleMXBean = getBgpDispatcherImplModuleMXBean(transaction, mxBean);
-        bgpDispatcherImplModuleMXBean.setMd5ChannelFactory(null);
-        try {
-            transaction.validateConfig();
-            fail();
-        } catch (final ValidationException e) {
-            assertTrue(e.getMessage(), e.getMessage().contains("Underlying dispatcher does not support MD5 clients"));
-        }
-    }
-
     @Test
     public void testReusingOldInstance() throws Exception {
         CommitStatus status = createBgpPeerInstance();
@@ -165,22 +134,10 @@ public class BGPPeerModuleTest extends AbstractRIBImplModuleTest {
             mxBean.setRib(ribON);
         }
         mxBean.setAddPath(createAddPathCollection(transaction));
-        if (md5) {
-            final BGPDispatcherImplModuleMXBean bgpDispatcherProxy = getBgpDispatcherImplModuleMXBean(transaction, mxBean);
-            final ObjectName jniON = transaction.createModule(NativeKeyAccessFactoryModuleFactory.NAME, NativeKeyAccessFactoryModuleFactory.NAME);
-            final ObjectName md5ClientON = transaction.createModule(MD5ClientChannelFactoryModuleFactory.NAME,
-                    MD5ClientChannelFactoryModuleFactory.NAME);
-            final MD5ClientChannelFactoryModuleMXBean md5ClientProxy =
-                    transaction.newMXBeanProxy(md5ClientON, MD5ClientChannelFactoryModuleMXBean.class);
-            md5ClientProxy.setKeyAccessFactory(jniON);
-
-            bgpDispatcherProxy.setMd5ChannelFactory(md5ClientON);
-
+        if (Epoll.isAvailable()) {
             mxBean.setPassword(Rfc2385Key.getDefaultInstance("foo"));
-
         }
-
-        if(internalPeerRole) {
+        if (internalPeerRole) {
             mxBean.setPeerRole(PeerRole.Internal);
         }
 
index 7683b7009669cf665a669bc4ec0aa633da74f488..b040443d21161f74861c648662938f64ffb37905 100755 (executable)
@@ -14,6 +14,9 @@ import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.epoll.Epoll;
+import io.netty.channel.epoll.EpollEventLoopGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.util.concurrent.Future;
 import io.netty.util.concurrent.GenericFutureListener;
@@ -55,20 +58,29 @@ import org.slf4j.LoggerFactory;
 public class BGPDispatcherImplTest {
 
     private static final AsNumber AS_NUMBER = new AsNumber(30L);
-    private static final int RETRY_TIMER = 10;
+    private static final int RETRY_TIMER = 1;
     private static final BgpTableType IPV_4_TT = new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
     private BGPDispatcherImpl serverDispatcher;
     private TestClientDispatcher clientDispatcher;
     private BGPPeerRegistry registry;
     private SimpleSessionListener clientListener;
     private SimpleSessionListener serverListener;
+    private EventLoopGroup boss;
+    private EventLoopGroup worker;
 
     @Before
     public void setUp() throws BGPDocumentedException {
+        if (Epoll.isAvailable()) {
+            this.boss = new EpollEventLoopGroup();
+            this.worker = new EpollEventLoopGroup();
+        } else {
+            this.boss = new NioEventLoopGroup();
+            this.worker = new NioEventLoopGroup();
+        }
         this.registry = new StrictBGPPeerRegistry();
         this.clientListener = new SimpleSessionListener();
         final BGPExtensionProviderContext ctx = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance();
-        this.serverDispatcher = new BGPDispatcherImpl(ctx.getMessageRegistry(), new NioEventLoopGroup(), new NioEventLoopGroup());
+        this.serverDispatcher = new BGPDispatcherImpl(ctx.getMessageRegistry(), this.boss, this.worker);
         configureClient(ctx);
     }
 
@@ -76,7 +88,7 @@ public class BGPDispatcherImplTest {
         final InetSocketAddress clientAddress = new InetSocketAddress("127.0.11.0", 1791);
         final IpAddress clientPeerIp = new IpAddress(new Ipv4Address(clientAddress.getAddress().getHostAddress()));
         this.registry.addPeer(clientPeerIp, this.clientListener, createPreferences(clientAddress));
-        this.clientDispatcher = new TestClientDispatcher(new NioEventLoopGroup(), new NioEventLoopGroup(), ctx.getMessageRegistry(), clientAddress);
+        this.clientDispatcher = new TestClientDispatcher(this.boss, this.worker, ctx.getMessageRegistry(), clientAddress);
     }
 
     private Channel createServer(final InetSocketAddress serverAddress) throws InterruptedException {
@@ -97,6 +109,8 @@ public class BGPDispatcherImplTest {
     public void tearDown() throws Exception {
         this.serverDispatcher.close();
         this.registry.close();
+        this.worker.shutdownGracefully().awaitUninterruptibly();
+        this.boss.shutdownGracefully().awaitUninterruptibly();
     }
 
     @Test
@@ -120,9 +134,8 @@ public class BGPDispatcherImplTest {
     @Test
     public void testCreateReconnectingClient() throws Exception {
         final InetSocketAddress serverAddress = new InetSocketAddress("127.0.20.0", 1792);
-        final Channel serverChannel = createServer(serverAddress);
-        Thread.sleep(1000);
         final Future<Void> future = this.clientDispatcher.createReconnectingClient(serverAddress, this.registry, RETRY_TIMER, Optional.absent());
+        final Channel serverChannel = createServer(serverAddress);
         Assert.assertEquals(BGPSessionImpl.State.UP, this.serverListener.getState());
         Assert.assertTrue(serverChannel.isWritable());
         future.cancel(true);
index 1d8aa16f78f4c7b5d1b8f5613b681f1eeee6591b..488536b00c94cdaee5ed7b62986e564c7cfe27a3 100755 (executable)
@@ -12,11 +12,14 @@ import com.google.common.base.Optional;
 import io.netty.bootstrap.Bootstrap;
 import io.netty.channel.ChannelOption;
 import io.netty.channel.EventLoopGroup;
+import io.netty.channel.epoll.Epoll;
+import io.netty.channel.epoll.EpollSocketChannel;
 import io.netty.channel.socket.nio.NioSocketChannel;
 import io.netty.util.concurrent.Future;
 import java.net.InetSocketAddress;
 import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
+import org.opendaylight.protocol.concepts.KeyMapping;
 
 public class TestClientDispatcher {
 
@@ -29,9 +32,13 @@ public class TestClientDispatcher {
                                    final InetSocketAddress locaAddress) {
         this.disp = new BGPDispatcherImpl(messageRegistry, bossGroup, workerGroup) {
             @Override
-            protected Bootstrap createClientBootStrap() {
+            protected Bootstrap createClientBootStrap(final Optional<KeyMapping> keys, final EventLoopGroup workerGroup) {
                 final Bootstrap bootstrap = new Bootstrap();
-                bootstrap.channel(NioSocketChannel.class);
+                if (Epoll.isAvailable()) {
+                    bootstrap.channel(EpollSocketChannel.class);
+                } else {
+                    bootstrap.channel(NioSocketChannel.class);
+                }
                 // Make sure we are doing round-robin processing
                 bootstrap.option(ChannelOption.MAX_MESSAGES_PER_READ, 1);
                 bootstrap.option(ChannelOption.SO_KEEPALIVE, Boolean.TRUE);
@@ -58,7 +65,7 @@ public class TestClientDispatcher {
     public synchronized Future<Void> createReconnectingClient(final InetSocketAddress address, final BGPPeerRegistry peerRegistry,
         final int retryTimer, final Optional<InetSocketAddress> localAddress) {
         setLocalAddress(localAddress);
-        return this.disp.createReconnectingClient(address, peerRegistry, retryTimer, null);
+        return this.disp.createReconnectingClient(address, peerRegistry, retryTimer, Optional.<KeyMapping>absent());
     }
 
     private synchronized void setLocalAddress(final Optional<InetSocketAddress> localAddress) {
index d6b1719257a20c6e9b01ec26915bd81f58aa5bfc..42c728616c0b4b39e19a64bae5668ce406751467 100644 (file)
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.opendaylight.tcpmd5</groupId>
-            <artifactId>tcpmd5-api</artifactId>
-            <scope>test</scope>
-        </dependency>
         <dependency>
             <groupId>org.opendaylight.controller</groupId>
             <artifactId>config-manager</artifactId>
index 302d48a0b5697919220b9ed8bd3c7ed8f5ea1280..5c45526065c19d9103f06b7ed0130978424127f0 100644 (file)
@@ -10,11 +10,13 @@ package org.opendaylight.protocol.concepts;
 import static com.google.common.base.Strings.isNullOrEmpty;
 
 import com.google.common.base.Charsets;
+import com.google.common.base.Optional;
 import java.net.InetAddress;
 import java.util.HashMap;
 import java.util.Map;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.rfc2385.cfg.rev160324.Rfc2385Key;
 
 public final class KeyMapping extends HashMap<InetAddress, byte[]> {
     private static final long serialVersionUID = 1L;
@@ -48,4 +50,11 @@ public final class KeyMapping extends HashMap<InetAddress, byte[]> {
         final KeyMapping keyMapping = new KeyMapping();
         return keyMapping;
     }
+
+    public static KeyMapping getKeyMapping(@Nonnull final InetAddress inetAddress, final Optional<Rfc2385Key> password){
+        if (password.isPresent()) {
+            return getKeyMapping(inetAddress, password.get().getValue());
+        }
+        return null;
+    }
 }