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