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.netconf;
20 import java.util.ArrayList;
21 import java.util.Collections;
22 import java.util.Iterator;
23 import java.util.List;
24 import java.util.concurrent.CopyOnWriteArrayList;
26 import javax.annotation.Nonnull;
27 import javax.annotation.Nullable;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.InventoryInformation;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.container.Capabilities;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.util.GenericTransactionUtils;
31 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
32 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ptp.dataset.rev170208.InstanceList;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ptp.dataset.rev170208.InstanceListKey;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ptp.dataset.rev170208.PortDsEntry;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ptp.dataset.rev170208.instance.list.PortDsList;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ptp.dataset.rev170208.port.ds.entry.PortIdentity;
38 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.NetworkElement;
39 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.extension.g.Extension;
40 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.logical.termination.point.g.Lp;
41 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.NetworkElementPac;
42 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
49 * This class contains the ONF Core model Version 1.2 related functions.
52 public abstract class ONFCoreNetworkElement12Base extends ONFCoreNetworkElementBase implements ONFCOreNetworkElementCoreData {
54 private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12Base.class);
56 protected static final List<Extension> EMPTYLTPEXTENSIONLIST = new ArrayList<>();
57 // private static final List<Ltp> EMPTYLTPLIST = new ArrayList<>();
59 protected static final InstanceIdentifier<NetworkElement> NETWORKELEMENT_IID = InstanceIdentifier
60 .builder(NetworkElement.class).build();
62 protected static final InstanceIdentifier<InstanceList> PTPINSTANCES_IID = InstanceIdentifier
63 .builder(InstanceList.class, new InstanceListKey(1)).build();
65 /*-----------------------------------------------------------------------------
69 // Non specific part. Used by all functions.
70 /** interfaceList is used by PM task and should be synchronized */
71 protected final @Nonnull List<Lp> interfaceList = Collections.synchronizedList(new CopyOnWriteArrayList<>());
72 protected @Nullable NetworkElement optionalNe = null;
74 // Performance monitoring specific part
75 /** Lock for the PM access specific elements that could be null */
76 protected final @Nonnull Object pmLock = new Object();
77 protected @Nullable Iterator<Lp> interfaceListIterator = null;
78 /** Actual pmLp used during iteration over interfaces */
79 protected @Nullable Lp pmLp = null;
81 // Device monitoring specific part
82 /** Lock for the DM access specific elements that could be null */
83 protected final @Nonnull Object dmLock = new Object();
85 protected final boolean isNetworkElementCurrentProblemsSupporting12;
87 protected final ONFCoreNetworkElement12Equipment equipment;
93 protected ONFCoreNetworkElement12Base(String mountPointNodeName, DataBroker netconfNodeDataBroker,
94 Capabilities capabilities) {
95 super(mountPointNodeName, netconfNodeDataBroker, capabilities);
96 // TODO Auto-generated constructor stub
97 this.isNetworkElementCurrentProblemsSupporting12 = capabilities.isSupportingNamespaceAndRevision(NetworkElementPac.QNAME);
98 this.equipment = new ONFCoreNetworkElement12Equipment(this, capabilities);
99 LOG.debug("support necurrent-problem-list=" + this.isNetworkElementCurrentProblemsSupporting12);
100 LOG.info("Create NE instance {}", InstanceList.QNAME.getLocalName());
103 /*---------------------------------------------------------------
108 public NetworkElement getOptionalNetworkElement() {
113 /*---------------------------------------------------------------
118 public boolean checkIfConnectionToMediatorIsOk() {
119 synchronized (dmLock) {
120 return optionalNe != null;
125 * New implementation to interpret status with empty LTP List as notConnected => return false
126 * 30.10.2018 Since this behavior is very specific and implicit for specific NE Types
127 * it needs to be activated by extension or configuration. Change to be disabled at the moment
130 public boolean checkIfConnectionToNeIsOk() {
134 /*---------------------------------------------------------------
139 * Query synchronization information out of NE
143 public void initSynchronizationExtension() {
144 // ClockIdentityType vv;
146 if (!getCapabilities().isSupportingNamespaceAndRevision(InstanceList.QNAME)) {
147 LOG.debug("Mountpoint {} does not support PTP", getMountPointNodeName());
149 StringBuffer sb = new StringBuffer();
150 sb.append("NE " + getMountPointNodeName() + " does support synchronisation.\n");
151 InstanceList ptpInstance = readPTPClockInstances();
152 if (ptpInstance != null) {
153 List<PortDsList> dsList = ptpInstance.getPortDsList();
154 if (dsList != null) {
156 for (PortDsEntry portDs : ptpInstance.getPortDsList()) {
157 PortIdentity portId = portDs.getPortIdentity();
158 if (portId != null) {
160 sb.append(portId.getPortNumber());
161 sb.append("]{ ClockId: ");
162 sb.append(portId.getClockIdentity());
163 sb.append(", Portstate: ");
164 sb.append(portDs.getPortState());
167 sb.append("Incomplete port #" + t + ", ");
172 sb.append("dsList contains null");
175 sb.append("ptpInstance equals null");
177 LOG.trace(sb.toString());
179 } catch (Exception e) {
180 LOG.info("Inconsistent synchronisation structure: " + e.getMessage());
186 private InstanceList readPTPClockInstances() {
187 return GenericTransactionUtils.readData(getNetconfNodeDataBroker(), LogicalDatastoreType.OPERATIONAL,
191 /*---------------------------------------------------------------
192 * Equipment related functions
197 public InventoryInformation getInventoryInformation() {
198 return this.getInventoryInformation(null);
203 public @Nonnull InventoryInformation getInventoryInformation(String layerProtocolFilter) {
204 LOG.debug("request inventory information. filter:" + layerProtocolFilter);
205 return this.equipment.getInventoryInformation(getFilteredInterfaceUuidsAsStringList(layerProtocolFilter));
208 /*---------------------------------------------------------------
213 protected List<String> getFilteredInterfaceUuidsAsStringList(String layerProtocolFilter) {
214 List<String> uuids = new ArrayList<>();
216 LOG.debug("request inventory information. filter:" + layerProtocolFilter);
217 if (optionalNe != null) {
219 for (Lp lp : this.interfaceList) {
220 if (layerProtocolFilter == null || layerProtocolFilter.isEmpty()) {
221 uuids.add(lp.getUuid().getValue());
222 } else if (lp.getLayerProtocolName() != null && lp.getLayerProtocolName().getValue() != null
223 && lp.getLayerProtocolName().getValue().equals(layerProtocolFilter)) {
224 uuids.add(lp.getUuid().getValue());
228 LOG.debug("uuids found: {}", uuids);