1 package org.opendaylight.controller.sal.connect.netconf
3 import org.opendaylight.controller.sal.core.api.mount.MountProvisionInstance
4 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier
5 import org.opendaylight.controller.md.sal.common.api.data.DataReader
6 import org.opendaylight.yangtools.yang.data.api.CompositeNode
7 import org.opendaylight.controller.netconf.client.NetconfClient
8 import org.opendaylight.controller.sal.core.api.RpcImplementation
9 import static extension org.opendaylight.controller.sal.connect.netconf.NetconfMapping.*
10 import java.net.InetSocketAddress
11 import org.opendaylight.yangtools.yang.data.api.Node
12 import org.opendaylight.yangtools.yang.data.api.SimpleNode
13 import org.opendaylight.yangtools.yang.common.QName
14 import java.util.Collections
15 import org.opendaylight.controller.netconf.client.NetconfClientDispatcher
16 import org.opendaylight.yangtools.concepts.Registration
18 class NetconfDevice implements DataReader<InstanceIdentifier, CompositeNode>, RpcImplementation {
20 var NetconfClient client;
23 var InetSocketAddress socketAddress;
26 val MountProvisionInstance mountInstance;
29 val InstanceIdentifier path;
31 Registration<DataReader<InstanceIdentifier,CompositeNode>> operReaderReg
33 Registration<DataReader<InstanceIdentifier,CompositeNode>> confReaderReg
35 public new(MountProvisionInstance mount,InstanceIdentifier path) {
36 _mountInstance = mount;
40 def start(NetconfClientDispatcher dispatcher) {
41 client = new NetconfClient("sal-netconf-connector", socketAddress, dispatcher);
43 confReaderReg = mountInstance.registerConfigurationReader(path,this);
44 operReaderReg = mountInstance.registerOperationalReader(path,this);
47 override readConfigurationData(InstanceIdentifier path) {
48 val result = invokeRpc(NETCONF_GET_CONFIG_QNAME, wrap(NETCONF_GET_CONFIG_QNAME, path.toFilterStructure()));
49 val data = result.result.getFirstCompositeByName(NETCONF_DATA_QNAME);
50 return data?.findNode(path) as CompositeNode;
53 override readOperationalData(InstanceIdentifier path) {
54 val result = invokeRpc(NETCONF_GET_QNAME, wrap(NETCONF_GET_QNAME, path.toFilterStructure()));
55 val data = result.result.getFirstCompositeByName(NETCONF_DATA_QNAME);
56 return data?.findNode(path) as CompositeNode;
59 override getSupportedRpcs() {
63 override invokeRpc(QName rpc, CompositeNode input) {
64 val message = rpc.toRpcMessage(input);
65 val result = client.sendMessage(message);
66 return result.toRpcResult();
69 def Node<?> findNode(CompositeNode node, InstanceIdentifier identifier) {
71 var Node<?> current = node;
72 for (arg : identifier.path) {
73 if (current instanceof SimpleNode<?>) {
75 } else if (current instanceof CompositeNode) {
76 val currentComposite = (current as CompositeNode);
78 current = currentComposite.getFirstCompositeByName(arg.nodeType);
79 if (current == null) {
80 current = currentComposite.getFirstSimpleByName(arg.nodeType);
82 if (current == null) {
91 confReaderReg?.close()
92 operReaderReg?.close()