Search in sources :

Example 16 with NetconfSessionPreferences

use of org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences in project netconf by opendaylight.

the class NetconfDeviceTest method testNetconfDeviceNotificationsModelIsPresent.

@Test
public void testNetconfDeviceNotificationsModelIsPresent() 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, Collections.emptyList());
    final Map<QName, AvailableCapability.CapabilityOrigin> moduleBasedCaps = new HashMap<>();
    moduleBasedCaps.put(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.$YangModuleInfoImpl.getInstance().getName(), AvailableCapability.CapabilityOrigin.DeviceAdvertised);
    moduleBasedCaps.put(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.$YangModuleInfoImpl.getInstance().getName(), AvailableCapability.CapabilityOrigin.DeviceAdvertised);
    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 Set<AvailableCapability> resolvedCapabilities = argument.getValue().getNetconfDeviceCapabilities().getResolvedCapabilities();
    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());
    assertEquals(2, resolvedCapabilities.size());
    assertTrue(resolvedCapabilities.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) 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) AvailableCapability(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.available.capabilities.AvailableCapability) Test(org.junit.Test)

Example 17 with NetconfSessionPreferences

use of org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences in project netconf by opendaylight.

the class NetconfDeviceTest method testNetconfDeviceFlawedModelFailedResolution.

@Test
public void testNetconfDeviceFlawedModelFailedResolution() throws Exception {
    final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
    final NetconfDeviceCommunicator listener = getListener();
    final EffectiveModelContextFactory schemaFactory = getSchemaFactory();
    final SchemaRepository schemaRepository = getSchemaRepository();
    final SchemaResolutionException schemaResolutionException = new SchemaResolutionException("fail first", TEST_SID, new Throwable("YangTools parser fail"));
    doAnswer(invocation -> {
        if (((Collection<?>) invocation.getArguments()[0]).size() == 2) {
            return Futures.immediateFailedFuture(schemaResolutionException);
        } else {
            return Futures.immediateFuture(SCHEMA_CONTEXT);
        }
    }).when(schemaFactory).createEffectiveModelContext(anyCollection());
    final NetconfDeviceSchemasResolver stateSchemasResolver = (deviceRpc, remoteSessionCapabilities, id, schemaContext) -> {
        final Module first = Iterables.getFirst(SCHEMA_CONTEXT.getModules(), null);
        final QName qName = QName.create(first.getQNameModule(), first.getName());
        final NetconfStateSchemas.RemoteYangSchema source1 = new NetconfStateSchemas.RemoteYangSchema(qName);
        final NetconfStateSchemas.RemoteYangSchema source2 = new NetconfStateSchemas.RemoteYangSchema(QName.create(first.getQNameModule(), "test-module2"));
        return new NetconfStateSchemas(Sets.newHashSet(source1, source2));
    };
    final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice.SchemaResourcesDTO(getSchemaRegistry(), schemaRepository, schemaFactory, stateSchemasResolver);
    final NetconfDevice device = new NetconfDeviceBuilder().setReconnectOnSchemasChange(true).setSchemaResourcesDTO(schemaResourcesDTO).setGlobalProcessingExecutor(getExecutor()).setId(getId()).setSalFacade(facade).setBaseSchemas(BASE_SCHEMAS).build();
    // Monitoring supported
    final NetconfSessionPreferences sessionCaps = getSessionCaps(true, Lists.newArrayList(TEST_CAPABILITY, TEST_CAPABILITY2));
    device.onRemoteSessionUp(sessionCaps, listener);
    verify(facade, timeout(5000)).onDeviceConnected(any(MountPointContext.class), any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class), isNull());
    verify(schemaFactory, times(2)).createEffectiveModelContext(anyCollection());
}
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) NetconfDeviceRpc(org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc) NetconfDeviceCommunicator(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator) 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) SchemaResolutionException(org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException) Module(org.opendaylight.yangtools.yang.model.api.Module) NetconfDeviceSchemasResolver(org.opendaylight.netconf.sal.connect.api.NetconfDeviceSchemasResolver) SchemaRepository(org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository) Test(org.junit.Test)

Example 18 with NetconfSessionPreferences

use of org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences in project netconf by opendaylight.

the class NetconfDeviceTest method testNetconfDeviceReconnect.

@Test
public void testNetconfDeviceReconnect() 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 NetconfSessionPreferences sessionCaps = getSessionCaps(true, Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&amp;revision=" + TEST_REVISION));
    device.onRemoteSessionUp(sessionCaps, listener);
    verify(schemaContextProviderFactory, timeout(5000)).createEffectiveModelContext(any(Collection.class));
    verify(facade, timeout(5000)).onDeviceConnected(any(MountPointContext.class), any(NetconfSessionPreferences.class), any(DOMRpcService.class), isNull());
    device.onRemoteSessionDown();
    verify(facade, timeout(5000)).onDeviceDisconnected();
    device.onRemoteSessionUp(sessionCaps, listener);
    verify(schemaContextProviderFactory, timeout(5000).times(2)).createEffectiveModelContext(any(Collection.class));
    verify(facade, timeout(5000).times(2)).onDeviceConnected(any(MountPointContext.class), any(NetconfSessionPreferences.class), any(DOMRpcService.class), isNull());
}
Also used : 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) Collection(java.util.Collection) ArgumentMatchers.anyCollection(org.mockito.ArgumentMatchers.anyCollection) NetconfSessionPreferences(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences) MountPointContext(org.opendaylight.yangtools.rfc8528.data.api.MountPointContext) Test(org.junit.Test)

Example 19 with NetconfSessionPreferences

use of org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences in project netconf by opendaylight.

the class NetconfDeviceSalFacadeTest method testOnDeviceConnected.

@Test
public void testOnDeviceConnected() {
    final EffectiveModelContext schemaContext = mock(EffectiveModelContext.class);
    final NetconfSessionPreferences netconfSessionPreferences = NetconfSessionPreferences.fromStrings(getCapabilities());
    final DOMRpcService deviceRpc = mock(DOMRpcService.class);
    deviceFacade.onDeviceConnected(new EmptyMountPointContext(schemaContext), netconfSessionPreferences, deviceRpc, null);
    verify(mountInstance, times(1)).onTopologyDeviceConnected(eq(schemaContext), any(DOMDataBroker.class), any(NetconfDataTreeService.class), eq(deviceRpc), any(NetconfDeviceNotificationService.class), isNull());
    verify(netconfDeviceTopologyAdapter, times(1)).updateDeviceData(true, netconfSessionPreferences.getNetconfDeviceCapabilities());
}
Also used : DOMRpcService(org.opendaylight.mdsal.dom.api.DOMRpcService) EmptyMountPointContext(org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext) NetconfDataTreeService(org.opendaylight.netconf.dom.api.NetconfDataTreeService) NetconfSessionPreferences(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences) DOMDataBroker(org.opendaylight.mdsal.dom.api.DOMDataBroker) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 20 with NetconfSessionPreferences

use of org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences in project netconf by opendaylight.

the class AbstractNetconfTopology method createDeviceCommunicator.

protected NetconfConnectorDTO createDeviceCommunicator(final NodeId nodeId, final NetconfNode node, final NetconfNodeAugmentedOptional nodeOptional) {
    final Host host = node.getHost();
    final IpAddress ipAddress = host.getIpAddress();
    final InetSocketAddress address;
    if (ipAddress != null) {
        address = new InetSocketAddress(IetfInetUtil.INSTANCE.inetAddressFor(ipAddress), node.getPort().getValue().toJava());
    } else {
        address = new InetSocketAddress(host.getDomainName().getValue(), node.getPort().getValue().toJava());
    }
    final RemoteDeviceId remoteDeviceId = new RemoteDeviceId(nodeId.getValue(), address);
    final long keepaliveDelay = node.requireKeepaliveDelay().toJava();
    RemoteDeviceHandler<NetconfSessionPreferences> salFacade = createSalFacade(remoteDeviceId);
    if (keepaliveDelay > 0) {
        LOG.info("Adding keepalive facade, for device {}", nodeId);
        salFacade = new KeepaliveSalFacade(remoteDeviceId, salFacade, this.keepaliveExecutor.getExecutor(), keepaliveDelay, node.requireDefaultRequestTimeoutMillis().toJava());
    }
    final RemoteDevice<NetconfSessionPreferences, NetconfMessage, NetconfDeviceCommunicator> device;
    final List<SchemaSourceRegistration<?>> yanglibRegistrations;
    if (node.requireSchemaless()) {
        device = new SchemalessNetconfDevice(baseSchemas, remoteDeviceId, salFacade);
        yanglibRegistrations = List.of();
    } else {
        final boolean reconnectOnChangedSchema = node.requireReconnectOnChangedSchema();
        final SchemaResourcesDTO resources = schemaManager.getSchemaResources(node, nodeId.getValue());
        device = new NetconfDeviceBuilder().setReconnectOnSchemasChange(reconnectOnChangedSchema).setSchemaResourcesDTO(resources).setGlobalProcessingExecutor(this.processingExecutor).setId(remoteDeviceId).setSalFacade(salFacade).setNode(node).setEventExecutor(eventExecutor).setNodeOptional(nodeOptional).setDeviceActionFactory(deviceActionFactory).setBaseSchemas(baseSchemas).build();
        yanglibRegistrations = registerDeviceSchemaSources(remoteDeviceId, node, resources);
    }
    final Optional<UserPreferences> userCapabilities = getUserCapabilities(node);
    final int rpcMessageLimit = node.requireConcurrentRpcLimit().toJava();
    if (rpcMessageLimit < 1) {
        LOG.info("Concurrent rpc limit is smaller than 1, no limit will be enforced for device {}", remoteDeviceId);
    }
    final NetconfDeviceCommunicator netconfDeviceCommunicator = userCapabilities.isPresent() ? new NetconfDeviceCommunicator(remoteDeviceId, device, userCapabilities.get(), rpcMessageLimit) : new NetconfDeviceCommunicator(remoteDeviceId, device, rpcMessageLimit);
    if (salFacade instanceof KeepaliveSalFacade) {
        ((KeepaliveSalFacade) salFacade).setListener(netconfDeviceCommunicator);
    }
    return new NetconfConnectorDTO(netconfDeviceCommunicator, salFacade, yanglibRegistrations);
}
Also used : UserPreferences(org.opendaylight.netconf.sal.connect.netconf.listener.UserPreferences) NetconfDeviceCommunicator(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator) InetSocketAddress(java.net.InetSocketAddress) KeepaliveSalFacade(org.opendaylight.netconf.sal.connect.netconf.sal.KeepaliveSalFacade) Host(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host) NetconfSessionPreferences(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences) SchemaResourcesDTO(org.opendaylight.netconf.sal.connect.netconf.NetconfDevice.SchemaResourcesDTO) RemoteDeviceId(org.opendaylight.netconf.sal.connect.util.RemoteDeviceId) NetconfDeviceBuilder(org.opendaylight.netconf.sal.connect.netconf.NetconfDeviceBuilder) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) SchemaSourceRegistration(org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) SchemalessNetconfDevice(org.opendaylight.netconf.sal.connect.netconf.SchemalessNetconfDevice)

Aggregations

NetconfSessionPreferences (org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences)21 Test (org.junit.Test)15 NetconfDeviceCommunicator (org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator)14 EffectiveModelContextFactory (org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory)10 DOMRpcService (org.opendaylight.mdsal.dom.api.DOMRpcService)9 RemoteDeviceId (org.opendaylight.netconf.sal.connect.util.RemoteDeviceId)9 ArrayList (java.util.ArrayList)8 Collection (java.util.Collection)8 ArgumentMatchers.anyCollection (org.mockito.ArgumentMatchers.anyCollection)8 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)8 MountPointContext (org.opendaylight.yangtools.rfc8528.data.api.MountPointContext)8 InetSocketAddress (java.net.InetSocketAddress)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 HashMultimap (com.google.common.collect.HashMultimap)5 Iterables (com.google.common.collect.Iterables)5 Lists (com.google.common.collect.Lists)5 Sets (com.google.common.collect.Sets)5 Futures (com.google.common.util.concurrent.Futures)5 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)5