package org.opendaylight.netconf.test.tool;
-import com.google.common.base.MoreObjects;
+import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.base.Optional;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
-import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import io.netty.channel.Channel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
-import org.apache.sshd.common.util.ThreadUtils;
-import org.apache.sshd.server.keyprovider.PEMGeneratorHostKeyProvider;
+import org.apache.sshd.common.keyprovider.KeyPairProvider;
+import org.apache.sshd.common.util.security.SecurityUtils;
+import org.apache.sshd.common.util.threads.ThreadUtils;
import org.opendaylight.controller.config.util.capability.BasicCapability;
import org.opendaylight.controller.config.util.capability.Capability;
import org.opendaylight.controller.config.util.capability.YangModuleCapability;
import org.opendaylight.netconf.test.tool.operations.OperationsProvider;
import org.opendaylight.netconf.test.tool.rpchandler.SettableOperationRpcProvider;
import org.opendaylight.netconf.test.tool.schemacache.SchemaSourceCache;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
import org.opendaylight.yangtools.yang.model.repo.util.FilesystemSchemaSourceCache;
import org.opendaylight.yangtools.yang.parser.repo.SharedSchemaRepository;
-import org.opendaylight.yangtools.yang.parser.util.TextToASTTransformer;
+import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToASTTransformer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private boolean sendFakeSchema = false;
- public NetconfDeviceSimulator(Configuration configuration) {
+ public NetconfDeviceSimulator(final Configuration configuration) {
this.configuration = configuration;
this.nettyThreadgroup = new NioEventLoopGroup();
this.hashedWheelTimer = new HashedWheelTimer();
final List<Integer> openDevices = Lists.newArrayList();
// Generate key to temp folder
- final PEMGeneratorHostKeyProvider keyPairProvider = getPemGeneratorHostKeyProvider();
+ final KeyPairProvider keyPairProvider = getPemGeneratorHostKeyProvider();
for (int i = 0; i < configuration.getDeviceCount(); i++) {
if (currentPort > 65535) {
}
private SshProxyServerConfiguration getSshConfiguration(final InetSocketAddress bindingAddress,
- final LocalAddress tcpLocalAddress, final PEMGeneratorHostKeyProvider keyPairProvider) throws IOException {
+ final LocalAddress tcpLocalAddress, final KeyPairProvider keyPairProvider) throws IOException {
return new SshProxyServerConfigurationBuilder()
.setBindingAddress(bindingAddress)
.setLocalAddress(tcpLocalAddress)
.createSshProxyServerConfiguration();
}
- private PEMGeneratorHostKeyProvider getPemGeneratorHostKeyProvider() {
+ private static KeyPairProvider getPemGeneratorHostKeyProvider() {
try {
final Path tempFile = Files.createTempFile("tempKeyNetconfTest", "suffix");
- return new PEMGeneratorHostKeyProvider(tempFile.toAbsolutePath().toString(), "RSA", 4096);
+ return SecurityUtils.createGeneratorHostKeyProvider(tempFile.toAbsolutePath());
} catch (final IOException e) {
LOG.error("Unable to generate PEM key", e);
throw new RuntimeException(e);
}
configuration.getDefaultYangResources().forEach(r -> {
- SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create(r.getModuleName(), r.getRevision());
+ SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create(r.getModuleName(),
+ Revision.ofNullable(r.getRevision()));
registerSource(consumer, r.getResourcePath(), sourceIdentifier);
});
try {
//necessary for creating mdsal data stores and operations
- this.schemaContext = consumer.createSchemaContextFactory(
- SchemaSourceFilter.ALWAYS_ACCEPT)
- .createSchemaContext(loadedSources).checkedGet();
- } catch (final SchemaResolutionException e) {
+ this.schemaContext = consumer.createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT)
+ .createSchemaContext(loadedSources).get();
+ } catch (final InterruptedException | ExecutionException e) {
throw new RuntimeException("Cannot parse schema context", e);
}
return capabilities;
}
- private void addModuleCapability(final SharedSchemaRepository consumer, final Set<Capability> capabilities,
+ private static void addModuleCapability(final SharedSchemaRepository consumer, final Set<Capability> capabilities,
final Module module) {
- final SourceIdentifier moduleSourceIdentifier = SourceIdentifier.create(module.getName(),
- (SimpleDateFormatUtil.DEFAULT_DATE_REV == module.getRevision() ? Optional.absent() :
- Optional.of(module.getQNameModule().getFormattedRevision())));
+ final SourceIdentifier moduleSourceIdentifier = RevisionSourceIdentifier.create(module.getName(),
+ module.getRevision());
try {
final String moduleContent = new String(
- consumer.getSchemaSource(moduleSourceIdentifier, YangTextSchemaSource.class).checkedGet().read());
+ consumer.getSchemaSource(moduleSourceIdentifier, YangTextSchemaSource.class).get().read());
capabilities.add(new YangModuleCapability(module, moduleContent));
//IOException would be thrown in creating SchemaContext already
- } catch (SchemaSourceException | IOException e) {
+ } catch (ExecutionException | InterruptedException | IOException e) {
throw new RuntimeException("Cannot retrieve schema source for module "
+ moduleSourceIdentifier.toString() + " from schema repository", e);
}
}
- private void registerSource(final SharedSchemaRepository consumer, final String resource,
+ private static void registerSource(final SharedSchemaRepository consumer, final String resource,
final SourceIdentifier sourceId) {
- consumer.registerSchemaSource(new SchemaSourceProvider<SchemaSourceRepresentation>() {
+ consumer.registerSchemaSource(sourceIdentifier -> Futures.immediateFuture(new YangTextSchemaSource(sourceId) {
@Override
- public CheckedFuture<? extends SchemaSourceRepresentation, SchemaSourceException> getSource(
- final SourceIdentifier sourceIdentifier) {
- return Futures.immediateCheckedFuture(new YangTextSchemaSource(sourceId) {
- @Override
- protected MoreObjects.ToStringHelper addToStringAttributes(
- final MoreObjects.ToStringHelper toStringHelper) {
- return toStringHelper;
- }
+ protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
+ return toStringHelper;
+ }
- @Override
- public InputStream openStream() throws IOException {
- return getClass().getResourceAsStream(resource);
- }
- });
+ @Override
+ public InputStream openStream() throws IOException {
+ return getClass().getResourceAsStream(resource);
}
- }, PotentialSchemaSource.create(
- sourceId, YangTextSchemaSource.class, PotentialSchemaSource.Costs.IMMEDIATE.getValue()));
+ }), PotentialSchemaSource.create(sourceId, YangTextSchemaSource.class,
+ PotentialSchemaSource.Costs.IMMEDIATE.getValue()));
}
private static InetSocketAddress getAddress(final String ip, final int port) {
@Override
public void close() {
for (final SshProxyServer sshWrapper : sshWrappers) {
- sshWrapper.close();
+ try {
+ sshWrapper.close();
+ } catch (IOException e) {
+ LOG.debug("Wrapper {} failed to close", sshWrapper, e);
+ }
}
for (final Channel deviceCh : devicesChannels) {
deviceCh.close();