2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.Hashtable;
27 import java.util.List;
28 import java.util.Optional;
29 import org.eclipse.jdt.annotation.NonNull;
30 import org.onap.ccsdk.features.sdnr.wt.common.YangHelper;
31 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp;
32 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
34 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
35 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
36 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNotifications;
37 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.OrgOpenroadmDevice;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.circuit.packs.CircuitPacks;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.interfaces.grp.Interface;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.org.openroadm.device.Xponder;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.shelf.Slots;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.shelves.Shelves;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.xponder.XpdrPort;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.PmdataEntity;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType;
49 import org.opendaylight.yangtools.concepts.ListenerRegistration;
50 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
51 import org.opendaylight.yangtools.yang.binding.NotificationListener;
52 import org.opendaylight.yangtools.yang.common.Uint32;
53 import org.slf4j.Logger;
54 import org.slf4j.LoggerFactory;
57 * @author Shabnam Sultana
59 * Creating the openroadm device as an optical network element and writing inventory, fault, pm data to elastic
63 public class OpenroadmNetworkElement extends OpenroadmNetworkElementBase {
66 private final long equipmentLevel = 1;
67 private static final Logger log = LoggerFactory.getLogger(OpenroadmNetworkElement.class);
68 private Hashtable<String, Long> circuitPacksRecord;
69 private Hashtable<String, Long> shelfProvisionedcircuitPacks;
70 private ListenerRegistration<NotificationListener> openRdmListenerRegistrationResult;
71 private @NonNull final OpenroadmChangeNotificationListener openRdmListener;
72 private ListenerRegistration<NotificationListener> opnRdmFaultListenerRegistrationResult;
73 private @NonNull OpenroadmFaultNotificationListener opnRdmFaultListener;
74 private ListenerRegistration<NotificationListener> opnRdmDeviceListenerRegistrationResult;
75 private OpenroadmDeviceChangeNotificationListener opnRdmDeviceListener;
76 private OpenroadmInventoryInput opnRdmInventoryInput;
77 private PmDataBuilderOpenRoadm openRoadmPmData;
78 private InitialDeviceAlarmReader initialAlarmReader;
80 private Optional<NetconfNotifications> notifications;
81 private static final NetconfTimeStamp ncTimeConverter = NetconfTimeStampImpl.getConverter();
82 private int counter = 1;
86 public OpenroadmNetworkElement(NetconfBindingAccessor netconfAccess, DeviceManagerServiceProvider serviceProvider) {
88 super(netconfAccess, serviceProvider);
90 this.notifications = netconfAccess.getNotificationAccessor();
92 log.info("Create {}", OpenroadmNetworkElement.class.getSimpleName());
93 this.openRdmListenerRegistrationResult = null;
94 this.openRdmListener = new OpenroadmChangeNotificationListener(netconfAccessor, databaseService);
95 this.opnRdmFaultListenerRegistrationResult = null;
96 this.opnRdmFaultListener = new OpenroadmFaultNotificationListener(serviceProvider);
97 this.opnRdmDeviceListenerRegistrationResult = null;
98 this.opnRdmDeviceListener = new OpenroadmDeviceChangeNotificationListener(netconfAccessor, databaseService);
99 this.circuitPacksRecord = new Hashtable<>();
100 this.shelfProvisionedcircuitPacks = new Hashtable<>();
101 this.openRoadmPmData = new PmDataBuilderOpenRoadm(this.netconfAccessor);
102 this.initialAlarmReader = new InitialDeviceAlarmReader(this.netconfAccessor, serviceProvider);
103 log.info("NodeId {}", this.netconfAccessor.getNodeId().getValue());
107 // end of constructors
110 public void initialReadFromNetworkElement() {
112 OrgOpenroadmDevice device = readDevice(this.netconfAccessor);
113 this.opnRdmInventoryInput = new OpenroadmInventoryInput(this.netconfAccessor, device);
114 log.info("openroadmMapper details{}", this.opnRdmInventoryInput.getClass().getName());
115 databaseService.writeInventory(this.opnRdmInventoryInput.getInventoryData(Uint32.valueOf(equipmentLevel)));
117 readShelvesData(device);
118 readXpndrData(device);
119 readCircuitPacketData(device);
120 readInterfaceData(device);
121 // Writing initial alarms at the time of device registration
122 initialAlarmReader.faultService();
123 // Writing historical PM data at the time of device registration
124 List<PmdataEntity> pmDataEntity = new ArrayList<>();
125 pmDataEntity = this.openRoadmPmData.buildPmDataEntity(this.openRoadmPmData.getPmData(this.netconfAccessor));
126 if (!pmDataEntity.isEmpty()) {
127 this.databaseService.doWritePerformanceData(pmDataEntity);
128 log.info("PmDatEntity is written with size {}", pmDataEntity.size());
129 for (PmdataEntity ent : pmDataEntity) {
130 log.info("GetNode: {}, granPeriod: {}", ent.getNodeName(), ent.getGranularityPeriod().getName());
133 log.info("PmDatEntity is empty");
139 public void register() {
140 initialReadFromNetworkElement();
142 this.openRdmListenerRegistrationResult = netconfAccessor.doRegisterNotificationListener(openRdmListener);
143 this.opnRdmFaultListenerRegistrationResult =
144 netconfAccessor.doRegisterNotificationListener(opnRdmFaultListener);
145 this.opnRdmDeviceListenerRegistrationResult =
146 netconfAccessor.doRegisterNotificationListener(opnRdmDeviceListener);
147 // Register netconf stream
148 notifications.get().registerNotificationsStream(NetconfAccessor.DefaultNotificationsStream);
152 public void deregister() {
153 if (openRdmListenerRegistrationResult != null) {
154 this.openRdmListenerRegistrationResult.close();
156 if (opnRdmFaultListenerRegistrationResult != null) {
157 this.opnRdmFaultListenerRegistrationResult.close();
159 if (opnRdmDeviceListenerRegistrationResult != null) {
160 this.opnRdmDeviceListenerRegistrationResult.close();
164 // end of public methods
167 private void readShelvesData(OrgOpenroadmDevice device) {
168 Collection<Shelves> shelves = YangHelper.getCollection(device.getShelves());
169 if (shelves != null) {
170 for (Shelves shelf : shelves) {
172 "Shelf Name: {}, \n Serial Id:{}, \n Product Code;{}, \n Position:{}, \n EquipmetState: {}, \n Hardware version: {}"
173 + "\n ShelfType:{}, \n Vendor: {}, \n LifecycleState: {} ",
174 shelf.getShelfName(), shelf.getSerialId(), shelf.getProductCode(), shelf.getShelfPosition(),
175 shelf.getEquipmentState(), shelf.getHardwareVersion(), shelf.getShelfType(), shelf.getVendor(),
176 shelf.getLifecycleState());
177 databaseService.writeInventory(
178 this.opnRdmInventoryInput.getShelvesInventory(shelf, Uint32.valueOf(equipmentLevel + 1)));
179 Collection<Slots> slotList = YangHelper.getCollection(shelf.getSlots());
180 if (slotList != null) {
181 for (Slots slot : slotList) {
182 if (slot.getProvisionedCircuitPack() != null) {
183 this.shelfProvisionedcircuitPacks.put(slot.getProvisionedCircuitPack(), equipmentLevel + 2);
185 log.info("Slots for the shelf: {}", shelf.getShelfName());
186 log.info("\n Slot Name: {}, \n Status: {}, \n Slot label: {} ", slot.getSlotName(),
187 slot.getSlotStatus(), slot.getLabel());
191 log.info("size of shelfProvisionedcircuitPacks: {} ", shelfProvisionedcircuitPacks.size());
196 private void readXpndrData(OrgOpenroadmDevice device) {
197 Collection<Xponder> xponderList = YangHelper.getCollection(device.getXponder());
199 if (xponderList != null) {
200 for (Xponder xponder : xponderList) {
202 databaseService.writeInventory(
203 this.opnRdmInventoryInput.getXponderInventory(xponder, Uint32.valueOf(equipmentLevel + 1)));
204 log.info("Xponders: No.: {} , \n Port: {} ,\n Type: {}", xponder.getXpdrNumber(), xponder.getXpdrPort(),
205 xponder.getXpdrType());
206 Collection<XpdrPort> xpdrportlist = YangHelper.getCollection(xponder.getXpdrPort());
207 if (xpdrportlist != null) {
208 for (XpdrPort xpdrport : xpdrportlist)
209 if (xpdrport.getCircuitPackName() != null) {
210 this.shelfProvisionedcircuitPacks.put(xpdrport.getCircuitPackName(), equipmentLevel + 2);
211 log.info("Size of dict{}", this.shelfProvisionedcircuitPacks.size());
219 private void readCircuitPacketData(OrgOpenroadmDevice device) {
220 Collection<CircuitPacks> circuitpackCollection = YangHelper.getCollection(device.getCircuitPacks());
221 List<String> cpNameList = new ArrayList<>();
223 if (circuitpackCollection != null) {
224 // collect all circuit pack names. Required to check for invalid parents later on
225 for (CircuitPacks cp : circuitpackCollection) {
226 cpNameList.add(cp.getCircuitPackName());
229 for (CircuitPacks cp : circuitpackCollection) {
230 log.info("CP Name:{}", cp.getCircuitPackName());
232 if (cp.getParentCircuitPack() == null
233 && !this.shelfProvisionedcircuitPacks.containsKey(cp.getCircuitPackName())) {
234 log.info("cp has no parent and no shelf");
235 this.circuitPacksRecord.put(cp.getCircuitPackName(), (equipmentLevel + 1));
236 databaseService.writeInventory(
237 this.opnRdmInventoryInput.getCircuitPackInventory(cp, Uint32.valueOf(equipmentLevel + 1)));
239 // check for missing valid parent circuit name
240 if (cp.getParentCircuitPack().getCpSlotName() != null
241 && cp.getParentCircuitPack().getCircuitPackName() == null) {
243 log.info("Cp {} has slotname of the parent circuit pack but no parent circuit pack name",
244 cp.getCircuitPackName());
245 this.circuitPacksRecord.put(cp.getCircuitPackName(), (equipmentLevel + 3));
246 databaseService.writeInventory(this.opnRdmInventoryInput.getCircuitPackInventory(cp,
247 Uint32.valueOf(equipmentLevel + 3)));
248 databaseService.writeEventLog(writeIncorrectParentLog(cp.getCircuitPackName(), counter)
249 .setObjectId(device.getInfo().getNodeId().getValue())
250 .setId(cp.getParentCircuitPack().getCpSlotName())
251 .setNewValue("Missing parent circuit pack name").build());
252 } else if (cp.getParentCircuitPack().getCircuitPackName() != null
253 && this.shelfProvisionedcircuitPacks
254 .containsKey(cp.getParentCircuitPack().getCircuitPackName())) {
255 log.info("Cp {} has parent circuit pack and shelf", cp.getCircuitPackName());
256 this.circuitPacksRecord.put(cp.getCircuitPackName(), (equipmentLevel + 3));
257 databaseService.writeInventory(this.opnRdmInventoryInput.getCircuitPackInventory(cp,
258 Uint32.valueOf(equipmentLevel + 3)));
260 // check for incorrect hierarchy
261 if (cp.getParentCircuitPack().getCircuitPackName() != null
262 && !cpNameList.contains(cp.getParentCircuitPack().getCircuitPackName())) {
263 databaseService.writeEventLog(writeIncorrectParentLog(cp.getCircuitPackName(), counter)
264 .setObjectId(device.getInfo().getNodeId().getValue())
265 .setId(cp.getParentCircuitPack().getCpSlotName()).build());
268 log.info("Cp has parent circuit pack but no shelf or a shelf but no parent circuit pack");
269 this.circuitPacksRecord.put(cp.getCircuitPackName(), (equipmentLevel + 2));
270 databaseService.writeInventory(this.opnRdmInventoryInput.getCircuitPackInventory(cp,
271 Uint32.valueOf(equipmentLevel + 2)));
280 private void readInterfaceData(OrgOpenroadmDevice device) {
281 Collection<Interface> interfaceList = YangHelper.getCollection(device.getInterface());
282 if (interfaceList != null) {
283 for (Interface deviceInterface : interfaceList) {
284 log.info("\n InterfaceName: {}", deviceInterface.getName());
285 log.info("Supporting CP {}", this.circuitPacksRecord.size());
286 for (String s : this.circuitPacksRecord.keySet()) {
287 log.info("{} value {}", s, this.circuitPacksRecord.get(s));
289 log.info("Interface {} and their supporting CP {}", deviceInterface.getName(),
290 deviceInterface.getSupportingCircuitPackName());
291 if (deviceInterface.getSupportingCircuitPackName() != null) {
292 if (this.circuitPacksRecord.containsKey(deviceInterface.getSupportingCircuitPackName())) {
293 databaseService.writeInventory(this.opnRdmInventoryInput.getInterfacesInventory(deviceInterface,
295 this.circuitPacksRecord.get(deviceInterface.getSupportingCircuitPackName())
299 databaseService.writeInventory(this.opnRdmInventoryInput.getInterfacesInventory(deviceInterface,
300 Uint32.valueOf(equipmentLevel + 1)));
306 private OrgOpenroadmDevice readDevice(NetconfBindingAccessor accessor) {
307 final Class<OrgOpenroadmDevice> openRoadmDev = OrgOpenroadmDevice.class;
308 InstanceIdentifier<OrgOpenroadmDevice> deviceId = InstanceIdentifier.builder(openRoadmDev).build();
309 return accessor.getTransactionUtils().readData(accessor.getDataBroker(),
310 LogicalDatastoreType.OPERATIONAL, deviceId);
313 private EventlogBuilder writeIncorrectParentLog(String attributeName, Integer counter) {
314 EventlogBuilder eventlogBuilder = new EventlogBuilder();
315 eventlogBuilder.setAttributeName(attributeName).setCounter(counter)
316 .setNodeId(this.netconfAccessor.getNodeId().getValue()).setSourceType(SourceType.Netconf)
317 .setNewValue("Invalid parent circuit-pack name")
318 .setTimestamp(new DateAndTime(ncTimeConverter.getTimeStamp()));
320 return eventlogBuilder;
323 // end of private methods