48f1ebba684591c4cf78c27923fb5e3e1dff5893
[ccsdk/features.git] /
1 /*******************************************************************************
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 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.onf.ne;
19
20 import java.util.ArrayList;
21 import java.util.Collections;
22 import java.util.Iterator;
23 import java.util.List;
24 import java.util.Optional;
25 import java.util.concurrent.CopyOnWriteArrayList;
26 import org.eclipse.jdt.annotation.NonNull;
27 import org.eclipse.jdt.annotation.Nullable;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElementService;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.NetworkElementCoreData;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.WrapperPTPModelRev170208;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.equipment.ONFCoreNetworkElement12Equipment;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.microwave.Helper;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.microwave.WrapperMicrowaveModelRev181010;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.InventoryInformationDcae;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.PerformanceDataLtp;
37 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
38 import org.opendaylight.mdsal.binding.api.MountPoint;
39 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
40 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.NetworkElement;
41 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.UniversalId;
42 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.extension.g.Extension;
43 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.logical.termination.point.g.Lp;
44 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.network.element.Ltp;
45 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.NetworkElementPac;
46 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.network.element.pac.NetworkElementCurrentProblems;
47 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
48 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
49 import org.slf4j.Logger;
50 import org.slf4j.LoggerFactory;
51
52
53 /**
54  * This class contains the ONF Core model Version 1.2 related functions.<br>
55  * Provides the basic ONF Core Model function.<br>
56  * - initialReadFromNetworkElement is not implemented in child classes.
57  */
58 public abstract class ONFCoreNetworkElement12Base extends ONFCoreNetworkElementBase implements NetworkElementCoreData {
59
60     private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12Base.class);
61
62     protected static final @NonNull List<Extension> EMPTYLTPEXTENSIONLIST = new ArrayList<>();
63     // private static final List<Ltp> EMPTYLTPLIST = new ArrayList<>();
64
65     protected static final InstanceIdentifier<NetworkElement> NETWORKELEMENT_IID = InstanceIdentifier
66             .builder(NetworkElement.class).build();
67
68
69     /*-----------------------------------------------------------------------------
70      * Class members
71      */
72
73     // Non specific part. Used by all functions.
74     /** interfaceList is used by PM task and should be synchronized */
75     @SuppressWarnings("null")
76     private final @NonNull List<Lp> interfaceList = Collections.synchronizedList(new CopyOnWriteArrayList<>());
77     private Optional<NetworkElement> optionalNe;
78
79     // Performance monitoring specific part
80     /** Lock for the PM access specific elements that could be null */
81     private final @NonNull Object pmLock = new Object();
82     protected @Nullable Iterator<Lp> interfaceListIterator = null;
83     /** Actual pmLp used during iteration over interfaces */
84     protected @Nullable Lp pmLp = null;
85
86     // Device monitoring specific part
87     /** Lock for the DM access specific elements that could be null */
88     protected final @NonNull Object dmLock = new Object();
89
90     protected final boolean isNetworkElementCurrentProblemsSupporting12;
91
92     protected final ONFCoreNetworkElement12Equipment equipment;
93
94     protected final NodeId nodeId;
95
96     /*---------------------------------------------------------------
97      * Constructor
98      */
99
100     protected ONFCoreNetworkElement12Base(@NonNull NetconfAccessor acessor) {
101         super(acessor);
102         this.optionalNe = Optional.empty();
103         this.nodeId = getAcessor().get().getNodeId();
104         this.isNetworkElementCurrentProblemsSupporting12 = acessor.getCapabilites().isSupportingNamespaceAndRevision(NetworkElementPac.QNAME);
105         this.equipment = new ONFCoreNetworkElement12Equipment(acessor, this, acessor.getCapabilites());
106         WrapperPTPModelRev170208.initSynchronizationExtension(acessor);
107         LOG.debug("support necurrent-problem-list={}", this.isNetworkElementCurrentProblemsSupporting12);
108     }
109
110     /*---------------------------------------------------------------
111      * Getter/ Setter
112      */
113
114     @Override
115     public Optional<NetworkElement> getOptionalNetworkElement() {
116         return optionalNe;
117     }
118
119     List<Lp> getInterfaceList() {
120         return interfaceList;
121     }
122
123     public Object getPmLock() {
124         return pmLock;
125     }
126
127     /*---------------------------------------------------------------
128      * Core model related function
129      */
130
131     /**
132      * Get uuid of Optional NE.
133      *
134      * @return Uuid or EMPTY String if optionNE is not available
135      */
136     protected String getUuId() {
137         String uuid = optionalNe.isPresent() ? Helper.nnGetUniversalId(optionalNe.get().getUuid()).getValue() : EMPTY;
138         return uuid;
139     }
140
141     /**
142      * Read from NetworkElement and verify LTPs have changed. If the NE has changed, update to the new
143      * structure. From initial state it changes also.
144      */
145     protected synchronized boolean readNetworkElementAndInterfaces() {
146
147         LOG.debug("Update mountpoint if changed {}", getMountPointNodeName());
148
149         optionalNe = Optional.ofNullable(getGenericTransactionUtils().readData(getNetconfNodeDataBroker(), LogicalDatastoreType.OPERATIONAL,
150                 NETWORKELEMENT_IID));
151         synchronized (pmLock) {
152             boolean change = false;
153
154             if (!optionalNe.isPresent()) {
155                 LOG.debug("Unable to read NE data for mountpoint {}", getMountPointNodeName());
156                 if (!interfaceList.isEmpty()) {
157                     interfaceList.clear();
158                     interfaceListIterator = null;
159                     change = true;
160                 }
161
162             } else {
163                 NetworkElement ne = optionalNe.get();
164                 LOG.debug("Mountpoint '{}' NE-Name '{}'", getMountPointNodeName(), ne.getName());
165                 List<Lp> actualInterfaceList = getLtpList(ne);
166                 if (!interfaceList.equals(actualInterfaceList)) {
167                     LOG.debug("Mountpoint '{}' Update LTP List. Elements {}", getMountPointNodeName(),
168                             actualInterfaceList.size());
169                     interfaceList.clear();
170                     interfaceList.addAll(actualInterfaceList);
171                     interfaceListIterator = null;
172                     change = true;
173                 }
174             }
175             return change;
176         }
177     }
178
179     /**
180      * Get List of UUIDs for conditional packages from Networkelement<br>
181      * Possible interfaces are:<br>
182      * MWPS, LTP(MWPS-TTP), MWAirInterfacePac, MicrowaveModel-ObjectClasses-AirInterface<br>
183      * ETH-CTP,LTP(Client), MW_EthernetContainer_Pac<br>
184      * MWS, LTP(MWS-CTP-xD), MWAirInterfaceDiversityPac,
185      * MicrowaveModel-ObjectClasses-AirInterfaceDiversity<br>
186      * MWS, LTP(MWS-TTP), ,MicrowaveModel-ObjectClasses-HybridMwStructure<br>
187      * MWS, LTP(MWS-TTP), ,MicrowaveModel-ObjectClasses-PureEthernetStructure<br>
188      *
189      * @param ne NetworkElement
190      * @return Id List, never null.
191      */
192
193     private static List<Lp> getLtpList(@Nullable NetworkElement ne) {
194
195         List<Lp> res = Collections.synchronizedList(new ArrayList<Lp>());
196
197         if (ne != null) {
198             List<Ltp> ltpRefList = ne.getLtp();
199             if (ltpRefList == null) {
200                 LOG.debug("DBRead NE-Interfaces: null");
201             } else {
202                 for (Ltp ltRefListE : ltpRefList) {
203                     List<Lp> lpList = ltRefListE.getLp();
204                     if (lpList == null) {
205                         LOG.debug("DBRead NE-Interfaces Reference List: null");
206                     } else {
207                         for (Lp ltp : lpList) {
208                             res.add(ltp);
209                         }
210                     }
211                 }
212             }
213         } else {
214             LOG.debug("DBRead NE: null");
215         }
216
217         // ---- Debug
218         if (LOG.isDebugEnabled()) {
219             StringBuffer strBuf = new StringBuffer();
220             for (Lp ltp : res) {
221                 if (strBuf.length() > 0) {
222                     strBuf.append(", ");
223                 }
224                 strBuf.append(Helper.nnGetLayerProtocolName(ltp.getLayerProtocolName()).getValue());
225                 strBuf.append(':');
226                 strBuf.append(Helper.nnGetUniversalId(ltp.getUuid()).getValue());
227             }
228             LOG.debug("DBRead NE-Interfaces: {}", strBuf.toString());
229         }
230         // ---- Debug end
231
232         return res;
233     }
234
235     /**
236      * Read current problems of AirInterfaces and EthernetContainer according to NE status into DB
237      *
238      * @return List with all problems
239      */
240     protected FaultData readAllCurrentProblemsOfNode() {
241
242         // Step 2.3: read the existing faults and add to DB
243         FaultData resultList = new FaultData();
244         int idxStart; // Start index for debug messages
245         UniversalId uuid;
246
247         synchronized (pmLock) {
248             for (Lp lp : interfaceList) {
249
250                 idxStart = resultList.size();
251                 uuid = lp.getUuid();
252                 FaultData.debugResultList(LOG, uuid.getValue(), resultList, idxStart);
253
254             }
255         }
256
257         // Step 2.4: Read other problems from mountpoint
258         if (isNetworkElementCurrentProblemsSupporting12) {
259             idxStart = resultList.size();
260             readNetworkElementCurrentProblems12(resultList);
261             FaultData.debugResultList(LOG, "CurrentProblems12", resultList, idxStart);
262         }
263
264         return resultList;
265
266     }
267
268     /**
269      * Reading problems for the networkElement V1.2
270      * @param resultList to collect the problems
271      * @return resultList with additonal problems
272      */
273     protected FaultData readNetworkElementCurrentProblems12(FaultData resultList) {
274
275         LOG.info("DBRead Get {} NetworkElementCurrentProblems12", getMountPointNodeName());
276
277         InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.NetworkElementPac> networkElementCurrentProblemsIID =
278                 InstanceIdentifier.builder(
279                         org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.NetworkElementPac.class)
280                         .build();
281
282         // Step 2.3: read to the config data store
283         NetworkElementPac problemPac;
284         NetworkElementCurrentProblems problems = null;
285         try {
286             problemPac = getGenericTransactionUtils().readData(getNetconfNodeDataBroker(), LogicalDatastoreType.OPERATIONAL,
287                     networkElementCurrentProblemsIID);
288             if (problemPac != null) {
289                 problems = problemPac.getNetworkElementCurrentProblems();
290             }
291             if (problems == null) {
292                 LOG.debug("DBRead no NetworkElementCurrentProblems12");
293             } else {
294                 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 : problems
295                         .nonnullCurrentProblemList()) {
296                     resultList.add(nodeId, problem.getSequenceNumber(), problem.getTimeStamp(),
297                             problem.getObjectReference(), problem.getProblemName(),
298                             WrapperMicrowaveModelRev181010.mapSeverity(problem.getProblemSeverity()));
299                 }
300             }
301         } catch (Exception e) {
302             LOG.warn("DBRead {} NetworkElementCurrentProblems12 not supported. Message '{}' ", getMountPointNodeName(),
303                     e.getMessage());
304         }
305         return resultList;
306     }
307
308     /*---------------------------------------------------------------
309      * Device Monitor
310      */
311
312     @Override
313     public boolean checkIfConnectionToMediatorIsOk() {
314         synchronized (dmLock) {
315             return optionalNe != null;
316         }
317     }
318
319     /*
320      * New implementation to interpret status with empty LTP List as notConnected => return false
321      * 30.10.2018 Since this behavior is very specific and implicit for specific NE Types
322      *     it needs to be activated by extension or configuration. Change to be disabled at the moment
323      */
324     @Override
325     public boolean checkIfConnectionToNeIsOk() {
326         return true;
327     }
328
329     /*---------------------------------------------------------------
330      * Synchronization
331      */
332
333
334     /*---------------------------------------------------------------
335      * Equipment related functions
336      */
337
338     @Override
339     public @NonNull InventoryInformationDcae getInventoryInformation(String layerProtocolFilter) {
340         LOG.debug("request inventory information. filter:" + layerProtocolFilter);
341         return this.equipment.getInventoryInformation(getFilteredInterfaceUuidsAsStringList(layerProtocolFilter));
342     }
343
344     @Override
345     public InventoryInformationDcae getInventoryInformation() {
346         return getInventoryInformation(null);
347     }
348
349     protected List<String> getFilteredInterfaceUuidsAsStringList(String layerProtocolFilter) {
350         List<String> uuids = new ArrayList<>();
351
352         LOG.debug("request inventory information. filter:" + layerProtocolFilter);
353         if (optionalNe != null) {
354             // uuids
355             for (Lp lp : this.interfaceList) {
356                 if (layerProtocolFilter == null || layerProtocolFilter.isEmpty()) {
357                     uuids.add(Helper.nnGetUniversalId(lp.getUuid()).getValue());
358                 } else if (layerProtocolFilter.equals(Helper.nnGetLayerProtocolName(lp.getLayerProtocolName()).getValue())) {
359                     uuids.add(Helper.nnGetUniversalId(lp.getUuid()).getValue());
360                 }
361             }
362         }
363         LOG.debug("uuids found: {}", uuids);
364         return uuids;
365     }
366
367
368     /*---------------------------------------------------------------
369      * Performancemanagement specific interface
370      */
371
372     @Override
373     public void resetPMIterator() {
374         synchronized (pmLock) {
375             interfaceListIterator = interfaceList.iterator();
376         }
377         LOG.debug("PM reset iterator");
378     }
379
380     @SuppressWarnings("null")
381     @Override
382     public boolean hasNext() {
383         boolean res;
384         synchronized (pmLock) {
385             res = interfaceListIterator != null ? interfaceListIterator.hasNext() : false;
386         }
387         LOG.debug("PM hasNext LTP {}", res);
388         return res;
389     }
390
391     @SuppressWarnings("null")
392     @Override
393     public void next() {
394         synchronized (pmLock) {
395             if (interfaceListIterator == null) {
396                 pmLp = null;
397                 LOG.debug("PM next LTP null");
398             } else {
399                 pmLp = interfaceListIterator.next();
400                 LOG.debug("PM next LTP {}", Helper.nnGetLayerProtocolName(pmLp.getLayerProtocolName()).getValue());
401             }
402         }
403     }
404
405     @SuppressWarnings("null")
406     @Override
407     public String pmStatusToString() {
408         StringBuffer res = new StringBuffer();
409         synchronized (pmLock) {
410             res.append(pmLp == null ? "no interface" : Helper.nnGetLayerProtocolName(pmLp.getLayerProtocolName()).getValue());
411             for (Lp lp : getInterfaceList()) {
412                 res.append("IF:");
413                 res.append(Helper.nnGetLayerProtocolName(lp.getLayerProtocolName()).getValue());
414                 res.append(" ");
415             }
416         }
417         return res.toString();
418     }
419
420     @Override
421     public void doRegisterEventListener(MountPoint mountPoint) {
422         //Do nothing
423     }
424
425     @SuppressWarnings("unchecked")
426     @Override
427     public <L extends NetworkElementService> Optional<L> getService(Class<L> clazz) {
428         return clazz.isInstance(this) ? Optional.of((L)this) : Optional.empty();
429     }
430
431     @Override
432     public Optional<PerformanceDataLtp> getLtpHistoricalPerformanceData() {
433         return Optional.empty();
434     }
435
436 }