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.yangspecs.CoreModel14;
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.schema.NormalizedNode;
49 import org.slf4j.Logger;
50 import org.slf4j.LoggerFactory;
53 * Representation of ONF Core model 1.4 device Top level element is "ControlConstruct" (replaces "NetworkElement" of
54 * older ONF Version) NOTE:
56 public class Onf14DomNetworkElement implements NetworkElement, PerformanceDataProvider {
58 private static final Logger log = LoggerFactory.getLogger(Onf14DomNetworkElement.class);
60 private final @NonNull Object pmLock = new Object();
61 protected @Nullable TechnologySpecificPacKeys pmLp = null;
62 protected @Nullable Iterator<TechnologySpecificPacKeys> interfaceListIterator = null;
63 private final NetconfDomAccessor netconfDomAccessor;
64 private final DataProvider databaseService;
65 private final @NonNull FaultService faultService;
66 private final @NonNull PerformanceManager performanceManager;
67 private final @NonNull NotificationService notificationService;
69 private final Onf14DomToInternalDataModel onf14Mapper;
71 private final @NonNull Onf14DomEquipmentManager equipmentManager;
72 private final @NonNull Onf14DomInterfacePacManager interfacePacManager;
73 private final @NonNull CoreModel14 onf14CoreModelQNames;
75 public Onf14DomNetworkElement(NetconfDomAccessor netconfDomAccessor, DeviceManagerServiceProvider serviceProvider,
76 CoreModel14 onf14CoreModelQNames) {
77 log.info("Create {}", Onf14DomNetworkElement.class.getSimpleName());
78 this.netconfDomAccessor = netconfDomAccessor;
79 this.onf14CoreModelQNames = onf14CoreModelQNames;
80 this.databaseService = serviceProvider.getDataProvider();
81 this.notificationService = serviceProvider.getNotificationService();
82 this.faultService = serviceProvider.getFaultService();
83 this.performanceManager = serviceProvider.getPerformanceManagerService();
84 this.onf14Mapper = new Onf14DomToInternalDataModel();
85 this.equipmentManager = new Onf14DomEquipmentManager(netconfDomAccessor, databaseService, onf14Mapper, onf14CoreModelQNames);
86 this.interfacePacManager = new Onf14DomInterfacePacManager(netconfDomAccessor, serviceProvider, onf14CoreModelQNames);
90 * reading the inventory (CoreModel 1.4 Equipment Model) and adding it to the DB
92 public void initialReadFromNetworkElement() {
93 log.debug("Calling read equipment");
94 // Read complete device tree
97 int problems = faultService.removeAllCurrentProblemsOfNode(netconfDomAccessor.getNodeId());
98 log.debug("Removed all {} problems from database at registration", problems);
100 // Read fault data and subscribe for notifications
101 interfacePacManager.register();
106 * @param nNode set core-model-capability
108 public void setCoreModel() {
109 NetworkElementConnectionBuilder eb = new NetworkElementConnectionBuilder();
110 eb.setCoreModelCapability(onf14CoreModelQNames.getRevision());
111 databaseService.updateNetworkConnection22(eb.build(), netconfDomAccessor.getNodeId().getValue());
115 public void register() {
116 // Set core-model revision value in "core-model-capability" field
118 initialReadFromNetworkElement();
120 if (netconfDomAccessor.isNotificationsRFC5277Supported()) {
121 // Output notification streams to LOG
122 Map<StreamKey, Stream> streams = netconfDomAccessor.getNotificationStreamsAsMap();
123 log.debug("Available notifications streams: {}", streams);
124 // Register to default stream
125 netconfDomAccessor.invokeCreateSubscription();
127 // -- Register NE to performance manager
128 performanceManager.registration(netconfDomAccessor.getNodeId(), this);
132 public void deregister() {
133 faultService.removeAllCurrentProblemsOfNode(netconfDomAccessor.getNodeId());
134 performanceManager.deRegistration(netconfDomAccessor.getNodeId());
138 public NodeId getNodeId() {
139 return netconfDomAccessor.getNodeId();
142 @SuppressWarnings("unchecked")
144 public <L extends NetworkElementService> Optional<L> getService(Class<L> clazz) {
145 return clazz.isInstance(this) ? Optional.of((L) this) : Optional.empty();
149 public void warmstart() {
150 int problems = removeAllCurrentProblemsOfNode();
151 log.debug("Removed all {} problems from database at deregistration for {}", problems, netconfDomAccessor.getNodeId().getValue());
155 * Remove all entries from list
157 public int removeAllCurrentProblemsOfNode() {
158 return faultService.removeAllCurrentProblemsOfNode(netconfDomAccessor.getNodeId());
162 public Optional<NetconfAccessor> getAcessor() {
163 return Optional.of(netconfDomAccessor);
167 public NetworkElementDeviceType getDeviceType() {
168 return NetworkElementDeviceType.Wireless;
171 private void readEquipmentData() {
172 Optional<NormalizedNode> topLevelEquipment = readTopLevelEquipment(netconfDomAccessor);
173 log.debug("Top level equipment data is {}", topLevelEquipment.isPresent() ? topLevelEquipment.get() : null);
174 if (topLevelEquipment.isPresent()) {
175 equipmentManager.setEquipmentData(topLevelEquipment.get());
180 private Optional<NormalizedNode> readTopLevelEquipment(NetconfDomAccessor netconfDomAccessor) {
181 log.debug("Reading Top level equipment data");
182 return netconfDomAccessor.readDataNode(LogicalDatastoreType.CONFIGURATION, onf14CoreModelQNames.getTopLevelEquipment_IId());
185 public Object getPmLock() {
190 public void resetPMIterator() {
191 synchronized (pmLock) {
192 interfaceListIterator = interfacePacManager.getAirInterfaceList().iterator();
194 log.debug("PM reset iterator");
198 public boolean hasNext() {
200 synchronized (pmLock) {
201 res = interfaceListIterator != null ? interfaceListIterator.hasNext() : false;
203 log.debug("PM hasNext LTP {}", res);
209 synchronized (pmLock) {
210 if (interfaceListIterator == null) {
212 log.debug("PM next LTP null");
214 pmLp = interfaceListIterator.next();
221 public Optional<PerformanceDataLtp> getLtpHistoricalPerformanceData() throws InconsistentPMDataException {
222 synchronized (getPmLock()) {
224 log.debug("Enter query PM");
226 TechnologySpecificPacKeys lp = pmLp;
227 return Optional.of(interfacePacManager.getLtpHistoricalPerformanceData(lp));
229 return Optional.empty();
234 public String pmStatusToString() {
235 StringBuilder res = new StringBuilder();
236 synchronized (pmLock) {
238 res.append("no interface");
240 res.append("ActualLP=");
241 res.append(pmLp.getLocalId());
243 res.append(" IFList=");
245 for (TechnologySpecificPacKeys lp : interfacePacManager.getAirInterfaceList()) {
249 res.append(lp.getLocalId());
253 return res.toString();