import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;
-import org.opendaylight.protocol.framework.ReconnectImmediatelyStrategy;
+import org.opendaylight.protocol.framework.NeverReconnectStrategy;
+import org.opendaylight.protocol.framework.ReconnectStrategy;
+import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
import org.opendaylight.protocol.framework.SessionListenerFactory;
import org.opendaylight.protocol.framework.SessionNegotiatorFactory;
+import org.opendaylight.protocol.framework.TimedReconnectStrategy;
import org.opendaylight.protocol.pcep.PCEPSessionListener;
import org.opendaylight.protocol.pcep.ietf.initiated00.CrabbeInitiatedActivator;
import org.opendaylight.protocol.pcep.ietf.stateful07.StatefulActivator;
short ka = DEFAULT_KEEP_ALIVE;
short dt = DEFAULT_DEAD_TIMER;
String password = null;
+ int reconnectTime = -1;
getRootLogger(lc).setLevel(ch.qos.logback.classic.Level.INFO);
int argIdx = 0;
dt = Short.valueOf(args[++argIdx]);
} else if (args[argIdx].equals("--password")) {
password = args[++argIdx];
+ } else if (args[argIdx].equals("--reconnect")) {
+ reconnectTime = Integer.valueOf(args[++argIdx]).intValue() * 1000;
} else {
LOG.warn("WARNING: Unrecognized argument: {}", args[argIdx]);
}
argIdx++;
}
- createPCCs(lsps, pcError, pccCount, localAddress, remoteAddress, ka, dt, password);
+ createPCCs(lsps, pcError, pccCount, localAddress, remoteAddress, ka, dt, password, reconnectTime);
}
public static void createPCCs(final int lspsPerPcc, final boolean pcerr, final int pccCount,
final InetSocketAddress localAddress, final List<InetSocketAddress> remoteAddress, final short keepalive, final short deadtimer,
- final String password) throws InterruptedException, ExecutionException {
+ final String password, final int reconnectTime) throws InterruptedException, ExecutionException {
startActivators();
InetAddress currentAddress = localAddress.getAddress();
final Open openMessage = getOpenMessage(keepalive, deadtimer);
getSessionNegotiatorFactory(openMessage));
for (int i = 0; i < pccCount; i++) {
createPCC(lspsPerPcc, pcerr, new InetSocketAddress(currentAddress, localAddress.getPort()),
- remoteAddress, openMessage, pccDispatcher, password);
+ remoteAddress, openMessage, pccDispatcher, password, reconnectTime);
currentAddress = InetAddresses.increment(currentAddress);
}
}
+ @SuppressWarnings("deprecation")
private static void createPCC(final int lspsPerPcc, final boolean pcerr, final InetSocketAddress localAddress,
final List<InetSocketAddress> remoteAddress, final Open openMessage, final PCCDispatcher pccDispatcher,
- final String password) throws InterruptedException, ExecutionException {
+ final String password, final int reconnectTime) throws InterruptedException, ExecutionException {
final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> snf = getSessionNegotiatorFactory(openMessage);
for (final InetSocketAddress pceAddress : remoteAddress) {
- pccDispatcher.createClient(localAddress, pceAddress, new ReconnectImmediatelyStrategy(GlobalEventExecutor.INSTANCE, RECONNECT_STRATEGY_TIMEOUT), new SessionListenerFactory<PCEPSessionListener>() {
+ pccDispatcher.createClient(localAddress, pceAddress, reconnectTime == -1 ? getNeverReconnectStrategyFactory() : getTimedReconnectStrategyFactory(reconnectTime), new SessionListenerFactory<PCEPSessionListener>() {
@Override
public PCEPSessionListener getSessionListener() {
return new SimpleSessionListener(lspsPerPcc, pcerr, localAddress.getAddress());
}
}
+ @SuppressWarnings("deprecation")
private static SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> getSessionNegotiatorFactory(final Open openMessage) {
return new DefaultPCEPSessionNegotiatorFactory(openMessage, 0);
}
activator.start(ctx);
}
+ @SuppressWarnings("deprecation")
+ private static ReconnectStrategyFactory getNeverReconnectStrategyFactory() {
+ return new ReconnectStrategyFactory() {
+
+ @Override
+ public ReconnectStrategy createReconnectStrategy() {
+ return new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, RECONNECT_STRATEGY_TIMEOUT);
+ }
+ };
+ }
+
+ @SuppressWarnings("deprecation")
+ private static ReconnectStrategyFactory getTimedReconnectStrategyFactory(final int reconnectTime) {
+ return new ReconnectStrategyFactory() {
+
+ @Override
+ public ReconnectStrategy createReconnectStrategy() {
+ return new TimedReconnectStrategy(GlobalEventExecutor.INSTANCE, RECONNECT_STRATEGY_TIMEOUT, reconnectTime, 1.0, null, null, null);
+ }
+ };
+ }
+
}
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
-import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.Promise;
import java.net.InetSocketAddress;
-import org.opendaylight.protocol.framework.ReconnectStrategy;
+import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
import org.opendaylight.protocol.framework.SessionListenerFactory;
import org.opendaylight.protocol.framework.SessionNegotiatorFactory;
import org.opendaylight.protocol.pcep.PCEPSessionListener;
}
}
- public synchronized Future<PCEPSessionImpl> createClient(final InetSocketAddress localAddress, final InetSocketAddress remoteAddress,
- final ReconnectStrategy strategy, final SessionListenerFactory<PCEPSessionListener> listenerFactory,
+ public synchronized void createClient(final InetSocketAddress localAddress, final InetSocketAddress remoteAddress,
+ final ReconnectStrategyFactory strategyFactory, final SessionListenerFactory<PCEPSessionListener> listenerFactory,
final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> negotiatorFactory, final KeyMapping keys) {
this.localAddress = localAddress;
this.keys = keys;
- final Future<PCEPSessionImpl> futureClient = super.createClient(remoteAddress, strategy, new PipelineInitializer<PCEPSessionImpl>() {
+ super.createReconnectingClient(remoteAddress, strategyFactory, new PipelineInitializer<PCEPSessionImpl>() {
@Override
public void initializeChannel(final SocketChannel ch, final Promise<PCEPSessionImpl> promise) {
ch.pipeline().addLast(PCCDispatcher.this.factory.getDecoders());
});
this.localAddress = null;
this.keys = null;
- return futureClient;
}
private static final class DeafultKeyAccessFactory {