Search in sources :

Example 11 with NetconfClientSession

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

the class ToasterDeviceTest method toasterNotificationTest.

@Test
public void toasterNotificationTest() throws ExecutionException, InterruptedException, URISyntaxException, SAXException, TimeoutException, IOException {
    final CountDownLatch notificationReceivedLatch = new CountDownLatch(1);
    final NotificationNetconfSessionListener sessionListenerNotification = new NotificationNetconfSessionListener(notificationReceivedLatch);
    final SimpleNetconfClientSessionListener sessionListenerSimple = new SimpleNetconfClientSessionListener();
    try (NetconfClientSession sessionNotification = dispatcher.createClient(createSHHConfig(sessionListenerNotification)).get(TimeoutUtil.TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
        NetconfClientSession sessionSimple = dispatcher.createClient(createSHHConfig(sessionListenerSimple)).get(TimeoutUtil.TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) {
        final NetconfMessage subscribeResponse = sentRequestToDevice(SUBSCRIBE_TO_NOTIFICATIONS_REQUEST_XML, sessionListenerNotification);
        assertTrue(containsOkElement(subscribeResponse));
        final NetconfMessage restockToastResponse = sentRequestToDevice(RESTOCK_TOAST_REQUEST_XML, sessionListenerSimple);
        assertTrue(containsOkElement(restockToastResponse));
        final boolean await = notificationReceivedLatch.await(REQUEST_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
        assertTrue(await);
        NetconfMessage restockToastNotification = sessionListenerNotification.getReceivedNotificationMessage();
        assertNotNull(restockToastNotification);
        assertTrue(containsNotificationElement(restockToastNotification));
        final String amountOfBreadExpected = XmlUtil.readXmlToDocument(xmlFileToInputStream(RESTOCK_TOAST_REQUEST_XML)).getElementsByTagName("amountOfBreadToStock").item(0).getTextContent();
        final String amountOfBread = restockToastNotification.getDocument().getElementsByTagName("amountOfBread").item(0).getTextContent();
        assertEquals(amountOfBreadExpected, amountOfBread);
    }
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) SimpleNetconfClientSessionListener(org.opendaylight.netconf.client.SimpleNetconfClientSessionListener) CountDownLatch(java.util.concurrent.CountDownLatch) NetconfClientSession(org.opendaylight.netconf.client.NetconfClientSession) Test(org.junit.jupiter.api.Test)

Example 12 with NetconfClientSession

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

the class DeviceTest method setUpClass.

@BeforeAll
public static void setUpClass() throws InterruptedException, ExecutionException, TimeoutException {
    deviceSimulator = new Main();
    deviceSimulator.start(new String[] { "--starting-port", String.valueOf(DEVICE_STARTING_PORT), "--thread-pool-size", String.valueOf(THREAD_POOL_SIZE), "--device-count", String.valueOf(DEVICE_COUNT) }, true, false);
    nettyGroup = new NioEventLoopGroup(THREAD_POOL_SIZE, new DefaultThreadFactory(NetconfClientDispatcher.class));
    NetconfClientDispatcherImpl dispatcher = new NetconfClientDispatcherImpl(nettyGroup, nettyGroup, new HashedWheelTimer());
    for (int port = DEVICE_STARTING_PORT; port < DEVICE_STARTING_PORT + DEVICE_COUNT; port++) {
        final SimpleNetconfClientSessionListener sessionListener = new SimpleNetconfClientSessionListener();
        NetconfClientSession session = dispatcher.createClient(createSHHConfig(sessionListener, port)).get(TimeoutUtil.TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
        NETCONF_CLIENT_SESSIONS.add(session);
        SESSION_LISTENERS.add(sessionListener);
    }
}
Also used : DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) SimpleNetconfClientSessionListener(org.opendaylight.netconf.client.SimpleNetconfClientSessionListener) HashedWheelTimer(io.netty.util.HashedWheelTimer) NetconfClientDispatcherImpl(org.opendaylight.netconf.client.NetconfClientDispatcherImpl) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) NetconfClientSession(org.opendaylight.netconf.client.NetconfClientSession) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 13 with NetconfClientSession

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

the class DeviceTest 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 = sendRequestToDevice(GET_SCHEMAS_REQUEST_XML, sessionListener);
        final NodeList schema = schemaResponse.getDocument().getDocumentElement().getElementsByTagName("schema");
        assertTrue(schema.getLength() > 0);
        boolean networkTopologySchemaContained = 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 ("network-topology".equals(schemaName) && "urn:TBD:params:xml:ns:yang:network-topology".equals(schemaNameSpace)) {
                    networkTopologySchemaContained = true;
                }
            }
        }
        assertTrue(networkTopologySchemaContained);
    }
}
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 14 with NetconfClientSession

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

the class DeviceTest method deviceConfigOperationsTest.

@Test
public void deviceConfigOperationsTest() throws InterruptedException, ExecutionException, IOException, TimeoutException, URISyntaxException, SAXException {
    final SimpleNetconfClientSessionListener sessionListener = new SimpleNetconfClientSessionListener();
    try (NetconfClientSession session = dispatcher.createClient(createSHHConfig(sessionListener)).get(TimeoutUtil.TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) {
        final NetconfMessage createTopoResponse = sendRequestToDevice(CREATE_TOPOLOGY_CONFIG_REQUEST_XML, sessionListener);
        assertTrue(containsOkElement(createTopoResponse));
        final NetconfMessage mergeTopoResponse = sendRequestToDevice(MERGE_TOPOLOGY_CONFIG_REQUEST_XML, sessionListener);
        assertTrue(containsOkElement(mergeTopoResponse));
        final NetconfMessage getConfigDataResponse = sendRequestToDevice(GET_CONFIG_REQUEST_XML, sessionListener);
        final NodeList topologies = getConfigDataResponse.getDocument().getElementsByTagName("topology");
        assertEquals(topologies.getLength(), 2);
        if (getTopologyID(topologies.item(0)).equals("test-config-topology")) {
            assertEquals(getTopologyID(topologies.item(0)), "test-config-topology");
            assertEquals(getTopologyID(topologies.item(1)), "test-config-topology-merge");
        } else {
            assertEquals(getTopologyID(topologies.item(1)), "test-config-topology");
            assertEquals(getTopologyID(topologies.item(0)), "test-config-topology-merge");
        }
        final NodeList nodes = getConfigDataResponse.getDocument().getElementsByTagName("node");
        assertEquals(nodes.getLength(), 1);
        final NetconfMessage deleteTopologyResponse = sendRequestToDevice(DELETE_TOPOLOGY_CONFIG_REQUEST_XML, sessionListener);
        assertTrue(containsOkElement(deleteTopologyResponse));
        final NetconfMessage getConfigDataResponseAfterDelete = sendRequestToDevice(GET_CONFIG_REQUEST_XML, sessionListener);
        final NodeList topologiesAfterDelete = getConfigDataResponseAfterDelete.getDocument().getElementsByTagName("topology");
        assertEquals(topologiesAfterDelete.getLength(), 1);
    }
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) SimpleNetconfClientSessionListener(org.opendaylight.netconf.client.SimpleNetconfClientSessionListener) NodeList(org.w3c.dom.NodeList) NetconfClientSession(org.opendaylight.netconf.client.NetconfClientSession) Test(org.junit.jupiter.api.Test)

Example 15 with NetconfClientSession

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

the class ActionDeviceTest 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(sessionListener, "get_schemas_request.xml");
        final NodeList schema = schemaResponse.getDocument().getDocumentElement().getElementsByTagName("schema");
        assertTrue(schema.getLength() > 0);
        boolean exampleDataCenterSchemaContained = 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 ("example-data-center".equals(schemaName) && "urn:example:data-center".equals(schemaNameSpace)) {
                    exampleDataCenterSchemaContained = true;
                }
            }
        }
        assertTrue(exampleDataCenterSchemaContained);
    }
}
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)

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