use of org.opendaylight.netconf.api.capability.YangModuleCapability in project netconf by opendaylight.
the class NetconfCapabilityMonitoringServiceTest method setUp.
@Before
public void setUp() throws Exception {
doReturn(XMLNamespace.of(TEST_MODULE_NAMESPACE.getValue())).when(moduleMock).getNamespace();
doReturn(TEST_MODULE_NAME).when(moduleMock).getName();
doReturn(Optional.of(TEST_MODULE_DATE)).when(moduleMock).getRevision();
moduleCapability1 = new YangModuleCapability(moduleMock, TEST_MODULE_CONTENT);
capabilities.add(moduleCapability1);
doReturn(XMLNamespace.of(TEST_MODULE_NAMESPACE.getValue())).when(moduleMock2).getNamespace();
doReturn(TEST_MODULE_NAME).when(moduleMock2).getName();
doReturn(Optional.of(TEST_MODULE_DATE2)).when(moduleMock2).getRevision();
moduleCapability2 = new YangModuleCapability(moduleMock2, TEST_MODULE_CONTENT2);
capabilities.add(new BasicCapability("urn:ietf:params:netconf:base:1.0"));
capabilities.add(new BasicCapability("urn:ietf:params:netconf:base:1.1"));
capabilities.add(new BasicCapability("urn:ietf:params:xml:ns:yang:ietf-inet-types?module=ietf-inet-types&" + "revision=2010-09-24"));
doReturn(capabilities).when(operationServiceFactoryMock).getCapabilities();
doReturn(null).when(operationServiceFactoryMock).registerCapabilityListener(any(NetconfCapabilityMonitoringService.class));
doNothing().when(listener).onCapabilitiesChanged(any());
doNothing().when(listener).onSchemasChanged(any());
doNothing().when(notificationPublisher).onCapabilityChanged(any());
monitoringService = new NetconfCapabilityMonitoringService(operationServiceFactoryMock);
monitoringService.onCapabilitiesChanged(capabilities, Set.of());
monitoringService.setNotificationPublisher(notificationPublisher);
monitoringService.registerListener(listener);
capabilitiesSize = monitoringService.getCapabilities().getCapability().size();
}
use of org.opendaylight.netconf.api.capability.YangModuleCapability in project netconf by opendaylight.
the class MdsalNetconfOperationServiceFactory method moduleToCapability.
private static Optional<YangModuleCapability> moduleToCapability(final ModuleLike module, final SchemaSourceProvider<YangTextSchemaSource> rootSchemaSourceProviderDependency) {
final SourceIdentifier moduleSourceIdentifier = RevisionSourceIdentifier.create(module.getName(), module.getRevision());
InputStream sourceStream = null;
String source;
try {
sourceStream = rootSchemaSourceProviderDependency.getSource(moduleSourceIdentifier).get().openStream();
source = CharStreams.toString(new InputStreamReader(sourceStream, StandardCharsets.UTF_8));
} catch (ExecutionException | InterruptedException | IOException e) {
LOG.warn("Ignoring source for module {}. Unable to read content", moduleSourceIdentifier, e);
source = null;
}
try {
if (sourceStream != null) {
sourceStream.close();
}
} catch (IOException e) {
LOG.warn("Error closing yang source stream {}. Ignoring", moduleSourceIdentifier, e);
}
if (source != null) {
return Optional.of(new YangModuleCapability(module, source));
}
LOG.warn("Missing source for module {}. This module will not be available from netconf server", moduleSourceIdentifier);
return Optional.empty();
}
use of org.opendaylight.netconf.api.capability.YangModuleCapability in project netconf by opendaylight.
the class NetconfDeviceSimulator method createDispatcher.
private NetconfServerDispatcherImpl createDispatcher(final Set<Capability> capabilities, final SchemaSourceProvider<YangTextSchemaSource> sourceProvider) {
final Set<Capability> transformedCapabilities = new HashSet<>(Collections2.transform(capabilities, input -> {
if (sendFakeSchema) {
sendFakeSchema = false;
return new FakeCapability((YangModuleCapability) input);
} else {
return input;
}
}));
transformedCapabilities.add(new BasicCapability("urn:ietf:params:netconf:capability:candidate:1.0"));
final NetconfMonitoringService monitoringService1 = new DummyMonitoringService(transformedCapabilities);
final SessionIdProvider idProvider = new SessionIdProvider();
final NetconfOperationServiceFactory aggregatedNetconfOperationServiceFactory = createOperationServiceFactory(sourceProvider, transformedCapabilities, monitoringService1, idProvider);
final Set<String> serverCapabilities = configuration.getCapabilities();
final NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new TesttoolNegotiationFactory(hashedWheelTimer, aggregatedNetconfOperationServiceFactory, idProvider, configuration.getGenerateConfigsTimeout(), monitoringService1, serverCapabilities);
final ServerChannelInitializer serverChannelInitializer = new ServerChannelInitializer(serverNegotiatorFactory);
return new NetconfServerDispatcherImpl(serverChannelInitializer, nettyThreadgroup, nettyThreadgroup);
}
use of org.opendaylight.netconf.api.capability.YangModuleCapability in project netconf by opendaylight.
the class NetconfDeviceSimulator method addModuleCapability.
private static void addModuleCapability(final SharedSchemaRepository consumer, final Set<Capability> capabilities, final ModuleLike module) {
final SourceIdentifier moduleSourceIdentifier = RevisionSourceIdentifier.create(module.getName(), module.getRevision());
try {
final String moduleContent = new String(consumer.getSchemaSource(moduleSourceIdentifier, YangTextSchemaSource.class).get().read());
capabilities.add(new YangModuleCapability(module, moduleContent));
// IOException would be thrown in creating SchemaContext already
} catch (final ExecutionException | InterruptedException | IOException e) {
throw new RuntimeException("Cannot retrieve schema source for module " + moduleSourceIdentifier.toString() + " from schema repository", e);
}
}
Aggregations