1 /*******************************************************************************
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==========================================================================
17 ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.base.onfcore;
20 import java.util.ArrayList;
21 import java.util.Collections;
22 import java.util.Iterator;
23 import java.util.List;
24 import java.util.Optional;
25 import java.util.concurrent.CopyOnWriteArrayList;
26 import org.eclipse.jdt.annotation.NonNull;
27 import org.eclipse.jdt.annotation.Nullable;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.NetworkElementService;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.NetworkElementCoreData;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.onfcore.container.AllPm;
31 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
32 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.INetconfAcessor;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.onfcore.wrapperc.WrapperPTPModelRev170208;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.util.InternalDateAndTime;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.util.InternalSeverity;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml;
37 import org.onap.ccsdk.features.sdnr.wt.devicemanager.legacy.InventoryInformation;
38 import org.opendaylight.mdsal.binding.api.DataBroker;
39 import org.opendaylight.mdsal.binding.api.MountPoint;
40 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ptp.dataset.rev170208.InstanceList;
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.yangtools.yang.binding.InstanceIdentifier;
50 import org.slf4j.Logger;
51 import org.slf4j.LoggerFactory;
55 * This class contains the ONF Core model Version 1.2 related functions.<br>
56 * Provides the basic ONF Core Model function.<br>
57 * - initialReadFromNetworkElement is not implemented in child classes.
59 public abstract class ONFCoreNetworkElement12Base extends ONFCoreNetworkElementBase implements NetworkElementCoreData {
61 private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12Base.class);
63 protected static final List<Extension> EMPTYLTPEXTENSIONLIST = new ArrayList<>();
64 // private static final List<Ltp> EMPTYLTPLIST = new ArrayList<>();
66 protected static final InstanceIdentifier<NetworkElement> NETWORKELEMENT_IID = InstanceIdentifier
67 .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 private final @NonNull List<Lp> interfaceList = Collections.synchronizedList(new CopyOnWriteArrayList<>());
77 private @Nullable NetworkElement optionalNe = null;
79 // Performance monitoring specific part
80 /** Lock for the PM access specific elements that could be null */
81 private final @NonNull Object pmLock = new Object();
82 protected @Nullable Iterator<Lp> interfaceListIterator = null;
83 /** Actual pmLp used during iteration over interfaces */
84 protected @Nullable Lp pmLp = null;
86 // Device monitoring specific part
87 /** Lock for the DM access specific elements that could be null */
88 protected final @NonNull Object dmLock = new Object();
90 protected final boolean isNetworkElementCurrentProblemsSupporting12;
92 protected final ONFCoreNetworkElement12Equipment equipment;
98 protected ONFCoreNetworkElement12Base(INetconfAcessor acessor, String mountPointNodeName, DataBroker netconfNodeDataBroker,
99 Capabilities capabilities) {
100 super(acessor, mountPointNodeName, netconfNodeDataBroker, capabilities);
101 // TODO Auto-generated constructor stub
102 this.isNetworkElementCurrentProblemsSupporting12 = capabilities.isSupportingNamespaceAndRevision(NetworkElementPac.QNAME);
103 this.equipment = new ONFCoreNetworkElement12Equipment(acessor, this, capabilities);
104 WrapperPTPModelRev170208.initSynchronizationExtension(acessor);
105 LOG.debug("support necurrent-problem-list=" + this.isNetworkElementCurrentProblemsSupporting12);
106 LOG.info("Create NE instance {}", InstanceList.QNAME.getLocalName());
109 /*---------------------------------------------------------------
114 public NetworkElement getOptionalNetworkElement() {
118 List<Lp> getInterfaceList() {
119 return interfaceList;
122 public Object getPmLock() {
126 /*---------------------------------------------------------------
127 * Core model related function
131 * Get uuid of Optional NE.
133 * @return Uuid or EMPTY String if optionNE is not available
135 @SuppressWarnings("null")
136 protected String getUuId() {
140 uuid = optionalNe != null ? optionalNe.getUuid() != null ? optionalNe.getUuid().getValue() : EMPTY : EMPTY;
141 } catch (NullPointerException e) {
142 // Unfortunately throws null pointer if not definied
148 * Read from NetworkElement and verify LTPs have changed. If the NE has changed, update to the new
149 * structure. From initial state it changes also.
151 protected synchronized boolean readNetworkElementAndInterfaces() {
153 LOG.debug("Update mountpoint if changed {}", getMountPointNodeName());
155 optionalNe = getGenericTransactionUtils().readData(getNetconfNodeDataBroker(), LogicalDatastoreType.OPERATIONAL,
156 NETWORKELEMENT_IID);;
157 synchronized (pmLock) {
158 boolean change = false;
160 if (optionalNe == null) {
161 LOG.debug("Unable to read NE data for mountpoint {}", getMountPointNodeName());
162 if (!interfaceList.isEmpty()) {
163 interfaceList.clear();
164 interfaceListIterator = null;
169 LOG.debug("Mountpoint '{}' NE-Name '{}'", getMountPointNodeName(), optionalNe.getName());
170 List<Lp> actualInterfaceList = getLtpList(optionalNe);
171 if (!interfaceList.equals(actualInterfaceList)) {
172 LOG.debug("Mountpoint '{}' Update LTP List. Elements {}", getMountPointNodeName(),
173 actualInterfaceList.size());
174 interfaceList.clear();
175 interfaceList.addAll(actualInterfaceList);
176 interfaceListIterator = null;
185 * Get List of UUIDs for conditional packages from Networkelement<br>
186 * Possible interfaces are:<br>
187 * MWPS, LTP(MWPS-TTP), MWAirInterfacePac, MicrowaveModel-ObjectClasses-AirInterface<br>
188 * ETH-CTP,LTP(Client), MW_EthernetContainer_Pac<br>
189 * MWS, LTP(MWS-CTP-xD), MWAirInterfaceDiversityPac,
190 * MicrowaveModel-ObjectClasses-AirInterfaceDiversity<br>
191 * MWS, LTP(MWS-TTP), ,MicrowaveModel-ObjectClasses-HybridMwStructure<br>
192 * MWS, LTP(MWS-TTP), ,MicrowaveModel-ObjectClasses-PureEthernetStructure<br>
194 * @param ne NetworkElement
195 * @return Id List, never null.
198 private static List<Lp> getLtpList(@Nullable NetworkElement ne) {
200 List<Lp> res = Collections.synchronizedList(new ArrayList<Lp>());
203 List<Ltp> ltpRefList = ne.getLtp();
204 if (ltpRefList == null) {
205 LOG.debug("DBRead NE-Interfaces: null");
207 for (Ltp ltRefListE : ltpRefList) {
208 List<Lp> lpList = ltRefListE.getLp();
209 if (lpList == null) {
210 LOG.debug("DBRead NE-Interfaces Reference List: null");
212 for (Lp ltp : lpList) {
219 LOG.debug("DBRead NE: null");
223 if (LOG.isDebugEnabled()) {
224 StringBuffer strBuf = new StringBuffer();
226 if (strBuf.length() > 0) {
229 strBuf.append(ltp.getLayerProtocolName().getValue());
231 strBuf.append(ltp.getUuid().getValue());
233 LOG.debug("DBRead NE-Interfaces: {}", strBuf.toString());
241 * Read current problems of AirInterfaces and EthernetContainer according to NE status into DB
243 * @return List with all problems
245 protected List<ProblemNotificationXml> readAllCurrentProblemsOfNode() {
247 // Step 2.3: read the existing faults and add to DB
248 List<ProblemNotificationXml> resultList = new ArrayList<>();
249 int idxStart; // Start index for debug messages
252 synchronized (pmLock) {
253 for (Lp lp : interfaceList) {
255 idxStart = resultList.size();
257 ProblemNotificationXml.debugResultList(LOG, uuid.getValue(), resultList, idxStart);
262 // Step 2.4: Read other problems from mountpoint
263 if (isNetworkElementCurrentProblemsSupporting12) {
264 idxStart = resultList.size();
265 readNetworkElementCurrentProblems12(resultList);
266 ProblemNotificationXml.debugResultList(LOG, "CurrentProblems12", resultList, idxStart);
274 * Reading problems for the networkElement V1.2
278 private List<ProblemNotificationXml> readNetworkElementCurrentProblems12(List<ProblemNotificationXml> resultList) {
280 LOG.info("DBRead Get {} NetworkElementCurrentProblems12", getMountPointNodeName());
282 InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.NetworkElementPac> networkElementCurrentProblemsIID =
283 InstanceIdentifier.builder(
284 org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.NetworkElementPac.class)
287 // Step 2.3: read to the config data store
288 NetworkElementPac problemPac;
289 NetworkElementCurrentProblems problems = null;
291 problemPac = getGenericTransactionUtils().readData(getNetconfNodeDataBroker(), LogicalDatastoreType.OPERATIONAL,
292 networkElementCurrentProblemsIID);
293 if (problemPac != null) {
294 problems = problemPac.getNetworkElementCurrentProblems();
296 if (problems == null) {
297 LOG.debug("DBRead no NetworkElementCurrentProblems12");
299 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 : problems
300 .nonnullCurrentProblemList()) {
301 resultList.add(new ProblemNotificationXml(getMountPointNodeName(), problem.getObjectReference(),
302 problem.getProblemName(), InternalSeverity.valueOf(problem.getProblemSeverity()),
303 problem.getSequenceNumber(),
304 InternalDateAndTime.valueOf(problem.getTimeStamp())));
307 } catch (Exception e) {
308 LOG.warn("DBRead {} NetworkElementCurrentProblems12 not supported. Message '{}' ", getMountPointNodeName(),
314 /*---------------------------------------------------------------
319 public boolean checkIfConnectionToMediatorIsOk() {
320 synchronized (dmLock) {
321 return optionalNe != null;
326 * New implementation to interpret status with empty LTP List as notConnected => return false
327 * 30.10.2018 Since this behavior is very specific and implicit for specific NE Types
328 * it needs to be activated by extension or configuration. Change to be disabled at the moment
331 public boolean checkIfConnectionToNeIsOk() {
335 /*---------------------------------------------------------------
341 /*---------------------------------------------------------------
342 * Equipment related functions
346 public @NonNull InventoryInformation getInventoryInformation(String layerProtocolFilter) {
347 LOG.debug("request inventory information. filter:" + layerProtocolFilter);
348 return this.equipment.getInventoryInformation(getFilteredInterfaceUuidsAsStringList(layerProtocolFilter));
352 public InventoryInformation getInventoryInformation() {
353 return getInventoryInformation(null);
356 protected List<String> getFilteredInterfaceUuidsAsStringList(String layerProtocolFilter) {
357 List<String> uuids = new ArrayList<>();
359 LOG.debug("request inventory information. filter:" + layerProtocolFilter);
360 if (optionalNe != null) {
362 for (Lp lp : this.interfaceList) {
363 if (layerProtocolFilter == null || layerProtocolFilter.isEmpty()) {
364 uuids.add(lp.getUuid().getValue());
365 } else if (lp.getLayerProtocolName() != null && lp.getLayerProtocolName().getValue() != null
366 && lp.getLayerProtocolName().getValue().equals(layerProtocolFilter)) {
367 uuids.add(lp.getUuid().getValue());
371 LOG.debug("uuids found: {}", uuids);
376 /*---------------------------------------------------------------
377 * Performancemanagement specific interface
381 public void resetPMIterator() {
382 synchronized (pmLock) {
383 interfaceListIterator = interfaceList.iterator();
385 LOG.debug("PM reset iterator");
389 public boolean hasNext() {
391 synchronized (pmLock) {
392 res = interfaceListIterator != null ? interfaceListIterator.hasNext() : false;
394 LOG.debug("PM hasNext LTP {}", res);
400 synchronized (pmLock) {
401 if (interfaceListIterator == null) {
403 LOG.debug("PM next LTP null");
405 pmLp = interfaceListIterator.next();
406 LOG.debug("PM next LTP {}", pmLp.getLayerProtocolName().getValue());
412 public String pmStatusToString() {
413 StringBuffer res = new StringBuffer();
414 synchronized (pmLock) {
415 res.append(pmLp == null ? "no interface" : pmLp.getLayerProtocolName().getValue());
416 for (Lp lp : getInterfaceList()) {
418 res.append(lp.getLayerProtocolName().getValue());
422 return res.toString();
426 public AllPm getHistoricalPM() {
427 return AllPm.getEmpty();
432 public void doRegisterEventListener(MountPoint mountPoint) {
438 public void register() {
443 public void deregister() {
446 @SuppressWarnings("unchecked")
448 public <L extends NetworkElementService> Optional<L> getService(Class<L> clazz) {
449 return clazz.isInstance(this) ? Optional.of((L)this) : Optional.empty();