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.ArrayList;
21 import java.util.Collection;
22 import java.util.Collections;
23 import java.util.Iterator;
24 import java.util.List;
25 import java.util.Optional;
26 import java.util.concurrent.CopyOnWriteArrayList;
27 import org.eclipse.jdt.annotation.NonNull;
28 import org.eclipse.jdt.annotation.Nullable;
29 import org.onap.ccsdk.features.sdnr.wt.common.YangHelper;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElementService;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.NetworkElementCoreData;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.WrapperPTPModelRev170208;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.equipment.ONFCoreNetworkElement12Equipment;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.microwave.Helper;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.microwave.WrapperMicrowaveModelRev181010;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
37 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.InventoryInformationDcae;
38 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.PerformanceDataLtp;
39 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
40 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
41 import org.opendaylight.mdsal.binding.api.MountPoint;
42 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
43 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.NetworkElement;
44 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.UniversalId;
45 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.extension.g.Extension;
46 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.logical.termination.point.g.Lp;
47 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.network.element.Ltp;
48 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.NetworkElementPac;
49 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.network.element.pac.NetworkElementCurrentProblems;
50 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
51 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
52 import org.slf4j.Logger;
53 import org.slf4j.LoggerFactory;
57 * This class contains the ONF Core model Version 1.2 related functions.<br>
58 * Provides the basic ONF Core Model function.<br>
59 * - initialReadFromNetworkElement is not implemented in child classes.
61 public abstract class ONFCoreNetworkElement12Base extends ONFCoreNetworkElementBase implements NetworkElementCoreData {
63 private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12Base.class);
65 protected static final @NonNull List<Extension> EMPTYLTPEXTENSIONLIST = new ArrayList<>();
67 protected static final InstanceIdentifier<NetworkElement> NETWORKELEMENT_IID =
68 InstanceIdentifier.builder(NetworkElement.class).build();
71 /*-----------------------------------------------------------------------------
75 // Non specific part. Used by all functions.
76 /** interfaceList is used by PM task and should be synchronized */
77 @SuppressWarnings("null")
78 private final @NonNull List<Lp> interfaceList = Collections.synchronizedList(new CopyOnWriteArrayList<>());
79 private Optional<NetworkElement> optionalNe;
81 // Performance monitoring specific part
82 /** Lock for the PM access specific elements that could be null */
83 private final @NonNull Object pmLock = new Object();
84 protected @Nullable Iterator<Lp> interfaceListIterator = null;
85 /** Actual pmLp used during iteration over interfaces */
86 protected @Nullable Lp pmLp = null;
88 // Device monitoring specific part
89 /** Lock for the DM access specific elements that could be null */
90 protected final @NonNull Object dmLock = new Object();
92 protected final boolean isNetworkElementCurrentProblemsSupporting12;
94 protected final ONFCoreNetworkElement12Equipment equipment;
96 protected final NodeId nodeId;
98 /*---------------------------------------------------------------
102 protected ONFCoreNetworkElement12Base(@NonNull NetconfBindingAccessor acessor) {
104 this.optionalNe = Optional.empty();
105 this.nodeId = getAcessor().get().getNodeId();
106 this.isNetworkElementCurrentProblemsSupporting12 =
107 acessor.getCapabilites().isSupportingNamespaceAndRevision(NetworkElementPac.QNAME);
108 this.equipment = new ONFCoreNetworkElement12Equipment(acessor, this);
109 WrapperPTPModelRev170208.initSynchronizationExtension(acessor);
110 LOG.debug("support necurrent-problem-list={}", this.isNetworkElementCurrentProblemsSupporting12);
113 /*---------------------------------------------------------------
118 public Optional<NetworkElement> getOptionalNetworkElement() {
122 List<Lp> getInterfaceList() {
123 return interfaceList;
126 public Object getPmLock() {
130 /*---------------------------------------------------------------
131 * Core model related function
135 * Get uuid of Optional NE.
137 * @return Uuid or EMPTY String if optionNE is not available
139 protected String getUuId() {
140 return optionalNe.isPresent() ? Helper.nnGetUniversalId(optionalNe.get().getUuid()).getValue() : EMPTY;
144 * Read from NetworkElement and verify LTPs have changed. If the NE has changed, update to the new structure. From
145 * initial state it changes also.
147 protected boolean readNetworkElementAndInterfaces() {
149 LOG.debug("Update mountpoint if changed {}", getMountpoint());
151 optionalNe = Optional.ofNullable(getGenericTransactionUtils().readData(getDataBroker(),
152 LogicalDatastoreType.OPERATIONAL, NETWORKELEMENT_IID));
153 synchronized (pmLock) {
154 boolean change = false;
156 if (!optionalNe.isPresent()) {
157 LOG.debug("Unable to read NE data for mountpoint {}", getMountpoint());
158 if (!interfaceList.isEmpty()) {
159 interfaceList.clear();
160 interfaceListIterator = null;
165 NetworkElement ne = optionalNe.get();
166 LOG.debug("Mountpoint '{}' NE-Name '{}'", getMountpoint(), ne.getName());
167 List<Lp> actualInterfaceList = getLtpList(ne);
168 if (!interfaceList.equals(actualInterfaceList)) {
169 LOG.debug("Mountpoint '{}' Update LTP List. Elements {}", getMountpoint(),
170 actualInterfaceList.size());
171 interfaceList.clear();
172 interfaceList.addAll(actualInterfaceList);
173 interfaceListIterator = null;
182 * Get List of UUIDs for conditional packages from Networkelement<br>
183 * Possible interfaces are:<br>
184 * MWPS, LTP(MWPS-TTP), MWAirInterfacePac, MicrowaveModel-ObjectClasses-AirInterface<br>
185 * ETH-CTP,LTP(Client), MW_EthernetContainer_Pac<br>
186 * MWS, LTP(MWS-CTP-xD), MWAirInterfaceDiversityPac, MicrowaveModel-ObjectClasses-AirInterfaceDiversity<br>
187 * MWS, LTP(MWS-TTP), ,MicrowaveModel-ObjectClasses-HybridMwStructure<br>
188 * MWS, LTP(MWS-TTP), ,MicrowaveModel-ObjectClasses-PureEthernetStructure<br>
190 * @param ne NetworkElement
191 * @return Id List, never null.
194 private static List<Lp> getLtpList(@Nullable NetworkElement ne) {
196 List<Lp> res = Collections.synchronizedList(new ArrayList<Lp>());
199 Collection<Ltp> ltpRefList = YangHelper.getCollection(ne.getLtp());
200 if (ltpRefList == null) {
201 LOG.debug("DBRead NE-Interfaces: null");
203 for (Ltp ltRefListE : ltpRefList) {
204 Collection<Lp> lpList = YangHelper.getCollection(ltRefListE.getLp());
205 if (lpList == null) {
206 LOG.debug("DBRead NE-Interfaces Reference List: null");
208 for (Lp ltp : lpList) {
215 LOG.debug("DBRead NE: null");
219 if (LOG.isDebugEnabled()) {
220 StringBuilder strBuild = new StringBuilder();
222 if (strBuild.length() > 0) {
223 strBuild.append(", ");
225 strBuild.append(Helper.nnGetLayerProtocolName(ltp.getLayerProtocolName()).getValue());
226 strBuild.append(':');
227 strBuild.append(Helper.nnGetUniversalId(ltp.getUuid()).getValue());
229 LOG.debug("DBRead NE-Interfaces: {}", strBuild.toString());
237 * Read current problems of AirInterfaces and EthernetContainer according to NE status into DB
239 * @return List with all problems
241 protected FaultData readAllCurrentProblemsOfNode() {
243 // Step 2.3: read the existing faults and add to DB
244 FaultData resultList = new FaultData();
245 int idxStart; // Start index for debug messages
248 synchronized (pmLock) {
249 for (Lp lp : interfaceList) {
251 idxStart = resultList.size();
253 FaultData.debugResultList(LOG, uuid.getValue(), resultList, idxStart);
258 // Step 2.4: Read other problems from mountpoint
259 if (isNetworkElementCurrentProblemsSupporting12) {
260 idxStart = resultList.size();
261 readNetworkElementCurrentProblems12(resultList);
262 FaultData.debugResultList(LOG, "CurrentProblems12", resultList, idxStart);
270 * Reading problems for the networkElement V1.2
272 * @param resultList to collect the problems
273 * @return resultList with additonal problems
275 protected FaultData readNetworkElementCurrentProblems12(FaultData resultList) {
277 LOG.info("DBRead Get {} NetworkElementCurrentProblems12", getMountpoint());
279 InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.NetworkElementPac> networkElementCurrentProblemsIID =
280 InstanceIdentifier.builder(
281 org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.NetworkElementPac.class)
284 // Step 2.3: read to the config data store
285 NetworkElementPac problemPac;
286 NetworkElementCurrentProblems problems = null;
288 problemPac = getGenericTransactionUtils().readData(getDataBroker(), LogicalDatastoreType.OPERATIONAL,
289 networkElementCurrentProblemsIID);
290 if (problemPac != null) {
291 problems = problemPac.getNetworkElementCurrentProblems();
293 if (problems == null) {
294 LOG.debug("DBRead no NetworkElementCurrentProblems12");
296 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 : YangHelper
297 .getCollection(problems.nonnullCurrentProblemList())) {
298 resultList.add(nodeId, problem.getSequenceNumber(), problem.getTimeStamp(),
299 problem.getObjectReference(), problem.getProblemName(),
300 WrapperMicrowaveModelRev181010.mapSeverity(problem.getProblemSeverity()));
303 } catch (Exception e) {
304 LOG.warn("DBRead {} NetworkElementCurrentProblems12 not supported. Message '{}' ", getMountpoint(),
310 /*---------------------------------------------------------------
315 public boolean checkIfConnectionToMediatorIsOk() {
316 synchronized (dmLock) {
317 return optionalNe != null;
322 * New implementation to interpret status with empty LTP List as notConnected => return false
323 * 30.10.2018 Since this behavior is very specific and implicit for specific NE Types
324 * it needs to be activated by extension or configuration. Change to be disabled at the moment
327 public boolean checkIfConnectionToNeIsOk() {
331 /*---------------------------------------------------------------
336 /*---------------------------------------------------------------
337 * Equipment related functions
341 public @NonNull InventoryInformationDcae getInventoryInformation(String layerProtocolFilter) {
342 LOG.debug("request inventory information. filter: {}" + layerProtocolFilter);
343 return this.equipment.getInventoryInformation(getFilteredInterfaceUuidsAsStringList(layerProtocolFilter));
347 public InventoryInformationDcae getInventoryInformation() {
348 return getInventoryInformation(null);
351 protected List<String> getFilteredInterfaceUuidsAsStringList(String layerProtocolFilter) {
352 List<String> uuids = new ArrayList<>();
354 LOG.debug("request inventory information. filter: {}" + layerProtocolFilter);
355 if (optionalNe != null) {
357 for (Lp lp : this.interfaceList) {
358 if (layerProtocolFilter == null || layerProtocolFilter.isEmpty() || layerProtocolFilter
359 .equals(Helper.nnGetLayerProtocolName(lp.getLayerProtocolName()).getValue())) {
360 uuids.add(Helper.nnGetUniversalId(lp.getUuid()).getValue());
364 LOG.debug("uuids found: {}", uuids);
369 /*---------------------------------------------------------------
370 * Performancemanagement specific interface
374 public void resetPMIterator() {
375 synchronized (pmLock) {
376 interfaceListIterator = interfaceList.iterator();
378 LOG.debug("PM reset iterator");
381 @SuppressWarnings("null")
383 public boolean hasNext() {
385 synchronized (pmLock) {
386 res = interfaceListIterator != null ? interfaceListIterator.hasNext() : false;
388 LOG.debug("PM hasNext LTP {}", res);
392 @SuppressWarnings("null")
395 synchronized (pmLock) {
396 if (interfaceListIterator == null) {
398 LOG.debug("PM next LTP null");
400 pmLp = interfaceListIterator.next();
401 LOG.debug("PM next LTP {}", Helper.nnGetLayerProtocolName(pmLp.getLayerProtocolName()).getValue());
406 @SuppressWarnings("null")
408 public String pmStatusToString() {
409 StringBuilder res = new StringBuilder();
410 synchronized (pmLock) {
411 res.append(pmLp == null ? "no interface"
412 : Helper.nnGetLayerProtocolName(pmLp.getLayerProtocolName()).getValue());
413 for (Lp lp : getInterfaceList()) {
415 res.append(Helper.nnGetLayerProtocolName(lp.getLayerProtocolName()).getValue());
419 return res.toString();
423 public void doRegisterEventListener(MountPoint mountPoint) {
427 @SuppressWarnings("unchecked")
429 public <L extends NetworkElementService> Optional<L> getService(Class<L> clazz) {
430 return clazz.isInstance(this) ? Optional.of((L) this) : Optional.empty();
434 public Optional<PerformanceDataLtp> getLtpHistoricalPerformanceData() {
435 return Optional.empty();