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