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