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.util.HashMap;
11 import java.util.List;
14 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev210528.NodeIdType;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.DiversityConstraints.DiversityType;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.common.constraints.LinkIdentifier;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.common.constraints.LinkIdentifierBuilder;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.constraints.CoRouting;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.constraints.CoRoutingBuilder;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.constraints.DistanceBuilder;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.constraints.DiversityBuilder;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.constraints.Exclude;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.constraints.ExcludeBuilder;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.constraints.HopCountBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.constraints.Include;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.constraints.IncludeBuilder;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.constraints.LatencyBuilder;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.constraints.TEMetricBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.constraints.co.routing.ServiceIdentifierList;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.constraints.co.routing.ServiceIdentifierListBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.diversity.existing.service.constraints.ServiceIdentifierListKey;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.equipment.EquipmentBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.routing.constraints.HardConstraints;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.routing.constraints.HardConstraintsBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.routing.constraints.SoftConstraints;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.routing.constraints.SoftConstraintsBuilder;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.service.applicability.g.ServiceApplicabilityBuilder;
38 import org.opendaylight.yangtools.yang.common.Decimal64;
39 import org.opendaylight.yangtools.yang.common.Uint32;
40 import org.opendaylight.yangtools.yang.common.Uint8;
43 * Utility Class to Build Hard Constraints and Soft Constraints.
44 * @author Ahmed Helmy ( ahmad.helmy@orange.com )
45 * @author Gilles Thouenon (gilles.thouenon@orange.com)
47 public final class ConstraintsUtils {
49 private ConstraintsUtils() {
53 * Build a rather configurable soft-constraint.
54 * @param customerCode set the list of customer-code provided
55 * @param operationalMode set list of operational-mode
56 * @param diversityServiceList set diversity constraints from serviceListId
58 * @param exclude set exclude constraints
59 * @param include set include constraints
60 * @param maxLatency set a maxLatency value, null otherwise
61 * @param hopCount set a max-wdm-hop-count value
62 * @param teMetric set a max-wdm-TE-metric
63 * @param maxDistance set a max-distance value, null otherwise
64 * @param coRoutingServiceId set co-routing constraints
65 * @return the hard-constraints
67 public static SoftConstraints buildSoftConstraint(Set<String> customerCode, boolean operationalMode,
68 Set<String> diversityServiceList, String exclude, String include,
69 Double maxLatency, boolean hopCount, boolean teMetric,
70 String maxDistance, String coRoutingServiceId) {
72 HardConstraints baseConstraint = buildHardConstraint(customerCode, operationalMode, diversityServiceList,
73 exclude, include, maxLatency, hopCount, teMetric, maxDistance, coRoutingServiceId);
74 return new SoftConstraintsBuilder()
75 .setCustomerCode(baseConstraint.getCustomerCode())
76 .setOperationalMode(baseConstraint.getOperationalMode())
77 .setDiversity(baseConstraint.getDiversity())
78 .setExclude(baseConstraint.getExclude())
79 .setInclude(baseConstraint.getInclude())
80 .setLatency(baseConstraint.getLatency())
81 .setHopCount(baseConstraint.getHopCount())
82 .setTEMetric(baseConstraint.getTEMetric())
83 .setDistance(baseConstraint.getDistance())
84 .setCoRouting(baseConstraint.getCoRouting())
89 * Build a rather configurable hard-constraint.
90 * @param customerCode set the list of customer-code provided
91 * @param operationalMode set list of operational-mode
92 * @param diversityServiceList set diversity constraints from serviceListId
94 * @param exclude set exclude constraints
95 * @param include set include constraints
96 * @param maxLatency set a maxLatency value, null otherwise
97 * @param hopCount set a max-wdm-hop-count value
98 * @param teMetric set a max-wdm-TE-metric
99 * @param maxDistance set a max-distance value, null otherwise
100 * @param coRoutingServiceId set co-routing constraints
101 * @return the hard-constraints
103 public static HardConstraints buildHardConstraint(Set<String> customerCode, boolean operationalMode,
104 Set<String> diversityServiceList, String exclude, String include,
105 Double maxLatency, boolean hopCount, boolean teMetric,
106 String maxDistance, String coRoutingServiceId) {
108 Map<ServiceIdentifierListKey,
109 org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.diversity.existing.service
110 .constraints.ServiceIdentifierList>
111 serviceIdList = new HashMap<>();
112 if (diversityServiceList != null) {
113 for (String serviceId : diversityServiceList) {
114 org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.diversity.existing.service
115 .constraints.ServiceIdentifierList sil = createServiceIdentifierListForDiversity(serviceId);
116 serviceIdList.put(sil.key(), sil);
120 Map<String, Exclude> excludeMap = initialiseExcludeMap();
121 Map<String, Include> includeMap = initialiseIncludeMap();
122 Map<String, CoRouting> coRoutingMap = initialiseCoRoutingMap();
124 return new HardConstraintsBuilder()
125 .setCustomerCode(customerCode)
128 ? Set.of("operational-mode 1", "operational-mode 2")
131 serviceIdList.isEmpty()
133 : new DiversityBuilder()
134 .setDiversityType(DiversityType.Serial)
135 .setServiceIdentifierList(serviceIdList)
138 exclude == null || !excludeMap.containsKey(exclude)
140 : excludeMap.get(exclude))
142 include == null || !includeMap.containsKey(include)
144 : includeMap.get(include))
148 : new LatencyBuilder().setMaxLatency(Decimal64.valueOf(String.valueOf(maxLatency))).build())
151 ? new HopCountBuilder()
152 .setMaxWdmHopCount(Uint8.valueOf(3))
153 .setMaxOtnHopCount(Uint8.valueOf(5))
158 ? new TEMetricBuilder()
159 .setMaxWdmTEMetric(Uint32.valueOf(8))
160 .setMaxOtnTEMetric(Uint32.valueOf(11))
166 : new DistanceBuilder().setMaxDistance(Decimal64.valueOf(String.valueOf(maxDistance))).build())
168 coRoutingServiceId == null || !coRoutingMap.containsKey(coRoutingServiceId)
170 : coRoutingMap.get(coRoutingServiceId))
174 private static org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.diversity.existing
175 .service.constraints.ServiceIdentifierList createServiceIdentifierListForDiversity(String serviceId) {
176 return new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.diversity.existing
177 .service.constraints.ServiceIdentifierListBuilder()
178 .setServiceIdentifier(serviceId)
179 .setServiceApplicability(new ServiceApplicabilityBuilder()
188 private static Map<String, Exclude> initialiseExcludeMap() {
189 HashMap<String, Exclude> excludeHashMap = new HashMap<>();
190 LinkIdentifier linkId1 = new LinkIdentifierBuilder()
191 .setLinkId("link-id 1")
192 .setLinkNetworkId("openroadm-topology")
197 .setLinkIdentifier(List.of(linkId1))
202 .setNodeId(List.of(new NodeIdType("node-id-2")))
207 .setSupportingServiceName(List.of("supported-service-1", "supported-service-5"))
212 .setFiberBundle(List.of("fiber-1", "fiber-2"))
217 .setFiberBundle(List.of("fiber-2", "fiber-3"))
219 LinkIdentifier linkId2 = new LinkIdentifierBuilder()
220 .setLinkId("link-id 2")
221 .setLinkNetworkId("openroadm-topology")
223 LinkIdentifier linkId3 = new LinkIdentifierBuilder()
224 .setLinkId("link-id 3")
225 .setLinkNetworkId("openroadm-topology")
230 .setLinkIdentifier(List.of(linkId2, linkId3))
232 return excludeHashMap;
235 private static Map<String, Include> initialiseIncludeMap() {
236 HashMap<String, Include> includeHashMap = new HashMap<>();
237 LinkIdentifier linkId1 = new LinkIdentifierBuilder()
238 .setLinkId("link-id 1")
239 .setLinkNetworkId("openroadm-topology")
244 .setLinkIdentifier(List.of(linkId1))
249 .setNodeId(List.of(new NodeIdType("node-id-1"), new NodeIdType("node-id-3")))
254 .setSupportingServiceName(List.of("supported-service-1", "supported-service-5"))
259 .setFiberBundle(List.of("fiber-1", "fiber-2"))
264 .setFiberBundle(List.of("fiber-2", "fiber-3"))
266 LinkIdentifier linkId2 = new LinkIdentifierBuilder()
267 .setLinkId("link-id 2")
268 .setLinkNetworkId("openroadm-topology")
270 LinkIdentifier linkId3 = new LinkIdentifierBuilder()
271 .setLinkId("link-id 3")
272 .setLinkNetworkId("openroadm-topology")
277 .setLinkIdentifier(List.of(linkId2, linkId3))
279 return includeHashMap;
282 private static Map<String, CoRouting> initialiseCoRoutingMap() {
283 ServiceIdentifierList sil1 = new ServiceIdentifierListBuilder()
284 .setServiceIdentifier("service 1")
285 .setServiceApplicability(new ServiceApplicabilityBuilder()
286 .setEquipment(new EquipmentBuilder()
291 ServiceIdentifierList sil2 = new ServiceIdentifierListBuilder()
292 .setServiceIdentifier("service 2")
293 .setServiceApplicability(new ServiceApplicabilityBuilder()
297 ServiceIdentifierList sil3 = new ServiceIdentifierListBuilder()
298 .setServiceIdentifier("service 3")
299 .setServiceApplicability(new ServiceApplicabilityBuilder()
305 new CoRoutingBuilder().setServiceIdentifierList(Map.of(sil1.key(), sil1, sil2.key(), sil2)).build(),
307 new CoRoutingBuilder().setServiceIdentifierList(Map.of(sil3.key(), sil3)).build());