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 @SuppressWarnings("deprecation")
53 public abstract class ONFCoreNetworkElement12Base extends ONFCoreNetworkElementBase implements ONFCOreNetworkElementCoreData {
55 private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12Base.class);
57 protected static final List<Extension> EMPTYLTPEXTENSIONLIST = new ArrayList<>();
58 // private static final List<Ltp> EMPTYLTPLIST = new ArrayList<>();
60 protected static final InstanceIdentifier<NetworkElement> NETWORKELEMENT_IID = InstanceIdentifier
61 .builder(NetworkElement.class).build();
63 protected static final InstanceIdentifier<InstanceList> PTPINSTANCES_IID = InstanceIdentifier
64 .builder(InstanceList.class, new InstanceListKey(1)).build();
66 /*-----------------------------------------------------------------------------
70 // Non specific part. Used by all functions.
71 /** interfaceList is used by PM task and should be synchronized */
72 protected final @Nonnull List<Lp> interfaceList = Collections.synchronizedList(new CopyOnWriteArrayList<>());
73 protected @Nullable NetworkElement optionalNe = null;
75 // Performance monitoring specific part
76 /** Lock for the PM access specific elements that could be null */
77 protected final @Nonnull Object pmLock = new Object();
78 protected @Nullable Iterator<Lp> interfaceListIterator = null;
79 /** Actual pmLp used during iteration over interfaces */
80 protected @Nullable Lp pmLp = null;
82 // Device monitoring specific part
83 /** Lock for the DM access specific elements that could be null */
84 protected final @Nonnull Object dmLock = new Object();
86 protected final boolean isNetworkElementCurrentProblemsSupporting12;
88 protected final ONFCoreNetworkElement12Equipment equipment;
94 protected ONFCoreNetworkElement12Base(String mountPointNodeName, DataBroker netconfNodeDataBroker,
95 Capabilities capabilities) {
96 super(mountPointNodeName, netconfNodeDataBroker, capabilities);
97 // TODO Auto-generated constructor stub
98 this.isNetworkElementCurrentProblemsSupporting12 = capabilities.isSupportingNamespaceAndRevision(NetworkElementPac.QNAME);
99 this.equipment = new ONFCoreNetworkElement12Equipment(this, capabilities);
100 LOG.debug("support necurrent-problem-list=" + this.isNetworkElementCurrentProblemsSupporting12);
101 LOG.info("Create NE instance {}", InstanceList.QNAME.getLocalName());
104 /*---------------------------------------------------------------
109 public NetworkElement getOptionalNetworkElement() {
114 /*---------------------------------------------------------------
119 public boolean checkIfConnectionToMediatorIsOk() {
120 synchronized (dmLock) {
121 return optionalNe != null;
126 * New implementation to interpret status with empty LTP List as notConnected => return false
127 * 30.10.2018 Since this behavior is very specific and implicit for specific NE Types
128 * it needs to be activated by extension or configuration. Change to be disabled at the moment
131 public boolean checkIfConnectionToNeIsOk() {
135 /*---------------------------------------------------------------
140 * Query synchronization information out of NE
144 public void initSynchronizationExtension() {
145 // ClockIdentityType vv;
147 if (!getCapabilities().isSupportingNamespaceAndRevision(InstanceList.QNAME)) {
148 LOG.debug("Mountpoint {} does not support PTP", getMountPointNodeName());
150 StringBuffer sb = new StringBuffer();
151 sb.append("NE " + getMountPointNodeName() + " does support synchronisation.\n");
152 InstanceList ptpInstance = readPTPClockInstances();
153 if (ptpInstance != null) {
154 List<PortDsList> dsList = ptpInstance.getPortDsList();
155 if (dsList != null) {
157 for (PortDsEntry portDs : ptpInstance.getPortDsList()) {
158 PortIdentity portId = portDs.getPortIdentity();
159 if (portId != null) {
161 sb.append(portId.getPortNumber());
162 sb.append("]{ ClockId: ");
163 sb.append(portId.getClockIdentity());
164 sb.append(", Portstate: ");
165 sb.append(portDs.getPortState());
168 sb.append("Incomplete port #" + t + ", ");
173 sb.append("dsList contains null");
176 sb.append("ptpInstance equals null");
178 LOG.trace(sb.toString());
180 } catch (Exception e) {
181 LOG.info("Inconsistent synchronisation structure: " + e.getMessage());
187 private InstanceList readPTPClockInstances() {
188 return GenericTransactionUtils.readData(getNetconfNodeDataBroker(), LogicalDatastoreType.OPERATIONAL,
192 /*---------------------------------------------------------------
193 * Equipment related functions
198 public InventoryInformation getInventoryInformation() {
199 return this.getInventoryInformation(null);
204 public @Nonnull InventoryInformation getInventoryInformation(String layerProtocolFilter) {
205 LOG.debug("request inventory information. filter:" + layerProtocolFilter);
206 return this.equipment.getInventoryInformation(getFilteredInterfaceUuidsAsStringList(layerProtocolFilter));
209 /*---------------------------------------------------------------
214 protected List<String> getFilteredInterfaceUuidsAsStringList(String layerProtocolFilter) {
215 List<String> uuids = new ArrayList<>();
217 LOG.debug("request inventory information. filter:" + layerProtocolFilter);
218 if (optionalNe != null) {
220 for (Lp lp : this.interfaceList) {
221 if (layerProtocolFilter == null || layerProtocolFilter.isEmpty()) {
222 uuids.add(lp.getUuid().getValue());
223 } else if (lp.getLayerProtocolName() != null && lp.getLayerProtocolName().getValue() != null
224 && lp.getLayerProtocolName().getValue().equals(layerProtocolFilter)) {
225 uuids.add(lp.getUuid().getValue());
229 LOG.debug("uuids found: {}", uuids);