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.common.YangHelper;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.microwave.Helper;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.microwave.OnfMicrowaveModel;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.impl.DeviceManagerOnfConfiguration;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.notifications.NotificationActor;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.notifications.NotificationWorker;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.util.ONFLayerProtocolName;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.EquipmentService;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.PerformanceDataLtp;
36 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
37 import org.opendaylight.mdsal.binding.api.MountPoint;
38 import org.opendaylight.mdsal.binding.api.NotificationService;
39 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.UniversalId;
40 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.extension.g.Extension;
41 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.logical.termination.point.g.Lp;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType;
44 import org.opendaylight.yangtools.concepts.ListenerRegistration;
45 import org.opendaylight.yangtools.yang.binding.NotificationListener;
46 import org.opendaylight.yangtools.yang.common.QName;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
51 * Get information over NETCONF device according to ONF Coremodel. Read networkelement and conditional packages.
53 * Get conditional packages from Networkelement Possible interfaces are: MWPS, LTP(MWPS-TTP), MWAirInterfacePac,
54 * MicrowaveModel-ObjectClasses-AirInterface ETH-CTP,LTP(Client), MW_EthernetContainer_Pac MWS, LTP(MWS-CTP-xD),
55 * MWAirInterfaceDiversityPac, MicrowaveModel-ObjectClasses-AirInterfaceDiversity MWS, LTP(MWS-TTP),
56 * ,MicrowaveModel-ObjectClasses-HybridMwStructure MWS, LTP(MWS-TTP),
57 * ,MicrowaveModel-ObjectClasses-PureEthernetStructure
62 public class ONFCoreNetworkElement12Microwave extends ONFCoreNetworkElement12Basic
63 implements NotificationActor<EventlogEntity> {
65 private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12Microwave.class);
67 private final @NonNull FaultService microwaveEventListener;
68 private final @NonNull EquipmentService equipmentService;
69 private final @NonNull OnfMicrowaveModel microwaveModel;
70 private final NotificationWorker<EventlogEntity> notificationQueue;
72 private ListenerRegistration<NotificationListener> listenerRegistrationresult = null;
74 /*-----------------------------------------------------------------------------
81 * @param acessor for device
82 * @param serviceProvider to get services
83 * @param onfMicrowaveModel handling ofmicrosoft model data
85 public ONFCoreNetworkElement12Microwave(@NonNull NetconfBindingAccessor acessor,
86 @NonNull DeviceManagerServiceProvider serviceProvider, DeviceManagerOnfConfiguration configuration,
87 OnfMicrowaveModel onfMicrowaveModel) {
89 super(acessor, serviceProvider, configuration);
90 this.microwaveModel = onfMicrowaveModel;
92 this.microwaveEventListener = serviceProvider.getFaultService();
93 this.equipmentService = serviceProvider.getEquipmentService();
95 this.notificationQueue = new NotificationWorker<>(1, 100, this);
96 this.microwaveModel.setNotificationQueue(notificationQueue);
100 /*-----------------------------------------------------------------------------
106 * @param serviceProvider
107 * @param configuration
108 * @param onfMicrowaveModel
111 * DeviceMonitor Prepare check by updating NE state and reading all interfaces.
114 public void prepareCheck() {
115 synchronized (dmLock) {
116 boolean change = readNetworkElementAndInterfaces();
118 int problems = microwaveEventListener.removeAllCurrentProblemsOfNode(nodeId);
119 FaultData resultList = readAllCurrentProblemsOfNode();
120 microwaveEventListener.initCurrentProblemStatus(nodeId, resultList);
121 LOG.info("Resync mountpoint {} for device {}. Removed {}. Current problems: {}", getMountpoint(),
122 getUuId(), problems, resultList.size());
127 // public boolean checkIfConnectionToMediatorIsOk() -> Shifted to super class
128 // public boolean checkIfConnectionToNeIsOk() -> Shifted to super class
130 /*-----------------------------------------------------------------------------
134 // public void initSynchronizationExtension() -> Shifted to super class
135 // private InstanceList readPTPClockInstances() -> Shifted to super class
137 /*-----------------------------------------------------------------------------
138 * Services for NE/Device synchronization
142 * Handling of specific Notifications from NE, indicating changes and need for synchronization.
144 * <attribute-value-changed-notification xmlns="urn:onf:params:xml:ns:yang:microwave-model">
145 * <attribute-name>/equipment-pac/equipment-current-problems</attribute-name>
146 * <object-id-ref>CARD-1.1.1.0</object-id-ref> <new-value></new-value> </attribute-value-changed-notification>
147 * <attribute-value-changed-notification xmlns="urn:onf:params:xml:ns:yang:microwave-model">
148 * <attribute-name>/network-element/extension[value-name="top-level-equipment"]/value</attribute-name>
149 * <object-id-ref>Hybrid-Z</object-id-ref>
150 * <new-value>SHELF-1.1.0.0,IDU-1.55.0.0,ODU-1.56.0.0,IDU-1.65.0.0</new-value>
151 * </attribute-value-changed-notification>
154 public void notificationActor(@NonNull EventlogEntity notification) {
156 LOG.debug("Enter change notification listener");
157 if (LOG.isTraceEnabled()) {
158 LOG.trace("Notification: {}", notification);
160 String attributeName = notification.getAttributeName();
161 if (attributeName != null) {
162 if (attributeName.equals("/equipment-pac/equipment-current-problems")) {
163 syncEquipmentPac(notification.getObjectId());
164 } else if (attributeName.equals("/network-element/extension[value-name=\"top-level-equipment\"]/value")) {
165 initialReadFromNetworkElement();
168 LOG.debug("Leave change notification listener");
172 * Synchronize problems for a specific equipment-pac
174 * @param uuidString of the equipment-pac
176 private void syncEquipmentPac(String uuidString) {
178 int problems = microwaveEventListener.removeObjectsCurrentProblemsOfNode(nodeId, uuidString);
179 LOG.debug("Removed {} problems for uuid {}", problems, uuidString);
181 FaultData resultList = equipment.addProblemsofNodeObject(uuidString);
182 microwaveEventListener.initCurrentProblemStatus(nodeId, resultList);
183 LOG.debug("Added {} problems for uuid {}", resultList.size(), uuidString);
188 /*-----------------------------------------------------------------------------
189 * Problem/Fault related functions
193 * Read during startup all relevant structure and status parameters from device
196 public void initialReadFromNetworkElement() {
197 LOG.debug("Get info about {}", getMountpoint());
199 int problems = microwaveEventListener.removeAllCurrentProblemsOfNode(nodeId);
200 LOG.debug("Removed all {} problems from database at registration", problems);
202 // Step 2.1: access data broker within this mount point
203 LOG.debug("DBRead start");
205 // Step 2.2: read ne from data store
206 readNetworkElementAndInterfaces();
207 LOG.debug("NETCONF read network element and interfaces completed");
208 equipment.readNetworkElementEquipment();
209 LOG.debug("NETCONF read equipment completed");
211 // Step 2.3: read the existing faults and add to DB
212 FaultData resultList = readAllCurrentProblemsOfNode();
213 LOG.debug("NETCONF read current problems completed");
214 equipment.addProblemsofNode(resultList);
216 microwaveEventListener.initCurrentProblemStatus(nodeId, resultList);
217 LOG.debug("DB write current problems completed");
218 equipmentService.writeEquipment(nodeId, equipment.getEquipmentData());
220 LOG.info("Found info at {} for device {} number of problems: {}", getMountpoint(), getUuId(),
225 * LOG the newly added problems of the interface pac
231 private void debugResultList(String uuid, FaultData resultList, int idxStart) {
232 if (LOG.isDebugEnabled()) {
233 StringBuilder sb = new StringBuilder();
235 for (int t = idxStart; t < resultList.size(); t++) {
238 sb.append(resultList.get(t));
241 LOG.debug("Found problems {} {}", uuid, sb);
246 * Read current problems of AirInterfaces and EthernetContainer according to NE status into DB
248 * @return List with all problems
251 protected FaultData readAllCurrentProblemsOfNode() {
253 // Step 2.3: read the existing faults and add to DB
254 FaultData resultList = new FaultData();
255 int idxStart; // Start index for debug messages
259 synchronized (getPmLock()) {
260 for (Lp lp : getInterfaceList()) {
262 idxStart = resultList.size();
263 uuid = Helper.nnGetUniversalId(lp.getUuid());
265 Class<?> lpClass = getLpExtension(lp);
267 ONFLayerProtocolName lpName = ONFLayerProtocolName.valueOf(lp.getLayerProtocolName());
268 microwaveModel.readTheFaultsOfMicrowaveModel(lpName, lpClass, uuid, resultList);
269 debugResultList(uuid.getValue(), resultList, idxStart);
273 // Step 2.4: Read other problems from mountpoint
274 if (isNetworkElementCurrentProblemsSupporting12) {
275 idxStart = resultList.size();
276 readNetworkElementCurrentProblems12(resultList);
277 debugResultList("CurrentProblems12", resultList, idxStart);
285 * Get from LayerProtocolExtensions the related generated ONF Interface PAC class which represents it.
287 * @param lp logical termination point
288 * @return Class of InterfacePac
291 private Class<?> getLpExtension(@Nullable Lp lp) {
293 String capability = EMPTY;
294 String revision = EMPTY;
295 String conditionalPackage = EMPTY;
299 for (Extension e : getExtensionList(lp)) {
300 String valueName = e.getValueName();
301 if (valueName != null) {
302 if (valueName.contentEquals("capability")) {
303 capability = e.getValue();
304 if (capability != null) {
305 int idx = capability.indexOf('?');
307 capability = capability.substring(0, idx);
311 if (valueName.contentEquals("revision")) {
312 revision = e.getValue();
314 if (valueName.contentEquals("conditional-package")) {
315 conditionalPackage = e.getValue();
321 // org.opendaylight.yangtools.yang.common.QName.create("urn:onf:params:xml:ns:yang:microwave-model",
322 // "2017-03-24", "mw-air-interface-pac").intern();
323 LOG.info("LpExtension capability={} revision={} conditionalPackage={}", capability, revision,
325 if (capability != null && !capability.isEmpty() && !revision.isEmpty() && !conditionalPackage.isEmpty()) {
327 QName qName = QName.create(capability, revision, conditionalPackage);
328 res = this.microwaveModel.getClassForLtpExtension(qName);
329 } catch (IllegalArgumentException e) {
330 LOG.warn("Can not create QName from ({}{}{}): {}", capability, revision, conditionalPackage,
338 * Read element from class that could be not available
340 * @param ltp layer termination point
341 * @return List with extension parameters or empty list
344 private static List<Extension> getExtensionList(@Nullable Lp ltp) {
346 return YangHelper.getList(ltp.nonnullExtension());
348 return EMPTYLTPEXTENSIONLIST;
353 public Optional<PerformanceDataLtp> getLtpHistoricalPerformanceData() {
354 synchronized (getPmLock()) {
356 LOG.debug("Enter query PM");
357 @SuppressWarnings("null")
360 ONFLayerProtocolName lpName = ONFLayerProtocolName.valueOf(lp.getLayerProtocolName());
361 return Optional.of(this.microwaveModel.getLtpHistoricalPerformanceData(lpName, lp));
363 return Optional.empty();
368 * Remove all entries from list
371 public int removeAllCurrentProblemsOfNode() {
372 return microwaveEventListener.removeAllCurrentProblemsOfNode(nodeId);
376 * Register the listener
379 public void doRegisterEventListener(MountPoint mountPoint) {
380 LOG.info("Begin registration listener for Mountpoint");
381 final Optional<NotificationService> optionalNotificationService =
382 mountPoint.getService(NotificationService.class);
383 final NotificationService notificationService = optionalNotificationService.get();
384 // notificationService.registerNotificationListener(microwaveEventListener);
385 listenerRegistrationresult =
386 notificationService.registerNotificationListener(microwaveModel.getNotificationListener());
387 LOG.info("End registration listener for Mountpoint Result: {}", listenerRegistrationresult);
390 /*------------------------------------------------------------
391 * private function to access database
394 /*-----------------------------------------------------------------------------
395 * Reading problems for the networkElement V1.2
399 public void close() throws Exception {
400 if (listenerRegistrationresult != null) {
401 listenerRegistrationresult.close();
406 public NetworkElementDeviceType getDeviceType() {
407 return NetworkElementDeviceType.Wireless;