Search in sources :

Example 46 with NetconfMessage

use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.

the class NetconfMessageTransformerTest method testGetConfigRequest.

@Test
public void testGetConfigRequest() throws Exception {
    final AnyxmlNode<?> filter = toFilterStructure(YangInstanceIdentifier.create(toId(NetconfState.QNAME), toId(Schemas.QNAME)), SCHEMA);
    final ContainerNode source = NetconfBaseOps.getSourceNode(NETCONF_RUNNING_QNAME);
    final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(NETCONF_GET_CONFIG_QNAME, NetconfMessageTransformUtil.wrap(NETCONF_GET_CONFIG_QNAME, source, filter));
    assertSimilarXml(netconfMessage, "<rpc message-id=\"m-0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" + "<get-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" + "<filter xmlns:ns0=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ns0:type=\"subtree\">\n" + "<netconf-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n" + "<schemas/>\n" + "</netconf-state>" + "</filter>\n" + "<source>\n" + "<running/>\n" + "</source>\n" + "</get-config>" + "</rpc>");
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 47 with NetconfMessage

use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.

the class NetconfMessageTransformerTest method testDiscardChangesRequest.

@Test
public void testDiscardChangesRequest() throws Exception {
    final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(NETCONF_DISCARD_CHANGES_QNAME, null);
    assertThat(XmlUtil.toString(netconfMessage.getDocument()), CoreMatchers.containsString("<discard"));
    assertThat(XmlUtil.toString(netconfMessage.getDocument()), CoreMatchers.containsString("<rpc"));
    assertThat(XmlUtil.toString(netconfMessage.getDocument()), CoreMatchers.containsString("message-id"));
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 48 with NetconfMessage

use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.

the class NetconfMessageTransformerTest method getSpecificFieldsUnderListTest.

@Test
public void getSpecificFieldsUnderListTest() throws IOException, SAXException {
    // preparation of the fields
    final YangInstanceIdentifier parentYiid = YangInstanceIdentifier.create(toId(NetconfState.QNAME), toId(Schemas.QNAME), toId(Schema.QNAME), NodeIdentifierWithPredicates.of(Schema.QNAME));
    final YangInstanceIdentifier versionField = YangInstanceIdentifier.create(toId(QName.create(Schema.QNAME, "version").intern()));
    final YangInstanceIdentifier identifierField = YangInstanceIdentifier.create(toId(QName.create(Schema.QNAME, "namespace").intern()));
    // building filter structure and NETCONF message
    final AnyxmlNode<?> filterStructure = toFilterStructure(List.of(FieldsFilter.of(parentYiid, List.of(versionField, identifierField))), SCHEMA);
    final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(NETCONF_GET_QNAME, NetconfMessageTransformUtil.wrap(toId(NETCONF_GET_QNAME), filterStructure));
    // testing
    assertSimilarXml(netconfMessage, "<rpc message-id=\"m-0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" + "<get>\n" + "<filter xmlns:ns0=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ns0:type=\"subtree\">\n" + "<netconf-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n" + "<schemas>\n" + "<schema>\n" + "<version/>\n" + "<namespace/>\n" + // explicitly fetched list keys - identifier and format
    "<identifier/>\n" + "<format/>\n" + "</schema>\n" + "</schemas>\n" + "</netconf-state>\n" + "</filter>\n" + "</get>\n" + "</rpc>");
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 49 with NetconfMessage

use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.

the class NetconfClientSessionNegotiatorTest method testNetconfClientSessionNegotiatorWithEXI.

@Test
public void testNetconfClientSessionNegotiatorWithEXI() throws Exception {
    Promise<NetconfClientSession> promise = mock(Promise.class);
    NetconfStartExiMessage exiMessage = NetconfStartExiMessage.create(EXIParameters.empty(), "msg-id");
    doReturn(promise).when(promise).setSuccess(any());
    NetconfClientSessionNegotiator negotiator = createNetconfClientSessionNegotiator(promise, exiMessage);
    negotiator.channelActive(null);
    Set<String> caps = Sets.newSet("exi:1.0");
    NetconfHelloMessage message = NetconfHelloMessage.createServerHello(caps, 10);
    doAnswer(invocationOnMock -> {
        channelInboundHandlerAdapter = invocationOnMock.getArgument(2);
        return null;
    }).when(pipeline).addAfter(anyString(), anyString(), any(ChannelHandler.class));
    ChannelHandlerContext handlerContext = mock(ChannelHandlerContext.class);
    doReturn(pipeline).when(handlerContext).pipeline();
    negotiator.handleMessage(message);
    Document expectedResult = XmlFileLoader.xmlFileToDocument("netconfMessages/rpc-reply_ok.xml");
    channelInboundHandlerAdapter.channelRead(handlerContext, new NetconfMessage(expectedResult));
    verify(promise).setSuccess(any());
    // two calls for exiMessage, 2 for hello message
    verify(pipeline, times(4)).replace(anyString(), anyString(), any(ChannelHandler.class));
}
Also used : NetconfStartExiMessage(org.opendaylight.netconf.nettyutil.handler.exi.NetconfStartExiMessage) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) NetconfHelloMessage(org.opendaylight.netconf.api.messages.NetconfHelloMessage) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ChannelHandler(io.netty.channel.ChannelHandler) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 50 with NetconfMessage

use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.

the class SimpleNetconfClientSessionListenerTest method testSessionDown.

@Test
public void testSessionDown() throws Exception {
    SimpleNetconfClientSessionListener simpleListener = new SimpleNetconfClientSessionListener();
    final Future<NetconfMessage> promise = simpleListener.sendRequest(message);
    simpleListener.onSessionUp(clientSession);
    verify(channel, times(1)).writeAndFlush(any(), any());
    simpleListener.onSessionDown(clientSession, new Exception());
    assertFalse(promise.isSuccess());
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) NetconfDocumentedException(org.opendaylight.netconf.api.NetconfDocumentedException) Test(org.junit.Test)

Aggregations

NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)125 Test (org.junit.Test)72 AbstractBaseSchemasTest (org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest)40 Document (org.w3c.dom.Document)28 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)23 QName (org.opendaylight.yangtools.yang.common.QName)17 DOMSourceAnyxmlNode (org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode)15 Test (org.junit.jupiter.api.Test)13 SimpleNetconfClientSessionListener (org.opendaylight.netconf.client.SimpleNetconfClientSessionListener)13 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)13 Node (org.w3c.dom.Node)13 NetconfClientSession (org.opendaylight.netconf.client.NetconfClientSession)12 ArrayList (java.util.ArrayList)11 Element (org.w3c.dom.Element)11 DOMRpcResult (org.opendaylight.mdsal.dom.api.DOMRpcResult)10 UnkeyedListNode (org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode)10 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)9 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)9 ChannelFuture (io.netty.channel.ChannelFuture)8 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)8