this.b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, this.connectTimeout);
this.b.remoteAddress(this.address);
final ChannelFuture connectFuture = this.b.connect();
- connectFuture.addListener(new BootstrapConnectListener(lock));
+ connectFuture.addListener(new BootstrapConnectListener());
this.pending = connectFuture;
} catch (Exception e) {
LOG.info("Failed to connect to {}", this.address, e);
}
private class BootstrapConnectListener implements ChannelFutureListener {
- private final Object lock;
-
- public BootstrapConnectListener(final Object lock) {
- this.lock = lock;
- }
-
@Override
public void operationComplete(final ChannelFuture cf) throws Exception {
- synchronized (this.lock) {
- PCEPProtocolSessionPromise.LOG.debug("Promise {} connection resolved", this.lock);
+ synchronized (PCEPProtocolSessionPromise.this) {
+ PCEPProtocolSessionPromise.LOG.debug("Promise {} connection resolved",
+ PCEPProtocolSessionPromise.this);
Preconditions.checkState(PCEPProtocolSessionPromise.this.pending.equals(cf));
if (PCEPProtocolSessionPromise.this.isCancelled()) {
if (cf.isSuccess()) {
- PCEPProtocolSessionPromise.LOG.debug("Closing channel for cancelled promise {}", this.lock);
+ PCEPProtocolSessionPromise.LOG.debug("Closing channel for cancelled promise {}",
+ PCEPProtocolSessionPromise.this);
cf.channel().close();
}
} else if (cf.isSuccess()) {
- PCEPProtocolSessionPromise.LOG.debug("Promise {} connection successful", this.lock);
+ PCEPProtocolSessionPromise.LOG.debug("Promise {} connection successful",
+ PCEPProtocolSessionPromise.this);
} else {
- PCEPProtocolSessionPromise.LOG.debug("Attempt to connect to {} failed", PCEPProtocolSessionPromise.this.address, cf.cause());
+ PCEPProtocolSessionPromise.LOG.debug("Attempt to connect to {} failed",
+ PCEPProtocolSessionPromise.this.address, cf.cause());
if (PCEPProtocolSessionPromise.this.retryTimer == 0) {
- PCEPProtocolSessionPromise.LOG.debug("Retry timer value is 0. Reconnection will not be attempted");
+ PCEPProtocolSessionPromise.LOG
+ .debug("Retry timer value is 0. Reconnection will not be attempted");
PCEPProtocolSessionPromise.this.setFailure(cf.cause());
return;
}
final EventLoop loop = cf.channel().eventLoop();
loop.schedule(() -> {
- PCEPProtocolSessionPromise.LOG.debug("Attempting to connect to {}", PCEPProtocolSessionPromise.this.address);
- final Future<Void> reconnectFuture = PCEPProtocolSessionPromise.this.b.connect();
- reconnectFuture.addListener(BootstrapConnectListener.this);
- PCEPProtocolSessionPromise.this.pending = reconnectFuture;
+ synchronized (PCEPProtocolSessionPromise.this) {
+ PCEPProtocolSessionPromise.LOG.debug("Attempting to connect to {}",
+ PCEPProtocolSessionPromise.this.address);
+ final Future<Void> reconnectFuture = PCEPProtocolSessionPromise.this.b.connect();
+ reconnectFuture.addListener(BootstrapConnectListener.this);
+ PCEPProtocolSessionPromise.this.pending = reconnectFuture;
+ }
}, PCEPProtocolSessionPromise.this.retryTimer, TimeUnit.SECONDS);
- PCEPProtocolSessionPromise.LOG.debug("Next reconnection attempt in {}s", PCEPProtocolSessionPromise.this.retryTimer);
+ PCEPProtocolSessionPromise.LOG.debug("Next reconnection attempt in {}s",
+ PCEPProtocolSessionPromise.this.retryTimer);
}
}
}
* @param error documented error in RFC5440 or draft
*/
@VisibleForTesting
- public void handleMalformedMessage(final PCEPErrors error) {
+ void handleMalformedMessage(final PCEPErrors error) {
final long ct = TICKER.read();
this.sendErrorMessage(error);
if (error == PCEPErrors.CAPABILITY_NOT_SUPPORTED) {
this.unknownMessagesTimes.add(ct);
while (ct - this.unknownMessagesTimes.peek() > MINUTE) {
- this.unknownMessagesTimes.poll();
+ final Long poll = this.unknownMessagesTimes.poll();
}
if (this.unknownMessagesTimes.size() > this.maxUnknownMessages) {
this.terminate(TerminationReason.TOO_MANY_UNKNOWN_MSGS);
remoteAddress = InetSocketAddressUtil.parseAddresses(args[++argIdx], DEFAULT_REMOTE_PORT);
break;
case "--pcc":
- pccCount = Integer.valueOf(args[++argIdx]);
+ pccCount = Integer.parseInt(args[++argIdx]);
break;
case "--lsp":
- lsps = Integer.valueOf(args[++argIdx]);
+ lsps = Integer.parseInt(args[++argIdx]);
break;
case "--pcerr":
pcError = true;
password = args[++argIdx];
break;
case "--reconnect":
- reconnectTime = Integer.valueOf(args[++argIdx]);
+ reconnectTime = Integer.parseInt(args[++argIdx]);
break;
case "--redelegation-timeout":
- redelegationTimeout = Integer.valueOf(args[++argIdx]);
+ redelegationTimeout = Integer.parseInt(args[++argIdx]);
break;
case "--state-timeout":
- stateTimeout = Integer.valueOf(args[++argIdx]);
+ stateTimeout = Integer.parseInt(args[++argIdx]);
break;
case "--state-sync-avoidance":
//"--state-sync-avoidance 10, 5, 10
includeDbv = Boolean.TRUE;
final Long dbVersionAfterReconnect = Long.valueOf(args[++argIdx]);
- disonnectAfterXSeconds = Integer.valueOf(args[++argIdx]);
- reconnectAfterXSeconds = Integer.valueOf(args[++argIdx]);
+ disonnectAfterXSeconds = Integer.parseInt(args[++argIdx]);
+ reconnectAfterXSeconds = Integer.parseInt(args[++argIdx]);
syncOptDBVersion = BigInteger.valueOf(dbVersionAfterReconnect);
break;
case "--incremental-sync-procedure":
incrementalSync = Boolean.TRUE;
//Version of database to be used after restart
final Long initialDbVersionAfterReconnect = Long.valueOf(args[++argIdx]);
- disonnectAfterXSeconds = Integer.valueOf(args[++argIdx]);
- reconnectAfterXSeconds = Integer.valueOf(args[++argIdx]);
+ disonnectAfterXSeconds = Integer.parseInt(args[++argIdx]);
+ reconnectAfterXSeconds = Integer.parseInt(args[++argIdx]);
syncOptDBVersion = BigInteger.valueOf(initialDbVersionAfterReconnect);
break;
case "--triggered-initial-sync":
}
if (incrementalSync) {
- Preconditions.checkArgument(syncOptDBVersion.intValue() > lsps, "Synchronization Database Version which will be used after " +
+ Preconditions.checkArgument(syncOptDBVersion.intValue() > lsps,
+ "Synchronization Database Version which will be used after " +
"reconnectes requires to be higher than lsps");
}
final Optional<BigInteger> dBVersion = Optional.fromNullable(syncOptDBVersion);
- final PCCsBuilder pccs = new PCCsBuilder(lsps, pcError, pccCount, localAddress, remoteAddress, ka, dt, password, reconnectTime, redelegationTimeout,
+ final PCCsBuilder pccs = new PCCsBuilder(lsps, pcError, pccCount, localAddress, remoteAddress, ka, dt,
+ password, reconnectTime, redelegationTimeout,
stateTimeout, getCapabilities());
- final TimerHandler timerHandler = new TimerHandler(pccs, dBVersion, disonnectAfterXSeconds, reconnectAfterXSeconds);
+ final TimerHandler timerHandler = new TimerHandler(pccs, dBVersion, disonnectAfterXSeconds,
+ reconnectAfterXSeconds);
pccs.createPCCs(BigInteger.valueOf(lsps), Optional.fromNullable(timerHandler));
if (!triggeredInitSync) {
timerHandler.createDisconnectTask();
if (triggeredInitSync) {
Preconditions.checkArgument(includeDbv);
}
- return new PCEPStatefulCapability(true, true, true, triggeredInitSync, triggeredResync, incrementalSync, includeDbv);
+ return new PCEPStatefulCapability(true, true, true, triggeredInitSync, triggeredResync,
+ incrementalSync, includeDbv);
}
private static ch.qos.logback.classic.Logger getRootLogger(final LoggerContext lc) {
import com.google.common.collect.Lists;
import java.util.HashMap;
import java.util.Map;
+import javax.annotation.Nonnull;
import org.opendaylight.protocol.pcep.pcc.mock.api.LspType;
import org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder;
-public final class PCCTunnelBuilder {
+final class PCCTunnelBuilder {
private static final Subobject DEFAULT_ENDPOINT_HOP = getDefaultEROEndpointHop();
private static final String ENDPOINT_ADDRESS = "1.1.1.1";
private static final String ENDPOINT_PREFIX = ENDPOINT_ADDRESS + "/32";
throw new UnsupportedOperationException();
}
- public static Map<PlspId, PCCTunnel> createTunnels(final String address, final int lsps) {
+ @Nonnull
+ static Map<PlspId, PCCTunnel> createTunnels(final String address, final int lsps) {
final Map<PlspId, PCCTunnel> tunnels = new HashMap<>();
for (int i = 1; i <= lsps; i++) {
final PCCTunnel tunnel = new PCCTunnel(MsgBuilderUtil.getDefaultPathName(address, i), PCC_DELEGATION, LspType.PCC_LSP,
}
private Tlvs buildTlvs(final PCCTunnel tunnel, final Long plspId, final Optional<List<Subobject>> subobjectsList) {
- final List<Subobject> subObject = subobjectsList.isPresent() ? subobjectsList.get() : tunnel.getLspState().getEro().getSubobject();
+ final List<Subobject> subObject = subobjectsList.isPresent() ? subobjectsList.get() :
+ tunnel.getLspState().getEro().getSubobject();
final String destinationAddress = getDestinationAddress(subObject, this.address);
- return createLspTlvs(plspId, true, destinationAddress, this.address, this.address, Optional.of(tunnel.getPathName()),
- this.syncOptimization.incrementLspDBVersion());
+ return createLspTlvs(plspId, true, destinationAddress, this.address, this.address,
+ Optional.of(tunnel.getPathName()), this.syncOptimization.incrementLspDBVersion());
}
- private void lazyTunnelInicialization() {
+ private synchronized void lazyTunnelInicialization() {
if (this.tunnels.isEmpty()) {
final BigInteger dbV = this.syncOptimization.getLocalLspDbVersionValue();
- if (this.syncOptimization.isSyncAvoidanceEnabled() && !((dbV != null) && dbV.equals(BigInteger.ONE))) {
+ if (dbV != null && this.syncOptimization.isSyncAvoidanceEnabled() && !dbV.equals(BigInteger.ONE)) {
this.tunnels.putAll(PCCTunnelBuilder.createTunnels(this.address, dbV.intValue()));
} else {
this.tunnels.putAll(PCCTunnelBuilder.createTunnels(this.address, this.lspsCount));
import io.netty.util.concurrent.Future;
import java.math.BigInteger;
import java.net.InetSocketAddress;
+import javax.annotation.Nonnull;
import org.opendaylight.protocol.concepts.KeyMapping;
import org.opendaylight.protocol.pcep.PCEPSession;
import org.opendaylight.protocol.pcep.PCEPSessionListenerFactory;
public interface PCCDispatcher {
- Future<PCEPSession> createClient(final InetSocketAddress remoteAddress,
- final long reconnectTime, final PCEPSessionListenerFactory listenerFactory,
- final PCEPSessionNegotiatorFactory<? extends PCEPSession> negotiatorFactory, final KeyMapping keys,
- final InetSocketAddress localAddress, final BigInteger dbVersion);
+ @Nonnull
+ Future<PCEPSession> createClient(@Nonnull InetSocketAddress remoteAddress,
+ long reconnectTime, @Nonnull PCEPSessionListenerFactory listenerFactory,
+ @Nonnull PCEPSessionNegotiatorFactory<? extends PCEPSession> negotiatorFactory, @Nonnull KeyMapping keys,
+ @Nonnull InetSocketAddress localAddress, @Nonnull BigInteger dbVersion);
- Future<PCEPSession> createClient(final InetSocketAddress remoteAddress,
- final long reconnectTime, final PCEPSessionListenerFactory listenerFactory,
- final PCEPSessionNegotiatorFactory<? extends PCEPSession> negotiatorFactory, final KeyMapping keys,
- final InetSocketAddress localAddress);
+ @Nonnull
+ Future<PCEPSession> createClient(@Nonnull InetSocketAddress remoteAddress,
+ long reconnectTime, @Nonnull PCEPSessionListenerFactory listenerFactory,
+ @Nonnull PCEPSessionNegotiatorFactory<? extends PCEPSession> negotiatorFactory, @Nonnull KeyMapping keys,
+ @Nonnull InetSocketAddress localAddress);
}
import java.net.InetSocketAddress;
import java.util.concurrent.ExecutionException;
import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
import org.opendaylight.protocol.concepts.KeyMapping;
import org.opendaylight.protocol.pcep.PCEPPeerProposal;
import org.opendaylight.protocol.pcep.PCEPSession;
}
@Override
- public Future<PCEPSession> createClient(
- @Nonnull final InetSocketAddress remoteAddress,
- final long reconnectTime,
- @Nonnull final PCEPSessionListenerFactory listenerFactory,
- @Nonnull final PCEPSessionNegotiatorFactory<? extends PCEPSession> negotiatorFactory,
- @Nullable final KeyMapping keys,
- @Nonnull final InetSocketAddress localAddress) {
- return createClient(remoteAddress, reconnectTime, listenerFactory, negotiatorFactory, keys,
- localAddress, BigInteger.ONE);
+ public Future<PCEPSession> createClient(final InetSocketAddress remoteAddress, final long reconnectTime,
+ final PCEPSessionListenerFactory listenerFactory,
+ final PCEPSessionNegotiatorFactory<? extends PCEPSession> negotiatorFactory, final KeyMapping keys,
+ final InetSocketAddress localAddress) {
+ return createClient(remoteAddress, reconnectTime, listenerFactory, negotiatorFactory, keys, localAddress,
+ BigInteger.ONE);
}
@Override
- public Future<PCEPSession> createClient(
- @Nonnull final InetSocketAddress remoteAddress,
- final long reconnectTime,
- @Nonnull final PCEPSessionListenerFactory listenerFactory,
- @Nonnull final PCEPSessionNegotiatorFactory negotiatorFactory,
- @Nullable final KeyMapping keys,
- @Nonnull final InetSocketAddress localAddress,
- @Nonnull final BigInteger dbVersion) {
+ @SuppressWarnings("unchecked")
+ public Future<PCEPSession> createClient(final InetSocketAddress remoteAddress, final long reconnectTime,
+ final PCEPSessionListenerFactory listenerFactory, final PCEPSessionNegotiatorFactory negotiatorFactory,
+ final KeyMapping keys, final InetSocketAddress localAddress, final BigInteger dbVersion) {
final Bootstrap b = new Bootstrap();
b.group(this.workerGroup);
b.localAddress(localAddress);
address = new InetSocketAddress(InetAddress.getByName(ip[0]), Integer.parseInt(ip[1]));
i++;
} else if (args[i].equalsIgnoreCase("-d") || args[i].equalsIgnoreCase("--deadtimer")) {
- deadTimerValue = Integer.valueOf(args[i + 1]);
+ deadTimerValue = Integer.parseInt(args[i + 1]);
i++;
} else if (args[i].equalsIgnoreCase("-ka") || args[i].equalsIgnoreCase("--keepalive")) {
- keepAliveValue = Integer.valueOf(args[i + 1]);
+ keepAliveValue = Integer.parseInt(args[i + 1]);
i++;
} else if (args[i].equalsIgnoreCase("--stateful")) {
stateful = true;