2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.access;
24 import java.util.Optional;
25 import org.eclipse.jdt.annotation.NonNull;
26 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
27 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
28 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.access.binding.NetconfBindingAccessorImpl;
29 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.access.dom.DomContext;
30 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.access.dom.NetconfDomAccessorImpl;
31 import org.opendaylight.mdsal.binding.api.DataBroker;
32 import org.opendaylight.mdsal.binding.api.MountPoint;
33 import org.opendaylight.mdsal.binding.api.MountPointService;
34 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
35 import org.opendaylight.mdsal.dom.api.DOMMountPoint;
36 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.network.topology.topology.topology.types.TopologyNetconf;
38 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
39 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
40 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
41 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
42 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
43 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
44 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
45 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
46 import org.opendaylight.yangtools.yang.common.QName;
47 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
51 public class NetconfCommunicatorManager {
53 private static final Logger LOG = LoggerFactory.getLogger(NetconfCommunicatorManager.class);
55 private static final @NonNull InstanceIdentifier<Topology> NETCONF_TOPO_IID =
56 InstanceIdentifier.create(NetworkTopology.class).child(Topology.class,
57 new TopologyKey(new TopologyId(TopologyNetconf.QNAME.getLocalName())));
59 private static final @NonNull InstanceIdentifier<Node> NETCONF_NODE_TOPO_IID =
60 InstanceIdentifier.create(NetworkTopology.class)
61 .child(Topology.class, new TopologyKey(new TopologyId(TopologyNetconf.QNAME.getLocalName())))
64 private final MountPointService mountPointService;
65 private final DOMMountPointService domMountPointService;
66 private final DomContext domContext;
69 public NetconfCommunicatorManager(MountPointService mountPointService, DOMMountPointService domMountPointService,
70 DomContext domContext) {
72 this.mountPointService = mountPointService;
73 this.domMountPointService = domMountPointService;
74 this.domContext = domContext;
77 public Optional<NetconfBindingAccessor> getNetconfBindingAccessor(NetconfAccessorImpl accessor) {
78 String mountPointNodeName = accessor.getNodeId().getValue();
79 InstanceIdentifier<Node> instanceIdentifier =
80 NETCONF_TOPO_IID.child(Node.class, new NodeKey(new NodeId(mountPointNodeName)));
82 final Optional<MountPoint> optionalMountPoint = mountPointService.getMountPoint(instanceIdentifier);
83 if (!optionalMountPoint.isPresent()) {
84 LOG.warn("No mountpoint available for Netconf device :: Name : {} ", mountPointNodeName);
86 final MountPoint mountPoint = optionalMountPoint.get();
88 LOG.info("Mountpoint with id: {} class:{}", mountPoint.getIdentifier(), mountPoint.getClass().getName());
90 Optional<DataBroker> optionalNetconfNodeDatabroker = mountPoint.getService(DataBroker.class);
92 if (!optionalNetconfNodeDatabroker.isPresent()) {
93 LOG.info("Slave mountpoint {} without databroker", mountPointNodeName);
95 LOG.info("Master mountpoint {}", mountPointNodeName);
97 new NetconfBindingAccessorImpl(accessor, optionalNetconfNodeDatabroker.get(), mountPoint));
100 return Optional.empty();
103 public Optional<NetconfDomAccessor> getNetconfDomAccessor(NetconfAccessorImpl accessor) {
105 final YangInstanceIdentifier mountpointPath = YangInstanceIdentifier.builder().node(NetworkTopology.QNAME)
106 .node(Topology.QNAME)
107 .nodeWithKey(Topology.QNAME, QName.create(Topology.QNAME, "topology-id").intern(), "topology-netconf")
109 .nodeWithKey(Node.QNAME, QName.create(Node.QNAME, "node-id").intern(), accessor.getNodeId().getValue())
111 final Optional<DOMMountPoint> oMountPoint = domMountPointService.getMountPoint(mountpointPath);
112 if (oMountPoint.isEmpty()) {
113 return Optional.empty();
116 final Optional<DOMDataBroker> domDataBroker = oMountPoint.get().getService(DOMDataBroker.class);
117 if (domDataBroker.isPresent()) {
119 .of(new NetconfDomAccessorImpl(accessor, domDataBroker.get(), oMountPoint.get(), domContext));
121 return Optional.empty();