2  * ============LICENSE_START========================================================================
 
   3  * ONAP : ccsdk feature sdnr wt
 
   4  * =================================================================================================
 
   5  * Copyright (C) 2020 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.onf14.dom.impl;
 
  20 import java.util.Iterator;
 
  22 import java.util.Optional;
 
  23 import org.eclipse.jdt.annotation.NonNull;
 
  24 import org.eclipse.jdt.annotation.Nullable;
 
  25 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
 
  26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
 
  27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElementService;
 
  28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.PerformanceDataProvider;
 
  29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.dataprovider.Onf14DomToInternalDataModel;
 
  30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.equipment.Onf14DomEquipmentManager;
 
  31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.interfaces.Onf14DomInterfacePacManager;
 
  32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.interfaces.TechnologySpecificPacKeys;
 
  33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.util.Onf14DevicemanagerQNames;
 
  34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
 
  35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
 
  36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationService;
 
  37 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.PerformanceManager;
 
  38 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.PerformanceDataLtp;
 
  39 import org.onap.ccsdk.features.sdnr.wt.devicemanager.util.InconsistentPMDataException;
 
  40 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
 
  41 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
 
  42 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 
  43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.Stream;
 
  44 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.StreamKey;
 
  45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementConnectionBuilder;
 
  46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType;
 
  47 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
 
  48 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 
  49 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
  50 import org.slf4j.Logger;
 
  51 import org.slf4j.LoggerFactory;
 
  54  * Representation of ONF Core model 1.4 device Top level element is "ControlConstruct" (replaces "NetworkElement" of
 
  55  * older ONF Version) NOTE:
 
  57 public class Onf14DomNetworkElement implements NetworkElement, PerformanceDataProvider {
 
  59     private static final Logger log = LoggerFactory.getLogger(Onf14DomNetworkElement.class);
 
  61     protected static final YangInstanceIdentifier TOPLEVELEQUIPMENT_IID =
 
  62             YangInstanceIdentifier.builder().node(Onf14DevicemanagerQNames.CORE_MODEL_CONTROL_CONSTRUCT_CONTAINER)
 
  63                     .node(Onf14DevicemanagerQNames.CORE_MODEL_CC_TOP_LEVEL_EQPT).build();
 
  65     private final @NonNull Object pmLock = new Object();
 
  66     protected @Nullable TechnologySpecificPacKeys pmLp = null;
 
  67     protected @Nullable Iterator<TechnologySpecificPacKeys> interfaceListIterator = null;
 
  68     private final NetconfDomAccessor netconfDomAccessor;
 
  69     private final DataProvider databaseService;
 
  70     private final @NonNull FaultService faultService;
 
  71     private final @NonNull PerformanceManager performanceManager;
 
  72     private final @NonNull NotificationService notificationService;
 
  74     private final Onf14DomToInternalDataModel onf14Mapper;
 
  76     private final @NonNull Onf14DomEquipmentManager equipmentManager;
 
  77     private final @NonNull Onf14DomInterfacePacManager interfacePacManager;
 
  78     private final @NonNull String namespaceRevision;
 
  80     public Onf14DomNetworkElement(NetconfDomAccessor netconfDomAccessor, DeviceManagerServiceProvider serviceProvider,
 
  81             String namespaceRevision) {
 
  82         log.info("Create {}", Onf14DomNetworkElement.class.getSimpleName());
 
  83         this.netconfDomAccessor = netconfDomAccessor;
 
  84         this.databaseService = serviceProvider.getDataProvider();
 
  85         this.notificationService = serviceProvider.getNotificationService();
 
  86         this.faultService = serviceProvider.getFaultService();
 
  87         this.performanceManager = serviceProvider.getPerformanceManagerService();
 
  88         this.namespaceRevision = namespaceRevision;
 
  89         this.onf14Mapper = new Onf14DomToInternalDataModel();
 
  90         this.equipmentManager = new Onf14DomEquipmentManager(netconfDomAccessor, databaseService, onf14Mapper);
 
  91         this.interfacePacManager = new Onf14DomInterfacePacManager(netconfDomAccessor, serviceProvider);
 
  96      * reading the inventory (CoreModel 1.4 Equipment Model) and adding it to the DB
 
  98     public void initialReadFromNetworkElement() {
 
  99         log.debug("Calling read equipment");
 
 100         // Read complete device tree
 
 103         int problems = faultService.removeAllCurrentProblemsOfNode(netconfDomAccessor.getNodeId());
 
 104         log.debug("Removed all {} problems from database at registration", problems);
 
 106         // Read fault data and subscribe for notifications
 
 107         interfacePacManager.register();
 
 112      * @param nNode set core-model-capability
 
 114     public void setCoreModel() {
 
 115         NetworkElementConnectionBuilder eb = new NetworkElementConnectionBuilder();
 
 116         eb.setCoreModelCapability(namespaceRevision);
 
 117         databaseService.updateNetworkConnection22(eb.build(), netconfDomAccessor.getNodeId().getValue());
 
 121     public void register() {
 
 122         // Set core-model revision value in "core-model-capability" field
 
 124         initialReadFromNetworkElement();
 
 126         if (netconfDomAccessor.isNotificationsRFC5277Supported()) {
 
 127             // Output notification streams to LOG
 
 128             Map<StreamKey, Stream> streams = netconfDomAccessor.getNotificationStreamsAsMap();
 
 129             log.debug("Available notifications streams: {}", streams);
 
 130             // Register to default stream
 
 131             netconfDomAccessor.invokeCreateSubscription();
 
 133         // -- Register NE to performance manager
 
 134         performanceManager.registration(netconfDomAccessor.getNodeId(), this);
 
 138     public void deregister() {
 
 139         performanceManager.deRegistration(netconfDomAccessor.getNodeId());
 
 143     public NodeId getNodeId() {
 
 144         return netconfDomAccessor.getNodeId();
 
 147     @SuppressWarnings("unchecked")
 
 149     public <L extends NetworkElementService> Optional<L> getService(Class<L> clazz) {
 
 150         return clazz.isInstance(this) ? Optional.of((L) this) : Optional.empty();
 
 154     public void warmstart() {}
 
 157     public Optional<NetconfAccessor> getAcessor() {
 
 158         return Optional.of(netconfDomAccessor);
 
 162     public NetworkElementDeviceType getDeviceType() {
 
 163         return NetworkElementDeviceType.Wireless;
 
 166     private void readEquipmentData() {
 
 167         Optional<NormalizedNode> topLevelEquipment = readTopLevelEquipment(netconfDomAccessor);
 
 168         log.debug("Top level equipment data is {}", topLevelEquipment.isPresent() ? topLevelEquipment.get() : null);
 
 169         if (topLevelEquipment.isPresent()) {
 
 170             equipmentManager.setEquipmentData(topLevelEquipment.get());
 
 175     private Optional<NormalizedNode> readTopLevelEquipment(NetconfDomAccessor netconfDomAccessor) {
 
 176         return netconfDomAccessor.readDataNode(LogicalDatastoreType.CONFIGURATION, TOPLEVELEQUIPMENT_IID);
 
 179     public Object getPmLock() {
 
 184     public void resetPMIterator() {
 
 185         synchronized (pmLock) {
 
 186             interfaceListIterator = interfacePacManager.getAirInterfaceList().iterator();
 
 188         log.debug("PM reset iterator");
 
 192     public boolean hasNext() {
 
 194         synchronized (pmLock) {
 
 195             res = interfaceListIterator != null ? interfaceListIterator.hasNext() : false;
 
 197         log.debug("PM hasNext LTP {}", res);
 
 203         synchronized (pmLock) {
 
 204             if (interfaceListIterator == null) {
 
 206                 log.debug("PM next LTP null");
 
 208                 pmLp = interfaceListIterator.next();
 
 215     public Optional<PerformanceDataLtp> getLtpHistoricalPerformanceData() throws InconsistentPMDataException {
 
 216         synchronized (getPmLock()) {
 
 218                 log.debug("Enter query PM");
 
 220                 TechnologySpecificPacKeys lp = pmLp;
 
 221                 return Optional.of(interfacePacManager.getLtpHistoricalPerformanceData(lp));
 
 223             return Optional.empty();
 
 228     public String pmStatusToString() {
 
 229         StringBuilder res = new StringBuilder();
 
 230         synchronized (pmLock) {
 
 232                 res.append("no interface");
 
 234                 res.append("ActualLP=");
 
 235                 res.append(pmLp.getLocalId());
 
 237             res.append(" IFList=");
 
 239             for (TechnologySpecificPacKeys lp : interfacePacManager.getAirInterfaceList()) {
 
 243                 res.append(lp.getLocalId());
 
 247         return res.toString();