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.rev210701.PathComputationRequestOutput;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.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.openroadm.service.rev190531.service.list.ServicesKey;
59 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.AToZDirectionBuilder;
60 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ZToADirectionBuilder;
61 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.ResponseParameters;
62 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.ResponseParametersBuilder;
63 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.response.parameters.PathDescriptionBuilder;
64 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths;
65 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsBuilder;
66 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsKey;
67 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
68 import org.opendaylight.yangtools.yang.common.RpcResult;
69 import org.opendaylight.yangtools.yang.common.Uint32;
71 public class ModelMappingUtilsTest extends AbstractTest {
73 private ListeningExecutorService executorService;
74 private CountDownLatch endSignal;
75 private static final int NUM_THREADS = 5;
79 executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS));
80 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 //TODO : is this unit test relevant ?
138 public void mappingServicesNullServiceCreateInput() {
139 Services services = ModelMappingUtils.mappingServices(null, null);
140 Assert.assertEquals(new ServicesBuilder().withKey(new ServicesKey("unknown")).build(), services);
144 public void mappingServiceNotNullServiceReconfigureInput() {
145 Services services = ModelMappingUtils.mappingServices(null, buildServiceConfigurationInput());
146 Assert.assertEquals("service 1", services.getServiceName());
150 public void mappingServiceValid() {
151 Services services = ModelMappingUtils.mappingServices(ServiceDataUtils.buildServiceCreateInput(),
153 Assert.assertEquals("service 1", services.getServiceName());
157 //TODO : is this unit test relevant ?
158 public void mappingServicesPathNullServiceCreateInput() {
159 ServicePaths services = ModelMappingUtils.mappingServicePaths(null, buildPathComputationOutput());
160 Assert.assertEquals(new ServicePathsBuilder().withKey(new ServicePathsKey("unknown")).build(), services);
164 public void mappingServicePathWithServiceInputWithHardConstraints() {
165 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInputWithHardConstraints();
166 ServiceInput serviceInput = new ServiceInput(createInput);
167 ServicePaths services = ModelMappingUtils.mappingServicePaths(serviceInput, buildPathComputationOutput());
168 Assert.assertEquals(serviceInput.getServiceName(), services.getServicePathName());
169 Assert.assertNotNull(services.getHardConstraints());
173 public void mappingServicePathWithServiceInputWithSoftConstraints() {
174 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInputWithSoftConstraints();
175 ServiceInput serviceInput = new ServiceInput(createInput);
176 ServicePaths services = ModelMappingUtils.mappingServicePaths(serviceInput, buildPathComputationOutput());
177 Assert.assertEquals(serviceInput.getServiceName(), services.getServicePathName());
178 Assert.assertNotNull(services.getSoftConstraints());
182 public void createServiceDeleteInputWithServiceRerouteInput() {
183 ServiceRerouteInput serviceRerouteinput = new ServiceRerouteInputBuilder().setServiceName("reroute").build();
184 Services services = new ServicesBuilder()
185 .withKey(new ServicesKey("reroute"))
186 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("123").build()).build();
187 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput
189 ModelMappingUtils.createServiceDeleteInput(serviceRerouteinput, services);
190 Assert.assertEquals("reroute", serviceDeleteInput.getServiceName());
191 Assert.assertEquals("123", serviceDeleteInput.getServiceHandlerHeader().getRequestId());
195 public void createServiceDeleteInputWithServiceReconfigureInput() {
196 ServiceReconfigureInput serviceReconfigureInput = new ServiceReconfigureInputBuilder()
197 .setServiceName("reconf").build();
198 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput
200 ModelMappingUtils.createServiceDeleteInput(serviceReconfigureInput);
201 Assert.assertEquals("reconf", serviceDeleteInput.getServiceName());
202 Assert.assertEquals("reconf-reconfigure", serviceDeleteInput.getServiceHandlerHeader().getRequestId());
206 public void createServiceDeleteInputWithServiceRestorationInput() {
207 Services services = new ServicesBuilder()
208 .withKey(new ServicesKey("rest"))
209 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("123").build()).build();
210 ServiceRestorationInput serviceRestorationInput =
211 new ServiceRestorationInputBuilder().setServiceName("rest").build();
212 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput
214 ModelMappingUtils.createServiceDeleteInput(serviceRestorationInput, services);
215 Assert.assertEquals("rest", serviceDeleteInput.getServiceName());
216 Assert.assertEquals("123", serviceDeleteInput.getServiceHandlerHeader().getRequestId());
220 public void createDeleteServiceReplyWithServiceDeleteInputWithSdncHeader()
221 throws ExecutionException, InterruptedException {
222 ServiceDeleteInput input = new ServiceDeleteInputBuilder()
223 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
224 ListenableFuture<RpcResult<ServiceDeleteOutput>> serviceDeleteOutputF =
225 ModelMappingUtils.createDeleteServiceReply(input, "ack", "message", "200");
226 serviceDeleteOutputF.addListener(new Runnable() {
229 endSignal.countDown();
234 RpcResult<ServiceDeleteOutput> serviceDeleteOutput = serviceDeleteOutputF.get();
235 Assert.assertEquals("200", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseCode());
237 "ack", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
239 "message", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
240 Assert.assertEquals("12", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getRequestId());
244 public void createDeleteServiceReplyWithServiceDeleteInputWithoutSdncHeader()
245 throws ExecutionException, InterruptedException {
246 ServiceDeleteInput input = new ServiceDeleteInputBuilder().build();
247 ListenableFuture<RpcResult<ServiceDeleteOutput>> serviceDeleteOutputF =
248 ModelMappingUtils.createDeleteServiceReply(input, "ack", "message", "200");
249 serviceDeleteOutputF.addListener(new Runnable() {
252 endSignal.countDown();
257 RpcResult<ServiceDeleteOutput> serviceDeleteOutput = serviceDeleteOutputF.get();
258 Assert.assertEquals("200", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseCode());
260 "ack", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
262 "message", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
263 Assert.assertNull(serviceDeleteOutput.getResult().getConfigurationResponseCommon().getRequestId());
267 public void createCreateServiceReplyWithServiceCreatInputWithSdncRequestHeader()
268 throws ExecutionException, InterruptedException {
269 ServiceCreateInput input =
270 new ServiceCreateInputBuilder()
271 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
272 ListenableFuture<RpcResult<ServiceCreateOutput>> serviceCreatOutputF =
273 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
274 serviceCreatOutputF.addListener(new Runnable() {
277 endSignal.countDown();
282 RpcResult<ServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
283 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
285 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
287 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
288 Assert.assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
292 public void createCreateServiceReplyWithServiceCreatInputWithoutSdncRequestHeader()
293 throws ExecutionException, InterruptedException {
294 ServiceCreateInput input = new ServiceCreateInputBuilder().build();
295 ListenableFuture<RpcResult<ServiceCreateOutput>> serviceCreatOutputF =
296 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
297 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() {
325 endSignal.countDown();
330 RpcResult<TempServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
331 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
333 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
335 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
336 Assert.assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
340 public void createCreateServiceReplyWithTempServiceCreatInputWithoutSdncRequestHeader()
341 throws ExecutionException, InterruptedException {
342 TempServiceCreateInput input = new TempServiceCreateInputBuilder().build();
343 ListenableFuture<RpcResult<TempServiceCreateOutput>> serviceCreatOutputF =
344 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
345 serviceCreatOutputF.addListener(new Runnable() {
348 endSignal.countDown();
353 RpcResult<TempServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
354 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
356 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
358 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
359 Assert.assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
363 public void createCreateServiceReplyWithServiceFeasibilityCheckInputWithSdncRequestHeader()
364 throws ExecutionException, InterruptedException {
365 ServiceFeasibilityCheckInput input =
366 new ServiceFeasibilityCheckInputBuilder()
367 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
368 ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> serviceCreatOutputF =
369 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
370 serviceCreatOutputF.addListener(new Runnable() {
373 endSignal.countDown();
378 RpcResult<ServiceFeasibilityCheckOutput> serviceCreatOutput = serviceCreatOutputF.get();
379 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
381 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
383 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
384 Assert.assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
388 public void createCreateServiceReplyWithServiceFeasibilityCheckInputWithoutSdncRequestHeader()
389 throws ExecutionException, InterruptedException {
390 ServiceFeasibilityCheckInput input = new ServiceFeasibilityCheckInputBuilder().build();
391 ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> serviceCreatOutputF =
392 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
393 serviceCreatOutputF.addListener(new Runnable() {
396 endSignal.countDown();
401 RpcResult<ServiceFeasibilityCheckOutput> serviceCreatOutput = serviceCreatOutputF.get();
402 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
404 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
406 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
407 Assert.assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
411 public void testCreateRestoreServiceReply() throws ExecutionException, InterruptedException {
412 ListenableFuture<RpcResult<ServiceRestorationOutput>> serviceRestorationOutputF =
413 ModelMappingUtils.createRestoreServiceReply("message", RpcStatus.Failed);
414 serviceRestorationOutputF.addListener(new Runnable() {
417 endSignal.countDown();
422 RpcResult<ServiceRestorationOutput> serviceRestorationOutput = serviceRestorationOutputF.get();
423 Assert.assertEquals("message", serviceRestorationOutput.getResult().getStatusMessage());