2 * Copyright © 2017 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
10 package org.opendaylight.transportpce.servicehandler;
12 import java.util.ArrayList;
13 import java.util.List;
14 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev181130.NodeIdType;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.Constraints;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.CoRoutingOrGeneral;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.CoRouting;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.General;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.general.Diversity;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.general.Exclude;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.general.Include;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.general.Latency;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.routing.constraints.HardConstraints;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.routing.constraints.SoftConstraints;
25 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.ConstraintsSp;
26 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.co.routing.CoRoutingBuilder;
27 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.general.DiversityBuilder;
28 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.general.ExcludeBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.general.IncludeBuilder;
30 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.general.LatencyBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.diversity.existing.service.contraints.sp.ExistingServiceApplicabilityBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing.constraints.sp.HardConstraintsBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing.constraints.sp.SoftConstraintsBuilder;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
39 * Hard/soft constraint from Service 1.2
41 * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
44 public class MappingConstraints {
46 private static final Logger LOG = LoggerFactory.getLogger(MappingConstraints.class);
47 private HardConstraints serviceHardConstraints;
48 private SoftConstraints serviceSoftConstraints;
49 private org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
50 .routing.constraints.rev171017.routing.constraints.sp.HardConstraints servicePathHardConstraints;
51 private org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
52 .routing.constraints.rev171017.routing.constraints.sp.SoftConstraints servicePathSoftConstraints;
55 * MappingConstraints class constructor
56 * for hard/soft from service 1.2.
58 * @param hard HardConstraints
59 * @param soft SoftConstraints
61 public MappingConstraints(HardConstraints hard, SoftConstraints soft) {
62 setServiceHardConstraints(hard);
63 setServiceSoftConstraints(soft);
67 * MappingConstraints class constructor
68 * for hard/soft from servicePath 1.4.
70 * @param hard HardConstraints
71 * @param soft SoftConstraints
73 public MappingConstraints(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
74 .routing.constraints.rev171017.routing.constraints.sp.HardConstraints hard,
75 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
76 .routing.constraints.rev171017.routing.constraints.sp.SoftConstraints soft) {
77 setServicePathHardConstraints(hard);
78 setServicePathSoftConstraints(soft);
82 *get all constraints informations
83 *from service constraints to map to
84 *servicePath constraints.
86 * @param input HardConstraints or SoftConstraints
87 * @return ConstraintsSp HardConstraintsSp or HardConstraintsSp
89 private <T> ConstraintsSp getConstraints(T input) {
90 HardConstraintsBuilder tempHard = new HardConstraintsBuilder();
91 SoftConstraintsBuilder tempSoft = new SoftConstraintsBuilder();
92 if ((input != null) && (input instanceof Constraints)) {
93 updateConstraintBuilders(input, tempHard, tempSoft);
95 if (input instanceof HardConstraints) {
96 return tempHard.build();
97 } else if (input instanceof SoftConstraints) {
98 return tempSoft.build();
105 * Update hardConstraintsBuilder and softConstraintsBuilder regarding input.
108 * @param hardConstraintsBuilder HardConstraintsBuilder
109 * @param softConstraintsBuilder SoftConstraintsBuilder
111 private <T> void updateConstraintBuilders(T input,
112 HardConstraintsBuilder hardConstraintsBuilder,
113 SoftConstraintsBuilder softConstraintsBuilder) {
114 Constraints constraints = (Constraints)input;
115 CoRoutingOrGeneral coRoutingOrGeneral = constraints.getCoRoutingOrGeneral();
116 if (coRoutingOrGeneral != null) {
117 if (coRoutingOrGeneral instanceof General) {
118 updateConstraintBuilders4General(hardConstraintsBuilder, softConstraintsBuilder, constraints);
119 } else if (coRoutingOrGeneral instanceof CoRouting) {
120 updateConstraintBuilders4Corouting(hardConstraintsBuilder, softConstraintsBuilder, constraints);
126 * Update hardConstraintsBuilder and softConstraintsBuilder for corouting constraints.
127 * @param hardConstraintsBuilder HardConstraintsBuilder
128 * @param softConstraintsBuilder SoftConstraintsBuilder
129 * @param constraints Constraints
131 private void updateConstraintBuilders4Corouting(HardConstraintsBuilder hardConstraintsBuilder,
132 SoftConstraintsBuilder softConstraintsBuilder, Constraints constraints) {
133 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017
134 .constraints.sp.co.routing.or.general.CoRoutingBuilder finalCoRouting =
135 new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017
136 .constraints.sp.co.routing.or.general.CoRoutingBuilder();
137 CoRouting tmpCoRouting = (CoRouting)constraints.getCoRoutingOrGeneral();
138 if (tmpCoRouting != null) {
139 org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329
140 .constraints.co.routing.or.general.co.routing.CoRouting tmpCoRoutingCoRouting =
141 tmpCoRouting.getCoRouting();
142 if (tmpCoRoutingCoRouting != null) {
143 finalCoRouting.setCoRouting(
144 new CoRoutingBuilder()
145 .setExistingService(tmpCoRoutingCoRouting.getExistingService())
149 hardConstraintsBuilder.setCoRoutingOrGeneral(finalCoRouting.build())
150 .setCustomerCode(constraints.getCustomerCode());
151 softConstraintsBuilder.setCoRoutingOrGeneral(finalCoRouting.build())
152 .setCustomerCode(constraints.getCustomerCode());
156 * Update hardConstraintsBuilder and softConstraintsBuilder for general constraints.
157 * @param hardConstraintsBuilder HardConstraintsBuilder
158 * @param softConstraintsBuilder SoftConstraintsBuilder
159 * @param constraints Constraints
161 private void updateConstraintBuilders4General(HardConstraintsBuilder hardConstraintsBuilder,
162 SoftConstraintsBuilder softConstraintsBuilder, Constraints constraints) {
163 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017
164 .constraints.sp.co.routing.or.general.GeneralBuilder finalGeneral =
165 new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017
166 .constraints.sp.co.routing.or.general.GeneralBuilder();
167 General tmpGeneral = (General) constraints.getCoRoutingOrGeneral();
168 if (tmpGeneral != null) {
169 Diversity tmpDiversity = tmpGeneral.getDiversity();
170 if (tmpDiversity != null) {
171 finalGeneral.setDiversity(
172 new DiversityBuilder()
173 .setExistingService(tmpDiversity.getExistingService())
174 .setExistingServiceApplicability(
175 new ExistingServiceApplicabilityBuilder()
176 .setClli(tmpDiversity.getExistingServiceApplicability().isSite())
177 .setNode(tmpDiversity.getExistingServiceApplicability().isNode())
178 .setSrlg(tmpDiversity.getExistingServiceApplicability().isSrlg())
182 Exclude tmpExclude = tmpGeneral.getExclude();
183 if (tmpExclude != null) {
184 List<String> nodeIdList = new ArrayList<>();
185 for (NodeIdType nodeId : tmpExclude.getNodeId()) {
186 nodeIdList.add(nodeId.getValue());
188 finalGeneral.setExclude(
190 .setSupportingServiceName(tmpExclude.getSupportingServiceName())
191 .setClli(tmpExclude.getSite())
192 .setNodeId(nodeIdList)
195 Include tmpInclude = tmpGeneral.getInclude();
196 if (tmpInclude != null) {
197 finalGeneral.setInclude(
201 Latency tmpLatency = tmpGeneral.getLatency();
202 if (tmpLatency != null) {
203 finalGeneral.setLatency(
205 .setMaxLatency(tmpLatency.getMaxLatency())
209 hardConstraintsBuilder.setCoRoutingOrGeneral(finalGeneral.build())
210 .setCustomerCode(constraints.getCustomerCode());
211 softConstraintsBuilder.setCoRoutingOrGeneral(finalGeneral.build())
212 .setCustomerCode(constraints.getCustomerCode());
216 * map hard/soft constraints from Service 1.2
217 * to ServicePath 1.4.
219 public void serviceToServicePathConstarints() {
220 LOG.info("Mapping Service Constraints to ServicePath Constraints");
221 if (serviceHardConstraints != null) {
222 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
223 .rev171017.routing.constraints.sp.HardConstraints tempHard = (org.opendaylight.yang.gen
224 .v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing
225 .constraints.sp.HardConstraints) getConstraints(serviceHardConstraints);
226 if (tempHard != null) {
227 servicePathHardConstraints = tempHard;
229 } else if (serviceSoftConstraints != null) {
230 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
231 .rev171017.routing.constraints.sp.SoftConstraints tempSoft = (org.opendaylight.yang.gen
232 .v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing
233 .constraints.sp.SoftConstraints) getConstraints(serviceSoftConstraints);
234 if (tempSoft != null) {
235 servicePathSoftConstraints = tempSoft;
241 public HardConstraints getServiceHardConstraints() {
242 return serviceHardConstraints;
246 public void setServiceHardConstraints(HardConstraints serviceHardConstraints) {
247 this.serviceHardConstraints = serviceHardConstraints;
251 public SoftConstraints getServiceSoftConstraints() {
252 return serviceSoftConstraints;
256 public void setServiceSoftConstraints(SoftConstraints serviceSoftConstraints) {
257 this.serviceSoftConstraints = serviceSoftConstraints;
261 public org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
262 .routing.constraints.rev171017.routing.constraints.sp.HardConstraints getServicePathHardConstraints() {
263 return servicePathHardConstraints;
267 public void setServicePathHardConstraints(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
268 .routing.constraints.rev171017.routing.constraints.sp.HardConstraints servicePathHardConstraints) {
269 this.servicePathHardConstraints = servicePathHardConstraints;
273 public org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
274 .routing.constraints.rev171017.routing.constraints.sp.SoftConstraints getServicePathSoftConstraints() {
275 return servicePathSoftConstraints;
279 public void setServicePathSoftConstraints(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
280 .routing.constraints.rev171017.routing.constraints.sp.SoftConstraints servicePathSoftConstraints) {
281 this.servicePathSoftConstraints = servicePathSoftConstraints;