import org.opendaylight.netconf.client.NetconfClientDispatcher;
import org.opendaylight.netconf.sal.connect.api.DeviceActionFactory;
import org.opendaylight.netconf.sal.connect.api.SchemaResourceManager;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
import org.opendaylight.netconf.topology.spi.AbstractNetconfTopology;
abstract class BaseCallHomeTopology extends AbstractNetconfTopology {
final DataBroker dataBroker,
final DOMMountPointService mountPointService,
final AAAEncryptionService encryptionService,
- final DeviceActionFactory deviceActionFactory) {
+ final DeviceActionFactory deviceActionFactory,
+ final BaseNetconfSchemas baseSchemas) {
super(topologyId, clientDispatcher, eventExecutor, keepaliveExecutor,
processingExecutor, schemaRepositoryProvider, dataBroker, mountPointService,
- encryptionService, deviceActionFactory);
+ encryptionService, deviceActionFactory, baseSchemas);
}
}
*/
package org.opendaylight.netconf.callhome.mount;
+import static java.util.Objects.requireNonNull;
+
import io.netty.util.concurrent.EventExecutor;
import io.netty.util.concurrent.FailedFuture;
import io.netty.util.concurrent.Future;
import org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration;
import org.opendaylight.netconf.sal.connect.api.DeviceActionFactory;
import org.opendaylight.netconf.sal.connect.api.SchemaResourceManager;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.slf4j.Logger;
};
private final DeviceActionFactory deviceActionFactory;
+ private final BaseNetconfSchemas baseSchemas;
public CallHomeMountDispatcher(final String topologyId, final EventExecutor eventExecutor,
final ScheduledThreadPool keepaliveExecutor, final ThreadPool processingExecutor,
- final SchemaResourceManager schemaRepositoryProvider, final DataBroker dataBroker,
+ final SchemaResourceManager schemaRepositoryProvider,
+ final BaseNetconfSchemas baseSchemas, final DataBroker dataBroker,
final DOMMountPointService mountService,
final AAAEncryptionService encryptionService) {
- this(topologyId, eventExecutor, keepaliveExecutor, processingExecutor, schemaRepositoryProvider, dataBroker,
- mountService, encryptionService, null);
+ this(topologyId, eventExecutor, keepaliveExecutor, processingExecutor, schemaRepositoryProvider, baseSchemas,
+ dataBroker, mountService, encryptionService, null);
}
public CallHomeMountDispatcher(final String topologyId, final EventExecutor eventExecutor,
final ScheduledThreadPool keepaliveExecutor, final ThreadPool processingExecutor,
- final SchemaResourceManager schemaRepositoryProvider, final DataBroker dataBroker,
- final DOMMountPointService mountService,
+ final SchemaResourceManager schemaRepositoryProvider, final BaseNetconfSchemas baseSchemas,
+ final DataBroker dataBroker, final DOMMountPointService mountService,
final AAAEncryptionService encryptionService, final DeviceActionFactory deviceActionFactory) {
this.topologyId = topologyId;
this.eventExecutor = eventExecutor;
this.schemaRepositoryProvider = schemaRepositoryProvider;
this.deviceActionFactory = deviceActionFactory;
this.sessionManager = new CallHomeMountSessionManager();
+ this.baseSchemas = requireNonNull(baseSchemas);
this.dataBroker = dataBroker;
this.mountService = mountService;
this.encryptionService = encryptionService;
void createTopology() {
this.topology = new CallHomeTopology(topologyId, this, eventExecutor, keepaliveExecutor, processingExecutor,
- schemaRepositoryProvider, dataBroker, mountService, encryptionService, deviceActionFactory);
+ schemaRepositoryProvider, dataBroker, mountService, encryptionService, baseSchemas,
+ deviceActionFactory);
}
@Override
import org.opendaylight.netconf.sal.connect.api.SchemaResourceManager;
import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceSalFacade;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
public class CallHomeTopology extends BaseCallHomeTopology {
final ScheduledThreadPool keepaliveExecutor, final ThreadPool processingExecutor,
final SchemaResourceManager schemaRepositoryProvider,
final DataBroker dataBroker, final DOMMountPointService mountPointService,
- final AAAEncryptionService encryptionService) {
+ final AAAEncryptionService encryptionService, final BaseNetconfSchemas baseSchemas) {
this(topologyId, clientDispatcher, eventExecutor,
keepaliveExecutor, processingExecutor, schemaRepositoryProvider,
- dataBroker, mountPointService, encryptionService, null);
+ dataBroker, mountPointService, encryptionService, baseSchemas, null);
}
public CallHomeTopology(final String topologyId, final NetconfClientDispatcher clientDispatcher,
final ScheduledThreadPool keepaliveExecutor, final ThreadPool processingExecutor,
final SchemaResourceManager schemaRepositoryProvider,
final DataBroker dataBroker, final DOMMountPointService mountPointService,
- final AAAEncryptionService encryptionService,
+ final AAAEncryptionService encryptionService, final BaseNetconfSchemas baseSchemas,
final DeviceActionFactory deviceActionFactory) {
super(topologyId, clientDispatcher, eventExecutor,
keepaliveExecutor, processingExecutor, schemaRepositoryProvider,
- dataBroker, mountPointService, encryptionService, deviceActionFactory);
+ dataBroker, mountPointService, encryptionService, deviceActionFactory, baseSchemas);
}
@Override
interface="org.opendaylight.netconf.sal.connect.api.DeviceActionFactory"/>
<reference id="schemaManager"
interface="org.opendaylight.netconf.sal.connect.api.SchemaResourceManager"/>
+ <reference id="baseSchemas"
+ interface="org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas"/>
<bean id="callhomeProvider" class="org.opendaylight.netconf.callhome.mount.IetfZeroTouchCallHomeServerProvider"
init-method="init"
<argument ref="keepAliveExecutor"/>
<argument ref="processingExecutor"/>
<argument ref="schemaManager"/>
+ <argument ref="baseSchemas"/>
<argument ref="dataBroker"/>
<argument ref="domMountPointService"/>
<argument ref="encryptionService"/>
import org.opendaylight.netconf.nettyutil.ReconnectStrategy;
import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
import org.opendaylight.netconf.sal.connect.api.SchemaResourceManager;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
private CallHomeTopology mockTopology;
private CallHomeProtocolSessionContext mockProtoSess;
private AAAEncryptionService mockEncryptionService;
+ private BaseNetconfSchemas mockBaseSchemas;
@Before
public void setup() {
mockTopology = mock(CallHomeTopology.class);
mockProtoSess = mock(CallHomeProtocolSessionContext.class);
mockEncryptionService = mock(AAAEncryptionService.class);
+ mockBaseSchemas = mock(BaseNetconfSchemas.class);
instance = new CallHomeMountDispatcher(topologyId, mockExecutor, mockKeepAlive,
- mockProcessingExecutor, mockSchemaRepoProvider, mockDataBroker, mockMount,
+ mockProcessingExecutor, mockSchemaRepoProvider, mockBaseSchemas, mockDataBroker, mockMount,
mockEncryptionService) {
@Override
public CallHomeMountSessionManager getSessionManager() {
import org.opendaylight.netconf.sal.connect.api.SchemaResourceManager;
import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceSalFacade;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
import org.opendaylight.netconf.topology.spi.AbstractNetconfTopology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
final ThreadPool processingExecutor,
final SchemaResourceManager schemaRepositoryProvider,
final DataBroker dataBroker, final DOMMountPointService mountPointService,
- final AAAEncryptionService encryptionService) {
+ final AAAEncryptionService encryptionService, final BaseNetconfSchemas baseSchemas) {
this(topologyId, clientDispatcher, eventExecutor, keepaliveExecutor, processingExecutor,
- schemaRepositoryProvider, dataBroker, mountPointService, encryptionService, null);
+ schemaRepositoryProvider, dataBroker, mountPointService, encryptionService, baseSchemas, null);
}
public NetconfTopologyImpl(final String topologyId, final NetconfClientDispatcher clientDispatcher,
final ThreadPool processingExecutor,
final SchemaResourceManager schemaRepositoryProvider,
final DataBroker dataBroker, final DOMMountPointService mountPointService,
- final AAAEncryptionService encryptionService,
+ final AAAEncryptionService encryptionService, final BaseNetconfSchemas baseSchemas,
final DeviceActionFactory deviceActionFactory) {
super(topologyId, clientDispatcher, eventExecutor, keepaliveExecutor, processingExecutor,
- schemaRepositoryProvider, dataBroker, mountPointService, encryptionService, deviceActionFactory);
+ schemaRepositoryProvider, dataBroker, mountPointService, encryptionService, deviceActionFactory,
+ baseSchemas);
}
@Override
interface="org.opendaylight.netconf.sal.connect.api.DeviceActionFactory"/>
<reference id="schemaManager"
interface="org.opendaylight.netconf.sal.connect.api.SchemaResourceManager"/>
+ <reference id="baseSchemas"
+ interface="org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas"/>
<cm:property-placeholder persistent-id="org.opendaylight.netconf.topology.sb.keypair" update-strategy="none">
<cm:default-properties>
<property name="privateKeyPath" value="${private-key-path}"/>
<property name="privateKeyPassphrase" value="${private-key-passphrase}"/>
<argument ref="encryptionService" />
+ <argument ref="baseSchemas"/>
<argument ref="deviceActionFactory"/>
</bean>
import org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration;
import org.opendaylight.netconf.sal.connect.api.SchemaResourceManager;
import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.DefaultBaseNetconfSchemas;
import org.opendaylight.netconf.topology.spi.AbstractNetconfTopology;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.common.Uint16;
import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.parser.impl.YangParserFactoryImpl;
@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class NetconfTopologyImplTest {
}
public static class TestingNetconfTopologyImpl extends NetconfTopologyImpl {
+ private static final BaseNetconfSchemas BASE_SCHEMAS =
+ new DefaultBaseNetconfSchemas(new YangParserFactoryImpl());
public TestingNetconfTopologyImpl(final String topologyId, final NetconfClientDispatcher clientDispatcher,
final EventExecutor eventExecutor,
final AAAEncryptionService encryptionService) {
super(topologyId, clientDispatcher, eventExecutor, keepaliveExecutor,
processingExecutor, schemaRepositoryProvider, dataBroker,
- mountPointService, encryptionService);
+ mountPointService, encryptionService, BASE_SCHEMAS);
}
@Override
import org.opendaylight.netconf.client.NetconfClientDispatcher;
import org.opendaylight.netconf.sal.connect.api.DeviceActionFactory;
import org.opendaylight.netconf.sal.connect.api.SchemaResourceManager;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
import org.opendaylight.netconf.topology.singleton.api.NetconfTopologySingletonService;
import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup;
private final Map<InstanceIdentifier<Node>, ClusterSingletonServiceRegistration>
clusterRegistrations = new ConcurrentHashMap<>();
+ private final BaseNetconfSchemas baseSchemas;
private final DataBroker dataBroker;
private final DOMRpcProviderService rpcProviderRegistry;
private final DOMActionProviderService actionProviderRegistry;
private final AAAEncryptionService encryptionService;
private final DeviceActionFactory deviceActionFactory;
private final SchemaResourceManager resourceManager;
+
private ListenerRegistration<NetconfTopologyManager> dataChangeListenerRegistration;
private String privateKeyPath;
private String privateKeyPassphrase;
- public NetconfTopologyManager(final DataBroker dataBroker, final DOMRpcProviderService rpcProviderRegistry,
+ public NetconfTopologyManager(final BaseNetconfSchemas baseSchemas, final DataBroker dataBroker,
+ final DOMRpcProviderService rpcProviderRegistry,
final DOMActionProviderService actionProviderService,
final ClusterSingletonServiceProvider clusterSingletonServiceProvider,
final ScheduledThreadPool keepaliveExecutor, final ThreadPool processingExecutor,
final AAAEncryptionService encryptionService,
final DeviceActionFactory deviceActionFactory,
final SchemaResourceManager resourceManager) {
+ this.baseSchemas = requireNonNull(baseSchemas);
this.dataBroker = requireNonNull(dataBroker);
this.rpcProviderRegistry = requireNonNull(rpcProviderRegistry);
this.actionProviderRegistry = requireNonNull(actionProviderService);
final NetconfTopologySetupBuilder builder = NetconfTopologySetupBuilder.create()
.setClusterSingletonServiceProvider(clusterSingletonServiceProvider)
+ .setBaseSchemas(baseSchemas)
.setDataBroker(dataBroker)
.setInstanceIdentifier(instanceIdentifier)
.setRpcProviderRegistry(rpcProviderRegistry)
final RemoteDevice<NetconfSessionPreferences, NetconfMessage, NetconfDeviceCommunicator> device;
if (node.isSchemaless()) {
- device = new SchemalessNetconfDevice(remoteDeviceId, salFacade);
+ device = new SchemalessNetconfDevice(netconfTopologyDeviceSetup.getBaseSchemas(), remoteDeviceId,
+ salFacade);
} else {
device = new NetconfDeviceBuilder()
.setReconnectOnSchemasChange(reconnectOnChangedSchema)
.setSchemaResourcesDTO(schemaResourcesDTO)
.setGlobalProcessingExecutor(netconfTopologyDeviceSetup.getProcessingExecutor())
+ .setBaseSchemas(netconfTopologyDeviceSetup.getBaseSchemas())
.setId(remoteDeviceId)
.setDeviceActionFactory(deviceActionFactory)
.setSalFacade(salFacade)
*/
package org.opendaylight.netconf.topology.singleton.impl.utils;
+import static java.util.Objects.requireNonNull;
+
import akka.actor.ActorSystem;
import com.google.common.util.concurrent.ListeningExecutorService;
import io.netty.util.concurrent.EventExecutor;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
import org.opendaylight.netconf.client.NetconfClientDispatcher;
import org.opendaylight.netconf.sal.connect.netconf.NetconfDevice;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import scala.concurrent.duration.Duration;
private final String privateKeyPath;
private final String privateKeyPassphrase;
private final AAAEncryptionService encryptionService;
+ private final BaseNetconfSchemas baseSchemas;
NetconfTopologySetup(final NetconfTopologySetupBuilder builder) {
this.clusterSingletonServiceProvider = builder.getClusterSingletonServiceProvider();
this.privateKeyPath = builder.getPrivateKeyPath();
this.privateKeyPassphrase = builder.getPrivateKeyPassphrase();
this.encryptionService = builder.getEncryptionService();
+ this.baseSchemas = builder.getBaseSchemas();
}
public ClusterSingletonServiceProvider getClusterSingletonServiceProvider() {
return encryptionService;
}
- public static class NetconfTopologySetupBuilder {
+ public BaseNetconfSchemas getBaseSchemas() {
+ return baseSchemas;
+ }
+ public static class NetconfTopologySetupBuilder {
private ClusterSingletonServiceProvider clusterSingletonServiceProvider;
private DOMRpcProviderService rpcProviderRegistry;
private DOMActionProviderService actionProviderRegistry;
private String privateKeyPath;
private String privateKeyPassphrase;
private AAAEncryptionService encryptionService;
+ private BaseNetconfSchemas baseSchemas;
public NetconfTopologySetupBuilder() {
}
+ BaseNetconfSchemas getBaseSchemas() {
+ return requireNonNull(baseSchemas, "BaseSchemas not initialized");
+ }
+
+ public NetconfTopologySetupBuilder setBaseSchemas(final BaseNetconfSchemas baseSchemas) {
+ this.baseSchemas = requireNonNull(baseSchemas);
+ return this;
+ }
+
ClusterSingletonServiceProvider getClusterSingletonServiceProvider() {
return clusterSingletonServiceProvider;
}
interface="org.opendaylight.netconf.sal.connect.api.DeviceActionFactory"/>
<reference id="schemaManager"
interface="org.opendaylight.netconf.sal.connect.api.SchemaResourceManager"/>
+ <reference id="baseSchemas"
+ interface="org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas"/>
<odl:clustered-app-config
id="singletonConfig"
binding-class="org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.topology.singleton.config.rev170419.Config"
init-method="init" destroy-method="close">
<cm:managed-properties persistent-id="org.opendaylight.netconf.topology.sb.keypair"
update-strategy="container-managed"/>
+ <argument ref="baseSchemas"/>
<argument ref="dataBroker"/>
<argument ref="rpcRegistry"/>
<argument ref="actionRegistry"/>
--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netconf.topology.singleton.impl;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.DefaultBaseNetconfSchemas;
+import org.opendaylight.yangtools.yang.parser.impl.YangParserFactoryImpl;
+
+public abstract class AbstractBaseSchemasTest {
+ protected static BaseNetconfSchemas BASE_SCHEMAS;
+
+ @BeforeClass
+ public static void initBaseSchemas() {
+ BASE_SCHEMAS = new DefaultBaseNetconfSchemas(new YangParserFactoryImpl());
+ }
+
+ @AfterClass
+ public static void freeBaseSchemas() {
+ BASE_SCHEMAS = null;
+ }
+}
* @author Thomas Pantelis
*/
@RunWith(MockitoJUnitRunner.class)
-public class MountPointEndToEndTest {
+public class MountPointEndToEndTest extends AbstractBaseSchemasTest {
private static final Logger LOG = LoggerFactory.getLogger(MountPointEndToEndTest.class);
private static final String TOP_MODULE_NAME = "opendaylight-mdsal-list-test";
PotentialSchemaSource.create(RevisionSourceIdentifier.create(TOP_MODULE_NAME,
topModuleInfo.getName().getRevision()), YangTextSchemaSource.class, 1));
- masterNetconfTopologyManager = new NetconfTopologyManager(masterDataBroker, mockRpcProviderRegistry,
- mockActionProviderRegistry, masterClusterSingletonServiceProvider, mockKeepaliveExecutor, mockThreadPool,
- mockMasterActorSystemProvider, eventExecutor, mockClientDispatcher, TOPOLOGY_ID, config,
- masterMountPointService, mockEncryptionService, deviceActionFactory, resourceManager) {
+ masterNetconfTopologyManager = new NetconfTopologyManager(BASE_SCHEMAS, masterDataBroker,
+ mockRpcProviderRegistry, mockActionProviderRegistry, masterClusterSingletonServiceProvider,
+ mockKeepaliveExecutor, mockThreadPool, mockMasterActorSystemProvider, eventExecutor,
+ mockClientDispatcher, TOPOLOGY_ID, config, masterMountPointService, mockEncryptionService,
+ deviceActionFactory, resourceManager) {
@Override
protected NetconfTopologyContext newNetconfTopologyContext(final NetconfTopologySetup setup,
final ServiceGroupIdentifier serviceGroupIdent, final Timeout actorResponseWaitTime,
doReturn(mockSlaveClusterSingletonServiceReg).when(mockSlaveClusterSingletonServiceProvider)
.registerClusterSingletonService(any());
- slaveNetconfTopologyManager = new NetconfTopologyManager(slaveDataBroker, mockRpcProviderRegistry,
+ slaveNetconfTopologyManager = new NetconfTopologyManager(BASE_SCHEMAS, slaveDataBroker, mockRpcProviderRegistry,
mockActionProviderRegistry, mockSlaveClusterSingletonServiceProvider, mockKeepaliveExecutor, mockThreadPool,
mockSlaveActorSystemProvider, eventExecutor, mockClientDispatcher, TOPOLOGY_ID, config,
slaveMountPointService, mockEncryptionService, deviceActionFactory, resourceManager) {
import scala.concurrent.Future;
import scala.concurrent.duration.Duration;
-public class NetconfNodeActorTest {
+public class NetconfNodeActorTest extends AbstractBaseSchemasTest {
private static final Timeout TIMEOUT = new Timeout(Duration.create(5, "seconds"));
private static final RevisionSourceIdentifier SOURCE_IDENTIFIER1 = RevisionSourceIdentifier.create("yang1");
doReturn(masterSchemaRepository).when(schemaResourceDTO).getSchemaRepository();
doReturn(mockRegistry).when(schemaResourceDTO).getSchemaRegistry();
final NetconfTopologySetup setup = NetconfTopologySetupBuilder.create().setActorSystem(system)
- .setIdleTimeout(Duration.apply(1, TimeUnit.SECONDS)).setSchemaResourceDTO(schemaResourceDTO).build();
+ .setIdleTimeout(Duration.apply(1, TimeUnit.SECONDS)).setSchemaResourceDTO(schemaResourceDTO)
+ .setBaseSchemas(BASE_SCHEMAS).build();
final Props props = NetconfNodeActor.props(setup, remoteDeviceId, TIMEOUT, mockMountPointService);
final RemoteDeviceId newRemoteDeviceId = new RemoteDeviceId("netconf-topology2",
new InetSocketAddress(InetAddresses.forString("127.0.0.2"), 9999));
- final NetconfTopologySetup newSetup = NetconfTopologySetupBuilder.create()
+ final NetconfTopologySetup newSetup = NetconfTopologySetupBuilder.create().setBaseSchemas(BASE_SCHEMAS)
.setSchemaResourceDTO(schemaResourceDTO).setActorSystem(system).build();
masterRef.tell(new RefreshSetupMasterActorData(newSetup, newRemoteDeviceId), testKit.getRef());
}
@Test
- public void tesAskForMasterMountPoint() {
+ public void testAskForMasterMountPoint() {
// Test with master not setup yet.
SchemaResourcesDTO schemaResourceDTO2 = mock(SchemaResourcesDTO.class);
doReturn(mockRegistry).when(schemaResourceDTO2).getSchemaRegistry();
doReturn(mockSchemaRepository).when(schemaResourceDTO2).getSchemaRepository();
- final NetconfTopologySetup setup = NetconfTopologySetupBuilder.create().setSchemaResourceDTO(schemaResourceDTO2)
- .setActorSystem(system).build();
+ final NetconfTopologySetup setup = NetconfTopologySetupBuilder.create()
+ .setSchemaResourceDTO(schemaResourceDTO2)
+ .setBaseSchemas(BASE_SCHEMAS)
+ .setActorSystem(system)
+ .build();
final ActorRef slaveRef = system.actorOf(NetconfNodeActor.props(setup, remoteDeviceId, TIMEOUT,
mockMountPointService));
doReturn(repository).when(schemaResourceDTO2).getSchemaRegistry();
doReturn(repository).when(schemaResourceDTO2).getSchemaRepository();
final NetconfTopologySetup setup = NetconfTopologySetupBuilder.create().setActorSystem(system)
- .setSchemaResourceDTO(schemaResourceDTO2).setIdleTimeout(Duration.apply(1, TimeUnit.SECONDS)).build();
+ .setSchemaResourceDTO(schemaResourceDTO2).setIdleTimeout(Duration.apply(1, TimeUnit.SECONDS))
+ .setBaseSchemas(BASE_SCHEMAS).build();
final Props props = NetconfNodeActor.props(setup, remoteDeviceId, TIMEOUT, mockMountPointService);
ActorRef actor = TestActorRef.create(system, props, "master_messages_2");
doReturn(mockSchemaRepository).when(schemaResourceDTO2).getSchemaRepository();
final ActorRef slaveRef = system.actorOf(NetconfNodeActor.props(
NetconfTopologySetupBuilder.create().setSchemaResourceDTO(schemaResourceDTO2).setActorSystem(system)
- .build(), remoteDeviceId, TIMEOUT, mockMountPointService));
+ .setBaseSchemas(BASE_SCHEMAS).build(), remoteDeviceId, TIMEOUT, mockMountPointService));
doReturn(Futures.immediateFuture(mockSchemaContext))
.when(mockSchemaContextFactory).createEffectiveModelContext(anyCollection());
*
* @author Thomas Pantelis
*/
-public class NetconfNodeManagerTest {
+public class NetconfNodeManagerTest extends AbstractBaseSchemasTest {
private static final String ACTOR_SYSTEM_NAME = "test";
private static final RemoteDeviceId DEVICE_ID = new RemoteDeviceId("device", new InetSocketAddress(65535));
private static final List<SourceIdentifier> SOURCE_IDENTIFIERS =
NetconfTopologySetup masterSetup = new NetconfTopologySetup.NetconfTopologySetupBuilder()
.setActorSystem(masterSystem).setDataBroker(mockDataBroker).setSchemaResourceDTO(
new NetconfDevice.SchemaResourcesDTO(masterSchemaRepository, masterSchemaRepository,
- mockSchemaContextFactory, mockSchemasResolver)).build();
+ mockSchemaContextFactory, mockSchemasResolver)).setBaseSchemas(BASE_SCHEMAS).build();
testMasterActorRef = TestActorRef.create(masterSystem, Props.create(TestMasterActor.class, masterSetup,
DEVICE_ID, responseTimeout, mockMountPointService).withDispatcher(Dispatchers.DefaultDispatcherId()),
NetconfTopologySetup slaveSetup = new NetconfTopologySetup.NetconfTopologySetupBuilder()
.setActorSystem(slaveSystem).setDataBroker(mockDataBroker).setSchemaResourceDTO(
new NetconfDevice.SchemaResourcesDTO(slaveSchemaRepository, slaveSchemaRepository,
- mockSchemaContextFactory, mockSchemasResolver)).build();
+ mockSchemaContextFactory, mockSchemasResolver)).setBaseSchemas(BASE_SCHEMAS).build();
netconfNodeManager = new NetconfNodeManager(slaveSetup, DEVICE_ID, responseTimeout,
mockMountPointService);
import org.opendaylight.yangtools.yang.common.Uint16;
import org.opendaylight.yangtools.yang.parser.impl.YangParserFactoryImpl;
-public class NetconfTopologyManagerTest {
+public class NetconfTopologyManagerTest extends AbstractBaseSchemasTest {
private static final Uint16 ACTOR_RESPONSE_WAIT_TIME = Uint16.valueOf(10);
private static final String TOPOLOGY_ID = "topologyID";
final DeviceActionFactory deviceActionFactory = mock(DeviceActionFactory.class);
final Config config = new ConfigBuilder().setWriteTransactionIdleTimeout(Uint16.ZERO).build();
- netconfTopologyManager = new NetconfTopologyManager(dataBroker, rpcProviderRegistry, actionProviderRegistry,
- clusterSingletonServiceProvider, keepaliveExecutor, processingThreadPool,
+ netconfTopologyManager = new NetconfTopologyManager(BASE_SCHEMAS, dataBroker, rpcProviderRegistry,
+ actionProviderRegistry, clusterSingletonServiceProvider, keepaliveExecutor, processingThreadPool,
actorSystemProvider, eventExecutor, clientDispatcher, TOPOLOGY_ID, config,
mountPointService, encryptionService, deviceActionFactory,
new DefaultSchemaResourceManager(new YangParserFactoryImpl())) {
import org.opendaylight.yangtools.yang.parser.impl.YangParserFactoryImpl;
import scala.concurrent.duration.Duration;
-public class RemoteDeviceConnectorImplTest {
+public class RemoteDeviceConnectorImplTest extends AbstractBaseSchemasTest {
private static final NodeId NODE_ID = new NodeId("testing-node");
private static final String TOPOLOGY_ID = "testing-topology";
doNothing().when(writeTx).merge(eq(LogicalDatastoreType.OPERATIONAL), any(), any());
doReturn("Some object").when(writeTx).getIdentifier();
doReturn(emptyFluentFuture()).when(writeTx).commit();
- builder = new NetconfTopologySetup.NetconfTopologySetupBuilder();
- builder.setDataBroker(dataBroker);
- builder.setRpcProviderRegistry(rpcProviderRegistry);
- builder.setClusterSingletonServiceProvider(clusterSingletonServiceProvider);
- builder.setKeepaliveExecutor(keepaliveExecutor);
- builder.setProcessingExecutor(processingExecutor);
- builder.setActorSystem(actorSystem);
- builder.setEventExecutor(eventExecutor);
- builder.setNetconfClientDispatcher(clientDispatcher);
- builder.setTopologyId(TOPOLOGY_ID);
+ builder = new NetconfTopologySetup.NetconfTopologySetupBuilder()
+ .setBaseSchemas(BASE_SCHEMAS)
+ .setDataBroker(dataBroker)
+ .setRpcProviderRegistry(rpcProviderRegistry)
+ .setClusterSingletonServiceProvider(clusterSingletonServiceProvider)
+ .setKeepaliveExecutor(keepaliveExecutor)
+ .setProcessingExecutor(processingExecutor)
+ .setActorSystem(actorSystem)
+ .setEventExecutor(eventExecutor)
+ .setNetconfClientDispatcher(clientDispatcher)
+ .setTopologyId(TOPOLOGY_ID);
}
@SuppressWarnings("unchecked")
import org.opendaylight.netconf.sal.connect.netconf.sal.KeepaliveSalFacade;
import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfKeystoreAdapter;
import org.opendaylight.netconf.sal.connect.netconf.schema.YangLibrarySchemaYangSourceProvider;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
import org.opendaylight.netconf.sal.connect.util.SslHandlerFactoryImpl;
import org.opendaylight.netconf.topology.api.NetconfTopology;
private final DeviceActionFactory deviceActionFactory;
private final NetconfKeystoreAdapter keystoreAdapter;
private final SchemaResourceManager schemaManager;
+ private final BaseNetconfSchemas baseSchemas;
protected final ScheduledThreadPool keepaliveExecutor;
protected final ListeningExecutorService processingExecutor;
protected final AAAEncryptionService encryptionService;
protected final HashMap<NodeId, NetconfConnectorDTO> activeConnectors = new HashMap<>();
+
protected AbstractNetconfTopology(final String topologyId, final NetconfClientDispatcher clientDispatcher,
final EventExecutor eventExecutor, final ScheduledThreadPool keepaliveExecutor,
final ThreadPool processingExecutor, final SchemaResourceManager schemaManager,
final DataBroker dataBroker, final DOMMountPointService mountPointService,
final AAAEncryptionService encryptionService,
- final DeviceActionFactory deviceActionFactory) {
+ final DeviceActionFactory deviceActionFactory,
+ final BaseNetconfSchemas baseSchemas) {
this.topologyId = topologyId;
this.clientDispatcher = clientDispatcher;
this.eventExecutor = eventExecutor;
this.dataBroker = dataBroker;
this.mountPointService = mountPointService;
this.encryptionService = encryptionService;
+ this.baseSchemas = requireNonNull(baseSchemas);
this.keystoreAdapter = new NetconfKeystoreAdapter(dataBroker);
}
final RemoteDevice<NetconfSessionPreferences, NetconfMessage, NetconfDeviceCommunicator> device;
if (node.isSchemaless()) {
- device = new SchemalessNetconfDevice(remoteDeviceId, salFacade);
+ device = new SchemalessNetconfDevice(baseSchemas, remoteDeviceId, salFacade);
} else {
device = createNetconfDevice(remoteDeviceId, salFacade, nodeId, node, nodeOptional);
}
.setEventExecutor(eventExecutor)
.setNodeOptional(nodeOptional)
.setDeviceActionFactory(deviceActionFactory)
+ .setBaseSchemas(baseSchemas)
.build();
final YangLibrary yangLibrary = node.getYangLibrary();
import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator;
import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseSchema;
import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer;
import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
private final NetconfDeviceSchemasResolver stateSchemasResolver;
private final NotificationHandler notificationHandler;
private final boolean reconnectOnSchemasChange;
+ private final BaseNetconfSchemas baseSchemas;
private final NetconfNode node;
private final EventExecutor eventExecutor;
private final NetconfNodeAugmentedOptional nodeOptional;
// Message transformer is constructed once the schemas are available
private MessageTransformer<NetconfMessage> messageTransformer;
- public NetconfDevice(final SchemaResourcesDTO schemaResourcesDTO, final RemoteDeviceId id,
- final RemoteDeviceHandler<NetconfSessionPreferences> salFacade,
- final ListeningExecutorService globalProcessingExecutor,
- final boolean reconnectOnSchemasChange) {
- this(schemaResourcesDTO, id, salFacade, globalProcessingExecutor, reconnectOnSchemasChange, null, null, null,
- null);
+ public NetconfDevice(final SchemaResourcesDTO schemaResourcesDTO, final BaseNetconfSchemas baseSchemas,
+ final RemoteDeviceId id, final RemoteDeviceHandler<NetconfSessionPreferences> salFacade,
+ final ListeningExecutorService globalProcessingExecutor, final boolean reconnectOnSchemasChange) {
+ this(schemaResourcesDTO, baseSchemas, id, salFacade, globalProcessingExecutor, reconnectOnSchemasChange, null,
+ null, null, null);
}
- public NetconfDevice(final SchemaResourcesDTO schemaResourcesDTO, final RemoteDeviceId id,
- final RemoteDeviceHandler<NetconfSessionPreferences> salFacade,
+ public NetconfDevice(final SchemaResourcesDTO schemaResourcesDTO, final BaseNetconfSchemas baseSchemas,
+ final RemoteDeviceId id, final RemoteDeviceHandler<NetconfSessionPreferences> salFacade,
final ListeningExecutorService globalProcessingExecutor, final boolean reconnectOnSchemasChange,
final DeviceActionFactory deviceActionFactory, final NetconfNode node, final EventExecutor eventExecutor,
final NetconfNodeAugmentedOptional nodeOptional) {
+ this.baseSchemas = requireNonNull(baseSchemas);
this.id = id;
this.reconnectOnSchemasChange = reconnectOnSchemasChange;
this.deviceActionFactory = deviceActionFactory;
//NetconfDevice.SchemaSetup can complete after NetconfDeviceCommunicator was closed. In that case do nothing,
//since salFacade.onDeviceDisconnected was already called.
if (connected) {
- final BaseSchema baseSchema =
- remoteSessionCapabilities.isNotificationsSupported()
- ? BaseSchema.BASE_NETCONF_CTX_WITH_NOTIFICATIONS : BaseSchema.BASE_NETCONF_CTX;
- this.messageTransformer = new NetconfMessageTransformer(result, true, baseSchema);
+ this.messageTransformer = new NetconfMessageTransformer(result, true,
+ resolveBaseSchema(remoteSessionCapabilities.isNotificationsSupported()));
// salFacade.onDeviceConnected has to be called before the notification handler is initialized
this.salFacade.onDeviceConnected(result, remoteSessionCapabilities, deviceRpc,
notificationHandler.handleNotification(notification);
}
- private static BaseSchema resolveBaseSchema(final boolean notificationSupport) {
- return notificationSupport ? BaseSchema.BASE_NETCONF_CTX_WITH_NOTIFICATIONS : BaseSchema.BASE_NETCONF_CTX;
+ private BaseSchema resolveBaseSchema(final boolean notificationSupport) {
+ return notificationSupport ? baseSchemas.getBaseSchemaWithNotifications() : baseSchemas.getBaseSchema();
}
protected NetconfDeviceRpc getDeviceSpecificRpc(final MountPointContext result,
final RemoteDeviceCommunicator<NetconfMessage> listener) {
- return new NetconfDeviceRpc(result.getSchemaContext(), listener, new NetconfMessageTransformer(result, true));
+ return new NetconfDeviceRpc(result.getSchemaContext(), listener,
+ new NetconfMessageTransformer(result, true, baseSchemas.getBaseSchema()));
}
/**
import org.opendaylight.netconf.sal.connect.api.DeviceActionFactory;
import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler;
import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.optional.rev190614.NetconfNodeAugmentedOptional;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
private NetconfNode node;
private EventExecutor eventExecutor;
private NetconfNodeAugmentedOptional nodeOptional;
+ private BaseNetconfSchemas baseSchemas;
public NetconfDeviceBuilder() {
}
return this;
}
+ public NetconfDeviceBuilder setBaseSchemas(final BaseNetconfSchemas baseSchemas) {
+ this.baseSchemas = requireNonNull(baseSchemas);
+ return this;
+ }
+
public NetconfDevice build() {
validation();
- return new NetconfDevice(this.schemaResourcesDTO, this.id, this.salFacade, this.globalProcessingExecutor,
- this.reconnectOnSchemasChange, this.deviceActionFactory, this.node, this.eventExecutor,
- this.nodeOptional);
+ return new NetconfDevice(this.schemaResourcesDTO, this.baseSchemas, this.id, this.salFacade,
+ this.globalProcessingExecutor, this.reconnectOnSchemasChange, this.deviceActionFactory, this.node,
+ this.eventExecutor, this.nodeOptional);
}
private void validation() {
+ requireNonNull(this.baseSchemas, "BaseSchemas is not initialized");
requireNonNull(this.id, "RemoteDeviceId is not initialized");
requireNonNull(this.salFacade, "RemoteDeviceHandler is not initialized");
requireNonNull(this.globalProcessingExecutor, "ExecutorService is not initialized");
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Verify.verify;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_DATA_NODEID;
+import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_FILTER_NODEID;
+import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_FILTER_QNAME;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_GET_NODEID;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_GET_PATH;
+import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_TYPE_QNAME;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.toId;
import com.google.common.annotations.VisibleForTesting;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import javax.xml.stream.XMLStreamException;
+import javax.xml.transform.dom.DOMSource;
import org.opendaylight.mdsal.dom.api.DOMRpcResult;
import org.opendaylight.mdsal.dom.api.DOMRpcService;
+import org.opendaylight.netconf.api.xml.XmlUtil;
import org.opendaylight.netconf.sal.connect.api.NetconfDeviceSchemas;
import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
-import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseSchema;
import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
import org.opendaylight.netconf.util.NetconfUtil;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
import org.xml.sax.SAXException;
/**
* Holds QNames for all yang modules reported by ietf-netconf-monitoring/state/schemas.
*/
public final class NetconfStateSchemas implements NetconfDeviceSchemas {
-
- private static final Logger LOG = LoggerFactory.getLogger(NetconfStateSchemas.class);
-
public static final NetconfStateSchemas EMPTY = new NetconfStateSchemas(ImmutableSet.of());
+ private static final Logger LOG = LoggerFactory.getLogger(NetconfStateSchemas.class);
private static final YangInstanceIdentifier STATE_SCHEMAS_IDENTIFIER =
YangInstanceIdentifier.builder().node(NetconfState.QNAME).node(Schemas.QNAME).build();
-
- private static final ContainerNode GET_SCHEMAS_RPC = Builders.containerBuilder()
- .withNodeIdentifier(NETCONF_GET_NODEID)
- .withChild(NetconfMessageTransformUtil.toFilterStructure(STATE_SCHEMAS_IDENTIFIER,
- BaseSchema.BASE_NETCONF_CTX_WITH_NOTIFICATIONS.getSchemaContext())).build();
+ private static final ContainerNode GET_SCHEMAS_RPC;
+
+ static {
+ final Document document = XmlUtil.newDocument();
+
+ final Element filterElem = XmlUtil.createElement(document, NETCONF_FILTER_QNAME.getLocalName(),
+ Optional.of(NETCONF_FILTER_QNAME.getNamespace().toString()));
+ filterElem.setAttributeNS(NETCONF_FILTER_QNAME.getNamespace().toString(), NETCONF_TYPE_QNAME.getLocalName(),
+ "subtree");
+
+ final Element stateElem = XmlUtil.createElement(document, NetconfState.QNAME.getLocalName(),
+ Optional.of(NetconfState.QNAME.getNamespace().toString()));
+ stateElem.appendChild(XmlUtil.createElement(document, Schemas.QNAME.getLocalName(),
+ Optional.of(Schemas.QNAME.getNamespace().toString())));
+ filterElem.appendChild(stateElem);
+
+ GET_SCHEMAS_RPC = Builders.containerBuilder()
+ .withNodeIdentifier(NETCONF_GET_NODEID)
+ .withChild(Builders.anyXmlBuilder()
+ .withNodeIdentifier(NETCONF_FILTER_NODEID)
+ .withValue(new DOMSource(filterElem))
+ .build())
+ .build();
+ }
private final Set<RemoteYangSchema> availableYangSchemas;
*/
package org.opendaylight.netconf.sal.connect.netconf;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.annotations.VisibleForTesting;
import org.opendaylight.netconf.api.NetconfMessage;
import org.opendaylight.netconf.sal.connect.api.RemoteDevice;
import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator;
import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
import org.opendaylight.netconf.sal.connect.netconf.sal.SchemalessNetconfDeviceRpc;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseRpcSchemalessTransformer;
-import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseSchema;
import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.SchemalessMessageTransformer;
import org.opendaylight.netconf.sal.connect.util.MessageCounter;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
-public class SchemalessNetconfDevice implements
- RemoteDevice<NetconfSessionPreferences, NetconfMessage, NetconfDeviceCommunicator> {
-
+public class SchemalessNetconfDevice
+ implements RemoteDevice<NetconfSessionPreferences, NetconfMessage, NetconfDeviceCommunicator> {
+ private final BaseNetconfSchemas baseSchemas;
private final RemoteDeviceId id;
private final RemoteDeviceHandler<NetconfSessionPreferences> salFacade;
private final SchemalessMessageTransformer messageTransformer;
private final BaseRpcSchemalessTransformer rpcTransformer;
- public SchemalessNetconfDevice(final RemoteDeviceId id,
+ public SchemalessNetconfDevice(final BaseNetconfSchemas baseSchemas, final RemoteDeviceId id,
final RemoteDeviceHandler<NetconfSessionPreferences> salFacade) {
+ this.baseSchemas = requireNonNull(baseSchemas);
this.id = id;
this.salFacade = salFacade;
final MessageCounter counter = new MessageCounter();
- rpcTransformer = new BaseRpcSchemalessTransformer(counter);
+ rpcTransformer = new BaseRpcSchemalessTransformer(baseSchemas, counter);
messageTransformer = new SchemalessMessageTransformer(counter);
}
@VisibleForTesting
- SchemalessNetconfDevice(final RemoteDeviceId id, final RemoteDeviceHandler<NetconfSessionPreferences> salFacade,
+ SchemalessNetconfDevice(final BaseNetconfSchemas baseSchemas, final RemoteDeviceId id,
+ final RemoteDeviceHandler<NetconfSessionPreferences> salFacade,
final SchemalessMessageTransformer messageTransformer) {
+ this.baseSchemas = requireNonNull(baseSchemas);
this.id = id;
this.salFacade = salFacade;
final MessageCounter counter = new MessageCounter();
- rpcTransformer = new BaseRpcSchemalessTransformer(counter);
+ rpcTransformer = new BaseRpcSchemalessTransformer(baseSchemas, counter);
this.messageTransformer = messageTransformer;
}
- @Override public void onRemoteSessionUp(final NetconfSessionPreferences remoteSessionCapabilities,
+ @Override
+ public void onRemoteSessionUp(final NetconfSessionPreferences remoteSessionCapabilities,
final NetconfDeviceCommunicator netconfDeviceCommunicator) {
final SchemalessNetconfDeviceRpc schemalessNetconfDeviceRpc = new SchemalessNetconfDeviceRpc(id,
netconfDeviceCommunicator, rpcTransformer, messageTransformer);
- salFacade.onDeviceConnected(BaseSchema.BASE_NETCONF_CTX.getMountPointContext(),
+ salFacade.onDeviceConnected(baseSchemas.getBaseSchema().getMountPointContext(),
remoteSessionCapabilities, schemalessNetconfDeviceRpc);
}
- @Override public void onRemoteSessionDown() {
+ @Override
+ public void onRemoteSessionDown() {
salFacade.onDeviceDisconnected();
}
- @Override public void onRemoteSessionFailed(final Throwable throwable) {
+ @Override
+ public void onRemoteSessionFailed(final Throwable throwable) {
salFacade.onDeviceFailed(throwable);
}
- @Override public void onNotification(final NetconfMessage notification) {
+ @Override
+ public void onNotification(final NetconfMessage notification) {
salFacade.onNotification(messageTransformer.toNotification(notification));
}
}
--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netconf.sal.connect.netconf.schema.mapping;
+
+import com.google.common.annotations.Beta;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.opendaylight.yangtools.concepts.Immutable;
+
+@Beta
+@NonNullByDefault
+public interface BaseNetconfSchemas extends Immutable {
+
+ BaseSchema getBaseSchema();
+
+ BaseSchema getBaseSchemaWithNotifications();
+}
package org.opendaylight.netconf.sal.connect.netconf.schema.mapping;
import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableMap;
import java.io.IOException;
-import java.util.Map;
import javax.xml.stream.XMLStreamException;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
* Transforms base netconf RPCs.
*/
public class BaseRpcSchemalessTransformer implements MessageTransformer<NetconfMessage> {
-
- private static final Map<QName, ? extends RpcDefinition> MAPPED_RPCS = BaseSchema.BASE_NETCONF_CTX.getMappedRpcs();
- private static final SchemaContext SCHEMA_CONTEXT = BaseSchema.BASE_NETCONF_CTX.getSchemaContext();
-
+ private final ImmutableMap<QName, ? extends RpcDefinition> mappedRpcs;
+ private final EffectiveModelContext modelContext;
private final MessageCounter counter;
- public BaseRpcSchemalessTransformer(final MessageCounter counter) {
+ public BaseRpcSchemalessTransformer(final BaseNetconfSchemas baseSchemas, final MessageCounter counter) {
+ final BaseSchema baseSchema = baseSchemas.getBaseSchema();
+ mappedRpcs = baseSchema.getMappedRpcs();
+ modelContext = baseSchema.getEffectiveModelContext();
this.counter = counter;
}
// In case no input for rpc is defined, we can simply construct the payload here
final QName rpcQName = rpc.getLastComponent();
- final RpcDefinition mappedRpc = Preconditions.checkNotNull(MAPPED_RPCS.get(rpcQName),
- "Unknown rpc %s, available rpcs: %s", rpcQName, MAPPED_RPCS.keySet());
+ final RpcDefinition mappedRpc = Preconditions.checkNotNull(mappedRpcs.get(rpcQName),
+ "Unknown rpc %s, available rpcs: %s", rpcQName, mappedRpcs.keySet());
final DOMResult domResult = NetconfMessageTransformUtil.prepareDomResultForRpcRequest(rpcQName, counter);
if (mappedRpc.getInput().getChildNodes().isEmpty()) {
return new NetconfMessage(domResult.getNode().getOwnerDocument());
final DOMResult result = domResult;
try {
- NetconfMessageTransformUtil.writeNormalizedRpc((ContainerNode) payload, result,
- inputPath, SCHEMA_CONTEXT);
+ NetconfMessageTransformUtil.writeNormalizedRpc((ContainerNode) payload, result, inputPath, modelContext);
} catch (final XMLStreamException | IOException | IllegalStateException e) {
throw new IllegalStateException("Unable to serialize " + inputPath, e);
}
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
-import java.util.Arrays;
import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.binding.runtime.spi.BindingRuntimeHelpers;
+import org.opendaylight.yangtools.concepts.Immutable;
import org.opendaylight.yangtools.rcf8528.data.util.EmptyMountPointContext;
-import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
-public enum BaseSchema implements EffectiveModelContextProvider {
- BASE_NETCONF_CTX(
- org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601
- .$YangModuleInfoImpl.getInstance(),
- org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.extension.rev131210
- .$YangModuleInfoImpl.getInstance()
- ),
- BASE_NETCONF_CTX_WITH_NOTIFICATIONS(
- org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.extension.rev131210
- .$YangModuleInfoImpl.getInstance(),
- org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714
- .$YangModuleInfoImpl.getInstance(),
- org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601
- .$YangModuleInfoImpl.getInstance(),
- org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206
- .$YangModuleInfoImpl.getInstance()
- );
-
+public final class BaseSchema implements EffectiveModelContextProvider, Immutable {
private final @NonNull ImmutableMap<QName, ? extends RpcDefinition> mappedRpcs;
private final @NonNull EmptyMountPointContext mountContext;
- BaseSchema(final YangModuleInfo... modules) {
- mountContext = new EmptyMountPointContext(BindingRuntimeHelpers.createEffectiveModel(Arrays.asList(modules)));
- mappedRpcs = Maps.uniqueIndex(getSchemaContext().getOperations(), RpcDefinition::getQName);
+ BaseSchema(final EffectiveModelContext context) {
+ mountContext = new EmptyMountPointContext(context);
+ mappedRpcs = Maps.uniqueIndex(context.getOperations(), RpcDefinition::getQName);
}
@NonNull ImmutableMap<QName, ? extends RpcDefinition> getMappedRpcs() {
--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netconf.sal.connect.netconf.schema.mapping;
+
+import com.google.common.annotations.Beta;
+import java.util.Arrays;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.binding.runtime.spi.BindingRuntimeHelpers;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.parser.api.YangParserFactory;
+
+@Beta
+@Singleton
+public final class DefaultBaseNetconfSchemas implements BaseNetconfSchemas {
+ private final @NonNull BaseSchema withoutNotifications;
+ private final @NonNull BaseSchema withNotifications;
+
+ @Inject
+ public DefaultBaseNetconfSchemas(final YangParserFactory parserFactory) {
+ withoutNotifications = new BaseSchema(withoutNotifications(parserFactory));
+ withNotifications = new BaseSchema(withNotifications(parserFactory));
+ }
+
+ @Override
+ public @NonNull BaseSchema getBaseSchema() {
+ return withoutNotifications;
+ }
+
+ @Override
+ public @NonNull BaseSchema getBaseSchemaWithNotifications() {
+ return withNotifications;
+ }
+
+ private static EffectiveModelContext withoutNotifications(final YangParserFactory parserFactory) {
+ return BindingRuntimeHelpers.createEffectiveModel(parserFactory, Arrays.asList(
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601
+ .$YangModuleInfoImpl.getInstance(),
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.extension.rev131210
+ .$YangModuleInfoImpl.getInstance()));
+ }
+
+ private static EffectiveModelContext withNotifications(final YangParserFactory parserFactory) {
+ return BindingRuntimeHelpers.createEffectiveModel(parserFactory, Arrays.asList(
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.extension.rev131210
+ .$YangModuleInfoImpl.getInstance(),
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714
+ .$YangModuleInfoImpl.getInstance(),
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601
+ .$YangModuleInfoImpl.getInstance(),
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206
+ .$YangModuleInfoImpl.getInstance()));
+ }
+}
private final boolean strictParsing;
private final ImmutableMap<SchemaPath, ActionDefinition> actions;
- public NetconfMessageTransformer(final MountPointContext mountContext, final boolean strictParsing) {
- this(mountContext, strictParsing, BaseSchema.BASE_NETCONF_CTX);
- }
-
public NetconfMessageTransformer(final MountPointContext mountContext, final boolean strictParsing,
final BaseSchema baseSchema) {
this.counter = new MessageCounter();
<service ref="schemaResourceManager"
interface="org.opendaylight.netconf.sal.connect.api.SchemaResourceManager"/>
+
+ <bean id="baseNetconfSchemas"
+ class="org.opendaylight.netconf.sal.connect.netconf.schema.mapping.DefaultBaseNetconfSchemas">
+ <argument ref="parserFactory"/>
+ </bean>
+
+ <service ref="baseNetconfSchemas"
+ interface="org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas"/>
</blueprint>
--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netconf.sal.connect.netconf;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.DefaultBaseNetconfSchemas;
+import org.opendaylight.yangtools.yang.parser.impl.YangParserFactoryImpl;
+
+public abstract class AbstractBaseSchemasTest {
+ protected static BaseNetconfSchemas BASE_SCHEMAS;
+
+ @BeforeClass
+ public static void initBaseSchemas() {
+ BASE_SCHEMAS = new DefaultBaseNetconfSchemas(new YangParserFactoryImpl());
+ }
+
+ @AfterClass
+ public static void freeBaseSchemas() {
+ BASE_SCHEMAS = null;
+ }
+
+}
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public abstract class AbstractTestModelTest {
+public abstract class AbstractTestModelTest extends AbstractBaseSchemasTest {
protected static EffectiveModelContext SCHEMA_CONTEXT;
@BeforeClass
.setGlobalProcessingExecutor(getExecutor())
.setId(getId())
.setSalFacade(facade)
+ .setBaseSchemas(BASE_SCHEMAS)
.build();
// Monitoring supported
final NetconfSessionPreferences sessionCaps =
.setGlobalProcessingExecutor(getExecutor())
.setId(getId())
.setSalFacade(facade)
+ .setBaseSchemas(BASE_SCHEMAS)
.build();
// Monitoring not supported
.setReconnectOnSchemasChange(true)
.setSchemaResourcesDTO(schemaResourcesDTO)
.setGlobalProcessingExecutor(getExecutor())
+ .setBaseSchemas(BASE_SCHEMAS)
.setId(getId())
.setSalFacade(facade)
.build();
.setGlobalProcessingExecutor(getExecutor())
.setId(getId())
.setSalFacade(facade)
+ .setBaseSchemas(BASE_SCHEMAS)
.build();
final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
.setGlobalProcessingExecutor(getExecutor())
.setId(getId())
.setSalFacade(facade)
+ .setBaseSchemas(BASE_SCHEMAS)
.build();
final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&revision=" + TEST_REVISION));
.setGlobalProcessingExecutor(getExecutor())
.setId(getId())
.setSalFacade(facade)
+ .setBaseSchemas(BASE_SCHEMAS)
.build();
final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&revision=" + TEST_REVISION));
.setGlobalProcessingExecutor(getExecutor())
.setId(getId())
.setSalFacade(facade)
+ .setBaseSchemas(BASE_SCHEMAS)
.build();
final NetconfDevice netconfSpy = Mockito.spy(device);
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
import org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException;
import org.opendaylight.mdsal.dom.api.DOMRpcResult;
import org.opendaylight.mdsal.dom.api.DOMRpcService;
import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
-import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseSchema;
import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.NetconfState;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class NetconfStateSchemasTest {
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
+public class NetconfStateSchemasTest extends AbstractBaseSchemasTest {
private static final Logger LOG = LoggerFactory.getLogger(NetconfStateSchemasTest.class);
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
- schemaContext = BaseSchema.BASE_NETCONF_CTX_WITH_NOTIFICATIONS.getEffectiveModelContext();
+ schemaContext = BASE_SCHEMAS.getBaseSchemaWithNotifications().getEffectiveModelContext();
final DataSchemaNode schemasNode =
((ContainerSchemaNode) schemaContext
.getDataChildByName(NetconfState.QNAME)).getDataChildByName(Schemas.QNAME);
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
import org.w3c.dom.Document;
-public class NetconfToNotificationTest {
+public class NetconfToNotificationTest extends AbstractBaseSchemasTest {
NetconfMessageTransformer messageTransformer;
@Test(expected = IllegalArgumentException.class)
public void testMostRecentWrongYangModel() throws Exception {
final EffectiveModelContext schemaContext = getNotificationSchemaContext(getClass(), true);
- messageTransformer = new NetconfMessageTransformer(new EmptyMountPointContext(schemaContext), true);
+ messageTransformer = new NetconfMessageTransformer(new EmptyMountPointContext(schemaContext), true,
+ BASE_SCHEMAS.getBaseSchema());
messageTransformer.toNotification(userNotification);
}
@Test
public void testToNotificationFunction() throws Exception {
final EffectiveModelContext schemaContext = getNotificationSchemaContext(getClass(), false);
- messageTransformer = new NetconfMessageTransformer(new EmptyMountPointContext(schemaContext), true);
+ messageTransformer = new NetconfMessageTransformer(new EmptyMountPointContext(schemaContext), true,
+ BASE_SCHEMAS.getBaseSchema());
final DOMNotification domNotification = messageTransformer.toNotification(userNotification);
final ContainerNode root = domNotification.getBody();
assertNotNull(root);
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.toPath;
import java.util.Collection;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.netconf.api.NetconfMessage;
import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer;
import org.opendaylight.yangtools.rcf8528.data.util.EmptyMountPointContext;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
import org.w3c.dom.Document;
-public class NetconfToRpcRequestTest {
+public class NetconfToRpcRequestTest extends AbstractBaseSchemasTest {
private static final String TEST_MODEL_NAMESPACE = "urn:opendaylight:params:xml:ns:yang:controller:md:sal:rpc-test";
private static final String REVISION = "2014-07-14";
- private static final QName INPUT_QNAME = QName.create(TEST_MODEL_NAMESPACE, REVISION, "input");
private static final QName STREAM_NAME = QName.create(TEST_MODEL_NAMESPACE, REVISION, "stream-name");
private static final QName SUBSCRIBE_RPC_NAME = QName.create(TEST_MODEL_NAMESPACE, REVISION, "subscribe");
private static final String CONFIG_TEST_REVISION = "2014-07-21";
private static final QName EDIT_CONFIG_QNAME =
QName.create(CONFIG_TEST_NAMESPACE, CONFIG_TEST_REVISION, "edit-config");
- private static final QName GET_QNAME = QName.create(CONFIG_TEST_NAMESPACE, CONFIG_TEST_REVISION, "get");
- private static final QName GET_CONFIG_QNAME =
- QName.create(CONFIG_TEST_NAMESPACE, CONFIG_TEST_REVISION, "get-config");
static EffectiveModelContext cfgCtx;
- static NetconfMessageTransformer messageTransformer;
+
+ private NetconfMessageTransformer messageTransformer;
@BeforeClass
public static void setup() {
cfgCtx = YangParserTestUtils.parseYangResources(NetconfToRpcRequestTest.class,
"/schemas/config-test-rpc.yang", "/schemas/rpc-notification-subscription.yang");
- messageTransformer = new NetconfMessageTransformer(new EmptyMountPointContext(cfgCtx), true);
}
- private static LeafNode<Object> buildLeaf(final QName running, final Object value) {
- return Builders.leafBuilder().withNodeIdentifier(toId(running)).withValue(value).build();
+ @Before
+ public void before() {
+ messageTransformer = new NetconfMessageTransformer(new EmptyMountPointContext(cfgCtx), true,
+ BASE_SCHEMAS.getBaseSchema());
}
@Test
public void testUserDefinedRpcCall() throws Exception {
- final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> rootBuilder =
- Builders.containerBuilder();
- rootBuilder.withNodeIdentifier(toId(SUBSCRIBE_RPC_NAME));
-
- rootBuilder.withChild(buildLeaf(STREAM_NAME, "NETCONF"));
- final ContainerNode root = rootBuilder.build();
+ final ContainerNode root = Builders.containerBuilder()
+ .withNodeIdentifier(toId(SUBSCRIBE_RPC_NAME))
+ .withChild(ImmutableNodes.leafNode(STREAM_NAME, "NETCONF"))
+ .build();
final NetconfMessage message = messageTransformer.toRpcRequest(toPath(SUBSCRIBE_RPC_NAME), root);
assertNotNull(message);
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
import org.opendaylight.yangtools.rfc8528.data.api.MountPointContext;
-public class SchemalessNetconfDeviceTest {
+public class SchemalessNetconfDeviceTest extends AbstractBaseSchemasTest {
private static final String TEST_NAMESPACE = "test:namespace";
private static final String TEST_MODULE = "test-module";
InetSocketAddress.createUnresolved("localhost", 22));
final Throwable throwable = new Throwable();
- final SchemalessNetconfDevice device = new SchemalessNetconfDevice(remoteDeviceId, facade, messageTransformer);
+ final SchemalessNetconfDevice device = new SchemalessNetconfDevice(BASE_SCHEMAS, remoteDeviceId, facade,
+ messageTransformer);
final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&revision=" + TEST_REVISION));
import org.opendaylight.netconf.api.NetconfMessage;
import org.opendaylight.netconf.api.xml.XmlUtil;
import org.opendaylight.netconf.sal.connect.api.RemoteDeviceCommunicator;
+import org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest;
import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer;
import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.IetfNetconfService;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.w3c.dom.Node;
-public class NetconfDeviceRpcTest {
+public class NetconfDeviceRpcTest extends AbstractBaseSchemasTest {
private static EffectiveModelContext SCHEMA_CONTEXT;
@Mock
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
NetconfMessageTransformer transformer = new NetconfMessageTransformer(
- new EmptyMountPointContext(SCHEMA_CONTEXT), true);
+ new EmptyMountPointContext(SCHEMA_CONTEXT), true, BASE_SCHEMAS.getBaseSchema());
final NetconfMessage reply = new NetconfMessage(XmlUtil.readXmlToDocument(
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
+ "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"101\">\n"
import org.opendaylight.netconf.api.NetconfMessage;
import org.opendaylight.netconf.api.xml.XmlUtil;
import org.opendaylight.netconf.sal.connect.api.RemoteDeviceCommunicator;
+import org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest;
import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseRpcSchemalessTransformer;
import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.SchemalessMessageTransformer;
import org.opendaylight.netconf.sal.connect.util.MessageCounter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class SchemalessNetconfDeviceRpcTest {
+public class SchemalessNetconfDeviceRpcTest extends AbstractBaseSchemasTest {
private static final Logger LOG = LoggerFactory.getLogger(SchemalessNetconfDeviceRpcTest.class);
final MessageCounter counter = new MessageCounter();
deviceRpc = new SchemalessNetconfDeviceRpc(
new RemoteDeviceId("device1", InetSocketAddress.createUnresolved("0.0.0.0", 17830)), listener,
- new BaseRpcSchemalessTransformer(counter), new SchemalessMessageTransformer(counter));
+ new BaseRpcSchemalessTransformer(BASE_SCHEMAS, counter), new SchemalessMessageTransformer(counter));
}
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.dom.api.DOMRpcService;
import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
-import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseSchema;
+import org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest;
import org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps;
import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-public class NetconfDeviceWriteOnlyTxTest {
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
+public class NetconfDeviceWriteOnlyTxTest extends AbstractBaseSchemasTest {
private final RemoteDeviceId id = new RemoteDeviceId("test-mount", new InetSocketAddress(99));
private YangInstanceIdentifier yangIId;
@Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
-
+ public void setUp() {
final FluentFuture<DefaultDOMRpcResult> successFuture =
FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult((NormalizedNode<?, ?>) null));
.when(rpc).invokeRpc(any(SchemaPath.class), any(ContainerNode.class));
final WriteRunningTx tx = new WriteRunningTx(id,
- new NetconfBaseOps(rpc, BaseSchema.BASE_NETCONF_CTX_WITH_NOTIFICATIONS.getEffectiveModelContext()), false);
+ new NetconfBaseOps(rpc, BASE_SCHEMAS.getBaseSchemaWithNotifications().getEffectiveModelContext()), false);
tx.delete(LogicalDatastoreType.CONFIGURATION, yangIId);
tx.commit();
doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult((NormalizedNode<?, ?>) null)))
.when(rpc).invokeRpc(any(SchemaPath.class), any(ContainerNode.class));
final WriteCandidateTx tx = new WriteCandidateTx(
- id, new NetconfBaseOps(rpc, BaseSchema.BASE_NETCONF_CTX.getEffectiveModelContext()), false);
+ id, new NetconfBaseOps(rpc, BASE_SCHEMAS.getBaseSchema().getEffectiveModelContext()), false);
final TxListener listener = mock(TxListener.class);
tx.addListener(listener);
tx.delete(LogicalDatastoreType.CONFIGURATION, yangIId);
doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult((NormalizedNode<?, ?>) null)))
.when(rpc).invokeRpc(any(SchemaPath.class), isNull());
final WriteCandidateTx tx = new WriteCandidateTx(
- id, new NetconfBaseOps(rpc, BaseSchema.BASE_NETCONF_CTX.getEffectiveModelContext()), false);
+ id, new NetconfBaseOps(rpc, BASE_SCHEMAS.getBaseSchema().getEffectiveModelContext()), false);
final TxListener listener = mock(TxListener.class);
tx.addListener(listener);
tx.delete(LogicalDatastoreType.CONFIGURATION, yangIId);
doReturn(FluentFutures.immediateFailedFluentFuture(cause))
.when(rpc).invokeRpc(any(SchemaPath.class), any(ContainerNode.class));
final WriteCandidateTx tx = new WriteCandidateTx(
- id, new NetconfBaseOps(rpc, BaseSchema.BASE_NETCONF_CTX.getEffectiveModelContext()), false);
+ id, new NetconfBaseOps(rpc, BASE_SCHEMAS.getBaseSchema().getEffectiveModelContext()), false);
final TxListener listener = mock(TxListener.class);
tx.addListener(listener);
tx.delete(LogicalDatastoreType.CONFIGURATION, yangIId);
import org.opendaylight.mdsal.dom.api.DOMRpcResult;
import org.opendaylight.netconf.api.NetconfMessage;
import org.opendaylight.netconf.api.xml.XmlUtil;
+import org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest;
import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
import org.opendaylight.netconf.sal.connect.util.MessageCounter;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.copy.config.input.target.ConfigTarget;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-public class BaseRpcSchemalessTransformerTest {
+public class BaseRpcSchemalessTransformerTest extends AbstractBaseSchemasTest {
static {
XMLUnit.setIgnoreWhitespace(true);
@Before
public void setUp() throws Exception {
- transformer = new BaseRpcSchemalessTransformer(new MessageCounter());
+ transformer = new BaseRpcSchemalessTransformer(BASE_SCHEMAS, new MessageCounter());
}
@Test(expected = UnsupportedOperationException.class)
import org.opendaylight.mdsal.dom.api.DOMRpcResult;
import org.opendaylight.netconf.api.NetconfMessage;
import org.opendaylight.netconf.api.xml.XmlUtil;
+import org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest;
import org.opendaylight.netconf.sal.connect.netconf.schema.NetconfRemoteSchemaYangSourceProvider;
import org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps;
import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
-public class NetconfMessageTransformerTest {
+public class NetconfMessageTransformerTest extends AbstractBaseSchemasTest {
private static final String REVISION_EXAMPLE_SERVER_FARM = "2018-08-07";
private static final String URN_EXAMPLE_SERVER_FARM = "urn:example:server-farm";
netconfMessageTransformer = getTransformer(SCHEMA);
actionNetconfMessageTransformer = new NetconfMessageTransformer(new EmptyMountPointContext(ACTION_SCHEMA),
- true);
+ true, BASE_SCHEMAS.getBaseSchema());
}
@Test
@Test
public void testCreateSubscriberNotificationSchemaNotPresent() throws Exception {
final NetconfMessageTransformer transformer = new NetconfMessageTransformer(new EmptyMountPointContext(SCHEMA),
- true, BaseSchema.BASE_NETCONF_CTX_WITH_NOTIFICATIONS);
+ true, BASE_SCHEMAS.getBaseSchemaWithNotifications());
NetconfMessage netconfMessage = transformer.toRpcRequest(
toPath(CREATE_SUBSCRIPTION_RPC_QNAME),
CREATE_SUBSCRIPTION_RPC_CONTENT
.node(NetconfState.QNAME).node(Schemas.QNAME).node(Schema.QNAME)
.nodeWithKey(Schema.QNAME, keys).build();
final DataContainerChild<?, ?> editConfigStructure =
- createEditConfigStructure(BaseSchema.BASE_NETCONF_CTX_WITH_NOTIFICATIONS.getSchemaContext(), id,
+ createEditConfigStructure(BASE_SCHEMAS.getBaseSchemaWithNotifications().getEffectiveModelContext(), id,
Optional.empty(), Optional.ofNullable(schemaNode));
final DataContainerChild<?, ?> target = NetconfBaseOps.getTargetNode(NETCONF_CANDIDATE_QNAME);
}
private static NetconfMessageTransformer getTransformer(final EffectiveModelContext schema) {
- return new NetconfMessageTransformer(new EmptyMountPointContext(schema), true);
+ return new NetconfMessageTransformer(new EmptyMountPointContext(schema), true, BASE_SCHEMAS.getBaseSchema());
}
@Test
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_COMMIT_QNAME)))
.thenReturn(FluentFuture.from(RpcResultBuilder.success(ok).buildFuture()));
final MessageTransformer<NetconfMessage> transformer = new NetconfMessageTransformer(
- new EmptyMountPointContext(SCHEMA_CONTEXT), true);
+ new EmptyMountPointContext(SCHEMA_CONTEXT), true, BASE_SCHEMAS.getBaseSchema());
final DOMRpcService rpc = new NetconfDeviceRpc(SCHEMA_CONTEXT, listener, transformer);
final RemoteDeviceId id =
new RemoteDeviceId("device-1", InetSocketAddress.createUnresolved("localhost", 17830));