Rework PCEP timers to work on channel 63/9163/5
authorRobert Varga <rovarga@cisco.com>
Fri, 18 Jul 2014 15:41:59 +0000 (17:41 +0200)
committerDana Kutenicsova <dkutenic@cisco.com>
Sun, 20 Jul 2014 15:28:04 +0000 (17:28 +0200)
This has the nice property that netty will ensure thread safety, e.g. we
do not have to synchronize channel lifecycle events anymore.

Change-Id: I37ddd71b6cca8210573e767966032885a7678669
Signed-off-by: Robert Varga <rovarga@cisco.com>
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
15 files changed:
pcep/controller-config/src/main/resources/initial/32-pcep.xml
pcep/impl/src/main/java/org/opendaylight/controller/config/yang/pcep/impl/PCEPDispatcherImplModule.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionNegotiator.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/DefaultPCEPSessionNegotiator.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/DefaultPCEPSessionNegotiatorFactory.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java
pcep/impl/src/main/yang/odl-pcep-impl-cfg.yang
pcep/impl/src/test/java/org/opendaylight/controller/config/yang/pcep/impl/PCEPDispatcherImplModuleTest.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/FiniteStateMachineTest.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/ServerSessionMock.java
pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/Main.java
pcep/testtool/src/test/java/org/opendaylight/protocol/pcep/testtool/PCCMock.java
pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/ParserToSalTest.java
pcep/topology-provider/src/test/java/org/opendaylight/controller/config/yang/pcep/topology/provider/PCEPTopologyProviderModuleTest.java
pcep/tunnel-provider/src/test/java/org/opendaylight/controller/config/yang/pcep/tunnel/provider/PCEPTunnelTopologyProviderModuleTest.java

index 5f8b7bf80b5b0ea87b95976c2e2be279f72fe9a5..4ceee88cc940d8f108aad20265d6a391e78c9275 100644 (file)
                         <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
index 3f469e5523101596c3acfd413501e07e760d8f79..9b8fdb9471da72215dc53bd87804c0805a3c0505 100644 (file)
@@ -48,7 +48,7 @@ public final class PCEPDispatcherImplModule extends org.opendaylight.controller.
     @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;
index 89514b192973022a42987f26daf3f95164e80c05..b0389977c6a3f67fe0da2762fde1def4ad7feb09 100644 (file)
@@ -11,16 +11,12 @@ import com.google.common.annotations.VisibleForTesting;
 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;
@@ -77,25 +73,14 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
     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);
     }
 
     /**
@@ -133,14 +118,13 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
     /**
      * 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.
@@ -153,38 +137,30 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
     }
 
     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(
@@ -197,8 +173,8 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
     }
 
     @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);
 
@@ -211,7 +187,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
                 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();
@@ -254,7 +230,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
                     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 {
@@ -297,7 +273,8 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
         this.state = State.Finished;
     }
 
-    public synchronized State getState() {
+    @VisibleForTesting
+    State getState() {
         return this.state;
     }
 }
index c33f767c45963bfbc3f8143326f43d201ee3f05b..62a22025bc1de088553f381c95fecbd5c8c8eba3 100644 (file)
@@ -11,7 +11,6 @@ import com.google.common.annotations.VisibleForTesting;
 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;
@@ -22,9 +21,9 @@ public final class DefaultPCEPSessionNegotiator extends AbstractPCEPSessionNegot
     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();
@@ -40,8 +39,8 @@ public final class DefaultPCEPSessionNegotiator extends AbstractPCEPSessionNegot
 
     @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
index c78ceb66736eb3f708e2ea58f52d30548ec560bb..004c8c1dc694a5c52f5d1cacdd2bc414e7626197 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.protocol.pcep.impl;
 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;
@@ -19,10 +18,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 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;
     }
@@ -30,6 +27,6 @@ public final class DefaultPCEPSessionNegotiatorFactory extends AbstractPCEPSessi
     @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);
     }
 }
index 01f4dd547c84ace640fb126f6bc1b083cb42fc27..9ba2b594b119b44e2c18e3acda46147672501d00 100644 (file)
@@ -15,9 +15,6 @@ import com.google.common.base.Preconditions;
 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;
@@ -82,11 +79,6 @@ public class PCEPSessionImpl extends AbstractProtocolSession<Message> implements
 
     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;
@@ -100,10 +92,9 @@ public class PCEPSessionImpl extends AbstractProtocolSession<Message> implements
 
     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);
@@ -113,19 +104,20 @@ public class PCEPSessionImpl extends AbstractProtocolSession<Message> implements
             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);
@@ -151,9 +143,9 @@ public class PCEPSessionImpl extends AbstractProtocolSession<Message> implements
                 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);
@@ -167,7 +159,7 @@ public class PCEPSessionImpl extends AbstractProtocolSession<Message> implements
      * 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());
@@ -178,9 +170,9 @@ public class PCEPSessionImpl extends AbstractProtocolSession<Message> implements
                 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);
index 3ce13aaf62eda049b90ff5cccb216f5136e84607..6f166c0e03287bfae95524b3bdaa8543fe5f5496 100644 (file)
@@ -98,15 +98,6 @@ module odl-pcep-impl-cfg {
                 }
             }
 
-            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 {
index ca5ffff5fc7a116e786fadf77573d9bac3c4f25f..fcc86a8d87504e2be88b329eb9dececeb32abe1b 100644 (file)
@@ -21,8 +21,6 @@ import org.opendaylight.controller.config.manager.impl.factoriesresolver.Hardcod
 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;
 
@@ -31,9 +29,6 @@ public class PCEPDispatcherImplModuleTest extends AbstractConfigTest {
     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";
@@ -43,7 +38,7 @@ public class PCEPDispatcherImplModuleTest extends AbstractConfigTest {
 
     @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
@@ -51,7 +46,7 @@ public class PCEPDispatcherImplModuleTest extends AbstractConfigTest {
         try {
             createDispatcherInstance(null);
             fail();
-        } catch (ValidationException e) {
+        } catch (final ValidationException e) {
             assertTrue(e.getMessage().contains("MaxUnknownMessages value is not set"));
         }
     }
@@ -61,7 +56,7 @@ public class PCEPDispatcherImplModuleTest extends AbstractConfigTest {
         try {
             createDispatcherInstance(0);
             fail();
-        } catch (ValidationException e) {
+        } catch (final ValidationException e) {
             assertTrue(e.getMessage().contains("must be greater than 0"));
         }
     }
@@ -70,7 +65,7 @@ public class PCEPDispatcherImplModuleTest extends AbstractConfigTest {
     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
@@ -80,7 +75,7 @@ public class PCEPDispatcherImplModuleTest extends AbstractConfigTest {
         assertBeanCount(1, FACTORY_NAME);
         final CommitStatus status = transaction.commit();
         assertBeanCount(1, FACTORY_NAME);
-        assertStatus(status, 0, 0, 6);
+        assertStatus(status, 0, 0, 5);
     }
 
     @Test
@@ -93,7 +88,7 @@ public class PCEPDispatcherImplModuleTest extends AbstractConfigTest {
         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 {
@@ -111,7 +106,6 @@ public class PCEPDispatcherImplModuleTest extends AbstractConfigTest {
         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;
     }
 
@@ -130,10 +124,4 @@ public class PCEPDispatcherImplModuleTest extends AbstractConfigTest {
         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;
-    }
-
 }
index 0d5d774d08dc6a4f2ee98bda469522e98285b117..ac2699cd06f10971ad791fae4439058888ea59a8 100644 (file)
@@ -15,20 +15,19 @@ import static org.mockito.Mockito.doReturn;
 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;
@@ -56,6 +55,12 @@ public class FiniteStateMachineTest {
     @Mock
     private Channel clientListener;
 
+    @Mock
+    private EventLoop eventLoop;
+
+    @Mock
+    private ScheduledFuture<?> future;
+
     @Mock
     private ChannelPipeline pipeline;
 
@@ -73,7 +78,7 @@ public class FiniteStateMachineTest {
         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
@@ -87,6 +92,9 @@ public class FiniteStateMachineTest {
         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();
@@ -127,7 +135,7 @@ public class FiniteStateMachineTest {
         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);
@@ -206,7 +214,7 @@ public class FiniteStateMachineTest {
     @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);
index b326af8a78d6eb16e58edccb97e5652ced0bd1ff..1276ae4a5028c4e2eec85dccaf6f7357ea88651e 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.protocol.pcep.impl;
 
 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;
 
@@ -24,7 +23,7 @@ public class ServerSessionMock extends PCEPSessionImpl {
     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;
     }
index 1a4c0e581deece11418edae943c2f52a78dbb438..d60f9c9eafd9a1f2fd0135197a49f88b8fda2318 100644 (file)
@@ -8,11 +8,8 @@
 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;
@@ -117,10 +114,10 @@ public final class Main {
 
         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();
     }
index edf0775185eea3a3fb69dd963687f9bcd8c0e4ba..a24fd3d2ac15cf4bae128ec329b48e9ff7bbfa46 100644 (file)
@@ -8,17 +8,13 @@
 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;
@@ -59,7 +55,7 @@ public class PCCMock<M, S extends ProtocolSession<M>, L extends SessionListener<
     }
 
     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));
index 612785f8904b35b46bfb41227e8545fa5429cf6a..e339040dd7fd42374765f0237d9b8ac718b5e542 100644 (file)
@@ -13,14 +13,12 @@ import static org.mockito.Mockito.doReturn;
 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;
@@ -30,7 +28,6 @@ import java.util.concurrent.ExecutionException;
 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;
@@ -81,6 +78,9 @@ public class ParserToSalTest {
 
     private PCEPSessionImpl session;
 
+    @Mock
+    private EventLoop eventLoop;
+
     @Mock
     private Channel clientListener;
 
@@ -115,6 +115,8 @@ public class ParserToSalTest {
         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();
@@ -203,8 +205,8 @@ public class ParserToSalTest {
 
         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(
index 93923d0801fb2a03b02ecf2a49324b0da2c7ef6e..c5f714cfac1c7c8f94523a5ed40eccbc4a8308c3 100644 (file)
@@ -52,7 +52,7 @@ public class PCEPTopologyProviderModuleTest extends AbstractInstructionScheduler
         try {
             createInstance(null, LISTEN_PORT, TOPOLOGY_ID, false);
             fail();
-        } catch (ValidationException e) {
+        } catch (final ValidationException e) {
             assertTrue(e.getMessage().contains("ListenAddress is not set"));
         }
     }
@@ -62,7 +62,7 @@ public class PCEPTopologyProviderModuleTest extends AbstractInstructionScheduler
         try {
             createInstance(LISTEN_ADDRESS, null, TOPOLOGY_ID, false);
             fail();
-        } catch (ValidationException e) {
+        } catch (final ValidationException e) {
             assertTrue(e.getMessage().contains("ListenPort is not set"));
         }
     }
@@ -72,26 +72,26 @@ public class PCEPTopologyProviderModuleTest extends AbstractInstructionScheduler
         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
@@ -104,15 +104,15 @@ public class PCEPTopologyProviderModuleTest extends AbstractInstructionScheduler
         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
@@ -124,13 +124,13 @@ public class PCEPTopologyProviderModuleTest extends AbstractInstructionScheduler
         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"));
         }
     }
@@ -143,7 +143,7 @@ public class PCEPTopologyProviderModuleTest extends AbstractInstructionScheduler
         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);
     }
 
@@ -164,20 +164,20 @@ public class PCEPTopologyProviderModuleTest extends AbstractInstructionScheduler
         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);
@@ -190,7 +190,7 @@ public class PCEPTopologyProviderModuleTest extends AbstractInstructionScheduler
         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));
index 9a7f9b29b0e27216d2cdfc0f528e7408d8ac646a..d09d22482ddc44833770be6d64cec571f6e76e49 100644 (file)
@@ -11,9 +11,7 @@ import static org.junit.Assert.assertTrue;
 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;
@@ -43,26 +41,26 @@ public class PCEPTunnelTopologyProviderModuleTest extends AbstractInstructionSch
         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
@@ -75,11 +73,11 @@ public class PCEPTunnelTopologyProviderModuleTest extends AbstractInstructionSch
         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();
     }