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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ne;
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;
50 * Get information over NETCONF device according to ONF Coremodel. Read networkelement and conditional packages.
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
61 public class ONFCoreNetworkElement12Microwave extends ONFCoreNetworkElement12Basic
62 implements NotificationActor<EventlogEntity> {
64 private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12Microwave.class);
66 private final @NonNull FaultService microwaveEventListener;
67 private final @NonNull EquipmentService equipmentService;
68 private final @NonNull OnfMicrowaveModel microwaveModel;
69 private final NotificationWorker<EventlogEntity> notificationQueue;
71 private ListenerRegistration<NotificationListener> listenerRegistrationresult = null;
73 /*-----------------------------------------------------------------------------
80 * @param acessor for device
81 * @param serviceProvider to get services
82 * @param onfMicrowaveModel handling ofmicrosoft model data
84 public ONFCoreNetworkElement12Microwave(@NonNull NetconfAccessor acessor,
85 @NonNull DeviceManagerServiceProvider serviceProvider, DeviceManagerOnfConfiguration configuration,
86 OnfMicrowaveModel onfMicrowaveModel) {
88 super(acessor, serviceProvider, configuration);
89 this.microwaveModel = onfMicrowaveModel;
91 this.microwaveEventListener = serviceProvider.getFaultService();
92 this.equipmentService = serviceProvider.getEquipmentService();
94 this.notificationQueue = new NotificationWorker<>(1, 100, this);
95 this.microwaveModel.setNotificationQueue(notificationQueue);
99 /*-----------------------------------------------------------------------------
105 * @param serviceProvider
106 * @param configuration
107 * @param onfMicrowaveModel
110 * DeviceMonitor Prepare check by updating NE state and reading all interfaces.
113 public void prepareCheck() {
114 synchronized (dmLock) {
115 boolean change = readNetworkElementAndInterfaces();
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());
126 // public boolean checkIfConnectionToMediatorIsOk() -> Shifted to super class
127 // public boolean checkIfConnectionToNeIsOk() -> Shifted to super class
129 /*-----------------------------------------------------------------------------
133 // public void initSynchronizationExtension() -> Shifted to super class
134 // private InstanceList readPTPClockInstances() -> Shifted to super class
136 /*-----------------------------------------------------------------------------
137 * Services for NE/Device synchronization
141 * Handling of specific Notifications from NE, indicating changes and need for synchronization.
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>
153 public void notificationActor(@NonNull EventlogEntity notification) {
155 LOG.debug("Enter change notification listener");
156 if (LOG.isTraceEnabled()) {
157 LOG.trace("Notification: {}", notification);
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();
167 LOG.debug("Leave change notification listener");
171 * Synchronize problems for a specific equipment-pac
173 * @param uuidString of the equipment-pac
175 private synchronized void syncEquipmentPac(String uuidString) {
177 int problems = microwaveEventListener.removeObjectsCurrentProblemsOfNode(nodeId, uuidString);
178 LOG.debug("Removed {} problems for uuid {}", problems, uuidString);
180 FaultData resultList = equipment.addProblemsofNodeObject(uuidString);
181 microwaveEventListener.initCurrentProblemStatus(nodeId, resultList);
182 LOG.debug("Added {} problems for uuid {}", resultList.size(), uuidString);
187 /*-----------------------------------------------------------------------------
188 * Problem/Fault related functions
192 * Read during startup all relevant structure and status parameters from device
195 public synchronized void initialReadFromNetworkElement() {
196 LOG.debug("Get info about {}", getMountpoint());
198 int problems = microwaveEventListener.removeAllCurrentProblemsOfNode(nodeId);
199 LOG.debug("Removed all {} problems from database at registration", problems);
201 // Step 2.1: access data broker within this mount point
202 LOG.debug("DBRead start");
204 // Step 2.2: read ne from data store
205 readNetworkElementAndInterfaces();
206 equipment.readNetworkElementEquipment();
208 // Step 2.3: read the existing faults and add to DB
209 FaultData resultList = readAllCurrentProblemsOfNode();
210 equipment.addProblemsofNode(resultList);
212 microwaveEventListener.initCurrentProblemStatus(nodeId, resultList);
213 equipmentService.writeEquipment(equipment.getEquipmentData());
215 LOG.info("Found info at {} for device {} number of problems: {}", getMountpoint(), getUuId(),
220 * LOG the newly added problems of the interface pac
226 private void debugResultList(String uuid, FaultData resultList, int idxStart) {
227 if (LOG.isDebugEnabled()) {
228 StringBuilder sb = new StringBuilder();
230 for (int t = idxStart; t < resultList.size(); t++) {
233 sb.append(resultList.get(t));
236 LOG.debug("Found problems {} {}", uuid, sb);
241 * Read current problems of AirInterfaces and EthernetContainer according to NE status into DB
243 * @return List with all problems
246 protected FaultData readAllCurrentProblemsOfNode() {
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
254 synchronized (getPmLock()) {
255 for (Lp lp : getInterfaceList()) {
257 idxStart = resultList.size();
258 uuid = Helper.nnGetUniversalId(lp.getUuid());
259 Class<?> lpClass = getLpExtension(lp);
261 ONFLayerProtocolName lpName = ONFLayerProtocolName.valueOf(lp.getLayerProtocolName());
262 microwaveModel.readTheFaultsOfMicrowaveModel(lpName, lpClass, uuid, resultList);
263 debugResultList(uuid.getValue(), resultList, idxStart);
267 // Step 2.4: Read other problems from mountpoint
268 if (isNetworkElementCurrentProblemsSupporting12) {
269 idxStart = resultList.size();
270 readNetworkElementCurrentProblems12(resultList);
271 debugResultList("CurrentProblems12", resultList, idxStart);
279 * Get from LayerProtocolExtensions the related generated ONF Interface PAC class which represents it.
281 * @param lp logical termination point
282 * @return Class of InterfacePac
285 private Class<?> getLpExtension(@Nullable Lp lp) {
287 String capability = EMPTY;
288 String revision = EMPTY;
289 String conditionalPackage = EMPTY;
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('?');
301 capability = capability.substring(0, idx);
305 if (valueName.contentEquals("revision")) {
306 revision = e.getValue();
308 if (valueName.contentEquals("conditional-package")) {
309 conditionalPackage = e.getValue();
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,
319 if (capability != null && !capability.isEmpty() && !revision.isEmpty() && !conditionalPackage.isEmpty()) {
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,
332 * Read element from class that could be not available
334 * @param ltp layer termination point
335 * @return List with extension parameters or empty list
338 private static List<Extension> getExtensionList(@Nullable Lp ltp) {
340 return ltp.nonnullExtension();
342 return EMPTYLTPEXTENSIONLIST;
347 public Optional<PerformanceDataLtp> getLtpHistoricalPerformanceData() {
348 synchronized (getPmLock()) {
350 LOG.debug("Enter query PM");
351 @SuppressWarnings("null")
354 ONFLayerProtocolName lpName = ONFLayerProtocolName.valueOf(lp.getLayerProtocolName());
355 return Optional.of(this.microwaveModel.getLtpHistoricalPerformanceData(lpName, lp));
357 return Optional.empty();
362 * Remove all entries from list
365 public int removeAllCurrentProblemsOfNode() {
366 return microwaveEventListener.removeAllCurrentProblemsOfNode(nodeId);
370 * Register the listener
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);
384 /*------------------------------------------------------------
385 * private function to access database
388 /*-----------------------------------------------------------------------------
389 * Reading problems for the networkElement V1.2
393 public void close() throws Exception {
394 if (listenerRegistrationresult != null) {
395 listenerRegistrationresult.close();
400 public NetworkElementDeviceType getDeviceType() {
401 return NetworkElementDeviceType.Wireless;