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