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.rev180226.NetworkId;
58 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.Networks;
59 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network;
60 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.NetworkKey;
61 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Network1;
62 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
63 import org.slf4j.Logger;
64 import org.slf4j.LoggerFactory;
66 public class OlmPowerServiceImplTest extends AbstractTest {
68 private static final Logger LOG = LoggerFactory.getLogger(OlmPowerServiceImplTest.class);
69 private MountPoint mountPoint;
70 private MountPointService mountPointService;
71 private DeviceTransactionManager deviceTransactionManager;
72 private CrossConnect crossConnect;
73 private OpenRoadmInterfaces openRoadmInterfaces;
74 private PortMapping portMapping;
75 private PowerMgmt powerMgmt;
76 private OlmPowerService olmPowerService;
77 private PowerMgmt powerMgmtMock;
79 private OlmPowerService olmPowerServiceMock;
80 private MappingUtils mappingUtils;
81 private OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121;
82 private OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl221;
83 private PortMappingVersion221 portMappingVersion22;
84 private PortMappingVersion121 portMappingVersion121;
85 private CrossConnectImpl121 crossConnectImpl121;
86 private CrossConnectImpl221 crossConnectImpl221;
92 this.mountPoint = new MountPointStub(this.getDataBroker());
93 this.mountPointService = new MountPointServiceStub(mountPoint);
94 this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
95 this.crossConnectImpl121 = new CrossConnectImpl121(this.deviceTransactionManager);
96 this.crossConnectImpl221 = new CrossConnectImpl221(this.deviceTransactionManager);
97 this.crossConnect = new CrossConnectImpl(this.deviceTransactionManager, this.mappingUtils,
98 this.crossConnectImpl121, this.crossConnectImpl221);
99 this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(this.deviceTransactionManager);
100 this.openRoadmInterfacesImpl221 = new OpenRoadmInterfacesImpl221(this.deviceTransactionManager);
101 this.mappingUtils = new MappingUtilsImpl(getDataBroker());
102 this.openRoadmInterfaces = new OpenRoadmInterfacesImpl(deviceTransactionManager, mappingUtils,
103 openRoadmInterfacesImpl121, openRoadmInterfacesImpl221);
104 this.portMappingVersion22 =
105 new PortMappingVersion221(getDataBroker(), this.deviceTransactionManager, this.openRoadmInterfaces);
106 this.portMappingVersion121 =
107 new PortMappingVersion121(getDataBroker(), this.deviceTransactionManager, this.openRoadmInterfaces);
108 this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion22, this.mappingUtils,
109 this.portMappingVersion121);
110 this.powerMgmt = new PowerMgmt(this.getDataBroker(), this.openRoadmInterfaces, this.crossConnect,
111 this.deviceTransactionManager);
112 this.olmPowerService = new OlmPowerServiceImpl(this.getDataBroker(), this.powerMgmt,
113 this.deviceTransactionManager, this.portMapping);
114 this.powerMgmtMock = Mockito.mock(PowerMgmt.class);
115 this.olmPowerServiceMock = new OlmPowerServiceImpl(this.getDataBroker(), this.powerMgmtMock,
116 this.deviceTransactionManager, this.portMapping);
117 MockitoAnnotations.initMocks(this);
121 public void dummyTest() {
122 OlmPowerServiceImpl olmPowerServiceImpl = (OlmPowerServiceImpl) this.olmPowerService;
123 olmPowerServiceImpl.init();
124 olmPowerServiceImpl.close();
129 public void testGetPm() {
130 GetPmInput input = OlmPowerServiceRpcImplUtil.getGetPmInput();
131 GetPmOutput output = this.olmPowerService.getPm(input);
132 Assert.assertEquals(new GetPmOutputBuilder().build(), output);
133 Assert.assertEquals(null, output.getResourceId());
137 public void testServicePowerSetupSuccess() {
138 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
139 Mockito.when(this.powerMgmtMock.setPower(Mockito.any())).thenReturn(true);
140 ServicePowerSetupOutput output = this.olmPowerServiceMock.servicePowerSetup(input);
141 Assert.assertEquals(new ServicePowerSetupOutputBuilder().setResult("Success").build(), output);
142 Assert.assertEquals("Success", output.getResult());
146 public void testServicePowerSetupFailed() {
147 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
148 Mockito.when(this.powerMgmtMock.setPower(Mockito.any())).thenReturn(false);
149 ServicePowerSetupOutput output = this.olmPowerServiceMock.servicePowerSetup(input);
150 Assert.assertEquals("Failed", output.getResult());
154 public void testServicePowerTurnDownSuccess() {
155 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
156 Mockito.when(this.powerMgmtMock.powerTurnDown(Mockito.any())).thenReturn(true);
157 ServicePowerTurndownOutput output = this.olmPowerServiceMock.servicePowerTurndown(input);
158 Assert.assertEquals(new ServicePowerTurndownOutputBuilder().setResult("Success").build(), output);
159 Assert.assertEquals("Success", output.getResult());
163 public void testServicePowerTurnDownFailed() {
164 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
165 Mockito.when(this.powerMgmtMock.powerTurnDown(Mockito.any())).thenReturn(false);
166 ServicePowerTurndownOutput output = this.olmPowerServiceMock.servicePowerTurndown(input);
167 Assert.assertEquals(new ServicePowerTurndownOutputBuilder().setResult("Failed").build(), output);
168 Assert.assertEquals("Failed", output.getResult());
172 public void testCalculateSpanlossBase() {
173 CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput();
174 CalculateSpanlossBaseOutput output = this.olmPowerService.calculateSpanlossBase(input);
175 Assert.assertEquals("Failed", output.getResult());
180 public void testCalculateSpanlossBase2() {
181 NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
182 InstanceIdentifier<Network1> networkIID = InstanceIdentifier.builder(Networks.class)
183 .child(Network.class, overlayTopologyKey)
184 .augmentation(Network1.class)
186 Network1 network = TransactionUtils.getNetwork();
187 TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, network);
190 } catch (InterruptedException e) {
191 LOG.error("Write transaction failed !",e);
193 CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput();
194 CalculateSpanlossBaseOutput output = this.olmPowerService.calculateSpanlossBase(input);
195 Assert.assertEquals("Failed", output.getResult());
200 public void testCalculateSpanlossBase3() {
201 NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
202 InstanceIdentifier<Network1> networkIID = InstanceIdentifier.builder(Networks.class)
203 .child(Network.class, overlayTopologyKey)
204 .augmentation(Network1.class)
206 Network1 network = TransactionUtils.getNetwork();
207 TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, network);
210 } catch (InterruptedException e) {
211 LOG.error("Write transaction failed !",e);
213 CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput2();
214 CalculateSpanlossBaseOutput output = this.olmPowerService.calculateSpanlossBase(input);
215 Assert.assertEquals("Failed", output.getResult());
221 public void testCalculateSpanlossBase4() {
222 NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
223 InstanceIdentifier<Network1> networkIID = InstanceIdentifier.builder(Networks.class)
224 .child(Network.class, overlayTopologyKey)
225 .augmentation(Network1.class)
227 Network1 network = TransactionUtils.getEmptyNetwork();
228 TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, network);
231 } catch (InterruptedException e) {
232 LOG.error("Write transaction failed !",e);
234 CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput2();
235 CalculateSpanlossBaseOutput output = this.olmPowerService.calculateSpanlossBase(input);
236 Assert.assertEquals("Failed", output.getResult());
241 public void testCalculateSpanlossBase5() {
242 NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
243 InstanceIdentifier<Network1> networkIID = InstanceIdentifier.builder(Networks.class)
244 .child(Network.class, overlayTopologyKey)
245 .augmentation(Network1.class)
247 Network1 network = TransactionUtils.getNullNetwork();
248 TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, network);
251 } catch (InterruptedException e) {
252 LOG.error("Write transaction failed !",e);
254 CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput2();
255 CalculateSpanlossBaseOutput output = this.olmPowerService.calculateSpanlossBase(input);
256 Assert.assertEquals("Failed", output.getResult());
261 // public void testCalculateSpanlossBase4() throws InterruptedException {
262 // NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
263 // InstanceIdentifier<Network1> networkIID = InstanceIdentifier.builder(Network.class, overlayTopologyKey)
264 // .augmentation(Network1.class)
266 // Network1 network = TransactionUtils.getNetwork2();
267 // TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, network);
269 // Thread.sleep(500);
271 // List<NodeId> nodes = TransactionUtils.getNodes();
273 // SupportingNode sn;
275 // List<SupportingNode> snl;
276 // NodeId n5 = new NodeId("node 5");
277 // KeyedInstanceIdentifier<Node, NodeKey> mappedNodeII2 =
278 // InstanceIdentifiers.UNDERLAY_NETWORK_II.child(Node.class, new NodeKey(n5));
280 // sn = new SupportingNodeBuilder().setNetworkRef(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID))
281 // .setNodeRef(n5).build();
282 // snl = new ArrayList<>();
284 // n = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608
285 // .network.NodeBuilder().setNodeId(n5).build();
286 // TransactionUtils.writeTransaction(this.getDataBroker(), mappedNodeII2, n);
287 // Thread.sleep(500);
289 // for(int i=0; i < nodes.size(); i++) {
290 // KeyedInstanceIdentifier<Node, NodeKey> mappedNodeII =
291 // InstanceIdentifiers.OVERLAY_NETWORK_II.child(Node.class, new NodeKey(nodes.get(i)));
293 // sn = new SupportingNodeBuilder().setNetworkRef(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID))
294 // .setNodeRef(nodes.get(i-1)).build();
296 // sn = new SupportingNodeBuilder().setNodeRef(n5).build();
298 // snl = new ArrayList<>();
300 // n = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608
301 // .network.NodeBuilder().setNodeId(nodes.get(i)).setSupportingNode(snl).build();
302 // TransactionUtils.writeTransaction(this.getDataBroker(), mappedNodeII, n);
303 // Thread.sleep(500);
306 // Thread.sleep(1000);
308 // CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput2();
309 // CalculateSpanlossBaseOutput output = this.olmPowerService.calculateSpanlossBase(input);
310 // Assert.assertEquals("Failed", output.getResult());
315 public void testCalculateSpanlossCurrent1() {
316 CalculateSpanlossCurrentInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossCurrentInput();
317 CalculateSpanlossCurrentOutput output = this.olmPowerService.calculateSpanlossCurrent(input);
318 Assert.assertEquals(null, output);
322 public void testCalculateSpanlossCurrent2() {
323 NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
324 InstanceIdentifier<Network1> networkIID = InstanceIdentifier.builder(Networks.class)
325 .child(Network.class, overlayTopologyKey)
326 .augmentation(Network1.class)
328 Network1 network = TransactionUtils.getNetwork();
329 TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, network);
332 } catch (InterruptedException e) {
333 LOG.error("Write transaction failed !",e);
335 CalculateSpanlossCurrentInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossCurrentInput();
336 CalculateSpanlossCurrentOutput output = this.olmPowerService.calculateSpanlossCurrent(input);
337 Assert.assertEquals(null, output);
341 public void testServicePowerReset() {
342 ServicePowerResetInput input = OlmPowerServiceRpcImplUtil.getServicePowerResetInput();
343 ServicePowerResetOutput output = this.olmPowerService.servicePowerReset(input);
344 Assert.assertEquals(null, output);