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.utils;
10 import java.math.BigDecimal;
11 import java.util.Arrays;
12 import java.util.HashMap;
13 import java.util.List;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev210528.NodeIdType;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.DiversityConstraints.DiversityType;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.common.constraints.LinkIdentifier;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.common.constraints.LinkIdentifierBuilder;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.CoRouting;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.CoRoutingBuilder;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.Distance;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.DistanceBuilder;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.Diversity;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.DiversityBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.Exclude;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.ExcludeBuilder;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.HopCount;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.HopCountBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.Include;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.IncludeBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.Latency;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.LatencyBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.TEMetric;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.TEMetricBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co.routing.ServiceIdentifierList;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co.routing.ServiceIdentifierListBuilder;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.diversity.existing.service.constraints.ServiceIdentifierListKey;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.equipment.EquipmentBuilder;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.HardConstraints;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.HardConstraintsBuilder;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.SoftConstraints;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.SoftConstraintsBuilder;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.service.applicability.g.ServiceApplicabilityBuilder;
44 import org.opendaylight.yangtools.yang.common.Uint32;
45 import org.opendaylight.yangtools.yang.common.Uint8;
48 * Utility Class to Build Hard Constraints and Soft Constraints.
49 * @author Ahmed Helmy ( ahmad.helmy@orange.com )
50 * @author Gilles Thouenon (gilles.thouenon@orange.com)
52 public final class ConstraintsUtils {
54 private ConstraintsUtils() {
58 * Build a rather configurable soft-constraint.
59 * @param customerCode set the list of customer-code provided
60 * @param operationalMode set list of operational-mode
61 * @param diversityServiceList set diversity constraints from serviceListId
63 * @param exclude set exclude constraints
64 * @param include set include constraints
65 * @param maxLatency set a maxLatency value, null otherwise
66 * @param hopCount set a max-wdm-hop-count value
67 * @param teMetric set a max-wdm-TE-metric
68 * @param maxDistance set a max-distance value, null otherwise
69 * @param coRoutingServiceId set co-routing constraints
70 * @return the hard-constraints
72 public static SoftConstraints buildSoftConstraint(List<String> customerCode, boolean operationalMode,
73 List<String> diversityServiceList, String exclude, String include,
74 Double maxLatency, boolean hopCount, boolean teMetric,
75 String maxDistance, String coRoutingServiceId) {
77 HardConstraints baseConstraint = buildHardConstraint(customerCode, operationalMode, diversityServiceList,
78 exclude, include, maxLatency, hopCount, teMetric, maxDistance, coRoutingServiceId);
79 return new SoftConstraintsBuilder()
80 .setCustomerCode(baseConstraint.getCustomerCode())
81 .setOperationalMode(baseConstraint.getOperationalMode())
82 .setDiversity(baseConstraint.getDiversity())
83 .setExclude(baseConstraint.getExclude())
84 .setInclude(baseConstraint.getInclude())
85 .setLatency(baseConstraint.getLatency())
86 .setHopCount(baseConstraint.getHopCount())
87 .setTEMetric(baseConstraint.getTEMetric())
88 .setDistance(baseConstraint.getDistance())
89 .setCoRouting(baseConstraint.getCoRouting())
94 * Build a rather configurable hard-constraint.
95 * @param customerCode set the list of customer-code provided
96 * @param operationalMode set list of operational-mode
97 * @param diversityServiceList set diversity constraints from serviceListId
99 * @param exclude set exclude constraints
100 * @param include set include constraints
101 * @param maxLatency set a maxLatency value, null otherwise
102 * @param hopCount set a max-wdm-hop-count value
103 * @param teMetric set a max-wdm-TE-metric
104 * @param maxDistance set a max-distance value, null otherwise
105 * @param coRoutingServiceId set co-routing constraints
106 * @return the hard-constraints
108 public static HardConstraints buildHardConstraint(List<String> customerCode, boolean operationalMode,
109 List<String> diversityServiceList, String exclude, String include,
110 Double maxLatency, boolean hopCount, boolean teMetric,
111 String maxDistance, String coRoutingServiceId) {
113 List<String> operationalModeList = null;
114 if (operationalMode) {
115 operationalModeList = Arrays.asList("operational-mode 1", "operational-mode 2");
117 Diversity diversity = null;
118 if (diversityServiceList != null && !diversityServiceList.isEmpty()) {
120 ServiceIdentifierListKey,
121 org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.diversity.existing.service
122 .constraints.ServiceIdentifierList> serviceIdList = new HashMap<>();
123 for (String serviceId : diversityServiceList) {
124 org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.diversity.existing.service
125 .constraints.ServiceIdentifierList sil = createServiceIdentifierListForDiversity(serviceId);
126 serviceIdList.put(sil.key(), sil);
128 diversity = new DiversityBuilder()
129 .setDiversityType(DiversityType.Serial)
130 .setServiceIdentifierList(serviceIdList)
134 Latency latency = null;
135 if (maxLatency != null) {
136 latency = new LatencyBuilder()
137 .setMaxLatency(new BigDecimal(maxLatency))
142 hc = new HopCountBuilder()
143 .setMaxWdmHopCount(Uint8.valueOf(3))
146 Map<String, Exclude> excludeMap = initialiseExcludeMap();
147 Exclude exclu = exclude == null || !excludeMap.containsKey(exclude)
149 : excludeMap.get(exclude);
151 Map<String, Include> includeMap = initialiseIncludeMap();
152 Include inclu = include == null || !includeMap.containsKey(include)
154 : includeMap.get(include);
158 tem = new TEMetricBuilder()
159 .setMaxWdmTEMetric(Uint32.valueOf(8))
162 Distance distance = null;
163 if (maxDistance != null) {
164 distance = new DistanceBuilder()
165 .setMaxDistance(new BigDecimal(maxDistance))
168 Map<String, CoRouting> coRoutingMap = initialiseCoRoutingMap();
169 CoRouting coRouting = coRoutingServiceId == null || !coRoutingMap.containsKey(coRoutingServiceId)
171 : coRoutingMap.get(coRoutingServiceId);
172 return new HardConstraintsBuilder()
173 .setCustomerCode(customerCode)
174 .setOperationalMode(operationalModeList)
175 .setDiversity(diversity)
181 .setDistance(distance)
182 .setCoRouting(coRouting)
186 private static org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.diversity.existing
187 .service.constraints.ServiceIdentifierList createServiceIdentifierListForDiversity(String serviceId) {
188 return new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.diversity.existing
189 .service.constraints.ServiceIdentifierListBuilder()
190 .setServiceIndentifier(serviceId)
191 .setServiceApplicability(new ServiceApplicabilityBuilder()
200 private static Map<String, Exclude> initialiseExcludeMap() {
201 LinkIdentifier linkId1 = new LinkIdentifierBuilder()
202 .setLinkId("link-id 1")
203 .setLinkNetworkId("openroadm-topology")
205 Exclude exclude1 = new ExcludeBuilder()
206 .setLinkIdentifier(Map.of(linkId1.key(), linkId1))
208 Exclude exclude2 = new ExcludeBuilder()
209 .setNodeId(List.of(new NodeIdType("node-id-2")))
211 Exclude exclude3 = new ExcludeBuilder()
212 .setSupportingServiceName(List.of("supported-service-1", "supported-service-5"))
214 Exclude exclude4 = new ExcludeBuilder()
215 .setFiberBundle(List.of("fiber-1", "fiber-2"))
217 Exclude exclude5 = new ExcludeBuilder()
218 .setFiberBundle(List.of("fiber-2", "fiber-3"))
220 LinkIdentifier linkId2 = new LinkIdentifierBuilder()
221 .setLinkId("link-id 2")
222 .setLinkNetworkId("openroadm-topology")
224 LinkIdentifier linkId3 = new LinkIdentifierBuilder()
225 .setLinkId("link-id 3")
226 .setLinkNetworkId("openroadm-topology")
228 Exclude exclude6 = new ExcludeBuilder()
229 .setLinkIdentifier(Map.of(linkId2.key(), linkId2, linkId3.key(), linkId3))
231 return Map.of("link1", exclude1, "node", exclude2, "service", exclude3, "fiber1", exclude4, "fiber2", exclude5,
235 private static Map<String, Include> initialiseIncludeMap() {
236 LinkIdentifier linkId1 = new LinkIdentifierBuilder()
237 .setLinkId("link-id 1")
238 .setLinkNetworkId("openroadm-topology")
240 Include exclude1 = new IncludeBuilder()
241 .setLinkIdentifier(Map.of(linkId1.key(), linkId1))
243 Include exclude2 = new IncludeBuilder()
244 .setNodeId(List.of(new NodeIdType("node-id-1"), new NodeIdType("node-id-3")))
246 Include exclude3 = new IncludeBuilder()
247 .setSupportingServiceName(List.of("supported-service-1", "supported-service-5"))
249 Include exclude4 = new IncludeBuilder()
250 .setFiberBundle(List.of("fiber-1", "fiber-2"))
252 Include exclude5 = new IncludeBuilder()
253 .setFiberBundle(List.of("fiber-2", "fiber-3"))
255 LinkIdentifier linkId2 = new LinkIdentifierBuilder()
256 .setLinkId("link-id 2")
257 .setLinkNetworkId("openroadm-topology")
259 LinkIdentifier linkId3 = new LinkIdentifierBuilder()
260 .setLinkId("link-id 3")
261 .setLinkNetworkId("openroadm-topology")
263 Include exclude6 = new IncludeBuilder()
264 .setLinkIdentifier(Map.of(linkId2.key(), linkId2, linkId3.key(), linkId3))
266 return Map.of("link1", exclude1, "node", exclude2, "service", exclude3, "fiber1", exclude4, "fiber2", exclude5,
270 private static Map<String, CoRouting> initialiseCoRoutingMap() {
271 ServiceIdentifierList sil1 = new ServiceIdentifierListBuilder()
272 .setServiceIdentifier("service 1")
273 .setServiceApplicability(new ServiceApplicabilityBuilder()
274 .setEquipment(new EquipmentBuilder()
279 ServiceIdentifierList sil2 = new ServiceIdentifierListBuilder()
280 .setServiceIdentifier("service 2")
281 .setServiceApplicability(new ServiceApplicabilityBuilder()
285 ServiceIdentifierList sil3 = new ServiceIdentifierListBuilder()
286 .setServiceIdentifier("service 3")
287 .setServiceApplicability(new ServiceApplicabilityBuilder()
291 CoRouting coRouting1 = new CoRoutingBuilder()
292 .setServiceIdentifierList(Map.of(sil1.key(), sil1, sil2.key(), sil2))
294 CoRouting coRouting2 = new CoRoutingBuilder()
295 .setServiceIdentifierList(Map.of(sil3.key(), sil3))
297 return Map.of("coRouting1", coRouting1, "coRouting2", coRouting2);