f4e697aec4dd0c3b12684de7b78bb6e8eae01494
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.interfaces;
23
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Objects;
29 import org.eclipse.jdt.annotation.NonNull;
30 import org.eclipse.jdt.annotation.Nullable;
31 import org.onap.ccsdk.features.sdnr.wt.common.YangHelper;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.equipment.Onf14DomEquipmentManager;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.util.Debug;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
36 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
37 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.LAYERPROTOCOLNAMETYPEAIRLAYER;
38 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.LayerProtocol1;
39 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.air._interface.lp.spec.AirInterfacePac;
40 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.air._interface.pac.AirInterfaceCurrentProblems;
41 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.ControlConstruct;
42 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.LAYERPROTOCOLNAMETYPE;
43 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.UniversalId;
44 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.control.construct.LogicalTerminationPoint;
45 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.control.construct.LogicalTerminationPointKey;
46 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.logical.termination.point.LayerProtocol;
47 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.logical.termination.point.LayerProtocolKey;
48 import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.LAYERPROTOCOLNAMETYPEETHERNETCONTAINERLAYER;
49 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.LAYERPROTOCOLNAMETYPEWIRELAYER;
50 import org.opendaylight.yangtools.concepts.ListenerRegistration;
51 import org.opendaylight.yangtools.yang.binding.NotificationListener;
52 import org.slf4j.Logger;
53 import org.slf4j.LoggerFactory;
54
55 public class Onf14DomInterfacePacManager {
56
57     // constants
58     private static final Logger log = LoggerFactory.getLogger(Onf14DomEquipmentManager.class);
59     // end of constants
60
61     // variables
62     private final NetconfDomAccessor netconfDomAccessor;
63     private final @NonNull DeviceManagerServiceProvider serviceProvider;
64
65     // air interface related members
66     private final List<TechnologySpecificPacKeys> airInterfaceList = new ArrayList<TechnologySpecificPacKeys>();
67     @SuppressWarnings("unused")
68     private ListenerRegistration<NotificationListener> airInterfaceNotificationListenerHandler;
69     private @NonNull final Onf14AirInterfaceNotificationListener airInterfaceNotificationListener;
70
71     // ethernet container related members
72     private final List<TechnologySpecificPacKeys> ethernetContainerList = new ArrayList<TechnologySpecificPacKeys>();
73     @SuppressWarnings("unused")
74     private ListenerRegistration<NotificationListener> etherneContainerNotificationListenerHandler;
75     private @NonNull final Onf14EthernetContainerNotificationListener ethernetContainerNotificationListener;
76
77     // wire interface related members
78     private final List<TechnologySpecificPacKeys> wireInterfaceList = new ArrayList<TechnologySpecificPacKeys>();
79     @SuppressWarnings("unused")
80     private ListenerRegistration<NotificationListener> wireInterfaceNotificationListenerHandler;
81     private @NonNull final Onf14WireInterfaceNotificationListener wireInterfaceNotificationListener;
82     // end of variables
83
84     // constructors
85     public Onf14DomInterfacePacManager(@NonNull NetconfDomAccessor netconfDomAccessor,
86             @NonNull DeviceManagerServiceProvider serviceProvider) {
87
88         this.netconfDomAccessor = Objects.requireNonNull(netconfDomAccessor);
89         this.serviceProvider = Objects.requireNonNull(serviceProvider);
90
91         this.airInterfaceNotificationListenerHandler = null;
92         this.airInterfaceNotificationListener =
93                 new Onf14AirInterfaceNotificationListener(netconfDomAccessor, serviceProvider);
94         this.etherneContainerNotificationListenerHandler = null;
95         ethernetContainerNotificationListener =
96                 new Onf14EthernetContainerNotificationListener(netconfDomAccessor, serviceProvider);
97         this.wireInterfaceNotificationListenerHandler = null;
98         wireInterfaceNotificationListener =
99                 new Onf14WireInterfaceNotificationListener(netconfDomAccessor, serviceProvider);
100     }
101     // end of constructors
102
103     // getters and setters
104     // end of getters and setters
105
106     // private methods
107     // end of private methods
108
109     // public methods
110     public void readAllAirInterfaceCurrentProblems(NetconfDomAccessor netconfDomAccessor,
111             ControlConstruct controlConstruct, FaultData resultList) {
112
113         int idxStart; // Start index for debug messages
114
115         for (TechnologySpecificPacKeys key : airInterfaceList) {
116             idxStart = resultList.size();
117
118             readAirInterfaceCurrentProblemForLtp(netconfDomAccessor, controlConstruct, key.getLtpUuid(),
119                     key.getLocalId(), resultList);
120             Debug.debugResultList(key.getLtpUuid().getValue(), resultList, idxStart);
121         }
122     }
123
124     /*
125     public void readAllEhernetContainerCurrentProblems(FaultData resultList) {
126
127         int idxStart; // Start index for debug messages
128
129         for (TechnologySpecificPacKeys key : ethernetContainerList) {
130             idxStart = resultList.size();
131
132             readEthernetConainerCurrentProblemForLtp(key.getLtpUuid(), key.getLocalId(), resultList);
133             debugResultList(key.getLtpUuid().getValue(), resultList, idxStart);
134         }
135     }
136
137     public void readAllWireInterfaceCurrentProblems(FaultData resultList) {
138
139         int idxStart; // Start index for debug messages
140
141         for (TechnologySpecificPacKeys key : wireInterfaceList) {
142             idxStart = resultList.size();
143
144             readWireInterfaceCurrentProblemForLtp(key.getLtpUuid(), key.getLocalId(), resultList);
145             debugResultList(key.getLtpUuid().getValue(), resultList, idxStart);
146         }
147     }*/
148     public void readKeys(ControlConstruct controlConstruct) {
149
150         @NonNull
151         Collection<LogicalTerminationPoint> ltpList =
152                 YangHelper.getCollection(controlConstruct.nonnullLogicalTerminationPoint());
153         log.debug("Iterating the LTP list for node {}", netconfDomAccessor.getNodeId().getValue());
154
155         // iterating all the Logical Termination Point list
156         for (LogicalTerminationPoint ltp : ltpList) {
157             @NonNull
158             List<LayerProtocol> lpList = YangHelper.getList(ltp.nonnullLayerProtocol());
159             // the Layer Protocol list should contain only one item, since we have an 1:1 relationship between the LTP and the LP
160             if (lpList.size() != 1) {
161                 log.debug("Layer protocol has no 1:1 relationship with the LTP.");
162                 return;
163             }
164             // accessing the LP, which should be only 1
165             LayerProtocol lp = lpList.get(0);
166             @Nullable
167             Class<? extends LAYERPROTOCOLNAMETYPE> layerProtocolName = lp.getLayerProtocolName();
168             if (layerProtocolName != null) {
169                 // if the LTP has an airInterface technology extension, the layer protocol name is air-layer
170                 if (layerProtocolName.getTypeName() == LAYERPROTOCOLNAMETYPEAIRLAYER.class.getName()) {
171                     TechnologySpecificPacKeys airInterfaceKey =
172                             new TechnologySpecificPacKeys(ltp.getUuid(), lp.getLocalId());
173                     airInterfaceList.add(airInterfaceKey);
174                     log.debug("Adding Ltp with uuid {} and local-id {} to the air-interface list",
175                             ltp.getUuid().getValue(), lp.getLocalId());
176                 }
177                 // if the LTP has an ethernetContainier technology extension, the layer protocol name is ethernet-container-layer
178                 else if (layerProtocolName.getTypeName() == LAYERPROTOCOLNAMETYPEETHERNETCONTAINERLAYER.class
179                         .getName()) {
180                     TechnologySpecificPacKeys ethernetContainerKey =
181                             new TechnologySpecificPacKeys(ltp.getUuid(), lp.getLocalId());
182                     ethernetContainerList.add(ethernetContainerKey);
183                     log.debug("Adding Ltp with uuid {} and local-id {} to the ethernet-contatinier list",
184                             ltp.getUuid().getValue(), lp.getLocalId());
185                 } else if (layerProtocolName.getTypeName() == LAYERPROTOCOLNAMETYPEWIRELAYER.class.getName()) {
186                     TechnologySpecificPacKeys wireInterfaceKey =
187                             new TechnologySpecificPacKeys(ltp.getUuid(), lp.getLocalId());
188                     wireInterfaceList.add(wireInterfaceKey);
189                     log.debug("Adding Ltp with uuid {} and local-id {} to the wire-interface list",
190                             ltp.getUuid().getValue(), lp.getLocalId());
191                 }
192             }
193         }
194     }
195
196     private static void readAirInterfaceCurrentProblemForLtp(NetconfDomAccessor netconfDomAccessor,
197             ControlConstruct controlConstruct, UniversalId ltpUuid, String localId, FaultData resultList) {
198
199         final Class<AirInterfacePac> clazzPac = AirInterfacePac.class;
200
201         log.info("DBRead Get current problems for class {} from mountpoint {} for LTP uuid {} and local-id {}",
202                 clazzPac.getSimpleName(), netconfDomAccessor.getNodeId().getValue(), ltpUuid.getValue(), localId);
203
204         // constructing the IID needs the augmentation exposed byy the air-interface-2-0 model
205         //        InstanceIdentifier<AirInterfaceCurrentProblems> airInterfaceCurrentProblem_IID = InstanceIdentifier
206         //                .builder(ControlConstruct.class)
207         //                .child(LogicalTerminationPoint.class, new LogicalTerminationPointKey(ltpUuid))
208         //                .child(LayerProtocol.class, new LayerProtocolKey(localId))
209         //                .augmentation(
210         //                        org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.LayerProtocol1.class)
211         //                .child(AirInterfacePac.class)
212         //                .child(AirInterfaceCurrentProblems.class).build();
213         /*
214         final YangInstanceIdentifier airInterfaceCurrentProblem_IID =
215                 YangInstanceIdentifier.builder().node(ControlConstruct.QNAME)
216                         .nodeWithKey(LogicalTerminationPoint.QNAME,
217                                 QName.create(LogicalTerminationPoint.QNAME, "logical-termination-point-key").intern(),
218                                 ltpUuid.getValue())
219                         .nodeWithKey(LayerProtocol.QNAME,
220                                 QName.create(LayerProtocol.QNAME, "layer-protocol-key").intern(), localId)
221                         //.node(org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.LayerProtocol1.QNAME)
222                         .node(AirInterfacePac.QNAME).node(AirInterfaceCurrentProblems.QNAME).build();
223
224         // reading all the current-problems list for this specific LTP and LP
225         AirInterfaceCurrentProblems problems =
226                  netconfDomAccessor.readData(LogicalDatastoreType.OPERATIONAL, airInterfaceCurrentProblem_IID);
227          */
228
229         @NonNull
230         Map<LogicalTerminationPointKey, LogicalTerminationPoint> ltpMap =
231                 controlConstruct.nonnullLogicalTerminationPoint();
232         LogicalTerminationPoint ltp = ltpMap.get(new LogicalTerminationPointKey(ltpUuid));
233         if (ltp != null) {
234             @NonNull
235             Map<LayerProtocolKey, LayerProtocol> lpMap = ltp.nonnullLayerProtocol();
236             LayerProtocol lp = lpMap.get(new LayerProtocolKey(localId));
237             @Nullable
238             LayerProtocol1 lp1 = lp.augmentation(
239                     org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.LayerProtocol1.class);
240             if (lp1 != null) {
241                 @Nullable
242                 AirInterfacePac airInterfacePack = lp1.getAirInterfacePac();
243                 if (airInterfacePack != null) {
244                     @Nullable
245                     AirInterfaceCurrentProblems cp = airInterfacePack.getAirInterfaceCurrentProblems();
246                     if (cp == null) {
247                         log.debug("DBRead Id {} no AirInterfaceCurrentProblems", ltpUuid);
248                     } else {
249                         for (org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.air._interface.current.problems.CurrentProblemList problem : YangHelper
250                                 .getCollection(cp.nonnullCurrentProblemList())) {
251                             resultList.add(netconfDomAccessor.getNodeId(), (int) problem.getSequenceNumber(),
252                                     problem.getTimestamp(), ltpUuid.getValue(), problem.getProblemName(),
253                                     Onf14AirInterface.mapSeverity(problem.getProblemSeverity()));
254                         }
255                     }
256                 }
257             }
258         }
259     }
260
261     /*
262     private void readEthernetConainerCurrentProblemForLtp(UniversalId ltpUuid, String localId, FaultData resultList) {
263
264         final Class<EthernetContainerPac> clazzPac = EthernetContainerPac.class;
265
266         log.info("DBRead Get current problems for class {} from mountpoint {} for LTP uuid {} and local-id {}",
267                 clazzPac.getSimpleName(), netconfDomAccessor.getNodeId().getValue(), ltpUuid.getValue(), localId);
268
269         // constructing the IID needs the augmentation exposed by the ethernet-container-2-0 model
270         //        InstanceIdentifier<EthernetContainerCurrentProblems> etherneContainerCurrentProblem_IID = InstanceIdentifier
271         //                .builder(ControlConstruct.class)
272         //                .child(LogicalTerminationPoint.class, new LogicalTerminationPointKey(ltpUuid))
273         //                .child(LayerProtocol.class, new LayerProtocolKey(localId))
274         //                .augmentation(
275         //                        org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.LayerProtocol1.class)
276         //                .child(EthernetContainerPac.class).child(EthernetContainerCurrentProblems.class).build();
277         final YangInstanceIdentifier etherneContainerCurrentProblem_IID =
278                 YangInstanceIdentifier.builder().node(ControlConstruct.QNAME)
279                         .nodeWithKey(LogicalTerminationPoint.QNAME,
280                                 QName.create(LogicalTerminationPoint.QNAME, "logical-termination-point-key").intern(),
281                                 ltpUuid.getValue())
282                         .nodeWithKey(LayerProtocol.QNAME,
283                                 QName.create(LayerProtocol.QNAME, "layer-protocol-key").intern(), localId)
284                         //.node(org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.LayerProtocol1.QNAME)
285                         .node(EthernetContainerPac.QNAME).node(EthernetContainerCurrentProblems.QNAME).build();
286
287         // reading all the current-problems list for this specific LTP and LP
288         EthernetContainerCurrentProblems problems =
289                 netconfDomAccessor.readData(LogicalDatastoreType.OPERATIONAL, etherneContainerCurrentProblem_IID);
290
291         if (problems == null) {
292             log.debug("DBRead Id {} no EthernetContainerCurrentProblems", ltpUuid);
293         } else if (problems.getCurrentProblemList() == null) {
294             log.debug("DBRead Id {} empty CurrentProblemList", ltpUuid);
295         } else {
296             for (org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.ethernet.container.current.problems.CurrentProblemList problem : YangHelper
297                     .getCollection(problems.nonnullCurrentProblemList())) {
298                 resultList.add(netconfDomAccessor.getNodeId(), (int) problem.getSequenceNumber(),
299                         problem.getTimestamp(), ltpUuid.getValue(), problem.getProblemName(),
300                         Onf14EthernetContainer.mapSeverity(problem.getProblemSeverity()));
301             }
302         }
303     }
304
305     private void readWireInterfaceCurrentProblemForLtp(UniversalId ltpUuid, String localId, FaultData resultList) {
306
307         final Class<WireInterfacePac> clazzPac = WireInterfacePac.class;
308
309         log.info("DBRead Get current problems for class {} from mountpoint {} for LTP uuid {} and local-id {}",
310                 clazzPac.getSimpleName(), netconfDomAccessor.getNodeId().getValue(), ltpUuid.getValue(), localId);
311
312         // constructing the IID needs the augmentation exposed by the wire-interface-2-0 model
313         //        InstanceIdentifier<WireInterfaceCurrentProblems> wireInterfaceCurrentProblem_IID = InstanceIdentifier
314         //                .builder(ControlConstruct.class)
315         //                .child(LogicalTerminationPoint.class, new LogicalTerminationPointKey(ltpUuid))
316         //                .child(LayerProtocol.class, new LayerProtocolKey(localId))
317         //                .augmentation(
318         //                        org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.LayerProtocol1.class)
319         //                .child(WireInterfacePac.class).child(WireInterfaceCurrentProblems.class).build();
320         final YangInstanceIdentifier wireInterfaceCurrentProblem_IID =
321                 YangInstanceIdentifier.builder().node(ControlConstruct.QNAME)
322                         .nodeWithKey(LogicalTerminationPoint.QNAME,
323                                 QName.create(LogicalTerminationPoint.QNAME, "logical-termination-point-key").intern(),
324                                 ltpUuid.getValue())
325                         .nodeWithKey(LayerProtocol.QNAME,
326                                 QName.create(LayerProtocol.QNAME, "layer-protocol-key").intern(), localId)
327                         //.node(org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.LayerProtocol1.QNAME)
328                         .node(WireInterfacePac.QNAME).node(WireInterfaceCurrentProblems.QNAME).build();
329
330         // reading all the current-problems list for this specific LTP and LP
331         WireInterfaceCurrentProblems problems =
332                 netconfDomAccessor.readData(LogicalDatastoreType.OPERATIONAL, wireInterfaceCurrentProblem_IID);
333
334         if (problems == null) {
335             log.debug("DBRead Id {} no WireInterfaceCurrentProblems", ltpUuid);
336         } else if (problems.getCurrentProblemList() == null) {
337             log.debug("DBRead Id {} empty CurrentProblemList", ltpUuid);
338         } else {
339             for (org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.wire._interface.current.problems.CurrentProblemList problem : YangHelper
340                     .getCollection(problems.nonnullCurrentProblemList())) {
341                 resultList.add(netconfDomAccessor.getNodeId(), (int) problem.getSequenceNumber(),
342                         problem.getTimestamp(), ltpUuid.getValue(), problem.getProblemName(),
343                         Onf14WireInterface.mapSeverity(problem.getProblemSeverity()));
344             }
345         }
346     }
347     */
348
349     // end of public methods
350
351     // static methods
352     // end of static methods
353
354     // private classes
355     // end of private classes
356 }