<type xmlns:netty="urn:opendaylight:params:xml:ns:yang:controller:netty">netty:netty-threadgroup</type>
<name>global-worker-group</name>
</worker-group>
- <timer>
- <type xmlns:netty="urn:opendaylight:params:xml:ns:yang:controller:netty">netty:netty-timer</type>
- <name>global-timer</name>
- </timer>
<!--
Uncomment this block to enable TCP MD5 Signature support
@Override
public java.lang.AutoCloseable createInstance() {
Open localPrefs = getPcepSessionProposalFactoryDependency().getSessionProposal(null, 0);
- DefaultPCEPSessionNegotiatorFactory negFactory = new DefaultPCEPSessionNegotiatorFactory(getTimerDependency(), localPrefs, getMaxUnknownMessages());
+ DefaultPCEPSessionNegotiatorFactory negFactory = new DefaultPCEPSessionNegotiatorFactory(localPrefs, getMaxUnknownMessages());
final PCEPDispatcherImpl instance = new PCEPDispatcherImpl(getPcepExtensionsDependency().getMessageHandlerRegistry(), negFactory, getBossGroupDependency(), getWorkerGroupDependency(), getMd5ChannelFactoryDependency(), getMd5ServerChannelFactoryDependency());
return instance;
import com.google.common.base.Preconditions;
import io.netty.channel.Channel;
-import io.netty.util.Timeout;
-import io.netty.util.Timer;
-import io.netty.util.TimerTask;
import io.netty.util.concurrent.Promise;
+import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
-import javax.annotation.concurrent.GuardedBy;
-
import org.opendaylight.protocol.framework.AbstractSessionNegotiator;
import org.opendaylight.protocol.pcep.spi.PCEPErrors;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Keepalive;
private static final Logger LOG = LoggerFactory.getLogger(AbstractPCEPSessionNegotiator.class);
private static final Keepalive KEEPALIVE = new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build();
- private final Timer timer;
-
- @GuardedBy("this")
- private State state = State.Idle;
-
- @GuardedBy("this")
- private Timeout failTimer;
-
- @GuardedBy("this")
+ private volatile boolean localOK, openRetry, remoteOK;
+ private volatile State state = State.Idle;
+ private Future<?> failTimer;
private Open localPrefs;
-
- @GuardedBy("this")
private Open remotePrefs;
- private volatile boolean localOK, openRetry, remoteOK;
-
- protected AbstractPCEPSessionNegotiator(final Timer timer, final Promise<PCEPSessionImpl> promise, final Channel channel) {
+ protected AbstractPCEPSessionNegotiator(final Promise<PCEPSessionImpl> promise, final Channel channel) {
super(promise, channel);
- this.timer = Preconditions.checkNotNull(timer);
}
/**
/**
* Create the protocol session.
*
- * @param timer Timer which the session can use for its various functions.
* @param channel Underlying channel.
* @param sessionId Assigned session ID.
* @param localPrefs Session preferences proposed by us and accepted by the peer.
* @param remotePrefs Session preferences proposed by the peer and accepted by us.
* @return New protocol session.
*/
- protected abstract PCEPSessionImpl createSession(Timer timer, Channel channel, Open localPrefs, Open remotePrefs);
+ protected abstract PCEPSessionImpl createSession(Channel channel, Open localPrefs, Open remotePrefs);
/**
* Sends PCEP Error Message with one PCEPError.
}
private void scheduleFailTimer() {
- final Object lock = this;
-
- this.failTimer = this.timer.newTimeout(new TimerTask() {
+ this.failTimer = this.channel.eventLoop().schedule(new Runnable() {
@Override
- public void run(final Timeout timeout) {
- synchronized (lock) {
- // This closes the race between timer expiring and new timer
- // being armed while it waits for the lock.
- if (AbstractPCEPSessionNegotiator.this.failTimer == timeout) {
- switch (AbstractPCEPSessionNegotiator.this.state) {
- case Finished:
- case Idle:
- break;
- case KeepWait:
- sendErrorMessage(PCEPErrors.NO_MSG_BEFORE_EXP_KEEPWAIT);
- negotiationFailed(new TimeoutException("KeepWait timer expired"));
- AbstractPCEPSessionNegotiator.this.state = State.Finished;
- break;
- case OpenWait:
- sendErrorMessage(PCEPErrors.NO_OPEN_BEFORE_EXP_OPENWAIT);
- negotiationFailed(new TimeoutException("OpenWait timer expired"));
- AbstractPCEPSessionNegotiator.this.state = State.Finished;
- break;
- }
- }
+ public void run() {
+ switch (AbstractPCEPSessionNegotiator.this.state) {
+ case Finished:
+ case Idle:
+ break;
+ case KeepWait:
+ sendErrorMessage(PCEPErrors.NO_MSG_BEFORE_EXP_KEEPWAIT);
+ negotiationFailed(new TimeoutException("KeepWait timer expired"));
+ AbstractPCEPSessionNegotiator.this.state = State.Finished;
+ break;
+ case OpenWait:
+ sendErrorMessage(PCEPErrors.NO_OPEN_BEFORE_EXP_OPENWAIT);
+ negotiationFailed(new TimeoutException("OpenWait timer expired"));
+ AbstractPCEPSessionNegotiator.this.state = State.Finished;
+ break;
}
}
}, FAIL_TIMER_VALUE, TimeUnit.SECONDS);
}
@Override
- protected final synchronized void startNegotiation() {
+ protected final void startNegotiation() {
Preconditions.checkState(this.state == State.Idle);
this.localPrefs = getInitialProposal();
final OpenMessage m = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.OpenBuilder().setOpenMessage(
}
@Override
- protected final synchronized void handleMessage(final Message msg) {
- this.failTimer.cancel();
+ protected final void handleMessage(final Message msg) {
+ this.failTimer.cancel(false);
LOG.debug("Channel {} handling message {} in state {}", this.channel, msg, this.state);
this.localOK = true;
if (this.remoteOK) {
LOG.info("PCEP peer {} completed negotiation", this.channel);
- negotiationSuccessful(createSession(this.timer, this.channel, this.localPrefs, this.remotePrefs));
+ negotiationSuccessful(createSession(this.channel, this.localPrefs, this.remotePrefs));
this.state = State.Finished;
} else {
scheduleFailTimer();
this.remotePrefs = open;
this.remoteOK = true;
if (this.localOK) {
- negotiationSuccessful(createSession(this.timer, this.channel, this.localPrefs, this.remotePrefs));
+ negotiationSuccessful(createSession(this.channel, this.localPrefs, this.remotePrefs));
LOG.info("PCEP peer {} completed negotiation", this.channel);
this.state = State.Finished;
} else {
this.state = State.Finished;
}
- public synchronized State getState() {
+ @VisibleForTesting
+ State getState() {
return this.state;
}
}
import com.google.common.base.Preconditions;
import io.netty.channel.Channel;
-import io.netty.util.Timer;
import io.netty.util.concurrent.Promise;
import org.opendaylight.protocol.pcep.PCEPSessionListener;
private final PCEPSessionListener listener;
private final int maxUnknownMessages;
- public DefaultPCEPSessionNegotiator(final Timer timer, final Promise<PCEPSessionImpl> promise, final Channel channel,
+ public DefaultPCEPSessionNegotiator(final Promise<PCEPSessionImpl> promise, final Channel channel,
final PCEPSessionListener listener, final short sessionId, final int maxUnknownMessages, final Open localPrefs) {
- super(timer, promise, channel);
+ super(promise, channel);
this.maxUnknownMessages = maxUnknownMessages;
this.myLocalPrefs = new OpenBuilder().setKeepalive(localPrefs.getKeepalive()).setDeadTimer(localPrefs.getDeadTimer()).setSessionId(
sessionId).setTlvs(localPrefs.getTlvs()).build();
@Override
@VisibleForTesting
- public PCEPSessionImpl createSession(final Timer timer, final Channel channel, final Open localPrefs, final Open remotePrefs) {
- return new PCEPSessionImpl(timer, this.listener, this.maxUnknownMessages, channel, localPrefs, remotePrefs);
+ public PCEPSessionImpl createSession(final Channel channel, final Open localPrefs, final Open remotePrefs) {
+ return new PCEPSessionImpl(this.listener, this.maxUnknownMessages, channel, localPrefs, remotePrefs);
}
@Override
import com.google.common.base.Preconditions;
import io.netty.channel.Channel;
-import io.netty.util.Timer;
import io.netty.util.concurrent.Promise;
import org.opendaylight.protocol.pcep.PCEPSessionListener;
public final class DefaultPCEPSessionNegotiatorFactory extends AbstractPCEPSessionNegotiatorFactory {
private final Open localPrefs;
private final int maxUnknownMessages;
- private final Timer timer;
- public DefaultPCEPSessionNegotiatorFactory(final Timer timer, final Open localPrefs, final int maxUnknownMessages) {
- this.timer = Preconditions.checkNotNull(timer);
+ public DefaultPCEPSessionNegotiatorFactory(final Open localPrefs, final int maxUnknownMessages) {
this.localPrefs = Preconditions.checkNotNull(localPrefs);
this.maxUnknownMessages = maxUnknownMessages;
}
@Override
protected AbstractPCEPSessionNegotiator createNegotiator(final Promise<PCEPSessionImpl> promise, final PCEPSessionListener listener,
final Channel channel, final short sessionId) {
- return new DefaultPCEPSessionNegotiator(this.timer, promise, channel, listener, sessionId, this.maxUnknownMessages, this.localPrefs);
+ return new DefaultPCEPSessionNegotiator(promise, channel, listener, sessionId, this.maxUnknownMessages, this.localPrefs);
}
}
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
-import io.netty.util.Timeout;
-import io.netty.util.Timer;
-import io.netty.util.TimerTask;
import io.netty.util.concurrent.Future;
import java.io.IOException;
private static final Logger LOG = LoggerFactory.getLogger(PCEPSessionImpl.class);
- /**
- * Timer object grouping FSM Timers
- */
- private final Timer stateTimer;
-
private int sentMsgCount = 0;
private int receivedMsgCount = 0;
private final Keepalive kaMessage = new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build();
- PCEPSessionImpl(final Timer timer, final PCEPSessionListener listener, final int maxUnknownMessages, final Channel channel,
+ PCEPSessionImpl(final PCEPSessionListener listener, final int maxUnknownMessages, final Channel channel,
final Open localOpen, final Open remoteOpen) {
this.listener = Preconditions.checkNotNull(listener);
- this.stateTimer = Preconditions.checkNotNull(timer);
this.channel = Preconditions.checkNotNull(channel);
this.localOpen = Preconditions.checkNotNull(localOpen);
this.remoteOpen = Preconditions.checkNotNull(remoteOpen);
this.maxUnknownMessages = maxUnknownMessages;
}
+
if (getDeadTimerValue() != 0) {
- this.stateTimer.newTimeout(new TimerTask() {
+ channel.eventLoop().schedule(new Runnable() {
@Override
- public void run(final Timeout timeout) {
+ public void run() {
handleDeadTimer();
}
}, getDeadTimerValue(), TimeUnit.SECONDS);
}
if (getKeepAliveTimerValue() != 0) {
- this.stateTimer.newTimeout(new TimerTask() {
+ channel.eventLoop().schedule(new Runnable() {
@Override
- public void run(final Timeout timeout) {
+ public void run() {
handleKeepaliveTimer();
}
}, getKeepAliveTimerValue(), TimeUnit.SECONDS);
LOG.debug("DeadTimer expired. {}", new Date());
this.terminate(TerminationReason.ExpDeadtimer);
} else {
- this.stateTimer.newTimeout(new TimerTask() {
+ this.channel.eventLoop().schedule(new Runnable() {
@Override
- public void run(final Timeout timeout) {
+ public void run() {
handleDeadTimer();
}
}, nextDead - ct, TimeUnit.NANOSECONDS);
* KeepAlive timer to the time at which the message was sent. If the session was closed by the time this method
* starts to execute (the session state will become IDLE), that rescheduling won't occur.
*/
- private synchronized void handleKeepaliveTimer() {
+ private void handleKeepaliveTimer() {
final long ct = System.nanoTime();
long nextKeepalive = this.lastMessageSentAt + TimeUnit.SECONDS.toNanos(getKeepAliveTimerValue());
nextKeepalive = this.lastMessageSentAt + TimeUnit.SECONDS.toNanos(getKeepAliveTimerValue());
}
- this.stateTimer.newTimeout(new TimerTask() {
+ this.channel.eventLoop().schedule(new Runnable() {
@Override
- public void run(final Timeout timeout) {
+ public void run() {
handleKeepaliveTimer();
}
}, nextKeepalive - ct, TimeUnit.NANOSECONDS);
}
}
- container timer {
- uses config:service-ref {
- refine type {
- mandatory true;
- config:required-identity netty:netty-timer;
- }
- }
- }
-
container md5-channel-factory {
uses config:service-ref {
refine type {
import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
import org.opendaylight.controller.config.yang.netty.threadgroup.NettyThreadgroupModuleFactory;
import org.opendaylight.controller.config.yang.netty.threadgroup.NettyThreadgroupModuleMXBean;
-import org.opendaylight.controller.config.yang.netty.timer.HashedWheelTimerModuleFactory;
-import org.opendaylight.controller.config.yang.netty.timer.HashedWheelTimerModuleMXBean;
import org.opendaylight.controller.config.yang.pcep.spi.SimplePCEPExtensionProviderContextModuleFactory;
import org.opendaylight.controller.config.yang.pcep.spi.SimplePCEPExtensionProviderContextModuleMXBean;
private static final String INSTANCE_NAME = "pcep-dispatcher-impl";
private static final String FACTORY_NAME = PCEPDispatcherImplModuleFactory.NAME;
- private static final String TIMER_INSTANCE_NAME = "hashed-wheel-timer";
- private static final String TIMER_FACTORY_NAME = HashedWheelTimerModuleFactory.NAME;
-
private static final String THREADGROUP_FACTORY_NAME = NettyThreadgroupModuleFactory.NAME;
private static final String BOSS_TG_INSTANCE_NAME = "boss-group";
private static final String WORKER_TG_INSTANCE_NAME = "worker-group";
@Before
public void setUp() throws Exception {
- super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext, new PCEPDispatcherImplModuleFactory(), new PCEPSessionProposalFactoryImplModuleFactory(), new NettyThreadgroupModuleFactory(), new SimplePCEPExtensionProviderContextModuleFactory(), new HashedWheelTimerModuleFactory()));
+ super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(this.mockedContext, new PCEPDispatcherImplModuleFactory(), new PCEPSessionProposalFactoryImplModuleFactory(), new NettyThreadgroupModuleFactory(), new SimplePCEPExtensionProviderContextModuleFactory()));
}
@Test
try {
createDispatcherInstance(null);
fail();
- } catch (ValidationException e) {
+ } catch (final ValidationException e) {
assertTrue(e.getMessage().contains("MaxUnknownMessages value is not set"));
}
}
try {
createDispatcherInstance(0);
fail();
- } catch (ValidationException e) {
+ } catch (final ValidationException e) {
assertTrue(e.getMessage().contains("must be greater than 0"));
}
}
public void testCreateBean() throws Exception {
final CommitStatus status = createDispatcherInstance(5);
assertBeanCount(1, FACTORY_NAME);
- assertStatus(status, 6, 0, 0);
+ assertStatus(status, 5, 0, 0);
}
@Test
assertBeanCount(1, FACTORY_NAME);
final CommitStatus status = transaction.commit();
assertBeanCount(1, FACTORY_NAME);
- assertStatus(status, 0, 0, 6);
+ assertStatus(status, 0, 0, 5);
}
@Test
mxBean.setMaxUnknownMessages(10);
final CommitStatus status = transaction.commit();
assertBeanCount(1, FACTORY_NAME);
- assertStatus(status, 0, 1, 5);
+ assertStatus(status, 0, 1, 4);
}
private CommitStatus createDispatcherInstance(final Integer maxUnknownMessages) throws Exception {
mxBean.setBossGroup(createThreadGroupInstance(transaction, 10, BOSS_TG_INSTANCE_NAME));
mxBean.setWorkerGroup(createThreadGroupInstance(transaction, 10, WORKER_TG_INSTANCE_NAME));
mxBean.setPcepExtensions(createExtensionsInstance(transaction));
- mxBean.setTimer(createTimerInstance(transaction));
return nameCreated;
}
return nameCreated;
}
- private static ObjectName createTimerInstance(final ConfigTransactionJMXClient transaction) throws InstanceAlreadyExistsException {
- final ObjectName nameCreated = transaction.createModule(TIMER_FACTORY_NAME, TIMER_INSTANCE_NAME);
- transaction.newMXBeanProxy(nameCreated, HashedWheelTimerModuleMXBean.class);
- return nameCreated;
- }
-
}
import static org.mockito.Mockito.mock;
import com.google.common.collect.Lists;
-
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.DefaultChannelPromise;
-import io.netty.util.HashedWheelTimer;
+import io.netty.channel.EventLoop;
import io.netty.util.concurrent.DefaultPromise;
import io.netty.util.concurrent.GlobalEventExecutor;
-
+import io.netty.util.concurrent.ScheduledFuture;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.List;
-
+import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
@Mock
private Channel clientListener;
+ @Mock
+ private EventLoop eventLoop;
+
+ @Mock
+ private ScheduledFuture<?> future;
+
@Mock
private ChannelPipeline pipeline;
MockitoAnnotations.initMocks(this);
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open localPrefs = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder().setKeepalive(
(short) 1).build();
- this.serverSession = new DefaultPCEPSessionNegotiator(new HashedWheelTimer(), new DefaultPromise<PCEPSessionImpl>(GlobalEventExecutor.INSTANCE), this.clientListener, new SimpleSessionListener(), (short) 1, 20, localPrefs);
+ this.serverSession = new DefaultPCEPSessionNegotiator(new DefaultPromise<PCEPSessionImpl>(GlobalEventExecutor.INSTANCE), this.clientListener, new SimpleSessionListener(), (short) 1, 20, localPrefs);
final ChannelFuture future = new DefaultChannelPromise(this.clientListener);
doAnswer(new Answer<Object>() {
@Override
doReturn(this.pipeline).when(this.clientListener).pipeline();
doReturn(this.address).when(this.clientListener).localAddress();
doReturn(this.address).when(this.clientListener).remoteAddress();
+ doReturn(this.eventLoop).when(this.clientListener).eventLoop();
+ doReturn(true).when(this.future).cancel(false);
+ doReturn(this.future).when(this.eventLoop).schedule(any(Runnable.class), any(long.class), any(TimeUnit.class));
doReturn(this.pipeline).when(this.pipeline).replace(any(ChannelHandler.class), any(String.class), any(ChannelHandler.class));
doReturn(true).when(this.clientListener).isActive();
doReturn(mock(ChannelFuture.class)).when(this.clientListener).close();
this.serverSession.channelActive(null);
assertEquals(1, this.receivedMsgs.size());
assertTrue(this.receivedMsgs.get(0) instanceof Open);
- Open remote = (Open) this.receivedMsgs.get(0);
+ final Open remote = (Open) this.receivedMsgs.get(0);
this.serverSession.handleMessage(this.openmsg);
assertEquals(2, this.receivedMsgs.size());
assertTrue(this.receivedMsgs.get(1) instanceof Keepalive);
@Ignore
public void testUnknownMessage() throws InterruptedException {
final SimpleSessionListener client = new SimpleSessionListener();
- final PCEPSessionImpl s = new PCEPSessionImpl(new HashedWheelTimer(), client, 5, this.clientListener, this.openmsg.getOpenMessage().getOpen(), this.openmsg.getOpenMessage().getOpen());
+ final PCEPSessionImpl s = new PCEPSessionImpl(client, 5, this.clientListener, this.openmsg.getOpenMessage().getOpen(), this.openmsg.getOpenMessage().getOpen());
s.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED);
assertEquals(1, s.unknownMessagesTimes.size());
Thread.sleep(10000);
import static org.mockito.Mockito.mock;
import io.netty.channel.Channel;
-import io.netty.util.HashedWheelTimer;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GlobalEventExecutor;
private final MockPCE client;
public ServerSessionMock(final PCEPSessionListener listener, final PCEPSessionListener client) {
- super(new HashedWheelTimer(), listener, 5, mock(Channel.class), new OpenBuilder().setKeepalive((short) 4).setDeadTimer((short) 9).setSessionId(
+ super(listener, 5, mock(Channel.class), new OpenBuilder().setKeepalive((short) 4).setDeadTimer((short) 9).setSessionId(
(short) 2).build(), new OpenBuilder().setKeepalive((short) 4).setDeadTimer((short) 9).setSessionId((short) 2).build());
this.client = (MockPCE) client;
}
package org.opendaylight.protocol.pcep.testtool;
import io.netty.channel.nio.NioEventLoopGroup;
-import io.netty.util.HashedWheelTimer;
-
import java.net.InetAddress;
import java.net.InetSocketAddress;
-
import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
import org.opendaylight.protocol.pcep.ietf.initiated00.Stateful07SessionProposalFactory;
import org.opendaylight.protocol.pcep.ietf.stateful07.StatefulActivator;
final Open prefs = spf.getSessionProposal(address, 0);
- StatefulActivator activator07 = new StatefulActivator();
+ final StatefulActivator activator07 = new StatefulActivator();
activator07.start(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance());
- final PCEPDispatcherImpl dispatcher = new PCEPDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry(), new DefaultPCEPSessionNegotiatorFactory(new HashedWheelTimer(), prefs, 5), new NioEventLoopGroup(), new NioEventLoopGroup());
+ final PCEPDispatcherImpl dispatcher = new PCEPDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry(), new DefaultPCEPSessionNegotiatorFactory(prefs, 5), new NioEventLoopGroup(), new NioEventLoopGroup());
dispatcher.createServer(address, new TestingSessionListenerFactory()).get();
}
package org.opendaylight.protocol.pcep.testtool;
import com.google.common.base.Preconditions;
-
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
-import io.netty.util.HashedWheelTimer;
import io.netty.util.concurrent.DefaultPromise;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GlobalEventExecutor;
import io.netty.util.concurrent.Promise;
-
import java.net.InetSocketAddress;
-
import org.opendaylight.protocol.framework.AbstractDispatcher;
import org.opendaylight.protocol.framework.NeverReconnectStrategy;
import org.opendaylight.protocol.framework.ProtocolSession;
}
public static void main(final String[] args) throws Exception {
- final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> snf = new DefaultPCEPSessionNegotiatorFactory(new HashedWheelTimer(), new OpenBuilder().setKeepalive(
+ final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> snf = new DefaultPCEPSessionNegotiatorFactory(new OpenBuilder().setKeepalive(
(short) 30).setDeadTimer((short) 120).setSessionId((short) 0).build(), 0);
final PCCMock<Message, PCEPSessionImpl, PCEPSessionListener> pcc = new PCCMock<>(snf, new PCEPHandlerFactory(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry()), new DefaultPromise<PCEPSessionImpl>(GlobalEventExecutor.INSTANCE));
import static org.mockito.Mockito.mock;
import com.google.common.collect.Lists;
-
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelPipeline;
-import io.netty.util.HashedWheelTimer;
+import io.netty.channel.EventLoop;
import io.netty.util.concurrent.Promise;
-
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
-
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
private PCEPSessionImpl session;
+ @Mock
+ private EventLoop eventLoop;
+
@Mock
private Channel clientListener;
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));
+ doReturn(this.eventLoop).when(this.clientListener).eventLoop();
+ doReturn(null).when(this.eventLoop).schedule(any(Runnable.class), any(long.class), any(TimeUnit.class));
doReturn(true).when(this.clientListener).isActive();
final SocketAddress ra = new InetSocketAddress("127.0.0.1", 4189);
doReturn(ra).when(this.clientListener).remoteAddress();
this.manager = new ServerSessionManager(this.providerService, InstanceIdentifier.builder(NetworkTopology.class).child(
Topology.class, new TopologyKey(new TopologyId("testtopo"))).toInstance(), new Stateful07TopologySessionListenerFactory());
- final DefaultPCEPSessionNegotiator neg = new DefaultPCEPSessionNegotiator(new HashedWheelTimer(), mock(Promise.class), this.clientListener, this.manager.getSessionListener(), (short) 1, 5, this.localPrefs);
- this.session = neg.createSession(new HashedWheelTimer(), this.clientListener, this.localPrefs, this.localPrefs);
+ final DefaultPCEPSessionNegotiator neg = new DefaultPCEPSessionNegotiator(mock(Promise.class), this.clientListener, this.manager.getSessionListener(), (short) 1, 5, this.localPrefs);
+ this.session = neg.createSession(this.clientListener, this.localPrefs, this.localPrefs);
final List<Reports> reports = Lists.newArrayList(new ReportsBuilder().setPath(new PathBuilder().setEro(new EroBuilder().build()).build()).setLsp(
new LspBuilder().setPlspId(new PlspId(5L)).setSync(false).setRemove(false).setTlvs(
try {
createInstance(null, LISTEN_PORT, TOPOLOGY_ID, false);
fail();
- } catch (ValidationException e) {
+ } catch (final ValidationException e) {
assertTrue(e.getMessage().contains("ListenAddress is not set"));
}
}
try {
createInstance(LISTEN_ADDRESS, null, TOPOLOGY_ID, false);
fail();
- } catch (ValidationException e) {
+ } catch (final ValidationException e) {
assertTrue(e.getMessage().contains("ListenPort is not set"));
}
}
try {
createInstance(LISTEN_ADDRESS, LISTEN_PORT, null, false);
fail();
- } catch (ValidationException e) {
+ } catch (final ValidationException e) {
assertTrue(e.getMessage().contains("TopologyId is not set"));
}
}
@Test
public void testCreateBean() throws Exception {
- CommitStatus status = createInstance(false);
+ final CommitStatus status = createInstance(false);
assertBeanCount(1, FACTORY_NAME);
- assertStatus(status, 16, 0, 0);
+ assertStatus(status, 15, 0, 0);
}
@Test
public void testReusingOldInstance() throws Exception {
createInstance(false);
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
+ final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
assertBeanCount(1, FACTORY_NAME);
- CommitStatus status = transaction.commit();
+ final CommitStatus status = transaction.commit();
assertBeanCount(1, FACTORY_NAME);
- assertStatus(status, 0, 0, 16);
+ assertStatus(status, 0, 0, 15);
}
@Test
mxBean.setTopologyId(new TopologyId("new-pcep-topology"));
final CommitStatus status = transaction.commit();
assertBeanCount(1, FACTORY_NAME);
- assertStatus(status, 0, 1, 15);
+ assertStatus(status, 0, 1, 14);
}
@Test
public void testCreateBeanWithMD5() throws Exception {
NativeTestSupport.assumeSupportedPlatform();
- CommitStatus status = createInstance(true);
+ final CommitStatus status = createInstance(true);
assertBeanCount(1, FACTORY_NAME);
- assertStatus(status, 18, 0, 0);
+ assertStatus(status, 17, 0, 0);
}
@Test
assertBeanCount(1, FACTORY_NAME);
final PCEPTopologyProviderModuleMXBean mxBean = transaction.newMXBeanProxy(
transaction.lookupConfigBean(FACTORY_NAME, INSTANCE_NAME), PCEPTopologyProviderModuleMXBean.class);
- ObjectName dispatcherON = mxBean.getDispatcher();
- PCEPDispatcherImplModuleMXBean dispatcher = transaction.newMXBeanProxy(dispatcherON, PCEPDispatcherImplModuleMXBean.class);
+ final ObjectName dispatcherON = mxBean.getDispatcher();
+ final PCEPDispatcherImplModuleMXBean dispatcher = transaction.newMXBeanProxy(dispatcherON, PCEPDispatcherImplModuleMXBean.class);
dispatcher.setMd5ServerChannelFactory(null);
try {
transaction.validateConfig();
fail();
- }catch(ValidationException e){
+ }catch(final ValidationException e){
assertTrue(e.getMessage(), e.getMessage().contains("Client password is not compatible with selected dispatcher"));
}
}
return transaction.commit();
}
- private CommitStatus createInstance(boolean addMD5) throws Exception {
+ private CommitStatus createInstance(final boolean addMD5) throws Exception {
return createInstance(LISTEN_ADDRESS, getRandomPortNumber(), TOPOLOGY_ID, addMD5);
}
return objectName;
}
- private static void addMd5(ConfigTransactionJMXClient transaction, PCEPTopologyProviderModuleMXBean mxBean) throws InstanceAlreadyExistsException {
- ObjectName jniON = transaction.createModule(NativeKeyAccessFactoryModuleFactory.NAME, NativeKeyAccessFactoryModuleFactory.NAME);
- ObjectName md5ServerChannelFactoryON = transaction.createModule(MD5ServerChannelFactoryModuleFactory.NAME, MD5ServerChannelFactoryModuleFactory.NAME);
- MD5ServerChannelFactoryModuleMXBean md5Factory = transaction.newMXBeanProxy(md5ServerChannelFactoryON, MD5ServerChannelFactoryModuleMXBean.class);
+ private static void addMd5(final ConfigTransactionJMXClient transaction, final PCEPTopologyProviderModuleMXBean mxBean) throws InstanceAlreadyExistsException {
+ final ObjectName jniON = transaction.createModule(NativeKeyAccessFactoryModuleFactory.NAME, NativeKeyAccessFactoryModuleFactory.NAME);
+ final ObjectName md5ServerChannelFactoryON = transaction.createModule(MD5ServerChannelFactoryModuleFactory.NAME, MD5ServerChannelFactoryModuleFactory.NAME);
+ final MD5ServerChannelFactoryModuleMXBean md5Factory = transaction.newMXBeanProxy(md5ServerChannelFactoryON, MD5ServerChannelFactoryModuleMXBean.class);
md5Factory.setServerKeyAccessFactory(jniON);
- ObjectName dispatcherON = mxBean.getDispatcher();
- PCEPDispatcherImplModuleMXBean dispatcher = transaction.newMXBeanProxy(dispatcherON, PCEPDispatcherImplModuleMXBean.class);
+ final ObjectName dispatcherON = mxBean.getDispatcher();
+ final PCEPDispatcherImplModuleMXBean dispatcher = transaction.newMXBeanProxy(dispatcherON, PCEPDispatcherImplModuleMXBean.class);
dispatcher.setMd5ServerChannelFactory(md5ServerChannelFactoryON);
}
private ObjectName createPCEPTopologyProviderModuleInstance(final ConfigTransactionJMXClient transaction, final String listenAddress,
- final PortNumber listenPort, final TopologyId topologyId, boolean addMD5) throws Exception {
+ final PortNumber listenPort, final TopologyId topologyId, final boolean addMD5) throws Exception {
final ObjectName objectName = transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
final ObjectName dataBrokerON = createDataBrokerInstance(transaction);
final ObjectName notificationBrokerON = createNotificationBrokerInstance(transaction);
if (addMD5) {
addMd5(transaction, mxBean);
// create 1 client
- Client client = new Client();
+ final Client client = new Client();
client.setPassword(Rfc2385Key.getDefaultInstance("foo"));
client.setAddress(new IpAddress("127.0.0.1".toCharArray()));
mxBean.setClient(Arrays.asList(client));
import static org.junit.Assert.fail;
import java.util.List;
-
import javax.management.ObjectName;
-
import org.junit.Test;
import org.opendaylight.controller.config.api.ValidationException;
import org.opendaylight.controller.config.api.jmx.CommitStatus;
try {
createInstance(null);
fail();
- } catch (ValidationException e) {
+ } catch (final ValidationException e) {
assertTrue(e.getMessage().contains("TopologyId is not set"));
}
}
@Test
public void testCreateBean() throws Exception {
- CommitStatus status = createInstance();
+ final CommitStatus status = createInstance();
assertBeanCount(1, FACTORY_NAME);
- assertStatus(status, 17, 0, 0);
+ assertStatus(status, 16, 0, 0);
}
@Test
public void testReusingOldInstance() throws Exception {
createInstance();
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
+ final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
assertBeanCount(1, FACTORY_NAME);
- CommitStatus status = transaction.commit();
+ final CommitStatus status = transaction.commit();
assertBeanCount(1, FACTORY_NAME);
- assertStatus(status, 0, 0, 17);
+ assertStatus(status, 0, 0, 16);
}
@Test
mxBean.setTopologyId(new TopologyId("new-pcep-topology"));
final CommitStatus status = transaction.commit();
assertBeanCount(1, FACTORY_NAME);
- assertStatus(status, 0, 1, 16);
+ assertStatus(status, 0, 1, 15);
}
private CommitStatus createInstance(final TopologyId topologyId) throws Exception {
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
+ final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
createPCEPTopologyProviderModuleInstance(transaction, topologyId);
return transaction.commit();
}