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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations