Search in sources :

Example 1 with NetconfSessionPreferences

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

the class RemoteDeviceConnectorImpl method getUserCapabilities.

private static Optional<NetconfSessionPreferences> getUserCapabilities(final NetconfNode node) {
    if (node.getYangModuleCapabilities() == null && node.getNonModuleCapabilities() == null) {
        return Optional.empty();
    }
    final List<String> capabilities = new ArrayList<>();
    if (node.getYangModuleCapabilities() != null) {
        capabilities.addAll(node.getYangModuleCapabilities().getCapability());
    }
    // non-module capabilities should not exist in yang module capabilities
    final NetconfSessionPreferences netconfSessionPreferences = NetconfSessionPreferences.fromStrings(capabilities);
    checkState(netconfSessionPreferences.getNonModuleCaps().isEmpty(), "List yang-module-capabilities/capability should contain only module based capabilities. " + "Non-module capabilities used: " + netconfSessionPreferences.getNonModuleCaps());
    if (node.getNonModuleCapabilities() != null) {
        capabilities.addAll(node.getNonModuleCapabilities().getCapability());
    }
    return Optional.of(NetconfSessionPreferences.fromStrings(capabilities, CapabilityOrigin.UserDefined));
}
Also used : ArrayList(java.util.ArrayList) NetconfSessionPreferences(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences)

Example 2 with NetconfSessionPreferences

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

the class RemoteDeviceConnectorImplTest method testKeapAliveFacade.

@SuppressWarnings("unchecked")
@Test
public void testKeapAliveFacade() {
    final Credentials credentials = new LoginPasswordBuilder().setPassword("admin").setUsername("admin").build();
    final NetconfNode netconfNode = new NetconfNodeBuilder().setHost(new Host(new IpAddress(new Ipv4Address("127.0.0.1")))).setPort(new PortNumber(Uint16.valueOf(9999))).setReconnectOnChangedSchema(true).setDefaultRequestTimeoutMillis(Uint32.valueOf(1000)).setBetweenAttemptsTimeoutMillis(Uint16.valueOf(100)).setSchemaless(false).setTcpOnly(false).setCredentials(credentials).setKeepaliveDelay(Uint32.ONE).build();
    final Node node = new NodeBuilder().setNodeId(NODE_ID).addAugmentation(netconfNode).build();
    builder.setSchemaResourceDTO(new DefaultSchemaResourceManager(new DefaultYangParserFactory()).getSchemaResources(netconfNode, "foo"));
    final RemoteDeviceConnectorImpl remoteDeviceConnection = new RemoteDeviceConnectorImpl(builder.build(), remoteDeviceId, deviceActionFactory);
    final RemoteDeviceHandler<NetconfSessionPreferences> salFacade = mock(RemoteDeviceHandler.class);
    final NetconfConnectorDTO connectorDTO = remoteDeviceConnection.createDeviceCommunicator(NODE_ID, netconfNode, salFacade);
    assertTrue(connectorDTO.getFacade() instanceof KeepaliveSalFacade);
}
Also used : NetconfNodeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder) 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) NetconfNode(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode) 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) DefaultYangParserFactory(org.opendaylight.yangtools.yang.parser.impl.DefaultYangParserFactory) NetconfNodeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder) NodeBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder) NetconfSessionPreferences(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences) NetconfConnectorDTO(org.opendaylight.netconf.topology.spi.NetconfConnectorDTO) LoginPasswordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.credentials.LoginPasswordBuilder) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) PortNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber) DefaultSchemaResourceManager(org.opendaylight.netconf.sal.connect.impl.DefaultSchemaResourceManager) Credentials(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.Credentials) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Test(org.junit.Test)

Example 3 with NetconfSessionPreferences

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

the class RemoteDeviceConnectorImplTest method testStopRemoteDeviceConnection.

@SuppressWarnings("unchecked")
@Test
public void testStopRemoteDeviceConnection() {
    builder.setNode(new NodeBuilder().setNodeId(NODE_ID).addAugmentation(new NetconfNodeBuilder().setHost(new Host(new IpAddress(new Ipv4Address("127.0.0.1")))).setPort(new PortNumber(Uint16.valueOf(9999))).setReconnectOnChangedSchema(true).setDefaultRequestTimeoutMillis(Uint32.valueOf(1000)).setBetweenAttemptsTimeoutMillis(Uint16.valueOf(100)).setSchemaless(false).setTcpOnly(false).setCredentials(new LoginPasswordBuilder().setPassword("admin").setUsername("admin").build()).build()).build());
    final NetconfDeviceCommunicator communicator = mock(NetconfDeviceCommunicator.class);
    final RemoteDeviceHandler<NetconfSessionPreferences> salFacade = mock(RemoteDeviceHandler.class);
    final TestingRemoteDeviceConnectorImpl remoteDeviceConnection = new TestingRemoteDeviceConnectorImpl(builder.build(), remoteDeviceId, communicator, deviceActionFactory);
    remoteDeviceConnection.startRemoteDeviceConnection(salFacade);
    remoteDeviceConnection.stopRemoteDeviceConnection();
    verify(communicator, times(1)).close();
    verify(salFacade, times(1)).close();
}
Also used : NetconfDeviceCommunicator(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator) NetconfNodeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder) Host(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) LoginPasswordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.credentials.LoginPasswordBuilder) NetconfNodeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder) NodeBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder) PortNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber) NetconfSessionPreferences(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Test(org.junit.Test)

Example 4 with NetconfSessionPreferences

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

the class AbstractNetconfTopology method getUserCapabilities.

private static Optional<UserPreferences> getUserCapabilities(final NetconfNode node) {
    // just return absent
    if (node.getYangModuleCapabilities() == null && node.getNonModuleCapabilities() == null) {
        return Optional.empty();
    }
    final List<String> capabilities = new ArrayList<>();
    boolean overrideYangModuleCaps = false;
    if (node.getYangModuleCapabilities() != null) {
        capabilities.addAll(node.getYangModuleCapabilities().getCapability());
        overrideYangModuleCaps = node.getYangModuleCapabilities().getOverride();
    }
    // non-module capabilities should not exist in yang module capabilities
    final NetconfSessionPreferences netconfSessionPreferences = NetconfSessionPreferences.fromStrings(capabilities);
    Preconditions.checkState(netconfSessionPreferences.getNonModuleCaps().isEmpty(), "List yang-module-capabilities/capability should contain only module based capabilities. " + "Non-module capabilities used: " + netconfSessionPreferences.getNonModuleCaps());
    boolean overrideNonModuleCaps = false;
    if (node.getNonModuleCapabilities() != null) {
        capabilities.addAll(node.getNonModuleCapabilities().getCapability());
        overrideNonModuleCaps = node.getNonModuleCapabilities().getOverride();
    }
    return Optional.of(new UserPreferences(NetconfSessionPreferences.fromStrings(capabilities, CapabilityOrigin.UserDefined), overrideYangModuleCaps, overrideNonModuleCaps));
}
Also used : UserPreferences(org.opendaylight.netconf.sal.connect.netconf.listener.UserPreferences) ArrayList(java.util.ArrayList) NetconfSessionPreferences(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences)

Example 5 with NetconfSessionPreferences

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

the class NetconfDeviceDataBrokerTest method getDataBroker.

private NetconfDeviceDataBroker getDataBroker(final String... caps) {
    NetconfSessionPreferences prefs = NetconfSessionPreferences.fromStrings(Arrays.asList(caps));
    final RemoteDeviceId id = new RemoteDeviceId("device-1", InetSocketAddress.createUnresolved("localhost", 17830));
    return new NetconfDeviceDataBroker(id, new EmptyMountPointContext(SCHEMA_CONTEXT), rpcService, prefs);
}
Also used : RemoteDeviceId(org.opendaylight.netconf.sal.connect.util.RemoteDeviceId) EmptyMountPointContext(org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext) NetconfSessionPreferences(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences)

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