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