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