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