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