From 587f3257393e79c720f88d41b8f3f65a600d32df Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 4 Jan 2019 15:24:23 +0100 Subject: [PATCH] Specialize protocol-framework to netconf As a first step towards sanity, we eliminate protocol-framwork by moving it into netconf-api, but specialized to deal with NETCONF protocol only. This eliminates one level of abstraction, allowing us to reduce the number of classes and artifacts involved. We also sacrifice tests, as most of the mechanics should be covered by netconf-level tests. JIRA: NETCONF-554 Change-Id: Iba41c5ad72a0148d4e1d768d3122ddebce18f4c2 Signed-off-by: Robert Varga --- features/netconf/odl-netconf-api/pom.xml | 7 - features/pom.xml | 1 - .../features-protocol-framework/pom.xml | 34 --- .../odl-protocol-framework/pom.xml | 46 ---- features/protocol-framework/pom.xml | 39 --- .../ReverseSshChannelInitializer.java | 5 +- .../mount/CallHomeMountDispatcherTest.java | 3 +- netconf/netconf-api/pom.xml | 9 +- .../netconf/api/NetconfSession.java | 15 +- .../netconf/api/NetconfSessionListener.java | 35 ++- .../api/NetconfSessionListenerFactory.java | 8 +- .../netconf/api/NetconfTerminationReason.java | 10 +- netconf/netconf-artifacts/pom.xml | 19 -- .../client/NetconfClientDispatcherImpl.java | 6 +- ...NetconfClientSessionNegotiatorFactory.java | 13 +- .../conf/NetconfClientConfiguration.java | 2 +- .../NetconfClientConfigurationBuilder.java | 2 +- ...etconfReconnectingClientConfiguration.java | 4 +- ...econnectingClientConfigurationBuilder.java | 4 +- .../NetconfClientConfigurationTest.java | 2 +- .../NetconfClientDispatcherImplTest.java | 4 +- ...onfClientSessionNegotiatorFactoryTest.java | 10 +- ...nfReconnectingClientConfigurationTest.java | 4 +- .../SshClientChannelInitializerTest.java | 10 +- .../TcpClientChannelInitializerTest.java | 12 +- .../netconf/client/TestingNetconfClient.java | 2 +- .../TlsClientChannelInitializerTest.java | 19 +- .../impl/NetconfServerDispatcherImpl.java | 5 +- ...NetconfServerSessionNegotiatorFactory.java | 14 +- .../netconf/impl/ConcurrentClientsTest.java | 2 +- .../nettyutil/AbstractNetconfDispatcher.java | 115 ++++---- .../nettyutil/AbstractNetconfSession.java | 34 ++- .../AbstractNetconfSessionNegotiator.java | 85 +++++- .../nettyutil/NetconfSessionNegotiator.java | 5 +- .../NetconfSessionNegotiatorFactory.java | 11 +- .../nettyutil/NetconfSessionPromise.java | 58 ++-- .../nettyutil}/NeverReconnectStrategy.java | 6 +- .../ReconnectImmediatelyStrategy.java | 7 +- .../netconf/nettyutil}/ReconnectPromise.java | 43 +-- .../netconf/nettyutil}/ReconnectStrategy.java | 3 +- .../nettyutil}/ReconnectStrategyFactory.java | 2 +- .../nettyutil}/TimedReconnectStrategy.java | 28 +- .../TimedReconnectStrategyFactory.java | 2 +- .../impl/RemoteDeviceConnectorImpl.java | 4 +- .../topology/AbstractNetconfTopology.java | 4 +- .../NetconfDeviceCommunicatorTest.java | 5 +- .../client/stress/StressClientCallable.java | 2 +- pom.xml | 1 - protocol-framework/.gitignore | 3 - protocol-framework/pom.xml | 92 ------- .../framework/AbstractProtocolSession.java | 60 ----- .../framework/AbstractSessionNegotiator.java | 98 ------- .../protocol/framework/ProtocolSession.java | 24 -- .../protocol/framework/SessionListener.java | 49 ---- .../protocol/framework/TerminationReason.java | 22 -- .../protocol/framework/ServerTest.java | 251 ------------------ .../protocol/framework/Session.java | 46 ---- .../framework/SimpleByteToMessageDecoder.java | 22 -- .../protocol/framework/SimpleDispatcher.java | 66 ----- .../protocol/framework/SimpleMessage.java | 22 -- .../framework/SimpleMessageToByteEncoder.java | 22 -- .../protocol/framework/SimpleSession.java | 31 --- .../framework/SimpleSessionListener.java | 50 ---- .../SimpleSessionListenerFactory.java | 17 -- .../framework/SimpleSessionNegotiator.java | 29 -- .../src/test/resources/logback-test.xml | 13 - 66 files changed, 364 insertions(+), 1314 deletions(-) delete mode 100644 features/protocol-framework/features-protocol-framework/pom.xml delete mode 100644 features/protocol-framework/odl-protocol-framework/pom.xml delete mode 100644 features/protocol-framework/pom.xml rename protocol-framework/src/main/java/org/opendaylight/protocol/framework/SessionListenerFactory.java => netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/NetconfSessionListenerFactory.java (78%) rename protocol-framework/src/main/java/org/opendaylight/protocol/framework/AbstractDispatcher.java => netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfDispatcher.java (73%) rename protocol-framework/src/main/java/org/opendaylight/protocol/framework/SessionNegotiator.java => netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NetconfSessionNegotiator.java (77%) rename protocol-framework/src/main/java/org/opendaylight/protocol/framework/SessionNegotiatorFactory.java => netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NetconfSessionNegotiatorFactory.java (60%) rename protocol-framework/src/main/java/org/opendaylight/protocol/framework/ProtocolSessionPromise.java => netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NetconfSessionPromise.java (74%) rename {protocol-framework/src/main/java/org/opendaylight/protocol/framework => netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil}/NeverReconnectStrategy.java (96%) rename {protocol-framework/src/main/java/org/opendaylight/protocol/framework => netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil}/ReconnectImmediatelyStrategy.java (97%) rename {protocol-framework/src/main/java/org/opendaylight/protocol/framework => netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil}/ReconnectPromise.java (70%) rename {protocol-framework/src/main/java/org/opendaylight/protocol/framework => netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil}/ReconnectStrategy.java (97%) rename {protocol-framework/src/main/java/org/opendaylight/protocol/framework => netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil}/ReconnectStrategyFactory.java (94%) rename {protocol-framework/src/main/java/org/opendaylight/protocol/framework => netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil}/TimedReconnectStrategy.java (93%) rename {protocol-framework/src/main/java/org/opendaylight/protocol/framework => netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil}/TimedReconnectStrategyFactory.java (96%) delete mode 100644 protocol-framework/.gitignore delete mode 100644 protocol-framework/pom.xml delete mode 100644 protocol-framework/src/main/java/org/opendaylight/protocol/framework/AbstractProtocolSession.java delete mode 100644 protocol-framework/src/main/java/org/opendaylight/protocol/framework/AbstractSessionNegotiator.java delete mode 100644 protocol-framework/src/main/java/org/opendaylight/protocol/framework/ProtocolSession.java delete mode 100644 protocol-framework/src/main/java/org/opendaylight/protocol/framework/SessionListener.java delete mode 100644 protocol-framework/src/main/java/org/opendaylight/protocol/framework/TerminationReason.java delete mode 100644 protocol-framework/src/test/java/org/opendaylight/protocol/framework/ServerTest.java delete mode 100644 protocol-framework/src/test/java/org/opendaylight/protocol/framework/Session.java delete mode 100644 protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleByteToMessageDecoder.java delete mode 100644 protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleDispatcher.java delete mode 100644 protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleMessage.java delete mode 100644 protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleMessageToByteEncoder.java delete mode 100644 protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleSession.java delete mode 100644 protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleSessionListener.java delete mode 100644 protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleSessionListenerFactory.java delete mode 100644 protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleSessionNegotiator.java delete mode 100644 protocol-framework/src/test/resources/logback-test.xml diff --git a/features/netconf/odl-netconf-api/pom.xml b/features/netconf/odl-netconf-api/pom.xml index f08cf2bbe0..500bdb2292 100644 --- a/features/netconf/odl-netconf-api/pom.xml +++ b/features/netconf/odl-netconf-api/pom.xml @@ -56,12 +56,6 @@ xml features - - org.opendaylight.netconf - odl-protocol-framework - xml - features - org.opendaylight.mdsal.model odl-mdsal-model-rfc7895 @@ -69,7 +63,6 @@ features - org.opendaylight.netconf netconf-api diff --git a/features/pom.xml b/features/pom.xml index 1ca1efdc6c..c37a6f36db 100644 --- a/features/pom.xml +++ b/features/pom.xml @@ -28,7 +28,6 @@ netconf netconf-connector - protocol-framework restconf yanglib diff --git a/features/protocol-framework/features-protocol-framework/pom.xml b/features/protocol-framework/features-protocol-framework/pom.xml deleted file mode 100644 index f1bb5078bd..0000000000 --- a/features/protocol-framework/features-protocol-framework/pom.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - 4.0.0 - - - org.opendaylight.odlparent - feature-repo-parent - 4.0.7 - - - - org.opendaylight.netconf - features-protocol-framework - 1.3.0-SNAPSHOT - feature - - - - org.opendaylight.netconf - odl-protocol-framework - 1.3.0-SNAPSHOT - xml - features - - - - diff --git a/features/protocol-framework/odl-protocol-framework/pom.xml b/features/protocol-framework/odl-protocol-framework/pom.xml deleted file mode 100644 index 92268243d8..0000000000 --- a/features/protocol-framework/odl-protocol-framework/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - 4.0.0 - - - org.opendaylight.odlparent - single-feature-parent - 4.0.7 - - - - org.opendaylight.netconf - odl-protocol-framework - 1.3.0-SNAPSHOT - feature - - OpenDaylight :: Protocol Framework - - - - org.opendaylight.odlparent - odl-netty-4 - xml - features - - - org.opendaylight.odlparent - odl-guava - xml - features - - - org.opendaylight.netconf - protocol-framework - ${project.version} - - - - diff --git a/features/protocol-framework/pom.xml b/features/protocol-framework/pom.xml deleted file mode 100644 index 83c1c8e6a3..0000000000 --- a/features/protocol-framework/pom.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - 4.0.0 - - org.opendaylight.odlparent - odlparent-lite - 4.0.7 - - - - org.opendaylight.netconf - features-protocol-framework-aggregator - 1.3.0-SNAPSHOT - pom - - - true - true - - - - features-protocol-framework - odl-protocol-framework - - - - scm:git:ssh://git.opendaylight.org:29418/netconf.git - scm:git:ssh://git.opendaylight.org:29418/netconf.git - HEAD - https://git.opendaylight.org/gerrit/gitweb?p=netconf.git;a=summary - - diff --git a/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/ReverseSshChannelInitializer.java b/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/ReverseSshChannelInitializer.java index 09b88a944a..9a5e10f506 100644 --- a/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/ReverseSshChannelInitializer.java +++ b/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/ReverseSshChannelInitializer.java @@ -5,19 +5,18 @@ * 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.netconf.callhome.protocol; import io.netty.channel.Channel; import io.netty.util.concurrent.Promise; +import org.opendaylight.netconf.api.NetconfSessionListenerFactory; import org.opendaylight.netconf.client.NetconfClientSession; import org.opendaylight.netconf.client.NetconfClientSessionListener; import org.opendaylight.netconf.client.NetconfClientSessionNegotiatorFactory; import org.opendaylight.netconf.nettyutil.AbstractChannelInitializer; -import org.opendaylight.protocol.framework.SessionListenerFactory; final class ReverseSshChannelInitializer extends AbstractChannelInitializer - implements SessionListenerFactory { + implements NetconfSessionListenerFactory { private final NetconfClientSessionNegotiatorFactory negotiatorFactory; private final NetconfClientSessionListener sessionListener; diff --git a/netconf/callhome-provider/src/test/java/org/opendaylight/netconf/callhome/mount/CallHomeMountDispatcherTest.java b/netconf/callhome-provider/src/test/java/org/opendaylight/netconf/callhome/mount/CallHomeMountDispatcherTest.java index b9e5e3f7c5..ecac3cc607 100644 --- a/netconf/callhome-provider/src/test/java/org/opendaylight/netconf/callhome/mount/CallHomeMountDispatcherTest.java +++ b/netconf/callhome-provider/src/test/java/org/opendaylight/netconf/callhome/mount/CallHomeMountDispatcherTest.java @@ -5,7 +5,6 @@ * 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.netconf.callhome.mount; import static org.junit.Assert.assertFalse; @@ -34,9 +33,9 @@ import org.opendaylight.netconf.client.NetconfClientSession; import org.opendaylight.netconf.client.NetconfClientSessionListener; import org.opendaylight.netconf.client.conf.NetconfClientConfiguration; import org.opendaylight.netconf.client.conf.NetconfClientConfigurationBuilder; +import org.opendaylight.netconf.nettyutil.ReconnectStrategy; import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler; import org.opendaylight.netconf.topology.api.SchemaRepositoryProvider; -import org.opendaylight.protocol.framework.ReconnectStrategy; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; diff --git a/netconf/netconf-api/pom.xml b/netconf/netconf-api/pom.xml index 51d2063d2e..5c54f5b93e 100644 --- a/netconf/netconf-api/pom.xml +++ b/netconf/netconf-api/pom.xml @@ -24,16 +24,17 @@ - ${project.groupId} - ietf-netconf-monitoring + io.netty + netty-transport + ${project.groupId} - ietf-netconf-monitoring-extension + ietf-netconf-monitoring ${project.groupId} - protocol-framework + ietf-netconf-monitoring-extension org.opendaylight.mdsal.binding.model.ietf diff --git a/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/NetconfSession.java b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/NetconfSession.java index bfa8bfeb66..182740b699 100644 --- a/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/NetconfSession.java +++ b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/NetconfSession.java @@ -8,10 +8,21 @@ package org.opendaylight.netconf.api; import io.netty.channel.ChannelFuture; -import org.opendaylight.protocol.framework.ProtocolSession; +import java.io.Closeable; -public interface NetconfSession extends ProtocolSession { +/** + * Protocol Session represents the finite state machine in underlying protocol, including timers and its purpose is to + * create a connection between server and client. Session is automatically started, when TCP connection is created, but + * can be stopped manually. If the session is up, it has to redirect messages to/from user. Handles also malformed + * messages and unknown requests. + * + *

+ * This interface should be implemented by a final class representing a protocol specific session. + */ +public interface NetconfSession extends Closeable { ChannelFuture sendMessage(NetconfMessage message); + @Override + void close(); } diff --git a/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/NetconfSessionListener.java b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/NetconfSessionListener.java index bfd1dbf0af..6f64fc5b73 100644 --- a/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/NetconfSessionListener.java +++ b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/NetconfSessionListener.java @@ -5,11 +5,38 @@ * 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.netconf.api; -import org.opendaylight.protocol.framework.SessionListener; +// FIXME: NETCONF-554: rework this interface +public interface NetconfSessionListener { + /** + * Fired when the session was established successfully. + * + * @param session New session + */ + void onSessionUp(S session); + + /** + * Fired when the session went down because of an IO error. Implementation should take care of closing underlying + * session. + * + * @param session that went down + * @param cause Exception that was thrown as the cause of session being down + */ + void onSessionDown(S session, Exception cause); + + /** + * Fired when the session is terminated locally. The session has already been closed and transitioned to IDLE state. + * Any outstanding queued messages were not sent. The user should not attempt to make any use of the session. + * + * @param reason the cause why the session went down + */ + void onSessionTerminated(S session, NetconfTerminationReason reason); -public interface NetconfSessionListener - extends SessionListener { + /** + * Fired when a normal protocol message is received. + * + * @param message Protocol message + */ + void onMessage(S session, NetconfMessage message); } diff --git a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/SessionListenerFactory.java b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/NetconfSessionListenerFactory.java similarity index 78% rename from protocol-framework/src/main/java/org/opendaylight/protocol/framework/SessionListenerFactory.java rename to netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/NetconfSessionListenerFactory.java index 99087a5434..a069968052 100644 --- a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/SessionListenerFactory.java +++ b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/NetconfSessionListenerFactory.java @@ -5,8 +5,7 @@ * 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.framework; - +package org.opendaylight.netconf.api; /** * Factory for generating Session Listeners. Used by a server. This interface should be @@ -14,9 +13,10 @@ package org.opendaylight.protocol.framework; * a final class that implements the methods. */ @Deprecated -public interface SessionListenerFactory> { +public interface NetconfSessionListenerFactory> { /** - * Returns one session listener + * Returns one session listener. + * * @return specific session listener */ T getSessionListener(); diff --git a/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/NetconfTerminationReason.java b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/NetconfTerminationReason.java index 697acdf694..62024fa1b1 100644 --- a/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/NetconfTerminationReason.java +++ b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/NetconfTerminationReason.java @@ -5,12 +5,9 @@ * 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.netconf.api; -import org.opendaylight.protocol.framework.TerminationReason; - -public class NetconfTerminationReason implements TerminationReason { +public class NetconfTerminationReason { private final String reason; @@ -18,7 +15,10 @@ public class NetconfTerminationReason implements TerminationReason { this.reason = reason; } - @Override + /** + * Get cause of session termination. + * @return human-readable cause. + */ public String getErrorMessage() { return reason; } diff --git a/netconf/netconf-artifacts/pom.xml b/netconf/netconf-artifacts/pom.xml index 259d497355..2e558438f5 100644 --- a/netconf/netconf-artifacts/pom.xml +++ b/netconf/netconf-artifacts/pom.xml @@ -252,27 +252,8 @@ netconf-topology-singleton ${project.version} - - ${project.groupId} - protocol-framework - 1.3.0-SNAPSHOT - - - ${project.groupId} - features-protocol-framework - 1.3.0-SNAPSHOT - xml - features - - - ${project.groupId} - odl-protocol-framework - 1.3.0-SNAPSHOT - xml - features - ${project.groupId} features-netconf diff --git a/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/NetconfClientDispatcherImpl.java b/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/NetconfClientDispatcherImpl.java index b8fdee2054..2f76f2b8b7 100644 --- a/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/NetconfClientDispatcherImpl.java +++ b/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/NetconfClientDispatcherImpl.java @@ -5,7 +5,6 @@ * 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.netconf.client; import io.netty.channel.EventLoopGroup; @@ -16,12 +15,13 @@ import java.util.List; import java.util.Set; import org.opendaylight.netconf.client.conf.NetconfClientConfiguration; import org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration; -import org.opendaylight.protocol.framework.AbstractDispatcher; +import org.opendaylight.netconf.nettyutil.AbstractNetconfDispatcher; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class NetconfClientDispatcherImpl extends AbstractDispatcher +public class NetconfClientDispatcherImpl + extends AbstractNetconfDispatcher implements NetconfClientDispatcher { private static final Logger LOG = LoggerFactory.getLogger(NetconfClientDispatcherImpl.class); diff --git a/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/NetconfClientSessionNegotiatorFactory.java b/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/NetconfClientSessionNegotiatorFactory.java index d6cc5b18c7..2e8a90719f 100644 --- a/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/NetconfClientSessionNegotiatorFactory.java +++ b/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/NetconfClientSessionNegotiatorFactory.java @@ -20,19 +20,18 @@ import io.netty.util.concurrent.Promise; import java.util.Set; import org.opendaylight.netconf.api.NetconfClientSessionPreferences; import org.opendaylight.netconf.api.NetconfMessage; +import org.opendaylight.netconf.api.NetconfSessionListenerFactory; import org.opendaylight.netconf.api.messages.NetconfHelloMessage; import org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader; import org.opendaylight.netconf.api.xml.XmlNetconfConstants; +import org.opendaylight.netconf.nettyutil.NetconfSessionNegotiatorFactory; import org.opendaylight.netconf.nettyutil.handler.exi.EXIParameters; import org.opendaylight.netconf.nettyutil.handler.exi.NetconfStartExiMessage; -import org.opendaylight.protocol.framework.SessionListenerFactory; -import org.opendaylight.protocol.framework.SessionNegotiator; -import org.opendaylight.protocol.framework.SessionNegotiatorFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class NetconfClientSessionNegotiatorFactory implements SessionNegotiatorFactory { +public class NetconfClientSessionNegotiatorFactory + implements NetconfSessionNegotiatorFactory { public static final Set EXI_CLIENT_CAPABILITIES = ImmutableSet.of( XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_0, @@ -104,8 +103,8 @@ public class NetconfClientSessionNegotiatorFactory implements SessionNegotiatorF } @Override - public SessionNegotiator getSessionNegotiator( - final SessionListenerFactory sessionListenerFactory, + public NetconfClientSessionNegotiator getSessionNegotiator( + final NetconfSessionListenerFactory sessionListenerFactory, final Channel channel, final Promise promise) { NetconfMessage startExiMessage = NetconfStartExiMessage.create(options, START_EXI_MESSAGE_ID); diff --git a/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/conf/NetconfClientConfiguration.java b/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/conf/NetconfClientConfiguration.java index b14d152e25..756789a8e0 100644 --- a/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/conf/NetconfClientConfiguration.java +++ b/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/conf/NetconfClientConfiguration.java @@ -16,8 +16,8 @@ import java.util.List; import org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader; import org.opendaylight.netconf.client.NetconfClientSessionListener; import org.opendaylight.netconf.client.SslHandlerFactory; +import org.opendaylight.netconf.nettyutil.ReconnectStrategy; import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler; -import org.opendaylight.protocol.framework.ReconnectStrategy; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/conf/NetconfClientConfigurationBuilder.java b/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/conf/NetconfClientConfigurationBuilder.java index 9e86c9c4b2..d79d5d5cc9 100644 --- a/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/conf/NetconfClientConfigurationBuilder.java +++ b/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/conf/NetconfClientConfigurationBuilder.java @@ -12,8 +12,8 @@ import java.util.List; import org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader; import org.opendaylight.netconf.client.NetconfClientSessionListener; import org.opendaylight.netconf.client.SslHandlerFactory; +import org.opendaylight.netconf.nettyutil.ReconnectStrategy; import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler; -import org.opendaylight.protocol.framework.ReconnectStrategy; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri; public class NetconfClientConfigurationBuilder { diff --git a/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/conf/NetconfReconnectingClientConfiguration.java b/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/conf/NetconfReconnectingClientConfiguration.java index c688534923..c43cd2d2b9 100644 --- a/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/conf/NetconfReconnectingClientConfiguration.java +++ b/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/conf/NetconfReconnectingClientConfiguration.java @@ -14,9 +14,9 @@ import java.util.List; import org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader; import org.opendaylight.netconf.client.NetconfClientSessionListener; import org.opendaylight.netconf.client.SslHandlerFactory; +import org.opendaylight.netconf.nettyutil.ReconnectStrategy; +import org.opendaylight.netconf.nettyutil.ReconnectStrategyFactory; import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler; -import org.opendaylight.protocol.framework.ReconnectStrategy; -import org.opendaylight.protocol.framework.ReconnectStrategyFactory; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri; public final class NetconfReconnectingClientConfiguration extends NetconfClientConfiguration { diff --git a/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/conf/NetconfReconnectingClientConfigurationBuilder.java b/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/conf/NetconfReconnectingClientConfigurationBuilder.java index 670c893a00..a23996c955 100644 --- a/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/conf/NetconfReconnectingClientConfigurationBuilder.java +++ b/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/conf/NetconfReconnectingClientConfigurationBuilder.java @@ -12,9 +12,9 @@ import java.util.List; import org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader; import org.opendaylight.netconf.client.NetconfClientSessionListener; import org.opendaylight.netconf.client.SslHandlerFactory; +import org.opendaylight.netconf.nettyutil.ReconnectStrategy; +import org.opendaylight.netconf.nettyutil.ReconnectStrategyFactory; import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler; -import org.opendaylight.protocol.framework.ReconnectStrategy; -import org.opendaylight.protocol.framework.ReconnectStrategyFactory; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri; public final class NetconfReconnectingClientConfigurationBuilder extends NetconfClientConfigurationBuilder { diff --git a/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/NetconfClientConfigurationTest.java b/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/NetconfClientConfigurationTest.java index f7e63bb896..2e2f7203cb 100644 --- a/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/NetconfClientConfigurationTest.java +++ b/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/NetconfClientConfigurationTest.java @@ -16,8 +16,8 @@ import org.mockito.Mockito; import org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader; import org.opendaylight.netconf.client.conf.NetconfClientConfiguration; import org.opendaylight.netconf.client.conf.NetconfClientConfigurationBuilder; +import org.opendaylight.netconf.nettyutil.ReconnectStrategy; import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler; -import org.opendaylight.protocol.framework.ReconnectStrategy; public class NetconfClientConfigurationTest { @Test diff --git a/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/NetconfClientDispatcherImplTest.java b/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/NetconfClientDispatcherImplTest.java index 3a1e0d7024..172871a566 100644 --- a/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/NetconfClientDispatcherImplTest.java +++ b/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/NetconfClientDispatcherImplTest.java @@ -27,9 +27,9 @@ import org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader import org.opendaylight.netconf.client.conf.NetconfClientConfiguration; import org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration; import org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfigurationBuilder; +import org.opendaylight.netconf.nettyutil.ReconnectStrategy; +import org.opendaylight.netconf.nettyutil.ReconnectStrategyFactory; import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler; -import org.opendaylight.protocol.framework.ReconnectStrategy; -import org.opendaylight.protocol.framework.ReconnectStrategyFactory; public class NetconfClientDispatcherImplTest { @Test diff --git a/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/NetconfClientSessionNegotiatorFactoryTest.java b/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/NetconfClientSessionNegotiatorFactoryTest.java index ca9eb2cefe..a033ea5c4b 100644 --- a/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/NetconfClientSessionNegotiatorFactoryTest.java +++ b/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/NetconfClientSessionNegotiatorFactoryTest.java @@ -18,15 +18,15 @@ import io.netty.util.HashedWheelTimer; import io.netty.util.Timer; import io.netty.util.concurrent.Promise; import org.junit.Test; -import org.opendaylight.protocol.framework.SessionListenerFactory; -import org.opendaylight.protocol.framework.SessionNegotiator; +import org.opendaylight.netconf.api.NetconfSessionListenerFactory; public class NetconfClientSessionNegotiatorFactoryTest { @Test public void testGetSessionNegotiator() throws Exception { NetconfClientSessionListener sessionListener = mock(NetconfClientSessionListener.class); Timer timer = new HashedWheelTimer(); - SessionListenerFactory listenerFactory = mock(SessionListenerFactory.class); + NetconfSessionListenerFactory listenerFactory = + mock(NetconfSessionListenerFactory.class); doReturn(sessionListener).when(listenerFactory).getSessionListener(); Channel channel = mock(Channel.class); @@ -34,8 +34,8 @@ public class NetconfClientSessionNegotiatorFactoryTest { NetconfClientSessionNegotiatorFactory negotiatorFactory = new NetconfClientSessionNegotiatorFactory(timer, Optional.absent(), 200L); - SessionNegotiator sessionNegotiator = negotiatorFactory.getSessionNegotiator(listenerFactory, channel, - promise); + NetconfClientSessionNegotiator sessionNegotiator = negotiatorFactory.getSessionNegotiator(listenerFactory, + channel, promise); assertNotNull(sessionNegotiator); } } diff --git a/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/NetconfReconnectingClientConfigurationTest.java b/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/NetconfReconnectingClientConfigurationTest.java index 406c19a8c3..be654a340c 100644 --- a/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/NetconfReconnectingClientConfigurationTest.java +++ b/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/NetconfReconnectingClientConfigurationTest.java @@ -17,9 +17,9 @@ import org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader import org.opendaylight.netconf.client.conf.NetconfClientConfiguration; import org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration; import org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfigurationBuilder; +import org.opendaylight.netconf.nettyutil.ReconnectStrategy; +import org.opendaylight.netconf.nettyutil.ReconnectStrategyFactory; import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler; -import org.opendaylight.protocol.framework.ReconnectStrategy; -import org.opendaylight.protocol.framework.ReconnectStrategyFactory; public class NetconfReconnectingClientConfigurationTest { @Test diff --git a/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/SshClientChannelInitializerTest.java b/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/SshClientChannelInitializerTest.java index 80e6d0450e..a13abada42 100644 --- a/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/SshClientChannelInitializerTest.java +++ b/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/SshClientChannelInitializerTest.java @@ -5,7 +5,6 @@ * 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.netconf.client; import static org.mockito.ArgumentMatchers.any; @@ -20,9 +19,8 @@ import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelPipeline; import io.netty.util.concurrent.Promise; import org.junit.Test; +import org.opendaylight.netconf.api.NetconfSessionListenerFactory; import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler; -import org.opendaylight.protocol.framework.SessionListenerFactory; -import org.opendaylight.protocol.framework.SessionNegotiator; public class SshClientChannelInitializerTest { @Test @@ -32,10 +30,10 @@ public class SshClientChannelInitializerTest { NetconfClientSessionNegotiatorFactory negotiatorFactory = mock(NetconfClientSessionNegotiatorFactory.class); NetconfClientSessionListener sessionListener = mock(NetconfClientSessionListener.class); - SessionNegotiator sessionNegotiator = mock(SessionNegotiator.class); + NetconfClientSessionNegotiator sessionNegotiator = mock(NetconfClientSessionNegotiator.class); doReturn("").when(sessionNegotiator).toString(); - doReturn(sessionNegotiator).when(negotiatorFactory).getSessionNegotiator(any(SessionListenerFactory.class), - any(Channel.class), any(Promise.class)); + doReturn(sessionNegotiator).when(negotiatorFactory).getSessionNegotiator( + any(NetconfSessionListenerFactory.class), any(Channel.class), any(Promise.class)); ChannelPipeline pipeline = mock(ChannelPipeline.class); doReturn(pipeline).when(pipeline).addAfter(anyString(), anyString(), any(ChannelHandler.class)); Channel channel = mock(Channel.class); diff --git a/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/TcpClientChannelInitializerTest.java b/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/TcpClientChannelInitializerTest.java index 7ff2f17473..000cfbef3d 100644 --- a/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/TcpClientChannelInitializerTest.java +++ b/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/TcpClientChannelInitializerTest.java @@ -5,11 +5,10 @@ * 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.netconf.client; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -20,16 +19,15 @@ import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelPipeline; import io.netty.util.concurrent.Promise; import org.junit.Test; -import org.opendaylight.protocol.framework.SessionListenerFactory; -import org.opendaylight.protocol.framework.SessionNegotiator; +import org.opendaylight.netconf.api.NetconfSessionListenerFactory; public class TcpClientChannelInitializerTest { @Test public void testInitializeSessionNegotiator() throws Exception { NetconfClientSessionNegotiatorFactory factory = mock(NetconfClientSessionNegotiatorFactory.class); - SessionNegotiator sessionNegotiator = mock(SessionNegotiator.class); + NetconfClientSessionNegotiator sessionNegotiator = mock(NetconfClientSessionNegotiator.class); doReturn("").when(sessionNegotiator).toString(); - doReturn(sessionNegotiator).when(factory).getSessionNegotiator(any(SessionListenerFactory.class), + doReturn(sessionNegotiator).when(factory).getSessionNegotiator(any(NetconfSessionListenerFactory.class), any(Channel.class), any(Promise.class)); NetconfClientSessionListener listener = mock(NetconfClientSessionListener.class); final TcpClientChannelInitializer initializer = new TcpClientChannelInitializer(factory, listener); diff --git a/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/TestingNetconfClient.java b/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/TestingNetconfClient.java index 094b570700..4a3a38edf8 100644 --- a/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/TestingNetconfClient.java +++ b/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/TestingNetconfClient.java @@ -29,9 +29,9 @@ import org.opendaylight.netconf.api.NetconfMessage; import org.opendaylight.netconf.client.conf.NetconfClientConfiguration; import org.opendaylight.netconf.client.conf.NetconfClientConfiguration.NetconfClientProtocol; import org.opendaylight.netconf.client.conf.NetconfClientConfigurationBuilder; +import org.opendaylight.netconf.nettyutil.NeverReconnectStrategy; import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler; import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.LoginPasswordHandler; -import org.opendaylight.protocol.framework.NeverReconnectStrategy; /** diff --git a/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/TlsClientChannelInitializerTest.java b/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/TlsClientChannelInitializerTest.java index da238bf90d..e6a518e4cb 100644 --- a/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/TlsClientChannelInitializerTest.java +++ b/netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/TlsClientChannelInitializerTest.java @@ -18,13 +18,13 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelPipeline; import io.netty.util.concurrent.Promise; -import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.opendaylight.protocol.framework.SessionListenerFactory; -import org.opendaylight.protocol.framework.SessionNegotiator; +import org.mockito.junit.MockitoJUnitRunner; +import org.opendaylight.netconf.api.NetconfSessionListenerFactory; +@RunWith(MockitoJUnitRunner.class) public class TlsClientChannelInitializerTest { @Mock private SslHandlerFactory sslHandlerFactory; @@ -33,17 +33,12 @@ public class TlsClientChannelInitializerTest { @Mock private NetconfClientSessionListener sessionListener; - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - } - @SuppressWarnings("unchecked") @Test public void testInitialize() throws Exception { - SessionNegotiator sessionNegotiator = mock(SessionNegotiator.class); - doReturn(sessionNegotiator).when(negotiatorFactory).getSessionNegotiator(any(SessionListenerFactory.class), - any(Channel.class), any(Promise.class)); + NetconfClientSessionNegotiator sessionNegotiator = mock(NetconfClientSessionNegotiator.class); + doReturn(sessionNegotiator).when(negotiatorFactory).getSessionNegotiator( + any(NetconfSessionListenerFactory.class), any(Channel.class), any(Promise.class)); ChannelPipeline pipeline = mock(ChannelPipeline.class); doReturn(pipeline).when(pipeline).addAfter(anyString(), anyString(), any(ChannelHandler.class)); Channel channel = mock(Channel.class); diff --git a/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/NetconfServerDispatcherImpl.java b/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/NetconfServerDispatcherImpl.java index 394771b122..67fd0208f8 100644 --- a/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/NetconfServerDispatcherImpl.java +++ b/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/NetconfServerDispatcherImpl.java @@ -5,7 +5,6 @@ * 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.netconf.impl; import io.netty.channel.Channel; @@ -18,9 +17,9 @@ import java.net.InetSocketAddress; import org.opendaylight.netconf.api.NetconfServerDispatcher; import org.opendaylight.netconf.impl.util.DeserializerExceptionHandler; import org.opendaylight.netconf.nettyutil.AbstractChannelInitializer; -import org.opendaylight.protocol.framework.AbstractDispatcher; +import org.opendaylight.netconf.nettyutil.AbstractNetconfDispatcher; -public class NetconfServerDispatcherImpl extends AbstractDispatcher implements NetconfServerDispatcher { private final ServerChannelInitializer initializer; diff --git a/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/NetconfServerSessionNegotiatorFactory.java b/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/NetconfServerSessionNegotiatorFactory.java index dbe9c0b7ee..619f97a6d4 100644 --- a/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/NetconfServerSessionNegotiatorFactory.java +++ b/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/NetconfServerSessionNegotiatorFactory.java @@ -5,7 +5,6 @@ * 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.netconf.impl; import com.google.common.base.Preconditions; @@ -18,6 +17,7 @@ import io.netty.util.concurrent.Promise; import java.net.SocketAddress; import java.util.Set; import org.opendaylight.netconf.api.NetconfServerSessionPreferences; +import org.opendaylight.netconf.api.NetconfSessionListenerFactory; import org.opendaylight.netconf.api.messages.NetconfHelloMessage; import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService; import org.opendaylight.netconf.api.xml.XmlNetconfConstants; @@ -25,14 +25,12 @@ import org.opendaylight.netconf.impl.osgi.NetconfOperationRouter; import org.opendaylight.netconf.impl.osgi.NetconfOperationRouterImpl; import org.opendaylight.netconf.mapping.api.NetconfOperationService; import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory; -import org.opendaylight.protocol.framework.SessionListenerFactory; -import org.opendaylight.protocol.framework.SessionNegotiator; -import org.opendaylight.protocol.framework.SessionNegotiatorFactory; +import org.opendaylight.netconf.nettyutil.NetconfSessionNegotiatorFactory; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Capabilities; -public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorFactory { +public class NetconfServerSessionNegotiatorFactory + implements NetconfSessionNegotiatorFactory { public static final Set DEFAULT_BASE_CAPABILITIES = ImmutableSet.of( XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_0, @@ -95,8 +93,8 @@ public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorF * @return session negotiator */ @Override - public SessionNegotiator getSessionNegotiator( - final SessionListenerFactory defunctSessionListenerFactory, + public NetconfServerSessionNegotiator getSessionNegotiator( + final NetconfSessionListenerFactory defunctSessionListenerFactory, final Channel channel, final Promise promise) { final long sessionId = idProvider.getNextSessionId(); diff --git a/netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/ConcurrentClientsTest.java b/netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/ConcurrentClientsTest.java index a9fcf4731f..bd9eb070d1 100644 --- a/netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/ConcurrentClientsTest.java +++ b/netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/ConcurrentClientsTest.java @@ -69,10 +69,10 @@ import org.opendaylight.netconf.mapping.api.NetconfOperation; import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution; import org.opendaylight.netconf.mapping.api.NetconfOperationService; import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory; +import org.opendaylight.netconf.nettyutil.NeverReconnectStrategy; import org.opendaylight.netconf.nettyutil.handler.exi.NetconfStartExiMessage; import org.opendaylight.netconf.util.messages.NetconfMessageUtil; import org.opendaylight.netconf.util.test.XmlFileLoader; -import org.opendaylight.protocol.framework.NeverReconnectStrategy; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.CapabilitiesBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/AbstractDispatcher.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfDispatcher.java similarity index 73% rename from protocol-framework/src/main/java/org/opendaylight/protocol/framework/AbstractDispatcher.java rename to netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfDispatcher.java index 80e30dc90c..7997095850 100644 --- a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/AbstractDispatcher.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfDispatcher.java @@ -5,7 +5,7 @@ * 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.framework; +package org.opendaylight.netconf.nettyutil; import com.google.common.base.Preconditions; import io.netty.bootstrap.Bootstrap; @@ -29,6 +29,8 @@ import io.netty.util.concurrent.Promise; import java.io.Closeable; import java.net.InetSocketAddress; import java.net.SocketAddress; +import org.opendaylight.netconf.api.NetconfSession; +import org.opendaylight.netconf.api.NetconfSessionListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,26 +39,27 @@ import org.slf4j.LoggerFactory; * start method that will handle sockets in different thread. */ @Deprecated -public abstract class AbstractDispatcher, L extends SessionListener> implements Closeable { +public abstract class AbstractNetconfDispatcher> + implements Closeable { - - protected interface ChannelPipelineInitializer> { + protected interface ChannelPipelineInitializer { /** - * Initializes channel by specifying the handlers in its pipeline. Handlers are protocol specific, therefore this - * method needs to be implemented in protocol specific Dispatchers. + * Initializes channel by specifying the handlers in its pipeline. Handlers are protocol specific, therefore + * this method needs to be implemented in protocol specific Dispatchers. * - * @param channel whose pipeline should be defined, also to be passed to {@link SessionNegotiatorFactory} - * @param promise to be passed to {@link SessionNegotiatorFactory} + * @param channel whose pipeline should be defined, also to be passed to {@link NetconfSessionNegotiatorFactory} + * @param promise to be passed to {@link NetconfSessionNegotiatorFactory} */ - void initializeChannel(CH channel, Promise promise); + void initializeChannel(C channel, Promise promise); } - protected interface PipelineInitializer> extends ChannelPipelineInitializer { + protected interface PipelineInitializer + extends ChannelPipelineInitializer { } - private static final Logger LOG = LoggerFactory.getLogger(AbstractDispatcher.class); + private static final Logger LOG = LoggerFactory.getLogger(AbstractNetconfDispatcher.class); private final EventLoopGroup bossGroup; @@ -64,11 +67,12 @@ public abstract class AbstractDispatcher, L extends private final EventExecutor executor; - protected AbstractDispatcher(final EventLoopGroup bossGroup, final EventLoopGroup workerGroup) { + protected AbstractNetconfDispatcher(final EventLoopGroup bossGroup, final EventLoopGroup workerGroup) { this(GlobalEventExecutor.INSTANCE, bossGroup, workerGroup); } - protected AbstractDispatcher(final EventExecutor executor, final EventLoopGroup bossGroup, final EventLoopGroup workerGroup) { + protected AbstractNetconfDispatcher(final EventExecutor executor, final EventLoopGroup bossGroup, + final EventLoopGroup workerGroup) { this.bossGroup = Preconditions.checkNotNull(bossGroup); this.workerGroup = Preconditions.checkNotNull(workerGroup); this.executor = Preconditions.checkNotNull(executor); @@ -96,13 +100,13 @@ public abstract class AbstractDispatcher, L extends * * @return ChannelFuture representing the binding process */ - protected ChannelFuture createServer(final SocketAddress address, final Class channelClass, - final ChannelPipelineInitializer initializer) { + protected ChannelFuture createServer(final SocketAddress address, + final Class channelClass, final ChannelPipelineInitializer initializer) { final ServerBootstrap b = new ServerBootstrap(); - b.childHandler(new ChannelInitializer() { + b.childHandler(new ChannelInitializer() { @Override - protected void initChannel(final CH ch) { + protected void initChannel(final C ch) { initializer.initializeChannel(ch, new DefaultPromise<>(executor)); } }); @@ -137,9 +141,20 @@ public abstract class AbstractDispatcher, L extends * subclasses to assign non-default server options before the server is * created. * - * @param b Server bootstrap + * @param bootstrap Server bootstrap + */ + protected void customizeBootstrap(final ServerBootstrap bootstrap) { + // The default is a no-op + } + + /** + * Customize a client bootstrap before the connection is attempted. This + * allows subclasses to assign non-default options before the client is + * created. + * + * @param bootstrap Client bootstrap */ - protected void customizeBootstrap(final ServerBootstrap b) { + protected void customizeBootstrap(final Bootstrap bootstrap) { // The default is a no-op } @@ -152,9 +167,10 @@ public abstract class AbstractDispatcher, L extends * @return Future representing the connection process. Its result represents the combined success of TCP connection * as well as session negotiation. */ - protected Future createClient(final InetSocketAddress address, final ReconnectStrategy strategy, final PipelineInitializer initializer) { + protected Future createClient(final InetSocketAddress address, final ReconnectStrategy strategy, + final PipelineInitializer initializer) { final Bootstrap b = new Bootstrap(); - final ProtocolSessionPromise p = new ProtocolSessionPromise<>(executor, address, strategy, b); + final NetconfSessionPromise p = new NetconfSessionPromise<>(executor, address, strategy, b); b.option(ChannelOption.SO_KEEPALIVE, true).handler( new ChannelInitializer() { @Override @@ -172,20 +188,15 @@ public abstract class AbstractDispatcher, L extends return p; } - private void setWorkerGroup(final Bootstrap b) { - if (b.group() == null) { - b.group(workerGroup); - } - } - /** * Create a client but use a pre-configured bootstrap. * This method however replaces the ChannelInitializer in the bootstrap. All other configuration is preserved. * * @param address remote address */ - protected Future createClient(final InetSocketAddress address, final ReconnectStrategy strategy, final Bootstrap bootstrap, final PipelineInitializer initializer) { - final ProtocolSessionPromise p = new ProtocolSessionPromise<>(executor, address, strategy, bootstrap); + protected Future createClient(final InetSocketAddress address, final ReconnectStrategy strategy, + final Bootstrap bootstrap, final PipelineInitializer initializer) { + final NetconfSessionPromise p = new NetconfSessionPromise<>(executor, address, strategy, bootstrap); bootstrap.handler( new ChannelInitializer() { @@ -201,32 +212,21 @@ public abstract class AbstractDispatcher, L extends } /** - * Customize a client bootstrap before the connection is attempted. This - * allows subclasses to assign non-default options before the client is - * created. - * - * @param b Client bootstrap - */ - protected void customizeBootstrap(final Bootstrap b) { - // The default is a no-op - } - - /** - * - * @deprecated use {@link org.opendaylight.protocol.framework.AbstractDispatcher#createReconnectingClient(java.net.InetSocketAddress, ReconnectStrategyFactory, org.opendaylight.protocol.framework.AbstractDispatcher.PipelineInitializer)} with only one reconnectStrategyFactory instead. - * * Creates a client. * * @param address remote address * @param connectStrategyFactory Factory for creating reconnection strategy to be used when initial connection fails * @param reestablishStrategy Reconnection strategy to be used when the already-established session fails - * * @return Future representing the reconnection task. It will report completion based on reestablishStrategy, e.g. * success if it indicates no further attempts should be made and failure if it reports an error + * @deprecated Use + * {@link #createReconnectingClient(InetSocketAddress, ReconnectStrategyFactory, PipelineInitializer)} + * instead. */ @Deprecated - protected Future createReconnectingClient(final InetSocketAddress address, final ReconnectStrategyFactory connectStrategyFactory, - final ReconnectStrategy reestablishStrategy, final PipelineInitializer initializer) { + protected Future createReconnectingClient(final InetSocketAddress address, + final ReconnectStrategyFactory connectStrategyFactory, final ReconnectStrategy reestablishStrategy, + final PipelineInitializer initializer) { return createReconnectingClient(address, connectStrategyFactory, initializer); } @@ -235,15 +235,15 @@ public abstract class AbstractDispatcher, L extends * * @param address remote address * @param connectStrategyFactory Factory for creating reconnection strategy for every reconnect attempt - * * @return Future representing the reconnection task. It will report completion based on reestablishStrategy, e.g. * success is never reported, only failure when it runs out of reconnection attempts. */ - protected Future createReconnectingClient(final InetSocketAddress address, final ReconnectStrategyFactory connectStrategyFactory, - final PipelineInitializer initializer) { + protected Future createReconnectingClient(final InetSocketAddress address, + final ReconnectStrategyFactory connectStrategyFactory, final PipelineInitializer initializer) { final Bootstrap b = new Bootstrap(); - final ReconnectPromise p = new ReconnectPromise<>(GlobalEventExecutor.INSTANCE, this, address, connectStrategyFactory, b, initializer); + final ReconnectPromise p = new ReconnectPromise<>(GlobalEventExecutor.INSTANCE, this, address, + connectStrategyFactory, b, initializer); b.option(ChannelOption.SO_KEEPALIVE, true); @@ -255,19 +255,22 @@ public abstract class AbstractDispatcher, L extends return p; } - private void setChannelFactory(final Bootstrap b) { + private static void setChannelFactory(final Bootstrap bootstrap) { // There is no way to detect if this was already set by // customizeBootstrap() try { - b.channel(NioSocketChannel.class); + bootstrap.channel(NioSocketChannel.class); } catch (final IllegalStateException e) { - LOG.trace("Not overriding channelFactory on bootstrap {}", b, e); + LOG.trace("Not overriding channelFactory on bootstrap {}", bootstrap, e); + } + } + + private void setWorkerGroup(final Bootstrap bootstrap) { + if (bootstrap.group() == null) { + bootstrap.group(workerGroup); } } - /** - * @deprecated Should only be used with AbstractDispatcher#AbstractDispatcher() - */ @Deprecated @Override public void close() { diff --git a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfSession.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfSession.java index e74a9a1038..f187122fdb 100644 --- a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfSession.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfSession.java @@ -12,7 +12,9 @@ import com.siemens.ct.exi.core.exceptions.UnsupportedOption; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelHandler; +import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelPromise; +import io.netty.channel.SimpleChannelInboundHandler; import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.MessageToByteEncoder; import java.io.IOException; @@ -26,12 +28,12 @@ import org.opendaylight.netconf.nettyutil.handler.NetconfEXICodec; import org.opendaylight.netconf.nettyutil.handler.NetconfEXIToMessageDecoder; import org.opendaylight.netconf.nettyutil.handler.NetconfMessageToEXIEncoder; import org.opendaylight.netconf.nettyutil.handler.exi.EXIParameters; -import org.opendaylight.protocol.framework.AbstractProtocolSession; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public abstract class AbstractNetconfSession> - extends AbstractProtocolSession implements NetconfSession, NetconfExiSession { + extends SimpleChannelInboundHandler implements NetconfSession, NetconfExiSession { + private static final Logger LOG = LoggerFactory.getLogger(AbstractNetconfSession.class); private final L sessionListener; private final long sessionId; @@ -57,7 +59,6 @@ public abstract class AbstractNetconfSession, L extends NetconfSessionListener> - extends AbstractSessionNegotiator { + extends ChannelInboundHandlerAdapter implements NetconfSessionNegotiator { private static final Logger LOG = LoggerFactory.getLogger(AbstractNetconfSessionNegotiator.class); public static final String NAME_OF_EXCEPTION_HANDLER = "lastExceptionHandler"; protected final P sessionPreferences; + protected final Channel channel; + private final Promise promise; private final L sessionListener; private Timeout timeout; @@ -61,22 +63,20 @@ public abstract class AbstractNetconfSessionNegotiator

promise; private final Timer timer; private final long connectionTimeoutMillis; protected AbstractNetconfSessionNegotiator(final P sessionPreferences, final Promise promise, final Channel channel, final Timer timer, final L sessionListener, final long connectionTimeoutMillis) { - super(promise, channel); + this.channel = requireNonNull(channel); + this.promise = requireNonNull(promise); this.sessionPreferences = sessionPreferences; - this.promise = promise; this.timer = timer; this.sessionListener = sessionListener; this.connectionTimeoutMillis = connectionTimeoutMillis; } - @Override protected final void startNegotiation() { if (ifNegotiatedAlready()) { LOG.debug("Negotiation on channel {} already started", channel); @@ -84,7 +84,7 @@ public abstract class AbstractNetconfSessionNegotiator

sslHandler = getSslHandler(channel); if (sslHandler.isPresent()) { sslHandler.get().handshakeFuture().addListener(future -> { - Preconditions.checkState(future.isSuccess(), "Ssl handshake was not successful"); + checkState(future.isSuccess(), "Ssl handshake was not successful"); LOG.debug("Ssl handshake complete"); start(); }); @@ -163,8 +163,6 @@ public abstract class AbstractNetconfSessionNegotiator

netconfMessagesFromNegotiation = ((NetconfXMLToHelloMessageDecoder) helloMessageHandler).getPostHelloNetconfMessages(); @@ -234,7 +232,7 @@ public abstract class AbstractNetconfSessionNegotiator

{ + if (!f.isSuccess()) { + LOG.info("Failed to send message {}", msg, f.cause()); + negotiationFailed(f.cause()); + } else { + LOG.trace("Message {} sent to socket", msg); + } + }); + } + + @Override + @SuppressWarnings("checkstyle:illegalCatch") + public final void channelActive(final ChannelHandlerContext ctx) { + LOG.debug("Starting session negotiation on channel {}", channel); + try { + startNegotiation(); + } catch (final Exception e) { + LOG.warn("Unexpected negotiation failure", e); + negotiationFailed(e); + } + } + + @Override + @SuppressWarnings("checkstyle:illegalCatch") + public final void channelRead(final ChannelHandlerContext ctx, final Object msg) { + LOG.debug("Negotiation read invoked on channel {}", channel); + try { + handleMessage((NetconfHelloMessage) msg); + } catch (final Exception e) { + LOG.debug("Unexpected error while handling negotiation message {}", msg, e); + negotiationFailed(e); + } + } + + @Override + public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) { + LOG.info("Unexpected error during negotiation", cause); + negotiationFailed(cause); + } + + protected abstract void handleMessage(NetconfHelloMessage msg) throws Exception; } diff --git a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/SessionNegotiator.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NetconfSessionNegotiator.java similarity index 77% rename from protocol-framework/src/main/java/org/opendaylight/protocol/framework/SessionNegotiator.java rename to netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NetconfSessionNegotiator.java index c2abf50716..38978ced3d 100644 --- a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/SessionNegotiator.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NetconfSessionNegotiator.java @@ -5,9 +5,10 @@ * 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.framework; +package org.opendaylight.netconf.nettyutil; import io.netty.channel.ChannelInboundHandler; +import org.opendaylight.netconf.api.NetconfSession; /** * Session negotiator concepts. A negotiator is responsible for message @@ -18,6 +19,6 @@ import io.netty.channel.ChannelInboundHandler; * @param Protocol session type. */ @Deprecated -public interface SessionNegotiator> extends ChannelInboundHandler { +public interface NetconfSessionNegotiator extends ChannelInboundHandler { } diff --git a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/SessionNegotiatorFactory.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NetconfSessionNegotiatorFactory.java similarity index 60% rename from protocol-framework/src/main/java/org/opendaylight/protocol/framework/SessionNegotiatorFactory.java rename to netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NetconfSessionNegotiatorFactory.java index 66293f368f..93997e536b 100644 --- a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/SessionNegotiatorFactory.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NetconfSessionNegotiatorFactory.java @@ -5,10 +5,13 @@ * 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.framework; +package org.opendaylight.netconf.nettyutil; import io.netty.channel.Channel; import io.netty.util.concurrent.Promise; +import org.opendaylight.netconf.api.NetconfSession; +import org.opendaylight.netconf.api.NetconfSessionListener; +import org.opendaylight.netconf.api.NetconfSessionListenerFactory; /** * A factory class creating SessionNegotiators. @@ -16,7 +19,8 @@ import io.netty.util.concurrent.Promise; * @param session type */ @Deprecated -public interface SessionNegotiatorFactory, L extends SessionListener> { +public interface NetconfSessionNegotiatorFactory> { /** * Create a new negotiator attached to a channel, which will notify * a promise once the negotiation completes. @@ -25,5 +29,6 @@ public interface SessionNegotiatorFactory, L ext * @param promise Promise to be notified * @return new negotiator instance */ - SessionNegotiator getSessionNegotiator(SessionListenerFactory factory, Channel channel, Promise promise); + NetconfSessionNegotiator getSessionNegotiator(NetconfSessionListenerFactory factory, Channel channel, + Promise promise); } diff --git a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/ProtocolSessionPromise.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NetconfSessionPromise.java similarity index 74% rename from protocol-framework/src/main/java/org/opendaylight/protocol/framework/ProtocolSessionPromise.java rename to netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NetconfSessionPromise.java index 2ee8419f8f..fec85ae871 100644 --- a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/ProtocolSessionPromise.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NetconfSessionPromise.java @@ -5,7 +5,7 @@ * 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.framework; +package org.opendaylight.netconf.nettyutil; import com.google.common.base.Preconditions; import io.netty.bootstrap.Bootstrap; @@ -20,43 +20,43 @@ import io.netty.util.concurrent.Promise; import java.net.InetSocketAddress; import javax.annotation.concurrent.GuardedBy; import javax.annotation.concurrent.ThreadSafe; +import org.opendaylight.netconf.api.NetconfSession; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Deprecated @ThreadSafe -final class ProtocolSessionPromise> extends DefaultPromise { - private static final Logger LOG = LoggerFactory.getLogger(ProtocolSessionPromise.class); +final class NetconfSessionPromise extends DefaultPromise { + private static final Logger LOG = LoggerFactory.getLogger(NetconfSessionPromise.class); private final ReconnectStrategy strategy; private InetSocketAddress address; - private final Bootstrap b; + private final Bootstrap bootstrap; @GuardedBy("this") private Future pending; - ProtocolSessionPromise(final EventExecutor executor, final InetSocketAddress address, final ReconnectStrategy strategy, - final Bootstrap b) { + NetconfSessionPromise(final EventExecutor executor, final InetSocketAddress address, + final ReconnectStrategy strategy, final Bootstrap bootstrap) { super(executor); this.strategy = Preconditions.checkNotNull(strategy); this.address = Preconditions.checkNotNull(address); - this.b = Preconditions.checkNotNull(b); + this.bootstrap = Preconditions.checkNotNull(bootstrap); } + @SuppressWarnings("checkstyle:illegalCatch") synchronized void connect() { - final Object lock = this; - try { final int timeout = this.strategy.getConnectTimeout(); - LOG.debug("Promise {} attempting connect for {}ms", lock, timeout); + LOG.debug("Promise {} attempting connect for {}ms", this, timeout); - if(this.address.isUnresolved()) { + if (this.address.isUnresolved()) { this.address = new InetSocketAddress(this.address.getHostName(), this.address.getPort()); } - this.b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, timeout); - final ChannelFuture connectFuture = this.b.connect(this.address); + this.bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, timeout); + final ChannelFuture connectFuture = this.bootstrap.connect(this.address); // Add listener that attempts reconnect by invoking this method again. - connectFuture.addListener(new BootstrapConnectListener(lock)); + connectFuture.addListener(new BootstrapConnectListener()); this.pending = connectFuture; } catch (final Exception e) { LOG.info("Failed to connect to {}", address, e); @@ -82,20 +82,14 @@ final class ProtocolSessionPromise> extends Default } private class BootstrapConnectListener implements ChannelFutureListener { - private final Object lock; - - public BootstrapConnectListener(final Object lock) { - this.lock = lock; - } - @Override public void operationComplete(final ChannelFuture cf) { - synchronized (lock) { + synchronized (NetconfSessionPromise.this) { - LOG.debug("Promise {} connection resolved", lock); + LOG.debug("Promise {} connection resolved", NetconfSessionPromise.this); // Triggered when a connection attempt is resolved. - Preconditions.checkState(ProtocolSessionPromise.this.pending.equals(cf)); + Preconditions.checkState(NetconfSessionPromise.this.pending.equals(cf)); /* * The promise we gave out could have been cancelled, @@ -108,31 +102,31 @@ final class ProtocolSessionPromise> extends Default */ if (isCancelled()) { if (cf.isSuccess()) { - LOG.debug("Closing channel for cancelled promise {}", lock); + LOG.debug("Closing channel for cancelled promise {}", NetconfSessionPromise.this); cf.channel().close(); } return; } - if(cf.isSuccess()) { - LOG.debug("Promise {} connection successful", lock); + if (cf.isSuccess()) { + LOG.debug("Promise {} connection successful", NetconfSessionPromise.this); return; } - LOG.debug("Attempt to connect to {} failed", ProtocolSessionPromise.this.address, cf.cause()); + LOG.debug("Attempt to connect to {} failed", NetconfSessionPromise.this.address, cf.cause()); - final Future rf = ProtocolSessionPromise.this.strategy.scheduleReconnect(cf.cause()); + final Future rf = NetconfSessionPromise.this.strategy.scheduleReconnect(cf.cause()); rf.addListener(new ReconnectingStrategyListener()); - ProtocolSessionPromise.this.pending = rf; + NetconfSessionPromise.this.pending = rf; } } private class ReconnectingStrategyListener implements FutureListener { @Override public void operationComplete(final Future sf) { - synchronized (lock) { + synchronized (NetconfSessionPromise.this) { // Triggered when a connection attempt is to be made. - Preconditions.checkState(ProtocolSessionPromise.this.pending.equals(sf)); + Preconditions.checkState(NetconfSessionPromise.this.pending.equals(sf)); /* * The promise we gave out could have been cancelled, @@ -152,7 +146,5 @@ final class ProtocolSessionPromise> extends Default } } } - } - } diff --git a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/NeverReconnectStrategy.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NeverReconnectStrategy.java similarity index 96% rename from protocol-framework/src/main/java/org/opendaylight/protocol/framework/NeverReconnectStrategy.java rename to netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NeverReconnectStrategy.java index 824242cba6..dc501eab73 100644 --- a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/NeverReconnectStrategy.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NeverReconnectStrategy.java @@ -5,15 +5,13 @@ * 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.framework; +package org.opendaylight.netconf.nettyutil; +import com.google.common.base.Preconditions; import io.netty.util.concurrent.EventExecutor; import io.netty.util.concurrent.Future; - import javax.annotation.concurrent.ThreadSafe; -import com.google.common.base.Preconditions; - /** * Utility ReconnectStrategy singleton, which will cause the reconnect process * to always fail. diff --git a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/ReconnectImmediatelyStrategy.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/ReconnectImmediatelyStrategy.java similarity index 97% rename from protocol-framework/src/main/java/org/opendaylight/protocol/framework/ReconnectImmediatelyStrategy.java rename to netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/ReconnectImmediatelyStrategy.java index 56cdcfb0c3..dd1f851acd 100644 --- a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/ReconnectImmediatelyStrategy.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/ReconnectImmediatelyStrategy.java @@ -5,18 +5,15 @@ * 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.framework; +package org.opendaylight.netconf.nettyutil; +import com.google.common.base.Preconditions; import io.netty.util.concurrent.EventExecutor; import io.netty.util.concurrent.Future; - import javax.annotation.concurrent.ThreadSafe; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Preconditions; - /** * Utility ReconnectStrategy singleton, which will cause the reconnect process * to immediately schedule a reconnection attempt. diff --git a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/ReconnectPromise.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/ReconnectPromise.java similarity index 70% rename from protocol-framework/src/main/java/org/opendaylight/protocol/framework/ReconnectPromise.java rename to netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/ReconnectPromise.java index a0728514ed..696d9f7ad0 100644 --- a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/ReconnectPromise.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/ReconnectPromise.java @@ -5,7 +5,7 @@ * 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.framework; +package org.opendaylight.netconf.nettyutil; import com.google.common.base.Preconditions; import io.netty.bootstrap.Bootstrap; @@ -15,24 +15,28 @@ import io.netty.util.concurrent.DefaultPromise; import io.netty.util.concurrent.EventExecutor; import io.netty.util.concurrent.Future; import java.net.InetSocketAddress; +import org.opendaylight.netconf.api.NetconfSession; +import org.opendaylight.netconf.api.NetconfSessionListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Deprecated -final class ReconnectPromise, L extends SessionListener> extends DefaultPromise { +final class ReconnectPromise> + extends DefaultPromise { private static final Logger LOG = LoggerFactory.getLogger(ReconnectPromise.class); - private final AbstractDispatcher dispatcher; + private final AbstractNetconfDispatcher dispatcher; private final InetSocketAddress address; private final ReconnectStrategyFactory strategyFactory; - private final Bootstrap b; - private final AbstractDispatcher.PipelineInitializer initializer; + private final Bootstrap bootstrap; + private final AbstractNetconfDispatcher.PipelineInitializer initializer; private Future pending; - public ReconnectPromise(final EventExecutor executor, final AbstractDispatcher dispatcher, final InetSocketAddress address, - final ReconnectStrategyFactory connectStrategyFactory, final Bootstrap b, final AbstractDispatcher.PipelineInitializer initializer) { + ReconnectPromise(final EventExecutor executor, final AbstractNetconfDispatcher dispatcher, + final InetSocketAddress address, final ReconnectStrategyFactory connectStrategyFactory, + final Bootstrap bootstrap, final AbstractNetconfDispatcher.PipelineInitializer initializer) { super(executor); - this.b = b; + this.bootstrap = bootstrap; this.initializer = Preconditions.checkNotNull(initializer); this.dispatcher = Preconditions.checkNotNull(dispatcher); this.address = Preconditions.checkNotNull(address); @@ -42,13 +46,17 @@ final class ReconnectPromise, L extends SessionList synchronized void connect() { final ReconnectStrategy cs = this.strategyFactory.createReconnectStrategy(); - // Set up a client with pre-configured bootstrap, but add a closed channel handler into the pipeline to support reconnect attempts - pending = this.dispatcher.createClient(this.address, cs, b, (channel, promise) -> { + // Set up a client with pre-configured bootstrap, but add a closed channel handler into the pipeline to support + // reconnect attempts + pending = this.dispatcher.createClient(this.address, cs, bootstrap, (channel, promise) -> { initializer.initializeChannel(channel, promise); // add closed channel handler - // This handler has to be added as last channel handler and the channel inactive event has to be caught by it - // Handlers in front of it can react to channelInactive event, but have to forward the event or the reconnect will not work - // This handler is last so all handlers in front of it can handle channel inactive (to e.g. resource cleanup) before a new connection is started + // This handler has to be added as last channel handler and the channel inactive event has to be caught by + // it + // Handlers in front of it can react to channelInactive event, but have to forward the event or the + // reconnect will not work + // This handler is last so all handlers in front of it can handle channel inactive (to e.g. resource + // cleanup) before a new connection is started channel.pipeline().addLast(new ClosedChannelHandler(ReconnectPromise.this)); }); @@ -60,10 +68,12 @@ final class ReconnectPromise, L extends SessionList } /** + * Indicate if the initial connection succeeded. * - * @return true if initial connection was established successfully, false if initial connection failed due to e.g. Connection refused, Negotiation failed + * @return true if initial connection was established successfully, false if initial connection failed due to e.g. + * Connection refused, Negotiation failed */ - private boolean isInitialConnectFinished() { + private synchronized boolean isInitialConnectFinished() { Preconditions.checkNotNull(pending); return pending.isDone() && pending.isSuccess(); } @@ -86,7 +96,7 @@ final class ReconnectPromise, L extends SessionList private static final class ClosedChannelHandler extends ChannelInboundHandlerAdapter { private final ReconnectPromise promise; - public ClosedChannelHandler(final ReconnectPromise promise) { + ClosedChannelHandler(final ReconnectPromise promise) { this.promise = promise; } @@ -105,5 +115,4 @@ final class ReconnectPromise, L extends SessionList promise.connect(); } } - } diff --git a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/ReconnectStrategy.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/ReconnectStrategy.java similarity index 97% rename from protocol-framework/src/main/java/org/opendaylight/protocol/framework/ReconnectStrategy.java rename to netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/ReconnectStrategy.java index a0a9150799..55e6b03828 100644 --- a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/ReconnectStrategy.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/ReconnectStrategy.java @@ -5,7 +5,7 @@ * 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.framework; +package org.opendaylight.netconf.nettyutil; import io.netty.util.concurrent.Future; @@ -13,6 +13,7 @@ import io.netty.util.concurrent.Future; * Interface exposed by a reconnection strategy provider. A reconnection * strategy decides whether to attempt reconnection and when to do that. * + *

* The proper way of using this API is such that when a connection attempt * has failed, the user will call scheduleReconnect() to obtain a future, * which tracks schedule of the next connect attempt. The user should add its diff --git a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/ReconnectStrategyFactory.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/ReconnectStrategyFactory.java similarity index 94% rename from protocol-framework/src/main/java/org/opendaylight/protocol/framework/ReconnectStrategyFactory.java rename to netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/ReconnectStrategyFactory.java index a71fa677c8..275e9b926e 100644 --- a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/ReconnectStrategyFactory.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/ReconnectStrategyFactory.java @@ -5,7 +5,7 @@ * 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.framework; +package org.opendaylight.netconf.nettyutil; /** * Factory interface for creating new ReconnectStrategy instances. This is diff --git a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/TimedReconnectStrategy.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/TimedReconnectStrategy.java similarity index 93% rename from protocol-framework/src/main/java/org/opendaylight/protocol/framework/TimedReconnectStrategy.java rename to netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/TimedReconnectStrategy.java index 6a1607803b..2547049254 100644 --- a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/TimedReconnectStrategy.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/TimedReconnectStrategy.java @@ -5,40 +5,42 @@ * 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.framework; +package org.opendaylight.netconf.nettyutil; +import com.google.common.base.Preconditions; import io.netty.util.concurrent.EventExecutor; import io.netty.util.concurrent.Future; - import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; - import javax.annotation.concurrent.GuardedBy; import javax.annotation.concurrent.ThreadSafe; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Preconditions; - /** * Swiss army knife equivalent for reconnect strategies. * + *

* This strategy continues to schedule reconnect attempts, each having to complete in a fixed time (connectTime). * + *

* Initial sleep time is specified as minSleep. Each subsequent unsuccessful attempt multiplies this time by a constant * factor (sleepFactor) -- this allows for either constant reconnect times (sleepFactor = 1), or various degrees of * exponential back-off (sleepFactor > 1). Maximum sleep time between attempts can be capped to a specific value * (maxSleep). * + *

* The strategy can optionally give up based on two criteria: * + *

* A preset number of connection retries (maxAttempts) has been reached, or * + *

* A preset absolute deadline is reached (deadline nanoseconds, as reported by System.nanoTime(). In this specific case, * both connectTime and maxSleep will be controlled such that the connection attempt is resolved as closely to the * deadline as possible. * + *

* Both these caps can be combined, with the strategy giving up as soon as the first one is reached. */ @Deprecated @@ -46,7 +48,9 @@ import com.google.common.base.Preconditions; public final class TimedReconnectStrategy implements ReconnectStrategy { private static final Logger LOG = LoggerFactory.getLogger(TimedReconnectStrategy.class); private final EventExecutor executor; - private final Long deadline, maxAttempts, maxSleep; + private final Long deadline; + private final Long maxAttempts; + private final Long maxSleep; private final double sleepFactor; private final int connectTime; private final long minSleep; @@ -60,8 +64,8 @@ public final class TimedReconnectStrategy implements ReconnectStrategy { @GuardedBy("this") private boolean scheduled; - public TimedReconnectStrategy(final EventExecutor executor, final int connectTime, final long minSleep, final double sleepFactor, - final Long maxSleep, final Long maxAttempts, final Long deadline) { + public TimedReconnectStrategy(final EventExecutor executor, final int connectTime, final long minSleep, + final double sleepFactor, final Long maxSleep, final Long maxAttempts, final Long deadline) { Preconditions.checkArgument(maxSleep == null || minSleep <= maxSleep); Preconditions.checkArgument(sleepFactor >= 1); Preconditions.checkArgument(connectTime >= 0); @@ -122,14 +126,12 @@ public final class TimedReconnectStrategy implements ReconnectStrategy { return this.executor.newSucceededFuture(null); } - // Need to retain a final reference to this for locking purposes, - // also set the scheduled flag. - final Object lock = this; + // Set the scheduled flag. this.scheduled = true; // Schedule a task for the right time. It will also clear the flag. return this.executor.schedule(() -> { - synchronized (lock) { + synchronized (TimedReconnectStrategy.this) { Preconditions.checkState(TimedReconnectStrategy.this.scheduled); TimedReconnectStrategy.this.scheduled = false; } diff --git a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/TimedReconnectStrategyFactory.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/TimedReconnectStrategyFactory.java similarity index 96% rename from protocol-framework/src/main/java/org/opendaylight/protocol/framework/TimedReconnectStrategyFactory.java rename to netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/TimedReconnectStrategyFactory.java index 8ea14f83d0..bf26187e12 100644 --- a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/TimedReconnectStrategyFactory.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/TimedReconnectStrategyFactory.java @@ -5,7 +5,7 @@ * 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.framework; +package org.opendaylight.netconf.nettyutil; import io.netty.util.concurrent.EventExecutor; import java.math.BigDecimal; diff --git a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java index 443094a991..da2831a6f4 100644 --- a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java +++ b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java @@ -30,6 +30,8 @@ import org.opendaylight.netconf.client.NetconfClientSessionListener; import org.opendaylight.netconf.client.conf.NetconfClientConfiguration; import org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration; import org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfigurationBuilder; +import org.opendaylight.netconf.nettyutil.ReconnectStrategyFactory; +import org.opendaylight.netconf.nettyutil.TimedReconnectStrategyFactory; import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler; import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.LoginPasswordHandler; import org.opendaylight.netconf.sal.connect.api.RemoteDevice; @@ -51,8 +53,6 @@ import org.opendaylight.netconf.topology.singleton.api.RemoteDeviceConnector; import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfConnectorDTO; import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup; import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologyUtils; -import org.opendaylight.protocol.framework.ReconnectStrategyFactory; -import org.opendaylight.protocol.framework.TimedReconnectStrategyFactory; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri; diff --git a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/AbstractNetconfTopology.java b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/AbstractNetconfTopology.java index f8f0153d55..d4dc99c698 100644 --- a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/AbstractNetconfTopology.java +++ b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/AbstractNetconfTopology.java @@ -38,6 +38,8 @@ import org.opendaylight.netconf.client.NetconfClientSessionListener; import org.opendaylight.netconf.client.conf.NetconfClientConfiguration; import org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration; import org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfigurationBuilder; +import org.opendaylight.netconf.nettyutil.ReconnectStrategyFactory; +import org.opendaylight.netconf.nettyutil.TimedReconnectStrategyFactory; import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler; import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.LoginPasswordHandler; import org.opendaylight.netconf.sal.connect.api.DeviceActionFactory; @@ -59,8 +61,6 @@ import org.opendaylight.netconf.sal.connect.netconf.schema.YangLibrarySchemaYang import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId; import org.opendaylight.netconf.topology.api.NetconfTopology; import org.opendaylight.netconf.topology.api.SchemaRepositoryProvider; -import org.opendaylight.protocol.framework.ReconnectStrategyFactory; -import org.opendaylight.protocol.framework.TimedReconnectStrategyFactory; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; diff --git a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/listener/NetconfDeviceCommunicatorTest.java b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/listener/NetconfDeviceCommunicatorTest.java index 8d416c8a3a..0771258da8 100644 --- a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/listener/NetconfDeviceCommunicatorTest.java +++ b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/listener/NetconfDeviceCommunicatorTest.java @@ -5,7 +5,6 @@ * 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.netconf.sal.connect.netconf.listener; import static org.junit.Assert.assertEquals; @@ -59,12 +58,12 @@ import org.opendaylight.netconf.client.NetconfClientSession; import org.opendaylight.netconf.client.conf.NetconfClientConfiguration; import org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration; import org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfigurationBuilder; +import org.opendaylight.netconf.nettyutil.ReconnectStrategy; +import org.opendaylight.netconf.nettyutil.TimedReconnectStrategy; import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.LoginPasswordHandler; import org.opendaylight.netconf.sal.connect.api.RemoteDevice; import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil; import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId; -import org.opendaylight.protocol.framework.ReconnectStrategy; -import org.opendaylight.protocol.framework.TimedReconnectStrategy; import org.opendaylight.yangtools.util.xml.UntrustedXML; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.RpcError; diff --git a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/client/stress/StressClientCallable.java b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/client/stress/StressClientCallable.java index 9a29a1ec9d..d808f2bf5d 100644 --- a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/client/stress/StressClientCallable.java +++ b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/client/stress/StressClientCallable.java @@ -19,12 +19,12 @@ import org.opendaylight.netconf.client.NetconfClientDispatcherImpl; import org.opendaylight.netconf.client.NetconfClientSession; import org.opendaylight.netconf.client.conf.NetconfClientConfiguration; import org.opendaylight.netconf.client.conf.NetconfClientConfigurationBuilder; +import org.opendaylight.netconf.nettyutil.NeverReconnectStrategy; import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.LoginPasswordHandler; import org.opendaylight.netconf.sal.connect.api.RemoteDevice; import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator; import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences; import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId; -import org.opendaylight.protocol.framework.NeverReconnectStrategy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/pom.xml b/pom.xml index 88d77e3266..5a8e3c06f2 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,6 @@ features karaf netconf - protocol-framework restconf diff --git a/protocol-framework/.gitignore b/protocol-framework/.gitignore deleted file mode 100644 index fc1d35eb24..0000000000 --- a/protocol-framework/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -target -.classpath -.settings diff --git a/protocol-framework/pom.xml b/protocol-framework/pom.xml deleted file mode 100644 index c6d5456e75..0000000000 --- a/protocol-framework/pom.xml +++ /dev/null @@ -1,92 +0,0 @@ - - - - - 4.0.0 - - - org.opendaylight.odlparent - bundle-parent - 4.0.7 - - - - org.opendaylight.netconf - protocol-framework - 1.3.0-SNAPSHOT - bundle - ${project.artifactId} - Common protocol framework - - - - com.google.guava - guava - - - io.netty - netty-buffer - - - io.netty - netty-codec - - - io.netty - netty-common - - - io.netty - netty-transport - - - junit - junit - - - - - org.opendaylight.yangtools - mockito-configuration - 2.1.6 - test - - - org.osgi - org.osgi.core - - - org.slf4j - slf4j-api - - - ch.qos.logback - logback-classic - test - - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - - test-jar - - package - - - - - - - - scm:git:ssh://git.opendaylight.org:29418/netconf.git - scm:git:ssh://git.opendaylight.org:29418/netconf.git - HEAD - https://git.opendaylight.org/gerrit/gitweb?p=netconf.git;a=summary - - diff --git a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/AbstractProtocolSession.java b/protocol-framework/src/main/java/org/opendaylight/protocol/framework/AbstractProtocolSession.java deleted file mode 100644 index 44afc4e7a1..0000000000 --- a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/AbstractProtocolSession.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. 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.framework; - -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.SimpleChannelInboundHandler; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Deprecated -public abstract class AbstractProtocolSession extends SimpleChannelInboundHandler implements ProtocolSession { - private static final Logger LOG = LoggerFactory.getLogger(AbstractProtocolSession.class); - - /** - * Handles incoming message (parsing, reacting if necessary). - * - * @param msg incoming message - */ - protected abstract void handleMessage(final M msg); - - /** - * Called when reached the end of input stream while reading. - */ - protected abstract void endOfInput(); - - /** - * Called when the session is added to the pipeline. - */ - protected abstract void sessionUp(); - - @Override - public final void channelInactive(final ChannelHandlerContext ctx) { - LOG.debug("Channel {} inactive.", ctx.channel()); - endOfInput(); - try { - // Forward channel inactive event, all handlers in pipeline might be interested in the event e.g. close channel handler of reconnect promise - super.channelInactive(ctx); - } catch (final Exception e) { - throw new RuntimeException("Failed to delegate channel inactive event on channel " + ctx.channel(), e); - } - } - - @Override - @SuppressWarnings("unchecked") - protected final void channelRead0(final ChannelHandlerContext ctx, final Object msg) { - LOG.debug("Message was received: {}", msg); - handleMessage((M) msg); - } - - @Override - public final void handlerAdded(final ChannelHandlerContext ctx) { - sessionUp(); - } -} diff --git a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/AbstractSessionNegotiator.java b/protocol-framework/src/main/java/org/opendaylight/protocol/framework/AbstractSessionNegotiator.java deleted file mode 100644 index a7ec22f56a..0000000000 --- a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/AbstractSessionNegotiator.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. 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.framework; - -import com.google.common.base.Preconditions; -import io.netty.channel.Channel; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundHandlerAdapter; -import io.netty.util.concurrent.Promise; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Abstract base class for session negotiators. It implements the basic - * substrate to implement SessionNegotiator API specification, with subclasses - * needing to provide only - * - * @param Protocol message type - * @param Protocol session type, has to extend {@code ProtocolSession} - */ -@Deprecated -public abstract class AbstractSessionNegotiator> - extends ChannelInboundHandlerAdapter implements SessionNegotiator { - private final Logger LOG = LoggerFactory.getLogger(AbstractSessionNegotiator.class); - private final Promise promise; - protected final Channel channel; - - public AbstractSessionNegotiator(final Promise promise, final Channel channel) { - this.promise = Preconditions.checkNotNull(promise); - this.channel = Preconditions.checkNotNull(channel); - } - - protected abstract void startNegotiation() throws Exception; - protected abstract void handleMessage(M msg) throws Exception; - - protected final void negotiationSuccessful(final S session) { - LOG.debug("Negotiation on channel {} successful with session {}", channel, session); - channel.pipeline().replace(this, "session", session); - promise.setSuccess(session); - } - - protected void negotiationFailed(final Throwable cause) { - LOG.debug("Negotiation on channel {} failed", channel, cause); - channel.close(); - promise.setFailure(cause); - } - - /** - * Send a message to peer and fail negotiation if it does not reach - * the peer. - * - * @param msg Message which should be sent. - */ - protected final void sendMessage(final M msg) { - this.channel.writeAndFlush(msg).addListener(f -> { - if (!f.isSuccess()) { - LOG.info("Failed to send message {}", msg, f.cause()); - negotiationFailed(f.cause()); - } else { - LOG.trace("Message {} sent to socket", msg); - } - }); - } - - @Override - public final void channelActive(final ChannelHandlerContext ctx) { - LOG.debug("Starting session negotiation on channel {}", channel); - try { - startNegotiation(); - } catch (final Exception e) { - LOG.warn("Unexpected negotiation failure", e); - negotiationFailed(e); - } - } - - @Override - @SuppressWarnings("unchecked") - public final void channelRead(final ChannelHandlerContext ctx, final Object msg) { - LOG.debug("Negotiation read invoked on channel {}", channel); - try { - handleMessage((M)msg); - } catch (final Exception e) { - LOG.debug("Unexpected error while handling negotiation message {}", msg, e); - negotiationFailed(e); - } - } - - @Override - public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) { - LOG.info("Unexpected error during negotiation", cause); - negotiationFailed(cause); - } -} diff --git a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/ProtocolSession.java b/protocol-framework/src/main/java/org/opendaylight/protocol/framework/ProtocolSession.java deleted file mode 100644 index b99844112f..0000000000 --- a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/ProtocolSession.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. 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.framework; - -import java.io.Closeable; - -/** - * Protocol Session represents the finite state machine in underlying protocol, including timers and its purpose is to - * create a connection between server and client. Session is automatically started, when TCP connection is created, but - * can be stopped manually. If the session is up, it has to redirect messages to/from user. Handles also malformed - * messages and unknown requests. - * - * This interface should be implemented by a final class representing a protocol specific session. - */ -@Deprecated -public interface ProtocolSession extends Closeable { - @Override - void close(); -} diff --git a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/SessionListener.java b/protocol-framework/src/main/java/org/opendaylight/protocol/framework/SessionListener.java deleted file mode 100644 index 06b2730730..0000000000 --- a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/SessionListener.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. 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.framework; - -import java.util.EventListener; - -/** - * Listener that receives session state information. This interface should be - * implemented by a protocol specific abstract class, that is extended by - * a final class that implements the methods. - */ -@Deprecated -public interface SessionListener, T extends TerminationReason> extends EventListener { - /** - * Fired when the session was established successfully. - * - * @param session New session - */ - void onSessionUp(S session); - - /** - * Fired when the session went down because of an IO error. Implementation should take care of closing underlying - * session. - * - * @param session that went down - * @param e Exception that was thrown as the cause of session being down - */ - void onSessionDown(S session, Exception e); - - /** - * Fired when the session is terminated locally. The session has already been closed and transitioned to IDLE state. - * Any outstanding queued messages were not sent. The user should not attempt to make any use of the session. - * - * @param reason the cause why the session went down - */ - void onSessionTerminated(S session, T reason); - - /** - * Fired when a normal protocol message is received. - * - * @param message Protocol message - */ - void onMessage(S session, M message); -} diff --git a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/TerminationReason.java b/protocol-framework/src/main/java/org/opendaylight/protocol/framework/TerminationReason.java deleted file mode 100644 index 19d11125e5..0000000000 --- a/protocol-framework/src/main/java/org/opendaylight/protocol/framework/TerminationReason.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. 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.framework; - -/** - * Marker interface for grouping session termination cause. - */ -@Deprecated -public interface TerminationReason { - - /** - * Get cause of session termination. - * @return human-readable cause. - */ - String getErrorMessage(); -} - diff --git a/protocol-framework/src/test/java/org/opendaylight/protocol/framework/ServerTest.java b/protocol-framework/src/test/java/org/opendaylight/protocol/framework/ServerTest.java deleted file mode 100644 index eeb4aa32ae..0000000000 --- a/protocol-framework/src/test/java/org/opendaylight/protocol/framework/ServerTest.java +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. 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.framework; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.timeout; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import io.netty.channel.ChannelFuture; -import io.netty.channel.nio.NioEventLoopGroup; -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 io.netty.util.concurrent.SucceededFuture; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; - -@Deprecated -public class ServerTest { - SimpleDispatcher clientDispatcher, dispatcher; - - SimpleSession session = null; - - ChannelFuture server = null; - - InetSocketAddress serverAddress; - private NioEventLoopGroup eventLoopGroup; - // Dedicated loop group for server, needed for testing reconnection client - // With dedicated server group we can simulate session drop by shutting only the server group down - private NioEventLoopGroup serverLoopGroup; - - @Before - public void setUp() { - final int port = 10000 + (int)(10000 * Math.random()); - serverAddress = new InetSocketAddress("127.0.0.1", port); - eventLoopGroup = new NioEventLoopGroup(); - serverLoopGroup = new NioEventLoopGroup(); - } - - @After - public void tearDown() throws IOException, InterruptedException, ExecutionException { - if(server != null) { - this.server.channel().close(); - } - this.eventLoopGroup.shutdownGracefully().get(); - this.serverLoopGroup.shutdownGracefully().get(); - try { - Thread.sleep(500); - } catch (final InterruptedException e) { - throw new RuntimeException(e); - } - } - - @Test - public void testConnectionRefused() throws Exception { - this.clientDispatcher = getClientDispatcher(); - - final ReconnectStrategy mockReconnectStrategy = getMockedReconnectStrategy(); - - this.clientDispatcher.createClient(this.serverAddress, mockReconnectStrategy, SimpleSessionListener::new); - - Mockito.verify(mockReconnectStrategy, timeout(5000).atLeast(2)).scheduleReconnect(any(Throwable.class)); - } - - @Test - public void testConnectionReestablishInitial() throws Exception { - this.clientDispatcher = getClientDispatcher(); - - final ReconnectStrategy mockReconnectStrategy = getMockedReconnectStrategy(); - - this.clientDispatcher.createClient(this.serverAddress, mockReconnectStrategy, SimpleSessionListener::new); - - Mockito.verify(mockReconnectStrategy, timeout(5000).atLeast(2)).scheduleReconnect(any(Throwable.class)); - - final Promise p = new DefaultPromise<>(GlobalEventExecutor.INSTANCE); - this.dispatcher = getServerDispatcher(p); - - this.server = this.dispatcher.createServer(this.serverAddress, SimpleSessionListener::new); - - this.server.get(); - - assertEquals(true, p.get(3, TimeUnit.SECONDS)); - } - - @Test - public void testConnectionDrop() throws Exception { - final Promise p = new DefaultPromise<>(GlobalEventExecutor.INSTANCE); - - this.dispatcher = getServerDispatcher(p); - - this.server = this.dispatcher.createServer(this.serverAddress, SimpleSessionListener::new); - - this.server.get(); - - this.clientDispatcher = getClientDispatcher(); - - final ReconnectStrategy reconnectStrategy = getMockedReconnectStrategy(); - this.session = this.clientDispatcher.createClient(this.serverAddress, - reconnectStrategy, SimpleSessionListener::new).get(6, TimeUnit.SECONDS); - - assertEquals(true, p.get(3, TimeUnit.SECONDS)); - - shutdownServer(); - - // No reconnect should be scheduled after server drops connection with not-reconnecting client - verify(reconnectStrategy, times(0)).scheduleReconnect(any(Throwable.class)); - } - - @Test - public void testConnectionReestablishAfterDrop() throws Exception { - final Promise p = new DefaultPromise<>(GlobalEventExecutor.INSTANCE); - - this.dispatcher = getServerDispatcher(p); - - this.server = this.dispatcher.createServer(this.serverAddress, SimpleSessionListener::new); - - this.server.get(); - - this.clientDispatcher = getClientDispatcher(); - - final ReconnectStrategyFactory reconnectStrategyFactory = mock(ReconnectStrategyFactory.class); - final ReconnectStrategy reconnectStrategy = getMockedReconnectStrategy(); - doReturn(reconnectStrategy).when(reconnectStrategyFactory).createReconnectStrategy(); - - this.clientDispatcher.createReconnectingClient(this.serverAddress, - reconnectStrategyFactory, SimpleSessionListener::new); - - assertEquals(true, p.get(3, TimeUnit.SECONDS)); - shutdownServer(); - - verify(reconnectStrategyFactory, timeout(20000).atLeast(2)).createReconnectStrategy(); - } - - @Test - public void testConnectionEstablished() throws Exception { - final Promise p = new DefaultPromise<>(GlobalEventExecutor.INSTANCE); - - this.dispatcher = getServerDispatcher(p); - - this.server = this.dispatcher.createServer(this.serverAddress, SimpleSessionListener::new); - - this.server.get(); - - this.clientDispatcher = getClientDispatcher(); - - this.session = this.clientDispatcher.createClient(this.serverAddress, - new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000), SimpleSessionListener::new).get(6, - TimeUnit.SECONDS); - - assertEquals(true, p.get(3, TimeUnit.SECONDS)); - } - - @Test - public void testConnectionFailed() throws IOException, InterruptedException, ExecutionException, TimeoutException { - final Promise p = new DefaultPromise<>(GlobalEventExecutor.INSTANCE); - - this.dispatcher = getServerDispatcher(p); - - this.server = this.dispatcher.createServer(this.serverAddress, SimpleSessionListener::new); - - this.server.get(); - - this.clientDispatcher = getClientDispatcher(); - - this.session = this.clientDispatcher.createClient(this.serverAddress, - new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000), SimpleSessionListener::new).get(6, - TimeUnit.SECONDS); - - final Future session = this.clientDispatcher.createClient(this.serverAddress, - new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000), SimpleSessionListener::new); - assertFalse(session.isSuccess()); - } - - @Test - public void testNegotiationFailedReconnect() throws Exception { - final Promise p = new DefaultPromise<>(GlobalEventExecutor.INSTANCE); - - this.dispatcher = getServerDispatcher(p); - - this.server = this.dispatcher.createServer(this.serverAddress, SimpleSessionListener::new); - - this.server.get(); - - this.clientDispatcher = new SimpleDispatcher( - (factory, channel, promise) -> new SimpleSessionNegotiator(promise, channel) { - @Override - protected void startNegotiation() throws Exception { - negotiationFailed(new IllegalStateException("Negotiation failed")); - } - }, new DefaultPromise<>(GlobalEventExecutor.INSTANCE), eventLoopGroup); - - final ReconnectStrategyFactory reconnectStrategyFactory = mock(ReconnectStrategyFactory.class); - final ReconnectStrategy reconnectStrategy = getMockedReconnectStrategy(); - doReturn(reconnectStrategy).when(reconnectStrategyFactory).createReconnectStrategy(); - - this.clientDispatcher.createReconnectingClient(this.serverAddress, - reconnectStrategyFactory, SimpleSessionListener::new); - - - // Reconnect strategy should be consulted at least twice, for initial connect and reconnect attempts after drop - verify(reconnectStrategyFactory, timeout((int) TimeUnit.MINUTES.toMillis(3)).atLeast(2)).createReconnectStrategy(); - } - - private SimpleDispatcher getClientDispatcher() { - return new SimpleDispatcher((factory, channel, promise) -> new SimpleSessionNegotiator(promise, channel), new DefaultPromise<>(GlobalEventExecutor.INSTANCE), eventLoopGroup); - } - - private ReconnectStrategy getMockedReconnectStrategy() throws Exception { - final ReconnectStrategy mockReconnectStrategy = mock(ReconnectStrategy.class); - final Future future = new SucceededFuture<>(GlobalEventExecutor.INSTANCE, null); - doReturn(future).when(mockReconnectStrategy).scheduleReconnect(any(Throwable.class)); - doReturn(5000).when(mockReconnectStrategy).getConnectTimeout(); - doNothing().when(mockReconnectStrategy).reconnectSuccessful(); - return mockReconnectStrategy; - } - - - private void shutdownServer() throws InterruptedException, ExecutionException { - // Shutdown server - server.channel().close().get(); - // Closing server channel does not close established connections, eventLoop has to be closed as well to simulate dropped session - serverLoopGroup.shutdownGracefully().get(); - } - - private SimpleDispatcher getServerDispatcher(final Promise p) { - return new SimpleDispatcher((factory, channel, promise) -> { - p.setSuccess(true); - return new SimpleSessionNegotiator(promise, channel); - }, null, serverLoopGroup); - } - -} diff --git a/protocol-framework/src/test/java/org/opendaylight/protocol/framework/Session.java b/protocol-framework/src/test/java/org/opendaylight/protocol/framework/Session.java deleted file mode 100644 index 790bd4e96a..0000000000 --- a/protocol-framework/src/test/java/org/opendaylight/protocol/framework/Session.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. 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.framework; - -import com.google.common.collect.Lists; -import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Deprecated -public class Session extends AbstractProtocolSession { - - private static final Logger LOG = LoggerFactory.getLogger(Session.class); - - public final List msgs = Lists.newArrayList(); - - public boolean up = false; - - @Override - public void close() { - - } - - @Override - public void handleMessage(final SimpleMessage msg) { - LOG.debug("Message received: {}", msg.getMessage()); - this.up = true; - this.msgs.add(msg); - LOG.debug(this.msgs.size() + ""); - } - - @Override - public void endOfInput() { - LOG.debug("End of input reported."); - } - - @Override - protected void sessionUp() { - LOG.debug("Session up reported."); - } -} diff --git a/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleByteToMessageDecoder.java b/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleByteToMessageDecoder.java deleted file mode 100644 index c53ee75f66..0000000000 --- a/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleByteToMessageDecoder.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. 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.framework; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.ByteToMessageDecoder; -import java.nio.charset.StandardCharsets; -import java.util.List; - -@Deprecated -public class SimpleByteToMessageDecoder extends ByteToMessageDecoder { - @Override - protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List out) { - out.add(new SimpleMessage(StandardCharsets.UTF_8.decode(in.nioBuffer()).toString())); - } -} diff --git a/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleDispatcher.java b/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleDispatcher.java deleted file mode 100644 index 5c7cd4fb73..0000000000 --- a/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleDispatcher.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. 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.framework; - -import com.google.common.base.Preconditions; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelOutboundHandler; -import io.netty.channel.EventLoopGroup; -import io.netty.channel.socket.SocketChannel; -import io.netty.util.concurrent.Future; -import io.netty.util.concurrent.Promise; -import java.net.InetSocketAddress; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Deprecated -public class SimpleDispatcher extends AbstractDispatcher { - private static final Logger LOG = LoggerFactory.getLogger(SimpleDispatcher.class); - - private final SessionNegotiatorFactory negotiatorFactory; - private final ChannelOutboundHandler encoder = new SimpleMessageToByteEncoder(); - - private final class SimplePipelineInitializer implements PipelineInitializer { - final SessionListenerFactory listenerFactory; - - SimplePipelineInitializer(final SessionListenerFactory listenerFactory) { - this.listenerFactory = Preconditions.checkNotNull(listenerFactory); - } - - @Override - public void initializeChannel(final SocketChannel channel, final Promise promise) { - channel.pipeline().addLast(new SimpleByteToMessageDecoder()); - channel.pipeline().addLast("negotiator", negotiatorFactory.getSessionNegotiator(listenerFactory, channel, promise)); - channel.pipeline().addLast(encoder); - LOG.debug("initialization completed for channel {}", channel); - } - - } - - public SimpleDispatcher(final SessionNegotiatorFactory negotiatorFactory, - final Promise promise, final EventLoopGroup eventLoopGroup) { - super(eventLoopGroup, eventLoopGroup); - this.negotiatorFactory = Preconditions.checkNotNull(negotiatorFactory); - } - - public Future createClient(final InetSocketAddress address, final ReconnectStrategy strategy, final SessionListenerFactory listenerFactory) { - return super.createClient(address, strategy, new SimplePipelineInitializer(listenerFactory)); - } - - public Future createReconnectingClient(final InetSocketAddress address, final ReconnectStrategyFactory strategy, final SessionListenerFactory listenerFactory) { - return super.createReconnectingClient(address, strategy, new SimplePipelineInitializer(listenerFactory)); - } - - public ChannelFuture createServer(final InetSocketAddress address, final SessionListenerFactory listenerFactory) { - return super.createServer(address, new SimplePipelineInitializer(listenerFactory)); - } - - @Override - public void close() { - } -} diff --git a/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleMessage.java b/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleMessage.java deleted file mode 100644 index 5bd5b07e4c..0000000000 --- a/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleMessage.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. 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.framework; - -@Deprecated -public class SimpleMessage { - - private final String s; - - public SimpleMessage(final String s) { - this.s = s; - } - - public String getMessage() { - return this.s; - } -} diff --git a/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleMessageToByteEncoder.java b/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleMessageToByteEncoder.java deleted file mode 100644 index 43a5601f9d..0000000000 --- a/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleMessageToByteEncoder.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. 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.framework; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandler.Sharable; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToByteEncoder; - -@Deprecated -@Sharable -public class SimpleMessageToByteEncoder extends MessageToByteEncoder { - @Override - protected void encode(final ChannelHandlerContext ctx, final SimpleMessage msg, final ByteBuf out) { - out.writeBytes(msg.getMessage().getBytes()); - } -} diff --git a/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleSession.java b/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleSession.java deleted file mode 100644 index 136e98d43f..0000000000 --- a/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleSession.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. 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.framework; - -@Deprecated -public final class SimpleSession extends AbstractProtocolSession { - - public SimpleSession() { - } - - @Override - public void close() { - } - - @Override - public void handleMessage(final SimpleMessage msg) { - } - - @Override - public void endOfInput() { - } - - @Override - protected void sessionUp() { - } -} diff --git a/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleSessionListener.java b/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleSessionListener.java deleted file mode 100644 index 632305607c..0000000000 --- a/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleSessionListener.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. 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.framework; - -import java.util.ArrayList; -import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Simple Session Listener that is notified about messages and changes in the session. - */ -@Deprecated -public class SimpleSessionListener implements SessionListener { - private static final Logger LOG = LoggerFactory.getLogger(SimpleSessionListener.class); - - public List messages = new ArrayList<>(); - - public boolean up = false; - - public boolean failed = false; - - @Override - public void onMessage(final SimpleSession session, final SimpleMessage message) { - LOG.debug("Received message: " + message.getClass() + " " + message); - this.messages.add(message); - } - - @Override - public void onSessionUp(final SimpleSession session) { - this.up = true; - } - - @Override - public void onSessionDown(final SimpleSession session, final Exception e) { - this.failed = true; - this.notifyAll(); - } - - @Override - public void onSessionTerminated(final SimpleSession session, final TerminationReason reason) { - this.failed = true; - this.notifyAll(); - } -} diff --git a/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleSessionListenerFactory.java b/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleSessionListenerFactory.java deleted file mode 100644 index 04bc279300..0000000000 --- a/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleSessionListenerFactory.java +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. 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.framework; - -@Deprecated -public class SimpleSessionListenerFactory implements SessionListenerFactory { - - @Override - public SimpleSessionListener getSessionListener() { - return new SimpleSessionListener(); - } -} diff --git a/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleSessionNegotiator.java b/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleSessionNegotiator.java deleted file mode 100644 index 50b2922851..0000000000 --- a/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleSessionNegotiator.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. 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.framework; - -import io.netty.channel.Channel; -import io.netty.util.concurrent.Promise; - -@Deprecated -public class SimpleSessionNegotiator extends AbstractSessionNegotiator { - - public SimpleSessionNegotiator(final Promise promise, final Channel channel) { - super(promise, channel); - } - - @Override - protected void startNegotiation() throws Exception { - negotiationSuccessful(new SimpleSession()); - } - - @Override - protected void handleMessage(final SimpleMessage msg) throws Exception { - throw new IllegalStateException("This method should never be invoked"); - } -} diff --git a/protocol-framework/src/test/resources/logback-test.xml b/protocol-framework/src/test/resources/logback-test.xml deleted file mode 100644 index 7ace93024a..0000000000 --- a/protocol-framework/src/test/resources/logback-test.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - -- 2.36.6