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
51 * conditional packages.
53 * Get conditional packages from Networkelement Possible interfaces are: MWPS, LTP(MWPS-TTP),
54 * MWAirInterfacePac, MicrowaveModel-ObjectClasses-AirInterface ETH-CTP,LTP(Client),
55 * MW_EthernetContainer_Pac MWS, LTP(MWS-CTP-xD), MWAirInterfaceDiversityPac,
56 * MicrowaveModel-ObjectClasses-AirInterfaceDiversity MWS, LTP(MWS-TTP),
57 * ,MicrowaveModel-ObjectClasses-HybridMwStructure MWS, LTP(MWS-TTP),
58 * ,MicrowaveModel-ObjectClasses-PureEthernetStructure
63 public class ONFCoreNetworkElement12Microwave extends ONFCoreNetworkElement12Basic
64 implements NotificationActor<EventlogEntity> {
66 private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12Microwave.class);
68 private final @NonNull FaultService microwaveEventListener;
69 private final @NonNull EquipmentService equipmentService;
70 private final @NonNull OnfMicrowaveModel microwaveModel;
71 private final NotificationWorker<EventlogEntity> notificationQueue;
73 private ListenerRegistration<NotificationListener> listenerRegistrationresult = null;
75 /*-----------------------------------------------------------------------------
81 * @param acessor for device
82 * @param serviceProvider to get services
83 * @param onfMicrowaveModel handling ofmicrosoft model data
85 public ONFCoreNetworkElement12Microwave(@NonNull NetconfAccessor acessor,
86 @NonNull DeviceManagerServiceProvider serviceProvider,
87 DeviceManagerOnfConfiguration configuration,
88 OnfMicrowaveModel onfMicrowaveModel) {
90 super(acessor, serviceProvider,configuration);
91 this.microwaveModel = onfMicrowaveModel;
93 this.microwaveEventListener = serviceProvider.getFaultService();
94 this.equipmentService = serviceProvider.getEquipmentService();
96 this.notificationQueue = new NotificationWorker<>(1, 100, this);
97 this.microwaveModel.setNotificationQueue(notificationQueue);
101 /*-----------------------------------------------------------------------------
107 * @param serviceProvider
108 * @param configuration
109 * @param onfMicrowaveModel
112 * DeviceMonitor Prepare check by updating NE state and reading all interfaces.
115 public void prepareCheck() {
116 synchronized (dmLock) {
117 boolean change = readNetworkElementAndInterfaces();
119 int problems = microwaveEventListener.removeAllCurrentProblemsOfNode(nodeId);
120 FaultData resultList = readAllCurrentProblemsOfNode();
121 microwaveEventListener.initCurrentProblemStatus(nodeId, resultList);
122 LOG.info("Resync mountpoint {} for device {}. Removed {}. Current problems: {}", getMountpoint(),
123 getUuId(), problems, resultList.size());
128 // public boolean checkIfConnectionToMediatorIsOk() -> Shifted to super class
129 // public boolean checkIfConnectionToNeIsOk() -> Shifted to super class
131 /*-----------------------------------------------------------------------------
135 // public void initSynchronizationExtension() -> Shifted to super class
136 // private InstanceList readPTPClockInstances() -> Shifted to super class
138 /*-----------------------------------------------------------------------------
139 * Services for NE/Device synchronization
143 * Handling of specific Notifications from NE, indicating changes and need for synchronization.
145 * <attribute-value-changed-notification xmlns="urn:onf:params:xml:ns:yang:microwave-model">
146 * <attribute-name>/equipment-pac/equipment-current-problems</attribute-name>
147 * <object-id-ref>CARD-1.1.1.0</object-id-ref> <new-value></new-value>
148 * </attribute-value-changed-notification>
149 * <attribute-value-changed-notification xmlns="urn:onf:params:xml:ns:yang:microwave-model">
150 * <attribute-name>/network-element/extension[value-name="top-level-equipment"]/value</attribute-name>
151 * <object-id-ref>Hybrid-Z</object-id-ref>
152 * <new-value>SHELF-1.1.0.0,IDU-1.55.0.0,ODU-1.56.0.0,IDU-1.65.0.0</new-value>
153 * </attribute-value-changed-notification>
156 public void notificationActor(@NonNull EventlogEntity notification) {
158 LOG.debug("Enter change notification listener");
159 if (LOG.isTraceEnabled()) {
160 LOG.trace("Notification: {}", notification);
162 String attributeName = notification.getAttributeName();
163 if (attributeName != null) {
164 if (attributeName.equals("/equipment-pac/equipment-current-problems")) {
165 syncEquipmentPac(notification.getObjectId());
166 } else if (attributeName.equals("/network-element/extension[value-name=\"top-level-equipment\"]/value")) {
167 initialReadFromNetworkElement();
170 LOG.debug("Leave change notification listener");
174 * Synchronize problems for a specific equipment-pac
176 * @param uuidString of the equipment-pac
178 private synchronized void syncEquipmentPac(String uuidString) {
180 int problems = microwaveEventListener.removeObjectsCurrentProblemsOfNode(nodeId, uuidString);
181 LOG.debug("Removed {} problems for uuid {}", problems, uuidString);
183 FaultData resultList = equipment.addProblemsofNodeObject(uuidString);
184 microwaveEventListener.initCurrentProblemStatus(nodeId, resultList);
185 LOG.debug("Added {} problems for uuid {}", resultList.size(), uuidString);
190 /*-----------------------------------------------------------------------------
191 * Problem/Fault related functions
195 * Read during startup all relevant structure and status parameters from device
198 public synchronized void initialReadFromNetworkElement() {
199 LOG.debug("Get info about {}", getMountpoint());
201 int problems = microwaveEventListener.removeAllCurrentProblemsOfNode(nodeId);
202 LOG.debug("Removed all {} problems from database at registration", problems);
204 // Step 2.1: access data broker within this mount point
205 LOG.debug("DBRead start");
207 // Step 2.2: read ne from data store
208 readNetworkElementAndInterfaces();
209 equipment.readNetworkElementEquipment();
211 // Step 2.3: read the existing faults and add to DB
212 FaultData resultList = readAllCurrentProblemsOfNode();
213 equipment.addProblemsofNode(resultList);
215 microwaveEventListener.initCurrentProblemStatus(nodeId, resultList);
216 equipmentService.writeEquipment(equipment.getEquipmentData());
218 LOG.info("Found info at {} for device {} number of problems: {}", getMountpoint(), getUuId(),
223 * LOG the newly added problems of the interface pac
229 private void debugResultList(String uuid, FaultData resultList, int idxStart) {
230 if (LOG.isDebugEnabled()) {
231 StringBuilder sb = new StringBuilder();
233 for (int t = idxStart; t < resultList.size(); t++) {
236 sb.append(resultList.get(t));
239 LOG.debug("Found problems {} {}", uuid, sb);
244 * Read current problems of AirInterfaces and EthernetContainer according to NE status into DB
246 * @return List with all problems
249 protected FaultData readAllCurrentProblemsOfNode() {
251 // Step 2.3: read the existing faults and add to DB
252 FaultData resultList = new FaultData();
253 int idxStart; // Start index for debug messages
254 @NonNull UniversalId uuid;
256 synchronized (getPmLock()) {
257 for (Lp lp : getInterfaceList()) {
259 idxStart = resultList.size();
260 uuid = Helper.nnGetUniversalId(lp.getUuid());
261 Class<?> lpClass = getLpExtension(lp);
263 ONFLayerProtocolName lpName = ONFLayerProtocolName.valueOf(lp.getLayerProtocolName());
264 microwaveModel.readTheFaultsOfMicrowaveModel(lpName, lpClass, uuid, resultList);
265 debugResultList(uuid.getValue(), resultList, idxStart);
269 // Step 2.4: Read other problems from mountpoint
270 if (isNetworkElementCurrentProblemsSupporting12) {
271 idxStart = resultList.size();
272 readNetworkElementCurrentProblems12(resultList);
273 debugResultList("CurrentProblems12", resultList, idxStart);
281 * Get from LayerProtocolExtensions the related generated ONF Interface PAC class which represents it.
283 * @param lp logical termination point
284 * @return Class of InterfacePac
287 private Class<?> getLpExtension(@Nullable Lp lp) {
289 String capability = EMPTY;
290 String revision = EMPTY;
291 String conditionalPackage = EMPTY;
295 for (Extension e : getExtensionList(lp)) {
296 String valueName = e.getValueName();
297 if (valueName != null) {
298 if (valueName.contentEquals("capability")) {
299 capability = e.getValue();
300 if (capability != null) {
301 int idx = capability.indexOf('?');
303 capability = capability.substring(0, idx);
307 if (valueName.contentEquals("revision")) {
308 revision = e.getValue();
310 if (valueName.contentEquals("conditional-package")) {
311 conditionalPackage = e.getValue();
317 // org.opendaylight.yangtools.yang.common.QName.create("urn:onf:params:xml:ns:yang:microwave-model",
318 // "2017-03-24", "mw-air-interface-pac").intern();
319 LOG.info("LpExtension capability={} revision={} conditionalPackage={}", capability, revision,
321 if (capability != null && !capability.isEmpty() && !revision.isEmpty() && !conditionalPackage.isEmpty()) {
323 QName qName = QName.create(capability, revision, conditionalPackage);
324 res = this.microwaveModel.getClassForLtpExtension(qName);
325 } catch (IllegalArgumentException e) {
326 LOG.debug("Can not create QName from ({}{}{}): {}", capability, revision, conditionalPackage,
334 * Read element from class that could be not available
336 * @param ltp layer termination point
337 * @return List with extension parameters or empty list
340 private static List<Extension> getExtensionList(@Nullable Lp ltp) {
342 return ltp.nonnullExtension();
344 return EMPTYLTPEXTENSIONLIST;
349 public Optional<PerformanceDataLtp> getLtpHistoricalPerformanceData() {
350 synchronized (getPmLock()) {
352 LOG.debug("Enter query PM");
353 @SuppressWarnings("null")
356 ONFLayerProtocolName lpName = ONFLayerProtocolName.valueOf(lp.getLayerProtocolName());
357 return Optional.of(this.microwaveModel.getLtpHistoricalPerformanceData(lpName, lp));
359 return Optional.empty();
364 * Remove all entries from list
367 public int removeAllCurrentProblemsOfNode() {
368 return microwaveEventListener.removeAllCurrentProblemsOfNode(nodeId);
372 * Register the listener
375 public void doRegisterEventListener(MountPoint mountPoint) {
376 LOG.info("Begin registration listener for Mountpoint");
377 final Optional<NotificationService> optionalNotificationService =
378 mountPoint.getService(NotificationService.class);
379 final NotificationService notificationService = optionalNotificationService.get();
380 // notificationService.registerNotificationListener(microwaveEventListener);
381 listenerRegistrationresult =
382 notificationService.registerNotificationListener(microwaveModel.getNotificationListener());
383 LOG.info("End registration listener for Mountpoint Result: {}",listenerRegistrationresult);
386 /*------------------------------------------------------------
387 * private function to access database
390 /*-----------------------------------------------------------------------------
391 * Reading problems for the networkElement V1.2
395 public void close() throws Exception {
396 if (listenerRegistrationresult != null) {
397 listenerRegistrationresult.close();
402 public NetworkElementDeviceType getDeviceType() {
403 return NetworkElementDeviceType.Wireless;