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
 
  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==========================================================================
 
  17  ******************************************************************************/
 
  18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf;
 
  20 import java.util.ArrayList;
 
  21 import java.util.Collections;
 
  22 import java.util.Iterator;
 
  23 import java.util.List;
 
  24 import java.util.concurrent.CopyOnWriteArrayList;
 
  26 import javax.annotation.Nonnull;
 
  27 import javax.annotation.Nullable;
 
  29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.InternalDateAndTime;
 
  30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.InternalSeverity;
 
  31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.InventoryInformation;
 
  32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.container.AllPm;
 
  33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.container.Capabilities;
 
  34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.util.GenericTransactionUtils;
 
  35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.wrapperc.WrapperPTPModelRev170208;
 
  36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml;
 
  37 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 
  38 import org.opendaylight.controller.md.sal.binding.api.MountPoint;
 
  39 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 
  40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ptp.dataset.rev170208.InstanceList;
 
  41 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.NetworkElement;
 
  42 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.UniversalId;
 
  43 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.extension.g.Extension;
 
  44 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.logical.termination.point.g.Lp;
 
  45 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.network.element.Ltp;
 
  46 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.NetworkElementPac;
 
  47 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.network.element.pac.NetworkElementCurrentProblems;
 
  48 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
  49 import org.slf4j.Logger;
 
  50 import org.slf4j.LoggerFactory;
 
  54  * This class contains the ONF Core model Version 1.2 related functions.<br>
 
  55  * Provides the basic ONF Core Model function.<br>
 
  56  * - initialReadFromNetworkElement is not implemented in child classes.
 
  58 @SuppressWarnings("deprecation")
 
  59 public abstract class ONFCoreNetworkElement12Base extends ONFCoreNetworkElementBase implements ONFCoreNetworkElementCoreData {
 
  61     private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12Base.class);
 
  63     protected static final List<Extension> EMPTYLTPEXTENSIONLIST = new ArrayList<>();
 
  64     // private static final List<Ltp> EMPTYLTPLIST = new ArrayList<>();
 
  66     protected static final InstanceIdentifier<NetworkElement> NETWORKELEMENT_IID = InstanceIdentifier
 
  67             .builder(NetworkElement.class).build();
 
  70     /*-----------------------------------------------------------------------------
 
  74     // Non specific part. Used by all functions.
 
  75     /** interfaceList is used by PM task and should be synchronized */
 
  76     private final @Nonnull List<Lp> interfaceList = Collections.synchronizedList(new CopyOnWriteArrayList<>());
 
  77     private @Nullable NetworkElement optionalNe = null;
 
  79     // Performance monitoring specific part
 
  80     /** Lock for the PM access specific elements that could be null */
 
  81     private final @Nonnull Object pmLock = new Object();
 
  82     protected @Nullable Iterator<Lp> interfaceListIterator = null;
 
  83     /** Actual pmLp used during iteration over interfaces */
 
  84     protected @Nullable Lp pmLp = null;
 
  86     // Device monitoring specific part
 
  87     /** Lock for the DM access specific elements that could be null */
 
  88     protected final @Nonnull Object dmLock = new Object();
 
  90     protected final boolean isNetworkElementCurrentProblemsSupporting12;
 
  92     private final ONFCoreNetworkElement12Equipment equipment;
 
  94     private @Nonnull InventoryInformation inventoryInformation = new InventoryInformation();
 
 100     protected ONFCoreNetworkElement12Base(String mountPointNodeName, DataBroker netconfNodeDataBroker,
 
 101             Capabilities capabilities) {
 
 102         super(mountPointNodeName, netconfNodeDataBroker, capabilities);
 
 103         // TODO Auto-generated constructor stub
 
 104         this.isNetworkElementCurrentProblemsSupporting12 = capabilities.isSupportingNamespaceAndRevision(NetworkElementPac.QNAME);
 
 105         this.equipment = new ONFCoreNetworkElement12Equipment(this, capabilities);
 
 106         WrapperPTPModelRev170208.initSynchronizationExtension(mountPointNodeName, netconfNodeDataBroker, capabilities);
 
 107         LOG.debug("support necurrent-problem-list=" + this.isNetworkElementCurrentProblemsSupporting12);
 
 108         LOG.info("Create NE instance {}", InstanceList.QNAME.getLocalName());
 
 111     /*---------------------------------------------------------------
 
 116     public NetworkElement getOptionalNetworkElement() {
 
 120         List<Lp> getInterfaceList() {
 
 121                 return interfaceList;
 
 124     public Object getPmLock() {
 
 128     public ONFCoreNetworkElement12Equipment getEquipment() {
 
 132     /*---------------------------------------------------------------
 
 133      * Core model related function
 
 137      * Read the NetworkElement part from database.
 
 139      * @return Optional with NetworkElement or empty
 
 142     private NetworkElement readNetworkElement() {
 
 143         // Step 2.2: construct data and the relative iid
 
 144         // The schema path to identify an instance is
 
 145         // <i>CoreModel-CoreNetworkModule-ObjectClasses/NetworkElement</i>
 
 146         // Read to the config data store
 
 147         return GenericTransactionUtils.readData(getNetconfNodeDataBroker(), LogicalDatastoreType.OPERATIONAL,
 
 152      * Get uuid of Optional NE.
 
 154      * @return Uuid or EMPTY String if optionNE is not available
 
 156     protected String getUuId() {
 
 160             uuid = optionalNe != null ? optionalNe.getUuid() != null ? optionalNe.getUuid().getValue() : EMPTY : EMPTY;
 
 161         } catch (NullPointerException e) {
 
 162             // Unfortunately throws null pointer if not definied
 
 168      * Read from NetworkElement and verify LTPs have changed. If the NE has changed, update to the new
 
 169      * structure. From initial state it changes also.
 
 171     protected synchronized boolean readNetworkElementAndInterfaces() {
 
 173         LOG.debug("Update mountpoint if changed {}", getMountPointNodeName());
 
 175         optionalNe = GenericTransactionUtils.readData(getNetconfNodeDataBroker(), LogicalDatastoreType.OPERATIONAL,
 
 176                 NETWORKELEMENT_IID);;
 
 177         synchronized (pmLock) {
 
 178             boolean change = false;
 
 180             if (optionalNe == null) {
 
 181                 LOG.debug("Unable to read NE data for mountpoint {}", getMountPointNodeName());
 
 182                 if (!interfaceList.isEmpty()) {
 
 183                     interfaceList.clear();
 
 184                     interfaceListIterator = null;
 
 189                 LOG.debug("Mountpoint '{}' NE-Name '{}'", getMountPointNodeName(), optionalNe.getName());
 
 190                 List<Lp> actualInterfaceList = getLtpList(optionalNe);
 
 191                 if (!interfaceList.equals(actualInterfaceList)) {
 
 192                     LOG.debug("Mountpoint '{}' Update LTP List. Elements {}", getMountPointNodeName(),
 
 193                             actualInterfaceList.size());
 
 194                     interfaceList.clear();
 
 195                     interfaceList.addAll(actualInterfaceList);
 
 196                     interfaceListIterator = null;
 
 205      * Get List of UUIDs for conditional packages from Networkelement<br>
 
 206      * Possible interfaces are:<br>
 
 207      * MWPS, LTP(MWPS-TTP), MWAirInterfacePac, MicrowaveModel-ObjectClasses-AirInterface<br>
 
 208      * ETH-CTP,LTP(Client), MW_EthernetContainer_Pac<br>
 
 209      * MWS, LTP(MWS-CTP-xD), MWAirInterfaceDiversityPac,
 
 210      * MicrowaveModel-ObjectClasses-AirInterfaceDiversity<br>
 
 211      * MWS, LTP(MWS-TTP), ,MicrowaveModel-ObjectClasses-HybridMwStructure<br>
 
 212      * MWS, LTP(MWS-TTP), ,MicrowaveModel-ObjectClasses-PureEthernetStructure<br>
 
 214      * @param ne NetworkElement
 
 215      * @return Id List, never null.
 
 218     private static List<Lp> getLtpList(@Nullable NetworkElement ne) {
 
 220         List<Lp> res = Collections.synchronizedList(new ArrayList<Lp>());
 
 223             List<Ltp> ltpRefList = ne.getLtp();
 
 224             if (ltpRefList == null) {
 
 225                 LOG.debug("DBRead NE-Interfaces: null");
 
 227                 for (Ltp ltRefListE : ltpRefList) {
 
 228                     List<Lp> lpList = ltRefListE.getLp();
 
 229                     if (lpList == null) {
 
 230                         LOG.debug("DBRead NE-Interfaces Reference List: null");
 
 232                         for (Lp ltp : lpList) {
 
 239             LOG.debug("DBRead NE: null");
 
 243         if (LOG.isDebugEnabled()) {
 
 244             StringBuffer strBuf = new StringBuffer();
 
 246                 if (strBuf.length() > 0) {
 
 249                 strBuf.append(ltp.getLayerProtocolName().getValue());
 
 251                 strBuf.append(ltp.getUuid().getValue());
 
 253             LOG.debug("DBRead NE-Interfaces: {}", strBuf.toString());
 
 261      * Read current problems of AirInterfaces and EthernetContainer according to NE status into DB
 
 263      * @return List with all problems
 
 265     protected List<ProblemNotificationXml> readAllCurrentProblemsOfNode() {
 
 267         // Step 2.3: read the existing faults and add to DB
 
 268         List<ProblemNotificationXml> resultList = new ArrayList<>();
 
 269         int idxStart; // Start index for debug messages
 
 272         synchronized (pmLock) {
 
 273             for (Lp lp : interfaceList) {
 
 275                 idxStart = resultList.size();
 
 277                 ProblemNotificationXml.debugResultList(LOG, uuid.getValue(), resultList, idxStart);
 
 282         // Step 2.4: Read other problems from mountpoint
 
 283         if (isNetworkElementCurrentProblemsSupporting12) {
 
 284             idxStart = resultList.size();
 
 285             readNetworkElementCurrentProblems12(resultList);
 
 286             ProblemNotificationXml.debugResultList(LOG, "CurrentProblems12", resultList, idxStart);
 
 294          * Reading problems for the networkElement V1.2
 
 298     private List<ProblemNotificationXml> readNetworkElementCurrentProblems12(List<ProblemNotificationXml> resultList) {
 
 300         LOG.info("DBRead Get {} NetworkElementCurrentProblems12", getMountPointNodeName());
 
 302         InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.NetworkElementPac> networkElementCurrentProblemsIID =
 
 303                 InstanceIdentifier.builder(
 
 304                         org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.NetworkElementPac.class)
 
 307         // Step 2.3: read to the config data store
 
 308         NetworkElementPac problemPac;
 
 309         NetworkElementCurrentProblems problems;
 
 311             problemPac = GenericTransactionUtils.readData(getNetconfNodeDataBroker(), LogicalDatastoreType.OPERATIONAL,
 
 312                     networkElementCurrentProblemsIID);
 
 313             problems = problemPac.getNetworkElementCurrentProblems();
 
 314             if (problems == null) {
 
 315                 LOG.debug("DBRead no NetworkElementCurrentProblems12");
 
 316             } else if (problems.getCurrentProblemList() == null) {
 
 317                 LOG.debug("DBRead empty CurrentProblemList12");
 
 319                 for (org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.network.element.current.problems.g.CurrentProblemList problem : problems
 
 320                         .getCurrentProblemList()) {
 
 321                     resultList.add(new ProblemNotificationXml(getMountPointNodeName(), problem.getObjectReference(),
 
 322                             problem.getProblemName(), InternalSeverity.valueOf(problem.getProblemSeverity()),
 
 323                             problem.getSequenceNumber().toString(),
 
 324                             InternalDateAndTime.valueOf(problem.getTimeStamp())));
 
 327         } catch (Exception e) {
 
 328             LOG.warn("DBRead {} NetworkElementCurrentProblems12 not supported. Message '{}' ", getMountPointNodeName(),
 
 334     /*---------------------------------------------------------------
 
 339     public boolean checkIfConnectionToMediatorIsOk() {
 
 340         synchronized (dmLock) {
 
 341             return optionalNe != null;
 
 346      * New implementation to interpret status with empty LTP List as notConnected => return false
 
 347      * 30.10.2018 Since this behavior is very specific and implicit for specific NE Types
 
 348      *     it needs to be activated by extension or configuration. Change to be disabled at the moment
 
 351     public boolean checkIfConnectionToNeIsOk() {
 
 355     /*---------------------------------------------------------------
 
 361     /*---------------------------------------------------------------
 
 362      * Equipment related functions
 
 366     public @Nonnull InventoryInformation getInventoryInformation(String layerProtocolFilter) {
 
 367         LOG.debug("request inventory information. filter:" + layerProtocolFilter);
 
 368         return this.equipment.getInventoryInformation(getFilteredInterfaceUuidsAsStringList(layerProtocolFilter));
 
 372         public InventoryInformation getInventoryInformation() {
 
 373                 return getInventoryInformation(null);
 
 376     protected List<String> getFilteredInterfaceUuidsAsStringList(String layerProtocolFilter) {
 
 377         List<String> uuids = new ArrayList<>();
 
 379         LOG.debug("request inventory information. filter:" + layerProtocolFilter);
 
 380         if (optionalNe != null) {
 
 382             for (Lp lp : this.interfaceList) {
 
 383                 if (layerProtocolFilter == null || layerProtocolFilter.isEmpty()) {
 
 384                     uuids.add(lp.getUuid().getValue());
 
 385                 } else if (lp.getLayerProtocolName() != null && lp.getLayerProtocolName().getValue() != null
 
 386                         && lp.getLayerProtocolName().getValue().equals(layerProtocolFilter)) {
 
 387                     uuids.add(lp.getUuid().getValue());
 
 391         LOG.debug("uuids found: {}", uuids);
 
 396     /*---------------------------------------------------------------
 
 397      * Performancemanagement specific interface
 
 401     public void resetPMIterator() {
 
 402         synchronized (pmLock) {
 
 403             interfaceListIterator = interfaceList.iterator();
 
 405         LOG.debug("PM reset iterator");
 
 409     public boolean hasNext() {
 
 411         synchronized (pmLock) {
 
 412             res = interfaceListIterator != null ? interfaceListIterator.hasNext() : false;
 
 414         LOG.debug("PM hasNext LTP {}", res);
 
 420         synchronized (pmLock) {
 
 421             if (interfaceListIterator == null) {
 
 423                 LOG.debug("PM next LTP null");
 
 425                 pmLp = interfaceListIterator.next();
 
 426                 LOG.debug("PM next LTP {}", pmLp.getLayerProtocolName().getValue());
 
 432     public String pmStatusToString() {
 
 433         StringBuffer res = new StringBuffer();
 
 434         synchronized (pmLock) {
 
 435             res.append(pmLp == null ? "no interface" : pmLp.getLayerProtocolName().getValue());
 
 436             for (Lp lp : getInterfaceList()) {
 
 438                 res.append(lp.getLayerProtocolName().getValue());
 
 442         return res.toString();
 
 446         public AllPm getHistoricalPM() {
 
 447         return AllPm.getEmpty();
 
 452         public void doRegisterMicrowaveEventListener(MountPoint mountPoint) {