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