2 * Copyright (c) 2016 Brocade Communication Systems 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
9 package org.opendaylight.netconf.callhome.mount;
11 import io.netty.util.concurrent.EventExecutor;
12 import io.netty.util.concurrent.FailedFuture;
13 import io.netty.util.concurrent.Future;
14 import java.net.InetSocketAddress;
15 import org.opendaylight.controller.config.threadpool.ScheduledThreadPool;
16 import org.opendaylight.controller.config.threadpool.ThreadPool;
17 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
18 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
19 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
20 import org.opendaylight.controller.sal.core.api.Broker;
21 import org.opendaylight.netconf.callhome.mount.CallHomeMountSessionContext.CloseCallback;
22 import org.opendaylight.netconf.callhome.protocol.CallHomeChannelActivator;
23 import org.opendaylight.netconf.callhome.protocol.CallHomeNetconfSubsystemListener;
24 import org.opendaylight.netconf.callhome.protocol.CallHomeProtocolSessionContext;
25 import org.opendaylight.netconf.client.NetconfClientDispatcher;
26 import org.opendaylight.netconf.client.NetconfClientSession;
27 import org.opendaylight.netconf.client.conf.NetconfClientConfiguration;
28 import org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration;
29 import org.opendaylight.netconf.topology.api.SchemaRepositoryProvider;
30 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
31 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
36 public class CallHomeMountDispatcher implements NetconfClientDispatcher, CallHomeNetconfSubsystemListener {
38 private final static Logger LOG = LoggerFactory.getLogger(CallHomeMountDispatcher.class);
40 private final String topologyId;
41 private final BindingAwareBroker bindingAwareBroker;
42 private final EventExecutor eventExecutor;
43 private final ScheduledThreadPool keepaliveExecutor;
44 private final ThreadPool processingExecutor;
45 private final SchemaRepositoryProvider schemaRepositoryProvider;
46 private final org.opendaylight.controller.sal.core.api.Broker domBroker;
47 private final CallHomeMountSessionManager sessionManager;
48 private final DataBroker dataBroker;
49 private final DOMMountPointService mountService;
51 protected CallHomeTopology topology;
53 private final CloseCallback onCloseHandler = new CloseCallback() {
55 public void onClosed(CallHomeMountSessionContext deviceContext) {
56 LOG.info("Removing {} from Netconf Topology.", deviceContext.getId());
57 topology.disconnectNode(deviceContext.getId());
61 public CallHomeMountDispatcher(String topologyId, BindingAwareBroker bindingAwareBroker,
62 EventExecutor eventExecutor,
63 ScheduledThreadPool keepaliveExecutor,
64 ThreadPool processingExecutor,
65 SchemaRepositoryProvider schemaRepositoryProvider,
66 Broker domBroker, DataBroker dataBroker,
67 DOMMountPointService mountService) {
68 this.topologyId = topologyId;
69 this.bindingAwareBroker = bindingAwareBroker;
70 this.eventExecutor = eventExecutor;
71 this.keepaliveExecutor = keepaliveExecutor;
72 this.processingExecutor = processingExecutor;
73 this.schemaRepositoryProvider = schemaRepositoryProvider;
74 this.domBroker = domBroker;
75 this.sessionManager = new CallHomeMountSessionManager();
76 this.dataBroker = dataBroker;
77 this.mountService = mountService;
81 public Future<NetconfClientSession> createClient(NetconfClientConfiguration clientConfiguration) {
82 return activateChannel(clientConfiguration);
86 public Future<Void> createReconnectingClient(NetconfReconnectingClientConfiguration clientConfiguration) {
87 return activateChannel(clientConfiguration);
90 private <V> Future<V> activateChannel(NetconfClientConfiguration conf) {
91 InetSocketAddress remoteAddr = conf.getAddress();
92 CallHomeMountSessionContext context = getSessionManager().getByAddress(remoteAddr);
93 LOG.info("Activating NETCONF channel for ip {} device context {}", remoteAddr, context);
94 if (context == null) {
95 return new FailedFuture<>(eventExecutor, new NullPointerException());
97 return context.activateNetconfChannel(conf.getSessionListener());
100 void createTopology() {
101 this.topology = new CallHomeTopology(topologyId, this, bindingAwareBroker, domBroker, eventExecutor,
102 keepaliveExecutor, processingExecutor, schemaRepositoryProvider, dataBroker, mountService);
106 public void onNetconfSubsystemOpened(CallHomeProtocolSessionContext session,
107 CallHomeChannelActivator activator) {
108 CallHomeMountSessionContext deviceContext = getSessionManager().createSession(session, activator, onCloseHandler);
109 NodeId nodeId = deviceContext.getId();
110 Node configNode = deviceContext.getConfigNode();
111 LOG.info("Provisioning fake config {}", configNode);
112 topology.connectNode(nodeId, configNode);
115 public CallHomeMountSessionManager getSessionManager() {
116 return sessionManager;