Initial commit for ServiceHandler
[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.CoRoutingOrGeneral;
13 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.CoRouting;
14 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.General;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.Diversity;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.Exclude;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.Include;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.Latency;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.HardConstraints;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.SoftConstraints;
21 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.constraints.sp.co.routing.or.general.co.routing.CoRoutingBuilder;
22 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.constraints.sp.co.routing.or.general.general.DiversityBuilder;
23 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.constraints.sp.co.routing.or.general.general.ExcludeBuilder;
24 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.constraints.sp.co.routing.or.general.general.IncludeBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.constraints.sp.co.routing.or.general.general.LatencyBuilder;
26 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.diversity.existing.service.contraints.sp.ExistingServiceApplicabilityBuilder;
27 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.routing.constraints.sp.HardConstraintsBuilder;
28 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.routing.constraints.sp.SoftConstraintsBuilder;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 /*
33  * Class for mapping
34  * Hard/soft constraint from Service 1.2
35  * to servicePath 1.4.
36  * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
37  *
38  */
39 public class MappingConstraints {
40     /* Logging. */
41     private static final Logger LOG = LoggerFactory.getLogger(MappingConstraints.class);
42     private HardConstraints serviceHardConstraints;
43     private SoftConstraints serviceSoftConstraints;
44     private org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
45         .routing.constraints.rev170426.routing.constraints.sp.HardConstraints servicePathHardConstraints;
46     private org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
47         .routing.constraints.rev170426.routing.constraints.sp.SoftConstraints servicePathSoftConstraints;
48
49
50     /*
51      * MappingConstraints class constructor
52      * for hard/soft from service 1.2.
53      *
54      * @param hard HardConstraints
55      * @param soft SoftConstraints
56      */
57     public MappingConstraints(HardConstraints hard, SoftConstraints soft) {
58         setServiceHardConstraints(hard);
59         setServiceSoftConstraints(soft);
60     }
61
62     /*
63      * MappingConstraints class constructor
64      * for hard/soft from servicePath 1.4.
65      *
66      * @param hard HardConstraints
67      * @param soft SoftConstraints
68      */
69     public MappingConstraints(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
70             .routing.constraints.rev170426.routing.constraints.sp.HardConstraints hard,
71             org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
72             .routing.constraints.rev170426.routing.constraints.sp.SoftConstraints soft) {
73         setServicePathHardConstraints(hard);
74         setServicePathSoftConstraints(soft);
75     }
76
77     /*
78      * map hard/soft constraints from Service 1.2
79      * to ServicePath 1.4.
80      */
81     public void serviceToServicePathConstarints() {
82         LOG.info("Mapping Service Constraints to ServicePath Constraints");
83         CoRoutingOrGeneral coRoutingOrGeneral = null;
84         if (serviceHardConstraints  !=  null) {
85             HardConstraintsBuilder tempHard = new HardConstraintsBuilder();
86             coRoutingOrGeneral = serviceHardConstraints.getCoRoutingOrGeneral();
87             General tmpGeneral = null;
88             CoRouting tmpCoRouting = null;
89             if (coRoutingOrGeneral  !=  null) {
90                 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
91                     .rev170426.constraints.sp.co.routing.or.general.GeneralBuilder finalGeneral =
92                     new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
93                     .rev170426.constraints.sp.co.routing.or.general.GeneralBuilder();
94                 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
95                     .rev170426.constraints.sp.co.routing.or.general.CoRoutingBuilder finalCoRouting =
96                     new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
97                     .rev170426.constraints.sp.co.routing.or.general.CoRoutingBuilder();
98                 if (coRoutingOrGeneral instanceof General) {
99                     tmpGeneral = (General) coRoutingOrGeneral;
100                     if (tmpGeneral  !=  null) {
101                         Diversity tmpDiversity =  tmpGeneral.getDiversity();
102                         if (tmpDiversity  !=  null) {
103                             finalGeneral.setDiversity(
104                                     new DiversityBuilder()
105                                         .setExistingService(tmpDiversity.getExistingService())
106                                         .setExistingServiceApplicability(
107                                                 new ExistingServiceApplicabilityBuilder()
108                                                 .setClli(tmpDiversity.getExistingServiceApplicability().isSite())
109                                                 .setNode(tmpDiversity.getExistingServiceApplicability().isNode())
110                                                 .setSrlg(tmpDiversity.getExistingServiceApplicability().isSrlg())
111                                                 .build())
112                                         .build());
113                         }
114                         Exclude tmpExclude = tmpGeneral.getExclude();
115                         if (tmpExclude  !=  null) {
116                             finalGeneral.setExclude(
117                                     new ExcludeBuilder()
118                                         .setSupportingServiceName(tmpExclude.getSupportingServiceName())
119                                         .setClli(tmpExclude.getSite())
120                                         .setNodeId(tmpExclude.getNodeId())
121                                         //.setAffinity(value)
122                                         //.setSRLG(value)
123                                         .build());
124                         }
125                         Include tmpInclude = tmpGeneral.getInclude();
126                         if (tmpInclude  !=  null) {
127                             finalGeneral.setInclude(
128                                     new IncludeBuilder()
129                                         //.setOrderedHops()
130                                         .build());
131                         }
132                         Latency tmpLatency = tmpGeneral.getLatency();
133                         if (tmpLatency != null) {
134                             finalGeneral.setLatency(
135                                     new LatencyBuilder()
136                                         .setMaxLatency(tmpLatency.getMaxLatency())
137                                         .build());
138                         }
139                     }
140                     tempHard
141                         .setCoRoutingOrGeneral(finalGeneral.build())
142                         .setCustomerCode(serviceHardConstraints.getCustomerCode());
143                 } else if (coRoutingOrGeneral instanceof CoRouting) {
144                     tmpCoRouting = (CoRouting)coRoutingOrGeneral;
145                     if (tmpCoRouting  !=  null) {
146                         org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014
147                             .constraints.co.routing.or.general.co.routing.CoRouting tmpCoRoutingCoRouting =
148                             tmpCoRouting.getCoRouting();
149                         if (tmpCoRoutingCoRouting  !=  null) {
150                             finalCoRouting.setCoRouting(
151                                     new CoRoutingBuilder()
152                                         .setExistingService(tmpCoRoutingCoRouting.getExistingService())
153                                         .build());
154                         }
155                     }
156                     tempHard
157                         .setCoRoutingOrGeneral(finalCoRouting.build())
158                         .setCustomerCode(serviceHardConstraints.getCustomerCode());
159
160                 }
161             }
162             servicePathHardConstraints = tempHard.build();
163         } else if (serviceSoftConstraints  !=  null) {
164             SoftConstraintsBuilder tempSoft = new SoftConstraintsBuilder();
165             coRoutingOrGeneral = serviceSoftConstraints.getCoRoutingOrGeneral();
166             General tmpGeneral = null;
167             CoRouting tmpCoRouting = null;
168             if (coRoutingOrGeneral  !=  null) {
169                 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
170                     .rev170426.constraints.sp.co.routing.or.general.GeneralBuilder finalGeneral =
171                     new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
172                     .rev170426.constraints.sp.co.routing.or.general.GeneralBuilder();
173                 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
174                     .rev170426.constraints.sp.co.routing.or.general.CoRoutingBuilder finalCoRouting =
175                     new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
176                     .rev170426.constraints.sp.co.routing.or.general.CoRoutingBuilder();
177                 if (coRoutingOrGeneral instanceof General) {
178                     tmpGeneral = (General) coRoutingOrGeneral;
179                     if (tmpGeneral  !=  null) {
180                         Diversity tmpDiversity =  tmpGeneral.getDiversity();
181                         if (tmpDiversity  !=  null) {
182                             finalGeneral.setDiversity(
183                                     new DiversityBuilder()
184                                         .setExistingService(tmpDiversity.getExistingService())
185                                         .setExistingServiceApplicability(
186                                                 new ExistingServiceApplicabilityBuilder()
187                                                 .setClli(tmpDiversity.getExistingServiceApplicability().isSite())
188                                                 .setNode(tmpDiversity.getExistingServiceApplicability().isNode())
189                                                 .setSrlg(tmpDiversity.getExistingServiceApplicability().isSrlg())
190                                                 .build())
191                                         .build());
192                         }
193                         Exclude tmpExclude = tmpGeneral.getExclude();
194                         if (tmpExclude  !=  null) {
195                             finalGeneral.setExclude(
196                                     new ExcludeBuilder()
197                                         .setSupportingServiceName(tmpExclude.getSupportingServiceName())
198                                         .setClli(tmpExclude.getSite())
199                                         .setNodeId(tmpExclude.getNodeId())
200                                         //.setAffinity(value)
201                                         //.setSRLG(value)
202                                         .build());
203                         }
204                         Include tmpInclude = tmpGeneral.getInclude();
205                         if (tmpInclude  !=  null) {
206                             finalGeneral.setInclude(
207                                     new IncludeBuilder()
208                                         //.setOrderedHops()
209                                         .build());
210                         }
211                         Latency tmpLatency = tmpGeneral.getLatency();
212                         if (tmpLatency  !=  null) {
213                             finalGeneral.setLatency(
214                                     new LatencyBuilder()
215                                         .setMaxLatency(tmpLatency.getMaxLatency())
216                                         .build());
217                         }
218                     }
219                     tempSoft
220                         .setCoRoutingOrGeneral(finalGeneral.build())
221                         .setCustomerCode(serviceSoftConstraints.getCustomerCode());
222                 } else if (coRoutingOrGeneral instanceof CoRouting) {
223                     tmpCoRouting = (CoRouting)coRoutingOrGeneral;
224                     if (tmpCoRouting != null) {
225                         org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014
226                             .constraints.co.routing.or.general.co.routing.CoRouting tmpCoRoutingCoRouting =
227                             tmpCoRouting.getCoRouting();
228                         if (tmpCoRoutingCoRouting != null) {
229                             finalCoRouting.setCoRouting(
230                                     new CoRoutingBuilder()
231                                         .setExistingService(tmpCoRoutingCoRouting.getExistingService())
232                                         .build());
233                         }
234                     }
235                     tempSoft
236                         .setCoRoutingOrGeneral(finalCoRouting.build())
237                         .setCustomerCode(serviceSoftConstraints.getCustomerCode());
238
239                 }
240             }
241             servicePathSoftConstraints = tempSoft.build();
242         }
243     }
244
245
246     public HardConstraints getServiceHardConstraints() {
247         return serviceHardConstraints;
248     }
249
250
251     public void setServiceHardConstraints(HardConstraints serviceHardConstraints) {
252         this.serviceHardConstraints = serviceHardConstraints;
253     }
254
255
256     public SoftConstraints getServiceSoftConstraints() {
257         return serviceSoftConstraints;
258     }
259
260
261     public void setServiceSoftConstraints(SoftConstraints serviceSoftConstraints) {
262         this.serviceSoftConstraints = serviceSoftConstraints;
263     }
264
265
266     public org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
267         .routing.constraints.rev170426.routing.constraints.sp.HardConstraints getServicePathHardConstraints() {
268         return servicePathHardConstraints;
269     }
270
271
272     public void setServicePathHardConstraints(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
273             .routing.constraints.rev170426.routing.constraints.sp.HardConstraints servicePathHardConstraints) {
274         this.servicePathHardConstraints = servicePathHardConstraints;
275     }
276
277
278     public org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
279         .routing.constraints.rev170426.routing.constraints.sp.SoftConstraints getServicePathSoftConstraints() {
280         return servicePathSoftConstraints;
281     }
282
283
284     public void setServicePathSoftConstraints(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
285             .routing.constraints.rev170426.routing.constraints.sp.SoftConstraints servicePathSoftConstraints) {
286         this.servicePathSoftConstraints = servicePathSoftConstraints;
287     }
288
289 }