f6f2fac74b4f272366662c7c63e90d97290c8b45
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
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
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.yangspecs;
23
24 import java.util.Arrays;
25 import java.util.Collection;
26 import java.util.List;
27 import java.util.Optional;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.dataprovider.InternalDataModelSeverity;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.interfaces.TechnologySpecificPacKeys;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.pm.PerformanceDataAirInterface;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.qnames.Onf14DevicemanagerQNames;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.util.Debug;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.util.Onf14DMDOMUtility;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.PerformanceDataLtp;
36 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
37 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
38 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
40 import org.opendaylight.yangtools.yang.common.QNameModule;
41 import org.opendaylight.yangtools.yang.common.Revision;
42 import org.opendaylight.yangtools.yang.common.XMLNamespace;
43 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
44 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceIdentifierBuilder;
45 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
46 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
47 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
48 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
49 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
50 import org.slf4j.Logger;
51 import org.slf4j.LoggerFactory;
52
53 public class AirInterface20 extends YangModule {
54
55     private static final Logger LOG = LoggerFactory.getLogger(AirInterface20.class);
56
57     private static String NAMESPACE = "urn:onf:yang:air-interface-2-0";
58     private static final List<QNameModule> MODULES =
59             Arrays.asList(QNameModule.create(XMLNamespace.of(NAMESPACE), Revision.of("2020-01-21")),
60                     QNameModule.create(XMLNamespace.of(NAMESPACE), Revision.of("2022-07-29")));
61
62     private final CoreModel14 coreModel14;
63
64     private AirInterface20(NetconfDomAccessor netconfDomAccessor, QNameModule module, CoreModel14 coreModel14) {
65         super(netconfDomAccessor, module);
66         this.coreModel14 = coreModel14;
67     }
68
69     public FaultData readAllCurrentProblems(FaultData resultList, List<TechnologySpecificPacKeys> airInterfaceList) {
70
71         int idxStart; // Start index for debug messages
72
73         for (TechnologySpecificPacKeys key : airInterfaceList) {
74             idxStart = resultList.size();
75             readAirInterfaceCurrentProblemForLtp(key.getLtpUuid(), key.getLocalId(), resultList);
76             Debug.debugResultList(key.getLtpUuid(), resultList, idxStart);
77         }
78         return resultList;
79     }
80
81     /**
82      * Get specific module for device, depending on capabilities
83      */
84     public static Optional<AirInterface20> getModule(NetconfDomAccessor netconfDomAccessor, CoreModel14 coreModel14) {
85
86         Capabilities capabilities = netconfDomAccessor.getCapabilites();
87         for (QNameModule module : MODULES) {
88
89             if (capabilities.isSupportingNamespaceAndRevision(module)) {
90                 return Optional.of(new AirInterface20(netconfDomAccessor, module, coreModel14));
91             }
92         }
93         return Optional.empty();
94     }
95
96     private FaultData readAirInterfaceCurrentProblemForLtp(String ltpUuid, String localId, FaultData resultList) {
97
98         LOG.debug("DBRead Get current problems for class {} from mountpoint {} for LTP uuid {} and local-id {}",
99                 getQNameModule(), netconfDomAccessor.getNodeId().getValue(), ltpUuid, localId);
100
101         // constructing the IID needs the augmentation exposed by the air-interface-2-0
102         // model
103
104         YangInstanceIdentifier layerProtocolIID = coreModel14.getLayerProtocolIId(ltpUuid, localId);
105         InstanceIdentifierBuilder airInterfacePacIID =
106                 YangInstanceIdentifier.builder(layerProtocolIID).node(getQName("air-interface-pac"));
107
108         //        @NonNull
109         //        AugmentationIdentifier airInterfacePacIID =
110         //                YangInstanceIdentifier.AugmentationIdentifier.create(Sets.newHashSet(getQName("air-interface-pac")));
111         //
112         //        InstanceIdentifierBuilder augmentedAirInterfacePacIID =
113         //                YangInstanceIdentifier.builder(layerProtocolIID).node(airInterfacePacIID);
114         //
115         // reading all the current-problems list for this specific LTP and LP
116         Optional<NormalizedNode> airInterfacePacDataOpt =
117                 netconfDomAccessor.readDataNode(LogicalDatastoreType.OPERATIONAL, airInterfacePacIID.build());
118         if (airInterfacePacDataOpt.isPresent()) {
119             LOG.info("Air Interface = {}", airInterfacePacDataOpt.get().prettyTree());
120         }
121         if (airInterfacePacDataOpt.isPresent()) {
122             ContainerNode airInterfacePacData = (ContainerNode) airInterfacePacDataOpt.get();
123             MapNode airInterfaceCurrentProblemsList =
124                     (MapNode) airInterfacePacData.childByArg(new NodeIdentifier(getQName("current-problem-list")));
125             if (airInterfaceCurrentProblemsList != null) {
126                 Collection<MapEntryNode> airInterfaceProblemsCollection = airInterfaceCurrentProblemsList.body();
127                 for (MapEntryNode airInterfaceProblem : airInterfaceProblemsCollection) {
128                     resultList.add(netconfDomAccessor.getNodeId(),
129                             Integer.parseInt(
130                                     Onf14DMDOMUtility.getLeafValue(airInterfaceProblem, getQName("sequence-number"))),
131                             new DateAndTime(Onf14DMDOMUtility.getLeafValue(airInterfaceProblem, getQName("timestamp"))),
132                             ltpUuid, Onf14DMDOMUtility.getLeafValue(airInterfaceProblem, getQName("problem-name")),
133                             InternalDataModelSeverity.mapSeverity(
134                                     Onf14DMDOMUtility.getLeafValue(airInterfaceProblem, getQName("problem-severity"))));
135                 }
136             } else {
137                 LOG.debug("DBRead Id {} empty CurrentProblemList", ltpUuid);
138             }
139         }
140         return resultList;
141     }
142
143     public PerformanceDataLtp readAirInterfaceHistoricalPerformanceData(String ltpUuid, String localId,
144             PerformanceDataLtp res) {
145         LOG.debug("Get historical performance data for class {} from mountpoint {} for LTP uuid {} and local-id {}",
146                 Onf14DevicemanagerQNames.AIR_INTERFACE_2_0_MODULE, netconfDomAccessor.getNodeId().getValue(), ltpUuid,
147                 localId);
148
149         // constructing the IID needs the augmentation exposed by the air-interface-2-0
150         // model
151
152         YangInstanceIdentifier layerProtocolIID = coreModel14.getLayerProtocolIId(ltpUuid, localId);
153         InstanceIdentifierBuilder airInterfacePacIID =
154                 YangInstanceIdentifier.builder(layerProtocolIID).node(getQName("air-interface-pac"));
155
156         //        @NonNull
157         //        AugmentationIdentifier airInterfacePacIID = YangInstanceIdentifier.AugmentationIdentifier
158         //                .create(Sets.newHashSet(Onf14DevicemanagerQNames.AIR_INTERFACE_PAC));
159         //
160         //        InstanceIdentifierBuilder augmentedAirInterfacePacIID =
161         //                YangInstanceIdentifier.builder(layerProtocolIID).node(airInterfacePacIID);
162         //
163         //        // reading historical performance list for this specific LTP and LP
164                 Optional<NormalizedNode> airInterfacePacDataOpt =
165                         netconfDomAccessor.readDataNode(LogicalDatastoreType.OPERATIONAL, airInterfacePacIID.build());
166                 LOG.debug("Performance Data = {}", airInterfacePacDataOpt.get().body());
167                 if (airInterfacePacDataOpt.isPresent()) {
168                     ContainerNode airInterfacePacData = (ContainerNode) airInterfacePacDataOpt.get();
169                     ContainerNode cn = (ContainerNode) airInterfacePacData
170                             .childByArg(new NodeIdentifier(Onf14DevicemanagerQNames.AIR_INTERFACE_PAC));
171                     if (cn != null) {
172                         ContainerNode airIntfHistPerf = (ContainerNode) cn
173                                 .childByArg(new NodeIdentifier(Onf14DevicemanagerQNames.AIR_INTERFACE_HISTORICAL_PERFORMANCES));
174                         if (airIntfHistPerf != null) {
175                             MapNode airInterfaceHistoricalPerformanceList = (MapNode) airIntfHistPerf.childByArg(
176                                     new NodeIdentifier(Onf14DevicemanagerQNames.AIR_INTERFACE_HISTORICAL_PERFORMANCES_LIST));
177                             if (airInterfaceHistoricalPerformanceList != null) {
178                                 Collection<MapEntryNode> airInterfaceHistoricalPerfCollection =
179                                         airInterfaceHistoricalPerformanceList.body();
180                                 for (MapEntryNode airInterfaceHistPerf : airInterfaceHistoricalPerfCollection) {
181                                     res.add(new PerformanceDataAirInterface(netconfDomAccessor.getNodeId(), ltpUuid, localId,
182                                             airInterfaceHistPerf));
183                                 }
184                                 return res;
185                             } else {
186                                 LOG.debug("DBRead Id {} empty CurrentProblemList", ltpUuid);
187                             }
188                         }
189                     }
190                 }
191         return null;
192
193     }
194 }