ServiceHandler Update
[transportpce.git] / servicehandler / src / main / java / org / opendaylight / transportpce / servicehandler / MappingConstraints.java
1 /*
2  * Copyright © 2017 Orange, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9
10 package org.opendaylight.transportpce.servicehandler;
11
12 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.Constraints;
13 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.CoRoutingOrGeneral;
14 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.CoRouting;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.General;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.Diversity;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.Exclude;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.Include;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.Latency;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.HardConstraints;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.SoftConstraints;
22 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.ConstraintsSp;
23 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.constraints.sp.co.routing.or.general.co.routing.CoRoutingBuilder;
24 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.constraints.sp.co.routing.or.general.general.DiversityBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.constraints.sp.co.routing.or.general.general.ExcludeBuilder;
26 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.constraints.sp.co.routing.or.general.general.IncludeBuilder;
27 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.constraints.sp.co.routing.or.general.general.LatencyBuilder;
28 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.diversity.existing.service.contraints.sp.ExistingServiceApplicabilityBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.routing.constraints.sp.HardConstraintsBuilder;
30 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.routing.constraints.sp.SoftConstraintsBuilder;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 /**
35  * Class for mapping
36  * Hard/soft constraint from Service 1.2
37  * to servicePath 1.4.
38  * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
39  *
40  */
41 public class MappingConstraints {
42     /** Logging. */
43     private static final Logger LOG = LoggerFactory.getLogger(MappingConstraints.class);
44     private HardConstraints serviceHardConstraints;
45     private SoftConstraints serviceSoftConstraints;
46     private org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
47         .routing.constraints.rev170426.routing.constraints.sp.HardConstraints servicePathHardConstraints;
48     private org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
49         .routing.constraints.rev170426.routing.constraints.sp.SoftConstraints servicePathSoftConstraints;
50
51     /**
52      * MappingConstraints class constructor
53      * for hard/soft from service 1.2.
54      *
55      * @param hard HardConstraints
56      * @param soft SoftConstraints
57      */
58     public MappingConstraints(HardConstraints hard, SoftConstraints soft) {
59         setServiceHardConstraints(hard);
60         setServiceSoftConstraints(soft);
61     }
62
63     /**
64      * MappingConstraints class constructor
65      * for hard/soft from servicePath 1.4.
66      *
67      * @param hard HardConstraints
68      * @param soft SoftConstraints
69      */
70     public MappingConstraints(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
71             .routing.constraints.rev170426.routing.constraints.sp.HardConstraints hard,
72             org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
73             .routing.constraints.rev170426.routing.constraints.sp.SoftConstraints soft) {
74         setServicePathHardConstraints(hard);
75         setServicePathSoftConstraints(soft);
76     }
77
78     /**
79      *get all constraints informations
80      *from service constraints to map to
81      *servicePath constraints.
82      *
83      * @param input HardConstraints or SoftConstraints
84      * @return ConstraintsSp HardConstraintsSp or HardConstraintsSp
85      */
86     private <T> ConstraintsSp getConstraints(T input) {
87         CoRoutingOrGeneral coRoutingOrGeneral = null;
88         HardConstraintsBuilder tempHard = new HardConstraintsBuilder();
89         SoftConstraintsBuilder tempSoft = new SoftConstraintsBuilder();
90         if (input  !=  null && input instanceof Constraints) {
91             Constraints constraints = (Constraints)input;
92             coRoutingOrGeneral = constraints.getCoRoutingOrGeneral();
93             General tmpGeneral = null;
94             CoRouting tmpCoRouting = null;
95             if (coRoutingOrGeneral  !=  null) {
96                 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
97                     .rev170426.constraints.sp.co.routing.or.general.GeneralBuilder finalGeneral =
98                     new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
99                     .rev170426.constraints.sp.co.routing.or.general.GeneralBuilder();
100                 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
101                     .rev170426.constraints.sp.co.routing.or.general.CoRoutingBuilder finalCoRouting =
102                     new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
103                     .rev170426.constraints.sp.co.routing.or.general.CoRoutingBuilder();
104                 if (coRoutingOrGeneral instanceof General) {
105                     tmpGeneral = (General) coRoutingOrGeneral;
106                     if (tmpGeneral  !=  null) {
107                         Diversity tmpDiversity =  tmpGeneral.getDiversity();
108                         if (tmpDiversity  !=  null) {
109                             finalGeneral.setDiversity(
110                                     new DiversityBuilder()
111                                     .setExistingService(tmpDiversity.getExistingService())
112                                     .setExistingServiceApplicability(
113                                             new ExistingServiceApplicabilityBuilder()
114                                             .setClli(tmpDiversity.getExistingServiceApplicability().isSite())
115                                             .setNode(tmpDiversity.getExistingServiceApplicability().isNode())
116                                             .setSrlg(tmpDiversity.getExistingServiceApplicability().isSrlg())
117                                             .build())
118                                     .build());
119                         }
120                         Exclude tmpExclude = tmpGeneral.getExclude();
121                         if (tmpExclude  !=  null) {
122                             finalGeneral.setExclude(
123                                     new ExcludeBuilder()
124                                     .setSupportingServiceName(tmpExclude.getSupportingServiceName())
125                                     .setClli(tmpExclude.getSite())
126                                     .setNodeId(tmpExclude.getNodeId())
127                                     //.setAffinity(value)
128                                     //.setSRLG(value)
129                                     .build());
130                         }
131                         Include tmpInclude = tmpGeneral.getInclude();
132                         if (tmpInclude  !=  null) {
133                             finalGeneral.setInclude(
134                                     new IncludeBuilder()
135                                     //.setOrderedHops()
136                                     .build());
137                         }
138                         Latency tmpLatency = tmpGeneral.getLatency();
139                         if (tmpLatency != null) {
140                             finalGeneral.setLatency(
141                                     new LatencyBuilder()
142                                     .setMaxLatency(tmpLatency.getMaxLatency())
143                                     .build());
144                         }
145                     }
146                     tempHard.setCoRoutingOrGeneral(finalGeneral.build())
147                         .setCustomerCode(constraints.getCustomerCode());
148                     tempSoft.setCoRoutingOrGeneral(finalGeneral.build())
149                         .setCustomerCode(constraints.getCustomerCode());
150                 } else if (coRoutingOrGeneral instanceof CoRouting) {
151                     tmpCoRouting = (CoRouting)coRoutingOrGeneral;
152                     if (tmpCoRouting  !=  null) {
153                         org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014
154                             .constraints.co.routing.or.general.co.routing.CoRouting tmpCoRoutingCoRouting =
155                             tmpCoRouting.getCoRouting();
156                         if (tmpCoRoutingCoRouting  !=  null) {
157                             finalCoRouting.setCoRouting(
158                                     new CoRoutingBuilder()
159                                     .setExistingService(tmpCoRoutingCoRouting.getExistingService())
160                                     .build());
161                         }
162                     }
163                     tempHard.setCoRoutingOrGeneral(finalCoRouting.build())
164                         .setCustomerCode(constraints.getCustomerCode());
165                     tempSoft.setCoRoutingOrGeneral(finalCoRouting.build())
166                         .setCustomerCode(constraints.getCustomerCode());
167                 }
168             }
169         }
170         if (input instanceof HardConstraints) {
171             return tempHard.build();
172         } else if (input instanceof SoftConstraints) {
173             return tempSoft.build();
174         } else {
175             return null;
176         }
177     }
178
179     /**
180      * map hard/soft constraints from Service 1.2
181      * to ServicePath 1.4.
182      */
183     public void serviceToServicePathConstarints() {
184         LOG.info("Mapping Service Constraints to ServicePath Constraints");
185         //CoRoutingOrGeneral coRoutingOrGeneral = null;
186         if (serviceHardConstraints  !=  null) {
187             /*HardConstraintsBuilder tempHard = new HardConstraintsBuilder();
188             coRoutingOrGeneral = serviceHardConstraints.getCoRoutingOrGeneral();
189             General tmpGeneral = null;
190             CoRouting tmpCoRouting = null;
191             if (coRoutingOrGeneral  !=  null) {
192                 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
193                     .rev170426.constraints.sp.co.routing.or.general.GeneralBuilder finalGeneral =
194                     new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
195                     .rev170426.constraints.sp.co.routing.or.general.GeneralBuilder();
196                 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
197                     .rev170426.constraints.sp.co.routing.or.general.CoRoutingBuilder finalCoRouting =
198                     new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
199                     .rev170426.constraints.sp.co.routing.or.general.CoRoutingBuilder();
200                 if (coRoutingOrGeneral instanceof General) {
201                     tmpGeneral = (General) coRoutingOrGeneral;
202                     if (tmpGeneral  !=  null) {
203                         Diversity tmpDiversity =  tmpGeneral.getDiversity();
204                         if (tmpDiversity  !=  null) {
205                             finalGeneral.setDiversity(
206                                     new DiversityBuilder()
207                                         .setExistingService(tmpDiversity.getExistingService())
208                                         .setExistingServiceApplicability(
209                                                 new ExistingServiceApplicabilityBuilder()
210                                                 .setClli(tmpDiversity.getExistingServiceApplicability().isSite())
211                                                 .setNode(tmpDiversity.getExistingServiceApplicability().isNode())
212                                                 .setSrlg(tmpDiversity.getExistingServiceApplicability().isSrlg())
213                                                 .build())
214                                         .build());
215                         }
216                         Exclude tmpExclude = tmpGeneral.getExclude();
217                         if (tmpExclude  !=  null) {
218                             finalGeneral.setExclude(
219                                     new ExcludeBuilder()
220                                         .setSupportingServiceName(tmpExclude.getSupportingServiceName())
221                                         .setClli(tmpExclude.getSite())
222                                         .setNodeId(tmpExclude.getNodeId())
223                                         //.setAffinity(value)
224                                         //.setSRLG(value)
225                                         .build());
226                         }
227                         Include tmpInclude = tmpGeneral.getInclude();
228                         if (tmpInclude  !=  null) {
229                             finalGeneral.setInclude(
230                                     new IncludeBuilder()
231                                         //.setOrderedHops()
232                                         .build());
233                         }
234                         Latency tmpLatency = tmpGeneral.getLatency();
235                         if (tmpLatency != null) {
236                             finalGeneral.setLatency(
237                                     new LatencyBuilder()
238                                         .setMaxLatency(tmpLatency.getMaxLatency())
239                                         .build());
240                         }
241                     }
242                     tempHard
243                         .setCoRoutingOrGeneral(finalGeneral.build())
244                         .setCustomerCode(serviceHardConstraints.getCustomerCode());
245                 } else if (coRoutingOrGeneral instanceof CoRouting) {
246                     tmpCoRouting = (CoRouting)coRoutingOrGeneral;
247                     if (tmpCoRouting  !=  null) {
248                         org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014
249                             .constraints.co.routing.or.general.co.routing.CoRouting tmpCoRoutingCoRouting =
250                             tmpCoRouting.getCoRouting();
251                         if (tmpCoRoutingCoRouting  !=  null) {
252                             finalCoRouting.setCoRouting(
253                                     new CoRoutingBuilder()
254                                         .setExistingService(tmpCoRoutingCoRouting.getExistingService())
255                                         .build());
256                         }
257                     }
258                     tempHard
259                         .setCoRoutingOrGeneral(finalCoRouting.build())
260                         .setCustomerCode(serviceHardConstraints.getCustomerCode());
261
262                 }
263             }
264             servicePathHardConstraints = tempHard.build();*/
265
266             org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
267                 .rev170426.routing.constraints.sp.HardConstraints tempHard = (org.opendaylight.yang.gen
268                     .v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.routing
269                     .constraints.sp.HardConstraints) getConstraints(serviceHardConstraints);
270             if (tempHard != null) {
271                 servicePathHardConstraints = tempHard;
272             }
273         } else if (serviceSoftConstraints  !=  null) {
274             /*oftConstraintsBuilder tempSoft = new SoftConstraintsBuilder();
275             coRoutingOrGeneral = serviceSoftConstraints.getCoRoutingOrGeneral();
276             General tmpGeneral = null;
277             CoRouting tmpCoRouting = null;
278             if (coRoutingOrGeneral  !=  null) {
279                 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
280                     .rev170426.constraints.sp.co.routing.or.general.GeneralBuilder finalGeneral =
281                     new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
282                     .rev170426.constraints.sp.co.routing.or.general.GeneralBuilder();
283                 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
284                     .rev170426.constraints.sp.co.routing.or.general.CoRoutingBuilder finalCoRouting =
285                     new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
286                     .rev170426.constraints.sp.co.routing.or.general.CoRoutingBuilder();
287                 if (coRoutingOrGeneral instanceof General) {
288                     tmpGeneral = (General) coRoutingOrGeneral;
289                     if (tmpGeneral  !=  null) {
290                         Diversity tmpDiversity =  tmpGeneral.getDiversity();
291                         if (tmpDiversity  !=  null) {
292                             finalGeneral.setDiversity(
293                                     new DiversityBuilder()
294                                         .setExistingService(tmpDiversity.getExistingService())
295                                         .setExistingServiceApplicability(
296                                                 new ExistingServiceApplicabilityBuilder()
297                                                 .setClli(tmpDiversity.getExistingServiceApplicability().isSite())
298                                                 .setNode(tmpDiversity.getExistingServiceApplicability().isNode())
299                                                 .setSrlg(tmpDiversity.getExistingServiceApplicability().isSrlg())
300                                                 .build())
301                                         .build());
302                         }
303                         Exclude tmpExclude = tmpGeneral.getExclude();
304                         if (tmpExclude  !=  null) {
305                             finalGeneral.setExclude(
306                                     new ExcludeBuilder()
307                                         .setSupportingServiceName(tmpExclude.getSupportingServiceName())
308                                         .setClli(tmpExclude.getSite())
309                                         .setNodeId(tmpExclude.getNodeId())
310                                         //.setAffinity(value)
311                                         //.setSRLG(value)
312                                         .build());
313                         }
314                         Include tmpInclude = tmpGeneral.getInclude();
315                         if (tmpInclude  !=  null) {
316                             finalGeneral.setInclude(
317                                     new IncludeBuilder()
318                                         //.setOrderedHops()
319                                         .build());
320                         }
321                         Latency tmpLatency = tmpGeneral.getLatency();
322                         if (tmpLatency  !=  null) {
323                             finalGeneral.setLatency(
324                                     new LatencyBuilder()
325                                         .setMaxLatency(tmpLatency.getMaxLatency())
326                                         .build());
327                         }
328                     }
329                     tempSoft
330                         .setCoRoutingOrGeneral(finalGeneral.build())
331                         .setCustomerCode(serviceSoftConstraints.getCustomerCode());
332                 } else if (coRoutingOrGeneral instanceof CoRouting) {
333                     tmpCoRouting = (CoRouting)coRoutingOrGeneral;
334                     if (tmpCoRouting != null) {
335                         org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014
336                             .constraints.co.routing.or.general.co.routing.CoRouting tmpCoRoutingCoRouting =
337                             tmpCoRouting.getCoRouting();
338                         if (tmpCoRoutingCoRouting != null) {
339                             finalCoRouting.setCoRouting(
340                                     new CoRoutingBuilder()
341                                         .setExistingService(tmpCoRoutingCoRouting.getExistingService())
342                                         .build());
343                         }
344                     }
345                     tempSoft
346                         .setCoRoutingOrGeneral(finalCoRouting.build())
347                         .setCustomerCode(serviceSoftConstraints.getCustomerCode());
348
349                 }
350             }
351             servicePathSoftConstraints = tempSoft.build();*/
352             org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
353                 .rev170426.routing.constraints.sp.SoftConstraints tempSoft = (org.opendaylight.yang.gen
354                     .v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.routing
355                     .constraints.sp.SoftConstraints) getConstraints(serviceSoftConstraints);
356             if (tempSoft != null) {
357                 servicePathSoftConstraints = tempSoft;
358             }
359         }
360     }
361
362
363     public HardConstraints getServiceHardConstraints() {
364         return serviceHardConstraints;
365     }
366
367
368     public void setServiceHardConstraints(HardConstraints serviceHardConstraints) {
369         this.serviceHardConstraints = serviceHardConstraints;
370     }
371
372
373     public SoftConstraints getServiceSoftConstraints() {
374         return serviceSoftConstraints;
375     }
376
377
378     public void setServiceSoftConstraints(SoftConstraints serviceSoftConstraints) {
379         this.serviceSoftConstraints = serviceSoftConstraints;
380     }
381
382
383     public org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
384         .routing.constraints.rev170426.routing.constraints.sp.HardConstraints getServicePathHardConstraints() {
385         return servicePathHardConstraints;
386     }
387
388
389     public void setServicePathHardConstraints(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
390             .routing.constraints.rev170426.routing.constraints.sp.HardConstraints servicePathHardConstraints) {
391         this.servicePathHardConstraints = servicePathHardConstraints;
392     }
393
394
395     public org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
396         .routing.constraints.rev170426.routing.constraints.sp.SoftConstraints getServicePathSoftConstraints() {
397         return servicePathSoftConstraints;
398     }
399
400
401     public void setServicePathSoftConstraints(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
402             .routing.constraints.rev170426.routing.constraints.sp.SoftConstraints servicePathSoftConstraints) {
403         this.servicePathSoftConstraints = servicePathSoftConstraints;
404     }
405
406 }