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.qnames.Onf14DevicemanagerQNames;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.yangspecs.CoreModel14;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
37 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationService;
38 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.PerformanceManager;
39 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.PerformanceDataLtp;
40 import org.onap.ccsdk.features.sdnr.wt.devicemanager.util.InconsistentPMDataException;
41 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
42 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
43 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
44 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.Stream;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.StreamKey;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementConnectionBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType;
48 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
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 private final @NonNull Object pmLock = new Object();
62 protected @Nullable TechnologySpecificPacKeys pmLp = null;
63 protected @Nullable Iterator<TechnologySpecificPacKeys> interfaceListIterator = null;
64 private final NetconfDomAccessor netconfDomAccessor;
65 private final DataProvider databaseService;
66 private final @NonNull FaultService faultService;
67 private final @NonNull PerformanceManager performanceManager;
68 private final @NonNull NotificationService notificationService;
70 private final Onf14DomToInternalDataModel onf14Mapper;
72 private final @NonNull Onf14DomEquipmentManager equipmentManager;
73 private final @NonNull Onf14DomInterfacePacManager interfacePacManager;
74 private final @NonNull CoreModel14 onf14CoreModelQNames;
76 public Onf14DomNetworkElement(NetconfDomAccessor netconfDomAccessor, DeviceManagerServiceProvider serviceProvider,
77 CoreModel14 onf14CoreModelQNames) {
78 log.info("Create {}", Onf14DomNetworkElement.class.getSimpleName());
79 this.netconfDomAccessor = netconfDomAccessor;
80 this.onf14CoreModelQNames = onf14CoreModelQNames;
81 this.databaseService = serviceProvider.getDataProvider();
82 this.notificationService = serviceProvider.getNotificationService();
83 this.faultService = serviceProvider.getFaultService();
84 this.performanceManager = serviceProvider.getPerformanceManagerService();
85 this.onf14Mapper = new Onf14DomToInternalDataModel();
86 this.equipmentManager = new Onf14DomEquipmentManager(netconfDomAccessor, databaseService, onf14Mapper, onf14CoreModelQNames);
87 this.interfacePacManager = new Onf14DomInterfacePacManager(netconfDomAccessor, serviceProvider, onf14CoreModelQNames);
91 * reading the inventory (CoreModel 1.4 Equipment Model) and adding it to the DB
93 public void initialReadFromNetworkElement() {
94 log.debug("Calling read equipment");
95 // Read complete device tree
98 int problems = faultService.removeAllCurrentProblemsOfNode(netconfDomAccessor.getNodeId());
99 log.debug("Removed all {} problems from database at registration", problems);
101 // Read fault data and subscribe for notifications
102 interfacePacManager.register();
107 * @param nNode set core-model-capability
109 public void setCoreModel() {
110 NetworkElementConnectionBuilder eb = new NetworkElementConnectionBuilder();
111 eb.setCoreModelCapability(onf14CoreModelQNames.getRevision());
112 databaseService.updateNetworkConnection22(eb.build(), netconfDomAccessor.getNodeId().getValue());
116 public void register() {
117 // Set core-model revision value in "core-model-capability" field
119 initialReadFromNetworkElement();
121 if (netconfDomAccessor.isNotificationsRFC5277Supported()) {
122 // Output notification streams to LOG
123 Map<StreamKey, Stream> streams = netconfDomAccessor.getNotificationStreamsAsMap();
124 log.debug("Available notifications streams: {}", streams);
125 // Register to default stream
126 netconfDomAccessor.invokeCreateSubscription();
128 // -- Register NE to performance manager
129 performanceManager.registration(netconfDomAccessor.getNodeId(), this);
133 public void deregister() {
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() {}
152 public Optional<NetconfAccessor> getAcessor() {
153 return Optional.of(netconfDomAccessor);
157 public NetworkElementDeviceType getDeviceType() {
158 return NetworkElementDeviceType.Wireless;
161 private void readEquipmentData() {
162 Optional<NormalizedNode> topLevelEquipment = readTopLevelEquipment(netconfDomAccessor);
163 log.debug("Top level equipment data is {}", topLevelEquipment.isPresent() ? topLevelEquipment.get() : null);
164 if (topLevelEquipment.isPresent()) {
165 equipmentManager.setEquipmentData(topLevelEquipment.get());
170 private Optional<NormalizedNode> readTopLevelEquipment(NetconfDomAccessor netconfDomAccessor) {
171 log.debug("Reading Top level equipment data");
172 return netconfDomAccessor.readDataNode(LogicalDatastoreType.CONFIGURATION, onf14CoreModelQNames.getTopLevelEquipment_IId());
175 public Object getPmLock() {
180 public void resetPMIterator() {
181 synchronized (pmLock) {
182 interfaceListIterator = interfacePacManager.getAirInterfaceList().iterator();
184 log.debug("PM reset iterator");
188 public boolean hasNext() {
190 synchronized (pmLock) {
191 res = interfaceListIterator != null ? interfaceListIterator.hasNext() : false;
193 log.debug("PM hasNext LTP {}", res);
199 synchronized (pmLock) {
200 if (interfaceListIterator == null) {
202 log.debug("PM next LTP null");
204 pmLp = interfaceListIterator.next();
211 public Optional<PerformanceDataLtp> getLtpHistoricalPerformanceData() throws InconsistentPMDataException {
212 synchronized (getPmLock()) {
214 log.debug("Enter query PM");
216 TechnologySpecificPacKeys lp = pmLp;
217 return Optional.of(interfacePacManager.getLtpHistoricalPerformanceData(lp));
219 return Optional.empty();
224 public String pmStatusToString() {
225 StringBuilder res = new StringBuilder();
226 synchronized (pmLock) {
228 res.append("no interface");
230 res.append("ActualLP=");
231 res.append(pmLp.getLocalId());
233 res.append(" IFList=");
235 for (TechnologySpecificPacKeys lp : interfacePacManager.getAirInterfaceList()) {
239 res.append(lp.getLocalId());
243 return res.toString();