2 * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.impl.mdsal;
10 import static com.google.common.base.Verify.verifyNotNull;
11 import static java.util.Objects.requireNonNull;
13 import io.netty.channel.EventLoopGroup;
14 import io.netty.util.Timer;
16 import org.opendaylight.controller.config.threadpool.ScheduledThreadPool;
17 import org.opendaylight.netconf.impl.NetconfServerSessionNegotiatorFactory;
18 import org.opendaylight.netconf.impl.ServerChannelInitializer;
19 import org.opendaylight.netconf.impl.SessionIdProvider;
20 import org.opendaylight.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory;
21 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory;
22 import org.osgi.framework.FrameworkUtil;
23 import org.osgi.service.component.ComponentFactory;
24 import org.osgi.service.component.ComponentInstance;
25 import org.osgi.service.component.annotations.Activate;
26 import org.osgi.service.component.annotations.Component;
27 import org.osgi.service.component.annotations.Deactivate;
28 import org.osgi.service.component.annotations.Reference;
29 import org.osgi.service.metatype.annotations.AttributeDefinition;
30 import org.osgi.service.metatype.annotations.Designate;
31 import org.osgi.service.metatype.annotations.ObjectClassDefinition;
33 @Component(service = { }, configurationPid = "org.opendaylight.netconf.impl")
34 @Designate(ocd = OSGiNetconfServer.Configuration.class)
35 public final class OSGiNetconfServer {
36 @ObjectClassDefinition
37 public @interface Configuration {
38 @AttributeDefinition(min = "0")
39 long connection$_$timeout$_$millis() default 20000;
41 long monitoring$_$update$_$interval() default 6;
44 private final AggregatedNetconfOperationServiceFactory mappers = new AggregatedNetconfOperationServiceFactory();
45 private final ComponentInstance<DefaultNetconfMonitoringService> monitoring;
46 private final ComponentInstance<DefaultNetconfServerDispatcher> dispatcher;
49 public OSGiNetconfServer(
50 @Reference(target = "(component.factory=" + DefaultNetconfMonitoringService.FACTORY_NAME + ")")
51 final ComponentFactory<DefaultNetconfMonitoringService> monitoringFactory,
52 @Reference(target = "(component.factory=" + DefaultNetconfServerDispatcher.FACTORY_NAME + ")")
53 final ComponentFactory<DefaultNetconfServerDispatcher> dispatcherFactory,
54 @Reference(target = "(" + NetconfMapperAggregator.OSGI_TYPE + ")")
55 final NetconfOperationServiceFactory mapperAggregatorRegistry,
56 @Reference(target = "(type=global-netconf-ssh-scheduled-executor)")
57 final ScheduledThreadPool sshScheduledExecutor,
58 @Reference(target = "(type=global-boss-group)") final EventLoopGroup bossGroup,
59 @Reference(target = "(type=global-boss-group)") final EventLoopGroup workerGroup,
60 @Reference(target = "(type=global-timer)") final Timer timer,
61 @Reference final SessionIdProvider sessionIdProvider,
62 final Configuration configuration) {
63 mappers.onAddNetconfOperationServiceFactory(mapperAggregatorRegistry);
64 monitoring = monitoringFactory.newInstance(FrameworkUtil.asDictionary(DefaultNetconfMonitoringService.props(
65 mapperAggregatorRegistry, sshScheduledExecutor, configuration.monitoring$_$update$_$interval())));
66 dispatcher = dispatcherFactory.newInstance(FrameworkUtil.asDictionary(DefaultNetconfServerDispatcher.props(
67 bossGroup, workerGroup, new ServerChannelInitializer(new NetconfServerSessionNegotiatorFactory(timer,
68 mappers, sessionIdProvider, configuration.connection$_$timeout$_$millis(),
69 monitoring.getInstance())))));
73 public void deactivate() {
79 static <T> T extractProp(final Map<String, ?> properties, final String key, final Class<T> valueType) {
80 return valueType.cast(verifyNotNull(properties.get(requireNonNull(key))));