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