Search in sources :

Example 11 with SimpleNetconfClientSessionListener

use of org.opendaylight.netconf.client.SimpleNetconfClientSessionListener 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 12 with SimpleNetconfClientSessionListener

use of org.opendaylight.netconf.client.SimpleNetconfClientSessionListener 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 13 with SimpleNetconfClientSessionListener

use of org.opendaylight.netconf.client.SimpleNetconfClientSessionListener 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 14 with SimpleNetconfClientSessionListener

use of org.opendaylight.netconf.client.SimpleNetconfClientSessionListener 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

SimpleNetconfClientSessionListener (org.opendaylight.netconf.client.SimpleNetconfClientSessionListener)14 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)13 Test (org.junit.jupiter.api.Test)12 NetconfClientSession (org.opendaylight.netconf.client.NetconfClientSession)11 NodeList (org.w3c.dom.NodeList)6 Element (org.w3c.dom.Element)5 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 HashedWheelTimer (io.netty.util.HashedWheelTimer)1 DefaultThreadFactory (io.netty.util.concurrent.DefaultThreadFactory)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 NetconfClientDispatcherImpl (org.opendaylight.netconf.client.NetconfClientDispatcherImpl)1 NetconfClientConfiguration (org.opendaylight.netconf.client.conf.NetconfClientConfiguration)1 Document (org.w3c.dom.Document)1