aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/devicemanager-onf/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/onf/ne/ONFCoreNetworkElement12Base.java
blob: 30897da1d94d0c32af972fbc9267d5c04098d0da (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
/*
 * ============LICENSE_START========================================================================
 * ONAP : ccsdk feature sdnr wt
 * =================================================================================================
 * Copyright (C) 2019 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.onf.ne;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CopyOnWriteArrayList;
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.devicemanager.ne.service.NetworkElementService;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.NetworkElementCoreData;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.WrapperPTPModelRev170208;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.equipment.ONFCoreNetworkElement12Equipment;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.microwave.Helper;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.microwave.WrapperMicrowaveModelRev181010;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.InventoryInformationDcae;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.PerformanceDataLtp;
import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
import org.opendaylight.mdsal.binding.api.MountPoint;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.NetworkElement;
import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.UniversalId;
import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.extension.g.Extension;
import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.logical.termination.point.g.Lp;
import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.network.element.Ltp;
import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.NetworkElementPac;
import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.network.element.pac.NetworkElementCurrentProblems;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * This class contains the ONF Core model Version 1.2 related functions.<br>
 * Provides the basic ONF Core Model function.<br>
 * - initialReadFromNetworkElement is not implemented in child classes.
 */
public abstract class ONFCoreNetworkElement12Base extends ONFCoreNetworkElementBase implements NetworkElementCoreData {

    private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12Base.class);

    protected static final @NonNull List<Extension> EMPTYLTPEXTENSIONLIST = new ArrayList<>();

    protected static final InstanceIdentifier<NetworkElement> NETWORKELEMENT_IID =
            InstanceIdentifier.builder(NetworkElement.class).build();


    /*-----------------------------------------------------------------------------
     * Class members
     */

    // Non specific part. Used by all functions.
    /** interfaceList is used by PM task and should be synchronized */
    @SuppressWarnings("null")
    private final @NonNull List<Lp> interfaceList = Collections.synchronizedList(new CopyOnWriteArrayList<>());
    private Optional<NetworkElement> optionalNe;

    // Performance monitoring specific part
    /** Lock for the PM access specific elements that could be null */
    private final @NonNull Object pmLock = new Object();
    protected @Nullable Iterator<Lp> interfaceListIterator = null;
    /** Actual pmLp used during iteration over interfaces */
    protected @Nullable Lp pmLp = null;

    // Device monitoring specific part
    /** Lock for the DM access specific elements that could be null */
    protected final @NonNull Object dmLock = new Object();

    protected final boolean isNetworkElementCurrentProblemsSupporting12;

    protected final ONFCoreNetworkElement12Equipment equipment;

    protected final NodeId nodeId;

    /*---------------------------------------------------------------
     * Constructor
     */

    protected ONFCoreNetworkElement12Base(@NonNull NetconfAccessor acessor) {
        super(acessor);
        this.optionalNe = Optional.empty();
        this.nodeId = getAcessor().get().getNodeId();
        this.isNetworkElementCurrentProblemsSupporting12 =
                acessor.getCapabilites().isSupportingNamespaceAndRevision(NetworkElementPac.QNAME);
        this.equipment = new ONFCoreNetworkElement12Equipment(acessor, this);
        WrapperPTPModelRev170208.initSynchronizationExtension(acessor);
        LOG.debug("support necurrent-problem-list={}", this.isNetworkElementCurrentProblemsSupporting12);
    }

    /*---------------------------------------------------------------
     * Getter/ Setter
     */

    @Override
    public Optional<NetworkElement> getOptionalNetworkElement() {
        return optionalNe;
    }

    List<Lp> getInterfaceList() {
        return interfaceList;
    }

    public Object getPmLock() {
        return pmLock;
    }

    /*---------------------------------------------------------------
     * Core model related function
     */

    /**
     * Get uuid of Optional NE.
     *
     * @return Uuid or EMPTY String if optionNE is not available
     */
    protected String getUuId() {
        return optionalNe.isPresent() ? Helper.nnGetUniversalId(optionalNe.get().getUuid()).getValue() : EMPTY;
    }

    /**
     * Read from NetworkElement and verify LTPs have changed. If the NE has changed, update to the new structure. From
     * initial state it changes also.
     */
    protected boolean readNetworkElementAndInterfaces() {

        LOG.debug("Update mountpoint if changed {}", getMountpoint());

        optionalNe = Optional.ofNullable(getGenericTransactionUtils().readData(getDataBroker(),
                LogicalDatastoreType.OPERATIONAL, NETWORKELEMENT_IID));
        synchronized (pmLock) {
            boolean change = false;

            if (!optionalNe.isPresent()) {
                LOG.debug("Unable to read NE data for mountpoint {}", getMountpoint());
                if (!interfaceList.isEmpty()) {
                    interfaceList.clear();
                    interfaceListIterator = null;
                    change = true;
                }

            } else {
                NetworkElement ne = optionalNe.get();
                LOG.debug("Mountpoint '{}' NE-Name '{}'", getMountpoint(), ne.getName());
                List<Lp> actualInterfaceList = getLtpList(ne);
                if (!interfaceList.equals(actualInterfaceList)) {
                    LOG.debug("Mountpoint '{}' Update LTP List. Elements {}", getMountpoint(),
                            actualInterfaceList.size());
                    interfaceList.clear();
                    interfaceList.addAll(actualInterfaceList);
                    interfaceListIterator = null;
                    change = true;
                }
            }
            return change;
        }
    }

    /**
     * Get List of UUIDs for conditional packages from Networkelement<br>
     * Possible interfaces are:<br>
     * MWPS, LTP(MWPS-TTP), MWAirInterfacePac, MicrowaveModel-ObjectClasses-AirInterface<br>
     * ETH-CTP,LTP(Client), MW_EthernetContainer_Pac<br>
     * MWS, LTP(MWS-CTP-xD), MWAirInterfaceDiversityPac, MicrowaveModel-ObjectClasses-AirInterfaceDiversity<br>
     * MWS, LTP(MWS-TTP), ,MicrowaveModel-ObjectClasses-HybridMwStructure<br>
     * MWS, LTP(MWS-TTP), ,MicrowaveModel-ObjectClasses-PureEthernetStructure<br>
     *
     * @param ne NetworkElement
     * @return Id List, never null.
     */

    private static List<Lp> getLtpList(@Nullable NetworkElement ne) {

        List<Lp> res = Collections.synchronizedList(new ArrayList<Lp>());

        if (ne != null) {
            Collection<Ltp> ltpRefList = YangHelper.getCollection(ne.getLtp());
            if (ltpRefList == null) {
                LOG.debug("DBRead NE-Interfaces: null");
            } else {
                for (Ltp ltRefListE : ltpRefList) {
                    Collection<Lp> lpList = YangHelper.getCollection(ltRefListE.getLp());
                    if (lpList == null) {
                        LOG.debug("DBRead NE-Interfaces Reference List: null");
                    } else {
                        for (Lp ltp : lpList) {
                            res.add(ltp);
                        }
                    }
                }
            }
        } else {
            LOG.debug("DBRead NE: null");
        }

        // ---- Debug
        if (LOG.isDebugEnabled()) {
            StringBuilder strBuild = new StringBuilder();
            for (Lp ltp : res) {
                if (strBuild.length() > 0) {
                    strBuild.append(", ");
                }
                strBuild.append(Helper.nnGetLayerProtocolName(ltp.getLayerProtocolName()).getValue());
                strBuild.append(':');
                strBuild.append(Helper.nnGetUniversalId(ltp.getUuid()).getValue());
            }
            LOG.debug("DBRead NE-Interfaces: {}", strBuild.toString());
        }
        // ---- Debug end

        return res;
    }

    /**
     * Read current problems of AirInterfaces and EthernetContainer according to NE status into DB
     *
     * @return List with all problems
     */
    protected FaultData readAllCurrentProblemsOfNode() {

        // Step 2.3: read the existing faults and add to DB
        FaultData resultList = new FaultData();
        int idxStart; // Start index for debug messages
        UniversalId uuid;

        synchronized (pmLock) {
            for (Lp lp : interfaceList) {

                idxStart = resultList.size();
                uuid = lp.getUuid();
                FaultData.debugResultList(LOG, uuid.getValue(), resultList, idxStart);

            }
        }

        // Step 2.4: Read other problems from mountpoint
        if (isNetworkElementCurrentProblemsSupporting12) {
            idxStart = resultList.size();
            readNetworkElementCurrentProblems12(resultList);
            FaultData.debugResultList(LOG, "CurrentProblems12", resultList, idxStart);
        }

        return resultList;

    }

    /**
     * Reading problems for the networkElement V1.2
     *
     * @param resultList to collect the problems
     * @return resultList with additonal problems
     */
    protected FaultData readNetworkElementCurrentProblems12(FaultData resultList) {

        LOG.info("DBRead Get {} NetworkElementCurrentProblems12", getMountpoint());

        InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.NetworkElementPac> networkElementCurrentProblemsIID =
                InstanceIdentifier.builder(
                        org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.NetworkElementPac.class)
                        .build();

        // Step 2.3: read to the config data store
        NetworkElementPac problemPac;
        NetworkElementCurrentProblems problems = null;
        try {
            problemPac = getGenericTransactionUtils().readData(getDataBroker(), LogicalDatastoreType.OPERATIONAL,
                    networkElementCurrentProblemsIID);
            if (problemPac != null) {
                problems = problemPac.getNetworkElementCurrentProblems();
            }
            if (problems == null) {
                LOG.debug("DBRead no NetworkElementCurrentProblems12");
            } else {
                for (org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.network.element.current.problems.g.CurrentProblemList problem : YangHelper
                        .getCollection(problems.nonnullCurrentProblemList())) {
                    resultList.add(nodeId, problem.getSequenceNumber(), problem.getTimeStamp(),
                            problem.getObjectReference(), problem.getProblemName(),
                            WrapperMicrowaveModelRev181010.mapSeverity(problem.getProblemSeverity()));
                }
            }
        } catch (Exception e) {
            LOG.warn("DBRead {} NetworkElementCurrentProblems12 not supported. Message '{}' ", getMountpoint(),
                    e.getMessage());
        }
        return resultList;
    }

    /*---------------------------------------------------------------
     * Device Monitor
     */

    @Override
    public boolean checkIfConnectionToMediatorIsOk() {
        synchronized (dmLock) {
            return optionalNe != null;
        }
    }

    /*
     * New implementation to interpret status with empty LTP List as notConnected => return false
     * 30.10.2018 Since this behavior is very specific and implicit for specific NE Types
     *     it needs to be activated by extension or configuration. Change to be disabled at the moment
     */
    @Override
    public boolean checkIfConnectionToNeIsOk() {
        return true;
    }

    /*---------------------------------------------------------------
     * Synchronization
     */


    /*---------------------------------------------------------------
     * Equipment related functions
     */

    @Override
    public @NonNull InventoryInformationDcae getInventoryInformation(String layerProtocolFilter) {
        LOG.debug("request inventory information. filter: {}" + layerProtocolFilter);
        return this.equipment.getInventoryInformation(getFilteredInterfaceUuidsAsStringList(layerProtocolFilter));
    }

    @Override
    public InventoryInformationDcae getInventoryInformation() {
        return getInventoryInformation(null);
    }

    protected List<String> getFilteredInterfaceUuidsAsStringList(String layerProtocolFilter) {
        List<String> uuids = new ArrayList<>();

        LOG.debug("request inventory information. filter: {}" + layerProtocolFilter);
        if (optionalNe != null) {
            // uuids
            for (Lp lp : this.interfaceList) {
                if (layerProtocolFilter == null || layerProtocolFilter.isEmpty() || layerProtocolFilter
                        .equals(Helper.nnGetLayerProtocolName(lp.getLayerProtocolName()).getValue())) {
                    uuids.add(Helper.nnGetUniversalId(lp.getUuid()).getValue());
                }
            }
        }
        LOG.debug("uuids found: {}", uuids);
        return uuids;
    }


    /*---------------------------------------------------------------
     * Performancemanagement specific interface
     */

    @Override
    public void resetPMIterator() {
        synchronized (pmLock) {
            interfaceListIterator = interfaceList.iterator();
        }
        LOG.debug("PM reset iterator");
    }

    @SuppressWarnings("null")
    @Override
    public boolean hasNext() {
        boolean res;
        synchronized (pmLock) {
            res = interfaceListIterator != null ? interfaceListIterator.hasNext() : false;
        }
        LOG.debug("PM hasNext LTP {}", res);
        return res;
    }

    @SuppressWarnings("null")
    @Override
    public void next() {
        synchronized (pmLock) {
            if (interfaceListIterator == null) {
                pmLp = null;
                LOG.debug("PM next LTP null");
            } else {
                pmLp = interfaceListIterator.next();
                LOG.debug("PM next LTP {}", Helper.nnGetLayerProtocolName(pmLp.getLayerProtocolName()).getValue());
            }
        }
    }

    @SuppressWarnings("null")
    @Override
    public String pmStatusToString() {
        StringBuilder res = new StringBuilder();
        synchronized (pmLock) {
            res.append(pmLp == null ? "no interface"
                    : Helper.nnGetLayerProtocolName(pmLp.getLayerProtocolName()).getValue());
            for (Lp lp : getInterfaceList()) {
                res.append("IF:");
                res.append(Helper.nnGetLayerProtocolName(lp.getLayerProtocolName()).getValue());
                res.append(" ");
            }
        }
        return res.toString();
    }

    @Override
    public void doRegisterEventListener(MountPoint mountPoint) {
        //Do nothing
    }

    @SuppressWarnings("unchecked")
    @Override
    public <L extends NetworkElementService> Optional<L> getService(Class<L> clazz) {
        return clazz.isInstance(this) ? Optional.of((L) this) : Optional.empty();
    }

    @Override
    public Optional<PerformanceDataLtp> getLtpHistoricalPerformanceData() {
        return Optional.empty();
    }

}