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
8 package org.opendaylight.transportpce.servicehandler;
10 import com.google.common.util.concurrent.ListenableFuture;
11 import com.google.common.util.concurrent.ListeningExecutorService;
12 import com.google.common.util.concurrent.MoreExecutors;
13 import java.time.OffsetDateTime;
14 import java.time.ZoneOffset;
15 import java.time.format.DateTimeFormatter;
16 import java.util.Arrays;
17 import java.util.concurrent.CountDownLatch;
18 import java.util.concurrent.ExecutionException;
19 import java.util.concurrent.Executors;
20 import org.junit.After;
21 import org.junit.Assert;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.opendaylight.transportpce.common.ResponseCodes;
25 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
26 import org.opendaylight.transportpce.test.AbstractTest;
27 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestOutput;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestOutputBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.ConnectionType;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommon;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommonBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.sdnc.request.header.SdncRequestHeaderBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev190531.RpcStatus;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.CoRoutingBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.routing.constraints.HardConstraintsBuilder;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.routing.constraints.SoftConstraintsBuilder;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInput;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInputBuilder;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateOutput;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteInput;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteInputBuilder;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteOutput;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckInput;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckInputBuilder;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckOutput;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceReconfigureInput;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceReconfigureInputBuilder;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRerouteInput;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRerouteInputBuilder;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRestorationInput;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRestorationInputBuilder;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRestorationOutput;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateInput;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateInputBuilder;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateOutput;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.Services;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.ServicesBuilder;
58 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.path.description.AToZDirectionBuilder;
59 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.path.description.ZToADirectionBuilder;
60 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.ResponseParameters;
61 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.ResponseParametersBuilder;
62 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.response.parameters.PathDescriptionBuilder;
63 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths;
64 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsBuilder;
65 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
66 import org.opendaylight.yangtools.yang.common.RpcResult;
67 import org.opendaylight.yangtools.yang.common.Uint32;
69 public class ModelMappingUtilsTest extends AbstractTest {
71 private ListeningExecutorService executorService;
72 private CountDownLatch endSignal;
73 private static final int NUM_THREADS = 5;
74 private boolean callbackRan;
78 executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS));
79 endSignal = new CountDownLatch(1);
84 public void tearDown() {
85 executorService.shutdownNow();
88 private ServiceReconfigureInput buildServiceConfigurationInput() {
89 DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx");
90 OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC);
91 OffsetDateTime offsetDateTime2 = offsetDateTime.plusDays(10);
92 return new ServiceReconfigureInputBuilder().setNewServiceName("service 1")
93 .setServiceName("service 1").setCommonId("common id").setConnectionType(ConnectionType.Service)
94 .setCustomer("customer").setCustomerContact("customer contact").setDueDate(new DateAndTime(
95 dtf.format(offsetDateTime)))
96 .setEndDate(new DateAndTime(dtf.format(offsetDateTime2)))
97 .setNcCode("nc node").setNciCode("nci node").setSecondaryNciCode("secondry").setOperatorContact("operator")
98 .setServiceAEnd(ServiceDataUtils.getServiceAEndBuildReconfigure().build())
99 .setServiceZEnd(ServiceDataUtils.getServiceZEndBuildReconfigure().build())
100 .setHardConstraints(new HardConstraintsBuilder()
101 .setCoRoutingOrGeneral(new CoRoutingBuilder()
102 .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing
103 .constrains.rev190329.constraints.co.routing.or.general.co.routing
104 .CoRoutingBuilder().setExistingService(
105 Arrays.asList("Some existing-service")).build())
107 .setCustomerCode(Arrays.asList("Some customer-code"))
109 .setSoftConstraints(new SoftConstraintsBuilder()
110 .setCoRoutingOrGeneral(new CoRoutingBuilder()
111 .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing
112 .constrains.rev190329.constraints.co.routing.or.general.co.routing
113 .CoRoutingBuilder().setExistingService(
114 Arrays.asList("Some existing-service")).build())
116 .setCustomerCode(Arrays.asList("Some customer-code"))
121 private PathComputationRequestOutput buildPathComputationOutput() {
122 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
123 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
124 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
125 ResponseParameters responseParameters = new ResponseParametersBuilder()
126 .setPathDescription(new PathDescriptionBuilder()
127 .setAToZDirection(new AToZDirectionBuilder().setAToZWavelengthNumber(Uint32.valueOf(1))
128 .setRate(Uint32.valueOf(1)).build())
129 .setZToADirection(new ZToADirectionBuilder().setZToAWavelengthNumber(Uint32.valueOf(1))
130 .setRate(Uint32.valueOf(1)).build()).build())
132 return new PathComputationRequestOutputBuilder().setConfigurationResponseCommon(configurationResponseCommon)
133 .setResponseParameters(responseParameters).build();
137 public void mappingServicesNullServiceCreateInput() {
138 Services services = ModelMappingUtils.mappingServices(null, null);
139 Assert.assertEquals(new ServicesBuilder().build(), services);
143 public void mappingServiceNotNullServiceReconfigureInput() {
144 Services services = ModelMappingUtils.mappingServices(null, buildServiceConfigurationInput());
145 Assert.assertEquals("service 1", services.getServiceName());
149 public void mappingServiceValid() {
150 Services services = ModelMappingUtils.mappingServices(ServiceDataUtils.buildServiceCreateInput(),
152 Assert.assertEquals("service 1", services.getServiceName());
156 public void mappingServicesPathNullServiceCreateInput() {
157 ServicePaths services = ModelMappingUtils.mappingServicePaths(null, buildPathComputationOutput());
158 Assert.assertEquals(new ServicePathsBuilder().build(), services);
162 public void mappingServicePathWithServiceInputWithHardConstraints() {
163 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInputWithHardConstraints();
164 ServiceInput serviceInput = new ServiceInput(createInput);
165 ServicePaths services = ModelMappingUtils.mappingServicePaths(serviceInput, buildPathComputationOutput());
166 Assert.assertEquals(serviceInput.getServiceName(), services.getServicePathName());
167 Assert.assertNotNull(services.getHardConstraints());
171 public void mappingServicePathWithServiceInputWithSoftConstraints() {
172 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInputWithSoftConstraints();
173 ServiceInput serviceInput = new ServiceInput(createInput);
174 ServicePaths services = ModelMappingUtils.mappingServicePaths(serviceInput, buildPathComputationOutput());
175 Assert.assertEquals(serviceInput.getServiceName(), services.getServicePathName());
176 Assert.assertNotNull(services.getSoftConstraints());
180 public void createServiceDeleteInputWithServiceRerouteInput() {
181 ServiceRerouteInput serviceRerouteinput = new ServiceRerouteInputBuilder().setServiceName("reroute").build();
182 Services services = new ServicesBuilder()
183 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("123").build()).build();
184 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceDeleteInput
186 ModelMappingUtils.createServiceDeleteInput(serviceRerouteinput, services);
187 Assert.assertEquals("reroute", serviceDeleteInput.getServiceName());
188 Assert.assertEquals("123", serviceDeleteInput.getServiceHandlerHeader().getRequestId());
192 public void createServiceDeleteInputWithServiceReconfigureInput() {
193 ServiceReconfigureInput serviceReconfigureInput = new ServiceReconfigureInputBuilder()
194 .setServiceName("reconf").build();
195 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceDeleteInput
197 ModelMappingUtils.createServiceDeleteInput(serviceReconfigureInput);
198 Assert.assertEquals("reconf", serviceDeleteInput.getServiceName());
199 Assert.assertEquals("reconf-reconfigure", serviceDeleteInput.getServiceHandlerHeader().getRequestId());
203 public void createServiceDeleteInputWithServiceRestorationInput() {
204 Services services = new ServicesBuilder()
205 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("123").build()).build();
206 ServiceRestorationInput serviceRestorationInput =
207 new ServiceRestorationInputBuilder().setServiceName("rest").build();
208 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceDeleteInput
210 ModelMappingUtils.createServiceDeleteInput(serviceRestorationInput, services);
211 Assert.assertEquals("rest", serviceDeleteInput.getServiceName());
212 Assert.assertEquals("123", serviceDeleteInput.getServiceHandlerHeader().getRequestId());
216 public void createDeleteServiceReplyWithServiceDeleteInputWithSdncHeader()
217 throws ExecutionException, InterruptedException {
218 ServiceDeleteInput input = new ServiceDeleteInputBuilder()
219 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
220 ListenableFuture<RpcResult<ServiceDeleteOutput>> serviceDeleteOutputF =
221 ModelMappingUtils.createDeleteServiceReply(input, "ack", "message", "200");
222 serviceDeleteOutputF.addListener(new Runnable() {
226 endSignal.countDown();
231 RpcResult<ServiceDeleteOutput> serviceDeleteOutput = serviceDeleteOutputF.get();
232 Assert.assertEquals("200", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseCode());
234 "ack", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
236 "message", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
237 Assert.assertEquals("12", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getRequestId());
241 public void createDeleteServiceReplyWithServiceDeleteInputWithoutSdncHeader()
242 throws ExecutionException, InterruptedException {
243 ServiceDeleteInput input = new ServiceDeleteInputBuilder().build();
244 ListenableFuture<RpcResult<ServiceDeleteOutput>> serviceDeleteOutputF =
245 ModelMappingUtils.createDeleteServiceReply(input, "ack", "message", "200");
246 serviceDeleteOutputF.addListener(new Runnable() {
250 endSignal.countDown();
255 RpcResult<ServiceDeleteOutput> serviceDeleteOutput = serviceDeleteOutputF.get();
256 Assert.assertEquals("200", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseCode());
258 "ack", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
260 "message", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
261 Assert.assertNull(serviceDeleteOutput.getResult().getConfigurationResponseCommon().getRequestId());
265 public void createCreateServiceReplyWithServiceCreatInputWithSdncRequestHeader()
266 throws ExecutionException, InterruptedException {
267 ServiceCreateInput input =
268 new ServiceCreateInputBuilder()
269 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
270 ListenableFuture<RpcResult<ServiceCreateOutput>> serviceCreatOutputF =
271 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
272 serviceCreatOutputF.addListener(new Runnable() {
276 endSignal.countDown();
281 RpcResult<ServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
282 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
284 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
286 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
287 Assert.assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
291 public void createCreateServiceReplyWithServiceCreatInputWithoutSdncRequestHeader()
292 throws ExecutionException, InterruptedException {
293 ServiceCreateInput input = new ServiceCreateInputBuilder().build();
294 ListenableFuture<RpcResult<ServiceCreateOutput>> serviceCreatOutputF =
295 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
296 serviceCreatOutputF.addListener(new Runnable() {
300 endSignal.countDown();
305 RpcResult<ServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
306 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
308 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
310 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
311 Assert.assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
315 public void createCreateServiceReplyWithTempServiceCreatInputWithSdncRequestHeader()
316 throws ExecutionException, InterruptedException {
317 TempServiceCreateInput input =
318 new TempServiceCreateInputBuilder()
319 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
320 ListenableFuture<RpcResult<TempServiceCreateOutput>> serviceCreatOutputF =
321 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
322 serviceCreatOutputF.addListener(new Runnable() {
326 endSignal.countDown();
331 RpcResult<TempServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
332 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
334 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
336 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
337 Assert.assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
341 public void createCreateServiceReplyWithTempServiceCreatInputWithoutSdncRequestHeader()
342 throws ExecutionException, InterruptedException {
343 TempServiceCreateInput input = new TempServiceCreateInputBuilder().build();
344 ListenableFuture<RpcResult<TempServiceCreateOutput>> serviceCreatOutputF =
345 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
346 serviceCreatOutputF.addListener(new Runnable() {
350 endSignal.countDown();
355 RpcResult<TempServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
356 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
358 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
360 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
361 Assert.assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
365 public void createCreateServiceReplyWithServiceFeasibilityCheckInputWithSdncRequestHeader()
366 throws ExecutionException, InterruptedException {
367 ServiceFeasibilityCheckInput input =
368 new ServiceFeasibilityCheckInputBuilder()
369 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
370 ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> serviceCreatOutputF =
371 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
372 serviceCreatOutputF.addListener(new Runnable() {
376 endSignal.countDown();
381 RpcResult<ServiceFeasibilityCheckOutput> serviceCreatOutput = serviceCreatOutputF.get();
382 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
384 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
386 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
387 Assert.assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
391 public void createCreateServiceReplyWithServiceFeasibilityCheckInputWithoutSdncRequestHeader()
392 throws ExecutionException, InterruptedException {
393 ServiceFeasibilityCheckInput input = new ServiceFeasibilityCheckInputBuilder().build();
394 ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> serviceCreatOutputF =
395 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
396 serviceCreatOutputF.addListener(new Runnable() {
400 endSignal.countDown();
405 RpcResult<ServiceFeasibilityCheckOutput> serviceCreatOutput = serviceCreatOutputF.get();
406 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
408 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
410 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
411 Assert.assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
415 public void testCreateRestoreServiceReply() throws ExecutionException, InterruptedException {
416 ListenableFuture<RpcResult<ServiceRestorationOutput>> serviceRestorationOutputF =
417 ModelMappingUtils.createRestoreServiceReply("message", RpcStatus.Failed);
418 serviceRestorationOutputF.addListener(new Runnable() {
422 endSignal.countDown();
427 RpcResult<ServiceRestorationOutput> serviceRestorationOutput = serviceRestorationOutputF.get();
428 Assert.assertEquals("message", serviceRestorationOutput.getResult().getStatusMessage());