2 * Copyright (c) 2013 Cisco Systems, Inc. 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.controller.netconf.impl.osgi;
10 import com.google.common.base.Optional;
11 import io.netty.util.HashedWheelTimer;
12 import org.opendaylight.controller.config.stat.ConfigProvider;
13 import org.opendaylight.controller.netconf.impl.*;
14 import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil;
15 import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil.TLSConfiguration;
16 import org.osgi.framework.BundleActivator;
17 import org.osgi.framework.BundleContext;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 import javax.net.ssl.SSLContext;
22 import java.lang.management.ManagementFactory;
23 import java.net.InetSocketAddress;
25 public class NetconfImplActivator implements BundleActivator {
27 private static final Logger logger = LoggerFactory.getLogger(NetconfImplActivator.class);
29 private Optional<InetSocketAddress> maybeTCPAddress;
30 private Optional<TLSConfiguration> maybeTLSConfiguration;
32 private NetconfOperationServiceFactoryTracker factoriesTracker;
33 private DefaultCommitNotificationProducer commitNot;
34 private NetconfServerDispatcher dispatch;
37 public void start(final BundleContext context) throws Exception {
38 final ConfigProvider configProvider = new ConfigProvider.ConfigProviderImpl(context);
39 maybeTCPAddress = NetconfConfigUtil.extractTCPNetconfAddress(configProvider);
40 maybeTLSConfiguration = NetconfConfigUtil.extractTLSConfiguration(configProvider);
41 if (maybeTCPAddress.isPresent() == false && maybeTLSConfiguration.isPresent() == false) {
42 throw new IllegalStateException("TCP nor TLS is configured, netconf not available.");
44 NetconfOperationServiceFactoryListenerImpl factoriesListener = new NetconfOperationServiceFactoryListenerImpl();
45 factoriesTracker = new NetconfOperationServiceFactoryTracker(context, factoriesListener);
46 factoriesTracker.open();
48 SessionIdProvider idProvider = new SessionIdProvider();
49 NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory(
50 new HashedWheelTimer(), factoriesListener, idProvider);
52 commitNot = new DefaultCommitNotificationProducer(ManagementFactory.getPlatformMBeanServer());
54 NetconfServerSessionListenerFactory listenerFactory = new NetconfServerSessionListenerFactory(
55 factoriesListener, commitNot, idProvider);
57 if (maybeTCPAddress.isPresent()) {
58 Optional<SSLContext> maybeSSLContext = Optional.absent();
59 InetSocketAddress address = maybeTCPAddress.get();
60 dispatch = new NetconfServerDispatcher(maybeSSLContext, serverNegotiatorFactory, listenerFactory);
62 logger.info("Starting TCP netconf server at {}", address);
63 dispatch.createServer(address);
65 if (maybeTLSConfiguration.isPresent()) {
66 Optional<SSLContext> maybeSSLContext = Optional.of(maybeTLSConfiguration.get().getSslContext());
67 InetSocketAddress address = maybeTLSConfiguration.get().getAddress();
68 dispatch = new NetconfServerDispatcher(maybeSSLContext, serverNegotiatorFactory, listenerFactory);
70 logger.info("Starting TLS netconf server at {}", address);
71 dispatch.createServer(address);
76 public void stop(final BundleContext context) throws Exception {
77 logger.info("Shutting down netconf because YangStoreService service was removed");