use of org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences in project netconf by opendaylight.
the class NetconfDeviceTest method testNetconfDeviceAvailableCapabilitiesBuilding.
@Test
public void testNetconfDeviceAvailableCapabilitiesBuilding() throws Exception {
final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
final NetconfDeviceCommunicator listener = getListener();
final EffectiveModelContextFactory schemaContextProviderFactory = getSchemaFactory();
final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice.SchemaResourcesDTO(getSchemaRegistry(), getSchemaRepository(), schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
final NetconfDevice device = new NetconfDeviceBuilder().setReconnectOnSchemasChange(true).setSchemaResourcesDTO(schemaResourcesDTO).setGlobalProcessingExecutor(getExecutor()).setId(getId()).setSalFacade(facade).setBaseSchemas(BASE_SCHEMAS).build();
final NetconfDevice netconfSpy = spy(device);
final NetconfSessionPreferences sessionCaps = getSessionCaps(true, Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&revision=" + TEST_REVISION));
final Map<QName, AvailableCapability.CapabilityOrigin> moduleBasedCaps = new HashMap<>();
moduleBasedCaps.putAll(sessionCaps.getModuleBasedCapsOrigin());
moduleBasedCaps.put(QName.create("(test:qname:side:loading)test"), AvailableCapability.CapabilityOrigin.UserDefined);
netconfSpy.onRemoteSessionUp(sessionCaps.replaceModuleCaps(moduleBasedCaps), listener);
final ArgumentCaptor<NetconfSessionPreferences> argument = ArgumentCaptor.forClass(NetconfSessionPreferences.class);
verify(facade, timeout(5000)).onDeviceConnected(any(MountPointContext.class), argument.capture(), any(DOMRpcService.class), isNull());
final NetconfDeviceCapabilities netconfDeviceCaps = argument.getValue().getNetconfDeviceCapabilities();
netconfDeviceCaps.getResolvedCapabilities().forEach(entry -> assertEquals("Builded 'AvailableCapability' schemas should match input capabilities.", moduleBasedCaps.get(QName.create(entry.getCapability())).getName(), entry.getCapabilityOrigin().getName()));
}
use of org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences in project netconf by opendaylight.
the class NetconfDeviceTest method testNetconfDeviceNotificationsCapabilityIsNotPresent.
@Test
public void testNetconfDeviceNotificationsCapabilityIsNotPresent() throws Exception {
final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
final NetconfDeviceCommunicator listener = getListener();
final EffectiveModelContextFactory schemaContextProviderFactory = getSchemaFactory();
final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice.SchemaResourcesDTO(getSchemaRegistry(), getSchemaRepository(), schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
final NetconfDevice device = new NetconfDeviceBuilder().setSchemaResourcesDTO(schemaResourcesDTO).setGlobalProcessingExecutor(getExecutor()).setId(getId()).setSalFacade(facade).setBaseSchemas(BASE_SCHEMAS).build();
final NetconfDevice netconfSpy = spy(device);
final NetconfSessionPreferences sessionCaps = getSessionCaps(false, Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&revision=" + TEST_REVISION));
netconfSpy.onRemoteSessionUp(sessionCaps, listener);
final ArgumentCaptor<NetconfSessionPreferences> argument = ArgumentCaptor.forClass(NetconfSessionPreferences.class);
verify(facade, timeout(5000)).onDeviceConnected(any(MountPointContext.class), argument.capture(), any(DOMRpcService.class), isNull());
final NetconfDeviceCapabilities netconfDeviceCaps = argument.getValue().getNetconfDeviceCapabilities();
List<String> notificationModulesName = Arrays.asList(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.$YangModuleInfoImpl.getInstance().getName().toString(), org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.$YangModuleInfoImpl.getInstance().getName().toString());
assertFalse(netconfDeviceCaps.getResolvedCapabilities().stream().anyMatch(entry -> notificationModulesName.contains(entry.getCapability())));
}
use of org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences in project netconf by opendaylight.
the class NetconfDeviceTest method testNetconfDeviceMissingSource.
@Test
public void testNetconfDeviceMissingSource() throws Exception {
final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
final NetconfDeviceCommunicator listener = getListener();
final EffectiveModelContextFactory schemaFactory = getSchemaFactory();
final SchemaRepository schemaRepository = getSchemaRepository();
// Make fallback attempt to fail due to empty resolved sources
final MissingSchemaSourceException schemaResolutionException = new MissingSchemaSourceException("fail first", TEST_SID);
doReturn(Futures.immediateFailedFuture(schemaResolutionException)).when(schemaRepository).getSchemaSource(eq(TEST_SID), eq(YangTextSchemaSource.class));
doAnswer(invocation -> {
if (((Collection<?>) invocation.getArguments()[0]).size() == 2) {
return Futures.immediateFailedFuture(schemaResolutionException);
} else {
return Futures.immediateFuture(SCHEMA_CONTEXT);
}
}).when(schemaFactory).createEffectiveModelContext(anyCollection());
final NetconfDeviceSchemasResolver stateSchemasResolver = (deviceRpc, remoteSessionCapabilities, id, schemaContext) -> {
final Module first = Iterables.getFirst(SCHEMA_CONTEXT.getModules(), null);
final QName qName = QName.create(first.getQNameModule(), first.getName());
final NetconfStateSchemas.RemoteYangSchema source1 = new NetconfStateSchemas.RemoteYangSchema(qName);
final NetconfStateSchemas.RemoteYangSchema source2 = new NetconfStateSchemas.RemoteYangSchema(QName.create(first.getQNameModule(), "test-module2"));
return new NetconfStateSchemas(Sets.newHashSet(source1, source2));
};
final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice.SchemaResourcesDTO(getSchemaRegistry(), schemaRepository, schemaFactory, stateSchemasResolver);
final NetconfDevice device = new NetconfDeviceBuilder().setReconnectOnSchemasChange(true).setSchemaResourcesDTO(schemaResourcesDTO).setGlobalProcessingExecutor(getExecutor()).setBaseSchemas(BASE_SCHEMAS).setId(getId()).setSalFacade(facade).build();
// Monitoring supported
final NetconfSessionPreferences sessionCaps = getSessionCaps(true, Lists.newArrayList(TEST_CAPABILITY, TEST_CAPABILITY2));
device.onRemoteSessionUp(sessionCaps, listener);
verify(facade, timeout(5000)).onDeviceConnected(any(MountPointContext.class), any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class), isNull());
verify(schemaFactory, times(1)).createEffectiveModelContext(anyCollection());
}
use of org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences in project netconf by opendaylight.
the class NetconfStateSchemasTest method testCreateMonitoringNotSupported.
@Test
public void testCreateMonitoringNotSupported() throws Exception {
final NetconfSessionPreferences caps = NetconfSessionPreferences.fromStrings(Collections.emptySet());
final NetconfStateSchemas stateSchemas = NetconfStateSchemas.create(rpc, caps, deviceId, schemaContext);
final Set<QName> availableYangSchemasQNames = stateSchemas.getAvailableYangSchemasQNames();
assertTrue(availableYangSchemasQNames.isEmpty());
}
use of org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences in project netconf by opendaylight.
the class SchemalessNetconfDeviceTest method testSessionOnMethods.
@Test
public void testSessionOnMethods() throws Exception {
final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
final NetconfDeviceCommunicator listener = mockCloseableClass(NetconfDeviceCommunicator.class);
final SchemalessMessageTransformer messageTransformer = mock(SchemalessMessageTransformer.class);
final RemoteDeviceId remoteDeviceId = new RemoteDeviceId("test-D", InetSocketAddress.createUnresolved("localhost", 22));
final Throwable throwable = new Throwable();
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));
final NetconfMessage netconfMessage = mock(NetconfMessage.class);
device.onRemoteSessionUp(sessionCaps, listener);
verify(facade).onDeviceConnected(any(MountPointContext.class), any(NetconfSessionPreferences.class), any(DOMRpcService.class));
device.onNotification(netconfMessage);
verify(facade).onNotification(isNull());
device.onRemoteSessionDown();
verify(facade).onDeviceDisconnected();
device.onRemoteSessionFailed(throwable);
verify(facade).onDeviceFailed(throwable);
}
Aggregations