use of org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities in project netconf by opendaylight.
the class NetconfDeviceTopologyAdapterTest method testDeviceUpdate.
@Test
public void testDeviceUpdate() throws Exception {
doReturn(emptyFluentFuture()).when(writeTx).commit();
NetconfDeviceTopologyAdapter adapter = new NetconfDeviceTopologyAdapter(id, txChain);
adapter.updateDeviceData(true, new NetconfDeviceCapabilities());
verify(txChain, times(2)).newWriteOnlyTransaction();
verify(writeTx, times(1)).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class));
verify(writeTx, times(1)).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class));
}
use of org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities in project netconf by opendaylight.
the class NetconfDeviceTest method testNetconfDeviceAvailableCapabilitiesBuilding.
@Test
public void testNetconfDeviceAvailableCapabilitiesBuilding() throws Exception {
final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
final NetconfDeviceCommunicator listener = getListener();
final EffectiveModelContextFactory schemaContextProviderFactory = getSchemaFactory();
final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice.SchemaResourcesDTO(getSchemaRegistry(), getSchemaRepository(), schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
final NetconfDevice device = new NetconfDeviceBuilder().setReconnectOnSchemasChange(true).setSchemaResourcesDTO(schemaResourcesDTO).setGlobalProcessingExecutor(getExecutor()).setId(getId()).setSalFacade(facade).setBaseSchemas(BASE_SCHEMAS).build();
final NetconfDevice netconfSpy = spy(device);
final NetconfSessionPreferences sessionCaps = getSessionCaps(true, Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&revision=" + TEST_REVISION));
final Map<QName, AvailableCapability.CapabilityOrigin> moduleBasedCaps = new HashMap<>();
moduleBasedCaps.putAll(sessionCaps.getModuleBasedCapsOrigin());
moduleBasedCaps.put(QName.create("(test:qname:side:loading)test"), AvailableCapability.CapabilityOrigin.UserDefined);
netconfSpy.onRemoteSessionUp(sessionCaps.replaceModuleCaps(moduleBasedCaps), listener);
final ArgumentCaptor<NetconfSessionPreferences> argument = ArgumentCaptor.forClass(NetconfSessionPreferences.class);
verify(facade, timeout(5000)).onDeviceConnected(any(MountPointContext.class), argument.capture(), any(DOMRpcService.class), isNull());
final NetconfDeviceCapabilities netconfDeviceCaps = argument.getValue().getNetconfDeviceCapabilities();
netconfDeviceCaps.getResolvedCapabilities().forEach(entry -> assertEquals("Builded 'AvailableCapability' schemas should match input capabilities.", moduleBasedCaps.get(QName.create(entry.getCapability())).getName(), entry.getCapabilityOrigin().getName()));
}
use of org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities in project netconf by opendaylight.
the class NetconfDeviceTest method testNetconfDeviceNotificationsCapabilityIsNotPresent.
@Test
public void testNetconfDeviceNotificationsCapabilityIsNotPresent() throws Exception {
final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
final NetconfDeviceCommunicator listener = getListener();
final EffectiveModelContextFactory schemaContextProviderFactory = getSchemaFactory();
final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice.SchemaResourcesDTO(getSchemaRegistry(), getSchemaRepository(), schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
final NetconfDevice device = new NetconfDeviceBuilder().setSchemaResourcesDTO(schemaResourcesDTO).setGlobalProcessingExecutor(getExecutor()).setId(getId()).setSalFacade(facade).setBaseSchemas(BASE_SCHEMAS).build();
final NetconfDevice netconfSpy = spy(device);
final NetconfSessionPreferences sessionCaps = getSessionCaps(false, Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&revision=" + TEST_REVISION));
netconfSpy.onRemoteSessionUp(sessionCaps, listener);
final ArgumentCaptor<NetconfSessionPreferences> argument = ArgumentCaptor.forClass(NetconfSessionPreferences.class);
verify(facade, timeout(5000)).onDeviceConnected(any(MountPointContext.class), argument.capture(), any(DOMRpcService.class), isNull());
final NetconfDeviceCapabilities netconfDeviceCaps = argument.getValue().getNetconfDeviceCapabilities();
List<String> notificationModulesName = Arrays.asList(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.$YangModuleInfoImpl.getInstance().getName().toString(), org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.$YangModuleInfoImpl.getInstance().getName().toString());
assertFalse(netconfDeviceCaps.getResolvedCapabilities().stream().anyMatch(entry -> notificationModulesName.contains(entry.getCapability())));
}
use of org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities in project netconf by opendaylight.
the class NetconfDeviceTopologyAdapterTest method testDeviceAugmentedNodePresence.
@Test
public void testDeviceAugmentedNodePresence() throws Exception {
Integer dataTestId = 474747;
NetconfDeviceTopologyAdapter adapter = new NetconfDeviceTopologyAdapter(id, transactionChain);
QName netconfTestLeafQname = QName.create("urn:TBD:params:xml:ns:yang:network-topology-augment-test", "2016-08-08", "test-id").intern();
YangInstanceIdentifier pathToAugmentedLeaf = YangInstanceIdentifier.builder().node(NetworkTopology.QNAME).node(Topology.QNAME).nodeWithKey(Topology.QNAME, QName.create(Topology.QNAME, "topology-id"), "topology-netconf").node(Node.QNAME).nodeWithKey(Node.QNAME, QName.create(Node.QNAME, "node-id"), "test").node(netconfTestLeafQname).build();
NormalizedNode augmentNode = ImmutableLeafNodeBuilder.create().withValue(dataTestId).withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(netconfTestLeafQname)).build();
DOMDataTreeWriteTransaction wtx = domDataBroker.newWriteOnlyTransaction();
wtx.put(LogicalDatastoreType.OPERATIONAL, pathToAugmentedLeaf, augmentNode);
wtx.commit().get(5, TimeUnit.SECONDS);
adapter.updateDeviceData(true, new NetconfDeviceCapabilities());
Optional<NormalizedNode> testNode = domDataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, pathToAugmentedLeaf).get(2, TimeUnit.SECONDS);
assertTrue("Augmented node data should be still present after device update.", testNode.isPresent());
assertEquals("Augmented data should be the same as before update node.", dataTestId, testNode.get().body());
adapter.setDeviceAsFailed(null);
testNode = domDataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, pathToAugmentedLeaf).get(2, TimeUnit.SECONDS);
assertEquals("Augmented node data should be still present after device failed.", true, testNode.isPresent());
assertEquals("Augmented data should be the same as before failed device.", dataTestId, testNode.get().body());
}
use of org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities in project netconf by opendaylight.
the class AbstractNetconfTopology method setupConnection.
protected ListenableFuture<NetconfDeviceCapabilities> setupConnection(final NodeId nodeId, final Node configNode) {
final NetconfNode netconfNode = configNode.augmentation(NetconfNode.class);
final NetconfNodeAugmentedOptional nodeOptional = configNode.augmentation(NetconfNodeAugmentedOptional.class);
requireNonNull(netconfNode.getHost());
requireNonNull(netconfNode.getPort());
final NetconfConnectorDTO deviceCommunicatorDTO = createDeviceCommunicator(nodeId, netconfNode, nodeOptional);
final NetconfDeviceCommunicator deviceCommunicator = deviceCommunicatorDTO.getCommunicator();
final NetconfClientSessionListener netconfClientSessionListener = deviceCommunicatorDTO.getSessionListener();
final NetconfReconnectingClientConfiguration clientConfig = getClientConfig(netconfClientSessionListener, netconfNode);
final ListenableFuture<NetconfDeviceCapabilities> future = deviceCommunicator.initializeRemoteConnection(clientDispatcher, clientConfig);
activeConnectors.put(nodeId, deviceCommunicatorDTO);
Futures.addCallback(future, new FutureCallback<NetconfDeviceCapabilities>() {
@Override
public void onSuccess(final NetconfDeviceCapabilities result) {
LOG.debug("Connector for {} started succesfully", nodeId.getValue());
}
@Override
public void onFailure(final Throwable throwable) {
LOG.error("Connector for {} failed", nodeId.getValue(), throwable);
// remove this node from active connectors?
}
}, MoreExecutors.directExecutor());
return future;
}
Aggregations