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.openroadm71.test;
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.verify;
26 import static org.mockito.Mockito.when;
27 import java.util.Arrays;
28 import java.util.HashMap;
30 import org.eclipse.jdt.annotation.Nullable;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm71.impl.OpenroadmInventoryInput;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm71.impl.OpenroadmNetworkElement;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
37 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
38 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
39 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
40 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
41 import org.opendaylight.mdsal.binding.api.DataBroker;
42 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.ActiveAlarmList;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.Severity;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.active.alarm.list.ActiveAlarms;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.active.alarm.list.ActiveAlarmsKey;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.alarm.ProbableCauseBuilder;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.alarm.ResourceBuilder;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev191129.NodeIdType;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.LifecycleState;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev200529.OpenroadmVersionType;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.OrgOpenroadmDevice;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.circuit.pack.ParentCircuitPack;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.circuit.packs.CircuitPacks;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.circuit.packs.CircuitPacksKey;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.interfaces.grp.Interface;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.interfaces.grp.InterfaceKey;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.Info;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.InfoBuilder;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.Xponder;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.XponderKey;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.shelf.Slots;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.shelf.SlotsKey;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.shelves.Shelves;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.shelves.ShelvesKey;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.NodeTypes;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.XpdrNodeTypes;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.HistoricalPmList;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.group.HistoricalPm;
71 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.group.HistoricalPmKey;
72 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.list.HistoricalPmEntry;
73 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.list.HistoricalPmEntryKey;
74 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.val.group.Measurement;
75 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.val.group.MeasurementKey;
76 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev200327.PmDataType;
77 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev200327.PmGranularity;
78 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev200327.PmNamesEnum;
79 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev200327.Validity;
80 import org.opendaylight.yang.gen.v1.http.org.openroadm.probablecause.rev200529.ProbableCauseEnum;
81 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.DeviceBuilder;
82 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.types.rev191129.ResourceTypeEnum;
83 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
84 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
85 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
86 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
87 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
88 import org.opendaylight.yangtools.yang.common.*;
90 public class TestOpenRoadmNetworkElement {
92 NetconfBindingAccessor accessor = mock(NetconfBindingAccessor.class);
93 DeviceManagerServiceProvider serviceProvider = mock(DeviceManagerServiceProvider.class);
94 DataProvider dataprovider = mock(DataProvider.class);
95 Capabilities capabilities = mock(Capabilities.class);
96 TransactionUtils transactionUtils = mock(TransactionUtils.class);
97 DataBroker dataBroker = mock(DataBroker.class);
98 FaultService faultService = mock(FaultService.class);
99 OrgOpenroadmDevice device;
100 OpenroadmInventoryInput inventoryData;
102 private Shelves shelf = mock(Shelves.class);
103 private @Nullable Map<ShelvesKey, Shelves> shelfList;
104 private CircuitPacks cp, cp1, cp2, cp3;
105 private Interface interfaces = mock(Interface.class);
106 private Xponder xpdr = mock(Xponder.class);
107 private IpAddress ipAddress = new IpAddress(new Ipv4Address("127.0.0.11"));
108 private Info info = new InfoBuilder().setNodeId(NodeIdType.getDefaultInstance("zNhe2i5")).setClli("NodeB")
109 .setSerialId("0002").setModel("model2").setVendor("VendorA").setCurrentIpAddress(ipAddress)
110 .setCurrentIpAddress(ipAddress).setCurrentDefaultGateway(new IpAddress(new Ipv4Address("127.0.0.20")))
111 .setCurrentDefaultGateway(new IpAddress(new Ipv4Address("127.0.0.20"))).setNodeType(NodeTypes.Rdm)
112 .setCurrentDatetime(new DateAndTime("2017-10-22T15:23:43Z")).setSoftwareVersion("swversion1234")
113 .setCurrentPrefixLength(Uint8.valueOf(45)).setMaxDegrees(Uint16.valueOf(56)).setMaxSrgs(Uint16.valueOf(251))
114 .setMaxNumBin15minHistoricalPm(Uint16.valueOf(324)).setMaxNumBin24hourHistoricalPm(Uint16.valueOf(142))
115 .setOpenroadmVersion(OpenroadmVersionType._20).build();
116 private ActiveAlarmList alarmList = mock(ActiveAlarmList.class);
117 private ActiveAlarms activeAlarms = mock(ActiveAlarms.class);
118 private HistoricalPmList pmDataList = mock(HistoricalPmList.class);
119 private HistoricalPm historicalPm = mock(HistoricalPm.class);
123 when(accessor.getCapabilites()).thenReturn(capabilities);
124 when(serviceProvider.getFaultService()).thenReturn(faultService);
125 when(serviceProvider.getDataProvider()).thenReturn(dataprovider);
126 NodeId nNodeId = new NodeId("RoadmA");
127 when(accessor.getNodeId()).thenReturn(nNodeId);
128 when(accessor.getDataBroker()).thenReturn(dataBroker);
129 when(accessor.getTransactionUtils()).thenReturn(transactionUtils);
130 when(accessor.getCapabilites().isSupportingNamespaceAndRevision(OrgOpenroadmDevice.QNAME)).thenReturn(true);
131 final Class<OrgOpenroadmDevice> openRoadmDev = OrgOpenroadmDevice.class;
132 // Reading data from device
133 InstanceIdentifier<OrgOpenroadmDevice> deviceId = InstanceIdentifier.create(openRoadmDev);
134 device = mock(OrgOpenroadmDevice.class);
135 when(accessor.getTransactionUtils().readData(accessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
136 deviceId)).thenReturn(device);
138 when(device.getInfo()).thenReturn(info);
139 inventoryData = new OpenroadmInventoryInput(accessor, device);
140 // Reading the shelfs data;
141 when(shelf.getShelfPosition()).thenReturn("10");
142 when(shelf.getOperationalState()).thenReturn(State.InService);
143 when(shelf.getSerialId()).thenReturn("nodeid-1");
144 when(shelf.getShelfName()).thenReturn("Shelf1");
145 when(shelf.getShelfType()).thenReturn("Shelf");
146 when(shelf.getClei()).thenReturn("1234567890");
147 when(shelf.getVendor()).thenReturn("vendorA");
148 when(shelf.getModel()).thenReturn("1");
149 when(shelf.getHardwareVersion()).thenReturn("0.1");
150 when(shelf.getManufactureDate()).thenReturn(new DateAndTime("2017-10-22T15:23:43Z"));
152 Map<SlotsKey, Slots> slotList = null;
153 Slots slots = mock(Slots.class);
154 when(slots.getLabel()).thenReturn("Slot56746");
155 when(slots.getSlotName()).thenReturn("slotofRoadmA");
156 when(slots.getProvisionedCircuitPack()).thenReturn("1/0");
157 slotList = new HashMap<>();
158 slotList.put(slots.key(), slots);
159 when(shelf.getSlots()).thenReturn(slotList);
160 shelfList = new HashMap<>();
161 shelfList.put(shelf.key(), shelf);
162 when(device.getShelves()).thenReturn(shelfList);
164 // Reading data from CircuitPacks
165 cp = mock(CircuitPacks.class);
166 when(cp.getCircuitPackName()).thenReturn("1/0");
167 when(cp.getVendor()).thenReturn("VendorA");
168 when(cp.getModel()).thenReturn("Model1");
169 when(cp.getSerialId()).thenReturn("46277sgh6");
170 when(cp.getClei()).thenReturn("136268785");
171 when(cp.getHardwareVersion()).thenReturn("0.1");
172 when(cp.getType()).thenReturn("WSS");
173 when(cp.getProductCode()).thenReturn("oooooo");
174 when(cp.getCircuitPackMode()).thenReturn("inServiceMode");
176 ParentCircuitPack parentCp = mock(ParentCircuitPack.class);
177 when(parentCp.getCircuitPackName()).thenReturn("1/0");
178 when(parentCp.getCpSlotName()).thenReturn("Slot1");
179 cp1 = mock(CircuitPacks.class);
180 when(cp1.getCircuitPackName()).thenReturn("1/0 EThernet");
181 when(cp1.getVendor()).thenReturn("VendorA");
182 when(cp1.getModel()).thenReturn("Model1678");
183 when(cp1.getSerialId()).thenReturn("4627dgs7sgh6");
184 when(cp1.getClei()).thenReturn("1362d68785");
185 when(cp1.getHardwareVersion()).thenReturn("0.1");
186 when(cp1.getType()).thenReturn("EthPlug");
187 when(cp1.getProductCode()).thenReturn("oooooo");
188 when(cp1.getCircuitPackMode()).thenReturn("inServiceMode");
189 when(cp1.getParentCircuitPack()).thenReturn(parentCp);
191 cp2 = mock(CircuitPacks.class);
192 when(cp2.getCircuitPackName()).thenReturn("2/0");
193 when(cp2.getVendor()).thenReturn("VendorA");
194 when(cp2.getModel()).thenReturn("Model1678");
195 when(cp2.getSerialId()).thenReturn("4sads7sgh6");
196 when(cp2.getClei()).thenReturn("1wew362d68785");
197 when(cp2.getHardwareVersion()).thenReturn("0.1");
198 when(cp2.getType()).thenReturn("WSS");
199 when(cp2.getProductCode()).thenReturn("osooooo");
200 when(cp2.getCircuitPackMode()).thenReturn("inServiceMode");
202 cp3 = mock(CircuitPacks.class);
203 when(parentCp.getCircuitPackName()).thenReturn("2/0");
204 when(parentCp.getCpSlotName()).thenReturn("Slot1");
205 when(cp3.getCircuitPackName()).thenReturn("2/0 OCS");
206 when(cp3.getVendor()).thenReturn("VendorA");
207 when(cp3.getModel()).thenReturn("Model1678");
208 when(cp3.getSerialId()).thenReturn("dswsads7sgh6");
209 when(cp3.getClei()).thenReturn("1ew62d68785");
210 when(cp3.getHardwareVersion()).thenReturn("0.1");
211 when(cp3.getType()).thenReturn("OCS Plug");
212 when(cp3.getProductCode()).thenReturn("osooooo");
213 when(cp3.getCircuitPackMode()).thenReturn("inServiceMode");
214 when(cp3.getParentCircuitPack()).thenReturn(parentCp);
216 Map<CircuitPacksKey, CircuitPacks> cpList = new HashMap<>();
217 cpList.put(cp.key(), cp);
218 cpList.put(cp1.key(), cp1);
219 cpList.put(cp2.key(), cp2);
220 cpList.put(cp3.key(), cp3);
221 when(device.getCircuitPacks()).thenReturn(cpList);
223 // Reading Interface Data
224 when(interfaces.getName()).thenReturn("1GE-interface-1");
225 when(interfaces.getDescription()).thenReturn("Ethernet Interface");
226 when(interfaces.getSupportingCircuitPackName()).thenReturn("1/0 EThernet");
228 Map<InterfaceKey, Interface> interfacesList = new HashMap<>();
229 interfacesList.put(interfaces.key(), interfaces);
230 when(device.getInterface()).thenReturn(interfacesList);
232 // Reading Xponder Data
233 when(xpdr.getXpdrNumber()).thenReturn(Uint16.valueOf(1));
234 when(xpdr.getXpdrType()).thenReturn(XpdrNodeTypes.Mpdr);
235 when(xpdr.getLifecycleState()).thenReturn(LifecycleState.Deployed);
237 Map<XponderKey, Xponder> xpnderList = new HashMap<>();
238 xpnderList.put(xpdr.key(), xpdr);
239 when(device.getXponder()).thenReturn(xpnderList);
241 // Read initial Alarm data
242 final Class<ActiveAlarmList> classAlarm = ActiveAlarmList.class;
243 InstanceIdentifier<ActiveAlarmList> alarmDataIid = InstanceIdentifier.builder(classAlarm).build();
244 when(accessor.getTransactionUtils().readData(accessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
245 alarmDataIid)).thenReturn(alarmList);
246 when(activeAlarms.getId()).thenReturn("Alarm1");
247 when(activeAlarms.getCircuitId()).thenReturn("1/0");
248 when(activeAlarms.getRaiseTime()).thenReturn(new DateAndTime("2017-10-22T15:23:43Z"));
249 when(activeAlarms.getSeverity()).thenReturn(Severity.Critical);
250 when(activeAlarms.getProbableCause())
251 .thenReturn(new ProbableCauseBuilder().setCause(ProbableCauseEnum.AutomaticLaserShutdown).build());
252 when(activeAlarms.getAdditionalDetail()).thenReturn("LaserShutdown");
253 when(activeAlarms.getResource()).thenReturn(new ResourceBuilder()
254 .setDevice(new DeviceBuilder().setNodeId(NodeIdType.getDefaultInstance("zNhe2i5")).build()).build());
256 Map<ActiveAlarmsKey, ActiveAlarms> activeAlarmlist = new HashMap<>();
257 activeAlarmlist.put(activeAlarms.key(), activeAlarms);
258 when(alarmList.getActiveAlarms()).thenReturn(activeAlarmlist);
261 final Class<HistoricalPmList> pmDataClass = HistoricalPmList.class;
262 InstanceIdentifier<HistoricalPmList> pmDataIid = InstanceIdentifier.builder(pmDataClass).build();
263 when(accessor.getTransactionUtils().readData(accessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
264 pmDataIid)).thenReturn(pmDataList);
266 Measurement measurement = mock(Measurement.class);
267 PmDataType pmDataType = mock(PmDataType.class);
268 when(pmDataType.getDecimal64()).thenReturn(Decimal64.valueOf(1,2425425));
269 when(measurement.getBinNumber()).thenReturn(Uint16.valueOf(1452));
270 when(measurement.getCompletionTime()).thenReturn(new DateAndTime("2018-10-22T15:23:43Z"));
271 when(measurement.getGranularity()).thenReturn(PmGranularity._24Hour);
272 when(measurement.getPmParameterUnit()).thenReturn("6824545199534863756");
273 when(measurement.getPmParameterValue()).thenReturn(pmDataType);
274 when(measurement.getValidity()).thenReturn(Validity.Partial);
277 Map<MeasurementKey, Measurement> measurementList = new HashMap<>();
278 measurementList.put(measurement.key(), measurement);
279 when(historicalPm.getMeasurement()).thenReturn(measurementList);
280 when(historicalPm.getType()).thenReturn(PmNamesEnum.ErroredSeconds);
281 when(historicalPm.getExtension()).thenReturn("OpticalPowerOutput");
283 Map<HistoricalPmKey, HistoricalPm> historicalPmList = new HashMap<>();
284 historicalPmList.put(historicalPm.key(), historicalPm);
285 HistoricalPmEntry histPmEntry = mock(HistoricalPmEntry.class);
286 when(histPmEntry.getHistoricalPm()).thenReturn(historicalPmList);
287 when(histPmEntry.getPmResourceType()).thenReturn(ResourceTypeEnum.CircuitPack);
289 Map<HistoricalPmEntryKey, HistoricalPmEntry> histPmList = new HashMap<>();
290 histPmList.put(histPmEntry.key(), histPmEntry);
291 when(pmDataList.getHistoricalPmEntry()).thenReturn(histPmList);
299 OpenroadmNetworkElement optionalNe = new OpenroadmNetworkElement(accessor, serviceProvider);
300 optionalNe.initialReadFromNetworkElement();
301 verify(dataprovider).writeInventory(accessor.getNodeId().getValue(),
302 Arrays.asList(inventoryData.getInventoryData(Uint32.valueOf(0)),
303 inventoryData.getShelvesInventory(shelf, Uint32.valueOf(1)),
304 inventoryData.getXponderInventory(xpdr, Uint32.valueOf(1)),
305 inventoryData.getCircuitPackInventory(cp3, Uint32.valueOf(2))));