use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class NetconfToRpcRequestTest method testRpcResponse.
// The edit config defined in yang has no output
@Test(expected = IllegalArgumentException.class)
public void testRpcResponse() throws Exception {
final NetconfMessage response = new NetconfMessage(XmlUtil.readXmlToDocument("<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"m-5\">\n" + "<data xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">" + "module schema" + "</data>\n" + "</rpc-reply>\n"));
messageTransformer.toRpcResult(response, EDIT_CONFIG_QNAME);
}
use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class SchemalessNetconfDeviceTest method testSessionOnMethods.
@Test
public void testSessionOnMethods() throws Exception {
final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
final NetconfDeviceCommunicator listener = mockCloseableClass(NetconfDeviceCommunicator.class);
final SchemalessMessageTransformer messageTransformer = mock(SchemalessMessageTransformer.class);
final RemoteDeviceId remoteDeviceId = new RemoteDeviceId("test-D", InetSocketAddress.createUnresolved("localhost", 22));
final Throwable throwable = new Throwable();
final SchemalessNetconfDevice device = new SchemalessNetconfDevice(BASE_SCHEMAS, remoteDeviceId, facade, messageTransformer);
final NetconfSessionPreferences sessionCaps = getSessionCaps(true, Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&revision=" + TEST_REVISION));
final NetconfMessage netconfMessage = mock(NetconfMessage.class);
device.onRemoteSessionUp(sessionCaps, listener);
verify(facade).onDeviceConnected(any(MountPointContext.class), any(NetconfSessionPreferences.class), any(DOMRpcService.class));
device.onNotification(netconfMessage);
verify(facade).onNotification(isNull());
device.onRemoteSessionDown();
verify(facade).onDeviceDisconnected();
device.onRemoteSessionFailed(throwable);
verify(facade).onDeviceFailed(throwable);
}
use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class NetconfDeviceCommunicatorTest method createErrorResponseMessage.
private static NetconfMessage createErrorResponseMessage(final String messageID) throws Exception {
String xmlStr = "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"" + " message-id=\"" + messageID + "\">" + " <rpc-error>" + " <error-type>rpc</error-type>" + " <error-tag>missing-attribute</error-tag>" + " <error-severity>error</error-severity>" + " <error-message>Missing attribute</error-message>" + " <error-info>" + " <bad-attribute>foo</bad-attribute>" + " <bad-element>bar</bad-element>" + " </error-info>" + " </rpc-error>" + "</rpc-reply>";
ByteArrayInputStream bis = new ByteArrayInputStream(xmlStr.getBytes());
Document doc = UntrustedXML.newDocumentBuilder().parse(bis);
return new NetconfMessage(doc);
}
use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class NetconfDeviceCommunicatorTest method createSuccessResponseMessage.
private static NetconfMessage createSuccessResponseMessage(final String messageID) throws ParserConfigurationException {
Document doc = UntrustedXML.newDocumentBuilder().newDocument();
Element rpcReply = doc.createElementNS(URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, XmlNetconfConstants.RPC_REPLY_KEY);
rpcReply.setAttribute("message-id", messageID);
Element element = doc.createElementNS("ns", "data");
element.setTextContent(messageID);
rpcReply.appendChild(element);
doc.appendChild(rpcReply);
return new NetconfMessage(doc);
}
use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class NetconfDeviceCommunicatorTest method testNetconfDeviceReconnectInCommunicator.
/**
* Test whether reconnect is scheduled properly.
*/
@Test
public void testNetconfDeviceReconnectInCommunicator() {
final RemoteDevice<NetconfSessionPreferences, NetconfMessage, NetconfDeviceCommunicator> device = mock(RemoteDevice.class);
final TimedReconnectStrategy timedReconnectStrategy = new TimedReconnectStrategy(GlobalEventExecutor.INSTANCE, 10000, 0, 1.0, null, 100L, null);
final ReconnectStrategy reconnectStrategy = spy(new ReconnectStrategy() {
@Override
@Deprecated
public int getConnectTimeout() throws Exception {
return timedReconnectStrategy.getConnectTimeout();
}
@Override
@Deprecated
public Future<Void> scheduleReconnect(final Throwable cause) {
return timedReconnectStrategy.scheduleReconnect(cause);
}
@Override
@Deprecated
public void reconnectSuccessful() {
timedReconnectStrategy.reconnectSuccessful();
}
});
final EventLoopGroup group = new NioEventLoopGroup();
final Timer time = new HashedWheelTimer();
try {
final NetconfDeviceCommunicator listener = new NetconfDeviceCommunicator(new RemoteDeviceId("test", InetSocketAddress.createUnresolved("localhost", 22)), device, 10);
final NetconfReconnectingClientConfiguration cfg = NetconfReconnectingClientConfigurationBuilder.create().withAddress(new InetSocketAddress("localhost", 65000)).withReconnectStrategy(reconnectStrategy).withConnectStrategyFactory(() -> reconnectStrategy).withAuthHandler(new LoginPasswordHandler("admin", "admin")).withConnectionTimeoutMillis(10000).withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH).withSessionListener(listener).build();
listener.initializeRemoteConnection(new NetconfClientDispatcherImpl(group, group, time), cfg);
verify(reconnectStrategy, timeout(TimeUnit.MINUTES.toMillis(4)).times(101)).scheduleReconnect(any(Throwable.class));
} finally {
time.stop();
group.shutdownGracefully();
}
}
Aggregations