d2a3be7b975784649904e119288b7d3f2da178c9
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18 package org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.access;
19
20 import java.util.Objects;
21 import java.util.Optional;
22 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
23 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
24 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
25 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
26 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.NetconfNodeStateServiceImpl;
27 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.access.dom.DomContext;
28 import org.opendaylight.mdsal.binding.api.DataBroker;
29 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev221225.ConnectionOper.ConnectionStatus;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.NetconfNode;
32 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 public class NetconfAccessorImpl implements NetconfAccessor {
37
38     @SuppressWarnings("unused")
39     private static final Logger LOG = LoggerFactory.getLogger(NetconfAccessorImpl.class);
40
41     private final NodeId nodeId;
42     private final NetconfNode netconfNode;
43     private final Capabilities capabilities;
44     private final NetconfCommunicatorManager netconfCommunicatorManager;
45     private final DomContext domContext;
46     private final NetconfNodeStateServiceImpl netconfNodeStateService;
47     /**
48      * Contains all data to access and manage netconf device
49      *
50      * @param netconfCommunicatorManager
51      *
52      * @param nodeId of managed netconf node
53      * @param netconfNode information
54      * @param domContext
55      * @param dataBroker to access node
56      * @param mountpoint of netconfNode
57      */
58      public NetconfAccessorImpl(NodeId nodeId, NetconfNode netconfNode,
59             NetconfCommunicatorManager netconfCommunicatorManager, DomContext domContext, NetconfNodeStateServiceImpl netconfNodeStateService) {
60         super();
61         this.nodeId = Objects.requireNonNull(nodeId);
62         this.netconfNode = Objects.requireNonNull(netconfNode);
63         this.netconfCommunicatorManager = Objects.requireNonNull(netconfCommunicatorManager);
64         this.domContext = Objects.requireNonNull(domContext);
65         this.netconfNodeStateService = Objects.requireNonNull(netconfNodeStateService);
66
67         ConnectionStatus csts = netconfNode.getConnectionStatus();
68         if (csts == null) {
69             throw new IllegalStateException(String.format("connection status for %s is not connected", nodeId));
70         }
71         Capabilities tmp = Capabilities.getAvailableCapabilities(netconfNode);
72         if (tmp.getCapabilities().size() <= 0) {
73             throw new IllegalStateException(String.format("no capabilities found for %s", nodeId));
74         }
75         this.capabilities = tmp;
76     }
77
78     public NetconfAccessorImpl(NetconfAccessorImpl accessor) {
79         this.nodeId = accessor.getNodeId();
80         this.netconfNode = accessor.getNetconfNode();
81         this.capabilities = accessor.getCapabilites();
82         this.netconfCommunicatorManager = accessor.netconfCommunicatorManager;
83         this.domContext = accessor.domContext;
84         this.netconfNodeStateService = accessor.netconfNodeStateService;
85     }
86
87     @Override
88     public NodeId getNodeId() {
89         return nodeId;
90     }
91
92     @Override
93     public NetconfNode getNetconfNode() {
94         return netconfNode;
95     }
96
97     @Override
98     public Capabilities getCapabilites() {
99         return capabilities;
100     }
101
102     @Override
103     public Optional<NetconfBindingAccessor> getNetconfBindingAccessor() {
104         return netconfCommunicatorManager.getNetconfBindingAccessor(this);
105     }
106
107     @Override
108     public Optional<NetconfDomAccessor> getNetconfDomAccessor() {
109         return netconfCommunicatorManager.getNetconfDomAccessor(this);
110     }
111
112     @Override
113     public DataBroker getControllerBindingDataBroker() {
114         return netconfNodeStateService.getDataBroker();
115     }
116
117     @Override
118     public DOMDataBroker getControllerDOMDataBroker() {
119         return netconfNodeStateService.getDOMDataBroker();
120     }
121
122     /**
123      * check if nc-notifications.yang is supported by the device
124      */
125     @Override
126     public boolean isNotificationsRFC5277Supported() {
127         return getCapabilites().isSupportingNamespace("urn:ietf:params:netconf:capability:notification:1.0");
128     }
129
130 }