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;
18 import java.util.concurrent.CountDownLatch;
19 import java.util.concurrent.ExecutionException;
20 import java.util.concurrent.Executors;
21 import org.junit.After;
22 import org.junit.Assert;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.opendaylight.transportpce.common.ResponseCodes;
26 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
27 import org.opendaylight.transportpce.test.AbstractTest;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220615.PathComputationRequestOutput;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220615.PathComputationRequestOutputBuilder;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.ConnectionType;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.configuration.response.common.ConfigurationResponseCommon;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.configuration.response.common.ConfigurationResponseCommonBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.sdnc.request.header.SdncRequestHeaderBuilder;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.CoRoutingBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co.routing.ServiceIdentifierListBuilder;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.HardConstraintsBuilder;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.SoftConstraintsBuilder;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceCreateInput;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceCreateInputBuilder;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceCreateOutput;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceDeleteInput;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceDeleteInputBuilder;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceDeleteOutput;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceFeasibilityCheckInput;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceFeasibilityCheckInputBuilder;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceFeasibilityCheckOutput;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceReconfigureInput;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceReconfigureInputBuilder;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRerouteInput;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRerouteInputBuilder;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRestorationInput;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRestorationInputBuilder;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRestorationOutput;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceCreateInput;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceCreateInputBuilder;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceCreateOutput;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service.list.Services;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service.list.ServicesBuilder;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service.list.ServicesKey;
60 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.AToZDirectionBuilder;
61 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ZToADirectionBuilder;
62 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.ResponseParameters;
63 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.ResponseParametersBuilder;
64 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.response.parameters.PathDescriptionBuilder;
65 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths;
66 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsBuilder;
67 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsKey;
68 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
69 import org.opendaylight.yangtools.yang.common.RpcResult;
70 import org.opendaylight.yangtools.yang.common.Uint32;
72 public class ModelMappingUtilsTest extends AbstractTest {
74 private ListeningExecutorService executorService;
75 private CountDownLatch endSignal;
76 private static final int NUM_THREADS = 5;
80 executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS));
81 endSignal = new CountDownLatch(1);
85 public void tearDown() {
86 executorService.shutdownNow();
89 private ServiceReconfigureInput buildServiceConfigurationInput() {
90 DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx");
91 OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC);
92 OffsetDateTime offsetDateTime2 = offsetDateTime.plusDays(10);
93 return new ServiceReconfigureInputBuilder().setNewServiceName("service 1")
94 .setServiceName("service 1").setCommonId("common id").setConnectionType(ConnectionType.Service)
95 .setCustomer("customer").setCustomerContact("customer contact").setDueDate(new DateAndTime(
96 dtf.format(offsetDateTime)))
97 .setEndDate(new DateAndTime(dtf.format(offsetDateTime2)))
98 .setNcCode("nc node").setNciCode("nci node").setSecondaryNciCode("secondry").setOperatorContact("operator")
99 .setServiceAEnd(ServiceDataUtils.getServiceAEndBuildReconfigure().build())
100 .setServiceZEnd(ServiceDataUtils.getServiceZEndBuildReconfigure().build())
101 .setHardConstraints(new HardConstraintsBuilder()
102 .setCustomerCode(Set.of("Some customer-code"))
103 .setCoRouting(new CoRoutingBuilder()
104 .setServiceIdentifierList(Map.of(
105 new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210
106 .constraints.co.routing.ServiceIdentifierListKey("Some existing-service"),
107 new ServiceIdentifierListBuilder().setServiceIdentifier("Some existing-service")
111 .setSoftConstraints(new SoftConstraintsBuilder()
112 .setCustomerCode(Set.of("Some customer-code"))
113 .setCoRouting(new CoRoutingBuilder()
114 .setServiceIdentifierList(Map.of(
115 new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210
116 .constraints.co.routing.ServiceIdentifierListKey("Some existing-service"),
117 new ServiceIdentifierListBuilder().setServiceIdentifier("Some existing-service")
124 private PathComputationRequestOutput buildPathComputationOutput() {
125 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
126 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
127 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
128 ResponseParameters responseParameters = new ResponseParametersBuilder()
129 .setPathDescription(new PathDescriptionBuilder()
130 .setAToZDirection(new AToZDirectionBuilder().setAToZWavelengthNumber(Uint32.valueOf(1))
131 .setRate(Uint32.valueOf(1)).build())
132 .setZToADirection(new ZToADirectionBuilder().setZToAWavelengthNumber(Uint32.valueOf(1))
133 .setRate(Uint32.valueOf(1)).build()).build())
135 return new PathComputationRequestOutputBuilder().setConfigurationResponseCommon(configurationResponseCommon)
136 .setResponseParameters(responseParameters).build();
140 //TODO : is this unit test relevant ?
141 public void mappingServicesNullServiceCreateInput() {
142 Services services = ModelMappingUtils.mappingServices(null, null);
143 Assert.assertEquals(new ServicesBuilder().withKey(new ServicesKey("unknown")).build(), services);
147 public void mappingServiceNotNullServiceReconfigureInput() {
148 Services services = ModelMappingUtils.mappingServices(null, buildServiceConfigurationInput());
149 Assert.assertEquals("service 1", services.getServiceName());
153 public void mappingServiceValid() {
154 Services services = ModelMappingUtils.mappingServices(ServiceDataUtils.buildServiceCreateInput(),
156 Assert.assertEquals("service 1", services.getServiceName());
160 //TODO : is this unit test relevant ?
161 public void mappingServicesPathNullServiceCreateInput() {
162 ServicePaths services = ModelMappingUtils.mappingServicePaths(null, buildPathComputationOutput());
163 Assert.assertEquals(new ServicePathsBuilder().withKey(new ServicePathsKey("unknown")).build(), services);
167 public void mappingServicePathWithServiceInputWithHardConstraints() {
168 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInputWithHardConstraints();
169 ServiceInput serviceInput = new ServiceInput(createInput);
170 ServicePaths services = ModelMappingUtils.mappingServicePaths(serviceInput, buildPathComputationOutput());
171 Assert.assertEquals(serviceInput.getServiceName(), services.getServicePathName());
172 Assert.assertNotNull(services.getHardConstraints());
176 public void mappingServicePathWithServiceInputWithSoftConstraints() {
177 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInputWithSoftConstraints();
178 ServiceInput serviceInput = new ServiceInput(createInput);
179 ServicePaths services = ModelMappingUtils.mappingServicePaths(serviceInput, buildPathComputationOutput());
180 Assert.assertEquals(serviceInput.getServiceName(), services.getServicePathName());
181 Assert.assertNotNull(services.getSoftConstraints());
185 public void createServiceDeleteInputWithServiceRerouteInput() {
186 ServiceRerouteInput serviceRerouteinput = new ServiceRerouteInputBuilder().setServiceName("reroute").build();
187 Services services = new ServicesBuilder()
188 .withKey(new ServicesKey("reroute"))
189 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("123").build()).build();
190 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput
192 ModelMappingUtils.createServiceDeleteInput(serviceRerouteinput, services);
193 Assert.assertEquals("reroute", serviceDeleteInput.getServiceName());
194 Assert.assertEquals("123", serviceDeleteInput.getServiceHandlerHeader().getRequestId());
198 public void createServiceDeleteInputWithServiceReconfigureInput() {
199 ServiceReconfigureInput serviceReconfigureInput = new ServiceReconfigureInputBuilder()
200 .setServiceName("reconf").build();
201 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput
203 ModelMappingUtils.createServiceDeleteInput(serviceReconfigureInput);
204 Assert.assertEquals("reconf", serviceDeleteInput.getServiceName());
205 Assert.assertEquals("reconf-reconfigure", serviceDeleteInput.getServiceHandlerHeader().getRequestId());
209 public void createServiceDeleteInputWithServiceRestorationInput() {
210 Services services = new ServicesBuilder()
211 .withKey(new ServicesKey("rest"))
212 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("123").build()).build();
213 ServiceRestorationInput serviceRestorationInput =
214 new ServiceRestorationInputBuilder().setServiceName("rest").build();
215 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput
217 ModelMappingUtils.createServiceDeleteInput(serviceRestorationInput, services);
218 Assert.assertEquals("rest", serviceDeleteInput.getServiceName());
219 Assert.assertEquals("123", serviceDeleteInput.getServiceHandlerHeader().getRequestId());
223 public void createDeleteServiceReplyWithServiceDeleteInputWithSdncHeader()
224 throws ExecutionException, InterruptedException {
225 ServiceDeleteInput input = new ServiceDeleteInputBuilder()
226 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
227 ListenableFuture<RpcResult<ServiceDeleteOutput>> serviceDeleteOutputF =
228 ModelMappingUtils.createDeleteServiceReply(input, "ack", "message", "200");
229 serviceDeleteOutputF.addListener(new Runnable() {
232 endSignal.countDown();
237 RpcResult<ServiceDeleteOutput> serviceDeleteOutput = serviceDeleteOutputF.get();
238 Assert.assertEquals("200", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseCode());
240 "ack", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
242 "message", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
243 Assert.assertEquals("12", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getRequestId());
247 public void createDeleteServiceReplyWithServiceDeleteInputWithoutSdncHeader()
248 throws ExecutionException, InterruptedException {
249 ServiceDeleteInput input = new ServiceDeleteInputBuilder().build();
250 ListenableFuture<RpcResult<ServiceDeleteOutput>> serviceDeleteOutputF =
251 ModelMappingUtils.createDeleteServiceReply(input, "ack", "message", "200");
252 serviceDeleteOutputF.addListener(new Runnable() {
255 endSignal.countDown();
260 RpcResult<ServiceDeleteOutput> serviceDeleteOutput = serviceDeleteOutputF.get();
261 Assert.assertEquals("200", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseCode());
263 "ack", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
265 "message", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
266 Assert.assertNull(serviceDeleteOutput.getResult().getConfigurationResponseCommon().getRequestId());
270 public void createCreateServiceReplyWithServiceCreatInputWithSdncRequestHeader()
271 throws ExecutionException, InterruptedException {
272 ServiceCreateInput input =
273 new ServiceCreateInputBuilder()
274 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
275 ListenableFuture<RpcResult<ServiceCreateOutput>> serviceCreatOutputF =
276 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
277 serviceCreatOutputF.addListener(new Runnable() {
280 endSignal.countDown();
285 RpcResult<ServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
286 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
288 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
290 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
291 Assert.assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
295 public void createCreateServiceReplyWithServiceCreatInputWithoutSdncRequestHeader()
296 throws ExecutionException, InterruptedException {
297 ServiceCreateInput input = new ServiceCreateInputBuilder().build();
298 ListenableFuture<RpcResult<ServiceCreateOutput>> serviceCreatOutputF =
299 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
300 serviceCreatOutputF.addListener(new Runnable() {
303 endSignal.countDown();
308 RpcResult<ServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
309 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
311 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
313 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
314 Assert.assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
318 public void createCreateServiceReplyWithTempServiceCreatInputWithSdncRequestHeader()
319 throws ExecutionException, InterruptedException {
320 TempServiceCreateInput input =
321 new TempServiceCreateInputBuilder()
322 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
323 ListenableFuture<RpcResult<TempServiceCreateOutput>> serviceCreatOutputF =
324 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
325 serviceCreatOutputF.addListener(new Runnable() {
328 endSignal.countDown();
333 RpcResult<TempServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
334 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
336 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
338 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
339 Assert.assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
343 public void createCreateServiceReplyWithTempServiceCreatInputWithoutSdncRequestHeader()
344 throws ExecutionException, InterruptedException {
345 TempServiceCreateInput input = new TempServiceCreateInputBuilder().build();
346 ListenableFuture<RpcResult<TempServiceCreateOutput>> serviceCreatOutputF =
347 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
348 serviceCreatOutputF.addListener(new Runnable() {
351 endSignal.countDown();
356 RpcResult<TempServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
357 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
359 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
361 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
362 Assert.assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
366 public void createCreateServiceReplyWithServiceFeasibilityCheckInputWithSdncRequestHeader()
367 throws ExecutionException, InterruptedException {
368 ServiceFeasibilityCheckInput input =
369 new ServiceFeasibilityCheckInputBuilder()
370 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
371 ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> serviceCreatOutputF =
372 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
373 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() {
399 endSignal.countDown();
404 RpcResult<ServiceFeasibilityCheckOutput> serviceCreatOutput = serviceCreatOutputF.get();
405 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
407 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
409 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
410 Assert.assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
414 public void testCreateRestoreServiceReply() throws ExecutionException, InterruptedException {
415 ListenableFuture<RpcResult<ServiceRestorationOutput>> serviceRestorationOutputF =
416 ModelMappingUtils.createRestoreServiceReply("message");
417 serviceRestorationOutputF.addListener(new Runnable() {
420 endSignal.countDown();