35f7dcb709a40bc097112632185d045b3bc428be
[ccsdk/apps.git] / sdnr / wireless-transport / code-Carbon-SR1 / apps / devicemanager / impl / src / main / java / org / opendaylight / mwtn / base / netconf / ONFCoreNetworkElement10.java
1 /*
2 * Copyright (c) 2017 highstreet technologies GmbH and others. All rights reserved.
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
7 */
8
9 package org.opendaylight.mwtn.base.netconf;
10
11 import java.util.ArrayList;
12 import java.util.Collections;
13 import java.util.Iterator;
14 import java.util.List;
15 import java.util.concurrent.CopyOnWriteArrayList;
16
17 import javax.annotation.Nonnull;
18 import javax.annotation.Nullable;
19
20 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
21 import org.opendaylight.controller.md.sal.binding.api.MountPoint;
22 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
23 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
24 import org.opendaylight.mwtn.base.internalTypes.InternalDateAndTime;
25 import org.opendaylight.mwtn.base.internalTypes.InternalSeverity;
26 import org.opendaylight.mwtn.base.internalTypes.InventoryInformation;
27 import org.opendaylight.mwtn.devicemanager.impl.ProviderClient;
28 import org.opendaylight.mwtn.devicemanager.impl.database.service.HtDatabaseEventsService;
29 import org.opendaylight.mwtn.devicemanager.impl.listener.MicrowaveEventListener;
30 import org.opendaylight.mwtn.devicemanager.impl.xml.ProblemNotificationXml;
31 import org.opendaylight.mwtn.devicemanager.impl.xml.WebSocketServiceClient;
32 import org.opendaylight.mwtn.performancemanager.impl.database.types.EsHistoricalPerformance15Minutes;
33 import org.opendaylight.mwtn.performancemanager.impl.database.types.EsHistoricalPerformance24Hours;
34 import org.opendaylight.yang.gen.v1.uri.onf.coremodel.corefoundationmodule.superclassesandcommonpackages.rev160710.UniversalId;
35 import org.opendaylight.yang.gen.v1.uri.onf.coremodel.corefoundationmodule.superclassesandcommonpackages.rev160710.extension.ExtensionList;
36 import org.opendaylight.yang.gen.v1.uri.onf.coremodel.corenetworkmodule.objectclasses.rev160811.NetworkElement;
37 import org.opendaylight.yang.gen.v1.uri.onf.coremodel.corenetworkmodule.objectclasses.rev160811.logicalterminationpoint.LpList;
38 import org.opendaylight.yang.gen.v1.uri.onf.coremodel.corenetworkmodule.objectclasses.rev160811.networkelement.LtpRefList;
39 import org.opendaylight.yang.gen.v1.uri.onf.g_874_1_model.object_classes.rev160710.OTNHistoryData;
40 import org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.networkelement.currentproblemlist.rev161120.GenericCurrentProblemType;
41 import org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.networkelement.currentproblemlist.rev161120.NetworkElementCurrentProblems;
42 import org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.networkelement.currentproblemlist.rev161120.networkelementcurrentproblems.CurrentProblemList;
43 import org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.objectclasses.airinterface.rev160901.MWAirInterfacePac;
44 import org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.objectclasses.airinterface.rev160901.MWAirInterfacePacKey;
45 import org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.objectclasses.airinterface.rev160901.mw_airinterface_pac.AirInterfaceConfiguration;
46 import org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.objectclasses.airinterface.rev160901.mw_airinterface_pac.AirInterfaceCurrentProblems;
47 import org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.objectclasses.airinterface.rev160901.mw_airinterface_pac.AirInterfaceHistoricalPerformances;
48 import org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.objectclasses.ethernetcontainer.rev160902.MWEthernetContainerPac;
49 import org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.objectclasses.ethernetcontainer.rev160902.MWEthernetContainerPacKey;
50 import org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.objectclasses.ethernetcontainer.rev160902.mw_ethernetcontainer_pac.EthernetContainerCurrentProblems;
51 import org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.objectclasses.ethernetcontainer.rev160902.mw_ethernetcontainer_pac.EthernetContainerHistoricalPerformances;
52 import org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.typedefinitions.rev160902.AirInterfaceCurrentProblemType;
53 import org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.typedefinitions.rev160902.ContainerCurrentProblemType;
54 import org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.typedefinitions.rev160902.ContainerHistoricalPerformanceType;
55 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
56 import org.slf4j.Logger;
57 import org.slf4j.LoggerFactory;
58
59 import com.google.common.base.Optional;
60
61 /**
62  * Get information over NETCONF device according to ONF Coremodel. Read networkelement and conditional packages.
63  *
64  * Get conditional packages from Networkelement
65  * Possible interfaces are:
66  *   MWPS, LTP(MWPS-TTP), MWAirInterfacePac, MicrowaveModel-ObjectClasses-AirInterface
67  *   ETH-CTP,LTP(Client), MW_EthernetContainer_Pac
68  *   MWS, LTP(MWS-CTP-xD), MWAirInterfaceDiversityPac, MicrowaveModel-ObjectClasses-AirInterfaceDiversity
69  *   MWS, LTP(MWS-TTP), ,MicrowaveModel-ObjectClasses-HybridMwStructure
70  *   MWS, LTP(MWS-TTP), ,MicrowaveModel-ObjectClasses-PureEthernetStructure
71  *
72  * @author herbert
73  *
74  */
75 public class ONFCoreNetworkElement10 extends ONFCoreNetworkElementBase {
76
77     private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElementRepresentation.class);
78
79     private static final InstanceIdentifier<NetworkElement> NETWORKELEMENT_IID = InstanceIdentifier
80             .builder(NetworkElement.class)
81             .build();
82
83     /*-----------------------------------------------------------------------------
84      * Class members
85      */
86
87     // Non specific part. Used by all functions.
88     /** interfaceList is used by performance monitoring (pm) task and should be synchronized */
89     private final @Nonnull List<LpList> interfaceList = Collections.synchronizedList(new CopyOnWriteArrayList<>());
90     private final @Nonnull MicrowaveEventListener microwaveEventListener;
91     private @Nullable NetworkElement optionalNe = null;
92
93     // Performance monitoring specific part
94     /** Lock for the PM access specific elements that could be null */
95     private final @Nonnull Object pmLock = new Object();
96     private @Nullable Iterator<LpList> interfaceListIterator = null;
97     /** Actual pmLp used during iteration over interfaces */
98     private @Nullable LpList pmLp = null;
99
100     // Device monitoring specific part
101     /** Lock for the DM access specific elements that could be null */
102     private final @Nonnull Object dmLock = new Object();
103     /** Interface used for device monitoring (dm). If not null it contains the interface that is used for monitoring calls */
104     private @Nullable InstanceIdentifier<AirInterfaceCurrentProblems> dmAirIfCurrentProblemsIID = null;
105
106     /*------------------------------------------------------------------------
107      * Constructing
108      */
109
110     public ONFCoreNetworkElement10(String mountPointNodeName, Capabilities capabilities,
111             DataBroker netconfNodeDataBroker, WebSocketServiceClient webSocketService,
112             HtDatabaseEventsService databaseService, ProviderClient dcaeProvider ,@Nullable ProviderClient aotsmClient) {
113
114         super(mountPointNodeName, netconfNodeDataBroker, capabilities );
115
116         //Create MicrowaveService here
117         this.microwaveEventListener = new MicrowaveEventListener(mountPointNodeName, webSocketService, databaseService, dcaeProvider,aotsmClient);
118
119         LOG.info("Create NE instance {}", ONFCoreNetworkElement10.class.getSimpleName());
120     }
121
122     public static boolean checkType(Capabilities capabilities) {
123         return capabilities.isSupportingNamespace(NetworkElement.QNAME);
124     }
125
126     public static ONFCoreNetworkElement10 build(String mountPointNodeName, Capabilities capabilities,
127             DataBroker netconfNodeDataBroker, WebSocketServiceClient webSocketService,
128             HtDatabaseEventsService databaseService, ProviderClient dcaeProvider ,@Nullable ProviderClient aotsmClient) {
129
130         return checkType(capabilities) ? new ONFCoreNetworkElement10(mountPointNodeName, capabilities, netconfNodeDataBroker, webSocketService, databaseService, dcaeProvider ,aotsmClient) : null;
131
132     }
133
134
135     /*------------------------------------------------------------------------
136      * Functions
137      */
138
139     /**
140      * Have this as a separate function to avoid that representation is not created because of exceptions are thrown.
141      */
142     @Override
143     public void initialReadFromNetworkElement() {
144         LOG.debug("Get info about {}", mountPointNodeName);
145
146         int problems = microwaveEventListener.removeAllCurrentProblemsOfNode();
147         LOG.debug("Removed all {} problems from database at registration",problems);
148
149
150         //Step 2.1: access data broker within this mount point
151         LOG.debug("DBRead start");
152         //Step 2.2: read NEtworkElement from data store and initialize class variables
153         readNetworkElementAndInterfaces();
154
155         //Step 2.3: read the existing faults and add to DB
156         int problemsFound = readAllCurrentProblemsToDB();
157
158         LOG.info("Found info at {} for device {} number of problems: {}", mountPointNodeName, getUuId(), problemsFound);
159
160     }
161
162     /*------------------------------------------------------------
163      * private function to access database
164      */
165
166     /**
167      * Read from NetworkElement and verify LTPs have changed.
168      * If the NE has changed, update to the new structure.
169      * From initial state it changes also.
170      */
171     private synchronized boolean readNetworkElementAndInterfaces() {
172
173         LOG.debug("Update mountpoint if changed {}", mountPointNodeName);
174
175         //get NE data
176         synchronized (pmLock) {
177             boolean change = false;
178
179             optionalNe = GenericTransactionUtils.readData(netconfNodeDataBroker, LogicalDatastoreType.OPERATIONAL, NETWORKELEMENT_IID);
180             if (optionalNe == null) {
181                 LOG.debug("Unable to read NE data for mountpoint {}", mountPointNodeName);
182                 if (! interfaceList.isEmpty()) {
183                     interfaceList.clear();
184                     interfaceListIterator = null;
185                     change = true;
186                 }
187             } else {
188                 LOG.debug("Mountpoint '{}' NE-Name '{}'", mountPointNodeName, optionalNe.getNameList().toString());
189                 List<LpList> actualInterfaceList = getLtpList(optionalNe);
190                 if (! interfaceList.equals(actualInterfaceList) ) {
191                     LOG.debug("Mountpoint '{}' Update LTP List. Elements {}", mountPointNodeName, actualInterfaceList.size() );
192                     interfaceList.clear();
193                     interfaceList.addAll(actualInterfaceList);
194                     interfaceListIterator = null;
195                     change = true;
196                 }
197             }
198             return change;
199         }
200     }
201
202     /**
203      * Get UUID as string from networkelemen
204      * @return UUID or EMPTY
205      */
206     private String getUuId() {
207         String uuid = EMPTY;
208
209         try {
210             uuid = optionalNe != null ? optionalNe.getUuid() != null ? optionalNe.getUuid().getValue() : EMPTY : EMPTY;
211         } catch (NullPointerException  e) {
212             //Unfortunately throws null pointer if not definied
213         }
214         return uuid;
215     }
216
217     /**
218      * Read current problems of AirInterfaces and EthernetContainer
219      * according to NE status into DB
220      * @return Number of problems
221      */
222     private int readAllCurrentProblemsToDB() {
223
224         int problemsFound = 0;
225
226         synchronized (pmLock) {
227             for (LpList lp : interfaceList) {
228                 if (ONFLayerProtocolName.MWAirInterface.is(lp.getLayerProtocolName())) {
229                     //if (ltp.getLayerProtocolName().getValue().contains("MWPS")) {
230                     problemsFound += readTheFaultsOfMWAirInterfacePac(lp.getUuid());
231                     synchronized (dmLock) {
232                         if (dmAirIfCurrentProblemsIID == null) {
233                             dmAirIfCurrentProblemsIID = getMWAirInterfacePacIId(lp.getUuid());
234                         }
235                     }
236                 }
237                 if (ONFLayerProtocolName.EthernetContainer10.is(lp.getLayerProtocolName())) {
238                     //if (ltp.getLayerProtocolName().getValue().contains("ETH")) {
239                     problemsFound += readTheFaultsOfMWEthernetContainerPac(lp.getUuid());
240                 }
241             }
242         }
243
244         //Step 2.4: Read other problems from Mountpoint
245         if (isNetworkElementCurrentProblemsSupporting10) {
246             problemsFound += readNetworkElementCurrentProblems();
247         }
248
249         return problemsFound;
250     }
251
252     /**
253      * Read currentProblems of network elemement
254      * @return number of listed problems<br>
255      *
256      * <br>EXAMPLE from log:<br>
257      * karaf.log:2016-12-05 16:36:15,764 | INFO  | dispatcher-25390 | EventManagerImpl                 | 346 - org.opendaylight.mwtn.eventmanager-impl - 0.3.0.SNAPSHOT | DBRead
258      * Currentproblems: NetworkElementCurrentProblems{getCurrentProblemList=[
259      *   CurrentProblemList{
260      *      getProblemName=powerLoss, getProblemSeverity=Critical, getSequenceNumber=1,
261      *      getTimeStamp=DateAndTime [_value=20160822133005.0Z], augmentations={}},
262      *      CurrentProblemList{
263      *          getProblemName=powerLoss,
264      *          getProblemSeverity=Minor,
265      *          getSequenceNumber=2,
266      *          getTimeStamp=DateAndTime [_value=20160822143005.0Z], augmentations={}}],  augmentations={}}
267      *
268      *          cpl(2),
269      *             powerLoss[CurrentProblemList{getProblemName=powerLoss, getProblemSeverity=Critical, getSequenceNumber=1, getTimeStamp=DateAndTime [_value=20160822133005.0Z], augmentations={}}],
270      *             powerLoss[CurrentProblemList{getProblemName=powerLoss, getProblemSeverity=Minor, getSequenceNumber=2, getTimeStamp=DateAndTime [_value=20160822143005.0Z], augmentations={}}]
271      */
272
273     private int readNetworkElementCurrentProblems() {
274
275         int problemsFound = 0;
276         LOG.info("DBRead Get {} NetworkElementCurrentProblems", mountPointNodeName);
277
278         InstanceIdentifier<NetworkElementCurrentProblems> networkElementCurrentProblemsIID = InstanceIdentifier
279                 .builder(NetworkElementCurrentProblems.class)
280                 .build();
281
282         //Step 2.3: read to the config data store
283         NetworkElementCurrentProblems problems;
284         try {
285             problems = GenericTransactionUtils.readData(netconfNodeDataBroker, LogicalDatastoreType.OPERATIONAL, networkElementCurrentProblemsIID);
286             if (problems == null) {
287                 LOG.debug("DBRead NetworkElementCurrentProblems no CurrentProblemsList");
288             } else {
289                 List<CurrentProblemList> cpl = problems.getCurrentProblemList();
290                 LOG.debug("DBRead NetworkElementCurrentProblems input: {}", cpl);
291
292                 if (cpl != null) {
293                     List<ProblemNotificationXml> resultList = new ArrayList<>();
294                     for(GenericCurrentProblemType problem : cpl) {
295                         resultList.add(new ProblemNotificationXml(mountPointNodeName, problem.getObjectIdRef(),
296                                 problem.getProblemName(), InternalSeverity.valueOf(problem.getProblemSeverity()),
297                                 problem.getSequenceNumber().toString(), InternalDateAndTime.valueOf(problem.getTimeStamp())));
298
299                     }
300                     microwaveEventListener.initCurrentProblem(resultList);
301                     LOG.debug("DBRead NetworkElementCurrentProblems result: {}",resultList);
302                     problemsFound = resultList.size();
303                 }
304             }
305         } catch (Exception e) {
306             LOG.warn( "DBRead {} NetworkElementCurrentProblems not supported. Message '{}' ", mountPointNodeName, e.getMessage() );
307         }
308         return problemsFound;
309     }
310
311
312     /*
313     /**
314      * Read the NetworkElement part from database.
315      * @return NetworkElement or null
316      * /
317     private NetworkElement readNetworkElement() {
318         //Step 2.2: construct data and the relative iid
319         // The schema path to identify an instance is
320         // <i>CoreModel-CoreNetworkModule-ObjectClasses/NetworkElement</i>
321
322         //InstanceIdentifier<NetworkElement> networkElementIID = InstanceIdentifier
323         //       .builder(NetworkElement.class)
324         //       .build();
325
326         //Step 2.3: read to the config data store
327         return GenericTransactionUtils.readData(netconfNodeDataBroker, LogicalDatastoreType.OPERATIONAL, NETWORKELEMENT_IID);
328     } */
329
330     /**
331      * Prepare check by updating NE state and reading all interfaces.
332      * @see org.opendaylight.mwtn.deviceMonitor.impl.DeviceMonitorSupport#prepareCheck()
333      */
334     @Override
335     public void prepareCheck() {
336         synchronized (dmLock) {
337             boolean change = readNetworkElementAndInterfaces();
338             if (change) {
339                 int problems = microwaveEventListener.removeAllCurrentProblemsOfNode();
340                 int problemsFound = readAllCurrentProblemsToDB();
341                 LOG.info("Resync mountpoint {} for device {}. Removed {}. Current problems: {}", mountPointNodeName, getUuId(), problems, problemsFound);
342             }
343         }
344     }
345
346     /**
347      * New implementation
348      * @see org.opendaylight.mwtn.deviceMonitor.impl.DeviceMonitorSupport#checkAndConnectionToMediatorIsOk()
349      */
350     @Override
351     public boolean checkAndConnectionToMediatorIsOk() {
352         synchronized (dmLock) {
353             return optionalNe != null;
354         }
355     }
356
357     /**
358      * New implementation to interpret status with empty LTP List as notConnected => false
359      * @see org.opendaylight.mwtn.deviceMonitor.impl.DeviceMonitorSupport#checkAndConnectionToNeIsOk()
360      */
361     @Override
362     public boolean checkAndConnectionToNeIsOk() {
363         synchronized (dmLock) {
364             return optionalNe != null && !interfaceList.isEmpty();
365         }
366
367     }
368
369     /* OLD:public boolean checkAndConnectionToNeIsOk() {
370         synchronized (dmLock) {
371            if (dmAirIfCurrentProblemsIID != null) {
372               //Read to the config data store
373               AtomicBoolean noErrorIndicator = new AtomicBoolean();
374               AtomicReference<String> status = new AtomicReference<>();
375
376               GenericTransactionUtils.readDataOptionalWithStatus(netconfNodeDataBroker, LogicalDatastoreType.OPERATIONAL, dmAirIfCurrentProblemsIID, noErrorIndicator, status);
377               LOG.debug("Status noErrorIndicator: {} statusTxt:{}",noErrorIndicator.get(), status.get());
378               return noErrorIndicator.get();
379            }
380         }
381
382         return true;
383         }
384     */
385
386     /**
387      * Get List of UUIDs for conditional packages from Networkelement<br>
388      * Possible interfaces are:<br>
389      *   MWPS, LTP(MWPS-TTP), MWAirInterfacePac, MicrowaveModel-ObjectClasses-AirInterface<br>
390      *   ETH-CTP,LTP(Client), MW_EthernetContainer_Pac<br>
391      *   MWS, LTP(MWS-CTP-xD), MWAirInterfaceDiversityPac, MicrowaveModel-ObjectClasses-AirInterfaceDiversity<br>
392      *   MWS, LTP(MWS-TTP), ,MicrowaveModel-ObjectClasses-HybridMwStructure<br>
393      *   MWS, LTP(MWS-TTP), ,MicrowaveModel-ObjectClasses-PureEthernetStructure<br>
394      * @param ne Networkelement
395      * @return Id List, never null.
396      */
397     private static List<LpList> getLtpList( @Nullable NetworkElement ne ) {
398
399         List<LpList> res = new ArrayList<>();
400
401         if (ne != null) {
402             List<LtpRefList> ltpRefList = ne.getLtpRefList();
403             if (ltpRefList == null) {
404                 LOG.debug("DBRead NE-Interfaces: null");
405             } else {
406                 for (LtpRefList ltRefListE : ltpRefList ) {
407                     List<LpList> lpList = ltRefListE.getLpList();
408                     if (lpList == null) {
409                         LOG.debug("DBRead NE-Interfaces Reference List: null");
410                     } else {
411                         for (LpList lp : lpList) {
412                             ////LayerProtocolName layerProtocolName = lpListE.getLayerProtocolName();
413                             //UniversalId uuId = lpListE.getUuid();
414                             res.add(lp);
415                         }
416                     }
417                 }
418             }
419         } else {
420             LOG.debug("DBRead NE: null");
421         }
422
423         //---- Debug
424         if (LOG.isDebugEnabled()) {
425             StringBuffer strBuf = new StringBuffer();
426             for (LpList ltp : res) {
427                 if (strBuf.length() > 0) {
428                     strBuf.append(", ");
429                 }
430                 strBuf.append(ltp.getLayerProtocolName().getValue());
431                 strBuf.append(':');
432                 strBuf.append(ltp.getUuid().getValue());
433             }
434             LOG.debug("DBRead NE-Interfaces: {}", strBuf.toString());
435         }
436         //---- Debug end
437
438         return res;
439     }
440
441      private int readTheFaultsOfMWEthernetContainerPac(UniversalId interfacePacUuid) {
442
443         int problemsFound = 0;
444         LOG.info("DBRead Get {} MWEthernetContainerPac: {}", mountPointNodeName, interfacePacUuid.getValue());
445
446         //Step 2.2: construct data and the relative iid
447         InstanceIdentifier<EthernetContainerCurrentProblems> mwEthInterfaceIID = InstanceIdentifier
448                 .builder(MWEthernetContainerPac.class, new MWEthernetContainerPacKey(interfacePacUuid))
449                 .child(EthernetContainerCurrentProblems.class)
450                 .build();
451
452         //Step 2.3: read to the config data store
453         EthernetContainerCurrentProblems ethProblems = GenericTransactionUtils.readData(netconfNodeDataBroker, LogicalDatastoreType.OPERATIONAL, mwEthInterfaceIID);
454         if (ethProblems == null) {
455             LOG.debug("DBRead EthProblems Id {} no EthernetContainerCurrentProblems", interfacePacUuid.getValue());
456         } else if (ethProblems.getCurrentProblemList() == null) {
457             LOG.debug("DBRead Id {} empty CurrentProblemsList", interfacePacUuid.getValue());
458         } else {
459             List<ProblemNotificationXml> resultList = new ArrayList<>();
460             for ( ContainerCurrentProblemType problem : ethProblems.getCurrentProblemList()) {
461                 resultList.add(new ProblemNotificationXml(mountPointNodeName, interfacePacUuid.getValue(),
462                         problem.getProblemName(), InternalSeverity.valueOf(problem.getProblemSeverity()),
463                         problem.getSequenceNumber().toString(), InternalDateAndTime.valueOf(problem.getTimeStamp())));
464
465             }
466             microwaveEventListener.initCurrentProblem(resultList);
467             LOG.debug("DBRead EthProblems result: {}",resultList);
468             problemsFound = resultList.size();
469         }
470         return problemsFound;
471      }
472
473      /**
474       * Deliver for specific AirInterfacePac with key the related IId
475       * @param interfacePacUuid as UniversalId
476       * @return related InstanceIdentifier
477       */
478      private InstanceIdentifier<AirInterfaceCurrentProblems> getMWAirInterfacePacIId(UniversalId interfacePacUuid) {
479          InstanceIdentifier<AirInterfaceCurrentProblems> mwAirInterfaceIID = InstanceIdentifier
480                  .builder(MWAirInterfacePac.class, new MWAirInterfacePacKey(interfacePacUuid))
481                  .child(AirInterfaceCurrentProblems.class)
482                  .build();
483          return mwAirInterfaceIID;
484      }
485
486      private int readTheFaultsOfMWAirInterfacePac(UniversalId interfacePacUuid) {
487
488          int problemsFound = 0;
489          LOG.info("DBRead Get {} MWAirInterfacePac: {}", mountPointNodeName, interfacePacUuid.getValue());
490          //----
491          //Step 2.2: construct data and the relative iid
492
493          InstanceIdentifier<AirInterfaceCurrentProblems> mwAirInterfaceIID = getMWAirInterfacePacIId(interfacePacUuid);
494
495          //Step 2.3: read to the config data store
496          AirInterfaceCurrentProblems airProblems = GenericTransactionUtils.readData(netconfNodeDataBroker, LogicalDatastoreType.OPERATIONAL, mwAirInterfaceIID);
497
498          if (airProblems == null) {
499              LOG.debug("DBRead Id {} no AirInterfaceCurrentProblems", interfacePacUuid);
500          } else if (airProblems.getCurrentProblemList() == null) {
501              LOG.debug("DBRead Id {} no CurrentProblemList", interfacePacUuid);
502          } else {
503              List<ProblemNotificationXml> resultList = new ArrayList<>();
504              for ( AirInterfaceCurrentProblemType problem : airProblems.getCurrentProblemList()) {
505                  resultList.add(new ProblemNotificationXml(mountPointNodeName, interfacePacUuid.getValue(),
506                          problem.getProblemName(), InternalSeverity.valueOf(problem.getProblemSeverity()),
507                          problem.getSequenceNumber().toString(), InternalDateAndTime.valueOf(problem.getTimeStamp())));
508
509              }
510              microwaveEventListener.initCurrentProblem(resultList);
511              LOG.debug("DBRead AirProblems result: {}",resultList);
512              problemsFound = resultList.size();
513          }
514          return problemsFound;
515      }
516
517      public List<ExtendedAirInterfaceHistoricalPerformanceType> readTheHistoricalPerformanceDataOfMWAirInterfacePac(LpList lp) {
518
519          String uuId = lp.getUuid().getValue();
520
521          List<ExtendedAirInterfaceHistoricalPerformanceType> resultList = new ArrayList<>();
522          LOG.debug("DBRead Get {} MWAirInterfacePac: {}", mountPointNodeName, uuId);
523          //----
524          UniversalId mwAirInterfacePacuuId = new UniversalId(uuId);
525          //Step 2.1: construct data and the relative iid
526          InstanceIdentifier<AirInterfaceConfiguration> mwAirInterfaceConfigurationIID = InstanceIdentifier
527                  .builder(MWAirInterfacePac.class, new MWAirInterfacePacKey(mwAirInterfacePacuuId))
528                  .child(AirInterfaceConfiguration.class)
529                  .build();
530          AirInterfaceConfiguration airConfiguration = GenericTransactionUtils.readData(netconfNodeDataBroker, LogicalDatastoreType.OPERATIONAL, mwAirInterfaceConfigurationIID);
531
532          if (airConfiguration == null) {
533              LOG.debug("DBRead MWAirInterfacePac Id {} no AirInterfaceConfiguration", mwAirInterfacePacuuId);
534
535          } else {
536
537              //Step 2.2: construct data and the relative iid
538              InstanceIdentifier<AirInterfaceHistoricalPerformances> mwAirInterfaceHistoricalPerformanceIID = InstanceIdentifier
539                      .builder(MWAirInterfacePac.class, new MWAirInterfacePacKey(mwAirInterfacePacuuId))
540                      .child(AirInterfaceHistoricalPerformances.class)
541                      .build();
542
543              //Step 2.3: read to the config data store
544              AirInterfaceHistoricalPerformances airHistoricalPerformanceData = GenericTransactionUtils.readData(netconfNodeDataBroker, LogicalDatastoreType.OPERATIONAL, mwAirInterfaceHistoricalPerformanceIID);
545
546              if (airHistoricalPerformanceData == null) {
547                  LOG.debug("DBRead MWAirInterfacePac Id {} no AirInterfaceHistoricalPerformances", mwAirInterfacePacuuId);
548
549              } else {
550                  List<org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.objectclasses.airinterface.rev160901.airinterfacehistoricalperformances.HistoricalPerformanceDataList> airHistPMList = airHistoricalPerformanceData.getHistoricalPerformanceDataList();
551                  LOG.debug("DBRead MWAirInterfacePac Id {} Records intermediate: {}",mwAirInterfacePacuuId, airHistPMList.size());
552                  if (airHistPMList != null) {
553                      for ( org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.typedefinitions.rev160902.AirInterfaceHistoricalPerformanceType pmRecord : airHistPMList) {
554                          resultList.add(new ExtendedAirInterfaceHistoricalPerformanceType(pmRecord, airConfiguration));
555                      }
556                  }
557              }
558          }
559          LOG.debug("DBRead MWAirInterfacePac Id {} Records result: {}",mwAirInterfacePacuuId, resultList.size());
560          return resultList;
561      }
562
563      public List<ContainerHistoricalPerformanceType> readTheHistoricalPerformanceDataOfEthernetContainer(LpList lp) {
564
565          final String myName = "MWEthernetContainerPac";
566          String uuId = lp.getUuid().getValue();
567
568          List<ContainerHistoricalPerformanceType> resultList = new ArrayList<>();
569          LOG.debug("DBRead Get {} : {}", mountPointNodeName, myName,uuId);
570          //----
571          UniversalId ethContainerPacuuId = new UniversalId(uuId);
572          //Step 2.2: construct data and the relative iid
573          InstanceIdentifier<EthernetContainerHistoricalPerformances> ethContainerIID = InstanceIdentifier
574                  .builder(MWEthernetContainerPac.class, new MWEthernetContainerPacKey(ethContainerPacuuId))
575                  .child(EthernetContainerHistoricalPerformances.class)
576                  .build();
577
578          //Step 2.3: read to the config data store
579          EthernetContainerHistoricalPerformances ethContainerHistoricalPerformanceData = GenericTransactionUtils.readData(netconfNodeDataBroker, LogicalDatastoreType.OPERATIONAL, ethContainerIID);
580
581          if (ethContainerHistoricalPerformanceData == null) {
582              LOG.debug("DBRead {} Id {} no EthernetContainerHistoricalPerformances", myName, ethContainerPacuuId);
583          } else {
584              List<org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.objectclasses.ethernetcontainer.rev160902.ethernetcontainerhistoricalperformances.HistoricalPerformanceDataList> airHistPMList = ethContainerHistoricalPerformanceData.getHistoricalPerformanceDataList();
585              LOG.debug("DBRead {} Id {} Records intermediate: {}", myName, ethContainerPacuuId, airHistPMList.size());
586              if (airHistPMList != null) {
587                  for ( org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.typedefinitions.rev160902.ContainerHistoricalPerformanceType pmRecord : airHistPMList) {
588                      resultList.add(pmRecord);
589                  }
590              }
591          }
592          LOG.debug("DBRead {} Id {} Records result: {}", myName, ethContainerPacuuId, resultList.size());
593          return resultList;
594      }
595
596     private List<? extends OTNHistoryData> readTheHistoricalPerformanceData(LpList lp) {
597          ONFLayerProtocolName lpName = ONFLayerProtocolName.valueOf(lp.getLayerProtocolName());
598
599          switch( lpName ) {
600              case MWAirInterface:
601                  return readTheHistoricalPerformanceDataOfMWAirInterfacePac(lp);
602
603              case EthernetContainer10:
604                  return readTheHistoricalPerformanceDataOfEthernetContainer(lp);
605
606              case EthernetContainer12:
607              case EthernetPhysical:
608              case TDMContainer:
609              case Ethernet:
610              case Structure:
611              case Unknown:
612                  LOG.debug("Do not read HistoricalPM data for", lpName);
613                  break;
614          }
615          return new ArrayList<>();
616      }
617
618     @Override
619     public AllPm getHistoricalPM() {
620         synchronized ( pmLock ) {
621             if (pmLp != null) {
622                 AllPm allPm = new AllPm();
623                 LpList lp = pmLp;
624
625                 List<? extends OTNHistoryData> resultList = readTheHistoricalPerformanceData(lp);
626
627                 for (OTNHistoryData perf : resultList) {
628
629                     switch(perf.getGranularityPeriod()) {
630                     case PERIOD15MIN: {
631                         EsHistoricalPerformance15Minutes pm = new EsHistoricalPerformance15Minutes(mountPointNodeName, lp)
632                                 .setHistoricalRecord15Minutes(perf);
633                         allPm.add(pm);
634                     }
635                     break;
636
637                     case PERIOD24HOURS: {
638                         LOG.debug("Write 24h create");
639                         EsHistoricalPerformance24Hours pm = new EsHistoricalPerformance24Hours(mountPointNodeName, lp)
640                                 .setHistoricalRecord24Hours(perf);
641                         LOG.debug("Write 24h write to DB");
642                         allPm.add(pm);
643                     }
644
645                     break;
646                     default:
647                         LOG.warn("Unknown granularity {}",perf.getGranularityPeriod());
648                         break;
649                     }
650                 }
651                 return allPm;
652             } else {
653                 return AllPm.EMPTY;
654             }
655         }
656
657     }
658
659     @Override
660     public void resetPMIterator() {
661         synchronized ( pmLock ) {
662             interfaceListIterator = interfaceList.iterator();
663         }
664         LOG.debug("PM reset iterator");
665     }
666
667     @Override
668     public boolean hasNext() {
669         boolean res;
670         synchronized ( pmLock ) {
671             res = interfaceListIterator != null ? interfaceListIterator.hasNext(): false;
672         }
673         LOG.debug("PM hasNext LTP {}", res);
674         return res;
675     }
676
677     @Override
678     public void next() {
679         synchronized ( pmLock ) {
680             pmLp = interfaceListIterator != null ? interfaceListIterator.next() : null;
681         }
682         LOG.debug("PM next LTP {}", pmLp.getUuid().toString());
683     }
684
685     @Override
686     public String pmStatusToString() {
687         StringBuffer res = new StringBuffer();
688         synchronized ( pmLock ) {
689             res.append(pmLp == null ? "no interface" : pmLp.getLayerProtocolName().getValue());
690             for (LpList lp : interfaceList ) {
691                 res.append("IF:");
692                 res.append(lp.getLayerProtocolName().getValue());
693                 res.append(" ");
694             }
695         }
696         return(res.toString());
697     }
698
699     @Override
700     public int removeAllCurrentProblemsOfNode() {
701         return microwaveEventListener.removeAllCurrentProblemsOfNode();
702     }
703
704     @Override
705     public void doRegisterMicrowaveEventListener(MountPoint mountPoint) {
706         final Optional<NotificationService> optionalNotificationService = mountPoint.getService(NotificationService.class);
707         final NotificationService notificationService = optionalNotificationService.get();
708         notificationService.registerNotificationListener(microwaveEventListener);
709     }
710
711     @Override
712         public @Nonnull InventoryInformation getInventoryInformation() {
713         return this.getInventoryInformation(null);
714     }
715
716         @Override
717         public @Nonnull InventoryInformation getInventoryInformation(String layerProtocolFilter) {
718
719                 String type=InventoryInformation.UNKNOWN;
720                 String model=InventoryInformation.UNKNOWN;
721                 String vendor=InventoryInformation.UNKNOWN;
722                 String ipv4=InventoryInformation.UNKNOWN;
723                 String ipv6=InventoryInformation.UNKNOWN;
724                 List<String> uuids = new ArrayList<String>();
725                 LOG.debug("request inventory information. filter:"+layerProtocolFilter);
726
727                 if (optionalNe != null) {
728
729                         //uuids
730                         for(LpList lp : this.interfaceList)
731                         {
732                                 if(layerProtocolFilter==null || layerProtocolFilter.isEmpty())
733                                         uuids.add(lp.getUuid().getValue());
734                                 else if(lp.getLayerProtocolName()!=null &&
735                                         lp.getLayerProtocolName().getValue()!=null &&
736                                         lp.getLayerProtocolName().getValue().equals(layerProtocolFilter))
737                                 uuids.add(lp.getUuid().getValue());
738                         }
739                         //type
740                         List<ExtensionList> extensions = optionalNe.getExtensionList();
741                         if(extensions!=null)
742                         {
743                                 for(ExtensionList e: extensions)
744                                 {
745                                         if(e.getValueName()!=null)
746                                         {
747                                                 if(e.getValueName().equals("neIpAddress"))
748                                                 {
749                                                         ipv4=e.getValue();
750                                                         LOG.debug("ip information found: "+ipv4);
751                                                 }
752                                         }
753                                 }
754                                 if(ipv4==InventoryInformation.UNKNOWN)
755                         {
756                                 LOG.debug("no ip information found");
757                         }
758                         }
759                         else
760                 {
761                         LOG.debug("extension list is null");
762                 }
763                 }
764
765
766                 return new InventoryInformation(type, model, vendor, ipv4, ipv6, uuids);
767         }
768
769
770 }