2 * Copyright © 2018 2022 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 static org.hamcrest.CoreMatchers.hasItems;
11 import static org.hamcrest.CoreMatchers.is;
12 import static org.hamcrest.MatcherAssert.assertThat;
13 import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
14 import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16 import static org.junit.jupiter.api.Assertions.assertNotNull;
17 import static org.junit.jupiter.api.Assertions.assertNull;
18 import static org.junit.jupiter.api.Assertions.assertTrue;
19 import static org.opendaylight.transportpce.servicehandler.utils.ConstraintsUtils.buildHardConstraint;
20 import static org.opendaylight.transportpce.servicehandler.utils.ConstraintsUtils.buildSoftConstraint;
23 import org.hamcrest.collection.IsMapContaining;
24 import org.junit.jupiter.api.Test;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev210528.NodeIdType;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.DiversityConstraints.DiversityType;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.common.constraints.LinkIdentifierBuilder;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.diversity.existing.service.constraints.ServiceIdentifierListKey;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.routing.constraints.HardConstraints;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.routing.constraints.HardConstraintsBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.routing.constraints.SoftConstraints;
34 * Class to test downgrading and updating Constraints .
35 * @author Ahmed Helmy ( ahmad.helmy@orange.com )
36 * @author Gilles Thouenon (gilles.thouenon@orange.com)
38 public class DowngradeConstraintsTest {
41 void testUpdateSoftConstraintsForCustomerCode() {
42 // test no addition when hard customer-code is null or empty
43 HardConstraints initialHardConstraints =
44 buildHardConstraint(null, false, null, null, null, null, false, false, null, null);
45 SoftConstraints initialSoftConstraints =
46 buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
47 SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
48 initialHardConstraints, initialSoftConstraints);
49 assertNull(generatedSoftConstraints.getCustomerCode(),
50 "updated soft constraints should contain no customer code");
51 Set<String> softCustomerCode = Set.of("soft-customer-code 3", "soft-customer-code 4");
52 initialSoftConstraints =
53 buildSoftConstraint(softCustomerCode, false, null, null, null, null, false, false, null, null);
54 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
55 initialHardConstraints, initialSoftConstraints);
56 assertEquals(initialSoftConstraints.getCustomerCode(), generatedSoftConstraints.getCustomerCode());
58 // test addition of hard customer-code when no soft customer-code
59 Set<String> hardCustomerCode = Set.of("hard-customer-code 1", "hard-customer-code 2");
60 initialHardConstraints =
61 buildHardConstraint(hardCustomerCode, false, null, null, null, null, false, false, null, null);
62 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
63 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
64 initialHardConstraints, initialSoftConstraints);
65 assertEquals(generatedSoftConstraints.getCustomerCode(),initialHardConstraints.getCustomerCode(),
66 "updated soft constraints should contain the customer code of hard constraint");
67 // test addition of hard customer-code when existing soft customer-code
68 initialSoftConstraints =
69 buildSoftConstraint(softCustomerCode, false, null, null, null, null, false, false, null, null);
70 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
71 initialHardConstraints, initialSoftConstraints);
72 assertThat("updated soft constraints should contain 4 customer code",
73 generatedSoftConstraints.getCustomerCode(), hasSize(4));
74 assertThat(generatedSoftConstraints.getCustomerCode(),
75 containsInAnyOrder("hard-customer-code 1", "hard-customer-code 2", "soft-customer-code 3",
76 "soft-customer-code 4"));
80 void testUpdateSoftConstraintsForDiversity() {
81 HardConstraints initialHardConstraints =
82 buildHardConstraint(null, false, null, null, null, null, false, false, null, null);
83 SoftConstraints initialSoftConstraints =
84 buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
85 SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
86 initialHardConstraints, initialSoftConstraints);
87 assertNull(generatedSoftConstraints.getDiversity(),
88 "updated soft constraints should contain no diversity constraint");
89 Set<String> softDiversityServiceid = Set.of("soft-service 3");
90 initialSoftConstraints =
91 buildSoftConstraint(null, false, softDiversityServiceid, null, null, null, false, false, null, null);
92 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
93 initialHardConstraints, initialSoftConstraints);
94 assertEquals(initialSoftConstraints.getDiversity(), generatedSoftConstraints.getDiversity());
96 // test addition of hard diversity when no soft diversity
97 Set<String> hardDiversityServiceid = Set.of("hard-service 1", "hard-service 2");
98 initialHardConstraints =
99 buildHardConstraint(null, false, hardDiversityServiceid, null, null, null, false, false, null, null);
100 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
101 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
102 initialHardConstraints, initialSoftConstraints);
103 assertEquals(generatedSoftConstraints.getDiversity(), initialHardConstraints.getDiversity(),
104 "updated soft constraints should contain the diversity of hard constraint");
106 // test addition of hard diversity when existing soft diversity
107 initialSoftConstraints =
108 buildSoftConstraint(null, false, softDiversityServiceid, null, null, null, false, false, null, null);
109 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
110 initialHardConstraints, initialSoftConstraints);
111 assertThat("updated soft constraints should contain diversity with 3 services",
112 generatedSoftConstraints.getDiversity().getServiceIdentifierList().size(), is(3));
113 assertEquals(DiversityType.Serial, generatedSoftConstraints.getDiversity().getDiversityType(),
114 "updated soft constraints should have diversity type of serial");
115 assertThat(generatedSoftConstraints.getDiversity().getServiceIdentifierList(),
116 IsMapContaining.hasKey(new ServiceIdentifierListKey("hard-service 1")));
117 assertThat(generatedSoftConstraints.getDiversity().getServiceIdentifierList(),
118 IsMapContaining.hasKey(new ServiceIdentifierListKey("hard-service 2")));
119 assertThat(generatedSoftConstraints.getDiversity().getServiceIdentifierList(),
120 IsMapContaining.hasKey(new ServiceIdentifierListKey("soft-service 3")));
124 void testUpdateSoftConstraintsForExclude() {
125 HardConstraints initialHardConstraints =
126 buildHardConstraint(null, false, null, null, null, null, false, false, null, null);
127 SoftConstraints initialSoftConstraints =
128 buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
129 SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
130 initialHardConstraints, initialSoftConstraints);
131 assertNull(generatedSoftConstraints.getExclude(),
132 "updated soft constraints should contain no exclude constraint");
134 initialSoftConstraints = buildSoftConstraint(null, false, null, "link", null, null, false, false, null, null);
135 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
136 initialHardConstraints, initialSoftConstraints);
137 assertEquals(initialSoftConstraints.getExclude(), generatedSoftConstraints.getExclude(),
138 "updated soft constraints should not be changed");
140 // test addition of hard exclude with fiber list when no soft exclude
141 initialHardConstraints =
142 buildHardConstraint(null, false, null, "fiber1", null, null, false, false, null, null);
143 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
144 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
145 initialHardConstraints, initialSoftConstraints);
146 assertEquals(generatedSoftConstraints.getExclude(), initialHardConstraints.getExclude(),
147 "updated soft constraints should contain the exclude constraint of hard constraint");
149 // test addition of hard exclude with fiber list when existing soft
150 // exclude with fiber list
151 initialSoftConstraints =
152 buildSoftConstraint(null, false, null, "fiber2", null, null, false, false, null, null);
153 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
154 initialHardConstraints, initialSoftConstraints);
155 assertThat("updated soft constraints should contain exclude with 3 fiber bundles",
156 generatedSoftConstraints.getExclude().getFiberBundle().size(), is(3));
157 assertThat(generatedSoftConstraints.getExclude().getFiberBundle(),
158 containsInAnyOrder("fiber-1", "fiber-2", "fiber-3"));
160 // test addition of hard exclude with link list when no soft exclude
161 initialHardConstraints = buildHardConstraint(null, false, null, "link1", null, null, false, false, null, null);
162 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
163 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
164 initialHardConstraints, initialSoftConstraints);
165 assertEquals(generatedSoftConstraints.getExclude(), initialHardConstraints.getExclude(),
166 "updated soft constraints should contain the exclude constraint of hard constraint");
168 // test addition of hard exclude with link list when existing soft
169 // exclude with link list
170 initialSoftConstraints = buildSoftConstraint(null, false, null, "link2", null, null, false, false, null, null);
171 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
172 initialHardConstraints, initialSoftConstraints);
173 assertThat("updated soft constraints should contain exclude with 3 links",
174 generatedSoftConstraints.getExclude().getLinkIdentifier().size(), is(3));
175 assertThat(generatedSoftConstraints.getExclude().getLinkIdentifier(), hasItems(new LinkIdentifierBuilder()
176 .setLinkId("link-id 1").setLinkNetworkId("openroadm-topology").build()));
177 assertThat(generatedSoftConstraints.getExclude().getLinkIdentifier(), hasItems(new LinkIdentifierBuilder()
178 .setLinkId("link-id 2").setLinkNetworkId("openroadm-topology").build()));
179 assertThat(generatedSoftConstraints.getExclude().getLinkIdentifier(), hasItems(new LinkIdentifierBuilder()
180 .setLinkId("link-id 3").setLinkNetworkId("openroadm-topology").build()));
184 void testUpdateSoftConstraintsForInclude() {
185 HardConstraints initialHardConstraints =
186 buildHardConstraint(null, false, null, null, null, null, false, false, null, null);
187 SoftConstraints initialSoftConstraints =
188 buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
189 SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
190 initialHardConstraints, initialSoftConstraints);
191 assertNull(generatedSoftConstraints.getInclude(),
192 "updated soft constraints should contain no include constraint");
194 initialSoftConstraints = buildSoftConstraint(null, false, null, null, "link", null, false, false, null, null);
195 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
196 initialHardConstraints, initialSoftConstraints);
197 assertEquals(initialSoftConstraints.getInclude(), generatedSoftConstraints.getInclude(),
198 "updated soft constraints should not be changed");
200 // test addition of hard include with fiber list when no soft include
201 initialHardConstraints =
202 buildHardConstraint(null, false, null, null, "fiber1", null, false, false, null, null);
203 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
204 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
205 initialHardConstraints, initialSoftConstraints);
206 assertEquals(generatedSoftConstraints.getInclude(), initialHardConstraints.getInclude(),
207 "updated soft constraints should contain the include constraint of hard constraint");
209 // test addition of hard include with fiber list when existing soft
210 // include with fiber list
211 initialSoftConstraints =
212 buildSoftConstraint(null, false, null, null, "fiber2", null, false, false, null, null);
213 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
214 initialHardConstraints, initialSoftConstraints);
215 assertThat("updated soft constraints should contain exclude with 3 fiber bundles",
216 generatedSoftConstraints.getInclude().getFiberBundle().size(), is(3));
217 assertThat(generatedSoftConstraints.getInclude().getFiberBundle(),
218 containsInAnyOrder("fiber-1", "fiber-2", "fiber-3"));
220 // test addition of hard include with link list when no soft include
221 initialHardConstraints = buildHardConstraint(null, false, null, null, "link1", null, false, false, null, null);
222 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
223 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
224 initialHardConstraints, initialSoftConstraints);
225 assertEquals(generatedSoftConstraints.getInclude(), initialHardConstraints.getInclude(),
226 "updated soft constraints should contain the include constraint of hard constraint");
228 // test addition of hard include with link list when existing soft
229 // include with link list
230 initialSoftConstraints = buildSoftConstraint(null, false, null, null, "link2", null, false, false, null, null);
231 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
232 initialHardConstraints, initialSoftConstraints);
233 assertThat("updated soft constraints should contain include with 3 links",
234 generatedSoftConstraints.getInclude().getLinkIdentifier().size(), is(3));
235 assertThat(generatedSoftConstraints.getInclude().getLinkIdentifier(), hasItems(new LinkIdentifierBuilder()
236 .setLinkId("link-id 1").setLinkNetworkId("openroadm-topology").build()));
237 assertThat(generatedSoftConstraints.getInclude().getLinkIdentifier(), hasItems(new LinkIdentifierBuilder()
238 .setLinkId("link-id 2").setLinkNetworkId("openroadm-topology").build()));
239 assertThat(generatedSoftConstraints.getInclude().getLinkIdentifier(), hasItems(new LinkIdentifierBuilder()
240 .setLinkId("link-id 3").setLinkNetworkId("openroadm-topology").build()));
244 void testUpdateSoftConstraintsForLatency() {
245 HardConstraints initialHardConstraints =
246 buildHardConstraint(null, false, null, null, null, null, false, false, null, null);
247 SoftConstraints initialSoftConstraints =
248 buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
249 SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
250 initialHardConstraints, initialSoftConstraints);
251 assertNull(generatedSoftConstraints.getLatency(),
252 "updated soft constraints should contain no latency constraint");
254 initialSoftConstraints =
255 buildSoftConstraint(null, false, null, null, null, Double.valueOf(12.2), false, false, null, null);
256 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
257 initialHardConstraints, initialSoftConstraints);
258 assertEquals(initialSoftConstraints.getLatency(), generatedSoftConstraints.getLatency(),
259 "updated soft constraints should not be changed");
260 assertEquals((float) 12.2, generatedSoftConstraints.getLatency().getMaxLatency().floatValue(), 0.0f,
261 "updated soft constraints value should be '12.2'");
263 // test addition of hard latency when no soft latency
264 initialHardConstraints =
265 buildHardConstraint(null, false, null, null, null, Double.valueOf(16.59), false, false, null, null);
266 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
267 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
268 initialHardConstraints, initialSoftConstraints);
269 assertEquals((float) 16.59, generatedSoftConstraints.getLatency().getMaxLatency().floatValue(), 0.0f,
270 "updated soft constraints value should be '16.59'");
272 // test addition of hard latency when existing different soft latency
273 initialSoftConstraints =
274 buildSoftConstraint(null, false, null, null, null, Double.valueOf(12.2), false, false, null, null);
275 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
276 initialHardConstraints, initialSoftConstraints);
277 assertEquals((float) 12.2, generatedSoftConstraints.getLatency().getMaxLatency().floatValue(), 0.0f,
278 "updated soft constraints value should be '12.2'");
282 void testUpdateSoftConstraintsForDistance() {
283 HardConstraints initialHardConstraints =
284 buildHardConstraint(null, false, null, null, null, null, false, false, null, null);
285 SoftConstraints initialSoftConstraints =
286 buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
287 SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
288 initialHardConstraints, initialSoftConstraints);
289 assertNull(generatedSoftConstraints.getDistance(),
290 "updated soft constraints should contain no distance constraint");
292 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, "750.2", null);
293 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
294 initialHardConstraints, initialSoftConstraints);
295 assertEquals(initialSoftConstraints.getDistance(), generatedSoftConstraints.getDistance(),
296 "updated soft constraints should not be changed");
297 assertEquals((float) 750.2, generatedSoftConstraints.getDistance().getMaxDistance().floatValue(), 0.0f,
298 "updated soft constraints value should be '750.2'");
300 // test addition of hard distance when no soft distance
301 initialHardConstraints = buildHardConstraint(null, false, null, null, null, null, false, false, "555.5", null);
302 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
303 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
304 initialHardConstraints, initialSoftConstraints);
305 assertEquals((float) 555.5, generatedSoftConstraints.getDistance().getMaxDistance().floatValue(), 0.0f,
306 "updated soft constraints value should be '555.5'");
308 // test addition of hard distance when existing different soft distance
309 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, "750.2", null);
310 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
311 initialHardConstraints, initialSoftConstraints);
312 assertEquals((float) 555.5, generatedSoftConstraints.getDistance().getMaxDistance().floatValue(), 0.0f,
313 "updated soft constraints value should be '555.5'");
317 void testUpdateSoftConstraintsForHopCountAndTEmetric() {
318 HardConstraints initialHardConstraints =
319 buildHardConstraint(null, false, null, null, null, null, false, false, null, null);
320 SoftConstraints initialSoftConstraints =
321 buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
322 SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
323 initialHardConstraints, initialSoftConstraints);
324 assertNull(generatedSoftConstraints.getHopCount(),
325 "updated soft constraints should contain no hop-count constraint");
327 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, true, true, null, null);
328 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
329 initialHardConstraints, initialSoftConstraints);
330 assertEquals(initialSoftConstraints.getHopCount(), generatedSoftConstraints.getHopCount(),
331 "updated soft constraints should not be changed");
332 assertEquals(3, generatedSoftConstraints.getHopCount().getMaxWdmHopCount().intValue(),
333 "updated soft constraints max-wdm-hop-count should be '3'");
334 assertEquals(5, generatedSoftConstraints.getHopCount().getMaxOtnHopCount().intValue(),
335 "updated soft constraints max-otn-hop-count should be '5'");
336 assertEquals(8, generatedSoftConstraints.getTEMetric().getMaxWdmTEMetric().intValue(),
337 "updated soft constraints max-wdm-TE-metric should be '8'");
338 assertEquals(11, generatedSoftConstraints.getTEMetric().getMaxOtnTEMetric().intValue(),
339 "updated soft constraints max-otn-TE-metric should be '11'");
341 // test addition of hard hop-count when no soft hop-count
342 initialHardConstraints = buildHardConstraint(null, false, null, null, null, null, true, true, null, null);
343 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
344 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
345 initialHardConstraints, initialSoftConstraints);
346 assertEquals(initialHardConstraints.getHopCount(), generatedSoftConstraints.getHopCount(),
347 "updated soft constraints should contain hard constraint");
348 assertEquals(3, generatedSoftConstraints.getHopCount().getMaxWdmHopCount().intValue(),
349 "updated soft constraints max-wdm-hop-count should be '3'");
350 assertEquals(5, generatedSoftConstraints.getHopCount().getMaxOtnHopCount().intValue(),
351 "updated soft constraints max-otn-hop-count should be '5'");
352 assertEquals(8, generatedSoftConstraints.getTEMetric().getMaxWdmTEMetric().intValue(),
353 "updated soft constraints max-wdm-TE-metric should be '8'");
354 assertEquals(11, generatedSoftConstraints.getTEMetric().getMaxOtnTEMetric().intValue(),
355 "updated soft constraints max-otn-TE-metric should be '11'");
357 // test addition of hard hop-count when existing soft hop-count
358 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, true, true, null, null);
359 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
360 initialHardConstraints, initialSoftConstraints);
361 assertEquals(3, generatedSoftConstraints.getHopCount().getMaxWdmHopCount().intValue(),
362 "updated soft constraints max-wdm-hop-count should be '3'");
363 assertEquals(5, generatedSoftConstraints.getHopCount().getMaxOtnHopCount().intValue(),
364 "updated soft constraints max-otn-hop-count should be '5'");
365 assertEquals(8, generatedSoftConstraints.getTEMetric().getMaxWdmTEMetric().intValue(),
366 "updated soft constraints max-wdm-TE-metric should be '8'");
367 assertEquals(11, generatedSoftConstraints.getTEMetric().getMaxOtnTEMetric().intValue(),
368 "updated soft constraints max-otn-TE-metric should be '11'");
372 void testUpdateSoftConstraintsForCoRouting() {
373 HardConstraints initialHardConstraints =
374 buildHardConstraint(null, false, null, null, null, null, false, false, null, null);
375 SoftConstraints initialSoftConstraints =
376 buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
377 SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
378 initialHardConstraints, initialSoftConstraints);
379 assertNull(generatedSoftConstraints.getCoRouting(),
380 "updated soft constraints should contain no co-routing constraint");
382 initialSoftConstraints =
383 buildSoftConstraint(null, false, null, null, null, null, true, false, null, "coRouting1");
384 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
385 initialHardConstraints, initialSoftConstraints);
386 assertEquals(initialSoftConstraints.getCoRouting(), generatedSoftConstraints.getCoRouting(),
387 "updated soft constraints should not be changed");
388 assertEquals(2, generatedSoftConstraints.getCoRouting().getServiceIdentifierList().size(),
389 "updated soft constraints should contain 2 co-routed services");
390 assertTrue(generatedSoftConstraints.getCoRouting().getServiceIdentifierList()
391 .get(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.constraints.co
392 .routing.ServiceIdentifierListKey("service 1"))
393 .getServiceApplicability().getEquipment().getRoadmSrg());
394 assertNull(generatedSoftConstraints.getCoRouting().getServiceIdentifierList()
395 .get(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.constraints.co
396 .routing.ServiceIdentifierListKey("service 1"))
397 .getServiceApplicability().getLink());
398 assertNull(generatedSoftConstraints.getCoRouting().getServiceIdentifierList()
399 .get(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.constraints.co
400 .routing.ServiceIdentifierListKey("service 2"))
401 .getServiceApplicability().getEquipment());
402 assertTrue(generatedSoftConstraints.getCoRouting().getServiceIdentifierList()
403 .get(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.constraints.co
404 .routing.ServiceIdentifierListKey("service 2"))
405 .getServiceApplicability().getLink());
407 // test addition of hard co-routing when no soft co-routing
408 initialHardConstraints =
409 buildHardConstraint(null, false, null, null, null, null, true, false, null, "coRouting2");
410 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
411 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
412 initialHardConstraints, initialSoftConstraints);
413 assertEquals(initialHardConstraints.getCoRouting(), generatedSoftConstraints.getCoRouting(),
414 "updated soft constraints should contain hard constraint");
415 assertEquals(1, generatedSoftConstraints.getCoRouting().getServiceIdentifierList().size(),
416 "updated soft constraints should contain 1 co-routed service");
417 assertTrue(generatedSoftConstraints.getCoRouting().getServiceIdentifierList()
418 .get(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.constraints.co
419 .routing.ServiceIdentifierListKey("service 3"))
420 .getServiceApplicability().getSite());
421 assertNull(generatedSoftConstraints.getCoRouting().getServiceIdentifierList()
422 .get(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.constraints.co
423 .routing.ServiceIdentifierListKey("service 3"))
424 .getServiceApplicability().getLink());
426 // test addition of hard hop-count when existing soft hop-count
427 initialSoftConstraints =
428 buildSoftConstraint(null, false, null, null, null, null, true, false, null, "coRouting1");
429 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
430 initialHardConstraints, initialSoftConstraints);
431 assertEquals(3, generatedSoftConstraints.getCoRouting().getServiceIdentifierList().size(),
432 "updated soft constraints should contain 3 co-routed service");
433 assertThat(generatedSoftConstraints.getCoRouting().getServiceIdentifierList(),
434 IsMapContaining.hasKey(
435 new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.constraints.co
436 .routing.ServiceIdentifierListKey("service 1")));
437 assertThat(generatedSoftConstraints.getCoRouting().getServiceIdentifierList(),
438 IsMapContaining.hasKey(
439 new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.constraints.co
440 .routing.ServiceIdentifierListKey("service 2")));
441 assertThat(generatedSoftConstraints.getCoRouting().getServiceIdentifierList(),
442 IsMapContaining.hasKey(
443 new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.constraints.co
444 .routing.ServiceIdentifierListKey("service 3")));
448 void testDowngradeHardConstraints() {
449 HardConstraints initialHardConstraints = null;
450 HardConstraints genHardConstraints = DowngradeConstraints.downgradeHardConstraints(initialHardConstraints);
451 assertNotNull(genHardConstraints, "generated hard-constraints should be empty, not null");
452 initialHardConstraints = new HardConstraintsBuilder().build();
453 genHardConstraints = DowngradeConstraints.downgradeHardConstraints(initialHardConstraints);
454 assertNotNull(genHardConstraints, "generated hard-constraints should be empty, not null");
455 initialHardConstraints = buildHardConstraint(null, false, null, "link1", null, Double.valueOf(12.8), false,
457 genHardConstraints = DowngradeConstraints.downgradeHardConstraints(initialHardConstraints);
458 assertEquals((long) 12.8, genHardConstraints.getLatency().getMaxLatency().longValue(),
459 "Latency value should be 12.8");
460 assertNull(genHardConstraints.getCoRouting(),
461 "generated hard constraints should only contain max-latency value");
462 assertNull(genHardConstraints.getExclude(), "generated hard constraints should only contain max-latency value");
463 assertNull(genHardConstraints.getInclude(), "generated hard constraints should only contain max-latency value");
467 void testConvertToSoftConstraints() {
468 HardConstraints initialHardConstraints = null;
469 SoftConstraints genSoftConstraints = DowngradeConstraints.convertToSoftConstraints(initialHardConstraints);
470 assertNotNull(genSoftConstraints, "generated soft constraints should never be null");
471 assertNull(genSoftConstraints.getExclude(), "generated soft constraints should be empty");
472 assertNull(genSoftConstraints.getCoRouting(), "generated soft constraints should be empty");
473 assertNull(genSoftConstraints.getLatency(), "generated soft constraints should be empty");
475 Set<String> hardCustomerCode = Set.of("customer-code 1", "customer-code 2");
476 initialHardConstraints =
477 buildHardConstraint(hardCustomerCode, false, null, "link1", "node", null, false, false, null, null);
478 genSoftConstraints = DowngradeConstraints.convertToSoftConstraints(initialHardConstraints);
479 assertEquals(2, genSoftConstraints.getCustomerCode().size(),
480 "generated soft constraints should contain customer-code items");
481 assertTrue(genSoftConstraints.getCustomerCode().contains("customer-code 1"));
482 assertTrue(genSoftConstraints.getCustomerCode().contains("customer-code 2"));
483 assertNotNull(genSoftConstraints.getExclude(), "generated soft constraints should contain exclude constraint");
484 assertEquals(1, genSoftConstraints.getExclude().getLinkIdentifier().size(),
485 "generated soft constraints should contain exclude constraint with one link-id");
486 assertEquals("link-id 1",
487 genSoftConstraints.getExclude().getLinkIdentifier().stream().findAny().orElseThrow().getLinkId());
488 assertEquals("openroadm-topology",
489 genSoftConstraints.getExclude().getLinkIdentifier().stream().findAny().orElseThrow()
490 .getLinkNetworkId());
491 assertNotNull(genSoftConstraints.getInclude(), "generated soft constraints should contain include constraint");
492 assertEquals(2, genSoftConstraints.getInclude().getNodeId().size(),
493 "generated soft constraints should contain include constraint with two node-id");
494 assertTrue(genSoftConstraints.getInclude().getNodeId().contains(new NodeIdType("node-id-1")));
495 assertTrue(genSoftConstraints.getInclude().getNodeId().contains(new NodeIdType("node-id-3")));
496 assertNull(genSoftConstraints.getLatency(),
497 "generated soft constraints should not contain any latency constraint");
498 assertNull(genSoftConstraints.getDistance(),
499 "generated soft constraints should not contain any max-distance constraint");
500 assertNull(genSoftConstraints.getCoRouting(),
501 "generated soft constraints should not contain any co-routing constraint");