c90e76efc830835acc58bd01b7e2a4b15bb27c95
[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: {}", getMountPointNodeName(),
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         // optionalNe.getLtp().get(0).getLp();
191         LOG.debug("Get info about {}", getMountPointNodeName());
192
193         int problems = microwaveEventListener.removeAllCurrentProblemsOfNode(nodeId);
194         LOG.debug("Removed all {} problems from database at registration", problems);
195
196         // Step 2.1: access data broker within this mount point
197         LOG.debug("DBRead start");
198
199         // Step 2.2: read ne from data store
200         readNetworkElementAndInterfaces();
201         equipment.readNetworkElementEquipment();
202
203         // Step 2.3: read the existing faults and add to DB
204         FaultData resultList = readAllCurrentProblemsOfNode();
205         equipment.addProblemsofNode(resultList);
206
207         microwaveEventListener.initCurrentProblemStatus(nodeId, resultList);
208         equipmentService.writeEquipment(equipment.getEquipmentData());
209
210         LOG.info("Found info at {} for device {} number of problems: {}", getMountPointNodeName(), getUuId(),
211                 resultList.size());
212     }
213
214     /**
215      * LOG the newly added problems of the interface pac
216      *
217      * @param idxStart
218      * @param uuid
219      * @param resultList
220      */
221     private void debugResultList(String uuid, FaultData resultList, int idxStart) {
222         if (LOG.isDebugEnabled()) {
223             StringBuffer sb = new StringBuffer();
224             int idx = 0;
225             for (int t = idxStart; t < resultList.size(); t++) {
226                 sb.append(idx++);
227                 sb.append(":{");
228                 sb.append(resultList.get(t));
229                 sb.append('}');
230             }
231             LOG.debug("Found problems {} {}", uuid, sb.toString());
232         }
233     }
234
235     /**
236      * Read current problems of AirInterfaces and EthernetContainer according to NE status into DB
237      *
238      * @return List with all problems
239      */
240     @Override
241     protected FaultData readAllCurrentProblemsOfNode() {
242
243         // Step 2.3: read the existing faults and add to DB
244         FaultData resultList = new FaultData();
245         int idxStart; // Start index for debug messages
246         @NonNull UniversalId uuid;
247
248         synchronized (getPmLock()) {
249             for (Lp lp : getInterfaceList()) {
250
251                 idxStart = resultList.size();
252                 uuid = Helper.nnGetUniversalId(lp.getUuid());
253                 Class<?> lpClass = getLpExtension(lp);
254
255                 ONFLayerProtocolName lpName = ONFLayerProtocolName.valueOf(lp.getLayerProtocolName());
256                 microwaveModel.readTheFaultsOfMicrowaveModel(lpName, lpClass, uuid, resultList);
257                 debugResultList(uuid.getValue(), resultList, idxStart);
258             }
259         }
260
261         // Step 2.4: Read other problems from mountpoint
262         if (isNetworkElementCurrentProblemsSupporting12) {
263             idxStart = resultList.size();
264             readNetworkElementCurrentProblems12(resultList);
265             debugResultList("CurrentProblems12", resultList, idxStart);
266         }
267
268         return resultList;
269
270     }
271
272     /**
273      * Get from LayerProtocolExtensions the related generated ONF Interface PAC class which represents it.
274      *
275      * @param lp logical termination point
276      * @return Class of InterfacePac
277      */
278     @Nullable
279     private Class<?> getLpExtension(@Nullable Lp lp) {
280
281         String capability = EMPTY;
282         String revision = EMPTY;
283         String conditionalPackage = EMPTY;
284         Class<?> res = null;
285
286         if (lp != null) {
287             for (Extension e : getExtensionList(lp)) {
288                 String valueName = e.getValueName();
289                 if (valueName != null) {
290                     if (valueName.contentEquals("capability")) {
291                         capability = e.getValue();
292                         if (capability != null) {
293                             int idx = capability.indexOf("?");
294                             if (idx != -1) {
295                                 capability = capability.substring(0, idx);
296                             }
297                         }
298                     }
299                     if (valueName.contentEquals("revision")) {
300                         revision = e.getValue();
301                     }
302                     if (valueName.contentEquals("conditional-package")) {
303                         conditionalPackage = e.getValue();
304                     }
305                 }
306             }
307         }
308         // QName qName =
309         // org.opendaylight.yangtools.yang.common.QName.create("urn:onf:params:xml:ns:yang:microwave-model",
310         // "2017-03-24", "mw-air-interface-pac").intern();
311         LOG.info("LpExtension capability={} revision={} conditionalPackage={}", capability, revision,
312                 conditionalPackage);
313         if (!capability.isEmpty() && !revision.isEmpty() && !conditionalPackage.isEmpty()) {
314             try {
315                 QName qName = QName.create(capability, revision, conditionalPackage);
316                 res = this.microwaveModel.getClassForLtpExtension(qName);
317             } catch (IllegalArgumentException e) {
318                 LOG.debug("Can not create QName from ({}{}{}): {}", capability, revision, conditionalPackage,
319                         e.getMessage());
320             }
321         }
322         return res;
323     }
324
325     /**
326      * Read element from class that could be not available
327      *
328      * @param ltp layer termination point
329      * @return List with extension parameters or empty list
330      */
331     @NonNull
332     private static List<Extension> getExtensionList(@Nullable Lp ltp) {
333         if (ltp != null) {
334             return ltp.nonnullExtension();
335         } else {
336             return EMPTYLTPEXTENSIONLIST;
337         }
338     }
339
340     @Override
341     public Optional<PerformanceDataLtp> getLtpHistoricalPerformanceData() {
342         synchronized (getPmLock()) {
343             if (pmLp != null) {
344                 LOG.debug("Enter query PM");
345                 @SuppressWarnings("null")
346                 @NonNull
347                 Lp lp = pmLp;
348                 ONFLayerProtocolName lpName = ONFLayerProtocolName.valueOf(lp.getLayerProtocolName());
349                 return Optional.of(this.microwaveModel.getLtpHistoricalPerformanceData(lpName, lp));
350             }
351             return Optional.empty();
352         }
353     }
354
355     /**
356      * Remove all entries from list
357      */
358     @Override
359     public int removeAllCurrentProblemsOfNode() {
360         return microwaveEventListener.removeAllCurrentProblemsOfNode(nodeId);
361     }
362
363     /**
364      * Register the listener
365      */
366     @Override
367     public void doRegisterEventListener(MountPoint mountPoint) {
368         LOG.info("Begin registration listener for Mountpoint");
369         final Optional<NotificationService> optionalNotificationService =
370                 mountPoint.getService(NotificationService.class);
371         final NotificationService notificationService = optionalNotificationService.get();
372         // notificationService.registerNotificationListener(microwaveEventListener);
373         listenerRegistrationresult =
374                 notificationService.registerNotificationListener(microwaveModel.getNotificationListener());
375         LOG.info("End registration listener for Mountpoint Result: {}",listenerRegistrationresult);
376     }
377
378     /*------------------------------------------------------------
379      * private function to access database
380      */
381
382     /*-----------------------------------------------------------------------------
383      * Reading problems for the networkElement V1.2
384      */
385
386     @Override
387     public void close() throws Exception {
388         if (listenerRegistrationresult != null) {
389             listenerRegistrationresult.close();
390         }
391     }
392
393     @Override
394     public NetworkElementDeviceType getDeviceType() {
395         return NetworkElementDeviceType.Wireless;
396     }
397
398 }