aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/devicemanager-onf14/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/onf14/impl/Onf14NetworkElement.java
blob: d2db231bc40a49b761eb2ccbf8fdde13ed30d3a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
/*
 * ============LICENSE_START========================================================================
 * ONAP : ccsdk feature sdnr wt
 * =================================================================================================
 * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. All rights reserved.
 * =================================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 * ============LICENSE_END==========================================================================
 */
package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.onap.ccsdk.features.sdnr.wt.common.YangHelper;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElementService;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.LAYERPROTOCOLNAMETYPEAIRLAYER;
import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.air._interface.lp.spec.AirInterfacePac;
import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.air._interface.pac.AirInterfaceCurrentProblems;
import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.ControlConstruct;
import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.LAYERPROTOCOLNAMETYPE;
import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.UniversalId;
import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.control.construct.Equipment;
import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.control.construct.EquipmentKey;
import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.control.construct.LogicalTerminationPoint;
import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.control.construct.LogicalTerminationPointKey;
import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.equipment.ContainedHolder;
import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.logical.termination.point.LayerProtocol;
import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.logical.termination.point.LayerProtocolKey;
import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.LAYERPROTOCOLNAMETYPEETHERNETCONTAINERLAYER;
import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.ethernet.container.lp.spec.EthernetContainerPac;
import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.ethernet.container.pac.EthernetContainerCurrentProblems;
import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.LAYERPROTOCOLNAMETYPEWIRELAYER;
import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.wire._interface.lp.spec.WireInterfacePac;
import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.wire._interface.pac.WireInterfaceCurrentProblems;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementConnectionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.NotificationListener;
import org.opendaylight.yangtools.yang.common.QName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Repesentation of ONF Core model 1.4 device Top level element is "ControlConstruct" (replaces "NetworkElement" of
 * older ONF Version)
 */
public class Onf14NetworkElement implements NetworkElement {

    private static final Logger log = LoggerFactory.getLogger(Onf14NetworkElement.class);

    protected static final InstanceIdentifier<ControlConstruct> CONTROLCONSTRUCT_IID =
            InstanceIdentifier.builder(ControlConstruct.class).build();

    private static final int EQUIPMENTROOTLEVEL = 0;

    private final NetconfAccessor netconfAccessor;
    private final DataProvider databaseService;
    private final Onf14ToInternalDataModel onf14Mapper;
    private final @NonNull FaultService faultService;

    // for storing the Equipment UUIDs that are inserted in the DB
    private final List<String> equipmentUuidList = new ArrayList<String>();

    // air interface related members
    private final List<TechnologySpecificPacKeys> airInterfaceList = new ArrayList<TechnologySpecificPacKeys>();
    private ListenerRegistration<NotificationListener> airInterfaceNotificationListenerHandler;
    private @NonNull final Onf14AirInterfaceNotificationListener airInterfaceNotificationListener;

    // ethernet container related members
    private final List<TechnologySpecificPacKeys> ethernetContainerList = new ArrayList<TechnologySpecificPacKeys>();
    private ListenerRegistration<NotificationListener> etherneContainerNotificationListenerHandler;
    private @NonNull final Onf14EthernetContainerNotificationListener ethernetContainerNotificationListener;

    // wire interface related members
    private final List<TechnologySpecificPacKeys> wireInterfaceList = new ArrayList<TechnologySpecificPacKeys>();
    private ListenerRegistration<NotificationListener> wireInterfaceNotificationListenerHandler;
    private @NonNull final Onf14WireInterfaceNotificationListener wireInterfaceNotificationListener;

    Onf14NetworkElement(NetconfAccessor netconfAccess, DeviceManagerServiceProvider serviceProvider) {
        log.info("Create {}", Onf14NetworkElement.class.getSimpleName());
        this.netconfAccessor = netconfAccess;
        this.databaseService = serviceProvider.getDataProvider();
        this.faultService = serviceProvider.getFaultService();
        this.onf14Mapper = new Onf14ToInternalDataModel();
        this.airInterfaceNotificationListenerHandler = null;
        airInterfaceNotificationListener = new Onf14AirInterfaceNotificationListener(netconfAccess, serviceProvider);
        this.etherneContainerNotificationListenerHandler = null;
        ethernetContainerNotificationListener =
                new Onf14EthernetContainerNotificationListener(netconfAccess, serviceProvider);
        this.wireInterfaceNotificationListenerHandler = null;
        wireInterfaceNotificationListener = new Onf14WireInterfaceNotificationListener(netconfAccess, serviceProvider);
    }

    public void initialReadFromNetworkElement() {

        // reading the inventory (CoreModel 1.4 Equipment Model) and adding it to the DB
        readEquipmentData();

        FaultData resultList = new FaultData();

        int problems = faultService.removeAllCurrentProblemsOfNode(netconfAccessor.getNodeId());
        log.debug("Removed all {} problems from database at registration", problems);

        readAllAirInterfaceCurrentProblems(resultList);
        problems = resultList.size();
        log.debug("NETCONF read air interface current problems completed. Got back {} problems.", problems);

        readAllEhernetContainerCurrentProblems(resultList);
        problems = resultList.size() - problems;
        log.debug("NETCONF read current problems completed. Got back {} problems.", resultList.size());

        readAllWireInterfaceCurrentProblems(resultList);
        problems = resultList.size();
        log.debug("NETCONF read wire interface current problems completed. Got back {} problems.", problems);

        faultService.initCurrentProblemStatus(netconfAccessor.getNodeId(), resultList);
        log.debug("DB write current problems completed");

    }

    public void readAllAirInterfaceCurrentProblems(FaultData resultList) {

        int idxStart; // Start index for debug messages

        for (TechnologySpecificPacKeys key : airInterfaceList) {
            idxStart = resultList.size();

            readAirInterfaceCurrentProblemForLtp(key.getLtpUuid(), key.getLocalId(), resultList);
            debugResultList(key.getLtpUuid().getValue(), resultList, idxStart);
        }
    }

    public void readAllEhernetContainerCurrentProblems(FaultData resultList) {

        int idxStart; // Start index for debug messages

        for (TechnologySpecificPacKeys key : ethernetContainerList) {
            idxStart = resultList.size();

            readEthernetConainerCurrentProblemForLtp(key.getLtpUuid(), key.getLocalId(), resultList);
            debugResultList(key.getLtpUuid().getValue(), resultList, idxStart);
        }
    }

    public void readAllWireInterfaceCurrentProblems(FaultData resultList) {

        int idxStart; // Start index for debug messages

        for (TechnologySpecificPacKeys key : wireInterfaceList) {
            idxStart = resultList.size();

            readWireInterfaceCurrentProblemForLtp(key.getLtpUuid(), key.getLocalId(), resultList);
            debugResultList(key.getLtpUuid().getValue(), resultList, idxStart);
        }
    }

    /**
     * @param nNode
     * set core-model-capability
     */
    public void setCoreModel(@NonNull NetconfNode nNode) {
        NetworkElementConnectionBuilder eb = new NetworkElementConnectionBuilder();
        log.info("In setCoreModel for Onf14NetworkElement");
        String namespaceRevision;
        QName QNAME_COREMODEL14 = QName.create("urn:onf:yang:core-model-1-4", "2019-11-27", "core-model-1-4").intern();

        Capabilities availableCapabilities = Capabilities.getAvailableCapabilities(nNode);
        namespaceRevision = availableCapabilities.getRevisionForNamespace(QNAME_COREMODEL14);
        log.info("In setCoreModel for Onf14NetworkElement- namespaceRevision = "+namespaceRevision);
        if (Capabilities.isNamespaceSupported(namespaceRevision)) {
            eb.setCoreModelCapability(namespaceRevision);
        } else {
            eb.setCoreModelCapability("Unsupported");
        }
        databaseService.updateNetworkConnection22(eb.build(), netconfAccessor.getNodeId().getValue());
    }

    @Override
    public void register() {
        // Set core-model revision value in "core-model-capability" field
        setCoreModel(netconfAccessor.getNetconfNode());
        initialReadFromNetworkElement();

        // Register netconf stream
        airInterfaceNotificationListenerHandler =
                netconfAccessor.doRegisterNotificationListener(airInterfaceNotificationListener);
        etherneContainerNotificationListenerHandler =
                netconfAccessor.doRegisterNotificationListener(ethernetContainerNotificationListener);
        wireInterfaceNotificationListenerHandler =
                netconfAccessor.doRegisterNotificationListener(wireInterfaceNotificationListener);
        netconfAccessor.registerNotificationsStream(NetconfAccessor.DefaultNotificationsStream);
    }

    @Override
    public void deregister() {}


    @Override
    public NodeId getNodeId() {
        return netconfAccessor.getNodeId();
    }

    @Override
    public <L extends NetworkElementService> Optional<L> getService(Class<L> clazz) {
        return Optional.empty();
    }

    @Override
    public void warmstart() {}

    @Override
    public Optional<NetconfAccessor> getAcessor() {
        return Optional.of(netconfAccessor);
    }

    @Override
    public NetworkElementDeviceType getDeviceType() {
        return NetworkElementDeviceType.Wireless;
    }

    private void readEquipmentData() {

        Optional<ControlConstruct> controlConstruct = readControlConstruct(netconfAccessor);

        if (controlConstruct.isPresent()) {
            // the top-level-equipment list contains the root objects of the Equipment Model
            log.debug("Getting list of topLevelEquipment for mountpoint {}", netconfAccessor.getNodeId());
            @Nullable
            List<UniversalId> topLevelEquipment = controlConstruct.get().getTopLevelEquipment();

            if (topLevelEquipment != null) {
                for (UniversalId uuid : topLevelEquipment) {
                    log.debug("Got back topLevelEquipment with uuid {}", uuid.getValue());

                    // adding all root Equipment objects to the DB
                    @Nullable
                    Equipment equipmentInstance = readEquipmentInstance(netconfAccessor, uuid);
                    if (equipmentInstance != null) {
                        // recursively adding the root equipment and all its children into the DB
                        addEquipmentToDb(equipmentInstance, null, EQUIPMENTROOTLEVEL);
                    }
                }
            }
        }

        // storing all the LTP UUIDs internally, for later usage, for air-interface and ethernet-container
        readKeys(controlConstruct);
    }

    private void addEquipmentToDb(Equipment currentEq, Equipment parentEq, long treeLevel) {

        // if the Equipment UUID is already in the list, it was already processed
        // needed for solving possible circular dependencies
        if (equipmentUuidList.contains(currentEq.getUuid().getValue())) {
            log.debug("Not adding equipment with uuid {} because it was aleady added...",
                    currentEq.getUuid().getValue());
            return;
        }

        // we add this to our internal list, such that we avoid circular dependencies
        equipmentUuidList.add(currentEq.getUuid().getValue());
        log.debug("Adding equipment with uuid {} to the database...", currentEq.getUuid().getValue());

        // we add our current equipment to the database
        databaseService.writeInventory(
                onf14Mapper.getInternalEquipment(netconfAccessor.getNodeId(), currentEq, parentEq, treeLevel));

        // we iterate the kids of our current equipment and add them to the database recursively
        // the actual reference is here: /core-model:control-construct/equipment/contained-holder/occupying-fru
        @NonNull
        Collection<ContainedHolder> holderList = YangHelper.getCollection(currentEq.nonnullContainedHolder());

        for (ContainedHolder holder : holderList) {
            @Nullable
            UniversalId occupyingFru = holder.getOccupyingFru();
            if (occupyingFru != null) {
                @Nullable
                Equipment childEq = readEquipmentInstance(netconfAccessor, occupyingFru);

                if (childEq != null) {
                    // current becomes parent and tree level increases by 1
                    addEquipmentToDb(childEq, currentEq, treeLevel + 1);
                }
            }
        }
    }

    private void readKeys(Optional<ControlConstruct> controlConstruct) {

        if (controlConstruct.isPresent()) {
            @NonNull
            Collection<LogicalTerminationPoint> ltpList = YangHelper.getCollection(controlConstruct.get().nonnullLogicalTerminationPoint());
            log.debug("Iterating the LTP list for node {}", netconfAccessor.getNodeId().getValue());

            // iterating all the Logical Termination Point list
            for (LogicalTerminationPoint ltp : ltpList) {
                @NonNull
                List<LayerProtocol> lpList = YangHelper.getList(ltp.nonnullLayerProtocol());
                // the Layer Protocol list should contain only one item, since we have an 1:1 relationship between the LTP and the LP
                if (lpList.size() != 1) {
                    log.debug("Layer protocol has no 1:1 relationship with the LTP.");
                    return;
                }
                // accessing the LP, which should be only 1
                LayerProtocol lp = lpList.get(0);
                @Nullable
                Class<? extends LAYERPROTOCOLNAMETYPE> layerProtocolName = lp.getLayerProtocolName();
                if (layerProtocolName != null) {
                    // if the LTP has an airInterface technology extension, the layer protocol name is air-layer
                    if (layerProtocolName.getTypeName() == LAYERPROTOCOLNAMETYPEAIRLAYER.class.getName()) {
                        TechnologySpecificPacKeys airInterfaceKey =
                                new TechnologySpecificPacKeys(ltp.getUuid(), lp.getLocalId());
                        airInterfaceList.add(airInterfaceKey);
                        log.debug("Adding Ltp with uuid {} and local-id {} to the air-interface list",
                                ltp.getUuid().getValue(), lp.getLocalId());
                    }
                    // if the LTP has an ethernetContainier technology extension, the layer protocol name is ethernet-container-layer
                    else if (layerProtocolName.getTypeName() == LAYERPROTOCOLNAMETYPEETHERNETCONTAINERLAYER.class
                            .getName()) {
                        TechnologySpecificPacKeys ethernetContainerKey =
                                new TechnologySpecificPacKeys(ltp.getUuid(), lp.getLocalId());
                        ethernetContainerList.add(ethernetContainerKey);
                        log.debug("Adding Ltp with uuid {} and local-id {} to the ethernet-contatinier list",
                                ltp.getUuid().getValue(), lp.getLocalId());
                    } else if (layerProtocolName.getTypeName() == LAYERPROTOCOLNAMETYPEWIRELAYER.class.getName()) {
                        TechnologySpecificPacKeys wireInterfaceKey =
                                new TechnologySpecificPacKeys(ltp.getUuid(), lp.getLocalId());
                        wireInterfaceList.add(wireInterfaceKey);
                        log.debug("Adding Ltp with uuid {} and local-id {} to the wire-interface list",
                                ltp.getUuid().getValue(), lp.getLocalId());
                    }
                }
            }
        }
    }

    private void readAirInterfaceCurrentProblemForLtp(UniversalId ltpUuid, String localId, FaultData resultList) {

        final Class<AirInterfacePac> clazzPac = AirInterfacePac.class;

        log.info("DBRead Get current problems for class {} from mountpoint {} for LTP uuid {} and local-id {}",
                clazzPac.getSimpleName(), netconfAccessor.getNodeId().getValue(), ltpUuid.getValue(), localId);

        // constructing the IID needs the augmentation exposed byy the air-interface-2-0 model
        InstanceIdentifier<AirInterfaceCurrentProblems> airInterfaceCurrentProblem_IID = InstanceIdentifier
                .builder(ControlConstruct.class)
                .child(LogicalTerminationPoint.class, new LogicalTerminationPointKey(ltpUuid))
                .child(LayerProtocol.class, new LayerProtocolKey(localId))
                .augmentation(
                        org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.LayerProtocol1.class)
                .child(AirInterfacePac.class).child(AirInterfaceCurrentProblems.class).build();

        // reading all the current-problems list for this specific LTP and LP
        AirInterfaceCurrentProblems problems = netconfAccessor.getTransactionUtils().readData(
                netconfAccessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL, airInterfaceCurrentProblem_IID);

        if (problems == null) {
            log.debug("DBRead Id {} no AirInterfaceCurrentProblems", ltpUuid);
        } else if (problems.getCurrentProblemList() == null) {
            log.debug("DBRead Id {} empty CurrentProblemList", ltpUuid);
        } else {
            for (org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.air._interface.current.problems.CurrentProblemList problem : YangHelper.getCollection(problems
                    .nonnullCurrentProblemList())) {
                resultList.add(netconfAccessor.getNodeId(), (int) problem.getSequenceNumber(), problem.getTimestamp(),
                        ltpUuid.getValue(), problem.getProblemName(),
                        Onf14AirInterface.mapSeverity(problem.getProblemSeverity()));
            }
        }
    }

    private void readEthernetConainerCurrentProblemForLtp(UniversalId ltpUuid, String localId, FaultData resultList) {

        final Class<EthernetContainerPac> clazzPac = EthernetContainerPac.class;

        log.info("DBRead Get current problems for class {} from mountpoint {} for LTP uuid {} and local-id {}",
                clazzPac.getSimpleName(), netconfAccessor.getNodeId().getValue(), ltpUuid.getValue(), localId);

        // constructing the IID needs the augmentation exposed by the ethernet-container-2-0 model
        InstanceIdentifier<EthernetContainerCurrentProblems> etherneContainerCurrentProblem_IID = InstanceIdentifier
                .builder(ControlConstruct.class)
                .child(LogicalTerminationPoint.class, new LogicalTerminationPointKey(ltpUuid))
                .child(LayerProtocol.class, new LayerProtocolKey(localId))
                .augmentation(
                        org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.LayerProtocol1.class)
                .child(EthernetContainerPac.class).child(EthernetContainerCurrentProblems.class).build();

        // reading all the current-problems list for this specific LTP and LP
        EthernetContainerCurrentProblems problems = netconfAccessor.getTransactionUtils().readData(
                netconfAccessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL, etherneContainerCurrentProblem_IID);

        if (problems == null) {
            log.debug("DBRead Id {} no EthernetContainerCurrentProblems", ltpUuid);
        } else if (problems.getCurrentProblemList() == null) {
            log.debug("DBRead Id {} empty CurrentProblemList", ltpUuid);
        } else {
            for (org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.ethernet.container.current.problems.CurrentProblemList problem : YangHelper.getCollection(problems
                    .nonnullCurrentProblemList())) {
                resultList.add(netconfAccessor.getNodeId(), (int) problem.getSequenceNumber(), problem.getTimestamp(),
                        ltpUuid.getValue(), problem.getProblemName(),
                        Onf14EthernetContainer.mapSeverity(problem.getProblemSeverity()));
            }
        }
    }

    private void readWireInterfaceCurrentProblemForLtp(UniversalId ltpUuid, String localId, FaultData resultList) {

        final Class<WireInterfacePac> clazzPac = WireInterfacePac.class;

        log.info("DBRead Get current problems for class {} from mountpoint {} for LTP uuid {} and local-id {}",
                clazzPac.getSimpleName(), netconfAccessor.getNodeId().getValue(), ltpUuid.getValue(), localId);

        // constructing the IID needs the augmentation exposed by the wire-interface-2-0 model
        InstanceIdentifier<WireInterfaceCurrentProblems> wireInterfaceCurrentProblem_IID = InstanceIdentifier
                .builder(ControlConstruct.class)
                .child(LogicalTerminationPoint.class, new LogicalTerminationPointKey(ltpUuid))
                .child(LayerProtocol.class, new LayerProtocolKey(localId))
                .augmentation(
                        org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.LayerProtocol1.class)
                .child(WireInterfacePac.class).child(WireInterfaceCurrentProblems.class).build();

        // reading all the current-problems list for this specific LTP and LP
        WireInterfaceCurrentProblems problems = netconfAccessor.getTransactionUtils().readData(
                netconfAccessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL, wireInterfaceCurrentProblem_IID);

        if (problems == null) {
            log.debug("DBRead Id {} no WireInterfaceCurrentProblems", ltpUuid);
        } else if (problems.getCurrentProblemList() == null) {
            log.debug("DBRead Id {} empty CurrentProblemList", ltpUuid);
        } else {
            for (org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.wire._interface.current.problems.CurrentProblemList problem : YangHelper.getCollection(problems
                    .nonnullCurrentProblemList())) {
                resultList.add(netconfAccessor.getNodeId(), (int) problem.getSequenceNumber(), problem.getTimestamp(),
                        ltpUuid.getValue(), problem.getProblemName(),
                        Onf14WireInterface.mapSeverity(problem.getProblemSeverity()));
            }
        }
    }

    private Optional<ControlConstruct> readControlConstruct(NetconfAccessor netconfAccessor) {
        return Optional.ofNullable(netconfAccessor.getTransactionUtils().readData(netconfAccessor.getDataBroker(),
                LogicalDatastoreType.CONFIGURATION, CONTROLCONSTRUCT_IID));
    }

    private @Nullable Equipment readEquipmentInstance(NetconfAccessor accessData, UniversalId equipmentUuid) {

        final Class<?> clazzPac = Equipment.class;

        log.info("DBRead Get equipment for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
                accessData.getNodeId().getValue(), equipmentUuid.getValue());

        InstanceIdentifier<Equipment> equipmentIID = InstanceIdentifier.builder(ControlConstruct.class)
                .child(Equipment.class, new EquipmentKey(equipmentUuid)).build();

        return accessData.getTransactionUtils().readData(accessData.getDataBroker(), LogicalDatastoreType.CONFIGURATION,
                equipmentIID);
    }

    // defining a structure that can map the LP local-id and its corresponding LTP uuid
    private class TechnologySpecificPacKeys {

        private UniversalId ltpUuid;
        private String localId;

        public TechnologySpecificPacKeys(UniversalId uuid, String lId) {
            this.ltpUuid = uuid;
            this.localId = lId;
        }

        public UniversalId getLtpUuid() {
            return ltpUuid;
        }

        public String getLocalId() {
            return localId;
        }

        public void setLtpUuid(UniversalId uuid) {
            this.ltpUuid = uuid;
        }

        public void setLocalId(String lId) {
            this.localId = lId;
        }
    }


    /**
     * LOG the newly added problems of the interface pac
     *
     * @param idxStart
     * @param uuid
     * @param resultList
     */
    private void debugResultList(String uuid, FaultData resultList, int idxStart) {
        StringBuilder sb = new StringBuilder();
        int idx = 0;
        for (int t = idxStart; t < resultList.size(); t++) {
            sb.append(idx++);
            sb.append(":{");
            sb.append(resultList.get(t));
            sb.append('}');
        }
        log.debug("Found problems {} {}", uuid, sb);
    }

}