2 * Copyright © 2018 Orange, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.transportpce.olm.service;
11 import org.junit.Assert;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.mockito.InjectMocks;
15 import org.mockito.Mockito;
16 import org.mockito.MockitoAnnotations;
17 import org.opendaylight.controller.md.sal.binding.api.MountPoint;
18 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
19 import org.opendaylight.transportpce.common.NetworkUtils;
20 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
21 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl;
22 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl121;
23 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl221;
24 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
25 import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
26 import org.opendaylight.transportpce.common.mapping.MappingUtils;
27 import org.opendaylight.transportpce.common.mapping.MappingUtilsImpl;
28 import org.opendaylight.transportpce.common.mapping.PortMapping;
29 import org.opendaylight.transportpce.common.mapping.PortMappingImpl;
30 import org.opendaylight.transportpce.common.mapping.PortMappingVersion121;
31 import org.opendaylight.transportpce.common.mapping.PortMappingVersion221;
32 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
33 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
34 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl121;
35 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl221;
36 import org.opendaylight.transportpce.olm.power.PowerMgmt;
37 import org.opendaylight.transportpce.olm.stub.MountPointServiceStub;
38 import org.opendaylight.transportpce.olm.stub.MountPointStub;
39 import org.opendaylight.transportpce.olm.util.OlmPowerServiceRpcImplUtil;
40 import org.opendaylight.transportpce.olm.util.TransactionUtils;
41 import org.opendaylight.transportpce.test.AbstractTest;
42 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.CalculateSpanlossBaseInput;
43 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.CalculateSpanlossBaseOutput;
44 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.CalculateSpanlossCurrentInput;
45 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.CalculateSpanlossCurrentOutput;
46 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.GetPmInput;
47 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.GetPmOutput;
48 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.GetPmOutputBuilder;
49 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerResetInput;
50 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerResetOutput;
51 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerSetupInput;
52 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerSetupOutput;
53 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerSetupOutputBuilder;
54 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerTurndownInput;
55 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerTurndownOutput;
56 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerTurndownOutputBuilder;
57 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608.Network;
58 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608.NetworkId;
59 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608.NetworkKey;
60 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.Network1;
61 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
62 import org.slf4j.Logger;
63 import org.slf4j.LoggerFactory;
65 public class OlmPowerServiceImplTest extends AbstractTest {
67 private static final Logger LOG = LoggerFactory.getLogger(OlmPowerServiceImplTest.class);
68 private MountPoint mountPoint;
69 private MountPointService mountPointService;
70 private DeviceTransactionManager deviceTransactionManager;
71 private CrossConnect crossConnect;
72 private OpenRoadmInterfaces openRoadmInterfaces;
73 private PortMapping portMapping;
74 private PowerMgmt powerMgmt;
75 private OlmPowerService olmPowerService;
76 private PowerMgmt powerMgmtMock;
78 private OlmPowerService olmPowerServiceMock;
79 private MappingUtils mappingUtils;
80 private OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121;
81 private OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl221;
82 private PortMappingVersion221 portMappingVersion22;
83 private PortMappingVersion121 portMappingVersion121;
84 private CrossConnectImpl121 crossConnectImpl121;
85 private CrossConnectImpl221 crossConnectImpl221;
91 this.mountPoint = new MountPointStub(this.getDataBroker());
92 this.mountPointService = new MountPointServiceStub(mountPoint);
93 this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
94 this.crossConnectImpl121 = new CrossConnectImpl121(this.deviceTransactionManager);
95 this.crossConnectImpl221 = new CrossConnectImpl221(this.deviceTransactionManager);
96 this.crossConnect = new CrossConnectImpl(this.deviceTransactionManager, this.mappingUtils,
97 this.crossConnectImpl121, this.crossConnectImpl221);
98 this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(this.deviceTransactionManager);
99 this.openRoadmInterfacesImpl221 = new OpenRoadmInterfacesImpl221(this.deviceTransactionManager);
100 this.mappingUtils = new MappingUtilsImpl(getDataBroker());
101 this.openRoadmInterfaces = new OpenRoadmInterfacesImpl(deviceTransactionManager, mappingUtils,
102 openRoadmInterfacesImpl121, openRoadmInterfacesImpl221);
103 this.portMappingVersion22 =
104 new PortMappingVersion221(getDataBroker(), this.deviceTransactionManager, this.openRoadmInterfaces);
105 this.portMappingVersion121 =
106 new PortMappingVersion121(getDataBroker(), this.deviceTransactionManager, this.openRoadmInterfaces);
107 this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion22, this.mappingUtils,
108 this.portMappingVersion121);
109 this.powerMgmt = new PowerMgmt(this.getDataBroker(), this.openRoadmInterfaces, this.crossConnect,
110 this.deviceTransactionManager);
111 this.olmPowerService = new OlmPowerServiceImpl(this.getDataBroker(), this.powerMgmt,
112 this.deviceTransactionManager, this.portMapping);
113 this.powerMgmtMock = Mockito.mock(PowerMgmt.class);
114 this.olmPowerServiceMock = new OlmPowerServiceImpl(this.getDataBroker(), this.powerMgmtMock,
115 this.deviceTransactionManager, this.portMapping);
116 MockitoAnnotations.initMocks(this);
120 public void dummyTest() {
121 OlmPowerServiceImpl olmPowerServiceImpl = (OlmPowerServiceImpl) this.olmPowerService;
122 olmPowerServiceImpl.init();
123 olmPowerServiceImpl.close();
128 public void testGetPm() {
129 GetPmInput input = OlmPowerServiceRpcImplUtil.getGetPmInput();
130 GetPmOutput output = this.olmPowerService.getPm(input);
131 Assert.assertEquals(new GetPmOutputBuilder().build(), output);
132 Assert.assertEquals(null, output.getResourceId());
136 public void testServicePowerSetupSuccess() {
137 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
138 Mockito.when(this.powerMgmtMock.setPower(Mockito.any())).thenReturn(true);
139 ServicePowerSetupOutput output = this.olmPowerServiceMock.servicePowerSetup(input);
140 Assert.assertEquals(new ServicePowerSetupOutputBuilder().setResult("Success").build(), output);
141 Assert.assertEquals("Success", output.getResult());
145 public void testServicePowerSetupFailed() {
146 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
147 Mockito.when(this.powerMgmtMock.setPower(Mockito.any())).thenReturn(false);
148 ServicePowerSetupOutput output = this.olmPowerServiceMock.servicePowerSetup(input);
149 Assert.assertEquals("Failed", output.getResult());
153 public void testServicePowerTurnDownSuccess() {
154 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
155 Mockito.when(this.powerMgmtMock.powerTurnDown(Mockito.any())).thenReturn(true);
156 ServicePowerTurndownOutput output = this.olmPowerServiceMock.servicePowerTurndown(input);
157 Assert.assertEquals(new ServicePowerTurndownOutputBuilder().setResult("Success").build(), output);
158 Assert.assertEquals("Success", output.getResult());
162 public void testServicePowerTurnDownFailed() {
163 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
164 Mockito.when(this.powerMgmtMock.powerTurnDown(Mockito.any())).thenReturn(false);
165 ServicePowerTurndownOutput output = this.olmPowerServiceMock.servicePowerTurndown(input);
166 Assert.assertEquals(new ServicePowerTurndownOutputBuilder().setResult("Failed").build(), output);
167 Assert.assertEquals("Failed", output.getResult());
171 public void testCalculateSpanlossBase() {
172 CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput();
173 CalculateSpanlossBaseOutput output = this.olmPowerService.calculateSpanlossBase(input);
174 Assert.assertEquals("Failed", output.getResult());
179 public void testCalculateSpanlossBase2() {
180 NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
181 InstanceIdentifier<Network1> networkIID = InstanceIdentifier.builder(Network.class, overlayTopologyKey)
182 .augmentation(Network1.class)
184 Network1 network = TransactionUtils.getNetwork();
185 TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, network);
188 } catch (InterruptedException e) {
189 LOG.error("Write transaction failed !",e);
191 CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput();
192 CalculateSpanlossBaseOutput output = this.olmPowerService.calculateSpanlossBase(input);
193 Assert.assertEquals("Failed", output.getResult());
198 public void testCalculateSpanlossBase3() {
199 NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
200 InstanceIdentifier<Network1> networkIID = InstanceIdentifier.builder(Network.class, overlayTopologyKey)
201 .augmentation(Network1.class)
203 Network1 network = TransactionUtils.getNetwork();
204 TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, network);
207 } catch (InterruptedException e) {
208 LOG.error("Write transaction failed !",e);
210 CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput2();
211 CalculateSpanlossBaseOutput output = this.olmPowerService.calculateSpanlossBase(input);
212 Assert.assertEquals("Failed", output.getResult());
218 public void testCalculateSpanlossBase4() {
219 NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
220 InstanceIdentifier<Network1> networkIID = InstanceIdentifier.builder(Network.class, overlayTopologyKey)
221 .augmentation(Network1.class)
223 Network1 network = TransactionUtils.getEmptyNetwork();
224 TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, network);
227 } catch (InterruptedException e) {
228 LOG.error("Write transaction failed !",e);
230 CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput2();
231 CalculateSpanlossBaseOutput output = this.olmPowerService.calculateSpanlossBase(input);
232 Assert.assertEquals("Failed", output.getResult());
237 public void testCalculateSpanlossBase5() {
238 NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
239 InstanceIdentifier<Network1> networkIID = InstanceIdentifier.builder(Network.class, overlayTopologyKey)
240 .augmentation(Network1.class)
242 Network1 network = TransactionUtils.getNullNetwork();
243 TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, network);
246 } catch (InterruptedException e) {
247 LOG.error("Write transaction failed !",e);
249 CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput2();
250 CalculateSpanlossBaseOutput output = this.olmPowerService.calculateSpanlossBase(input);
251 Assert.assertEquals("Failed", output.getResult());
256 // public void testCalculateSpanlossBase4() throws InterruptedException {
257 // NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
258 // InstanceIdentifier<Network1> networkIID = InstanceIdentifier.builder(Network.class, overlayTopologyKey)
259 // .augmentation(Network1.class)
261 // Network1 network = TransactionUtils.getNetwork2();
262 // TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, network);
264 // Thread.sleep(500);
266 // List<NodeId> nodes = TransactionUtils.getNodes();
268 // SupportingNode sn;
270 // List<SupportingNode> snl;
271 // NodeId n5 = new NodeId("node 5");
272 // KeyedInstanceIdentifier<Node, NodeKey> mappedNodeII2 =
273 // InstanceIdentifiers.UNDERLAY_NETWORK_II.child(Node.class, new NodeKey(n5));
275 // sn = new SupportingNodeBuilder().setNetworkRef(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID))
276 // .setNodeRef(n5).build();
277 // snl = new ArrayList<>();
279 // n = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608
280 // .network.NodeBuilder().setNodeId(n5).build();
281 // TransactionUtils.writeTransaction(this.getDataBroker(), mappedNodeII2, n);
282 // Thread.sleep(500);
284 // for(int i=0; i < nodes.size(); i++) {
285 // KeyedInstanceIdentifier<Node, NodeKey> mappedNodeII =
286 // InstanceIdentifiers.OVERLAY_NETWORK_II.child(Node.class, new NodeKey(nodes.get(i)));
288 // sn = new SupportingNodeBuilder().setNetworkRef(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID))
289 // .setNodeRef(nodes.get(i-1)).build();
291 // sn = new SupportingNodeBuilder().setNodeRef(n5).build();
293 // snl = new ArrayList<>();
295 // n = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608
296 // .network.NodeBuilder().setNodeId(nodes.get(i)).setSupportingNode(snl).build();
297 // TransactionUtils.writeTransaction(this.getDataBroker(), mappedNodeII, n);
298 // Thread.sleep(500);
301 // Thread.sleep(1000);
303 // CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput2();
304 // CalculateSpanlossBaseOutput output = this.olmPowerService.calculateSpanlossBase(input);
305 // Assert.assertEquals("Failed", output.getResult());
310 public void testCalculateSpanlossCurrent1() {
311 CalculateSpanlossCurrentInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossCurrentInput();
312 CalculateSpanlossCurrentOutput output = this.olmPowerService.calculateSpanlossCurrent(input);
313 Assert.assertEquals(null, output);
317 public void testCalculateSpanlossCurrent2() {
318 NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
319 InstanceIdentifier<Network1> networkIID = InstanceIdentifier.builder(Network.class, overlayTopologyKey)
320 .augmentation(Network1.class)
322 Network1 network = TransactionUtils.getNetwork();
323 TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, network);
326 } catch (InterruptedException e) {
327 LOG.error("Write transaction failed !",e);
329 CalculateSpanlossCurrentInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossCurrentInput();
330 CalculateSpanlossCurrentOutput output = this.olmPowerService.calculateSpanlossCurrent(input);
331 Assert.assertEquals(null, output);
335 public void testServicePowerReset() {
336 ServicePowerResetInput input = OlmPowerServiceRpcImplUtil.getServicePowerResetInput();
337 ServicePowerResetOutput output = this.olmPowerService.servicePowerReset(input);
338 Assert.assertEquals(null, output);