use of org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences in project netconf by opendaylight.
the class NetconfDataTreeServiceImplTest method getNetconService.
private AbstractNetconfDataTreeService getNetconService() {
NetconfSessionPreferences prefs = NetconfSessionPreferences.fromStrings(Collections.singletonList(NetconfMessageTransformUtil.NETCONF_CANDIDATE_URI.toString()));
final RemoteDeviceId id = new RemoteDeviceId("device-1", InetSocketAddress.createUnresolved("localhost", 17830));
return AbstractNetconfDataTreeService.of(id, new EmptyMountPointContext(SCHEMA_CONTEXT), rpcService, prefs);
}
use of org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences in project netconf by opendaylight.
the class NetconfDeviceTest method testNetconfDeviceFailFirstSchemaFailSecondEmpty.
@Test
public void testNetconfDeviceFailFirstSchemaFailSecondEmpty() throws Exception {
final ArrayList<String> capList = Lists.newArrayList(TEST_CAPABILITY);
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 SchemaResolutionException schemaResolutionException = new SchemaResolutionException("fail first", Collections.emptyList(), HashMultimap.create());
doReturn(Futures.immediateFailedFuture(schemaResolutionException)).when(schemaFactory).createEffectiveModelContext(anyCollection());
final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice.SchemaResourcesDTO(getSchemaRegistry(), schemaRepository, schemaFactory, STATE_SCHEMAS_RESOLVER);
final NetconfDevice device = new NetconfDeviceBuilder().setReconnectOnSchemasChange(true).setSchemaResourcesDTO(schemaResourcesDTO).setGlobalProcessingExecutor(getExecutor()).setId(getId()).setSalFacade(facade).setBaseSchemas(BASE_SCHEMAS).build();
// Monitoring not supported
final NetconfSessionPreferences sessionCaps = getSessionCaps(false, capList);
device.onRemoteSessionUp(sessionCaps, listener);
verify(facade, timeout(5000)).onDeviceDisconnected();
verify(listener, timeout(5000)).close();
verify(schemaFactory, times(1)).createEffectiveModelContext(anyCollection());
}
use of org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences in project netconf by opendaylight.
the class NetconfDeviceTest method testNetconfDeviceNotificationsModelNotPresentWithCapability.
@Test
public void testNetconfDeviceNotificationsModelNotPresentWithCapability() 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(XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_CAPABILITY_NOTIFICATION_1_0));
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());
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());
final Set<AvailableCapability> resolvedCapabilities = argument.getValue().getNetconfDeviceCapabilities().getResolvedCapabilities();
assertEquals(2, resolvedCapabilities.size());
assertTrue(resolvedCapabilities.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 testNotificationBeforeSchema.
@Test
public void testNotificationBeforeSchema() throws Exception {
final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
final NetconfDeviceCommunicator listener = getListener();
final EffectiveModelContextFactory schemaContextProviderFactory = mock(EffectiveModelContextFactory.class);
final SettableFuture<SchemaContext> schemaFuture = SettableFuture.create();
doReturn(schemaFuture).when(schemaContextProviderFactory).createEffectiveModelContext(any(Collection.class));
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 NetconfSessionPreferences sessionCaps = getSessionCaps(true, Lists.newArrayList(TEST_CAPABILITY));
device.onRemoteSessionUp(sessionCaps, listener);
device.onNotification(NOTIFICATION);
device.onNotification(NOTIFICATION);
verify(facade, times(0)).onNotification(any(DOMNotification.class));
verify(facade, times(0)).onNotification(any(DOMNotification.class));
schemaFuture.set(NetconfToNotificationTest.getNotificationSchemaContext(getClass(), false));
verify(facade, timeout(10000).times(2)).onNotification(any(DOMNotification.class));
device.onNotification(NOTIFICATION);
verify(facade, timeout(10000).times(3)).onNotification(any(DOMNotification.class));
}
use of org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences in project netconf by opendaylight.
the class NetconfDeviceTest method testNetconfDeviceDisconnectListenerCallCancellation.
@Test
public void testNetconfDeviceDisconnectListenerCallCancellation() throws Exception {
final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
final NetconfDeviceCommunicator listener = getListener();
final EffectiveModelContextFactory schemaContextProviderFactory = mock(EffectiveModelContextFactory.class);
final SettableFuture<SchemaContext> schemaFuture = SettableFuture.create();
doReturn(schemaFuture).when(schemaContextProviderFactory).createEffectiveModelContext(any(Collection.class));
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 NetconfSessionPreferences sessionCaps = getSessionCaps(true, Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&revision=" + TEST_REVISION));
// session up, start schema resolution
device.onRemoteSessionUp(sessionCaps, listener);
// session closed
device.onRemoteSessionDown();
verify(facade, timeout(5000)).onDeviceDisconnected();
// complete schema setup
schemaFuture.set(SCHEMA_CONTEXT);
// facade.onDeviceDisconnected() was called, so facade.onDeviceConnected() shouldn't be called anymore
verify(facade, after(1000).never()).onDeviceConnected(any(), any(), any(), any(DOMActionService.class));
}
Aggregations