Merge "Optimize cm-handle registration with CPS-DMI Plugin to upload yang model"
[ccsdk/features.git] / sdnr / wt / devicemanager-onap / onf14 / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / onf14 / impl / Onf14NetworkElement.java
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.devicemanager.onf14.impl;
19
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.List;
23 import java.util.Optional;
24 import org.eclipse.jdt.annotation.NonNull;
25 import org.eclipse.jdt.annotation.Nullable;
26 import org.onap.ccsdk.features.sdnr.wt.common.YangHelper;
27 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElementService;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.dataprovider.Onf14ToInternalDataModel;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.interfaces.Onf14AirInterface;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.interfaces.Onf14AirInterfaceNotificationListener;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.interfaces.Onf14EthernetContainer;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.interfaces.Onf14EthernetContainerNotificationListener;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.interfaces.Onf14WireInterface;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.interfaces.Onf14WireInterfaceNotificationListener;
37 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
38 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
39 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
40 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
41 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
42 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
43 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
44 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.LAYERPROTOCOLNAMETYPEAIRLAYER;
45 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.air._interface.lp.spec.AirInterfacePac;
46 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.air._interface.pac.AirInterfaceCurrentProblems;
47 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.ControlConstruct;
48 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.LAYERPROTOCOLNAMETYPE;
49 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.UniversalId;
50 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.control.construct.Equipment;
51 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.control.construct.EquipmentKey;
52 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.control.construct.LogicalTerminationPoint;
53 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.control.construct.LogicalTerminationPointKey;
54 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.equipment.ContainedHolder;
55 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.logical.termination.point.LayerProtocol;
56 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.logical.termination.point.LayerProtocolKey;
57 import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.LAYERPROTOCOLNAMETYPEETHERNETCONTAINERLAYER;
58 import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.ethernet.container.lp.spec.EthernetContainerPac;
59 import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.ethernet.container.pac.EthernetContainerCurrentProblems;
60 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.LAYERPROTOCOLNAMETYPEWIRELAYER;
61 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.wire._interface.lp.spec.WireInterfacePac;
62 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.wire._interface.pac.WireInterfaceCurrentProblems;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementConnectionBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType;
67 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
68 import org.opendaylight.yangtools.concepts.ListenerRegistration;
69 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
70 import org.opendaylight.yangtools.yang.binding.NotificationListener;
71 import org.opendaylight.yangtools.yang.common.QName;
72 import org.slf4j.Logger;
73 import org.slf4j.LoggerFactory;
74
75 /**
76  * Repesentation of ONF Core model 1.4 device Top level element is "ControlConstruct" (replaces "NetworkElement" of
77  * older ONF Version)
78  */
79 public class Onf14NetworkElement implements NetworkElement {
80
81     private static final Logger log = LoggerFactory.getLogger(Onf14NetworkElement.class);
82
83     protected static final InstanceIdentifier<ControlConstruct> CONTROLCONSTRUCT_IID =
84             InstanceIdentifier.builder(ControlConstruct.class).build();
85
86     private static final int EQUIPMENTROOTLEVEL = 0;
87
88     private final NetconfBindingAccessor netconfAccessor;
89     private final DataProvider databaseService;
90     private final Onf14ToInternalDataModel onf14Mapper;
91     @NonNull
92     private final FaultService faultService;
93
94     // for storing the Equipment UUIDs that are inserted in the DB
95     private final List<String> equipmentUuidList = new ArrayList<>();
96
97     // air interface related members
98     private final List<TechnologySpecificPacKeys> airInterfaceList = new ArrayList<>();
99     @SuppressWarnings("unused")
100     private ListenerRegistration<NotificationListener> airInterfaceNotificationListenerHandler;
101     @NonNull
102     private final Onf14AirInterfaceNotificationListener airInterfaceNotificationListener;
103
104     // ethernet container related members
105     private final List<TechnologySpecificPacKeys> ethernetContainerList = new ArrayList<>();
106     @SuppressWarnings("unused")
107     private ListenerRegistration<NotificationListener> etherneContainerNotificationListenerHandler;
108     @NonNull
109     private final Onf14EthernetContainerNotificationListener ethernetContainerNotificationListener;
110
111     // wire interface related members
112     private final List<TechnologySpecificPacKeys> wireInterfaceList = new ArrayList<>();
113     @SuppressWarnings("unused")
114     private ListenerRegistration<NotificationListener> wireInterfaceNotificationListenerHandler;
115     @NonNull
116     private final Onf14WireInterfaceNotificationListener wireInterfaceNotificationListener;
117
118     Onf14NetworkElement(NetconfBindingAccessor netconfAccess, DeviceManagerServiceProvider serviceProvider) {
119         log.info("Create {}", Onf14NetworkElement.class.getSimpleName());
120         this.netconfAccessor = netconfAccess;
121         this.databaseService = serviceProvider.getDataProvider();
122         this.faultService = serviceProvider.getFaultService();
123         this.onf14Mapper = new Onf14ToInternalDataModel();
124         this.airInterfaceNotificationListenerHandler = null;
125         this.airInterfaceNotificationListener =
126                 new Onf14AirInterfaceNotificationListener(netconfAccess, serviceProvider);
127         this.etherneContainerNotificationListenerHandler = null;
128         ethernetContainerNotificationListener =
129                 new Onf14EthernetContainerNotificationListener(netconfAccess, serviceProvider);
130         this.wireInterfaceNotificationListenerHandler = null;
131         wireInterfaceNotificationListener = new Onf14WireInterfaceNotificationListener(netconfAccess, serviceProvider);
132     }
133
134     public void initialReadFromNetworkElement() {
135
136         // reading the inventory (CoreModel 1.4 Equipment Model) and adding it to the DB
137         readEquipmentData();
138
139         var resultList = new FaultData();
140
141         int problems = faultService.removeAllCurrentProblemsOfNode(netconfAccessor.getNodeId());
142         log.debug("Removed all {} problems from database at registration", problems);
143
144         readAllAirInterfaceCurrentProblems(resultList);
145         problems = resultList.size();
146         log.debug("NETCONF read air interface current problems completed. Got back {} problems.", problems);
147
148         readAllEhernetContainerCurrentProblems(resultList);
149         problems = resultList.size() - problems;
150         log.debug("NETCONF read current problems completed. Got back {} problems.", resultList.size());
151
152         readAllWireInterfaceCurrentProblems(resultList);
153         problems = resultList.size();
154         log.debug("NETCONF read wire interface current problems completed. Got back {} problems.", problems);
155
156         faultService.initCurrentProblemStatus(netconfAccessor.getNodeId(), resultList);
157         log.debug("DB write current problems completed");
158
159     }
160
161     public void readAllAirInterfaceCurrentProblems(FaultData resultList) {
162
163         int idxStart; // Start index for debug messages
164
165         for (TechnologySpecificPacKeys key : airInterfaceList) {
166             idxStart = resultList.size();
167
168             readAirInterfaceCurrentProblemForLtp(key.getLtpUuid(), key.getLocalId(), resultList);
169             debugResultList(key.getLtpUuid().getValue(), resultList, idxStart);
170         }
171     }
172
173     public void readAllEhernetContainerCurrentProblems(FaultData resultList) {
174
175         int idxStart; // Start index for debug messages
176
177         for (TechnologySpecificPacKeys key : ethernetContainerList) {
178             idxStart = resultList.size();
179
180             readEthernetConainerCurrentProblemForLtp(key.getLtpUuid(), key.getLocalId(), resultList);
181             debugResultList(key.getLtpUuid().getValue(), resultList, idxStart);
182         }
183     }
184
185     public void readAllWireInterfaceCurrentProblems(FaultData resultList) {
186
187         int idxStart; // Start index for debug messages
188
189         for (TechnologySpecificPacKeys key : wireInterfaceList) {
190             idxStart = resultList.size();
191
192             readWireInterfaceCurrentProblemForLtp(key.getLtpUuid(), key.getLocalId(), resultList);
193             debugResultList(key.getLtpUuid().getValue(), resultList, idxStart);
194         }
195     }
196
197     /**
198      * @param nNode set core-model-capability
199      */
200     public void setCoreModel(@NonNull NetconfNode nNode) {
201         NetworkElementConnectionBuilder eb = new NetworkElementConnectionBuilder();
202         log.info("In setCoreModel for Onf14NetworkElement");
203         String namespaceRevision;
204         QName QNAME_COREMODEL14 = QName.create("urn:onf:yang:core-model-1-4", "2019-11-27", "core-model-1-4").intern();
205
206         Capabilities availableCapabilities = Capabilities.getAvailableCapabilities(nNode);
207         namespaceRevision = availableCapabilities.getRevisionForNamespace(QNAME_COREMODEL14);
208         log.info("In setCoreModel for Onf14NetworkElement- namespaceRevision = " + namespaceRevision);
209         if (Capabilities.isNamespaceSupported(namespaceRevision)) {
210             eb.setCoreModelCapability(namespaceRevision);
211         } else {
212             eb.setCoreModelCapability("Unsupported");
213         }
214         databaseService.updateNetworkConnection22(eb.build(), netconfAccessor.getNodeId().getValue());
215     }
216
217     @Override
218     public void register() {
219         // Set core-model revision value in "core-model-capability" field
220         setCoreModel(netconfAccessor.getNetconfNode());
221         initialReadFromNetworkElement();
222
223         // Register netconf stream
224         airInterfaceNotificationListenerHandler =
225                 netconfAccessor.doRegisterNotificationListener(airInterfaceNotificationListener);
226         etherneContainerNotificationListenerHandler =
227                 netconfAccessor.doRegisterNotificationListener(ethernetContainerNotificationListener);
228         wireInterfaceNotificationListenerHandler =
229                 netconfAccessor.doRegisterNotificationListener(wireInterfaceNotificationListener);
230         // Register to default (NETCONF) stream
231         netconfAccessor.registerNotificationsStream();
232     }
233
234     @Override
235     public void deregister() {}
236
237
238     @Override
239     public NodeId getNodeId() {
240         return netconfAccessor.getNodeId();
241     }
242
243     @Override
244     public <L extends NetworkElementService> Optional<L> getService(Class<L> clazz) {
245         return Optional.empty();
246     }
247
248     @Override
249     public void warmstart() {}
250
251     @Override
252     public Optional<NetconfAccessor> getAcessor() {
253         return Optional.of(netconfAccessor);
254     }
255
256     @Override
257     public NetworkElementDeviceType getDeviceType() {
258         return NetworkElementDeviceType.Wireless;
259     }
260
261     private void readEquipmentData() {
262
263         Optional<ControlConstruct> controlConstruct = readControlConstruct(netconfAccessor);
264
265         if (controlConstruct.isPresent()) {
266             // the top-level-equipment list contains the root objects of the Equipment Model
267             log.debug("Getting list of topLevelEquipment for mountpoint {}", netconfAccessor.getNodeId());
268             @Nullable
269             List<UniversalId> topLevelEquipment = controlConstruct.get().getTopLevelEquipment();
270
271             if (topLevelEquipment != null) {
272                 List<Inventory> inventoryList = new ArrayList<>();
273                 for (UniversalId uuid : topLevelEquipment) {
274                     log.debug("Got back topLevelEquipment with uuid {}", uuid.getValue());
275
276                     // adding all root Equipment objects to the DB
277                     @Nullable
278                     Equipment equipmentInstance = readEquipmentInstance(netconfAccessor, uuid);
279                     if (equipmentInstance != null) {
280                         // recursively adding the root equipment and all its children into the DB
281                         collectEquipment(inventoryList, equipmentInstance, null, EQUIPMENTROOTLEVEL);
282                     }
283                 }
284                 this.databaseService.writeInventory(this.netconfAccessor.getNodeId().getValue(), inventoryList);
285             }
286         }
287
288         // storing all the LTP UUIDs internally, for later usage, for air-interface and ethernet-container
289         readKeys(controlConstruct);
290     }
291
292     private List<Inventory> collectEquipment(List<Inventory> list, Equipment currentEq, Equipment parentEq,
293             long treeLevel) {
294
295         // if the Equipment UUID is already in the list, it was already processed
296         // needed for solving possible circular dependencies
297         if (equipmentUuidList.contains(currentEq.getUuid().getValue())) {
298             log.debug("Not adding equipment with uuid {} because it was aleady added...",
299                     currentEq.getUuid().getValue());
300             return list;
301         }
302
303         // we add this to our internal list, such that we avoid circular dependencies
304         equipmentUuidList.add(currentEq.getUuid().getValue());
305         log.debug("Adding equipment with uuid {} to the database...", currentEq.getUuid().getValue());
306
307         // we add our current equipment to the database
308         list.add(onf14Mapper.getInternalEquipment(netconfAccessor.getNodeId(), currentEq, parentEq, treeLevel));
309
310         // we iterate the kids of our current equipment and add them to the database recursively
311         // the actual reference is here: /core-model:control-construct/equipment/contained-holder/occupying-fru
312         @NonNull
313         Collection<ContainedHolder> holderList = YangHelper.getCollection(currentEq.nonnullContainedHolder());
314
315         for (ContainedHolder holder : holderList) {
316             @Nullable
317             UniversalId occupyingFru = holder.getOccupyingFru();
318             if (occupyingFru != null) {
319                 @Nullable
320                 Equipment childEq = readEquipmentInstance(netconfAccessor, occupyingFru);
321
322                 if (childEq != null) {
323                     // current becomes parent and tree level increases by 1
324                     collectEquipment(list, childEq, currentEq, treeLevel + 1);
325                 }
326             }
327         }
328         return list;
329     }
330
331     private void readKeys(Optional<ControlConstruct> controlConstruct) {
332
333         if (controlConstruct.isPresent()) {
334             @NonNull
335             Collection<LogicalTerminationPoint> ltpList =
336                     YangHelper.getCollection(controlConstruct.get().nonnullLogicalTerminationPoint());
337             log.debug("Iterating the LTP list for node {}", netconfAccessor.getNodeId().getValue());
338
339             // iterating all the Logical Termination Point list
340             for (LogicalTerminationPoint ltp : ltpList) {
341                 @NonNull
342                 List<LayerProtocol> lpList = YangHelper.getList(ltp.nonnullLayerProtocol());
343                 // the Layer Protocol list should contain only one item, since we have an 1:1 relationship between the LTP and the LP
344                 if (lpList.size() != 1) {
345                     log.debug("Layer protocol has no 1:1 relationship with the LTP.");
346                     return;
347                 }
348                 // accessing the LP, which should be only 1
349                 LayerProtocol lp = lpList.get(0);
350                 @Nullable
351                 Class<? extends LAYERPROTOCOLNAMETYPE> layerProtocolName = lp.getLayerProtocolName();
352                 if (layerProtocolName != null) {
353                     // if the LTP has an airInterface technology extension, the layer protocol name is air-layer
354                     if (layerProtocolName.getTypeName().equals(LAYERPROTOCOLNAMETYPEAIRLAYER.class.getName())) {
355                         TechnologySpecificPacKeys airInterfaceKey =
356                                 new TechnologySpecificPacKeys(ltp.getUuid(), lp.getLocalId());
357                         airInterfaceList.add(airInterfaceKey);
358                         log.debug("Adding Ltp with uuid {} and local-id {} to the air-interface list",
359                                 ltp.getUuid().getValue(), lp.getLocalId());
360                     }
361                     // if the LTP has an ethernetContainier technology extension, the layer protocol name is ethernet-container-layer
362                     else if (layerProtocolName.getTypeName().equals(LAYERPROTOCOLNAMETYPEETHERNETCONTAINERLAYER.class
363                             .getName())) {
364                         TechnologySpecificPacKeys ethernetContainerKey =
365                                 new TechnologySpecificPacKeys(ltp.getUuid(), lp.getLocalId());
366                         ethernetContainerList.add(ethernetContainerKey);
367                         log.debug("Adding Ltp with uuid {} and local-id {} to the ethernet-contatinier list",
368                                 ltp.getUuid().getValue(), lp.getLocalId());
369                     } else if (layerProtocolName.getTypeName().equals(LAYERPROTOCOLNAMETYPEWIRELAYER.class.getName())) {
370                         TechnologySpecificPacKeys wireInterfaceKey =
371                                 new TechnologySpecificPacKeys(ltp.getUuid(), lp.getLocalId());
372                         wireInterfaceList.add(wireInterfaceKey);
373                         log.debug("Adding Ltp with uuid {} and local-id {} to the wire-interface list",
374                                 ltp.getUuid().getValue(), lp.getLocalId());
375                     }
376                 }
377             }
378         }
379     }
380
381     private void readAirInterfaceCurrentProblemForLtp(UniversalId ltpUuid, String localId, FaultData resultList) {
382
383         final Class<AirInterfacePac> clazzPac = AirInterfacePac.class;
384
385         log.info("DBRead Get current problems for class {} from mountpoint {} for LTP uuid {} and local-id {}",
386                 clazzPac.getSimpleName(), netconfAccessor.getNodeId().getValue(), ltpUuid.getValue(), localId);
387
388         // constructing the IID needs the augmentation exposed byy the air-interface-2-0 model
389         InstanceIdentifier<AirInterfaceCurrentProblems> airInterfaceCurrentProblem_IID = InstanceIdentifier
390                 .builder(ControlConstruct.class)
391                 .child(LogicalTerminationPoint.class, new LogicalTerminationPointKey(ltpUuid))
392                 .child(LayerProtocol.class, new LayerProtocolKey(localId))
393                 .augmentation(
394                         org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.LayerProtocol1.class)
395                 .child(AirInterfacePac.class).child(AirInterfaceCurrentProblems.class).build();
396
397         // reading all the current-problems list for this specific LTP and LP
398         AirInterfaceCurrentProblems problems = netconfAccessor.getTransactionUtils().readData(
399                 netconfAccessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL, airInterfaceCurrentProblem_IID);
400
401         if (problems == null) {
402             log.debug("DBRead Id {} no AirInterfaceCurrentProblems", ltpUuid);
403         } else if (problems.getCurrentProblemList() == null) {
404             log.debug("DBRead Id {} empty CurrentProblemList", ltpUuid);
405         } else {
406             for (org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.air._interface.current.problems.CurrentProblemList problem : YangHelper
407                     .getCollection(problems.nonnullCurrentProblemList())) {
408                 resultList.add(netconfAccessor.getNodeId(), (int) problem.getSequenceNumber(), problem.getTimestamp(),
409                         ltpUuid.getValue(), problem.getProblemName(),
410                         Onf14AirInterface.mapSeverity(problem.getProblemSeverity()));
411             }
412         }
413     }
414
415     private void readEthernetConainerCurrentProblemForLtp(UniversalId ltpUuid, String localId, FaultData resultList) {
416
417         final Class<EthernetContainerPac> clazzPac = EthernetContainerPac.class;
418
419         log.info("DBRead Get current problems for class {} from mountpoint {} for LTP uuid {} and local-id {}",
420                 clazzPac.getSimpleName(), netconfAccessor.getNodeId().getValue(), ltpUuid.getValue(), localId);
421
422         // constructing the IID needs the augmentation exposed by the ethernet-container-2-0 model
423         InstanceIdentifier<EthernetContainerCurrentProblems> etherneContainerCurrentProblem_IID = InstanceIdentifier
424                 .builder(ControlConstruct.class)
425                 .child(LogicalTerminationPoint.class, new LogicalTerminationPointKey(ltpUuid))
426                 .child(LayerProtocol.class, new LayerProtocolKey(localId))
427                 .augmentation(
428                         org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.LayerProtocol1.class)
429                 .child(EthernetContainerPac.class).child(EthernetContainerCurrentProblems.class).build();
430
431         // reading all the current-problems list for this specific LTP and LP
432         EthernetContainerCurrentProblems problems = netconfAccessor.getTransactionUtils().readData(
433                 netconfAccessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL, etherneContainerCurrentProblem_IID);
434
435         if (problems == null) {
436             log.debug("DBRead Id {} no EthernetContainerCurrentProblems", ltpUuid);
437         } else if (problems.getCurrentProblemList() == null) {
438             log.debug("DBRead Id {} empty CurrentProblemList", ltpUuid);
439         } else {
440             for (org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.ethernet.container.current.problems.CurrentProblemList problem : YangHelper
441                     .getCollection(problems.nonnullCurrentProblemList())) {
442                 resultList.add(netconfAccessor.getNodeId(), (int) problem.getSequenceNumber(), problem.getTimestamp(),
443                         ltpUuid.getValue(), problem.getProblemName(),
444                         Onf14EthernetContainer.mapSeverity(problem.getProblemSeverity()));
445             }
446         }
447     }
448
449     private void readWireInterfaceCurrentProblemForLtp(UniversalId ltpUuid, String localId, FaultData resultList) {
450
451         final Class<WireInterfacePac> clazzPac = WireInterfacePac.class;
452
453         log.info("DBRead Get current problems for class {} from mountpoint {} for LTP uuid {} and local-id {}",
454                 clazzPac.getSimpleName(), netconfAccessor.getNodeId().getValue(), ltpUuid.getValue(), localId);
455
456         // constructing the IID needs the augmentation exposed by the wire-interface-2-0 model
457         InstanceIdentifier<WireInterfaceCurrentProblems> wireInterfaceCurrentProblem_IID = InstanceIdentifier
458                 .builder(ControlConstruct.class)
459                 .child(LogicalTerminationPoint.class, new LogicalTerminationPointKey(ltpUuid))
460                 .child(LayerProtocol.class, new LayerProtocolKey(localId))
461                 .augmentation(
462                         org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.LayerProtocol1.class)
463                 .child(WireInterfacePac.class).child(WireInterfaceCurrentProblems.class).build();
464
465         // reading all the current-problems list for this specific LTP and LP
466         WireInterfaceCurrentProblems problems = netconfAccessor.getTransactionUtils().readData(
467                 netconfAccessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL, wireInterfaceCurrentProblem_IID);
468
469         if (problems == null) {
470             log.debug("DBRead Id {} no WireInterfaceCurrentProblems", ltpUuid);
471         } else if (problems.getCurrentProblemList() == null) {
472             log.debug("DBRead Id {} empty CurrentProblemList", ltpUuid);
473         } else {
474             for (org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.wire._interface.current.problems.CurrentProblemList problem : YangHelper
475                     .getCollection(problems.nonnullCurrentProblemList())) {
476                 resultList.add(netconfAccessor.getNodeId(), (int) problem.getSequenceNumber(), problem.getTimestamp(),
477                         ltpUuid.getValue(), problem.getProblemName(),
478                         Onf14WireInterface.mapSeverity(problem.getProblemSeverity()));
479             }
480         }
481     }
482
483     private Optional<ControlConstruct> readControlConstruct(NetconfBindingAccessor netconfAccessor) {
484         return Optional.ofNullable(netconfAccessor.getTransactionUtils().readData(netconfAccessor.getDataBroker(),
485                 LogicalDatastoreType.CONFIGURATION, CONTROLCONSTRUCT_IID));
486     }
487
488     private @Nullable Equipment readEquipmentInstance(NetconfBindingAccessor accessData, UniversalId equipmentUuid) {
489
490         final Class<?> clazzPac = Equipment.class;
491
492         log.info("DBRead Get equipment for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
493                 accessData.getNodeId().getValue(), equipmentUuid.getValue());
494
495         InstanceIdentifier<Equipment> equipmentIID = InstanceIdentifier.builder(ControlConstruct.class)
496                 .child(Equipment.class, new EquipmentKey(equipmentUuid)).build();
497
498         return accessData.getTransactionUtils().readData(accessData.getDataBroker(), LogicalDatastoreType.CONFIGURATION,
499                 equipmentIID);
500     }
501
502     // defining a structure that can map the LP local-id and its corresponding LTP uuid
503     private class TechnologySpecificPacKeys {
504
505         private UniversalId ltpUuid;
506         private String localId;
507
508         public TechnologySpecificPacKeys(UniversalId uuid, String lId) {
509             this.ltpUuid = uuid;
510             this.localId = lId;
511         }
512
513         public UniversalId getLtpUuid() {
514             return ltpUuid;
515         }
516
517         public String getLocalId() {
518             return localId;
519         }
520
521         @SuppressWarnings("unused")
522         public void setLtpUuid(UniversalId uuid) {
523             this.ltpUuid = uuid;
524         }
525
526         @SuppressWarnings("unused")
527         public void setLocalId(String lId) {
528             this.localId = lId;
529         }
530     }
531
532
533     /**
534      * LOG the newly added problems of the interface pac
535      *
536      * @param idxStart
537      * @param uuid
538      * @param resultList
539      */
540     private void debugResultList(String uuid, FaultData resultList, int idxStart) {
541         StringBuilder sb = new StringBuilder();
542         int idx = 0;
543         for (int t = idxStart; t < resultList.size(); t++) {
544             sb.append(idx++);
545             sb.append(":{");
546             sb.append(resultList.get(t));
547             sb.append('}');
548         }
549         log.debug("Found problems {} {}", uuid, sb);
550     }
551
552 }