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>
<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>
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;
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> {
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 {
<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>
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
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");
<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>
@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());
}
}
*/
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;
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;
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;
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() {
}
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);
return password != null && ! password.getValue().isEmpty() ? Optional.of(password) : Optional.<Rfc2385Key>absent();
}
-}
+}
\ No newline at end of file
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;
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;
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,
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);
@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;
}
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);
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
};
}
}
-}
+}
\ No newline at end of file
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.
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.
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>";
}
leaf password {
- type tcpmd5:rfc2385-key;
+ type rfc2385:rfc2385-key;
description "RFC2385 shared secret";
}
}
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;}
}
}
}
-
- 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;
- }
- }
- }
}
}
}
}
-
@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) {}
}
}
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;
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;
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 {
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;
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();
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);
}
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;
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);
}
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 {
public void tearDown() throws Exception {
this.serverDispatcher.close();
this.registry.close();
+ this.worker.shutdownGracefully().awaitUninterruptibly();
+ this.boss.shutdownGracefully().awaitUninterruptibly();
}
@Test
@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);
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 {
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);
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) {
<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>
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;
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;
+ }
}