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.common.YangHelper;
 
  25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.microwave.Helper;
 
  26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.microwave.OnfMicrowaveModel;
 
  27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.impl.DeviceManagerOnfConfiguration;
 
  28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.notifications.NotificationActor;
 
  29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.notifications.NotificationWorker;
 
  30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.util.ONFLayerProtocolName;
 
  31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
 
  32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.EquipmentService;
 
  33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
 
  34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
 
  35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.PerformanceDataLtp;
 
  36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.util.InconsistentPMDataException;
 
  37 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
 
  38 import org.opendaylight.mdsal.binding.api.MountPoint;
 
  39 import org.opendaylight.mdsal.binding.api.NotificationService;
 
  40 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.UniversalId;
 
  41 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.extension.g.Extension;
 
  42 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.logical.termination.point.g.Lp;
 
  43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity;
 
  44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType;
 
  45 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 
  46 import org.opendaylight.yangtools.yang.binding.NotificationListener;
 
  47 import org.opendaylight.yangtools.yang.common.QName;
 
  48 import org.slf4j.Logger;
 
  49 import org.slf4j.LoggerFactory;
 
  52  * Get information over NETCONF device according to ONF Coremodel. Read networkelement and conditional packages.
 
  54  * Get conditional packages from Networkelement Possible interfaces are: MWPS, LTP(MWPS-TTP), MWAirInterfacePac,
 
  55  * MicrowaveModel-ObjectClasses-AirInterface ETH-CTP,LTP(Client), MW_EthernetContainer_Pac MWS, LTP(MWS-CTP-xD),
 
  56  * MWAirInterfaceDiversityPac, MicrowaveModel-ObjectClasses-AirInterfaceDiversity MWS, LTP(MWS-TTP),
 
  57  * ,MicrowaveModel-ObjectClasses-HybridMwStructure MWS, LTP(MWS-TTP),
 
  58  * ,MicrowaveModel-ObjectClasses-PureEthernetStructure
 
  63 public class ONFCoreNetworkElement12Microwave extends ONFCoreNetworkElement12Basic
 
  64         implements NotificationActor<EventlogEntity> {
 
  66     private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12Microwave.class);
 
  68     private final @NonNull FaultService microwaveEventListener;
 
  69     private final @NonNull EquipmentService equipmentService;
 
  70     private final @NonNull OnfMicrowaveModel microwaveModel;
 
  71     private final NotificationWorker<EventlogEntity> notificationQueue;
 
  73     private ListenerRegistration<NotificationListener> listenerRegistrationresult = null;
 
  75     /*-----------------------------------------------------------------------------
 
  82      * @param acessor for device
 
  83      * @param serviceProvider to get services
 
  84      * @param onfMicrowaveModel handling ofmicrosoft model data
 
  86     public ONFCoreNetworkElement12Microwave(@NonNull NetconfBindingAccessor acessor,
 
  87             @NonNull DeviceManagerServiceProvider serviceProvider, DeviceManagerOnfConfiguration configuration,
 
  88             OnfMicrowaveModel onfMicrowaveModel) {
 
  90         super(acessor, serviceProvider, configuration);
 
  91         this.microwaveModel = onfMicrowaveModel;
 
  93         this.microwaveEventListener = serviceProvider.getFaultService();
 
  94         this.equipmentService = serviceProvider.getEquipmentService();
 
  96         this.notificationQueue = new NotificationWorker<>(1, 100, this);
 
  97         this.microwaveModel.setNotificationQueue(notificationQueue);
 
 101     /*-----------------------------------------------------------------------------
 
 107      * @param serviceProvider
 
 108      * @param configuration
 
 109      * @param onfMicrowaveModel
 
 112      * DeviceMonitor Prepare check by updating NE state and reading all interfaces.
 
 115     public void prepareCheck() {
 
 116         synchronized (dmLock) {
 
 117             boolean change = readNetworkElementAndInterfaces();
 
 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());
 
 128     // public boolean checkIfConnectionToMediatorIsOk() -> Shifted to super class
 
 129     // public boolean checkIfConnectionToNeIsOk() -> Shifted to super class
 
 131     /*-----------------------------------------------------------------------------
 
 135     // public void initSynchronizationExtension() -> Shifted to super class
 
 136     // private InstanceList readPTPClockInstances() -> Shifted to super class
 
 138     /*-----------------------------------------------------------------------------
 
 139      * Services for NE/Device synchronization
 
 143      * Handling of specific Notifications from NE, indicating changes and need for synchronization.
 
 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> </attribute-value-changed-notification>
 
 148      * <attribute-value-changed-notification xmlns="urn:onf:params:xml:ns:yang:microwave-model">
 
 149      * <attribute-name>/network-element/extension[value-name="top-level-equipment"]/value</attribute-name>
 
 150      * <object-id-ref>Hybrid-Z</object-id-ref>
 
 151      * <new-value>SHELF-1.1.0.0,IDU-1.55.0.0,ODU-1.56.0.0,IDU-1.65.0.0</new-value>
 
 152      * </attribute-value-changed-notification>
 
 155     public void notificationActor(@NonNull EventlogEntity notification) {
 
 157         LOG.debug("Enter change notification listener");
 
 158         if (LOG.isTraceEnabled()) {
 
 159             LOG.trace("Notification: {}", notification);
 
 161         String attributeName = notification.getAttributeName();
 
 162         if (attributeName != null) {
 
 163             if (attributeName.equals("/equipment-pac/equipment-current-problems")) {
 
 164                 syncEquipmentPac(notification.getObjectId());
 
 165             } else if (attributeName.equals("/network-element/extension[value-name=\"top-level-equipment\"]/value")) {
 
 166                 initialReadFromNetworkElement();
 
 169         LOG.debug("Leave change notification listener");
 
 173      * Synchronize problems for a specific equipment-pac
 
 175      * @param uuidString of the equipment-pac
 
 177     private void syncEquipmentPac(String uuidString) {
 
 179         int problems = microwaveEventListener.removeObjectsCurrentProblemsOfNode(nodeId, uuidString);
 
 180         LOG.debug("Removed {} problems for uuid {}", problems, uuidString);
 
 182         FaultData resultList = equipment.addProblemsofNodeObject(uuidString);
 
 183         microwaveEventListener.initCurrentProblemStatus(nodeId, resultList);
 
 184         LOG.debug("Added {} problems for uuid {}", resultList.size(), uuidString);
 
 189     /*-----------------------------------------------------------------------------
 
 190      * Problem/Fault related functions
 
 194      * Read during startup all relevant structure and status parameters from device
 
 197     public void initialReadFromNetworkElement() {
 
 198         LOG.debug("Get info about {}", getMountpoint());
 
 200         int problems = microwaveEventListener.removeAllCurrentProblemsOfNode(nodeId);
 
 201         LOG.debug("Removed all {} problems from database at registration", problems);
 
 203         // Step 2.1: access data broker within this mount point
 
 204         LOG.debug("DBRead start");
 
 206         // Step 2.2: read ne from data store
 
 207         readNetworkElementAndInterfaces();
 
 208         LOG.debug("NETCONF read network element and interfaces completed");
 
 209         equipment.readNetworkElementEquipment();
 
 210         LOG.debug("NETCONF read equipment completed");
 
 212         // Step 2.3: read the existing faults and add to DB
 
 213         FaultData resultList = readAllCurrentProblemsOfNode();
 
 214         LOG.debug("NETCONF read current problems completed");
 
 215         equipment.addProblemsofNode(resultList);
 
 217         microwaveEventListener.initCurrentProblemStatus(nodeId, resultList);
 
 218         LOG.debug("DB write current problems completed");
 
 219         equipmentService.writeEquipment(nodeId, equipment.getEquipmentData());
 
 221         LOG.info("Found info at {} for device {} number of problems: {}", getMountpoint(), getUuId(),
 
 226      * LOG the newly added problems of the interface pac
 
 232     private void debugResultList(String uuid, FaultData resultList, int idxStart) {
 
 233         if (LOG.isDebugEnabled()) {
 
 234             StringBuilder sb = new StringBuilder();
 
 236             for (int t = idxStart; t < resultList.size(); t++) {
 
 239                 sb.append(resultList.get(t));
 
 242             LOG.debug("Found problems {} {}", uuid, sb);
 
 247      * Read current problems of AirInterfaces and EthernetContainer according to NE status into DB
 
 249      * @return List with all problems
 
 252     protected FaultData readAllCurrentProblemsOfNode() {
 
 254         // Step 2.3: read the existing faults and add to DB
 
 255         FaultData resultList = new FaultData();
 
 256         int idxStart; // Start index for debug messages
 
 260         synchronized (getPmLock()) {
 
 261             for (Lp lp : getInterfaceList()) {
 
 263                 idxStart = resultList.size();
 
 264                 uuid = Helper.nnGetUniversalId(lp.getUuid());
 
 266                 Class<?> lpClass = getLpExtension(lp);
 
 268                 ONFLayerProtocolName lpName = ONFLayerProtocolName.valueOf(lp.getLayerProtocolName());
 
 269                 microwaveModel.readTheFaultsOfMicrowaveModel(lpName, lpClass, uuid, resultList);
 
 270                 debugResultList(uuid.getValue(), resultList, idxStart);
 
 274         // Step 2.4: Read other problems from mountpoint
 
 275         if (isNetworkElementCurrentProblemsSupporting12) {
 
 276             idxStart = resultList.size();
 
 277             readNetworkElementCurrentProblems12(resultList);
 
 278             debugResultList("CurrentProblems12", resultList, idxStart);
 
 286      * Get from LayerProtocolExtensions the related generated ONF Interface PAC class which represents it.
 
 288      * @param lp logical termination point
 
 289      * @return Class of InterfacePac
 
 292     private Class<?> getLpExtension(@Nullable Lp lp) {
 
 294         String capability = EMPTY;
 
 295         String revision = EMPTY;
 
 296         String conditionalPackage = EMPTY;
 
 300             for (Extension e : getExtensionList(lp)) {
 
 301                 String valueName = e.getValueName();
 
 302                 if (valueName != null) {
 
 303                     if (valueName.contentEquals("capability")) {
 
 304                         capability = e.getValue();
 
 305                         if (capability != null) {
 
 306                             int idx = capability.indexOf('?');
 
 308                                 capability = capability.substring(0, idx);
 
 312                     if (valueName.contentEquals("revision")) {
 
 313                         revision = e.getValue();
 
 315                     if (valueName.contentEquals("conditional-package")) {
 
 316                         conditionalPackage = e.getValue();
 
 322         // org.opendaylight.yangtools.yang.common.QName.create("urn:onf:params:xml:ns:yang:microwave-model",
 
 323         // "2017-03-24", "mw-air-interface-pac").intern();
 
 324         LOG.info("LpExtension capability={} revision={} conditionalPackage={}", capability, revision,
 
 326         if (capability != null && !capability.isEmpty() && !revision.isEmpty() && !conditionalPackage.isEmpty()) {
 
 328                 QName qName = QName.create(capability, revision, conditionalPackage);
 
 329                 res = this.microwaveModel.getClassForLtpExtension(qName);
 
 330             } catch (IllegalArgumentException e) {
 
 331                 LOG.warn("Can not create QName from ({}{}{}): {}", capability, revision, conditionalPackage,
 
 339      * Read element from class that could be not available
 
 341      * @param ltp layer termination point
 
 342      * @return List with extension parameters or empty list
 
 345     private static List<Extension> getExtensionList(@Nullable Lp ltp) {
 
 347             return YangHelper.getList(ltp.nonnullExtension());
 
 349             return EMPTYLTPEXTENSIONLIST;
 
 354     public Optional<PerformanceDataLtp> getLtpHistoricalPerformanceData() throws InconsistentPMDataException {
 
 355         synchronized (getPmLock()) {
 
 357                 LOG.debug("Enter query PM");
 
 360                 ONFLayerProtocolName lpName = ONFLayerProtocolName.valueOf(lp.getLayerProtocolName());
 
 361                 return Optional.of(this.microwaveModel.getLtpHistoricalPerformanceData(lpName, lp));
 
 363             return Optional.empty();
 
 368      * Remove all entries from list
 
 371     public int removeAllCurrentProblemsOfNode() {
 
 372         return microwaveEventListener.removeAllCurrentProblemsOfNode(nodeId);
 
 376      * Register the listener
 
 379     public void doRegisterEventListener(MountPoint mountPoint) {
 
 380         LOG.info("Begin registration listener for Mountpoint");
 
 381         final Optional<NotificationService> optionalNotificationService =
 
 382                 mountPoint.getService(NotificationService.class);
 
 383         if (optionalNotificationService.isPresent()) {
 
 384             final NotificationService notificationService = optionalNotificationService.get();
 
 385             // notificationService.registerNotificationListener(microwaveEventListener);
 
 386             listenerRegistrationresult =
 
 387                     notificationService.registerNotificationListener(microwaveModel.getNotificationListener());
 
 388             LOG.info("End registration listener for Mountpoint Result: {}", listenerRegistrationresult);
 
 390             LOG.error("Could not get NotificationService, hence microwave notification listener not registered");
 
 394     /*------------------------------------------------------------
 
 395      * private function to access database
 
 398     /*-----------------------------------------------------------------------------
 
 399      * Reading problems for the networkElement V1.2
 
 403     public void close() throws Exception {
 
 404         if (listenerRegistrationresult != null) {
 
 405             listenerRegistrationresult.close();
 
 410     public NetworkElementDeviceType getDeviceType() {
 
 411         return NetworkElementDeviceType.Wireless;