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.util.concurrent.Future;
}
private io.netty.util.concurrent.Future<Void> initiateConnection(final InetSocketAddress address, final String password, final BGPPeerRegistry registry) {
- final KeyMapping keys;
+ KeyMapping keys = null;
if (password != null) {
keys = new KeyMapping();
keys.put(address.getAddress(), password.getBytes(Charsets.US_ASCII));
- } else {
- keys = null;
}
final RIB rib = getRibDependency();
- return rib.getDispatcher().createReconnectingClient(address, registry, rib.getTcpStrategyFactory(), keys);
+ final Optional<KeyMapping> optionalKey = Optional.fromNullable(keys);
+ return rib.getDispatcher().createReconnectingClient(address, registry, rib.getTcpStrategyFactory(), optionalKey);
}
private BGPPeerRegistry getPeerRegistryBackwards() {
*/
package org.opendaylight.protocol.bgp.rib.impl;
+import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
private final EventLoopGroup bossGroup;
private final EventLoopGroup workerGroup;
private final EventExecutor executor;
- private KeyMapping keys;
+ private Optional<KeyMapping> keys;
public BGPDispatcherImpl(final MessageRegistry messageRegistry, final EventLoopGroup bossGroup, final EventLoopGroup workerGroup) {
this(messageRegistry, bossGroup, workerGroup, null, null);
this.handlerFactory = new BGPHandlerFactory(messageRegistry);
this.channelFactory = cf;
this.serverChannelFactory = scf;
- this.keys = null;
+ this.keys = Optional.absent();
}
@Override
final BGPClientSessionNegotiatorFactory snf = new BGPClientSessionNegotiatorFactory(listener);
final ChannelPipelineInitializer initializer = BGPChannel.createChannelPipelineInitializer(BGPDispatcherImpl.this.handlerFactory, snf);
- final Bootstrap bootstrap = new Bootstrap();
+ final Bootstrap bootstrap = createClientBootStrap();
final BGPProtocolSessionPromise sessionPromise = new BGPProtocolSessionPromise(this.executor, address, strategy, bootstrap);
- bootstrap.option(ChannelOption.SO_KEEPALIVE, Boolean.TRUE);
bootstrap.handler(BGPChannel.createChannelInitializer(initializer, sessionPromise));
- this.customizeBootstrap(bootstrap);
- setWorkerGroup(bootstrap);
sessionPromise.connect();
LOG.debug("Client created.");
return sessionPromise;
}
+ protected Bootstrap createClientBootStrap() {
+ final Bootstrap bootstrap = new Bootstrap();
+ if (this.keys.isPresent()) {
+ if (this.channelFactory == null) {
+ throw new UnsupportedOperationException("No key access instance available, cannot use key mapping");
+ }
+ bootstrap.channelFactory(this.channelFactory);
+ bootstrap.option(MD5ChannelOption.TCP_MD5SIG, this.keys.get());
+ } 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);
+
+ if (bootstrap.group() == null) {
+ bootstrap.group(this.workerGroup);
+ }
+
+ return bootstrap;
+ }
+
@Override
public void close() {
try {
@Override
public synchronized Future<Void> createReconnectingClient(final InetSocketAddress address, final BGPPeerRegistry peerRegistry,
- final ReconnectStrategyFactory connectStrategyFactory, final KeyMapping keys) {
+ final ReconnectStrategyFactory connectStrategyFactory, final Optional<KeyMapping> keys) {
final BGPClientSessionNegotiatorFactory snf = new BGPClientSessionNegotiatorFactory(peerRegistry);
this.keys = keys;
-
- final Bootstrap bootstrap = new Bootstrap();
+ final Bootstrap bootstrap = createClientBootStrap();
final BGPReconnectPromise reconnectPromise = new BGPReconnectPromise<BGPSessionImpl>(GlobalEventExecutor.INSTANCE, address,
connectStrategyFactory, bootstrap, BGPChannel.createChannelPipelineInitializer(BGPDispatcherImpl.this.handlerFactory, snf));
- bootstrap.option(ChannelOption.SO_KEEPALIVE, Boolean.TRUE);
- this.customizeBootstrap(bootstrap);
- setWorkerGroup(bootstrap);
reconnectPromise.connect();
-
this.keys = null;
-
return reconnectPromise;
}
public ChannelFuture createServer(final BGPPeerRegistry registry, final InetSocketAddress address) {
final BGPServerSessionNegotiatorFactory snf = new BGPServerSessionNegotiatorFactory(registry);
final ChannelPipelineInitializer initializer = BGPChannel.createChannelPipelineInitializer(BGPDispatcherImpl.this.handlerFactory, snf);
- final ServerBootstrap serverBootstrap = new ServerBootstrap();
- serverBootstrap.childHandler(BGPChannel.createChannelInitializer(initializer, new DefaultPromise(BGPDispatcherImpl.this.executor)));
- serverBootstrap.option(ChannelOption.SO_BACKLOG, Integer.valueOf(SOCKET_BACKLOG_SIZE));
- serverBootstrap.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
- this.customizeBootstrap(serverBootstrap);
-
+ final ServerBootstrap serverBootstrap = createServerBootstrap(initializer);
final ChannelFuture channelFuture = serverBootstrap.bind(address);
LOG.debug("Initiated server {} at {}.", channelFuture, address);
return channelFuture;
}
- protected void customizeBootstrap(final Bootstrap bootstrap) {
- if (this.keys != null && !this.keys.isEmpty()) {
- if (this.channelFactory == null) {
- throw new UnsupportedOperationException("No key access instance available, cannot use key mapping");
- }
- bootstrap.channelFactory(this.channelFactory);
- bootstrap.option(MD5ChannelOption.TCP_MD5SIG, this.keys);
- }
-
- // Make sure we are doing round-robin processing
- bootstrap.option(ChannelOption.MAX_MESSAGES_PER_READ, 1);
- }
-
- private void customizeBootstrap(final ServerBootstrap serverBootstrap) {
- if (this.keys != null && !this.keys.isEmpty()) {
+ private ServerBootstrap createServerBootstrap(final ChannelPipelineInitializer initializer) {
+ final ServerBootstrap serverBootstrap = new ServerBootstrap();
+ serverBootstrap.childHandler(BGPChannel.createChannelInitializer(initializer, new DefaultPromise(BGPDispatcherImpl.this.executor)));
+ serverBootstrap.option(ChannelOption.SO_BACKLOG, Integer.valueOf(SOCKET_BACKLOG_SIZE));
+ serverBootstrap.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
+ if (this.keys.isPresent()) {
if (this.serverChannelFactory == null) {
throw new UnsupportedOperationException("No key access instance available, cannot use key mapping");
}
serverBootstrap.channelFactory(this.serverChannelFactory);
- serverBootstrap.option(MD5ChannelOption.TCP_MD5SIG, this.keys);
+ serverBootstrap.option(MD5ChannelOption.TCP_MD5SIG, this.keys.get());
+ } else {
+ serverBootstrap.channel(NioServerSocketChannel.class);
}
// Make sure we are doing round-robin processing
if (serverBootstrap.group() == null) {
serverBootstrap.group(this.bossGroup, this.workerGroup);
}
-
- try {
- serverBootstrap.channel(NioServerSocketChannel.class);
- } catch (final IllegalStateException e) {
- LOG.trace("Not overriding channelFactory on bootstrap {}", serverBootstrap, e);
- }
- }
-
- private void setWorkerGroup(final Bootstrap bootstrap) {
- if (bootstrap.group() == null) {
- bootstrap.group(this.workerGroup);
- }
- try {
- bootstrap.channel(NioSocketChannel.class);
- } catch (final IllegalStateException e) {
- LOG.trace("Not overriding channelFactory on bootstrap {}", bootstrap, e);
- }
+ return serverBootstrap;
}
private static final class BGPChannel {
*/
package org.opendaylight.protocol.bgp.rib.impl.spi;
+import com.google.common.base.Optional;
import io.netty.channel.ChannelFuture;
import io.netty.util.concurrent.Future;
import java.net.InetSocketAddress;
* @return Future promising a client session
*/
Future<Void> createReconnectingClient(InetSocketAddress address,
- BGPPeerRegistry peerRegistry, ReconnectStrategyFactory connectStrategyFactory, KeyMapping keys);
+ BGPPeerRegistry peerRegistry, ReconnectStrategyFactory connectStrategyFactory, Optional<KeyMapping> keys);
/**
* Create new BGP server to accept incoming bgp connections (bound to provided socket address).
import org.opendaylight.protocol.bgp.rib.spi.SimpleRIBExtensionProviderContext;
import org.opendaylight.protocol.bgp.util.HexDumpBGPFileParser;
import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
-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.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes.Ipv4Route;
this.mock = new BGPMock(new EventBus("test"), ServiceLoaderBGPExtensionProviderContext.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.eq(this.tcpStrategyFactory), Mockito.any(KeyMapping.class));
+ Mockito.any(InetSocketAddress.class), Mockito.any(BGPPeerRegistry.class), Mockito.eq(this.tcpStrategyFactory), Mockito.any(Optional.class));
this.ext1 = new SimpleRIBExtensionProviderContext();
this.ext2 = new SimpleRIBExtensionProviderContext();
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
+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;
final InetSocketAddress locaAddress) {
this.disp = new BGPDispatcherImpl(messageRegistry, bossGroup, workerGroup) {
@Override
- protected void customizeBootstrap(final Bootstrap b) {
- b.localAddress(locaAddress);
- b.option(ChannelOption.SO_REUSEADDR, true);
+ protected Bootstrap createClientBootStrap() {
+ final Bootstrap bootstrap = new Bootstrap();
+ 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);
+
+ if (bootstrap.group() == null) {
+ bootstrap.group(workerGroup);
+ }
+ bootstrap.localAddress(locaAddress);
+ bootstrap.option(ChannelOption.SO_REUSEADDR, true);
+ return bootstrap;
}
};
this.hf = new BGPHandlerFactory(messageRegistry);
*/
package org.opendaylight.protocol.pcep;
+import com.google.common.base.Optional;
import io.netty.channel.ChannelFuture;
import java.net.InetSocketAddress;
import org.opendaylight.tcpmd5.api.KeyMapping;
* @param peerProposal information used in our Open message
* @return instance of PCEPServer
*/
- ChannelFuture createServer(InetSocketAddress address, KeyMapping keys, PCEPSessionListenerFactory listenerFactory, PCEPPeerProposal peerProposal);
+ ChannelFuture createServer(InetSocketAddress address, Optional<KeyMapping> keys, PCEPSessionListenerFactory listenerFactory, PCEPPeerProposal peerProposal);
}
*/
package org.opendaylight.protocol.pcep.impl;
+import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.PooledByteBufAllocator;
private final EventLoopGroup workerGroup;
private final EventExecutor executor;
private final MD5ServerChannelFactory<?> scf;
- private KeyMapping keys;
+ private Optional<KeyMapping> keys;
/**
* Creates an instance of PCEPDispatcherImpl, gets the default selector and opens it.
@Override
public synchronized ChannelFuture createServer(final InetSocketAddress address,
final PCEPSessionListenerFactory listenerFactory, final PCEPPeerProposal peerProposal) {
- return createServer(address, null, listenerFactory, peerProposal);
+ return createServer(address, Optional.<KeyMapping>absent(), listenerFactory, peerProposal);
}
@Override
- public synchronized ChannelFuture createServer(final InetSocketAddress address, final KeyMapping keys,
+ public synchronized ChannelFuture createServer(final InetSocketAddress address, final Optional<KeyMapping> keys,
final PCEPSessionListenerFactory listenerFactory, final PCEPPeerProposal peerProposal) {
this.keys = keys;
ch.pipeline().addLast(PCEPDispatcherImpl.this.hf.getEncoders());
}
};
+
+ final ServerBootstrap b = createServerBootstrap(initializer);
+ final ChannelFuture f = b.bind(address);
+ LOG.debug("Initiated server {} at {}.", f, address);
+
+ this.keys = null;
+ return f;
+ }
+
+ protected ServerBootstrap createServerBootstrap(final ChannelPipelineInitializer initializer) {
final ServerBootstrap b = new ServerBootstrap();
b.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
b.option(ChannelOption.SO_BACKLOG, SOCKET_BACKLOG_SIZE);
b.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
- this.customizeBootstrap(b);
- if (b.group() == null) {
- b.group(this.bossGroup, this.workerGroup);
- }
-
- try {
- b.channel(NioServerSocketChannel.class);
- } catch (final IllegalStateException e) {
- LOG.trace("Not overriding channelFactory on bootstrap {}", b, e);
- }
- final ChannelFuture f = b.bind(address);
- LOG.debug("Initiated server {} at {}.", f, address);
-
- this.keys = null;
- return f;
- }
-
- protected void customizeBootstrap(final ServerBootstrap b) {
- if (this.keys != null && !this.keys.isEmpty()) {
+ if (this.keys.isPresent()) {
if (this.scf == null) {
throw new UnsupportedOperationException("No key access instance available, cannot use key mapping");
}
- LOG.debug("Adding MD5 keys {} to bootstrap {}", this.keys, b);
+ LOG.debug("Adding MD5 keys {} to bootstrap {}", this.keys.get(), b);
b.channelFactory(this.scf);
- b.option(MD5ChannelOption.TCP_MD5SIG, this.keys);
+ b.option(MD5ChannelOption.TCP_MD5SIG, this.keys.get());
+ } else {
+ b.channel(NioServerSocketChannel.class);
}
// Make sure we are doing round-robin processing
b.childOption(ChannelOption.MAX_MESSAGES_PER_READ, 1);
+
+ if (b.group() == null) {
+ b.group(this.bossGroup, this.workerGroup);
+ }
+
+ return b;
}
@Override
package org.opendaylight.protocol.pcep.impl;
+import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import io.netty.bootstrap.Bootstrap;
-import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
keys.put(CLIENT1_ADDRESS.getAddress(), new String("CLIENT1_ADDRESS").getBytes() );
keys.put(CLIENT2_ADDRESS.getAddress(), new String("CLIENT2_ADDRESS").getBytes() );
- final ChannelFuture futureChannel = this.disp2Spy.createServer(new InetSocketAddress("0.0.0.0", PORT), keys,
+ final ChannelFuture futureChannel = this.disp2Spy.createServer(new InetSocketAddress("0.0.0.0", PORT), Optional.fromNullable(keys),
new PCEPSessionListenerFactory() {
@Override
public PCEPSessionListener getSessionListener() {
return new SimpleSessionListener();
}
}, null);
- Mockito.verify(this.disp2Spy).customizeBootstrap(Mockito.any(ServerBootstrap.class));
+ Mockito.verify(this.disp2Spy).createServerBootstrap(Mockito.any(PCEPDispatcherImpl.ChannelPipelineInitializer.class));
}
@After
this.network = Preconditions.checkNotNull(network);
}
- public static PCEPTopologyProvider create(final PCEPDispatcher dispatcher, final InetSocketAddress address, final KeyMapping keys,
+ public static PCEPTopologyProvider create(final PCEPDispatcher dispatcher, final InetSocketAddress address, final Optional<KeyMapping> keys,
final InstructionScheduler scheduler, final DataBroker dataBroker, final RpcProviderRegistry rpcRegistry,
final InstanceIdentifier<Topology> topology, final TopologySessionListenerFactory listenerFactory,
final Optional<PCEPTopologyProviderRuntimeRegistrator> runtimeRootRegistrator) throws InterruptedException,
import com.google.common.net.InetAddresses;
import java.net.InetAddress;
import java.net.InetSocketAddress;
+import java.util.List;
import java.util.concurrent.ExecutionException;
import org.opendaylight.bgpcep.pcep.topology.provider.PCEPTopologyProvider;
import org.opendaylight.controller.config.api.JmxAttributeValidationException;
super(identifier, dependencyResolver, oldModule, oldInstance);
}
- private KeyMapping contructKeys() {
- final KeyMapping ret = new KeyMapping();
- if (getClient() != null) {
- for (final Client c : getClient()) {
+ private Optional<KeyMapping> contructKeys() {
+ KeyMapping ret = null;
+ final List<Client> clients = getClient();
+
+ if (clients != null && !clients.isEmpty()) {
+ ret = new KeyMapping();
+ for (final Client c : clients) {
if (c.getAddress() == null) {
LOG.warn("Client {} does not have an address skipping it", c);
continue;
}
}
}
- return ret;
+ return Optional.fromNullable(ret);
}
JmxAttributeValidationException.checkNotNull(getListenPort(), IS_NOT_SET, listenPortJmxAttribute);
JmxAttributeValidationException.checkNotNull(getStatefulPlugin(), IS_NOT_SET, statefulPluginJmxAttribute);
- final KeyMapping keys = contructKeys();
- if (!keys.isEmpty()) {
+ final Optional<KeyMapping> keys = contructKeys();
+ if (keys.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
final InstanceIdentifier<Topology> topology = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class,
new TopologyKey(getTopologyId())).build();
final InetSocketAddress address = new InetSocketAddress(listenAddress(), getListenPort().getValue());
- final KeyMapping keys = contructKeys();
try {
- return PCEPTopologyProvider.create(getDispatcherDependency(), address, keys.isEmpty() ? null : keys, getSchedulerDependency(),
+ return PCEPTopologyProvider.create(getDispatcherDependency(), address, contructKeys(), getSchedulerDependency(),
getDataProviderDependency(), getRpcRegistryDependency(), topology, getStatefulPluginDependency(),
Optional.of(getRootRuntimeBeanRegistratorWrapper()));
} catch (InterruptedException | ExecutionException | TransactionCommitFailedException | ReadFailedException e) {