2 * Copyright © 2020 Orange Labs, 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
8 package org.opendaylight.transportpce.pce.networkanalyzer;
10 import static org.mockito.ArgumentMatchers.anyString;
11 import static org.mockito.Mockito.when;
13 import java.util.concurrent.ExecutionException;
14 import org.junit.Assert;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.mockito.Mock;
19 import org.mockito.junit.MockitoJUnitRunner;
20 import org.opendaylight.transportpce.common.StringConstants;
21 import org.opendaylight.transportpce.common.mapping.PortMapping;
22 import org.opendaylight.transportpce.common.network.NetworkTransactionImpl;
23 import org.opendaylight.transportpce.common.network.RequestProcessor;
24 import org.opendaylight.transportpce.pce.constraints.PceConstraintsCalc;
25 import org.opendaylight.transportpce.pce.utils.PceTestData;
26 import org.opendaylight.transportpce.pce.utils.PceTestUtils;
27 import org.opendaylight.transportpce.pce.utils.TransactionUtils;
28 import org.opendaylight.transportpce.test.AbstractTest;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestInput;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mapping.Mapping;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mapping.MappingBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.network.Nodes;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.network.NodesBuilder;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.network.NodesKey;
35 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.network.nodes.NodeInfo;
36 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.network.nodes.NodeInfoBuilder;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.NodeTypes;
39 @RunWith(MockitoJUnitRunner.StrictStubs.class)
40 public class PceCalculationTest extends AbstractTest {
42 private PceCalculation pceCalculation;
43 private PceConstraintsCalc pceConstraintsCalc;
44 private PceResult pceResult = new PceResult();
45 private Mapping mapping;
48 private PortMapping portMapping;
52 public void setUp() throws ExecutionException, InterruptedException {
53 pceResult.setRC("200");
54 PceTestUtils.writeNetworkIntoDataStore(getDataBroker(), getDataStoreContextUtil(),
55 TransactionUtils.getNetworkForSpanLoss());
56 pceConstraintsCalc = new PceConstraintsCalc(PceTestData.getPCERequest(),
57 new NetworkTransactionImpl(new RequestProcessor(getDataBroker())));
58 mapping = new MappingBuilder().setLogicalConnectionPoint("logicalConnectionPoint").setPortQual("xpdr-client")
60 NodeInfo info = new NodeInfoBuilder().setNodeType(NodeTypes.Xpdr).build();
61 Nodes node = new NodesBuilder().withKey(new NodesKey("node")).setNodeId("node").setNodeInfo(info).build();
62 when(portMapping.getMapping(anyString(), anyString())).thenReturn(mapping);
63 when(portMapping.getNode(anyString())).thenReturn(node);
67 public void testPceCalculationValues() {
68 pceCalculation = new PceCalculation(
69 PceTestData.getPCERequest(),
70 new NetworkTransactionImpl(new RequestProcessor(getDataBroker())),
71 pceConstraintsCalc.getPceHardConstraints(),
72 pceConstraintsCalc.getPceSoftConstraints(),
75 pceCalculation.retrievePceNetwork();
76 Assert.assertEquals(StringConstants.SERVICE_TYPE_100GE_T, pceCalculation.getServiceType());
77 Assert.assertNotNull(pceCalculation.getReturnStructure());
79 Assert.assertNull(pceCalculation.getaendPceNode());
80 Assert.assertNull(pceCalculation.getzendPceNode());
84 public void testPceCalculationValues2() {
85 pceCalculation = new PceCalculation(
86 PceTestData.getPathComputationRequestInputWithCoRoutingOrGeneral(),
87 new NetworkTransactionImpl(new RequestProcessor(getDataBroker())),
88 pceConstraintsCalc.getPceHardConstraints(),
89 pceConstraintsCalc.getPceSoftConstraints(),
90 pceResult, portMapping);
91 pceCalculation.retrievePceNetwork();
92 Assert.assertEquals(StringConstants.SERVICE_TYPE_100GE_T, pceCalculation.getServiceType());
93 Assert.assertNotNull(pceCalculation.getReturnStructure());
95 Assert.assertNull(pceCalculation.getaendPceNode());
96 Assert.assertNull(pceCalculation.getzendPceNode());
100 public void testPceCalculationValues42() {
101 PathComputationRequestInput input = PceTestData.getPathComputationRequestInputWithCoRoutingOrGeneral2();
102 pceConstraintsCalc = new PceConstraintsCalc(input,
103 new NetworkTransactionImpl(new RequestProcessor(getDataBroker())));
104 pceCalculation = new PceCalculation(
105 PceTestData.getPCE_test3_request_54(),
106 new NetworkTransactionImpl(new RequestProcessor(getDataBroker())),
107 pceConstraintsCalc.getPceHardConstraints(),
108 pceConstraintsCalc.getPceSoftConstraints(),
109 pceResult, portMapping);
110 pceCalculation.retrievePceNetwork();
111 Assert.assertEquals(StringConstants.SERVICE_TYPE_100GE_T, pceCalculation.getServiceType());
112 Assert.assertNotNull(pceCalculation.getReturnStructure());
114 Assert.assertNull(pceCalculation.getaendPceNode());
115 Assert.assertNull(pceCalculation.getzendPceNode());