d1914342fb11ed81b7cc4b56297c265cedffbef2
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2022 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.interfaces;
23
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.List;
27 import java.util.Objects;
28 import java.util.Optional;
29 import org.eclipse.jdt.annotation.NonNull;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.notifications.Onf14DomAirInterfaceNotificationListener;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.notifications.Onf14DomAlarmsNotificationListener;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.notifications.Onf14DomEthernetContainerNotificationListener;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.notifications.Onf14DomWireInterfaceNotificationListener;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.qnames.Onf14DevicemanagerQNames;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.util.Onf14DMDOMUtility;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.yangspecs.AirInterface20;
37 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.yangspecs.Alarms10;
38 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.yangspecs.CoreModel14;
39 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.yangspecs.EthernetContainer20;
40 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.yangspecs.WireInterface20;
41 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
42 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
43 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
44 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.PerformanceDataLtp;
45 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
46 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
47 import org.opendaylight.yangtools.yang.common.QName;
48 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
49 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
50 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
51 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
52 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
53 import org.slf4j.Logger;
54 import org.slf4j.LoggerFactory;
55
56 /*
57 * Notifications streams provided by device NTSSim ONF14
58 * Stream{getName=StreamNameType{_value=nc-notifications}, isReplaySupport=true, augmentation=[]},
59 * Stream{getName=StreamNameType{_value=hybrid-mw-structure-2-0}, isReplaySupport=true, augmentation=[]},
60 * Stream{getName=StreamNameType{_value=vlan-interface-1-0}, isReplaySupport=true, augmentation=[]},
61 * Stream{getName=StreamNameType{_value=tdm-container-2-0}, isReplaySupport=true, augmentation=[]},
62 * Stream{getName=StreamNameType{_value=ethernet-container-2-0}, isReplaySupport=true, augmentation=[]},
63 * Stream{getName=StreamNameType{_value=ietf-yang-library}, isReplaySupport=false, augmentation=[]},
64 * Stream{getDescription=Default NETCONF stream containing all the Event Notifications., getName=StreamNameType{_value=NETCONF}, isReplaySupport=true, augmentation=[]},
65 * Stream{getName=StreamNameType{_value=vlan-fd-1-0}, isReplaySupport=true, augmentation=[]},
66 * Stream{getName=StreamNameType{_value=wire-interface-2-0}, isReplaySupport=true, augmentation=[]},
67 * Stream{getName=StreamNameType{_value=mac-fd-1-0}, isReplaySupport=true, augmentation=[]},
68 * Stream{getName=StreamNameType{_value=co-channel-profile-1-0}, isReplaySupport=true, augmentation=[]},
69 * Stream{getName=StreamNameType{_value=mac-interface-1-0}, isReplaySupport=true, augmentation=[]},
70 * Stream{getName=StreamNameType{_value=ietf-keystore}, isReplaySupport=true, augmentation=[]},
71 * Stream{getName=StreamNameType{_value=pure-ethernet-structure-2-0}, isReplaySupport=true, augmentation=[]},
72 * Stream{getName=StreamNameType{_value=ietf-netconf-notifications}, isReplaySupport=true, augmentation=[]},
73 * Stream{getName=StreamNameType{_value=mac-fc-1-0}, isReplaySupport=true, augmentation=[]},
74 * Stream{getName=StreamNameType{_value=wred-profile-1-0}, isReplaySupport=true, augmentation=[]},
75 * Stream{getName=StreamNameType{_value=air-interface-2-0}, isReplaySupport=true, augmentation=[]},
76 * Stream{getName=StreamNameType{_value=ip-interface-1-0}, isReplaySupport=true, augmentation=[]},
77 * Stream{getName=StreamNameType{_value=qos-profile-1-0}, isReplaySupport=true, augmentation=[]},
78 * Stream{getName=StreamNameType{_value=vlan-fc-1-0}, isReplaySupport=true, augmentation=[]},
79 * Stream{getName=StreamNameType{_value=l-3vpn-profile-1-0}, isReplaySupport=true, augmentation=[]}]
80 */
81
82 public class Onf14DomInterfacePacManager {
83
84     private static final Logger LOG = LoggerFactory.getLogger(Onf14DomInterfacePacManager.class);
85
86     // private static final YangInstanceIdentifier LTP_IID =
87     // YangInstanceIdentifier.builder().node(Onf14DevicemanagerQNames.CORE_MODEL_CONTROL_CONSTRUCT_CONTAINER)
88     // .node(Onf14DevicemanagerQNames.CORE_MODEL_CC_LTP).build();
89
90     private final NetconfDomAccessor netconfDomAccessor;
91     private final @NonNull DeviceManagerServiceProvider serviceProvider;
92
93     // air interface related members
94     private final List<TechnologySpecificPacKeys> airInterfaceList = new ArrayList<>();
95     @NonNull
96     private final Onf14DomAirInterfaceNotificationListener airInterfaceNotificationListener;
97
98     // ethernet container related members
99     private final List<TechnologySpecificPacKeys> ethernetContainerList = new ArrayList<>();
100     @NonNull
101     private final Onf14DomEthernetContainerNotificationListener ethernetContainerNotificationListener;
102
103     // wire interface related members
104     private final List<TechnologySpecificPacKeys> wireInterfaceList = new ArrayList<>();
105     @NonNull
106     private final Onf14DomWireInterfaceNotificationListener wireInterfaceNotificationListener;
107
108     // alarm-1-0 related alarms
109     private final Onf14DomAlarmsNotificationListener alarmNotifListener;
110
111     // Services and models
112     private final @NonNull FaultService faultService;
113     private final @NonNull CoreModel14 coreModel14;
114
115     private final Optional<Alarms10> alarms10;
116     private final Optional<AirInterface20> airInterface20;
117     private final Optional<EthernetContainer20> ethernetInterface20;
118     private final Optional<WireInterface20> wireInterface20;
119
120     private final Onf14Interfaces interfaces;
121
122     public Onf14DomInterfacePacManager(@NonNull NetconfDomAccessor netconfDomAccessor,
123             @NonNull DeviceManagerServiceProvider serviceProvider, CoreModel14 coreModel14) {
124
125         this.netconfDomAccessor = Objects.requireNonNull(netconfDomAccessor);
126         this.serviceProvider = Objects.requireNonNull(serviceProvider);
127         this.faultService = Objects.requireNonNull(serviceProvider.getFaultService());
128         this.interfaces = new Onf14Interfaces();
129
130         this.coreModel14 = coreModel14;
131         this.alarms10 = Alarms10.getModule(netconfDomAccessor, coreModel14);
132         this.airInterface20 = AirInterface20.getModule(netconfDomAccessor, coreModel14);
133         this.ethernetInterface20 = EthernetContainer20.getModule(netconfDomAccessor, coreModel14);
134         this.wireInterface20 = WireInterface20.getModule(netconfDomAccessor, coreModel14);
135
136         if (alarms10.isPresent()) {
137             this.alarmNotifListener =
138                     new Onf14DomAlarmsNotificationListener(netconfDomAccessor, serviceProvider, alarms10.get());
139         } else {
140             this.alarmNotifListener = null;
141         }
142         this.airInterfaceNotificationListener =
143                 new Onf14DomAirInterfaceNotificationListener(netconfDomAccessor, serviceProvider);
144         this.ethernetContainerNotificationListener =
145                 new Onf14DomEthernetContainerNotificationListener(netconfDomAccessor, serviceProvider);
146         this.wireInterfaceNotificationListener =
147                 new Onf14DomWireInterfaceNotificationListener(netconfDomAccessor, serviceProvider);
148     }
149
150     public void register() {
151         // storing all the LTP UUIDs internally, for later usage, for air-interface and
152         // ethernet-container and wire-interface
153         coreModel14.readKeys(interfaces);
154         readAndWriteInterfaceCurrentProblems();
155         readCurrentAlarms();
156         registerForNotifications();
157     }
158
159     public List<TechnologySpecificPacKeys> getAirInterfaceList() {
160         return airInterfaceList;
161     }
162
163     private void readCurrentAlarms() {
164         if (alarms10.isPresent()) {
165             FaultData resultList = alarms10.get().getCurrentAlarms();
166             LOG.debug("ResultList = {}", resultList.toString());
167             faultService.initCurrentProblemStatus(netconfDomAccessor.getNodeId(), resultList);
168         }
169     }
170
171     private void readAndWriteInterfaceCurrentProblems() {
172         // Read all fault data
173         FaultData resultList = new FaultData();
174         int problems = 0;
175
176         if (airInterface20.isPresent()) {
177             resultList = airInterface20.get().readAllCurrentProblems(resultList, airInterfaceList);
178
179             problems = resultList.size();
180             LOG.debug("NETCONF read airinterface current problems completed. Got back {} problems.", problems);
181         }
182         if (ethernetInterface20.isPresent()) {
183             resultList = ethernetInterface20.get().readAllCurrentProblems(resultList, ethernetContainerList);
184
185             problems = resultList.size() - problems;
186             LOG.debug("NETCONF read ethernet interface current problems completed. Got back {} problems.", problems);
187         }
188         if (wireInterface20.isPresent()) {
189             resultList = wireInterface20.get().readAllCurrentProblems(resultList, wireInterfaceList);
190
191             problems = resultList.size() - problems;
192             LOG.debug("NETCONF read wire interface current problems completed. Got back {} problems.", problems);
193         }
194
195         if (resultList.size() > 0) {
196             faultService.initCurrentProblemStatus(netconfDomAccessor.getNodeId(), resultList);
197             LOG.debug("DB write current problems completed");
198         }
199
200     }
201
202     private void readKeys() {
203         Optional<NormalizedNode> ltpData = readLtpData(netconfDomAccessor);
204         LOG.debug("LTP Data is - {}", ltpData);
205         if (ltpData.isPresent()) {
206             LOG.debug("In readKeys - ltpData = {}", ltpData.get());
207
208             MapNode ccLtp = (MapNode) ltpData.get();
209             if (ccLtp != null) {
210                 LOG.debug("Iterating the LTP list for node {}", netconfDomAccessor.getNodeId().getValue());
211                 Collection<MapEntryNode> ltpList = ccLtp.body();
212
213                 // iterating all the Logical Termination Point list
214                 for (MapEntryNode ltp : ltpList) {
215                     MapNode lpList =
216                             (MapNode) ltp.childByArg(new NodeIdentifier(coreModel14.getQName("layer-protocol")));
217                     // the Layer Protocol list should contain only one item, since we have an 1:1
218                     // relationship between the LTP and the LP
219                     if (lpList != null && lpList.size() != 1) {
220                         LOG.debug("Layer protocol has no 1:1 relationship with the LTP.");
221                         return;
222                     }
223                     // accessing the LP, which should be only 1
224                     Collection<MapEntryNode> lp = lpList.body();
225                     for (MapEntryNode lpEntry : lp) {
226                         String layerProtocolName = Onf14DMDOMUtility.getLeafValue(lpEntry,
227
228                                 coreModel14.getQName("layer-protocol-name"));
229                         if (layerProtocolName != null) {
230                             // if the LTP has an airInterface technology extension, the layer protocol name
231                             // is air-layer
232                             if (layerProtocolName.contains("LAYER_PROTOCOL_NAME_TYPE_AIR_LAYER")) {
233                                 TechnologySpecificPacKeys airInterfaceKey = new TechnologySpecificPacKeys(
234                                         Onf14DMDOMUtility.getLeafValue(ltp, coreModel14.getQName("uuid")),
235                                         Onf14DMDOMUtility.getLeafValue(lpEntry, coreModel14.getQName("local-id")));
236                                 airInterfaceList.add(airInterfaceKey);
237                                 LOG.debug("Adding Ltp with uuid {} and local-id {} to the air-interface list",
238                                         Onf14DMDOMUtility.getLeafValue(ltp, coreModel14.getQName("uuid")),
239                                         Onf14DMDOMUtility.getLeafValue(lpEntry, coreModel14.getQName("local-id")));
240                             }
241                             // if the LTP has an ethernetContainier technology extension, the layer protocol
242                             // name is ethernet-container-layer
243                             else if (layerProtocolName.contains("LAYER_PROTOCOL_NAME_TYPE_ETHERNET_CONTAINER_LAYER")) {
244                                 TechnologySpecificPacKeys ethernetContainerKey = new TechnologySpecificPacKeys(
245                                         Onf14DMDOMUtility.getLeafValue(ltp, coreModel14.getQName("uuid")),
246                                         Onf14DMDOMUtility.getLeafValue(lpEntry, coreModel14.getQName("local-id")));
247                                 ethernetContainerList.add(ethernetContainerKey);
248                                 LOG.debug("Adding Ltp with uuid {} and local-id {} to the ethernet-container list",
249                                         Onf14DMDOMUtility.getLeafValue(ltp, coreModel14.getQName("uuid")),
250                                         Onf14DMDOMUtility.getLeafValue(lpEntry, coreModel14.getQName("local-id")));
251                             } else if (layerProtocolName.contains("LAYER_PROTOCOL_NAME_TYPE_WIRE_LAYER")) {
252                                 TechnologySpecificPacKeys wireInterfaceKey = new TechnologySpecificPacKeys(
253                                         Onf14DMDOMUtility.getLeafValue(ltp, coreModel14.getQName("uuid")),
254                                         Onf14DMDOMUtility.getLeafValue(lpEntry, coreModel14.getQName("local-id")));
255                                 wireInterfaceList.add(wireInterfaceKey);
256                                 LOG.debug("Adding Ltp with uuid {} and local-id {} to the wire-interface list",
257                                         Onf14DMDOMUtility.getLeafValue(ltp, coreModel14.getQName("uuid")),
258                                         Onf14DMDOMUtility.getLeafValue(lpEntry, coreModel14.getQName("local-id")));
259                             }
260                         }
261                     }
262                 }
263             }
264         }
265     }
266
267     private void registerForNotifications() {
268
269         if (alarms10.isPresent()) {
270             alarms10.get().doRegisterNotificationListener(alarmNotifListener);
271         }
272
273         QName[] airInterfaceNotifications = {Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_CREATE_NOTIFICATION,
274                 Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_AVC_NOTIFICATION,
275                 Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_DELETE_NOTIFICATION,
276                 Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_PROBLEM_NOTIFICATION};
277         netconfDomAccessor.doRegisterNotificationListener(airInterfaceNotificationListener, airInterfaceNotifications);
278
279         QName[] ethernetContainerNotifications =
280                 {Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_CREATE_NOTIFICATION,
281                         Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_AVC_NOTIFICATION,
282                         Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_DELETE_NOTIFICATION,
283                         Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_PROBLEM_NOTIFICATION};
284         netconfDomAccessor.doRegisterNotificationListener(ethernetContainerNotificationListener,
285                 ethernetContainerNotifications);
286
287         QName[] wireInterfaceNotifications = {Onf14DevicemanagerQNames.WIRE_INTERFACE_OBJECT_CREATE_NOTIFICATION,
288                 Onf14DevicemanagerQNames.WIRE_INTERFACE_OBJECT_AVC_NOTIFICATION,
289                 Onf14DevicemanagerQNames.WIRE_INTERFACE_OBJECT_DELETE_NOTIFICATION,
290                 Onf14DevicemanagerQNames.WIRE_INTERFACE_OBJECT_PROBLEM_NOTIFICATION};
291         netconfDomAccessor.doRegisterNotificationListener(wireInterfaceNotificationListener,
292                 wireInterfaceNotifications);
293     }
294
295     public Optional<NormalizedNode> readLtpData(NetconfDomAccessor netconfDomAccessor) {
296         LOG.info("Reading Logical Termination Point data");
297         return netconfDomAccessor.readDataNode(LogicalDatastoreType.CONFIGURATION, getLtp_IID());
298     }
299
300     public PerformanceDataLtp getLtpHistoricalPerformanceData(@NonNull TechnologySpecificPacKeys lp) {
301         PerformanceDataLtp res = new PerformanceDataLtp();
302         if (airInterface20.isPresent()) {
303             airInterface20.get().readAirInterfaceHistoricalPerformanceData(lp.getLtpUuid(), lp.getLocalId(), res);
304         } else {
305             LOG.warn("Air Interface Module Unsupported. PM data not read");
306         }
307         return res;
308     }
309
310     private YangInstanceIdentifier getLtp_IID() {
311         return YangInstanceIdentifier.builder().node(coreModel14.getQName("control-construct"))
312                 .node(coreModel14.getQName("logical-termination-point")).build();
313     }
314 }