Search in sources :

Example 1 with NetconfDeviceCapabilities

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));
}
Also used : NetconfDeviceCapabilities(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities) NetconfNode(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) Test(org.junit.Test)

Example 2 with NetconfDeviceCapabilities

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 + "&amp;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()));
}
Also used : NetconfDeviceCommunicator(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator) DOMRpcService(org.opendaylight.mdsal.dom.api.DOMRpcService) HashMap(java.util.HashMap) QName(org.opendaylight.yangtools.yang.common.QName) EffectiveModelContextFactory(org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory) NetconfSessionPreferences(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences) MountPointContext(org.opendaylight.yangtools.rfc8528.data.api.MountPointContext) NetconfDeviceCapabilities(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities) Test(org.junit.Test)

Example 3 with NetconfDeviceCapabilities

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 + "&amp;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())));
}
Also used : Arrays(java.util.Arrays) SchemaSourceRegistration(org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) EffectiveModelContextFactory(org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory) SettableFuture(com.google.common.util.concurrent.SettableFuture) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) HashMultimap(com.google.common.collect.HashMultimap) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) Mockito.after(org.mockito.Mockito.after) Mockito.doReturn(org.mockito.Mockito.doReturn) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) RemoteDeviceHandler(org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler) DOMActionService(org.opendaylight.mdsal.dom.api.DOMActionService) XmlUtil(org.opendaylight.netconf.api.xml.XmlUtil) Module(org.opendaylight.yangtools.yang.model.api.Module) Collection(java.util.Collection) RemoteDeviceId(org.opendaylight.netconf.sal.connect.util.RemoteDeviceId) DOMNotification(org.opendaylight.mdsal.dom.api.DOMNotification) Set(java.util.Set) Mockito.doNothing(org.mockito.Mockito.doNothing) InetSocketAddress(java.net.InetSocketAddress) Sets(com.google.common.collect.Sets) Executors(java.util.concurrent.Executors) NetconfDeviceCommunicator(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator) SchemaSourceRepresentation(org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation) List(java.util.List) Revision(org.opendaylight.yangtools.yang.common.Revision) MissingSchemaSourceException(org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException) Assert.assertFalse(org.junit.Assert.assertFalse) PotentialSchemaSource(org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource) SAXException(org.xml.sax.SAXException) NetconfSessionPreferences(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences) Mockito.mock(org.mockito.Mockito.mock) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) YangTextSchemaSource(org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource) Iterables(com.google.common.collect.Iterables) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) ArrayList(java.util.ArrayList) Mockito.timeout(org.mockito.Mockito.timeout) SchemaSourceRegistry(org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry) Lists(com.google.common.collect.Lists) ArgumentCaptor(org.mockito.ArgumentCaptor) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) XmlNetconfConstants(org.opendaylight.netconf.api.xml.XmlNetconfConstants) NetconfDeviceRpc(org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) ArgumentMatchers.isNull(org.mockito.ArgumentMatchers.isNull) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) SchemaRepository(org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository) DOMRpcService(org.opendaylight.mdsal.dom.api.DOMRpcService) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) NetconfMessageTransformUtil(org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil) MountPointContext(org.opendaylight.yangtools.rfc8528.data.api.MountPointContext) QName(org.opendaylight.yangtools.yang.common.QName) Mockito.verify(org.mockito.Mockito.verify) ArgumentMatchers.anyCollection(org.mockito.ArgumentMatchers.anyCollection) Futures(com.google.common.util.concurrent.Futures) NetconfDeviceSchemasResolver(org.opendaylight.netconf.sal.connect.api.NetconfDeviceSchemasResolver) RevisionSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier) SchemaResolutionException(org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException) AvailableCapability(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.available.capabilities.AvailableCapability) Collections(java.util.Collections) NetconfDeviceCapabilities(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities) Assert.assertEquals(org.junit.Assert.assertEquals) MessageTransformer(org.opendaylight.netconf.sal.connect.api.MessageTransformer) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) NetconfDeviceCommunicator(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator) DOMRpcService(org.opendaylight.mdsal.dom.api.DOMRpcService) EffectiveModelContextFactory(org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory) NetconfSessionPreferences(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences) MountPointContext(org.opendaylight.yangtools.rfc8528.data.api.MountPointContext) NetconfDeviceCapabilities(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities) Test(org.junit.Test)

Example 4 with NetconfDeviceCapabilities

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());
}
Also used : QName(org.opendaylight.yangtools.yang.common.QName) NetconfDeviceCapabilities(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 5 with NetconfDeviceCapabilities

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;
}
Also used : NetconfClientSessionListener(org.opendaylight.netconf.client.NetconfClientSessionListener) NetconfNodeAugmentedOptional(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.optional.rev190614.NetconfNodeAugmentedOptional) NetconfDeviceCommunicator(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator) NetconfDeviceCapabilities(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities) NetconfNode(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode) NetconfReconnectingClientConfiguration(org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration)

Aggregations

NetconfDeviceCapabilities (org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities)8 Test (org.junit.Test)4 NetconfDeviceCommunicator (org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator)4 QName (org.opendaylight.yangtools.yang.common.QName)3 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)3 HashMap (java.util.HashMap)2 DOMRpcService (org.opendaylight.mdsal.dom.api.DOMRpcService)2 NetconfClientSessionListener (org.opendaylight.netconf.client.NetconfClientSessionListener)2 NetconfReconnectingClientConfiguration (org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration)2 NetconfSessionPreferences (org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences)2 NetconfNode (org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode)2 MountPointContext (org.opendaylight.yangtools.rfc8528.data.api.MountPointContext)2 EffectiveModelContextFactory (org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory)2 HashMultimap (com.google.common.collect.HashMultimap)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 Futures (com.google.common.util.concurrent.Futures)1 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1