Search in sources :

Example 1 with NetconfClientSession

use of org.opendaylight.netconf.client.NetconfClientSession in project lighty-netconf-simulator by PANTHEONtech.

the class NotificationTest method getNotificationSchemaTest.

@Test
public void getNotificationSchemaTest() throws IOException, URISyntaxException, SAXException, InterruptedException, ExecutionException, TimeoutException {
    final SimpleNetconfClientSessionListener sessionListener = new SimpleNetconfClientSessionListener();
    try (NetconfClientSession session = dispatcher.createClient(createSHHConfig(sessionListener)).get(TimeoutUtil.TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) {
        final NetconfMessage schemaResponse = sendRequesttoDevice(sessionListener, GET_SCHEMAS_REQUEST_XML);
        final NodeList schema = schemaResponse.getDocument().getDocumentElement().getElementsByTagName("schema");
        assertTrue(schema.getLength() > 0);
        boolean notificationSchemaContained = false;
        for (int i = 0; i < schema.getLength(); i++) {
            if (schema.item(i).getNodeType() == Node.ELEMENT_NODE) {
                final Element item = (Element) schema.item(i);
                final String schemaName = item.getElementsByTagName("identifier").item(0).getTextContent();
                final String schemaNameSpace = item.getElementsByTagName("namespace").item(0).getTextContent();
                if ("lighty-test-notifications".equals(schemaName) && "yang:lighty:test:notifications".equals(schemaNameSpace)) {
                    notificationSchemaContained = true;
                }
            }
        }
        assertTrue(notificationSchemaContained);
    }
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) SimpleNetconfClientSessionListener(org.opendaylight.netconf.client.SimpleNetconfClientSessionListener) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) NetconfClientSession(org.opendaylight.netconf.client.NetconfClientSession) Test(org.junit.jupiter.api.Test)

Example 2 with NetconfClientSession

use of org.opendaylight.netconf.client.NetconfClientSession in project lighty-netconf-simulator by PANTHEONtech.

the class NotificationTest method triggerNotificationRpcTest.

@Test
public void triggerNotificationRpcTest() throws IOException, URISyntaxException, SAXException, InterruptedException, ExecutionException, TimeoutException {
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    final NotificationNetconfSessionListener sessionListener = new NotificationNetconfSessionListener(countDownLatch, EXPECTED_NOTIFICATION_PAYLOAD);
    try (NetconfClientSession session = dispatcher.createClient(createSHHConfig(sessionListener)).get(TimeoutUtil.TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) {
        final NetconfMessage subscribeResponse = sendRequesttoDevice(sessionListener, SUBCRIBE_TO_NOTIFICATIONS_REQUEST_XML);
        final boolean okPresent = subscribeResponse.getDocument().getDocumentElement().getElementsByTagName("ok").getLength() > 0;
        assertTrue(okPresent);
        final boolean msgIdMatches = subscribeResponse.getDocument().getDocumentElement().getAttribute("message-id").equals(SUBSCRIBE_MSG_TAG);
        assertTrue(msgIdMatches);
        sendRequesttoDevice(sessionListener, TRIGGER_DATA_NOTIFICATION_REQUEST_XML);
        final boolean isNotificationPublished = countDownLatch.await(REQUEST_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
        assertTrue(isNotificationPublished);
    }
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) CountDownLatch(java.util.concurrent.CountDownLatch) NetconfClientSession(org.opendaylight.netconf.client.NetconfClientSession) Test(org.junit.jupiter.api.Test)

Example 3 with NetconfClientSession

use of org.opendaylight.netconf.client.NetconfClientSession in project lighty-netconf-simulator by PANTHEONtech.

the class DeviceTest method deviceRpcTest.

@Test
public void deviceRpcTest() throws ExecutionException, InterruptedException, IOException, URISyntaxException, SAXException, TimeoutException {
    final SimpleNetconfClientSessionListener sessionListener = new SimpleNetconfClientSessionListener();
    try (NetconfClientSession session = dispatcher.createClient(createSHHConfig(sessionListener)).get(TimeoutUtil.TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) {
        final NetconfMessage createTopoResponse = sendRequestToDevice(CREATE_TOPOLOGY_RPC_REQUEST_XML, sessionListener);
        assertResponseIsIdentical(createTopoResponse, xmlFileToInputStream(CREATE_TOPOLOGY_RPC_RESPONSE_XML));
        final NetconfMessage addNodeResponse = sendRequestToDevice(ADD_NODE_RPC_REQUEST_XML, sessionListener);
        assertResponseIsIdentical(addNodeResponse, xmlFileToInputStream(EXCEPTED_ADD_NODE_RESPONSE));
        final NetconfMessage deleteTopoResponse = sendRequestToDevice(DELETE_TOPOLOGY_RPC_REQUEST_XML, sessionListener);
        assertResponseIsIdentical(deleteTopoResponse, xmlFileToInputStream(DELETE_TOPOLOGY_RPC_RESPONSE_XML));
    }
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) SimpleNetconfClientSessionListener(org.opendaylight.netconf.client.SimpleNetconfClientSessionListener) NetconfClientSession(org.opendaylight.netconf.client.NetconfClientSession) Test(org.junit.jupiter.api.Test)

Example 4 with NetconfClientSession

use of org.opendaylight.netconf.client.NetconfClientSession in project lighty-netconf-simulator by PANTHEONtech.

the class ToasterDeviceTest method getSchemaTest.

@Test
public void getSchemaTest() throws IOException, URISyntaxException, SAXException, InterruptedException, ExecutionException, TimeoutException {
    final SimpleNetconfClientSessionListener sessionListener = new SimpleNetconfClientSessionListener();
    try (NetconfClientSession session = dispatcher.createClient(createSHHConfig(sessionListener)).get(TimeoutUtil.TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) {
        final NetconfMessage schemaResponse = sentRequestToDevice(GET_SCHEMAS_REQUEST_XML, sessionListener);
        final NodeList schema = schemaResponse.getDocument().getDocumentElement().getElementsByTagName("schema");
        assertTrue(schema.getLength() > 0);
        boolean toasterSchemaContained = false;
        for (int i = 0; i < schema.getLength(); i++) {
            if (schema.item(i).getNodeType() == Node.ELEMENT_NODE) {
                final Element item = (Element) schema.item(i);
                final String schemaName = item.getElementsByTagName("identifier").item(0).getTextContent();
                final String schemaNameSpace = item.getElementsByTagName("namespace").item(0).getTextContent();
                if ("toaster".equals(schemaName) && "http://netconfcentral.org/ns/toaster".equals(schemaNameSpace)) {
                    toasterSchemaContained = true;
                }
            }
        }
        assertTrue(toasterSchemaContained);
    }
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) SimpleNetconfClientSessionListener(org.opendaylight.netconf.client.SimpleNetconfClientSessionListener) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) NetconfClientSession(org.opendaylight.netconf.client.NetconfClientSession) Test(org.junit.jupiter.api.Test)

Example 5 with NetconfClientSession

use of org.opendaylight.netconf.client.NetconfClientSession in project lighty-netconf-simulator by PANTHEONtech.

the class ToasterDeviceTest method toasterRpcsTest.

@Test
public void toasterRpcsTest() throws ExecutionException, InterruptedException, URISyntaxException, SAXException, TimeoutException, IOException {
    final SimpleNetconfClientSessionListener sessionListenerSimple = new SimpleNetconfClientSessionListener();
    try (NetconfClientSession sessionSimple = dispatcher.createClient(createSHHConfig(sessionListenerSimple)).get(TimeoutUtil.TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) {
        final NetconfMessage createToasterResponse = sentRequestToDevice(CREATE_TOASTER_REQUEST_XML, sessionListenerSimple);
        assertTrue(containsOkElement(createToasterResponse));
        final NetconfMessage toasterData = sentRequestToDevice(GET_TOASTER_DATA_REQUEST_XML, sessionListenerSimple);
        final String toasterDarknessFactor = toasterData.getDocument().getDocumentElement().getElementsByTagName("darknessFactor").item(0).getTextContent();
        assertEquals(EXPECTED_DARKNESS_FACTOR, toasterDarknessFactor);
        final NetconfMessage makeToastResponse = sentRequestToDevice(MAKE_TOAST_REQUEST_XML, sessionListenerSimple);
        assertTrue(containsOkElement(makeToastResponse));
        final NetconfMessage restockToastResponse = sentRequestToDevice(RESTOCK_TOAST_REQUEST_XML, sessionListenerSimple);
        assertTrue(containsOkElement(restockToastResponse));
    }
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) SimpleNetconfClientSessionListener(org.opendaylight.netconf.client.SimpleNetconfClientSessionListener) NetconfClientSession(org.opendaylight.netconf.client.NetconfClientSession) Test(org.junit.jupiter.api.Test)

Aggregations

NetconfClientSession (org.opendaylight.netconf.client.NetconfClientSession)18 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)12 SimpleNetconfClientSessionListener (org.opendaylight.netconf.client.SimpleNetconfClientSessionListener)11 Test (org.junit.jupiter.api.Test)10 Test (org.junit.Test)5 NodeList (org.w3c.dom.NodeList)5 NetconfClientSessionListener (org.opendaylight.netconf.client.NetconfClientSessionListener)4 Element (org.w3c.dom.Element)4 HashedWheelTimer (io.netty.util.HashedWheelTimer)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 NetconfClientConfiguration (org.opendaylight.netconf.client.conf.NetconfClientConfiguration)2 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 DefaultThreadFactory (io.netty.util.concurrent.DefaultThreadFactory)1 InetSocketAddress (java.net.InetSocketAddress)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 NetconfTerminationReason (org.opendaylight.netconf.api.NetconfTerminationReason)1 NetconfClientDispatcherImpl (org.opendaylight.netconf.client.NetconfClientDispatcherImpl)1 NetconfClientSessionNegotiatorFactory (org.opendaylight.netconf.client.NetconfClientSessionNegotiatorFactory)1 TlsClientChannelInitializer (org.opendaylight.netconf.client.TlsClientChannelInitializer)1 Document (org.w3c.dom.Document)1