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==========================================================================
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ne;
20 import java.util.List;
21 import java.util.Optional;
22 import org.eclipse.jdt.annotation.NonNull;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.microwave.Helper;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.microwave.OnfMicrowaveModel;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.impl.DeviceManagerOnfConfiguration;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.notifications.NotificationActor;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.notifications.NotificationWorker;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.util.ONFLayerProtocolName;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.EquipmentService;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.PerformanceDataLtp;
35 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
36 import org.opendaylight.mdsal.binding.api.MountPoint;
37 import org.opendaylight.mdsal.binding.api.NotificationService;
38 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.UniversalId;
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.opendaylight.params.xml.ns.yang.data.provider.rev190801.EventlogEntity;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.NetworkElementDeviceType;
43 import org.opendaylight.yangtools.concepts.ListenerRegistration;
44 import org.opendaylight.yangtools.yang.binding.NotificationListener;
45 import org.opendaylight.yangtools.yang.common.QName;
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
50 * Get information over NETCONF device according to ONF Coremodel. Read networkelement and conditional packages.
52 * Get conditional packages from Networkelement Possible interfaces are: MWPS, LTP(MWPS-TTP), MWAirInterfacePac,
53 * MicrowaveModel-ObjectClasses-AirInterface ETH-CTP,LTP(Client), MW_EthernetContainer_Pac MWS, LTP(MWS-CTP-xD),
54 * MWAirInterfaceDiversityPac, MicrowaveModel-ObjectClasses-AirInterfaceDiversity MWS, LTP(MWS-TTP),
55 * ,MicrowaveModel-ObjectClasses-HybridMwStructure MWS, LTP(MWS-TTP),
56 * ,MicrowaveModel-ObjectClasses-PureEthernetStructure
61 public class ONFCoreNetworkElement12Microwave extends ONFCoreNetworkElement12Basic
62 implements NotificationActor<EventlogEntity> {
64 private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12Microwave.class);
66 private final @NonNull FaultService microwaveEventListener;
67 private final @NonNull EquipmentService equipmentService;
68 private final @NonNull OnfMicrowaveModel microwaveModel;
69 private final NotificationWorker<EventlogEntity> notificationQueue;
71 private ListenerRegistration<NotificationListener> listenerRegistrationresult = null;
73 /*-----------------------------------------------------------------------------
80 * @param acessor for device
81 * @param serviceProvider to get services
82 * @param onfMicrowaveModel handling ofmicrosoft model data
84 public ONFCoreNetworkElement12Microwave(@NonNull NetconfAccessor acessor,
85 @NonNull DeviceManagerServiceProvider serviceProvider, DeviceManagerOnfConfiguration configuration,
86 OnfMicrowaveModel onfMicrowaveModel) {
88 super(acessor, serviceProvider, configuration);
89 this.microwaveModel = onfMicrowaveModel;
91 this.microwaveEventListener = serviceProvider.getFaultService();
92 this.equipmentService = serviceProvider.getEquipmentService();
94 this.notificationQueue = new NotificationWorker<>(1, 100, this);
95 this.microwaveModel.setNotificationQueue(notificationQueue);
99 /*-----------------------------------------------------------------------------
105 * @param serviceProvider
106 * @param configuration
107 * @param onfMicrowaveModel
110 * DeviceMonitor Prepare check by updating NE state and reading all interfaces.
113 public void prepareCheck() {
114 synchronized (dmLock) {
115 boolean change = readNetworkElementAndInterfaces();
117 int problems = microwaveEventListener.removeAllCurrentProblemsOfNode(nodeId);
118 FaultData resultList = readAllCurrentProblemsOfNode();
119 microwaveEventListener.initCurrentProblemStatus(nodeId, resultList);
120 LOG.info("Resync mountpoint {} for device {}. Removed {}. Current problems: {}", getMountpoint(),
121 getUuId(), problems, resultList.size());
126 // public boolean checkIfConnectionToMediatorIsOk() -> Shifted to super class
127 // public boolean checkIfConnectionToNeIsOk() -> Shifted to super class
129 /*-----------------------------------------------------------------------------
133 // public void initSynchronizationExtension() -> Shifted to super class
134 // private InstanceList readPTPClockInstances() -> Shifted to super class
136 /*-----------------------------------------------------------------------------
137 * Services for NE/Device synchronization
141 * Handling of specific Notifications from NE, indicating changes and need for synchronization.
143 * <attribute-value-changed-notification xmlns="urn:onf:params:xml:ns:yang:microwave-model">
144 * <attribute-name>/equipment-pac/equipment-current-problems</attribute-name>
145 * <object-id-ref>CARD-1.1.1.0</object-id-ref> <new-value></new-value> </attribute-value-changed-notification>
146 * <attribute-value-changed-notification xmlns="urn:onf:params:xml:ns:yang:microwave-model">
147 * <attribute-name>/network-element/extension[value-name="top-level-equipment"]/value</attribute-name>
148 * <object-id-ref>Hybrid-Z</object-id-ref>
149 * <new-value>SHELF-1.1.0.0,IDU-1.55.0.0,ODU-1.56.0.0,IDU-1.65.0.0</new-value>
150 * </attribute-value-changed-notification>
153 public void notificationActor(@NonNull EventlogEntity notification) {
155 LOG.debug("Enter change notification listener");
156 if (LOG.isTraceEnabled()) {
157 LOG.trace("Notification: {}", notification);
159 String attributeName = notification.getAttributeName();
160 if (attributeName != null) {
161 if (attributeName.equals("/equipment-pac/equipment-current-problems")) {
162 syncEquipmentPac(notification.getObjectId());
163 } else if (attributeName.equals("/network-element/extension[value-name=\"top-level-equipment\"]/value")) {
164 initialReadFromNetworkElement();
167 LOG.debug("Leave change notification listener");
171 * Synchronize problems for a specific equipment-pac
173 * @param uuidString of the equipment-pac
175 private void syncEquipmentPac(String uuidString) {
177 int problems = microwaveEventListener.removeObjectsCurrentProblemsOfNode(nodeId, uuidString);
178 LOG.debug("Removed {} problems for uuid {}", problems, uuidString);
180 FaultData resultList = equipment.addProblemsofNodeObject(uuidString);
181 microwaveEventListener.initCurrentProblemStatus(nodeId, resultList);
182 LOG.debug("Added {} problems for uuid {}", resultList.size(), uuidString);
187 /*-----------------------------------------------------------------------------
188 * Problem/Fault related functions
192 * Read during startup all relevant structure and status parameters from device
195 public void initialReadFromNetworkElement() {
196 LOG.debug("Get info about {}", getMountpoint());
198 int problems = microwaveEventListener.removeAllCurrentProblemsOfNode(nodeId);
199 LOG.debug("Removed all {} problems from database at registration", problems);
201 // Step 2.1: access data broker within this mount point
202 LOG.debug("DBRead start");
204 // Step 2.2: read ne from data store
205 readNetworkElementAndInterfaces();
206 LOG.debug("NETCONF read network element and interfaces completed");
207 equipment.readNetworkElementEquipment();
208 LOG.debug("NETCONF read equipment completed");
210 // Step 2.3: read the existing faults and add to DB
211 FaultData resultList = readAllCurrentProblemsOfNode();
212 LOG.debug("NETCONF read current problems completed");
213 equipment.addProblemsofNode(resultList);
215 microwaveEventListener.initCurrentProblemStatus(nodeId, resultList);
216 LOG.debug("DB write current problems completed");
217 equipmentService.writeEquipment(equipment.getEquipmentData());
219 LOG.info("Found info at {} for device {} number of problems: {}", getMountpoint(), getUuId(),
224 * LOG the newly added problems of the interface pac
230 private void debugResultList(String uuid, FaultData resultList, int idxStart) {
231 if (LOG.isDebugEnabled()) {
232 StringBuilder sb = new StringBuilder();
234 for (int t = idxStart; t < resultList.size(); t++) {
237 sb.append(resultList.get(t));
240 LOG.debug("Found problems {} {}", uuid, sb);
245 * Read current problems of AirInterfaces and EthernetContainer according to NE status into DB
247 * @return List with all problems
250 protected FaultData readAllCurrentProblemsOfNode() {
252 // Step 2.3: read the existing faults and add to DB
253 FaultData resultList = new FaultData();
254 int idxStart; // Start index for debug messages
258 synchronized (getPmLock()) {
259 for (Lp lp : getInterfaceList()) {
261 idxStart = resultList.size();
262 uuid = Helper.nnGetUniversalId(lp.getUuid());
264 Class<?> lpClass = getLpExtension(lp);
266 ONFLayerProtocolName lpName = ONFLayerProtocolName.valueOf(lp.getLayerProtocolName());
267 microwaveModel.readTheFaultsOfMicrowaveModel(lpName, lpClass, uuid, resultList);
268 debugResultList(uuid.getValue(), resultList, idxStart);
272 // Step 2.4: Read other problems from mountpoint
273 if (isNetworkElementCurrentProblemsSupporting12) {
274 idxStart = resultList.size();
275 readNetworkElementCurrentProblems12(resultList);
276 debugResultList("CurrentProblems12", resultList, idxStart);
284 * Get from LayerProtocolExtensions the related generated ONF Interface PAC class which represents it.
286 * @param lp logical termination point
287 * @return Class of InterfacePac
290 private Class<?> getLpExtension(@Nullable Lp lp) {
292 String capability = EMPTY;
293 String revision = EMPTY;
294 String conditionalPackage = EMPTY;
298 for (Extension e : getExtensionList(lp)) {
299 String valueName = e.getValueName();
300 if (valueName != null) {
301 if (valueName.contentEquals("capability")) {
302 capability = e.getValue();
303 if (capability != null) {
304 int idx = capability.indexOf('?');
306 capability = capability.substring(0, idx);
310 if (valueName.contentEquals("revision")) {
311 revision = e.getValue();
313 if (valueName.contentEquals("conditional-package")) {
314 conditionalPackage = e.getValue();
320 // org.opendaylight.yangtools.yang.common.QName.create("urn:onf:params:xml:ns:yang:microwave-model",
321 // "2017-03-24", "mw-air-interface-pac").intern();
322 LOG.info("LpExtension capability={} revision={} conditionalPackage={}", capability, revision,
324 if (capability != null && !capability.isEmpty() && !revision.isEmpty() && !conditionalPackage.isEmpty()) {
326 QName qName = QName.create(capability, revision, conditionalPackage);
327 res = this.microwaveModel.getClassForLtpExtension(qName);
328 } catch (IllegalArgumentException e) {
329 LOG.warn("Can not create QName from ({}{}{}): {}", capability, revision, conditionalPackage,
337 * Read element from class that could be not available
339 * @param ltp layer termination point
340 * @return List with extension parameters or empty list
343 private static List<Extension> getExtensionList(@Nullable Lp ltp) {
345 return ltp.nonnullExtension();
347 return EMPTYLTPEXTENSIONLIST;
352 public Optional<PerformanceDataLtp> getLtpHistoricalPerformanceData() {
353 synchronized (getPmLock()) {
355 LOG.debug("Enter query PM");
356 @SuppressWarnings("null")
359 ONFLayerProtocolName lpName = ONFLayerProtocolName.valueOf(lp.getLayerProtocolName());
360 return Optional.of(this.microwaveModel.getLtpHistoricalPerformanceData(lpName, lp));
362 return Optional.empty();
367 * Remove all entries from list
370 public int removeAllCurrentProblemsOfNode() {
371 return microwaveEventListener.removeAllCurrentProblemsOfNode(nodeId);
375 * Register the listener
378 public void doRegisterEventListener(MountPoint mountPoint) {
379 LOG.info("Begin registration listener for Mountpoint");
380 final Optional<NotificationService> optionalNotificationService =
381 mountPoint.getService(NotificationService.class);
382 final NotificationService notificationService = optionalNotificationService.get();
383 // notificationService.registerNotificationListener(microwaveEventListener);
384 listenerRegistrationresult =
385 notificationService.registerNotificationListener(microwaveModel.getNotificationListener());
386 LOG.info("End registration listener for Mountpoint Result: {}", listenerRegistrationresult);
389 /*------------------------------------------------------------
390 * private function to access database
393 /*-----------------------------------------------------------------------------
394 * Reading problems for the networkElement V1.2
398 public void close() throws Exception {
399 if (listenerRegistrationresult != null) {
400 listenerRegistrationresult.close();
405 public NetworkElementDeviceType getDeviceType() {
406 return NetworkElementDeviceType.Wireless;