package org.opendaylight.protocol.pcep;
import io.netty.channel.ChannelFuture;
-import java.net.InetSocketAddress;
-import org.opendaylight.protocol.concepts.KeyMapping;
+import javax.annotation.Nonnull;
/**
* Dispatcher class for creating servers and clients.
/**
* Creates server. Each server needs three factories to pass their instances to client sessions.
*
- * @param address to be bound with the server
- * @param listenerFactory to create listeners for clients
- * @param peerProposal information used in our Open message
+ * @param dispatcherDependencies contains required dependencies for instantiate a PCEP Server
* @return instance of PCEPServer
*/
- ChannelFuture createServer(InetSocketAddress address, PCEPSessionListenerFactory listenerFactory,
- PCEPPeerProposal peerProposal);
-
- /**
- * Creates server. Each server needs three factories to pass their instances to client sessions.
- *
- * @param address to be bound with the server
- * @param keys RFC2385 key mapping
- * @param listenerFactory to create listeners for clients
- * @param peerProposal information used in our Open message
- * @return instance of PCEPServer
- */
- ChannelFuture createServer(InetSocketAddress address, KeyMapping keys, PCEPSessionListenerFactory listenerFactory,
- PCEPPeerProposal peerProposal);
+ @Nonnull
+ ChannelFuture createServer(@Nonnull PCEPDispatcherDependencies dispatcherDependencies);
+ @Nonnull
PCEPSessionNegotiatorFactory<?> getPCEPSessionNegotiatorFactory();
}
--- /dev/null
+/*
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.pcep;
+
+import java.net.InetSocketAddress;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import org.opendaylight.protocol.concepts.KeyMapping;
+
+/**
+ * Contains all required dependencies for instantiate a PCEPDispatcher.
+ */
+public interface PCEPDispatcherDependencies extends PCEPSessionNegotiatorFactoryDependencies {
+ /**
+ * Return the address to be bound with the server.
+ *
+ * @return ip address
+ */
+ @Nonnull
+ InetSocketAddress getAddress();
+
+ /**
+ * RFC2385 key mapping.
+ *
+ * @return map containing Keys
+ */
+ @Nonnull
+ KeyMapping getKeys();
+}
package org.opendaylight.protocol.pcep;
import java.net.InetSocketAddress;
+import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
/**
/**
* Sets specific TLVs into incoming builder
*
- * @param address
- * @param openBuilder
+ * @param address of the pcep speaker to be assigned given tlvs
+ * @param tlvs builder, to attach tl's with more information to be sent under Open message
*/
- void setPeerSpecificProposal(InetSocketAddress address, TlvsBuilder openBuilder);
-
+ void setPeerSpecificProposal(@Nonnull InetSocketAddress address, @Nonnull TlvsBuilder tlvs);
}
import io.netty.channel.Channel;
import io.netty.util.concurrent.Promise;
+import javax.annotation.Nonnull;
/**
- * Factory for creating PCEP session negotiator
+ * Factory for creating PCEP session negotiator.
*
* @param <S>
*/
public interface PCEPSessionNegotiatorFactory<S extends PCEPSession> {
/**
- * Creates PCEPSessionNegotiator instance for income attributes
+ * Creates PCEPSessionNegotiator instance for income attributes.
*
- * @param sessionListenerFactory
- * @param channel
- * @param promise
- * @param peerProposal for including information from peer to our Open message
+ * @param sessionNegotiatorDependencies contains PCEPSessionNegotiator dependencies
+ * @param channel session channel
+ * @param promise session promise
* @return PCEPSessionNegotiator instance
*/
- SessionNegotiator getSessionNegotiator(PCEPSessionListenerFactory sessionListenerFactory, Channel channel, Promise<S> promise, final PCEPPeerProposal peerProposal);
+ @Nonnull
+ SessionNegotiator getSessionNegotiator(
+ @Nonnull PCEPSessionNegotiatorFactoryDependencies sessionNegotiatorDependencies,
+ @Nonnull Channel channel,
+ @Nonnull Promise<S> promise);
+ /**
+ * Returns a PCEPSessionProposalFactory
+ *
+ * @return session factory
+ */
+ @Nonnull
PCEPSessionProposalFactory getPCEPSessionProposalFactory();
}
--- /dev/null
+/*
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.pcep;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+/**
+ * Contains required dependencies for create SessionNegotiator
+ */
+public interface PCEPSessionNegotiatorFactoryDependencies {
+ /**
+ * ListenerFactory to create listeners for clients.
+ *
+ * @return ListenerFactory
+ */
+ @Nonnull
+ PCEPSessionListenerFactory getListenerFactory();
+
+ /**
+ * Returns a non mandatory PeerProposal information used in our Open message.
+ *
+ * @return by default null or peerProposal if implemented.
+ */
+ @Nullable
+ default PCEPPeerProposal getPeerProposal() {
+ return null;
+ }
+}
import java.net.InetSocketAddress;
import java.util.List;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
/**
*/
public interface PCEPSessionProposalFactory {
/**
- *
- * @param address serves as constraint, so that factory is able to return different proposals for different
- * addresses
- * @param sessionId is used for creation of PCEPOpenObject
+ * @param address serves as constraint, so that factory is able to return different proposals for different
+ * addresses
+ * @param sessionId is used for creation of PCEPOpenObject
* @param peerProposal for including information from peer to our Open message
* @return specific session proposal
*/
- Open getSessionProposal(InetSocketAddress address, int sessionId, PCEPPeerProposal peerProposal);
+ @Nonnull
+ Open getSessionProposal(@Nonnull InetSocketAddress address, int sessionId, @Nullable PCEPPeerProposal peerProposal);
+ /**
+ * Returns list containing PCEP Capabilities
+ *
+ * @return PCEPCapabilities
+ */
+ @Nonnull
List<PCEPCapability> getCapabilities();
}
*/
package org.opendaylight.protocol.pcep;
+import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.pcep.session.state.LocalPref;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.pcep.session.state.Messages;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.pcep.session.state.PeerPref;
/**
- * Exposes Session state
+ * Exposes Session state.
*/
public interface PCEPSessionState {
/**
* The statistics of PCEP received/sent messages from the PCE point of view.
*
- * @return <code>org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.stats.rev171113.pcep.session.state.Messages</code> <code>messages</code>, or <code>null</code> if not present
+ * @return messages
*/
- Messages getMessages();
+ @Nonnull Messages getMessages();
/**
* The local (PCE) preferences.
*
- * @return <code>org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.stats.rev171113.pcep.session.state.LocalPref</code> <code>localPref</code>, or <code>null</code> if not present
+ * @return local preferences
*/
- LocalPref getLocalPref();
+ @Nonnull LocalPref getLocalPref();
/**
* The remote peer (PCC) preferences.
*
- * @return <code>org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.stats.rev171113.pcep.session.state.PeerPref</code> <code>peerPref</code>, or <code>null</code> if not present
+ * @return peer preferences
*/
- PeerPref getPeerPref();
+ @Nonnull PeerPref getPeerPref();
}
import io.netty.channel.Channel;
import io.netty.util.concurrent.Promise;
+import javax.annotation.Nonnull;
import org.opendaylight.protocol.pcep.PCEPPeerProposal;
import org.opendaylight.protocol.pcep.PCEPSessionListener;
-import org.opendaylight.protocol.pcep.PCEPSessionListenerFactory;
import org.opendaylight.protocol.pcep.PCEPSessionNegotiatorFactory;
+import org.opendaylight.protocol.pcep.PCEPSessionNegotiatorFactoryDependencies;
import org.opendaylight.protocol.pcep.SessionNegotiator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Create a new negotiator. This method needs to be implemented by subclasses to actually provide a negotiator.
*
- * @param promise Session promise to be completed by the negotiator
- * @param listener PCEPSessionListener
- * @param channel Associated channel
+ * @param promise Session promise to be completed by the negotiator
+ * @param channel Associated channel
* @param sessionId Session ID assigned to the resulting session
* @return a PCEP session negotiator
*/
- protected abstract AbstractPCEPSessionNegotiator createNegotiator(Promise<PCEPSessionImpl> promise, PCEPSessionListener listener,
- Channel channel, short sessionId, final PCEPPeerProposal peerProposal);
+ protected abstract AbstractPCEPSessionNegotiator createNegotiator(
+ @Nonnull PCEPSessionNegotiatorFactoryDependencies sessionNegotiatorDependencies,
+ Promise<PCEPSessionImpl> promise,
+ Channel channel, short sessionId);
@Override
- public final SessionNegotiator getSessionNegotiator(final PCEPSessionListenerFactory factory,
- final Channel channel, final Promise<PCEPSessionImpl> promise, final PCEPPeerProposal peerProposal) {
+ public final SessionNegotiator getSessionNegotiator(final PCEPSessionNegotiatorFactoryDependencies dependencies,
+ final Channel channel, final Promise<PCEPSessionImpl> promise) {
LOG.debug("Instantiating bootstrap negotiator for channel {}", channel);
- return new PCEPSessionNegotiator(channel, promise, factory, this, peerProposal);
+ return new PCEPSessionNegotiator(channel, promise, dependencies, this);
}
public PCEPPeerRegistry getSessionRegistry() {
*/
package org.opendaylight.protocol.pcep.impl;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.base.Preconditions;
import java.net.InetSocketAddress;
import java.util.List;
this.deadTimer = deadTimer;
this.keepAlive = keepAlive;
- this.capabilities = capabilities;
+ this.capabilities = requireNonNull(capabilities);
}
private void addTlvs(final InetSocketAddress address, final TlvsBuilder builder) {
private final int maxUnknownMessages;
public DefaultPCEPSessionNegotiator(final Promise<PCEPSessionImpl> promise, final Channel channel,
- final PCEPSessionListener listener, final short sessionId, final int maxUnknownMessages, final Open localPrefs, final Tls tlsConfiguration) {
+ final PCEPSessionListener listener, final short sessionId, final int maxUnknownMessages,
+ final Open localPrefs, final Tls tlsConfiguration) {
super(promise, channel);
super.setTlsConfiguration(tlsConfiguration);
this.maxUnknownMessages = maxUnknownMessages;
- this.myLocalPrefs = new OpenBuilder().setKeepalive(localPrefs.getKeepalive()).setDeadTimer(localPrefs.getDeadTimer()).setSessionId(
+ this.myLocalPrefs = new OpenBuilder().setKeepalive(localPrefs.getKeepalive())
+ .setDeadTimer(localPrefs.getDeadTimer()).setSessionId(
sessionId).setTlvs(localPrefs.getTlvs()).build();
this.listener = requireNonNull(listener);
}
import io.netty.channel.Channel;
import io.netty.util.concurrent.Promise;
import java.net.InetSocketAddress;
+import javax.annotation.Nonnull;
import org.opendaylight.protocol.pcep.PCEPPeerProposal;
import org.opendaylight.protocol.pcep.PCEPSessionListener;
+import org.opendaylight.protocol.pcep.PCEPSessionNegotiatorFactoryDependencies;
import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.app.config.rev160707.PcepDispatcherConfig;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.app.config.rev160707.pcep.dispatcher.config.Tls;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
public final class DefaultPCEPSessionNegotiatorFactory extends AbstractPCEPSessionNegotiatorFactory {
private final PCEPSessionProposalFactory spf;
this(spf, maxUnknownMessages, null);
}
- public DefaultPCEPSessionNegotiatorFactory(final PCEPSessionProposalFactory spf, final int maxUnknownMessages, final Tls tlsConfiguration) {
+ private DefaultPCEPSessionNegotiatorFactory(final PCEPSessionProposalFactory spf, final int maxUnknownMessages,
+ final Tls tlsConfiguration) {
this.spf = requireNonNull(spf);
this.maxUnknownMessages = maxUnknownMessages;
this.tlsConfiguration = tlsConfiguration;
}
@Override
- protected AbstractPCEPSessionNegotiator createNegotiator(final Promise<PCEPSessionImpl> promise, final PCEPSessionListener listener,
- final Channel channel, final short sessionId, final PCEPPeerProposal peerProposal) {
- return new DefaultPCEPSessionNegotiator(promise, channel, listener, sessionId, this.maxUnknownMessages,
- this.spf.getSessionProposal((InetSocketAddress)channel.remoteAddress(), sessionId, peerProposal), this.tlsConfiguration);
+ protected AbstractPCEPSessionNegotiator createNegotiator(
+ final PCEPSessionNegotiatorFactoryDependencies sessionNegotiatorDependencies,
+ final Promise<PCEPSessionImpl> promise,
+ final Channel channel,
+ final short sessionId) {
+
+ final Open proposal = this.spf.getSessionProposal((InetSocketAddress) channel.remoteAddress(), sessionId,
+ sessionNegotiatorDependencies.getPeerProposal());
+ return new DefaultPCEPSessionNegotiator(
+ promise,
+ channel,
+ sessionNegotiatorDependencies.getListenerFactory().getSessionListener(),
+ sessionId,
+ this.maxUnknownMessages,
+ proposal,
+ this.tlsConfiguration);
}
@Override
import javax.annotation.concurrent.GuardedBy;
import org.opendaylight.protocol.concepts.KeyMapping;
import org.opendaylight.protocol.pcep.PCEPDispatcher;
-import org.opendaylight.protocol.pcep.PCEPPeerProposal;
-import org.opendaylight.protocol.pcep.PCEPSessionListenerFactory;
+import org.opendaylight.protocol.pcep.PCEPDispatcherDependencies;
import org.opendaylight.protocol.pcep.PCEPSessionNegotiatorFactory;
import org.opendaylight.protocol.pcep.spi.MessageRegistry;
import org.slf4j.Logger;
private static final Logger LOG = LoggerFactory.getLogger(PCEPDispatcherImpl.class);
private static final Integer SOCKET_BACKLOG_SIZE = 128;
private static final long TIMEOUT = 10;
- private final PCEPSessionNegotiatorFactory snf;
+ private final PCEPSessionNegotiatorFactory<PCEPSessionImpl> snf;
private final PCEPHandlerFactory hf;
private final EventLoopGroup bossGroup;
private final EventLoopGroup workerGroup;
* @param workerGroup handles the traffic of accepted connection
*/
public PCEPDispatcherImpl(@Nonnull final MessageRegistry registry,
- @Nonnull final PCEPSessionNegotiatorFactory negotiatorFactory,
+ @Nonnull final PCEPSessionNegotiatorFactory<PCEPSessionImpl> negotiatorFactory,
@Nonnull final EventLoopGroup bossGroup, @Nonnull final EventLoopGroup workerGroup) {
this.snf = requireNonNull(negotiatorFactory);
this.hf = new PCEPHandlerFactory(registry);
}
@Override
- public final synchronized ChannelFuture createServer(final InetSocketAddress address,
- final PCEPSessionListenerFactory listenerFactory, final PCEPPeerProposal peerProposal) {
- return createServer(address, KeyMapping.getKeyMapping(), listenerFactory, peerProposal);
- }
-
- @Override
- public final synchronized ChannelFuture createServer(final InetSocketAddress address, final KeyMapping keys,
- final PCEPSessionListenerFactory listenerFactory, final PCEPPeerProposal peerProposal) {
- this.keys = keys;
+ public final synchronized ChannelFuture createServer(final PCEPDispatcherDependencies dispatcherDependencies) {
+ this.keys = dispatcherDependencies.getKeys();
- final ChannelPipelineInitializer initializer = (ch, promise) -> {
+ @SuppressWarnings("unchecked") final ChannelPipelineInitializer initializer = (ch, promise) -> {
ch.pipeline().addLast(this.hf.getDecoders());
- ch.pipeline().addLast("negotiator", this.snf.getSessionNegotiator(listenerFactory, ch, promise, peerProposal));
+ ch.pipeline().addLast("negotiator", this.snf
+ .getSessionNegotiator(dispatcherDependencies, ch, promise));
ch.pipeline().addLast(this.hf.getEncoders());
};
final ServerBootstrap b = createServerBootstrap(initializer);
+ final InetSocketAddress address = dispatcherDependencies.getAddress();
final ChannelFuture f = b.bind(address);
LOG.debug("Initiated server {} at {}.", f, address);
}
@Override
- public final PCEPSessionNegotiatorFactory<?> getPCEPSessionNegotiatorFactory() {
+ public final PCEPSessionNegotiatorFactory<PCEPSessionImpl> getPCEPSessionNegotiatorFactory() {
return this.snf;
}
package org.opendaylight.protocol.pcep.impl;
-import com.google.common.base.Optional;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
+import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import javax.annotation.concurrent.GuardedBy;
if (sessionReference != null) {
return Optional.of(sessionReference);
}
- return Optional.absent();
+ return Optional.empty();
}
protected synchronized Optional<SessionReference> removeSessionReference(final byte[] clientAddress) {
if (sessionReference != null) {
return Optional.of(sessionReference);
}
- return Optional.absent();
+ return Optional.empty();
}
protected synchronized void putSessionReference(final byte[] clientAddress, final SessionReference sessionReference) {
*/
package org.opendaylight.protocol.pcep.impl;
-import com.google.common.base.Optional;
import com.google.common.primitives.UnsignedBytes;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFutureListener;
import io.netty.util.concurrent.Promise;
import java.net.InetSocketAddress;
import java.util.Comparator;
+import java.util.Optional;
import java.util.concurrent.ExecutionException;
-import org.opendaylight.protocol.pcep.PCEPPeerProposal;
-import org.opendaylight.protocol.pcep.PCEPSessionListenerFactory;
+import org.opendaylight.protocol.pcep.PCEPSessionNegotiatorFactoryDependencies;
import org.opendaylight.protocol.pcep.impl.PCEPPeerRegistry.SessionReference;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
import org.slf4j.Logger;
private static final Logger LOG = LoggerFactory.getLogger(PCEPSessionNegotiator.class);
private static final Comparator<byte[]> COMPARATOR = UnsignedBytes.lexicographicalComparator();
-
- private final PCEPSessionListenerFactory factory;
-
private final AbstractPCEPSessionNegotiatorFactory negFactory;
- private final PCEPPeerProposal peerProposal;
+ private final PCEPSessionNegotiatorFactoryDependencies nfd;
public PCEPSessionNegotiator(final Channel channel, final Promise<PCEPSessionImpl> promise,
- final PCEPSessionListenerFactory factory,
- final AbstractPCEPSessionNegotiatorFactory negFactory, final PCEPPeerProposal peerProposal) {
+ final PCEPSessionNegotiatorFactoryDependencies dependencies,
+ final AbstractPCEPSessionNegotiatorFactory negFactory) {
super(promise, channel);
- this.factory = factory;
+ this.nfd = dependencies;
this.negFactory = negFactory;
- this.peerProposal = peerProposal;
}
@Override
final Short sessionId = sessionReg.nextSession(clientAddress);
final AbstractPCEPSessionNegotiator n = this.negFactory
- .createNegotiator(this.promise, this.factory.getSessionListener(),
- this.channel, sessionId, this.peerProposal);
+ .createNegotiator(this.nfd, this.promise, this.channel, sessionId);
sessionReg.putSessionReference(clientAddress, new SessionReference() {
@Override
return this.msgsBuilder.build();
}
- void reset() {
- this.receivedMsgCount = 0;
- this.sentMsgCount = 0;
- this.receivedErrMsgCount = 0;
- this.sentErrMsgCount = 0;
- this.lastSentMsgTimestamp = 0;
- this.lastReceivedErrorBuilder.setErrorType((short) 0);
- this.lastReceivedErrorBuilder.setErrorValue((short) 0);
- this.lastSentErrorBuilder.setErrorType((short) 0);
- this.lastSentErrorBuilder.setErrorValue((short) 0);
- }
-
public LocalPref getLocalPref() {
return this.localPref;
}
import static java.util.Objects.requireNonNull;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
import static org.opendaylight.protocol.util.CheckUtil.waitFutureSuccess;
import io.netty.bootstrap.Bootstrap;
import org.mockito.MockitoAnnotations;
import org.opendaylight.protocol.concepts.KeyMapping;
import org.opendaylight.protocol.pcep.PCEPCapability;
+import org.opendaylight.protocol.pcep.PCEPDispatcherDependencies;
import org.opendaylight.protocol.pcep.PCEPSession;
import org.opendaylight.protocol.pcep.PCEPSessionListenerFactory;
import org.opendaylight.protocol.pcep.PCEPSessionNegotiatorFactory;
@Mock
private Channel mockChannel;
+ @Mock
+ private PCEPDispatcherDependencies dispatcherDependencies;
+ @Mock
+ private PCEPSessionListenerFactory listenerFactory;
private PCCMock pccMock;
MockitoAnnotations.initMocks(this);
final List<PCEPCapability> capList = new ArrayList<>();
final PCEPSessionProposalFactory sessionProposal = new BasePCEPSessionProposalFactory(DEAD_TIMER, KEEP_ALIVE,
- capList);
+ capList);
final EventLoopGroup eventLoopGroup;
if (Epoll.isAvailable()) {
eventLoopGroup = new EpollEventLoopGroup();
eventLoopGroup = new NioEventLoopGroup();
}
final MessageRegistry msgReg = ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance()
- .getMessageHandlerRegistry();
- this.dispatcher = new PCEPDispatcherImpl(msgReg, new DefaultPCEPSessionNegotiatorFactory(sessionProposal, 0),
- eventLoopGroup, eventLoopGroup);
+ .getMessageHandlerRegistry();
+ this.dispatcher = new PCEPDispatcherImpl(msgReg,
+ new DefaultPCEPSessionNegotiatorFactory(sessionProposal, 0),
+ eventLoopGroup, eventLoopGroup);
- Mockito.doReturn("mockChannel").when(this.mockChannel).toString();
+ doReturn(KeyMapping.getKeyMapping()).when(this.dispatcherDependencies).getKeys();
+ doReturn(null).when(this.dispatcherDependencies).getPeerProposal();
+
+ doReturn("mockChannel").when(this.mockChannel).toString();
final PCEPDispatcherImpl dispatcher2 = new PCEPDispatcherImpl(msgReg,
- new DefaultPCEPSessionNegotiatorFactory(sessionProposal, 0),
- eventLoopGroup, eventLoopGroup);
+ new DefaultPCEPSessionNegotiatorFactory(sessionProposal, 0),
+ eventLoopGroup, eventLoopGroup);
this.disp2Spy = Mockito.spy(dispatcher2);
this.pccMock = new PCCMock(new DefaultPCEPSessionNegotiatorFactory(sessionProposal, 0),
- new PCEPHandlerFactory(msgReg));
+ new PCEPHandlerFactory(msgReg));
}
@Test
final InetSocketAddress serverAddr = new InetSocketAddress("0.0.0.0", port);
final InetSocketAddress clientAddr1 = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(port);
final InetSocketAddress clientAddr2 = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(port);
- final ChannelFuture futureChannel = this.dispatcher.createServer(serverAddr,
- SimpleSessionListener::new, null);
+
+ doReturn(serverAddr).when(this.dispatcherDependencies).getAddress();
+ doReturn(this.listenerFactory).when(this.dispatcherDependencies).getListenerFactory();
+ doReturn(new SimpleSessionListener()).when(this.listenerFactory).getSessionListener();
+ final ChannelFuture futureChannel = this.dispatcher.createServer(this.dispatcherDependencies);
waitFutureSuccess(futureChannel);
- final PCEPSessionImpl session1 = (PCEPSessionImpl) this.pccMock.createClient(clientAddr1,
- RETRY_TIMER, CONNECT_TIMEOUT, SimpleSessionListener::new).get();
+ final PCEPSessionImpl session1 = this.pccMock.createClient(clientAddr1,
+ RETRY_TIMER, CONNECT_TIMEOUT, SimpleSessionListener::new).get();
- final PCEPSessionImpl session2 = (PCEPSessionImpl) this.pccMock.createClient(clientAddr2,
- RETRY_TIMER, CONNECT_TIMEOUT, SimpleSessionListener::new).get();
+ final PCEPSessionImpl session2 = this.pccMock.createClient(clientAddr2,
+ RETRY_TIMER, CONNECT_TIMEOUT, SimpleSessionListener::new).get();
Assert.assertTrue(futureChannel.channel().isActive());
assertEquals(clientAddr1.getAddress().getHostAddress(), session1.getPeerPref().getIpAddress());
final int port = InetSocketAddressUtil.getRandomPort();
final InetSocketAddress serverAddr = new InetSocketAddress("0.0.0.0", port);
final InetSocketAddress clientAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(port);
- waitFutureSuccess(this.dispatcher.createServer(serverAddr, SimpleSessionListener::new, null));
- final Future<PCEPSession> futureClient = this.pccMock.createClient(clientAddr, RETRY_TIMER, CONNECT_TIMEOUT,
- SimpleSessionListener::new);
+
+ doReturn(serverAddr).when(this.dispatcherDependencies).getAddress();
+ doReturn(this.listenerFactory).when(this.dispatcherDependencies).getListenerFactory();
+ doReturn(new SimpleSessionListener()).when(this.listenerFactory).getSessionListener();
+
+ waitFutureSuccess(this.dispatcher.createServer(this.dispatcherDependencies));
+ final Future<PCEPSessionImpl> futureClient = this.pccMock.createClient(clientAddr, RETRY_TIMER, CONNECT_TIMEOUT,
+ SimpleSessionListener::new);
waitFutureSuccess(futureClient);
- final PCEPSessionImpl session1 = (PCEPSessionImpl) futureClient.get();
+ final PCEPSessionImpl session1 = futureClient.get();
try {
this.pccMock.createClient(clientAddr, RETRY_TIMER, CONNECT_TIMEOUT,
- SimpleSessionListener::new).get();
+ SimpleSessionListener::new).get();
Assert.fail();
} catch (final ExecutionException e) {
Assert.assertTrue(e.getMessage().contains("A conflicting session for address"));
public void testReconectClient() throws InterruptedException, ExecutionException {
final int port = InetSocketAddressUtil.getRandomPort();
final InetSocketAddress clientAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(port);
- waitFutureSuccess(this.dispatcher.createServer(new InetSocketAddress("0.0.0.0", port),
- SimpleSessionListener::new, null));
- final PCEPSessionImpl session1 = (PCEPSessionImpl) this.pccMock.createClient(clientAddr,
- RETRY_TIMER, CONNECT_TIMEOUT, SimpleSessionListener::new).get();
+
+ doReturn(new InetSocketAddress("0.0.0.0", port)).when(this.dispatcherDependencies).getAddress();
+ doReturn(this.listenerFactory).when(this.dispatcherDependencies).getListenerFactory();
+ doReturn(new SimpleSessionListener()).when(this.listenerFactory).getSessionListener();
+ waitFutureSuccess(this.dispatcher.createServer(this.dispatcherDependencies));
+ final PCEPSessionImpl session1 = this.pccMock.createClient(clientAddr,
+ RETRY_TIMER, CONNECT_TIMEOUT, SimpleSessionListener::new).get();
assertEquals(clientAddr.getAddress(), session1.getRemoteAddress());
assertEquals(DEAD_TIMER, session1.getDeadTimerValue().shortValue());
assertEquals(KEEP_ALIVE, session1.getKeepAliveTimerValue().shortValue());
waitFutureSuccess(session1.closeChannel());
- final PCEPSessionImpl session2 = (PCEPSessionImpl) this.pccMock.createClient(clientAddr,
- RETRY_TIMER, CONNECT_TIMEOUT, SimpleSessionListener::new).get();
+ final PCEPSessionImpl session2 = this.pccMock.createClient(clientAddr,
+ RETRY_TIMER, CONNECT_TIMEOUT, SimpleSessionListener::new).get();
assertEquals(clientAddr.getAddress(), session1.getRemoteAddress());
assertEquals(DEAD_TIMER, session2.getDeadTimerValue().shortValue());
final KeyMapping keys = KeyMapping.getKeyMapping(clientAddr1.getAddress(), "CLIENT1_ADDRESS");
keys.put(clientAddr2.getAddress(), "CLIENT2_ADDRESS".getBytes());
- final ChannelFuture futureChannel = this.disp2Spy.createServer(new InetSocketAddress("0.0.0.0", port),
- SimpleSessionListener::new, null);
+ doReturn(new InetSocketAddress("0.0.0.0", port)).when(this.dispatcherDependencies).getAddress();
+ doReturn(this.listenerFactory).when(this.dispatcherDependencies).getListenerFactory();
+ doReturn(new SimpleSessionListener()).when(this.listenerFactory).getSessionListener();
+
+ final ChannelFuture futureChannel = this.disp2Spy.createServer(this.dispatcherDependencies);
waitFutureSuccess(futureChannel);
Mockito.verify(this.disp2Spy).createServerBootstrap(any(PCEPDispatcherImpl.ChannelPipelineInitializer.class));
}
}
private static class PCCMock {
- private final PCEPSessionNegotiatorFactory negotiatorFactory;
+ private final PCEPSessionNegotiatorFactory<PCEPSessionImpl> negotiatorFactory;
private final PCEPHandlerFactory factory;
private final EventExecutor executor;
private final EventLoopGroup workerGroup;
- PCCMock(final PCEPSessionNegotiatorFactory<?> negotiatorFactory, final PCEPHandlerFactory factory) {
- this.workerGroup = requireNonNull(new NioEventLoopGroup());
+ PCCMock(final PCEPSessionNegotiatorFactory<PCEPSessionImpl> negotiatorFactory,
+ final PCEPHandlerFactory factory) {
+ this.workerGroup = new NioEventLoopGroup();
this.negotiatorFactory = requireNonNull(negotiatorFactory);
this.factory = requireNonNull(factory);
this.executor = requireNonNull(GlobalEventExecutor.INSTANCE);
}
- Future<PCEPSession> createClient(final InetSocketAddress address, final int retryTimer,
- final int connectTimeout, final PCEPSessionListenerFactory listenerFactory) {
+ Future<PCEPSessionImpl> createClient(final InetSocketAddress address, final int retryTimer,
+ final int connectTimeout, final PCEPSessionListenerFactory listenerFactory) {
return createClient(address, retryTimer, connectTimeout, (ch, promise) -> {
ch.pipeline().addLast(this.factory.getDecoders());
- ch.pipeline().addLast("negotiator", this.negotiatorFactory.getSessionNegotiator(listenerFactory, ch,
- promise, null));
+ ch.pipeline().addLast("negotiator", this.negotiatorFactory.getSessionNegotiator(
+ () -> listenerFactory,
+ ch,
+ promise));
ch.pipeline().addLast(this.factory.getEncoders());
});
}
- Future<PCEPSession> createClient(final InetSocketAddress address, final int retryTimer,
- final int connectTimeout, final PCEPDispatcherImpl.ChannelPipelineInitializer initializer) {
+ Future<PCEPSessionImpl> createClient(final InetSocketAddress address, final int retryTimer,
+ final int connectTimeout, final PCEPDispatcherImpl.ChannelPipelineInitializer initializer) {
final Bootstrap b = new Bootstrap();
- final PCEPProtocolSessionPromise p = new PCEPProtocolSessionPromise<>(this.executor, address, retryTimer,
- connectTimeout, b);
+ final PCEPProtocolSessionPromise<PCEPSessionImpl> p = new PCEPProtocolSessionPromise<>(this.executor,
+ address, retryTimer, connectTimeout, b);
b.option(ChannelOption.SO_KEEPALIVE, Boolean.TRUE).handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(final SocketChannel ch) {
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;
import org.opendaylight.protocol.pcep.PCEPSessionListenerFactory;
import org.opendaylight.protocol.pcep.PCEPSessionNegotiatorFactory;
+import org.opendaylight.protocol.pcep.PCEPSessionNegotiatorFactoryDependencies;
import org.opendaylight.protocol.pcep.impl.PCEPHandlerFactory;
import org.opendaylight.protocol.pcep.pcc.mock.api.PCCDispatcher;
import org.opendaylight.protocol.pcep.spi.MessageRegistry;
}
@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(
+ @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);
}
@Override
- public Future<PCEPSession> createClient(@Nonnull final InetSocketAddress remoteAddress, final long reconnectTime,
- @Nonnull final PCEPSessionListenerFactory listenerFactory, @Nonnull final PCEPSessionNegotiatorFactory negotiatorFactory,
- @Nonnull final KeyMapping keys, @Nonnull final InetSocketAddress localAddress, @Nonnull final BigInteger dbVersion) {
+ 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) {
final Bootstrap b = new Bootstrap();
b.group(this.workerGroup);
b.localAddress(localAddress);
b.option(ChannelOption.SO_REUSEADDR, true);
b.option(ChannelOption.RCVBUF_ALLOCATOR, new io.netty.channel.FixedRecvByteBufAllocator(1));
final long retryTimer = reconnectTime == -1 ? 0 : reconnectTime;
- final PCCReconnectPromise promise = new PCCReconnectPromise(remoteAddress, (int) retryTimer, CONNECT_TIMEOUT, b);
+ final PCCReconnectPromise promise =
+ new PCCReconnectPromise(remoteAddress, (int) retryTimer, CONNECT_TIMEOUT, b);
final ChannelInitializer<SocketChannel> channelInitializer = new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(final SocketChannel ch) throws Exception {
ch.pipeline().addLast(PCCDispatcherImpl.this.factory.getDecoders());
- ch.pipeline().addLast("negotiator", negotiatorFactory.getSessionNegotiator(listenerFactory, ch, promise, new PCCPeerProposal(dbVersion)));
+ ch.pipeline().addLast("negotiator", negotiatorFactory.getSessionNegotiator(
+ new PCEPSessionNegotiatorFactoryDependencies() {
+ @Override
+ public PCEPSessionListenerFactory getListenerFactory() {
+ return listenerFactory;
+ }
+
+ @Override
+ public PCEPPeerProposal getPeerProposal() {
+ return new PCCPeerProposal(dbVersion);
+ }
+ }
+ , ch, promise));
ch.pipeline().addLast(PCCDispatcherImpl.this.factory.getEncoders());
ch.pipeline().addLast(new ChannelInboundHandlerAdapter() {
@Override
return;
}
LOG.debug("Reconnecting after connection to {} was dropped", remoteAddress);
- PCCDispatcherImpl.this.createClient(remoteAddress, reconnectTime, listenerFactory, negotiatorFactory,
- keys, localAddress, dbVersion);
+ PCCDispatcherImpl.this.createClient(
+ remoteAddress,
+ reconnectTime,
+ listenerFactory,
+ negotiatorFactory,
+ keys,
+ localAddress,
+ dbVersion);
}
});
}
package org.opendaylight.protocol.pcep.pcc.mock;
+import static org.mockito.Mockito.doReturn;
import static org.opendaylight.protocol.pcep.pcc.mock.PCCMockCommon.checkSessionListenerNotNull;
import static org.opendaylight.protocol.util.CheckUtil.waitFutureSuccess;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
import org.opendaylight.protocol.concepts.KeyMapping;
import org.opendaylight.protocol.pcep.PCEPCapability;
import org.opendaylight.protocol.pcep.PCEPDispatcher;
+import org.opendaylight.protocol.pcep.PCEPDispatcherDependencies;
import org.opendaylight.protocol.pcep.PCEPSession;
import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
import org.opendaylight.protocol.pcep.impl.BasePCEPSessionProposalFactory;
private EventLoopGroup workerGroup;
private EventLoopGroup bossGroup;
+ @Mock
+ PCEPDispatcherDependencies dispatcherDependencies;
+
@Before
public void setUp() {
+ MockitoAnnotations.initMocks(this);
this.workerGroup = new NioEventLoopGroup();
this.bossGroup = new NioEventLoopGroup();
this.dispatcher = new PCCDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry());
this.nf, this.bossGroup, this.workerGroup);
this.serverAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
this.clientAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(0);
+ doReturn(KeyMapping.getKeyMapping()).when(this.dispatcherDependencies).getKeys();
+ doReturn(this.serverAddress).when(this.dispatcherDependencies).getAddress();
+ doReturn(null).when(this.dispatcherDependencies).getPeerProposal();
}
@After
final Future<PCEPSession> futureSession = this.dispatcher.createClient(this.serverAddress, 1, new TestingSessionListenerFactory(),
this.nf, KeyMapping.getKeyMapping(), this.clientAddress);
final TestingSessionListenerFactory slf = new TestingSessionListenerFactory();
- final ChannelFuture futureServer = this.pcepDispatcher.createServer(this.serverAddress, slf, null);
+ doReturn(slf).when(this.dispatcherDependencies).getListenerFactory();
+
+ final ChannelFuture futureServer = this.pcepDispatcher.createServer(this.dispatcherDependencies);
waitFutureSuccess(futureServer);
final Channel channel = futureServer.channel();
Assert.assertNotNull(futureSession.get());
this.nf, this.bossGroup, this.workerGroup);
final TestingSessionListenerFactory slf2 = new TestingSessionListenerFactory();
- final ChannelFuture future2 = this.pcepDispatcher.createServer(this.serverAddress, slf2, null);
+ doReturn(slf2).when(this.dispatcherDependencies).getListenerFactory();
+ final ChannelFuture future2 = this.pcepDispatcher.createServer(this.dispatcherDependencies);
waitFutureSuccess(future2);
final Channel channel2 = future2.channel();
final TestingSessionListener sl2 = checkSessionListenerNotNull(slf2, this.clientAddress.getAddress().getHostAddress());
import org.opendaylight.protocol.concepts.KeyMapping;
import org.opendaylight.protocol.pcep.PCEPCapability;
import org.opendaylight.protocol.pcep.PCEPDispatcher;
+import org.opendaylight.protocol.pcep.PCEPDispatcherDependencies;
import org.opendaylight.protocol.pcep.PCEPPeerProposal;
import org.opendaylight.protocol.pcep.PCEPSession;
+import org.opendaylight.protocol.pcep.PCEPSessionListenerFactory;
import org.opendaylight.protocol.pcep.PCEPSessionNegotiatorFactory;
import org.opendaylight.protocol.pcep.ietf.stateful07.StatefulActivator;
import org.opendaylight.protocol.pcep.impl.BasePCEPSessionProposalFactory;
private static final short DEAD_TIMER = 120;
private static final long SLEEP_FOR = 50;
private final int port = InetSocketAddressUtil.getRandomPort();
- protected final InetSocketAddress remoteAddress = InetSocketAddressUtil
- .getRandomLoopbackInetSocketAddress(this.port);
- protected final InetSocketAddress localAddress = new InetSocketAddress("127.0.0.1", this.port);
- protected PCCSessionListener pccSessionListener;
+ final InetSocketAddress remoteAddress = InetSocketAddressUtil
+ .getRandomLoopbackInetSocketAddress(this.port);
+ final InetSocketAddress localAddress = new InetSocketAddress("127.0.0.1", this.port);
+ PCCSessionListener pccSessionListener;
private PCEPDispatcher pceDispatcher;
private PCEPExtensionProviderContext extensionProvider;
private MessageRegistry messageRegistry;
@Before
public void setUp() {
final BasePCEPSessionProposalFactory proposal = new BasePCEPSessionProposalFactory(DEAD_TIMER, KEEP_ALIVE,
- getCapabilities());
+ getCapabilities());
final DefaultPCEPSessionNegotiatorFactory nf = new DefaultPCEPSessionNegotiatorFactory(proposal, 0);
- this.extensionProvider = ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance();
+ this.extensionProvider = ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance();
this.messageRegistry = this.extensionProvider.getMessageHandlerRegistry();
this.pceDispatcher = new PCEPDispatcherImpl(this.messageRegistry, nf, new NioEventLoopGroup(),
- new NioEventLoopGroup());
+ new NioEventLoopGroup());
}
- protected static TestingSessionListener checkSessionListener(final int numMessages, final Channel channel,
- final TestingSessionListenerFactory factory,
- final String localAddress) throws
- Exception {
+ static TestingSessionListener checkSessionListener(final int numMessages, final Channel channel,
+ final TestingSessionListenerFactory factory,
+ final String localAddress) throws
+ Exception {
final TestingSessionListener sessionListener = checkSessionListenerNotNull(factory, localAddress);
assertTrue(sessionListener.isUp());
checkReceivedMessages(sessionListener, numMessages);
}
static TestingSessionListener checkSessionListenerNotNull(final TestingSessionListenerFactory factory,
- final String localAddress) {
+ final String localAddress) {
final Stopwatch sw = Stopwatch.createStarted();
TestingSessionListener listener;
final InetAddress address = InetAddresses.forString(localAddress);
throw new NullPointerException();
}
- protected Channel createServer(final TestingSessionListenerFactory factory,
- final InetSocketAddress serverAddress2) throws InterruptedException {
+ Channel createServer(final TestingSessionListenerFactory factory,
+ final InetSocketAddress serverAddress2) throws InterruptedException {
return createServer(factory, serverAddress2, null);
}
- protected Channel createServer(final TestingSessionListenerFactory factory, final InetSocketAddress
- serverAddress2, final PCEPPeerProposal peerProposal) {
+ Channel createServer(final TestingSessionListenerFactory factory, final InetSocketAddress
+ serverAddress2, final PCEPPeerProposal peerProposal) {
final StatefulActivator activator07 = new StatefulActivator();
final SyncOptimizationsActivator optimizationsActivator = new SyncOptimizationsActivator();
activator07.start(this.extensionProvider);
optimizationsActivator.start(this.extensionProvider);
- final ChannelFuture future = this.pceDispatcher.createServer(serverAddress2, factory, peerProposal);
+
+ final ChannelFuture future = this.pceDispatcher
+ .createServer(new DispatcherDependencies(serverAddress2, factory, peerProposal));
waitFutureSuccess(future);
return future.channel();
}
- protected static void checkSynchronizedSession(final int numberOfLsp,
- final TestingSessionListener pceSessionListener, final BigInteger expectedeInitialDb) throws Exception {
+ static void checkSynchronizedSession(final int numberOfLsp,
+ final TestingSessionListener pceSessionListener, final BigInteger expectedeInitialDb) throws Exception {
assertTrue(pceSessionListener.isUp());
//Send Open with LspDBV = 1
final int numberOfSyncMessage = 1;
int numberOfLspExpected = numberOfLsp;
if (!expectedeInitialDb.equals(BigInteger.ZERO)) {
- checkEquals(()-> checkSequequenceDBVersionSync(pceSessionListener, expectedeInitialDb));
+ checkEquals(() -> checkSequequenceDBVersionSync(pceSessionListener, expectedeInitialDb));
numberOfLspExpected += numberOfSyncMessage;
}
checkReceivedMessages(pceSessionListener, numberOfLspExpected);
checkSession(session, DEAD_TIMER, KEEP_ALIVE);
assertTrue(session.getRemoteTlvs().getAugmentation(Tlvs1.class).getStateful()
- .getAugmentation(Stateful1.class).isInitiation());
+ .getAugmentation(Stateful1.class).isInitiation());
assertNull(session.localSessionCharacteristics().getAugmentation(Tlvs3.class)
- .getLspDbVersion().getLspDbVersionValue());
+ .getLspDbVersion().getLspDbVersionValue());
}
- protected static void checkResyncSession(final Optional<Integer> startAtNumberLsp, final int expectedNumberOfLsp,
- final int expectedTotalMessages, final BigInteger startingDBVersion, final BigInteger expectedDBVersion,
- final TestingSessionListener pceSessionListener) throws Exception {
+ static void checkResyncSession(final Optional<Integer> startAtNumberLsp, final int expectedNumberOfLsp,
+ final int expectedTotalMessages, final BigInteger startingDBVersion, final BigInteger expectedDBVersion,
+ final TestingSessionListener pceSessionListener) throws Exception {
assertNotNull(pceSessionListener.getSession());
assertTrue(pceSessionListener.isUp());
final List<Message> messages;
checkReceivedMessages(pceSessionListener, expectedTotalMessages);
if (startAtNumberLsp.isPresent()) {
messages = pceSessionListener.messages().subList(startAtNumberLsp.get(),
- startAtNumberLsp.get() + expectedNumberOfLsp);
+ startAtNumberLsp.get() + expectedNumberOfLsp);
} else {
messages = pceSessionListener.messages();
}
- checkEquals(()-> checkSequequenceDBVersionSync(pceSessionListener, expectedDBVersion));
+ checkEquals(() -> checkSequequenceDBVersionSync(pceSessionListener, expectedDBVersion));
assertEquals(expectedNumberOfLsp, messages.size());
final PCEPSession session = pceSessionListener.getSession();
checkSession(session, DEAD_TIMER, KEEP_ALIVE);
assertTrue(session.getRemoteTlvs().getAugmentation(Tlvs1.class).getStateful()
- .getAugmentation(Stateful1.class).isInitiation());
+ .getAugmentation(Stateful1.class).isInitiation());
final BigInteger pceDBVersion = session.localSessionCharacteristics().getAugmentation(Tlvs3.class)
- .getLspDbVersion().getLspDbVersionValue();
+ .getLspDbVersion().getLspDbVersionValue();
assertEquals(startingDBVersion, pceDBVersion);
}
- protected static void checkSession(final PCEPSession session, final int expectedDeadTimer,
- final int expectedKeepAlive) {
+ static void checkSession(final PCEPSession session, final int expectedDeadTimer,
+ final int expectedKeepAlive) {
assertNotNull(session);
assertEquals(expectedDeadTimer, session.getPeerPref().getDeadtimer().shortValue());
assertEquals(expectedKeepAlive, session.getPeerPref().getKeepalive().shortValue());
final Stateful1 stateful = session.getRemoteTlvs().getAugmentation(Tlvs1.class)
- .getStateful().getAugmentation(Stateful1.class);
+ .getStateful().getAugmentation(Stateful1.class);
assertTrue(stateful.isInitiation());
}
protected static void checkSequequenceDBVersionSync(final TestingSessionListener pceSessionListener,
- final BigInteger expectedDbVersion) {
+ final BigInteger expectedDbVersion) {
for (final Message msg : pceSessionListener.messages()) {
final List<Reports> pcrt = ((Pcrpt) msg).getPcrptMessage().getReports();
for (final Reports report : pcrt) {
assertEquals(true, lsp.isSync());
}
final BigInteger actuaLspDBVersion = lsp.getTlvs().getAugmentation(org.opendaylight.yang.gen
- .v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev171025.Tlvs1.class)
- .getLspDbVersion().getLspDbVersionValue();
+ .v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev171025.Tlvs1.class)
+ .getLspDbVersion().getLspDbVersionValue();
assertEquals(expectedDbVersion, actuaLspDBVersion);
}
}
}
- protected Future<PCEPSession> createPCCSession(final BigInteger dbVersion) {
+ Future<PCEPSession> createPCCSession(final BigInteger dbVersion) {
final PCCDispatcherImpl pccDispatcher = new PCCDispatcherImpl(this.messageRegistry);
final PCEPSessionNegotiatorFactory<PCEPSessionImpl> snf = getSessionNegotiatorFactory();
final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(3, this.localAddress.getAddress(),
- 0, -1, new HashedWheelTimer(), Optional.absent());
+ 0, -1, new HashedWheelTimer(), Optional.absent());
return pccDispatcher.createClient(this.remoteAddress, -1,
- () -> {
- this.pccSessionListener = new PCCSessionListener(1, tunnelManager, false);
- return this.pccSessionListener;
- }, snf, KeyMapping.getKeyMapping(), this.localAddress, dbVersion);
+ () -> {
+ this.pccSessionListener = new PCCSessionListener(1, tunnelManager, false);
+ return this.pccSessionListener;
+ }, snf, KeyMapping.getKeyMapping(), this.localAddress, dbVersion);
}
private PCEPSessionNegotiatorFactory<PCEPSessionImpl> getSessionNegotiatorFactory() {
return new DefaultPCEPSessionNegotiatorFactory(new BasePCEPSessionProposalFactory(DEAD_TIMER, KEEP_ALIVE,
- getCapabilities()), 0);
+ getCapabilities()), 0);
}
- protected TestingSessionListener getListener(final TestingSessionListenerFactory factory) {
+ TestingSessionListener getListener(final TestingSessionListenerFactory factory) {
return checkSessionListenerNotNull(factory, this.localAddress.getHostString());
}
+
+ private class DispatcherDependencies implements PCEPDispatcherDependencies {
+ final KeyMapping keys = KeyMapping.getKeyMapping();
+ private final InetSocketAddress address;
+ private final TestingSessionListenerFactory listenerFactory;
+ private final PCEPPeerProposal peerProposal;
+
+ DispatcherDependencies(
+ final InetSocketAddress address,
+ final TestingSessionListenerFactory listenerFactory,
+ final PCEPPeerProposal peerProposal) {
+ this.address = address;
+ this.listenerFactory = listenerFactory;
+ this.peerProposal = peerProposal;
+ }
+
+ @Override
+ public InetSocketAddress getAddress() {
+ return this.address;
+ }
+
+ @Override
+ public KeyMapping getKeys() {
+ return keys;
+ }
+
+ @Override
+ public PCEPSessionListenerFactory getListenerFactory() {
+ return this.listenerFactory;
+ }
+
+ @Override
+ public PCEPPeerProposal getPeerProposal() {
+ return this.peerProposal;
+ }
+ }
}
import java.util.List;
import java.util.concurrent.ExecutionException;
import org.opendaylight.protocol.pcep.PCEPCapability;
+import org.opendaylight.protocol.pcep.PCEPDispatcherDependencies;
import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
import org.opendaylight.protocol.pcep.ietf.stateful07.PCEPStatefulCapability;
import org.opendaylight.protocol.pcep.ietf.stateful07.StatefulActivator;
try (final StatefulActivator activator07 = new StatefulActivator()) {
activator07.start(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance());
- final PCEPDispatcherImpl dispatcher = new PCEPDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry(), new DefaultPCEPSessionNegotiatorFactory(spf, MAX_UNKNOWN_MESSAGES), new NioEventLoopGroup(), new NioEventLoopGroup());
- dispatcher.createServer(address, new TestingSessionListenerFactory(), null).get();
+ final PCEPDispatcherImpl dispatcher = new PCEPDispatcherImpl(
+ ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry(),
+ new DefaultPCEPSessionNegotiatorFactory(spf, MAX_UNKNOWN_MESSAGES),
+ new NioEventLoopGroup(), new NioEventLoopGroup());
+ dispatcher.createServer(new TestToolPCEPDispatcherDependencies(address)).get();
}
}
}
--- /dev/null
+/*
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.pcep.testtool;
+
+import java.net.InetSocketAddress;
+import javax.annotation.Nonnull;
+import org.opendaylight.protocol.concepts.KeyMapping;
+import org.opendaylight.protocol.pcep.PCEPDispatcherDependencies;
+import org.opendaylight.protocol.pcep.PCEPSessionListenerFactory;
+
+public final class TestToolPCEPDispatcherDependencies implements PCEPDispatcherDependencies {
+ private final PCEPSessionListenerFactory listenerFactory = new TestingSessionListenerFactory();
+ private final InetSocketAddress address;
+ private final KeyMapping keys = KeyMapping.getKeyMapping();
+
+ TestToolPCEPDispatcherDependencies(@Nonnull final InetSocketAddress address) {
+ this.address = address;
+ }
+
+ @Override
+ public InetSocketAddress getAddress() {
+ return this.address;
+ }
+
+ @Override
+ public KeyMapping getKeys() {
+ return this.keys;
+ }
+
+ @Override
+ public PCEPSessionListenerFactory getListenerFactory() {
+ return this.listenerFactory;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.bgpcep.pcep.topology.provider;
+
+import static java.util.Objects.requireNonNull;
+
+import java.net.InetSocketAddress;
+import javax.annotation.Nonnull;
+import org.opendaylight.bgpcep.pcep.topology.provider.config.PCEPTopologyConfiguration;
+import org.opendaylight.protocol.concepts.KeyMapping;
+import org.opendaylight.protocol.pcep.PCEPDispatcherDependencies;
+import org.opendaylight.protocol.pcep.PCEPPeerProposal;
+import org.opendaylight.protocol.pcep.PCEPSessionListenerFactory;
+
+public final class PCEPDispatcherDependenciesImpl implements PCEPDispatcherDependencies {
+ private final ServerSessionManager manager;
+ private final PCEPTopologyConfiguration topologyConfigDependencies;
+
+ public PCEPDispatcherDependenciesImpl(
+ @Nonnull final ServerSessionManager manager,
+ @Nonnull final PCEPTopologyConfiguration topologyConfigDependencies
+ ) {
+ this.manager = requireNonNull(manager);
+ this.topologyConfigDependencies = requireNonNull(topologyConfigDependencies);
+ }
+
+ @Override
+ public InetSocketAddress getAddress() {
+ return this.topologyConfigDependencies.getAddress();
+ }
+
+ @Override
+ public KeyMapping getKeys() {
+ return this.topologyConfigDependencies.getKeys();
+ }
+
+ @Override
+ public PCEPSessionListenerFactory getListenerFactory() {
+ return this.manager;
+ }
+
+ @Override
+ public PCEPPeerProposal getPeerProposal() {
+ return this.manager;
+ }
+}
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
-import java.net.InetSocketAddress;
import java.util.List;
+import java.util.Optional;
import org.opendaylight.bgpcep.pcep.topology.provider.config.PCEPTopologyConfiguration;
-import org.opendaylight.bgpcep.pcep.topology.provider.config.PCEPTopologyProviderDependenciesProvider;
-import org.opendaylight.bgpcep.programming.spi.InstructionScheduler;
+import org.opendaylight.bgpcep.pcep.topology.provider.config.PCEPTopologyProviderDependencies;
import org.opendaylight.bgpcep.topology.DefaultTopologyReference;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
-import org.opendaylight.protocol.concepts.KeyMapping;
import org.opendaylight.protocol.pcep.PCEPCapability;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.topology.rev140113.NetworkTopologyContext;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev171025.NetworkTopologyPcepProgrammingService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.NetworkTopologyPcepService;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final String STATEFUL_NOT_DEFINED = "Stateful capability not defined, aborting PCEP Topology" +
" Provider instantiation";
- private final InstanceIdentifier<Topology> topology;
private final ServerSessionManager manager;
- private final InetSocketAddress address;
- private final KeyMapping keys;
- private final InstructionScheduler scheduler;
- private final PCEPTopologyProviderDependenciesProvider dependenciesProvider;
+ private final PCEPTopologyProviderDependencies dependenciesProvider;
+ private final PCEPTopologyConfiguration configDependencies;
private RoutedRpcRegistration<NetworkTopologyPcepProgrammingService> network;
private RoutedRpcRegistration<NetworkTopologyPcepService> element;
private Channel channel;
- private PCEPTopologyProvider(final InetSocketAddress address, final KeyMapping keys,
- final PCEPTopologyProviderDependenciesProvider dependenciesProvider,
- final InstanceIdentifier<Topology> topology, final ServerSessionManager manager,
- final InstructionScheduler scheduler) {
- super(topology);
+ private PCEPTopologyProvider(
+ final PCEPTopologyConfiguration configDependencies,
+ final PCEPTopologyProviderDependencies dependenciesProvider,
+ final ServerSessionManager manager) {
+ super(configDependencies.getTopology());
this.dependenciesProvider = requireNonNull(dependenciesProvider);
- this.address = address;
- this.topology = requireNonNull(topology);
- this.keys = keys;
+ this.configDependencies = configDependencies;
this.manager = requireNonNull(manager);
- this.scheduler = scheduler;
}
- public static PCEPTopologyProvider create(final PCEPTopologyProviderDependenciesProvider dependenciesProvider,
+ public static PCEPTopologyProvider create(final PCEPTopologyProviderDependencies dependenciesProvider,
final PCEPTopologyConfiguration configDependencies) {
final List<PCEPCapability> capabilities = dependenciesProvider.getPCEPDispatcher()
.getPCEPSessionNegotiatorFactory().getPCEPSessionProposalFactory().getCapabilities();
- boolean statefulCapability = false;
- for (final PCEPCapability capability : capabilities) {
- if (capability.isStateful()) {
- statefulCapability = true;
- break;
- }
- }
+ final Optional<PCEPCapability> statefulCapability = capabilities
+ .stream()
+ .filter(PCEPCapability::isStateful)
+ .findAny();
final TopologySessionListenerFactory listenerFactory = dependenciesProvider.getTopologySessionListenerFactory();
- if (!statefulCapability && listenerFactory != null) {
+ if (!statefulCapability.isPresent()) {
throw new IllegalStateException(STATEFUL_NOT_DEFINED);
}
- final InstanceIdentifier<Topology> topology = InstanceIdentifier.builder(NetworkTopology.class)
- .child(Topology.class, new TopologyKey(configDependencies.getTopologyId())).build();
- final ServerSessionManager manager = new ServerSessionManager(
- dependenciesProvider.getDataBroker(),
- topology,
- listenerFactory,
- dependenciesProvider.getStateRegistry(),
- configDependencies.getRpcTimeout());
+ final ServerSessionManager manager = new ServerSessionManager(dependenciesProvider, listenerFactory,
+ configDependencies);
- return new PCEPTopologyProvider(configDependencies.getAddress(), configDependencies.getKeys(),
- dependenciesProvider, topology, manager, configDependencies.getSchedulerDependency());
+ return new PCEPTopologyProvider(configDependencies, dependenciesProvider, manager);
}
public void instantiateServiceInstance() {
this.element = requireNonNull(rpcRegistry
.addRoutedRpcImplementation(NetworkTopologyPcepService.class, new TopologyRPCs(this.manager)));
- this.element.registerPath(NetworkTopologyContext.class, this.topology);
+ this.element.registerPath(NetworkTopologyContext.class, this.configDependencies.getTopology());
this.network = requireNonNull(rpcRegistry
.addRoutedRpcImplementation(NetworkTopologyPcepProgrammingService.class,
- new TopologyProgramming(this.scheduler, this.manager)));
- this.network.registerPath(NetworkTopologyContext.class, this.topology);
+ new TopologyProgramming(configDependencies.getSchedulerDependency(), this.manager)));
+ this.network.registerPath(NetworkTopologyContext.class, this.configDependencies.getTopology());
try {
this.manager.instantiateServiceInstance().get();
final ChannelFuture channelFuture = this.dependenciesProvider.getPCEPDispatcher()
- .createServer(this.address, this.keys, this.manager, this.manager);
+ .createServer(this.manager.getPCEPDispatcherDependencies());
channelFuture.get();
this.channel = channelFuture.channel();
} catch (final Exception e) {
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.annotation.concurrent.GuardedBy;
+import org.opendaylight.bgpcep.pcep.topology.provider.config.PCEPTopologyConfiguration;
+import org.opendaylight.bgpcep.pcep.topology.provider.config.PCEPTopologyProviderDependencies;
import org.opendaylight.bgpcep.pcep.topology.spi.stats.TopologySessionStatsRegistry;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.protocol.pcep.PCEPDispatcherDependencies;
import org.opendaylight.protocol.pcep.PCEPPeerProposal;
import org.opendaylight.protocol.pcep.PCEPSession;
import org.opendaylight.protocol.pcep.PCEPSessionListener;
private final Map<NodeId, TopologyNodeState> state = new HashMap<>();
private final TopologySessionListenerFactory listenerFactory;
private final InstanceIdentifier<Topology> topology;
- private final DataBroker broker;
private final PCEPStatefulPeerProposal peerProposal;
private final short rpcTimeout;
- private final TopologySessionStatsRegistry statsRegistry;
+ private final PCEPTopologyProviderDependencies dependenciesProvider;
+ private final PCEPDispatcherDependencies pcepDispatcherDependencies;
- public ServerSessionManager(final DataBroker broker,
- final InstanceIdentifier<Topology> topology,
+ public ServerSessionManager(
+ final PCEPTopologyProviderDependencies dependenciesProvider,
final TopologySessionListenerFactory listenerFactory,
- final TopologySessionStatsRegistry statsRegistry,
- final short rpcTimeout) {
- this.broker = requireNonNull(broker);
- this.topology = requireNonNull(topology);
- this.statsRegistry = requireNonNull(statsRegistry);
+ final PCEPTopologyConfiguration configDependencies) {
+ this.dependenciesProvider = requireNonNull(dependenciesProvider);
+ this.topology = requireNonNull(configDependencies.getTopology());
this.listenerFactory = requireNonNull(listenerFactory);
- this.peerProposal = PCEPStatefulPeerProposal.createStatefulPeerProposal(this.broker, this.topology);
- this.rpcTimeout = rpcTimeout;
+ this.peerProposal = PCEPStatefulPeerProposal
+ .createStatefulPeerProposal(this.dependenciesProvider.getDataBroker(), this.topology);
+ this.rpcTimeout = configDependencies.getRpcTimeout();
+ this.pcepDispatcherDependencies = new PCEPDispatcherDependenciesImpl(this, configDependencies);
}
private static NodeId createNodeId(final InetAddress addr) {
synchronized ListenableFuture<Void> instantiateServiceInstance() {
final TopologyKey key = InstanceIdentifier.keyOf(this.topology);
final TopologyId topologyId = key.getTopologyId();
- final WriteTransaction tx = this.broker.newWriteOnlyTransaction();
+ final WriteTransaction tx = this.dependenciesProvider.getDataBroker().newWriteOnlyTransaction();
tx.put(LogicalDatastoreType.OPERATIONAL, this.topology, new TopologyBuilder().setKey(key)
.setTopologyId(topologyId).setTopologyTypes(new TopologyTypesBuilder()
.addAugmentation(TopologyTypes1.class, new TopologyTypes1Builder().setTopologyPcep(
return future;
}
- synchronized void releaseNodeState(final TopologyNodeState nodeState, final PCEPSession session, final boolean persistNode) {
+ synchronized void releaseNodeState(final TopologyNodeState nodeState, final PCEPSession session,
+ final boolean persistNode) {
if (this.isClosed.get()) {
LOG.error("Session Manager has already been closed.");
return;
}
}
- synchronized TopologyNodeState takeNodeState(final InetAddress address, final TopologySessionListener sessionListener, final boolean retrieveNode) {
+ synchronized TopologyNodeState takeNodeState(final InetAddress address,
+ final TopologySessionListener sessionListener, final boolean retrieveNode) {
final NodeId id = createNodeId(address);
if (this.isClosed.get()) {
- LOG.error("Server Session Manager is closed. Unable to create topology node {} with listener {}", id, sessionListener);
+ LOG.error("Server Session Manager is closed. Unable to create topology node {} with listener {}",
+ id, sessionListener);
return null;
}
TopologyNodeState ret = this.state.get(id);
if (ret == null) {
- ret = new TopologyNodeState(this.broker, this.topology, id, DEFAULT_HOLD_STATE_NANOS);
+ ret = new TopologyNodeState(this.dependenciesProvider.getDataBroker(), this.topology, id,
+ DEFAULT_HOLD_STATE_NANOS);
LOG.debug("Created topology node {} for id {} at {}", ret, id, ret.getNodeId());
this.state.put(id, ret);
}
// if another listener requests the same session, close it
final TopologySessionListener existingSessionListener = this.nodes.get(id);
if (existingSessionListener != null && !sessionListener.equals(existingSessionListener)) {
- LOG.error("New session listener {} is in conflict with existing session listener {} on node {}, closing the existing one.", existingSessionListener, sessionListener, id);
+ LOG.error("New session listener {} is in conflict with existing session listener {} on node {}," +
+ " closing the existing one.", existingSessionListener, sessionListener, id);
existingSessionListener.close();
}
ret.taken(retrieveNode);
return this.listenerFactory.createTopologySessionListener(this);
}
- protected final synchronized TopologySessionListener checkSessionPresence(final NodeId nodeId) {
+ private synchronized TopologySessionListener checkSessionPresence(final NodeId nodeId) {
// Get the listener corresponding to the node
final TopologySessionListener l = this.nodes.get(nodeId);
if (l == null) {
nodeState.close();
}
this.state.clear();
- final WriteTransaction t = this.broker.newWriteOnlyTransaction();
+ final WriteTransaction t = this.dependenciesProvider.getDataBroker().newWriteOnlyTransaction();
t.delete(LogicalDatastoreType.OPERATIONAL, this.topology);
final ListenableFuture<Void> future = t.submit();
Futures.addCallback(future, new FutureCallback<Void>() {
@Override
public synchronized void bind(final KeyedInstanceIdentifier<Node, NodeKey> nodeId,
final PcepSessionState sessionState) {
- this.statsRegistry.bind(nodeId, sessionState);
+ this.dependenciesProvider.getStateRegistry().bind(nodeId, sessionState);
}
@Override
public synchronized void unbind(final KeyedInstanceIdentifier<Node, NodeKey> nodeId) {
- this.statsRegistry.unbind(nodeId);
+ this.dependenciesProvider.getStateRegistry().unbind(nodeId);
+ }
+
+ PCEPDispatcherDependencies getPCEPDispatcherDependencies(){
+ return this.pcepDispatcherDependencies;
}
}
\ No newline at end of file
import javax.annotation.Nonnull;
import org.opendaylight.bgpcep.programming.spi.InstructionScheduler;
import org.opendaylight.protocol.concepts.KeyMapping;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
public final class PCEPTopologyConfiguration {
private final InetSocketAddress address;
private final InstructionScheduler scheduler;
private final TopologyId topologyId;
private final short rpcTimeout;
+ private final InstanceIdentifier<Topology> topology;
public PCEPTopologyConfiguration(
@Nonnull final InetSocketAddress address,
this.scheduler = checkNotNull(scheduler);
this.topologyId = checkNotNull(topologyId);
this.rpcTimeout = rpcTimeout;
+ this.topology = InstanceIdentifier.builder(NetworkTopology.class)
+ .child(Topology.class, new TopologyKey(this.topologyId)).build();
}
+ @Nonnull
public TopologyId getTopologyId() {
return this.topologyId;
}
+ @Nonnull
+ public InstanceIdentifier<Topology> getTopology() {
+ return this.topology;
+ }
+
+ @Nonnull
public InstructionScheduler getSchedulerDependency() {
return this.scheduler;
}
return this.rpcTimeout;
}
+ @Nonnull
public InetSocketAddress getAddress() {
return this.address;
}
+ @Nonnull
public KeyMapping getKeys() {
return this.keys;
}
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public final class PCEPTopologyProviderBean implements PCEPTopologyProviderDependenciesProvider, AutoCloseable {
+public final class PCEPTopologyProviderBean implements PCEPTopologyProviderDependencies, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(PCEPTopologyProviderBean.class);
private static final String STATEFUL_NOT_DEFINED =
*/
package org.opendaylight.bgpcep.pcep.topology.provider.config;
+import com.google.common.annotations.Beta;
import javax.annotation.Nonnull;
import org.opendaylight.bgpcep.pcep.topology.provider.TopologySessionListenerFactory;
import org.opendaylight.bgpcep.pcep.topology.spi.stats.TopologySessionStatsRegistry;
/**
* Provides required dependencies for PCEPTopologyProviderProvider instantiation
*/
-public interface PCEPTopologyProviderDependenciesProvider {
+@Beta
+public interface PCEPTopologyProviderDependencies {
/**
* @return PCEPDispatcher
*/
import io.netty.util.concurrent.Promise;
import java.lang.reflect.ParameterizedType;
import java.net.InetSocketAddress;
-import java.net.SocketAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
+import org.opendaylight.bgpcep.pcep.topology.provider.config.PCEPTopologyConfiguration;
+import org.opendaylight.bgpcep.pcep.topology.provider.config.PCEPTopologyProviderDependencies;
import org.opendaylight.bgpcep.pcep.topology.spi.stats.TopologySessionStatsRegistry;
+import org.opendaylight.bgpcep.programming.spi.InstructionScheduler;
import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
+import org.opendaylight.protocol.concepts.KeyMapping;
import org.opendaylight.protocol.pcep.PCEPSessionListener;
import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiator;
import org.opendaylight.protocol.pcep.impl.PCEPSessionImpl;
import org.opendaylight.yangtools.yang.binding.Notification;
public abstract class AbstractPCEPSessionTest<T extends TopologySessionListenerFactory>
- extends AbstractConcurrentDataBrokerTest {
+ extends AbstractConcurrentDataBrokerTest {
- private static final String TEST_TOPOLOGY_NAME = "testtopo";
- static final InstanceIdentifier<Topology> TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class)
- .child(Topology.class, new TopologyKey(new TopologyId(TEST_TOPOLOGY_NAME))).build();
- private static final String IPV4_MASK = "/32";
static final short DEAD_TIMER = 30;
static final short KEEP_ALIVE = 10;
static final short RPC_TIMEOUT = 4;
-
+ private static final TopologyId TEST_TOPOLOGY_ID = new TopologyId("testtopo");
+ static final InstanceIdentifier<Topology> TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class)
+ .child(Topology.class, new TopologyKey(TEST_TOPOLOGY_ID)).build();
+ private static final String IPV4_MASK = "/32";
final String testAddress = InetSocketAddressUtil.getRandomLoopbackIpAddress();
final NodeId nodeId = new NodeId("pcc://" + this.testAddress);
protected final InstanceIdentifier<PathComputationClient> pathComputationClientIId = TOPO_IID.builder()
- .child(Node.class, new NodeKey(this.nodeId)).augmentation(Node1.class).child(PathComputationClient.class
- ).build();
+ .child(Node.class, new NodeKey(this.nodeId)).augmentation(Node1.class).child(PathComputationClient.class
+ ).build();
final String eroIpPrefix = this.testAddress + IPV4_MASK;
final String newDestinationAddress = InetSocketAddressUtil.getRandomLoopbackIpAddress();
final String dstIpPrefix = this.newDestinationAddress + IPV4_MASK;
-
+ private final Open localPrefs = new OpenBuilder().setDeadTimer((short) 30).setKeepalive((short) 10)
+ .setSessionId((short) 0).build();
+ private final Open remotePrefs = this.localPrefs;
List<Notification> receivedMsgs;
-
+ ServerSessionManager manager;
+ NetworkTopologyPcepService topologyRpcs;
@Mock
private EventLoop eventLoop;
-
@Mock
private Channel clientListener;
-
@Mock
private ChannelPipeline pipeline;
-
@Mock
private ChannelFuture channelFuture;
-
@Mock
private TopologySessionStatsRegistry statsRegistry;
-
- private final Open localPrefs = new OpenBuilder().setDeadTimer((short) 30).setKeepalive((short) 10)
- .setSessionId((short) 0).build();
-
- private final Open remotePrefs = this.localPrefs;
-
- ServerSessionManager manager;
-
- NetworkTopologyPcepService topologyRpcs;
-
+ @Mock
+ private PCEPTopologyProviderDependencies topologyDependencies;
+ @Mock
+ private InstructionScheduler scheduler;
+ @Mock
+ private Promise<PCEPSessionImpl> promise;
private DefaultPCEPSessionNegotiator neg;
@Before
doReturn("TestingChannel").when(this.clientListener).toString();
doReturn(this.pipeline).when(this.clientListener).pipeline();
doReturn(this.pipeline).when(this.pipeline).replace(any(ChannelHandler.class), any(String.class),
- any(ChannelHandler.class));
+ any(ChannelHandler.class));
doReturn(this.eventLoop).when(this.clientListener).eventLoop();
doNothing().when(this.statsRegistry).bind(any(), any());
doNothing().when(this.statsRegistry).unbind(any());
doReturn(null).when(this.eventLoop).schedule(any(Runnable.class), any(long.class),
- any(TimeUnit.class));
+ any(TimeUnit.class));
doReturn(true).when(this.clientListener).isActive();
- final SocketAddress ra = new InetSocketAddress(this.testAddress, 4189);
+ final InetSocketAddress ra = new InetSocketAddress(this.testAddress, 4189);
doReturn(ra).when(this.clientListener).remoteAddress();
- final SocketAddress la = new InetSocketAddress(this.testAddress, InetSocketAddressUtil.getRandomPort());
+ final InetSocketAddress la = new InetSocketAddress(this.testAddress, InetSocketAddressUtil.getRandomPort());
doReturn(la).when(this.clientListener).localAddress();
doReturn(mock(ChannelFuture.class)).when(this.clientListener).close();
- final T listenerFactory = (T) ((Class) ((ParameterizedType) this.getClass().getGenericSuperclass())
- .getActualTypeArguments()[0]).newInstance();
- this.manager = new ServerSessionManager(getDataBroker(), TOPO_IID, listenerFactory, this.statsRegistry,
- RPC_TIMEOUT);
+ doReturn(getDataBroker()).when(this.topologyDependencies).getDataBroker();
+ doReturn(this.statsRegistry).when(this.topologyDependencies).getStateRegistry();
+
+ @SuppressWarnings("unchecked") final T listenerFactory = (T) ((Class) ((ParameterizedType) this.getClass().getGenericSuperclass())
+ .getActualTypeArguments()[0]).newInstance();
+
+ final PCEPTopologyConfiguration configDep = new PCEPTopologyConfiguration(ra, KeyMapping.getKeyMapping(),
+ this.scheduler, TEST_TOPOLOGY_ID, RPC_TIMEOUT);
+ this.manager = new ServerSessionManager(this.topologyDependencies, listenerFactory, configDep);
startSessionManager();
- this.neg = new DefaultPCEPSessionNegotiator(mock(Promise.class), this.clientListener,
- this.manager.getSessionListener(), (short) 1, 5, this.localPrefs);
+ this.neg = new DefaultPCEPSessionNegotiator(this.promise, this.clientListener,
+ this.manager.getSessionListener(), (short) 1, 5, this.localPrefs);
this.topologyRpcs = new TopologyRPCs(this.manager);
}
- protected void startSessionManager() throws Exception {
+ void startSessionManager() throws Exception {
final ListenableFuture<Void> future = this.manager.instantiateServiceInstance();
future.get();
- checkEquals(()-> assertFalse(this.manager.isClosed.get()));
+ checkEquals(() -> assertFalse(this.manager.isClosed.get()));
}
- protected void stopSessionManager() {
+ void stopSessionManager() {
this.manager.closeServiceInstance();
}
final SubobjectBuilder subobjBuilder = new SubobjectBuilder();
for (final String ipPrefix : ipPrefixes) {
subobjBuilder.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(new IpPrefixBuilder().setIpPrefix(
- new IpPrefix(new Ipv4Prefix(ipPrefix))).build()).build());
+ new IpPrefix(new Ipv4Prefix(ipPrefix))).build()).build());
subobjs.add(subobjBuilder.build());
}
return new EroBuilder().setSubobject(subobjs).build();
}
String getLastEroIpPrefix(final Ero ero) {
- return ((IpPrefixCase)ero.getSubobject().get(ero.getSubobject().size() - 1).getSubobjectType()).getIpPrefix()
- .getIpPrefix().getIpv4Prefix().getValue();
+ return ((IpPrefixCase) ero.getSubobject().get(ero.getSubobject().size() - 1).getSubobjectType()).getIpPrefix()
+ .getIpPrefix().getIpv4Prefix().getValue();
}
protected Open getLocalPref() {