</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+ </configuration>
+ </plugin>
</plugins>
</build>
public interface NetconfClientDispatcher {
/**
+ * Create netconf client. Network communication has to be set up based on network protocol specified in
+ * clientConfiguration
*
- * Create netconf client. Network communication has to be set up based on network protocol specified in clientConfiguration
- *
- * @param clientConfiguration
+ * @param clientConfiguration Configuration of client
* @return netconf client based on provided configuration
*/
Future<NetconfClientSession> createClient(NetconfClientConfiguration clientConfiguration);
private final Timer timer;
- public NetconfClientDispatcherImpl(final EventLoopGroup bossGroup, final EventLoopGroup workerGroup, final Timer timer) {
+ public NetconfClientDispatcherImpl(final EventLoopGroup bossGroup, final EventLoopGroup workerGroup,
+ final Timer timer) {
super(bossGroup, workerGroup);
this.timer = timer;
}
@Override
public Future<NetconfClientSession> createClient(final NetconfClientConfiguration clientConfiguration) {
switch (clientConfiguration.getProtocol()) {
- case TCP:
- return createTcpClient(clientConfiguration);
- case SSH:
- return createSshClient(clientConfiguration);
+ case TCP:
+ return createTcpClient(clientConfiguration);
+ case SSH:
+ return createSshClient(clientConfiguration);
+ default:
+ throw new IllegalArgumentException("Unknown client protocol " + clientConfiguration.getProtocol());
}
- throw new IllegalArgumentException("Unknown client protocol " + clientConfiguration.getProtocol());
}
@Override
public Future<Void> createReconnectingClient(final NetconfReconnectingClientConfiguration clientConfiguration) {
switch (clientConfiguration.getProtocol()) {
- case TCP:
- return createReconnectingTcpClient(clientConfiguration);
- case SSH:
- return createReconnectingSshClient(clientConfiguration);
+ case TCP:
+ return createReconnectingTcpClient(clientConfiguration);
+ case SSH:
+ return createReconnectingSshClient(clientConfiguration);
+ default:
+ throw new IllegalArgumentException("Unknown client protocol " + clientConfiguration.getProtocol());
}
- throw new IllegalArgumentException("Unknown client protocol " + clientConfiguration.getProtocol());
}
private Future<NetconfClientSession> createTcpClient(final NetconfClientConfiguration currentConfiguration) {
LOG.debug("Creating TCP client with configuration: {}", currentConfiguration);
return super.createClient(currentConfiguration.getAddress(), currentConfiguration.getReconnectStrategy(),
- (ch, promise) -> new TcpClientChannelInitializer(getNegotiatorFactory(currentConfiguration), currentConfiguration
- .getSessionListener()).initialize(ch, promise));
+ (ch, promise) -> new TcpClientChannelInitializer(getNegotiatorFactory(currentConfiguration),
+ currentConfiguration
+ .getSessionListener()).initialize(ch, promise));
}
- private Future<Void> createReconnectingTcpClient(final NetconfReconnectingClientConfiguration currentConfiguration) {
+ private Future<Void> createReconnectingTcpClient(
+ final NetconfReconnectingClientConfiguration currentConfiguration) {
LOG.debug("Creating reconnecting TCP client with configuration: {}", currentConfiguration);
- final TcpClientChannelInitializer init = new TcpClientChannelInitializer(getNegotiatorFactory(currentConfiguration),
+ final TcpClientChannelInitializer init =
+ new TcpClientChannelInitializer(getNegotiatorFactory(currentConfiguration),
currentConfiguration.getSessionListener());
- return super.createReconnectingClient(currentConfiguration.getAddress(), currentConfiguration.getConnectStrategyFactory(),
+ return super.createReconnectingClient(currentConfiguration.getAddress(), currentConfiguration
+ .getConnectStrategyFactory(),
currentConfiguration.getReconnectStrategy(), init::initialize);
}
private Future<NetconfClientSession> createSshClient(final NetconfClientConfiguration currentConfiguration) {
LOG.debug("Creating SSH client with configuration: {}", currentConfiguration);
return super.createClient(currentConfiguration.getAddress(), currentConfiguration.getReconnectStrategy(),
- (ch, sessionPromise) -> new SshClientChannelInitializer(currentConfiguration.getAuthHandler(),
+ (ch, sessionPromise) -> new SshClientChannelInitializer(currentConfiguration.getAuthHandler(),
getNegotiatorFactory(currentConfiguration), currentConfiguration.getSessionListener())
.initialize(ch, sessionPromise));
}
- private Future<Void> createReconnectingSshClient(final NetconfReconnectingClientConfiguration currentConfiguration) {
+ private Future<Void> createReconnectingSshClient(
+ final NetconfReconnectingClientConfiguration currentConfiguration) {
LOG.debug("Creating reconnecting SSH client with configuration: {}", currentConfiguration);
final SshClientChannelInitializer init = new SshClientChannelInitializer(currentConfiguration.getAuthHandler(),
getNegotiatorFactory(currentConfiguration), currentConfiguration.getSessionListener());
- return super.createReconnectingClient(currentConfiguration.getAddress(), currentConfiguration.getConnectStrategyFactory(), currentConfiguration.getReconnectStrategy(),
+ return super.createReconnectingClient(currentConfiguration.getAddress(), currentConfiguration
+ .getConnectStrategyFactory(), currentConfiguration.getReconnectStrategy(),
init::initialize);
}
/**
* Construct a new session.
*
- * @param sessionListener
- * @param channel
- * @param sessionId
- * @param capabilities set of advertised capabilities. Expected to be immutable.
+ * @param sessionListener Netconf client session listener.
+ * @param channel Channel.
+ * @param sessionId Session Id.
+ * @param capabilities Set of advertised capabilities. Expected to be immutable.
*/
- public NetconfClientSession(final NetconfClientSessionListener sessionListener, final Channel channel, final long sessionId,
- final Collection<String> capabilities) {
+ public NetconfClientSession(final NetconfClientSessionListener sessionListener, final Channel channel,
+ final long sessionId, final Collection<String> capabilities) {
super(sessionListener, channel, sessionId);
this.capabilities = capabilities;
LOG.debug("Client Session {} created", this);
}
@Override
- protected void addExiHandlers(final ByteToMessageDecoder decoder, final MessageToByteEncoder<NetconfMessage> encoder) {
+ protected void addExiHandlers(final ByteToMessageDecoder decoder,
+ final MessageToByteEncoder<NetconfMessage> encoder) {
// TODO used only in negotiator, client supports only auto start-exi
replaceMessageDecoder(decoder);
replaceMessageEncoder(encoder);
import org.w3c.dom.NodeList;
public class NetconfClientSessionNegotiator extends
- AbstractNetconfSessionNegotiator<NetconfClientSessionPreferences, NetconfClientSession, NetconfClientSessionListener>
-{
+ AbstractNetconfSessionNegotiator<NetconfClientSessionPreferences, NetconfClientSession,
+ NetconfClientSessionListener> {
private static final Logger LOG = LoggerFactory.getLogger(NetconfClientSessionNegotiator.class);
- private static final XPathExpression sessionIdXPath = XMLNetconfUtil
+ private static final XPathExpression SESSION_ID_X_PATH = XMLNetconfUtil
.compileXPath("/netconf:hello/netconf:session-id");
- private static final XPathExpression sessionIdXPathNoNamespace = XMLNetconfUtil
+ private static final XPathExpression SESSION_ID_X_PATH_NO_NAMESPACE = XMLNetconfUtil
.compileXPath("/hello/session-id");
private static final String EXI_1_0_CAPABILITY_MARKER = "exi:1.0";
/**
* Initiates exi communication by sending start-exi message and waiting for positive/negative response.
*
- * @param startExiMessage
+ * @param startExiMessage Exi message for initilization of exi communication.
*/
void tryToInitiateExi(final NetconfClientSession session, final NetconfStartExiMessage startExiMessage) {
channel.pipeline().addAfter(AbstractChannelInitializer.NETCONF_MESSAGE_DECODER,
session.sendMessage(startExiMessage).addListener(new ChannelFutureListener() {
@Override
- public void operationComplete(final ChannelFuture f) {
- if (!f.isSuccess()) {
- LOG.warn("Failed to send start-exi message {} on session {}", startExiMessage, this, f.cause());
+ public void operationComplete(final ChannelFuture channelFuture) {
+ if (!channelFuture.isSuccess()) {
+ LOG.warn("Failed to send start-exi message {} on session {}", startExiMessage, this,
+ channelFuture.cause());
channel.pipeline().remove(ExiConfirmationInboundHandler.EXI_CONFIRMED_HANDLER);
} else {
LOG.trace("Start-exi message {} sent to socket on session {}", startExiMessage, this);
}
private static long extractSessionId(final Document doc) {
- String textContent = getSessionIdWithXPath(doc, sessionIdXPath);
+ String textContent = getSessionIdWithXPath(doc, SESSION_ID_X_PATH);
if (Strings.isNullOrEmpty(textContent)) {
- textContent = getSessionIdWithXPath(doc, sessionIdXPathNoNamespace);
+ textContent = getSessionIdWithXPath(doc, SESSION_ID_X_PATH_NO_NAMESPACE);
if (Strings.isNullOrEmpty(textContent)) {
- throw new IllegalStateException("Session id not received from server, hello message: " + XmlUtil.toString(doc));
+ throw new IllegalStateException("Session id not received from server, hello message: " + XmlUtil
+ .toString(doc));
}
}
final long sessionId = extractSessionId(message.getDocument());
// Copy here is important: it disconnects the strings from the document
- Set<String> capabilities = ImmutableSet.copyOf(NetconfMessageUtil.extractCapabilitiesFromHello(message.getDocument()));
+ Set<String> capabilities = ImmutableSet.copyOf(NetconfMessageUtil.extractCapabilitiesFromHello(message
+ .getDocument()));
capabilities = INTERNER.intern(capabilities);
}
/**
- * Handler to process response for start-exi message
+ * Handler to process response for start-exi message.
*/
private final class ExiConfirmationInboundHandler extends ChannelInboundHandlerAdapter {
private static final String EXI_CONFIRMED_HANDLER = "exiConfirmedHandler";
private final NetconfClientSession session;
private final NetconfStartExiMessage startExiMessage;
- ExiConfirmationInboundHandler(final NetconfClientSession session, final NetconfStartExiMessage startExiMessage) {
+ ExiConfirmationInboundHandler(final NetconfClientSession session,
+ final NetconfStartExiMessage startExiMessage) {
this.session = session;
this.startExiMessage = startExiMessage;
}
+ @SuppressWarnings("checkstyle:IllegalCatch")
@Override
public void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception {
ctx.pipeline().remove(ExiConfirmationInboundHandler.EXI_CONFIRMED_HANDLER);
session.startExiCommunication(startExiMessage);
} catch (RuntimeException e) {
// Unable to add exi, continue without exi
- LOG.warn("Unable to start exi communication, Communication will continue without exi on session {}", session, e);
+ LOG.warn("Unable to start exi communication, Communication will continue without exi on session "
+ + "{}", session, e);
}
// Error response
- } else if(NetconfMessageUtil.isErrorMessage(netconfMessage)) {
+ } else if (NetconfMessageUtil.isErrorMessage(netconfMessage)) {
LOG.warn(
"Error response to start-exi message {}, Communication will continue without exi on session {}",
netconfMessage, session);
// Unexpected response to start-exi, throwing message away, continue without exi
} else {
- LOG.warn("Unexpected response to start-exi message, should be ok, was {}, " +
- "Communication will continue without exi and response message will be thrown away on session {}",
- netconfMessage, session);
+ LOG.warn("Unexpected response to start-exi message, should be ok, was {}, "
+ + "Communication will continue without exi "
+ + "and response message will be thrown away on session {}",
+ netconfMessage, session);
}
negotiationSuccessful(session);
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class NetconfClientSessionNegotiatorFactory implements SessionNegotiatorFactory<NetconfMessage, NetconfClientSession, NetconfClientSessionListener> {
+public class NetconfClientSessionNegotiatorFactory implements SessionNegotiatorFactory<NetconfMessage,
+ NetconfClientSession, NetconfClientSessionListener> {
public static final Set<String> EXI_CLIENT_CAPABILITIES = ImmutableSet.of(
XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_0,
public NetconfClientSessionNegotiatorFactory(final Timer timer,
final Optional<NetconfHelloMessageAdditionalHeader> additionalHeader,
- final long connectionTimeoutMillis, final EXIOptions exiOptions, final Set<String> capabilities) {
+ final long connectionTimeoutMillis, final EXIOptions exiOptions,
+ final Set<String> capabilities) {
this.timer = Preconditions.checkNotNull(timer);
this.additionalHeader = additionalHeader;
this.connectionTimeoutMillis = connectionTimeoutMillis;
}
@Override
- public SessionNegotiator<NetconfClientSession> getSessionNegotiator(final SessionListenerFactory<NetconfClientSessionListener> sessionListenerFactory,
- final Channel channel,
- final Promise<NetconfClientSession> promise) {
+ public SessionNegotiator<NetconfClientSession> getSessionNegotiator(
+ final SessionListenerFactory<NetconfClientSessionListener> sessionListenerFactory,
+ final Channel channel, final Promise<NetconfClientSession> promise) {
NetconfMessage startExiMessage = NetconfStartExiMessage.create(options, START_EXI_MESSAGE_ID);
NetconfHelloMessage helloMessage = null;
try {
helloMessage = NetconfHelloMessage.createClientHello(clientCapabilities, additionalHeader);
} catch (NetconfDocumentedException e) {
- LOG.error("Unable to create client hello message with capabilities {} and additional handler {}", clientCapabilities,additionalHeader);
+ LOG.error("Unable to create client hello message with capabilities {} and additional handler {}",
+ clientCapabilities, additionalHeader);
throw new IllegalStateException(e);
}
NetconfClientSessionPreferences proposal = new NetconfClientSessionPreferences(helloMessage, startExiMessage);
return new NetconfClientSessionNegotiator(proposal, promise, channel, timer,
- sessionListenerFactory.getSessionListener(),connectionTimeoutMillis);
+ sessionListenerFactory.getSessionListener(), connectionTimeoutMillis);
}
}
private final Promise<NetconfMessage> promise;
private final NetconfMessage request;
- public RequestEntry(Promise<NetconfMessage> future, NetconfMessage request) {
+ RequestEntry(Promise<NetconfMessage> future, NetconfMessage request) {
this.promise = Preconditions.checkNotNull(future);
this.request = Preconditions.checkNotNull(request);
}
}
@Override
- public final void onSessionDown(NetconfClientSession clientSession, Exception e) {
- LOG.debug("Client Session {} went down unexpectedly", clientSession, e);
- tearDown(e);
+ public final void onSessionDown(NetconfClientSession clientSession, Exception exception) {
+ LOG.debug("Client Session {} went down unexpectedly", clientSession, exception);
+ tearDown(exception);
}
@Override
public final void onSessionTerminated(NetconfClientSession clientSession,
- NetconfTerminationReason netconfTerminationReason) {
+ NetconfTerminationReason netconfTerminationReason) {
LOG.debug("Client Session {} terminated, reason: {}", clientSession,
netconfTerminationReason.getErrorMessage());
tearDown(new RuntimeException(netconfTerminationReason.getErrorMessage()));
private final NetconfClientSessionNegotiatorFactory negotiatorFactory;
private final NetconfClientSessionListener sessionListener;
- public SshClientChannelInitializer(final AuthenticationHandler authHandler,
- final NetconfClientSessionNegotiatorFactory negotiatorFactory,
- final NetconfClientSessionListener sessionListener) {
+ SshClientChannelInitializer(final AuthenticationHandler authHandler,
+ final NetconfClientSessionNegotiatorFactory negotiatorFactory,
+ final NetconfClientSessionListener sessionListener) {
this.authenticationHandler = authHandler;
this.negotiatorFactory = negotiatorFactory;
this.sessionListener = sessionListener;
try {
// ssh handler has to be the first handler in pipeline
ch.pipeline().addFirst(AsyncSshHandler.createForNetconfSubsystem(authenticationHandler, promise));
- super.initialize(ch,promise);
+ super.initialize(ch, promise);
} catch (final IOException e) {
throw new RuntimeException(e);
}
@Override
protected void initializeSessionNegotiator(final Channel ch,
final Promise<NetconfClientSession> promise) {
- ch.pipeline().addAfter(NETCONF_MESSAGE_DECODER, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR,
+ ch.pipeline().addAfter(NETCONF_MESSAGE_DECODER, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR,
negotiatorFactory.getSessionNegotiator(() -> sessionListener, ch, promise));
}
}
GenericFutureListener<Future<NetconfClientSession>> negotiationFutureListener;
@Override
- public void connect(final ChannelHandlerContext ctx, final SocketAddress remoteAddress, final SocketAddress localAddress,
+ public void connect(final ChannelHandlerContext ctx, final SocketAddress remoteAddress,
+ final SocketAddress localAddress,
final ChannelPromise channelPromise) throws Exception {
connectPromise = channelPromise;
ChannelPromise tcpConnectFuture = new DefaultChannelPromise(ch);
};
tcpConnectFuture.addListener(future -> {
- if(future.isSuccess()) {
+ if (future.isSuccess()) {
//complete connection promise with netconf negotiation future
negotiationFuture.addListener(negotiationFutureListener);
} else {
@Override
public void disconnect(final ChannelHandlerContext ctx, final ChannelPromise promise) throws Exception {
- // If we have already succeeded and the session was dropped after, we need to fire inactive to notify reconnect logic
- if(connectPromise.isSuccess()) {
+ // If we have already succeeded and the session was dropped after, we need to fire inactive to notify
+ // reconnect logic
+ if (connectPromise.isSuccess()) {
ctx.fireChannelInactive();
}
//If connection promise is not already set, it means negotiation failed
//we must set connection promise to failure
- if(!connectPromise.isDone()) {
+ if (!connectPromise.isDone()) {
connectPromise.setFailure(new IllegalStateException("Negotiation failed"));
}
import org.opendaylight.netconf.client.NetconfClientSessionListener;
import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
import org.opendaylight.protocol.framework.ReconnectStrategy;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class NetconfClientConfiguration {
+ private static final Logger LOG = LoggerFactory.getLogger(NetconfClientConfiguration.class);
+
private final NetconfClientProtocol clientProtocol;
private final InetSocketAddress address;
private final Long connectionTimeoutMillis;
private final AuthenticationHandler authHandler;
- NetconfClientConfiguration(final NetconfClientProtocol protocol, final InetSocketAddress address, final Long connectionTimeoutMillis, final NetconfHelloMessageAdditionalHeader additionalHeader, final NetconfClientSessionListener sessionListener, final ReconnectStrategy reconnectStrategy, final AuthenticationHandler authHandler) {
+ NetconfClientConfiguration(final NetconfClientProtocol protocol, final InetSocketAddress address,
+ final Long connectionTimeoutMillis,
+ final NetconfHelloMessageAdditionalHeader additionalHeader,
+ final NetconfClientSessionListener sessionListener,
+ final ReconnectStrategy reconnectStrategy, final AuthenticationHandler authHandler) {
this.address = address;
this.connectionTimeoutMillis = connectionTimeoutMillis;
this.additionalHeader = additionalHeader;
return clientProtocol;
}
+ @SuppressWarnings("checkstyle:FallThrough")
private void validateConfiguration() {
Preconditions.checkNotNull(clientProtocol, " ");
switch (clientProtocol) {
- case SSH:
- validateSshConfiguration();
- // Fall through intentional (ssh validation is a superset of tcp validation)
- case TCP:
- validateTcpConfiguration();
+ case SSH:
+ validateSshConfiguration();
+ // Fall through intentional (ssh validation is a superset of tcp validation)
+ case TCP:
+ validateTcpConfiguration();
+ default:
+ LOG.warn("Unexpected protocol: {} in netconf client configuration.", clientProtocol);
}
}
.add("authHandler", authHandler);
}
- public static enum NetconfClientProtocol {
+ public enum NetconfClientProtocol {
TCP, SSH
}
}
\ No newline at end of file
public class NetconfClientConfigurationBuilder {
public static final int DEFAULT_CONNECTION_TIMEOUT_MILLIS = 5000;
- public static final NetconfClientConfiguration.NetconfClientProtocol DEFAULT_CLIENT_PROTOCOL = NetconfClientConfiguration.NetconfClientProtocol.TCP;
+ public static final NetconfClientConfiguration.NetconfClientProtocol DEFAULT_CLIENT_PROTOCOL =
+ NetconfClientConfiguration.NetconfClientProtocol.TCP;
private InetSocketAddress address;
private long connectionTimeoutMillis = DEFAULT_CONNECTION_TIMEOUT_MILLIS;
return this;
}
- public NetconfClientConfigurationBuilder withProtocol(final NetconfClientConfiguration.NetconfClientProtocol clientProtocol) {
+ public NetconfClientConfigurationBuilder withProtocol(
+ final NetconfClientConfiguration.NetconfClientProtocol clientProtocol) {
this.clientProtocol = clientProtocol;
return this;
}
- public NetconfClientConfigurationBuilder withAdditionalHeader(final NetconfHelloMessageAdditionalHeader additionalHeader) {
+ public NetconfClientConfigurationBuilder withAdditionalHeader(
+ final NetconfHelloMessageAdditionalHeader additionalHeader) {
this.additionalHeader = additionalHeader;
return this;
}
}
public NetconfClientConfiguration build() {
- return new NetconfClientConfiguration(clientProtocol, address, connectionTimeoutMillis, additionalHeader, sessionListener, reconnectStrategy, authHandler);
+ return new NetconfClientConfiguration(clientProtocol, address, connectionTimeoutMillis, additionalHeader,
+ sessionListener, reconnectStrategy, authHandler);
}
}
private final ReconnectStrategyFactory connectStrategyFactory;
NetconfReconnectingClientConfiguration(final NetconfClientProtocol clientProtocol, final InetSocketAddress address,
- final Long connectionTimeoutMillis, final NetconfHelloMessageAdditionalHeader additionalHeader,
- final NetconfClientSessionListener sessionListener, final ReconnectStrategy reconnectStrategy,
- final ReconnectStrategyFactory connectStrategyFactory, final AuthenticationHandler authHandler) {
+ final Long connectionTimeoutMillis,
+ final NetconfHelloMessageAdditionalHeader additionalHeader,
+ final NetconfClientSessionListener sessionListener,
+ final ReconnectStrategy reconnectStrategy,
+ final ReconnectStrategyFactory connectStrategyFactory,
+ final AuthenticationHandler authHandler) {
super(clientProtocol, address, connectionTimeoutMillis, additionalHeader, sessionListener, reconnectStrategy,
authHandler);
this.connectStrategyFactory = connectStrategyFactory;
}
- public NetconfReconnectingClientConfigurationBuilder withConnectStrategyFactory(final ReconnectStrategyFactory connectStrategyFactory) {
+ public NetconfReconnectingClientConfigurationBuilder withConnectStrategyFactory(
+ final ReconnectStrategyFactory connectStrategyFactory) {
this.connectStrategyFactory = connectStrategyFactory;
return this;
}
@Override
public NetconfReconnectingClientConfiguration build() {
- return new NetconfReconnectingClientConfiguration(getProtocol(), getAddress(), getConnectionTimeoutMillis(), getAdditionalHeader(), getSessionListener(), getReconnectStrategy(), connectStrategyFactory, getAuthHandler());
+ return new NetconfReconnectingClientConfiguration(getProtocol(), getAddress(), getConnectionTimeoutMillis(),
+ getAdditionalHeader(), getSessionListener(), getReconnectStrategy(), connectStrategyFactory,
+ getAuthHandler());
}
// Override setter methods to return subtype
}
@Override
- public NetconfReconnectingClientConfigurationBuilder withConnectionTimeoutMillis(final long connectionTimeoutMillis) {
- return (NetconfReconnectingClientConfigurationBuilder) super.withConnectionTimeoutMillis(connectionTimeoutMillis);
+ public NetconfReconnectingClientConfigurationBuilder withConnectionTimeoutMillis(
+ final long connectionTimeoutMillis) {
+ return (NetconfReconnectingClientConfigurationBuilder)
+ super.withConnectionTimeoutMillis(connectionTimeoutMillis);
}
@Override
- public NetconfReconnectingClientConfigurationBuilder withAdditionalHeader(final NetconfHelloMessageAdditionalHeader additionalHeader) {
+ public NetconfReconnectingClientConfigurationBuilder withAdditionalHeader(
+ final NetconfHelloMessageAdditionalHeader additionalHeader) {
return (NetconfReconnectingClientConfigurationBuilder) super.withAdditionalHeader(additionalHeader);
}
@Override
- public NetconfReconnectingClientConfigurationBuilder withSessionListener(final NetconfClientSessionListener sessionListener) {
+ public NetconfReconnectingClientConfigurationBuilder withSessionListener(
+ final NetconfClientSessionListener sessionListener) {
return (NetconfReconnectingClientConfigurationBuilder) super.withSessionListener(sessionListener);
}
@Override
- public NetconfReconnectingClientConfigurationBuilder withReconnectStrategy(final ReconnectStrategy reconnectStrategy) {
+ public NetconfReconnectingClientConfigurationBuilder withReconnectStrategy(
+ final ReconnectStrategy reconnectStrategy) {
return (NetconfReconnectingClientConfigurationBuilder) super.withReconnectStrategy(reconnectStrategy);
}
}
@Override
- public NetconfReconnectingClientConfigurationBuilder withProtocol(NetconfClientConfiguration.NetconfClientProtocol clientProtocol) {
+ public NetconfReconnectingClientConfigurationBuilder withProtocol(
+ NetconfClientConfiguration.NetconfClientProtocol clientProtocol) {
return (NetconfReconnectingClientConfigurationBuilder) super.withProtocol(clientProtocol);
}
}
@Test
public void testNetconfClientConfiguration() throws Exception {
Long timeout = 200L;
- NetconfHelloMessageAdditionalHeader header = new NetconfHelloMessageAdditionalHeader("a", "host", "port", "trans", "id");
+ NetconfHelloMessageAdditionalHeader header =
+ new NetconfHelloMessageAdditionalHeader("a", "host", "port", "trans", "id");
NetconfClientSessionListener listener = new SimpleNetconfClientSessionListener();
InetSocketAddress address = InetSocketAddress.createUnresolved("host", 830);
ReconnectStrategy strategy = Mockito.mock(ReconnectStrategy.class);
AuthenticationHandler handler = Mockito.mock(AuthenticationHandler.class);
- NetconfClientConfiguration cfg = NetconfClientConfigurationBuilder.create().
- withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH).
- withAddress(address).
- withConnectionTimeoutMillis(timeout).
- withReconnectStrategy(strategy).
- withAdditionalHeader(header).
- withSessionListener(listener).
- withAuthHandler(handler).build();
+ NetconfClientConfiguration cfg = NetconfClientConfigurationBuilder.create()
+ .withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH)
+ .withAddress(address)
+ .withConnectionTimeoutMillis(timeout)
+ .withReconnectStrategy(strategy)
+ .withAdditionalHeader(header)
+ .withSessionListener(listener)
+ .withAuthHandler(handler).build();
Assert.assertEquals(timeout, cfg.getConnectionTimeoutMillis());
Assert.assertEquals(Optional.fromNullable(header), cfg.getAdditionalHeader());
doReturn(thr).when(chf).cause();
Long timeout = 200L;
- NetconfHelloMessageAdditionalHeader header = new NetconfHelloMessageAdditionalHeader("a", "host", "port", "trans", "id");
+ NetconfHelloMessageAdditionalHeader header =
+ new NetconfHelloMessageAdditionalHeader("a", "host", "port", "trans", "id");
NetconfClientSessionListener listener = new SimpleNetconfClientSessionListener();
InetSocketAddress address = InetSocketAddress.createUnresolved("host", 830);
ReconnectStrategyFactory reconnectStrategyFactory = Mockito.mock(ReconnectStrategyFactory.class);
doReturn("").when(reconnectStrategyFactory).toString();
doReturn(reconnect).when(reconnectStrategyFactory).createReconnectStrategy();
- NetconfReconnectingClientConfiguration cfg = NetconfReconnectingClientConfigurationBuilder.create().
- withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH).
- withAddress(address).
- withConnectionTimeoutMillis(timeout).
- withReconnectStrategy(reconnect).
- withAdditionalHeader(header).
- withSessionListener(listener).
- withConnectStrategyFactory(reconnectStrategyFactory).
- withAuthHandler(handler).build();
+ NetconfReconnectingClientConfiguration cfg = NetconfReconnectingClientConfigurationBuilder.create()
+ .withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH)
+ .withAddress(address)
+ .withConnectionTimeoutMillis(timeout)
+ .withReconnectStrategy(reconnect)
+ .withAdditionalHeader(header)
+ .withSessionListener(listener)
+ .withConnectStrategyFactory(reconnectStrategyFactory)
+ .withAuthHandler(handler).build();
- NetconfReconnectingClientConfiguration cfg2 = NetconfReconnectingClientConfigurationBuilder.create().
- withProtocol(NetconfClientConfiguration.NetconfClientProtocol.TCP).
- withAddress(address).
- withConnectionTimeoutMillis(timeout).
- withReconnectStrategy(reconnect).
- withAdditionalHeader(header).
- withSessionListener(listener).
- withConnectStrategyFactory(reconnectStrategyFactory).
- withAuthHandler(handler).build();
+ NetconfReconnectingClientConfiguration cfg2 = NetconfReconnectingClientConfigurationBuilder.create()
+ .withProtocol(NetconfClientConfiguration.NetconfClientProtocol.TCP)
+ .withAddress(address)
+ .withConnectionTimeoutMillis(timeout)
+ .withReconnectStrategy(reconnect)
+ .withAdditionalHeader(header)
+ .withSessionListener(listener)
+ .withConnectStrategyFactory(reconnectStrategyFactory)
+ .withAuthHandler(handler).build();
NetconfClientDispatcherImpl dispatcher = new NetconfClientDispatcherImpl(bossGroup, workerGroup, timer);
Future<NetconfClientSession> sshSession = dispatcher.createClient(cfg);
Future<NetconfClientSession> tcpSession = dispatcher.createClient(cfg2);
Future<Void> sshReconn = dispatcher.createReconnectingClient(cfg);
- Future<Void> tcpReconn = dispatcher.createReconnectingClient(cfg2);
+ final Future<Void> tcpReconn = dispatcher.createReconnectingClient(cfg2);
assertNotNull(sshSession);
assertNotNull(tcpSession);
NetconfClientSessionNegotiatorFactory negotiatorFactory = new NetconfClientSessionNegotiatorFactory(timer,
Optional.<NetconfHelloMessageAdditionalHeader>absent(), 200L);
- SessionNegotiator<?> sessionNegotiator = negotiatorFactory.getSessionNegotiator(listenerFactory, channel, promise);
+ SessionNegotiator<?> sessionNegotiator = negotiatorFactory.getSessionNegotiator(listenerFactory, channel,
+ promise);
assertNotNull(sessionNegotiator);
}
}
@Before
public void setUp() throws Exception {
- helloMessage = NetconfHelloMessage.createClientHello(Sets.newSet("exi:1.0"), Optional.<NetconfHelloMessageAdditionalHeader>absent());
+ helloMessage = NetconfHelloMessage.createClientHello(Sets.newSet("exi:1.0"), Optional
+ .<NetconfHelloMessageAdditionalHeader>absent());
pipeline = mockChannelPipeline();
future = mockChannelFuture();
channel = mockChannel();
doReturn(handler).when(pipeline).replace(anyString(), anyString(), any(ChunkedFramingMechanismEncoder.class));
NetconfXMLToHelloMessageDecoder messageDecoder = new NetconfXMLToHelloMessageDecoder();
- doReturn(messageDecoder).when(pipeline).replace(anyString(), anyString(), any(NetconfXMLToMessageDecoder.class));
- doReturn(pipeline).when(pipeline).replace(any(ChannelHandler.class), anyString(), any(NetconfClientSession.class));
+ doReturn(messageDecoder).when(pipeline).replace(anyString(), anyString(), any(NetconfXMLToMessageDecoder
+ .class));
+ doReturn(pipeline).when(pipeline).replace(any(ChannelHandler.class), anyString(), any(NetconfClientSession
+ .class));
return pipeline;
}
}).when(eventLoop).execute(any(Runnable.class));
}
- private NetconfClientSessionNegotiator createNetconfClientSessionNegotiator(final Promise<NetconfClientSession> promise,
- final NetconfMessage startExi) {
+ private NetconfClientSessionNegotiator createNetconfClientSessionNegotiator(
+ final Promise<NetconfClientSession> promise,
+ final NetconfMessage startExi) {
ChannelProgressivePromise progressivePromise = mock(ChannelProgressivePromise.class);
NetconfClientSessionPreferences preferences = new NetconfClientSessionPreferences(helloMessage, startExi);
doReturn(progressivePromise).when(promise).setFailure(any(Throwable.class));
NetconfClientSessionListener sessionListener = mock(NetconfClientSessionListener.class);
NetconfClientSessionNegotiator negotiator = createNetconfClientSessionNegotiator(promise, null);
- Set<String> set = createCapabilities("/helloMessage3.xml");
+ Set<String> set = createCapabilities("/helloMessage3.xml");
- final Set<String> cachedS1 = (Set<String>) negotiator.getSession(sessionListener,channel,createHelloMsg("/helloMessage1.xml")).getServerCapabilities();
+ final Set<String> cachedS1 = (Set<String>) negotiator.getSession(sessionListener, channel,
+ createHelloMsg("/helloMessage1.xml")).getServerCapabilities();
//helloMessage2 and helloMessage3 are the same with different order
- final Set<String> cachedS2 = (Set<String>) negotiator.getSession(sessionListener,channel,createHelloMsg("/helloMessage2.xml")).getServerCapabilities();
- final Set<String> cachedS3 = (Set<String>) negotiator.getSession(sessionListener,channel,createHelloMsg("/helloMessage3.xml")).getServerCapabilities();
+ final Set<String> cachedS2 = (Set<String>) negotiator.getSession(sessionListener, channel,
+ createHelloMsg("/helloMessage2.xml")).getServerCapabilities();
+ final Set<String> cachedS3 = (Set<String>) negotiator.getSession(sessionListener, channel,
+ createHelloMsg("/helloMessage3.xml")).getServerCapabilities();
assertEquals(cachedS3, set);
assertNotEquals(cachedS1, set);
@Test
public void testNetconfReconnectingClientConfiguration() throws Exception {
Long timeout = 200L;
- NetconfHelloMessageAdditionalHeader header = new NetconfHelloMessageAdditionalHeader("a", "host", "port", "trans", "id");
+ NetconfHelloMessageAdditionalHeader header =
+ new NetconfHelloMessageAdditionalHeader("a", "host", "port", "trans", "id");
NetconfClientSessionListener listener = new SimpleNetconfClientSessionListener();
InetSocketAddress address = InetSocketAddress.createUnresolved("host", 830);
ReconnectStrategyFactory strategy = Mockito.mock(ReconnectStrategyFactory.class);
AuthenticationHandler handler = Mockito.mock(AuthenticationHandler.class);
ReconnectStrategy reconnect = Mockito.mock(ReconnectStrategy.class);
- NetconfReconnectingClientConfiguration cfg = NetconfReconnectingClientConfigurationBuilder.create().
- withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH).
- withAddress(address).
- withConnectionTimeoutMillis(timeout).
- withReconnectStrategy(reconnect).
- withAdditionalHeader(header).
- withSessionListener(listener).
- withConnectStrategyFactory(strategy).
- withAuthHandler(handler).build();
+ NetconfReconnectingClientConfiguration cfg = NetconfReconnectingClientConfigurationBuilder.create()
+ .withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH)
+ .withAddress(address)
+ .withConnectionTimeoutMillis(timeout)
+ .withReconnectStrategy(reconnect)
+ .withAdditionalHeader(header)
+ .withSessionListener(listener)
+ .withConnectStrategyFactory(strategy)
+ .withAuthHandler(handler).build();
Assert.assertEquals(timeout, cfg.getConnectionTimeoutMillis());
Assert.assertEquals(Optional.fromNullable(header), cfg.getAdditionalHeader());
@Test
public void testSessionDown() throws Exception {
SimpleNetconfClientSessionListener simpleListener = new SimpleNetconfClientSessionListener();
- Future<NetconfMessage> promise = simpleListener.sendRequest(message);
+ final Future<NetconfMessage> promise = simpleListener.sendRequest(message);
simpleListener.onSessionUp(clientSession);
verify(channel, times(1)).writeAndFlush(anyObject());
@Test
public void testSendRequest() throws Exception {
SimpleNetconfClientSessionListener simpleListener = new SimpleNetconfClientSessionListener();
- Future<NetconfMessage> promise = simpleListener.sendRequest(message);
+ final Future<NetconfMessage> promise = simpleListener.sendRequest(message);
simpleListener.onSessionUp(clientSession);
verify(channel, times(1)).writeAndFlush(anyObject());
@Test
public void testOnMessage() throws Exception {
SimpleNetconfClientSessionListener simpleListener = new SimpleNetconfClientSessionListener();
- Future<NetconfMessage> promise = simpleListener.sendRequest(message);
+ final Future<NetconfMessage> promise = simpleListener.sendRequest(message);
simpleListener.onSessionUp(clientSession);
verify(channel, times(1)).writeAndFlush(anyObject());
SessionNegotiator<?> sessionNegotiator = mock(SessionNegotiator.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(SessionListenerFactory.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);
Promise<NetconfClientSession> promise = mock(Promise.class);
doReturn("").when(promise).toString();
- SshClientChannelInitializer initializer = new SshClientChannelInitializer(authenticationHandler, negotiatorFactory,
- sessionListener);
+ SshClientChannelInitializer initializer = new SshClientChannelInitializer(authenticationHandler,
+ negotiatorFactory, sessionListener);
initializer.initialize(channel, promise);
verify(pipeline, times(1)).addFirst(any(ChannelHandler.class));
}
NetconfClientSessionNegotiatorFactory factory = mock(NetconfClientSessionNegotiatorFactory.class);
SessionNegotiator<?> sessionNegotiator = mock(SessionNegotiator.class);
doReturn("").when(sessionNegotiator).toString();
- doReturn(sessionNegotiator).when(factory).getSessionNegotiator(any(SessionListenerFactory.class), any(Channel.class), any(Promise.class));
+ doReturn(sessionNegotiator).when(factory).getSessionNegotiator(any(SessionListenerFactory.class),
+ any(Channel.class), any(Promise.class));
NetconfClientSessionListener listener = mock(NetconfClientSessionListener.class);
- TcpClientChannelInitializer initializer = new TcpClientChannelInitializer(factory, listener);
+ final TcpClientChannelInitializer initializer = new TcpClientChannelInitializer(factory, listener);
ChannelPipeline pipeline = mock(ChannelPipeline.class);
doReturn(pipeline).when(pipeline).addAfter(anyString(), anyString(), any(ChannelHandler.class));
Channel channel = mock(Channel.class);
/**
- * Synchronous netconf client suitable for testing
+ * Synchronous netconf client suitable for testing.
*/
public class TestingNetconfClient implements Closeable {
private final long sessionId;
public TestingNetconfClient(String clientLabel,
- NetconfClientDispatcher netconfClientDispatcher, final NetconfClientConfiguration config) throws InterruptedException {
+ NetconfClientDispatcher netconfClientDispatcher,
+ final NetconfClientConfiguration config) throws InterruptedException {
this.label = clientLabel;
sessionListener = config.getSessionListener();
Future<NetconfClientSession> clientFuture = netconfClientDispatcher.createClient(config);
}
public Future<NetconfMessage> sendRequest(NetconfMessage message) {
- return ((SimpleNetconfClientSessionListener)sessionListener).sendRequest(message);
+ return ((SimpleNetconfClientSessionListener) sessionListener).sendRequest(message);
}
public NetconfMessage sendMessage(NetconfMessage message, int attemptMsDelay) throws ExecutionException,
public static void main(String[] args) throws Exception {
HashedWheelTimer hashedWheelTimer = new HashedWheelTimer();
NioEventLoopGroup nettyGroup = new NioEventLoopGroup();
- NetconfClientDispatcherImpl netconfClientDispatcher = new NetconfClientDispatcherImpl(nettyGroup, nettyGroup, hashedWheelTimer);
+ NetconfClientDispatcherImpl netconfClientDispatcher = new NetconfClientDispatcherImpl(nettyGroup, nettyGroup,
+ hashedWheelTimer);
LoginPassword authHandler = new LoginPassword("admin", "admin");
- TestingNetconfClient client = new TestingNetconfClient("client", netconfClientDispatcher, getClientConfig("127.0.0.1", 1830, true, Optional.of(authHandler)));
+ TestingNetconfClient client = new TestingNetconfClient("client", netconfClientDispatcher,
+ getClientConfig("127.0.0.1", 1830, true, Optional.of(authHandler)));
System.console().writer().println(client.getCapabilities());
}
- private static NetconfClientConfiguration getClientConfig(String host ,int port, boolean ssh, Optional<? extends AuthenticationHandler> maybeAuthHandler) throws UnknownHostException {
+ private static NetconfClientConfiguration getClientConfig(String host, int port, boolean ssh, Optional<? extends
+ AuthenticationHandler> maybeAuthHandler) throws UnknownHostException {
InetSocketAddress netconfAddress = new InetSocketAddress(InetAddress.getByName(host), port);
final NetconfClientConfigurationBuilder b = NetconfClientConfigurationBuilder.create();
b.withAddress(netconfAddress);