use of org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader in project netconf by opendaylight.
the class NetconfClientConfigurationTest method testNetconfClientConfiguration.
@Test
public void testNetconfClientConfiguration() throws Exception {
Long timeout = 200L;
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();
Assert.assertEquals(timeout, cfg.getConnectionTimeoutMillis());
Assert.assertEquals(Optional.of(header), cfg.getAdditionalHeader());
Assert.assertEquals(listener, cfg.getSessionListener());
Assert.assertEquals(handler, cfg.getAuthHandler());
Assert.assertEquals(strategy, cfg.getReconnectStrategy());
Assert.assertEquals(NetconfClientConfiguration.NetconfClientProtocol.SSH, cfg.getProtocol());
Assert.assertEquals(address, cfg.getAddress());
SslHandlerFactory sslHandlerFactory = Mockito.mock(SslHandlerFactory.class);
NetconfClientConfiguration cfg2 = NetconfClientConfigurationBuilder.create().withProtocol(NetconfClientConfiguration.NetconfClientProtocol.TLS).withAddress(address).withConnectionTimeoutMillis(timeout).withReconnectStrategy(strategy).withAdditionalHeader(header).withSessionListener(listener).withSslHandlerFactory(sslHandlerFactory).build();
Assert.assertEquals(timeout, cfg2.getConnectionTimeoutMillis());
Assert.assertEquals(Optional.of(header), cfg2.getAdditionalHeader());
Assert.assertEquals(listener, cfg2.getSessionListener());
Assert.assertEquals(sslHandlerFactory, cfg2.getSslHandlerFactory());
Assert.assertEquals(strategy, cfg2.getReconnectStrategy());
Assert.assertEquals(NetconfClientConfiguration.NetconfClientProtocol.TLS, cfg2.getProtocol());
Assert.assertEquals(address, cfg2.getAddress());
}
use of org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader in project netconf by opendaylight.
the class NetconfServerSessionNegotiator method getSession.
@Override
@SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
protected NetconfServerSession getSession(NetconfServerSessionListener sessionListener, Channel channel, NetconfHelloMessage message) {
Optional<NetconfHelloMessageAdditionalHeader> additionalHeader = message.getAdditionalHeader();
NetconfHelloMessageAdditionalHeader parsedHeader;
if (additionalHeader.isPresent()) {
parsedHeader = additionalHeader.get();
} else {
parsedHeader = new NetconfHelloMessageAdditionalHeader(UNKNOWN, getHostName(channel.localAddress()).getValue(), getHostName(channel.localAddress()).getKey(), "tcp", "client");
}
LOG.debug("Additional header from hello parsed as {} from {}", parsedHeader, additionalHeader);
return new NetconfServerSession(sessionListener, channel, getSessionPreferences().getSessionId(), parsedHeader);
}
use of org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader in project netconf by opendaylight.
the class NetconfServerSessionTest method testToManagementSession.
@Test
public void testToManagementSession() throws Exception {
final NetconfHelloMessageAdditionalHeader header = new NetconfHelloMessageAdditionalHeader(USER, HOST, PORT, TCP_TRANSPORT, SESSION_ID);
final EmbeddedChannel ch = new EmbeddedChannel();
final NetconfServerSession tcpSession = new NetconfServerSession(listener, ch, 1L, header);
tcpSession.sessionUp();
final Session managementSession = tcpSession.toManagementSession();
assertEquals(HOST, managementSession.getSourceHost().getIpAddress().getIpv4Address().getValue());
assertEquals(managementSession.getUsername(), USER);
assertEquals(managementSession.getSessionId().toString(), SESSION_ID);
assertEquals(managementSession.getTransport(), NetconfTcp.class);
}
use of org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader in project netconf by opendaylight.
the class NetconfServerSessionTest method testToManagementSessionUnknownTransport.
@Test(expected = IllegalArgumentException.class)
public void testToManagementSessionUnknownTransport() throws Exception {
final NetconfHelloMessageAdditionalHeader header = new NetconfHelloMessageAdditionalHeader(USER, HOST, PORT, "http", SESSION_ID);
final EmbeddedChannel ch = new EmbeddedChannel();
final NetconfServerSession tcpSession = new NetconfServerSession(listener, ch, 1L, header);
tcpSession.sessionUp();
tcpSession.toManagementSession();
tcpSession.close();
}
use of org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader in project netconf by opendaylight.
the class NetconfServerSessionTest method setUp.
@Before
public void setUp() throws Exception {
final NetconfHelloMessageAdditionalHeader header = new NetconfHelloMessageAdditionalHeader(USER, HOST, PORT, SSH_TRANSPORT, SESSION_ID);
channel = new EmbeddedChannel();
session = new NetconfServerSession(listener, channel, 1L, header);
doNothing().when(listener).onSessionUp(any());
msg = new NetconfMessage(XmlUtil.readXmlToDocument("<rpc-reply></rpc-reply>"));
}
Aggregations