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.opendaylight.mdsal.binding.api.MountPoint;
41 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
42 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.NetworkElement;
43 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.UniversalId;
44 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.extension.g.Extension;
45 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.logical.termination.point.g.Lp;
46 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.network.element.Ltp;
47 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.NetworkElementPac;
48 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.network.element.pac.NetworkElementCurrentProblems;
49 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
50 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
56 * This class contains the ONF Core model Version 1.2 related functions.<br>
57 * Provides the basic ONF Core Model function.<br>
58 * - initialReadFromNetworkElement is not implemented in child classes.
60 public abstract class ONFCoreNetworkElement12Base extends ONFCoreNetworkElementBase implements NetworkElementCoreData {
62 private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12Base.class);
64 protected static final @NonNull List<Extension> EMPTYLTPEXTENSIONLIST = new ArrayList<>();
66 protected static final InstanceIdentifier<NetworkElement> NETWORKELEMENT_IID =
67 InstanceIdentifier.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 @SuppressWarnings("null")
77 private final @NonNull List<Lp> interfaceList = Collections.synchronizedList(new CopyOnWriteArrayList<>());
78 private Optional<NetworkElement> optionalNe;
80 // Performance monitoring specific part
81 /** Lock for the PM access specific elements that could be null */
82 private final @NonNull Object pmLock = new Object();
83 protected @Nullable Iterator<Lp> interfaceListIterator = null;
84 /** Actual pmLp used during iteration over interfaces */
85 protected @Nullable Lp pmLp = null;
87 // Device monitoring specific part
88 /** Lock for the DM access specific elements that could be null */
89 protected final @NonNull Object dmLock = new Object();
91 protected final boolean isNetworkElementCurrentProblemsSupporting12;
93 protected final ONFCoreNetworkElement12Equipment equipment;
95 protected final NodeId nodeId;
97 /*---------------------------------------------------------------
101 protected ONFCoreNetworkElement12Base(@NonNull NetconfAccessor acessor) {
103 this.optionalNe = Optional.empty();
104 this.nodeId = getAcessor().get().getNodeId();
105 this.isNetworkElementCurrentProblemsSupporting12 =
106 acessor.getCapabilites().isSupportingNamespaceAndRevision(NetworkElementPac.QNAME);
107 this.equipment = new ONFCoreNetworkElement12Equipment(acessor, this);
108 WrapperPTPModelRev170208.initSynchronizationExtension(acessor);
109 LOG.debug("support necurrent-problem-list={}", this.isNetworkElementCurrentProblemsSupporting12);
112 /*---------------------------------------------------------------
117 public Optional<NetworkElement> getOptionalNetworkElement() {
121 List<Lp> getInterfaceList() {
122 return interfaceList;
125 public Object getPmLock() {
129 /*---------------------------------------------------------------
130 * Core model related function
134 * Get uuid of Optional NE.
136 * @return Uuid or EMPTY String if optionNE is not available
138 protected String getUuId() {
139 return optionalNe.isPresent() ? Helper.nnGetUniversalId(optionalNe.get().getUuid()).getValue() : EMPTY;
143 * Read from NetworkElement and verify LTPs have changed. If the NE has changed, update to the new structure. From
144 * initial state it changes also.
146 protected boolean readNetworkElementAndInterfaces() {
148 LOG.debug("Update mountpoint if changed {}", getMountpoint());
150 optionalNe = Optional.ofNullable(getGenericTransactionUtils().readData(getDataBroker(),
151 LogicalDatastoreType.OPERATIONAL, NETWORKELEMENT_IID));
152 synchronized (pmLock) {
153 boolean change = false;
155 if (!optionalNe.isPresent()) {
156 LOG.debug("Unable to read NE data for mountpoint {}", getMountpoint());
157 if (!interfaceList.isEmpty()) {
158 interfaceList.clear();
159 interfaceListIterator = null;
164 NetworkElement ne = optionalNe.get();
165 LOG.debug("Mountpoint '{}' NE-Name '{}'", getMountpoint(), ne.getName());
166 List<Lp> actualInterfaceList = getLtpList(ne);
167 if (!interfaceList.equals(actualInterfaceList)) {
168 LOG.debug("Mountpoint '{}' Update LTP List. Elements {}", getMountpoint(),
169 actualInterfaceList.size());
170 interfaceList.clear();
171 interfaceList.addAll(actualInterfaceList);
172 interfaceListIterator = null;
181 * Get List of UUIDs for conditional packages from Networkelement<br>
182 * Possible interfaces are:<br>
183 * MWPS, LTP(MWPS-TTP), MWAirInterfacePac, MicrowaveModel-ObjectClasses-AirInterface<br>
184 * ETH-CTP,LTP(Client), MW_EthernetContainer_Pac<br>
185 * MWS, LTP(MWS-CTP-xD), MWAirInterfaceDiversityPac, MicrowaveModel-ObjectClasses-AirInterfaceDiversity<br>
186 * MWS, LTP(MWS-TTP), ,MicrowaveModel-ObjectClasses-HybridMwStructure<br>
187 * MWS, LTP(MWS-TTP), ,MicrowaveModel-ObjectClasses-PureEthernetStructure<br>
189 * @param ne NetworkElement
190 * @return Id List, never null.
193 private static List<Lp> getLtpList(@Nullable NetworkElement ne) {
195 List<Lp> res = Collections.synchronizedList(new ArrayList<Lp>());
198 Collection<Ltp> ltpRefList = YangHelper.getCollection(ne.getLtp());
199 if (ltpRefList == null) {
200 LOG.debug("DBRead NE-Interfaces: null");
202 for (Ltp ltRefListE : ltpRefList) {
203 Collection<Lp> lpList = YangHelper.getCollection(ltRefListE.getLp());
204 if (lpList == null) {
205 LOG.debug("DBRead NE-Interfaces Reference List: null");
207 for (Lp ltp : lpList) {
214 LOG.debug("DBRead NE: null");
218 if (LOG.isDebugEnabled()) {
219 StringBuilder strBuild = new StringBuilder();
221 if (strBuild.length() > 0) {
222 strBuild.append(", ");
224 strBuild.append(Helper.nnGetLayerProtocolName(ltp.getLayerProtocolName()).getValue());
225 strBuild.append(':');
226 strBuild.append(Helper.nnGetUniversalId(ltp.getUuid()).getValue());
228 LOG.debug("DBRead NE-Interfaces: {}", strBuild.toString());
236 * Read current problems of AirInterfaces and EthernetContainer according to NE status into DB
238 * @return List with all problems
240 protected FaultData readAllCurrentProblemsOfNode() {
242 // Step 2.3: read the existing faults and add to DB
243 FaultData resultList = new FaultData();
244 int idxStart; // Start index for debug messages
247 synchronized (pmLock) {
248 for (Lp lp : interfaceList) {
250 idxStart = resultList.size();
252 FaultData.debugResultList(LOG, uuid.getValue(), resultList, idxStart);
257 // Step 2.4: Read other problems from mountpoint
258 if (isNetworkElementCurrentProblemsSupporting12) {
259 idxStart = resultList.size();
260 readNetworkElementCurrentProblems12(resultList);
261 FaultData.debugResultList(LOG, "CurrentProblems12", resultList, idxStart);
269 * Reading problems for the networkElement V1.2
271 * @param resultList to collect the problems
272 * @return resultList with additonal problems
274 protected FaultData readNetworkElementCurrentProblems12(FaultData resultList) {
276 LOG.info("DBRead Get {} NetworkElementCurrentProblems12", getMountpoint());
278 InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.NetworkElementPac> networkElementCurrentProblemsIID =
279 InstanceIdentifier.builder(
280 org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.NetworkElementPac.class)
283 // Step 2.3: read to the config data store
284 NetworkElementPac problemPac;
285 NetworkElementCurrentProblems problems = null;
287 problemPac = getGenericTransactionUtils().readData(getDataBroker(), LogicalDatastoreType.OPERATIONAL,
288 networkElementCurrentProblemsIID);
289 if (problemPac != null) {
290 problems = problemPac.getNetworkElementCurrentProblems();
292 if (problems == null) {
293 LOG.debug("DBRead no NetworkElementCurrentProblems12");
295 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
296 .getCollection(problems.nonnullCurrentProblemList())) {
297 resultList.add(nodeId, problem.getSequenceNumber(), problem.getTimeStamp(),
298 problem.getObjectReference(), problem.getProblemName(),
299 WrapperMicrowaveModelRev181010.mapSeverity(problem.getProblemSeverity()));
302 } catch (Exception e) {
303 LOG.warn("DBRead {} NetworkElementCurrentProblems12 not supported. Message '{}' ", getMountpoint(),
309 /*---------------------------------------------------------------
314 public boolean checkIfConnectionToMediatorIsOk() {
315 synchronized (dmLock) {
316 return optionalNe != null;
321 * New implementation to interpret status with empty LTP List as notConnected => return false
322 * 30.10.2018 Since this behavior is very specific and implicit for specific NE Types
323 * it needs to be activated by extension or configuration. Change to be disabled at the moment
326 public boolean checkIfConnectionToNeIsOk() {
330 /*---------------------------------------------------------------
335 /*---------------------------------------------------------------
336 * Equipment related functions
340 public @NonNull InventoryInformationDcae getInventoryInformation(String layerProtocolFilter) {
341 LOG.debug("request inventory information. filter: {}" + layerProtocolFilter);
342 return this.equipment.getInventoryInformation(getFilteredInterfaceUuidsAsStringList(layerProtocolFilter));
346 public InventoryInformationDcae getInventoryInformation() {
347 return getInventoryInformation(null);
350 protected List<String> getFilteredInterfaceUuidsAsStringList(String layerProtocolFilter) {
351 List<String> uuids = new ArrayList<>();
353 LOG.debug("request inventory information. filter: {}" + layerProtocolFilter);
354 if (optionalNe != null) {
356 for (Lp lp : this.interfaceList) {
357 if (layerProtocolFilter == null || layerProtocolFilter.isEmpty() || layerProtocolFilter
358 .equals(Helper.nnGetLayerProtocolName(lp.getLayerProtocolName()).getValue())) {
359 uuids.add(Helper.nnGetUniversalId(lp.getUuid()).getValue());
363 LOG.debug("uuids found: {}", uuids);
368 /*---------------------------------------------------------------
369 * Performancemanagement specific interface
373 public void resetPMIterator() {
374 synchronized (pmLock) {
375 interfaceListIterator = interfaceList.iterator();
377 LOG.debug("PM reset iterator");
380 @SuppressWarnings("null")
382 public boolean hasNext() {
384 synchronized (pmLock) {
385 res = interfaceListIterator != null ? interfaceListIterator.hasNext() : false;
387 LOG.debug("PM hasNext LTP {}", res);
391 @SuppressWarnings("null")
394 synchronized (pmLock) {
395 if (interfaceListIterator == null) {
397 LOG.debug("PM next LTP null");
399 pmLp = interfaceListIterator.next();
400 LOG.debug("PM next LTP {}", Helper.nnGetLayerProtocolName(pmLp.getLayerProtocolName()).getValue());
405 @SuppressWarnings("null")
407 public String pmStatusToString() {
408 StringBuilder res = new StringBuilder();
409 synchronized (pmLock) {
410 res.append(pmLp == null ? "no interface"
411 : Helper.nnGetLayerProtocolName(pmLp.getLayerProtocolName()).getValue());
412 for (Lp lp : getInterfaceList()) {
414 res.append(Helper.nnGetLayerProtocolName(lp.getLayerProtocolName()).getValue());
418 return res.toString();
422 public void doRegisterEventListener(MountPoint mountPoint) {
426 @SuppressWarnings("unchecked")
428 public <L extends NetworkElementService> Optional<L> getService(Class<L> clazz) {
429 return clazz.isInstance(this) ? Optional.of((L) this) : Optional.empty();
433 public Optional<PerformanceDataLtp> getLtpHistoricalPerformanceData() {
434 return Optional.empty();