use of org.opendaylight.netconf.api.capability.Capability in project netconf by opendaylight.
the class NetconfCapabilityMonitoringServiceTest method testOnCapabilitiesChanged.
@Test
public void testOnCapabilitiesChanged() throws Exception {
final String capUri = "test";
final Uri uri = new Uri(capUri);
final HashSet<Capability> testCaps = new HashSet<>();
testCaps.add(new BasicCapability(capUri));
final ArgumentCaptor<NetconfCapabilityChange> capabilityChangeCaptor = ArgumentCaptor.forClass(NetconfCapabilityChange.class);
final ArgumentCaptor<Capabilities> monitoringListenerCaptor = ArgumentCaptor.forClass(Capabilities.class);
// add capability
monitoringService.onCapabilitiesChanged(testCaps, Set.of());
// remove capability
monitoringService.onCapabilitiesChanged(Set.of(), testCaps);
verify(listener, times(3)).onCapabilitiesChanged(monitoringListenerCaptor.capture());
verify(notificationPublisher, times(2)).onCapabilityChanged(capabilityChangeCaptor.capture());
// verify listener calls
final List<Capabilities> listenerValues = monitoringListenerCaptor.getAllValues();
final List<Uri> afterRegisterState = listenerValues.get(0).getCapability();
final List<Uri> afterAddState = listenerValues.get(1).getCapability();
final List<Uri> afterRemoveState = listenerValues.get(2).getCapability();
assertEquals(capabilitiesSize, afterRegisterState.size());
assertEquals(capabilitiesSize + 1, afterAddState.size());
assertEquals(capabilitiesSize, afterRemoveState.size());
assertFalse(afterRegisterState.contains(uri));
assertTrue(afterAddState.contains(uri));
assertFalse(afterRemoveState.contains(uri));
// verify notification publication
final List<NetconfCapabilityChange> publisherValues = capabilityChangeCaptor.getAllValues();
final NetconfCapabilityChange afterAdd = publisherValues.get(0);
final NetconfCapabilityChange afterRemove = publisherValues.get(1);
assertEquals(Set.of(uri), Set.copyOf(afterAdd.getAddedCapability()));
assertEquals(List.of(), afterAdd.getDeletedCapability());
assertEquals(Set.of(uri), Set.copyOf(afterRemove.getDeletedCapability()));
assertEquals(List.of(), afterRemove.getAddedCapability());
}
use of org.opendaylight.netconf.api.capability.Capability 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.Capability in project netconf by opendaylight.
the class NetconfDeviceSimulator method parseSchemasToModuleCapabilities.
private Set<Capability> parseSchemasToModuleCapabilities(final SharedSchemaRepository consumer) {
final Set<SourceIdentifier> loadedSources = new HashSet<>();
consumer.registerSchemaSourceListener(TextToIRTransformer.create(consumer, consumer));
consumer.registerSchemaSourceListener(new SchemaSourceListener() {
@Override
public void schemaSourceEncountered(final SchemaSourceRepresentation schemaSourceRepresentation) {
}
@Override
public void schemaSourceRegistered(final Iterable<PotentialSchemaSource<?>> potentialSchemaSources) {
for (final PotentialSchemaSource<?> potentialSchemaSource : potentialSchemaSources) {
loadedSources.add(potentialSchemaSource.getSourceIdentifier());
}
}
@Override
public void schemaSourceUnregistered(final PotentialSchemaSource<?> potentialSchemaSource) {
}
});
if (configuration.getSchemasDir() != null) {
LOG.info("Loading models from directory.");
final FilesystemSchemaSourceCache<YangTextSchemaSource> cache = new FilesystemSchemaSourceCache<>(consumer, YangTextSchemaSource.class, configuration.getSchemasDir());
consumer.registerSchemaSourceListener(cache);
} else if (configuration.getModels() != null) {
LOG.info("Loading models from classpath.");
final SchemaSourceCache<YangTextSchemaSource> cache = new SchemaSourceCache<>(consumer, YangTextSchemaSource.class, configuration.getModels());
consumer.registerSchemaSourceListener(cache);
} else {
LOG.info("Custom module loading skipped.");
}
configuration.getDefaultYangResources().forEach(r -> {
final 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.createEffectiveModelContextFactory().createEffectiveModelContext(loadedSources).get();
} catch (final InterruptedException | ExecutionException e) {
throw new RuntimeException("Cannot parse schema context. " + "Please read stack trace and check YANG files in schema directory.", e);
}
final Set<Capability> capabilities = new HashSet<>();
for (final Module module : schemaContext.getModules()) {
for (final Submodule subModule : module.getSubmodules()) {
addModuleCapability(consumer, capabilities, subModule);
}
addModuleCapability(consumer, capabilities, module);
}
return capabilities;
}
use of org.opendaylight.netconf.api.capability.Capability in project netconf by opendaylight.
the class NetconfCapabilityMonitoringServiceTest method testListeners.
@Test
public void testListeners() throws Exception {
HashSet<Capability> added = new HashSet<>();
added.add(new BasicCapability("toAdd"));
monitoringService.onCapabilitiesChanged(added, Set.of());
// onCapabilitiesChanged and onSchemasChanged are invoked also after listener registration
verify(listener, times(2)).onCapabilitiesChanged(any());
verify(listener, times(2)).onSchemasChanged(any());
}
use of org.opendaylight.netconf.api.capability.Capability in project netconf by opendaylight.
the class NetconfCapabilityMonitoringServiceTest method testGetCapabilities.
@Test
public void testGetCapabilities() throws Exception {
List<Uri> exp = new ArrayList<>();
for (Capability capability : capabilities) {
exp.add(new Uri(capability.getCapabilityUri()));
}
// candidate and url capabilities are added by monitoring service automatically
exp.add(new Uri(URN_IETF_PARAMS_NETCONF_CAPABILITY_CANDIDATE_1_0));
exp.add(new Uri(URN_IETF_PARAMS_NETCONF_CAPABILITY_URL_1_0));
Capabilities expected = new CapabilitiesBuilder().setCapability(exp).build();
Capabilities actual = monitoringService.getCapabilities();
assertEquals(new HashSet<>(expected.getCapability()), new HashSet<>(actual.getCapability()));
}
Aggregations