f0ce392d7257933a47767800b908bbf3986f5bab
[ccsdk/features.git] /
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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
15  * the License.
16  * ============LICENSE_END==========================================================================
17  ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf;
19
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;
25
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;
45
46
47
48 /**
49  * This class contains the ONF Core model Version 1.2 related functions.
50  * It should import
51  */
52 @SuppressWarnings("deprecation")
53 public abstract class ONFCoreNetworkElement12Base extends ONFCoreNetworkElementBase implements ONFCOreNetworkElementCoreData {
54
55     private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12Base.class);
56
57     protected static final List<Extension> EMPTYLTPEXTENSIONLIST = new ArrayList<>();
58     // private static final List<Ltp> EMPTYLTPLIST = new ArrayList<>();
59
60     protected static final InstanceIdentifier<NetworkElement> NETWORKELEMENT_IID = InstanceIdentifier
61             .builder(NetworkElement.class).build();
62
63     protected static final InstanceIdentifier<InstanceList> PTPINSTANCES_IID = InstanceIdentifier
64             .builder(InstanceList.class, new InstanceListKey(1)).build();
65
66     /*-----------------------------------------------------------------------------
67      * Class members
68      */
69
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;
74
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;
81
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();
85
86     protected final boolean isNetworkElementCurrentProblemsSupporting12;
87
88     protected final ONFCoreNetworkElement12Equipment equipment;
89
90     /*
91      * Constructor
92      */
93
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());
102     }
103
104     /*---------------------------------------------------------------
105      * Getter/ Setter
106      */
107
108     @Override
109     public NetworkElement getOptionalNetworkElement() {
110         return optionalNe;
111     }
112
113
114     /*---------------------------------------------------------------
115      * Device Monitor
116      */
117
118     @Override
119     public boolean checkIfConnectionToMediatorIsOk() {
120         synchronized (dmLock) {
121             return optionalNe != null;
122         }
123     }
124
125     /*
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
129      */
130     @Override
131     public boolean checkIfConnectionToNeIsOk() {
132         return true;
133     }
134
135     /*---------------------------------------------------------------
136      * Synchronization
137      */
138
139     /**
140      * Query synchronization information out of NE
141      */
142
143     @Override
144     public void initSynchronizationExtension() {
145         // ClockIdentityType vv;
146         try {
147             if (!getCapabilities().isSupportingNamespaceAndRevision(InstanceList.QNAME)) {
148                 LOG.debug("Mountpoint {} does not support PTP", getMountPointNodeName());
149             } else {
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) {
156                         int t = 0;
157                         for (PortDsEntry portDs : ptpInstance.getPortDsList()) {
158                             PortIdentity portId = portDs.getPortIdentity();
159                             if (portId != null) {
160                                 sb.append("Port[");
161                                 sb.append(portId.getPortNumber());
162                                 sb.append("]{ ClockId: ");
163                                 sb.append(portId.getClockIdentity());
164                                 sb.append(", Portstate: ");
165                                 sb.append(portDs.getPortState());
166                                 sb.append("}, ");
167                             } else {
168                                 sb.append("Incomplete port #" + t + ", ");
169                             }
170                             t++;
171                         }
172                     } else {
173                         sb.append("dsList contains null");
174                     }
175                 } else {
176                     sb.append("ptpInstance equals null");
177                 }
178                 LOG.trace(sb.toString());
179             }
180         } catch (Exception e) {
181             LOG.info("Inconsistent synchronisation structure: " + e.getMessage());
182         }
183
184     }
185
186     @Nullable
187     private InstanceList readPTPClockInstances() {
188         return GenericTransactionUtils.readData(getNetconfNodeDataBroker(), LogicalDatastoreType.OPERATIONAL,
189                 PTPINSTANCES_IID);
190     }
191
192     /*---------------------------------------------------------------
193      * Equipment related functions
194      */
195
196
197     @Override
198     public InventoryInformation getInventoryInformation() {
199         return this.getInventoryInformation(null);
200     }
201
202
203     @Override
204     public @Nonnull InventoryInformation getInventoryInformation(String layerProtocolFilter) {
205         LOG.debug("request inventory information. filter:" + layerProtocolFilter);
206         return this.equipment.getInventoryInformation(getFilteredInterfaceUuidsAsStringList(layerProtocolFilter));
207     }
208
209     /*---------------------------------------------------------------
210      * Other
211      */
212
213     @Override
214     protected List<String> getFilteredInterfaceUuidsAsStringList(String layerProtocolFilter) {
215         List<String> uuids = new ArrayList<>();
216
217         LOG.debug("request inventory information. filter:" + layerProtocolFilter);
218         if (optionalNe != null) {
219             // uuids
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());
226                 }
227             }
228         }
229         LOG.debug("uuids found: {}", uuids);
230         return uuids;
231     }
232
233 }