766ebdd23a4b00ca73cb99c4f6e2f899041521ef
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ne;
19
20 import java.util.List;
21 import java.util.Optional;
22 import org.eclipse.jdt.annotation.NonNull;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.onap.ccsdk.features.sdnr.wt.common.YangHelper;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.microwave.Helper;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.microwave.OnfMicrowaveModel;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.impl.DeviceManagerOnfConfiguration;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.notifications.NotificationActor;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.notifications.NotificationWorker;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.util.ONFLayerProtocolName;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.EquipmentService;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.PerformanceDataLtp;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.util.InconsistentPMDataException;
37 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
38 import org.opendaylight.mdsal.binding.api.MountPoint;
39 import org.opendaylight.mdsal.binding.api.NotificationService;
40 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.UniversalId;
41 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.extension.g.Extension;
42 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.logical.termination.point.g.Lp;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType;
45 import org.opendaylight.yangtools.concepts.ListenerRegistration;
46 import org.opendaylight.yangtools.yang.binding.NotificationListener;
47 import org.opendaylight.yangtools.yang.common.QName;
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
50
51 /**
52  * Get information over NETCONF device according to ONF Coremodel. Read networkelement and conditional packages.
53  *
54  * Get conditional packages from Networkelement Possible interfaces are: MWPS, LTP(MWPS-TTP), MWAirInterfacePac,
55  * MicrowaveModel-ObjectClasses-AirInterface ETH-CTP,LTP(Client), MW_EthernetContainer_Pac MWS, LTP(MWS-CTP-xD),
56  * MWAirInterfaceDiversityPac, MicrowaveModel-ObjectClasses-AirInterfaceDiversity MWS, LTP(MWS-TTP),
57  * ,MicrowaveModel-ObjectClasses-HybridMwStructure MWS, LTP(MWS-TTP),
58  * ,MicrowaveModel-ObjectClasses-PureEthernetStructure
59  *
60  * @author herbert
61  *
62  */
63 public class ONFCoreNetworkElement12Microwave extends ONFCoreNetworkElement12Basic
64         implements NotificationActor<EventlogEntity> {
65
66     private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12Microwave.class);
67
68     private final @NonNull FaultService microwaveEventListener;
69     private final @NonNull EquipmentService equipmentService;
70     private final @NonNull OnfMicrowaveModel microwaveModel;
71     private final NotificationWorker<EventlogEntity> notificationQueue;
72
73     private ListenerRegistration<NotificationListener> listenerRegistrationresult = null;
74
75     /*-----------------------------------------------------------------------------
76      * Construction
77      */
78
79     /**
80      * Constructor
81      *
82      * @param acessor for device
83      * @param serviceProvider to get services
84      * @param onfMicrowaveModel handling ofmicrosoft model data
85      */
86     public ONFCoreNetworkElement12Microwave(@NonNull NetconfBindingAccessor acessor,
87             @NonNull DeviceManagerServiceProvider serviceProvider, DeviceManagerOnfConfiguration configuration,
88             OnfMicrowaveModel onfMicrowaveModel) {
89
90         super(acessor, serviceProvider, configuration);
91         this.microwaveModel = onfMicrowaveModel;
92
93         this.microwaveEventListener = serviceProvider.getFaultService();
94         this.equipmentService = serviceProvider.getEquipmentService();
95
96         this.notificationQueue = new NotificationWorker<>(1, 100, this);
97         this.microwaveModel.setNotificationQueue(notificationQueue);
98
99     }
100
101     /*-----------------------------------------------------------------------------
102      * Functions
103      */
104
105     /**
106      * @param acessor
107      * @param serviceProvider
108      * @param configuration
109      * @param onfMicrowaveModel
110      */
111     /**
112      * DeviceMonitor Prepare check by updating NE state and reading all interfaces.
113      */
114     @Override
115     public void prepareCheck() {
116         synchronized (dmLock) {
117             boolean change = readNetworkElementAndInterfaces();
118             if (change) {
119                 int problems = microwaveEventListener.removeAllCurrentProblemsOfNode(nodeId);
120                 FaultData resultList = readAllCurrentProblemsOfNode();
121                 microwaveEventListener.initCurrentProblemStatus(nodeId, resultList);
122                 LOG.info("Resync mountpoint {} for device {}. Removed {}. Current problems: {}", getMountpoint(),
123                         getUuId(), problems, resultList.size());
124             }
125         }
126     }
127
128     // public boolean checkIfConnectionToMediatorIsOk() -> Shifted to super class
129     // public boolean checkIfConnectionToNeIsOk() -> Shifted to super class
130
131     /*-----------------------------------------------------------------------------
132      * Synchronization
133      */
134
135     // public void initSynchronizationExtension() -> Shifted to super class
136     // private InstanceList readPTPClockInstances() -> Shifted to super class
137
138     /*-----------------------------------------------------------------------------
139      * Services for NE/Device synchronization
140      */
141
142     /**
143      * Handling of specific Notifications from NE, indicating changes and need for synchronization.
144      *
145      * <attribute-value-changed-notification xmlns="urn:onf:params:xml:ns:yang:microwave-model">
146      * <attribute-name>/equipment-pac/equipment-current-problems</attribute-name>
147      * <object-id-ref>CARD-1.1.1.0</object-id-ref> <new-value></new-value> </attribute-value-changed-notification>
148      * <attribute-value-changed-notification xmlns="urn:onf:params:xml:ns:yang:microwave-model">
149      * <attribute-name>/network-element/extension[value-name="top-level-equipment"]/value</attribute-name>
150      * <object-id-ref>Hybrid-Z</object-id-ref>
151      * <new-value>SHELF-1.1.0.0,IDU-1.55.0.0,ODU-1.56.0.0,IDU-1.65.0.0</new-value>
152      * </attribute-value-changed-notification>
153      */
154     @Override
155     public void notificationActor(@NonNull EventlogEntity notification) {
156
157         LOG.debug("Enter change notification listener");
158         if (LOG.isTraceEnabled()) {
159             LOG.trace("Notification: {}", notification);
160         }
161         String attributeName = notification.getAttributeName();
162         if (attributeName != null) {
163             if (attributeName.equals("/equipment-pac/equipment-current-problems")) {
164                 syncEquipmentPac(notification.getObjectId());
165             } else if (attributeName.equals("/network-element/extension[value-name=\"top-level-equipment\"]/value")) {
166                 initialReadFromNetworkElement();
167             }
168         }
169         LOG.debug("Leave change notification listener");
170     }
171
172     /**
173      * Synchronize problems for a specific equipment-pac
174      *
175      * @param uuidString of the equipment-pac
176      */
177     private void syncEquipmentPac(String uuidString) {
178
179         int problems = microwaveEventListener.removeObjectsCurrentProblemsOfNode(nodeId, uuidString);
180         LOG.debug("Removed {} problems for uuid {}", problems, uuidString);
181
182         FaultData resultList = equipment.addProblemsofNodeObject(uuidString);
183         microwaveEventListener.initCurrentProblemStatus(nodeId, resultList);
184         LOG.debug("Added {} problems for uuid {}", resultList.size(), uuidString);
185
186     }
187
188
189     /*-----------------------------------------------------------------------------
190      * Problem/Fault related functions
191      */
192
193     /**
194      * Read during startup all relevant structure and status parameters from device
195      */
196     @Override
197     public void initialReadFromNetworkElement() {
198         LOG.debug("Get info about {}", getMountpoint());
199
200         int problems = microwaveEventListener.removeAllCurrentProblemsOfNode(nodeId);
201         LOG.debug("Removed all {} problems from database at registration", problems);
202
203         // Step 2.1: access data broker within this mount point
204         LOG.debug("DBRead start");
205
206         // Step 2.2: read ne from data store
207         readNetworkElementAndInterfaces();
208         LOG.debug("NETCONF read network element and interfaces completed");
209         equipment.readNetworkElementEquipment();
210         LOG.debug("NETCONF read equipment completed");
211
212         // Step 2.3: read the existing faults and add to DB
213         FaultData resultList = readAllCurrentProblemsOfNode();
214         LOG.debug("NETCONF read current problems completed");
215         equipment.addProblemsofNode(resultList);
216
217         microwaveEventListener.initCurrentProblemStatus(nodeId, resultList);
218         LOG.debug("DB write current problems completed");
219         equipmentService.writeEquipment(nodeId, equipment.getEquipmentData());
220
221         LOG.info("Found info at {} for device {} number of problems: {}", getMountpoint(), getUuId(),
222                 resultList.size());
223     }
224
225     /**
226      * LOG the newly added problems of the interface pac
227      *
228      * @param idxStart
229      * @param uuid
230      * @param resultList
231      */
232     private void debugResultList(String uuid, FaultData resultList, int idxStart) {
233         if (LOG.isDebugEnabled()) {
234             StringBuilder sb = new StringBuilder();
235             int idx = 0;
236             for (int t = idxStart; t < resultList.size(); t++) {
237                 sb.append(idx++);
238                 sb.append(":{");
239                 sb.append(resultList.get(t));
240                 sb.append('}');
241             }
242             LOG.debug("Found problems {} {}", uuid, sb);
243         }
244     }
245
246     /**
247      * Read current problems of AirInterfaces and EthernetContainer according to NE status into DB
248      *
249      * @return List with all problems
250      */
251     @Override
252     protected FaultData readAllCurrentProblemsOfNode() {
253
254         // Step 2.3: read the existing faults and add to DB
255         FaultData resultList = new FaultData();
256         int idxStart; // Start index for debug messages
257         @NonNull
258         UniversalId uuid;
259
260         synchronized (getPmLock()) {
261             for (Lp lp : getInterfaceList()) {
262
263                 idxStart = resultList.size();
264                 uuid = Helper.nnGetUniversalId(lp.getUuid());
265                 @Nullable
266                 Class<?> lpClass = getLpExtension(lp);
267
268                 ONFLayerProtocolName lpName = ONFLayerProtocolName.valueOf(lp.getLayerProtocolName());
269                 microwaveModel.readTheFaultsOfMicrowaveModel(lpName, lpClass, uuid, resultList);
270                 debugResultList(uuid.getValue(), resultList, idxStart);
271             }
272         }
273
274         // Step 2.4: Read other problems from mountpoint
275         if (isNetworkElementCurrentProblemsSupporting12) {
276             idxStart = resultList.size();
277             readNetworkElementCurrentProblems12(resultList);
278             debugResultList("CurrentProblems12", resultList, idxStart);
279         }
280
281         return resultList;
282
283     }
284
285     /**
286      * Get from LayerProtocolExtensions the related generated ONF Interface PAC class which represents it.
287      *
288      * @param lp logical termination point
289      * @return Class of InterfacePac
290      */
291     @Nullable
292     private Class<?> getLpExtension(@Nullable Lp lp) {
293
294         String capability = EMPTY;
295         String revision = EMPTY;
296         String conditionalPackage = EMPTY;
297         Class<?> res = null;
298
299         if (lp != null) {
300             for (Extension e : getExtensionList(lp)) {
301                 String valueName = e.getValueName();
302                 if (valueName != null) {
303                     if (valueName.contentEquals("capability")) {
304                         capability = e.getValue();
305                         if (capability != null) {
306                             int idx = capability.indexOf('?');
307                             if (idx != -1) {
308                                 capability = capability.substring(0, idx);
309                             }
310                         }
311                     }
312                     if (valueName.contentEquals("revision")) {
313                         revision = e.getValue();
314                     }
315                     if (valueName.contentEquals("conditional-package")) {
316                         conditionalPackage = e.getValue();
317                     }
318                 }
319             }
320         }
321         // QName qName =
322         // org.opendaylight.yangtools.yang.common.QName.create("urn:onf:params:xml:ns:yang:microwave-model",
323         // "2017-03-24", "mw-air-interface-pac").intern();
324         LOG.info("LpExtension capability={} revision={} conditionalPackage={}", capability, revision,
325                 conditionalPackage);
326         if (capability != null && !capability.isEmpty() && !revision.isEmpty() && !conditionalPackage.isEmpty()) {
327             try {
328                 QName qName = QName.create(capability, revision, conditionalPackage);
329                 res = this.microwaveModel.getClassForLtpExtension(qName);
330             } catch (IllegalArgumentException e) {
331                 LOG.warn("Can not create QName from ({}{}{}): {}", capability, revision, conditionalPackage,
332                         e.getMessage());
333             }
334         }
335         return res;
336     }
337
338     /**
339      * Read element from class that could be not available
340      *
341      * @param ltp layer termination point
342      * @return List with extension parameters or empty list
343      */
344     @NonNull
345     private static List<Extension> getExtensionList(@Nullable Lp ltp) {
346         if (ltp != null) {
347             return YangHelper.getList(ltp.nonnullExtension());
348         } else {
349             return EMPTYLTPEXTENSIONLIST;
350         }
351     }
352
353     @Override
354     public Optional<PerformanceDataLtp> getLtpHistoricalPerformanceData() throws InconsistentPMDataException {
355         synchronized (getPmLock()) {
356             if (pmLp != null) {
357                 LOG.debug("Enter query PM");
358                 @NonNull
359                 Lp lp = pmLp;
360                 ONFLayerProtocolName lpName = ONFLayerProtocolName.valueOf(lp.getLayerProtocolName());
361                 return Optional.of(this.microwaveModel.getLtpHistoricalPerformanceData(lpName, lp));
362             }
363             return Optional.empty();
364         }
365     }
366
367     /**
368      * Remove all entries from list
369      */
370     @Override
371     public int removeAllCurrentProblemsOfNode() {
372         return microwaveEventListener.removeAllCurrentProblemsOfNode(nodeId);
373     }
374
375     /**
376      * Register the listener
377      */
378     @Override
379     public void doRegisterEventListener(MountPoint mountPoint) {
380         LOG.info("Begin registration listener for Mountpoint");
381         final Optional<NotificationService> optionalNotificationService =
382                 mountPoint.getService(NotificationService.class);
383         if (optionalNotificationService.isPresent()) {
384             final NotificationService notificationService = optionalNotificationService.get();
385             // notificationService.registerNotificationListener(microwaveEventListener);
386             listenerRegistrationresult =
387                     notificationService.registerNotificationListener(microwaveModel.getNotificationListener());
388             LOG.info("End registration listener for Mountpoint Result: {}", listenerRegistrationresult);
389         } else {
390             LOG.error("Could not get NotificationService, hence microwave notification listener not registered");
391         }
392     }
393
394     /*------------------------------------------------------------
395      * private function to access database
396      */
397
398     /*-----------------------------------------------------------------------------
399      * Reading problems for the networkElement V1.2
400      */
401
402     @Override
403     public void close() throws Exception {
404         if (listenerRegistrationresult != null) {
405             listenerRegistrationresult.close();
406         }
407     }
408
409     @Override
410     public NetworkElementDeviceType getDeviceType() {
411         return NetworkElementDeviceType.Wireless;
412     }
413
414 }