2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.protocol.bgp.rib.impl;
11 import com.google.common.base.Optional;
12 import io.netty.bootstrap.Bootstrap;
13 import io.netty.channel.EventLoopGroup;
14 import io.netty.util.concurrent.Future;
15 import java.net.InetSocketAddress;
16 import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
17 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
18 import org.opendaylight.protocol.framework.ReconnectStrategy;
19 import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
22 public class TestClientDispatcher {
24 private final BGPHandlerFactory hf;
25 private final InetSocketAddress defaulAddress;
26 private InetSocketAddress localAddress;
27 private final BGPDispatcherImpl disp;
29 protected TestClientDispatcher(final EventLoopGroup bossGroup, final EventLoopGroup workerGroup, final MessageRegistry messageRegistry,
30 final InetSocketAddress locaAddress) {
31 disp = new BGPDispatcherImpl(messageRegistry, bossGroup, workerGroup) {
33 protected void customizeBootstrap(final Bootstrap b) {
34 b.localAddress(locaAddress);
37 this.hf = new BGPHandlerFactory(messageRegistry);
38 this.localAddress = locaAddress;
39 this.defaulAddress = locaAddress;
42 public synchronized Future<BGPSessionImpl> createClient(final InetSocketAddress remoteAddress,
43 final AsNumber remoteAs, final BGPPeerRegistry listener, final ReconnectStrategy strategy, final Optional<InetSocketAddress> localAddress) {
44 setLocalAddress(localAddress);
45 return disp.createClient(remoteAddress, remoteAs, listener, strategy);
48 public synchronized Future<Void> createReconnectingClient(final InetSocketAddress address,
49 final AsNumber remoteAs, final BGPPeerRegistry peerRegistry, final ReconnectStrategyFactory reconnectStrategyFactory,
50 final Optional<InetSocketAddress> localAddress) {
51 setLocalAddress(localAddress);
52 return disp.createReconnectingClient(address, remoteAs, peerRegistry, reconnectStrategyFactory, null);
55 private synchronized void setLocalAddress(final Optional<InetSocketAddress> localAddress) {
56 if (localAddress.isPresent()) {
57 this.localAddress = localAddress.get();
59 this.localAddress = defaulAddress;