2aa8dd99b14bf94db57ecc0e35699e8ede74cd20
[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.base.netconf;
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.concurrent.CopyOnWriteArrayList;
25
26 import javax.annotation.Nonnull;
27 import javax.annotation.Nullable;
28
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.InternalDateAndTime;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.InternalSeverity;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.InventoryInformation;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.container.AllPm;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.container.Capabilities;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.util.GenericTransactionUtils;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.wrapperc.WrapperPTPModelRev170208;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml;
37 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
38 import org.opendaylight.controller.md.sal.binding.api.MountPoint;
39 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ptp.dataset.rev170208.InstanceList;
41 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.NetworkElement;
42 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.UniversalId;
43 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.extension.g.Extension;
44 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.logical.termination.point.g.Lp;
45 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.network.element.Ltp;
46 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.NetworkElementPac;
47 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.network.element.pac.NetworkElementCurrentProblems;
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 @SuppressWarnings("deprecation")
59 public abstract class ONFCoreNetworkElement12Base extends ONFCoreNetworkElementBase implements ONFCoreNetworkElementCoreData {
60
61     private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12Base.class);
62
63     protected static final List<Extension> EMPTYLTPEXTENSIONLIST = new ArrayList<>();
64     // private static final List<Ltp> EMPTYLTPLIST = new ArrayList<>();
65
66     protected static final InstanceIdentifier<NetworkElement> NETWORKELEMENT_IID = InstanceIdentifier
67             .builder(NetworkElement.class).build();
68
69
70     /*-----------------------------------------------------------------------------
71      * Class members
72      */
73
74     // Non specific part. Used by all functions.
75     /** interfaceList is used by PM task and should be synchronized */
76     private final @Nonnull List<Lp> interfaceList = Collections.synchronizedList(new CopyOnWriteArrayList<>());
77     private @Nullable NetworkElement optionalNe = null;
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     private final ONFCoreNetworkElement12Equipment equipment;
93
94     private @Nonnull InventoryInformation inventoryInformation = new InventoryInformation();
95
96     /*
97      * Constructor
98      */
99
100     protected ONFCoreNetworkElement12Base(String mountPointNodeName, DataBroker netconfNodeDataBroker,
101             Capabilities capabilities) {
102         super(mountPointNodeName, netconfNodeDataBroker, capabilities);
103         // TODO Auto-generated constructor stub
104         this.isNetworkElementCurrentProblemsSupporting12 = capabilities.isSupportingNamespaceAndRevision(NetworkElementPac.QNAME);
105         this.equipment = new ONFCoreNetworkElement12Equipment(this, capabilities);
106         WrapperPTPModelRev170208.initSynchronizationExtension(mountPointNodeName, netconfNodeDataBroker, capabilities);
107         LOG.debug("support necurrent-problem-list=" + this.isNetworkElementCurrentProblemsSupporting12);
108         LOG.info("Create NE instance {}", InstanceList.QNAME.getLocalName());
109     }
110
111     /*---------------------------------------------------------------
112      * Getter/ Setter
113      */
114
115     @Override
116     public NetworkElement getOptionalNetworkElement() {
117         return optionalNe;
118     }
119
120         List<Lp> getInterfaceList() {
121                 return interfaceList;
122         }
123
124     public Object getPmLock() {
125                 return pmLock;
126         }
127
128     public ONFCoreNetworkElement12Equipment getEquipment() {
129         return equipment;
130     }
131
132     /*---------------------------------------------------------------
133      * Core model related function
134      */
135
136         /**
137      * Read the NetworkElement part from database.
138      *
139      * @return Optional with NetworkElement or empty
140      */
141     @Nullable
142     private NetworkElement readNetworkElement() {
143         // Step 2.2: construct data and the relative iid
144         // The schema path to identify an instance is
145         // <i>CoreModel-CoreNetworkModule-ObjectClasses/NetworkElement</i>
146         // Read to the config data store
147         return GenericTransactionUtils.readData(getNetconfNodeDataBroker(), LogicalDatastoreType.OPERATIONAL,
148                 NETWORKELEMENT_IID);
149     }
150
151     /**
152      * Get uuid of Optional NE.
153      *
154      * @return Uuid or EMPTY String if optionNE is not available
155      */
156     protected String getUuId() {
157         String uuid = EMPTY;
158
159         try {
160             uuid = optionalNe != null ? optionalNe.getUuid() != null ? optionalNe.getUuid().getValue() : EMPTY : EMPTY;
161         } catch (NullPointerException e) {
162             // Unfortunately throws null pointer if not definied
163         }
164         return uuid;
165     }
166
167     /**
168      * Read from NetworkElement and verify LTPs have changed. If the NE has changed, update to the new
169      * structure. From initial state it changes also.
170      */
171     protected synchronized boolean readNetworkElementAndInterfaces() {
172
173         LOG.debug("Update mountpoint if changed {}", getMountPointNodeName());
174
175         optionalNe = GenericTransactionUtils.readData(getNetconfNodeDataBroker(), LogicalDatastoreType.OPERATIONAL,
176                 NETWORKELEMENT_IID);;
177         synchronized (pmLock) {
178             boolean change = false;
179
180             if (optionalNe == null) {
181                 LOG.debug("Unable to read NE data for mountpoint {}", getMountPointNodeName());
182                 if (!interfaceList.isEmpty()) {
183                     interfaceList.clear();
184                     interfaceListIterator = null;
185                     change = true;
186                 }
187
188             } else {
189                 LOG.debug("Mountpoint '{}' NE-Name '{}'", getMountPointNodeName(), optionalNe.getName());
190                 List<Lp> actualInterfaceList = getLtpList(optionalNe);
191                 if (!interfaceList.equals(actualInterfaceList)) {
192                     LOG.debug("Mountpoint '{}' Update LTP List. Elements {}", getMountPointNodeName(),
193                             actualInterfaceList.size());
194                     interfaceList.clear();
195                     interfaceList.addAll(actualInterfaceList);
196                     interfaceListIterator = null;
197                     change = true;
198                 }
199             }
200             return change;
201         }
202     }
203
204     /**
205      * Get List of UUIDs for conditional packages from Networkelement<br>
206      * Possible interfaces are:<br>
207      * MWPS, LTP(MWPS-TTP), MWAirInterfacePac, MicrowaveModel-ObjectClasses-AirInterface<br>
208      * ETH-CTP,LTP(Client), MW_EthernetContainer_Pac<br>
209      * MWS, LTP(MWS-CTP-xD), MWAirInterfaceDiversityPac,
210      * MicrowaveModel-ObjectClasses-AirInterfaceDiversity<br>
211      * MWS, LTP(MWS-TTP), ,MicrowaveModel-ObjectClasses-HybridMwStructure<br>
212      * MWS, LTP(MWS-TTP), ,MicrowaveModel-ObjectClasses-PureEthernetStructure<br>
213      *
214      * @param ne NetworkElement
215      * @return Id List, never null.
216      */
217
218     private static List<Lp> getLtpList(@Nullable NetworkElement ne) {
219
220         List<Lp> res = Collections.synchronizedList(new ArrayList<Lp>());
221
222         if (ne != null) {
223             List<Ltp> ltpRefList = ne.getLtp();
224             if (ltpRefList == null) {
225                 LOG.debug("DBRead NE-Interfaces: null");
226             } else {
227                 for (Ltp ltRefListE : ltpRefList) {
228                     List<Lp> lpList = ltRefListE.getLp();
229                     if (lpList == null) {
230                         LOG.debug("DBRead NE-Interfaces Reference List: null");
231                     } else {
232                         for (Lp ltp : lpList) {
233                             res.add(ltp);
234                         }
235                     }
236                 }
237             }
238         } else {
239             LOG.debug("DBRead NE: null");
240         }
241
242         // ---- Debug
243         if (LOG.isDebugEnabled()) {
244             StringBuffer strBuf = new StringBuffer();
245             for (Lp ltp : res) {
246                 if (strBuf.length() > 0) {
247                     strBuf.append(", ");
248                 }
249                 strBuf.append(ltp.getLayerProtocolName().getValue());
250                 strBuf.append(':');
251                 strBuf.append(ltp.getUuid().getValue());
252             }
253             LOG.debug("DBRead NE-Interfaces: {}", strBuf.toString());
254         }
255         // ---- Debug end
256
257         return res;
258     }
259
260     /**
261      * Read current problems of AirInterfaces and EthernetContainer according to NE status into DB
262      *
263      * @return List with all problems
264      */
265     protected List<ProblemNotificationXml> readAllCurrentProblemsOfNode() {
266
267         // Step 2.3: read the existing faults and add to DB
268         List<ProblemNotificationXml> resultList = new ArrayList<>();
269         int idxStart; // Start index for debug messages
270         UniversalId uuid;
271
272         synchronized (pmLock) {
273             for (Lp lp : interfaceList) {
274
275                 idxStart = resultList.size();
276                 uuid = lp.getUuid();
277                 ProblemNotificationXml.debugResultList(LOG, uuid.getValue(), resultList, idxStart);
278
279             }
280         }
281
282         // Step 2.4: Read other problems from mountpoint
283         if (isNetworkElementCurrentProblemsSupporting12) {
284             idxStart = resultList.size();
285             readNetworkElementCurrentProblems12(resultList);
286             ProblemNotificationXml.debugResultList(LOG, "CurrentProblems12", resultList, idxStart);
287         }
288
289         return resultList;
290
291     }
292
293         /**
294          * Reading problems for the networkElement V1.2
295          * @param resultList
296          * @return
297          */
298     private List<ProblemNotificationXml> readNetworkElementCurrentProblems12(List<ProblemNotificationXml> resultList) {
299
300         LOG.info("DBRead Get {} NetworkElementCurrentProblems12", getMountPointNodeName());
301
302         InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.NetworkElementPac> networkElementCurrentProblemsIID =
303                 InstanceIdentifier.builder(
304                         org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.NetworkElementPac.class)
305                         .build();
306
307         // Step 2.3: read to the config data store
308         NetworkElementPac problemPac;
309         NetworkElementCurrentProblems problems;
310         try {
311             problemPac = GenericTransactionUtils.readData(getNetconfNodeDataBroker(), LogicalDatastoreType.OPERATIONAL,
312                     networkElementCurrentProblemsIID);
313             problems = problemPac.getNetworkElementCurrentProblems();
314             if (problems == null) {
315                 LOG.debug("DBRead no NetworkElementCurrentProblems12");
316             } else if (problems.getCurrentProblemList() == null) {
317                 LOG.debug("DBRead empty CurrentProblemList12");
318             } else {
319                 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
320                         .getCurrentProblemList()) {
321                     resultList.add(new ProblemNotificationXml(getMountPointNodeName(), problem.getObjectReference(),
322                             problem.getProblemName(), InternalSeverity.valueOf(problem.getProblemSeverity()),
323                             problem.getSequenceNumber().toString(),
324                             InternalDateAndTime.valueOf(problem.getTimeStamp())));
325                 }
326             }
327         } catch (Exception e) {
328             LOG.warn("DBRead {} NetworkElementCurrentProblems12 not supported. Message '{}' ", getMountPointNodeName(),
329                     e.getMessage());
330         }
331         return resultList;
332     }
333
334     /*---------------------------------------------------------------
335      * Device Monitor
336      */
337
338         @Override
339     public boolean checkIfConnectionToMediatorIsOk() {
340         synchronized (dmLock) {
341             return optionalNe != null;
342         }
343     }
344
345     /*
346      * New implementation to interpret status with empty LTP List as notConnected => return false
347      * 30.10.2018 Since this behavior is very specific and implicit for specific NE Types
348      *     it needs to be activated by extension or configuration. Change to be disabled at the moment
349      */
350     @Override
351     public boolean checkIfConnectionToNeIsOk() {
352         return true;
353     }
354
355     /*---------------------------------------------------------------
356      * Synchronization
357      */
358
359
360
361     /*---------------------------------------------------------------
362      * Equipment related functions
363      */
364
365     @Override
366     public @Nonnull InventoryInformation getInventoryInformation(String layerProtocolFilter) {
367         LOG.debug("request inventory information. filter:" + layerProtocolFilter);
368         return this.equipment.getInventoryInformation(getFilteredInterfaceUuidsAsStringList(layerProtocolFilter));
369     }
370
371         @Override
372         public InventoryInformation getInventoryInformation() {
373                 return getInventoryInformation(null);
374         }
375
376     protected List<String> getFilteredInterfaceUuidsAsStringList(String layerProtocolFilter) {
377         List<String> uuids = new ArrayList<>();
378
379         LOG.debug("request inventory information. filter:" + layerProtocolFilter);
380         if (optionalNe != null) {
381             // uuids
382             for (Lp lp : this.interfaceList) {
383                 if (layerProtocolFilter == null || layerProtocolFilter.isEmpty()) {
384                     uuids.add(lp.getUuid().getValue());
385                 } else if (lp.getLayerProtocolName() != null && lp.getLayerProtocolName().getValue() != null
386                         && lp.getLayerProtocolName().getValue().equals(layerProtocolFilter)) {
387                     uuids.add(lp.getUuid().getValue());
388                 }
389             }
390         }
391         LOG.debug("uuids found: {}", uuids);
392         return uuids;
393     }
394
395
396     /*---------------------------------------------------------------
397      * Performancemanagement specific interface
398      */
399
400     @Override
401     public void resetPMIterator() {
402         synchronized (pmLock) {
403             interfaceListIterator = interfaceList.iterator();
404         }
405         LOG.debug("PM reset iterator");
406     }
407
408     @Override
409     public boolean hasNext() {
410         boolean res;
411         synchronized (pmLock) {
412             res = interfaceListIterator != null ? interfaceListIterator.hasNext() : false;
413         }
414         LOG.debug("PM hasNext LTP {}", res);
415         return res;
416     }
417
418     @Override
419     public void next() {
420         synchronized (pmLock) {
421             if (interfaceListIterator == null) {
422                 pmLp = null;
423                 LOG.debug("PM next LTP null");
424             } else {
425                 pmLp = interfaceListIterator.next();
426                 LOG.debug("PM next LTP {}", pmLp.getLayerProtocolName().getValue());
427             }
428         }
429     }
430
431     @Override
432     public String pmStatusToString() {
433         StringBuffer res = new StringBuffer();
434         synchronized (pmLock) {
435             res.append(pmLp == null ? "no interface" : pmLp.getLayerProtocolName().getValue());
436             for (Lp lp : getInterfaceList()) {
437                 res.append("IF:");
438                 res.append(lp.getLayerProtocolName().getValue());
439                 res.append(" ");
440             }
441         }
442         return res.toString();
443     }
444
445         @Override
446         public AllPm getHistoricalPM() {
447         return AllPm.getEmpty();
448         }
449
450
451         @Override
452         public void doRegisterMicrowaveEventListener(MountPoint mountPoint) {
453         //Do nothing
454         }
455
456
457 }