Assign image keyname and pubkey at vnf level
[ccsdk/apps.git] / sdnr / wireless-transport / code-Carbon-SR1 / apps / devicemanager / impl / src / main / java / org / opendaylight / mwtn / base / netconf / ONFCoreNetworkElement12.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.lang.reflect.Constructor;
12 import java.lang.reflect.InvocationTargetException;
13 import java.util.ArrayList;
14 import java.util.Collections;
15 import java.util.Iterator;
16 import java.util.List;
17 import java.util.concurrent.CopyOnWriteArrayList;
18
19 import javax.annotation.Nonnull;
20 import javax.annotation.Nullable;
21
22 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
23 import org.opendaylight.controller.md.sal.binding.api.MountPoint;
24 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
25 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
26 import org.opendaylight.mwtn.base.internalTypes.InternalDateAndTime;
27 import org.opendaylight.mwtn.base.internalTypes.InternalSeverity;
28 import org.opendaylight.mwtn.base.internalTypes.InventoryInformation;
29 import org.opendaylight.mwtn.devicemanager.impl.ProviderClient;
30 import org.opendaylight.mwtn.devicemanager.impl.database.service.HtDatabaseEventsService;
31 import org.opendaylight.mwtn.devicemanager.impl.listener.MicrowaveEventListener12;
32 import org.opendaylight.mwtn.devicemanager.impl.xml.ProblemNotificationXml;
33 import org.opendaylight.mwtn.devicemanager.impl.xml.WebSocketServiceClient;
34 import org.opendaylight.mwtn.performancemanager.impl.database.types.EsHistoricalPerformance15Minutes;
35 import org.opendaylight.mwtn.performancemanager.impl.database.types.EsHistoricalPerformance24Hours;
36 //import org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.networkelement.currentproblemlist.rev161120.GenericCurrentProblemType;
37 //import org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.networkelement.currentproblemlist.rev161120.NetworkElementCurrentProblems;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ptp.dataset.rev170208.InstanceList;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ptp.dataset.rev170208.InstanceListKey;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ptp.dataset.rev170208.PortDsEntry;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ptp.dataset.rev170208.instance.list.PortDsList;
42 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ptp.dataset.rev170208.port.ds.entry.PortIdentity;
43 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.Equipment;
44 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.EquipmentKey;
45 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.NetworkElement;
46 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.UniversalId;
47 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.extension.g.Extension;
48 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.logical.termination.point.g.Lp;
49 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.network.element.Ltp;
50 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.g._874._1.model.rev170320.GranularityPeriodType;
51 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.g._874._1.model.rev170320.OtnHistoryDataG;
52 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.AirInterfaceCurrentProblemTypeG;
53 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.AirInterfaceDiversityCurrentProblemTypeG;
54 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.AirInterfaceHistoricalPerformanceTypeG;
55 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.ContainerCurrentProblemTypeG;
56 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.ContainerHistoricalPerformanceTypeG;
57 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.MwAirInterfaceDiversityPac;
58 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.MwAirInterfaceDiversityPacKey;
59 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.MwAirInterfacePac;
60 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.MwAirInterfacePacKey;
61 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.MwEthernetContainerPac;
62 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.MwEthernetContainerPacKey;
63 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.MwHybridMwStructurePac;
64 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.MwHybridMwStructurePacKey;
65 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.MwPureEthernetStructurePac;
66 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.MwPureEthernetStructurePacKey;
67 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.MwTdmContainerPac;
68 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.MwTdmContainerPacKey;
69 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.StructureCurrentProblemTypeG;
70 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.mw.air._interface.diversity.pac.AirInterfaceDiversityCurrentProblems;
71 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.mw.air._interface.pac.AirInterfaceConfiguration;
72 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.mw.air._interface.pac.AirInterfaceCurrentProblems;
73 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.mw.air._interface.pac.AirInterfaceHistoricalPerformances;
74 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.mw.ethernet.container.pac.EthernetContainerCurrentProblems;
75 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.mw.ethernet.container.pac.EthernetContainerHistoricalPerformances;
76 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.mw.hybrid.mw.structure.pac.HybridMwStructureCurrentProblems;
77 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.mw.pure.ethernet.structure.pac.PureEthernetStructureCurrentProblems;
78 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.mw.tdm.container.pac.TdmContainerCurrentProblems;
79 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.NetworkElementPac;
80 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.network.element.pac.NetworkElementCurrentProblems;
81 //import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.NetworkElementPac;
82 //import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.network.element.pac.NetworkElementCurrentProblems;
83 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.ethernet.conditional.packages.rev170402.EthernetPac;
84 import org.opendaylight.yangtools.concepts.ListenerRegistration;
85 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
86 import org.opendaylight.yangtools.yang.common.QName;
87 import org.slf4j.Logger;
88 import org.slf4j.LoggerFactory;
89
90 import com.google.common.base.Optional;
91
92 /**
93  * Get information over NETCONF device according to ONF Coremodel. Read
94  * networkelement and conditional packages.
95  *
96  * Get conditional packages from Networkelement Possible interfaces are: MWPS,
97  * LTP(MWPS-TTP), MWAirInterfacePac, MicrowaveModel-ObjectClasses-AirInterface
98  * ETH-CTP,LTP(Client), MW_EthernetContainer_Pac MWS, LTP(MWS-CTP-xD),
99  * MWAirInterfaceDiversityPac,
100  * MicrowaveModel-ObjectClasses-AirInterfaceDiversity MWS, LTP(MWS-TTP),
101  * ,MicrowaveModel-ObjectClasses-HybridMwStructure MWS, LTP(MWS-TTP),
102  * ,MicrowaveModel-ObjectClasses-PureEthernetStructure
103  *
104  * @author herbert
105  *
106  */
107 public class ONFCoreNetworkElement12 extends ONFCoreNetworkElementBase {
108
109         private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12.class);
110
111         private static final List<Extension> EMPTYLTPEXTENSIONLIST = new ArrayList<>();
112         // private static final List<Ltp> EMPTYLTPLIST = new ArrayList<>();
113
114         private static final InstanceIdentifier<NetworkElement> NETWORKELEMENT_IID = InstanceIdentifier
115                         .builder(NetworkElement.class).build();
116
117         private static final InstanceIdentifier<InstanceList> PTPINSTANCES_IID = InstanceIdentifier
118                         .builder(InstanceList.class, new InstanceListKey(1)).build();
119
120         /*-----------------------------------------------------------------------------
121          * Class members
122          */
123
124         // Non specific part. Used by all functions.
125         /** interfaceList is used by PM task and should be synchonized */
126         private final @Nonnull List<Lp> interfaceList = Collections.synchronizedList(new CopyOnWriteArrayList<>());
127         private final @Nonnull MicrowaveEventListener12 microwaveEventListener;
128         private @Nullable NetworkElement optionalNe = null;
129
130         // Performance monitoring specific part
131         /** Lock for the PM access specific elements that could be null */
132         private final @Nonnull Object pmLock = new Object();
133         private @Nullable Iterator<Lp> interfaceListIterator = null;
134         /** Actual pmLp used during iteration over interfaces */
135         private @Nullable Lp pmLp = null;
136
137         // Device monitoring specific part
138         /** Lock for the DM access specific elements that could be null */
139         private final @Nonnull Object dmLock = new Object();
140         /**
141          * Interface used for device monitoring (dm). If not null it contains the
142          * interface that is used for monitoring calls
143          */
144         private @Nullable InstanceIdentifier<AirInterfaceCurrentProblems> dmAirIfCurrentProblemsIID = null;
145         private final boolean isNetworkElementCurrentProblemsSupporting12;
146         private ListenerRegistration<MicrowaveEventListener12> listenerRegistrationresult;
147
148         /*-----------------------------------------------------------------------------
149          * Construction
150          */
151
152         /**
153          * Constructor
154          *
155          * @param mountPointNodeName
156          *            as String
157          * @param capabilities
158          *            of the specific network element
159          * @param netconfNodeDataBroker
160          *            for the network element specific data
161          * @param webSocketService
162          *            to forward event notifications
163          * @param databaseService
164          *            to access the database
165          * @param dcaeProvider
166          *            to forward problem / change notifications
167          */
168         private ONFCoreNetworkElement12(String mountPointNodeName, Capabilities capabilities,
169                         DataBroker netconfNodeDataBroker, WebSocketServiceClient webSocketService,
170                         HtDatabaseEventsService databaseService, ProviderClient dcaeProvider,
171                         @Nullable ProviderClient aotsmClient) {
172
173                 super(mountPointNodeName, netconfNodeDataBroker, capabilities);
174
175                 // Create MicrowaveService here
176                 this.microwaveEventListener = new MicrowaveEventListener12(mountPointNodeName, webSocketService,
177                                 databaseService, dcaeProvider, aotsmClient);
178                 this.isNetworkElementCurrentProblemsSupporting12 = capabilities.isSupportingNamespace(NetworkElementPac.QNAME);
179                 LOG.debug("support necurrent-problem-list=" + this.isNetworkElementCurrentProblemsSupporting12);
180                 LOG.info("Create NE instance {}", InstanceList.QNAME.getLocalName());
181         }
182
183         /**
184          * Check capabilities are matching the this specific implementation and create
185          * network element representation if so.
186          *
187          * @param mountPointNodeName
188          *            as String
189          * @param capabilities
190          *            of the specific network element
191          * @param netconfNodeDataBroker
192          *            for the network element specific data
193          * @param webSocketService
194          *            to forward event notifications
195          * @param databaseService
196          *            to access the database
197          * @param dcaeProvider
198          *            to forward problem / change notifications
199          * @return created Object if conditions are OK or null if not.
200          */
201         public static @Nullable ONFCoreNetworkElement12 build(String mountPointNodeName, Capabilities capabilities,
202                         DataBroker netconfNodeDataBroker, WebSocketServiceClient webSocketService,
203                         HtDatabaseEventsService databaseService, ProviderClient dcaeProvider,
204                         @Nullable ProviderClient aotsmClient) {
205                 return checkType(capabilities)
206                                 ? new ONFCoreNetworkElement12(mountPointNodeName, capabilities, netconfNodeDataBroker, webSocketService,
207                                                 databaseService, dcaeProvider, aotsmClient)
208                                 : null;
209         }
210
211         /*-----------------------------------------------------------------------------
212          * Functions
213          */
214
215         private static boolean checkType(Capabilities capabilities) {
216                 return capabilities.isSupportingNamespace(NetworkElement.QNAME);
217         }
218
219         /**
220          * Prepare check by updating NE state and reading all interfaces.
221          *
222          * @see org.opendaylight.mwtn.deviceMonitor.impl.DeviceMonitorSupport#prepareCheck()
223          */
224         @Override
225         public void prepareCheck() {
226                 synchronized (dmLock) {
227                         boolean change = readNetworkElementAndInterfaces();
228                         if (change) {
229                                 int problems = microwaveEventListener.removeAllCurrentProblemsOfNode();
230                                 List<ProblemNotificationXml> resultList = readAllCurrentProblemsToDB();
231                                 microwaveEventListener.initCurrentProblem(resultList);
232                                 LOG.info("Resync mountpoint {} for device {}. Removed {}. Current problems: {}", mountPointNodeName,
233                                                 getUuId(), problems, resultList.size());
234                         }
235                 }
236         }
237
238         /**
239          * New implementation
240          *
241          * @see org.opendaylight.mwtn.deviceMonitor.impl.DeviceMonitorSupport#checkAndConnectionToMediatorIsOk()
242          */
243         @Override
244         public boolean checkAndConnectionToMediatorIsOk() {
245                 synchronized (dmLock) {
246                         return optionalNe != null;
247                 }
248         }
249
250         /**
251          * New implementation to interpret status with empty LTP List as notConnected =>
252          * false
253          *
254          * @see org.opendaylight.mwtn.deviceMonitor.impl.DeviceMonitorSupport#checkAndConnectionToNeIsOk()
255          */
256         @Override
257         public boolean checkAndConnectionToNeIsOk() {
258                 synchronized (dmLock) {
259                         return optionalNe != null && !interfaceList.isEmpty();
260                 }
261
262         }
263
264         /*
265          * /** Check connection by requesting NetworkElement object
266          *
267          * @see org.opendaylight.mwtn.base.netconf.ONFCoreNetworkElementRepresentation#
268          * checkAndConnectionToMediatorIsOk() /
269          *
270          * @Override public boolean checkAndConnectionToMediatorIsOk() {
271          *
272          * //Read to the config data store AtomicBoolean noErrorIndicator = new
273          * AtomicBoolean(); AtomicReference<String> status = new AtomicReference<>();
274          *
275          * GenericTransactionUtils.readDataOptionalWithStatus(netconfNodeDataBroker,
276          * LogicalDatastoreType.OPERATIONAL, NETWORKELEMENT_IID, noErrorIndicator,
277          * status);
278          * LOG.debug("Status noErrorIndicator: {} statusTxt:{}",noErrorIndicator.get(),
279          * status.get()); return noErrorIndicator.get(); }
280          */
281
282         /*
283          * /** Check connection only possible if AirInterface (MWTN) exists. Request
284          *
285          * @see org.opendaylight.mwtn.base.netconf.ONFCoreNetworkElementRepresentation#
286          * checkAndConnectionToNeIsOk() /
287          *
288          * @Override public boolean checkAndConnectionToNeIsOk() { synchronized (dmLock)
289          * { if (dmAirIfCurrentProblemsIID != null) { //Read to the config data store
290          * AtomicBoolean noErrorIndicator = new AtomicBoolean(); AtomicReference<String>
291          * status = new AtomicReference<>();
292          *
293          * GenericTransactionUtils.readDataOptionalWithStatus(netconfNodeDataBroker,
294          * LogicalDatastoreType.OPERATIONAL, dmAirIfCurrentProblemsIID,
295          * noErrorIndicator, status);
296          * LOG.debug("Status noErrorIndicator: {} statusTxt:{}",noErrorIndicator.get(),
297          * status.get()); return noErrorIndicator.get(); } } return true; }
298          */
299
300         /*-----------------------------------------------------------------------------
301          * Sychronization
302          */
303
304         /**
305          * Query synchronization information out of NE
306          */
307
308         @Override
309         public void initSynchronizationExtension() {
310                 // ClockIdentityType vv;
311                 try {
312                         if (!capabilities.isSupportingNamespace(InstanceList.QNAME)) {
313                                 LOG.debug("Mountpoint {} does not support PTP", mountPointNodeName);
314                         } else {
315                                 StringBuffer sb = new StringBuffer();
316                                 sb.append("NE " + mountPointNodeName + " does support synchronisation.\n");
317                                 InstanceList ptpInstance = readPTPClockInstances();
318                                 if (ptpInstance != null) {
319                                         List<PortDsList> dsList = ptpInstance.getPortDsList();
320                                         if (dsList != null) {
321                                                 int t = 0;
322                                                 for (PortDsEntry portDs : ptpInstance.getPortDsList()) {
323                                                         PortIdentity portId = portDs.getPortIdentity();
324                                                         if (portId != null) {
325                                                                 sb.append("Port[");
326                                                                 sb.append(portId.getPortNumber());
327                                                                 sb.append("]{ ClockId: ");
328                                                                 sb.append(portId.getClockIdentity());
329                                                                 sb.append(", Portstate: ");
330                                                                 sb.append(portDs.getPortState());
331                                                                 sb.append("}, ");
332                                                         } else {
333                                                                 sb.append("Incomplete port #" + t + ", ");
334                                                         }
335                                                         t++;
336                                                 }
337                                         } else {
338                                                 sb.append("dsList contains null");
339                                         }
340                                 } else
341                                         sb.append("ptpInstance equals null");
342                                 LOG.trace(sb.toString());
343                         }
344                 } catch (Exception e) {
345                         LOG.info("Inconsistent synchronisation structure: " + e.getMessage());
346                 }
347
348         }
349
350         @Nullable
351         private InstanceList readPTPClockInstances() {
352                 return GenericTransactionUtils.readData(netconfNodeDataBroker, LogicalDatastoreType.OPERATIONAL,
353                                 PTPINSTANCES_IID);
354         }
355
356         /*-----------------------------------------------------------------------------
357          * Problem/Fault related functions
358          */
359
360         /**
361          * Read during startup all relevant structure and status parameters from device
362          */
363         @Override
364         public void initialReadFromNetworkElement() {
365                 // optionalNe.getLtp().get(0).getLp();
366                 LOG.debug("Get info about {}", mountPointNodeName);
367
368                 int problems = microwaveEventListener.removeAllCurrentProblemsOfNode();
369                 LOG.debug("Removed all {} problems from database at registration", problems);
370
371                 // Step 2.1: access data broker within this mount point
372                 LOG.debug("DBRead start");
373
374                 // Step 2.2: read ne from data store
375                 readNetworkElementAndInterfaces();
376
377                 // Step 2.3: read the existing faults and add to DB
378                 List<ProblemNotificationXml> resultList = readAllCurrentProblemsToDB();
379
380                 microwaveEventListener.initCurrentProblem(resultList);
381
382                 LOG.info("Found info at {} for device {} number of problems: {}", mountPointNodeName, getUuId(),
383                                 resultList.size());
384         }
385         @Override
386         public InventoryInformation getInventoryInformation() {
387                 return this.getInventoryInformation(null);
388         }
389         @Override
390     public @Nonnull InventoryInformation getInventoryInformation(String layerProtocolFilter) {
391
392         List<String> uuids = new ArrayList<String>();
393         String type=InventoryInformation.UNKNOWN;
394                 String model=InventoryInformation.UNKNOWN;
395                 String vendor=InventoryInformation.UNKNOWN;
396                 String ipv4=InventoryInformation.UNKNOWN;
397                 String ipv6=InventoryInformation.UNKNOWN;
398                 LOG.debug("request inventory information. filter:"+layerProtocolFilter);
399                 if (optionalNe != null) {
400
401                         //uuids
402                 for(Lp lp : this.interfaceList)
403                 {
404                         if(layerProtocolFilter==null || layerProtocolFilter.isEmpty())
405                                         uuids.add(lp.getUuid().getValue());
406                                 else if(lp.getLayerProtocolName()!=null &&
407                                         lp.getLayerProtocolName().getValue()!=null &&
408                                         lp.getLayerProtocolName().getValue().equals(layerProtocolFilter))
409                                 uuids.add(lp.getUuid().getValue());
410                 }
411                 LOG.debug("uuids found: {}",uuids);
412                 //type
413                 List<Extension> extensions = optionalNe.getExtension();
414                 if(extensions!=null)
415                 {
416                         String topLevelEqUuid=null;
417                         for(Extension e: extensions)
418                         {
419                                 if(e.getValueName()!=null)
420                                 {
421                                         if(e.getValueName().equals("top-level-equipment") && e.getValue()!=null)
422                                         {
423                                                 topLevelEqUuid=e.getValue();
424                                                 LOG.debug("top level equipment found: "+topLevelEqUuid);
425                                         }
426                                         else if(e.getValueName().equals("neIpAddress") && e.getValue()!=null)
427                                         {
428                                                 ipv4=e.getValue();
429                                                 LOG.debug("ip information found: "+ipv4);
430                                         }
431                                 }
432                         }
433                         if(ipv4==InventoryInformation.UNKNOWN)
434                         {
435                                 LOG.debug("no ip information found");
436                         }
437                         if(topLevelEqUuid!=null)
438                         {
439                                 Equipment e = this.readEquipmentPac(topLevelEqUuid);
440                                 if(e!=null)
441                                 {
442                                         if( e.getManufacturedThing()!=null &&
443                                                         e.getManufacturedThing().getEquipmentType()!=null &&
444                                                         e.getManufacturedThing().getEquipmentType().getTypeName()!=null)
445                                         {
446                                                 type = e.getManufacturedThing().getEquipmentType().getTypeName();
447                                                 LOG.debug("equipment type found: "+type);
448                                         }
449                                         else
450                                         {
451                                                 LOG.debug("no equipment type found");
452                                         }
453                                         if( e.getManufacturedThing()!=null &&
454                                                         e.getManufacturedThing().getEquipmentType()!=null &&
455                                                         e.getManufacturedThing().getEquipmentType().getModelIdentifier()!=null)
456                                         {
457                                                 model=e.getManufacturedThing().getEquipmentType().getModelIdentifier();
458                                                 LOG.debug("model identifier found:"+model);
459                                         }
460                                         else
461                                         {
462                                                 LOG.debug("no model identifier found");
463                                         }
464                                         if(e.getManufacturedThing()!=null &&
465                                                         e.getManufacturedThing().getManufacturerProperties()!=null &&
466                                                         e.getManufacturedThing().getManufacturerProperties().getManufacturerIdentifier()!=null)
467                                         {
468                                                 vendor = e.getManufacturedThing().getManufacturerProperties().getManufacturerIdentifier();
469                                                 LOG.debug("manifacturer found: "+ vendor);
470                                         }
471                                         else
472                                         {
473                                                 LOG.debug("no manifacturer found");
474                                         }
475                                 }
476                         }
477                         else
478                         {
479                                 LOG.debug("no top level equipment found");
480                         }
481                 }
482                 else
483                 {
484                         LOG.debug("extension list is null");
485                 }
486                 }
487
488         return new InventoryInformation(type, model, vendor, ipv4, ipv6, uuids);
489
490
491     }
492
493
494         /**
495          * LOG the newly added problems of the interface pac
496          *
497          * @param idxStart
498          * @param uuid
499          * @param resultList
500          */
501         private void debugResultList(String uuid, List<ProblemNotificationXml> resultList, int idxStart) {
502                 if (LOG.isDebugEnabled()) {
503                         StringBuffer sb = new StringBuffer();
504                         int idx = 0;
505                         for (int t = idxStart; t < resultList.size(); t++) {
506                                 sb.append(idx++);
507                                 sb.append(":{");
508                                 sb.append(resultList.get(t));
509                                 sb.append('}');
510                         }
511                         LOG.debug("Found problems {} {}", uuid, sb.toString());
512                 }
513         }
514
515         /**
516          * Read from NetworkElement and verify LTPs have changed. If the NE has changed,
517          * update to the new structure. From initial state it changes also.
518          */
519         private synchronized boolean readNetworkElementAndInterfaces() {
520
521                 LOG.debug("Update mountpoint if changed {}", mountPointNodeName);
522
523                 optionalNe = GenericTransactionUtils.readData(netconfNodeDataBroker, LogicalDatastoreType.OPERATIONAL,
524                                 NETWORKELEMENT_IID);
525                 ;
526                 synchronized (pmLock) {
527                         boolean change = false;
528
529                         if (optionalNe == null) {
530                                 LOG.debug("Unable to read NE data for mountpoint {}", mountPointNodeName);
531                                 if (!interfaceList.isEmpty()) {
532                                         interfaceList.clear();
533                                         interfaceListIterator = null;
534                                         change = true;
535                                 }
536
537                         } else {
538                                 LOG.debug("Mountpoint '{}' NE-Name '{}'", mountPointNodeName, optionalNe.getName().toString());
539                                 List<Lp> actualInterfaceList = getLtpList(optionalNe);
540                                 if (!interfaceList.equals(actualInterfaceList)) {
541                                         LOG.debug("Mountpoint '{}' Update LTP List. Elements {}", mountPointNodeName,
542                                                         actualInterfaceList.size());
543                                         interfaceList.clear();
544                                         interfaceList.addAll(actualInterfaceList);
545                                         interfaceListIterator = null;
546                                         change = true;
547                                 }
548                         }
549                         return change;
550                 }
551         }
552
553         /**
554          * Read current problems of AirInterfaces and EthernetContainer according to NE
555          * status into DB
556          *
557          * @return List with all problems
558          */
559         private List<ProblemNotificationXml> readAllCurrentProblemsToDB() {
560
561                 // Step 2.3: read the existing faults and add to DB
562                 List<ProblemNotificationXml> resultList = new ArrayList<>();
563                 int idxStart; // Start index for debug messages
564                 UniversalId uuid;
565
566                 synchronized (pmLock) {
567                         for (Lp ltp : interfaceList) {
568
569                                 idxStart = resultList.size();
570                                 uuid = ltp.getUuid();
571                                 Class<?> lpClass = getLpExtension(ltp);
572
573                                 ONFLayerProtocolName lpName = ONFLayerProtocolName.valueOf(ltp.getLayerProtocolName());
574                                 switch (lpName) {
575                                 case MWAirInterface:
576                                         readTheFaultsOfMwAirInterfacePac(uuid, resultList);
577                                         synchronized (dmLock) {
578                                                 if (dmAirIfCurrentProblemsIID == null) {
579                                                         dmAirIfCurrentProblemsIID = getMWAirInterfacePacIId(uuid);
580                                                 }
581                                         }
582                                         break;
583
584                                 case EthernetContainer12:
585                                         readTheFaultsOfMwEthernetContainerPac(uuid, resultList);
586                                         break;
587
588                                 case TDMContainer:
589                                         readTheFaultsOfMwTdmContainerPac(uuid, resultList);
590                                         break;
591
592                                 case Structure:
593                                         if (lpClass == MwHybridMwStructurePac.class) {
594                                                 readTheFaultsOfMwHybridMwStructurePac(uuid, resultList);
595
596                                         } else if (lpClass == MwAirInterfaceDiversityPac.class) {
597                                                 readTheFaultsOfMwAirInterfaceDiversityPac(uuid, resultList);
598
599                                         } else if (lpClass == MwPureEthernetStructurePac.class) {
600                                                 readTheFaultsOfMwPureEthernetStructurePac(uuid, resultList);
601
602                                         } else {
603                                                 LOG.warn("Unassigned lp model {} class {}", lpName, lpClass);
604                                         }
605                                         break;
606
607                                 case Ethernet:
608                                         // No alarms supported
609                                         break;
610                                 case EthernetContainer10:
611                                 default:
612                                         LOG.warn("Unassigned or not expected lp in model {}", lpName);
613                                 }
614
615                                 debugResultList(uuid.getValue(), resultList, idxStart);
616
617                         }
618                 }
619
620                 // Step 2.4: Read other problems from mountpoint
621                 if (isNetworkElementCurrentProblemsSupporting10) {
622                         idxStart = resultList.size();
623                         readNetworkElementCurrentProblems10(resultList);
624                         debugResultList("CurrentProblems10", resultList, idxStart);
625                 }
626
627                 // Step 2.5: Read other problems from mountpoint
628                 if (isNetworkElementCurrentProblemsSupporting12) {
629                         idxStart = resultList.size();
630                         readNetworkElementCurrentProblems12(resultList);
631                         debugResultList("CurrentProblems12", resultList, idxStart);
632                 }
633
634                 return resultList;
635
636         }
637
638         /**
639          * Get uuid of Optional NE.
640          *
641          * @return Uuid or EMPTY String if optionNE is not available
642          */
643         private String getUuId() {
644                 String uuid = EMPTY;
645
646                 try {
647                         uuid = optionalNe != null ? optionalNe.getUuid() != null ? optionalNe.getUuid().getValue() : EMPTY : EMPTY;
648                 } catch (NullPointerException e) {
649                         // Unfortunately throws null pointer if not definied
650                 }
651                 return uuid;
652         }
653
654         /**
655          * Read the NetworkElement part from database.
656          *
657          * @return Optional with NetworkElement or empty
658          */
659         @Nullable
660         private NetworkElement readNetworkElement() {
661                 // Step 2.2: construct data and the relative iid
662                 // The schema path to identify an instance is
663                 // <i>CoreModel-CoreNetworkModule-ObjectClasses/NetworkElement</i>
664                 /*
665                  * InstanceIdentifier<NetworkElement> networkElementIID = InstanceIdentifier
666                  * .builder(NetworkElement.class) .build();
667                  */
668                 // Read to the config data store
669                 return GenericTransactionUtils.readData(netconfNodeDataBroker, LogicalDatastoreType.OPERATIONAL,
670                                 NETWORKELEMENT_IID);
671         }
672
673         /**
674          * Get from LayProtocolExtensions the related generated ONF Interface PAC class
675          * which represents it.
676          *
677          * @param ltp
678          *            logical termination point
679          * @return Class of InterfacePac
680          */
681         @Nullable
682         private static Class<?> getLpExtension(@Nullable Lp ltp) {
683
684                 String capability = EMPTY;
685                 String revision = EMPTY;
686                 String conditionalPackage = EMPTY;
687                 Class<?> res = null;
688
689                 if (ltp != null) {
690                         for (Extension e : getExtensionList(ltp)) {
691                                 if (e.getValueName().contentEquals("capability")) {
692                                         capability = e.getValue();
693                                         int idx = capability.indexOf("?");
694                                         if (idx != -1) {
695                                                 capability = capability.substring(0, idx);
696                                         }
697                                 }
698                                 if (e.getValueName().contentEquals("revision")) {
699                                         revision = e.getValue();
700                                 }
701                                 if (e.getValueName().contentEquals("conditional-package")) {
702                                         conditionalPackage = e.getValue();
703                                 }
704                         }
705                 }
706                 // QName qName =
707                 // org.opendaylight.yangtools.yang.common.QName.create("urn:onf:params:xml:ns:yang:microwave-model",
708                 // "2017-03-24", "mw-air-interface-pac").intern();
709                 LOG.info("LpExtension capability={} revision={} conditionalPackage={}", capability, revision,
710                                 conditionalPackage);
711                 if (!capability.isEmpty() && !revision.isEmpty() && !conditionalPackage.isEmpty()) {
712                         try {
713                                 QName qName = QName.create(capability, revision, conditionalPackage);
714
715                                 if (qName.equals(MwAirInterfacePac.QNAME)) {
716                                         res = MwAirInterfacePac.class;
717                                 } else if (qName.equals(MwAirInterfaceDiversityPac.QNAME)) {
718                                         res = MwAirInterfaceDiversityPac.class;
719                                 } else if (qName.equals(MwPureEthernetStructurePac.QNAME)) {
720                                         res = MwPureEthernetStructurePac.class;
721                                 } else if (qName.equals(MwHybridMwStructurePac.QNAME)) {
722                                         res = MwHybridMwStructurePac.class;
723                                 } else if (qName.equals(MwEthernetContainerPac.QNAME)) {
724                                         res = MwEthernetContainerPac.class;
725                                 } else if (qName.equals(MwTdmContainerPac.QNAME)) {
726                                         res = MwTdmContainerPac.class;
727                                 } else if (qName.equals(EthernetPac.QNAME)) {
728                                         res = MwTdmContainerPac.class;
729                                 }
730                                 LOG.info("Found QName {} mapped to {}", String.valueOf(qName), String.valueOf(res));
731                         } catch (IllegalArgumentException e) {
732                                 LOG.debug("Can not create QName from ({}{{}{{}): {}", capability, revision, conditionalPackage,
733                                                 e.getMessage());
734                         }
735                 }
736                 return res;
737         }
738
739         /**
740          * Read element from class that could be not available
741          *
742          * @param ltp
743          *            layer termination point
744          * @return List with extension parameters or empty list
745          */
746         @Nonnull
747         private static List<Extension> getExtensionList(@Nullable Lp ltp) {
748                 if (ltp != null && ltp.getExtension() != null) {
749                         return ltp.getExtension();
750                 } else {
751                         return EMPTYLTPEXTENSIONLIST;
752                 }
753         }
754
755         /**
756          * Get List of UUIDs for conditional packages from Networkelement<br>
757          * Possible interfaces are:<br>
758          * MWPS, LTP(MWPS-TTP), MWAirInterfacePac,
759          * MicrowaveModel-ObjectClasses-AirInterface<br>
760          * ETH-CTP,LTP(Client), MW_EthernetContainer_Pac<br>
761          * MWS, LTP(MWS-CTP-xD), MWAirInterfaceDiversityPac,
762          * MicrowaveModel-ObjectClasses-AirInterfaceDiversity<br>
763          * MWS, LTP(MWS-TTP), ,MicrowaveModel-ObjectClasses-HybridMwStructure<br>
764          * MWS, LTP(MWS-TTP), ,MicrowaveModel-ObjectClasses-PureEthernetStructure<br>
765          *
766          * @param ne
767          *            Networkelement
768          * @return Id List, never null.
769          */
770         private static List<Lp> getLtpList(@Nullable NetworkElement ne) {
771
772                 List<Lp> res = Collections.synchronizedList(new ArrayList<Lp>());
773
774                 if (ne != null) {
775                         List<Ltp> ltpRefList = ne.getLtp();
776                         if (ltpRefList == null) {
777                                 LOG.debug("DBRead NE-Interfaces: null");
778                         } else {
779                                 for (Ltp ltRefListE : ltpRefList) {
780                                         List<Lp> lpList = ltRefListE.getLp();
781                                         if (lpList == null) {
782                                                 LOG.debug("DBRead NE-Interfaces Reference List: null");
783                                         } else {
784                                                 for (Lp ltp : lpList) {
785                                                         //// LayerProtocolName layerProtocolName = lpListE.getLayerProtocolName();
786                                                         // UniversalId uuId = lpListE.getUuid();
787                                                         res.add(ltp);
788                                                 }
789                                         }
790                                 }
791                         }
792                 } else {
793                         LOG.debug("DBRead NE: null");
794                 }
795
796                 // ---- Debug
797                 if (LOG.isDebugEnabled()) {
798                         StringBuffer strBuf = new StringBuffer();
799                         for (Lp ltp : res) {
800                                 if (strBuf.length() > 0) {
801                                         strBuf.append(", ");
802                                 }
803                                 strBuf.append(ltp.getLayerProtocolName().getValue());
804                                 strBuf.append(':');
805                                 strBuf.append(ltp.getUuid().getValue());
806                         }
807                         LOG.debug("DBRead NE-Interfaces: {}", strBuf.toString());
808                 }
809                 // ---- Debug end
810
811                 return res;
812         }
813
814         /*-----------------------------------------------------------------------------
815          * Performance related data
816          */
817
818         /**
819          * PM MwAirInterfacePac
820          *
821          * @param lp
822          * @return
823          */
824         private List<ExtendedAirInterfaceHistoricalPerformanceType12> readTheHistoricalPerformanceDataOfMwAirInterfacePac(
825                         Lp lp) {
826
827                 String uuId = lp.getUuid().getValue();
828
829                 List<ExtendedAirInterfaceHistoricalPerformanceType12> resultList = new ArrayList<>();
830                 LOG.debug("DBRead Get {} MWAirInterfacePac: {}", mountPointNodeName, uuId);
831                 // ----
832                 UniversalId mwAirInterfacePacuuId = new UniversalId(uuId);
833                 // Step 2.1: construct data and the relative iid
834                 InstanceIdentifier<AirInterfaceConfiguration> mwAirInterfaceConfigurationIID = InstanceIdentifier
835                                 .builder(MwAirInterfacePac.class, new MwAirInterfacePacKey(mwAirInterfacePacuuId))
836                                 .child(AirInterfaceConfiguration.class).build();
837                 AirInterfaceConfiguration airConfiguration = GenericTransactionUtils.readData(netconfNodeDataBroker,
838                                 LogicalDatastoreType.OPERATIONAL, mwAirInterfaceConfigurationIID);
839
840                 if (airConfiguration == null) {
841                         LOG.debug("DBRead MWAirInterfacePac Id {} no AirInterfaceConfiguration", mwAirInterfacePacuuId);
842
843                 } else {
844                         // Step 2.2: construct data and the relative iid
845                         InstanceIdentifier<AirInterfaceHistoricalPerformances> mwAirInterfaceHistoricalPerformanceIID = InstanceIdentifier
846                                         .builder(MwAirInterfacePac.class, new MwAirInterfacePacKey(mwAirInterfacePacuuId))
847                                         .child(AirInterfaceHistoricalPerformances.class).build();
848
849                         // Step 2.3: read to the config data store
850                         AirInterfaceHistoricalPerformances airHistoricalPerformanceData = GenericTransactionUtils.readData(
851                                         netconfNodeDataBroker, LogicalDatastoreType.OPERATIONAL, mwAirInterfaceHistoricalPerformanceIID);
852
853                         if (airHistoricalPerformanceData == null) {
854                                 LOG.debug("DBRead MWAirInterfacePac Id {} no AirInterfaceHistoricalPerformances",
855                                                 mwAirInterfacePacuuId);
856                         } else {
857                                 // org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170320.air._interface.historical.performances.g.HistoricalPerformanceDataList
858                                 List<org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.air._interface.historical.performances.g.HistoricalPerformanceDataList> airHistPMList = airHistoricalPerformanceData
859                                                 .getHistoricalPerformanceDataList();
860                                 LOG.debug("DBRead MWAirInterfacePac Id {} Records intermediate: {}", mwAirInterfacePacuuId,
861                                                 airHistPMList.size());
862                                 if (airHistPMList != null) {
863                                         for (AirInterfaceHistoricalPerformanceTypeG pmRecord : airHistoricalPerformanceData
864                                                         .getHistoricalPerformanceDataList()) {
865                                                 resultList.add(new ExtendedAirInterfaceHistoricalPerformanceType12(pmRecord, airConfiguration));
866                                         }
867                                 }
868                         }
869                 }
870                 LOG.debug("DBRead MWAirInterfacePac Id {} Records result: {}", mwAirInterfacePacuuId, resultList.size());
871                 return resultList;
872         }
873
874         private List<ContainerHistoricalPerformanceTypeG> readTheHistoricalPerformanceDataOfEthernetContainer(Lp lp) {
875
876                 final String myName = "MWEthernetContainerPac";
877                 String uuId = lp.getUuid().getValue();
878
879                 List<ContainerHistoricalPerformanceTypeG> resultList = new ArrayList<>();
880                 LOG.debug("DBRead Get {} : {}", mountPointNodeName, myName, uuId);
881                 // ----
882                 UniversalId ethContainerPacuuId = new UniversalId(uuId);
883                 // Step 2.2: construct data and the relative iid
884                 InstanceIdentifier<EthernetContainerHistoricalPerformances> ethContainerIID = InstanceIdentifier
885                                 .builder(MwEthernetContainerPac.class, new MwEthernetContainerPacKey(ethContainerPacuuId))
886                                 .child(EthernetContainerHistoricalPerformances.class).build();
887
888                 // Step 2.3: read to the config data store
889                 EthernetContainerHistoricalPerformances ethContainerHistoricalPerformanceData = GenericTransactionUtils
890                                 .readData(netconfNodeDataBroker, LogicalDatastoreType.OPERATIONAL, ethContainerIID);
891
892                 if (ethContainerHistoricalPerformanceData == null) {
893                         LOG.debug("DBRead {} Id {} no HistoricalPerformances", myName, ethContainerPacuuId);
894                 } else {
895                         // import
896                         // org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170320.ethernet.container.historical.performances.g.HistoricalPerformanceDataList
897                         List<org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.ethernet.container.historical.performances.g.HistoricalPerformanceDataList> airHistPMList = ethContainerHistoricalPerformanceData
898                                         .getHistoricalPerformanceDataList();
899                         LOG.debug("DBRead {} Id {} Records intermediate: {}", myName, ethContainerPacuuId, airHistPMList.size());
900                         if (airHistPMList != null) {
901                                 for (ContainerHistoricalPerformanceTypeG pmRecord : airHistPMList) {
902                                         resultList.add(pmRecord);
903                                 }
904                         }
905                 }
906                 LOG.debug("DBRead {} Id {} Records result: {}", myName, ethContainerPacuuId, resultList.size());
907                 return resultList;
908         }
909
910         @Nonnull
911         private List<? extends OtnHistoryDataG> readTheHistoricalPerformanceData(Lp lp) {
912                 ONFLayerProtocolName lpName = ONFLayerProtocolName.valueOf(lp.getLayerProtocolName());
913
914                 switch (lpName) {
915                 case MWAirInterface:
916                         return readTheHistoricalPerformanceDataOfMwAirInterfacePac(lp);
917
918                 case EthernetContainer12:
919                         return readTheHistoricalPerformanceDataOfEthernetContainer(lp);
920
921                 case EthernetContainer10:
922                 case EthernetPhysical:
923                 case Ethernet:
924                 case TDMContainer:
925                 case Structure:
926                 case Unknown:
927                         LOG.debug("Do not read HistoricalPM data for {} {}", lpName, lp.getUuid().getValue());
928                         break;
929                 }
930                 return new ArrayList<>();
931         }
932
933         @Override
934         public AllPm getHistoricalPM() {
935
936                 synchronized (pmLock) {
937                         if (pmLp != null) {
938                                 LOG.debug("Enter query PM");
939                                 AllPm allPm = new AllPm();
940                                 Lp lp = pmLp;
941
942                                 List<? extends OtnHistoryDataG> resultList = readTheHistoricalPerformanceData(lp);
943                                 LOG.debug("Got records: {}", resultList.size());
944                                 // org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.g._874._1.model.rev170320.GranularityPeriodType
945                                 GranularityPeriodType granularityPeriod;
946                                 for (OtnHistoryDataG perf : resultList) {
947
948                                         granularityPeriod = perf.getGranularityPeriod();
949                                         if (granularityPeriod == null) {
950                                                 granularityPeriod = GranularityPeriodType.Unknown;
951                                         }
952
953                                         switch (granularityPeriod) {
954                                         case Period15Min: {
955                                                 EsHistoricalPerformance15Minutes pm = new EsHistoricalPerformance15Minutes(mountPointNodeName,
956                                                                 lp).setHistoricalRecord15Minutes(perf);
957                                                 allPm.add(pm);
958                                         }
959                                                 break;
960
961                                         case Period24Hours: {
962                                                 EsHistoricalPerformance24Hours pm = new EsHistoricalPerformance24Hours(mountPointNodeName, lp)
963                                                                 .setHistoricalRecord24Hours(perf);
964                                                 LOG.debug("Write 24h write to DB");
965                                                 allPm.add(pm);
966                                         }
967                                                 break;
968
969                                         default:
970                                                 LOG.warn("Unknown granularity {}", perf.getGranularityPeriod());
971                                                 break;
972
973                                         }
974                                 }
975                                 LOG.debug("Deliver normalized records: {}", allPm.size());
976                                 return allPm;
977                         } else {
978                                 LOG.debug("Deliver empty, no LTP");
979                                 return AllPm.EMPTY;
980                         }
981                 }
982         }
983
984         @Override
985         public void resetPMIterator() {
986                 synchronized (pmLock) {
987                         interfaceListIterator = interfaceList.iterator();
988                 }
989                 LOG.debug("PM reset iterator");
990         }
991
992         @Override
993         public boolean hasNext() {
994                 boolean res;
995                 synchronized (pmLock) {
996                         res = interfaceListIterator != null ? interfaceListIterator.hasNext() : false;
997                 }
998                 LOG.debug("PM hasNext LTP {}", res);
999                 return res;
1000         }
1001
1002         @Override
1003         public void next() {
1004                 synchronized (pmLock) {
1005                         pmLp = interfaceListIterator != null ? interfaceListIterator.next() : null;
1006                 }
1007                 LOG.debug("PM next LTP {}", pmLp.getLayerProtocolName().getValue());
1008         }
1009
1010         @Override
1011         public String pmStatusToString() {
1012                 StringBuffer res = new StringBuffer();
1013                 synchronized (pmLock) {
1014                         res.append(pmLp == null ? "no interface" : pmLp.getLayerProtocolName().getValue());
1015                         for (Lp lp : interfaceList) {
1016                                 res.append("IF:");
1017                                 res.append(lp.getLayerProtocolName().getValue());
1018                                 res.append(" ");
1019                         }
1020                 }
1021                 return (res.toString());
1022         }
1023
1024         /*------------------------------------------------------------
1025          * private function to access database
1026          */
1027
1028         /*-----------------------------------------------------------------------------
1029          * Reading problems for the networkElement V1.0
1030          */
1031
1032         private List<ProblemNotificationXml> readNetworkElementCurrentProblems10(List<ProblemNotificationXml> resultList) {
1033
1034                 LOG.info("DBRead Get {} NetworkElementCurrentProblems", mountPointNodeName);
1035
1036                 InstanceIdentifier<org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.networkelement.currentproblemlist.rev161120.NetworkElementCurrentProblems> networkElementCurrentProblemsIID = InstanceIdentifier
1037                                 .builder(
1038                                                 org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.networkelement.currentproblemlist.rev161120.NetworkElementCurrentProblems.class)
1039                                 .build();
1040
1041                 // Step 2.3: read to the config data store
1042                 org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.networkelement.currentproblemlist.rev161120.NetworkElementCurrentProblems problems;
1043                 try {
1044                         problems = GenericTransactionUtils.readData(netconfNodeDataBroker, LogicalDatastoreType.OPERATIONAL,
1045                                         networkElementCurrentProblemsIID);
1046                         if (problems == null) {
1047                                 LOG.debug("DBRead no NetworkElementCurrentProblems");
1048                         } else if (problems.getCurrentProblemList() == null) {
1049                                 LOG.debug("DBRead empty CurrentProblemList");
1050                         } else {
1051                                 for (org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.networkelement.currentproblemlist.rev161120.GenericCurrentProblemType problem : problems
1052                                                 .getCurrentProblemList()) {
1053                                         resultList.add(new ProblemNotificationXml(mountPointNodeName, problem.getObjectIdRef(),
1054                                                         problem.getProblemName(), InternalSeverity.valueOf(problem.getProblemSeverity()),
1055                                                         problem.getSequenceNumber().toString(),
1056                                                         InternalDateAndTime.valueOf(problem.getTimeStamp())));
1057                                 }
1058                         }
1059                 } catch (Exception e) {
1060                         LOG.warn("DBRead {} NetworkElementCurrentProblems not supported. Message '{}' ", mountPointNodeName,
1061                                         e.getMessage());
1062                 }
1063                 return resultList;
1064         }
1065
1066         /*-----------------------------------------------------------------------------
1067          * Reading problems for the networkElement V1.0
1068          */
1069
1070         private List<ProblemNotificationXml> readNetworkElementCurrentProblems12(List<ProblemNotificationXml> resultList) {
1071
1072                 LOG.info("DBRead Get {} NetworkElementCurrentProblems12", mountPointNodeName);
1073
1074                 InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.NetworkElementPac> networkElementCurrentProblemsIID = InstanceIdentifier
1075                                 .builder(
1076                                                 org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.NetworkElementPac.class)
1077                                 .build();
1078
1079                 // Step 2.3: read to the config data store
1080                 NetworkElementPac problemPac;
1081                 NetworkElementCurrentProblems problems;
1082                 try {
1083                         problemPac = GenericTransactionUtils.readData(netconfNodeDataBroker, LogicalDatastoreType.OPERATIONAL,
1084                                         networkElementCurrentProblemsIID);
1085                         problems = problemPac.getNetworkElementCurrentProblems();
1086                         if (problems == null) {
1087                                 LOG.debug("DBRead no NetworkElementCurrentProblems12");
1088                         } else if (problems.getCurrentProblemList() == null) {
1089                                 LOG.debug("DBRead empty CurrentProblemList12");
1090                         } else {
1091                                 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
1092                                                 .getCurrentProblemList()) {
1093                                         resultList.add(new ProblemNotificationXml(mountPointNodeName, problem.getObjectReference(),
1094                                                         problem.getProblemName(), InternalSeverity.valueOf(problem.getProblemSeverity()),
1095                                                         problem.getSequenceNumber().toString(),
1096                                                         InternalDateAndTime.valueOf(problem.getTimeStamp())));
1097                                 }
1098                         }
1099                 } catch (Exception e) {
1100                         LOG.warn("DBRead {} NetworkElementCurrentProblems12 not supported. Message '{}' ", mountPointNodeName,
1101                                         e.getMessage());
1102                 }
1103                 return resultList;
1104
1105         }
1106
1107         /*-----------------------------------------------------------------------------
1108          * Reading problems for specific interface pacs
1109          */
1110
1111         /**
1112          * Generate ID
1113          *
1114          * @param interfacePacUuid
1115          *            for airinterface
1116          * @return AirInterfaceCurrentProblemsIID
1117          */
1118         private InstanceIdentifier<AirInterfaceCurrentProblems> getMWAirInterfacePacIId(UniversalId interfacePacUuid) {
1119                 InstanceIdentifier<AirInterfaceCurrentProblems> mwAirInterfaceIID = InstanceIdentifier
1120                                 .builder(MwAirInterfacePac.class, new MwAirInterfacePacKey(interfacePacUuid))
1121                                 .child(AirInterfaceCurrentProblems.class).build();
1122                 return mwAirInterfaceIID;
1123         }
1124
1125         /**
1126          * Read problems of specific interfaces
1127          *
1128          * @param uuId
1129          *            Universal Id String of the interface
1130          * @return number of alarms
1131          */
1132         private List<ProblemNotificationXml> readTheFaultsOfMwAirInterfacePac(UniversalId interfacePacUuid,
1133                         List<ProblemNotificationXml> resultList) {
1134
1135                 final Class<MwAirInterfacePac> clazzPac = MwAirInterfacePac.class;
1136                 // final Class<MwAirInterfacePacKey> clazzPacKey = MwAirInterfacePacKey.class;
1137                 // final Class<AirInterfaceCurrentProblems> clazzProblems =
1138                 // AirInterfaceCurrentProblems.class;
1139                 // final Class<AirInterfaceCurrentProblemTypeG> clazzProblem =
1140                 // AirInterfaceCurrentProblemTypeG.class;
1141
1142                 LOG.info("DBRead Get problems for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
1143                                 mountPointNodeName, interfacePacUuid.getValue());
1144
1145                 // Step 2.2: construct data and the relative iid
1146                 InstanceIdentifier<AirInterfaceCurrentProblems> mwAirInterfaceIID = InstanceIdentifier
1147                                 .builder(MwAirInterfacePac.class, new MwAirInterfacePacKey(interfacePacUuid))
1148                                 .child(AirInterfaceCurrentProblems.class).build();
1149
1150                 // Step 2.3: read to the config data store
1151                 AirInterfaceCurrentProblems problems = GenericTransactionUtils.readData(netconfNodeDataBroker,
1152                                 LogicalDatastoreType.OPERATIONAL, mwAirInterfaceIID);
1153
1154                 if (problems == null) {
1155                         LOG.debug("DBRead Id {} no AirInterfaceCurrentProblems", interfacePacUuid);
1156                 } else if (problems.getCurrentProblemList() == null) {
1157                         LOG.debug("DBRead Id {} empty CurrentProblemList", interfacePacUuid);
1158                 } else {
1159                         for (AirInterfaceCurrentProblemTypeG problem : problems.getCurrentProblemList()) {
1160                                 resultList.add(new ProblemNotificationXml(mountPointNodeName, interfacePacUuid.getValue(),
1161                                                 problem.getProblemName(), InternalSeverity.valueOf(problem.getProblemSeverity()),
1162                                                 problem.getSequenceNumber().toString(), InternalDateAndTime.valueOf(problem.getTimeStamp())));
1163                         }
1164                 }
1165                 return resultList;
1166         }
1167
1168         /**
1169          * Read problems of specific interfaces
1170          *
1171          * @param uuId
1172          *            Universal index of Interfacepac
1173          * @return number of alarms
1174          */
1175         private List<ProblemNotificationXml> readTheFaultsOfMwEthernetContainerPac(UniversalId interfacePacUuid,
1176                         List<ProblemNotificationXml> resultList) {
1177
1178                 final Class<MwEthernetContainerPac> clazzPac = MwEthernetContainerPac.class;
1179                 // final Class<MwEthernetContainerPacKey> clazzPacKey =
1180                 // MwEthernetContainerPacKey.class;
1181                 // final Class<EthernetContainerCurrentProblems> clazzProblems =
1182                 // EthernetContainerCurrentProblems.class;
1183                 // final Class<ContainerCurrentProblemTypeG> clazzProblem =
1184                 // ContainerCurrentProblemTypeG.class;
1185
1186                 LOG.info("DBRead Get problems for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
1187                                 mountPointNodeName, interfacePacUuid.getValue());
1188
1189                 InstanceIdentifier<EthernetContainerCurrentProblems> mwEthInterfaceIID = InstanceIdentifier
1190                                 .builder(MwEthernetContainerPac.class, new MwEthernetContainerPacKey(interfacePacUuid))
1191                                 .child(EthernetContainerCurrentProblems.class).build();
1192
1193                 EthernetContainerCurrentProblems problems = GenericTransactionUtils.readData(netconfNodeDataBroker,
1194                                 LogicalDatastoreType.OPERATIONAL, mwEthInterfaceIID);
1195                 if (problems == null) {
1196                         LOG.debug("DBRead Id {} no EthernetContainerCurrentProblems", interfacePacUuid);
1197                 } else if (problems.getCurrentProblemList() == null) {
1198                         LOG.debug("DBRead Id {} empty CurrentProblemsList", interfacePacUuid);
1199                 } else {
1200                         for (ContainerCurrentProblemTypeG problem : problems.getCurrentProblemList()) {
1201                                 resultList.add(new ProblemNotificationXml(mountPointNodeName, interfacePacUuid.getValue(),
1202                                                 problem.getProblemName(), InternalSeverity.valueOf(problem.getProblemSeverity()),
1203                                                 problem.getSequenceNumber().toString(), InternalDateAndTime.valueOf(problem.getTimeStamp())));
1204                         }
1205                 }
1206                 return resultList;
1207         }
1208
1209         /**
1210          * Read problems of specific interfaces
1211          *
1212          * @param uuId
1213          *            Universal index of Interfacepac
1214          * @return number of alarms
1215          */
1216         private List<ProblemNotificationXml> readTheFaultsOfMwAirInterfaceDiversityPac(UniversalId interfacePacUuid,
1217                         List<ProblemNotificationXml> resultList) {
1218
1219                 final Class<MwAirInterfaceDiversityPac> clazzPac = MwAirInterfaceDiversityPac.class;
1220                 // final Class<MwAirInterfaceDiversityPacKey> clazzPacKey =
1221                 // MwAirInterfaceDiversityPacKey.class;
1222                 final Class<AirInterfaceDiversityCurrentProblems> clazzProblems = AirInterfaceDiversityCurrentProblems.class;
1223                 // final Class<AirInterfaceDiversityCurrentProblemTypeG> clazzProblem =
1224                 // AirInterfaceDiversityCurrentProblemTypeG.class;
1225
1226                 LOG.info("DBRead Get problems for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
1227                                 mountPointNodeName, interfacePacUuid.getValue());
1228
1229                 InstanceIdentifier<AirInterfaceDiversityCurrentProblems> mwEthInterfaceIID = InstanceIdentifier
1230                                 .builder(clazzPac, new MwAirInterfaceDiversityPacKey(interfacePacUuid)).child(clazzProblems).build();
1231
1232                 AirInterfaceDiversityCurrentProblems problems = GenericTransactionUtils.readData(netconfNodeDataBroker,
1233                                 LogicalDatastoreType.OPERATIONAL, mwEthInterfaceIID);
1234                 if (problems == null) {
1235                         LOG.debug("DBRead Id {} no AirInterfaceDiversityCurrentProblems", interfacePacUuid);
1236                 } else if (problems.getCurrentProblemList() == null) {
1237                         LOG.debug("DBRead Id {} empty CurrentProblemList", interfacePacUuid);
1238                 } else {
1239                         for (AirInterfaceDiversityCurrentProblemTypeG problem : problems.getCurrentProblemList()) {
1240                                 resultList.add(new ProblemNotificationXml(mountPointNodeName, interfacePacUuid.getValue(),
1241                                                 problem.getProblemName(), InternalSeverity.valueOf(problem.getProblemSeverity()),
1242                                                 problem.getSequenceNumber().toString(), InternalDateAndTime.valueOf(problem.getTimeStamp())));
1243                         }
1244                 }
1245                 return resultList;
1246         }
1247
1248         /**
1249          * Read problems of specific interfaces
1250          *
1251          * @param uuId
1252          *            Universal index of Interfacepac
1253          * @return number of alarms
1254          */
1255         private List<ProblemNotificationXml> readTheFaultsOfMwPureEthernetStructurePac(UniversalId interfacePacUuid,
1256                         List<ProblemNotificationXml> resultList) {
1257
1258                 final Class<MwPureEthernetStructurePac> clazzPac = MwPureEthernetStructurePac.class;
1259                 // final Class<MwPureEthernetStructurePacKey> clazzPacKey =
1260                 // MwPureEthernetStructurePacKey.class;
1261                 final Class<PureEthernetStructureCurrentProblems> clazzProblems = PureEthernetStructureCurrentProblems.class;
1262                 // final Class<StructureCurrentProblemTypeG> clazzProblem =
1263                 // StructureCurrentProblemTypeG.class;
1264
1265                 LOG.info("DBRead Get problems for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
1266                                 mountPointNodeName, interfacePacUuid.getValue());
1267
1268                 InstanceIdentifier<PureEthernetStructureCurrentProblems> mwEthInterfaceIID = InstanceIdentifier
1269                                 .builder(clazzPac, new MwPureEthernetStructurePacKey(interfacePacUuid)).child(clazzProblems).build();
1270
1271                 PureEthernetStructureCurrentProblems problems = GenericTransactionUtils.readData(netconfNodeDataBroker,
1272                                 LogicalDatastoreType.OPERATIONAL, mwEthInterfaceIID);
1273                 if (problems == null) {
1274                         LOG.debug("DBRead Id {} no PureEthernetStructureCurrentProblems", interfacePacUuid);
1275                 } else if (problems.getCurrentProblemList() == null) {
1276                         LOG.debug("DBRead Id {} empty CurrentProblemsList", interfacePacUuid);
1277                 } else {
1278                         for (StructureCurrentProblemTypeG problem : problems.getCurrentProblemList()) {
1279                                 resultList.add(new ProblemNotificationXml(mountPointNodeName, interfacePacUuid.getValue(),
1280                                                 problem.getProblemName(), InternalSeverity.valueOf(problem.getProblemSeverity()),
1281                                                 problem.getSequenceNumber().toString(), InternalDateAndTime.valueOf(problem.getTimeStamp())));
1282                         }
1283                 }
1284                 return resultList;
1285         }
1286
1287         /**
1288          * Read problems of specific interfaces
1289          *
1290          * @param uuId
1291          *            Universal index of Interfacepac
1292          * @return number of alarms
1293          */
1294         private List<ProblemNotificationXml> readTheFaultsOfMwHybridMwStructurePac(UniversalId interfacePacUuid,
1295                         List<ProblemNotificationXml> resultList) {
1296
1297                 final Class<MwHybridMwStructurePac> clazzPac = MwHybridMwStructurePac.class;
1298                 // final Class<MwHybridMwStructurePacKey> clazzPacKey =
1299                 // MwHybridMwStructurePacKey.class;
1300                 final Class<HybridMwStructureCurrentProblems> clazzProblems = HybridMwStructureCurrentProblems.class;
1301                 // final Class<HybridMwStructureCurrentProblemsG> clazzProblem =
1302                 // HybridMwStructureCurrentProblemsG.class;
1303
1304                 LOG.info("DBRead Get problems for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
1305                                 mountPointNodeName, interfacePacUuid.getValue());
1306
1307                 InstanceIdentifier<HybridMwStructureCurrentProblems> mwEthInterfaceIID = InstanceIdentifier
1308                                 .builder(clazzPac, new MwHybridMwStructurePacKey(interfacePacUuid)).child(clazzProblems).build();
1309
1310                 HybridMwStructureCurrentProblems problems = GenericTransactionUtils.readData(netconfNodeDataBroker,
1311                                 LogicalDatastoreType.OPERATIONAL, mwEthInterfaceIID);
1312                 if (problems == null) {
1313                         LOG.debug("DBRead Id {} no HybridMwStructureCurrentProblems", interfacePacUuid);
1314                 } else if (problems.getCurrentProblemList() == null) {
1315                         LOG.debug("DBRead Id {} empty CurrentProblemsList", interfacePacUuid);
1316                 } else {
1317                         for (StructureCurrentProblemTypeG problem : problems.getCurrentProblemList()) {
1318                                 resultList.add(new ProblemNotificationXml(mountPointNodeName, interfacePacUuid.getValue(),
1319                                                 problem.getProblemName(), InternalSeverity.valueOf(problem.getProblemSeverity()),
1320                                                 problem.getSequenceNumber().toString(), InternalDateAndTime.valueOf(problem.getTimeStamp())));
1321                         }
1322                 }
1323                 return resultList;
1324         }
1325
1326         /**
1327          * Read problems of specific interfaces. TODO Goal for future implementation
1328          * without usage of explicit new. Key is generated by newInstance() function
1329          * here to verify this approach.
1330          *
1331          * @param uuId
1332          *            Universal index of Interfacepac
1333          * @return number of alarms
1334          * @throws SecurityException
1335          * @throws NoSuchMethodException
1336          * @throws InvocationTargetException
1337          * @throws IllegalArgumentException
1338          * @throws IllegalAccessException
1339          * @throws InstantiationException
1340          */
1341         private List<ProblemNotificationXml> readTheFaultsOfMwTdmContainerPac(UniversalId interfacePacUuid,
1342                         List<ProblemNotificationXml> resultList) {
1343
1344                 final Class<MwTdmContainerPac> clazzPac = MwTdmContainerPac.class;
1345                 final Class<MwTdmContainerPacKey> clazzPacKey = MwTdmContainerPacKey.class;
1346                 final Class<TdmContainerCurrentProblems> clazzProblems = TdmContainerCurrentProblems.class;
1347                 // final Class<ContainerCurrentProblemTypeG> clazzProblem =
1348                 // ContainerCurrentProblemTypeG.class;
1349
1350                 LOG.info("DBRead Get problems for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
1351                                 mountPointNodeName, interfacePacUuid.getValue());
1352
1353                 try {
1354                         // -- Specific part 1
1355                         Constructor<MwTdmContainerPacKey> cons = clazzPacKey.getConstructor(UniversalId.class); // Avoid new()
1356                         InstanceIdentifier<TdmContainerCurrentProblems> mwEthInterfaceIID = InstanceIdentifier
1357                                         .builder(clazzPac, cons.newInstance(interfacePacUuid)).child(clazzProblems).build();
1358
1359                         // -- Specific part 2
1360                         TdmContainerCurrentProblems problems = GenericTransactionUtils.readData(netconfNodeDataBroker,
1361                                         LogicalDatastoreType.OPERATIONAL, mwEthInterfaceIID);
1362                         if (problems == null) {
1363                                 LOG.debug("DBRead Id {} no TdmContainerCurrentProblems", interfacePacUuid);
1364                         } else if (problems.getCurrentProblemList() == null) {
1365                                 LOG.debug("DBRead Id {} empty CurrentProblemsList", interfacePacUuid);
1366                         } else {
1367                                 // -- Specific part 3
1368                                 for (ContainerCurrentProblemTypeG problem : problems.getCurrentProblemList()) {
1369                                         resultList.add(new ProblemNotificationXml(mountPointNodeName, interfacePacUuid.getValue(),
1370                                                         problem.getProblemName(), InternalSeverity.valueOf(problem.getProblemSeverity()),
1371                                                         problem.getSequenceNumber().toString(),
1372                                                         InternalDateAndTime.valueOf(problem.getTimeStamp())));
1373                                 }
1374                         }
1375                 } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
1376                                 | IllegalArgumentException | InvocationTargetException e) {
1377                         LOG.warn("Could not reade instance of MwTdmContainerPacKey: ", e);
1378                 }
1379                 return resultList;
1380         }
1381
1382         private @Nullable Equipment readEquipmentPac(String interfacePacUuid) {
1383
1384                 return this.readEquipmentPac(new UniversalId(interfacePacUuid));
1385         }
1386
1387         /**
1388          * Read problems of specific interfaces
1389          *
1390          * @param interfacePacUuid
1391          *            Universal index of Equipmentpac
1392          * @return Equipment or null
1393          */
1394         private @Nullable Equipment readEquipmentPac(UniversalId interfacePacUuid) {
1395
1396                 final Class<Equipment> clazzPac = Equipment.class;
1397
1398                 LOG.info("DBRead Get problems for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
1399                                 mountPointNodeName, interfacePacUuid.getValue());
1400
1401                 InstanceIdentifier<Equipment> equipmentIID = InstanceIdentifier
1402                                 .builder(Equipment.class, new EquipmentKey(interfacePacUuid)).build();
1403
1404                 Equipment res = GenericTransactionUtils.readData(netconfNodeDataBroker, LogicalDatastoreType.OPERATIONAL,
1405                                 equipmentIID);
1406
1407                 return res;
1408         }
1409
1410         /**
1411          * Remove all entries from list
1412          */
1413         @Override
1414         public int removeAllCurrentProblemsOfNode() {
1415                 return microwaveEventListener.removeAllCurrentProblemsOfNode();
1416         }
1417
1418         /**
1419          * Register the listener
1420          */
1421         @Override
1422         public void doRegisterMicrowaveEventListener(MountPoint mountPoint) {
1423                 LOG.info("End registration listener for Mountpoint {}", mountPoint.getIdentifier().toString());
1424                 final Optional<NotificationService> optionalNotificationService = mountPoint
1425                                 .getService(NotificationService.class);
1426                 final NotificationService notificationService = optionalNotificationService.get();
1427                 // notificationService.registerNotificationListener(microwaveEventListener);
1428                 listenerRegistrationresult = notificationService.registerNotificationListener(microwaveEventListener);
1429                 LOG.info("End registration listener for Mountpoint {} Listener: {} Result: {}",
1430                                 mountPoint.getIdentifier().toString(), optionalNotificationService, listenerRegistrationresult);
1431         }
1432
1433
1434
1435 }