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.Hashtable;
26 import java.util.List;
27 import java.util.Optional;
28 import org.eclipse.jdt.annotation.NonNull;
29 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElementService;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
33 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
34 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.OrgOpenroadmDevice;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.circuit.packs.CircuitPacks;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.interfaces.grp.Interface;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.org.openroadm.device.Xponder;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.shelf.Slots;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.shelves.Shelves;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.xponder.XpdrPort;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.NetworkElementDeviceType;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.PmdataEntity;
44 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
45 import org.opendaylight.yangtools.concepts.ListenerRegistration;
46 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
47 import org.opendaylight.yangtools.yang.binding.NotificationListener;
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
52 * @author Shabnam Sultana
54 * Creating the openroadm device as an optical network element and writing inventory, fault, pm data to elastic
58 public class OpenroadmNetworkElement implements NetworkElement {
61 private final long equipmentLevel = 0;
62 private static final Logger log = LoggerFactory.getLogger(OpenroadmNetworkElement.class);
63 private final NetconfAccessor netconfAccessor;
64 private final DataProvider databaseService;
65 private Hashtable<String, Long> circuitPacksRecord;
66 private Hashtable<String, Long> shelfProvisionedcircuitPacks;
67 private ListenerRegistration<NotificationListener> openRdmListenerRegistrationResult;
68 private @NonNull final OpenroadmChangeNotificationListener openRdmListener;
69 private ListenerRegistration<NotificationListener> opnRdmFaultListenerRegistrationResult;
70 private @NonNull OpenroadmFaultNotificationListener opnRdmFaultListener;
71 private ListenerRegistration<NotificationListener> opnRdmDeviceListenerRegistrationResult;
72 private OpenroadmDeviceChangeNotificationListener opnRdmDeviceListener;
73 private OpenroadmInventoryInput opnRdmInventoryInput;
74 private PmDataBuilderOpenRoadm openRoadmPmData;
75 private InitialDeviceAlarmReader initialAlarmReader;
76 private List<PmdataEntity> pmDataEntity = new ArrayList<PmdataEntity>();
80 public OpenroadmNetworkElement(NetconfAccessor netconfAccess, DeviceManagerServiceProvider serviceProvider) {
82 log.info("Create {}", OpenroadmNetworkElement.class.getSimpleName());
83 this.netconfAccessor = netconfAccess;
84 this.databaseService = serviceProvider.getDataProvider();
85 this.openRdmListenerRegistrationResult = null;
86 this.openRdmListener = new OpenroadmChangeNotificationListener(netconfAccessor, databaseService);
87 this.opnRdmFaultListenerRegistrationResult = null;
88 this.opnRdmFaultListener = new OpenroadmFaultNotificationListener(netconfAccessor, serviceProvider);
89 this.opnRdmDeviceListenerRegistrationResult = null;
90 this.opnRdmDeviceListener = new OpenroadmDeviceChangeNotificationListener(netconfAccessor, databaseService);
91 this.opnRdmInventoryInput = new OpenroadmInventoryInput(netconfAccess, readDevice(netconfAccess));
92 this.circuitPacksRecord = new Hashtable<String, Long>();
93 this.shelfProvisionedcircuitPacks = new Hashtable<String, Long>();
94 this.openRoadmPmData = new PmDataBuilderOpenRoadm(this.netconfAccessor);
95 this.initialAlarmReader = new InitialDeviceAlarmReader(this.netconfAccessor, serviceProvider);
96 log.info("NodeId {}", this.netconfAccessor.getNodeId().getValue());
97 log.info("oScaMapper details{}", this.opnRdmInventoryInput.getClass().getName());
100 // end of constructors
103 public void initialReadFromNetworkElement() {
104 OrgOpenroadmDevice device = readDevice(this.netconfAccessor);
105 databaseService.writeInventory(this.opnRdmInventoryInput.getInventoryData(equipmentLevel));
107 readShelvesData(device);
108 readXpndrData(device);
109 readCircuitPacketData(device);
110 readInterfaceData(device);
111 // Writing initial alarms at the time of device registration
112 initialAlarmReader.faultService();
113 pmDataEntity = this.openRoadmPmData.buildPmDataEntity(this.openRoadmPmData.getPmData(this.netconfAccessor));
114 if (!pmDataEntity.isEmpty()) {
115 this.databaseService.doWritePerformanceData(pmDataEntity);
116 log.info("PmDatEntity is written with size {}", pmDataEntity.size());
117 for (PmdataEntity ent : pmDataEntity) {
118 log.info("GetNode: {}, granPeriod: {}", ent.getNodeName(), ent.getGranularityPeriod().getName());
121 log.info("PmDatEntity is empty");
127 public NetworkElementDeviceType getDeviceType() {
128 return NetworkElementDeviceType.OROADM;
132 public void register() {
133 initialReadFromNetworkElement();
135 this.openRdmListenerRegistrationResult = netconfAccessor.doRegisterNotificationListener(openRdmListener);
136 this.opnRdmFaultListenerRegistrationResult =
137 netconfAccessor.doRegisterNotificationListener(opnRdmFaultListener);
138 this.opnRdmDeviceListenerRegistrationResult =
139 netconfAccessor.doRegisterNotificationListener(opnRdmDeviceListener);
140 // Register netconf stream
141 netconfAccessor.registerNotificationsStream(NetconfAccessor.DefaultNotificationsStream);
146 public void deregister() {
147 if (openRdmListenerRegistrationResult != null) {
148 this.openRdmListenerRegistrationResult.close();
150 if (opnRdmFaultListenerRegistrationResult != null) {
151 this.opnRdmFaultListenerRegistrationResult.close();
153 if (opnRdmDeviceListenerRegistrationResult != null) {
154 this.opnRdmDeviceListenerRegistrationResult.close();
159 public NodeId getNodeId() {
160 return netconfAccessor.getNodeId();
164 public <L extends NetworkElementService> Optional<L> getService(Class<L> clazz) {
165 return Optional.empty();
169 public void warmstart() {}
172 public Optional<NetconfAccessor> getAcessor() {
173 return Optional.of(netconfAccessor);
175 // end of public methods
178 private void readShelvesData(OrgOpenroadmDevice device) {
179 List<Shelves> shelves = device.getShelves();
180 if (shelves != null) {
181 for (Shelves shelf : shelves) {
183 "Shelf Name: {}, \n Serial Id:{}, \n Product Code;{}, \n Position:{}, \n EquipmetState: {}, \n Hardware version: {}"
184 + "\n ShelfType:{}, \n Vendor: {}, \n LifecycleState: {} ",
185 shelf.getShelfName(), shelf.getSerialId(), shelf.getProductCode(), shelf.getShelfPosition(),
186 shelf.getEquipmentState(), shelf.getHardwareVersion(), shelf.getShelfType(), shelf.getVendor(),
187 shelf.getLifecycleState());
189 .writeInventory(this.opnRdmInventoryInput.getShelvesInventory(shelf, equipmentLevel + 1));
190 List<Slots> slotList = shelf.getSlots();
191 if (slotList != null) {
192 for (Slots slot : slotList) {
193 if (!slot.getProvisionedCircuitPack().isEmpty()) {
194 this.shelfProvisionedcircuitPacks.put(slot.getProvisionedCircuitPack(), equipmentLevel + 2);
196 log.info("Slots for the shelf: {}", shelf.getShelfName());
197 log.info("\n Slot Name: {}, \n Status: {}, \n Slot label: {} ", slot.getSlotName(),
198 slot.getSlotStatus(), slot.getLabel());
201 log.info("size of shelfProvisionedcircuitPacks: {} ", shelfProvisionedcircuitPacks.size());
208 private void readXpndrData(OrgOpenroadmDevice device) {
209 List<Xponder> xponderList = device.getXponder();
210 if (xponderList != null) {
211 for (Xponder xponder : xponderList) {
213 .writeInventory(this.opnRdmInventoryInput.getXponderInventory(xponder, equipmentLevel + 1));
214 log.info("Xponders: No.: {} , \n Port: {} ,\n Type: {}", xponder.getXpdrNumber(), xponder.getXpdrPort(),
215 xponder.getXpdrType());
216 List<XpdrPort> xpdrportlist = xponder.getXpdrPort();
217 if (xpdrportlist != null) {
218 for (XpdrPort xpdrport : xpdrportlist)
219 if (!xpdrport.getCircuitPackName().isEmpty()) {
220 this.shelfProvisionedcircuitPacks.put(xpdrport.getCircuitPackName(), equipmentLevel + 2);
221 log.info("Size of dict{}", this.shelfProvisionedcircuitPacks.size());
231 private void readCircuitPacketData(OrgOpenroadmDevice device) {
232 List<CircuitPacks> circuitpacklist = device.getCircuitPacks();
234 if (circuitpacklist != null) {
235 for (CircuitPacks cp : circuitpacklist) {
236 log.info("CP Name:{}", cp.getCircuitPackName());
237 if (!this.shelfProvisionedcircuitPacks.isEmpty()
238 && this.shelfProvisionedcircuitPacks.containsKey(cp.getCircuitPackName())) {
240 this.circuitPacksRecord.put(cp.getCircuitPackName(), (equipmentLevel + 2));
241 databaseService.writeInventory(this.opnRdmInventoryInput.getCircuitPackInventory(cp,
242 this.shelfProvisionedcircuitPacks.get(cp.getCircuitPackName())));
243 log.info("shelf has circuit pack");
245 if (cp.getParentCircuitPack() == null) {
246 this.circuitPacksRecord.put(cp.getCircuitPackName(), (equipmentLevel + 1));
247 databaseService.writeInventory(
248 this.opnRdmInventoryInput.getCircuitPackInventory(cp, equipmentLevel + 1));
249 log.info("Cp has no parent circuit pack and no shelf");
252 if (this.shelfProvisionedcircuitPacks
253 .containsKey(cp.getParentCircuitPack().getCircuitPackName())) {
254 this.circuitPacksRecord.put(cp.getCircuitPackName(), (equipmentLevel + 3));
255 databaseService.writeInventory(
256 this.opnRdmInventoryInput.getCircuitPackInventory(cp, equipmentLevel + 3));
257 log.info("Cp {} has parent circuit pack and shelf", cp.getCircuitPackName());
259 this.circuitPacksRecord.put(cp.getCircuitPackName(), (equipmentLevel + 2));
260 databaseService.writeInventory(
261 this.opnRdmInventoryInput.getCircuitPackInventory(cp, equipmentLevel + 2));
262 log.info("Cp {} has parent circuit pack but no shelf", cp.getCircuitPackName());
277 private void readInterfaceData(OrgOpenroadmDevice device) {
278 List<Interface> interfaceList = device.getInterface();
279 if (interfaceList != null) {
280 for (Interface deviceInterface : interfaceList) {
282 log.info("\n InterfaceName: {}", deviceInterface.getName());
283 log.info("Supporting CP {}", this.circuitPacksRecord.size());
284 for (String s : this.circuitPacksRecord.keySet()) {
285 log.info("{} value {}", s, this.circuitPacksRecord.get(s));
287 log.info("Interface {} and their supporting CP {}", deviceInterface.getName(),
288 deviceInterface.getSupportingCircuitPackName());
291 if (deviceInterface.getSupportingCircuitPackName() != null) {
292 if (this.circuitPacksRecord.containsKey(deviceInterface.getSupportingCircuitPackName())) {
293 databaseService.writeInventory(this.opnRdmInventoryInput.getInterfacesInventory(deviceInterface,
294 this.circuitPacksRecord.get(deviceInterface.getSupportingCircuitPackName()) + 1));
298 databaseService.writeInventory(
299 this.opnRdmInventoryInput.getInterfacesInventory(deviceInterface, equipmentLevel + 1));
306 private OrgOpenroadmDevice readDevice(NetconfAccessor accessor) {
308 final Class<OrgOpenroadmDevice> openRoadmDev = OrgOpenroadmDevice.class;
309 InstanceIdentifier<OrgOpenroadmDevice> deviceId = InstanceIdentifier.builder(openRoadmDev).build();
311 OrgOpenroadmDevice device = accessor.getTransactionUtils().readData(accessor.getDataBroker(),
312 LogicalDatastoreType.OPERATIONAL, deviceId);
317 // end of private methods